Commit 4ab7b459df

LemonBoy <thatlemon@gmail.com>
2019-05-06 21:48:10
Avoid endless recursion in __extendhfsf2
On some platforms the conversion ended up creating a dangerous recursive loop that ate all the stack. The conversion to f16 is also pointless since we're operating on the raw bits anyway.
1 parent 94b504c
Changed files (1)
std
special
compiler_rt
std/special/compiler_rt/extendXfYf2.zig
@@ -3,20 +3,20 @@ const builtin = @import("builtin");
 const is_test = builtin.is_test;
 
 pub extern fn __extenddftf2(a: f64) f128 {
-    return extendXfYf2(f128, f64, a);
+    return extendXfYf2(f128, f64, @bitCast(u64, a));
 }
 
 pub extern fn __extendsftf2(a: f32) f128 {
-    return extendXfYf2(f128, f32, a);
+    return extendXfYf2(f128, f32, @bitCast(u32, a));
 }
 
 pub extern fn __extendhfsf2(a: u16) f32 {
-    return extendXfYf2(f32, f16, @bitCast(f16, a));
+    return extendXfYf2(f32, f16, a);
 }
 
 const CHAR_BIT = 8;
 
-inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: src_t) dst_t {
+inline fn extendXfYf2(comptime dst_t: type, comptime src_t: type, a: @IntType(false, @typeInfo(src_t).Float.bits)) dst_t {
     const src_rep_t = @IntType(false, @typeInfo(src_t).Float.bits);
     const dst_rep_t = @IntType(false, @typeInfo(dst_t).Float.bits);
     const srcSigBits = std.math.floatMantissaBits(src_t);