Skip to content

Commit 6c8c816

Browse files
[libc] Fix feature check for riscv (#145169)
This PR fixes the feature detection for RISC-V floating-point support in LLVM's libc implementation. The `__riscv_flen` macro represents the floating-point register width in bits (32, 64, or 128). Since Extension D is specifically documented as implying F, we can use simple >= comparisons to detect them. For half-precision support, the implementation checks for the Zfhmin extension as RVA22 and RVA23 profiles only require Zfhmin rather than the full Zfh extension. Zfh also implies Zfhmin, so checking for Zfhmin should cover all cases.
1 parent 0c47628 commit 6c8c816

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

libc/src/__support/macros/properties/cpu_features.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,15 @@
6161

6262
#if defined(__riscv_flen)
6363
// https://github.com/riscv-non-isa/riscv-c-api-doc/blob/main/src/c-api.adoc
64-
#if (__riscv_flen & 0x10)
64+
#if (__riscv_arch_test && __riscv_zfhmin)
6565
#define LIBC_TARGET_CPU_HAS_RISCV_FPU_HALF
6666
#define LIBC_TARGET_CPU_HAS_FPU_HALF
6767
#endif // LIBC_TARGET_CPU_HAS_RISCV_FPU_HALF
68-
#if (__riscv_flen & 0x20)
68+
#if (__riscv_flen >= 32)
6969
#define LIBC_TARGET_CPU_HAS_RISCV_FPU_FLOAT
7070
#define LIBC_TARGET_CPU_HAS_FPU_FLOAT
7171
#endif // LIBC_TARGET_CPU_HAS_RISCV_FPU_FLOAT
72-
#if (__riscv_flen & 0x40)
72+
#if (__riscv_flen >= 64)
7373
#define LIBC_TARGET_CPU_HAS_RISCV_FPU_DOUBLE
7474
#define LIBC_TARGET_CPU_HAS_FPU_DOUBLE
7575
#endif // LIBC_TARGET_CPU_HAS_RISCV_FPU_DOUBLE

0 commit comments

Comments
 (0)