[llvm-branch-commits] [libc] [libc] Add optimized clang_vector memchr implementation (PR #244469)
Michael Jones via llvm-branch-commits
llvm-branch-commits at lists.llvm.org
Fri Nov 20 13:48:38 PST 2026
================
@@ -163,26 +165,22 @@ find_first_character(const unsigned char *s, unsigned char c, size_t n) {
const cpp::simd<char> *loop_aligned;
if (LOOP_BLOCK_SIZE <= 64 && n > LOOP_BLOCK_SIZE) {
- if constexpr (LOOP_BLOCK_SIZE <= 64) {
- // Align s down to LOOP_BLOCK_SIZE; all 4 vectors lie on the same page.
- const cpp::simd<char> *block = reinterpret_cast<const cpp::simd<char> *>(
- __builtin_align_down(s, LOOP_BLOCK_SIZE));
- size_t offset = static_cast<size_t>(
- s - reinterpret_cast<const unsigned char *>(block));
- uint64_t combined = 0;
- for (size_t i = 0; i < 4; ++i) {
- cpp::simd_mask<char> m =
- cpp::load<cpp::simd<char>>(block + i, /*aligned=*/true) == c_byte;
- combined |=
- static_cast<uint64_t>(cpp::bit_cast<cpp::simd_bitmask<char>>(m))
- << (i * VEC_SIZE);
- }
- combined >>= offset;
- if (LIBC_UNLIKELY(combined != 0))
- return s + cpp::countr_zero(combined);
- n -= LOOP_BLOCK_SIZE - offset;
- loop_aligned = block + 4;
+ // Align s down to LOOP_BLOCK_SIZE; all 4 vectors lie on the same page.
+ const cpp::simd<char> *block = reinterpret_cast<const cpp::simd<char> *>(
+ __builtin_align_down(s, LOOP_BLOCK_SIZE));
+ size_t offset =
+ static_cast<size_t>(s - reinterpret_cast<const unsigned char *>(block));
+ uint64_t combined = 0;
+ for (size_t i = 0; i < 4; ++i) {
----------------
michaelrj-google wrote:
nit: the 4 here is a magic number, put it in a constant so the purpose is clearer.
https://github.com/llvm/llvm-project/pull/244469
More information about the llvm-branch-commits
mailing list