compiler_rt: add __cmpXi2 and __ucmpXi2
- adds __cmpsi2, __cmpdi2, __cmpti2
- adds __ucmpsi2, __ucmpdi2, __ucmpti2
- use 2 if statements with 2 temporaries and a constant
- tests: MIN, MIN+1, MIN/2, -1, 0, 1, MAX/2, MAX-1, MAX if applicable
See #1290
2021-12-12 20:19:25 +00:00
|
|
|
const std = @import("std");
|
|
|
|
const builtin = @import("builtin");
|
2022-06-10 09:25:59 +01:00
|
|
|
const is_test = builtin.is_test;
|
2022-06-18 02:10:00 +01:00
|
|
|
const common = @import("common.zig");
|
|
|
|
|
|
|
|
pub const panic = common.panic;
|
2022-06-10 09:25:59 +01:00
|
|
|
|
|
|
|
comptime {
|
2022-12-28 13:57:17 +00:00
|
|
|
@export(__cmpsi2, .{ .name = "__cmpsi2", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__cmpdi2, .{ .name = "__cmpdi2", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__cmpti2, .{ .name = "__cmpti2", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__ucmpsi2, .{ .name = "__ucmpsi2", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__ucmpdi2, .{ .name = "__ucmpdi2", .linkage = common.linkage, .visibility = common.visibility });
|
|
|
|
@export(__ucmpti2, .{ .name = "__ucmpti2", .linkage = common.linkage, .visibility = common.visibility });
|
2022-06-10 09:25:59 +01:00
|
|
|
}
|
compiler_rt: add __cmpXi2 and __ucmpXi2
- adds __cmpsi2, __cmpdi2, __cmpti2
- adds __ucmpsi2, __ucmpdi2, __ucmpti2
- use 2 if statements with 2 temporaries and a constant
- tests: MIN, MIN+1, MIN/2, -1, 0, 1, MAX/2, MAX-1, MAX if applicable
See #1290
2021-12-12 20:19:25 +00:00
|
|
|
|
|
|
|
// cmp - signed compare
|
|
|
|
// - cmpXi2_generic for unoptimized little and big endian
|
|
|
|
|
|
|
|
// ucmp - unsigned compare
|
|
|
|
// - ucmpXi2_generic for unoptimized little and big endian
|
|
|
|
|
|
|
|
// a < b => 0
|
|
|
|
// a == b => 1
|
|
|
|
// a > b => 2
|
|
|
|
|
2022-01-02 02:49:34 +00:00
|
|
|
inline fn XcmpXi2(comptime T: type, a: T, b: T) i32 {
|
|
|
|
var cmp1: i32 = 0;
|
|
|
|
var cmp2: i32 = 0;
|
|
|
|
if (a > b)
|
|
|
|
cmp1 = 1;
|
|
|
|
if (a < b)
|
|
|
|
cmp2 = 1;
|
|
|
|
return cmp1 - cmp2 + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __cmpsi2(a: i32, b: i32) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(i32, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __cmpdi2(a: i64, b: i64) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(i64, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __cmpti2(a: i128, b: i128) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(i128, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __ucmpsi2(a: u32, b: u32) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(u32, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __ucmpdi2(a: u64, b: u64) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(u64, a, b);
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn __ucmpti2(a: u128, b: u128) callconv(.C) i32 {
|
|
|
|
return XcmpXi2(u128, a, b);
|
|
|
|
}
|
compiler_rt: add __cmpXi2 and __ucmpXi2
- adds __cmpsi2, __cmpdi2, __cmpti2
- adds __ucmpsi2, __ucmpdi2, __ucmpti2
- use 2 if statements with 2 temporaries and a constant
- tests: MIN, MIN+1, MIN/2, -1, 0, 1, MAX/2, MAX-1, MAX if applicable
See #1290
2021-12-12 20:19:25 +00:00
|
|
|
|
|
|
|
test {
|
|
|
|
_ = @import("cmpsi2_test.zig");
|
|
|
|
_ = @import("cmpdi2_test.zig");
|
|
|
|
_ = @import("cmpti2_test.zig");
|
|
|
|
|
|
|
|
_ = @import("ucmpsi2_test.zig");
|
|
|
|
_ = @import("ucmpdi2_test.zig");
|
|
|
|
_ = @import("ucmpti2_test.zig");
|
|
|
|
}
|