compiler-rt: Add __floatundidf & __floatunsidf

Add AEABI builtins __aeabi_ul2d, __aeabi_ui2d
master
LemonBoy 2019-05-08 22:35:14 +02:00
parent 92fd2df054
commit d4434dfb67
5 changed files with 114 additions and 0 deletions

View File

@ -678,9 +678,11 @@ set(ZIG_STD_FILES
"special/compiler_rt/fixunstfsi.zig"
"special/compiler_rt/fixunstfti.zig"
"special/compiler_rt/floatsiXf.zig"
"special/compiler_rt/floatunsidf.zig"
"special/compiler_rt/floattidf.zig"
"special/compiler_rt/floattisf.zig"
"special/compiler_rt/floattitf.zig"
"special/compiler_rt/floatundidf.zig"
"special/compiler_rt/floatunditf.zig"
"special/compiler_rt/floatunsitf.zig"
"special/compiler_rt/floatuntidf.zig"

View File

@ -66,6 +66,9 @@ comptime {
@export("__floatsidf", @import("compiler_rt/floatsiXf.zig").__floatsidf, linkage);
@export("__floatsisf", @import("compiler_rt/floatsiXf.zig").__floatsisf, linkage);
@export("__floatunsidf", @import("compiler_rt/floatunsidf.zig").__floatunsidf, linkage);
@export("__floatundidf", @import("compiler_rt/floatundidf.zig").__floatundidf, linkage);
@export("__floattitf", @import("compiler_rt/floattitf.zig").__floattitf, linkage);
@export("__floattidf", @import("compiler_rt/floattidf.zig").__floattidf, linkage);
@export("__floattisf", @import("compiler_rt/floattisf.zig").__floattisf, linkage);
@ -158,6 +161,8 @@ comptime {
@export("__aeabi_memcmp8", __aeabi_memcmp, linkage);
@export("__aeabi_i2d", @import("compiler_rt/floatsiXf.zig").__floatsidf, linkage);
@export("__aeabi_ui2d", @import("compiler_rt/floatunsidf.zig").__floatunsidf, linkage);
@export("__aeabi_ul2d", @import("compiler_rt/floatundidf.zig").__floatundidf, linkage);
@export("__aeabi_fneg", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
@export("__aeabi_dneg", @import("compiler_rt/negXf2.zig").__negdf2, linkage);

View File

@ -0,0 +1,24 @@
const builtin = @import("builtin");
const std = @import("std");
const twop52: f64 = 0x1.0p52;
const twop84: f64 = 0x1.0p84;
const twop84_plus_twop52: f64 = 0x1.00000001p84;
pub extern fn __floatundidf(a: u64) f64 {
@setRuntimeSafety(builtin.is_test);
if (a == 0) return 0;
var high = @bitCast(u64, twop84);
var low = @bitCast(u64, twop52);
high |= a >> 32;
low |= a & 0xFFFFFFFF;
return (@bitCast(f64, high) - twop84_plus_twop52) + @bitCast(f64, low);
}
test "import floatundidf" {
_ = @import("floatundidf_test.zig");
}

View File

@ -0,0 +1,50 @@
const __floatundidf = @import("floatundidf.zig").__floatundidf;
const testing = @import("std").testing;
fn test__floatundidf(a: u64, expected: f64) void {
const r = __floatundidf(a);
testing.expect(r == expected);
}
test "floatundidf" {
test__floatundidf(0, 0.0);
test__floatundidf(1, 1.0);
test__floatundidf(2, 2.0);
test__floatundidf(20, 20.0);
test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
test__floatundidf(0x8000008000000000, 0x1.000001p+63);
test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
test__floatundidf(0x8000010000000000, 0x1.000002p+63);
test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
test__floatundidf(0x8000000000000000, 0x1p+63);
test__floatundidf(0x8000000000000001, 0x1p+63);
test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
}

View File

@ -0,0 +1,33 @@
const builtin = @import("builtin");
const std = @import("std");
const maxInt = std.math.maxInt;
const implicitBit = u64(1) << 52;
pub extern fn __floatunsidf(arg: u32) f64 {
@setRuntimeSafety(builtin.is_test);
if (arg == 0) return 0.0;
// The exponent is the width of abs(a)
const exp = u64(31) - @clz(arg);
// Shift a into the significand field and clear the implicit bit
const shift = @intCast(u6, 52 - exp);
const mant = u64(arg) << shift ^ implicitBit;
return @bitCast(f64, mant | (exp + 1023) << 52);
}
fn test_one_floatunsidf(a: u32, expected: u64) void {
const r = __floatunsidf(a);
std.testing.expect(@bitCast(u64, r) == expected);
}
test "floatsidf" {
// Test the produced bit pattern
test_one_floatunsidf(0, 0x0000000000000000);
test_one_floatunsidf(1, 0x3ff0000000000000);
test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
}