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

Commit 3f9bfc9

Browse files
Merge pull request #3068 from kinke/cpuid
[stable] core.cpuid: Slightly adapt GDC-style inline asm
2 parents a479398 + 8943559 commit 3f9bfc9

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

src/core/cpuid.d

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -954,7 +954,7 @@ void cpuidX86()
954954

955955
if (cf.probablyAMD && max_extended_cpuid >= 0x8000_001E) {
956956
version (GNU_OR_LDC) asm pure nothrow @nogc {
957-
"cpuid" : "=a" a, "=b" b : "a" 0x8000_001E : "ecx", "edx";
957+
"cpuid" : "=a" (a), "=b" (b) : "a" (0x8000_001E) : "ecx", "edx";
958958
} else {
959959
asm pure nothrow @nogc {
960960
mov EAX, 0x8000_001e;
@@ -977,22 +977,19 @@ bool hasCPUID()
977977
else
978978
{
979979
uint flags;
980-
version (GNU)
980+
version (GNU_OR_LDC)
981981
{
982982
// http://wiki.osdev.org/CPUID#Checking_CPUID_availability
983-
// ASM template supports both AT&T and Intel syntax.
984983
asm nothrow @nogc { "
985-
pushf{l|d} # Save EFLAGS
986-
pushf{l|d} # Store EFLAGS
987-
xor{l $0x00200000, (%%esp)| dword ptr [esp], 0x00200000}
988-
# Invert the ID bit in stored EFLAGS
989-
popf{l|d} # Load stored EFLAGS (with ID bit inverted)
990-
pushf{l|d} # Store EFLAGS again (ID bit may or may not be inverted)
991-
pop {%%}eax # eax = modified EFLAGS (ID bit may or may not be inverted)
992-
xor {(%%esp), %%eax|eax, [esp]}
993-
# eax = whichever bits were changed
994-
popf{l|d} # Restore original EFLAGS
995-
" : "=a" flags;
984+
pushfl # Save EFLAGS
985+
pushfl # Store EFLAGS
986+
xorl $0x00200000, (%%esp) # Invert the ID bit in stored EFLAGS
987+
popfl # Load stored EFLAGS (with ID bit inverted)
988+
pushfl # Store EFLAGS again (ID bit may or may not be inverted)
989+
popl %%eax # eax = modified EFLAGS (ID bit may or may not be inverted)
990+
xorl (%%esp), %%eax # eax = whichever bits were changed
991+
popfl # Restore original EFLAGS
992+
" : "=a" (flags);
996993
}
997994
}
998995
else version (D_InlineAsm_X86)

0 commit comments

Comments
 (0)