From f6cdabe973a284dddf9783c48c861329e5d15f72 Mon Sep 17 00:00:00 2001 From: Dr-Noob Date: Tue, 6 Aug 2024 08:57:37 +0100 Subject: [PATCH] [v1.05][ARM] Another try at properly implement SVE detection --- Makefile | 5 +++++ src/arm/midr.c | 19 +++++++++++++------ src/arm/uarch.c | 2 +- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/Makefile b/Makefile index 4606f97..8c3b9e6 100644 --- a/Makefile +++ b/Makefile @@ -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 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) SOURCE += $(SRC_COMMON)sysctl.c HEADERS += $(SRC_COMMON)sysctl.h diff --git a/src/arm/midr.c b/src/arm/midr.c index ee677ea..44f25d1 100644 --- a/src/arm/midr.c +++ b/src/arm/midr.c @@ -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 static inline uint32_t sve_cntb(void) { + #ifdef __ARM_FEATURE_SVE uint32_t x0 = 0; - -#ifdef __ARM_FEATURE_SVE __asm volatile("cntb %0" : "=r"(x0)); printf("cntb=%d\n", x0); -#endif - 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; #endif // ifdef __linux__ - if (feat->SVE || feat->SVE2) - feat->cntb = sve_cntb(); + if (feat->SVE || feat->SVE2) { + #ifdef __ARM_FEATURE_SVE + feat->cntb = sve_cntb(); + #else + printWarn("Hardware supports SVE, but not the compiler"); + feat->cntb = 0; + #endif + } return feat; } diff --git a/src/arm/uarch.c b/src/arm/uarch.c index 802434a..32d6e33 100644 --- a/src/arm/uarch.c +++ b/src/arm/uarch.c @@ -294,7 +294,7 @@ int get_vpus_width(struct cpuInfo* cpu) { case UARCH_NEOVERSE_V1: return 256; default: - if (cpu->feat->SVE) { + if (cpu->feat->SVE && cpu->feat->cntb > 0) { return cpu->feat->cntb * 8; } else if (cpu->feat->NEON) {