Hello, I used the following guide in order to write code for CPU feature detection at runtime: https://community.arm.com/arm-community-blogs/b/operating-systems-blog/posts/runtime-detection-of-cpu-features-on-an-armv8-a-cpu I modified the HWCAP example so that it reports SVE features:
#include <stdio.h> #include <sys/auxv.h> #include <asm/hwcap.h> int main() { long hwcaps = getauxval(AT_HWCAP); printf("FP: %d\n", hwcaps & HWCAP_FP); printf("SVE: %d\n", hwcaps & HWCAP_SVE); printf("SVE2: %d\n", hwcaps & HWCAP2_SVE2); printf("SVEF32MM: %d\n", hwcaps & HWCAP2_SVEF32MM); printf("SVEF64MM: %d\n", hwcaps & HWCAP2_SVEF64MM); return 0; }
When I run the program on RPi4, I get strange values for SVE2 and SVEF64MM:
FP: 1 SVE: 0 SVE2: 2 SVEF32MM: 0 SVEF64MM: 2048
I am supposed to get 0es. Why am I getting 2 and 2048?
I figured out what the problem is. I should call hwcaps = getauxval(AT_HWCAP2); before checking for HWCAP2 features.
hwcaps = getauxval(AT_HWCAP2);
HWCAP2
Thank you for coming back to let us know the solution you discovered :)