aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2021-07-13 18:15:47 +0100
committergingerBill <bill@gingerbill.org>2021-07-13 18:15:47 +0100
commitda9870c77d539be7571c14cfb7176120b398ed84 (patch)
tree42e5066bbf4e47cecb74a6525cc9b66f6829cc11 /src/llvm_backend.cpp
parent698eeaf7c3f0884ff743169d9cb980bb5d53c59a (diff)
Do manual byte swapping for endianness in `lb_big_int_to_llvm`
Diffstat (limited to 'src/llvm_backend.cpp')
-rw-r--r--src/llvm_backend.cpp17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/llvm_backend.cpp b/src/llvm_backend.cpp
index d04344c1f..c9eaadfda 100644
--- a/src/llvm_backend.cpp
+++ b/src/llvm_backend.cpp
@@ -6373,11 +6373,6 @@ LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *
size_t size = 1;
size_t nails = 0;
mp_endian endian = MP_NATIVE_ENDIAN;
- if (is_type_endian_little(original_type)) {
- endian = MP_LITTLE_ENDIAN;
- } else if (is_type_endian_big(original_type)) {
- endian = MP_BIG_ENDIAN;
- }
max_count = mp_pack_count(a, nails, size);
rop = cast(u8 *)gb_alloc_align(permanent_allocator(), max_count, gb_align_of(u64));
@@ -6387,6 +6382,18 @@ LLVMValueRef lb_big_int_to_llvm(lbModule *m, Type *original_type, BigInt const *
a);
GB_ASSERT(err == MP_OKAY);
+ i64 sz = type_size_of(original_type);
+ if (is_type_different_to_arch_endianness(original_type)) {
+ GB_ASSERT(sz == cast(i64)written);
+ for (i64 i = 0; i < sz/2; i++) {
+ u8 tmp = rop[i];
+ rop[i] = rop[sz-1-i];
+ rop[sz-1-i] = tmp;
+ }
+ }
+
+
+
LLVMValueRef value = LLVMConstIntOfArbitraryPrecision(lb_type(m, original_type), cast(unsigned)((written+7)/8), cast(u64 *)rop);
if (big_int_is_neg(a)) {
value = LLVMConstNeg(value);