startup: refuse a binary32 vector operation with the wrong operand count #1709
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1716"
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 Asimmimx on 2026-11-24T17:39:30Z.
Refs #1149.
Change
tools/startup/gfx2hlsl.pychecks the operand count of its integer vector table (VEC_U), but not of its binary32 table (VEC_F). Onorigin/main:v_add_f32 v1, v2(one source short)IndexError: Replacement index 1 out of rangefromstr.format, notUnsupportedv_med3_f32 v1, v2, v3, v4, v5(one source too many)med3(v2, v3, v4); the extra source is droppedVEC_Fnow refuses any count other than its sources plus the destination, with the same message asVEC_U. This is a 3-line change inStage.one.I found this while drawing the
VEC_Foperations in #1712.Test
tests/startup_gfx2hlsl_operand_count_check.py(startup_gfx2hlsl_operand_count) is pure Python. It checks:VEC_F, 41VEC_U) with one source fewer, the exact count and one source more, expectingrefused,okandrefused;v_fmac_f32,v_mac_f32_e64,v_fmamk_f32,v_fmaak_f32,v_madmk_f32,v_madak_f32,v_rcp_f32_e64 ... clamp, andv_med3_f32with an inline constant;IndexErrorand the accepted long form to come back.It is added to the platform-independent Python job and the list in
AGENTS.md.docs/experiments.mdgets one paragraph under the per-lane bit operations section, which describes theVEC_Urule.Results
Commit
17866fd4onorigin/main, Python 3.12, Windows 11 26300.9974:Without the translator change, the same file reports
2 failed(theVEC_Ftable check and the guard control) and exits 1.These also still pass:
startup_gfx2hlsl_bit_alu_check.py,startup_translator_check.py,startup_gfx2hlsl_sdwa_check.py,startup_flat_param_check.py,startup_gfx2hlsl_smem_offset_check.py,startup_inline_sampler_check.py,startup_image_sample_c_check.py,docs_links_check.pyandbidi_controls_check.py.AI-assisted (Claude Code).
Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-24T17:46:19Z.
Review: COMMENTED
Peer review at
head_sha:17866fd4f5d1119fb6bb3b980590766f6a286f1fVerdict: 0 P1, 0 P2.
Scope (full diff read)
tools/startup/gfx2hlsl.py(+3): inStage.one, theVEC_Fbranch now refuses a form whose operand count is notarity + 1withUnsupported('<op> with N operands, expected M'), the same ruleVEC_Ualready has.tests/startup_gfx2hlsl_operand_count_check.py, registered inCMakeLists.txt(startup_gfx2hlsl_operand_count, inside theINTAKE_PYTHONblock next to its neighbours), listed inAGENTS.mdand in the Linux checks of.github/workflows/windows.yml(one line, betweenstartup_image_load_mip_check.pyandstartup_image_2d_array_check.py; no other workflow change).docs/experiments.mdgets one paragraph that matches the code.git merge-treeagainst currentmain(eaa2024b): no conflicts. It also merges cleanly with #1712.What I checked
v_fmac_f32/v_mac_f32(2 sources + the destination as accumulator),v_fmamk/fmaak/madmk/madak(3) all still translate, andv_rcp_f32_e64 ... clampandv_med3_f32 ... 1.0 ...too (the PR's own check asserts this).startup_gfx2hlsl_capture_check,startup_gfx2hlsl_sdwa_check,startup_gfx2hlsl_smem_offset_check,startup_translator_checkandstartup_gfx2hlsl_bit_alu_checkall still exit 0 on this head.llvm-mc-19 -mcpu=gfx1030agrees with the rule:v_add_f32 v1, v2-> "too few operands for instruction",v_med3_f32 v1, v2, v3, v4, v5-> "invalid operand for instruction"; the exact-count forms (v_add_f32,v_med3_f32,v_fmamk_f32,v_fmaak_f32,v_rcp_f32_e64 ... clamp) assemble.VEC_F, 41VEC_U) with one source fewer, the exact count and one more, and it loads a copy of the translator with the guard removed to show that the oldIndexErrorand the silently dropped extra source come back.Findings
v_mac_f32_e64 v1, v2, v3is not a gfx1030 instruction (llvm-mc-19says "instruction not supported on this GPU"). It is only a translator-level example, so nothing breaks, butv_fmac_f32_e64would be the form real code contains.Verified
Limits: Linux x86-64 only. No Windows run, no D3D12.
python3 -B tests/startup_gfx2hlsl_operand_count_check.py-> "operand count checks: 0 failed", exit 0.python3 -B tests/docs_links_check.py-> 17 files, 364 links OK.git diff --check HEAD^ HEADclean.VEC_Fguard condition!=-><(only a short form refused): exit 1,VEC_F: ... MISMATCH [('v_add_f32', ['refused', 'ok', 'ok']), ...].VEC_Fguard replaced byif False:: exit 1,VEC_F: ... MISMATCH [('v_add_f32', ['IndexError', 'ok', 'ok']), ...].VEC_FandVEC_U) to>,<and!= arity + 2: each exits 1 with the table mismatches for both tables.git checkout -- .;git status --shortclean.AI-assisted; commands listed were executed locally.