Warning: This file is not a C or C++ file. It does not have highlighting.
| 1 | //===-- Memcmp implementation for aarch64 -----------------------*- C++ -*-===// |
|---|---|
| 2 | // |
| 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 |
| 6 | // |
| 7 | //===----------------------------------------------------------------------===// |
| 8 | #ifndef LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H |
| 9 | #define LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H |
| 10 | |
| 11 | #include "src/__support/macros/attributes.h" // LIBC_INLINE |
| 12 | #include "src/__support/macros/optimization.h" // LIBC_UNLIKELY |
| 13 | #include "src/string/memory_utils/op_aarch64.h" |
| 14 | #include "src/string/memory_utils/op_generic.h" |
| 15 | #include "src/string/memory_utils/utils.h" // MemcmpReturnType |
| 16 | |
| 17 | namespace LIBC_NAMESPACE_DECL { |
| 18 | |
| 19 | [[maybe_unused]] LIBC_INLINE MemcmpReturnType |
| 20 | inline_memcmp_aarch64_no_fp(CPtr p1, CPtr p2, size_t count) { |
| 21 | if (count == 0) |
| 22 | return MemcmpReturnType::zero(); |
| 23 | if (count == 1) |
| 24 | return generic::Memcmp<uint8_t>::block(p1, p2); |
| 25 | if (count == 2) |
| 26 | return generic::Memcmp<uint16_t>::block(p1, p2); |
| 27 | if (count == 3) |
| 28 | return generic::MemcmpSequence<uint16_t, uint8_t>::block(p1, p2); |
| 29 | if (count <= 8) |
| 30 | return generic::Memcmp<uint32_t>::head_tail(p1, p2, count); |
| 31 | if (count <= 16) |
| 32 | return generic::Memcmp<uint64_t>::head_tail(p1, p2, count); |
| 33 | |
| 34 | return generic::Memcmp<uint64_t>::loop_and_tail_align_above(384, p1, p2, |
| 35 | count); |
| 36 | } |
| 37 | |
| 38 | #if defined(__ARM_NEON) |
| 39 | [[maybe_unused]] LIBC_INLINE MemcmpReturnType |
| 40 | inline_memcmp_aarch64_with_fp(CPtr p1, CPtr p2, size_t count) { |
| 41 | if (count == 0) |
| 42 | return MemcmpReturnType::zero(); |
| 43 | if (count == 1) |
| 44 | return generic::Memcmp<uint8_t>::block(p1, p2); |
| 45 | if (count == 2) |
| 46 | return generic::Memcmp<uint16_t>::block(p1, p2); |
| 47 | if (count == 3) |
| 48 | return generic::MemcmpSequence<uint16_t, uint8_t>::block(p1, p2); |
| 49 | if (count <= 8) |
| 50 | return generic::Memcmp<uint32_t>::head_tail(p1, p2, count); |
| 51 | if (count <= 16) |
| 52 | return generic::Memcmp<uint64_t>::head_tail(p1, p2, count); |
| 53 | |
| 54 | if (LIBC_UNLIKELY(count >= 128)) { // [128, ∞] |
| 55 | if (auto value = generic::Memcmp<uint8x16_t>::block(p1, p2)) |
| 56 | return value; |
| 57 | align_to_next_boundary<16, Arg::P1>(p1, p2, count); |
| 58 | return generic::Memcmp<uint8x16x2_t>::loop_and_tail(p1, p2, count); |
| 59 | } |
| 60 | if (generic::Bcmp<uint8x16_t>::block(p1, p2)) // [16, 16] |
| 61 | return generic::Memcmp<uint8x16_t>::block(p1, p2); |
| 62 | if (count < 32) // [17, 31] |
| 63 | return generic::Memcmp<uint8x16_t>::tail(p1, p2, count); |
| 64 | if (generic::Bcmp<uint8x16_t>::block(p1 + 16, p2 + 16)) // [32, 32] |
| 65 | return generic::Memcmp<uint8x16_t>::block(p1 + 16, p2 + 16); |
| 66 | if (count < 64) // [33, 63] |
| 67 | return generic::Memcmp<uint8x16x2_t>::tail(p1, p2, count); |
| 68 | // [64, 127] |
| 69 | return generic::Memcmp<uint8x16_t>::loop_and_tail(p1 + 32, p2 + 32, |
| 70 | count - 32); |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | [[gnu::flatten]] LIBC_INLINE MemcmpReturnType |
| 75 | inline_memcmp_aarch64_dispatch(CPtr p1, CPtr p2, size_t count) { |
| 76 | #if defined(__ARM_NEON) |
| 77 | return inline_memcmp_aarch64_with_fp(p1, p2, count); |
| 78 | #else |
| 79 | return inline_memcmp_aarch64_no_fp(p1, p2, count); |
| 80 | #endif |
| 81 | } |
| 82 | } // namespace LIBC_NAMESPACE_DECL |
| 83 | |
| 84 | #endif // LIBC_SRC_STRING_MEMORY_UTILS_X86_64_INLINE_MEMCMP_H |
| 85 |
Warning: This file is not a C or C++ file. It does not have highlighting.
