brintos

brintos / llvm-project-archived public Read only

0
0
Text · 3.0 KiB · 71a28c3 Raw
73 lines · c
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-exception6//7//===----------------------------------------------------------------------===//8 9#ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H10#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H11 12#include "src/__support/macros/attributes.h" // LIBC_INLINE13#include "src/__support/macros/config.h"     // LIBC_NAMESPACE_DECL14#include <stddef.h>                          // size_t, ptrdiff_t15 16#if defined(LIBC_TARGET_ARCH_IS_X86)17#include "src/string/memory_utils/x86_64/inline_memmove.h"18#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \19  inline_memmove_small_size_x8620#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP                         \21  inline_memmove_follow_up_x8622#elif defined(LIBC_TARGET_ARCH_IS_AARCH64)23#include "src/string/memory_utils/aarch64/inline_memmove.h"24#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \25  inline_memmove_no_small_size26#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_aarch6427#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV)28#include "src/string/memory_utils/riscv/inline_memmove.h"29#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \30  inline_memmove_no_small_size31#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_riscv32#elif defined(LIBC_TARGET_ARCH_IS_GPU)33#include "src/string/memory_utils/generic/builtin.h"34#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \35  inline_memmove_no_small_size36#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP inline_memmove_builtin37#else38#include "src/string/memory_utils/generic/byte_per_byte.h"39#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE                        \40  inline_memmove_no_small_size41#define LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP                         \42  inline_memmove_byte_per_byte43#endif44 45namespace LIBC_NAMESPACE_DECL {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 bool53inline_memmove_small_size(void *dst, const void *src, size_t count) {54  return LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_SMALL_SIZE(55      reinterpret_cast<Ptr>(dst), reinterpret_cast<CPtr>(src), count);56}57 58[[gnu::flatten]] LIBC_INLINE void59inline_memmove_follow_up(void *dst, const void *src, size_t count) {60  LIBC_SRC_STRING_MEMORY_UTILS_MEMMOVE_FOLLOW_UP(61      reinterpret_cast<Ptr>(dst), 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_DECL71 72#endif /* LLVM_LIBC_SRC_STRING_MEMORY_UTILS_INLINE_MEMMOVE_H */73