From c56ca4a0fad6ccef8a659f90ac3b65f9bdd6ffaf Mon Sep 17 00:00:00 2001 From: Gregory Hainaut Date: Sat, 16 Jul 2016 16:40:29 +0200 Subject: [PATCH] common: include cpuid.h on unix I tested both clang and gcc. --- common/include/Pcsx2Defs.h | 6 +----- common/include/intrin_x86.h | 10 ---------- common/include/x86emitter/x86_intrin.h | 21 +++++++++++++++++++++ common/src/x86emitter/cpudetect.cpp | 18 +++++++++--------- 4 files changed, 31 insertions(+), 24 deletions(-) diff --git a/common/include/Pcsx2Defs.h b/common/include/Pcsx2Defs.h index 862068d845..bba17b0c23 100644 --- a/common/include/Pcsx2Defs.h +++ b/common/include/Pcsx2Defs.h @@ -33,11 +33,7 @@ #include "Pcsx2Types.h" -#ifdef _MSC_VER -# include -#else -# include -#endif +#include "x86emitter/x86_intrin.h" // Renamed ARRAYSIZE to ArraySize -- looks nice and gets rid of Windows.h conflicts (air) // Notes: I'd have used ARRAY_SIZE instead but ran into cross-platform lib conflicts with diff --git a/common/include/intrin_x86.h b/common/include/intrin_x86.h index 6b83a2928e..d9342a9d84 100644 --- a/common/include/intrin_x86.h +++ b/common/include/intrin_x86.h @@ -69,16 +69,6 @@ static __inline__ __attribute__((always_inline)) s64 _InterlockedExchange64(vola } /*** System information ***/ -static __inline__ __attribute__((always_inline)) void __cpuid(int CPUInfo[], const int InfoType) -{ - __asm__ __volatile__("cpuid": "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (InfoType)); -} - -static __inline__ __attribute__((always_inline)) void __cpuidex(int CPUInfo[], const int level, const int count) -{ - __asm__ __volatile__("cpuid": "=a" (CPUInfo[0]), "=b" (CPUInfo[1]), "=c" (CPUInfo[2]), "=d" (CPUInfo[3]) : "a" (level), "c" (count)); -} - static __inline__ __attribute__((always_inline)) unsigned long long _xgetbv(unsigned int index) { unsigned int eax, edx; diff --git a/common/include/x86emitter/x86_intrin.h b/common/include/x86emitter/x86_intrin.h index 572f70759c..c0c0a59477 100644 --- a/common/include/x86emitter/x86_intrin.h +++ b/common/include/x86emitter/x86_intrin.h @@ -31,6 +31,27 @@ #endif +// CPU information support +#if defined(_WIN32) + +#define cpuid __cpuid +#define cpuidex __cpuidex + +#else + +#include + +static __inline__ __attribute__((always_inline)) void cpuidex(int CPUInfo[], const int InfoType, const int count) { + __cpuid_count(InfoType, count, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); +} + +static __inline__ __attribute__((always_inline)) void cpuid(int CPUInfo[], const int InfoType) { + __cpuid(InfoType, CPUInfo[0], CPUInfo[1], CPUInfo[2], CPUInfo[3]); +} + +#endif + +// Rotate instruction #if defined(__clang__) // Seriously what is so complicated to provided this bunch of intrinsics in clangs. static unsigned int _rotr(unsigned int x, int s) diff --git a/common/src/x86emitter/cpudetect.cpp b/common/src/x86emitter/cpudetect.cpp index 38f506dba2..b6eb60bf84 100644 --- a/common/src/x86emitter/cpudetect.cpp +++ b/common/src/x86emitter/cpudetect.cpp @@ -149,7 +149,7 @@ void x86capabilities::CountCores() s32 regs[ 4 ]; u32 cmds; - __cpuid( regs, 0x80000000 ); + cpuid( regs, 0x80000000 ); cmds = regs[ 0 ]; // detect multicore for AMD cpu @@ -191,7 +191,7 @@ void x86capabilities::Identify() #endif memzero( VendorName ); - __cpuid( regs, 0 ); + cpuid( regs, 0 ); cmds = regs[ 0 ]; ((u32*)VendorName)[ 0 ] = regs[ 1 ]; @@ -211,7 +211,7 @@ void x86capabilities::Identify() if ( cmds >= 0x00000001 ) { - __cpuid( regs, 0x00000001 ); + cpuid( regs, 0x00000001 ); StepID = regs[ 0 ] & 0xf; Model = (regs[ 0 ] >> 4) & 0xf; @@ -227,16 +227,16 @@ void x86capabilities::Identify() if ( cmds >= 0x00000007 ) { // Note: ECX must be 0 for AVX2 detection. - __cpuidex( regs, 0x00000007, 0 ); + cpuidex( regs, 0x00000007, 0 ); SEFlag = regs[ 1 ]; } - __cpuid( regs, 0x80000000 ); + cpuid( regs, 0x80000000 ); cmds = regs[ 0 ]; if ( cmds >= 0x80000001 ) { - __cpuid( regs, 0x80000001 ); + cpuid( regs, 0x80000001 ); #ifdef __x86_64__ x86_64_12BITBRANDID = regs[1] & 0xfff; @@ -246,9 +246,9 @@ void x86capabilities::Identify() } memzero( FamilyName ); - __cpuid( (int*)FamilyName, 0x80000002); - __cpuid( (int*)(FamilyName+16), 0x80000003); - __cpuid( (int*)(FamilyName+32), 0x80000004); + cpuid( (int*)FamilyName, 0x80000002); + cpuid( (int*)(FamilyName+16), 0x80000003); + cpuid( (int*)(FamilyName+32), 0x80000004); hasFloatingPointUnit = ( Flags >> 0 ) & 1; hasVirtual8086ModeEnhancements = ( Flags >> 1 ) & 1;