diff options
| author | Michael Dusan <michael.dusan@gmail.com> | 2023-01-04 15:18:17 -0500 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2023-01-05 02:22:30 -0700 |
| commit | e0fb4c29cb618fe912c82fed06bb305db14606d8 (patch) | |
| tree | 8443bb64aaf65db00dc760c659c93754031fd824 /src | |
| parent | b89158d6fd7ce0960b3f8085368ae102b48747d0 (diff) | |
| download | zig-e0fb4c29cb618fe912c82fed06bb305db14606d8.tar.gz zig-e0fb4c29cb618fe912c82fed06bb305db14606d8.zip | |
llvm codegen: fix f16,f32,f64 nan bitcasts
@bitCast from integer NaN representation to float NaN resulted in
changed bits in float. This only happened with signaled NaN.
- added test for signaled NaN
- added tests for quiet NaN (for completeness)
closes #14198
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/llvm.zig | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/src/codegen/llvm.zig b/src/codegen/llvm.zig index a0db229796..39bb0dd94c 100644 --- a/src/codegen/llvm.zig +++ b/src/codegen/llvm.zig @@ -3287,15 +3287,24 @@ pub const DeclGen = struct { .Float => { const llvm_ty = try dg.lowerType(tv.ty); switch (tv.ty.floatBits(target)) { - 16 => if (intrinsicsAllowed(tv.ty, target)) { - return llvm_ty.constReal(tv.val.toFloat(f16)); - } else { + 16 => { const repr = @bitCast(u16, tv.val.toFloat(f16)); const llvm_i16 = dg.context.intType(16); const int = llvm_i16.constInt(repr, .False); return int.constBitCast(llvm_ty); }, - 32, 64 => return llvm_ty.constReal(tv.val.toFloat(f64)), + 32 => { + const repr = @bitCast(u32, tv.val.toFloat(f32)); + const llvm_i32 = dg.context.intType(32); + const int = llvm_i32.constInt(repr, .False); + return int.constBitCast(llvm_ty); + }, + 64 => { + const repr = @bitCast(u64, tv.val.toFloat(f64)); + const llvm_i64 = dg.context.intType(64); + const int = llvm_i64.constInt(repr, .False); + return int.constBitCast(llvm_ty); + }, 80 => { const float = tv.val.toFloat(f80); const repr = std.math.break_f80(float); |
