1010 #include <asm/hwcap.h>
1111#elif defined __APPLE__ || __MACH__
1212 #include "sysctl.h"
13- // From Linux kernel: arch/arm64/include/asm/cputype.h
14- #define MIDR_APPLE_M1_ICESTORM 0x610F0220
15- #define MIDR_APPLE_M1_FIRESTORM 0x610F0230
16- #ifndef CPUFAMILY_ARM_FIRESTORM_ICESTORM
17- #define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1B588BB3
18- #endif
1913#endif
2014
2115#include "../common/global.h"
@@ -244,7 +238,7 @@ struct cpuInfo* get_cpu_info_linux(struct cpuInfo* cpu) {
244238}
245239
246240#elif defined __APPLE__ || __MACH__
247- void fill_cpu_info_firestorm_icestorm (struct cpuInfo * cpu ) {
241+ void fill_cpu_info_firestorm_icestorm (struct cpuInfo * cpu , uint32_t pcores , uint32_t ecores ) {
248242 // 1. Fill ICESTORM
249243 struct cpuInfo * ice = cpu ;
250244
@@ -254,7 +248,7 @@ void fill_cpu_info_firestorm_icestorm(struct cpuInfo* cpu) {
254248 ice -> feat = get_features_info ();
255249 ice -> topo = malloc (sizeof (struct topology ));
256250 ice -> topo -> cach = ice -> cach ;
257- ice -> topo -> total_cores = 4 ;
251+ ice -> topo -> total_cores = ecores ;
258252 ice -> freq = malloc (sizeof (struct frequency ));
259253 ice -> freq -> base = UNKNOWN_DATA ;
260254 ice -> freq -> max = 2064 ;
@@ -270,7 +264,7 @@ void fill_cpu_info_firestorm_icestorm(struct cpuInfo* cpu) {
270264 fire -> feat = get_features_info ();
271265 fire -> topo = malloc (sizeof (struct topology ));
272266 fire -> topo -> cach = fire -> cach ;
273- fire -> topo -> total_cores = 4 ;
267+ fire -> topo -> total_cores = pcores ;
274268 fire -> freq = malloc (sizeof (struct frequency ));
275269 fire -> freq -> base = UNKNOWN_DATA ;
276270 fire -> freq -> max = 3200 ;
@@ -286,8 +280,26 @@ struct cpuInfo* get_cpu_info_mach(struct cpuInfo* cpu) {
286280 // is a ARM_FIRESTORM_ICESTORM (Apple M1)
287281 if (cpu_family == CPUFAMILY_ARM_FIRESTORM_ICESTORM ) {
288282 cpu -> num_cpus = 2 ;
283+ // Now detect the M1 version
284+ uint32_t cpu_subfamily = get_sys_info_by_name ("hw.cpusubfamily" );
285+ if (cpu_subfamily == CPUSUBFAMILY_ARM_HG ) {
286+ // Apple M1
287+ fill_cpu_info_firestorm_icestorm (cpu , 4 , 4 );
288+ }
289+ else if (cpu_subfamily == CPUSUBFAMILY_ARM_HS || cpu_subfamily == CPUSUBFAMILY_ARM_HC_HD ) {
290+ // Apple M1 Pro/Max. Detect number of cores
291+ uint32_t physicalcpu = get_sys_info_by_name ("hw.physicalcpu" );
292+ if (physicalcpu < 8 || physicalcpu > 10 ) {
293+ printBug ("Found invalid physicalcpu: 0x%.8X" , physicalcpu );
294+ return NULL ;
295+ }
296+ fill_cpu_info_firestorm_icestorm (cpu , physicalcpu - 2 , 2 );
297+ }
298+ else {
299+ printBug ("Found invalid cpu_subfamily: 0x%.8X" , cpu_subfamily );
300+ return NULL ;
301+ }
289302 cpu -> soc = get_soc ();
290- fill_cpu_info_firestorm_icestorm (cpu );
291303 cpu -> peak_performance = get_peak_performance (cpu );
292304 }
293305 else {
0 commit comments