diff options
| author | Jacob Young <jacobly0@users.noreply.github.com> | 2024-02-22 23:51:35 +0100 |
|---|---|---|
| committer | Jacob Young <jacobly0@users.noreply.github.com> | 2024-02-22 23:51:53 +0100 |
| commit | dbfa3238fefee0c802fceb39c8605a0b21659bd3 (patch) | |
| tree | 7675a3d354c42e548041e058fbd545698089086c /src/codegen | |
| parent | 83e66d301eede71800a9b5d72010ce63dbbac3fc (diff) | |
| download | zig-dbfa3238fefee0c802fceb39c8605a0b21659bd3.tar.gz zig-dbfa3238fefee0c802fceb39c8605a0b21659bd3.zip | |
Builder: fix float constants in llvm ir
Diffstat (limited to 'src/codegen')
| -rw-r--r-- | src/codegen/llvm/Builder.zig | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/codegen/llvm/Builder.zig b/src/codegen/llvm/Builder.zig index f76d528dcf..428330dc99 100644 --- a/src/codegen/llvm/Builder.zig +++ b/src/codegen/llvm/Builder.zig @@ -7220,17 +7220,31 @@ pub const Constant = enum(u32) { }; } }; + const Mantissa64 = std.meta.FieldType(Float.Repr(f64), .mantissa); const Exponent32 = std.meta.FieldType(Float.Repr(f32), .exponent); const Exponent64 = std.meta.FieldType(Float.Repr(f64), .exponent); + const repr: Float.Repr(f32) = @bitCast(item.data); + const denormal_shift = switch (repr.exponent) { + std.math.minInt(Exponent32) => @as( + std.math.Log2Int(Mantissa64), + @clz(repr.mantissa), + ) + 1, + else => 0, + }; try writer.print("0x{X:0>16}", .{@as(u64, @bitCast(Float.Repr(f64){ .mantissa = std.math.shl( - std.meta.FieldType(Float.Repr(f64), .mantissa), + Mantissa64, repr.mantissa, - std.math.floatMantissaBits(f64) - std.math.floatMantissaBits(f32), + std.math.floatMantissaBits(f64) - std.math.floatMantissaBits(f32) + + denormal_shift, ), .exponent = switch (repr.exponent) { - std.math.minInt(Exponent32) => std.math.minInt(Exponent64), + std.math.minInt(Exponent32) => if (repr.mantissa > 0) + @as(Exponent64, std.math.floatExponentMin(f32) + + std.math.floatExponentMax(f64)) - denormal_shift + else + std.math.minInt(Exponent64), else => @as(Exponent64, repr.exponent) + (std.math.floatExponentMax(f64) - std.math.floatExponentMax(f32)), std.math.maxInt(Exponent32) => std.math.maxInt(Exponent64), @@ -9920,7 +9934,7 @@ pub fn printUnbuffered( .scope = extra.file, .file = extra.file, .line = extra.line, - .type = null, + .type = extra.ty, .scopeLine = extra.scope_line, .containingType = null, .virtualIndex = null, |
