1 //===-- Bcmp implementation for x86_64 --------------------------*- C++ -*-===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
8 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_BCMP_H
9 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_BCMP_H
11 #include "src/__support/macros/attributes.h" // LIBC_INLINE
12 #include "src/__support/macros/config.h"
13 #include "src/string/memory_utils/op_generic.h"
14 #include "src/string/memory_utils/op_x86.h"
15 #include "src/string/memory_utils/utils.h" // Ptr, CPtr
17 #include <stddef.h> // size_t
19 namespace LIBC_NAMESPACE_DECL
{
21 [[maybe_unused
]] LIBC_INLINE BcmpReturnType
22 inline_bcmp_generic_gt16(CPtr p1
, CPtr p2
, size_t count
) {
23 return generic::Bcmp
<uint64_t>::loop_and_tail_align_above(256, p1
, p2
, count
);
26 #if defined(__SSE4_1__)
27 [[maybe_unused
]] LIBC_INLINE BcmpReturnType
28 inline_bcmp_x86_sse41_gt16(CPtr p1
, CPtr p2
, size_t count
) {
30 return generic::branchless_head_tail_neq
<__m128i
>(p1
, p2
, count
);
31 return generic::Bcmp
<__m128i
>::loop_and_tail_align_above(256, p1
, p2
, count
);
36 [[maybe_unused
]] LIBC_INLINE BcmpReturnType
37 inline_bcmp_x86_avx_gt16(CPtr p1
, CPtr p2
, size_t count
) {
39 return generic::branchless_head_tail_neq
<__m128i
>(p1
, p2
, count
);
41 return generic::branchless_head_tail_neq
<__m256i
>(p1
, p2
, count
);
42 return generic::Bcmp
<__m256i
>::loop_and_tail_align_above(256, p1
, p2
, count
);
46 #if defined(__AVX512BW__)
47 [[maybe_unused
]] LIBC_INLINE BcmpReturnType
48 inline_bcmp_x86_avx512bw_gt16(CPtr p1
, CPtr p2
, size_t count
) {
50 return generic::branchless_head_tail_neq
<__m128i
>(p1
, p2
, count
);
52 return generic::branchless_head_tail_neq
<__m256i
>(p1
, p2
, count
);
54 return generic::branchless_head_tail_neq
<__m512i
>(p1
, p2
, count
);
55 return generic::Bcmp
<__m512i
>::loop_and_tail_align_above(256, p1
, p2
, count
);
57 #endif // __AVX512BW__
59 [[maybe_unused
]] LIBC_INLINE BcmpReturnType
inline_bcmp_x86(CPtr p1
, CPtr p2
,
62 return BcmpReturnType::zero();
64 return generic::Bcmp
<uint8_t>::block(p1
, p2
);
66 return generic::branchless_head_tail_neq
<uint16_t>(p1
, p2
, count
);
68 return generic::branchless_head_tail_neq
<uint32_t>(p1
, p2
, count
);
70 return generic::branchless_head_tail_neq
<uint64_t>(p1
, p2
, count
);
71 #if defined(__AVX512BW__)
72 return inline_bcmp_x86_avx512bw_gt16(p1
, p2
, count
);
73 #elif defined(__AVX__)
74 return inline_bcmp_x86_avx_gt16(p1
, p2
, count
);
75 #elif defined(__SSE4_1__)
76 return inline_bcmp_x86_sse41_gt16(p1
, p2
, count
);
78 return inline_bcmp_generic_gt16(p1
, p2
, count
);
82 } // namespace LIBC_NAMESPACE_DECL
84 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_BCMP_H