Skip to content
This repository was archived by the owner on Oct 12, 2022. It is now read-only.

Commit b09663d

Browse files
authored
Merge pull request #1981 from kinke/ldc_to_upstream
Upstream some LDC patches merged-on-behalf-of: David Nadlinger <code@klickverbot.at>
2 parents a66f9fa + 3fd5df3 commit b09663d

File tree

10 files changed

+238
-55
lines changed

10 files changed

+238
-55
lines changed

src/core/bitop.d

Lines changed: 28 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -561,24 +561,17 @@ version (DigitalMars) version (AnyX86) @system // not pure
561561
int popcnt(uint x) pure
562562
{
563563
// Select the fastest method depending on the compiler and CPU architecture
564-
version(LDC)
564+
version(DigitalMars)
565565
{
566-
return _popcnt(x);
567-
}
568-
else
569-
{
570-
version(DigitalMars)
566+
static if (is(typeof(_popcnt(uint.max))))
571567
{
572-
static if (is(typeof(_popcnt(uint.max))))
573-
{
574-
import core.cpuid;
575-
if (!__ctfe && hasPopcnt)
576-
return _popcnt(x);
577-
}
568+
import core.cpuid;
569+
if (!__ctfe && hasPopcnt)
570+
return _popcnt(x);
578571
}
579-
580-
return softPopcnt!uint(x);
581572
}
573+
574+
return softPopcnt!uint(x);
582575
}
583576

584577
unittest
@@ -600,44 +593,37 @@ unittest
600593
int popcnt(ulong x) pure
601594
{
602595
// Select the fastest method depending on the compiler and CPU architecture
603-
version(LDC)
604-
{
605-
return _popcnt(x);
606-
}
607-
else
608-
{
609-
import core.cpuid;
596+
import core.cpuid;
610597

611-
static if (size_t.sizeof == uint.sizeof)
598+
static if (size_t.sizeof == uint.sizeof)
599+
{
600+
const sx = Split64(x);
601+
version(DigitalMars)
612602
{
613-
const sx = Split64(x);
614-
version(DigitalMars)
603+
static if (is(typeof(_popcnt(uint.max))))
615604
{
616-
static if (is(typeof(_popcnt(uint.max))))
617-
{
618-
if (!__ctfe && hasPopcnt)
619-
return _popcnt(sx.lo) + _popcnt(sx.hi);
620-
}
605+
if (!__ctfe && hasPopcnt)
606+
return _popcnt(sx.lo) + _popcnt(sx.hi);
621607
}
622-
623-
return softPopcnt!uint(sx.lo) + softPopcnt!uint(sx.hi);
624608
}
625-
else static if (size_t.sizeof == ulong.sizeof)
609+
610+
return softPopcnt!uint(sx.lo) + softPopcnt!uint(sx.hi);
611+
}
612+
else static if (size_t.sizeof == ulong.sizeof)
613+
{
614+
version(DigitalMars)
626615
{
627-
version(DigitalMars)
616+
static if (is(typeof(_popcnt(ulong.max))))
628617
{
629-
static if (is(typeof(_popcnt(ulong.max))))
630-
{
631-
if (!__ctfe && hasPopcnt)
632-
return _popcnt(x);
633-
}
618+
if (!__ctfe && hasPopcnt)
619+
return _popcnt(x);
634620
}
635-
636-
return softPopcnt!ulong(x);
637621
}
638-
else
639-
static assert(false);
622+
623+
return softPopcnt!ulong(x);
640624
}
625+
else
626+
static assert(false);
641627
}
642628

643629
unittest

src/core/stdc/config.d

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,7 @@ else version( DigitalMars )
138138
else version( GNU )
139139
alias real c_long_double;
140140
else version( LDC )
141-
{
142-
version( X86 )
143-
alias real c_long_double;
144-
else version( X86_64 )
145-
alias real c_long_double;
146-
}
141+
alias real c_long_double;
147142
else version( SDC )
148143
{
149144
version( X86 )

src/core/stdc/fenv.d

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ extern (C):
2828
nothrow:
2929
@nogc:
3030

31+
version (PPC)
32+
version = PPC_Any;
33+
else version (PPC64)
34+
version = PPC_Any;
35+
3136
version( MinGW )
3237
version = GNUFP;
3338
version( CRuntime_Glibc )
@@ -120,7 +125,7 @@ version( GNUFP )
120125
alias fexcept_t = uint;
121126
}
122127
// https://sourceware.org/git/?p=glibc.git;a=blob;f=sysdeps/powerpc/bits/fenv.h
123-
else version (PPC64)
128+
else version (PPC_Any)
124129
{
125130
alias fenv_t = double;
126131
alias fexcept_t = uint;

src/core/stdc/stdlib.d

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,11 @@ else version( GNU )
220220
{
221221
void* alloca(size_t size) pure; // compiler intrinsic
222222
}
223+
else version( LDC )
224+
{
225+
pragma(LDC_alloca)
226+
void* alloca(size_t size) pure;
227+
}
223228

224229
version( CRuntime_Microsoft )
225230
{

src/core/sys/posix/pwd.d

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,8 +220,12 @@ else version( DragonFlyBSD )
220220
}
221221
else version (Solaris)
222222
{
223-
int getpwnam_r(in char*, passwd*, char*, size_t, passwd**);
224-
int getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
223+
alias getpwnam_r = __posix_getpwnam_r;
224+
alias getpwuid_r = __posix_getpwuid_r;
225+
226+
// POSIX.1c standard version of the functions
227+
int __posix_getpwnam_r(in char*, passwd*, char*, size_t, passwd**);
228+
int __posix_getpwuid_r(uid_t, passwd*, char*, size_t, passwd**);
225229
}
226230
else version( CRuntime_Bionic )
227231
{

src/core/thread.d

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3559,6 +3559,15 @@ private
35593559
version = AsmExternal;
35603560
}
35613561
}
3562+
else version( AArch64 )
3563+
{
3564+
version( Posix )
3565+
{
3566+
version = AsmAArch64_Posix;
3567+
version = AsmExternal;
3568+
version = AlignFiberStackTo16Byte;
3569+
}
3570+
}
35623571
else version( ARM )
35633572
{
35643573
version( Posix )
@@ -4890,6 +4899,29 @@ private:
48904899
pstack -= ABOVE;
48914900
*cast(size_t*)(pstack - SZ_RA) = cast(size_t)&fiber_entryPoint;
48924901
}
4902+
else version( AsmAArch64_Posix )
4903+
{
4904+
// Like others, FP registers and return address (lr) are kept
4905+
// below the saved stack top (tstack) to hide from GC scanning.
4906+
// fiber_switchContext expects newp sp to look like this:
4907+
// 19: x19
4908+
// ...
4909+
// 9: x29 (fp) <-- newp tstack
4910+
// 8: x30 (lr) [&fiber_entryPoint]
4911+
// 7: d8
4912+
// ...
4913+
// 0: d15
4914+
4915+
version( StackGrowsDown ) {}
4916+
else
4917+
static assert(false, "Only full descending stacks supported on AArch64");
4918+
4919+
// Only need to set return address (lr). Everything else is fine
4920+
// zero initialized.
4921+
pstack -= size_t.sizeof * 11; // skip past x19-x29
4922+
push(cast(size_t) &fiber_entryPoint);
4923+
pstack += size_t.sizeof; // adjust sp (newp) above lr
4924+
}
48934925
else version( AsmARM_Posix )
48944926
{
48954927
/* We keep the FP registers and the return address below

src/core/threadasm.S

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,4 +449,59 @@ fiber_switchContext:
449449
// return by writing lr into pc
450450
mov pc, r1
451451
.fnend
452+
453+
#elif defined(__aarch64__)
454+
/************************************************************************************
455+
* AArch64 (arm64) ASM BITS
456+
************************************************************************************/
457+
/**
458+
* preserve/restore AAPCS64 registers
459+
* x19-x28 5.1.1 64-bit callee saved
460+
* x29 fp, or possibly callee saved reg - depends on platform choice 5.2.3)
461+
* x30 lr
462+
* d8-d15 5.1.2 says callee only must save bottom 64-bits (the "d" regs)
463+
*
464+
* saved regs on stack will look like:
465+
* 19: x19
466+
* 18: x20
467+
* ...
468+
* 10: x28
469+
* 9: x29 (fp) <-- oldp / *newp save stack top
470+
* 8: x30 (lr)
471+
* 7: d8
472+
* ...
473+
* 0: d15 <-- sp
474+
*/
475+
.text
476+
.global CSYM(fiber_switchContext)
477+
.p2align 2
478+
CSYM(fiber_switchContext):
479+
stp d15, d14, [sp, #-20*8]!
480+
stp d13, d12, [sp, #2*8]
481+
stp d11, d10, [sp, #4*8]
482+
stp d9, d8, [sp, #6*8]
483+
stp x30, x29, [sp, #8*8] // lr, fp
484+
stp x28, x27, [sp, #10*8]
485+
stp x26, x25, [sp, #12*8]
486+
stp x24, x23, [sp, #14*8]
487+
stp x22, x21, [sp, #16*8]
488+
stp x20, x19, [sp, #18*8]
489+
490+
// oldp is set above saved lr (x30) to hide it and float regs
491+
// from GC
492+
add x19, sp, #9*8
493+
str x19, [x0] // *oldp tstack
494+
sub sp, x1, #9*8 // switch to newp sp
495+
496+
ldp x20, x19, [sp, #18*8]
497+
ldp x22, x21, [sp, #16*8]
498+
ldp x24, x23, [sp, #14*8]
499+
ldp x26, x25, [sp, #12*8]
500+
ldp x28, x27, [sp, #10*8]
501+
ldp x30, x29, [sp, #8*8] // lr, fp
502+
ldp d9, d8, [sp, #6*8]
503+
ldp d11, d10, [sp, #4*8]
504+
ldp d13, d12, [sp, #2*8]
505+
ldp d15, d14, [sp], #20*8
506+
ret
452507
#endif

src/object.d

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3109,7 +3109,7 @@ version (unittest)
31093109
private
31103110
{
31113111
extern (C) void _d_arrayshrinkfit(const TypeInfo ti, void[] arr) nothrow;
3112-
extern (C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void *arrptr) pure nothrow;
3112+
extern (C) size_t _d_arraysetcapacity(const TypeInfo ti, size_t newcapacity, void[]* arrptr) pure nothrow;
31133113
}
31143114

31153115
/**
@@ -3125,7 +3125,7 @@ private
31253125
*/
31263126
@property size_t capacity(T)(T[] arr) pure nothrow @trusted
31273127
{
3128-
return _d_arraysetcapacity(typeid(T[]), 0, cast(void *)&arr);
3128+
return _d_arraysetcapacity(typeid(T[]), 0, cast(void[]*)&arr);
31293129
}
31303130
///
31313131
@safe unittest
@@ -3160,7 +3160,7 @@ private
31603160
*/
31613161
size_t reserve(T)(ref T[] arr, size_t newcapacity) pure nothrow @trusted
31623162
{
3163-
return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void *)&arr);
3163+
return _d_arraysetcapacity(typeid(T[]), newcapacity, cast(void[]*)&arr);
31643164
}
31653165
///
31663166
unittest

src/rt/backtrace/elf.d

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,48 @@ else version(X86_64)
219219
alias Elf_Shdr = Elf64_Shdr;
220220
enum ELFCLASS = ELFCLASS64;
221221
}
222+
else version(ARM)
223+
{
224+
alias Elf_Ehdr = Elf32_Ehdr;
225+
alias Elf_Shdr = Elf32_Shdr;
226+
enum ELFCLASS = ELFCLASS32;
227+
}
228+
else version(AArch64)
229+
{
230+
alias Elf_Ehdr = Elf64_Ehdr;
231+
alias Elf_Shdr = Elf64_Shdr;
232+
enum ELFCLASS = ELFCLASS64;
233+
}
234+
else version(PPC)
235+
{
236+
alias Elf_Ehdr = Elf32_Ehdr;
237+
alias Elf_Shdr = Elf32_Shdr;
238+
enum ELFCLASS = ELFCLASS32;
239+
}
240+
else version(PPC64)
241+
{
242+
alias Elf_Ehdr = Elf64_Ehdr;
243+
alias Elf_Shdr = Elf64_Shdr;
244+
enum ELFCLASS = ELFCLASS64;
245+
}
246+
else version(MIPS)
247+
{
248+
alias Elf_Ehdr = Elf32_Ehdr;
249+
alias Elf_Shdr = Elf32_Shdr;
250+
enum ELFCLASS = ELFCLASS32;
251+
}
252+
else version(MIPS64)
253+
{
254+
alias Elf_Ehdr = Elf64_Ehdr;
255+
alias Elf_Shdr = Elf64_Shdr;
256+
enum ELFCLASS = ELFCLASS64;
257+
}
258+
else version(SystemZ)
259+
{
260+
alias Elf_Ehdr = Elf64_Ehdr;
261+
alias Elf_Shdr = Elf64_Shdr;
262+
enum ELFCLASS = ELFCLASS64;
263+
}
222264
else
223265
{
224266
static assert(0, "unsupported architecture");

0 commit comments

Comments
 (0)