negXi2.zig (1171B) - Raw
1 //! neg - negate (the number) 2 //! - negXi2 for unoptimized little and big endian 3 //! sfffffff = 2^31-1 4 //! two's complement inverting bits and add 1 would result in -INT_MIN == 0 5 //! => -INT_MIN = -2^31 forbidden 6 //! * size optimized builds 7 //! * machines that dont support carry operations 8 9 const std = @import("std"); 10 const builtin = @import("builtin"); 11 const common = @import("common.zig"); 12 13 pub const panic = common.panic; 14 15 comptime { 16 @export(&__negsi2, .{ .name = "__negsi2", .linkage = common.linkage, .visibility = common.visibility }); 17 @export(&__negdi2, .{ .name = "__negdi2", .linkage = common.linkage, .visibility = common.visibility }); 18 @export(&__negti2, .{ .name = "__negti2", .linkage = common.linkage, .visibility = common.visibility }); 19 } 20 21 pub fn __negsi2(a: i32) callconv(.c) i32 { 22 return negXi2(i32, a); 23 } 24 25 pub fn __negdi2(a: i64) callconv(.c) i64 { 26 return negXi2(i64, a); 27 } 28 29 pub fn __negti2(a: i128) callconv(.c) i128 { 30 return negXi2(i128, a); 31 } 32 33 inline fn negXi2(comptime T: type, a: T) T { 34 return -a; 35 } 36 37 test { 38 _ = @import("negsi2_test.zig"); 39 _ = @import("negdi2_test.zig"); 40 _ = @import("negti2_test.zig"); 41 }