xref: /aosp_15_r20/external/llvm-libc/src/string/memory_utils/aarch64/inline_memmove.h (revision 71db0c75aadcf003ffe3238005f61d7618a3fead)
1 //===-- Memmove 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_AARCH64_INLINE_MEMMOVE_H
9 #define LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H
10 
11 #include "src/__support/macros/attributes.h"    // LIBC_INLINE
12 #include "src/string/memory_utils/op_aarch64.h" // aarch64::kNeon
13 #include "src/string/memory_utils/op_builtin.h"
14 #include "src/string/memory_utils/op_generic.h"
15 #include "src/string/memory_utils/utils.h"
16 
17 #include <stddef.h> // size_t
18 
19 namespace LIBC_NAMESPACE_DECL {
20 
inline_memmove_aarch64(Ptr dst,CPtr src,size_t count)21 LIBC_INLINE void inline_memmove_aarch64(Ptr dst, CPtr src, size_t count) {
22   static_assert(aarch64::kNeon, "aarch64 supports vector types");
23   using uint128_t = generic_v128;
24   using uint256_t = generic_v256;
25   using uint512_t = generic_v512;
26   if (count == 0)
27     return;
28   if (count == 1)
29     return generic::Memmove<uint8_t>::block(dst, src);
30   if (count <= 4)
31     return generic::Memmove<uint16_t>::head_tail(dst, src, count);
32   if (count <= 8)
33     return generic::Memmove<uint32_t>::head_tail(dst, src, count);
34   if (count <= 16)
35     return generic::Memmove<uint64_t>::head_tail(dst, src, count);
36   if (count <= 32)
37     return generic::Memmove<uint128_t>::head_tail(dst, src, count);
38   if (count <= 64)
39     return generic::Memmove<uint256_t>::head_tail(dst, src, count);
40   if (count <= 128)
41     return generic::Memmove<uint512_t>::head_tail(dst, src, count);
42   if (dst < src) {
43     generic::Memmove<uint256_t>::align_forward<Arg::Src>(dst, src, count);
44     return generic::Memmove<uint512_t>::loop_and_tail_forward(dst, src, count);
45   } else {
46     generic::Memmove<uint256_t>::align_backward<Arg::Src>(dst, src, count);
47     return generic::Memmove<uint512_t>::loop_and_tail_backward(dst, src, count);
48   }
49 }
50 
51 } // namespace LIBC_NAMESPACE_DECL
52 
53 #endif // LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_MEMMOVE_H
54