Repository navigation
Port upstream #162: lower v_sad_u8, v_sad_hi_u8, v_sad_u16, v_sad_u32 and v_msad_u8 - #33
Merged
Merged
Conversation
src2 plus the sum of the unsigned differences |a - b| of the operands' bytes (v_sad_u8), halves (v_sad_u16) or whole dwords (v_sad_u32), wrapping at 32 bits. v_sad_hi_u8 adds the byte sum shifted to the high half; v_msad_u8 leaves out a byte whose mask byte (src1) is 0. AI-assisted (Claude Code). (cherry picked from commit 5d6889e)
Upstream added it with the v_mul_hi_*_24 lowering (344704e), which this tree already has in another form; only the helper is taken. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 of 23 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this changes
This ports the
v_sadhalf of Marvisak/VIctory#162 by Rareuncommon. Commit 5d6889e is cherry-picked with-x, so it keeps their authorship.VIPort decodes
v_sad_u8,v_sad_hi_u8,v_sad_u16,v_sad_u32andv_msad_u8(VOP3 0x15a–0x15d, 0x171), but has no lowering for them. A shader that uses one is refused as a whole:The upstream merge is in VIPort's history, but the lowering arm is not in the tree. It was lost in a later merge.
The lowering is src2 plus the sum of the unsigned differences |a − b| of the operands' bytes, halves or whole dword, wrapping at 32 bits.
v_sad_hi_u8shifts the sum into the high half.v_msad_u8skips a byte whose mask byte (src1) is 0.#162 also contained
v_mul_hi_u32_u24/v_mul_hi_i32_i24(344704e). This tree already lowers those, throughmul_hi_24, so that commit is not taken. Its test helperlowers_valuis used by thev_sadtest, though. A second commit adds that helper verbatim from upstream.Checked
docs/asset-policy.mdbuild.rs, git hook,.cargoconfig, CI change or script (or an issue explains why)cargo test --workspacepasses (onlyviport-shader --libon Linux, see below)cargo clippy --workspace --all-targets --locked -- -D warningspasses (forviport-shader, with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in locally)rustfmt; I did not reformat lines I did not changeWhat I ran
On Linux, Rust 1.98.1:
cargo test -p viport-shader --lib --locked: 191 passed, 0 failed, 3 ignored, includingemit::lower::tests::sums_of_absolute_differences_lower.VOP3 0x15afirst.cargo clippy -p viport-shader --all-targets --locked --target x86_64-pc-windows-msvc -- -D warnings: clean with CI: clear the clippy errors that keep main red since a3e7f17 #21 merged in. Without it, the only errors are the two already onmain.Not run: the translated shaders on a GPU, against the hardware. I have no Windows machine. The test only checks that the five instructions lower to valid IR. Upstream did not add a hardware test for these either.
Overlaps
#27 moves the
lower.rsunit tests intoemit/lower_tests.rs. If it lands first, the new helper and test have to move with them, and I will rebase. #22 and #28 also editlower.rs, in other functions.🤖 Generated with Claude Code