authorgravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-27 20:10:59+01:00
committergravatar for thatlemon@gmail.comLemonBoy <thatlemon@gmail.com> 2020-03-27 20:10:59+01:00
log0512be227c76ade696de07929f30367468b91c19
tree6092c10da7deb275ab2bcd6bc60c1a5d3b8c3b2c
parentaec4967f36d16cfee43529bd341300f5f77af34a

compiler-rt: Fix __floatunditf

This builtin converts a u64 into a f128, not a u128 into a f128. Fixes some weird-ass crashes that happened only on AArch64 systems.

2 files changed, 6 insertions(+), 6 deletions(-)

lib/std/special/compiler_rt/floatunditf.zig+5-5
...@@ -2,7 +2,7 @@ const builtin = @import("builtin");...@@ -2,7 +2,7 @@ const builtin = @import("builtin");
2const is_test = builtin.is_test;2const is_test = builtin.is_test;
3const std = @import("std");3const std = @import("std");
44
5pub fn __floatunditf(a: u128) callconv(.C) f128 {5pub fn __floatunditf(a: u64) callconv(.C) f128 {
6 @setRuntimeSafety(is_test);6 @setRuntimeSafety(is_test);
77
8 if (a == 0) {8 if (a == 0) {
...@@ -14,11 +14,11 @@ pub fn __floatunditf(a: u128) callconv(.C) f128 {...@@ -14,11 +14,11 @@ pub fn __floatunditf(a: u128) callconv(.C) f128 {
14 const exponent_bias = (1 << (exponent_bits - 1)) - 1;14 const exponent_bias = (1 << (exponent_bits - 1)) - 1;
15 const implicit_bit = 1 << mantissa_bits;15 const implicit_bit = 1 << mantissa_bits;
1616
17 const exp = (u128.bit_count - 1) - @clz(u128, a);17 const exp: u128 = (u64.bit_count - 1) - @clz(u64, a);
18 const shift = mantissa_bits - @intCast(u7, exp);18 const shift: u7 = mantissa_bits - @intCast(u7, exp);
1919
20 var result: u128 align(16) = (a << shift) ^ implicit_bit;20 var result: u128 = (@intCast(u128, a) << shift) ^ implicit_bit;
21 result += (@intCast(u128, exp) + exponent_bias) << mantissa_bits;21 result += (exp + exponent_bias) << mantissa_bits;
2222
23 return @bitCast(f128, result);23 return @bitCast(f128, result);
24}24}
lib/std/special/compiler_rt/floatunditf_test.zig+1-1
...@@ -1,6 +1,6 @@...@@ -1,6 +1,6 @@
1const __floatunditf = @import("floatunditf.zig").__floatunditf;1const __floatunditf = @import("floatunditf.zig").__floatunditf;
22
3fn test__floatunditf(a: u128, expected_hi: u64, expected_lo: u64) void {3fn test__floatunditf(a: u64, expected_hi: u64, expected_lo: u64) void {
4 const x = __floatunditf(a);4 const x = __floatunditf(a);
55
6 const x_repr = @bitCast(u128, x);6 const x_repr = @bitCast(u128, x);