[v1.05][ARM] Another try at properly implement SVE detection

This commit is contained in:
Dr-Noob
2024-08-06 08:57:37 +01:00
parent 26af5ff83e
commit f6cdabe973
3 changed files with 19 additions and 7 deletions

View File

@@ -42,6 +42,11 @@ ifneq ($(OS),Windows_NT)
HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_COMMON)soc.h $(SRC_DIR)soc.h $(SRC_COMMON)pci.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h HEADERS += $(COMMON_HDR) $(SRC_DIR)midr.h $(SRC_DIR)uarch.h $(SRC_COMMON)soc.h $(SRC_DIR)soc.h $(SRC_COMMON)pci.h $(SRC_DIR)udev.c $(SRC_DIR)socs.h
CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 -fstack-protector-all CFLAGS += -DARCH_ARM -Wno-unused-parameter -std=c99 -fstack-protector-all
is_sve_flag_supported := $(shell touch foo.c && $(CC) -march=armv8-a+sve -c foo.c -o foo.o &> /dev/null && echo 'yes'; rm -f foo.c foo.o)
ifeq ($(is_sve_flag_supported), yes)
CFLAGS += -march=armv8-a+sve
endif
ifeq ($(os), Darwin) ifeq ($(os), Darwin)
SOURCE += $(SRC_COMMON)sysctl.c SOURCE += $(SRC_COMMON)sysctl.c
HEADERS += $(SRC_COMMON)sysctl.h HEADERS += $(SRC_COMMON)sysctl.h

View File

@@ -144,15 +144,16 @@ void init_cpu_info(struct cpuInfo* cpu) {
// https://learn.arm.com/learning-paths/servers-and-cloud-computing/sve/sve_basics/#:~:text=Using%20a%20text%20editor%20of%20your%20choice%2C%20copy,svcntb%28%29%29%3B%20%7D%20This%20program%20prints%20the%20vector%20length // https://learn.arm.com/learning-paths/servers-and-cloud-computing/sve/sve_basics/#:~:text=Using%20a%20text%20editor%20of%20your%20choice%2C%20copy,svcntb%28%29%29%3B%20%7D%20This%20program%20prints%20the%20vector%20length
static inline uint32_t sve_cntb(void) { static inline uint32_t sve_cntb(void) {
#ifdef __ARM_FEATURE_SVE
uint32_t x0 = 0; uint32_t x0 = 0;
#ifdef __ARM_FEATURE_SVE
__asm volatile("cntb %0" __asm volatile("cntb %0"
: "=r"(x0)); : "=r"(x0));
printf("cntb=%d\n", x0); printf("cntb=%d\n", x0);
#endif
return x0; return x0;
#else
printBug("sve_cntb: SVE not enabled by the compiler");
return 0;
#endif
} }
@@ -221,8 +222,14 @@ struct features* get_features_info(void) {
feat->SVE2 = false; feat->SVE2 = false;
#endif // ifdef __linux__ #endif // ifdef __linux__
if (feat->SVE || feat->SVE2) if (feat->SVE || feat->SVE2) {
feat->cntb = sve_cntb(); #ifdef __ARM_FEATURE_SVE
feat->cntb = sve_cntb();
#else
printWarn("Hardware supports SVE, but not the compiler");
feat->cntb = 0;
#endif
}
return feat; return feat;
} }

View File

@@ -294,7 +294,7 @@ int get_vpus_width(struct cpuInfo* cpu) {
case UARCH_NEOVERSE_V1: case UARCH_NEOVERSE_V1:
return 256; return 256;
default: default:
if (cpu->feat->SVE) { if (cpu->feat->SVE && cpu->feat->cntb > 0) {
return cpu->feat->cntb * 8; return cpu->feat->cntb * 8;
} }
else if (cpu->feat->NEON) { else if (cpu->feat->NEON) {