zig/lib/compiler_rt/negXi2.zig
Andrew Kelley 0556a2ba53 compiler-rt: finish cleanups
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.
2022-06-17 18:10:00 -07:00

42 lines
1.0 KiB
Zig

//! neg - negate (the number)
//! - negXi2 for unoptimized little and big endian
//! sfffffff = 2^31-1
//! two's complement inverting bits and add 1 would result in -INT_MIN == 0
//! => -INT_MIN = -2^31 forbidden
//! * size optimized builds
//! * machines that dont support carry operations
const std = @import("std");
const builtin = @import("builtin");
const common = @import("common.zig");
pub const panic = common.panic;
comptime {
@export(__negsi2, .{ .name = "__negsi2", .linkage = common.linkage });
@export(__negdi2, .{ .name = "__negdi2", .linkage = common.linkage });
@export(__negti2, .{ .name = "__negti2", .linkage = common.linkage });
}
pub fn __negsi2(a: i32) callconv(.C) i32 {
return negXi2(i32, a);
}
pub fn __negdi2(a: i64) callconv(.C) i64 {
return negXi2(i64, a);
}
pub fn __negti2(a: i128) callconv(.C) i128 {
return negXi2(i128, a);
}
inline fn negXi2(comptime T: type, a: T) T {
return -a;
}
test {
_ = @import("negsi2_test.zig");
_ = @import("negdi2_test.zig");
_ = @import("negti2_test.zig");
}