Skip to content

[libc] change PREFER_GENERIC to EXPLICIT_SIMD_OPT #79486

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions libc/cmake/modules/LLVMLibCFlagRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -132,16 +132,21 @@ 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.
set(PREFER_GENERIC_FLAG "PREFER_GENERIC")
# 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.
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()

# 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)
Expand Down
18 changes: 9 additions & 9 deletions libc/cmake/modules/LLVMLibCObjectRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down Expand Up @@ -73,17 +73,17 @@ 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-")
list(APPEND compile_options "/GR-")
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)
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/HashTable/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion libc/src/__support/HashTable/bitmask.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down