mirror of
https://github.com/ziglang/zig.git
synced 2025-12-09 07:43:10 +00:00
Tests with no names are executed when using `zig test` regardless of the `--test-filter` used. Non-named tests should be used when simply importing unit tests from another file. This allows `zig test` to find all the appropriate tests, even when using `--test-filter`.
50 lines
1017 B
Zig
50 lines
1017 B
Zig
const builtin = @import("builtin");
|
|
const compiler_rt = @import("../compiler_rt.zig");
|
|
|
|
pub fn __muloti4(a: i128, b: i128, overflow: *c_int) callconv(.C) i128 {
|
|
@setRuntimeSafety(builtin.is_test);
|
|
|
|
const min = @bitCast(i128, @as(u128, 1 << (128 - 1)));
|
|
const max = ~min;
|
|
overflow.* = 0;
|
|
|
|
const r = a *% b;
|
|
if (a == min) {
|
|
if (b != 0 and b != 1) {
|
|
overflow.* = 1;
|
|
}
|
|
return r;
|
|
}
|
|
if (b == min) {
|
|
if (a != 0 and a != 1) {
|
|
overflow.* = 1;
|
|
}
|
|
return r;
|
|
}
|
|
|
|
const sa = a >> (128 - 1);
|
|
const abs_a = (a ^ sa) -% sa;
|
|
const sb = b >> (128 - 1);
|
|
const abs_b = (b ^ sb) -% sb;
|
|
|
|
if (abs_a < 2 or abs_b < 2) {
|
|
return r;
|
|
}
|
|
|
|
if (sa == sb) {
|
|
if (abs_a > @divTrunc(max, abs_b)) {
|
|
overflow.* = 1;
|
|
}
|
|
} else {
|
|
if (abs_a > @divTrunc(min, -abs_b)) {
|
|
overflow.* = 1;
|
|
}
|
|
}
|
|
|
|
return r;
|
|
}
|
|
|
|
test {
|
|
_ = @import("muloti4_test.zig");
|
|
}
|