Skip to content

linalg/wasm: make the relaxed-dot int8 path bit-exact on all engines - #2594

Open
czoli1976 wants to merge 1 commit into
sonos:mainfrom
czoli1976:wasm-relaxed-dot-i8-exact
Open

linalg/wasm: make the relaxed-dot int8 path bit-exact on all engines#2594
czoli1976 wants to merge 1 commit into
sonos:mainfrom
czoli1976:wasm-relaxed-dot-i8-exact

Conversation

@czoli1976

Copy link
Copy Markdown
Contributor

Under +relaxed-simd, wasm_i32_4x4 feeds full-signed i8 B into i32x4.relaxed_dot_i8x16_i7x16_add's i7-range operand, which x86 lowerings (pmaddubsw/vpdpbusd) read as unsigned: the wasm::mmm_i32 i8i8 tests fail under wasmtime on x86-64, and would block #2565's relaxed-simd CI lane once it merges. This sign-splits B into two i7-safe planes with one relaxed dot each, folded back after the K-loop as acc -= acc_hi << 7 — bit-exact on every engine, still dot-product speed, no packing change.

🍍

🤖 Generated with Claude Code

The i8 kernel fed full-signed B into i32x4_relaxed_dot_i8x16_i7x16_add's second
operand, which is only defined for lanes in [0, 127]: x86 lowerings
(pmaddubsw/vpdpbusd) read out-of-range lanes as unsigned, so every negative B
byte skewed the result by 256*a. Sign-split B into two i7-safe planes (b & 0x7f
and b >> 7), give each its own relaxed dot, and fold acc -= acc_hi << 7 after
the K-loop; in-range operands also keep pmaddubsw's i16 pair-sums below
saturation, so the kernel is bit-exact on every engine.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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