1//===-- Memmove implementation ----------------------------------*- 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
9#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H
10#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H
11
12#include <stddef.h> // size_t, ptrdiff_t
13
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
41#else
42#error "Unsupported architecture"
43#endif
44
45namespace LIBC_NAMESPACE {
46
47LIBC_INLINE constexpr bool inline_memmove_no_small_size(void *, const void *,
48 size_t) {
49 return false;
50}
51
52[[gnu::flatten]] LIBC_INLINE bool
53inline_memmove_small_size(void *dst, const void *src, size_t count) {
54 return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE(
55 dst: reinterpret_cast<Ptr>(dst), src: reinterpret_cast<CPtr>(src), count);
56}
57
58[[gnu::flatten]] LIBC_INLINE void
59inline_memmove_follow_up(void *dst, const void *src, size_t count) {
60 LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP(
61 dst: reinterpret_cast<Ptr>(dst), src: reinterpret_cast<CPtr>(src), count);
62}
63
64LIBC_INLINE void inline_memmove(void *dst, const void *src, size_t count) {
65 if (inline_memmove_small_size(dst, src, count))
66 return;
67 inline_memmove_follow_up(dst, src, count);
68}
69
70} // namespace LIBC_NAMESPACE
71
72#endif /* LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H */
73

source code of libc/src/string/memory_utils/inline_memmove.h