Skip to content
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
4 changes: 2 additions & 2 deletions libc/src/__support/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@
LLVM_LIBC_FUNCTION_ATTR decltype(__llvm_libc::name) \
__##name##_impl__ __asm__(#name); \
decltype(__llvm_libc::name) name [[gnu::alias(#name)]]; \
type __##name##_impl__ arglist
type __##name##_impl__ arglist noexcept
#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
2 changes: 1 addition & 1 deletion 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 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