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

Commit 8943559

Browse files
committed
core.cpuid: Simplify GDC-style inline asm for 32-bit x86 hasCPUID()
Only use the AT&T syntax, making it compatible with LDC too.
1 parent 928caec commit 8943559

File tree

1 file changed

+9
-12
lines changed

1 file changed

+9
-12
lines changed

src/core/cpuid.d

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -977,21 +977,18 @@ 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
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
995992
" : "=a" (flags);
996993
}
997994
}

0 commit comments

Comments
 (0)