-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[clang][x86] Support -masm=intel in cpuid.h #127331
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@llvm/pr-subscribers-backend-x86 Author: None (Alcaro) ChangesFixes #127271 Testing mostly done in Compiler Explorer https://godbolt.org/z/q1h3ohxr7 Full diff: https://github.com/llvm/llvm-project/pull/127331.diff 1 Files Affected:
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)
|
@llvm/pr-subscribers-clang Author: None (Alcaro) ChangesFixes #127271 Testing mostly done in Compiler Explorer https://godbolt.org/z/q1h3ohxr7 Full diff: https://github.com/llvm/llvm-project/pull/127331.diff 1 Files Affected:
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)
|
✅ With the latest revision this PR passed the C/C++ code formatter. |
Oh come on, format bot, it was like that when I found it. |
Please update test in clang\test\Headers\cpuid.c |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
So what's going on here? What's the next step? Who's waiting for who? |
Fixes #127271
Testing mostly done in Compiler Explorer https://godbolt.org/z/q1h3ohxr7