[libc-commits] [libc] af029d3 - [libc][reland] Fix builtin definition for memory functions
Michael Jones via libc-commits
libc-commits at lists.llvm.org
Fri Nov 18 14:25:28 PST 2022
Author: Michael Jones
Date: 2022-11-18T14:25:23-08:00
New Revision: af029d383a24ee454e1124f64f3427d5b79e5f7e
URL: https://github.com/llvm/llvm-project/commit/af029d383a24ee454e1124f64f3427d5b79e5f7e
DIFF: https://github.com/llvm/llvm-project/commit/af029d383a24ee454e1124f64f3427d5b79e5f7e.diff
LOG: [libc][reland] Fix builtin definition for memory functions
The memory functions are highly performance sensitive and use builtins
where possible, but also need to define those functions names when they
don't exist to avoid compilation errors. Previously all those
redefinitions were behind the SSE2 flag for x86, which caused errors on
CPUs that supported SSE2 but not AVX512. This patch splits the various
CPU extensions out to avoid errors on such CPUs.
Reviewed By: gchatelet
Differential Revision: https://reviews.llvm.org/D138163
Added:
Modified:
libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
libc/src/string/CMakeLists.txt
libc/src/string/memory_utils/op_x86.h
Removed:
################################################################################
diff --git a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
index 358d07480ab80..fdd477c1155ec 100644
--- a/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
+++ b/libc/cmake/modules/LLVMLibCCheckCpuFeatures.cmake
@@ -6,7 +6,7 @@
set(ALL_CPU_FEATURES "")
if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
- set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX2 AVX512F FMA)
+ set(ALL_CPU_FEATURES SSE2 SSE4_2 AVX2 AVX512F AVX512BW FMA)
set(LIBC_COMPILE_OPTIONS_NATIVE -march=native)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
set(LIBC_COMPILE_OPTIONS_NATIVE -mcpu=native)
diff --git a/libc/src/string/CMakeLists.txt b/libc/src/string/CMakeLists.txt
index e300a036655ab..9e8287fe8b938 100644
--- a/libc/src/string/CMakeLists.txt
+++ b/libc/src/string/CMakeLists.txt
@@ -355,7 +355,7 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_bcmp(bcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_bcmp(bcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_bcmp(bcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
- add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
+ add_bcmp(bcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)
add_bcmp(bcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_bcmp(bcmp)
else()
@@ -409,7 +409,7 @@ if(${LIBC_TARGET_ARCHITECTURE_IS_X86})
add_memcmp(memcmp_x86_64_opt_sse2 COMPILE_OPTIONS -march=k8 REQUIRE SSE2)
add_memcmp(memcmp_x86_64_opt_sse4 COMPILE_OPTIONS -march=nehalem REQUIRE SSE4_2)
add_memcmp(memcmp_x86_64_opt_avx2 COMPILE_OPTIONS -march=haswell REQUIRE AVX2)
- add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512F)
+ add_memcmp(memcmp_x86_64_opt_avx512 COMPILE_OPTIONS -march=skylake-avx512 REQUIRE AVX512BW)
add_memcmp(memcmp_opt_host COMPILE_OPTIONS ${LIBC_COMPILE_OPTIONS_NATIVE})
add_memcmp(memcmp)
elseif(${LIBC_TARGET_ARCHITECTURE_IS_AARCH64})
diff --git a/libc/src/string/memory_utils/op_x86.h b/libc/src/string/memory_utils/op_x86.h
index 8e6432233ca31..d2bf0e4c0738a 100644
--- a/libc/src/string/memory_utils/op_x86.h
+++ b/libc/src/string/memory_utils/op_x86.h
@@ -20,15 +20,22 @@
#include "src/string/memory_utils/op_builtin.h"
#include "src/string/memory_utils/op_generic.h"
-#ifdef __SSE2__
+#if defined(__AVX512BW__) || defined(__AVX512F__) || defined(__AVX2__) || \
+ defined(__SSE2__)
#include <immintrin.h>
-#else
+#endif
+
// Define fake functions to prevent the compiler from failing on undefined
-// functions in case SSE2 is not present.
+// functions in case the CPU extension is not present.
+#if !defined(__AVX512BW__) && (defined(_MSC_VER) || defined(__SCE__))
#define _mm512_cmpneq_epi8_mask(A, B) 0
-#define _mm_movemask_epi8(A) 0
+#endif
+#if !defined(__AVX2__) && (defined(_MSC_VER) || defined(__SCE__))
#define _mm256_movemask_epi8(A) 0
-#endif // __SSE2__
+#endif
+#if !defined(__SSE2__) && (defined(_MSC_VER) || defined(__SCE__))
+#define _mm_movemask_epi8(A) 0
+#endif
namespace __llvm_libc::x86 {
More information about the libc-commits
mailing list