diff options
| author | gingerBill <gingerBill@users.noreply.github.com> | 2024-03-29 22:13:58 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2024-03-29 22:13:58 +0000 |
| commit | d84d65ba450efbd8d39469da868c973e355339f0 (patch) | |
| tree | ae123a5882c7bc5fbfe3384c9a7914a03ed1ad8b /src | |
| parent | 28fb1ba83d14dd3804a7323d3d6287f8bfd91358 (diff) | |
| parent | e1b545860f06f31f073c7142e3df8a2c1177776b (diff) | |
Merge pull request #3348 from rick-masters/fix_convert_smaller_float_endian
Implement endian conversions for smaller float types.
Diffstat (limited to 'src')
| -rw-r--r-- | src/llvm_backend_const.cpp | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/llvm_backend_const.cpp b/src/llvm_backend_const.cpp index bbb0b8387..1ca5f4965 100644 --- a/src/llvm_backend_const.cpp +++ b/src/llvm_backend_const.cpp @@ -730,9 +730,21 @@ gb_internal lbValue lb_const_value(lbModule *m, Type *type, ExactValue value, bo return res; case ExactValue_Float: if (is_type_different_to_arch_endianness(type)) { - u64 u = bit_cast<u64>(value.value_float); - u = gb_endian_swap64(u); - res.value = LLVMConstReal(lb_type(m, original_type), bit_cast<f64>(u)); + if (type->Basic.kind == Basic_f32le || type->Basic.kind == Basic_f32be) { + f32 f = static_cast<float>(value.value_float); + u32 u = bit_cast<u32>(f); + u = gb_endian_swap32(u); + res.value = LLVMConstReal(lb_type(m, original_type), bit_cast<f32>(u)); + } else if (type->Basic.kind == Basic_f16le || type->Basic.kind == Basic_f16be) { + f32 f = static_cast<float>(value.value_float); + u16 u = f32_to_f16(f); + u = gb_endian_swap16(u); + res.value = LLVMConstReal(lb_type(m, original_type), f16_to_f32(u)); + } else { + u64 u = bit_cast<u64>(value.value_float); + u = gb_endian_swap64(u); + res.value = LLVMConstReal(lb_type(m, original_type), bit_cast<f64>(u)); + } } else { res.value = LLVMConstReal(lb_type(m, original_type), value.value_float); } |