Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Check availability and length of SVE
#include <cstdio>
#ifdef __ARM_FEATURE_SVE
#include <arm_sve.h>
#endif
int main() {
int n = 0;
#ifdef __ARM_FEATURE_SVE
n = svcntb() * 8;
#endif
if (n) {
printf("SVE is available. The length is %d bits\n", n);
} else {
printf("SVE is unavailable.\n");
}
}
@kaityo256
Copy link
Author

kaityo256 commented Jan 7, 2021

$ aarch64-linux-gnu-g++ -static sve_check.cpp 
$ qemu-aarch64 ./a.out
SVE is unavailable.

$ aarch64-linux-gnu-g++ -march=armv8-a+sve -static sve_check.cpp 
$ qemu-aarch64 -cpu max,sve128=on ./a.out
SVE is available. The length is 128 bits
$ qemu-aarch64 -cpu max,sve256=on ./a.out
SVE is available. The length is 256 bits
$ qemu-aarch64 -cpu max,sve512=on ./a.out
SVE is available. The length is 512 bits
$ qemu-aarch64 -cpu max,sve=off ./a.out
qemu: uncaught target signal 4 (Illegal instruction) - core dumped
Illegal instruction

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment