zig

fork of https://codeberg.org/ziglang/zig
Log | Files | Refs | README | LICENSE

cmpdf2.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_dcmpeq, .{ .name = "__aeabi_dcmpeq", .linkage = common.linkage, .visibility = common.visibility });
     11         @export(&__aeabi_dcmplt, .{ .name = "__aeabi_dcmplt", .linkage = common.linkage, .visibility = common.visibility });
     12         @export(&__aeabi_dcmple, .{ .name = "__aeabi_dcmple", .linkage = common.linkage, .visibility = common.visibility });
     13     } else {
     14         @export(&__eqdf2, .{ .name = "__eqdf2", .linkage = common.linkage, .visibility = common.visibility });
     15         @export(&__nedf2, .{ .name = "__nedf2", .linkage = common.linkage, .visibility = common.visibility });
     16         @export(&__ledf2, .{ .name = "__ledf2", .linkage = common.linkage, .visibility = common.visibility });
     17         @export(&__cmpdf2, .{ .name = "__cmpdf2", .linkage = common.linkage, .visibility = common.visibility });
     18         @export(&__ltdf2, .{ .name = "__ltdf2", .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 `__ledf2`, `__eqdf2`, `__nedf2`, `__cmpdf2`,
     27 /// and `__ltdf2`.
     28 fn __cmpdf2(a: f64, b: f64) callconv(.c) i32 {
     29     return @intFromEnum(comparef.cmpf2(f64, 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 __ledf2(a: f64, b: f64) callconv(.c) i32 {
     35     return __cmpdf2(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, __eqdf2 and __nedf2 are defined
     40 /// to have the same return value.
     41 pub fn __eqdf2(a: f64, b: f64) callconv(.c) i32 {
     42     return __cmpdf2(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, __eqdf2 and __nedf2 are defined
     47 /// to have the same return value.
     48 pub fn __nedf2(a: f64, b: f64) callconv(.c) i32 {
     49     return __cmpdf2(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 __ltdf2(a: f64, b: f64) callconv(.c) i32 {
     55     return __cmpdf2(a, b);
     56 }
     57 
     58 fn __aeabi_dcmpeq(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
     59     return @intFromBool(comparef.cmpf2(f64, comparef.LE, a, b) == .Equal);
     60 }
     61 
     62 fn __aeabi_dcmplt(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
     63     return @intFromBool(comparef.cmpf2(f64, comparef.LE, a, b) == .Less);
     64 }
     65 
     66 fn __aeabi_dcmple(a: f64, b: f64) callconv(.{ .arm_aapcs = .{} }) i32 {
     67     return @intFromBool(comparef.cmpf2(f64, comparef.LE, a, b) != .Greater);
     68 }