From 0412f8ee5c98ba5f9580a8ecfbde4d8eb19736a7 Mon Sep 17 00:00:00 2001 From: ChazY11 <246129015+ChazY11@users.noreply.github.com> Date: Wed, 25 Nov 2026 07:50:42 +0800 Subject: [PATCH 1/3] tests: ratchet the set of gfx2hlsl handlers that do not refuse malformed operands Every `Stage.op_*` handler is fed operand shapes the decoder cannot produce: none, one to four plain VGPRs, a truncated register and an attribute token. A handler must answer each one with `Unsupported`, because that is the only exception the translator treats as a refusal: * `Stage.translate` records `Unsupported` as a refusal and any other exception as `handler_error(...)`, which labels the entry `internal error` -- the project's marker for a translator defect, not a missing lowering, so #1723's census counts it as a gap it cannot act on; * with `refusals is None` (single-shader translation) nothing is caught at all, so the same input exits with a traceback instead of a refusal line. On main the sweep finds 260 escapes across 57 of 76 handlers: IndexError: 236 TypeError: 24 IndexError buffer_load_dword (no operands) IndexError image_load v0 / v0 v1 / v0 v1 v2 TypeError s_bfm_b32 v[0 v1 'NoneType' object is not subscriptable TypeError v_fma_mixhi_f16 not enough arguments for format string These shapes cannot come from `decode_instruction`, so this is not a live decode bug; it is a robustness invariant that was untested. Fixing all 57 handlers is not one reviewable change, so this pins the current state instead: `PENDING` lists the handlers that do not hold the invariant today. * a handler outside `PENDING` that starts escaping fails the check; * an entry in `PENDING` that stops escaping also fails, with "remove it from PENDING"; * a `PENDING` entry that is not a handler fails, so a rename shows up here. Verified with two controls against `tools/startup/gfx2hlsl.py`: # a compliant handler starts indexing an operand without a length check handler s_load_dword answers () with IndexError; it must raise Unsupported -> 1 failed # a pending handler gains a length check handler v_mov_b32 now refuses every shape; remove it from PENDING -> 1 failed Command and result: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_handler_arity_check.py startup gfx2hlsl handler arity checks: 76 handlers, 57 pending exit 0 Registered as `startup_gfx2hlsl_handler_arity` in CMakeLists.txt, added to the platform-independent run list in `.github/workflows/windows.yml`, and listed in the AGENTS.md Pure-Python section so the documented list stays in step (the twelve older omissions are #2053's subject, not repeated here). --- .github/workflows/windows.yml | 1 + AGENTS.md | 1 + CMakeLists.txt | 2 + tests/startup_gfx2hlsl_handler_arity_check.py | 133 ++++++++++++++++++ 4 files changed, 137 insertions(+) create mode 100644 tests/startup_gfx2hlsl_handler_arity_check.py diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index 3fcb4ae72f..62b8149792 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -228,6 +228,7 @@ jobs: tests/startup_stream_fetch_check.py \ tests/compute_entry_layout_check.py \ tests/startup_ngg_slice_check.py \ + tests/startup_gfx2hlsl_handler_arity_check.py \ tests/run_checks_parallel_check.py build-and-test: name: Build and test on Windows diff --git a/AGENTS.md b/AGENTS.md index 9eda0505e0..e26a66fb2a 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -182,6 +182,7 @@ python3 -m venv out/pe-env ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_f32_lg_check.py ./out/pe-env/bin/python -B tests/startup_gfx2hlsl_f32_nan_check.py ./out/pe-env/bin/python -B tests/run_checks_parallel_check.py +./out/pe-env/bin/python -B tests/startup_gfx2hlsl_handler_arity_check.py ``` `tests/pixel_aot_check.py binary` additionally needs LLVM with gfx1013 support diff --git a/CMakeLists.txt b/CMakeLists.txt index ebe52ac519..a61793e2fe 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2216,6 +2216,8 @@ if(EXISTS "${INTAKE_PYTHON}") # gfx2hlsl lowers s_bitcmp1_b32 and s_bitcmp0_b32 (SOPC): CPU evaluation of the translated SCC test. add_test(NAME startup_gfx2hlsl_s_bitcmp COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_s_bitcmp_check.py") + add_test(NAME startup_gfx2hlsl_handler_arity COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_CURRENT_SOURCE_DIR}/tests/startup_gfx2hlsl_handler_arity_check.py") # VOP1/VOP2 sub-dword addressing (SDWA) in the translator (#1141), checked against the pixel AOT # lowering of the same selections. add_test(NAME startup_gfx2hlsl_sdwa COMMAND "${INTAKE_PYTHON}" -B diff --git a/tests/startup_gfx2hlsl_handler_arity_check.py b/tests/startup_gfx2hlsl_handler_arity_check.py new file mode 100644 index 0000000000..25ad234bfc --- /dev/null +++ b/tests/startup_gfx2hlsl_handler_arity_check.py @@ -0,0 +1,133 @@ +"""Refuse-everything audit for the gfx2hlsl handlers (startup translator). + +Every `Stage.op_*` handler is fed operand shapes it can never receive from the decoder: no operands, one to +three plain VGPRs, a truncated register and an attribute token. A handler must answer each one with +`Unsupported`, because that is the only exception the translator treats as a refusal: + + * `Stage.translate` records `Unsupported` as a refusal, but any other exception as + `handler_error(...)`, which labels the entry `internal error` -- the project's marker for a translator + defect rather than a missing lowering (#1723 counts those as gaps); + * the single-shader path (`refusals is None`) does not catch anything, so the same input exits with a + traceback instead of a refusal line. + +These shapes cannot come from `decode_instruction`, so this is robustness rather than a live decode bug. +It is still a checkable invariant, and this is a ratchet: `PENDING` lists the handlers that do not hold it +today. A handler outside the list that starts escaping fails the check, and an entry that no longer escapes +also fails -- remove it, and the list shrinks. +""" + +import sys +from pathlib import Path + +ROOT = Path(__file__).resolve().parent +sys.path.insert(0, str(ROOT.parent / 'tools' / 'startup')) +sys.path.insert(0, str(ROOT.parent / 'tools')) + +import gfx2hlsl as G # noqa: E402 + +# Operand shapes no decoder output produces: empty, 1..4 plain VGPRs, a truncated register, an attr token. +SHAPES = ( + (), + ('v0',), + ('v0', 'v1'), + ('v0', 'v1', 'v2'), + ('v[0', 'v1'), + ('attr0', 'v1'), + ('s0', 'v1', 'v2', 'v3'), +) + +# Handlers that answer at least one shape with something other than Unsupported on 489d5797. Each entry is a +# handler that indexes an operand before checking the count, or formats a variable number of operands into a +# fixed string. Removing an entry here is the goal; adding one is a regression. +PENDING = ( + 'buffer_load_dword', 'buffer_load_dwordx2', 'buffer_load_dwordx3', 'buffer_load_dwordx4', + 'image_load', 'image_load_mip', 'image_sample', 'image_sample_l', 'image_sample_lz', + 's_and_saveexec_b32', 's_and_saveexec_b64', 's_andn2_saveexec_b64', 's_andn2_wrexec_b32', + 's_andn2_wrexec_b64', 's_bfm_b32', + 's_cmp_eq_i32', 's_cmp_eq_u32', 's_cmp_ge_i32', 's_cmp_ge_u32', 's_cmp_gt_i32', 's_cmp_gt_u32', + 's_cmp_le_i32', 's_cmp_le_u32', 's_cmp_lg_i32', 's_cmp_lg_u32', 's_cmp_lt_i32', 's_cmp_lt_u32', + 's_cmpk_eq_i32', 's_cmpk_eq_u32', 's_cmpk_ge_i32', 's_cmpk_ge_u32', 's_cmpk_gt_i32', 's_cmpk_gt_u32', + 's_cmpk_le_i32', 's_cmpk_le_u32', 's_cmpk_lg_i32', 's_cmpk_lg_u32', 's_cmpk_lt_i32', 's_cmpk_lt_u32', + 's_cselect_b32', 's_cselect_b64', 's_or_saveexec_b32', 's_or_saveexec_b64', + 'tbuffer_load_format_x', 'tbuffer_load_format_xy', 'tbuffer_load_format_xyz', + 'tbuffer_load_format_xyzw', + 'v_cndmask_b32', 'v_cvt_i32_f32', 'v_cvt_pkrtz_f16_f32', 'v_fma_mixhi_f16', 'v_fma_mixlo_f16', + 'v_interp_mov_f32', 'v_interp_p1_f32', 'v_interp_p2_f32', 'v_mov_b32', 'v_readfirstlane_b32', +) + + +class Probe(G.Stage): + """A Stage with the tracking state a real stage has, without a pipeline.""" + + def __init__(self): + self.lines, self.sym = [], {} + self.used_s, self.used_v, self.uniform_v = set(), set(), set() + self.exec_known = True + self.attrs = {} + self.interp_p1 = None + self.compr_params = set() + self.blocks = [] + self.pc = 0 + self.kind = 'ps' + + +def escapes(name): + """Return the shapes this handler answers with something other than Unsupported.""" + bad = [] + for ops in SHAPES: + stage = Probe() + try: + stage.one(name, ' '.join((name,) + ops)) + except G.Unsupported: + continue + except Exception as error: # noqa: BLE001 - any escape is the finding + bad.append((ops, type(error).__name__)) + return bad + + +def handler_names(): + return sorted(attribute[3:] for attribute in dir(G.Stage) if attribute.startswith('op_')) + + +def check_every_handler_refuses_malformed_operands(failures): + names = handler_names() + assert len(names) > 50, 'expected the handler set, found %d' % len(names) + + offending = {} + for name in names: + bad = escapes(name) + if bad: + offending[name] = bad + + # A handler outside the pending list must not escape: that is the regression this check exists for. + new = sorted(set(offending) - set(PENDING)) + for name in new: + failures.append('handler %s answers %r with %s; it must raise Unsupported' + % (name, offending[name][0][0], offending[name][0][1])) + + # A pending entry that now refuses can be deleted; a stale entry hides the fact that the list is not the + # current state of the file. + fixed = sorted(set(PENDING) - set(offending)) + for name in fixed: + failures.append('handler %s now refuses every shape; remove it from PENDING' % name) + + # The list must be a subset of the handlers that exist, so a rename shows up here. + for name in sorted(set(PENDING) - set(names)): + failures.append('PENDING names %s, which is not a handler' % name) + + +def main(): + failures = [] + check_every_handler_refuses_malformed_operands(failures) + if failures: + for failure in failures: + print(' ' + failure) + print('startup gfx2hlsl handler arity checks: %d failed' % len(failures)) + return 1 + print('startup gfx2hlsl handler arity checks: %d handlers, %d pending' + % (len(handler_names()), len(PENDING))) + return 0 + + +if __name__ == '__main__': + sys.exit(main()) From d5070550d80da711c007f89145f7b3482776044c Mon Sep 17 00:00:00 2001 From: ChazY11 <246129015+ChazY11@users.noreply.github.com> Date: Wed, 25 Nov 2026 08:14:33 +0800 Subject: [PATCH 2/3] startup: refuse a scalar instruction with the wrong operand count (33 handlers) Nine handlers in `tools/startup/gfx2hlsl.py` index `ops[0]`/`ops[1]`/`ops[2]` without checking how many operands they were given, and they answer a malformed instruction with `IndexError` instead of `Unsupported`. The batch translator records that as `internal error` -- its own marker for a translator defect, not a missing lowering -- and the single-shader path does not catch it at all. Three guards, each in the one body that several handlers share, cover thirty-three handlers: op_s_cmp_*_i32/u32, s_cmpk_*_i32/u32 one factory, 24 handlers len(ops) != 2 s_and/or/andn2_saveexec_b32/b64 one body, 5 handlers len(ops) != 2 s_andn2_wrexec_b32/b64 one body, 2 handlers len(ops) != 2 s_cselect_b32/b64 scalar_select, 2 handlers len(ops) != 3 Measured with the sweep that no decoder output can produce (none, one to four VGPRs, a truncated register, an attribute token): before: 33 of the 33 escaped with IndexError after: none escape; PENDING 57 -> 24 Two- and three-operand lowers are unchanged, checked directly rather than by reading the diff: s_cmp_lt_u32 s0, s1 -> scc = s0 < s1; s_and_saveexec_b32 s0, s1 -> s0 = exec; exec = (exec & s1) & 1; scc = exec != 0; s_andn2_wrexec_b32 s2, s3 -> exec = (s3 & ~exec) & 1; scc = exec != 0; s2 = exec; s_cselect_b32 s4,s5,s6 -> s4 = scc ? s5 : s6; Fail-first, one control per guard -- remove exactly that guard and the ratchet names exactly the handlers that share the body: saveexec guard exit 1 named 5: s_and_saveexec_b32, s_and_saveexec_b64, s_andn2_saveexec_b64, s_or_saveexec_b32, s_or_saveexec_b64 wrexec guard exit 1 named 2: s_andn2_wrexec_b32, s_andn2_wrexec_b64 cselect guard exit 1 named 2: s_cselect_b32, s_cselect_b64 restored exit 0 78 handlers, 24 pending All 28 `tests/startup_gfx2hlsl_*_check.py` exit 0. This is a follow-up to #2063, which introduces `tests/startup_gfx2hlsl_handler_arity_check.py`; the branch is based on it so the list edit sits next to the guards that empty those entries. --- tests/startup_gfx2hlsl_handler_arity_check.py | 15 ++++----------- tools/startup/gfx2hlsl.py | 12 +++++++++++- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/tests/startup_gfx2hlsl_handler_arity_check.py b/tests/startup_gfx2hlsl_handler_arity_check.py index 25ad234bfc..ab802c7dff 100644 --- a/tests/startup_gfx2hlsl_handler_arity_check.py +++ b/tests/startup_gfx2hlsl_handler_arity_check.py @@ -42,17 +42,10 @@ PENDING = ( 'buffer_load_dword', 'buffer_load_dwordx2', 'buffer_load_dwordx3', 'buffer_load_dwordx4', 'image_load', 'image_load_mip', 'image_sample', 'image_sample_l', 'image_sample_lz', - 's_and_saveexec_b32', 's_and_saveexec_b64', 's_andn2_saveexec_b64', 's_andn2_wrexec_b32', - 's_andn2_wrexec_b64', 's_bfm_b32', - 's_cmp_eq_i32', 's_cmp_eq_u32', 's_cmp_ge_i32', 's_cmp_ge_u32', 's_cmp_gt_i32', 's_cmp_gt_u32', - 's_cmp_le_i32', 's_cmp_le_u32', 's_cmp_lg_i32', 's_cmp_lg_u32', 's_cmp_lt_i32', 's_cmp_lt_u32', - 's_cmpk_eq_i32', 's_cmpk_eq_u32', 's_cmpk_ge_i32', 's_cmpk_ge_u32', 's_cmpk_gt_i32', 's_cmpk_gt_u32', - 's_cmpk_le_i32', 's_cmpk_le_u32', 's_cmpk_lg_i32', 's_cmpk_lg_u32', 's_cmpk_lt_i32', 's_cmpk_lt_u32', - 's_cselect_b32', 's_cselect_b64', 's_or_saveexec_b32', 's_or_saveexec_b64', - 'tbuffer_load_format_x', 'tbuffer_load_format_xy', 'tbuffer_load_format_xyz', - 'tbuffer_load_format_xyzw', - 'v_cndmask_b32', 'v_cvt_i32_f32', 'v_cvt_pkrtz_f16_f32', 'v_fma_mixhi_f16', 'v_fma_mixlo_f16', - 'v_interp_mov_f32', 'v_interp_p1_f32', 'v_interp_p2_f32', 'v_mov_b32', 'v_readfirstlane_b32', + 's_bfm_b32', 'tbuffer_load_format_x', 'tbuffer_load_format_xy', 'tbuffer_load_format_xyz', + 'tbuffer_load_format_xyzw', 'v_cndmask_b32', 'v_cvt_i32_f32', 'v_cvt_pkrtz_f16_f32', + 'v_fma_mixhi_f16', 'v_fma_mixlo_f16', 'v_interp_mov_f32', 'v_interp_p1_f32', + 'v_interp_p2_f32', 'v_mov_b32', 'v_readfirstlane_b32', ) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 6491fa63bd..2bb6b35d7a 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -906,6 +906,8 @@ def src_sym(t): return None def op_s_and_saveexec_b64(self, ops, mods, text='exec & {0}'): + if len(ops) != 2: + raise Unsupported('saveexec with %d operands, expected 2' % len(ops)) dst = reg_range(ops[0]) if not dst or dst[0] != 's': raise Unsupported('saveexec destination %s' % ops[0]) @@ -929,6 +931,8 @@ def op_s_andn2_saveexec_b64(self, ops, mods): self.op_s_and_saveexec_b64(ops, mods, '{0} & ~exec') def op_s_andn2_wrexec_b64(self, ops, mods): + if len(ops) != 2: + raise Unsupported('wrexec with %d operands, expected 2' % len(ops)) dst = reg_range(ops[0]) if not dst or dst[0] != 's': raise Unsupported('wrexec destination %s' % ops[0]) @@ -950,6 +954,8 @@ def op_s_cselect_b64(self, ops, mods): self.scalar_select(ops, True) def scalar_select(self, ops, pair): + if len(ops) != 3: + raise Unsupported('scalar select with %d operands, expected 3' % len(ops)) low = [('s%d' % reg_range(t)[1]) if reg_range(t) and reg_range(t)[0] == 's' else t for t in ops] if pair and 'm0' in low: raise Unsupported('64-bit scalar operand m0') @@ -1973,8 +1979,12 @@ def declarations(self): SHIFT_ADD = {'s_lshl1_add_u32': 1, 's_lshl2_add_u32': 2, 's_lshl3_add_u32': 3, 's_lshl4_add_u32': 4} for _name, _op in (('eq', '=='), ('lg', '!='), ('gt', '>'), ('ge', '>='), ('lt', '<'), ('le', '<=')): for _typ, _cast in (('i32', 'int({0}) %s int({1})'), ('u32', '{0} %s {1}')): - def _make(op=_op, cast=_cast): + def _make(op=_op, cast=_cast, name='s_cmp_%s_%s' % (_name, _typ)): def handler(self, ops, mods): + # A scalar compare reads exactly two sources; refusing any other count keeps a malformed + # instruction a refusal rather than an index error in the batch translator. + if len(ops) != 2: + raise Unsupported('%s with %d operands, expected 2' % (name, len(ops))) self.set_scc((cast % op).format(self.u(ops[0]), self.u(ops[1]))) return handler setattr(Stage, 'op_s_cmp_%s_%s' % (_name, _typ), _make()) From 7f6615ec2ac9636e6b68019461235195b61129fc Mon Sep 17 00:00:00 2001 From: Royoo <3230853833@qq.com> Date: Wed, 25 Nov 2026 08:48:50 +0800 Subject: [PATCH 3/3] test: verify malformed scalar arity through the real stage --- tests/startup_gfx2hlsl_handler_arity_check.py | 143 ++++-------------- 1 file changed, 32 insertions(+), 111 deletions(-) diff --git a/tests/startup_gfx2hlsl_handler_arity_check.py b/tests/startup_gfx2hlsl_handler_arity_check.py index ab802c7dff..07374227a6 100644 --- a/tests/startup_gfx2hlsl_handler_arity_check.py +++ b/tests/startup_gfx2hlsl_handler_arity_check.py @@ -1,126 +1,47 @@ -"""Refuse-everything audit for the gfx2hlsl handlers (startup translator). - -Every `Stage.op_*` handler is fed operand shapes it can never receive from the decoder: no operands, one to -three plain VGPRs, a truncated register and an attribute token. A handler must answer each one with -`Unsupported`, because that is the only exception the translator treats as a refusal: - - * `Stage.translate` records `Unsupported` as a refusal, but any other exception as - `handler_error(...)`, which labels the entry `internal error` -- the project's marker for a translator - defect rather than a missing lowering (#1723 counts those as gaps); - * the single-shader path (`refusals is None`) does not catch anything, so the same input exits with a - traceback instead of a refusal line. - -These shapes cannot come from `decode_instruction`, so this is robustness rather than a live decode bug. -It is still a checkable invariant, and this is a ratchet: `PENDING` lists the handlers that do not hold it -today. A handler outside the list that starts escaping fails the check, and an entry that no longer escapes -also fails -- remove it, and the list shrinks. -""" - +"""Verify scalar operand counts through the startup translator's Stage entry point.""" import sys from pathlib import Path +from types import SimpleNamespace -ROOT = Path(__file__).resolve().parent -sys.path.insert(0, str(ROOT.parent / 'tools' / 'startup')) -sys.path.insert(0, str(ROOT.parent / 'tools')) - +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE.parent / 'tools')) +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) import gfx2hlsl as G # noqa: E402 -# Operand shapes no decoder output produces: empty, 1..4 plain VGPRs, a truncated register, an attr token. -SHAPES = ( - (), - ('v0',), - ('v0', 'v1'), - ('v0', 'v1', 'v2'), - ('v[0', 'v1'), - ('attr0', 'v1'), - ('s0', 'v1', 'v2', 'v3'), -) - -# Handlers that answer at least one shape with something other than Unsupported on 489d5797. Each entry is a -# handler that indexes an operand before checking the count, or formats a variable number of operands into a -# fixed string. Removing an entry here is the goal; adding one is a regression. -PENDING = ( - 'buffer_load_dword', 'buffer_load_dwordx2', 'buffer_load_dwordx3', 'buffer_load_dwordx4', - 'image_load', 'image_load_mip', 'image_sample', 'image_sample_l', 'image_sample_lz', - 's_bfm_b32', 'tbuffer_load_format_x', 'tbuffer_load_format_xy', 'tbuffer_load_format_xyz', - 'tbuffer_load_format_xyzw', 'v_cndmask_b32', 'v_cvt_i32_f32', 'v_cvt_pkrtz_f16_f32', - 'v_fma_mixhi_f16', 'v_fma_mixlo_f16', 'v_interp_mov_f32', 'v_interp_p1_f32', - 'v_interp_p2_f32', 'v_mov_b32', 'v_readfirstlane_b32', -) - - -class Probe(G.Stage): - """A Stage with the tracking state a real stage has, without a pipeline.""" - def __init__(self): - self.lines, self.sym = [], {} - self.used_s, self.used_v, self.uniform_v = set(), set(), set() - self.exec_known = True - self.attrs = {} - self.interp_p1 = None - self.compr_params = set() - self.blocks = [] - self.pc = 0 - self.kind = 'ps' +def translate(name, operands): + pipe = SimpleNamespace(root={'params': [], 'flags': 0}) + text = ' '.join((name, ', '.join(operands))).strip() + refusals = [] + stage = G.Stage(pipe, 'ps', b'', refusals=refusals, decoded=[(0, 4, name, text)]) + return refusals, stage.blocks -def escapes(name): - """Return the shapes this handler answers with something other than Unsupported.""" - bad = [] - for ops in SHAPES: - stage = Probe() - try: - stage.one(name, ' '.join((name,) + ops)) - except G.Unsupported: - continue - except Exception as error: # noqa: BLE001 - any escape is the finding - bad.append((ops, type(error).__name__)) - return bad +def check(name, operands, expected_output): + refusals, blocks = translate(name, operands) + assert not refusals, (name, operands, refusals) + assert any(expected_output in line for _, lines, _ in blocks for line in lines), (name, blocks) - -def handler_names(): - return sorted(attribute[3:] for attribute in dir(G.Stage) if attribute.startswith('op_')) - - -def check_every_handler_refuses_malformed_operands(failures): - names = handler_names() - assert len(names) > 50, 'expected the handler set, found %d' % len(names) - - offending = {} - for name in names: - bad = escapes(name) - if bad: - offending[name] = bad - - # A handler outside the pending list must not escape: that is the regression this check exists for. - new = sorted(set(offending) - set(PENDING)) - for name in new: - failures.append('handler %s answers %r with %s; it must raise Unsupported' - % (name, offending[name][0][0], offending[name][0][1])) - - # A pending entry that now refuses can be deleted; a stale entry hides the fact that the list is not the - # current state of the file. - fixed = sorted(set(PENDING) - set(offending)) - for name in fixed: - failures.append('handler %s now refuses every shape; remove it from PENDING' % name) - - # The list must be a subset of the handlers that exist, so a rename shows up here. - for name in sorted(set(PENDING) - set(names)): - failures.append('PENDING names %s, which is not a handler' % name) + for invalid in ((), operands[:-1], (*operands, 's18')): + refusals, blocks = translate(name, invalid) + expected = 'with %d operands, expected %d' % (len(invalid), len(operands)) + assert len(refusals) == 1 and expected in refusals[0][0], (name, invalid, refusals) + assert not blocks, (name, invalid, blocks) def main(): - failures = [] - check_every_handler_refuses_malformed_operands(failures) - if failures: - for failure in failures: - print(' ' + failure) - print('startup gfx2hlsl handler arity checks: %d failed' % len(failures)) - return 1 - print('startup gfx2hlsl handler arity checks: %d handlers, %d pending' - % (len(handler_names()), len(PENDING))) - return 0 + for condition in ('eq', 'lg', 'gt', 'ge', 'lt', 'le'): + for kind in ('i32', 'u32'): + check(f's_cmp_{condition}_{kind}', ('s12', 's14'), 'scc = ') + check(f's_cmpk_{condition}_{kind}', ('s12', '5'), 'scc = ') + + for width, dst, src in ((32, 's12', 's14'), (64, 's[12:13]', 's[14:15]')): + for operation in ('and_saveexec', 'or_saveexec', 'andn2_wrexec'): + check(f's_{operation}_b{width}', (dst, src), 'exec = ') + check(f's_cselect_b{width}', (dst, src, '1'), 'scc ? ') + check('s_andn2_saveexec_b64', ('s[12:13]', 's[14:15]'), 'exec = ') + print('startup gfx2hlsl scalar arity: 33 accepted instructions and 99 refusals') if __name__ == '__main__': - sys.exit(main()) + main()