From 5aa76de35f70d46702e955308a3cc1a0a07abdcf Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Wed, 22 Mar 2023 23:40:35 +0100
Subject: [PATCH] cpuinfo: use __cpuidex instead of __cpuid
The classic Intel Compiler does not clear the ecx register prior
to executing the cpuid opcode.
---
src/cpuinfo/SDL_cpuinfo.c | 19 ++++++++++---------
1 file changed, 10 insertions(+), 9 deletions(-)
diff --git a/src/cpuinfo/SDL_cpuinfo.c b/src/cpuinfo/SDL_cpuinfo.c
index b82bb791f790..0ceadfd2cb3c 100644
--- a/src/cpuinfo/SDL_cpuinfo.c
+++ b/src/cpuinfo/SDL_cpuinfo.c
@@ -262,15 +262,16 @@ static int CPU_haveCPUID(void)
__asm mov c, ecx \
__asm mov d, edx \
}
-#elif defined(_MSC_VER) && defined(_M_X64)
-#define cpuid(func, a, b, c, d) \
- { \
- int CPUInfo[4]; \
- __cpuid(CPUInfo, func); \
- a = CPUInfo[0]; \
- b = CPUInfo[1]; \
- c = CPUInfo[2]; \
- d = CPUInfo[3]; \
+#elif (defined(_MSC_VER) && defined(_M_X64))
+/* Use __cpuidex instead of __cpuid because ICL does not clear ecx register */
+#define cpuid(func, a, b, c, d) \
+ { \
+ int CPUInfo[4]; \
+ __cpuidex(CPUInfo, func, 0); \
+ a = CPUInfo[0]; \
+ b = CPUInfo[1]; \
+ c = CPUInfo[2]; \
+ d = CPUInfo[3]; \
}
#else
#define cpuid(func, a, b, c, d) \