authorgravatar for hilger.mueller@gmail.comHilger Baumstark <hilger.mueller@gmail.com> 2025-06-01 20:17:25+02:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2025-06-01 20:17:25+02:00
log0386730777da858908aaba4ef96fb5bd48faafc9
tree777eb4aaa0625b5dd69a15291a300b58e80a20f0
parentc907866d55dd92352e26f7501e5a441210bedaba
signaturebadge-check Signed by PGP key B5690EEEBB952194

compiler-rt: add __addvsi3, __subvsi3, __mulvsi3, and __subvdi3


6 files changed, 113 insertions(+), 0 deletions(-)

CMakeLists.txt+4
...@@ -205,6 +205,7 @@ set(ZIG_STAGE2_SOURCES...@@ -205,6 +205,7 @@ set(ZIG_STAGE2_SOURCES
205 lib/compiler_rt/addo.zig205 lib/compiler_rt/addo.zig
206 lib/compiler_rt/addsf3.zig206 lib/compiler_rt/addsf3.zig
207 lib/compiler_rt/addtf3.zig207 lib/compiler_rt/addtf3.zig
208 lib/compiler_rt/addvsi3.zig
208 lib/compiler_rt/addxf3.zig209 lib/compiler_rt/addxf3.zig
209 lib/compiler_rt/arm.zig210 lib/compiler_rt/arm.zig
210 lib/compiler_rt/atomics.zig211 lib/compiler_rt/atomics.zig
...@@ -323,6 +324,7 @@ set(ZIG_STAGE2_SOURCES...@@ -323,6 +324,7 @@ set(ZIG_STAGE2_SOURCES
323 lib/compiler_rt/mulo.zig324 lib/compiler_rt/mulo.zig
324 lib/compiler_rt/mulsf3.zig325 lib/compiler_rt/mulsf3.zig
325 lib/compiler_rt/multf3.zig326 lib/compiler_rt/multf3.zig
327 lib/compiler_rt/mulvsi3.zig
326 lib/compiler_rt/mulxf3.zig328 lib/compiler_rt/mulxf3.zig
327 lib/compiler_rt/negXi2.zig329 lib/compiler_rt/negXi2.zig
328 lib/compiler_rt/negdf2.zig330 lib/compiler_rt/negdf2.zig
...@@ -346,6 +348,8 @@ set(ZIG_STAGE2_SOURCES...@@ -346,6 +348,8 @@ set(ZIG_STAGE2_SOURCES
346 lib/compiler_rt/subo.zig348 lib/compiler_rt/subo.zig
347 lib/compiler_rt/subsf3.zig349 lib/compiler_rt/subsf3.zig
348 lib/compiler_rt/subtf3.zig350 lib/compiler_rt/subtf3.zig
351 lib/compiler_rt/subvdi3.zig
352 lib/compiler_rt/subvsi3.zig
349 lib/compiler_rt/subxf3.zig353 lib/compiler_rt/subxf3.zig
350 lib/compiler_rt/tan.zig354 lib/compiler_rt/tan.zig
351 lib/compiler_rt/trig.zig355 lib/compiler_rt/trig.zig
lib/compiler_rt.zig+5
...@@ -27,6 +27,11 @@ comptime {...@@ -27,6 +27,11 @@ comptime {
27 _ = @import("compiler_rt/absvti2.zig");27 _ = @import("compiler_rt/absvti2.zig");
28 _ = @import("compiler_rt/negv.zig");28 _ = @import("compiler_rt/negv.zig");
2929
30 _ = @import("compiler_rt/addvsi3.zig");
31 _ = @import("compiler_rt/subvsi3.zig");
32 _ = @import("compiler_rt/subvdi3.zig");
33 _ = @import("compiler_rt/mulvsi3.zig");
34
30 _ = @import("compiler_rt/addo.zig");35 _ = @import("compiler_rt/addo.zig");
31 _ = @import("compiler_rt/subo.zig");36 _ = @import("compiler_rt/subo.zig");
32 _ = @import("compiler_rt/mulo.zig");37 _ = @import("compiler_rt/mulo.zig");
lib/compiler_rt/addvsi3.zig created+26
...@@ -0,0 +1,26 @@
1const addv = @import("addo.zig");
2const common = @import("./common.zig");
3const testing = @import("std").testing;
4
5pub const panic = common.panic;
6
7comptime {
8 @export(&__addvsi3, .{ .name = "__addvsi3", .linkage = common.linkage, .visibility = common.visibility });
9}
10
11pub 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");
15 return sum;
16}
17
18test "addvsi3" {
19 // const min: i32 = -2147483648
20 // const max: i32 = 2147483647
21 // TODO write panic handler for testing panics
22 // try test__addvsi3(-2147483648, -1, -1); // panic
23 // try test__addvsi3(2147483647, 1, 1); // panic
24 try testing.expectEqual(-2147483648, __addvsi3(-2147483647, -1));
25 try testing.expectEqual(2147483647, __addvsi3(2147483646, 1));
26}
lib/compiler_rt/mulvsi3.zig created+26
...@@ -0,0 +1,26 @@
1const mulv = @import("mulo.zig");
2const common = @import("./common.zig");
3const testing = @import("std").testing;
4
5pub const panic = common.panic;
6
7comptime {
8 @export(&__mulvsi3, .{ .name = "__mulvsi3", .linkage = common.linkage, .visibility = common.visibility });
9}
10
11pub fn __mulvsi3(a: i32, b: i32) callconv(.c) i32 {
12 var overflow: c_int = 0;
13 const sum = mulv.__mulosi4(a, b, &overflow);
14 if (overflow != 0) @panic("compiler-rt: integer overflow");
15 return sum;
16}
17
18test "mulvsi3" {
19 // min i32 = -2147483648
20 // max i32 = 2147483647
21 // TODO write panic handler for testing panics
22 // try test__mulvsi3(-2147483648, -1, -1); // panic
23 // try test__mulvsi3(2147483647, 1, 1); // panic
24 try testing.expectEqual(-2147483648, __mulvsi3(-1073741824, 2));
25 try testing.expectEqual(2147483646, __mulvsi3(1073741823, 2)); // one too less for corner case 2147483647
26}
lib/compiler_rt/subvdi3.zig created+26
...@@ -0,0 +1,26 @@
1const subv = @import("subo.zig");
2const common = @import("./common.zig");
3const testing = @import("std").testing;
4
5pub const panic = common.panic;
6
7comptime {
8 @export(&__subvdi3, .{ .name = "__subvdi3", .linkage = common.linkage, .visibility = common.visibility });
9}
10
11pub fn __subvdi3(a: i64, b: i64) callconv(.c) i64 {
12 var overflow: c_int = 0;
13 const sum = subv.__subodi4(a, b, &overflow);
14 if (overflow != 0) @panic("compiler-rt: integer overflow");
15 return sum;
16}
17
18test "subvdi3" {
19 // min i64 = -9223372036854775808
20 // max i64 = 9223372036854775807
21 // TODO write panic handler for testing panics
22 // try test__subvdi3(-9223372036854775808, -1, -1); // panic
23 // try test__addvdi3(9223372036854775807, 1, 1); // panic
24 try testing.expectEqual(-9223372036854775808, __subvdi3(-9223372036854775807, 1));
25 try testing.expectEqual(9223372036854775807, __subvdi3(9223372036854775806, -1));
26}
lib/compiler_rt/subvsi3.zig created+26
...@@ -0,0 +1,26 @@
1const subv = @import("subo.zig");
2const common = @import("./common.zig");
3const testing = @import("std").testing;
4
5pub const panic = common.panic;
6
7comptime {
8 @export(&__subvsi3, .{ .name = "__subvsi3", .linkage = common.linkage, .visibility = common.visibility });
9}
10
11pub fn __subvsi3(a: i32, b: i32) callconv(.c) i32 {
12 var overflow: c_int = 0;
13 const sum = subv.__subosi4(a, b, &overflow);
14 if (overflow != 0) @panic("compiler-rt: integer overflow");
15 return sum;
16}
17
18test "subvsi3" {
19 // min i32 = -2147483648
20 // max i32 = 2147483647
21 // TODO write panic handler for testing panics
22 // try test__subvsi3(-2147483648, -1, -1); // panic
23 // try test__subvsi3(2147483647, 1, 1); // panic
24 try testing.expectEqual(-2147483648, __subvsi3(-2147483647, 1));
25 try testing.expectEqual(2147483647, __subvsi3(2147483646, -1));
26}