Feat/matching round2 - #10
Merged
Merged
Conversation
Replace the scalar per-element loop in the NEON backend of eq_words_unaligned with true 2-lane SIMD: vld1q_u64 loads, vshlq_u64 (variable shift, negative = logical right), vorrq_u64 for window construction, and vceqq_u64 for parallel comparison. Previously the NEON backend iterated with 'while i + 2 <= len' but computed each 64-bit window one at a time via scalar shift and OR, matching neither SSE2 nor AVX2 which use parallel _mm_srl_epi64 / _mm_sll_epi64. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
Rust 2024 requires explicit unsafe {} blocks for unsafe intrinsics
inside unsafe fn bodies. These two vld1q_u64 calls in the NEON
backends of funcs_for_find_core and funcs_for_rfind_core were
missing the unsafe block.
Co-authored-by: Claude <noreply@anthropic.com>
Co-authored-by: DeepSeek AI <service@deepseek.com>
Refactor matches_at to reuse the existing SIMD word-equality backends: - Word-aligned offsets (shift == 0): delegate to starts_with_words - Unaligned offsets: delegate to ends_with_words (shifted-window SIMD) Previously matches_at always took the scalar bits_equal_at path. The remainder (partial word) handling mirrors the ends_with pattern. Also add doc comments to all three methods. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
When full_words < SMALL_WORDS, bypass the shift/base_word/slice setup and delegate directly to the scalar bits_equal_at. The underlying starts_with_words/ends_with_words already have the same guard internally, but checking at the matches_at level avoids computing shift, base_word, and the word slice. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
…ends The scalar rfind computes max_shift = min(last_start - base, 63) as the maximum shift value (0..=63). The SIMD backends compute min(64, last_start - base + 1) as a count (1..=64), then round up to a LANES multiple (2 or 4). Out-of-range positions are guarded by the pos <= last_start check in the verify loop. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
Move bits_equal_at from a private free function in impls_for_matching to a pub(crate) method on BitString in impls_for_matches_at, giving it direct access to starts_with_words / ends_with_words. The method now uses SIMD word-equality for long patterns (full_words >= SMALL_WORDS) and scalar comparison for short ones. matches_at simplifies to a thin guard-and-delegate wrapper. All call sites updated: find/rfind/contains verify closures, backend equivalence tests, and bits_equal_at unit tests. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
When the pattern fits in a single u64 (<= 64 bits), skip the full_words / SMALL_WORDS / SIMD dispatch and use a single read_word_at + mask + compare. This eliminates branching and loop overhead for the common short-pattern case. starts_with now beats String in small scenarios (5.0ns vs 6.9ns). Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
Move empty-pattern guards above all variable bindings in bits_equal_at, starts_with, and ends_with. This makes the early-return intent obvious and avoids computing needle_words, sw, shift, base_word, etc. just to find mask == 0. Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: DeepSeek AI <service@deepseek.com>
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Merging this PR will improve performance by 60.69%
Performance Changes
Tip Curious why this is faster? Comment Comparing Footnotes
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.