Skip to content

Commit 63d18b4

Browse files
authored
Merge pull request #3892 from ljmf00/real-size-riscv
gen/target: make real 128bit on RISC-V targets
2 parents f154d67 + 4967565 commit 63d18b4

File tree

1 file changed

+28
-18
lines changed

1 file changed

+28
-18
lines changed

gen/target.cpp

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,30 +31,40 @@ TypeTuple *toArgTypes_sysv_x64(Type *t);
3131
TypeTuple *toArgTypes_aarch64(Type *t);
3232

3333
namespace {
34+
// Returns the LL type to be used for D `real` (C `long double`).
3435
llvm::Type *getRealType(const llvm::Triple &triple) {
35-
auto &ctx = getGlobalContext();
36+
using llvm::Triple;
3637

37-
const auto a = triple.getArch();
38-
const bool anyX86 = (a == llvm::Triple::x86) || (a == llvm::Triple::x86_64);
39-
const bool anyAarch64 =
40-
(a == llvm::Triple::aarch64) || (a == llvm::Triple::aarch64_be);
41-
const bool isAndroid = triple.getEnvironment() == llvm::Triple::Android;
38+
auto &ctx = getGlobalContext();
4239

43-
// Only x86 has 80-bit extended precision.
44-
// MSVC and Android/x86 use double precision, Android/x64 quadruple.
45-
if (anyX86 && !triple.isWindowsMSVCEnvironment() && !isAndroid) {
46-
return llvm::Type::getX86_FP80Ty(ctx);
40+
// Android: x86 targets follow ARM, with emulated quad precision for x64
41+
if (triple.getEnvironment() == llvm::Triple::Android) {
42+
return triple.isArch64Bit() ? LLType::getFP128Ty(ctx)
43+
: LLType::getDoubleTy(ctx);
4744
}
4845

49-
// AArch64 targets except Darwin (64-bit) use 128-bit quadruple precision.
50-
// FIXME: PowerPC, SystemZ, ...
51-
if ((anyAarch64 && !triple.isOSDarwin()) ||
52-
(isAndroid && a == llvm::Triple::x86_64)) {
53-
return llvm::Type::getFP128Ty(ctx);
46+
switch (triple.getArch()) {
47+
case Triple::x86:
48+
case Triple::x86_64:
49+
// only x86 has 80-bit extended precision; MSVC uses double
50+
return triple.isWindowsMSVCEnvironment() ? LLType::getDoubleTy(ctx)
51+
: LLType::getX86_FP80Ty(ctx);
52+
53+
case Triple::aarch64:
54+
case Triple::aarch64_be:
55+
// AArch64 has 128-bit quad precision; Apple uses double
56+
return triple.isOSDarwin() ? LLType::getDoubleTy(ctx)
57+
: LLType::getFP128Ty(ctx);
58+
59+
case Triple::riscv32:
60+
case Triple::riscv64:
61+
return LLType::getFP128Ty(ctx);
62+
63+
default:
64+
// 64-bit double precision for all other targets
65+
// FIXME: PowerPC, SystemZ, ...
66+
return LLType::getDoubleTy(ctx);
5467
}
55-
56-
// 64-bit double precision for all other targets.
57-
return llvm::Type::getDoubleTy(ctx);
5868
}
5969
}
6070

0 commit comments

Comments
 (0)