Author: manx
Date: Fri May 10 15:59:45 2024
New Revision: 20751
URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20751
Log:
[Fix] mpt/arch/x86_amd64.hpp: Work-around <https://reviews.llvm.org/D101338>, which affects Clang < 13.0 on AMD64. It misses saving RBX across CPUID.
Modified:
trunk/OpenMPT/src/mpt/arch/x86_amd64.hpp
Modified: trunk/OpenMPT/src/mpt/arch/x86_amd64.hpp
==============================================================================
--- trunk/OpenMPT/src/mpt/arch/x86_amd64.hpp Fri May 10 15:39:12 2024 (r20750)
+++ trunk/OpenMPT/src/mpt/arch/x86_amd64.hpp Fri May 10 15:59:45 2024 (r20751)
@@ -748,7 +748,8 @@
result.d = CPUInfo[3];
return result;
-#elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG
+#elif MPT_COMPILER_GCC || (MPT_COMPILER_CLANG && !MPT_ARCH_AMD64) || MPT_CLANG_AT_LEAST(13,0,0)
+ // <https://reviews.llvm.org/D101338>
cpuid_result result;
unsigned int regeax{};
@@ -761,6 +762,28 @@
result.c = regecx;
result.d = regedx;
return result;
+
+#elif MPT_COMPILER_CLANG && MPT_ARCH_AMD64
+ // <https://reviews.llvm.org/D101338>
+
+ cpuid_result result;
+ unsigned int a{};
+ unsigned int b{};
+ unsigned int c{};
+ unsigned int d{};
+ // clang-format off
+ __asm__ __volatile__ (
+ "xchgq %%rbx,%q1 \n\t"
+ "cpuid \n\t"
+ "xchgq %%rbx,%q1 \n\t"
+ : "=a" (a), "=r" (b), "=c" (c), "=d" (d)
+ : "0" (function));
+ // clang-format on
+ result.a = a;
+ result.b = b;
+ result.c = c;
+ result.d = d;
+ return result;
#elif 0
@@ -801,7 +824,8 @@
result.d = CPUInfo[3];
return result;
-#elif MPT_COMPILER_GCC || MPT_COMPILER_CLANG
+#elif MPT_COMPILER_GCC || (MPT_COMPILER_CLANG && !MPT_ARCH_AMD64) || MPT_CLANG_AT_LEAST(13,0,0)
+ // <https://reviews.llvm.org/D101338>
cpuid_result result;
unsigned int regeax{};
@@ -815,6 +839,28 @@
result.d = regedx;
return result;
+#elif MPT_COMPILER_CLANG && MPT_ARCH_AMD64
+ // <https://reviews.llvm.org/D101338>
+
+ cpuid_result result;
+ unsigned int a{};
+ unsigned int b{};
+ unsigned int c{};
+ unsigned int d{};
+ // clang-format off
+ __asm__ __volatile__ (
+ "xchgq %%rbx,%q1 \n\t"
+ "cpuid \n\t"
+ "xchgq %%rbx,%q1 \n\t"
+ : "=a" (a), "=r" (b), "=c" (c), "=d" (d)
+ : "0" (function_a), "2" (function_c));
+ // clang-format on
+ result.a = a;
+ result.b = b;
+ result.c = c;
+ result.d = d;
+ return result;
+
#elif 0
cpuid_result result;
|