| ... | @@ -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" |
| 22 | | 23 | |
| 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 too | 7425 | 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: |