tests: evaluate the emitted run-time block of the 64-bit scalar shifts and s_bfe #2392
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2400"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from R0Y00/Xbox2Windows. Originally posted by Makto94 on 2026-11-25T15:15:17Z.
Refs #1723
Problem:
startup_gfx2hlsl_scalar_shift64_bfe_check.py(from #2088) checks the run-time block thatscalar_wide_opemits only by substring (runtime_blocks) and evaluates the helper functions on their own. Nothing executes the emitted block itself, so the order of the two destination words, the SCC expression and the signed flag ofbfe32/bfe64are unchecked. Operands that are only partly known at translation time (one constant word, or a constant source with an unknown amount), and uniformity of the result and SCC for each unknown operand, are not covered either.What this adds (tests only, one file, no change to
tools/):runtime_semantics(): parses the emitted{ uint2? t = helper(...); sN = t.x; ... scc = ...; }block for unknown operands, evaluates it with the helpers translated to Python, and compares both destination registers and SCC withreference(). Thes_bfe_i32rows include x=1, amount=2<<16 (result 1, so at > 1uSCC is caught).partly_known(): with one known word, one unknown word, or a known source and unknown amount, the translator must emit the helper call and must not fold. It then runs the emitted block with concrete values for the unknown registers and compares result and SCC withreference(). It also checks that a destination register that held a constant no longer has a symbol after the block is emitted.varying_operand(): a varying low word, high word or amount makes the destination register(s) varying and SCC non-uniform.Mutants (applied to
tools/startup/gfx2hlsl.py, one at a time):scalar_wide_opt.x/t.ystoress_lshl_b64, x=1, amount=320x100000000runtime_semantics: block gave 0x1, reference 0x100000000(t.x | t.y) == 0us_lshl_b64, x=1, amount=32runtime_semantics: SCC False for result 0x100000000bfe32SCCt == 0us_bfe_i32, x=0xf0, amount=4|4<<160xffffffff, SCC trueruntime_semantics: SCC False for result 0xffffffffbfe32SCCt > 1us_bfe_i32, x=1, amount=2<<161, SCC trueruntime_semantics: SCC False for result 0x10 if signed else 1)s_bfe_i32, x=0xf0, amount=4|4<<160xffffffffruntime_semantics: block gave 0xf, reference 0xffffffffs_lshl_b64, amount register varyings20varyingvarying_operand:('s_lshl_b64', 9, {9})s_lshl_b64,s7varyings20/s21varyingvarying_operand:('s_lshl_b64', 7, {7})None not in known[:1](fold with an unknown high word)s_lshl_b64,s6known,s7unknownpartly_known:TypeError: unsupported operand type(s) for <<: 'NoneType' and 'int'(the mutant translator raises instead of emitting the helper call)s_lshl_b64,s6=1 (known),s7=2,s9=10x400000002partly_known: block gave 0x200000004, reference 0x400000002s_lshl_b64,s9=3 (known), x=0x2000000010x1000000008partly_known: block gave 0x400000002, reference 0x1000000008self.sym.pop(r, None)removed after emissions_lshl_b64withs20/s21previously constants20/s21partly_known:AssertionError: ('s_lshl_b64', {6: ('const', 1)}, ...)on the destination symbols left instage.symOn
origin/main(7092683a, whose onlygfx2hlsl.pychange sincea4f7a95caddss_ff1_i32_b32) the unchanged check passes for all eleven mutants. With this change all eleven fail.Command and result (Linux-compatible, Python only; the check is in the
python-linuxjob list in.github/workflows/windows.yml):Run on Windows 11 build 26300 with Python 3.12. No GPU, dxc or fxc involved. The registered CTest
startup_gfx2hlsl_scalar_shift64_bfe_controlsruns the same script.Scope and limits:
run_blockdepends on the text format of the emitted block: one line{ uint2 t = f(args); sN = ...; scc = ...; }(oruint t). A change of that format makesrun_blockfail its format assertion and the check must be updated with it.make_helpers), not compiled HLSL. This checks the emitted block's register and SCC wiring, not HLSL compilation.partly_known().tools/,CMakeLists.txtor docs.Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T15:39:03Z.
Six mutations against the helpers, all caught — this is the strongest test-only PR I have reviewed here
Baseline on this branch:
gfx2hlsl.pyshl64: dropsh &= 63u(shifts ≥ 64)shl64: drop the cross-word carry(hi << sb) | cy→(hi << sb)shl64/shr64u:sc = (32u - sb) & 31u→sc = sb(direction)shr64i:asuint(asint(hi) >> sb)→asuint(hi >> sb)(sign extension)shr64i: the sign fillasuint(asint(hi) >> 31u)→0ubfe64: dropmin(..., 64u - (s1 & 63u))(width clamp)What makes
run_block()worth the 106 lines is that it evaluates the emitted text, not a Python reimplementation of it: the mutation has to survive both the translator and the evaluator to pass, so a helper that is wrong in a way the reference model shares still gets caught. Thet.x/t.y→t[0]/t[1]rewriting inrun_blockis the part that makes that possible for theuint2returns, and it is the sort of glue that usually rots — worth a comment saying which helper shapes the regex accepts (uint2 t = f(...)anduint t = f(...), one trailing statement list, no loops or branches).Two things I would tighten
1. The six cases per helper are chosen, not enumerated over a boundary set. I can see
(1, 32),(0x8000000000000000, 63),(1, 1)and similar inrows, which is the right instinct — but the interesting shifts are exactly0, 1, 31, 32, 33, 63and the interesting values are0,1,0x80000000in the low word,0x80000000in the high word. If those are all present, ignore me; if they are sampled, the six mutations above passing does not tell you the boundary is covered, because each of my mutations breaks a whole class rather than one case.2.
eval(rhs, {'t': ...})on generated text is fine here and worth keeping safe. The text comes from our own translator, so the# noqa: S307is honest. The risk is the opposite direction:evalaccepts more than the emitter produces, so a future emitter change that produces something the reference cannot parse fails as aNameError/SyntaxErrorinside the check rather than as a clear message. A one-lineassertnaming the unrecognised right-hand side would save the next person the traceback.What I would not change
The docstring states the reference values come from the ISA rather than from the helper, which is the distinction that matters for a test of this shape; and printing the case count (
3498 helper cases) makes the CI log tell you whether the table shrank.AI-assisted; the six mutations and the baseline run were executed locally on Windows 11 build 26300.9974.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:12:58Z.
Review: COMMENTED
Review of head
95c31d22(tests only: +106 lines in tests/startup_gfx2hlsl_scalar_shift64_bfe_check.py).Checked:
startup_gfx2hlsl_scalar_shift64_bfe_controls. No production code changes.runtime_semantics()runs the emitted run-time block (helper call, result registers, SCC) for s_lshl_b64, s_lshr_b64, s_ashr_i64, s_bfe_i32, s_bfe_u64 and s_bfe_i64 and compares it withreference(). It also checks that the high register is not written for 32-bit results.partly_known()covers one known word, one unknown word, and a known source with an unknown amount. It checks that nothing is folded, that the block gives the reference result, and that a stale constant in the destination is dropped.varying_operand()checks that a varying low word, high word or amount makes the result and SCC varying.evalonly sees the generator's own output.Ran:
python3 -I tests/startup_gfx2hlsl_scalar_shift64_bfe_check.pygivesstartup scalar 64-bit shift and bitfield extract controls passed (3498 helper cases).No problems found. Small, additive.
AI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by KelboLive on 2026-11-25T16:07:54Z.
APPROVED. Tests run-time block for 64-bit scalar shifts and s_bfe.
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T16:14:50Z.
Win2025 WARP receipt for head
95c31d22after updating with main.Verified on Windows Server 2025 (Build 26100, MSVC 14.44.35207 + D3D12 WARP) at commit
95c31d22b77550a5c2c0c73a25aad136d1e0a37a:--preset dev):cmake --build --preset dev -- -j 2):0.00s(configure0.00s)ctest --preset dev -R 'startup_gfx2hlsl_scalar_shift64_bfe_controls' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.31s:startup_gfx2hlsl_scalar_shift64_bfe_controls0.19s)/O2(--preset release):cmake --build --preset release -- -j 2):0.00s(configure0.00s)ctest --preset release -R 'startup_gfx2hlsl_scalar_shift64_bfe_controls' --parallel 4 --no-tests=error --output-on-failure): 1/1 passed (0.31s:startup_gfx2hlsl_scalar_shift64_bfe_controls0.19s)5.3sAI-assisted; commands listed were executed locally.
Imported from R0Y00/Xbox2Windows. Originally posted by MasterDomino on 2026-11-25T17:14:21Z.
Review: APPROVED
Approved at head
95c31d22. The change is test-only: +106 lines intests/startup_gfx2hlsl_scalar_shift64_bfe_check.py. This adds a local mutation run to @tedin7's and @ChazY11's reviews.Commands executed (Windows 11 build 26300, Python 3.13; no GPU needed)
95c31d22:startup scalar 64-bit shift and bitfield extract controls passed (3498 helper cases), exit 0.main(f59f7761plus this PR): same result, and the merge is clean.Negative control
I applied five of the description's mutants to
scalar_wide_opintools/startup/gfx2hlsl.py, one at a time, then reverted each. Each ran againstmain's copy of the check and against this PR's:maincheckt.x/t.ystores swappeds_lshl_b64 0x1,0x20: block gave 0x1, reference 0x100000000== 0uSCC False for result 0x100000000bfesigned flag inverteds_bfe_i32 0xf0,0x40004: block gave 0xf, reference 0xffffffffknown[:1])TypeErrorfrom the mutated foldself.sym.pop(r, None)removedThe results match the table in the description.
Merge checks: CI passed at this head ("Build and test on Windows" and both Linux jobs). The
/O2and coverage skips come from explicit workflow conditions. There are no unresolved review threads.AI-assisted; commands listed were executed locally.