Skip to content

Keep simdutf westmere and fallback kernels in x86_64 builds - #266

Open
dylan-conway wants to merge 1 commit into
mainfrom
simdutf-keep-westmere-fallback
Open

dylan-conway wants to merge 1 commit into
mainfrom
simdutf-keep-westmere-fallback

Conversation

@dylan-conway

Copy link
Copy Markdown
Member

The x64 artifacts are built with -march=haswell, which makes simdutf's amalgamation compile out its SSE4.2 (westmere) and scalar (fallback) kernels. On CPUs that execute AVX but don't advertise it via CPUID — Rosetta 2 — runtime dispatch then finds no usable implementation and silently installs the unsupported singleton, whose methods return constants instead of computing: validate_ascii() returns false for ASCII input and validate_ascii_with_errors() returns (OTHER, 0). In Bun this sends the latin1→utf8 conversion into an infinite loop during startup, so the x64 build hangs under Rosetta 2 on any JS execution.

This forces the SSE4.2 and scalar kernels back in on x86_64. Dispatch priority is unchanged (icelake → haswell → westmere → fallback), so CPUs that advertise AVX2/AVX-512 select the same kernels as before. The re-enabled kernels are still compiled at the TU's -march, so this helps translators that execute AVX without advertising it, not CPUs that genuinely cannot execute AVX.

Verified by compiling the amalgamation with -march=haswell with and without these defines and running under Rosetta 2: without them the active implementation is unsupported and validate_ascii returns false on pure-ASCII input; with them it is westmere and all results are correct. arm64 builds are unaffected (the block is gated on CPU(X86_64)).

Building with -march=haswell compiles out simdutf's SSE4.2 and scalar
kernels, leaving only haswell and icelake. CPUs that execute AVX but do
not advertise it via CPUID (e.g. Rosetta 2) then get the "unsupported"
implementation, whose methods return constants instead of computing —
validate_ascii() returns false for ASCII input and
validate_ascii_with_errors() returns (OTHER, 0), which sends callers
into infinite loops.

Force the lower-tier kernels back in for x86_64 so runtime dispatch
always has a working floor. CPUs with AVX2/AVX-512 still select the
haswell/icelake kernels, so this has no effect on machines that
advertise those features.
@coderabbitai

coderabbitai Bot commented Jul 2, 2026

Copy link
Copy Markdown

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: dd99cf42-e094-4b12-8eab-e5dad7aa950e

📥 Commits

Reviewing files that changed from the base of the PR and between c9ad581 and 60795ae.

📒 Files selected for processing (1)
  • Source/WTF/wtf/SIMDUTF.cpp

Walkthrough

Adds preprocessor directives in SIMDUTF.cpp that force inclusion of the Westmere and fallback SIMDUTF implementation kernels on x86_64 builds, ensuring runtime dispatch always has a valid implementation available instead of potentially selecting an unsupported, constant-returning implementation.

Changes

SIMDUTF Kernel Configuration

Layer / File(s) Summary
Compile-time kernel inclusion directives
Source/WTF/wtf/SIMDUTF.cpp
Adds CPU(X86_64)-guarded defines for SIMDUTF_IMPLEMENTATION_WESTMERE and SIMDUTF_IMPLEMENTATION_FALLBACK, with comments explaining that builds like -march=haswell or CPUs/VMs not advertising AVX could otherwise select an unsupported constant-returning implementation.

Sequence Diagram(s)

Not applicable; this change is a compile-time configuration adjustment with no observable runtime call flow to diagram.

Estimated code review effort: Low

Suggested labels: WTF, build

Suggested reviewers: none identified from the provided context

Poem
A rabbit tunes the SIMD gears,
Westmere and fallback, no more fears,
Haswell flags won't leave us bare,
Dispatch always finds kernels there,
Compiled in, with hopping cheer. 🐇

🚥 Pre-merge checks | ✅ 3 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description explains the bug and fix, but it does not follow the required template or include the Bugzilla and commit-message fields. Add the Bugzilla link/title, Reviewed by line, and file/change list in the repository's required commit-message template format.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: retaining westmere and fallback simdutf kernels in x86_64 builds.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

Comment @coderabbitai help to get the list of available commands.

@claude claude 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.

LGTM — straightforward preprocessor fix to keep simdutf's westmere/fallback kernels compiled in on x86_64.

Extended reasoning...

Overview

This PR adds a small preprocessor block to Source/WTF/wtf/SIMDUTF.cpp that defines SIMDUTF_IMPLEMENTATION_WESTMERE=1 and SIMDUTF_IMPLEMENTATION_FALLBACK=1 on x86_64 before including the simdutf amalgamation. I verified against simdutf_impl.cpp.h that these macros are the correct override points: the amalgamation's own #ifndef blocks default westmere/fallback to 0 when SIMDUTF_CAN_ALWAYS_RUN_HASWELL is set (i.e., under -march=haswell), and pre-defining them to 1 re-enables those kernels without touching dispatch priority.

Security risks

None. This is a compile-time configuration change that enables additional (already-present) SIMD kernel implementations in the simdutf amalgamation. No new code paths are introduced beyond what simdutf already ships; runtime dispatch order is unchanged.

Level of scrutiny

Low. The change is 17 lines (mostly explanatory comment), gated behind CPU(X86_64), and uses #ifndef guards so it composes with any external overrides. It is purely additive at build time — CPUs advertising AVX2/AVX-512 continue to select haswell/icelake, while environments like Rosetta 2 that don't advertise AVX now get a working westmere/fallback floor instead of the unsupported singleton.

Other factors

The PR description includes manual verification under Rosetta 2 with and without the defines. The bug-hunting system found no issues. The comment in the code accurately captures the caveat that these kernels are still compiled at the TU's -march, so this targets translators rather than genuinely pre-AVX hardware. No outstanding reviewer comments on the timeline.

@github-actions

github-actions Bot commented Jul 2, 2026

Copy link
Copy Markdown

Preview Builds

Commit Release Date
60795ae6 autobuild-preview-pr-266-60795ae6 2026-07-02 02:12:49 UTC

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