| 1 | //===-- Implementation of memmove -----------------------------------------===// |
| 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 | #include "src/string/memmove.h" |
| 10 | #include "src/__support/macros/config.h" |
| 11 | #include "src/__support/macros/null_check.h" |
| 12 | #include "src/string/memory_utils/inline_memcpy.h" |
| 13 | #include "src/string/memory_utils/inline_memmove.h" |
| 14 | #include <stddef.h> // size_t |
| 15 | |
| 16 | namespace LIBC_NAMESPACE_DECL { |
| 17 | |
| 18 | LLVM_LIBC_FUNCTION(void *, memmove, |
| 19 | (void *dst, const void *src, size_t count)) { |
| 20 | if (count) { |
| 21 | LIBC_CRASH_ON_NULLPTR(dst); |
| 22 | LIBC_CRASH_ON_NULLPTR(src); |
| 23 | } |
| 24 | // Memmove may handle some small sizes as efficiently as inline_memcpy. |
| 25 | // For these sizes we may not do is_disjoint check. |
| 26 | // This both avoids additional code for the most frequent smaller sizes |
| 27 | // and removes code bloat (we don't need the memcpy logic for small sizes). |
| 28 | if (inline_memmove_small_size(dst, src, count)) |
| 29 | return dst; |
| 30 | if (is_disjoint(dst, src, count)) |
| 31 | inline_memcpy(dst, src, count); |
| 32 | else |
| 33 | inline_memmove_follow_up(dst, src, count); |
| 34 | return dst; |
| 35 | } |
| 36 | |
| 37 | } // namespace LIBC_NAMESPACE_DECL |
| 38 | |