|
| 1 | +//===-- Trivial builtin implementations ----------------------------------===// |
| 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_GENERIC_BUILTIN_H |
| 10 | +#define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BUILTIN_H |
| 11 | + |
| 12 | +#include "src/__support/macros/attributes.h" // LIBC_INLINE |
| 13 | +#include "src/__support/macros/config.h" // LIBC_HAS_BUILTIN |
| 14 | +#include "src/string/memory_utils/utils.h" // Ptr, CPtr |
| 15 | + |
| 16 | +#include <stddef.h> // size_t |
| 17 | + |
| 18 | +namespace LIBC_NAMESPACE { |
| 19 | + |
| 20 | +static_assert(LIBC_HAS_BUILTIN(__builtin_memcpy), "Builtin not defined"); |
| 21 | +static_assert(LIBC_HAS_BUILTIN(__builtin_memset), "Builtin not defined"); |
| 22 | +static_assert(LIBC_HAS_BUILTIN(__builtin_memmove), "Builtin not defined"); |
| 23 | +static_assert(LIBC_HAS_BUILTIN(__builtin_bcmp), "Builtin not defined"); |
| 24 | + |
| 25 | +[[maybe_unused]] LIBC_INLINE void |
| 26 | +inline_memcpy_builtin(Ptr dst, CPtr src, size_t count, size_t offset = 0) { |
| 27 | + __builtin_memcpy(dst + offset, src + offset, count); |
| 28 | +} |
| 29 | + |
| 30 | +[[maybe_unused]] LIBC_INLINE void inline_memmove_builtin(Ptr dst, CPtr src, |
| 31 | + size_t count) { |
| 32 | + __builtin_memmove(dst, src, count); |
| 33 | +} |
| 34 | + |
| 35 | +[[maybe_unused]] LIBC_INLINE static void |
| 36 | +inline_memset_builtin(Ptr dst, uint8_t value, size_t count, size_t offset = 0) { |
| 37 | + __builtin_memset(dst + offset, value, count); |
| 38 | +} |
| 39 | + |
| 40 | +[[maybe_unused]] LIBC_INLINE int |
| 41 | +inline_bcmp_builtin(CPtr p1, CPtr p2, size_t count, size_t offset = 0) { |
| 42 | + return __builtin_bcmp(p1 + offset, p2 + offset, count); |
| 43 | +} |
| 44 | + |
| 45 | +} // namespace LIBC_NAMESPACE |
| 46 | + |
| 47 | +#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BUILTIN_H |
0 commit comments