|
9 | 9 | #ifndef LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H
|
10 | 10 | #define LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H
|
11 | 11 |
|
12 |
| -#include "src/__support/common.h" |
13 |
| -#include "src/__support/macros/optimization.h" |
14 |
| -#include "src/__support/macros/properties/architectures.h" |
15 |
| -#include "src/string/memory_utils/generic/aligned_access.h" |
16 |
| -#include "src/string/memory_utils/generic/byte_per_byte.h" |
17 |
| -#include "src/string/memory_utils/op_aarch64.h" |
18 |
| -#include "src/string/memory_utils/op_builtin.h" |
19 |
| -#include "src/string/memory_utils/op_generic.h" |
20 |
| -#include "src/string/memory_utils/op_x86.h" |
21 |
| -#include "src/string/memory_utils/utils.h" |
| 12 | +#include "src/__support/macros/config.h" // LIBC_INLINE |
| 13 | +#include "src/__support/macros/properties/architectures.h" // LIBC_TARGET_ARCH_IS_ |
| 14 | +#include "src/string/memory_utils/utils.h" // Ptr, CPtr |
22 | 15 |
|
23 | 16 | #include <stddef.h> // size_t
|
24 | 17 |
|
25 |
| -namespace __llvm_libc { |
26 |
| - |
27 |
| -#if defined(LIBC_TARGET_ARCH_IS_X86) |
28 |
| -[[maybe_unused]] LIBC_INLINE static void |
29 |
| -inline_memset_x86(Ptr dst, uint8_t value, size_t count) { |
30 |
| -#if defined(__AVX512F__) |
31 |
| - using uint128_t = generic_v128; |
32 |
| - using uint256_t = generic_v256; |
33 |
| - using uint512_t = generic_v512; |
34 |
| -#elif defined(__AVX__) |
35 |
| - using uint128_t = generic_v128; |
36 |
| - using uint256_t = generic_v256; |
37 |
| - using uint512_t = cpp::array<generic_v256, 2>; |
38 |
| -#elif defined(__SSE2__) |
39 |
| - using uint128_t = generic_v128; |
40 |
| - using uint256_t = cpp::array<generic_v128, 2>; |
41 |
| - using uint512_t = cpp::array<generic_v128, 4>; |
42 |
| -#else |
43 |
| - using uint128_t = cpp::array<uint64_t, 2>; |
44 |
| - using uint256_t = cpp::array<uint64_t, 4>; |
45 |
| - using uint512_t = cpp::array<uint64_t, 8>; |
46 |
| -#endif |
47 |
| - |
48 |
| - if (count == 0) |
49 |
| - return; |
50 |
| - if (count == 1) |
51 |
| - return generic::Memset<uint8_t>::block(dst, value); |
52 |
| - if (count == 2) |
53 |
| - return generic::Memset<uint16_t>::block(dst, value); |
54 |
| - if (count == 3) |
55 |
| - return generic::MemsetSequence<uint16_t, uint8_t>::block(dst, value); |
56 |
| - if (count <= 8) |
57 |
| - return generic::Memset<uint32_t>::head_tail(dst, value, count); |
58 |
| - if (count <= 16) |
59 |
| - return generic::Memset<uint64_t>::head_tail(dst, value, count); |
60 |
| - if (count <= 32) |
61 |
| - return generic::Memset<uint128_t>::head_tail(dst, value, count); |
62 |
| - if (count <= 64) |
63 |
| - return generic::Memset<uint256_t>::head_tail(dst, value, count); |
64 |
| - if (count <= 128) |
65 |
| - return generic::Memset<uint512_t>::head_tail(dst, value, count); |
66 |
| - // Aligned loop |
67 |
| - generic::Memset<uint256_t>::block(dst, value); |
68 |
| - align_to_next_boundary<32>(dst, count); |
69 |
| - return generic::Memset<uint256_t>::loop_and_tail(dst, value, count); |
70 |
| -} |
71 |
| -#endif // defined(LIBC_TARGET_ARCH_IS_X86) |
72 |
| - |
73 |
| -#if defined(LIBC_TARGET_ARCH_IS_AARCH64) |
74 |
| -[[maybe_unused]] LIBC_INLINE static void |
75 |
| -inline_memset_aarch64(Ptr dst, uint8_t value, size_t count) { |
76 |
| - static_assert(aarch64::kNeon, "aarch64 supports vector types"); |
77 |
| - using uint128_t = generic_v128; |
78 |
| - using uint256_t = generic_v256; |
79 |
| - using uint512_t = generic_v512; |
80 |
| - if (count == 0) |
81 |
| - return; |
82 |
| - if (count <= 3) { |
83 |
| - generic::Memset<uint8_t>::block(dst, value); |
84 |
| - if (count > 1) |
85 |
| - generic::Memset<uint16_t>::tail(dst, value, count); |
86 |
| - return; |
87 |
| - } |
88 |
| - if (count <= 8) |
89 |
| - return generic::Memset<uint32_t>::head_tail(dst, value, count); |
90 |
| - if (count <= 16) |
91 |
| - return generic::Memset<uint64_t>::head_tail(dst, value, count); |
92 |
| - if (count <= 32) |
93 |
| - return generic::Memset<uint128_t>::head_tail(dst, value, count); |
94 |
| - if (count <= (32 + 64)) { |
95 |
| - generic::Memset<uint256_t>::block(dst, value); |
96 |
| - if (count <= 64) |
97 |
| - return generic::Memset<uint256_t>::tail(dst, value, count); |
98 |
| - generic::Memset<uint256_t>::block(dst + 32, value); |
99 |
| - generic::Memset<uint256_t>::tail(dst, value, count); |
100 |
| - return; |
101 |
| - } |
102 |
| - if (count >= 448 && value == 0 && aarch64::neon::hasZva()) { |
103 |
| - generic::Memset<uint512_t>::block(dst, 0); |
104 |
| - align_to_next_boundary<64>(dst, count); |
105 |
| - return aarch64::neon::BzeroCacheLine::loop_and_tail(dst, 0, count); |
106 |
| - } else { |
107 |
| - generic::Memset<uint128_t>::block(dst, value); |
108 |
| - align_to_next_boundary<16>(dst, count); |
109 |
| - return generic::Memset<uint512_t>::loop_and_tail(dst, value, count); |
110 |
| - } |
111 |
| -} |
112 |
| -#endif // defined(LIBC_TARGET_ARCH_IS_AARCH64) |
113 |
| - |
114 |
| -LIBC_INLINE static void inline_memset(Ptr dst, uint8_t value, size_t count) { |
115 | 18 | #if defined(LIBC_TARGET_ARCH_IS_X86)
|
116 |
| - return inline_memset_x86(dst, value, count); |
| 19 | +#include "src/string/memory_utils/x86_64/memset_implementations.h" |
| 20 | +#define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_x86 |
117 | 21 | #elif defined(LIBC_TARGET_ARCH_IS_AARCH64)
|
118 |
| - return inline_memset_aarch64(dst, value, count); |
119 |
| -#elif defined(LIBC_TARGET_ARCH_IS_RISCV64) |
120 |
| - return inline_memset_aligned_access_64bit(dst, value, count); |
121 |
| -#elif defined(LIBC_TARGET_ARCH_IS_RISCV32) |
122 |
| - return inline_memset_aligned_access_32bit(dst, value, count); |
| 22 | +#include "src/string/memory_utils/aarch64/memset_implementations.h" |
| 23 | +#define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_aarch64 |
| 24 | +#elif defined(LIBC_TARGET_ARCH_IS_ANY_RISCV) |
| 25 | +#include "src/string/memory_utils/riscv/memset_implementations.h" |
| 26 | +#define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_riscv |
123 | 27 | #else
|
124 |
| - return inline_memset_byte_per_byte(dst, value, count); |
| 28 | +// We may want to error instead of defaulting to suboptimal implementation. |
| 29 | +#include "src/string/memory_utils/generic/byte_per_byte.h" |
| 30 | +#define LIBC_SRC_STRING_MEMORY_UTILS_MEMSET inline_memset_byte_per_byte |
125 | 31 | #endif
|
126 |
| -} |
| 32 | + |
| 33 | +namespace __llvm_libc { |
127 | 34 |
|
128 | 35 | LIBC_INLINE static void inline_memset(void *dst, uint8_t value, size_t count) {
|
129 |
| - inline_memset(reinterpret_cast<Ptr>(dst), value, count); |
| 36 | + LIBC_SRC_STRING_MEMORY_UTILS_MEMSET(reinterpret_cast<Ptr>(dst), value, count); |
130 | 37 | }
|
131 | 38 |
|
132 | 39 | } // namespace __llvm_libc
|
133 | 40 |
|
| 41 | +#undef LIBC_SRC_STRING_MEMORY_UTILS_MEMSET |
| 42 | + |
134 | 43 | #endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_MEMSET_IMPLEMENTATIONS_H
|
0 commit comments