Sfoglia il codice sorgente

M1 Support for cpu detection

Jeff Hutchinson 3 anni fa
parent
commit
eb92a8927e
2 ha cambiato i file con 15 aggiunte e 8 eliminazioni
  1. 4 4
      Engine/source/platform/platform.h
  2. 11 4
      Engine/source/platformMac/macCPU.mm

+ 4 - 4
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. 

+ 11 - 4
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<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;
 	}