mirror of
https://github.com/ziglang/zig.git
synced 2025-12-12 17:23:09 +00:00
compiler-rt: add __addvsi3, __subvsi3, __mulvsi3, and __subvdi3
This commit is contained in:
parent
c907866d55
commit
0386730777
@ -205,6 +205,7 @@ set(ZIG_STAGE2_SOURCES
|
|||||||
lib/compiler_rt/addo.zig
|
lib/compiler_rt/addo.zig
|
||||||
lib/compiler_rt/addsf3.zig
|
lib/compiler_rt/addsf3.zig
|
||||||
lib/compiler_rt/addtf3.zig
|
lib/compiler_rt/addtf3.zig
|
||||||
|
lib/compiler_rt/addvsi3.zig
|
||||||
lib/compiler_rt/addxf3.zig
|
lib/compiler_rt/addxf3.zig
|
||||||
lib/compiler_rt/arm.zig
|
lib/compiler_rt/arm.zig
|
||||||
lib/compiler_rt/atomics.zig
|
lib/compiler_rt/atomics.zig
|
||||||
@ -323,6 +324,7 @@ set(ZIG_STAGE2_SOURCES
|
|||||||
lib/compiler_rt/mulo.zig
|
lib/compiler_rt/mulo.zig
|
||||||
lib/compiler_rt/mulsf3.zig
|
lib/compiler_rt/mulsf3.zig
|
||||||
lib/compiler_rt/multf3.zig
|
lib/compiler_rt/multf3.zig
|
||||||
|
lib/compiler_rt/mulvsi3.zig
|
||||||
lib/compiler_rt/mulxf3.zig
|
lib/compiler_rt/mulxf3.zig
|
||||||
lib/compiler_rt/negXi2.zig
|
lib/compiler_rt/negXi2.zig
|
||||||
lib/compiler_rt/negdf2.zig
|
lib/compiler_rt/negdf2.zig
|
||||||
@ -346,6 +348,8 @@ set(ZIG_STAGE2_SOURCES
|
|||||||
lib/compiler_rt/subo.zig
|
lib/compiler_rt/subo.zig
|
||||||
lib/compiler_rt/subsf3.zig
|
lib/compiler_rt/subsf3.zig
|
||||||
lib/compiler_rt/subtf3.zig
|
lib/compiler_rt/subtf3.zig
|
||||||
|
lib/compiler_rt/subvdi3.zig
|
||||||
|
lib/compiler_rt/subvsi3.zig
|
||||||
lib/compiler_rt/subxf3.zig
|
lib/compiler_rt/subxf3.zig
|
||||||
lib/compiler_rt/tan.zig
|
lib/compiler_rt/tan.zig
|
||||||
lib/compiler_rt/trig.zig
|
lib/compiler_rt/trig.zig
|
||||||
|
|||||||
@ -27,6 +27,11 @@ comptime {
|
|||||||
_ = @import("compiler_rt/absvti2.zig");
|
_ = @import("compiler_rt/absvti2.zig");
|
||||||
_ = @import("compiler_rt/negv.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/addo.zig");
|
||||||
_ = @import("compiler_rt/subo.zig");
|
_ = @import("compiler_rt/subo.zig");
|
||||||
_ = @import("compiler_rt/mulo.zig");
|
_ = @import("compiler_rt/mulo.zig");
|
||||||
|
|||||||
26
lib/compiler_rt/addvsi3.zig
Normal file
26
lib/compiler_rt/addvsi3.zig
Normal file
@ -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
lib/compiler_rt/mulvsi3.zig
Normal file
26
lib/compiler_rt/mulvsi3.zig
Normal file
@ -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
lib/compiler_rt/subvdi3.zig
Normal file
26
lib/compiler_rt/subvdi3.zig
Normal file
@ -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
lib/compiler_rt/subvsi3.zig
Normal file
26
lib/compiler_rt/subvsi3.zig
Normal file
@ -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));
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user