zig/lib/compiler_rt/fmodq_test.zig

53 lines
2.0 KiB
Zig
Raw Normal View History

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-09 02:54:53 +01:00
const std = @import("std");
const fmod = @import("fmod.zig");
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-09 02:54:53 +01:00
const testing = std.testing;
fn test_fmodq(a: f128, b: f128, exp: f128) !void {
const res = fmod.fmodq(a, b);
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-09 02:54:53 +01:00
try testing.expect(exp == res);
}
fn test_fmodq_nans() !void {
try testing.expect(std.math.isNan(fmod.fmodq(1.0, std.math.nan(f128))));
try testing.expect(std.math.isNan(fmod.fmodq(1.0, -std.math.nan(f128))));
try testing.expect(std.math.isNan(fmod.fmodq(std.math.nan(f128), 1.0)));
try testing.expect(std.math.isNan(fmod.fmodq(-std.math.nan(f128), 1.0)));
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-09 02:54:53 +01:00
}
fn test_fmodq_infs() !void {
try testing.expect(fmod.fmodq(1.0, std.math.inf(f128)) == 1.0);
try testing.expect(fmod.fmodq(1.0, -std.math.inf(f128)) == 1.0);
try testing.expect(std.math.isNan(fmod.fmodq(std.math.inf(f128), 1.0)));
try testing.expect(std.math.isNan(fmod.fmodq(-std.math.inf(f128), 1.0)));
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-09 02:54:53 +01:00
}
test "fmodq" {
try test_fmodq(6.8, 4.0, 2.8);
try test_fmodq(6.8, -4.0, 2.8);
try test_fmodq(-6.8, 4.0, -2.8);
try test_fmodq(-6.8, -4.0, -2.8);
try test_fmodq(3.0, 2.0, 1.0);
try test_fmodq(-5.0, 3.0, -2.0);
try test_fmodq(3.0, 2.0, 1.0);
try test_fmodq(1.0, 2.0, 1.0);
try test_fmodq(0.0, 1.0, 0.0);
try test_fmodq(-0.0, 1.0, -0.0);
try test_fmodq(7046119.0, 5558362.0, 1487757.0);
try test_fmodq(9010357.0, 1957236.0, 1181413.0);
2022-04-25 21:25:15 +01:00
try test_fmodq(5192296858534827628530496329220095, 10.0, 5.0);
try test_fmodq(5192296858534827628530496329220095, 922337203681230954775807, 220474884073715748246157);
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-09 02:54:53 +01:00
// Denormals
2022-04-25 21:25:15 +01:00
const a1: f128 = 0xedcb34a235253948765432134674p-16494;
const b1: f128 = 0x5d2e38791cfbc0737402da5a9518p-16494;
const exp1: f128 = 0x336ec3affb2db8618e4e7d5e1c44p-16494;
try test_fmodq(a1, b1, exp1);
const a2: f128 = 0x0.7654_3210_fdec_ba98_7654_3210_fdecp-16382;
const b2: f128 = 0x0.0012_fdac_bdef_1234_fdec_3222_1111p-16382;
const exp2: f128 = 0x0.0001_aecd_9d66_4a6e_67b7_d7d0_a901p-16382;
try test_fmodq(a2, b2, exp2);
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-09 02:54:53 +01:00
try test_fmodq_nans();
try test_fmodq_infs();
}