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 @@...@@ -1,4 +1,5 @@
1const common = @import("./common.zig");1const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
3pub const panic = common.panic;4pub const panic = common.panic;
45
...@@ -11,11 +12,14 @@ comptime {...@@ -11,11 +12,14 @@ comptime {
11}12}
1213
13fn __subdf3(a: f64, b: f64) callconv(.C) f64 {14fn __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 sub(a, b);
15 return a + neg_b;
16}16}
1717
18fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {18fn __aeabi_dsub(a: f64, b: f64) callconv(.AAPCS) f64 {
19 return sub(a, b);
20}
21
22inline fn sub(a: f64, b: f64) f64 {
19 const neg_b = @as(f64, @bitCast(@as(u64, @bitCast(b)) ^ (@as(u64, 1) << 63)));23 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);
21}25}
lib/compiler_rt/subhf3.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const common = @import("./common.zig");1const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
3pub const panic = common.panic;4pub const panic = common.panic;
45
...@@ -8,5 +9,5 @@ comptime {...@@ -8,5 +9,5 @@ comptime {
89
9fn __subhf3(a: f16, b: f16) callconv(.C) f16 {10fn __subhf3(a: f16, b: f16) callconv(.C) f16 {
10 const neg_b = @as(f16, @bitCast(@as(u16, @bitCast(b)) ^ (@as(u16, 1) << 15)));11 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);
12}13}
lib/compiler_rt/subsf3.zig+7-3
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const common = @import("./common.zig");1const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
3pub const panic = common.panic;4pub const panic = common.panic;
45
...@@ -11,11 +12,14 @@ comptime {...@@ -11,11 +12,14 @@ comptime {
11}12}
1213
13fn __subsf3(a: f32, b: f32) callconv(.C) f32 {14fn __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 sub(a, b);
15 return a + neg_b;
16}16}
1717
18fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {18fn __aeabi_fsub(a: f32, b: f32) callconv(.AAPCS) f32 {
19 return sub(a, b);
20}
21
22inline fn sub(a: f32, b: f32) f32 {
19 const neg_b = @as(f32, @bitCast(@as(u32, @bitCast(b)) ^ (@as(u32, 1) << 31)));23 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);
21}25}
lib/compiler_rt/subtf3.zig+2-1
...@@ -1,4 +1,5 @@...@@ -1,4 +1,5 @@
1const common = @import("./common.zig");1const common = @import("./common.zig");
2const addf3 = @import("./addf3.zig").addf3;
23
3pub const panic = common.panic;4pub const panic = common.panic;
45
...@@ -21,5 +22,5 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {...@@ -21,5 +22,5 @@ fn _Qp_sub(c: *f128, a: *const f128, b: *const f128) callconv(.C) void {
2122
22inline fn sub(a: f128, b: f128) f128 {23inline fn sub(a: f128, b: f128) f128 {
23 const neg_b = @as(f128, @bitCast(@as(u128, @bitCast(b)) ^ (@as(u128, 1) << 127)));24 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);
25}26}
test/behavior/atomics.zig-5
...@@ -243,11 +243,6 @@ test "atomicrmw with ints" {...@@ -243,11 +243,6 @@ test "atomicrmw with ints" {
243 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO243 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
244 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;244 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
251 try testAtomicRmwInts();246 try testAtomicRmwInts();
252 try comptime testAtomicRmwInts();247 try comptime testAtomicRmwInts();
253}248}
test/behavior/floatop.zig-40
...@@ -711,18 +711,6 @@ test "@floor f80" {...@@ -711,18 +711,6 @@ test "@floor f80" {
711 return error.SkipZigTest;711 return error.SkipZigTest;
712 }712 }
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
726 try testFloorLegacy(f80, 12.0);714 try testFloorLegacy(f80, 12.0);
727 try comptime testFloorLegacy(f80, 12.0);715 try comptime testFloorLegacy(f80, 12.0);
728}716}
...@@ -734,13 +722,6 @@ test "@floor f128" {...@@ -734,13 +722,6 @@ test "@floor f128" {
734 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;722 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
735 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;723 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
744 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isARM()) {725 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch.isARM()) {
745 // https://github.com/ziglang/zig/issues/16848726 // https://github.com/ziglang/zig/issues/16848
746 return error.SkipZigTest;727 return error.SkipZigTest;
...@@ -831,13 +812,6 @@ test "@ceil f80" {...@@ -831,13 +812,6 @@ test "@ceil f80" {
831 return error.SkipZigTest;812 return error.SkipZigTest;
832 }813 }
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
841 try testCeilLegacy(f80, 12.0);815 try testCeilLegacy(f80, 12.0);
842 try comptime testCeilLegacy(f80, 12.0);816 try comptime testCeilLegacy(f80, 12.0);
843}817}
...@@ -849,13 +823,6 @@ test "@ceil f128" {...@@ -849,13 +823,6 @@ test "@ceil f128" {
849 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;823 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
850 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;824 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
859 try testCeilLegacy(f128, 12.0);826 try testCeilLegacy(f128, 12.0);
860 try comptime testCeilLegacy(f128, 12.0);827 try comptime testCeilLegacy(f128, 12.0);
861}828}
...@@ -962,13 +929,6 @@ test "@trunc f128" {...@@ -962,13 +929,6 @@ test "@trunc f128" {
962 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;929 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
963 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;930 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
972 try testTruncLegacy(f128, 12.0);932 try testTruncLegacy(f128, 12.0);
973 try comptime testTruncLegacy(f128, 12.0);933 try comptime testTruncLegacy(f128, 12.0);
974}934}
test/behavior/math.zig-28
...@@ -1360,13 +1360,6 @@ test "float remainder division using @rem" {...@@ -1360,13 +1360,6 @@ test "float remainder division using @rem" {
1360 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1360 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1361 if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; // TODO1361 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
1370 try comptime frem(f16);1363 try comptime frem(f16);
1371 try comptime frem(f32);1364 try comptime frem(f32);
1372 try comptime frem(f64);1365 try comptime frem(f64);
...@@ -1410,13 +1403,6 @@ test "float modulo division using @mod" {...@@ -1410,13 +1403,6 @@ test "float modulo division using @mod" {
1410 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO1403 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
1411 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1404 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
1420 try comptime fmod(f16);1406 try comptime fmod(f16);
1421 try comptime fmod(f32);1407 try comptime fmod(f32);
1422 try comptime fmod(f64);1408 try comptime fmod(f64);
...@@ -1480,13 +1466,6 @@ test "@round f80" {...@@ -1480,13 +1466,6 @@ test "@round f80" {
1480 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1466 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1481 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;1467 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
1490 try testRound(f80, 12.0);1469 try testRound(f80, 12.0);
1491 try comptime testRound(f80, 12.0);1470 try comptime testRound(f80, 12.0);
1492}1471}
...@@ -1499,13 +1478,6 @@ test "@round f128" {...@@ -1499,13 +1478,6 @@ test "@round f128" {
1499 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;1478 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
1500 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;1479 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
1509 try testRound(f128, 12.0);1481 try testRound(f128, 12.0);
1510 try comptime testRound(f128, 12.0);1482 try comptime testRound(f128, 12.0);
1511}1483}
test/behavior/muladd.zig-28
...@@ -62,13 +62,6 @@ test "@mulAdd f80" {...@@ -62,13 +62,6 @@ test "@mulAdd f80" {
62 return error.SkipZigTest;62 return error.SkipZigTest;
63 }63 }
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
72 try comptime testMulAdd80();65 try comptime testMulAdd80();
73 try testMulAdd80();66 try testMulAdd80();
74}67}
...@@ -93,13 +86,6 @@ test "@mulAdd f128" {...@@ -93,13 +86,6 @@ test "@mulAdd f128" {
93 return error.SkipZigTest;86 return error.SkipZigTest;
94 }87 }
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
103 try comptime testMulAdd128();89 try comptime testMulAdd128();
104 try testMulAdd128();90 try testMulAdd128();
105}91}
...@@ -203,13 +189,6 @@ test "vector f80" {...@@ -203,13 +189,6 @@ test "vector f80" {
203 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;189 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
204 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;190 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
213 try comptime vector80();192 try comptime vector80();
214 try vector80();193 try vector80();
215}194}
...@@ -235,13 +214,6 @@ test "vector f128" {...@@ -235,13 +214,6 @@ test "vector f128" {
235 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;214 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
236 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;215 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
245 try comptime vector128();217 try comptime vector128();
246 try vector128();218 try vector128();
247}219}
test/behavior/vector.zig-7
...@@ -104,13 +104,6 @@ test "vector float operators" {...@@ -104,13 +104,6 @@ test "vector float operators" {
104 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;104 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
105 if (builtin.zig_backend == .stage2_c and comptime builtin.cpu.arch.isArmOrThumb()) return error.SkipZigTest;105 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
114 inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {107 inline for ([_]type{ f16, f32, f64, f80, f128 }) |T| {
115 const S = struct {108 const S = struct {
116 fn doTheTest() !void {109 fn doTheTest() !void {