Skip to content

#23909 adds __addvsi3, __subvsi3, __mulvsi3, subvdi3 to compiler_rt #24000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Jun 1, 2025
Merged
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/addo.zig
lib/compiler_rt/addsf3.zig
lib/compiler_rt/addtf3.zig
lib/compiler_rt/addvsi3.zig
lib/compiler_rt/addxf3.zig
lib/compiler_rt/arm.zig
lib/compiler_rt/atomics.zig
Expand Down Expand Up @@ -323,6 +324,7 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/mulo.zig
lib/compiler_rt/mulsf3.zig
lib/compiler_rt/multf3.zig
lib/compiler_rt/mulvsi3.zig
lib/compiler_rt/mulxf3.zig
lib/compiler_rt/negXi2.zig
lib/compiler_rt/negdf2.zig
Expand All @@ -346,6 +348,8 @@ set(ZIG_STAGE2_SOURCES
lib/compiler_rt/subo.zig
lib/compiler_rt/subsf3.zig
lib/compiler_rt/subtf3.zig
lib/compiler_rt/subvdi3.zig
lib/compiler_rt/subvsi3.zig
lib/compiler_rt/subxf3.zig
lib/compiler_rt/tan.zig
lib/compiler_rt/trig.zig
Expand Down
5 changes: 5 additions & 0 deletions lib/compiler_rt.zig
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@ comptime {
_ = @import("compiler_rt/absvti2.zig");
_ = @import("compiler_rt/negv.zig");

_ = @import("compiler_rt/addvsi3.zig");
_ = @import("compiler_rt/subvsi3.zig");
_ = @import("compiler_rt/subvdi3.zig");
_ = @import("compiler_rt/mulvsi3.zig");

_ = @import("compiler_rt/addo.zig");
_ = @import("compiler_rt/subo.zig");
_ = @import("compiler_rt/mulo.zig");
Expand Down
26 changes: 26 additions & 0 deletions lib/compiler_rt/addvsi3.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const addv = @import("addo.zig");
const common = @import("./common.zig");
const testing = @import("std").testing;

pub const panic = common.panic;

comptime {
@export(&__addvsi3, .{ .name = "__addvsi3", .linkage = common.linkage, .visibility = common.visibility });
}

pub fn __addvsi3(a: i32, b: i32) callconv(.c) i32 {
var overflow: c_int = 0;
const sum = addv.__addosi4(a, b, &overflow);
if (overflow != 0) @panic("compiler-rt: integer overflow");
return sum;
}

test "addvsi3" {
// const min: i32 = -2147483648
// const max: i32 = 2147483647
// TODO write panic handler for testing panics
// try test__addvsi3(-2147483648, -1, -1); // panic
// try test__addvsi3(2147483647, 1, 1); // panic
try testing.expectEqual(-2147483648, __addvsi3(-2147483647, -1));
try testing.expectEqual(2147483647, __addvsi3(2147483646, 1));
}
26 changes: 26 additions & 0 deletions lib/compiler_rt/mulvsi3.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const mulv = @import("mulo.zig");
const common = @import("./common.zig");
const testing = @import("std").testing;

pub const panic = common.panic;

comptime {
@export(&__mulvsi3, .{ .name = "__mulvsi3", .linkage = common.linkage, .visibility = common.visibility });
}

pub fn __mulvsi3(a: i32, b: i32) callconv(.c) i32 {
var overflow: c_int = 0;
const sum = mulv.__mulosi4(a, b, &overflow);
if (overflow != 0) @panic("compiler-rt: integer overflow");
return sum;
}

test "mulvsi3" {
// min i32 = -2147483648
// max i32 = 2147483647
// TODO write panic handler for testing panics
// try test__mulvsi3(-2147483648, -1, -1); // panic
// try test__mulvsi3(2147483647, 1, 1); // panic
try testing.expectEqual(-2147483648, __mulvsi3(-1073741824, 2));
try testing.expectEqual(2147483646, __mulvsi3(1073741823, 2)); // one too less for corner case 2147483647
}
26 changes: 26 additions & 0 deletions lib/compiler_rt/subvdi3.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const subv = @import("subo.zig");
const common = @import("./common.zig");
const testing = @import("std").testing;

pub const panic = common.panic;

comptime {
@export(&__subvdi3, .{ .name = "__subvdi3", .linkage = common.linkage, .visibility = common.visibility });
}

pub fn __subvdi3(a: i64, b: i64) callconv(.c) i64 {
var overflow: c_int = 0;
const sum = subv.__subodi4(a, b, &overflow);
if (overflow != 0) @panic("compiler-rt: integer overflow");
return sum;
}

test "subvdi3" {
// min i64 = -9223372036854775808
// max i64 = 9223372036854775807
// TODO write panic handler for testing panics
// try test__subvdi3(-9223372036854775808, -1, -1); // panic
// try test__addvdi3(9223372036854775807, 1, 1); // panic
try testing.expectEqual(-9223372036854775808, __subvdi3(-9223372036854775807, 1));
try testing.expectEqual(9223372036854775807, __subvdi3(9223372036854775806, -1));
}
26 changes: 26 additions & 0 deletions lib/compiler_rt/subvsi3.zig
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const subv = @import("subo.zig");
const common = @import("./common.zig");
const testing = @import("std").testing;

pub const panic = common.panic;

comptime {
@export(&__subvsi3, .{ .name = "__subvsi3", .linkage = common.linkage, .visibility = common.visibility });
}

pub fn __subvsi3(a: i32, b: i32) callconv(.c) i32 {
var overflow: c_int = 0;
const sum = subv.__subosi4(a, b, &overflow);
if (overflow != 0) @panic("compiler-rt: integer overflow");
return sum;
}

test "subvsi3" {
// min i32 = -2147483648
// max i32 = 2147483647
// TODO write panic handler for testing panics
// try test__subvsi3(-2147483648, -1, -1); // panic
// try test__subvsi3(2147483647, 1, 1); // panic
try testing.expectEqual(-2147483648, __subvsi3(-2147483647, 1));
try testing.expectEqual(2147483647, __subvsi3(2147483646, -1));
}