mirror of
https://codeberg.org/ziglang/zig.git
synced 2025-12-06 05:44:20 +00:00
`__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 https://github.com/ziglang/zig/pull/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.
26 lines
983 B
Zig
26 lines
983 B
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 {
|
|
const sum = a -% b;
|
|
// Overflow occurred iff the operands have opposite signs, and the sign of the
|
|
// sum is the opposite of the lhs sign.
|
|
if (((a ^ b) & (sum ^ a)) < 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));
|
|
}
|