Skip to content

Commit 81bc2e0

Browse files
committed
Add SME vector length detect
- cpuinfo_get_max_arm_sme_length() returns svl vector length in bits - Display length of SME vectors in isa-tool SME may be enabled on cpus that do not have SVE
1 parent 39ea79a commit 81bc2e0

File tree

3 files changed

+29
-0
lines changed

3 files changed

+29
-0
lines changed

include/cpuinfo.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1700,6 +1700,7 @@ struct cpuinfo_arm_isa {
17001700
bool sme_b16b16;
17011701
bool sme_f16f16;
17021702
uint32_t svelen;
1703+
uint32_t smelen;
17031704
#endif
17041705
bool rdm;
17051706
bool fp16arith;
@@ -2081,6 +2082,15 @@ static inline uint32_t cpuinfo_get_max_arm_sve_length(void) {
20812082
#endif
20822083
}
20832084

2085+
// Function to get the max SME vector length on ARM CPU's which support SME.
2086+
static inline uint32_t cpuinfo_get_max_arm_sme_length(void) {
2087+
#if CPUINFO_ARCH_ARM64
2088+
return cpuinfo_isa.smelen * 8; // bytes * 8 = bit length(vector length)
2089+
#else
2090+
return 0;
2091+
#endif
2092+
}
2093+
20842094
static inline bool cpuinfo_has_arm_sme(void) {
20852095
#if CPUINFO_ARCH_ARM64
20862096
return cpuinfo_isa.sme;

src/arm/linux/aarch64-isa.c

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,4 +191,22 @@ void cpuinfo_arm64_linux_decode_isa_from_proc_cpuinfo(
191191
// Mask out the SVE vector length bits
192192
isa->svelen = ret & PR_SVE_VL_LEN_MASK;
193193
}
194+
195+
#ifndef PR_SME_GET_VL
196+
#define PR_SME_GET_VL 64
197+
#endif
198+
199+
#ifndef PR_SME_VL_LEN_MASK
200+
#define PR_SME_VL_LEN_MASK 0xffff
201+
#endif
202+
203+
ret = prctl(PR_SME_GET_VL);
204+
if (ret < 0) {
205+
cpuinfo_log_warning("No SME support on this machine");
206+
isa->smelen = 0; // Assume no SME support if the call fails
207+
} else {
208+
// Mask out the SME vector length bits
209+
isa->smelen = ret & PR_SME_VL_LEN_MASK;
210+
}
194211
}
212+

tools/isa-info.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ int main(int argc, char** argv) {
178178

179179
printf("ARM SVE Capabilities:\n");
180180
printf("\tSVE max length: %d\n", cpuinfo_get_max_arm_sve_length());
181+
printf("\tSME max length: %d\n", cpuinfo_get_max_arm_sme_length());
181182

182183
printf("Cryptography extensions:\n");
183184
printf("\tAES: %s\n", cpuinfo_has_arm_aes() ? "yes" : "no");

0 commit comments

Comments
 (0)