Added __cpuid and __cpuidex wrappers, and fixed wrong argument order in __cpuid.

This commit is contained in:
Tom Lally 2022-08-30 13:42:36 +01:00
parent 0a170d6efc
commit ab1e6f3f53
7 changed files with 34 additions and 30 deletions

View file

@ -32,7 +32,7 @@ uint64 muldiv64(uint64 a, uint64 b, uint64 d)
bool PPCTimer_hasInvariantRDTSCSupport()
{
uint32 cpuv[4];
__cpuid((int*)cpuv, 0x80000007);
cpuid((int*)cpuv, 0x80000007);
return ((cpuv[3] >> 8) & 1);
}

View file

@ -575,12 +575,12 @@ void PPCRecompiler_init()
// query processor extensions
int cpuInfo[4];
__cpuid(cpuInfo, 0x80000001);
cpuid(cpuInfo, 0x80000001);
hasLZCNTSupport = ((cpuInfo[2] >> 5) & 1) != 0;
__cpuid(cpuInfo, 0x1);
cpuid(cpuInfo, 0x1);
hasMOVBESupport = ((cpuInfo[2] >> 22) & 1) != 0;
hasAVXSupport = ((cpuInfo[2] >> 28) & 1) != 0;
__cpuidex(cpuInfo, 0x7, 0);
cpuidex(cpuInfo, 0x7, 0);
hasBMI2Support = ((cpuInfo[1] >> 8) & 1) != 0;
forceLog_printf("Recompiler initialized. CPU extensions: %s%s%s", hasLZCNTSupport ? "LZCNT " : "", hasMOVBESupport ? "MOVBE " : "", hasAVXSupport ? "AVX " : "");

View file

@ -237,6 +237,30 @@ typedef union _LARGE_INTEGER {
#error No definition for DLLEXPORT
#endif
#ifdef __GNUC__
#include <cpuid.h>
#endif
inline void cpuid(int cpuInfo[4], unsigned int functionId) {
#if defined(_MSC_VER)
__cpuid(cpuInfo, functionId);
#elif defined(__GNUC__)
__cpuid(functionId, cpuInfo[0], cpuInfo[1], cpuInfo[2], cpuInfo[3]);
#else
#error No definition for cpuid
#endif
}
inline void cpuidex(int cpuInfo[4], int functionId, int subFunctionId) {
#if defined(_MSC_VER)
__cpuidex(cpuInfo, functionId, subFunctionId);
#elif defined(__GNUC__)
__cpuid_count(functionId, subFunctionId, cpuInfo[0], cpuInfo[1], cpuInfo[2], cpuInfo[3]);
#else
#error No definition for cpuidex
#endif
}
// MEMPTR
#include "Common/MemPtr.h"

View file

@ -7,19 +7,3 @@ uint32_t GetTickCount()
clock_gettime(CLOCK_MONOTONIC, &ts);
return (1000 * ts.tv_sec + ts.tv_nsec / 1000000);
}
#include <cpuid.h>
void (__cpuid)(int __cpuVal[4], unsigned int __leaf)
{
__cpuid(__cpuVal[0], __cpuVal[1], __cpuVal[2], __cpuVal[3], __leaf);
}
#undef __cpuid
#ifdef __clang__
void __cpuidex(int __cpuid_info[4], int __leaf, int __subleaf)
{
__cpuid_count (__leaf, __subleaf, __cpuid_info[0], __cpuid_info[1],
__cpuid_info[2], __cpuid_info[3]);
}
#endif

View file

@ -40,10 +40,6 @@ inline uint32_t GetExceptionError()
#undef Success
#undef ClientMessage
// cpu id (somewhat hacky, reorganize later)
void (__cpuid)(int __cpuVal[4], unsigned int __leaf);
void __cpuidex (int __cpuid_info[4], int __leaf, int __subleaf);
// placeholder
uint32_t GetTickCount();

View file

@ -62,11 +62,11 @@ void logCPUAndMemoryInfo()
unsigned nExIds, i = 0;
char CPUBrandString[0x40];
// Get the information associated with each extended ID.
__cpuid(CPUInfo, 0x80000000);
cpuid(CPUInfo, 0x80000000);
nExIds = CPUInfo[0];
for (i = 0x80000000; i <= nExIds; ++i)
{
__cpuid(CPUInfo, i);
cpuid(CPUInfo, i);
// Interpret CPU brand string
if (i == 0x80000002)
memcpy(CPUBrandString, CPUInfo, sizeof(CPUInfo));
@ -194,11 +194,11 @@ void mainEmulatorCommonInit()
PPCTimer_init();
// check available CPU extensions
int cpuInfo[4];
__cpuid(cpuInfo, 0x1);
cpuid(cpuInfo, 0x1);
_cpuExtension_SSSE3 = ((cpuInfo[2] >> 9) & 1) != 0;
_cpuExtension_SSE4_1 = ((cpuInfo[2] >> 19) & 1) != 0;
__cpuidex(cpuInfo, 0x7, 0);
cpuidex(cpuInfo, 0x7, 0);
_cpuExtension_AVX2 = ((cpuInfo[1] >> 5) & 1) != 0;
#if BOOST_OS_WINDOWS

View file

@ -837,7 +837,7 @@ void AES128_init()
}
// check if AES-NI is available
int v[4];
__cpuid(v, 1);
cpuid(v, 1);
useAESNI = (v[2] & 0x2000000) != 0;
if (useAESNI)
{