From 5c612e4aa740b04464bf0ba65d652e924305932e Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:00:57 -0400 Subject: [PATCH 01/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index edbc4b80d5fbf..1701954a3d42d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# The LLVM Compiler Infrastructure +# The LLVM Compiler Infrastructuren This directory and its sub-directories contain source code for LLVM, a toolkit for the construction of highly optimized compilers, From 04796dffbd84e10d47a37c5ba66a971cb94683c0 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:01:44 -0400 Subject: [PATCH 02/16] Patch 13 (#13) * Update README.md * Patch 12 (#11) * Update README.md * Patch 13 (#10) * Update README.md * Patch 12 (#9) * Update memchr.cpp * Patch 10 (#6) * Optimize string functions * Update string_utils.h * Update memrchr.cpp * Patch 11 (#8) * Update README.md * Patch 10 (#5) * Update CMakeLists.txt * Patch 9 (#4) * Update strchr.cpp * Add explicit cast (#3) We need to have the most efficient c++ casting * Update strchr.cpp * Update CMakeLists.txt * Update strrchr.cpp * Update README.md * Update string_utils.h * Update string_utils.h * Update memchr.cpp * Update README.md * Update string_utils.h * Update README.md * Update README.md * Update memcpy.cpp * Update memmove.cpp * Update memmove.cpp * Update strcpy.cpp * Update strcpy.cpp * Update strcpy.cpp * Update memcpy.cpp * Update memmove.cpp * Update memmove.cpp --- libc/src/string/memchr.cpp | 3 +- libc/src/string/memcpy.cpp | 6 ++-- libc/src/string/memmove.cpp | 13 +++++---- libc/src/string/memrchr.cpp | 7 ++--- libc/src/string/strchr.cpp | 12 ++++---- libc/src/string/strcpy.cpp | 50 ++++++++++++++++++++++++++++++++-- libc/src/string/string_utils.h | 32 +++++++++++----------- libc/src/string/strrchr.cpp | 4 +-- 8 files changed, 88 insertions(+), 39 deletions(-) diff --git a/libc/src/string/memchr.cpp b/libc/src/string/memchr.cpp index 02b4016398414..a2a537680920d 100644 --- a/libc/src/string/memchr.cpp +++ b/libc/src/string/memchr.cpp @@ -17,7 +17,8 @@ namespace __llvm_libc { // TODO: Look at performance benefits of comparing words. LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) { return internal::find_first_character( - reinterpret_cast(src), c, n); + reinterpret_cast(src), + static_cast(c), n); } } // namespace __llvm_libc diff --git a/libc/src/string/memcpy.cpp b/libc/src/string/memcpy.cpp index 5e70e00db1b91..dbf59be70cf81 100644 --- a/libc/src/string/memcpy.cpp +++ b/libc/src/string/memcpy.cpp @@ -30,7 +30,7 @@ namespace __llvm_libc { // implementation parameters. // - As compilers and processors get better, the generated code is improved // with little change on the code side. -static void memcpy_impl(char *__restrict dst, const char *__restrict src, +static void memcpy_impl(unsigned char *__restrict dst, const unsigned char *__restrict src, size_t count) { // Use scalar strategies (_1, _2, _3 ...) using namespace __llvm_libc::scalar; @@ -61,8 +61,8 @@ static void memcpy_impl(char *__restrict dst, const char *__restrict src, LLVM_LIBC_FUNCTION(void *, memcpy, (void *__restrict dst, const void *__restrict src, size_t size)) { - memcpy_impl(reinterpret_cast(dst), - reinterpret_cast(src), size); + memcpy_impl(reinterpret_cast(dst), + reinterpret_cast(src), size); return dst; } diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index ebbe4643e7da6..058ca2a8e7327 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -15,13 +15,13 @@ namespace __llvm_libc { -static inline void move_byte_forward(char *dest_m, const char *src_m, +static inline void move_byte_forward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { for (size_t offset = 0; count; --count, ++offset) dest_m[offset] = src_m[offset]; } -static inline void move_byte_backward(char *dest_m, const char *src_m, +static inline void move_byte_backward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { for (size_t offset = count - 1; count; --count, --offset) dest_m[offset] = src_m[offset]; @@ -29,8 +29,11 @@ static inline void move_byte_backward(char *dest_m, const char *src_m, LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count)) { - char *dest_c = reinterpret_cast(dest); - const char *src_c = reinterpret_cast(src); + if (dest == src) + return dest; + + unsigned char *dest_c = reinterpret_cast(dest); + const unsigned char *src_c = reinterpret_cast(src); // If the distance between src_c and dest_c is equal to or greater // than count (integerAbs(src_c - dest_c) >= count), they would not overlap. @@ -58,7 +61,7 @@ LLVM_LIBC_FUNCTION(void *, memmove, // TODO: Optimize `move_byte_xxx(...)` functions. if (dest_c < src_c) move_byte_forward(dest_c, src_c, count); - if (dest_c > src_c) + else // (dest_c > src_c) move_byte_backward(dest_c, src_c, count); return dest; } diff --git a/libc/src/string/memrchr.cpp b/libc/src/string/memrchr.cpp index b010b8ad87c5f..da5baa47f4f9d 100644 --- a/libc/src/string/memrchr.cpp +++ b/libc/src/string/memrchr.cpp @@ -14,11 +14,10 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(void *, memrchr, (const void *src, int c, size_t n)) { const unsigned char *str = reinterpret_cast(src); - const unsigned char ch = c; + const unsigned char ch = static_cast(c); for (; n != 0; --n) { - const unsigned char *s = str + n - 1; - if (*s == ch) - return const_cast(s); + if (*(--str) == ch) + return const_cast(str); } return nullptr; } diff --git a/libc/src/string/strchr.cpp b/libc/src/string/strchr.cpp index 6288b64b74628..836f243d87593 100644 --- a/libc/src/string/strchr.cpp +++ b/libc/src/string/strchr.cpp @@ -14,12 +14,12 @@ namespace __llvm_libc { // TODO: Look at performance benefits of comparing words. LLVM_LIBC_FUNCTION(char *, strchr, (const char *src, int c)) { - unsigned char *str = - const_cast(reinterpret_cast(src)); - const unsigned char ch = c; - for (; *str && *str != ch; ++str) - ; - return *str == ch ? reinterpret_cast(str) : nullptr; + const char ch = static_cast(c); + for (; *src != ch; ++src) + if (*src == '\0') + return nullptr; + + return const_cast(src); } } // namespace __llvm_libc diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index d081d6c497dfd..b6e0b7761a2b0 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -14,10 +14,56 @@ namespace __llvm_libc { +// Design rationale +// ================ +// +// Using a profiler to observe size distributions for calls into libc +// functions, it was found most operations act on a small number of bytes. +// This makes it important to favor small sizes. +// +// The tests for `count` are in ascending order so the cost of branching is +// proportional to the cost of copying. +// +// The function is written in C++ for several reasons: +// - The compiler can __see__ the code, this is useful when performing Profile +// Guided Optimization as the optimized code can take advantage of branching +// probabilities. +// - It also allows for easier customization and favors testing multiple +// implementation parameters. +// - As compilers and processors get better, the generated code is improved +// with little change on the code side. +static void strcpy_impl(char *__restrict dst, const char *__restrict src, + size_t count) { + // Use scalar strategies (_1, _2, _3 ...) + using namespace __llvm_libc::scalar; + + if (count == 0) + return; + if (count == 1) + return Copy<_1>(dst, src); + if (count == 2) + return Copy<_2>(dst, src); + if (count == 3) + return Copy<_3>(dst, src); + if (count == 4) + return Copy<_4>(dst, src); + if (count < 8) + return Copy>(dst, src, count); + if (count < 16) + return Copy>(dst, src, count); + if (count < 32) + return Copy>(dst, src, count); + if (count < 64) + return Copy>(dst, src, count); + if (count < 128) + return Copy>(dst, src, count); + return Copy::Then>>(dst, src, count); +} + LLVM_LIBC_FUNCTION(char *, strcpy, (char *__restrict dest, const char *__restrict src)) { - return reinterpret_cast( - __llvm_libc::memcpy(dest, src, internal::string_length(src) + 1)); + strcpy_impl(dest, src, internal::string_length(src) + 1)); + return dst; } } // namespace __llvm_libc diff --git a/libc/src/string/string_utils.h b/libc/src/string/string_utils.h index dfb2c8af45279..60ec0687f8811 100644 --- a/libc/src/string/string_utils.h +++ b/libc/src/string/string_utils.h @@ -18,30 +18,31 @@ namespace internal { // Returns the length of a string, denoted by the first occurrence // of a null terminator. static inline size_t string_length(const char *src) { - size_t length; - for (length = 0; *src; ++src, ++length) + const char *const initial = src; + for (; *src != '\0'; ++src) ; - return length; + return src - initial; } // Returns the first occurrence of 'ch' within the first 'n' characters of // 'src'. If 'ch' is not found, returns nullptr. static inline void *find_first_character(const unsigned char *src, unsigned char ch, size_t n) { - for (; n && *src != ch; --n, ++src) - ; - return n ? const_cast(src) : nullptr; + for (; n != 0; --n, ++src) + if (*src == ch) + return const_cast(src); + return nullptr; } // Returns the maximum length span that contains only characters not found in // 'segment'. If no characters are found, returns the length of 'src'. static inline size_t complementary_span(const char *src, const char *segment) { - const char *initial = src; + const char *const initial = src; cpp::Bitset<256> bitset; - for (; *segment; ++segment) + for (; *segment != '\0'; ++segment) bitset.set(*segment); - for (; *src && !bitset.test(*src); ++src) + for (; *src != '\0' && !bitset.test(*src); ++src) ; return src - initial; } @@ -59,22 +60,21 @@ static inline char *string_token(char *__restrict src, const char *__restrict delimiter_string, char **__restrict saveptr) { cpp::Bitset<256> delimiter_set; - for (; *delimiter_string; ++delimiter_string) + for (; *delimiter_string != '\0'; ++delimiter_string) delimiter_set.set(*delimiter_string); src = src ? src : *saveptr; - for (; *src && delimiter_set.test(*src); ++src) + for (; *src != '\0' && delimiter_set.test(*src); ++src) ; - if (!*src) { + if (*src == '\0') { *saveptr = src; return nullptr; } char *token = src; - for (; *src && !delimiter_set.test(*src); ++src) + for (; *src != '\0' && !delimiter_set.test(*src); ++src) ; - if (*src) { - *src = '\0'; - ++src; + if (*src != '\0') { + *src++ = '\0'; } *saveptr = src; return token; diff --git a/libc/src/string/strrchr.cpp b/libc/src/string/strrchr.cpp index 33a638bacd862..21c640772c1f7 100644 --- a/libc/src/string/strrchr.cpp +++ b/libc/src/string/strrchr.cpp @@ -13,12 +13,12 @@ namespace __llvm_libc { LLVM_LIBC_FUNCTION(char *, strrchr, (const char *src, int c)) { - const char ch = c; + const char ch = static_cast(c); char *last_occurrence = nullptr; do { if (*src == ch) last_occurrence = const_cast(src); - } while (*src++); + } while (*src++ != '\0'); return last_occurrence; } From c6ac3ea5536afa67ac1302d5904e10b987943fc6 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:12:39 -0400 Subject: [PATCH 03/16] Update memcpy.cpp --- libc/src/string/memcpy.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libc/src/string/memcpy.cpp b/libc/src/string/memcpy.cpp index dbf59be70cf81..fdb9caf56d669 100644 --- a/libc/src/string/memcpy.cpp +++ b/libc/src/string/memcpy.cpp @@ -30,8 +30,8 @@ namespace __llvm_libc { // implementation parameters. // - As compilers and processors get better, the generated code is improved // with little change on the code side. -static void memcpy_impl(unsigned char *__restrict dst, const unsigned char *__restrict src, - size_t count) { +static void memcpy_impl(unsigned char *__restrict dst, + const unsigned char *__restrict src, size_t count) { // Use scalar strategies (_1, _2, _3 ...) using namespace __llvm_libc::scalar; From 10e9f8e52b959ea64446114e7a37173b6bb532e1 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:18:11 -0400 Subject: [PATCH 04/16] Update memmove.cpp --- libc/src/string/memmove.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index 058ca2a8e7327..3ee0530ea09c4 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -15,14 +15,14 @@ namespace __llvm_libc { -static inline void move_byte_forward(unsigned char *dest_m, const unsigned char *src_m, - size_t count) { +static inline void move_byte_forward(unsigned char *dest_m, + const unsigned char *src_m, size_t count) { for (size_t offset = 0; count; --count, ++offset) dest_m[offset] = src_m[offset]; } -static inline void move_byte_backward(unsigned char *dest_m, const unsigned char *src_m, - size_t count) { +static inline void move_byte_backward(unsigned char *dest_m, + const unsigned char *src_m, size_t count) { for (size_t offset = count - 1; count; --count, --offset) dest_m[offset] = src_m[offset]; } From 8308d315cd6fd3e2890ef4c11360504b652047ca Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:18:32 -0400 Subject: [PATCH 05/16] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 1701954a3d42d..edbc4b80d5fbf 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# The LLVM Compiler Infrastructuren +# The LLVM Compiler Infrastructure This directory and its sub-directories contain source code for LLVM, a toolkit for the construction of highly optimized compilers, From aa3d628e015c3c31b2eab4b6a1c8be327bda386c Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:28:50 -0400 Subject: [PATCH 06/16] Update memmove.cpp --- libc/src/string/memmove.cpp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index 3ee0530ea09c4..3c423a4b74932 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -29,9 +29,6 @@ static inline void move_byte_backward(unsigned char *dest_m, LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count)) { - if (dest == src) - return dest; - unsigned char *dest_c = reinterpret_cast(dest); const unsigned char *src_c = reinterpret_cast(src); @@ -61,7 +58,7 @@ LLVM_LIBC_FUNCTION(void *, memmove, // TODO: Optimize `move_byte_xxx(...)` functions. if (dest_c < src_c) move_byte_forward(dest_c, src_c, count); - else // (dest_c > src_c) + else if (dest_c > src_c) move_byte_backward(dest_c, src_c, count); return dest; } From 109e0dbce4c171bfb0c46e49b085ecef58d4781a Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:29:15 -0400 Subject: [PATCH 07/16] Update strcpy.cpp --- libc/src/string/strcpy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index b6e0b7761a2b0..4fc4f4a191b89 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -63,7 +63,7 @@ static void strcpy_impl(char *__restrict dst, const char *__restrict src, LLVM_LIBC_FUNCTION(char *, strcpy, (char *__restrict dest, const char *__restrict src)) { strcpy_impl(dest, src, internal::string_length(src) + 1)); - return dst; + return dest; } } // namespace __llvm_libc From e8c1fd206bdefc16ed43110c3415f33430f37a13 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:32:25 -0400 Subject: [PATCH 08/16] Update strcpy.cpp --- libc/src/string/strcpy.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index 4fc4f4a191b89..bfdee5c2c5b41 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -7,10 +7,8 @@ //===----------------------------------------------------------------------===// #include "src/string/strcpy.h" -#include "src/string/memcpy.h" -#include "src/string/string_utils.h" - #include "src/__support/common.h" +#include "src/string/memory_utils/elements.h" namespace __llvm_libc { From 7a9e5c0bcd5d153aa4a6fecd7a55afa08aba65cc Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:34:31 -0400 Subject: [PATCH 09/16] Update memmove.cpp --- libc/src/string/memmove.cpp | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index 3c423a4b74932..609619dd18a66 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -15,14 +15,12 @@ namespace __llvm_libc { -static inline void move_byte_forward(unsigned char *dest_m, - const unsigned char *src_m, size_t count) { +static inline void move_byte_forward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { for (size_t offset = 0; count; --count, ++offset) dest_m[offset] = src_m[offset]; } -static inline void move_byte_backward(unsigned char *dest_m, - const unsigned char *src_m, size_t count) { +static inline void move_byte_backward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { for (size_t offset = count - 1; count; --count, --offset) dest_m[offset] = src_m[offset]; } From 67aed6ef01fe1baa8b119667f41437fae73b2938 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:43:16 -0400 Subject: [PATCH 10/16] Update strcpy.cpp --- libc/src/string/strcpy.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index bfdee5c2c5b41..3de9bb53cb1e3 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -60,7 +60,7 @@ static void strcpy_impl(char *__restrict dst, const char *__restrict src, LLVM_LIBC_FUNCTION(char *, strcpy, (char *__restrict dest, const char *__restrict src)) { - strcpy_impl(dest, src, internal::string_length(src) + 1)); + strcpy_impl(dest, src, internal::string_length(src) + 1); return dest; } From c1a4757f87de9595c9abc9b2c5fe68e4de1e9d84 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:43:54 -0400 Subject: [PATCH 11/16] Update strcpy.cpp --- libc/src/string/strcpy.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index 3de9bb53cb1e3..be56b4f9fee22 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -7,6 +7,7 @@ //===----------------------------------------------------------------------===// #include "src/string/strcpy.h" +#include "src/string/string_utils.h" #include "src/__support/common.h" #include "src/string/memory_utils/elements.h" From 3bb2b80671cf67aba2e478c3e5add8e9c8c2585f Mon Sep 17 00:00:00 2001 From: Alfonso Gregory Date: Fri, 23 Jul 2021 16:46:54 -0400 Subject: [PATCH 12/16] Update memmove.cpp --- libc/src/string/memmove.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/libc/src/string/memmove.cpp b/libc/src/string/memmove.cpp index 609619dd18a66..e7b839aa3ebc6 100644 --- a/libc/src/string/memmove.cpp +++ b/libc/src/string/memmove.cpp @@ -15,12 +15,15 @@ namespace __llvm_libc { -static inline void move_byte_forward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { +static inline void move_byte_forward(unsigned char *dest_m, + const unsigned char *src_m, size_t count) { for (size_t offset = 0; count; --count, ++offset) dest_m[offset] = src_m[offset]; } -static inline void move_byte_backward(unsigned char *dest_m, const unsigned char *src_m, size_t count) { +static inline void move_byte_backward(unsigned char *dest_m, + const unsigned char *src_m, + size_t count) { for (size_t offset = count - 1; count; --count, --offset) dest_m[offset] = src_m[offset]; } From 9da400002c8b74b60ae0f6012b67f07273bb79a7 Mon Sep 17 00:00:00 2001 From: Radical Dweamer <83354299+RadiD234@users.noreply.github.com> Date: Sun, 25 Jul 2021 14:45:49 -0400 Subject: [PATCH 13/16] Fix --- libc/src/string/memory_utils/elements.h | 15 +++++++++++++++ libc/src/string/strcpy.cpp | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h index 48fb0084d610f..049d923b75de1 100644 --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -29,12 +29,22 @@ template void Copy(char *__restrict dst, const char *__restrict src) { Element::Copy(dst, src); } + +template +void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src) { + Element::Copy(dst, src); +} // Runtime-size copies from 'src' to 'dst'. template void Copy(char *__restrict dst, const char *__restrict src, size_t size) { Element::Copy(dst, src, size); } +template +void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src, size_t size) { + Element::Copy(dst, src, size); +} + // Fixed-size equality between 'lhs' and 'rhs'. template bool Equals(const char *lhs, const char *rhs) { return Element::Equals(lhs, rhs); @@ -124,6 +134,11 @@ template struct Chained { __llvm_libc::Copy(dst, src); } + static void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src) { + Chained::Copy(dst + Head::kSize, src + Head::kSize); + __llvm_libc::Copy(dst, src); + } + static bool Equals(const char *lhs, const char *rhs) { if (!__llvm_libc::Equals(lhs, rhs)) return false; diff --git a/libc/src/string/strcpy.cpp b/libc/src/string/strcpy.cpp index be56b4f9fee22..e0de497dceec6 100644 --- a/libc/src/string/strcpy.cpp +++ b/libc/src/string/strcpy.cpp @@ -7,9 +7,9 @@ //===----------------------------------------------------------------------===// #include "src/string/strcpy.h" -#include "src/string/string_utils.h" #include "src/__support/common.h" #include "src/string/memory_utils/elements.h" +#include "src/string/string_utils.h" namespace __llvm_libc { From fa9af833665fb0c0571e750e2b61ef155b9519a6 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 25 Jul 2021 14:55:52 -0400 Subject: [PATCH 14/16] Fix --- libc/src/string/memory_utils/elements.h | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h index 049d923b75de1..58e1dc389e5db 100644 --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -29,17 +29,16 @@ template void Copy(char *__restrict dst, const char *__restrict src) { Element::Copy(dst, src); } - template void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src) { Element::Copy(dst, src); } + // Runtime-size copies from 'src' to 'dst'. template void Copy(char *__restrict dst, const char *__restrict src, size_t size) { Element::Copy(dst, src, size); } - template void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src, size_t size) { Element::Copy(dst, src, size); From 00d4310419100cbd44e9ea7741a48f61516fe8ae Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 25 Jul 2021 14:59:36 -0400 Subject: [PATCH 15/16] Update elements.h --- libc/src/string/memory_utils/elements.h | 1 - 1 file changed, 1 deletion(-) diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h index 58e1dc389e5db..4eeb74a0816a9 100644 --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -33,7 +33,6 @@ template void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src) { Element::Copy(dst, src); } - // Runtime-size copies from 'src' to 'dst'. template void Copy(char *__restrict dst, const char *__restrict src, size_t size) { From a062c8e69d6432aebbfa54314985483a49034157 Mon Sep 17 00:00:00 2001 From: Alfonso Gregory <83477269+gAlfonso-bit@users.noreply.github.com> Date: Sun, 25 Jul 2021 15:05:41 -0400 Subject: [PATCH 16/16] Update elements.h --- libc/src/string/memory_utils/elements.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/libc/src/string/memory_utils/elements.h b/libc/src/string/memory_utils/elements.h index 4eeb74a0816a9..443ab21b98cf3 100644 --- a/libc/src/string/memory_utils/elements.h +++ b/libc/src/string/memory_utils/elements.h @@ -39,7 +39,8 @@ void Copy(char *__restrict dst, const char *__restrict src, size_t size) { Element::Copy(dst, src, size); } template -void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src, size_t size) { +void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src, + size_t size) { Element::Copy(dst, src, size); } @@ -132,7 +133,8 @@ template struct Chained { __llvm_libc::Copy(dst, src); } - static void Copy(unsigned char *__restrict dst, const unsigned char *__restrict src) { + static void Copy(unsigned char *__restrict dst, + const unsigned char *__restrict src) { Chained::Copy(dst + Head::kSize, src + Head::kSize); __llvm_libc::Copy(dst, src); }