Skip to content

fix(core): restrict AVX2 normalize to x86_64 (fix i686 build)#657

Merged
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-656
Jul 7, 2026
Merged

fix(core): restrict AVX2 normalize to x86_64 (fix i686 build)#657
dmtrKovalenko merged 2 commits into
mainfrom
triage-bot/issue-656

Conversation

@gustav-fff

Copy link
Copy Markdown
Collaborator

Closes #656

Root cause

normalize_bytes in crates/fff-core/src/bigram_filter.rs gated the AVX2 dispatch and the normalize_bytes_avx2 fn on #[cfg(any(target_arch = \"x86_64\", target_arch = \"x86\"))], but the body unconditionally does use std::arch::x86_64::*;. On 32-bit x86 (i686-unknown-linux-gnu) std::arch::x86_64 does not exist, so fff-search failed to compile:

error[E0432]: unresolved import `std::arch::x86_64`
   --> fff-search-0.9.6/src/bigram_filter.rs:626:20
    |
626 |     use std::arch::x86_64::*;
    |                    ^^^^^^ could not find `x86_64` in `arch`

Regressed in #566. Reported by @Juhan280 hitting this while packaging nushell for termux i686 android devices.

Fix

Restrict the AVX2 dispatch and the normalize_bytes_avx2 implementation to #[cfg(target_arch = \"x86_64\")]. On 32-bit x86 we fall back to normalize_bytes_scalar, which LLVM auto-vectorises with the baseline SIMD anyway. Per maintainer + @fdncred: dropping SIMD on 32-bit x86 is acceptable — compiling at all is more important.

Also add a Build i686-unknown-linux-gnu CI job in .github/workflows/rust.yml so this regresses loudly next time. The job installs gcc-multilib, adds the i686-unknown-linux-gnu target, and runs cargo build -p fff-search --target i686-unknown-linux-gnu.

Steps to reproduce

On pre-fix main (commit 8c76a1b):

rustup target add i686-unknown-linux-gnu
sudo apt-get install -y gcc-multilib   # linux host
cargo build -p fff-search --target i686-unknown-linux-gnu

Expected: build succeeds. Actual on pre-fix main: error[E0432]: unresolved import 'std::arch::x86_64' at crates/fff-core/src/bigram_filter.rs:626.

How verified

  • cargo check -p fff-search --no-default-features --features ripgrep on x86_64 macOS: clean.
  • cargo clippy -p fff-search --no-default-features --features ripgrep -- -D warnings: clean.
  • New CI job exercises the i686 build path on every PR; cross-compile toolchain not available locally on macOS host, so verification of the 32-bit target itself is deferred to CI.

Automated triage via Gustav. Honk-Honk 🪿

The AVX2 path in `normalize_bytes` gated on `any(target_arch = "x86_64",
target_arch = "x86")` unconditionally imports `std::arch::x86_64`, which
does not exist on 32-bit x86, so `fff-search` failed to compile for
`i686-unknown-linux-gnu` (e.g. termux i686 android builds pulling us in
via nushell). SIMD stays on x86_64/aarch64; 32-bit x86 falls back to the
scalar path.

Add a `Build i686-unknown-linux-gnu` CI job so this regresses loudly next
time. Closes #656.
@dmtrKovalenko

Copy link
Copy Markdown
Owner

@gustav-fff iterate on this PR and guard all the non x86_64 code that is failing to compile

`select_rare_pair` results are only consumed inside x86_64/aarch64 cfg
blocks, so on 32-bit x86 both bindings are unused and CI's
`-D unused-variables` fails the i686 build introduced in the previous
commit.
@dmtrKovalenko dmtrKovalenko merged commit 7221081 into main Jul 7, 2026
52 checks passed
@gustav-fff

Copy link
Copy Markdown
Collaborator Author

[triage-bot] DIRECTED: already guarded, i686 CI green as of afc23c4.

Timeline: your comment at 17:55:06 UTC preceded commit afc23c4 (17:57:28 UTC), which silenced the unused i1/i2 bindings in select_rare_pair that CI's -D unused-variables was rejecting on 32-bit x86. Latest run:

  • Build i686-unknown-linux-gnu: pass (55s)
  • cargo clippy (-D warnings): pass
  • cargo fmt: pass

Grep swept for every arch-specific site in crates/:

  • crates/fff-core/src/bigram_filter.rs:596 — AVX2 dispatch #[cfg(target_arch = "x86_64")]
  • crates/fff-core/src/bigram_filter.rs:604 — NEON dispatch #[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
  • crates/fff-core/src/bigram_filter.rs:623normalize_bytes_avx2 #[cfg(target_arch = "x86_64")]
  • crates/fff-core/src/bigram_filter.rs:656normalize_bytes_neon #[cfg(all(target_arch = "aarch64", target_feature = "neon"))]
  • crates/fff-core/src/case_insensitive_memmem.rs:106,375verify_avx2, search_packed_pair_avx2 #[cfg(target_arch = "x86_64")]
  • crates/fff-core/src/case_insensitive_memmem.rs:171,197,255 — NEON helpers #[cfg(target_arch = "aarch64")]
  • crates/fff-core/src/case_insensitive_memmem.rs:353,359,505,516 — runtime dispatch gated by arch
  • crates/fff-core/src/case_insensitive_memmem.rs:499select_rare_pair result #[cfg_attr(not(any(target_arch = "x86_64", target_arch = "aarch64")), allow(unused_variables))]

On i686 all SIMD paths compile out; normalize_bytes_scalar / search (memchr2 fallback) run and LLVM auto-vectorises them with the baseline SIMD. No further code was failing to compile.

If you were seeing a stale failure in your local view, please point me at the specific error — otherwise ready for review.

Honk-Honk 🪿

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.

[Bug]: Build failing for x86 32 bit cpus

2 participants