Skip to content

x86_64 SIMD string scanning and int decoding - #279

Merged
davidhewitt merged 4 commits into
mainfrom
x86-simd
Aug 31, 2026
Merged

davidhewitt merged 4 commits into
mainfrom
x86-simd

Conversation

@samuelcolvin

@samuelcolvin samuelcolvin commented Aug 27, 2026 •

Copy link
Copy Markdown
Member

Port the aarch64 NEON fast paths (decode_string_chunk, decode_int_chunk_big) to x86_64 using SSE2 only, selected at compile time with cfg(target_arch = "x86_64") — no runtime feature detection, since SSE2 is in the x86_64 baseline.

Design

  • String scan keeps the aarch64 shape (Faster aarch64 SIMD string scanning for non-ascii and mask extraction #270): the mask only detects a special chunk and jumps over non-ascii runs; the stop character is found by the scalar table scan so the returned index stays off the vector→GPR path. pmovmskb gives a bit-per-byte mask so no vshrn nibble trick. A single signed pcmpgtb against 32 catches control chars and bytes ≥ 0x80 (negative as i8).
  • Int decoding right-aligns digits with pslldq and reduces via pmullw/paddw → pmaddwd → pmuludq. One full_calc covers 0..=16 digits.
  • ONGOING_CHUNK_MULTIPLIER in number_decoder.rs is now 10^16 on both SIMD arches.
  • One-line TODOs mark follow-ups: SSSE3 pmaddubsw, SSE4.1 lane packing, AVX2 32-byte loop.

Verification

  • Ran the full test suite for x86_64-apple-darwin under Rosetta (incl. serde proptest) plus native aarch64 — all green. This caught one bug during development (all-digit mask → trailing_zeros of 0).
  • clippy -D warnings on x86_64 and the wasm32 fallback, cargo bench -- --test on x86_64.
  • objdump of the x86 release build shows pmovmskb/pmaddwd/pmuludq/pslldq and no cpuid.

Not yet measured

CodSpeed's macro runners are arm64, so the bench job here only confirms aarch64 is unchanged. x86 performance numbers still need a cargo bench main-vs-branch run on real x86 hardware (e.g. a Codespace).

🤖 Generated with Claude Code

https://claude.ai/code/session_01Dvr4FioDLzkHkriM5to3wC


Summary by cubic

Ports the aarch64 NEON fast paths for string scanning and integer decoding to x86_64 via SSE2 intrinsics, gated with #[target_feature(enable = "sse2")] and selected at compile time with cfg(target_arch = "x86_64"). No runtime feature detection is needed because SSE2 is part of the x86_64 baseline.

  • String scanning uses a pmovmskb bit-per-byte mask to jump over non-ASCII runs; the stop character is still located by the scalar scan so the index stays off the vector→GPR path.
  • Integer decoding right-aligns digits with pslldq and reduces via pmullw/paddw, pmaddwd, and pmuludq; one full_calc covers 0..=16 digits.
  • ONGOING_CHUNK_MULTIPLIER moved into simd/mod.rs and is now 10^16 for both SIMD architectures; number_decoder.rs imports it.
  • SIMD intrinsic calls sit behind the dispatchers in simd/mod.rs and are wrapped in unsafe blocks.
  • TODOs mark follow-ups for SSSE3, SSE4.1, and AVX2.

Verification

  • Full test suite passes on x86_64 (under Rosetta) and aarch64; clippy with -D warnings passes on x86_64 and wasm32 fallback.
  • cargo bench -- --test passes on x86_64, but x86 benchmark numbers on real hardware are still pending (CodSpeed runners are arm64).

Written for commit 4fd4265. Summary will update on new commits.

Review in cubic

@codecov

codecov Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 99.11504% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
crates/jiter/src/simd/x86_64.rs 99.02% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found and verified against the latest diff

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="crates/jiter/src/simd/x86_64.rs">

<violation number="1" location="crates/jiter/src/simd/x86_64.rs:74">
P1: When a long integer is followed by a non-float delimiter and at least 16 bytes remain, `first_non_digit` returns 32 and `full_calc` panics in its `unreachable!` arm. Return position 0 for an all-nondigit mask before decoding the chunk.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread crates/jiter/src/simd/x86_64.rs Resolved
@codspeed

codspeed Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.48%

⚡ 2 improved benchmarks
❌ 3 regressed benchmarks
✅ 62 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
❌ WallTime string_array_jiter_value_owned 13 µs 16.7 µs -21.97%
❌ WallTime x100_jiter_value 75 ns 81 ns -7.41%
❌ WallTime pass1_jiter_value 10.4 µs 11 µs -5.47%
⚡ WallTime python_parse_string_array_unique 1.7 ms 1.6 ms +8.29%
⚡ WallTime python_parse_string_array 14 µs 13 µs +7.56%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing x86-simd (4fd4265) with main (1da1e5c)

Open in CodSpeed

@samuelcolvin

Copy link
Copy Markdown
Member Author

@codspeedbot explain the regression.

@codspeed

codspeed Bot commented Aug 29, 2026 •

Copy link
Copy Markdown

@codspeedbot explain the regression.

Short answer: none of the 8 reported changes are real — the aarch64 machine code on this branch is identical to main.

1. The diff cannot affect what CodSpeed measures

Against the base commit e39ce33, this branch touches only three files:

file effect on aarch64
crates/jiter/src/simd/x86_64.rs (new) behind #[cfg(target_arch = "x86_64")] — never compiled
crates/jiter/src/simd/mod.rs ONGOING_CHUNK_MULTIPLIER moved here; still 10^16 on aarch64
crates/jiter/src/number_decoder.rs the same const removed and imported instead

The bench job runs on codspeed-macro, which is arm64, so the new SSE2 paths are dead code there.

I verified this rather than assuming it: cross-compiling the jiter lib at e39ce33 and at 75b5567 to aarch64-unknown-linux-gnu and diffing the emitted assembly gives 26,985 identical lines except one, and that one is a panic-location constant whose source line number changed (320 → 315) because 5 lines were deleted from number_decoder.rs. Zero instruction differences, same constant length, so no code or data layout shift either.

2. The per-commit history shows where the numbers actually moved

The branch has three commits. Comparing each run:

comparison contents python_parse_x100_not_cached
e39ce33 (main, base) — 128 ns
c858b19 — all the x86 SIMD code ~230 lines of new code 128 ns
1a7b95f — move the const trivial 128 ns
75b5567 — "bump" empty commit, zero diff 165 ns (-22%)

The commit that contains the entire feature measured flat. The regression appears on a commit with no diff at all. That same empty commit is also responsible for python_parse_x100 152 → 171 ns and unicode_jiter_value -8.8%, while giving back sentence_jiter_iter +7.9% and sentence_jiter_value +5.4%.

An empty commit moving a benchmark 29% is a measurement artefact by definition.

3. Why these particular benchmarks

  • python_parse_x100* run in ~130-170 ns. At that scale, code/data placement and process/heap state dominate; within-run stdev is 0.2-0.4%, but the between-run spread is much larger. These are the two smallest benchmarks in the suite and they are the two largest reported "regressions".
  • true_array_jiter_value / unicode_jiter_value / sentence_* are the allocation-heavy value benchmarks, which historically swing 5-15% between runs on this repo with no code change (true_array_jiter_value alone has ranged 2.84-3.08 µs across consecutive main pushes). Note the report shows them moving in both directions here, which is the usual signature.
  • CodSpeed also flagged different runtime environments between the base and head runs (different libpython3.10 / libexpat / libz build IDs recorded), and every benchmark in the report is in the affected list.

Recommendation

Nothing to fix on the branch — you can acknowledge these on CodSpeed. If you want a clean report, re-running the bench job on 75b5567 should shuffle them back.

Worth restating the point already in the PR description: because the macro runners are arm64, this PR is currently unmeasurable on CodSpeed — the report can only confirm that aarch64 is unchanged (which it now does, at the instruction level). The x86 numbers still need a main-vs-branch cargo bench on real x86 hardware.

No code changes were made.

Summary
  • Warming up the performance wizard...
  • Inspect CodSpeed runs for PR x86_64 SIMD string scanning and int decoding #279 — Compared 75b5567 vs e39ce33: 4 regressions, 4 improvements, env difference flagged
  • Check whether x86 changes can affect aarch64 codegen — Cross-compiled jiter to aarch64 at e39ce33 and 75b5567: asm identical except one panic-location line number
  • Reply with the explanation — Explanation posted; no code changes were needed
  • Handling comment — Comment handling finished successfully

Learnings updated. See what CodSpeed remembers about this repository.

Was this response helpful? React with 👍 or 👎 to help us improve CodSpeedBot.

samuelcolvin and others added 3 commits August 30, 2026 19:03
Port the aarch64 NEON fast paths to SSE2, selected at compile time via
`cfg(target_arch = "x86_64")` with no runtime feature detection, since SSE2 is
part of the x86_64 baseline.

The string scan keeps the aarch64 shape: the vector mask only detects that a
chunk contains a special byte and jumps over non-ascii runs; the stop character
is located by the scalar table scan so the returned index stays off the
vector->GPR transfer path. `pmovmskb` gives a bit-per-byte mask directly, so no
`vshrn` nibble packing is needed. The ascii mask uses a single signed compare
against 32, which catches control characters and bytes above 127 (negative as
i8) in one instruction.

Int decoding right-aligns the digits with `pslldq` and reduces with
`pmullw`/`paddw`, `pmaddwd`, and `pmuludq`; there are no 64-bit half registers
on x86 so one function covers 0..=16 digits.

`ONGOING_CHUNK_MULTIPLIER` is now 10^16 on both SIMD architectures, matching the
16-byte step.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dvr4FioDLzkHkriM5to3wC
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Dvr4FioDLzkHkriM5to3wC
@davidhewitt
davidhewitt merged commit 9e7d52f into main Aug 31, 2026
29 of 30 checks passed
@davidhewitt
davidhewitt deleted the x86-simd branch August 31, 2026 11:15
samuelcolvin added a commit that referenced this pull request Aug 31, 2026
x86_64 SIMD (#279) merged after the IntChunk::Float variant gained its
payload; like aarch64, the big decoder passes 0 since both callers
discard the value for floats.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01XkwvHii1SZaVsrhw5skD4g
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants