mirror of
https://github.com/ziglang/zig.git
synced 2024-11-27 23:52:31 +00:00
0556a2ba53
Finishes cleanups that I started in other commits in this branch. * Use common.linkage for all exports instead of redoing the logic in each file. * Remove pointless `@setRuntimeSafety` calls. * Avoid redundantly exporting multiple versions of functions. For example, if PPC wants `ceilf128` then don't also export `ceilq`; similarly if ARM wants `__aeabi_ddiv` then don't also export `__divdf3`. * Use `inline` for helper functions instead of making inline calls at callsites.
47 lines
1.2 KiB
Zig
47 lines
1.2 KiB
Zig
//! negv - negate oVerflow
|
|
//! * @panic, if result can not be represented
|
|
//! - negvXi4_generic for unoptimized version
|
|
const std = @import("std");
|
|
const builtin = @import("builtin");
|
|
const common = @import("common.zig");
|
|
|
|
pub const panic = common.panic;
|
|
|
|
comptime {
|
|
@export(__negvsi2, .{ .name = "__negvsi2", .linkage = common.linkage });
|
|
@export(__negvdi2, .{ .name = "__negvdi2", .linkage = common.linkage });
|
|
@export(__negvti2, .{ .name = "__negvti2", .linkage = common.linkage });
|
|
}
|
|
|
|
pub fn __negvsi2(a: i32) callconv(.C) i32 {
|
|
return negvXi(i32, a);
|
|
}
|
|
|
|
pub fn __negvdi2(a: i64) callconv(.C) i64 {
|
|
return negvXi(i64, a);
|
|
}
|
|
|
|
pub fn __negvti2(a: i128) callconv(.C) i128 {
|
|
return negvXi(i128, a);
|
|
}
|
|
|
|
inline fn negvXi(comptime ST: type, a: ST) ST {
|
|
const UT = switch (ST) {
|
|
i32 => u32,
|
|
i64 => u64,
|
|
i128 => u128,
|
|
else => unreachable,
|
|
};
|
|
const N: UT = @bitSizeOf(ST);
|
|
const min: ST = @bitCast(ST, (@as(UT, 1) << (N - 1)));
|
|
if (a == min)
|
|
@panic("compiler_rt negv: overflow");
|
|
return -a;
|
|
}
|
|
|
|
test {
|
|
_ = @import("negvsi2_test.zig");
|
|
_ = @import("negvdi2_test.zig");
|
|
_ = @import("negvti2_test.zig");
|
|
}
|