Skip to content

Commit ce79fe1

Browse files
committed
disable fp16 flags on RISC-V unless BUILD_HFLOAT16=1
The compiler options that enable 16 bit floating point instructions should not be enabled by default when building the RISCV64_ZVL128B and RISCV64_ZVL256B targets. The zfh and zvfh extensions are not part of the 'V' extension and are not required by any of the RVA profiles. There's no guarantee that kernels built with zfh and zvfh will work correctly on fully compliant RVA23U64 devices. To fix the issue we only build the RISCV64_ZVL128B and RISCV64_ZVL256B kernels with the half float flags if BUILD_HFLOAT16=1. We also update the RISC-V dynamic detection code to disable the RISCV64_ZVL128B and RISCV64_ZVL256B kernels at runtime if we've built with DYNAMIC_ARCH=1 and BUILD_HFLOAT16=1 and are running on a device that does not support both Zfh and Zvfh. Fixes: #5428
1 parent 06c09de commit ce79fe1

File tree

4 files changed

+27
-5
lines changed

4 files changed

+27
-5
lines changed

Makefile.prebuild

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ TARGET_FLAGS = -march=rv64imafdcv_zba_zbb_zfh -mabi=lp64d
6464
endif
6565

6666
ifeq ($(TARGET), RISCV64_ZVL256B)
67-
TARGET_FLAGS = -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
67+
TARGET_FLAGS = -march=rv64imafdcv -mabi=lp64d
6868
endif
6969

7070
ifeq ($(TARGET), RISCV64_ZVL128B)
71-
TARGET_FLAGS = -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
71+
TARGET_FLAGS = -march=rv64imafdcv -mabi=lp64d
7272
endif
7373

7474
ifeq ($(TARGET), RISCV64_GENERIC)

Makefile.riscv64

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,22 @@ CCOMMON_OPT += -march=rv64imafdcv_zba_zbb_zfh_zvl512b -mabi=lp64d
77
FCOMMON_OPT += -march=rv64imafdcv_zba_zbb_zfh -mabi=lp64d -static
88
endif
99
ifeq ($(CORE), RISCV64_ZVL256B)
10+
ifeq ($(BUILD_HFLOAT16), 1)
1011
CCOMMON_OPT += -march=rv64imafdcv_zvl256b_zvfh_zfh -mabi=lp64d
1112
FCOMMON_OPT += -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
13+
else
14+
CCOMMON_OPT += -march=rv64imafdcv_zvl256b -mabi=lp64d
15+
FCOMMON_OPT += -march=rv64imafdcv -mabi=lp64d
16+
endif
1217
endif
1318
ifeq ($(CORE), RISCV64_ZVL128B)
14-
CCOMMON_OPT += -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
19+
ifeq ($(BUILD_HFLOAT16), 1)
20+
CCOMMON_OPT += -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
1521
FCOMMON_OPT += -march=rv64imafdcv_zvfh_zfh -mabi=lp64d
22+
else
23+
CCOMMON_OPT += -march=rv64imafdcv -mabi=lp64d
24+
FCOMMON_OPT += -march=rv64imafdcv -mabi=lp64d
25+
endif
1626
endif
1727
ifeq ($(CORE), RISCV64_GENERIC)
1828
CCOMMON_OPT += -march=rv64imafdc -mabi=lp64d

driver/others/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,7 +218,7 @@ mulx.$(SUFFIX) : $(ARCH)/mulx.c
218218
$(CC) $(CFLAGS) -c -DXDOUBLE -UCOMPLEX $< -o $(@F)
219219

220220
detect_riscv64.$(SUFFIX): detect_riscv64.c
221-
$(CC) $(CFLAGS) -c -march=rv64imafdcv_zvfh_zfh $< -o $(@F)
221+
$(CC) $(CFLAGS) -c -march=rv64imafdcv $< -o $(@F)
222222

223223
xerbla.$(PSUFFIX) : xerbla.c
224224
$(CC) $(PFLAGS) -c $< -o $(@F)

driver/others/dynamic_riscv64.c

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ struct riscv_hwprobe {
9797

9898
#define RISCV_HWPROBE_KEY_IMA_EXT_0 4
9999
#define RISCV_HWPROBE_IMA_V (1 << 2)
100+
#define RISCV_HWPROBE_EXT_ZFH (1 << 27)
101+
#define RISCV_HWPROBE_EXT_ZVFH (1 << 30)
100102

101103
#ifndef NR_riscv_hwprobe
102104
#ifndef NR_arch_specific_syscall
@@ -147,6 +149,7 @@ char* gotoblas_corename(void) {
147149
}
148150

149151
static gotoblas_t* get_coretype(void) {
152+
uint64_t vector_mask;
150153
unsigned vlenb = 0;
151154

152155
#if !defined(OS_LINUX)
@@ -165,14 +168,23 @@ static gotoblas_t* get_coretype(void) {
165168
};
166169
int ret = syscall(NR_riscv_hwprobe, pairs, 1, 0, NULL, 0);
167170
if (ret == 0) {
168-
if (!(pairs[0].value & RISCV_HWPROBE_IMA_V))
171+
#if defined(BUILD_HFLOAT16)
172+
vector_mask = (RISCV_HWPROBE_IMA_V | RISCV_HWPROBE_EXT_ZFH | RISCV_HWPROBE_EXT_ZVFH);
173+
#else
174+
vector_mask = RISCV_HWPROBE_IMA_V;
175+
#endif
176+
if ((pairs[0].value & vector_mask) != vector_mask)
169177
return NULL;
170178
} else {
179+
#if defined(BUILD_HFLOAT16)
180+
return NULL;
181+
#else
171182
if (!(getauxval(AT_HWCAP) & DETECT_RISCV64_HWCAP_ISA_V))
172183
return NULL;
173184

174185
if (!detect_riscv64_rvv100())
175186
return NULL;
187+
#endif
176188
}
177189

178190
/*

0 commit comments

Comments
 (0)