From: Tue Ly Date: Thu, 23 Mar 2023 16:06:09 +0000 (-0400) Subject: [libc][RISCV] Let RISCV64 targets test implementations with and without FMA. X-Git-Tag: upstream/17.0.6~12424 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=6edad0c8f04fc4625570bf8513c20b14961f749e;p=platform%2Fupstream%2Fllvm.git [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 --- diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake index c96d6f3..a1d3dc4 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 5ddc67a..c372969 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 9884d56..827146f 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