ziglang / zig

General-purpose programming language and toolchain for maintaining robust, optimal, and reusable software.
https://ziglang.org
MIT License
34.09k stars 2.49k forks source link

Zig appears to think M1 mac is Apple A14 #15169

Open jmgurney opened 1 year ago

jmgurney commented 1 year ago

Zig Version

0.11.0-dev.2249+dcdb87836

Steps to Reproduce and Observed Behavior

On a 2021 14-inch MBP (M1 Pro), Ventura 13.2, run:

$ zig targets | jq '.native.cpu.name'
"apple_a14"

Expected Behavior

I'd expect it to return "apple_m1" instead.

andydude commented 1 year ago

It looks like there are many possible solutions to this:

  1. Write some CPUID code? Although this seems like a waste of time, because the Darwin kernel writes the sysctl properties based on what it reads from the Main ID register (MIDR), which is the ARM equivalent of the x86 CPUID instruction.
  2. Read more sysctl properties, specifically, we currently check hw.cpufamily, but we could also check the additional properties:
    • hw.cpusubfamily,
    • hw.cpusubtype,
    • hw.cputype, or
    • machdep.cpu.brand_string

The problem is that both A14 and M1 share a common micro-architecture (FIRESTORM_ICESTORM is what hw.cpufamily is set to on both A14 and M1), which might be more course-grained than we want. If we want more fine-grained details, then looking at other properties might be the best solution.

mikdusan commented 1 year ago
value cpu model
2 M1
4 M1 Pro
5 M1 Max

source: https://github.com/Dr-Noob/cpufetch/issues/139#issuecomment-1059933273

note: I can't find anything for M1 Ultra or M2 cpu models

jmgurney commented 1 year ago

I can confirm sub family 4 on my M1 Pro:

$ sysctl hw.cpusubfamily
hw.cpusubfamily: 4
andydude commented 1 year ago

I found these part numbers in proc_reg.h:

Brand SubFamily MIDR Part Num MIDR Part Num Desc Efficiency/Performance
Apple A14 1 0x20 MIDR_SICILY_ICESTORM E-core
Apple A14 1 0x21 MIDR_SICILY_FIRESTORM P-core
Apple M1 2 0x22 MIDR_TONGA_ICESTORM E-core
Apple M1 2 0x23 MIDR_TONGA_FIRESTORM P-core
Apple M1 Pro 4 0x24 MIDR_JADE_CHOP_ICESTORM E-core
Apple M1 Pro 4 0x25 MIDR_JADE_CHOP_FIRESTORM P-core
Apple M1 Max 5 0x28 MIDR_JADE_DIE_ICESTORM E-core
Apple M1 Max 5 0x29 MIDR_JADE_DIE_FIRESTORM P-core

I'm just musing here, but I think that Firestorm is the name of the Performance core, Icestorm is the name of the Efficiency core, Firestorm-Icestorm is the name of the micro-architecture, and the others appear to be like code names for TDP?

spofdamon commented 1 year ago

I have an M2 MBA (2022), family value is:

hw.cpufamily: 0xda33d83d
hw.cpusubfamily: 2