• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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/string/memory_utils/inline_memcpy.h"
11 #include "src/string/memory_utils/inline_memmove.h"
12 #include <stddef.h> // size_t
13 
14 namespace LIBC_NAMESPACE {
15 
16 LLVM_LIBC_FUNCTION(void *, memmove,
17                    (void *dst, const void *src, size_t count)) {
18   // Memmove may handle some small sizes as efficiently as inline_memcpy.
19   // For these sizes we may not do is_disjoint check.
20   // This both avoids additional code for the most frequent smaller sizes
21   // and removes code bloat (we don't need the memcpy logic for small sizes).
22   if (inline_memmove_small_size(dst, src, count))
23     return dst;
24   if (is_disjoint(dst, src, count))
25     inline_memcpy(dst, src, count);
26   else
27     inline_memmove_follow_up(dst, src, count);
28   return dst;
29 }
30 
31 } // namespace LIBC_NAMESPACE
32