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 "src/__support/macros/config.h" 13 #include <stddef.h> // size_t, ptrdiff_t 14 15 #if defined(LIBC_TARGET_ARCH_IS_X86) 16 #include "src/string/memory_utils/x86_64/inline_memmove.h" 17 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \ 18 inline_memmove_small_size_x86 19 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP \ 20 inline_memmove_follow_up_x86 21 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) 22 #include "src/string/memory_utils/aarch64/inline_memmove.h" 23 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \ 24 inline_memmove_no_small_size 25 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_aarch64 26 #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) 27 #include "src/string/memory_utils/riscv/inline_memmove.h" 28 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \ 29 inline_memmove_no_small_size 30 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_riscv 31 #elif defined(LIBC_TARGET_ARCH_IS_ARM) 32 #include "src/string/memory_utils/generic/byte_per_byte.h" 33 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \ 34 inline_memmove_no_small_size 35 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP \ 36 inline_memmove_byte_per_byte 37 #elif defined(LIBC_TARGET_ARCH_IS_GPU) 38 #include "src/string/memory_utils/generic/builtin.h" 39 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE \ 40 inline_memmove_no_small_size 41 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_builtin 42 #else 43 #error "Unsupported architecture" 44 #endif 45 46 namespace LIBC_NAMESPACE_DECL { 47 48 LIBC_INLINE constexpr bool inline_memmove_no_small_size(void *, const void *, 49 size_t) { 50 return false; 51 } 52 53 [[gnu::flatten]] LIBC_INLINE bool 54 inline_memmove_small_size(void *dst, const void *src, size_t count) { 55 return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE( 56 reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count); 57 } 58 59 [[gnu::flatten]] LIBC_INLINE void 60 inline_memmove_follow_up(void *dst, const void *src, size_t count) { 61 LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP( 62 reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count); 63 } 64 65 LIBC_INLINE void inline_memmove(void *dst, const void *src, size_t count) { 66 if (inline_memmove_small_size(dst, src, count)) 67 return; 68 inline_memmove_follow_up(dst, src, count); 69 } 70 71 } // namespace LIBC_NAMESPACE_DECL 72 73 #endif /* LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H */ 74