[libc-commits] [libc] 6edad0c - [libc][RISCV] Let RISCV64 targets test implementations with and without FMA.

Tue Ly via libc-commits libc-commits at lists.llvm.org
Thu Apr 6 06:24:05 PDT 2023


Author: Tue Ly
Date: 2023-04-06T09:23:48-04:00
New Revision: 6edad0c8f04fc4625570bf8513c20b14961f749e

URL: https://github.com/llvm/llvm-project/commit/6edad0c8f04fc4625570bf8513c20b14961f749e
DIFF: https://github.com/llvm/llvm-project/commit/6edad0c8f04fc4625570bf8513c20b14961f749e.diff

LOG: [libc][RISCV] Let RISCV64 targets test implementations with and without FMA.

Let RISCV64 targets math implementations with and without FMA
automatically.

Reviewed By: michaelrj

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

Added: 
    

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

Removed: 
    


################################################################################
diff  --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake
index c96d6f3fb51fd..a1d3dc4b567aa 100644
--- a/libc/cmake/modules/LLVMLibCFlagRules.cmake
+++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake
@@ -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()
 

diff  --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 5ddc67a1db4ca..c3729699e4ef8 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -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")

diff  --git a/libc/src/__support/macros/properties/cpu_features.h b/libc/src/__support/macros/properties/cpu_features.h
index 9884d561195f4..827146f706c07 100644
--- a/libc/src/__support/macros/properties/cpu_features.h
+++ b/libc/src/__support/macros/properties/cpu_features.h
@@ -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
 


        


More information about the libc-commits mailing list