diff options
| author | gingerBill <bill@gingerbill.org> | 2021-03-27 14:33:33 +0000 |
|---|---|---|
| committer | gingerBill <bill@gingerbill.org> | 2021-03-27 14:33:33 +0000 |
| commit | e21d7167200c76ff250db3308f1804b3314267c9 (patch) | |
| tree | 959b9553a17db3fc663117d05f36ca70c0e07a1b /src/llvm_backend.cpp | |
| parent | d62ff39e60401a42774510a8375a4e0a003325db (diff) | |
Fix endian conversion to and from floats and ints
Diffstat (limited to 'src/llvm_backend.cpp')
| -rw-r--r-- | src/llvm_backend.cpp | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp index a763a10ba..94832c4cd 100644 --- a/src/llvm_backend.cpp +++ b/src/llvm_backend.cpp @@ -7066,6 +7066,18 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { // float <-> integer if (is_type_float(src) && is_type_integer(dst)) { + if (is_type_different_to_arch_endianness(src) || is_type_different_to_arch_endianness(dst)) { + Type *platform_src_type = integer_endian_type_to_platform_type(src); + Type *platform_dst_type = integer_endian_type_to_platform_type(dst); + lbValue res = {}; + res = lb_emit_conv(p, value, platform_src_type); + res = lb_emit_conv(p, res, platform_dst_type); + if (is_type_different_to_arch_endianness(dst)) { + res = lb_emit_byte_swap(p, res, t); + } + return lb_emit_conv(p, res, t); + } + lbValue res = {}; res.type = t; if (is_type_unsigned(dst)) { @@ -7076,6 +7088,18 @@ lbValue lb_emit_conv(lbProcedure *p, lbValue value, Type *t) { return res; } if (is_type_integer(src) && is_type_float(dst)) { + if (is_type_different_to_arch_endianness(src) || is_type_different_to_arch_endianness(dst)) { + Type *platform_src_type = integer_endian_type_to_platform_type(src); + Type *platform_dst_type = integer_endian_type_to_platform_type(dst); + lbValue res = {}; + res = lb_emit_conv(p, value, platform_src_type); + res = lb_emit_conv(p, res, platform_dst_type); + if (is_type_different_to_arch_endianness(dst)) { + res = lb_emit_byte_swap(p, res, t); + } + return lb_emit_conv(p, res, t); + } + lbValue res = {}; res.type = t; if (is_type_unsigned(src)) { |