Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch 14 #31

Merged
merged 28 commits into from
Jul 26, 2021
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
21 changes: 11 additions & 10 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 @@ -49,11 +50,11 @@ static int memcmp_impl(const char *lhs, const char *rhs, size_t count) {
} // namespace aarch64

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

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.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

namespace __llvm_libc {

LLVM_LIBC_FUNCTION(void, bzero, (void *ptr, size_t count)) {
LLVM_LIBC_FUNCTION(void, bzero, (void *ptr, size_t count)) noexcept {
GeneralPurposeMemset(reinterpret_cast<char *>(ptr), 0, count);
}

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
6 changes: 4 additions & 2 deletions libc/src/string/memchr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
namespace __llvm_libc {

// TODO: Look at performance benefits of comparing words.
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n)) {
LLVM_LIBC_FUNCTION(void *, memchr, (const void *src, int c, size_t n))
noexcept {
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
3 changes: 2 additions & 1 deletion libc/src/string/memcmp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ namespace __llvm_libc {

// TODO: It is a simple implementation, an optimized version is preparing.
LLVM_LIBC_FUNCTION(int, memcmp,
(const void *lhs, const void *rhs, size_t count)) {
(const void *lhs, const void *rhs, size_t count))
noexcept {
const unsigned char *_lhs = reinterpret_cast<const unsigned char *>(lhs);
const unsigned char *_rhs = reinterpret_cast<const unsigned char *>(rhs);
for (size_t i = 0; i < count; ++i)
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
5 changes: 3 additions & 2 deletions 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 Expand Up @@ -60,7 +60,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)) {
size_t size))
noexcept {
memcpy_impl(reinterpret_cast<char *>(dst),
reinterpret_cast<const char *>(src), size);
return dst;
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
26 changes: 14 additions & 12 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);
LLVM_LIBC_FUNCTION(void *, memmove, (void *dest, const void *src, size_t count))
noexcept {
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