Skip to content

Commit

Permalink
GS: Swap to cpuinfo for checking CPU features
Browse files Browse the repository at this point in the history
  • Loading branch information
stenzek committed Jun 9, 2024
1 parent 37df1ad commit 4f5562a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 13 deletions.
25 changes: 13 additions & 12 deletions pcsx2/GS/MultiISA.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
// SPDX-License-Identifier: LGPL-3.0+

#include "MultiISA.h"
#include <xbyak/xbyak_util.h>

#include "common/Console.h"

#include "cpuinfo.h"

#ifdef _WIN32
#define strcasecmp _stricmp
#endif

static Xbyak::util::Cpu s_cpu;

static ProcessorFeatures::VectorISA getCurrentISA()
{
// For debugging
Expand All @@ -31,21 +32,22 @@ static ProcessorFeatures::VectorISA getCurrentISA()
return ProcessorFeatures::VectorISA::SSE4;
}
}
if (s_cpu.has(Xbyak::util::Cpu::tAVX2) && s_cpu.has(Xbyak::util::Cpu::tBMI1) && s_cpu.has(Xbyak::util::Cpu::tBMI2))

if (cpuinfo_has_x86_avx2() && cpuinfo_has_x86_bmi() && cpuinfo_has_x86_bmi2())
return ProcessorFeatures::VectorISA::AVX2;
else if (s_cpu.has(Xbyak::util::Cpu::tAVX))
else if (cpuinfo_has_x86_avx())
return ProcessorFeatures::VectorISA::AVX;
else if (s_cpu.has(Xbyak::util::Cpu::tSSE41))
return ProcessorFeatures::VectorISA::SSE4;
else
return ProcessorFeatures::VectorISA::None;
return ProcessorFeatures::VectorISA::SSE4;
}

static ProcessorFeatures getProcessorFeatures()
{
cpuinfo_initialize();

ProcessorFeatures features = {};
features.vectorISA = getCurrentISA();
features.hasFMA = s_cpu.has(Xbyak::util::Cpu::tFMA);
features.hasFMA = cpuinfo_has_x86_fma3();
if (const char* over = getenv("OVERRIDE_FMA"))
{
features.hasFMA = over[0] == 'Y' || over[0] == 'y' || over[0] == '1';
Expand All @@ -59,11 +61,10 @@ static ProcessorFeatures getProcessorFeatures()
}
else if (features.vectorISA == ProcessorFeatures::VectorISA::AVX2)
{
if (s_cpu.has(Xbyak::util::Cpu::tINTEL))
if (cpuinfo_get_cores_count() > 0 && cpuinfo_get_core(0)->vendor == cpuinfo_vendor_intel)
{
// Slow on Haswell
// CPUID data from https://en.wikichip.org/wiki/intel/cpuid
features.hasSlowGather = s_cpu.displayModel == 0x46 || s_cpu.displayModel == 0x45 || s_cpu.displayModel == 0x3c;
features.hasSlowGather = (cpuinfo_get_uarchs_count() == 0 || cpuinfo_get_uarch(0)->uarch == cpuinfo_uarch_haswell);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion pcsx2/GS/MultiISA.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@

struct ProcessorFeatures
{
enum class VectorISA { None, SSE4, AVX, AVX2 };
enum class VectorISA { SSE4, AVX, AVX2 };
VectorISA vectorISA;
bool hasFMA;
bool hasSlowGather;
Expand Down

0 comments on commit 4f5562a

Please sign in to comment.