@@ -31,30 +31,40 @@ TypeTuple *toArgTypes_sysv_x64(Type *t);
31
31
TypeTuple *toArgTypes_aarch64 (Type *t);
32
32
33
33
namespace {
34
+ // Returns the LL type to be used for D `real` (C `long double`).
34
35
llvm::Type *getRealType (const llvm::Triple &triple) {
35
- auto &ctx = getGlobalContext () ;
36
+ using llvm::Triple ;
36
37
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 ();
42
39
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);
47
44
}
48
45
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);
54
67
}
55
-
56
- // 64-bit double precision for all other targets.
57
- return llvm::Type::getDoubleTy (ctx);
58
68
}
59
69
}
60
70
0 commit comments