1 //===-- Memcpy 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_MEMCPY_H 10 #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H 11 12 #include "src/__support/macros/attributes.h" // LIBC_INLINE 13 #include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_ 14 #include "src/string/memory_utils/utils.h" // Ptr, CPtr 15 16 #include <stddef.h> // size_t 17 18 #if defined(LIBC_COPT_MEMCPY_USE_EMBEDDED_TINY) 19 #include "src/string/memory_utils/generic/byte_per_byte.h" 20 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_byte_per_byte 21 #elif defined(LIBC_TARGET_ARCH_IS_X86) 22 #include "src/string/memory_utils/x86_64/inline_memcpy.h" 23 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY \ 24 inline_memcpy_x86_maybe_interpose_repmovsb 25 #elif defined(LIBC_TARGET_ARCH_IS_AARCH64) 26 #include "src/string/memory_utils/aarch64/inline_memcpy.h" 27 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_aarch64 28 #elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) 29 #include "src/string/memory_utils/riscv/inline_memcpy.h" 30 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_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_MEMCPY inline_memcpy_byte_per_byte 34 #elif defined(LIBC_TARGET_ARCH_IS_GPU) 35 #include "src/string/memory_utils/generic/builtin.h" 36 #define LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY inline_memcpy_builtin 37 #else 38 #error "Unsupported architecture" 39 #endif 40 41 namespace LIBC_NAMESPACE_DECL { 42 43 [[gnu::flatten]] LIBC_INLINE void inline_memcpy(void * __restrict dst,const void * __restrict src,size_t count)44inline_memcpy(void *__restrict dst, const void *__restrict src, size_t count) { 45 LIBC_SRC_STRING_MEMORY_UTILS_MEMCPY(reinterpret_cast<Ptr>(dst), 46 reinterpret_cast<CPtr>(src), count); 47 } 48 49 } // namespace LIBC_NAMESPACE_DECL 50 51 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMCPY_H 52