[libc-commits] [libc] [libc] change PREFER_GENERIC to EXPLICIT_SIMD_OPT (PR #79486)

Schrodinger ZHU Yifan via libc-commits libc-commits at lists.llvm.org
Fri Jan 26 08:57:13 PST 2024


https://github.com/SchrodingerZhu updated https://github.com/llvm/llvm-project/pull/79486

>From 671326e55715c7299446c3ef5d81bb80c2494fb6 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Thu, 25 Jan 2024 13:53:19 -0500
Subject: [PATCH 1/3] [libc] change PREFER_GENERIC to EXPLICIT_SIMD_OPT

---
 libc/cmake/modules/LLVMLibCFlagRules.cmake   |  2 +-
 libc/cmake/modules/LLVMLibCObjectRules.cmake | 18 +++++++++---------
 libc/src/__support/HashTable/CMakeLists.txt  |  2 +-
 libc/src/__support/HashTable/bitmask.h       |  2 +-
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake
index 7d663f0682e1f2..3e0776e04596c9 100644
--- a/libc/cmake/modules/LLVMLibCFlagRules.cmake
+++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake
@@ -134,7 +134,7 @@ set(FMA_OPT_FLAG "FMA_OPT")
 set(ROUND_OPT_FLAG "ROUND_OPT")
 # This flag will define macros that gated away vectorization code such that
 # one can always test the fallback generic code path.
-set(PREFER_GENERIC_FLAG "PREFER_GENERIC")
+set(EXPLICIT_SIMD_OPT_FLAG "EXPLICIT_SIMD_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")) OR
diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake
index 667d7548f78316..c5c9f7c09a144b 100644
--- a/libc/cmake/modules/LLVMLibCObjectRules.cmake
+++ b/libc/cmake/modules/LLVMLibCObjectRules.cmake
@@ -18,12 +18,12 @@ function(_get_common_compile_options output_var flags)
     set(ADD_SSE4_2_FLAG TRUE)
   endif()
 
-  list(FIND flags ${PREFER_GENERIC_FLAG} prefer_generic)
-  if(${prefer_generic} LESS 0)
-    list(FIND flags "${PREFER_GENERIC_FLAG}__ONLY" prefer_generic)
+  list(FIND flags ${EXPLICIT_SIMD_OPT_FLAG} explicit_simd)
+  if(${explicit_simd} LESS 0)
+    list(FIND flags "${EXPLICIT_SIMD_OPT_FLAG}__ONLY" explicit_simd)
   endif()
-  if(${prefer_generic} GREATER -1)
-    set(ADD_PREFER_GENERIC_FLAG TRUE)
+  if(${explicit_simd} GREATER -1)
+    set(ADD_EXPLICIT_SIMD_OPT_FLAG TRUE)
   endif()
 
   set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
@@ -73,8 +73,8 @@ function(_get_common_compile_options output_var flags)
     if(ADD_SSE4_2_FLAG)
       list(APPEND compile_options "-msse4.2")
     endif()
-    if(ADD_PREFER_GENERIC_FLAG)
-      list(APPEND compile_options "-D__LIBC_PREFER_GENERIC")
+    if(ADD_EXPLICIT_SIMD_OPT_FLAG)
+      list(APPEND compile_options "-D__LIBC_EXPLICIT_SIMD_OPT")
     endif()
   elseif(MSVC)
     list(APPEND compile_options "/EHs-c-")
@@ -82,8 +82,8 @@ function(_get_common_compile_options output_var flags)
     if(ADD_FMA_FLAG)
       list(APPEND compile_options "/arch:AVX2")
     endif()
-    if(ADD_PREFER_GENERIC_FLAG)
-      list(APPEND compile_options "/D__LIBC_PREFER_GENERIC")
+    if(ADD_EXPLICIT_SIMD_OPT_FLAG)
+      list(APPEND compile_options "/D__LIBC_EXPLICIT_SIMD_OPT")
     endif()
   endif()
   if (LIBC_TARGET_ARCHITECTURE_IS_GPU)
diff --git a/libc/src/__support/HashTable/CMakeLists.txt b/libc/src/__support/HashTable/CMakeLists.txt
index dce37fdb5143ff..6fa90c780c90d3 100644
--- a/libc/src/__support/HashTable/CMakeLists.txt
+++ b/libc/src/__support/HashTable/CMakeLists.txt
@@ -3,7 +3,7 @@ add_header_library(
   HDRS
     bitmask.h
   FLAGS
-    PREFER_GENERIC
+    EXPLICIT_SIMD_OPT
   DEPENDS
     libc.src.__support.common
     libc.src.__support.CPP.bit
diff --git a/libc/src/__support/HashTable/bitmask.h b/libc/src/__support/HashTable/bitmask.h
index f97a7bccde3276..afdf7c2c43bfba 100644
--- a/libc/src/__support/HashTable/bitmask.h
+++ b/libc/src/__support/HashTable/bitmask.h
@@ -83,7 +83,7 @@ template <class BitMask> struct IteratableBitMaskAdaptor : public BitMask {
 } // namespace internal
 } // namespace LIBC_NAMESPACE
 
-#if defined(LIBC_TARGET_CPU_HAS_SSE2) && !defined(__LIBC_PREFER_GENERIC)
+#if defined(LIBC_TARGET_CPU_HAS_SSE2) && defined(__LIBC_EXPLICIT_SIMD_OPT)
 #include "sse2/bitmask_impl.inc"
 #else
 #include "generic/bitmask_impl.inc"

>From 3b6cd128bbee90c845de2277225062e00ff333c8 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Thu, 25 Jan 2024 13:56:36 -0500
Subject: [PATCH 2/3] fix doc

---
 libc/cmake/modules/LLVMLibCFlagRules.cmake | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake
index 3e0776e04596c9..5393107d18596b 100644
--- a/libc/cmake/modules/LLVMLibCFlagRules.cmake
+++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake
@@ -132,8 +132,7 @@ endfunction(get_fq_dep_list_without_flag)
 # Special flags
 set(FMA_OPT_FLAG "FMA_OPT")
 set(ROUND_OPT_FLAG "ROUND_OPT")
-# This flag will define macros that gated away vectorization code such that
-# one can always test the fallback generic code path.
+# This flag controls whether we use explicit SIMD instructions or not.
 set(EXPLICIT_SIMD_OPT_FLAG "EXPLICIT_SIMD_OPT")
 
 # Skip FMA_OPT flag for targets that don't support fma.

>From 38fb2c4a17ceeb7c2b52dfda763fbda9bc957c77 Mon Sep 17 00:00:00 2001
From: Schrodinger ZHU Yifan <yifanzhu at rochester.edu>
Date: Fri, 26 Jan 2024 11:56:56 -0500
Subject: [PATCH 3/3] address CR

---
 libc/cmake/modules/LLVMLibCFlagRules.cmake | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake
index 5393107d18596b..9a48d38b02893e 100644
--- a/libc/cmake/modules/LLVMLibCFlagRules.cmake
+++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake
@@ -141,6 +141,12 @@ if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) O
   set(SKIP_FLAG_EXPANSION_FMA_OPT TRUE)
 endif()
 
+# Skip EXPLICIT_SIMD_OPT flag for targets that don't support SSE2.
+# Note: one may want to revisit it if they want to control other explicit SIMD
+if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
+  set(SKIP_FLAG_EXPANSION_EXPLICIT_SIMD_OPT TRUE)
+endif()
+
 # Skip ROUND_OPT flag for targets that don't support SSE 4.2.
 if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")))
   set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)



More information about the libc-commits mailing list