Skip to content

Commit 517063e

Browse files
[libc] change PREFER_GENERIC to EXPLICIT_SIMD_OPT (#79486)
fixes #79474.
1 parent e976053 commit 517063e

File tree

4 files changed

+19
-14
lines changed

4 files changed

+19
-14
lines changed

libc/cmake/modules/LLVMLibCFlagRules.cmake

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,16 +132,21 @@ endfunction(get_fq_dep_list_without_flag)
132132
# Special flags
133133
set(FMA_OPT_FLAG "FMA_OPT")
134134
set(ROUND_OPT_FLAG "ROUND_OPT")
135-
# This flag will define macros that gated away vectorization code such that
136-
# one can always test the fallback generic code path.
137-
set(PREFER_GENERIC_FLAG "PREFER_GENERIC")
135+
# This flag controls whether we use explicit SIMD instructions or not.
136+
set(EXPLICIT_SIMD_OPT_FLAG "EXPLICIT_SIMD_OPT")
138137

139138
# Skip FMA_OPT flag for targets that don't support fma.
140139
if(NOT((LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "FMA")) OR
141140
LIBC_TARGET_ARCHITECTURE_IS_RISCV64))
142141
set(SKIP_FLAG_EXPANSION_FMA_OPT TRUE)
143142
endif()
144143

144+
# Skip EXPLICIT_SIMD_OPT flag for targets that don't support SSE2.
145+
# Note: one may want to revisit it if they want to control other explicit SIMD
146+
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2")))
147+
set(SKIP_FLAG_EXPANSION_EXPLICIT_SIMD_OPT TRUE)
148+
endif()
149+
145150
# Skip ROUND_OPT flag for targets that don't support SSE 4.2.
146151
if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2")))
147152
set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE)

libc/cmake/modules/LLVMLibCObjectRules.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ function(_get_common_compile_options output_var flags)
1818
set(ADD_SSE4_2_FLAG TRUE)
1919
endif()
2020

21-
list(FIND flags ${PREFER_GENERIC_FLAG} prefer_generic)
22-
if(${prefer_generic} LESS 0)
23-
list(FIND flags "${PREFER_GENERIC_FLAG}__ONLY" prefer_generic)
21+
list(FIND flags ${EXPLICIT_SIMD_OPT_FLAG} explicit_simd)
22+
if(${explicit_simd} LESS 0)
23+
list(FIND flags "${EXPLICIT_SIMD_OPT_FLAG}__ONLY" explicit_simd)
2424
endif()
25-
if(${prefer_generic} GREATER -1)
26-
set(ADD_PREFER_GENERIC_FLAG TRUE)
25+
if(${explicit_simd} GREATER -1)
26+
set(ADD_EXPLICIT_SIMD_OPT_FLAG TRUE)
2727
endif()
2828

2929
set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT})
@@ -73,17 +73,17 @@ function(_get_common_compile_options output_var flags)
7373
if(ADD_SSE4_2_FLAG)
7474
list(APPEND compile_options "-msse4.2")
7575
endif()
76-
if(ADD_PREFER_GENERIC_FLAG)
77-
list(APPEND compile_options "-D__LIBC_PREFER_GENERIC")
76+
if(ADD_EXPLICIT_SIMD_OPT_FLAG)
77+
list(APPEND compile_options "-D__LIBC_EXPLICIT_SIMD_OPT")
7878
endif()
7979
elseif(MSVC)
8080
list(APPEND compile_options "/EHs-c-")
8181
list(APPEND compile_options "/GR-")
8282
if(ADD_FMA_FLAG)
8383
list(APPEND compile_options "/arch:AVX2")
8484
endif()
85-
if(ADD_PREFER_GENERIC_FLAG)
86-
list(APPEND compile_options "/D__LIBC_PREFER_GENERIC")
85+
if(ADD_EXPLICIT_SIMD_OPT_FLAG)
86+
list(APPEND compile_options "/D__LIBC_EXPLICIT_SIMD_OPT")
8787
endif()
8888
endif()
8989
if (LIBC_TARGET_ARCHITECTURE_IS_GPU)

libc/src/__support/HashTable/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ add_header_library(
33
HDRS
44
bitmask.h
55
FLAGS
6-
PREFER_GENERIC
6+
EXPLICIT_SIMD_OPT
77
DEPENDS
88
libc.src.__support.common
99
libc.src.__support.CPP.bit

libc/src/__support/HashTable/bitmask.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ template <class BitMask> struct IteratableBitMaskAdaptor : public BitMask {
8383
} // namespace internal
8484
} // namespace LIBC_NAMESPACE
8585

86-
#if defined(LIBC_TARGET_CPU_HAS_SSE2) && !defined(__LIBC_PREFER_GENERIC)
86+
#if defined(LIBC_TARGET_CPU_HAS_SSE2) && defined(__LIBC_EXPLICIT_SIMD_OPT)
8787
#include "sse2/bitmask_impl.inc"
8888
#else
8989
#include "generic/bitmask_impl.inc"

0 commit comments

Comments
 (0)