Skip to content

Commit

Permalink
Merged revision(s) 20751 from trunk/OpenMPT:
Browse files Browse the repository at this point in the history
[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.
........


git-svn-id: https://source.openmpt.org/svn/openmpt/branches/OpenMPT-1.31@20752 56274372-70c3-4bfc-bfc3-4c3a0b034d27
  • Loading branch information
manxorist committed May 10, 2024
1 parent 01cb409 commit 038f175
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions src/mpt/arch/x86_amd64.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,8 @@ struct cpu_info {
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{};
Expand All @@ -761,6 +762,28 @@ struct cpu_info {
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

Expand Down Expand Up @@ -801,7 +824,8 @@ struct cpu_info {
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{};
Expand All @@ -815,6 +839,28 @@ struct cpu_info {
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;
Expand Down

0 comments on commit 038f175

Please sign in to comment.