authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2023-08-18 02:22:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-19 09:37:52-07:00
logd65318847ff4f8eb9d6655b27bf769ea94c2c3d7
treee048c9b992e0703ae1007a7bc634ea176da6b65b
parent821971106383e6e64e679c4402278399798c76eb

compiler_rt: fix fp sub being optimized to call itself

Closes #16844 Reduces #16846

9 files changed, 18 insertions(+), 116 deletions(-)

lib/compiler_rt/subdf3.zig+7-3
......@@ -1,4 +1,5 @@
11const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
34pub const panic = common.panic;
45
......@@ -11,11 +12,14 @@ comptime {
1112}
1213
1314fn __subdf3(a: f64, b: f64) callconv(.C) f64 {
14 const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
15 return a + neg_b;
15 return sub(a, b);
1616}
1717
1818fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
19 return sub(a, b);
20}
21
22inline fn sub(a: f64, b: f64) f64 {
1923 const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));
20 return a + neg_b;
24 return addf3(f64, a, neg_b);
2125}
lib/compiler_rt/subhf3.zig+2-1
......@@ -1,4 +1,5 @@
11const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
34pub const panic = common.panic;
45
......@@ -8,5 +9,5 @@ comptime {
89
910fn __subhf3(a: f16, b: f16) callconv(.C) f16 {
1011 const neg_b = @as(f16, @bitCast(@as(u16, @bitCast(b)) ^ (@as(u16, 1) << 15)));
11 return a + neg_b;
12 return addf3(f16, a, neg_b);
1213}
lib/compiler_rt/subsf3.zig+7-3
......@@ -1,4 +1,5 @@
11const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
34pub const panic = common.panic;
45
......@@ -11,11 +12,14 @@ comptime {
1112}
1213
1314fn __subsf3(a: f32, b: f32) callconv(.C) f32 {
14 const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
15 return a + neg_b;
15 return sub(a, b);
1616}
1717
1818fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {
19 return sub(a, b);
20}
21
22inline fn sub(a: f32, b: f32) f32 {
1923 const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));
20 return a + neg_b;
24 return addf3(f32, a, neg_b);
2125}
lib/compiler_rt/subtf3.zig+2-1
......@@ -1,4 +1,5 @@
11const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
34pub const panic = common.panic;
45
......@@ -21,5 +22,5 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {
2122
2223inline fn sub(a: f128, b: f128) f128 {
2324 const neg_b = @as(f128, @bitCast(@as(u128, @bitCast(b)) ^ (@as(u128, 1) << 127)));
24 return a + neg_b;
25 return addf3(f128, a, neg_b);
2526}
test/behavior/atomics.zig-5
......@@ -243,11 +243,6 @@ test "atomicrmw with ints" {
243243 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
244244 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
245245
246 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) {
247 // https://github.com/ziglang/zig/issues/16846
248 return error.SkipZigTest;
249 }
250
251246 try testAtomicRmwInts();
252247 try comptime testAtomicRmwInts();
253248}
test/behavior/floatop.zig-40
......@@ -711,18 +711,6 @@ test "@floor f80" {
711711 return error.SkipZigTest;
712712 }
713713
714 if (builtin.zig_backend == .stage2_llvm and
715 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
716 {
717 // https://github.com/ziglang/zig/issues/16844
718 return error.SkipZigTest;
719 }
720
721 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isMIPS()) {
722 // https://github.com/ziglang/zig/issues/16846
723 return error.SkipZigTest;
724 }
725
726714 try testFloorLegacy(f80, 12.0);
727715 try comptime testFloorLegacy(f80, 12.0);
728716}
......@@ -734,13 +722,6 @@ test "@floor f128" {
734722 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
735723 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
736724
737 if (builtin.zig_backend == .stage2_llvm and
738 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
739 {
740 // https://github.com/ziglang/zig/issues/16844
741 return error.SkipZigTest;
742 }
743
744725 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isARM()) {
745726 // https://github.com/ziglang/zig/issues/16848
746727 return error.SkipZigTest;
......@@ -831,13 +812,6 @@ test "@ceil f80" {
831812 return error.SkipZigTest;
832813 }
833814
834 if (builtin.zig_backend == .stage2_llvm and
835 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
836 {
837 // https://github.com/ziglang/zig/issues/16844
838 return error.SkipZigTest;
839 }
840
841815 try testCeilLegacy(f80, 12.0);
842816 try comptime testCeilLegacy(f80, 12.0);
843817}
......@@ -849,13 +823,6 @@ test "@ceil f128" {
849823 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
850824 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
851825
852 if (builtin.zig_backend == .stage2_llvm and
853 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
854 {
855 // https://github.com/ziglang/zig/issues/16844
856 return error.SkipZigTest;
857 }
858
859826 try testCeilLegacy(f128, 12.0);
860827 try comptime testCeilLegacy(f128, 12.0);
861828}
......@@ -962,13 +929,6 @@ test "@trunc f128" {
962929 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
963930 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
964931
965 if (builtin.zig_backend == .stage2_llvm and
966 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
967 {
968 // https://github.com/ziglang/zig/issues/16844
969 return error.SkipZigTest;
970 }
971
972932 try testTruncLegacy(f128, 12.0);
973933 try comptime testTruncLegacy(f128, 12.0);
974934}
test/behavior/math.zig-28
......@@ -1360,13 +1360,6 @@ test "float remainder division using @rem" {
13601360 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
13611361 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO
13621362
1363 if (builtin.zig_backend == .stage2_llvm and
1364 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
1365 {
1366 // https://github.com/ziglang/zig/issues/16844
1367 return error.SkipZigTest;
1368 }
1369
13701363 try comptime frem(f16);
13711364 try comptime frem(f32);
13721365 try comptime frem(f64);
......@@ -1410,13 +1403,6 @@ test "float modulo division using @mod" {
14101403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
14111404 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
14121405
1413 if (builtin.zig_backend == .stage2_llvm and
1414 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
1415 {
1416 // https://github.com/ziglang/zig/issues/16844
1417 return error.SkipZigTest;
1418 }
1419
14201406 try comptime fmod(f16);
14211407 try comptime fmod(f32);
14221408 try comptime fmod(f64);
......@@ -1480,13 +1466,6 @@ test "@round f80" {
14801466 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
14811467 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
14821468
1483 if (builtin.zig_backend == .stage2_llvm and
1484 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
1485 {
1486 // https://github.com/ziglang/zig/issues/16844
1487 return error.SkipZigTest;
1488 }
1489
14901469 try testRound(f80, 12.0);
14911470 try comptime testRound(f80, 12.0);
14921471}
......@@ -1499,13 +1478,6 @@ test "@round f128" {
14991478 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
15001479 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
15011480
1502 if (builtin.zig_backend == .stage2_llvm and
1503 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
1504 {
1505 // https://github.com/ziglang/zig/issues/16844
1506 return error.SkipZigTest;
1507 }
1508
15091481 try testRound(f128, 12.0);
15101482 try comptime testRound(f128, 12.0);
15111483}
test/behavior/muladd.zig-28
......@@ -62,13 +62,6 @@ test "@mulAdd f80" {
6262 return error.SkipZigTest;
6363 }
6464
65 if (builtin.zig_backend == .stage2_llvm and
66 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
67 {
68 // https://github.com/ziglang/zig/issues/16844
69 return error.SkipZigTest;
70 }
71
7265 try comptime testMulAdd80();
7366 try testMulAdd80();
7467}
......@@ -93,13 +86,6 @@ test "@mulAdd f128" {
9386 return error.SkipZigTest;
9487 }
9588
96 if (builtin.zig_backend == .stage2_llvm and
97 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
98 {
99 // https://github.com/ziglang/zig/issues/16844
100 return error.SkipZigTest;
101 }
102
10389 try comptime testMulAdd128();
10490 try testMulAdd128();
10591}
......@@ -203,13 +189,6 @@ test "vector f80" {
203189 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
204190 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
205191
206 if (builtin.zig_backend == .stage2_llvm and
207 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
208 {
209 // https://github.com/ziglang/zig/issues/16844
210 return error.SkipZigTest;
211 }
212
213192 try comptime vector80();
214193 try vector80();
215194}
......@@ -235,13 +214,6 @@ test "vector f128" {
235214 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
236215 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
237216
238 if (builtin.zig_backend == .stage2_llvm and
239 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
240 {
241 // https://github.com/ziglang/zig/issues/16844
242 return error.SkipZigTest;
243 }
244
245217 try comptime vector128();
246218 try vector128();
247219}
test/behavior/vector.zig-7
......@@ -104,13 +104,6 @@ test "vector float operators" {
104104 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
105105 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;
106106
107 if (builtin.zig_backend == .stage2_llvm and
108 (builtin.cpu.arch == .powerpc64le or builtin.cpu.arch == .aarch64))
109 {
110 // https://github.com/ziglang/zig/issues/16844
111 return error.SkipZigTest;
112 }
113
114107 inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
115108 const S = struct {
116109 fn doTheTest() !void {