From 1b12a034abdede39d0ee0413e5eca0407c3a805f Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Tue, 30 Dec 2025 11:20:52 -0800 Subject: [PATCH 1/3] Apple SME 2p1 and vector length detect - similar to windows/init.c but use sysinfo hw.optional.arm.FEAT_SME2p1 hw.optional.arm.sme_max_svl_b Tested on Macbook Pro with M4 --- src/arm/mach/init.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/arm/mach/init.c b/src/arm/mach/init.c index c8741bf4..fd554494 100644 --- a/src/arm/mach/init.c +++ b/src/arm/mach/init.c @@ -486,6 +486,16 @@ void cpuinfo_arm_mach_init(void) { cpuinfo_isa.sme2 = true; } + const uint32_t has_feat_sme2p1 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2p1"); + if (has_feat_sme2p1 != 0) { + cpuinfo_isa.sme2p1 = true; + } + + const uint32_t has_sme_max_svl_b = get_sys_info_by_name("hw.optional.arm.sme_max_svl_b"); + if (has_sme_max_svl_b != 0) { + cpuinfo_isa.smelen = has_sme_max_svl_b; + } + uint32_t num_clusters = 1; for (uint32_t i = 0; i < mach_topology.cores; i++) { cores[i] = (struct cpuinfo_core){ From cbb9addaf8661894e82f81b4befdbc6551d73997 Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Tue, 30 Dec 2025 11:49:55 -0800 Subject: [PATCH 2/3] Add Apple SME isa and vector length detects --- src/arm/mach/init.c | 95 ++++++++++++++------------------------------- 1 file changed, 29 insertions(+), 66 deletions(-) diff --git a/src/arm/mach/init.c b/src/arm/mach/init.c index fd554494..30d7ed93 100644 --- a/src/arm/mach/init.c +++ b/src/arm/mach/init.c @@ -362,10 +362,8 @@ void cpuinfo_arm_mach_init(void) { * possible. Otherwise, fallback to hardcoded set of CPUs with known * support. */ - const uint32_t has_feat_lse = get_sys_info_by_name("hw.optional.arm.FEAT_LSE"); - if (has_feat_lse != 0) { - cpuinfo_isa.atomics = true; - } else { + cpuinfo_isa.atomics = get_sys_info_by_name("hw.optional.arm.FEAT_LSE") != 0; + if (!cpuinfo_isa.atomics) { // Mandatory in ARMv8.1-A, list only cores released before iOS // 15 / macOS 12 switch (cpu_family) { @@ -377,10 +375,8 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_rdm = get_sys_info_by_name("hw.optional.arm.FEAT_RDM"); - if (has_feat_rdm != 0) { - cpuinfo_isa.rdm = true; - } else { + cpuinfo_isa.rdm = get_sys_info_by_name("hw.optional.arm.FEAT_RDM") != 0; + if (!cpuinfo_isa.rdm) { // Optional in ARMv8.2-A (implemented in Apple cores), // list only cores released before iOS 15 / macOS 12 switch (cpu_family) { @@ -392,10 +388,8 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_fp16 = get_sys_info_by_name("hw.optional.arm.FEAT_FP16"); - if (has_feat_fp16 != 0) { - cpuinfo_isa.fp16arith = true; - } else { + cpuinfo_isa.fp16arith = get_sys_info_by_name("hw.optional.arm.FEAT_FP16") != 0; + if (!cpuinfo_isa.fp16arith) { // Optional in ARMv8.2-A (implemented in Apple cores), // list only cores released before iOS 15 / macOS 12 switch (cpu_family) { @@ -407,15 +401,11 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_fhm = get_sys_info_by_name("hw.optional.arm.FEAT_FHM"); - if (has_feat_fhm != 0) { - cpuinfo_isa.fhm = true; - } else { + cpuinfo_isa.fhm = get_sys_info_by_name("hw.optional.arm.FEAT_FHM") != 0; + if (!cpuinfo_isa.fhm) { // Prior to iOS 15, use 'hw.optional.armv8_2_fhm' - const uint32_t has_feat_fhm_legacy = get_sys_info_by_name("hw.optional.armv8_2_fhm"); - if (has_feat_fhm_legacy != 0) { - cpuinfo_isa.fhm = true; - } else { + cpuinfo_isa.fhm = get_sys_info_by_name("hw.optional.armv8_2_fhm") != 0; + if (!cpuinfo_isa.fhm) { // Mandatory in ARMv8.4-A when FP16 arithmetics is // implemented, list only cores released before iOS 15 / // macOS 12 @@ -427,17 +417,10 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_bf16 = get_sys_info_by_name("hw.optional.arm.FEAT_BF16"); - if (has_feat_bf16 != 0) { - cpuinfo_isa.bf16 = true; - } - - const uint32_t has_feat_fcma = get_sys_info_by_name("hw.optional.arm.FEAT_FCMA"); - if (has_feat_fcma != 0) { - cpuinfo_isa.fcma = true; - } else { - // Mandatory in ARMv8.3-A, list only cores released before iOS - // 15 / macOS 12 + cpuinfo_isa.bf16 = get_sys_info_by_name("hw.optional.arm.FEAT_BF16") != 0; + cpuinfo_isa.fcma = get_sys_info_by_name("hw.optional.arm.FEAT_FCMA") != 0; + if (!cpuinfo_isa.fcma) { + // Mandatory in ARMv8.3-A, list only cores released before iOS 15 / macOS 12 switch (cpu_family) { case CPUFAMILY_ARM_LIGHTNING_THUNDER: case CPUFAMILY_ARM_FIRESTORM_ICESTORM: @@ -445,12 +428,9 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_jscvt = get_sys_info_by_name("hw.optional.arm.FEAT_JSCVT"); - if (has_feat_jscvt != 0) { - cpuinfo_isa.jscvt = true; - } else { - // Mandatory in ARMv8.3-A, list only cores released before iOS - // 15 / macOS 12 + cpuinfo_isa.jscvt = get_sys_info_by_name("hw.optional.arm.FEAT_JSCVT") != 0; + if (!cpuinfo_isa.jscvt) { + // Mandatory in ARMv8.3-A, list only cores released before iOS 15 / macOS 12 switch (cpu_family) { case CPUFAMILY_ARM_LIGHTNING_THUNDER: case CPUFAMILY_ARM_FIRESTORM_ICESTORM: @@ -458,12 +438,9 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_dotprod = get_sys_info_by_name("hw.optional.arm.FEAT_DotProd"); - if (has_feat_dotprod != 0) { - cpuinfo_isa.dot = true; - } else { - // Mandatory in ARMv8.4-A, list only cores released before iOS - // 15 / macOS 12 + cpuinfo_isa.dot = get_sys_info_by_name("hw.optional.arm.FEAT_DotProd") != 0; + if (!cpuinfo_isa.dot) { + // Mandatory in ARMv8.4-A, list only cores released before iOS 15 / macOS 12 switch (cpu_family) { case CPUFAMILY_ARM_LIGHTNING_THUNDER: case CPUFAMILY_ARM_FIRESTORM_ICESTORM: @@ -471,30 +448,16 @@ void cpuinfo_arm_mach_init(void) { } } - const uint32_t has_feat_i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM"); - if (has_feat_i8mm != 0) { - cpuinfo_isa.i8mm = true; - } - - const uint32_t has_feat_sme = get_sys_info_by_name("hw.optional.arm.FEAT_SME"); - if (has_feat_sme != 0) { - cpuinfo_isa.sme = true; - } - - const uint32_t has_feat_sme2 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2"); - if (has_feat_sme2 != 0) { - cpuinfo_isa.sme2 = true; - } + cpuinfo_isa.i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM") != 0; + cpuinfo_isa.sme= get_sys_info_by_name("hw.optional.arm.FEAT_SME") != 0; + cpuinfo_isa.sme2 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2") != 0; + cpuinfo_isa.sme2p1 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2p1") != 0; + cpuinfo_isa.sme_i16i32 = get_sys_info_by_name("hw.optional.arm.SME_I16I32") != 0; + cpuinfo_isa.sme_bi32i32 = get_sys_info_by_name("hw.optional.arm.SME_BI32I32") != 0; + cpuinfo_isa.sme_b16b16 = get_sys_info_by_name("hw.optional.arm.FEAT_SME_B16B16") != 0; + cpuinfo_isa.sme_f16f16 = get_sys_info_by_name("hw.optional.arm.FEAT_SME_F16F16") != 0; - const uint32_t has_feat_sme2p1 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2p1"); - if (has_feat_sme2p1 != 0) { - cpuinfo_isa.sme2p1 = true; - } - - const uint32_t has_sme_max_svl_b = get_sys_info_by_name("hw.optional.arm.sme_max_svl_b"); - if (has_sme_max_svl_b != 0) { - cpuinfo_isa.smelen = has_sme_max_svl_b; - } + cpuinfo_isa.smelen = get_sys_info_by_name("hw.optional.arm.sme_max_svl_b"); uint32_t num_clusters = 1; for (uint32_t i = 0; i < mach_topology.cores; i++) { From 31caeb963ccf227edfba3d94f845723e5fbb020e Mon Sep 17 00:00:00 2001 From: Frank Barchard Date: Tue, 30 Dec 2025 12:07:44 -0800 Subject: [PATCH 3/3] clang format applied --- src/arm/mach/init.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/arm/mach/init.c b/src/arm/mach/init.c index 30d7ed93..2efad8e2 100644 --- a/src/arm/mach/init.c +++ b/src/arm/mach/init.c @@ -449,7 +449,7 @@ void cpuinfo_arm_mach_init(void) { } cpuinfo_isa.i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM") != 0; - cpuinfo_isa.sme= get_sys_info_by_name("hw.optional.arm.FEAT_SME") != 0; + cpuinfo_isa.sme = get_sys_info_by_name("hw.optional.arm.FEAT_SME") != 0; cpuinfo_isa.sme2 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2") != 0; cpuinfo_isa.sme2p1 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2p1") != 0; cpuinfo_isa.sme_i16i32 = get_sys_info_by_name("hw.optional.arm.SME_I16I32") != 0;