From 029fd01cfbcc0b18475faee8353585313c88a95b Mon Sep 17 00:00:00 2001 From: Martin Kroeker Date: Wed, 2 Sep 2020 22:47:38 +0200 Subject: [PATCH] Detect AppleSilicon cpu on OSX --- cpuid_arm64.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/cpuid_arm64.c b/cpuid_arm64.c index 1fd43148a..df1be85ba 100644 --- a/cpuid_arm64.c +++ b/cpuid_arm64.c @@ -26,6 +26,11 @@ *****************************************************************************/ #include +#ifdef OS_DARWIN +#include +int32_t value; +size_t length=sizeof(value); +#endif #define CPU_UNKNOWN 0 #define CPU_ARMV8 1 @@ -45,6 +50,8 @@ #define CPU_TSV110 9 // Ampere #define CPU_EMAG8180 10 +// Apple +#define CPU_SILICON 11 static char *cpuname[] = { "UNKNOWN", @@ -59,7 +66,8 @@ static char *cpuname[] = { "TSV110", "EMAG8180", "NEOVERSEN1", - "THUNDERX3T110" + "THUNDERX3T110", + "SILICON" }; static char *cpuname_lower[] = { @@ -75,7 +83,8 @@ static char *cpuname_lower[] = { "tsv110", "emag8180", "neoversen1", - "thunderx3t110" + "thunderx3t110", + "silicon" }; int get_feature(char *search) @@ -198,6 +207,10 @@ int detect(void) } #else +#ifdef DARWIN + sysctlbyname("hw.cpufamily",&value,&length,NULL,0); + if (value ==131287967) return CPU_SILICON; +#endif return CPU_ARMV8; #endif @@ -247,7 +260,10 @@ int n=0; printf("#define NUM_CORES %d\n",n); #endif - +#ifdef DARWIN + sysctlbyname("hw.physicalcpu_max",&value,&length,NULL,0); + printf("#define NUM_CORES %d\n",value); +#endif } @@ -398,6 +414,19 @@ void get_cpuconfig(void) printf("#define DTB_DEFAULT_ENTRIES 64 \n"); printf("#define DTB_SIZE 4096 \n"); break; +#ifdef DARWIN + case CPU_SILICON: + printf("#define SILICON \n"); + sysctlbyname("hw.l1icachesize",&value,&length,NULL,0); + printf("#define L1_CODE_SIZE %d \n",value); + sysctlbyname("hw.cachelinesize",&value,&length,NULL,0); + printf("#define L1_CODE_LINESIZE %d \n",value); + sysctlbyname("hw.l1dcachesize",&value,&length,NULL,0); + printf("#define L1_DATA_SIZE %d \n",value); + sysctlbyname("hw.l2dcachesize",&value,&length,NULL,0); + printf("#define L2_DATA_SIZE %d \n",value); + break; +#endif } get_cpucount(); }