[clang] [clang][x86] Support -masm=intel in cpuid.h (PR #127331)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 15 07:28:47 PST 2025
https://github.com/Alcaro created https://github.com/llvm/llvm-project/pull/127331
Fixes #127271
Testing mostly done in Compiler Explorer https://godbolt.org/z/q1h3ohxr7
>From 90e3f502e582f44cd19e1b8b71d218330b13c9e4 Mon Sep 17 00:00:00 2001
From: Alcaro <floating at muncher.se>
Date: Sat, 15 Feb 2025 16:05:40 +0100
Subject: [PATCH] [clang][x86] Support -masm=intel in cpuid.h
---
clang/lib/Headers/cpuid.h | 30 +++++++++++++++---------------
1 file changed, 15 insertions(+), 15 deletions(-)
diff --git a/clang/lib/Headers/cpuid.h b/clang/lib/Headers/cpuid.h
index 2601aa5724f05..d8ace39d4e7d1 100644
--- a/clang/lib/Headers/cpuid.h
+++ b/clang/lib/Headers/cpuid.h
@@ -268,16 +268,16 @@
#else
/* x86-64 uses %rbx as the base register, so preserve it. */
#define __cpuid(__leaf, __eax, __ebx, __ecx, __edx) \
- __asm(" xchgq %%rbx,%q1\n" \
+ __asm(" xchg{q|} {%%|}rbx,%q1\n" \
" cpuid\n" \
- " xchgq %%rbx,%q1" \
+ " xchg{q|} {%%|}rbx,%q1" \
: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
: "0"(__leaf))
#define __cpuid_count(__leaf, __count, __eax, __ebx, __ecx, __edx) \
- __asm(" xchgq %%rbx,%q1\n" \
+ __asm(" xchg{q|} {%%|}rbx,%q1\n" \
" cpuid\n" \
- " xchgq %%rbx,%q1" \
+ " xchg{q|} {%%|}rbx,%q1" \
: "=a"(__eax), "=r" (__ebx), "=c"(__ecx), "=d"(__edx) \
: "0"(__leaf), "2"(__count))
#endif
@@ -289,18 +289,18 @@ static __inline unsigned int __get_cpuid_max (unsigned int __leaf,
#ifdef __i386__
int __cpuid_supported;
- __asm(" pushfl\n"
- " popl %%eax\n"
- " movl %%eax,%%ecx\n"
- " xorl $0x00200000,%%eax\n"
- " pushl %%eax\n"
- " popfl\n"
- " pushfl\n"
- " popl %%eax\n"
- " movl $0,%0\n"
- " cmpl %%eax,%%ecx\n"
+ __asm(" pushf{l|d}\n"
+ " pop{l|} {%%|}eax\n"
+ " mov{l|} {%%eax,%%ecx|ecx,eax}\n"
+ " xor{l|} {$0x00200000,%%eax|eax,0x00200000}\n"
+ " push{l|} {%%|}eax\n"
+ " popf{l|d}\n"
+ " pushf{l|d}\n"
+ " pop{l|} {%%|}eax\n"
+ " mov{l|} {$0,%0|%0,0}\n"
+ " cmp{l|} {%%eax,%%ecx|ecx,eax}\n"
" je 1f\n"
- " movl $1,%0\n"
+ " mov{l|} {$1,%0|%0,1}\n"
"1:"
: "=r" (__cpuid_supported) : : "eax", "ecx");
if (!__cpuid_supported)
More information about the cfe-commits
mailing list