sonic-simd fails to build on 32-bit x86 (i686): `arch::x86_64` imported under a `target_feature = "sse2"` gate

Open Beginner friendly
#228 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
82/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Quiet
Tech stack
rust

Research direction

Start with sonic-simd/src/lib.rs to understand the SSE2 backend selection, then inspect the architecture imports in sonic-simd/src/sse2.rs, avx2.rs, and avx512.rs. Reproduce with cargo build -p sonic-simd --target i686-unknown-linux-gnu after installing the target, and verify that both 32-bit and 64-bit x86 builds compile successfully.

Written by the indexing model from the issue text.

Description

Summary

sonic-simd (and therefore sonic-rs) fails to compile on 32-bit x86 targets such as i686-pc-windows-msvc / i686-unknown-linux-gnu.

Error

error[E0432]: unresolved import `core::arch::x86_64`
 --> sonic-simd/src/sse2.rs:2:11
  |
2 |     arch::x86_64::*,
  |           ^^^^^^ could not find `x86_64` in `arch`
error: could not compile `sonic-simd` (lib)

Root cause

In sonic-simd/src/lib.rs, the SSE2 backend is selected by CPU feature:

cfg_if::cfg_if! {
    if #[cfg(target_feature = "sse2")] {
        mod sse2;
    } else if #[cfg(all(target_feature = "neon", target_arch = "aarch64"))] {
        ...
    } else {
        mod v128; // portable fallback
    }
}

On 32-bit x86 (i686), SSE2 is enabled by default, so target_feature = "sse2" is true and mod sse2; is compiled — but sse2.rs (and avx2.rs, avx512.rs) import the intrinsics from core::arch::x86_64, which does not exist on 32-bit x86. The SSE2/AVX intrinsics it uses (_mm_loadu_si128, _mm_movemask_epi8, __m128i, …) are available in core::arch::x86 as well, so the modules just need to import the arch module that matches the target.

Fix

Gate the arch import by target_arch in sse2.rs, avx2.rs, and avx512.rs:

#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
use core::ops::{BitAnd, BitOr, BitOrAssign};

With this, 32-bit x86 builds use core::arch::x86's SSE2/AVX intrinsics and compile correctly; 64-bit is unchanged.

Repro

rustup target add i686-unknown-linux-gnu
cargo build -p sonic-simd --target i686-unknown-linux-gnu   # or i686-pc-windows-msvc

I'm happy to send a PR with the 3-file change if that's useful.

Dominant language
Rust
Stars
920
Forks
68
Avg merge
2h 5m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from cloudwego/sonic-rs

All issues in cloudwego/sonic-rs

Similar issues

More Rust issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.