From eb92a8927e37f782d785a2201b46d9c28b43689b Mon Sep 17 00:00:00 2001 From: Jeff Hutchinson Date: Sun, 26 Sep 2021 19:36:12 -0400 Subject: [PATCH] M1 Support for cpu detection --- Engine/source/platform/platform.h | 8 ++++---- Engine/source/platformMac/macCPU.mm | 15 +++++++++++---- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Engine/source/platform/platform.h b/Engine/source/platform/platform.h index 2944e596c..f8239f817 100644 --- a/Engine/source/platform/platform.h +++ b/Engine/source/platform/platform.h @@ -77,10 +77,10 @@ enum ProcessorProperties CPU_PROP_SSE4_1 = (1<<9), ///< Supports SSE4_1 instruction set extension. CPU_PROP_SSE4_2 = (1<<10), ///< Supports SSE4_2 instruction set extension. CPU_PROP_AVX = (1<<11), ///< Supports AVX256 instruction set extension. - CPU_PROP_MP = (1<<11), ///< This is a multi-processor system. - CPU_PROP_LE = (1<<12), ///< This processor is LITTLE ENDIAN. - CPU_PROP_64bit = (1<<13), ///< This processor is 64-bit capable - CPU_PROP_NEON = (1<<14), ///< Supports the Arm Neon instruction set extension. + CPU_PROP_MP = (1<<12), ///< This is a multi-processor system. + CPU_PROP_LE = (1<<13), ///< This processor is LITTLE ENDIAN. + CPU_PROP_64bit = (1<<14), ///< This processor is 64-bit capable + CPU_PROP_NEON = (1<<15), ///< Supports the Arm Neon instruction set extension. }; /// Processor info manager. diff --git a/Engine/source/platformMac/macCPU.mm b/Engine/source/platformMac/macCPU.mm index e961542e9..96cf068a9 100644 --- a/Engine/source/platformMac/macCPU.mm +++ b/Engine/source/platformMac/macCPU.mm @@ -81,6 +81,7 @@ int _getSysCTLvalue(const char key[], T * dest) { Platform::SystemInfo_struct Platform::SystemInfo; #define BASE_MHZ_SPEED 1000 +#define BASE_APPLE_SILICON_MHZ_SPEED 3200 static void detectCpuFeatures(U32 &procflags) { @@ -126,8 +127,10 @@ static void detectCpuFeatures(U32 &procflags) procflags |= CPU_PROP_AVX; #elif defined(TORQUE_CPU_ARM64) - // All Apple Cpus have Neon - procflags |= CPU_PROP_NEON; + + err = _getSysCTLvalue("hw.optional.neon", &lraw); + if ((err==0)&&(lraw==1)) + procflags |= CPU_PROP_NEON; #endif @@ -170,11 +173,15 @@ void Processor::init() if (err) vendor[0] = '\0'; - // The Gestalt version was known to have issues with some Processor Upgrade cards - // but it is uncertain whether this version has similar issues. + // Note: hw.cpufrequency seems to be missing on the M1. For Apple Silicon, + // we will assume the base frequency of the M1 which is 3.2ghz err = _getSysCTLvalue("hw.cpufrequency", &llraw); if (err) { +#if defined(TORQUE_CPU_ARM64) + llraw = BASE_APPLE_SILICON_MHZ_SPEED; +#else llraw = BASE_MHZ_SPEED; +#endif } else { llraw /= 1000000; }