cmpsf2.zig (3161B) - Raw
1 ///! The quoted behavior definitions are from 2 ///! https://gcc.gnu.org/onlinedocs/gcc-12.1.0/gccint/Soft-float-library-routines.html#Soft-float-library-routines 3 const common = @import("./common.zig"); 4 const comparef = @import("./comparef.zig"); 5 6 pub const panic = common.panic; 7 8 comptime { 9 if (common.want_aeabi) { 10 @export(&__aeabi_fcmpeq, .{ .name = "__aeabi_fcmpeq", .linkage = common.linkage, .visibility = common.visibility }); 11 @export(&__aeabi_fcmplt, .{ .name = "__aeabi_fcmplt", .linkage = common.linkage, .visibility = common.visibility }); 12 @export(&__aeabi_fcmple, .{ .name = "__aeabi_fcmple", .linkage = common.linkage, .visibility = common.visibility }); 13 } else { 14 @export(&__eqsf2, .{ .name = "__eqsf2", .linkage = common.linkage, .visibility = common.visibility }); 15 @export(&__nesf2, .{ .name = "__nesf2", .linkage = common.linkage, .visibility = common.visibility }); 16 @export(&__lesf2, .{ .name = "__lesf2", .linkage = common.linkage, .visibility = common.visibility }); 17 @export(&__cmpsf2, .{ .name = "__cmpsf2", .linkage = common.linkage, .visibility = common.visibility }); 18 @export(&__ltsf2, .{ .name = "__ltsf2", .linkage = common.linkage, .visibility = common.visibility }); 19 } 20 } 21 22 /// "These functions calculate a <=> b. That is, if a is less than b, they return -1; 23 /// if a is greater than b, they return 1; and if a and b are equal they return 0. 24 /// If either argument is NaN they return 1..." 25 /// 26 /// Note that this matches the definition of `__lesf2`, `__eqsf2`, `__nesf2`, `__cmpsf2`, 27 /// and `__ltsf2`. 28 fn __cmpsf2(a: f32, b: f32) callconv(.c) i32 { 29 return @intFromEnum(comparef.cmpf2(f32, comparef.LE, a, b)); 30 } 31 32 /// "These functions return a value less than or equal to zero if neither argument is NaN, 33 /// and a is less than or equal to b." 34 pub fn __lesf2(a: f32, b: f32) callconv(.c) i32 { 35 return __cmpsf2(a, b); 36 } 37 38 /// "These functions return zero if neither argument is NaN, and a and b are equal." 39 /// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined 40 /// to have the same return value. 41 pub fn __eqsf2(a: f32, b: f32) callconv(.c) i32 { 42 return __cmpsf2(a, b); 43 } 44 45 /// "These functions return a nonzero value if either argument is NaN, or if a and b are unequal." 46 /// Note that due to some kind of historical accident, __eqsf2 and __nesf2 are defined 47 /// to have the same return value. 48 pub fn __nesf2(a: f32, b: f32) callconv(.c) i32 { 49 return __cmpsf2(a, b); 50 } 51 52 /// "These functions return a value less than zero if neither argument is NaN, and a 53 /// is strictly less than b." 54 pub fn __ltsf2(a: f32, b: f32) callconv(.c) i32 { 55 return __cmpsf2(a, b); 56 } 57 58 fn __aeabi_fcmpeq(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { 59 return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) == .Equal); 60 } 61 62 fn __aeabi_fcmplt(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { 63 return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) == .Less); 64 } 65 66 fn __aeabi_fcmple(a: f32, b: f32) callconv(.{ .arm_aapcs = .{} }) i32 { 67 return @intFromBool(comparef.cmpf2(f32, comparef.LE, a, b) != .Greater); 68 }