diff --git a/libc/cmake/modules/LLVMLibCFlagRules.cmake b/libc/cmake/modules/LLVMLibCFlagRules.cmake index 37ffe708fb754..7d663f0682e1f 100644 --- a/libc/cmake/modules/LLVMLibCFlagRules.cmake +++ b/libc/cmake/modules/LLVMLibCFlagRules.cmake @@ -132,8 +132,9 @@ endfunction(get_fq_dep_list_without_flag) # Special flags set(FMA_OPT_FLAG "FMA_OPT") set(ROUND_OPT_FLAG "ROUND_OPT") -# SSE2 is the baseline for x86_64, so we add a negative flag to disable it if needed. -set(DISABLE_SSE2_OPT_FLAG "DISABLE_SSE2_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") # 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 @@ -145,8 +146,3 @@ endif() if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE4_2"))) set(SKIP_FLAG_EXPANSION_ROUND_OPT TRUE) endif() - -# Skip DISABLE_SSE2_OPT flag for targets that don't support SSE2. -if(NOT(LIBC_TARGET_ARCHITECTURE_IS_X86 AND (LIBC_CPU_FEATURES MATCHES "SSE2"))) - set(SKIP_FLAG_EXPANSION_DISABLE_SSE2_OPT TRUE) -endif() diff --git a/libc/cmake/modules/LLVMLibCObjectRules.cmake b/libc/cmake/modules/LLVMLibCObjectRules.cmake index 6d94ce97f0b68..5fbbfd58db2d0 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 ${DISABLE_SSE2_OPT_FLAG} no_sse2) - if(${no_sse2} LESS 0) - list(FIND flags "${DISABLE_SSE2_OPT_FLAG}__ONLY" no_sse2) + list(FIND flags ${PREFER_GENERIC_FLAG} prefer_generic) + if(${prefer_generic} LESS 0) + list(FIND flags "${PREFER_GENERIC_FLAG}__ONLY" prefer_generic) endif() - if((${no_sse2} GREATER -1) AND (LIBC_CPU_FEATURES MATCHES "SSE2")) - set(DISABLE_SSE2_FLAG TRUE) + if(${prefer_generic} GREATER -1) + set(ADD_PREFER_GENERIC_FLAG TRUE) endif() set(compile_options ${LIBC_COMPILE_OPTIONS_DEFAULT} ${ARGN}) @@ -66,8 +66,8 @@ function(_get_common_compile_options output_var flags) if(ADD_SSE4_2_FLAG) list(APPEND compile_options "-msse4.2") endif() - if(DISABLE_SSE2_FLAG) - list(APPEND compile_options "-mno-sse2") + if(ADD_PREFER_GENERIC_FLAG) + list(APPEND compile_options "-D__LIBC_PREFER_GENERIC") endif() elseif(MSVC) list(APPEND compile_options "/EHs-c-") @@ -75,8 +75,8 @@ function(_get_common_compile_options output_var flags) if(ADD_FMA_FLAG) list(APPEND compile_options "/arch:AVX2") endif() - if(DISABLE_SSE2_FLAG) - list(APPEND compile_options "/arch:SSE") + if(ADD_PREFER_GENERIC_FLAG) + list(APPEND compile_options "/D__LIBC_PREFER_GENERIC") 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 238d460dacd42..22e91d4f8708c 100644 --- a/libc/src/__support/HashTable/CMakeLists.txt +++ b/libc/src/__support/HashTable/CMakeLists.txt @@ -1,11 +1,9 @@ -# TODO: `DISABLE_SSE2_OPT` does not quite work yet. -# We will investigate a better way of feature flag control. add_header_library( bitmask HDRS bitmask.h FLAGS - DISABLE_SSE2_OPT + PREFER_GENERIC DEPENDS libc.src.__support.bit libc.src.__support.macros.properties.cpu_features diff --git a/libc/src/__support/HashTable/bitmask.h b/libc/src/__support/HashTable/bitmask.h index 761125feb951d..8247161c449bd 100644 --- a/libc/src/__support/HashTable/bitmask.h +++ b/libc/src/__support/HashTable/bitmask.h @@ -85,7 +85,7 @@ template struct IteratableBitMaskAdaptor : public BitMask { } // namespace internal } // namespace LIBC_NAMESPACE -#if defined(LIBC_TARGET_CPU_HAS_SSE2) +#if defined(LIBC_TARGET_CPU_HAS_SSE2) && !defined(__LIBC_PREFER_GENERIC) #include "sse2/bitmask_impl.inc" #else #include "generic/bitmask_impl.inc"