Skip to content

Commit 1989108

Browse files
Revert "Refactor WIDE_READ to allow finer control over high-performance funct…"
This reverts commit 8701c2a.
1 parent 01737c1 commit 1989108

File tree

13 files changed

+185
-275
lines changed

13 files changed

+185
-275
lines changed

libc/cmake/modules/LLVMLibCCompileOptionRules.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,9 @@ function(_get_compile_options_from_config output_var)
8181
list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
8282
endif()
8383

84-
list(APPEND config_options "-DLIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
85-
list(APPEND config_options "-DLIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
84+
if(LIBC_CONF_STRING_UNSAFE_WIDE_READ)
85+
list(APPEND config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ")
86+
endif()
8687

8788
if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
8889
list(APPEND config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")

libc/config/config.json

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"value": false,
4141
"doc": "Use an alternative printf float implementation based on 320-bit floats"
4242
},
43-
4443
"LIBC_CONF_PRINTF_DISABLE_FIXED_POINT": {
4544
"value": false,
4645
"doc": "Disable printing fixed point values in printf and friends."
@@ -65,13 +64,9 @@
6564
}
6665
},
6766
"string": {
68-
"LIBC_CONF_STRING_LENGTH_IMPL": {
69-
"value": "element",
70-
"doc": "Selects the implementation for string-length: 'element', 'word', 'clang_vector', or 'arch_vector'."
71-
},
72-
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
73-
"value": "element",
74-
"doc": "Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'."
67+
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
68+
"value": false,
69+
"doc": "Read more than a byte at a time to perform byte-string operations like strlen."
7570
},
7671
"LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING": {
7772
"value": false,

libc/config/linux/arm/config.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"string": {
3-
"LIBC_CONF_STRING_LENGTH_IMPL": {
4-
"value": "element"
5-
}
6-
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
7-
"value": "element"
3+
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
4+
"value": false
85
}
96
}
107
}

libc/config/linux/config.json

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"string": {
3-
"LIBC_CONF_STRING_LENGTH_IMPL": {
4-
"value": "clang_vector",
5-
},
6-
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
7-
"value": "word",
3+
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
4+
"value": true
85
}
96
}
107
}
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,7 @@
11
{
22
"string": {
3-
"LIBC_CONF_STRING_LENGTH_IMPL": {
4-
"value": "element"
5-
}
6-
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
7-
"value": "element"
3+
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
4+
"value": false
85
}
96
}
107
}

libc/docs/configure.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,8 @@ to learn about the defaults for your platform and target.
5858
* **"setjmp" options**
5959
- ``LIBC_CONF_SETJMP_AARCH64_RESTORE_PLATFORM_REGISTER``: Make setjmp save the value of x18, and longjmp restore it. The AArch64 ABI delegates this register to platform ABIs, which can choose whether to make it caller-saved.
6060
* **"string" options**
61-
- ``LIBC_CONF_FIND_FIRST_CHARACTER_IMPL``: Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'.
6261
- ``LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING``: Inserts prefetch for write instructions (PREFETCHW) for memset on x86 to recover performance when hardware prefetcher is disabled.
63-
- ``LIBC_CONF_STRING_LENGTH_IMPL``: Selects the implementation for string-length: 'element', 'word', 'clang_vector', or 'arch_vector'.
62+
- ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time to perform byte-string operations like strlen.
6463
* **"threads" options**
6564
- ``LIBC_CONF_THREAD_MODE``: The implementation used for Mutex, acceptable values are LIBC_THREAD_MODE_PLATFORM, LIBC_THREAD_MODE_SINGLE, and LIBC_THREAD_MODE_EXTERNAL.
6665
* **"time" options**

libc/src/string/memory_utils/aarch64/inline_strlen.h

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#include <arm_neon.h>
1616
#include <stddef.h> // size_t
1717
namespace LIBC_NAMESPACE_DECL {
18-
namespace internal::neon {
18+
namespace neon {
1919
[[maybe_unused]] LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE static size_t
2020
string_length(const char *src) {
2121
using Vector __attribute__((may_alias)) = uint8x8_t;
@@ -43,15 +43,15 @@ string_length(const char *src) {
4343
(cpp::countr_zero(cmp) >> 3));
4444
}
4545
}
46-
} // namespace internal::neon
46+
} // namespace neon
4747
} // namespace LIBC_NAMESPACE_DECL
4848
#endif // __ARM_NEON
4949

5050
#ifdef LIBC_TARGET_CPU_HAS_SVE
5151
#include "src/__support/macros/optimization.h"
5252
#include <arm_sve.h>
5353
namespace LIBC_NAMESPACE_DECL {
54-
namespace internal::sve {
54+
namespace sve {
5555
[[maybe_unused]] LIBC_INLINE static size_t string_length(const char *src) {
5656
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(src);
5757
// Initialize the first-fault register to all true
@@ -92,19 +92,15 @@ namespace internal::sve {
9292
len += svcntp_b8(all_true, before_zero);
9393
return len;
9494
}
95-
} // namespace internal::sve
95+
} // namespace sve
9696
} // namespace LIBC_NAMESPACE_DECL
9797
#endif // LIBC_TARGET_CPU_HAS_SVE
9898

9999
namespace LIBC_NAMESPACE_DECL {
100-
namespace internal::arch_vector {
101-
[[maybe_unused]] LIBC_INLINE size_t string_length(const char *src) {
102100
#ifdef LIBC_TARGET_CPU_HAS_SVE
103-
return sve::string_length(src);
101+
namespace string_length_impl = sve;
104102
#elif defined(__ARM_NEON)
105-
return neon::string_length(src);
103+
namespace string_length_impl = neon;
106104
#endif
107-
}
108-
} // namespace internal::arch_vector
109105
} // namespace LIBC_NAMESPACE_DECL
110106
#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_STRLEN_H

libc/src/string/memory_utils/generic/inline_strlen.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include "src/__support/common.h"
1515

1616
namespace LIBC_NAMESPACE_DECL {
17-
namespace clang_vector {
17+
namespace internal {
1818

1919
// Exploit the underlying integer representation to do a variable shift.
2020
LIBC_INLINE constexpr cpp::simd_mask<char> shift_mask(cpp::simd_mask<char> m,
@@ -46,8 +46,9 @@ LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE size_t string_length(const char *src) {
4646
cpp::find_first_set(mask);
4747
}
4848
}
49-
} // namespace clang_vector
49+
} // namespace internal
5050

51+
namespace string_length_impl = internal;
5152
} // namespace LIBC_NAMESPACE_DECL
5253

5354
#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_INLINE_STRLEN_H

libc/src/string/memory_utils/x86_64/inline_strlen.h

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@
1515

1616
namespace LIBC_NAMESPACE_DECL {
1717

18-
namespace internal::arch_vector {
19-
18+
namespace string_length_internal {
2019
// Return a bit-mask with the nth bit set if the nth-byte in block_ptr is zero.
2120
template <typename Vector, typename Mask>
2221
LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE static Mask
@@ -93,18 +92,15 @@ namespace avx512 {
9392
}
9493
} // namespace avx512
9594
#endif
95+
} // namespace string_length_internal
9696

97-
[[maybe_unused]] LIBC_INLINE size_t string_length(const char *src) {
9897
#if defined(__AVX512F__)
99-
return avx512::string_length(src);
98+
namespace string_length_impl = string_length_internal::avx512;
10099
#elif defined(__AVX2__)
101-
return avx2::string_length(src);
100+
namespace string_length_impl = string_length_internal::avx2;
102101
#else
103-
return sse2::string_length(src);
102+
namespace string_length_impl = string_length_internal::sse2;
104103
#endif
105-
}
106-
107-
} // namespace internal::arch_vector
108104

109105
} // namespace LIBC_NAMESPACE_DECL
110106

0 commit comments

Comments
 (0)