[libc-commits] [PATCH] D137868: [libc] Fix builtin definition for memory functions

Michael Jones via Phabricator via libc-commits libc-commits at lists.llvm.org
Fri Nov 11 14:13:42 PST 2022


michaelrj created this revision.
michaelrj added reviewers: gchatelet, sivachandra.
Herald added subscribers: libc-commits, ecnelises, tschuett, pengfei.
Herald added projects: libc-project, All.
michaelrj requested review of this revision.

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.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D137868

Files:
  libc/src/string/memory_utils/op_x86.h


Index: libc/src/string/memory_utils/op_x86.h
===================================================================
--- libc/src/string/memory_utils/op_x86.h
+++ libc/src/string/memory_utils/op_x86.h
@@ -20,15 +20,21 @@
 #include "src/string/memory_utils/op_builtin.h"
 #include "src/string/memory_utils/op_generic.h"
 
-#ifdef __SSE2__
+#if defined(__AVX512F__) || defined(__SSE2__) || defined(__AVX2__)
 #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 builtin is not present.
+#ifndef __AVX512F__
 #define _mm512_cmpneq_epi8_mask(A, B) 0
+#endif //  __AVX512F__
+#ifndef __SSE2__
 #define _mm_movemask_epi8(A) 0
-#define _mm256_movemask_epi8(A) 0
 #endif //  __SSE2__
+#ifndef __AVX2__
+#define _mm256_movemask_epi8(A) 0
+#endif //  __AVX2__
 
 namespace __llvm_libc::x86 {
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D137868.474859.patch
Type: text/x-patch
Size: 912 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libc-commits/attachments/20221111/3ac6b8ac/attachment.bin>


More information about the libc-commits mailing list