Skip to content

Commit 6d252a4

Browse files
committed
Revert "[libc] New version of the mem* framework"
This reverts commit 9721687.
1 parent 84f887c commit 6d252a4

26 files changed

+1895
-1740
lines changed

libc/src/stdio/printf_core/string_writer.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void StringWriter::write(char new_char, size_t len) {
3333
len = available_capacity;
3434

3535
if (len > 0) {
36-
inline_memset(cur_buffer, static_cast<uint8_t>(new_char), len);
36+
inline_memset(cur_buffer, new_char, len);
3737
cur_buffer += len;
3838
available_capacity -= len;
3939
}

libc/src/string/bcmp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ namespace __llvm_libc {
1414

1515
LLVM_LIBC_FUNCTION(int, bcmp,
1616
(const void *lhs, const void *rhs, size_t count)) {
17-
return static_cast<int>(inline_bcmp(static_cast<const char *>(lhs),
18-
static_cast<const char *>(rhs), count));
17+
return inline_bcmp(static_cast<const char *>(lhs),
18+
static_cast<const char *>(rhs), count);
1919
}
2020

2121
} // namespace __llvm_libc

libc/src/string/memcmp.cpp

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

1616
LLVM_LIBC_FUNCTION(int, memcmp,
1717
(const void *lhs, const void *rhs, size_t count)) {
18-
return static_cast<int>(inline_memcmp(static_cast<const char *>(lhs),
19-
static_cast<const char *>(rhs), count));
18+
return inline_memcmp(static_cast<const char *>(lhs),
19+
static_cast<const char *>(rhs), count);
2020
}
2121

2222
} // namespace __llvm_libc

libc/src/string/memmove.cpp

Lines changed: 16 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -9,104 +9,36 @@
99
#include "src/string/memmove.h"
1010

1111
#include "src/__support/common.h"
12-
#include "src/string/memory_utils/op_aarch64.h"
13-
#include "src/string/memory_utils/op_builtin.h"
14-
#include "src/string/memory_utils/op_generic.h"
15-
#include "src/string/memory_utils/op_x86.h"
12+
#include "src/__support/integer_operations.h"
13+
#include "src/string/memory_utils/elements.h"
1614
#include <stddef.h> // size_t, ptrdiff_t
1715

18-
#include <stdio.h>
19-
2016
namespace __llvm_libc {
2117

22-
[[maybe_unused]] static inline void
23-
inline_memmove_embedded_tiny(Ptr dst, CPtr src, size_t count) {
24-
if ((count == 0) || (dst == src))
25-
return;
26-
if (dst < src) {
27-
#pragma nounroll
28-
for (size_t offset = 0; offset < count; ++offset)
29-
builtin::Memcpy<1>::block(dst + offset, src + offset);
30-
} else {
31-
#pragma nounroll
32-
for (ptrdiff_t offset = count; offset >= 0; --offset)
33-
builtin::Memcpy<1>::block(dst + offset, src + offset);
34-
}
35-
}
36-
37-
template <size_t MaxSize>
38-
[[maybe_unused]] static inline void inline_memmove_generic(Ptr dst, CPtr src,
39-
size_t count) {
18+
static inline void inline_memmove(char *dst, const char *src, size_t count) {
19+
using namespace __llvm_libc::scalar;
4020
if (count == 0)
4121
return;
4222
if (count == 1)
43-
return generic::Memmove<1, MaxSize>::block(dst, src);
23+
return move<_1>(dst, src);
4424
if (count <= 4)
45-
return generic::Memmove<2, MaxSize>::head_tail(dst, src, count);
25+
return move<HeadTail<_2>>(dst, src, count);
4626
if (count <= 8)
47-
return generic::Memmove<4, MaxSize>::head_tail(dst, src, count);
27+
return move<HeadTail<_4>>(dst, src, count);
4828
if (count <= 16)
49-
return generic::Memmove<8, MaxSize>::head_tail(dst, src, count);
29+
return move<HeadTail<_8>>(dst, src, count);
5030
if (count <= 32)
51-
return generic::Memmove<16, MaxSize>::head_tail(dst, src, count);
31+
return move<HeadTail<_16>>(dst, src, count);
5232
if (count <= 64)
53-
return generic::Memmove<32, MaxSize>::head_tail(dst, src, count);
33+
return move<HeadTail<_32>>(dst, src, count);
5434
if (count <= 128)
55-
return generic::Memmove<64, MaxSize>::head_tail(dst, src, count);
56-
if (dst < src) {
57-
generic::Memmove<32, MaxSize>::template align_forward<Arg::Src>(dst, src,
58-
count);
59-
return generic::Memmove<64, MaxSize>::loop_and_tail_forward(dst, src,
60-
count);
61-
} else {
62-
generic::Memmove<32, MaxSize>::template align_backward<Arg::Src>(dst, src,
63-
count);
64-
return generic::Memmove<64, MaxSize>::loop_and_tail_backward(dst, src,
65-
count);
66-
}
67-
}
35+
return move<HeadTail<_64>>(dst, src, count);
6836

69-
static inline void inline_memmove(Ptr dst, CPtr src, size_t count) {
70-
#if defined(LLVM_LIBC_ARCH_X86) || defined(LLVM_LIBC_ARCH_AARCH64)
71-
#if defined(LLVM_LIBC_ARCH_X86)
72-
static constexpr size_t kMaxSize = x86::kAvx512F ? 64
73-
: x86::kAvx ? 32
74-
: x86::kSse2 ? 16
75-
: 8;
76-
#elif defined(LLVM_LIBC_ARCH_AARCH64)
77-
static constexpr size_t kMaxSize = aarch64::kNeon ? 16 : 8;
78-
#endif
79-
// return inline_memmove_generic<kMaxSize>(dst, src, count);
80-
if (count == 0)
81-
return;
82-
if (count == 1)
83-
return generic::Memmove<1, kMaxSize>::block(dst, src);
84-
if (count <= 4)
85-
return generic::Memmove<2, kMaxSize>::head_tail(dst, src, count);
86-
if (count <= 8)
87-
return generic::Memmove<4, kMaxSize>::head_tail(dst, src, count);
88-
if (count <= 16)
89-
return generic::Memmove<8, kMaxSize>::head_tail(dst, src, count);
90-
if (count <= 32)
91-
return generic::Memmove<16, kMaxSize>::head_tail(dst, src, count);
92-
if (count <= 64)
93-
return generic::Memmove<32, kMaxSize>::head_tail(dst, src, count);
94-
if (count <= 128)
95-
return generic::Memmove<64, kMaxSize>::head_tail(dst, src, count);
96-
if (dst < src) {
97-
generic::Memmove<32, kMaxSize>::align_forward<Arg::Src>(dst, src, count);
98-
return generic::Memmove<64, kMaxSize>::loop_and_tail_forward(dst, src,
99-
count);
100-
} else {
101-
generic::Memmove<32, kMaxSize>::align_backward<Arg::Src>(dst, src, count);
102-
return generic::Memmove<64, kMaxSize>::loop_and_tail_backward(dst, src,
103-
count);
104-
}
105-
#elif defined(LLVM_LIBC_ARCH_ARM)
106-
return inline_memmove_embedded_tiny(dst, src, count);
107-
#else
108-
#error "Unsupported platform"
109-
#endif
37+
using AlignedMoveLoop = Align<_16, Arg::Src>::Then<Loop<_64>>;
38+
if (dst < src)
39+
return move<AlignedMoveLoop>(dst, src, count);
40+
else if (dst > src)
41+
return move_backward<AlignedMoveLoop>(dst, src, count);
11042
}
11143

11244
LLVM_LIBC_FUNCTION(void *, memmove,

libc/src/string/memory_utils/CMakeLists.txt

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22
add_header_library(
33
memory_utils
44
HDRS
5+
utils.h
6+
elements.h
57
bcmp_implementations.h
68
bzero_implementations.h
79
memcmp_implementations.h
810
memcpy_implementations.h
911
memset_implementations.h
10-
op_aarch64.h
11-
op_higher_order.h
12-
op_builtin.h
13-
op_generic.h
14-
op_x86.h
15-
utils.h
1612
DEPS
1713
libc.src.__support.CPP.bit
1814
)

libc/src/string/memory_utils/README.md

Lines changed: 0 additions & 97 deletions
This file was deleted.

0 commit comments

Comments
 (0)