fix(shader): apply VOP3P neg_lo/neg_hi to packed 16-bit integer sources #4268

Merged
AlxcBTW merged 1 commit from upstream-pr/4268 into main 2026-10-12 18:35:11 +00:00
AlxcBTW commented 2026-10-12 03:37:47 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T03:37:47Z.


Sword of the Sea (PPSA25344) menu: the TSR history no longer loses ~17 % of its energy every frame; top luma 77 → 87 (PS5 capture 89-91), and the glow at the top of the menu is back.

What

The packed integer instructions (v_pk_add/sub_{u,i}16, v_pk_mul_lo_u16, v_pk_mad_{u,i}16, v_pk_min/max_{u,i}16, v_pk_lshlrev/lshrrev/ashrrev_b16) read their 16-bit sources through readU16LaneAsU32, which applied op_sel/op_sel_hi but dropped neg_lo/neg_hi. The decoder already sets both flags for every VOP3P source; only the f16 path used them.

Now readU16LaneAsU32 flips bit 15 of the selected 16-bit half when neg_lo (low lane) or neg_hi (high lane) is set for that source, before the optional sign extension. This is the same sign-bit flip the f16 path applies. The integer dot instructions also read through this function, but the decoder still rejects neg on them, so they are unchanged.

How the neg bit works on 16-bit integer halves

The RDNA 2 ISA (13.3.6, VOP3P) describes NEG and NEG_HI as "negate input for low/high 16-bits of sources". Unlike the VOP3 NEG field ("floating-point negation"), it does not limit them to floating-point opcodes. LLVM's assembler accepts them only on floating-point operands. That is an assembler rule, so it says nothing either way about what the hardware does with the bit on integer opcodes.

The compiled code settles it. Sony's shader compiler emits neg on integer packed ops, always as neg(literal 0x7fff), which only makes sense if the result is 0xffff, i.e. −1:

  • UE5's TSR UpdateHistory clamps its 3x3 neighbour offsets with v_pk_max_i16 v14, neg(0x7fff), v14 (neg_lo:[1,0] neg_hi:[1,0] op_sel_hi:[0,1]), i.e. max(-1, min - pos). The other side uses v_pk_min_i16 v11, 1, v11. Two such sites are in this program, and a third program has the same max(-1, ·) / min(1, ·) pair.
  • Another program decrements with v_pk_add_u16 v5, neg(0x7fff), v3.

These are the only uses of neg on packed integer ops among the 133 shader programs of one Sword of the Sea menu frame. A compiler that meant arithmetic negation would have written −1 as neg(1) with an inline constant. A compiler that expected the bit to be ignored would not emit it at all. Only the bit-15 flip turns 0x7fff into −1.

Ignoring the bit turned the clamp into max(0x7fff, x). The x−1 and y−1 taps of TSR's input filter were then loaded at 0x7fff + x, out of bounds as A16 coordinates, and read as 0. The weights were still normalised over all nine taps. Per-pixel register probes on a replayed menu frame:

  • the reconstructed input came out at 0.81× the input;
  • the history settled near 0.84× the scene.

With the change, the reconstructed input is 1.00× (mean 0.0243 against 0.0244). The history blend is a convex combination of the rectified history and the input again: 94 % of pixels lie between the two, with history weights in [0, 1].

Tested

Windows 11 (26200), WinLibs GCC 15.2.0, Release, on main 34a16b7f0.

  • agc_driver_packed_integer_negate (new) fails on main (439 of 512 results wrong; the TSR case returns 0x7fff7fff instead of max(-1, x)) and passes with this change. It runs 16 packed integer instructions over 32 lanes of edge values (0, ±1, 0x7fff, 0x8000, 0x8001, 0xffff, …). The cases:

    • every opcode above with neg_lo and neg_hi on different sources;
    • op_sel/op_sel_hi swaps combined with neg;
    • a clamped v_pk_add_i16 with neg;
    • the TSR encoding v_pk_max_i16 neg(lit 0x7fff), which must give max(-1, x) per lane.

    Expected values come from a per-lane reference: select the half, flip bit 15, then apply the opcode.

  • GPU suites on NVIDIA (RTX 5070 Laptop, AMD iGPU hidden), every ^agc_ ctest entry built on the Lenovo node and run here: 423/423 pass. On main with only the new test added, agc_driver_packed_integer_negate fails, and packed_integer_clamp, packed_alu and integer_dot pass.

  • Non-GPU suite (Lenovo node, ctest -E "^agc_driver|^video_out|^guest_video"): 578/579 pass. log_macros fails the same way on main 34a16b7f0 without this change.

  • Sword of the Sea menu, 240 s, shots at 60/120/230 s, on a lab branch that also carries a pending HTILE fix (without it the menu has black blobs): dark pixels 0.0 % and top luma 87/87/88 at frames 164/472/1026. On the same branch without this change, top luma was 77/73/80. The PS5 capture shows 89-91. The same holds with the shared direct-memory branch underneath: top luma 88 at frame 585.

  • Conventions: tools/check_conventions.py --base origin/main passes.

Checklist

  • Based on current main; no other open PR implements the same functions
  • One topic per PR; follow-ups go in a new PR
  • No comments in code except technical debt
  • Unimplemented paths throw (NotImplemented_nid_no_patch); silent stubs are listed in TechnicalDebt
  • No notes, investigation .md files or images added to the repository (attach them to this PR)
  • New third-party code is a submodule built from source
  • Generic behaviour, not specific to one title
  • Depends on: none
  • AI-assisted: yes (Claude Code)

🤖 Generated with Claude Code

<!-- greyfinch-sync:boykopovar/AnyPS5:issue:4824621045 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4268). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T03:37:47Z. --- Sword of the Sea (PPSA25344) menu: the TSR history no longer loses ~17 % of its energy every frame; top luma 77 → 87 (PS5 capture 89-91), and the glow at the top of the menu is back. ### What The packed integer instructions (`v_pk_add/sub_{u,i}16`, `v_pk_mul_lo_u16`, `v_pk_mad_{u,i}16`, `v_pk_min/max_{u,i}16`, `v_pk_lshlrev/lshrrev/ashrrev_b16`) read their 16-bit sources through `readU16LaneAsU32`, which applied `op_sel`/`op_sel_hi` but dropped `neg_lo`/`neg_hi`. The decoder already sets both flags for every VOP3P source; only the f16 path used them. Now `readU16LaneAsU32` flips bit 15 of the selected 16-bit half when `neg_lo` (low lane) or `neg_hi` (high lane) is set for that source, before the optional sign extension. This is the same sign-bit flip the f16 path applies. The integer dot instructions also read through this function, but the decoder still rejects `neg` on them, so they are unchanged. ### How the neg bit works on 16-bit integer halves The RDNA 2 ISA (13.3.6, VOP3P) describes `NEG` and `NEG_HI` as "negate input for low/high 16-bits of sources". Unlike the VOP3 `NEG` field ("floating-point negation"), it does not limit them to floating-point opcodes. LLVM's assembler accepts them only on floating-point operands. That is an assembler rule, so it says nothing either way about what the hardware does with the bit on integer opcodes. The compiled code settles it. Sony's shader compiler emits `neg` on integer packed ops, always as `neg(literal 0x7fff)`, which only makes sense if the result is `0xffff`, i.e. −1: - UE5's TSR `UpdateHistory` clamps its 3x3 neighbour offsets with `v_pk_max_i16 v14, neg(0x7fff), v14` (`neg_lo:[1,0] neg_hi:[1,0] op_sel_hi:[0,1]`), i.e. `max(-1, min - pos)`. The other side uses `v_pk_min_i16 v11, 1, v11`. Two such sites are in this program, and a third program has the same `max(-1, ·)` / `min(1, ·)` pair. - Another program decrements with `v_pk_add_u16 v5, neg(0x7fff), v3`. These are the only uses of `neg` on packed integer ops among the 133 shader programs of one Sword of the Sea menu frame. A compiler that meant arithmetic negation would have written −1 as `neg(1)` with an inline constant. A compiler that expected the bit to be ignored would not emit it at all. Only the bit-15 flip turns `0x7fff` into −1. Ignoring the bit turned the clamp into `max(0x7fff, x)`. The x−1 and y−1 taps of TSR's input filter were then loaded at `0x7fff + x`, out of bounds as A16 coordinates, and read as 0. The weights were still normalised over all nine taps. Per-pixel register probes on a replayed menu frame: - the reconstructed input came out at 0.81× the input; - the history settled near 0.84× the scene. With the change, the reconstructed input is 1.00× (mean 0.0243 against 0.0244). The history blend is a convex combination of the rectified history and the input again: 94 % of pixels lie between the two, with history weights in [0, 1]. ### Tested Windows 11 (26200), WinLibs GCC 15.2.0, Release, on `main` 34a16b7f0. - **`agc_driver_packed_integer_negate`** (new) fails on `main` (439 of 512 results wrong; the TSR case returns `0x7fff7fff` instead of `max(-1, x)`) and passes with this change. It runs 16 packed integer instructions over 32 lanes of edge values (0, ±1, 0x7fff, 0x8000, 0x8001, 0xffff, …). The cases: - every opcode above with `neg_lo` and `neg_hi` on different sources; - `op_sel`/`op_sel_hi` swaps combined with `neg`; - a clamped `v_pk_add_i16` with `neg`; - the TSR encoding `v_pk_max_i16 neg(lit 0x7fff)`, which must give `max(-1, x)` per lane. Expected values come from a per-lane reference: select the half, flip bit 15, then apply the opcode. - **GPU suites on NVIDIA (RTX 5070 Laptop, AMD iGPU hidden), every `^agc_` ctest entry built on the Lenovo node and run here:** 423/423 pass. On `main` with only the new test added, `agc_driver_packed_integer_negate` fails, and `packed_integer_clamp`, `packed_alu` and `integer_dot` pass. - **Non-GPU suite (Lenovo node, `ctest -E "^agc_driver|^video_out|^guest_video"`):** 578/579 pass. `log_macros` fails the same way on `main` 34a16b7f0 without this change. - **Sword of the Sea menu, 240 s, shots at 60/120/230 s**, on a lab branch that also carries a pending HTILE fix (without it the menu has black blobs): dark pixels 0.0 % and top luma 87/87/88 at frames 164/472/1026. On the same branch without this change, top luma was 77/73/80. The PS5 capture shows 89-91. The same holds with the shared direct-memory branch underneath: top luma 88 at frame 585. - **Conventions:** `tools/check_conventions.py --base origin/main` passes. ### Checklist <!-- Rules behind each item: https://github.com/boykopovar/AnyPS5/blob/main/CONTRIBUTING.md --> - [x] Based on current `main`; no other open PR implements the same functions - [x] One topic per PR; follow-ups go in a new PR - [x] No comments in code except [technical debt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/CONVENTIONS.md) - [x] Unimplemented paths throw (`NotImplemented_nid_no_patch`); silent stubs are listed in [TechnicalDebt](https://github.com/boykopovar/AnyPS5/blob/main/docs/dev/TechnicalDebt.md#silent-stubs) - [x] No notes, investigation `.md` files or images added to the repository (attach them to this PR) - [x] New third-party code is a submodule built from source - [x] Generic behaviour, not specific to one title - [x] Depends on: none - [x] AI-assisted: yes (Claude Code) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
parl0v commented 2026-10-12 03:44:28 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by parl0v on 2026-10-12T03:44:28Z.


Second-GPU data point, NVIDIA RTX 4060 (Windows 10, MinGW build):

  • With this PR: agc_driver_packed_integer_negate passes (0.4 s).
  • With SubwordPacking.cpp reverted to the pre-fix version (only the test rebuilt): fails with 439 mismatches, matching the 439/512 on main. Examples:
    v_pk_max_u16 v14, v4, v5 neg_lo:[0,1] neg_hi:[0,1]          is 0xc000021b, expected 0xc000821b
    v_pk_mul_lo_u16 v16, v4, v5 neg_lo:[1,0] neg_hi:[0,1]       is 0x80006ed9, expected 0x8000eed9
    v_pk_mad_i16 v17, v4, v5, v6 neg_lo:[0,0,1] neg_hi:[1,0,1]  is 0x800f5ca5, expected 0x000fdca5
    v_pk_ashrrev_i16 v20, v4, v5 neg_lo:[0,1] neg_hi:[1,1]      is 0x00020000, expected 0x8002fff0
    

In-game on the same machine (Sword of the Sea main menu, on the working-group stack): with the fix the top glow, light shafts and particle glow come back and match the PS5 frame; without it the scene settles noticeably darker.

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6117353885 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4268#issuecomment-6117353885). Originally posted by [parl0v](https://github.com/parl0v) on 2026-10-12T03:44:28Z. --- Second-GPU data point, NVIDIA RTX 4060 (Windows 10, MinGW build): - With this PR: `agc_driver_packed_integer_negate` **passes** (0.4 s). - With `SubwordPacking.cpp` reverted to the pre-fix version (only the test rebuilt): **fails with 439 mismatches**, matching the 439/512 on `main`. Examples: ``` v_pk_max_u16 v14, v4, v5 neg_lo:[0,1] neg_hi:[0,1] is 0xc000021b, expected 0xc000821b v_pk_mul_lo_u16 v16, v4, v5 neg_lo:[1,0] neg_hi:[0,1] is 0x80006ed9, expected 0x8000eed9 v_pk_mad_i16 v17, v4, v5, v6 neg_lo:[0,0,1] neg_hi:[1,0,1] is 0x800f5ca5, expected 0x000fdca5 v_pk_ashrrev_i16 v20, v4, v5 neg_lo:[0,1] neg_hi:[1,1] is 0x00020000, expected 0x8002fff0 ``` In-game on the same machine (Sword of the Sea main menu, on the working-group stack): with the fix the top glow, light shafts and particle glow come back and match the PS5 frame; without it the scene settles noticeably darker.
simonbbby commented 2026-10-12 12:54:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by simonbbby on 2026-10-12T12:54:30Z.


Measured on hardware: on gfx1036 (RDNA2), neg_lo/neg_hi on a packed 16-bit integer source flips bit 15 of the selected half, as this PR models. The gfx1036 output equals the values that Reference() in PackedIntegerNegate.cpp expects, in all 512 cells, in wave32 and in wave64.

Setup: tools/hw-oracle from main 3d8ffeb2 on gfx1036 (RDNA2 iGPU of a Ryzen 9 9950X), Linux 7.0 (Ubuntu 24.04), ROCm HSA runtime 5.7.1, LLVM 18.1.3. Float controls: ieee 0, dx10_clamp 1, denorm32 0, denorm16 3, round32 0, round16 0, fp16_overflow 0. The body is the test's 33 instruction dwords as raw .long words, run over its 32 rows. A second body runs 5 probes that are not in the test, over the same 32 rows.

Cells where gfx1036 matches each model of the neg bit:

model this PR's 16 instructions (512 cells) 5 extra probes (160 cells)
flip bit 15 (this PR) 512 160
ignore the bit (main) 73 23
two's-complement negate 47 24

Wave32 and wave64 gave identical tables. Three runs gave byte-identical output.

The extra probes:

  • v_pk_add_u16 v10, neg(0x7fff), v4 subtracts 1 per half: 0x000f8000 gives 0x000e7fff. This is the decrement form from the description.
  • v_pk_max_i16 v11, neg(1), v4 compares with 0x8001 (−32767), not −1: 0x80008000 gives 0x80018001.
  • v_pk_min_i16 v12, neg(-1), v4, v_pk_sub_u16 v13, v4, neg(0x7fff) (adds 1) and v_pk_mad_u16 v14, v4, neg(1), v5 (multiplies by 0x8001) also follow the bit-15 flip.

Controls:

  • With every neg_lo/neg_hi bit cleared in both bodies, gfx1036 matches the "ignore" model in 512/512 and 160/160 cells. So the match comes from the neg bits.
  • I switched one set neg bit at a time to "ignore" or to two's complement. For 49 of the 51 set bits, the hardware contradicts both alternatives in 8 to 32 of the 32 half-lanes. These bits include the v_pk_mad src2 accumulator, the clamped add, the literal and inline-constant sources, and the op_sel swaps.
  • The other 2 bits are neg on a shift count (v_pk_ashrrev_i16 src0.hi, v_pk_lshrrev_b16 src0.lo). Only the low 4 bits of the count are used, so flipping bit 15 and ignoring the bit give the same result. Two's complement is still refuted there (16 and 14 of 32 half-lanes), and the XOR in this PR is harmless.

Recompiler before and after: Ubuntu 24.04, GCC 13.3, Release with BUILD_TESTING=ON and ANYPS5_ENABLE_SPIRV_TOOLS=ON. I ran agc_driver_packed_integer_negate, agc_driver_packed_integer_clamp, agc_driver_packed_alu and agc_driver_integer_dot with ANYPS5_REQUIRE_VULKAN=1, so a missing device fails instead of skipping. The devices were RADV (gfx1036, Mesa 25.2.8), an RTX 3090 (NVIDIA 595.99.02) and llvmpipe (Mesa 25.2.8). parl0v's RTX 4060 run already covers NVIDIA; RADV and llvmpipe are new.

  • main 3d8ffeb2 with only PackedIntegerNegate.cpp added: 3/4 on each device. agc_driver_packed_integer_negate fails with 439 mismatches. That is exactly the number of cells where ignoring the neg bit differs from the bit-15 flip (512 − 73).
  • 48654bdc: 4/4 on each device.

One correction to the description: LLVM's assembler does accept neg on these integer ops. llvm-mc 18.1.3 and 22.1.8 assemble neg_lo/neg_hi on v_pk_max_i16 (with a literal), v_pk_mad_i16 and v_pk_lshrrev_b16 for -mcpu=gfx1013 and gfx1030, with identical encodings.

Not measured: gfx1013 itself. gfx1036 is gfx10.3 and the PS5 is gfx10.1. HW_ORACLE.md treats VALU encodings as shared apart from the gfx10.1-only ops, and none of these opcodes is one of them. Neg on the integer dot ops was not measured; the decoder still rejects it.

Reproduce

WORDS is Code[5..37] of PackedIntegerNegate.cpp (33 dwords). ROWS is its Rows. Result i of each row is v(10 + i); compare out[row][:16] with Reference(Cases[i], Rows[row]) from the test. The extra probes are 0xcc0a410a 0x300208ff 0x00007fff 0xcc07410b 0x30020881 0xcc08410c 0x300208c1 0xcc0b420d 0x4801ff04 0x00007fff 0xcc09420e 0x4c150304. Run as sg render -c "python3 repro.py".

import sys; sys.path.insert(0, "tools/hw-oracle")
from hw_oracle import run

body = "\n".join(f"  .long 0x{w:08x}" for w in WORDS)
for wave64 in (False, True):
    out = run(body, ROWS, wave64=wave64, ieee=0, dx10_clamp=1, denorm32=0, denorm16=3,
              round32=0, round16=0, fp16_overflow=0)
<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6124673182 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4268#issuecomment-6124673182). Originally posted by [simonbbby](https://github.com/simonbbby) on 2026-10-12T12:54:30Z. --- Measured on hardware: on gfx1036 (RDNA2), `neg_lo`/`neg_hi` on a packed 16-bit integer source flips bit 15 of the selected half, as this PR models. The gfx1036 output equals the values that `Reference()` in `PackedIntegerNegate.cpp` expects, in all 512 cells, in wave32 and in wave64. Setup: `tools/hw-oracle` from `main` 3d8ffeb2 on gfx1036 (RDNA2 iGPU of a Ryzen 9 9950X), Linux 7.0 (Ubuntu 24.04), ROCm HSA runtime 5.7.1, LLVM 18.1.3. Float controls: `ieee 0`, `dx10_clamp 1`, `denorm32 0`, `denorm16 3`, `round32 0`, `round16 0`, `fp16_overflow 0`. The body is the test's 33 instruction dwords as raw `.long` words, run over its 32 rows. A second body runs 5 probes that are not in the test, over the same 32 rows. Cells where gfx1036 matches each model of the neg bit: | model | this PR's 16 instructions (512 cells) | 5 extra probes (160 cells) | |---|---|---| | flip bit 15 (this PR) | 512 | 160 | | ignore the bit (`main`) | 73 | 23 | | two's-complement negate | 47 | 24 | Wave32 and wave64 gave identical tables. Three runs gave byte-identical output. The extra probes: - `v_pk_add_u16 v10, neg(0x7fff), v4` subtracts 1 per half: `0x000f8000` gives `0x000e7fff`. This is the decrement form from the description. - `v_pk_max_i16 v11, neg(1), v4` compares with 0x8001 (−32767), not −1: `0x80008000` gives `0x80018001`. - `v_pk_min_i16 v12, neg(-1), v4`, `v_pk_sub_u16 v13, v4, neg(0x7fff)` (adds 1) and `v_pk_mad_u16 v14, v4, neg(1), v5` (multiplies by 0x8001) also follow the bit-15 flip. Controls: - With every `neg_lo`/`neg_hi` bit cleared in both bodies, gfx1036 matches the "ignore" model in 512/512 and 160/160 cells. So the match comes from the neg bits. - I switched one set neg bit at a time to "ignore" or to two's complement. For 49 of the 51 set bits, the hardware contradicts both alternatives in 8 to 32 of the 32 half-lanes. These bits include the `v_pk_mad` src2 accumulator, the clamped add, the literal and inline-constant sources, and the `op_sel` swaps. - The other 2 bits are neg on a shift count (`v_pk_ashrrev_i16` src0.hi, `v_pk_lshrrev_b16` src0.lo). Only the low 4 bits of the count are used, so flipping bit 15 and ignoring the bit give the same result. Two's complement is still refuted there (16 and 14 of 32 half-lanes), and the XOR in this PR is harmless. Recompiler before and after: Ubuntu 24.04, GCC 13.3, Release with `BUILD_TESTING=ON` and `ANYPS5_ENABLE_SPIRV_TOOLS=ON`. I ran `agc_driver_packed_integer_negate`, `agc_driver_packed_integer_clamp`, `agc_driver_packed_alu` and `agc_driver_integer_dot` with `ANYPS5_REQUIRE_VULKAN=1`, so a missing device fails instead of skipping. The devices were RADV (gfx1036, Mesa 25.2.8), an RTX 3090 (NVIDIA 595.99.02) and llvmpipe (Mesa 25.2.8). parl0v's RTX 4060 run already covers NVIDIA; RADV and llvmpipe are new. - `main` 3d8ffeb2 with only `PackedIntegerNegate.cpp` added: 3/4 on each device. `agc_driver_packed_integer_negate` fails with 439 mismatches. That is exactly the number of cells where ignoring the neg bit differs from the bit-15 flip (512 − 73). - 48654bdc: 4/4 on each device. One correction to the description: LLVM's assembler does accept `neg` on these integer ops. `llvm-mc` 18.1.3 and 22.1.8 assemble `neg_lo`/`neg_hi` on `v_pk_max_i16` (with a literal), `v_pk_mad_i16` and `v_pk_lshrrev_b16` for `-mcpu=gfx1013` and `gfx1030`, with identical encodings. Not measured: gfx1013 itself. gfx1036 is gfx10.3 and the PS5 is gfx10.1. `HW_ORACLE.md` treats VALU encodings as shared apart from the gfx10.1-only ops, and none of these opcodes is one of them. Neg on the integer dot ops was not measured; the decoder still rejects it. <details><summary>Reproduce</summary> `WORDS` is `Code[5..37]` of `PackedIntegerNegate.cpp` (33 dwords). `ROWS` is its `Rows`. Result `i` of each row is `v(10 + i)`; compare `out[row][:16]` with `Reference(Cases[i], Rows[row])` from the test. The extra probes are `0xcc0a410a 0x300208ff 0x00007fff 0xcc07410b 0x30020881 0xcc08410c 0x300208c1 0xcc0b420d 0x4801ff04 0x00007fff 0xcc09420e 0x4c150304`. Run as `sg render -c "python3 repro.py"`. ```python import sys; sys.path.insert(0, "tools/hw-oracle") from hw_oracle import run body = "\n".join(f" .long 0x{w:08x}" for w in WORDS) for wave64 in (False, True): out = run(body, ROWS, wave64=wave64, ieee=0, dx10_clamp=1, denorm32=0, denorm16=3, round32=0, round16=0, fp16_overflow=0) ``` </details>
AlxcBTW commented 2026-10-12 15:42:27 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by AlxcBTW on 2026-10-12T15:42:27Z.


@simonbbby thanks a lot for running it on gfx1036. Hardware matching all 512 cells in both wave sizes is exactly the evidence this one needed.

AI-assisted: yes (Claude Code)

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6127591416 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4268#issuecomment-6127591416). Originally posted by [AlxcBTW](https://github.com/AlxcBTW) on 2026-10-12T15:42:27Z. --- @simonbbby thanks a lot for running it on gfx1036. Hardware matching all 512 cells in both wave sizes is exactly the evidence this one needed. AI-assisted: yes (Claude Code)
thuanquang commented 2026-10-20 08:34:30 +00:00 (Migrated from github.com)

Imported from boykopovar/AnyPS5. Originally posted by thuanquang on 2026-10-20T08:34:30Z.


Hardware confirmation of this rule on RDNA 2, for the record: RX 6700 XT (gfx1031), raw ISA through the HIP runtime of AMD's Windows driver 32.0.21045.5002. All 14 packed 16-bit integer VOP3P ops (v_pk_mad_i16/u16, v_pk_mul_lo_u16, v_pk_add/sub_i16/u16, v_pk_lshlrev/lshrrev_b16, v_pk_ashrrev_i16, v_pk_max/min_i16/u16) ran with the neg_lo/neg_hi bits set directly in the encoding: each source alone, both halves, all three sources for the mads. Inputs were 144 edge pairs (0, 1, 0x7fff, 0x8000, 0x8001, 0xffff, ...) and 112 random words, 256 rows per combination.

Every row of every combination matches flipping bit 15 of the selected half before the operation, which is what this PR implements. A two's-complement negate of the half matches 0-46% of the rows, and ignoring the bits 0-100% depending on the op (shifts ignore a negated shift amount in their low bits by construction).

<!-- greyfinch-sync:boykopovar/AnyPS5:comment:6286900403 --> Imported from [boykopovar/AnyPS5](https://github.com/boykopovar/AnyPS5/pull/4268#issuecomment-6286900403). Originally posted by [thuanquang](https://github.com/thuanquang) on 2026-10-20T08:34:30Z. --- Hardware confirmation of this rule on RDNA 2, for the record: RX 6700 XT (gfx1031), raw ISA through the HIP runtime of AMD's Windows driver 32.0.21045.5002. All 14 packed 16-bit integer VOP3P ops (`v_pk_mad_i16/u16`, `v_pk_mul_lo_u16`, `v_pk_add/sub_i16/u16`, `v_pk_lshlrev/lshrrev_b16`, `v_pk_ashrrev_i16`, `v_pk_max/min_i16/u16`) ran with the `neg_lo`/`neg_hi` bits set directly in the encoding: each source alone, both halves, all three sources for the mads. Inputs were 144 edge pairs (0, 1, 0x7fff, 0x8000, 0x8001, 0xffff, ...) and 112 random words, 256 rows per combination. Every row of every combination matches flipping bit 15 of the selected half before the operation, which is what this PR implements. A two's-complement negate of the half matches 0-46% of the rows, and ignoring the bits 0-100% depending on the op (shifts ignore a negated shift amount in their low bits by construction).
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
boykopovar/AnyPS5!4268
No description provided.