Skip to content

Commit 3dd3f25

Browse files
committed
[libc] Change __builtin_memcpy to inline_memcpy.
1 parent 6af94c5 commit 3dd3f25

File tree

15 files changed

+30
-14
lines changed

15 files changed

+30
-14
lines changed

libc/src/__support/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ add_header_library(
302302
DEPENDS
303303
libc.hdr.stdint_proxy
304304
libc.src.__support.common
305+
libc.src.string.memory_utils.inline_memcpy
305306
)
306307

307308
add_header_library(

libc/src/__support/arg_list.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hdr/stdint_proxy.h"
1313
#include "src/__support/common.h"
1414
#include "src/__support/macros/config.h"
15+
#include "src/string/memory_utils/inline_memcpy.h"
1516

1617
#include <stdarg.h>
1718
#include <stddef.h>
@@ -126,7 +127,7 @@ template <bool packed> class StructArgList {
126127

127128
// Memcpy because pointer alignment may be illegal given a packed struct.
128129
T val;
129-
__builtin_memcpy(&val, ptr, sizeof(T));
130+
inline_memcpy(&val, ptr, sizeof(T));
130131

131132
ptr =
132133
reinterpret_cast<void *>(reinterpret_cast<uintptr_t>(ptr) + sizeof(T));

libc/src/stdio/printf_core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ add_header_library(
112112
libc.src.__support.libc_assert
113113
libc.src.__support.uint128
114114
libc.src.__support.StringUtil.error_to_string
115+
libc.src.string.memory_utils.inline_memcpy
115116
)
116117

117118
add_header_library(

libc/src/stdio/printf_core/float_dec_converter_limited.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@
5353
#include "src/stdio/printf_core/core_structs.h"
5454
#include "src/stdio/printf_core/float_inf_nan_converter.h"
5555
#include "src/stdio/printf_core/writer.h"
56+
#include "src/string/memory_utils/inline_memcpy.h"
5657

5758
namespace LIBC_NAMESPACE_DECL {
5859
namespace printf_core {
@@ -250,7 +251,7 @@ DigitsOutput decimal_digits(DigitsInput input, int precision, bool e_mode) {
250251
// there's space for it in the DigitsOutput buffer).
251252
DigitsOutput output;
252253
output.ndigits = view.size();
253-
__builtin_memcpy(output.digits, view.data(), output.ndigits);
254+
inline_memcpy(output.digits, view.data(), output.ndigits);
254255

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

557558
// Now we know enough to work out the length of the unpadded output:

libc/src/stdlib/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,7 @@ add_header_library(
292292
libc.hdr.stdint_proxy
293293
libc.include.stdlib
294294
libc.src.__support.CPP.cstddef
295+
libc.src.string.memory_utils.inline_memcpy
295296
)
296297

297298
add_entrypoint_object(

libc/src/stdlib/qsort_data.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include "hdr/stdint_proxy.h"
1313
#include "src/__support/CPP/cstddef.h"
1414
#include "src/__support/macros/config.h"
15+
#include "src/string/memory_utils/inline_memcpy.h"
1516

1617
namespace LIBC_NAMESPACE_DECL {
1718
namespace internal {
@@ -54,9 +55,9 @@ class ArrayGenericSize {
5455
const cpp::byte *elem_i_block_end = elem_i + (elem_size - elem_size_rem);
5556

5657
while (elem_i != elem_i_block_end) {
57-
__builtin_memcpy(tmp_block, elem_i, BLOCK_SIZE);
58-
__builtin_memcpy(elem_i, elem_j, BLOCK_SIZE);
59-
__builtin_memcpy(elem_j, tmp_block, BLOCK_SIZE);
58+
inline_memcpy(tmp_block, elem_i, BLOCK_SIZE);
59+
inline_memcpy(elem_i, elem_j, BLOCK_SIZE);
60+
inline_memcpy(elem_j, tmp_block, BLOCK_SIZE);
6061

6162
elem_i += BLOCK_SIZE;
6263
elem_j += BLOCK_SIZE;
@@ -112,9 +113,9 @@ template <size_t ELEM_SIZE> class ArrayFixedSize {
112113
cpp::byte *elem_i = get_internal(i);
113114
cpp::byte *elem_j = get_internal(j);
114115

115-
__builtin_memcpy(tmp, elem_i, ELEM_SIZE);
116+
inline_memcpy(tmp, elem_i, ELEM_SIZE);
116117
__builtin_memmove(elem_i, elem_j, ELEM_SIZE);
117-
__builtin_memcpy(elem_j, tmp, ELEM_SIZE);
118+
inline_memcpy(elem_j, tmp, ELEM_SIZE);
118119
}
119120

120121
LIBC_INLINE size_t len() const { return array_len; }

libc/src/string/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ add_header_library(
2222
libc.src.__support.CPP.type_traits
2323
libc.src.__support.CPP.simd
2424
libc.src.__support.common
25+
libc.src.string.memory_utils.inline_memcpy
2526
${string_config_options}
2627
)
2728

libc/src/string/stpcpy.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#include "src/string/stpcpy.h"
1010
#include "src/__support/macros/config.h"
11+
#include "src/string/memory_utils/inline_memcpy.h"
1112
#include "src/string/string_utils.h"
1213

1314
#include "src/__support/common.h"
@@ -17,7 +18,7 @@ namespace LIBC_NAMESPACE_DECL {
1718
LLVM_LIBC_FUNCTION(char *, stpcpy,
1819
(char *__restrict dest, const char *__restrict src)) {
1920
size_t size = internal::string_length(src) + 1;
20-
__builtin_memcpy(dest, src, size);
21+
inline_memcpy(dest, src, size);
2122
char *result = dest + size;
2223

2324
if (result != nullptr)

libc/src/string/string_utils.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "src/__support/CPP/type_traits.h" // cpp::is_same_v
2222
#include "src/__support/macros/config.h"
2323
#include "src/__support/macros/optimization.h" // LIBC_UNLIKELY
24+
#include "src/string/memory_utils/inline_memcpy.h"
2425

2526
#if defined(LIBC_COPT_STRING_UNSAFE_WIDE_READ)
2627
#if LIBC_HAS_VECTOR_TYPE
@@ -242,7 +243,7 @@ LIBC_INLINE size_t strlcpy(char *__restrict dst, const char *__restrict src,
242243
if (!size)
243244
return len;
244245
size_t n = len < size - 1 ? len : size - 1;
245-
__builtin_memcpy(dst, src, n);
246+
inline_memcpy(dst, src, n);
246247
dst[n] = '\0';
247248
return len;
248249
}

libc/src/wchar/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ add_entrypoint_object(
452452
DEPENDS
453453
libc.hdr.types.size_t
454454
libc.hdr.wchar_macros
455+
libc.src.string.memory_utils.inline_memcpy
455456
)
456457

457458
add_entrypoint_object(

0 commit comments

Comments
 (0)