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

Commit 15a3f9d

Browse files
authored
Merge pull request #3048 from thewilsonator/ldc-cpuid
[core.cpuid] LDC uses GNU style asm merged-on-behalf-of: Mathias LANG <pro.mathias.lang@gmail.com>
2 parents bd67a95 + ab37c8e commit 15a3f9d

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

src/core/cpuid.d

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,9 @@
5656

5757
module core.cpuid;
5858

59+
version (GNU) version = GNU_OR_LDC;
60+
version (LDC) version = GNU_OR_LDC;
61+
5962
@trusted:
6063
nothrow:
6164
@nogc:
@@ -426,7 +429,7 @@ CpuFeatures* getCpuFeatures() @nogc nothrow
426429
}
427430

428431

429-
version (GNU) {
432+
version (GNU_OR_LDC) {
430433
version (X86)
431434
enum supportedX86 = true;
432435
else version (X86_64)
@@ -509,7 +512,7 @@ void getcacheinfoCPUID2()
509512
// for old single-core CPUs.
510513
uint numinfos = 1;
511514
do {
512-
version (GNU) asm pure nothrow @nogc {
515+
version (GNU_OR_LDC) asm pure nothrow @nogc {
513516
"cpuid" : "=a" (a[0]), "=b" (a[1]), "=c" (a[2]), "=d" (a[3]) : "a" (2);
514517
} else asm pure nothrow @nogc {
515518
mov EAX, 2;
@@ -553,7 +556,7 @@ void getcacheinfoCPUID4()
553556
int cachenum = 0;
554557
for (;;) {
555558
uint a, b, number_of_sets;
556-
version (GNU) asm pure nothrow @nogc {
559+
version (GNU_OR_LDC) asm pure nothrow @nogc {
557560
"cpuid" : "=a" (a), "=b" (b), "=c" (number_of_sets) : "a" (4), "c" (cachenum) : "edx";
558561
} else asm pure nothrow @nogc {
559562
mov EAX, 4;
@@ -593,7 +596,7 @@ void getcacheinfoCPUID4()
593596
void getAMDcacheinfo()
594597
{
595598
uint dummy, c5, c6, d6;
596-
version (GNU) asm pure nothrow @nogc {
599+
version (GNU_OR_LDC) asm pure nothrow @nogc {
597600
"cpuid" : "=a" (dummy), "=c" (c5) : "a" (0x8000_0005) : "ebx", "edx";
598601
} else asm pure nothrow @nogc {
599602
mov EAX, 0x8000_0005; // L1 cache
@@ -612,7 +615,7 @@ void getAMDcacheinfo()
612615
// AMD K6-III or K6-2+ or later.
613616
ubyte numcores = 1;
614617
if (max_extended_cpuid >= 0x8000_0008) {
615-
version (GNU) asm pure nothrow @nogc {
618+
version (GNU_OR_LDC) asm pure nothrow @nogc {
616619
"cpuid" : "=a" (dummy), "=c" (numcores) : "a" (0x8000_0008) : "ebx", "edx";
617620
} else asm pure nothrow @nogc {
618621
mov EAX, 0x8000_0008;
@@ -623,7 +626,7 @@ void getAMDcacheinfo()
623626
if (numcores>cpuFeatures.maxCores) cpuFeatures.maxCores = numcores;
624627
}
625628

626-
version (GNU) asm pure nothrow @nogc {
629+
version (GNU_OR_LDC) asm pure nothrow @nogc {
627630
"cpuid" : "=a" (dummy), "=c" (c6), "=d" (d6) : "a" (0x8000_0006) : "ebx";
628631
} else asm pure nothrow @nogc {
629632
mov EAX, 0x8000_0006; // L2/L3 cache
@@ -652,7 +655,7 @@ void getCpuInfo0B()
652655
int threadsPerCore;
653656
uint a, b, c, d;
654657
do {
655-
version (GNU) asm pure nothrow @nogc {
658+
version (GNU_OR_LDC) asm pure nothrow @nogc {
656659
"cpuid" : "=a" (a), "=b" (b), "=c" (c), "=d" (d) : "a" (0x0B), "c" (level);
657660
} else asm pure nothrow @nogc {
658661
mov EAX, 0x0B;
@@ -684,7 +687,7 @@ void cpuidX86()
684687

685688
uint a, b, c, d;
686689
uint* venptr = cast(uint*)cf.vendorID.ptr;
687-
version (GNU)
690+
version (GNU_OR_LDC)
688691
{
689692
asm pure nothrow @nogc {
690693
"cpuid" : "=a" (max_cpuid), "=b" (venptr[0]), "=d" (venptr[1]), "=c" (venptr[2]) : "a" (0);
@@ -731,7 +734,7 @@ void cpuidX86()
731734
cf.probablyIntel = cf.vendorID == "GenuineIntel";
732735
cf.probablyAMD = (cf.vendorID == "AuthenticAMD" || cf.vendorID == "HygonGenuine");
733736
uint apic = 0; // brand index, apic id
734-
version (GNU) asm pure nothrow @nogc {
737+
version (GNU_OR_LDC) asm pure nothrow @nogc {
735738
"cpuid" : "=a" (a), "=b" (apic), "=c" (cf.miscfeatures), "=d" (cf.features) : "a" (1);
736739
} else {
737740
asm pure nothrow @nogc {
@@ -754,7 +757,7 @@ void cpuidX86()
754757

755758
if (max_cpuid >= 7)
756759
{
757-
version (GNU) asm pure nothrow @nogc {
760+
version (GNU_OR_LDC) asm pure nothrow @nogc {
758761
"cpuid" : "=a" (a), "=b" (cf.extfeatures), "=c" (c) : "a" (7), "c" (0) : "edx";
759762
} else {
760763
uint ext;
@@ -770,7 +773,7 @@ void cpuidX86()
770773

771774
if (cf.miscfeatures & OSXSAVE_BIT)
772775
{
773-
version (GNU) asm pure nothrow @nogc {
776+
version (GNU_OR_LDC) asm pure nothrow @nogc {
774777
"xgetbv" : "=a" (a), "=d" (d) : "c" (0);
775778
} else asm pure nothrow @nogc {
776779
mov ECX, 0;
@@ -784,7 +787,7 @@ void cpuidX86()
784787
cf.amdfeatures = 0;
785788
cf.amdmiscfeatures = 0;
786789
if (max_extended_cpuid >= 0x8000_0001) {
787-
version (GNU) asm pure nothrow @nogc {
790+
version (GNU_OR_LDC) asm pure nothrow @nogc {
788791
"cpuid" : "=a" (a), "=c" (cf.amdmiscfeatures), "=d" (cf.amdfeatures) : "a" (0x8000_0001) : "ebx";
789792
} else {
790793
asm pure nothrow @nogc {
@@ -805,7 +808,7 @@ void cpuidX86()
805808
cf.maxCores = 1;
806809
if (hyperThreadingBit) {
807810
// determine max number of cores for AMD
808-
version (GNU) asm pure nothrow @nogc {
811+
version (GNU_OR_LDC) asm pure nothrow @nogc {
809812
"cpuid" : "=a" (a), "=c" (c) : "a" (0x8000_0008) : "ebx", "edx";
810813
} else asm pure nothrow @nogc {
811814
mov EAX, 0x8000_0008;
@@ -818,7 +821,7 @@ void cpuidX86()
818821

819822
if (max_extended_cpuid >= 0x8000_0004) {
820823
uint* pnb = cast(uint*)cf.processorNameBuffer.ptr;
821-
version (GNU)
824+
version (GNU_OR_LDC)
822825
{
823826
asm pure nothrow @nogc {
824827
"cpuid" : "=a" (pnb[0]), "=b" (pnb[1]), "=c" (pnb[ 2]), "=d" (pnb[ 3]) : "a" (0x8000_0002);
@@ -950,7 +953,7 @@ void cpuidX86()
950953
else cf.maxThreads = cf.maxCores;
951954

952955
if (cf.probablyAMD && max_extended_cpuid >= 0x8000_001E) {
953-
version (GNU) asm pure nothrow @nogc {
956+
version (GNU_OR_LDC) asm pure nothrow @nogc {
954957
"cpuid" : "=a" a, "=b" b : "a" 0x8000_001E : "ecx", "edx";
955958
} else {
956959
asm pure nothrow @nogc {

0 commit comments

Comments
 (0)