[libc][RISCV] Let RISCV64 targets test implementations with and without FMA.
authorTue Ly <lntue@google.com>
Thu, 23 Mar 2023 16:06:09 +0000 (12:06 -0400)
committerTue Ly <lntue@google.com>
Thu, 6 Apr 2023 13:23:48 +0000 (09:23 -0400)
Let RISCV64 targets math implementations with and without FMA
automatically.

Reviewed By: michaelrj

Differential Revision: https://reviews.llvm.org/D146730

libc/cmake/modules/LLVMLibCFlagRules.cmake
libc/cmake/modules/LLVMLibCObjectRules.cmake
libc/src/__support/macros/properties/cpu_features.h

index c96d6f3..a1d3dc4 100644 (file)
@@ -134,7 +134,8 @@ set(FMA_OPT_FLAG "FMA_OPT")
 set(ROUND_OPT_FLAG "ROUND_OPT")
 
 # Skip FMA_OPT flag for targets that don't support fma.
-if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")))
+if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
+       LIBC_TARGET_ARCHITECTURE_IS_RISCV64))
   set(SKIP_FLAG_EXPANSION_FMA_OPT TRUE)
 endif()
 
index 5ddc67a..c372969 100644 (file)
@@ -5,7 +5,8 @@ function(_get_common_compile_options output_var flags)
   if(${fma} LESS 0)
     list(FIND flags "${FMA_OPT_FLAG}__ONLY" fma)
   endif()
-  if((${fma} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "FMA"))
+  if((${fma} GREATER -1) AND (LIBC_TARGET_ARCHITECTURE_IS_RISCV64 OR
+                              (LIBC_CPU_FEATURES MATCHES "FMA")))
     set(ADD_FMA_FLAG TRUE)
   endif()
 
@@ -39,8 +40,12 @@ function(_get_common_compile_options output_var flags)
       list(APPEND compile_options "-Wthread-safety")
     endif()
     if(ADD_FMA_FLAG)
-      list(APPEND compile_options "-mavx2")
-      list(APPEND compile_options "-mfma")
+      if(LIBC_TARGET_ARCHITECTURE_IS_X86)
+        list(APPEND compile_options "-mavx2")
+        list(APPEND compile_options "-mfma")
+      elseif(LIBC_TARGET_ARCHITECTURE_IS_RISCV64)
+        list(APPEND compile_option "-D__LIBC_RISCV_USE_FMA")
+      endif()
     endif()
     if(ADD_SSE4_2_FLAG)
       list(APPEND compile_options "-msse4.2")
index 9884d56..827146f 100644 (file)
@@ -37,7 +37,7 @@
 #endif
 
 #if defined(__ARM_FEATURE_FMA) || defined(__AVX2__) || defined(__FMA__) ||     \
-    defined(__riscv)
+    defined(__LIBC_RISCV_USE_FMA)
 #define LIBC_TARGET_CPU_HAS_FMA
 #endif