Skip to content

Commit c44d91e

Browse files
AZero13Radical Dweamer
andauthored
Patch 14 (#27)
* Update README.md * 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 * Update memcpy.cpp * Update memmove.cpp * Update README.md * Update memmove.cpp * Update strcpy.cpp * Update strcpy.cpp * Update memmove.cpp * Update strcpy.cpp * Update strcpy.cpp * Update memmove.cpp * Fix * Fix * Update elements.h * Update elements.h * Oh * j * D * Update memcpy.cpp * fix * Update memmove.cpp * No except time * Update strspn.cpp * Update memmove.cpp Co-authored-by: Radical Dweamer <[email protected]>
1 parent f522fd3 commit c44d91e

26 files changed

+152
-128
lines changed

libc/src/string/aarch64/memcmp.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
namespace __llvm_libc {
1515
namespace aarch64 {
1616

17-
static int memcmp_impl(const char *lhs, const char *rhs, size_t count) {
17+
static int memcmp_impl(const char *lhs, const char *rhs,
18+
size_t count) noexcept {
1819
if (count == 0)
1920
return 0;
2021
if (count == 1)
2122
return ThreeWayCompare<_1>(lhs, rhs);
22-
else if (count == 2)
23+
if (count == 2)
2324
return ThreeWayCompare<_2>(lhs, rhs);
24-
else if (count == 3)
25+
if (count == 3)
2526
return ThreeWayCompare<_3>(lhs, rhs);
26-
else if (count < 8)
27+
if (count < 8)
2728
return ThreeWayCompare<HeadTail<_4>>(lhs, rhs, count);
28-
else if (count < 16)
29+
if (count < 16)
2930
return ThreeWayCompare<HeadTail<_8>>(lhs, rhs, count);
30-
else if (count < 128) {
31+
if (count < 128) {
3132
if (Equals<_16>(lhs, rhs)) {
3233
if (count < 32)
3334
return ThreeWayCompare<Tail<_16>>(lhs, rhs, count);
@@ -49,11 +50,11 @@ static int memcmp_impl(const char *lhs, const char *rhs, size_t count) {
4950
} // namespace aarch64
5051

5152
LLVM_LIBC_FUNCTION(int, memcmp,
52-
(const void *lhs, const void *rhs, size_t count)) {
53+
(const void *lhs, const void *rhs, size_t count))
54+
noexcept {
5355

54-
const char *_lhs = reinterpret_cast<const char *>(lhs);
55-
const char *_rhs = reinterpret_cast<const char *>(rhs);
56-
return aarch64::memcmp_impl(_lhs, _rhs, count);
56+
return aarch64::memcmp_impl(reinterpret_cast<const char *>(lhs),
57+
reinterpret_cast<const char *>(rhs), count);
5758
}
5859

5960
} // namespace __llvm_libc

libc/src/string/aarch64/memcpy.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ using _64 = Repeated<scalar::UINT64, 8>;
4242
// with little change on the code side.
4343
// This implementation has been tuned for Neoverse-N1.
4444
static void memcpy_aarch64(char *__restrict dst, const char *__restrict src,
45-
size_t count) {
45+
size_t count) noexcept {
4646
if (count == 0)
4747
return;
4848
if (count == 1)
@@ -68,7 +68,8 @@ static void memcpy_aarch64(char *__restrict dst, const char *__restrict src,
6868

6969
LLVM_LIBC_FUNCTION(void *, memcpy,
7070
(void *__restrict dst, const void *__restrict src,
71-
size_t size)) {
71+
size_t size))
72+
noexcept {
7273
memcpy_aarch64(reinterpret_cast<char *>(dst),
7374
reinterpret_cast<const char *>(src), size);
7475
return dst;

libc/src/string/memchr.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,10 @@
1515
namespace __llvm_libc {
1616

1717
// TODO: Look at performance benefits of comparing words.
18-
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) {
18+
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) noexcept{
1919
return internal::find_first_character(
20-
reinterpret_cast<const unsigned char *>(src), c, n);
20+
reinterpret_cast<const unsigned char *>(src),
21+
static_cast<unsigned char>(c), n);
2122
}
2223

2324
} // namespace __llvm_libc

libc/src/string/memcmp.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ namespace __llvm_libc {
1414

1515
// TODO: It is a simple implementation, an optimized version is preparing.
1616
LLVM_LIBC_FUNCTION(int, memcmp,
17-
(const void *lhs, const void *rhs, size_t count)) {
17+
(const void *lhs, const void *rhs, size_t count)) noexcept {
1818
const unsigned char *_lhs = reinterpret_cast<const unsigned char *>(lhs);
1919
const unsigned char *_rhs = reinterpret_cast<const unsigned char *>(rhs);
2020
for (size_t i = 0; i < count; ++i)

libc/src/string/memcpy.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ namespace __llvm_libc {
3131
// - As compilers and processors get better, the generated code is improved
3232
// with little change on the code side.
3333
static void memcpy_impl(char *__restrict dst, const char *__restrict src,
34-
size_t count) {
34+
size_t count) noexcept {
3535
// Use scalar strategies (_1, _2, _3 ...)
3636
using namespace __llvm_libc::scalar;
3737

@@ -60,7 +60,7 @@ static void memcpy_impl(char *__restrict dst, const char *__restrict src,
6060

6161
LLVM_LIBC_FUNCTION(void *, memcpy,
6262
(void *__restrict dst, const void *__restrict src,
63-
size_t size)) {
63+
size_t size)) noexcept {
6464
memcpy_impl(reinterpret_cast<char *>(dst),
6565
reinterpret_cast<const char *>(src), size);
6666
return dst;

libc/src/string/memmove.cpp

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,22 +15,24 @@
1515

1616
namespace __llvm_libc {
1717

18-
static inline void move_byte_forward(char *dest_m, const char *src_m,
19-
size_t count) {
20-
for (size_t offset = 0; count; --count, ++offset)
18+
static inline void move_byte_forward(unsigned char *dest_m,
19+
const unsigned char *src_m,
20+
size_t count) noexcept {
21+
for (size_t offset = 0; offset != count; ++offset)
2122
dest_m[offset] = src_m[offset];
2223
}
2324

24-
static inline void move_byte_backward(char *dest_m, const char *src_m,
25-
size_t count) {
26-
for (size_t offset = count - 1; count; --count, --offset)
27-
dest_m[offset] = src_m[offset];
25+
static inline void move_byte_backward(unsigned char *dest_m,
26+
const unsigned char *src_m,
27+
size_t count) noexcept {
28+
for (size_t offset = count; offset != 0; --offset)
29+
dest_m[offset - 1] = src_m[offset - 1];
2830
}
2931

30-
LLVM_LIBC_FUNCTION(void *, memmove,
31-
(void *dest, const void *src, size_t count)) {
32-
char *dest_c = reinterpret_cast<char *>(dest);
33-
const char *src_c = reinterpret_cast<const char *>(src);
32+
LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count))
33+
noexcept {
34+
unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest);
35+
const unsigned char *src_c = reinterpret_cast<const unsigned char *>(src);
3436

3537
// If the distance between src_c and dest_c is equal to or greater
3638
// than count (integerAbs(src_c - dest_c) >= count), they would not overlap.
@@ -58,7 +60,7 @@ LLVM_LIBC_FUNCTION(void *, memmove,
5860
// TODO: Optimize `move_byte_xxx(...)` functions.
5961
if (dest_c < src_c)
6062
move_byte_forward(dest_c, src_c, count);
61-
if (dest_c > src_c)
63+
else if (dest_c > src_c)
6264
move_byte_backward(dest_c, src_c, count);
6365
return dest;
6466
}

0 commit comments

Comments
 (0)