zig/lib/std/special/compiler_rt/sparc.zig
Cody Tapscott b5d5685a4e compiler_rt: Implement floatXiYf/fixXfYi, incl f80
This change:
 - Adds  generic implementation of the float -> integer conversion
   functions floatXiYf, including support for f80
 - Updates the existing implementation of integer -> float conversion
   fixXiYf to support f16 and f80
 - Fixes the handling of the explicit integer bit in `__trunctfxf2`
 - Combines the test cases for fixXfYi/floatXiYf into a single file
 - Renames `fmodl` to `fmodq`, since it operates on 128-bit floats

The new implementation for floatXiYf has been benchmarked, and generally
provides equal or better performance versus the current implementations:

Throughput (MiB/s) - Before
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |     none |     none |     none |     none |     none |     none |
 f32 |  2231.67 |  2001.19 |  1745.66 |  1405.77 |  2173.99 |  1874.63 |
 f64 |  1407.17 |  1055.83 |  2911.68 |  2437.21 |  1676.05 |  1476.67 |
 f80 |     none |     none |     none |     none |     none |     none |
f128 |   327.56 |   321.25 |   645.92 |   654.52 |  1153.56 |  1096.27 |

Throughput (MiB/s) - After
     |    u32   |    i32   |    u64   |    i64   |   u128   |   i128   |
-----|----------|----------|----------|----------|----------|----------|
 f16 |  1407.61 |  1637.25 |  3555.03 |  2594.56 |  3680.60 |  3063.34 |
 f32 |  2101.36 |  2122.62 |  3225.46 |  3123.86 |  2860.05 |  1985.21 |
 f64 |  1395.57 |  1314.87 |  2409.24 |  2196.30 |  2384.95 |  1908.15 |
 f80 |   475.53 |   457.92 |   884.50 |   812.12 |  1475.27 |  1382.16 |
f128 |   359.60 |   350.91 |   723.08 |   706.80 |  1296.42 |  1198.87 |
2022-04-12 10:25:26 -07:00

114 lines
3 KiB
Zig

//
// SPARC uses a different naming scheme for its support routines so we map it here to the x86 name.
const std = @import("std");
const builtin = @import("builtin");
// The SPARC Architecture Manual, Version 9:
// A.13 Floating-Point Compare
const FCMP = enum(i32) {
Equal = 0,
Less = 1,
Greater = 2,
Unordered = 3,
};
// Basic arithmetic
pub fn _Qp_add(c: *f128, a: *f128, b: *f128) callconv(.C) void {
c.* = @import("addXf3.zig").__addtf3(a.*, b.*);
}
pub fn _Qp_div(c: *f128, a: *f128, b: *f128) callconv(.C) void {
c.* = @import("divtf3.zig").__divtf3(a.*, b.*);
}
pub fn _Qp_mul(c: *f128, a: *f128, b: *f128) callconv(.C) void {
c.* = @import("mulXf3.zig").__multf3(a.*, b.*);
}
pub fn _Qp_sub(c: *f128, a: *f128, b: *f128) callconv(.C) void {
c.* = @import("addXf3.zig").__subtf3(a.*, b.*);
}
// Comparison
pub fn _Qp_cmp(a: *f128, b: *f128) callconv(.C) i32 {
return @enumToInt(@import("compareXf2.zig").cmp(f128, FCMP, a.*, b.*));
}
pub fn _Qp_feq(a: *f128, b: *f128) callconv(.C) bool {
return _Qp_cmp(a, b) == @enumToInt(FCMP.Equal);
}
pub fn _Qp_fne(a: *f128, b: *f128) callconv(.C) bool {
return _Qp_cmp(a, b) != @enumToInt(FCMP.Equal);
}
pub fn _Qp_flt(a: *f128, b: *f128) callconv(.C) bool {
return _Qp_cmp(a, b) == @enumToInt(FCMP.Less);
}
pub fn _Qp_fle(a: *f128, b: *f128) callconv(.C) bool {
const cmp = _Qp_cmp(a, b);
return cmp == @enumToInt(FCMP.Less) or cmp == @enumToInt(FCMP.Equal);
}
pub fn _Qp_fgt(a: *f128, b: *f128) callconv(.C) bool {
return _Qp_cmp(a, b) == @enumToInt(FCMP.Greater);
}
pub fn _Qp_fge(a: *f128, b: *f128) callconv(.C) bool {
const cmp = _Qp_cmp(a, b);
return cmp == @enumToInt(FCMP.Greater) or cmp == @enumToInt(FCMP.Equal);
}
// Conversion
pub fn _Qp_itoq(c: *f128, a: i32) callconv(.C) void {
c.* = @import("floatXiYf.zig").__floatsitf(a);
}
pub fn _Qp_uitoq(c: *f128, a: u32) callconv(.C) void {
c.* = @import("floatXiYf.zig").__floatunsitf(a);
}
pub fn _Qp_xtoq(c: *f128, a: i64) callconv(.C) void {
c.* = @import("floatXiYf.zig").__floatditf(a);
}
pub fn _Qp_uxtoq(c: *f128, a: u64) callconv(.C) void {
c.* = @import("floatXiYf.zig").__floatunditf(a);
}
pub fn _Qp_stoq(c: *f128, a: f32) callconv(.C) void {
c.* = @import("extendXfYf2.zig").__extendsftf2(a);
}
pub fn _Qp_dtoq(c: *f128, a: f64) callconv(.C) void {
c.* = @import("extendXfYf2.zig").__extenddftf2(a);
}
pub fn _Qp_qtoi(a: *f128) callconv(.C) i32 {
return @import("fixXfYi.zig").__fixtfsi(a.*);
}
pub fn _Qp_qtoui(a: *f128) callconv(.C) u32 {
return @import("fixXfYi.zig").__fixunstfsi(a.*);
}
pub fn _Qp_qtox(a: *f128) callconv(.C) i64 {
return @import("fixXfYi.zig").__fixtfdi(a.*);
}
pub fn _Qp_qtoux(a: *f128) callconv(.C) u64 {
return @import("fixXfYi.zig").__fixunstfdi(a.*);
}
pub fn _Qp_qtos(a: *f128) callconv(.C) f32 {
return @import("truncXfYf2.zig").__trunctfsf2(a.*);
}
pub fn _Qp_qtod(a: *f128) callconv(.C) f64 {
return @import("truncXfYf2.zig").__trunctfdf2(a.*);
}