1 //===-- Memmove implementation ----------------------------------*- 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 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H
10 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H
12 #include <stddef.h> // size_t, ptrdiff_t
14 #if defined(LIBC_TARGET_ARCH_IS_X86)
15 #include "src/string/memory_utils/x86_64/inline_memmove.h"
16 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \
17 inline_memmove_small_size_x86
18 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP \
19 inline_memmove_follow_up_x86
20 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
21 #include "src/string/memory_utils/aarch64/inline_memmove.h"
22 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \
23 inline_memmove_no_small_size
24 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_aarch64
25 #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)
26 #include "src/string/memory_utils/riscv/inline_memmove.h"
27 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \
28 inline_memmove_no_small_size
29 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_riscv
30 #elif defined(LIBC_TARGET_ARCH_IS_ARM)
31 #include "src/string/memory_utils/generic/byte_per_byte.h"
32 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \
33 inline_memmove_no_small_size
34 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP \
35 inline_memmove_byte_per_byte
36 #elif defined(LIBC_TARGET_ARCH_IS_GPU)
37 #include "src/string/memory_utils/generic/builtin.h"
38 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \
39 inline_memmove_no_small_size
40 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_builtin
42 #error "Unsupported architecture"
45 namespace LIBC_NAMESPACE
{
47 LIBC_INLINE
constexpr bool inline_memmove_no_small_size(void *, const void *,
52 LIBC_INLINE
bool inline_memmove_small_size(void *dst
, const void *src
,
54 return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE(
55 reinterpret_cast<Ptr
>(dst
), reinterpret_cast<CPtr
>(src
), count
);
58 LIBC_INLINE
void inline_memmove_follow_up(void *dst
, const void *src
,
60 LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP(
61 reinterpret_cast<Ptr
>(dst
), reinterpret_cast<CPtr
>(src
), count
);
64 LIBC_INLINE
void inline_memmove(void *dst
, const void *src
, size_t count
) {
65 if (inline_memmove_small_size(dst
, src
, count
))
67 inline_memmove_follow_up(dst
, src
, count
);
70 } // namespace LIBC_NAMESPACE
72 #endif /* LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H */