Skip to content

Instantly share code, notes, and snippets.

@kaityo256
Created January 7, 2021 07:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kaityo256/3b89fbddb2952e12699d089c20ffa416 to your computer and use it in GitHub Desktop.
Save kaityo256/3b89fbddb2952e12699d089c20ffa416 to your computer and use it in GitHub Desktop.
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

$ 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