From: <sv...@op...> - 2024-05-10 14:00:26
|
Author: manx Date: Fri May 10 16:00:14 2024 New Revision: 20752 URL: https://source.openmpt.org/browse/openmpt/?op=revision&rev=20752 Log: Merged revision(s) 20751 from trunk/OpenMPT: [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: branches/OpenMPT-1.31/ (props changed) branches/OpenMPT-1.31/src/mpt/arch/x86_amd64.hpp Modified: branches/OpenMPT-1.31/src/mpt/arch/x86_amd64.hpp ============================================================================== --- branches/OpenMPT-1.31/src/mpt/arch/x86_amd64.hpp Fri May 10 15:59:45 2024 (r20751) +++ branches/OpenMPT-1.31/src/mpt/arch/x86_amd64.hpp Fri May 10 16:00:14 2024 (r20752) @@ -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; |