M1 Support for cpu detection

This commit is contained in:
Jeff Hutchinson 2021-09-26 19:36:12 -04:00
parent 960ea2aa5a
commit eb92a8927e
2 changed files with 15 additions and 8 deletions

View file

@ -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.

View file

@ -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<U32>("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<U64>("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;
}