Skip to content

Commit 756e515

Browse files
[libc] Simplify fma handling for riscv (#149673)
This PR simplifies how we enable the different fma configs for riscv: 1. Removes __LIBC_RISCV_USE_FMA define 2. Checks if __riscv_flen is defined to set LIBC_TARGET_CPU_HAS_FMA As a bonus, we enable *FMA_OPT tests for rv32, so any rv32 hardware that doesn't implement the f/d extensions is also covered by the tests.
1 parent 07100c6 commit 756e515

File tree

4 files changed

+5
-5
lines changed

4 files changed

+5
-5
lines changed

libc/cmake/modules/LLVMLibCArchitectures.cmake

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,11 @@ elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "x86_64")
153153
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "i386")
154154
set(LIBC_TARGET_ARCHITECTURE_IS_X86 TRUE)
155155
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv64")
156+
set(LIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV TRUE)
156157
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV64 TRUE)
157158
set(LIBC_TARGET_ARCHITECTURE "riscv")
158159
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "riscv32")
160+
set(LIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV TRUE)
159161
set(LIBC_TARGET_ARCHITECTURE_IS_RISCV32 TRUE)
160162
set(LIBC_TARGET_ARCHITECTURE "riscv")
161163
elseif(LIBC_TARGET_ARCHITECTURE STREQUAL "amdgpu")

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ endif()
1313
function(_get_compile_options_from_flags output_var)
1414
set(compile_options "")
1515

16-
if(LIBC_TARGET_ARCHITECTURE_IS_RISCV64 OR(LIBC_CPU_FEATURES MATCHES "FMA"))
16+
if(LIBC_CPU_FEATURES MATCHES "FMA")
1717
check_flag(ADD_FMA_FLAG ${FMA_OPT_FLAG} ${ARGN})
1818
endif()
1919
check_flag(ADD_ROUND_OPT_FLAG ${ROUND_OPT_FLAG} ${ARGN})
@@ -25,8 +25,6 @@ function(_get_compile_options_from_flags output_var)
2525
if(LIBC_TARGET_ARCHITECTURE_IS_X86_64)
2626
list(APPEND compile_options "-mavx2")
2727
list(APPEND compile_options "-mfma")
28-
elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
29-
list(APPEND compile_options "-D__LIBC_RISCV_USE_FMA")
3028
endif()
3129
# For clang, we will build the math functions with `-fno-math-errno` so that
3230
# __builtin_fma* will generate the fused-mutliply-add instructions. We

libc/cmake/modules/LLVMLibCFlagRules.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ set(MISC_MATH_BASIC_OPS_OPT_FLAG "MISC_MATH_BASIC_OPS_OPT")
270270
# Skip FMA_OPT flag for targets that don't support fma.
271271
if(NOT DEFINED SKIP_FLAG_EXPANSION_FMA_OPT)
272272
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86_64 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
273-
LIBC_TARGET_ARCHITECTURE_IS_RISCV64))
273+
LIBC_TARGET_ARCHITECTURE_IS_ANY_RISCV))
274274
set(SKIP_FLAG_EXPANSION_FMA_OPT TRUE)
275275
endif()
276276
endif()

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
#endif
8282

8383
#if defined(__ARM_FEATURE_FMA) || (defined(__AVX2__) && defined(__FMA__)) || \
84-
defined(__NVPTX__) || defined(__AMDGPU__) || defined(__LIBC_RISCV_USE_FMA)
84+
defined(__NVPTX__) || defined(__AMDGPU__) || defined(__riscv_flen)
8585
#define LIBC_TARGET_CPU_HAS_FMA
8686
// Provide a more fine-grained control of FMA instruction for ARM targets.
8787
#if defined(LIBC_TARGET_CPU_HAS_FPU_HALF)

0 commit comments

Comments
 (0)