cpp-migration: lower the SDWA forms of binary16 add, sub and mul in the direct C++ compute path #2963

Closed
opened 2026-11-26 23:52:36 +00:00 by Leyukaka · 1 comment
Leyukaka commented 2026-11-26 23:52:36 +00:00 (Migrated from github.com)
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by Leyukaka on 2026-11-26T23:52:36Z.


Target branch cpp-migration. Part of #2935 (instruction coverage). I am taking the SDWA forms of binary16 arithmetic. The plain forms are #2945 (claimed); this builds on that lowering and will rebase onto it once it lands.

Gap: the direct compute decoder admits SDWA operand profiles for a list of integer and binary32 VOP1/VOP2 ops (gfx1013_compute_native.cpp, "unimplemented direct SDWA operand profile"). The binary16 VOP2 arithmetic ops are not on it, so v_add_f16_sdwa and v_mul_f16_sdwa are refused, for example:

  • v_add_f16_sdwa v16, v1, v12 dst_sel:WORD_0 dst_unused:UNUSED_PAD src0_sel:WORD_0 ...;
  • v_mul_f16_sdwa v6, v25, v19 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:WORD_0 ....

Measured on a local capture of 2,689 compute requests (counts and instruction shape only). The table counts every request that contains the form; occurrences are static counts up to each program's s_endpgm.

Form Requests Occurrences
v_add_f16_sdwa 18 178
v_mul_f16_sdwa 7 31

The most common shapes write dst_sel:WORD_0 with UNUSED_PRESERVE or UNUSED_PAD, and select WORD_0, WORD_1 or DWORD sources.

With compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests built from cpp-migration f934df52, 11 request keys stop first at this refusal: 9 with v_add_f16_sdwa and 2 with v_mul_f16_sdwa. In a 600 s start-up run, which used the Python translator, they were dispatched 16,828 times (6,723 + 10,105). I matched pipelines by request key.

Plan: the SDWA forms of v_add_f16, v_sub_f16, v_subrev_f16 and v_mul_f16, following tools/startup/gfx2hlsl.py sdwa_half(), which already lowers them on main.

  • Sources: src0_sel/src1_sel WORD_0 or WORD_1 pick the half, and DWORD reads the low half, as the 16-bit op does. abs/neg are allowed. Each source must be a single VGPR.
  • Compute in binary32 and round once to binary16 with the existing integer packed_half_rne, as v_cvt_f16_f32 does.
    • For add, sub and mul of binary16 inputs, binary32 has enough precision (24 >= 2*11 + 2) that this matches a direct binary16 rounding.
    • This assumes the default FP mode (round to nearest even, binary16 denormals kept), as sdwa_half and #2945 do.
  • Destination: dst_sel WORD_0 or WORD_1. UNUSED_PAD zeroes the other half; UNUSED_PRESERVE keeps the other half of the old register.
  • Keep refused, as sdwa_half() does:
    • dst_sel:DWORD;
    • byte selections, sext(), clamp and output modifiers;
    • SGPR and constant sources.
  • v_min_f16/v_max_f16 SDWA, which sdwa_half does not lower, stay refused.

Tests: a hardware readback against an independent binary16 CPU reference (Python struct 'e', round to nearest even).

  • Each op under the measured source and destination shapes, including WORD_1 sources, UNUSED_PRESERVE, UNUSED_PAD, and abs/neg.
  • Values: a rounding tie, a subnormal product that rounds, overflow to infinity, and a NaN input (compared as NaN, not bit for bit).
  • Controls: dst_sel:DWORD, a byte selection and an SGPR source stay refused.
  • Mutants: swapping WORD_0/WORD_1, and ignoring UNUSED_PRESERVE.

AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6637059065 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2963). Originally posted by [Leyukaka](https://github.com/Leyukaka) on 2026-11-26T23:52:36Z. --- Target branch `cpp-migration`. Part of #2935 (instruction coverage). I am taking the SDWA forms of binary16 arithmetic. The plain forms are #2945 (claimed); this builds on that lowering and will rebase onto it once it lands. **Gap:** the direct compute decoder admits SDWA operand profiles for a list of integer and binary32 VOP1/VOP2 ops (`gfx1013_compute_native.cpp`, "unimplemented direct SDWA operand profile"). The binary16 VOP2 arithmetic ops are not on it, so `v_add_f16_sdwa` and `v_mul_f16_sdwa` are refused, for example: - `v_add_f16_sdwa v16, v1, v12 dst_sel:WORD_0 dst_unused:UNUSED_PAD src0_sel:WORD_0 ...`; - `v_mul_f16_sdwa v6, v25, v19 dst_sel:WORD_1 dst_unused:UNUSED_PRESERVE src0_sel:WORD_0 ...`. **Measured** on a local capture of 2,689 compute requests (counts and instruction shape only). The table counts every request that contains the form; occurrences are static counts up to each program's `s_endpgm`. | Form | Requests | Occurrences | |---|---:|---:| | `v_add_f16_sdwa` | 18 | 178 | | `v_mul_f16_sdwa` | 7 | 31 | The most common shapes write `dst_sel:WORD_0` with `UNUSED_PRESERVE` or `UNUSED_PAD`, and select `WORD_0`, `WORD_1` or `DWORD` sources. With `compile_dxil --jobs 8 gfx1013-direct-cs@36 --requests` built from `cpp-migration` `f934df52`, 11 request keys stop first at this refusal: 9 with `v_add_f16_sdwa` and 2 with `v_mul_f16_sdwa`. In a 600 s start-up run, which used the Python translator, they were dispatched 16,828 times (6,723 + 10,105). I matched pipelines by request key. **Plan:** the SDWA forms of `v_add_f16`, `v_sub_f16`, `v_subrev_f16` and `v_mul_f16`, following `tools/startup/gfx2hlsl.py` `sdwa_half()`, which already lowers them on main. - Sources: `src0_sel`/`src1_sel` `WORD_0` or `WORD_1` pick the half, and `DWORD` reads the low half, as the 16-bit op does. abs/neg are allowed. Each source must be a single VGPR. - Compute in binary32 and round once to binary16 with the existing integer `packed_half_rne`, as `v_cvt_f16_f32` does. - For add, sub and mul of binary16 inputs, binary32 has enough precision (24 >= 2*11 + 2) that this matches a direct binary16 rounding. - This assumes the default FP mode (round to nearest even, binary16 denormals kept), as `sdwa_half` and #2945 do. - Destination: `dst_sel` `WORD_0` or `WORD_1`. `UNUSED_PAD` zeroes the other half; `UNUSED_PRESERVE` keeps the other half of the old register. - Keep refused, as `sdwa_half()` does: - `dst_sel:DWORD`; - byte selections, `sext()`, `clamp` and output modifiers; - SGPR and constant sources. - `v_min_f16`/`v_max_f16` SDWA, which `sdwa_half` does not lower, stay refused. **Tests:** a hardware readback against an independent binary16 CPU reference (Python `struct` `'e'`, round to nearest even). - Each op under the measured source and destination shapes, including `WORD_1` sources, `UNUSED_PRESERVE`, `UNUSED_PAD`, and abs/neg. - Values: a rounding tie, a subnormal product that rounds, overflow to infinity, and a NaN input (compared as NaN, not bit for bit). - Controls: `dst_sel:DWORD`, a byte selection and an SGPR source stay refused. - Mutants: swapping `WORD_0`/`WORD_1`, and ignoring `UNUSED_PRESERVE`. AI-assisted.
MasterDomino commented 2026-11-27 01:01:12 +00:00 (Migrated from github.com)
Author
Contributor

Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-27T01:01:12Z.


Closed by #2973, merged into cpp-migration as 7bcff286. native_sdwa_f16_{ir,hardware} pass on an RTX 5080 (author) and on an RX 9070 XT, and reading only the low half fails both. AI-assisted.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7206942636 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/issues/2963#issuecomment-7206942636). Originally posted by [MasterDomino](https://github.com/MasterDomino) on 2026-11-27T01:01:12Z. --- Closed by #2973, merged into `cpp-migration` as `7bcff286`. `native_sdwa_f16_{ir,hardware}` pass on an RTX 5080 (author) and on an RX 9070 XT, and reading only the low half fails both. AI-assisted.
Sign in to join this conversation.
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
R0Y00/Xbox2Windows#2963
No description provided.