Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / libc / src / string / memory_utils / inline_memmove.h
blob30c2c3ddbf1bb7406a2f893f0075d5896ad7d712
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 //===----------------------------------------------------------------------===//
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
41 #else
42 #error "Unsupported architecture"
43 #endif
45 namespace LIBC_NAMESPACE {
47 LIBC_INLINE constexpr bool inline_memmove_no_small_size(void *, const void *,
48 size_t) {
49 return false;
52 LIBC_INLINE bool inline_memmove_small_size(void *dst, const void *src,
53 size_t count) {
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,
59 size_t count) {
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))
66 return;
67 inline_memmove_follow_up(dst, src, count);
70 } // namespace LIBC_NAMESPACE
72 #endif /* LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H */