authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-08 22:35:14+02:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2019-05-08 23:57:09+02:00
logd4434dfb6744b82429060b4118ab71c55dff2141
tree2867bdc3068a6ba2c796cf015c21a7b5456d95b5
parent92fd2df054d1e1523489c6a959354f5e75f647a4

compiler-rt: Add __floatundidf & __floatunsidf

Add AEABI builtins __aeabi_ul2d, __aeabi_ui2d

5 files changed, 114 insertions(+), 0 deletions(-)

CMakeLists.txt+2
......@@ -678,9 +678,11 @@ set(ZIG_STD_FILES
678678 "special/compiler_rt/fixunstfsi.zig"
679679 "special/compiler_rt/fixunstfti.zig"
680680 "special/compiler_rt/floatsiXf.zig"
681 "special/compiler_rt/floatunsidf.zig"
681682 "special/compiler_rt/floattidf.zig"
682683 "special/compiler_rt/floattisf.zig"
683684 "special/compiler_rt/floattitf.zig"
685 "special/compiler_rt/floatundidf.zig"
684686 "special/compiler_rt/floatunditf.zig"
685687 "special/compiler_rt/floatunsitf.zig"
686688 "special/compiler_rt/floatuntidf.zig"
std/special/compiler_rt.zig+5
......@@ -66,6 +66,9 @@ comptime {
6666
6767 @export("__floatsidf", @import("compiler_rt/floatsiXf.zig").__floatsidf, linkage);
6868 @export("__floatsisf", @import("compiler_rt/floatsiXf.zig").__floatsisf, linkage);
69 @export("__floatunsidf", @import("compiler_rt/floatunsidf.zig").__floatunsidf, linkage);
70 @export("__floatundidf", @import("compiler_rt/floatundidf.zig").__floatundidf, linkage);
71
6972 @export("__floattitf", @import("compiler_rt/floattitf.zig").__floattitf, linkage);
7073 @export("__floattidf", @import("compiler_rt/floattidf.zig").__floattidf, linkage);
7174 @export("__floattisf", @import("compiler_rt/floattisf.zig").__floattisf, linkage);
......@@ -158,6 +161,8 @@ comptime {
158161 @export("__aeabi_memcmp8", __aeabi_memcmp, linkage);
159162
160163 @export("__aeabi_i2d", @import("compiler_rt/floatsiXf.zig").__floatsidf, linkage);
164 @export("__aeabi_ui2d", @import("compiler_rt/floatunsidf.zig").__floatunsidf, linkage);
165 @export("__aeabi_ul2d", @import("compiler_rt/floatundidf.zig").__floatundidf, linkage);
161166 @export("__aeabi_fneg", @import("compiler_rt/negXf2.zig").__negsf2, linkage);
162167 @export("__aeabi_dneg", @import("compiler_rt/negXf2.zig").__negdf2, linkage);
163168
std/special/compiler_rt/floatundidf.zig created+24
......@@ -0,0 +1,24 @@
1const builtin = @import("builtin");
2const std = @import("std");
3
4const twop52: f64 = 0x1.0p52;
5const twop84: f64 = 0x1.0p84;
6const twop84_plus_twop52: f64 = 0x1.00000001p84;
7
8pub extern fn __floatundidf(a: u64) f64 {
9 @setRuntimeSafety(builtin.is_test);
10
11 if (a == 0) return 0;
12
13 var high = @bitCast(u64, twop84);
14 var low = @bitCast(u64, twop52);
15
16 high |= a >> 32;
17 low |= a & 0xFFFFFFFF;
18
19 return (@bitCast(f64, high) - twop84_plus_twop52) + @bitCast(f64, low);
20}
21
22test "import floatundidf" {
23 _ = @import("floatundidf_test.zig");
24}
std/special/compiler_rt/floatundidf_test.zig created+50
......@@ -0,0 +1,50 @@
1const __floatundidf = @import("floatundidf.zig").__floatundidf;
2const testing = @import("std").testing;
3
4fn test__floatundidf(a: u64, expected: f64) void {
5 const r = __floatundidf(a);
6 testing.expect(r == expected);
7}
8
9test "floatundidf" {
10 test__floatundidf(0, 0.0);
11 test__floatundidf(1, 1.0);
12 test__floatundidf(2, 2.0);
13 test__floatundidf(20, 20.0);
14 test__floatundidf(0x7FFFFF8000000000, 0x1.FFFFFEp+62);
15 test__floatundidf(0x7FFFFFFFFFFFF800, 0x1.FFFFFFFFFFFFEp+62);
16 test__floatundidf(0x7FFFFF0000000000, 0x1.FFFFFCp+62);
17 test__floatundidf(0x7FFFFFFFFFFFF000, 0x1.FFFFFFFFFFFFCp+62);
18 test__floatundidf(0x8000008000000000, 0x1.000001p+63);
19 test__floatundidf(0x8000000000000800, 0x1.0000000000001p+63);
20 test__floatundidf(0x8000010000000000, 0x1.000002p+63);
21 test__floatundidf(0x8000000000001000, 0x1.0000000000002p+63);
22 test__floatundidf(0x8000000000000000, 0x1p+63);
23 test__floatundidf(0x8000000000000001, 0x1p+63);
24 test__floatundidf(0x0007FB72E8000000, 0x1.FEDCBAp+50);
25 test__floatundidf(0x0007FB72EA000000, 0x1.FEDCBA8p+50);
26 test__floatundidf(0x0007FB72EB000000, 0x1.FEDCBACp+50);
27 test__floatundidf(0x0007FB72EBFFFFFF, 0x1.FEDCBAFFFFFFCp+50);
28 test__floatundidf(0x0007FB72EC000000, 0x1.FEDCBBp+50);
29 test__floatundidf(0x0007FB72E8000001, 0x1.FEDCBA0000004p+50);
30 test__floatundidf(0x0007FB72E6000000, 0x1.FEDCB98p+50);
31 test__floatundidf(0x0007FB72E7000000, 0x1.FEDCB9Cp+50);
32 test__floatundidf(0x0007FB72E7FFFFFF, 0x1.FEDCB9FFFFFFCp+50);
33 test__floatundidf(0x0007FB72E4000001, 0x1.FEDCB90000004p+50);
34 test__floatundidf(0x0007FB72E4000000, 0x1.FEDCB9p+50);
35 test__floatundidf(0x023479FD0E092DC0, 0x1.1A3CFE870496Ep+57);
36 test__floatundidf(0x023479FD0E092DA1, 0x1.1A3CFE870496Dp+57);
37 test__floatundidf(0x023479FD0E092DB0, 0x1.1A3CFE870496Ep+57);
38 test__floatundidf(0x023479FD0E092DB8, 0x1.1A3CFE870496Ep+57);
39 test__floatundidf(0x023479FD0E092DB6, 0x1.1A3CFE870496Ep+57);
40 test__floatundidf(0x023479FD0E092DBF, 0x1.1A3CFE870496Ep+57);
41 test__floatundidf(0x023479FD0E092DC1, 0x1.1A3CFE870496Ep+57);
42 test__floatundidf(0x023479FD0E092DC7, 0x1.1A3CFE870496Ep+57);
43 test__floatundidf(0x023479FD0E092DC8, 0x1.1A3CFE870496Ep+57);
44 test__floatundidf(0x023479FD0E092DCF, 0x1.1A3CFE870496Ep+57);
45 test__floatundidf(0x023479FD0E092DD0, 0x1.1A3CFE870496Ep+57);
46 test__floatundidf(0x023479FD0E092DD1, 0x1.1A3CFE870496Fp+57);
47 test__floatundidf(0x023479FD0E092DD8, 0x1.1A3CFE870496Fp+57);
48 test__floatundidf(0x023479FD0E092DDF, 0x1.1A3CFE870496Fp+57);
49 test__floatundidf(0x023479FD0E092DE0, 0x1.1A3CFE870496Fp+57);
50}
std/special/compiler_rt/floatunsidf.zig created+33
......@@ -0,0 +1,33 @@
1const builtin = @import("builtin");
2const std = @import("std");
3const maxInt = std.math.maxInt;
4
5const implicitBit = u64(1) << 52;
6
7pub extern fn __floatunsidf(arg: u32) f64 {
8 @setRuntimeSafety(builtin.is_test);
9
10 if (arg == 0) return 0.0;
11
12 // The exponent is the width of abs(a)
13 const exp = u64(31) - @clz(arg);
14 // Shift a into the significand field and clear the implicit bit
15 const shift = @intCast(u6, 52 - exp);
16 const mant = u64(arg) << shift ^ implicitBit;
17
18 return @bitCast(f64, mant | (exp + 1023) << 52);
19}
20
21fn test_one_floatunsidf(a: u32, expected: u64) void {
22 const r = __floatunsidf(a);
23 std.testing.expect(@bitCast(u64, r) == expected);
24}
25
26test "floatsidf" {
27 // Test the produced bit pattern
28 test_one_floatunsidf(0, 0x0000000000000000);
29 test_one_floatunsidf(1, 0x3ff0000000000000);
30 test_one_floatunsidf(0x7FFFFFFF, 0x41dfffffffc00000);
31 test_one_floatunsidf(@intCast(u32, 0x80000000), 0x41e0000000000000);
32 test_one_floatunsidf(@intCast(u32, 0xFFFFFFFF), 0x41efffffffe00000);
33}