authorgravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2020-12-30 18:08:45+07:00
committergravatar for koachan@protonmail.comKoakuma <koachan@protonmail.com> 2021-01-15 19:07:38+07:00
logb531caac0265bcdecd1e043d43a36e41ed81b622
tree2c05c3a82a1457dd1c270100b2a27b21bda12eca
parentbbb58b10f6c0f7ce01fc61e8f64b69dd91d638dc

Fix f128 codegen on BE hosts


1 files changed, 15 insertions(+), 5 deletions(-)

src/stage1/codegen.cpp+15-5
...@@ -19,6 +19,7 @@...@@ -19,6 +19,7 @@
19#include "stage2.h"19#include "stage2.h"
20#include "dump_analysis.hpp"20#include "dump_analysis.hpp"
21#include "softfloat.hpp"21#include "softfloat.hpp"
22#include "zigendian.h"
2223
23#include <stdio.h>24#include <stdio.h>
24#include <errno.h>25#include <errno.h>
...@@ -7421,11 +7422,20 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n...@@ -7421,11 +7422,20 @@ static LLVMValueRef gen_const_val(CodeGen *g, ZigValue *const_val, const char *n
7421 return LLVMConstReal(get_llvm_type(g, type_entry), const_val->data.x_f64);7422 return LLVMConstReal(get_llvm_type(g, type_entry), const_val->data.x_f64);
7422 case 128:7423 case 128:
7423 {7424 {
7424 // TODO make sure this is correct on big endian targets too7425 uint64_t buf[2];
7425 uint8_t buf[16];7426
7426 memcpy(buf, &const_val->data.x_f128, 16);7427 // LLVM seems to require that the lower half of the f128 be placed first in the buffer.
7427 LLVMValueRef as_int = LLVMConstIntOfArbitraryPrecision(LLVMInt128Type(), 2,7428 #if defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_LITTLE_ENDIAN
7428 (uint64_t*)buf);7429 buf[0] = const_val->data.x_f128.v[0];
7430 buf[1] = const_val->data.x_f128.v[1];
7431 #elif defined(ZIG_BYTE_ORDER) && ZIG_BYTE_ORDER == ZIG_BIG_ENDIAN
7432 buf[0] = const_val->data.x_f128.v[1];
7433 buf[1] = const_val->data.x_f128.v[0];
7434 #else
7435 #error Unsupported endian
7436 #endif
7437
7438 LLVMValueRef as_int = LLVMConstIntOfArbitraryPrecision(LLVMInt128Type(), 2, buf);
7429 return LLVMConstBitCast(as_int, get_llvm_type(g, type_entry));7439 return LLVMConstBitCast(as_int, get_llvm_type(g, type_entry));
7430 }7440 }
7431 default:7441 default: