Skip to content

Commit 1e83a2f

Browse files
authored
Merge pull request #262 from gonnet/main
Add `sme2` detection for `aarch64`
2 parents a5ff6df + 8f02f6d commit 1e83a2f

File tree

7 files changed

+99
-19
lines changed

7 files changed

+99
-19
lines changed

include/cpuinfo-mock.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ ssize_t CPUINFO_ABI cpuinfo_mock_read(int fd, void* buffer, size_t capacity);
6060
void CPUINFO_ABI cpuinfo_set_hwcap(uint32_t hwcap);
6161
#endif
6262
#if CPUINFO_ARCH_ARM
63-
void CPUINFO_ABI cpuinfo_set_hwcap2(uint32_t hwcap2);
63+
void CPUINFO_ABI cpuinfo_set_hwcap2(uint64_t hwcap2);
6464
#endif
6565
#endif
6666

include/cpuinfo.h

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1671,6 +1671,12 @@ struct cpuinfo_arm_isa {
16711671
bool sve2;
16721672
bool i8mm;
16731673
bool sme;
1674+
bool sme2;
1675+
bool sme2p1;
1676+
bool sme_i16i32;
1677+
bool sme_bi32i32;
1678+
bool sme_b16b16;
1679+
bool sme_f16f16;
16741680
uint32_t svelen;
16751681
#endif
16761682
bool rdm;
@@ -2061,6 +2067,54 @@ static inline bool cpuinfo_has_arm_sme(void) {
20612067
#endif
20622068
}
20632069

2070+
static inline bool cpuinfo_has_arm_sme2(void) {
2071+
#if CPUINFO_ARCH_ARM64
2072+
return cpuinfo_isa.sme2;
2073+
#else
2074+
return false;
2075+
#endif
2076+
}
2077+
2078+
static inline bool cpuinfo_has_arm_sme2p1(void) {
2079+
#if CPUINFO_ARCH_ARM64
2080+
return cpuinfo_isa.sme2p1;
2081+
#else
2082+
return false;
2083+
#endif
2084+
}
2085+
2086+
static inline bool cpuinfo_has_arm_sme_i16i32(void) {
2087+
#if CPUINFO_ARCH_ARM64
2088+
return cpuinfo_isa.sme_i16i32;
2089+
#else
2090+
return false;
2091+
#endif
2092+
}
2093+
2094+
static inline bool cpuinfo_has_arm_sme_bi32i32(void) {
2095+
#if CPUINFO_ARCH_ARM64
2096+
return cpuinfo_isa.sme_bi32i32;
2097+
#else
2098+
return false;
2099+
#endif
2100+
}
2101+
2102+
static inline bool cpuinfo_has_arm_sme_b16b16(void) {
2103+
#if CPUINFO_ARCH_ARM64
2104+
return cpuinfo_isa.sme_b16b16;
2105+
#else
2106+
return false;
2107+
#endif
2108+
}
2109+
2110+
static inline bool cpuinfo_has_arm_sme_f16f16(void) {
2111+
#if CPUINFO_ARCH_ARM64
2112+
return cpuinfo_isa.sme_f16f16;
2113+
#else
2114+
return false;
2115+
#endif
2116+
}
2117+
20642118
#if CPUINFO_ARCH_RISCV32 || CPUINFO_ARCH_RISCV64
20652119
/* This structure is not a part of stable API. Use cpuinfo_has_riscv_* functions
20662120
* instead. */

src/arm/linux/aarch32-isa.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ void cpuinfo_set_wcid(uint32_t wcid) {
2424

2525
void cpuinfo_arm_linux_decode_isa_from_proc_cpuinfo(
2626
uint32_t features,
27-
uint32_t features2,
27+
uint64_t features2,
2828
uint32_t midr,
2929
uint32_t architecture_version,
3030
uint32_t architecture_flags,

src/arm/linux/aarch64-isa.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
void cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
99
uint32_t features,
10-
uint32_t features2,
10+
uint64_t features2,
1111
uint32_t midr,
1212
const struct cpuinfo_arm_chipset chipset[restrict static 1],
1313
struct cpuinfo_arm_isa isa[restrict static 1]) {
@@ -147,6 +147,24 @@ void cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
147147
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME) {
148148
isa->sme = true;
149149
}
150+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME2) {
151+
isa->sme2 = true;
152+
}
153+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME2P1) {
154+
isa->sme2p1 = true;
155+
}
156+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME_I16I32) {
157+
isa->sme_i16i32 = true;
158+
}
159+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME_BI32I32) {
160+
isa->sme_bi32i32 = true;
161+
}
162+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME_B16B16) {
163+
isa->sme_b16b16 = true;
164+
}
165+
if (features2 & CPUINFO_ARM_LINUX_FEATURE2_SME_F16F16) {
166+
isa->sme_f16f16 = true;
167+
}
150168
// SVEBF16 is set iff SVE and BF16 are both supported, but the SVEBF16
151169
// feature flag was added in Linux kernel before the BF16 feature flag,
152170
// so we check for either.

src/arm/linux/api.h

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ struct cpuinfo_arm_linux_proc_cpuinfo_cache {
138138
#define CPUINFO_ARM_LINUX_FEATURE2_RNG UINT32_C(0x00010000)
139139
#define CPUINFO_ARM_LINUX_FEATURE2_BTI UINT32_C(0x00020000)
140140
#define CPUINFO_ARM_LINUX_FEATURE2_SME UINT32_C(0x00800000)
141+
#define CPUINFO_ARM_LINUX_FEATURE2_SME2 UINT64_C(0x0000002000000000)
142+
#define CPUINFO_ARM_LINUX_FEATURE2_SME2P1 UINT64_C(0x0000004000000000)
143+
#define CPUINFO_ARM_LINUX_FEATURE2_SME_I16I32 UINT64_C(0x0000008000000000)
144+
#define CPUINFO_ARM_LINUX_FEATURE2_SME_BI32I32 UINT64_C(0x0000010000000000)
145+
#define CPUINFO_ARM_LINUX_FEATURE2_SME_B16B16 UINT64_C(0x0000020000000000)
146+
#define CPUINFO_ARM_LINUX_FEATURE2_SME_F16F16 UINT64_C(0x0000040000000000)
141147
#endif
142148

143149
#define CPUINFO_ARM_LINUX_VALID_ARCHITECTURE UINT32_C(0x00010000)
@@ -173,7 +179,7 @@ struct cpuinfo_arm_linux_processor {
173179
struct cpuinfo_arm_linux_proc_cpuinfo_cache proc_cpuinfo_cache;
174180
#endif
175181
uint32_t features;
176-
uint32_t features2;
182+
uint64_t features2;
177183
/**
178184
* Main ID Register value.
179185
*/
@@ -296,14 +302,14 @@ CPUINFO_INTERNAL bool cpuinfo_arm_linux_parse_proc_cpuinfo(
296302
#if CPUINFO_ARCH_ARM
297303
CPUINFO_INTERNAL bool cpuinfo_arm_linux_hwcap_from_getauxval(
298304
uint32_t hwcap[restrict static 1],
299-
uint32_t hwcap2[restrict static 1]);
305+
uint64_t hwcap2[restrict static 1]);
300306
CPUINFO_INTERNAL bool cpuinfo_arm_linux_hwcap_from_procfs(
301307
uint32_t hwcap[restrict static 1],
302-
uint32_t hwcap2[restrict static 1]);
308+
uint64_t hwcap2[restrict static 1]);
303309

304310
CPUINFO_INTERNAL void cpuinfo_arm_linux_decode_isa_from_proc_cpuinfo(
305311
uint32_t features,
306-
uint32_t features2,
312+
uint64_t features2,
307313
uint32_t midr,
308314
uint32_t architecture_version,
309315
uint32_t architecture_flags,
@@ -312,11 +318,11 @@ CPUINFO_INTERNAL void cpuinfo_arm_linux_decode_isa_from_proc_cpuinfo(
312318
#elif CPUINFO_ARCH_ARM64
313319
CPUINFO_INTERNAL void cpuinfo_arm_linux_hwcap_from_getauxval(
314320
uint32_t hwcap[restrict static 1],
315-
uint32_t hwcap2[restrict static 1]);
321+
uint64_t hwcap2[restrict static 1]);
316322

317323
CPUINFO_INTERNAL void cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
318324
uint32_t features,
319-
uint32_t features2,
325+
uint64_t features2,
320326
uint32_t midr,
321327
const struct cpuinfo_arm_chipset chipset[restrict static 1],
322328
struct cpuinfo_arm_isa isa[restrict static 1]);

src/arm/linux/hwcap.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,16 @@ void cpuinfo_set_hwcap(uint32_t hwcap) {
3131
mock_hwcap = hwcap;
3232
}
3333

34-
static uint32_t mock_hwcap2 = 0;
35-
void cpuinfo_set_hwcap2(uint32_t hwcap2) {
34+
static uint64_t mock_hwcap2 = 0;
35+
void cpuinfo_set_hwcap2(uint64_t hwcap2) {
3636
mock_hwcap2 = hwcap2;
3737
}
3838
#endif
3939

4040
#if CPUINFO_ARCH_ARM
4141
typedef unsigned long (*getauxval_function_t)(unsigned long);
4242

43-
bool cpuinfo_arm_linux_hwcap_from_getauxval(uint32_t hwcap[restrict static 1], uint32_t hwcap2[restrict static 1]) {
43+
bool cpuinfo_arm_linux_hwcap_from_getauxval(uint32_t hwcap[restrict static 1], uint64_t hwcap2[restrict static 1]) {
4444
#if CPUINFO_MOCK
4545
*hwcap = mock_hwcap;
4646
*hwcap2 = mock_hwcap2;
@@ -83,13 +83,13 @@ bool cpuinfo_arm_linux_hwcap_from_getauxval(uint32_t hwcap[restrict static 1], u
8383
}
8484

8585
#ifdef __ANDROID__
86-
bool cpuinfo_arm_linux_hwcap_from_procfs(uint32_t hwcap[restrict static 1], uint32_t hwcap2[restrict static 1]) {
86+
bool cpuinfo_arm_linux_hwcap_from_procfs(uint32_t hwcap[restrict static 1], uint64_t hwcap2[restrict static 1]) {
8787
#if CPUINFO_MOCK
8888
*hwcap = mock_hwcap;
8989
*hwcap2 = mock_hwcap2;
9090
return true;
9191
#else
92-
uint32_t hwcaps[2] = {0, 0};
92+
uint64_t hwcaps[2] = {0, 0};
9393
bool result = false;
9494
int file = -1;
9595

@@ -113,7 +113,7 @@ bool cpuinfo_arm_linux_hwcap_from_procfs(uint32_t hwcap[restrict static 1], uint
113113
hwcaps[0] = (uint32_t)elf_auxv.a_un.a_val;
114114
break;
115115
case AT_HWCAP2:
116-
hwcaps[1] = (uint32_t)elf_auxv.a_un.a_val;
116+
hwcaps[1] = (uint64_t)elf_auxv.a_un.a_val;
117117
break;
118118
}
119119
} else {
@@ -141,13 +141,13 @@ bool cpuinfo_arm_linux_hwcap_from_procfs(uint32_t hwcap[restrict static 1], uint
141141
}
142142
#endif /* __ANDROID__ */
143143
#elif CPUINFO_ARCH_ARM64
144-
void cpuinfo_arm_linux_hwcap_from_getauxval(uint32_t hwcap[restrict static 1], uint32_t hwcap2[restrict static 1]) {
144+
void cpuinfo_arm_linux_hwcap_from_getauxval(uint32_t hwcap[restrict static 1], uint64_t hwcap2[restrict static 1]) {
145145
#if CPUINFO_MOCK
146146
*hwcap = mock_hwcap;
147147
*hwcap2 = mock_hwcap2;
148148
#else
149149
*hwcap = (uint32_t)getauxval(AT_HWCAP);
150-
*hwcap2 = (uint32_t)getauxval(AT_HWCAP2);
150+
*hwcap2 = (uint64_t)getauxval(AT_HWCAP2);
151151
return;
152152
#endif
153153
}

src/arm/linux/init.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,8 @@ void cpuinfo_arm_linux_init(void) {
247247
#endif
248248

249249
#if CPUINFO_ARCH_ARM
250-
uint32_t isa_features = 0, isa_features2 = 0;
250+
uint32_t isa_features = 0;
251+
uint64_t isa_features2 = 0;
251252
#ifdef __ANDROID__
252253
/*
253254
* On Android before API 20, libc.so does not provide getauxval
@@ -299,7 +300,8 @@ void cpuinfo_arm_linux_init(void) {
299300
&chipset,
300301
&cpuinfo_isa);
301302
#elif CPUINFO_ARCH_ARM64
302-
uint32_t isa_features = 0, isa_features2 = 0;
303+
uint32_t isa_features = 0;
304+
uint64_t isa_features2 = 0;
303305
/* getauxval is always available on ARM64 Android */
304306
cpuinfo_arm_linux_hwcap_from_getauxval(&isa_features, &isa_features2);
305307
cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(

0 commit comments

Comments
 (0)