Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions libc/src/__support/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ add_header_library(
DEPENDS
libc.hdr.stdint_proxy
libc.src.__support.common
libc.src.string.memory_utils.inline_memcpy
)

add_header_library(
Expand Down
3 changes: 2 additions & 1 deletion libc/src/__support/arg_list.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "hdr/stdint_proxy.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_memcpy.h"

#include <stdarg.h>
#include <stddef.h>
Expand Down Expand Up @@ -126,7 +127,7 @@ template <bool packed> class StructArgList {

// Memcpy because pointer alignment may be illegal given a packed struct.
T val;
__builtin_memcpy(&val, ptr, sizeof(T));
inline_memcpy(&val, ptr, sizeof(T));

ptr =
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + sizeof(T));
Expand Down
1 change: 1 addition & 0 deletions libc/src/stdio/printf_core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ add_header_library(
libc.src.__support.libc_assert
libc.src.__support.uint128
libc.src.__support.StringUtil.error_to_string
libc.src.string.memory_utils.inline_memcpy
)

add_header_library(
Expand Down
5 changes: 3 additions & 2 deletions libc/src/stdio/printf_core/float_dec_converter_limited.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
#include "src/stdio/printf_core/core_structs.h"
#include "src/stdio/printf_core/float_inf_nan_converter.h"
#include "src/stdio/printf_core/writer.h"
#include "src/string/memory_utils/inline_memcpy.h"

namespace LIBC_NAMESPACE_DECL {
namespace printf_core {
Expand Down Expand Up @@ -250,7 +251,7 @@ DigitsOutput decimal_digits(DigitsInput input, int precision, bool e_mode) {
// there's space for it in the DigitsOutput buffer).
DigitsOutput output;
output.ndigits = view.size();
__builtin_memcpy(output.digits, view.data(), output.ndigits);
inline_memcpy(output.digits, view.data(), output.ndigits);

// Set up the output exponent, which is done differently depending on mode.
// Also, figure out whether we have one digit too many, and if so, set the
Expand Down Expand Up @@ -551,7 +552,7 @@ convert_float_inner(Writer<write_mode> *writer, const FormatSection &to_conv,
cpp::string_view expview = expcvt.view();
expbuf[0] = internal::islower(to_conv.conv_name) ? 'e' : 'E';
explen = expview.size() + 1;
__builtin_memcpy(expbuf + 1, expview.data(), expview.size());
inline_memcpy(expbuf + 1, expview.data(), expview.size());
}

// Now we know enough to work out the length of the unpadded output:
Expand Down
1 change: 1 addition & 0 deletions libc/src/stdlib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ add_header_library(
libc.hdr.stdint_proxy
libc.include.stdlib
libc.src.__support.CPP.cstddef
libc.src.string.memory_utils.inline_memcpy
)

add_entrypoint_object(
Expand Down
11 changes: 6 additions & 5 deletions libc/src/stdlib/qsort_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include "hdr/stdint_proxy.h"
#include "src/__support/CPP/cstddef.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_memcpy.h"

namespace LIBC_NAMESPACE_DECL {
namespace internal {
Expand Down Expand Up @@ -54,9 +55,9 @@ class ArrayGenericSize {
const cpp::byte *elem_i_block_end = elem_i + (elem_size - elem_size_rem);

while (elem_i != elem_i_block_end) {
__builtin_memcpy(tmp_block, elem_i, BLOCK_SIZE);
__builtin_memcpy(elem_i, elem_j, BLOCK_SIZE);
__builtin_memcpy(elem_j, tmp_block, BLOCK_SIZE);
inline_memcpy(tmp_block, elem_i, BLOCK_SIZE);
inline_memcpy(elem_i, elem_j, BLOCK_SIZE);
inline_memcpy(elem_j, tmp_block, BLOCK_SIZE);

elem_i += BLOCK_SIZE;
elem_j += BLOCK_SIZE;
Expand Down Expand Up @@ -112,9 +113,9 @@ template <size_t ELEM_SIZE> class ArrayFixedSize {
cpp::byte *elem_i = get_internal(i);
cpp::byte *elem_j = get_internal(j);

__builtin_memcpy(tmp, elem_i, ELEM_SIZE);
inline_memcpy(tmp, elem_i, ELEM_SIZE);
__builtin_memmove(elem_i, elem_j, ELEM_SIZE);
__builtin_memcpy(elem_j, tmp, ELEM_SIZE);
inline_memcpy(elem_j, tmp, ELEM_SIZE);
}

LIBC_INLINE size_t len() const { return array_len; }
Expand Down
1 change: 1 addition & 0 deletions libc/src/string/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ add_header_library(
libc.src.__support.CPP.type_traits
libc.src.__support.CPP.simd
libc.src.__support.common
libc.src.string.memory_utils.inline_memcpy
${string_config_options}
)

Expand Down
3 changes: 2 additions & 1 deletion libc/src/string/stpcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

#include "src/string/stpcpy.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_memcpy.h"
#include "src/string/string_utils.h"

#include "src/__support/common.h"
Expand All @@ -17,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(char *, stpcpy,
(char *__restrict dest, const char *__restrict src)) {
size_t size = internal::string_length(src) + 1;
__builtin_memcpy(dest, src, size);
inline_memcpy(dest, src, size);
char *result = dest + size;

if (result != nullptr)
Expand Down
3 changes: 2 additions & 1 deletion libc/src/string/string_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
#include "src/__support/CPP/type_traits.h" // cpp::is_same_v
#include "src/__support/macros/config.h"
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
#include "src/string/memory_utils/inline_memcpy.h"

#if defined(LIBC_COPT_STRING_UNSAFE_WIDE_READ)
#if LIBC_HAS_VECTOR_TYPE
Expand Down Expand Up @@ -242,7 +243,7 @@ LIBC_INLINE size_t strlcpy(char *__restrict dst, const char *__restrict src,
if (!size)
return len;
size_t n = len < size - 1 ? len : size - 1;
__builtin_memcpy(dst, src, n);
inline_memcpy(dst, src, n);
dst[n] = '\0';
return len;
}
Expand Down
1 change: 1 addition & 0 deletions libc/src/wchar/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ add_entrypoint_object(
DEPENDS
libc.hdr.types.size_t
libc.hdr.wchar_macros
libc.src.string.memory_utils.inline_memcpy
)

add_entrypoint_object(
Expand Down
2 changes: 1 addition & 1 deletion libc/src/wchar/wcpcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(wchar_t *, wcpcpy,
(wchar_t *__restrict s1, const wchar_t *__restrict s2)) {
size_t size = internal::string_length(s2);
__builtin_memcpy(s1, s2, (size + 1) * sizeof(wchar_t));
inline_memcpy(s1, s2, (size + 1) * sizeof(wchar_t));
wchar_t *result = s1 + size;
return result;
}
Expand Down
2 changes: 1 addition & 1 deletion libc/src/wchar/wcscpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ namespace LIBC_NAMESPACE_DECL {
LLVM_LIBC_FUNCTION(wchar_t *, wcscpy,
(wchar_t *__restrict s1, const wchar_t *__restrict s2)) {
size_t size = internal::string_length(s2) + 1;
__builtin_memcpy(s1, s2, size * sizeof(wchar_t));
inline_memcpy(s1, s2, size * sizeof(wchar_t));
return s1;
}

Expand Down
3 changes: 2 additions & 1 deletion libc/src/wchar/wmemcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,14 @@
#include "hdr/types/wchar_t.h"
#include "src/__support/common.h"
#include "src/__support/macros/config.h"
#include "src/string/memory_utils/inline_memcpy.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(wchar_t *, wmemcpy,
(wchar_t *__restrict s1, const wchar_t *__restrict s2,
size_t n)) {
__builtin_memcpy(s1, s2, n * sizeof(wchar_t));
inline_memcpy(s1, s2, n * sizeof(wchar_t));
return s1;
}

Expand Down
3 changes: 2 additions & 1 deletion libc/src/wchar/wmempcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,14 @@
#include "hdr/types/size_t.h"
#include "hdr/types/wchar_t.h"
#include "src/__support/common.h"
#include "src/string/memory_utils/inline_memcpy.h"

namespace LIBC_NAMESPACE_DECL {

LLVM_LIBC_FUNCTION(wchar_t *, wmempcpy,
(wchar_t *__restrict to, const wchar_t *__restrict from,
size_t size)) {
__builtin_memcpy(to, from, size * sizeof(wchar_t));
inline_memcpy(to, from, size * sizeof(wchar_t));
return reinterpret_cast<wchar_t *>(to) + size;
}

Expand Down
4 changes: 4 additions & 0 deletions utils/bazel/llvm-project-overlay/libc/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ libc_support_library(
hdrs = ["src/__support/arg_list.h"],
deps = [
":__support_common",
":string_memory_utils",
],
)

Expand Down Expand Up @@ -5003,6 +5004,7 @@ libc_support_library(
":__support_cpp_bit",
":__support_cpp_cstddef",
":__support_macros_attributes",
":string_memory_utils",
],
)

Expand Down Expand Up @@ -6945,6 +6947,7 @@ libc_function(
deps = [
":__support_common",
":__support_macros_config",
":string_memory_utils",
":types_size_t",
":types_wchar_t",
],
Expand All @@ -6968,6 +6971,7 @@ libc_function(
hdrs = ["src/wchar/wmempcpy.h"],
deps = [
":__support_common",
":string_memory_utils",
":types_size_t",
":types_wchar_t",
],
Expand Down
Loading