Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11372,6 +11372,10 @@ if(EXISTS "${INTAKE_PYTHON}")
"${CMAKE_SOURCE_DIR}/tests/pixel_aot_check.py" draw-f16-rcp-sqrt "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(pixel_aot_f16_rcp_sqrt_${adapter} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
add_test(NAME pixel_aot_f16_rsq_exp_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/pixel_aot_check.py" draw-f16-rsq-exp "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
set_tests_properties(pixel_aot_f16_rsq_exp_${adapter} PROPERTIES TIMEOUT 60 SKIP_RETURN_CODE 77)
add_test(NAME pixel_aot_f16_fmac_ldexp_${adapter} COMMAND "${INTAKE_PYTHON}" -B
"${CMAKE_SOURCE_DIR}/tests/pixel_aot_check.py" draw-f16-fmac-ldexp "${DXC_EXECUTABLE}"
"$<TARGET_FILE:offscreen_check>" ${adapter})
Expand Down Expand Up @@ -11660,6 +11664,8 @@ if(EXISTS "${INTAKE_PYTHON}")
ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_f16_round_${adapter}.txt")
set_tests_properties(pixel_aot_f16_rcp_sqrt_${adapter} PROPERTIES
ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_f16_rcp_sqrt_${adapter}.txt")
set_tests_properties(pixel_aot_f16_rsq_exp_${adapter} PROPERTIES
ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_f16_rsq_exp_${adapter}.txt")
set_tests_properties(pixel_aot_f16_fmac_ldexp_${adapter} PROPERTIES
ENVIRONMENT "FORM_COVERAGE_RECORD=${CMAKE_BINARY_DIR}/form_coverage/pixel_aot_f16_fmac_ldexp_${adapter}.txt")
set_tests_properties(pixel_aot_f16_cvt_int16_${adapter} PROPERTIES
Expand Down
4 changes: 4 additions & 0 deletions docs/experiments.md
Original file line number Diff line number Diff line change
Expand Up @@ -9003,6 +9003,10 @@ Plain binary16 `VOP1` reciprocal and square root (issue #839) `v_rcp_f16` and `v

The controls (`check_f16_rcp_sqrt_controls`, no GPU) cover the bare, `_e32` and `_e64` spellings, every source kind, the finite, register, modifier, mode, scheduling, sample and reader refusals, and chains of both operations. The Python reference (`f16_rcp_sqrt_reference`) applies the same two rounds from the semantics without `pixel_aot`, handles the binary16 overflow threshold and compares with the translator's `f16_rcp_sqrt_result` on every finite encoding. The draw (`tests/pixel_aot_check.py draw-f16-rcp-sqrt`, tests `pixel_aot_f16_rcp_sqrt_hardware` and `pixel_aot_f16_rcp_sqrt_warp`, 60 s limit, capability skip 77) runs five baked programs over 20 source values through both ops in a rotation of e32, e64, SGPR and literal forms and packs two results per word with SDWA `WORD_0` and `WORD_1`; four reader programs and two chains read both result tags. Bits 31:16 of every source word hold junk. The lossless `R32G32B32A32_UINT` readback is compared with the Python reference. Two deviations must each mismatch, one batch per mutation with the statuses printed (reciprocal and square root swapped, and a source read from bits 31:16), and a source with no finite proof is refused at translation. Both tests passed on WARP and on the RX 9060 XT. In `gfx1013.tsv` and `rdna2.tsv` the two operations add their VOP1 and VOP3 rows, so the fixture records four newly covered forms (rcp and sqrt, each e32 and e64); the two operations themselves are the +2. `tests/form_coverage_check.py check_f16_rcp_sqrt_forms` pins that the DPP, SDWA and rsq neighbours stay uncovered. `tools/scan_unsupported_shaders.py` accepts the syntactic source forms and `tests/rdna2_tools_check.py test_binary16_e64_scanner_translator_agreement` checks that its acceptance agrees with `pixel_aot.lower`. Not measured: the high half of the destination, the console's denormal and rounding state beyond the declared nearest-even entry profile, NaN payloads and special-function results beyond the modelled infinities, runtime sources, the DPP and SDWA spellings, the hardware behaviour of integer inline constants on binary16 operands, and whether any title executes these paths.

Plain binary16 `VOP1` reciprocal square root and exponent (issue #839), `v_rsq_f16` and `v_exp_f16`, extend the unary entry above: the unsuffixed, `_e32` and `_e64` spellings widen the low half with `widen16`, evaluate the direct compute path's `rsqrt` or `exp2` in binary32, narrow with `narrow16`, and then select RDNA 2's special results from the source half. `v_rsq_f16` maps any source above `+infinity` (every negative finite encoding) to the canonical quiet NaN `0x7e00`, `+infinity` to zero and a zero magnitude to `source | 0x7c00`, so `-0` gives `-infinity`; `v_exp_f16` applies the 70 midpoint corrections of `exp_f16_midpoints` from `src/gfx1013_direct_compute.inl`, maps `2^-25` (`0xce40`) to zero and a magnitude above `+infinity` to `0x7e00`. The emitted helpers are `f16_rsq_result` and `f16_exp2_result`, and `tools/pixel_aot.py` carries the same table as `EXP_F16_MIDPOINTS`. The translator tracks each result with `f16_rsq_exp_result`: a positive finite reciprocal square root is rounded exactly to binary16 with a 90-digit reference, a negative one is the canonical NaN above, and `exp` rounds the exact `2^S0` after the table corrections. Every finite source therefore has a modelled result and the function does not return None; its signature keeps the None contract for a future unmodelled NaN. The source proof, entry profile, destination range and sample scheduling are those of the reciprocal and square root entry; the same modifiers, `clamp`, `mul:`, `div:`, `op_sel`, DPP, SDWA and extra operands stay refused, and `v_log_f16`, `v_sin_f16` and `v_cos_f16` remain unlowered.

The controls (`check_f16_rsq_exp_controls`, no GPU) cover every spelling, operand kind, refusal, mode, scheduling and reader, compare the Python reference with `f16_rsq_exp_result` on all 65,536 finite encodings, and pin `pixel_aot.EXP_F16_MIDPOINTS` to the C++ `exp_f16_midpoints` array through `tests/f16_exp_midpoints.py check_cpp_table`. The draw (`tests/pixel_aot_check.py draw-f16-rsq-exp`, tests `pixel_aot_f16_rsq_exp_hardware` and `pixel_aot_f16_rsq_exp_warp`, 60 s limit, capability skip 77) runs six baked programs over 24 sources in a rotation of e32, e64, SGPR and literal forms, packs `rsq | exp << 16` with SDWA `WORD_0` and `WORD_1`, and adds four reader programs and two chains; the values cover exact roots and powers, inexact results, both signed zeros, subnormals, the largest finite half, `2^-25`, two midpoint-table rows, an overflow and the canonical negative-root NaN, and the chosen positive roots avoid the 8 f32 ULP window where the D3D `rsqrt` error allows either binary16 encoding. The lossless `R32G32B32A32_UINT` readback is compared with `f16_rsq_exp_reference`, an exact grid search and 90-digit `2^S0` without `pixel_aot`. Two deviations must each mismatch, one batch per mutation with the statuses printed (the two mnemonics swapped at translation, and a source read from bits 31:16), and a source with no finite proof is refused at translation. `tests/form_coverage_check.py check_f16_rsq_exp_forms` pins the four newly covered forms (rsq and exp, each e32 and e64) and leaves the DPP, SDWA, log, sin and cos neighbours uncovered; the four forms take the measured totals from 1546/1968 and 1537/1863 to 1550/1968 and 1541/1863. Both tests passed on WARP and on the RX 9060 XT (driver 32.0.32029.2010), Windows 11 build 10.0.26300.10075. Not measured: the high half of the destination, the D3D `rsqrt` and `exp2` error windows beyond the modelled midpoint corrections and the exact reference, runtime sources, NaN and infinity constants (refused before lowering), the DPP and SDWA spellings, the console's special-function behaviour, the remaining log, sin and cos forms, and whether any title executes these paths.

Plain binary16 fused multiply-accumulate and power-of-two scaling (issue #839), `v_fmac_f16` and `v_ldexp_f16` in the unsuffixed and `_e32` spellings, under the rules of the `VOP2` arithmetic above. The AMD RDNA 2 ISA reference gives `D.f16 = S0.f16 * S1.f16 + D.f16` for the first and `D.f16 = S0.f16 * 2.0 ^ S1.i16` for the second (LLVM 15.0.7 `VOP2Instructions.td` types the exponent as `i16`); the multiply-accumulate is fused, so the exact product and sum are rounded once to nearest even. The fused form reads the destination as a third operand, so the accumulator must already hold a statically proven finite half (a copy of a constant, or the result of an earlier accepted binary16 op); it is rounded with the existing integer routine `fma16_rne`, whose result must not overflow. `v_ldexp_f16` needs a statically known exponent, read as the signed low 16 bits of a VGPR (bits 31:16 are never read) and limited to -64..64: the binary32 product of the exactly widened half and a power of two is exact, because both the multiplier and the product are binary32 normals, and `narrow16` rounds it once, so a result below the smallest subnormal becomes a signed zero and a tie goes to the even encoding. The translator evaluates both results with exact rational arithmetic (`f16_pk_fmac_lane_result` for the fused form and `f16_ldexp_result`), so a chain stays proven and an overflow is refused with `binary16 result overflows: v_fmac_f16` or `v_ldexp_f16`; the exponent refusals are `binary16 ldexp exponent lacks a proof: <reg>` and `binary16 ldexp exponent out of range: <n>`. The source proof, the entry profile, the `("half16", alu)` result tag and the audited readers are those of the `VOP2` arithmetic. src1 must be a VGPR in the e32 encoding; the `_e64`, DPP and SDWA spellings, `clamp`, `mul:`, `op_sel` and source modifiers are refused. The controls (`check_f16_fmac_ldexp_controls`, no GPU) pin worked rows of an independent reference, which finds the nearest binary16 value on the sorted grid of exact values and shares no formula with the translator, and compare it with the translator's copies on a deterministic sample; they also cover every operand kind, the proof, overflow, exponent and mode refusals, the scheduling and mask checks and the readers. The draw (`tests/pixel_aot_check.py draw-f16-fmac-ldexp`, tests `pixel_aot_f16_fmac_ldexp_hardware` and `pixel_aot_f16_fmac_ldexp_warp`, 120 s limit, capability skip 77) bakes every operand into the program: six programs run 24 triples through `v_fmac_f16` (a cancellation, rows where rounding the product first gives another result, signed-zero sums, ties into the subnormals, the carry into `0x0400`, a product that only sets a sticky bit, 65504 and the values just below the overflow threshold) and six run 24 scalings (the binade edges, ties to even into the subnormals, subnormal to normal, signed zeros and exponents from -64 to 64), with src0 in a VGPR, an SGPR or a literal in rotation, and two chains feed a result into the next op as source, accumulator or scaled operand. Bits 31:16 of every source word hold junk, and the exponent words carry junk in the high half. The readback is the lossless `R32G32B32A32_UINT` target against the independent reference; the programs with a subnormal source or result also run under a binary32 `-denorm ftz` build and must still pass. Seven deviations must each mismatch, one batch per mutation with the statuses printed (the product rounded before the sum, the accumulator ignored, the multiplicand and the accumulator swapped, a source read from bits 31:16 in the fused form and again in the scaling form, the exponent negated, and subnormal results flushed to a signed zero), and a Python pre-check requires that each changes an expected word of some program and leaves unrelated rows alone. Not measured: the high half of the destination, the console's denormal state, NaN and infinity operands, runtime operands and exponents, exponents beyond 64 in magnitude (the ISA reference does not state a clamp), and the hardware reading of integer inline constants on binary16 operands. The shaders were not run on a GPU for this entry; the arithmetic of both lowerings was checked against the reference with a line-by-line Python transliteration only.

`tools/scan_unsupported_shaders.py` reports the `_e64` spelling of the four `VOP2` arithmetic ops and the four `VOP1` rounding ops above as supported, matching what `tools/pixel_aot.py` lowers: two sources of the `_e32` source set (a binary16 inline constant, 0, a 16-bit literal, a VGPR or an SGPR; the `_e64` src1 need not be a VGPR) or one source for the rounding ops, with no modifier, `clamp`, `mul:`, `div:` or `op_sel`. The `_e64` spellings of `v_cvt_f16_i16` and `v_cvt_f16_u16` and of `v_fract_f16` stay unsupported. This is a syntactic match only: whether a source is statically proven finite is decided by the translator. `tests/rdna2_tools_check.py` (`test_binary16_e64_scanner_translator_agreement`) lowers each accepted and each refused form through `pixel_aot.lower` and requires the scanner to agree with it. No lowering changed here, so this adds no new shader readback; the existing binary16 draws in `tests/pixel_aot_check.py` already cover the `_e64` lowering. It shows scanner and translator agreement, not that any title runs.
Expand Down
38 changes: 38 additions & 0 deletions tests/form_coverage_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -721,6 +721,43 @@ def check_f16_rcp_sqrt_forms():
pixel.ACCEPTED.update(saved)


def check_f16_rsq_exp_forms():
"""The four plain binary16 VOP1 reciprocal-square-root and exponent forms (e32 and e64 spellings of rsq and
exp) count as covered once the translator accepts their fixtures; the DPP and SDWA spellings and log, sin and
cos stay uncovered."""
import pixel_aot_check as pixel
saved = set(pixel.ACCEPTED)
pixel.ACCEPTED.clear()
try:
for key in pixel.F16_RSQ_EXP_PROGRAMS:
pixel.translate_f16(pixel.f16_rsq_exp_program(*key))
ops = ("rsq", "exp")
forms = {("VOP1", f"v_{op}_f16") for op in ops} | {("VOP3", f"v_{op}_f16_e64") for op in ops}
assert len(forms) == 4
neighbours = {
("VOP1", "v_log_f16"), ("VOP3", "v_log_f16_e64"),
("VOP1", "v_sin_f16"), ("VOP3", "v_cos_f16_e64"),
("DPP16", "v_rsq_f16_dpp"), ("DPP16", "v_exp_f16_dpp"),
("DPP8", "v_rsq_f16_dpp"), ("DPP8", "v_exp_f16_dpp"),
("SDWA", "v_rsq_f16_sdwa"), ("SDWA", "v_exp_f16_sdwa"),
}
for name in ("gfx1013.tsv", "rdna2.tsv"):
reference = fc.load_reference(name)
assert forms <= reference, (name, sorted(forms - reference))
assert neighbours <= reference, (name, sorted(neighbours - reference))
covered = fc.gfx_forms(pixel.ACCEPTED, reference)
assert forms <= covered, (name, sorted(forms - covered))
assert not neighbours & covered, (name, sorted(neighbours & covered))
# Without the rsq/exp fixtures none of the four forms is covered, not even through the other unary ones.
pixel.ACCEPTED.clear()
for body in pixel.F16_EXACT_EXTRA_PROGRAMS.values():
pixel.translate_f16(pixel.uncompressed_export(body))
assert not forms & fc.gfx_forms(pixel.ACCEPTED, fc.load_reference("gfx1013.tsv"))
finally:
pixel.ACCEPTED.clear()
pixel.ACCEPTED.update(saved)


def check_f16_fmac_ldexp_forms():
"""The two plain e32 binary16 forms v_fmac_f16 and v_ldexp_f16 count as covered once the translator accepts their
fixtures; their e64, DPP and SDWA spellings and the arithmetic they resemble stay uncovered."""
Expand Down Expand Up @@ -1803,6 +1840,7 @@ def check_f16_cvt_norm_forms():
check_f16_arith_forms()
check_f16_round_forms()
check_f16_rcp_sqrt_forms()
check_f16_rsq_exp_forms()
check_f16_fmac_ldexp_forms()
check_f16_cvt_int16_forms()
check_f16_to_int16_forms()
Expand Down
Loading
Loading