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/string/memory_utils/utils.h" // Ptr, CPtr
14
15 #include <stddef.h> // size_t
16
17 namespace LIBC_NAMESPACE {
18
19 #if !__has_builtin(__builtin_memcpy) || !__has_builtin(__builtin_memset) || \
20 !__has_builtin(__builtin_memmove)
21 #error "Builtin not defined");
22 #endif
23
24 [[maybe_unused]] LIBC_INLINE void
25 inline_memcpy_builtin(Ptr dst, CPtr src, size_t count, size_t offset = 0) {
26 __builtin_memcpy(dst + offset, src + offset, count);
27 }
28
inline_memmove_builtin(Ptr dst,CPtr src,size_t count)29 [[maybe_unused]] LIBC_INLINE void inline_memmove_builtin(Ptr dst, CPtr src,
30 size_t count) {
31 __builtin_memmove(dst, src, count);
32 }
33
34 [[maybe_unused]] LIBC_INLINE static void
35 inline_memset_builtin(Ptr dst, uint8_t value, size_t count, size_t offset = 0) {
36 __builtin_memset(dst + offset, value, count);
37 }
38
39 } // namespace LIBC_NAMESPACE
40
41 #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_BUILTIN_H
42