Skip to content

Commit ae47998

Browse files
authored
Merge pull request #4835 from rainers/rainer_winonarm
run on and build for Windows on ARM64
2 parents 3726a93 + 78eef1c commit ae47998

File tree

18 files changed

+235
-22
lines changed

18 files changed

+235
-22
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#### Platform support
1010
- Supports LLVM 15 - 19.
1111
- Initial compiler and runtime support for ppc64 and ppc64le systems that use IEEE 754R 128-bit floating-point as the default 128-bit floating-point format. (#4833)
12+
- Added support for building for Windows on ARM64. Use option '-march=arm64' to compile, 'ldc-build-runtime.exe --dFlags -march=arm64' to build the runtime libraries. (#4835)
1213

1314
#### Bug fixes
1415
- Building multi-file D applications with control-flow protection will no longer cause LDC to throw an internal compiler error. (#4828)

dmd/root/longdouble.d

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -338,9 +338,20 @@ void ld_setll(longdouble_soft* pthis, long d)
338338

339339
void ld_setull(longdouble_soft* pthis, ulong d)
340340
{
341-
d ^= (1L << 63);
342341
version(AsmX86)
343342
{
343+
// emulator accuracy not good enough when running on Windows on ARM,
344+
// so avoid chopping off small numbers
345+
if (!(d & (1L << 63)))
346+
{
347+
asm nothrow @nogc pure @trusted
348+
{
349+
fild qword ptr d;
350+
}
351+
mixin(fstp_parg!("pthis"));
352+
return;
353+
}
354+
d ^= (1L << 63);
344355
auto pTwoPow63 = &twoPow63;
345356
mixin(fld_parg!("pTwoPow63"));
346357
asm nothrow @nogc pure @trusted

gen/abi/aarch64.cpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,13 @@ struct AArch64TargetABI : TargetABI {
3232
IndirectByvalRewrite indirectByvalRewrite;
3333
ArgTypesRewrite argTypesRewrite;
3434

35+
bool hasAAPCS64VaList() {
36+
return !isDarwin() &&
37+
!global.params.targetTriple->isWindowsMSVCEnvironment();
38+
}
39+
3540
bool isAAPCS64VaList(Type *t) {
36-
if (isDarwin())
41+
if (!hasAAPCS64VaList())
3742
return false;
3843

3944
// look for a __va_list struct in a `std` C++ namespace
@@ -152,7 +157,7 @@ struct AArch64TargetABI : TargetABI {
152157
}
153158

154159
Type *vaListType() override {
155-
if (isDarwin())
160+
if (!hasAAPCS64VaList())
156161
return TargetABI::vaListType(); // char*
157162

158163
// We need to pass the actual va_list type for correct mangling. Simply

gen/target.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ llvm::Type *getRealType(const llvm::Triple &triple) {
7777

7878
case Triple::aarch64:
7979
case Triple::aarch64_be:
80-
// AArch64 has 128-bit quad precision; Apple uses double
81-
return triple.isOSDarwin() ? LLType::getDoubleTy(ctx)
82-
: LLType::getFP128Ty(ctx);
80+
// AArch64 has 128-bit quad precision; Apple and MSVC use double
81+
return triple.isOSDarwin() || triple.isWindowsMSVCEnvironment()
82+
? LLType::getDoubleTy(ctx) : LLType::getFP128Ty(ctx);
8383

8484
case Triple::riscv32:
8585
case Triple::riscv64:

runtime/druntime/src/__importc_builtins.di

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@ version (LDC)
3939
}
4040
else version (ARM_Any)
4141
{
42-
// Darwin does not use __va_list
42+
// Darwin and Windows do not use __va_list
4343
version (OSX) {}
4444
else version (iOS) {}
4545
else version (TVOS) {}
4646
else version (WatchOS) {}
47+
else version (CRuntime_Microsoft) {}
4748
else:
4849

4950
version (ARM)

runtime/druntime/src/core/internal/vararg/aarch64.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,12 @@ module core.internal.vararg.aarch64;
1414

1515
version (AArch64):
1616

17-
// Darwin uses a simpler varargs implementation
17+
// Darwin and Windows use a simpler varargs implementation
1818
version (OSX) {}
1919
else version (iOS) {}
2020
else version (TVOS) {}
2121
else version (WatchOS) {}
22+
else version (CRuntime_Microsoft) {}
2223
else:
2324

2425
import core.stdc.stdarg : alignUp;

runtime/druntime/src/core/stdc/math.d

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ version (CRuntime_Microsoft) // fully supported since MSVCRT 12 (VS 2013) only
482482
else // for backward compatibility with older runtimes
483483
{
484484
///
485-
pure int isnan(float x) { version (Win64) return _isnanf(x); else return _isnan(cast(double) x); }
485+
pure int isnan(float x) { version (X86_64) return _isnanf(x); else return _isnan(cast(double) x); }
486486
///
487487
extern(C) pragma(mangle, "_isnan") pure int isnan(double x);
488488
///

runtime/druntime/src/core/stdc/stdarg.d

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ version (GNU)
5555
}
5656
else version (ARM_Any)
5757
{
58-
// Darwin uses a simpler varargs implementation
58+
// Darwin and Windows use a simpler varargs implementation
5959
version (OSX) {}
6060
else version (iOS) {}
6161
else version (TVOS) {}
6262
else version (WatchOS) {}
63+
else version (CRuntime_Microsoft) {}
6364
else:
6465

6566
version (ARM)

runtime/druntime/src/core/sys/windows/dll.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ private bool isWindows8OrLater() nothrow @nogc
402402
int dll_getRefCount( HINSTANCE hInstance ) nothrow @nogc
403403
{
404404
void** peb;
405-
version (Win64)
405+
version (X86_64)
406406
{
407407
asm pure nothrow @nogc
408408
{
@@ -411,14 +411,18 @@ int dll_getRefCount( HINSTANCE hInstance ) nothrow @nogc
411411
mov peb, RAX;
412412
}
413413
}
414-
else version (Win32)
414+
else version (X86)
415415
{
416416
asm pure nothrow @nogc
417417
{
418418
mov EAX,FS:[0x30];
419419
mov peb, EAX;
420420
}
421421
}
422+
else version (AArch64)
423+
{
424+
asm nothrow @nogc { "ldr %0, [x18,%1]" : "=r" (peb) : "r" (0x30); }
425+
}
422426
dll_aux.LDR_MODULE *ldrMod = dll_aux.findLdrModule( hInstance, peb );
423427
if ( !ldrMod )
424428
return -2; // not in module list, bail out

runtime/druntime/src/core/sys/windows/stacktrace.d

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,7 @@ private:
230230

231231
version (X86) enum imageType = IMAGE_FILE_MACHINE_I386;
232232
else version (X86_64) enum imageType = IMAGE_FILE_MACHINE_AMD64;
233+
else version (AArch64) enum imageType = IMAGE_FILE_MACHINE_ARM64;
233234
else static assert(0, "unimplemented");
234235

235236
size_t frameNum = 0;

0 commit comments

Comments
 (0)