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
5 changes: 3 additions & 2 deletions libc/cmake/modules/LLVMLibCCompileOptionRules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ function(_get_compile_options_from_config output_var)
list(APPEND config_options "-DLIBC_QSORT_IMPL=${LIBC_CONF_QSORT_IMPL}")
endif()

list(APPEND config_options "-DLIBC_COPT_STRING_LENGTH_IMPL=${LIBC_CONF_STRING_LENGTH_IMPL}")
list(APPEND config_options "-DLIBC_COPT_FIND_FIRST_CHARACTER_IMPL=${LIBC_CONF_FIND_FIRST_CHARACTER_IMPL}")
if(LIBC_CONF_STRING_UNSAFE_WIDE_READ)
list(APPEND config_options "-DLIBC_COPT_STRING_UNSAFE_WIDE_READ")
endif()

if(LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING)
list(APPEND config_options "-DLIBC_COPT_MEMSET_X86_USE_SOFTWARE_PREFETCHING")
Expand Down
11 changes: 3 additions & 8 deletions libc/config/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
"value": false,
"doc": "Use an alternative printf float implementation based on 320-bit floats"
},

"LIBC_CONF_PRINTF_DISABLE_FIXED_POINT": {
"value": false,
"doc": "Disable printing fixed point values in printf and friends."
Expand All @@ -65,13 +64,9 @@
}
},
"string": {
"LIBC_CONF_STRING_LENGTH_IMPL": {
"value": "element",
"doc": "Selects the implementation for string-length: 'element', 'word', 'clang_vector', or 'arch_vector'."
},
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
"value": "element",
"doc": "Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'."
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": false,
"doc": "Read more than a byte at a time to perform byte-string operations like strlen."
},
"LIBC_CONF_MEMSET_X86_USE_SOFTWARE_PREFETCHING": {
"value": false,
Expand Down
7 changes: 2 additions & 5 deletions libc/config/linux/arm/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"string": {
"LIBC_CONF_STRING_LENGTH_IMPL": {
"value": "element"
}
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
"value": "element"
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": false
}
}
}
7 changes: 2 additions & 5 deletions libc/config/linux/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"string": {
"LIBC_CONF_STRING_LENGTH_IMPL": {
"value": "clang_vector",
},
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
"value": "word",
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": true
}
}
}
7 changes: 2 additions & 5 deletions libc/config/linux/riscv/config.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
{
"string": {
"LIBC_CONF_STRING_LENGTH_IMPL": {
"value": "element"
}
"LIBC_CONF_FIND_FIRST_CHARACTER_IMPL": {
"value": "element"
"LIBC_CONF_STRING_UNSAFE_WIDE_READ": {
"value": false
}
}
}
3 changes: 1 addition & 2 deletions libc/docs/configure.rst
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ to learn about the defaults for your platform and target.
* **"setjmp" options**
- ``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.
* **"string" options**
- ``LIBC_CONF_FIND_FIRST_CHARACTER_IMPL``: Selects the implementation for find-first-character-related functions: 'element', 'word', 'clang_vector', or 'arch_vector'.
- ``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.
- ``LIBC_CONF_STRING_LENGTH_IMPL``: Selects the implementation for string-length: 'element', 'word', 'clang_vector', or 'arch_vector'.
- ``LIBC_CONF_STRING_UNSAFE_WIDE_READ``: Read more than a byte at a time to perform byte-string operations like strlen.
* **"threads" options**
- ``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.
* **"time" options**
Expand Down
16 changes: 6 additions & 10 deletions libc/src/string/memory_utils/aarch64/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <arm_neon.h>
#include <stddef.h> // size_t
namespace LIBC_NAMESPACE_DECL {
namespace internal::neon {
namespace neon {
[[maybe_unused]] LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE static size_t
string_length(const char *src) {
using Vector __attribute__((may_alias)) = uint8x8_t;
Expand Down Expand Up @@ -43,15 +43,15 @@ string_length(const char *src) {
(cpp::countr_zero(cmp) >> 3));
}
}
} // namespace internal::neon
} // namespace neon
} // namespace LIBC_NAMESPACE_DECL
#endif // __ARM_NEON

#ifdef LIBC_TARGET_CPU_HAS_SVE
#include "src/__support/macros/optimization.h"
#include <arm_sve.h>
namespace LIBC_NAMESPACE_DECL {
namespace internal::sve {
namespace sve {
[[maybe_unused]] LIBC_INLINE static size_t string_length(const char *src) {
const uint8_t *ptr = reinterpret_cast<const uint8_t *>(src);
// Initialize the first-fault register to all true
Expand Down Expand Up @@ -92,19 +92,15 @@ namespace internal::sve {
len += svcntp_b8(all_true, before_zero);
return len;
}
} // namespace internal::sve
} // namespace sve
} // namespace LIBC_NAMESPACE_DECL
#endif // LIBC_TARGET_CPU_HAS_SVE

namespace LIBC_NAMESPACE_DECL {
namespace internal::arch_vector {
[[maybe_unused]] LIBC_INLINE size_t string_length(const char *src) {
#ifdef LIBC_TARGET_CPU_HAS_SVE
return sve::string_length(src);
namespace string_length_impl = sve;
#elif defined(__ARM_NEON)
return neon::string_length(src);
namespace string_length_impl = neon;
#endif
}
} // namespace internal::arch_vector
} // namespace LIBC_NAMESPACE_DECL
#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_AARCH64_INLINE_STRLEN_H
5 changes: 3 additions & 2 deletions libc/src/string/memory_utils/generic/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "src/__support/common.h"

namespace LIBC_NAMESPACE_DECL {
namespace clang_vector {
namespace internal {

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

namespace string_length_impl = internal;
} // namespace LIBC_NAMESPACE_DECL

#endif // LLVM_LIBC_SRC_STRING_MEMORY_UTILS_GENERIC_INLINE_STRLEN_H
14 changes: 5 additions & 9 deletions libc/src/string/memory_utils/x86_64/inline_strlen.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@

namespace LIBC_NAMESPACE_DECL {

namespace internal::arch_vector {

namespace string_length_internal {
// Return a bit-mask with the nth bit set if the nth-byte in block_ptr is zero.
template <typename Vector, typename Mask>
LIBC_NO_SANITIZE_OOB_ACCESS LIBC_INLINE static Mask
Expand Down Expand Up @@ -93,18 +92,15 @@ namespace avx512 {
}
} // namespace avx512
#endif
} // namespace string_length_internal

[[maybe_unused]] LIBC_INLINE size_t string_length(const char *src) {
#if defined(__AVX512F__)
return avx512::string_length(src);
namespace string_length_impl = string_length_internal::avx512;
#elif defined(__AVX2__)
return avx2::string_length(src);
namespace string_length_impl = string_length_internal::avx2;
#else
return sse2::string_length(src);
namespace string_length_impl = string_length_internal::sse2;
#endif
}

} // namespace internal::arch_vector

} // namespace LIBC_NAMESPACE_DECL

Expand Down
Loading
Loading