mirror of
https://github.com/ziglang/zig.git
synced 2025-12-06 06:13:07 +00:00
stage2: change logic for detecting whether the main package is inside
the std package. Previously it relied on realpath() which is not portable.
This uses resolve() which is how imports already work.
* stage2: fix cleanup bug when creating Module
* flatten lib/std/special/* to lib/*
- this was motivated by making main_pkg_is_inside_std false for
compiler_rt & friends.
* rename "mini libc" to "universal libc"
41 lines
939 B
Zig
41 lines
939 B
Zig
// absv - absolute oVerflow
|
|
// * @panic, if value can not be represented
|
|
// - absvXi4_generic for unoptimized version
|
|
|
|
inline fn absvXi(comptime ST: type, a: ST) ST {
|
|
const UT = switch (ST) {
|
|
i32 => u32,
|
|
i64 => u64,
|
|
i128 => u128,
|
|
else => unreachable,
|
|
};
|
|
// taken from Bit Twiddling Hacks
|
|
// compute the integer absolute value (abs) without branching
|
|
var x: ST = a;
|
|
const N: UT = @bitSizeOf(ST);
|
|
const sign: ST = a >> N - 1;
|
|
x +%= sign;
|
|
x ^= sign;
|
|
if (x < 0)
|
|
@panic("compiler_rt absv: overflow");
|
|
return x;
|
|
}
|
|
|
|
pub fn __absvsi2(a: i32) callconv(.C) i32 {
|
|
return absvXi(i32, a);
|
|
}
|
|
|
|
pub fn __absvdi2(a: i64) callconv(.C) i64 {
|
|
return absvXi(i64, a);
|
|
}
|
|
|
|
pub fn __absvti2(a: i128) callconv(.C) i128 {
|
|
return absvXi(i128, a);
|
|
}
|
|
|
|
test {
|
|
_ = @import("absvsi2_test.zig");
|
|
_ = @import("absvdi2_test.zig");
|
|
_ = @import("absvti2_test.zig");
|
|
}
|