Repository navigation
fix(tokenizer): let the SSE2 loops in ToLower run - #21436
Conversation
Both the out-buffer ToLower overload and ToLowerString compared the cursor against the vector end with `p > sse2_end`. The cursor starts at `begin` and `sse2_end` is never below it, so the condition was false on entry and the vector body never executed: every call fell through to the scalar byte loop. Compare with `<` so the 16-byte blocks are processed and the scalar loop keeps handling only the tail. Behaviour is unchanged; the mask built from signed compares is already false for bytes >= 0x80, so non-ASCII bytes stay untouched.
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Correct SSE2 loop bounds internal/binding/cpp/string_utils.h |
Both ToLower overloads now process full SSE2 blocks before the aligned end. Remaining bytes use the existing scalar conversion. |
Priority:
Estimated code review effort: 2 (Simple) | ~8 minutes
Change: Bug fix
Possibly related PRs
- infiniflow/ragflow#21433: Adds
ToLowerUTF8and changesRAGAnalyzerto use it instead ofToLower; both PRs change lowercasing behavior in tokenizer analysis.
Suggested labels: 🐞 bug, parsing
Merge Risk: 
Minimal · up to ada61
-
No merge-blocking issue was identified in the loop-bound correction.
Pre-merge checks: 
4 · 
1
-
Failed checks: 1 warning Passed checks: 4 passed-
Full details: Title check
-
Explanation
The title names the fix and its location: the SSE2 loops in ToLower now run. It matches the main change, which switches the 16-byte loop condition from p > sse2_end to p < sse2_end. It uses the conventional type(scope) prefix and is a single sentence of 8 words.
Full details: Description check
-
Explanation
The description follows the repository template. It has a clear What section that explains the bug (the p > sse2_end guard prevents the vector body from running) and the fix. It adds Scope, Verification, and Test plan sections. The template's Summary section is not used under that exact heading, but the What section covers the same purpose and background, so the required information is present.
-
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
A rabbit checks each block with care
Sixteen bytes now pass through there
The trailing bytes take the scalar trail
Lowercase letters leave no detail
The SSE2 loops hop along
And finish with a tidy song
Comment @coderabbitai help to get the list of available commands.
|
Verified the fix on source. With p < sse2_end the vector loop covers the whole 16-byte-aligned prefix and the last block load ends at sse2_end - 1, so no over-read; the scalar loop picks up the tail from there. The signed cmpgt mask keeps bytes >= 0x80 untouched (they compare negative against 'A'-1), which is exactly what the Cyrillic path in #21433 relies on, and the vector path agrees with the scalar one on the ASCII-only mapping. Good call spinning this out separately. Source-level review only, no C++ toolchain in this environment. |
|
Thanks for the source-level verification — the mask reasoning matches what we measured locally. One note on the CI so nobody re-reads it as a code defect: No code update needed for this thread. |
|
One operational note to go with the above: since |
|
Correction to my earlier note on the
So the checks panel is amber on an approved, test-green PR because of the job wrapper, not because of anything in For completeness, the other five checks on this head are green: |
|
FYI: the red
So the runner dropped out after the work finished. |
|
No re-run needed — the checks are already green on this head.
Thanks for digging into the job log rather than calling it a flake — the "self-hosted runner lost communication" annotation is the operational issue, not this change. If it recurs on another PR, a separate CI issue is the right place for it. |
What
ToLower(const char*, size_t, char*, size_t)andToLowerStringboth gate their 16-byte block loop onpstarts atbeginandsse2_end >= begin, sop > sse2_endis false on entry and the vector body never runs. Every call is served by the scalar byte loop. Changing the comparison to<lets the blocks through and leaves the scalar loop to finish the tail.Raised by @Harsh23Kashyap while reviewing #21433 as a pre-existing issue in the same file.
Scope
Two characters, no behaviour change. The mask is built from signed compares
bytes > 'A'-1and'Z'+1 > bytes, which is already false for bytes >= 0x80, so non-ASCII bytes stay untouched exactly as the scalar path leaves them.ToLower(char*, size_t)was already correct (while (len >= 16)) and is not touched.Verification
No repo test can observe this: the scalar path produces identical output, so only the executed path changes. Validated with a scratch harness against the header (not committed):
0 / 0, new4 / 4(once per 16-byte block in both functions).ToLowerString, the out-buffer overload (including the NUL terminator and no writes pastlen + 1) and the in-place overload. Vector build and scalar build emit the same FNV-1a digest, zero mismatches against a scalar reference.clang++ -arch x86_64 -msse2 -std=c++20 -con the header. The vector checks above were executed through simde aliases because this host is arm64; on aarch64__SSE2__is not defined and the block is compiled out either way.Test plan
ragflow_native_backendbuilds the binding on x86_64bash build.sh --test ./internal/tokenizer/...still passes