aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorrick-masters <grick23@gmail.com>2024-03-29 11:05:27 +0000
committerrick-masters <grick23@gmail.com>2024-03-29 11:05:27 +0000
commite1b545860f06f31f073c7142e3df8a2c1177776b (patch)
treeab89f00ce7509400e8159249c6155b171cb15cc0 /src
parent8899f42478a7735e81cd25cc9c6c81ce18f79df1 (diff)
Implement endian conversions for smaller float types.
Diffstat (limited to 'src')
-rw-r--r--src/llvm_backend_const.cpp18
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);
}