@@ -1460,6 +1460,18 @@ StringRef sys::getHostCPUName() {
14601460 return getCPUNameFromS390Model (Id, HaveVectorSupport);
14611461}
14621462#elif defined(__APPLE__) && (defined(__arm__) || defined(__aarch64__))
1463+ // Copied from <mach/machine.h> in the macOS SDK.
1464+ //
1465+ // Also available here, though usually not as up-to-date:
1466+ // https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.41.3/osfmk/mach/machine.h#L403-L452.
1467+ #define CPUFAMILY_UNKNOWN 0
1468+ #define CPUFAMILY_ARM_9 0xe73283ae
1469+ #define CPUFAMILY_ARM_11 0x8ff620d8
1470+ #define CPUFAMILY_ARM_XSCALE 0x53b005f5
1471+ #define CPUFAMILY_ARM_12 0xbd1b0ae9
1472+ #define CPUFAMILY_ARM_13 0x0cc90e64
1473+ #define CPUFAMILY_ARM_14 0x96077ef1
1474+ #define CPUFAMILY_ARM_15 0xa8511bca
14631475#define CPUFAMILY_ARM_SWIFT 0x1e2d6381
14641476#define CPUFAMILY_ARM_CYCLONE 0x37a09642
14651477#define CPUFAMILY_ARM_TYPHOON 0x2c91a47e
@@ -1471,13 +1483,46 @@ StringRef sys::getHostCPUName() {
14711483#define CPUFAMILY_ARM_FIRESTORM_ICESTORM 0x1b588bb3
14721484#define CPUFAMILY_ARM_BLIZZARD_AVALANCHE 0xda33d83d
14731485#define CPUFAMILY_ARM_EVEREST_SAWTOOTH 0x8765edea
1486+ #define CPUFAMILY_ARM_IBIZA 0xfa33415e
1487+ #define CPUFAMILY_ARM_PALMA 0x72015832
1488+ #define CPUFAMILY_ARM_COLL 0x2876f5b5
1489+ #define CPUFAMILY_ARM_LOBOS 0x5f4dea93
1490+ #define CPUFAMILY_ARM_DONAN 0x6f5129ac
1491+ #define CPUFAMILY_ARM_BRAVA 0x17d5b93a
1492+ #define CPUFAMILY_ARM_TAHITI 0x75d4acb9
1493+ #define CPUFAMILY_ARM_TUPAI 0x204526d0
14741494
14751495StringRef sys::getHostCPUName () {
14761496 uint32_t Family;
14771497 size_t Length = sizeof (Family);
14781498 sysctlbyname (" hw.cpufamily" , &Family, &Length, NULL , 0 );
14791499
1500+ // This is found by testing on actual hardware, and by looking at:
1501+ // https://github.com/apple-oss-distributions/xnu/blob/xnu-11215.41.3/osfmk/arm/cpuid.c#L109-L231.
1502+ //
1503+ // Another great resource is
1504+ // https://github.com/AsahiLinux/docs/wiki/Codenames.
1505+ //
1506+ // NOTE: We choose to return `apple-mX` instead of `apple-aX`, since the M1,
1507+ // M2, M3 etc. aliases are more widely known to users than A14, A15, A16 etc.
1508+ // (and this code is basically only used on host macOS anyways).
14801509 switch (Family) {
1510+ case CPUFAMILY_UNKNOWN:
1511+ return " invalid" ;
1512+ case CPUFAMILY_ARM_9:
1513+ return " arm920t" ; // or arm926ej-s
1514+ case CPUFAMILY_ARM_11:
1515+ return " arm1136jf-s" ;
1516+ case CPUFAMILY_ARM_XSCALE:
1517+ return " xscale" ;
1518+ case CPUFAMILY_ARM_12:
1519+ return " invalid" ; // Seems unsued by the kernel
1520+ case CPUFAMILY_ARM_13:
1521+ return " cortex-a8" ;
1522+ case CPUFAMILY_ARM_14:
1523+ return " cortex-a9" ;
1524+ case CPUFAMILY_ARM_15:
1525+ return " cortex-a7" ;
14811526 case CPUFAMILY_ARM_SWIFT:
14821527 return " swift" ;
14831528 case CPUFAMILY_ARM_CYCLONE:
@@ -1495,14 +1540,30 @@ StringRef sys::getHostCPUName() {
14951540 case CPUFAMILY_ARM_LIGHTNING_THUNDER:
14961541 return " apple-a13" ;
14971542 case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
1498- return " apple-m1" ;
1543+ return " apple-m1" ; // A14 / M1
14991544 case CPUFAMILY_ARM_BLIZZARD_AVALANCHE:
1500- return " apple-m2" ;
1545+ return " apple-m2" ; // A15 / M2
15011546 case CPUFAMILY_ARM_EVEREST_SAWTOOTH:
1502- return " apple-m3" ;
1547+ return " apple-m3" ; // A16
1548+ case CPUFAMILY_ARM_IBIZA:
1549+ return " apple-m3" ; // M3
1550+ case CPUFAMILY_ARM_PALMA:
1551+ return " apple-m3" ; // M3 Max
1552+ case CPUFAMILY_ARM_COLL:
1553+ return " apple-m3" ; // A17
1554+ case CPUFAMILY_ARM_LOBOS:
1555+ return " apple-m3" ; // M3 Pro
1556+ case CPUFAMILY_ARM_DONAN:
1557+ return " apple-m4" ; // M4
1558+ case CPUFAMILY_ARM_BRAVA:
1559+ return " apple-m4" ; // M4 Max
1560+ case CPUFAMILY_ARM_TAHITI:
1561+ return " apple-m4" ; // A18 Pro
1562+ case CPUFAMILY_ARM_TUPAI:
1563+ return " apple-m4" ; // A18
15031564 default :
15041565 // Default to the newest CPU we know about.
1505- return " apple-m3 " ;
1566+ return " apple-m4 " ;
15061567 }
15071568}
15081569#elif defined(_AIX)
0 commit comments