Skip to content

Commit

Permalink
Patch 14 (#33)
Browse files Browse the repository at this point in the history
* 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

* F

* Update elements.h

* format

* fix

Co-authored-by: Radical Dweamer <83354299+RadiD234@users.noreply.github.com>
  • Loading branch information
AZero13 and Radical Dweamer authored Jul 26, 2021
1 parent f3c34b5 commit 346d2ef
Show file tree
Hide file tree
Showing 35 changed files with 148 additions and 131 deletions.
2 changes: 1 addition & 1 deletion libc/src/__support/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
decltype(__llvm_libc::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
#else
#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist
#define LLVM_LIBC_FUNCTION(type, name, arglist) type name arglist noexcept
#endif

namespace __llvm_libc {
Expand Down
18 changes: 9 additions & 9 deletions libc/src/string/aarch64/memcmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
namespace __llvm_libc {
namespace aarch64 {

static int memcmp_impl(const char *lhs, const char *rhs, size_t count) {
static int memcmp_impl(const char *lhs, const char *rhs,
size_t count) noexcept {
if (count == 0)
return 0;
if (count == 1)
return ThreeWayCompare<_1>(lhs, rhs);
else if (count == 2)
if (count == 2)
return ThreeWayCompare<_2>(lhs, rhs);
else if (count == 3)
if (count == 3)
return ThreeWayCompare<_3>(lhs, rhs);
else if (count < 8)
if (count < 8)
return ThreeWayCompare<HeadTail<_4>>(lhs, rhs, count);
else if (count < 16)
if (count < 16)
return ThreeWayCompare<HeadTail<_8>>(lhs, rhs, count);
else if (count < 128) {
if (count < 128) {
if (Equals<_16>(lhs, rhs)) {
if (count < 32)
return ThreeWayCompare<Tail<_16>>(lhs, rhs, count);
Expand All @@ -51,9 +52,8 @@ static int memcmp_impl(const char *lhs, const char *rhs, size_t count) {
LLVM_LIBC_FUNCTION(int, memcmp,
(const void *lhs, const void *rhs, size_t count)) {

const char *_lhs = reinterpret_cast<const char *>(lhs);
const char *_rhs = reinterpret_cast<const char *>(rhs);
return aarch64::memcmp_impl(_lhs, _rhs, count);
return aarch64::memcmp_impl(reinterpret_cast<const char *>(lhs),
reinterpret_cast<const char *>(rhs), count);
}

} // namespace __llvm_libc
5 changes: 3 additions & 2 deletions libc/src/string/aarch64/memcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ using _64 = Repeated<scalar::UINT64, 8>;
// with little change on the code side.
// This implementation has been tuned for Neoverse-N1.
static void memcpy_aarch64(char *__restrict dst, const char *__restrict src,
size_t count) {
size_t count) noexcept {
if (count == 0)
return;
if (count == 1)
Expand All @@ -68,7 +68,8 @@ static void memcpy_aarch64(char *__restrict dst, const char *__restrict src,

LLVM_LIBC_FUNCTION(void *, memcpy,
(void *__restrict dst, const void *__restrict src,
size_t size)) {
size_t size))
noexcept {
memcpy_aarch64(reinterpret_cast<char *>(dst),
reinterpret_cast<const char *>(src), size);
return dst;
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/bzero.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace __llvm_libc {

void bzero(void *ptr, size_t count);
void bzero(void *ptr, size_t count) noexcept;

} // namespace __llvm_libc

Expand Down
3 changes: 2 additions & 1 deletion libc/src/string/memchr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<const unsigned char *>(src), c, n);
reinterpret_cast<const unsigned char *>(src),
static_cast<unsigned char>(c), n);
}

} // namespace __llvm_libc
2 changes: 1 addition & 1 deletion libc/src/string/memchr.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace __llvm_libc {

void *memchr(const void *src, int c, size_t n);
void *memchr(const void *src, int c, size_t n) noexcept;

} // namespace __llvm_libc

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memcmp.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace __llvm_libc {

int memcmp(const void *lhs, const void *rhs, size_t count);
int memcmp(const void *lhs, const void *rhs, size_t count) noexcept;

} // namespace __llvm_libc

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memcpy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace __llvm_libc {
// - 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,
size_t count) {
size_t count) noexcept {
// Use scalar strategies (_1, _2, _3 ...)
using namespace __llvm_libc::scalar;

Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memcpy.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace __llvm_libc {

void *memcpy(void *__restrict, const void *__restrict, size_t);
void *memcpy(void *__restrict, const void *__restrict, size_t) noexcept;

} // namespace __llvm_libc

Expand Down
22 changes: 12 additions & 10 deletions libc/src/string/memmove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,24 @@

namespace __llvm_libc {

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

static inline void move_byte_backward(char *dest_m, const char *src_m,
size_t count) {
for (size_t offset = count - 1; 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) noexcept {
for (size_t offset = count; offset != 0; --offset)
dest_m[offset - 1] = src_m[offset - 1];
}

LLVM_LIBC_FUNCTION(void *, memmove,
(void *dest, const void *src, size_t count)) {
char *dest_c = reinterpret_cast<char *>(dest);
const char *src_c = reinterpret_cast<const char *>(src);
unsigned char *dest_c = reinterpret_cast<unsigned char *>(dest);
const unsigned char *src_c = reinterpret_cast<const unsigned char *>(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.
Expand Down Expand Up @@ -58,7 +60,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 if (dest_c > src_c)
move_byte_backward(dest_c, src_c, count);
return dest;
}
Expand Down
2 changes: 1 addition & 1 deletion libc/src/string/memmove.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

namespace __llvm_libc {

void *memmove(void *dest, const void *src, size_t count);
void *memmove(void *dest, const void *src, size_t count) noexcept;

} // namespace __llvm_libc

Expand Down
Loading

0 comments on commit 346d2ef

Please sign in to comment.