From 9c8feefcdc943cff056467c8e0d730f6c186ea42 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Wed, 2 Dec 2020 21:56:52 +0100 Subject: [PATCH] M1: Correctly detect core count. --- Common/ArmCPUDetect.cpp | 16 ++++++++++++++++ Common/CPUDetect.cpp | 12 ++++++++---- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/Common/ArmCPUDetect.cpp b/Common/ArmCPUDetect.cpp index 540f7d7b0c..8ca50fd019 100644 --- a/Common/ArmCPUDetect.cpp +++ b/Common/ArmCPUDetect.cpp @@ -19,6 +19,11 @@ #include +#if PPSSPP_PLATFORM(MAC) +#include +#endif + + #if PPSSPP_ARCH(ARM) || PPSSPP_ARCH(ARM64) #include @@ -246,6 +251,17 @@ void CPUInfo::Detect() #endif strcpy(brand_string, "Apple A"); num_cores = 2; +#elif PPSSPP_PLATFORM(MAC) + strcpy(brand_string, "Apple M1"); + int num = 0; + size_t sz = sizeof(num); + if (sysctlbyname("hw.physicalcpu_max", &num, &sz, nullptr, 0) == 0) { + num_cores = num; + sz = sizeof(num); + if (sysctlbyname("hw.logicalcpu_max", &num, &sz, nullptr, 0) == 0) { + logical_cpu_count = num / num_cores; + } + } #elif PPSSPP_PLATFORM(WINDOWS) truncate_cpy(brand_string, GetCPUBrandString().c_str()); isVFP3 = true; diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index 9910f651cc..70c640eee7 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -35,6 +35,7 @@ #include "Common/StringUtils.h" #if defined(_WIN32) && !defined(__MINGW32__) + #define WIN32_LEAN_AND_MEAN #include #define _interlockedbittestandset workaround_ms_header_bug_platform_sdk6_set @@ -53,7 +54,8 @@ void do_cpuidex(u32 regs[4], u32 cpuid_leaf, u32 ecxval) { void do_cpuid(u32 regs[4], u32 cpuid_leaf) { __cpuid((int *)regs, cpuid_leaf); } -#else + +#else // _WIN32 #ifdef _M_SSE #include @@ -68,7 +70,7 @@ static unsigned long long _xgetbv(unsigned int index) #else #define _XCR_XFEATURE_ENABLED_MASK 0 -#endif +#endif // _M_SSE #if !defined(MIPS) @@ -92,8 +94,10 @@ void do_cpuid(u32 regs[4], u32 cpuid_leaf) do_cpuidex(regs, cpuid_leaf, 0); } -#endif -#endif +#endif // !defined(MIPS) + +#endif // !win32 + CPUInfo cpu_info;