sdl12-compat: updated cpuid code from SDL3

From 865e832d47381cbc224cce98c4a18d4a3783d055 Mon Sep 17 00:00:00 2001
From: Ozkan Sezer <[EMAIL REDACTED]>
Date: Sat, 1 Apr 2023 14:10:10 +0300
Subject: [PATCH] updated cpuid code from SDL3

---
 src/SDL12_compat.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/src/SDL12_compat.c b/src/SDL12_compat.c
index 43f49c098..b7f9e9429 100644
--- a/src/SDL12_compat.c
+++ b/src/SDL12_compat.c
@@ -1620,7 +1620,7 @@ SDL_revcpy(void *_dst, const void *_src, size_t len)
 
 
 /* SDL2 doesn't have MMXExt / 3dNowExt. */
-#if defined(__GNUC__) && defined(__i386__)
+#if (defined(__GNUC__) || defined(__llvm__)) && defined(__i386__)
 #define cpuid(func, a, b, c, d) \
     __asm__ __volatile__ ( \
 "        pushl %%ebx        \n" \
@@ -1629,7 +1629,7 @@ SDL_revcpy(void *_dst, const void *_src, size_t len)
 "        movl %%ebx, %%esi  \n" \
 "        popl %%ebx         \n" : \
             "=a" (a), "=S" (b), "=c" (c), "=d" (d) : "a" (func))
-#elif defined(__GNUC__) && defined(__x86_64__)
+#elif (defined(__GNUC__) || defined(__llvm__)) && defined(__x86_64__)
 #define cpuid(func, a, b, c, d) \
     __asm__ __volatile__ ( \
 "        pushq %%rbx        \n" \
@@ -1649,12 +1649,13 @@ SDL_revcpy(void *_dst, const void *_src, size_t len)
         __asm mov c, ecx \
         __asm mov d, edx \
 }
-#elif defined(_MSC_VER) && defined(_M_X64)
+#elif (defined(_MSC_VER) && defined(_M_X64))
+/* Use __cpuidex instead of __cpuid because ICL does not clear ecx register */
 #include <intrin.h>
 #define cpuid(func, a, b, c, d) \
 { \
     int CPUInfo[4]; \
-    __cpuid(CPUInfo, func); \
+    __cpuidex(CPUInfo, func, 0); \
     a = CPUInfo[0]; \
     b = CPUInfo[1]; \
     c = CPUInfo[2]; \