Skip to content

Commit 2846baf

Browse files
authored
Add Apple SME isa and vector length detects (#363)
* 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 * Add Apple SME isa and vector length detects * clang format applied
1 parent b3b2596 commit 2846baf

File tree

1 file changed

+29
-56
lines changed

1 file changed

+29
-56
lines changed

src/arm/mach/init.c

Lines changed: 29 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,8 @@ void cpuinfo_arm_mach_init(void) {
366366
* possible. Otherwise, fallback to hardcoded set of CPUs with known
367367
* support.
368368
*/
369-
const uint32_t has_feat_lse = get_sys_info_by_name("hw.optional.arm.FEAT_LSE");
370-
if (has_feat_lse != 0) {
371-
cpuinfo_isa.atomics = true;
372-
} else {
369+
cpuinfo_isa.atomics = get_sys_info_by_name("hw.optional.arm.FEAT_LSE") != 0;
370+
if (!cpuinfo_isa.atomics) {
373371
// Mandatory in ARMv8.1-A, list only cores released before iOS
374372
// 15 / macOS 12
375373
switch (cpu_family) {
@@ -381,10 +379,8 @@ void cpuinfo_arm_mach_init(void) {
381379
}
382380
}
383381

384-
const uint32_t has_feat_rdm = get_sys_info_by_name("hw.optional.arm.FEAT_RDM");
385-
if (has_feat_rdm != 0) {
386-
cpuinfo_isa.rdm = true;
387-
} else {
382+
cpuinfo_isa.rdm = get_sys_info_by_name("hw.optional.arm.FEAT_RDM") != 0;
383+
if (!cpuinfo_isa.rdm) {
388384
// Optional in ARMv8.2-A (implemented in Apple cores),
389385
// list only cores released before iOS 15 / macOS 12
390386
switch (cpu_family) {
@@ -396,10 +392,8 @@ void cpuinfo_arm_mach_init(void) {
396392
}
397393
}
398394

399-
const uint32_t has_feat_fp16 = get_sys_info_by_name("hw.optional.arm.FEAT_FP16");
400-
if (has_feat_fp16 != 0) {
401-
cpuinfo_isa.fp16arith = true;
402-
} else {
395+
cpuinfo_isa.fp16arith = get_sys_info_by_name("hw.optional.arm.FEAT_FP16") != 0;
396+
if (!cpuinfo_isa.fp16arith) {
403397
// Optional in ARMv8.2-A (implemented in Apple cores),
404398
// list only cores released before iOS 15 / macOS 12
405399
switch (cpu_family) {
@@ -411,15 +405,11 @@ void cpuinfo_arm_mach_init(void) {
411405
}
412406
}
413407

414-
const uint32_t has_feat_fhm = get_sys_info_by_name("hw.optional.arm.FEAT_FHM");
415-
if (has_feat_fhm != 0) {
416-
cpuinfo_isa.fhm = true;
417-
} else {
408+
cpuinfo_isa.fhm = get_sys_info_by_name("hw.optional.arm.FEAT_FHM") != 0;
409+
if (!cpuinfo_isa.fhm) {
418410
// Prior to iOS 15, use 'hw.optional.armv8_2_fhm'
419-
const uint32_t has_feat_fhm_legacy = get_sys_info_by_name("hw.optional.armv8_2_fhm");
420-
if (has_feat_fhm_legacy != 0) {
421-
cpuinfo_isa.fhm = true;
422-
} else {
411+
cpuinfo_isa.fhm = get_sys_info_by_name("hw.optional.armv8_2_fhm") != 0;
412+
if (!cpuinfo_isa.fhm) {
423413
// Mandatory in ARMv8.4-A when FP16 arithmetics is
424414
// implemented, list only cores released before iOS 15 /
425415
// macOS 12
@@ -431,64 +421,47 @@ void cpuinfo_arm_mach_init(void) {
431421
}
432422
}
433423

434-
const uint32_t has_feat_bf16 = get_sys_info_by_name("hw.optional.arm.FEAT_BF16");
435-
if (has_feat_bf16 != 0) {
436-
cpuinfo_isa.bf16 = true;
437-
}
438-
439-
const uint32_t has_feat_fcma = get_sys_info_by_name("hw.optional.arm.FEAT_FCMA");
440-
if (has_feat_fcma != 0) {
441-
cpuinfo_isa.fcma = true;
442-
} else {
443-
// Mandatory in ARMv8.3-A, list only cores released before iOS
444-
// 15 / macOS 12
424+
cpuinfo_isa.bf16 = get_sys_info_by_name("hw.optional.arm.FEAT_BF16") != 0;
425+
cpuinfo_isa.fcma = get_sys_info_by_name("hw.optional.arm.FEAT_FCMA") != 0;
426+
if (!cpuinfo_isa.fcma) {
427+
// Mandatory in ARMv8.3-A, list only cores released before iOS 15 / macOS 12
445428
switch (cpu_family) {
446429
case CPUFAMILY_ARM_LIGHTNING_THUNDER:
447430
case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
448431
cpuinfo_isa.fcma = true;
449432
}
450433
}
451434

452-
const uint32_t has_feat_jscvt = get_sys_info_by_name("hw.optional.arm.FEAT_JSCVT");
453-
if (has_feat_jscvt != 0) {
454-
cpuinfo_isa.jscvt = true;
455-
} else {
456-
// Mandatory in ARMv8.3-A, list only cores released before iOS
457-
// 15 / macOS 12
435+
cpuinfo_isa.jscvt = get_sys_info_by_name("hw.optional.arm.FEAT_JSCVT") != 0;
436+
if (!cpuinfo_isa.jscvt) {
437+
// Mandatory in ARMv8.3-A, list only cores released before iOS 15 / macOS 12
458438
switch (cpu_family) {
459439
case CPUFAMILY_ARM_LIGHTNING_THUNDER:
460440
case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
461441
cpuinfo_isa.jscvt = true;
462442
}
463443
}
464444

465-
const uint32_t has_feat_dotprod = get_sys_info_by_name("hw.optional.arm.FEAT_DotProd");
466-
if (has_feat_dotprod != 0) {
467-
cpuinfo_isa.dot = true;
468-
} else {
469-
// Mandatory in ARMv8.4-A, list only cores released before iOS
470-
// 15 / macOS 12
445+
cpuinfo_isa.dot = get_sys_info_by_name("hw.optional.arm.FEAT_DotProd") != 0;
446+
if (!cpuinfo_isa.dot) {
447+
// Mandatory in ARMv8.4-A, list only cores released before iOS 15 / macOS 12
471448
switch (cpu_family) {
472449
case CPUFAMILY_ARM_LIGHTNING_THUNDER:
473450
case CPUFAMILY_ARM_FIRESTORM_ICESTORM:
474451
cpuinfo_isa.dot = true;
475452
}
476453
}
477454

478-
const uint32_t has_feat_i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM");
479-
if (has_feat_i8mm != 0) {
480-
cpuinfo_isa.i8mm = true;
481-
}
482-
483-
const uint32_t has_feat_sme = get_sys_info_by_name("hw.optional.arm.FEAT_SME");
484-
if (has_feat_sme != 0) {
485-
cpuinfo_isa.sme = true;
486-
}
455+
cpuinfo_isa.i8mm = get_sys_info_by_name("hw.optional.arm.FEAT_I8MM") != 0;
456+
cpuinfo_isa.sme = get_sys_info_by_name("hw.optional.arm.FEAT_SME") != 0;
457+
cpuinfo_isa.sme2 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2") != 0;
458+
cpuinfo_isa.sme2p1 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2p1") != 0;
459+
cpuinfo_isa.sme_i16i32 = get_sys_info_by_name("hw.optional.arm.SME_I16I32") != 0;
460+
cpuinfo_isa.sme_bi32i32 = get_sys_info_by_name("hw.optional.arm.SME_BI32I32") != 0;
461+
cpuinfo_isa.sme_b16b16 = get_sys_info_by_name("hw.optional.arm.FEAT_SME_B16B16") != 0;
462+
cpuinfo_isa.sme_f16f16 = get_sys_info_by_name("hw.optional.arm.FEAT_SME_F16F16") != 0;
487463

488-
const uint32_t has_feat_sme2 = get_sys_info_by_name("hw.optional.arm.FEAT_SME2");
489-
if (has_feat_sme2 != 0) {
490-
cpuinfo_isa.sme2 = true;
491-
}
464+
cpuinfo_isa.smelen = get_sys_info_by_name("hw.optional.arm.sme_max_svl_b");
492465

493466
uint32_t num_clusters = 1;
494467
for (uint32_t i = 0; i < mach_topology.cores; i++) {

0 commit comments

Comments
 (0)