aboutsummaryrefslogtreecommitdiff
path: root/lib/std/special/compiler_rt/floattitf.zig
diff options
context:
space:
mode:
authorCody Tapscott <topolarity@tapscott.me>2022-04-08 18:54:53 -0700
committerCody Tapscott <topolarity@tapscott.me>2022-04-12 10:25:26 -0700
commitb5d5685a4e3a536999d3e69ce92cc786f052d4ec (patch)
tree22a2a956619df95d0165e62c7a53dbd466b2a841 /lib/std/special/compiler_rt/floattitf.zig
parent17631cb2d30bf2d7b10401cf8f784a599bade5c5 (diff)
downloadzig-b5d5685a4e3a536999d3e69ce92cc786f052d4ec.tar.gz
zig-b5d5685a4e3a536999d3e69ce92cc786f052d4ec.zip
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 |
Diffstat (limited to 'lib/std/special/compiler_rt/floattitf.zig')
-rw-r--r--lib/std/special/compiler_rt/floattitf.zig71
1 files changed, 0 insertions, 71 deletions
diff --git a/lib/std/special/compiler_rt/floattitf.zig b/lib/std/special/compiler_rt/floattitf.zig
deleted file mode 100644
index aa83f6686e..0000000000
--- a/lib/std/special/compiler_rt/floattitf.zig
+++ /dev/null
@@ -1,71 +0,0 @@
-const builtin = @import("builtin");
-const is_test = builtin.is_test;
-const std = @import("std");
-const maxInt = std.math.maxInt;
-
-const LDBL_MANT_DIG = 113;
-
-pub fn __floattitf(arg: i128) callconv(.C) f128 {
- @setRuntimeSafety(is_test);
-
- if (arg == 0)
- return 0.0;
-
- var ai = arg;
- const N: u32 = 128;
- const si = ai >> @intCast(u7, (N - 1));
- ai = ((ai ^ si) -% si);
- var a = @bitCast(u128, ai);
-
- const sd = @bitCast(i32, N - @clz(u128, a)); // number of significant digits
- var e: i32 = sd - 1; // exponent
- if (sd > LDBL_MANT_DIG) {
- // start: 0000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQxxxxxxxxxxxxxxxxxx
- // finish: 000000000000000000000000000000000000001xxxxxxxxxxxxxxxxxxxxxxPQR
- // 12345678901234567890123456
- // 1 = msb 1 bit
- // P = bit LDBL_MANT_DIG-1 bits to the right of 1
- // Q = bit LDBL_MANT_DIG bits to the right of 1
- // R = "or" of all bits to the right of Q
- switch (sd) {
- LDBL_MANT_DIG + 1 => {
- a <<= 1;
- },
- LDBL_MANT_DIG + 2 => {},
- else => {
- const shift1_amt = @intCast(i32, sd - (LDBL_MANT_DIG + 2));
- const shift1_amt_u7 = @intCast(u7, shift1_amt);
-
- const shift2_amt = @intCast(i32, N + (LDBL_MANT_DIG + 2)) - sd;
- const shift2_amt_u7 = @intCast(u7, shift2_amt);
-
- a = (a >> shift1_amt_u7) | @boolToInt((a & (@intCast(u128, maxInt(u128)) >> shift2_amt_u7)) != 0);
- },
- }
- // finish
- a |= @boolToInt((a & 4) != 0); // Or P into R
- a += 1; // round - this step may add a significant bit
- a >>= 2; // dump Q and R
- // a is now rounded to LDBL_MANT_DIG or LDBL_MANT_DIG+1 bits
- if ((a & (@as(u128, 1) << LDBL_MANT_DIG)) != 0) {
- a >>= 1;
- e += 1;
- }
- // a is now rounded to LDBL_MANT_DIG bits
- } else {
- a <<= @intCast(u7, LDBL_MANT_DIG - sd);
- // a is now rounded to LDBL_MANT_DIG bits
- }
-
- const s = @bitCast(u128, arg) >> (128 - 64);
- const high: u128 = (@intCast(u64, s) & 0x8000000000000000) | // sign
- (@intCast(u64, (e + 16383)) << 48) | // exponent
- (@truncate(u64, a >> 64) & 0x0000ffffffffffff); // mantissa-high
- const low = @truncate(u64, a); // mantissa-low
-
- return @bitCast(f128, low | (high << 64));
-}
-
-test {
- _ = @import("floattitf_test.zig");
-}