Skip to content

Pack mixed-width UTF-32 blocks on vector and fallback paths - #1018

Open
perfloop-agent wants to merge 2 commits into
simdutf:masterfrom
perfloop:perfloop-pr-open-2t28pwta2f
Open

perfloop-agent wants to merge 2 commits into
simdutf:masterfrom
perfloop:perfloop-pr-open-2t28pwta2f

Conversation

@perfloop-agent

Copy link
Copy Markdown

Summary

The UTF-32→UTF-8 converters fall back to scalar code as soon as a block contains mixed widths. This PR keeps such blocks on the vector path:

  • Haswell (AVX2): three comparison masks classify each lane and form two bits per code unit (its UTF-8 width); each group of four lanes is compacted with a PSHUFB plan indexed by those widths, packing eight valid code units at a time (new width-indexed tables).
  • Fallback: validates a batch plus lookahead before issuing 16-byte wide stores; on an invalid code unit, scalar code resumes at that batch, preserving the exact first-error index and output prefix — the _with_errors contract is unchanged.

Performance

Recorded verification runs (x86-64), 32768-scalar inputs:

workload before after
AVX2, all-width mixed 4.82 ns/scalar 1.12 ns/scalar
AVX2, mixed after BMP prefix 4.79 ns/scalar 1.12 ns/scalar
AVX2, emoji (all 4-byte) 2.14 ns/scalar 0.27 ns/scalar
forced fallback, all-width mixed 1.66 ns/scalar 1.35 ns/scalar
forced fallback, emoji 2.40 ns/scalar 1.35 ns/scalar

Testing

  • Full test suite passes, with extended convert_utf32_to_utf8_with_errors coverage pinning the first-error index and output prefix across the new batch boundaries.
  • Verified across implementations including the forced-fallback path; tests also pass on arm64 (which dispatches to unchanged kernels).

Full verification record: https://app.perfloop.ai/t/oss/case_nqbvgjwvc2

This branch has not been deployed

No deployments
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.

1 participant