Skip to content

Commit 24c6ab8

Browse files
committed
compiler-rt: remove dead code
`__addosi4`, `__addodi4`, `__addoti4`, `__subosi4`, `__subodi4`, and `__suboti4` were all functions which we invented for no apparent reason. Neither LLVM, nor GCC, nor the Zig compiler use these functions. It appears the functions were created in a kind of misunderstanding of an old language proposal; see #10824. There is no benefit to these functions existing; if a Zig compiler backend needs this operation, it is trivial to implement, and *far* simpler than calling a compiler-rt routine. Therefore, this commit deletes them. A small amount of that code was used by other parts of compiler-rt; the logic is trivial so has just been inlined where needed. I also chose to quickly implement `__addvdi3` (a standard function) because it is trivial and we already implement the `sub` parallel.
1 parent 1b6f963 commit 24c6ab8

File tree

13 files changed

+41
-589
lines changed

13 files changed

+41
-589
lines changed

lib/compiler_rt.zig

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ comptime {
2828
_ = @import("compiler_rt/negv.zig");
2929

3030
_ = @import("compiler_rt/addvsi3.zig");
31+
_ = @import("compiler_rt/addvdi3.zig");
32+
3133
_ = @import("compiler_rt/subvsi3.zig");
3234
_ = @import("compiler_rt/subvdi3.zig");
35+
3336
_ = @import("compiler_rt/mulvsi3.zig");
3437

35-
_ = @import("compiler_rt/addo.zig");
36-
_ = @import("compiler_rt/subo.zig");
3738
_ = @import("compiler_rt/mulo.zig");
3839

3940
// Float routines

lib/compiler_rt/addo.zig

Lines changed: 0 additions & 46 deletions
This file was deleted.

lib/compiler_rt/addodi4_test.zig

Lines changed: 0 additions & 77 deletions
This file was deleted.

lib/compiler_rt/addosi4_test.zig

Lines changed: 0 additions & 78 deletions
This file was deleted.

lib/compiler_rt/addoti4_test.zig

Lines changed: 0 additions & 80 deletions
This file was deleted.

lib/compiler_rt/addvdi3.zig

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
const common = @import("./common.zig");
2+
const testing = @import("std").testing;
3+
4+
pub const panic = common.panic;
5+
6+
comptime {
7+
@export(&__addvdi3, .{ .name = "__addvdi3", .linkage = common.linkage, .visibility = common.visibility });
8+
}
9+
10+
pub fn __addvdi3(a: i64, b: i64) callconv(.c) i64 {
11+
const sum = a +% b;
12+
// Overflow occurred iff both operands have the same sign, and the sign of the sum does
13+
// not match it. In other words, iff the sum sign is not the sign of either operand.
14+
if (((sum ^ a) & (sum ^ b)) < 0) @panic("compiler-rt: integer overflow");
15+
return sum;
16+
}
17+
18+
test "addvdi3" {
19+
// const min: i64 = -9223372036854775808
20+
// const max: i64 = 9223372036854775807
21+
// TODO write panic handler for testing panics
22+
// try test__addvdi3(-9223372036854775808, -1, -1); // panic
23+
// try test__addvdi3(9223372036854775807, 1, 1); // panic
24+
try testing.expectEqual(-9223372036854775808, __addvdi3(-9223372036854775807, -1));
25+
try testing.expectEqual(9223372036854775807, __addvdi3(9223372036854775806, 1));
26+
}

lib/compiler_rt/addvsi3.zig

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
const addv = @import("addo.zig");
21
const common = @import("./common.zig");
32
const testing = @import("std").testing;
43

@@ -9,9 +8,10 @@ comptime {
98
}
109

1110
pub fn __addvsi3(a: i32, b: i32) callconv(.c) i32 {
12-
var overflow: c_int = 0;
13-
const sum = addv.__addosi4(a, b, &overflow);
14-
if (overflow != 0) @panic("compiler-rt: integer overflow");
11+
const sum = a +% b;
12+
// Overflow occurred iff both operands have the same sign, and the sign of the sum does
13+
// not match it. In other words, iff the sum sign is not the sign of either operand.
14+
if (((sum ^ a) & (sum ^ b)) < 0) @panic("compiler-rt: integer overflow");
1515
return sum;
1616
}
1717

lib/compiler_rt/subo.zig

Lines changed: 0 additions & 47 deletions
This file was deleted.

0 commit comments

Comments
 (0)