From a60128b49e07fec7257912b0829a8256a5c96a90 Mon Sep 17 00:00:00 2001 From: R0D4X Date: Tue, 24 Nov 2026 19:04:09 +0100 Subject: [PATCH 1/5] startup: lower v_mul_hi_u32 in gfx2hlsl --- .github/workflows/windows.yml | 2 + CMakeLists.txt | 9 + tests/startup_gfx2hlsl_mul_hi_check.py | 220 +++++++++++++++++++++++++ tools/startup/gfx2hlsl.py | 4 +- 4 files changed, 234 insertions(+), 1 deletion(-) create mode 100644 tests/startup_gfx2hlsl_mul_hi_check.py diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index c135fb9747..c102283309 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -117,6 +117,7 @@ jobs: (["tests/startup_gfx2hlsl_f32_nan_check.py", "decode", "libLLVM-15.so.1"], {}), (["tests/startup_gfx2hlsl_f32_sdwa_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_f32_sdwa_check.py", "decode", "libLLVM-15.so.1"], {}), + (["tests/startup_gfx2hlsl_mul_hi_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_inline_sampler_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_smem_address_check.py", "binary", "llvm-mc-15"], {}), (["tests/compute_entry_layout_check.py", "binary", "llvm-mc-15"], {}), @@ -246,6 +247,7 @@ jobs: tests/startup_gfx2hlsl_f32_sdwa_check.py \ tests/startup_gfx2hlsl_root_check.py \ tests/startup_gfx2hlsl_sopk_signext_check.py \ + tests/startup_gfx2hlsl_mul_hi_check.py \ tests/startup_inline_sampler_check.py \ tests/startup_buffer_address_check.py \ tests/startup_smem_address_check.py \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 085338a5d8..d906e27ce2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3146,6 +3146,15 @@ if(EXISTS "${INTAKE_PYTHON}") set_tests_properties(startup_small_texture_4k_xg startup_small_texture_4k_xg_no_limit_control PROPERTIES TIMEOUT 30 ENVIRONMENT "X2W_D3D12_PERMISSIVE=1") set_tests_properties(startup_small_texture_4k_xg_no_limit_control PROPERTIES WILL_FAIL TRUE) + # gfx2hlsl v_mul_hi_u32 (#870): CPU helper evaluation, refusal and mutation controls, then desktop draw (FXC 5_1 and DXC 6_0). + add_test(NAME startup_gfx2hlsl_mul_hi_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mul_hi_check.py") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_gfx2hlsl_mul_hi_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mul_hi_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(startup_gfx2hlsl_mul_hi_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() add_test(NAME startup_xg_bc_tiling COMMAND "${INTAKE_PYTHON}" -B "${CMAKE_SOURCE_DIR}/tests/startup_xg_bc_tiling_check.py" "$") set_tests_properties(startup_xg_bc_tiling PROPERTIES TIMEOUT 30 ENVIRONMENT "X2W_D3D12_PERMISSIVE=1") diff --git a/tests/startup_gfx2hlsl_mul_hi_check.py b/tests/startup_gfx2hlsl_mul_hi_check.py new file mode 100644 index 0000000000..b5d6a411dd --- /dev/null +++ b/tests/startup_gfx2hlsl_mul_hi_check.py @@ -0,0 +1,220 @@ +"""Unsigned 32x32->high-32 vector multiply (v_mul_hi_u32) in tools/startup/gfx2hlsl.py (Refs #870). + + (no arguments) translation, helper-math, refusal and mutation controls, pure Python + binary reassemble the fixture sources and compare them with the words below + draw [fxc] + compile the translated pair with FXC ps_5_1 when given and with DXC ps_6_0, + draw one pixel per four input pairs and compare the four result words + +The pixel fixture reads two flat parameters (v0..v3 and v4..v7), computes v_mul_hi_u32 across all four lanes into +v12..v15, and exports v12..v15 to mrt0. The vertex stage supplies the input words through flat parameters so the +pixel stage cannot constant-fold them. + +Every result is compared with an independent Python reference ((a * b) >> 32). The emitted mul_hi_u32 HLSL helper is +parsed and evaluated in 32-bit unsigned arithmetic over a grid of edge cases. A mutation control replaces mul_hi_u32 +with the low 32-bit product (a * b) while keeping the same inputs read, and must produce the mutated low-word readback +on both CPU evaluation and desktop GPU draws. +""" +import re +import sys +import tempfile +from pathlib import Path + +HERE = Path(__file__).resolve().parent +sys.path.insert(0, str(HERE.parent / 'tools' / 'startup')) +sys.path.insert(0, str(HERE)) +import gfx2hlsl as G # noqa: E402 +from startup_flat_param_check import assemble, compile_hlsl, draw, root_blob # noqa: E402 +from startup_gfx2hlsl_bit_alu_check import ( # noqa: E402 + Expr, + MASK, + POST_SOURCE, + POST_WORDS, + PRE_SOURCE, + PRE_WORDS, + Probe, + check, + refused, + vs_source, + vs_words, + words_text, +) + +BODY_SOURCE = ''.join('v_mul_hi_u32 v%d, v%d, v%d\n' % (12 + lane, lane, 4 + lane) for lane in range(4)) +BODY_WORDS = bytes.fromhex( + '0c006ad500090200' + '0d006ad5010b0200' + '0e006ad5020d0200' + '0f006ad5030f0200' +) +PS_WORDS = PRE_WORDS + BODY_WORDS + POST_WORDS + +SPECIAL = ( + 0, 1, 2, 3, 0xffff, 0x10000, 0x10001, 0x0001ffff, 0x7fffffff, 0x80000000, 0x80000001, + 0xdeadbeef, 0xcafebabe, 0x9e3779b9, 0x85ebca6b, 0xffff0000, 0xffff0001, 0xfffffffe, MASK, +) +GRID = [(a, b) for a in SPECIAL for b in SPECIAL] + +# Four (src0, src1, unused_src2) tuples per draw. Set 0 separates high-word from low-word and from missing-carry bugs. +DRAW = [ + (0xffffffff, 0xffffffff, 0), + (0x80000000, 0x00000002, 0), + (0xdeadbeef, 0xcafebabe, 0), + (0x00010001, 0x00010001, 0), + (0x00000000, 0xffffffff, 0), + (0x00000001, 0xffffffff, 0), + (0x0000ffff, 0xffffffff, 0), + (0xffff0000, 0x00010001, 0), + (0x7fffffff, 0x7fffffff, 0), + (0x80000001, 0x80000001, 0), + (0x0001ffff, 0xffff0001, 0), + (0x9e3779b9, 0x85ebca6b, 0), +] + + +def ref_mul_hi_u32(a, b): + return ((a & MASK) * (b & MASK)) >> 32 + + +def mut_mul_lo_u32(a, b): + return ((a & MASK) * (b & MASK)) & MASK + + +def translate(mutate=False): + pipe = G.Pipeline(vs_words([(0, 0, 0)] * 4), PS_WORDS, root_blob()) + text = pipe.hlsl_ps() + if mutate: + mutated = re.sub(r'mul_hi_u32\((v\d+), (v\d+)\)', r'(\1 * \2)', text) + assert mutated != text, text + text = mutated + return pipe, text + + +def eval_emitted_helper(ps_text): + """Parse the emitted mul_hi_u32 helper body and return a 32-bit evaluator for it.""" + m = re.search(r'uint mul_hi_u32\(uint a, uint b\) \{ (.*?) \}', ps_text) + assert m, 'mul_hi_u32 helper missing from generated HLSL' + body = m.group(1) + m_vars = re.match(r'uint al = ([^,]+), bl = ([^,]+), m = ([^;]+); return ([^;]+);$', body) + assert m_vars, body + al_e, bl_e, m_e, ret_e = (Expr(part) for part in m_vars.groups()) + + def run(a, b): + env = {'a': a & MASK, 'b': b & MASK} + env['al'] = al_e.run(env)[0] + env['bl'] = bl_e.run(env)[0] + env['m'] = m_e.run(env)[0] + return ret_e.run(env)[0] + + return run + + +def controls(): + _, text = translate() + found = re.findall(r'^\s*v(1[2-5]) = mul_hi_u32\(v(\d+), v(\d+)\);$', text, re.M) + check('v_mul_hi_u32: four lane calls emitted', + found == [('12', '0', '4'), ('13', '1', '5'), ('14', '2', '6'), ('15', '3', '7')]) + + helper = eval_emitted_helper(text) + mismatch = next(((a, b, helper(a, b), ref_mul_hi_u32(a, b)) for a, b in GRID + if helper(a, b) != ref_mul_hi_u32(a, b)), None) + check('v_mul_hi_u32: emitted helper matches reference on %d edge pairs' % len(GRID), mismatch is None) + + # Carry-drop negative control on the helper itself: dropping ((al * bl) >> 16) must fail on 0xffffffff * 0xffffffff. + dropped = text.replace('+ ((al * bl) >> 16)', '+ 0u') + assert dropped != text + bad_helper = eval_emitted_helper(dropped) + check('v_mul_hi_u32: dropping low-half carry mismatches 0xffffffff * 0xffffffff', + bad_helper(0xffffffff, 0xffffffff) != ref_mul_hi_u32(0xffffffff, 0xffffffff)) + + # Lane mutation control: replacing mul_hi_u32(vX, vY) with (vX * vY) yields the low word on draw set 0. + mutated = translate(mutate=True)[1] + mut_lanes = re.findall(r'^\s*v(1[2-5]) = (.*);$', mutated, re.M) + assert [r for r, _ in mut_lanes] == ['12', '13', '14', '15'], mut_lanes + mut_exprs = [Expr(rhs) for _, rhs in mut_lanes] + first = DRAW[:4] + ref_first = [ref_mul_hi_u32(a, b) for a, b, _ in first] + mut_first = [mut_mul_lo_u32(a, b) for a, b, _ in first] + eval_mut = [expr.run({'v%d' % lane: a, 'v%d' % (4 + lane): b})[0] + for lane, (expr, (a, b, _)) in enumerate(zip(mut_exprs, first))] + check('v_mul_hi_u32: draw set 0 mutation reads %s (differs from %s)' % (words_text(mut_first), words_text(ref_first)), + mut_first != ref_first and eval_mut == mut_first) + + # Accepted operand forms (VGPR, SGPR, inline constant, literal) and exec-masked emission. + check('accepted operand forms translate', not any(refused(a) for a in ( + 'v_mul_hi_u32 v1, v2, v3', 'v_mul_hi_u32 v1, s0, v3', + 'v_mul_hi_u32 v1, v2, 7', 'v_mul_hi_u32 v1, v2, 0x12345678'))) + masked = Probe() + masked.exec_known = False + masked.one('v_mul_hi_u32', 'v_mul_hi_u32 v1, v2, v3') + check('exec-masked v_mul_hi_u32 guards assignment', + masked.lines == ['if (exec & 1) v1 = mul_hi_u32(v2, v3);']) + + # Unmodeled modifiers and wrong operand counts must stay refused. + check('modifiers and operand modifiers refused', all(refused(a) for a in ( + 'v_mul_hi_u32 v1, v2, v3 clamp', 'v_mul_hi_u32 v1, v2, v3 mul:2', + 'v_mul_hi_u32 v1, v2, v3 div:2', 'v_mul_hi_u32 v1, v2, v3 op_sel:[1,0,0,0]', + 'v_mul_hi_u32 v1, -v2, v3', 'v_mul_hi_u32 v1, |v2|, v3', + 'v_mul_hi_u32 v1, v2, -v3', 'v_mul_hi_u32 v1, v2, |v3|'))) + check('wrong operand counts refused', all(refused(a) for a in ( + 'v_mul_hi_u32 v1', 'v_mul_hi_u32 v1, v2', 'v_mul_hi_u32 v1, v2, v3, v4'))) + + +def check_binary(llvm_mc): + built = assemble(llvm_mc, BODY_SOURCE) + if built != BODY_WORDS: + raise AssertionError('v_mul_hi_u32: assembled %s, recorded %s' % (built.hex(), BODY_WORDS.hex())) + for name, source, words in (('prologue', PRE_SOURCE, PRE_WORDS), ('export', POST_SOURCE, POST_WORDS)): + if assemble(llvm_mc, source) != words: + raise AssertionError('%s fixture differs from llvm-mc' % name) + for index in range(0, len(DRAW), 4): + chunk = DRAW[index:index + 4] + if assemble(llvm_mc, vs_source(chunk)) != vs_words(chunk): + raise AssertionError('vertex fixture for %s differs from llvm-mc' % (chunk,)) + print('fixture words match llvm-mc') + + +def check_draw(dxc, renderer, adapter, fxc=None): + controls() + compilers = ([('fxc', fxc, 'vs_5_1', 'ps_5_1')] if fxc else []) + [('dxc', dxc, 'vs_6_0', 'ps_6_0')] + with tempfile.TemporaryDirectory() as tmp: + directory = Path(tmp) + for kind, compiler, vs_profile, ps_profile in compilers: + good_ps = compile_hlsl(compiler, kind, translate()[1], 'ps_mul_hi_%s' % kind, ps_profile, directory) + for index in range(0, len(DRAW), 4): + chunk = DRAW[index:index + 4] + vs = compile_hlsl(compiler, kind, G.Pipeline(vs_words(chunk), PS_WORDS, root_blob()).hlsl_vs(), + 'vs_mul_hi_%d_%s' % (index, kind), vs_profile, directory) + expected = words_text(ref_mul_hi_u32(a, b) for a, b, _ in chunk) + run = draw(renderer, adapter, vs, good_ps, expected) + if run.returncode: + raise AssertionError('%s v_mul_hi_u32 inputs %s\n%s\n%s' % (kind, chunk, run.stdout, run.stderr)) + print('%s v_mul_hi_u32 %s: %s' % (kind, [('%x' % a, '%x' % b) for a, b, _ in chunk], expected), + flush=True) + if index: + continue + wrong = words_text(mut_mul_lo_u32(a, b) for a, b, _ in chunk) + bad_ps = compile_hlsl(compiler, kind, translate(mutate=True)[1], + 'mutated_mul_hi_%s' % kind, ps_profile, directory) + run = draw(renderer, adapter, vs, bad_ps, expected) + if run.returncode == 0 or 'actual=%s' % wrong not in run.stderr: + raise AssertionError('%s v_mul_hi_u32 mutation did not read %s\n%s\n%s' + % (kind, wrong, run.stdout, run.stderr)) + print('%s v_mul_hi_u32 mutation: fails as expected, reads %s' % (kind, wrong), flush=True) + + +def main(): + if len(sys.argv) == 1: + controls() + return + mode, *args = sys.argv[1:] + if mode == 'binary': + check_binary(*args) + elif mode == 'draw': + check_draw(*args) + else: + raise SystemExit(__doc__) + + +if __name__ == '__main__': + main() diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index 79de72c05a..b377fb2398 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -3566,7 +3566,7 @@ def declarations(self): # operands are uints; the result is a uint expression VEC_U = { 'v_add_nc_u32': (2, '{0} + {1}'), 'v_sub_nc_u32': (2, '{0} - {1}'), 'v_subrev_nc_u32': (2, '{1} - {0}'), - 'v_mul_lo_u32': (2, '{0} * {1}'), 'v_and_b32': (2, '{0} & {1}'), 'v_or_b32': (2, '{0} | {1}'), 'v_xor_b32': (2, '{0} ^ {1}'), + 'v_mul_lo_u32': (2, '{0} * {1}'), 'v_mul_hi_u32': (2, 'mul_hi_u32({0}, {1})'), 'v_and_b32': (2, '{0} & {1}'), 'v_or_b32': (2, '{0} | {1}'), 'v_xor_b32': (2, '{0} ^ {1}'), 'v_not_b32': (1, '~{0}'), 'v_lshlrev_b32': (2, '{1} << ({0} & 31)'), 'v_lshrrev_b32': (2, '{1} >> ({0} & 31)'), 'v_ashrrev_i32': (2, 'uint(int({1}) >> ({0} & 31))'), 'v_min_u32': (2, 'min({0}, {1})'), 'v_max_u32': (2, 'max({0}, {1})'), 'v_min_i32': (2, 'uint(min(int({0}), int({1})))'), 'v_max_i32': (2, 'uint(max(int({0}), int({1})))'), @@ -3854,6 +3854,8 @@ def common(self): ' precise float sum = product + ftz32(c);', ' return ftz32(sum);', '}', + 'uint mul_hi_u32(uint a, uint b) { uint al = a & 0xffffu, bl = b & 0xffffu, m = (a >> 16) * bl + ((al * bl) >> 16); ' + 'return (a >> 16) * (b >> 16) + (m >> 16) + (((m & 0xffffu) + al * (b >> 16)) >> 16); }', 'float med3(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }', # High half of an unsigned 32x32 product, by halfword products so it fits 32-bit HLSL. 'uint mul_hi_u32(uint a, uint b) { uint la = a & 0xffffu, lb = b & 0xffffu;' From 92534e75c30f0010c2c35c709e430007d2f0af6e Mon Sep 17 00:00:00 2001 From: rdx <123564405+R0D4X@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:12:01 +0100 Subject: [PATCH 2/5] Update gfx2hlsl.py Remove the duplicate mul_hi_u32 definition introduced during rebase so v_mul_hi_u32 reuses the shared helper from #2176. --- tools/startup/gfx2hlsl.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/tools/startup/gfx2hlsl.py b/tools/startup/gfx2hlsl.py index b377fb2398..b59ac818c1 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -3854,8 +3854,6 @@ def common(self): ' precise float sum = product + ftz32(c);', ' return ftz32(sum);', '}', - 'uint mul_hi_u32(uint a, uint b) { uint al = a & 0xffffu, bl = b & 0xffffu, m = (a >> 16) * bl + ((al * bl) >> 16); ' - 'return (a >> 16) * (b >> 16) + (m >> 16) + (((m & 0xffffu) + al * (b >> 16)) >> 16); }', 'float med3(float a, float b, float c) { return max(min(a, b), min(max(a, b), c)); }', # High half of an unsigned 32x32 product, by halfword products so it fits 32-bit HLSL. 'uint mul_hi_u32(uint a, uint b) { uint la = a & 0xffffu, lb = b & 0xffffu;' From 2fadf5e1fc9c608420aec7bb9aaec6072bc56834 Mon Sep 17 00:00:00 2001 From: rdx <123564405+R0D4X@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:24:53 +0100 Subject: [PATCH 3/5] Update startup_gfx2hlsl_mul_hi_check.py --- tests/startup_gfx2hlsl_mul_hi_check.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tests/startup_gfx2hlsl_mul_hi_check.py b/tests/startup_gfx2hlsl_mul_hi_check.py index b5d6a411dd..dbd2e84ef4 100644 --- a/tests/startup_gfx2hlsl_mul_hi_check.py +++ b/tests/startup_gfx2hlsl_mul_hi_check.py @@ -95,20 +95,19 @@ def eval_emitted_helper(ps_text): m = re.search(r'uint mul_hi_u32\(uint a, uint b\) \{ (.*?) \}', ps_text) assert m, 'mul_hi_u32 helper missing from generated HLSL' body = m.group(1) - m_vars = re.match(r'uint al = ([^,]+), bl = ([^,]+), m = ([^;]+); return ([^;]+);$', body) + m_vars = re.match(r'uint la = ([^,]+), lb = ([^;]+); uint middle = ([^;]+); return ([^;]+);$', body) assert m_vars, body - al_e, bl_e, m_e, ret_e = (Expr(part) for part in m_vars.groups()) + la_e, lb_e, middle_e, ret_e = (Expr(part) for part in m_vars.groups()) def run(a, b): env = {'a': a & MASK, 'b': b & MASK} - env['al'] = al_e.run(env)[0] - env['bl'] = bl_e.run(env)[0] - env['m'] = m_e.run(env)[0] + env['la'] = la_e.run(env)[0] + env['lb'] = lb_e.run(env)[0] + env['middle'] = middle_e.run(env)[0] return ret_e.run(env)[0] return run - - + def controls(): _, text = translate() found = re.findall(r'^\s*v(1[2-5]) = mul_hi_u32\(v(\d+), v(\d+)\);$', text, re.M) From ee0b273f310dd800393ff4a2cf6935010ede5b8a Mon Sep 17 00:00:00 2001 From: rdx <123564405+R0D4X@users.noreply.github.com> Date: Wed, 25 Nov 2026 13:34:23 +0100 Subject: [PATCH 4/5] Update startup_gfx2hlsl_mul_hi_check.py --- tests/startup_gfx2hlsl_mul_hi_check.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/startup_gfx2hlsl_mul_hi_check.py b/tests/startup_gfx2hlsl_mul_hi_check.py index dbd2e84ef4..d9da8d2c67 100644 --- a/tests/startup_gfx2hlsl_mul_hi_check.py +++ b/tests/startup_gfx2hlsl_mul_hi_check.py @@ -119,8 +119,8 @@ def controls(): if helper(a, b) != ref_mul_hi_u32(a, b)), None) check('v_mul_hi_u32: emitted helper matches reference on %d edge pairs' % len(GRID), mismatch is None) - # Carry-drop negative control on the helper itself: dropping ((al * bl) >> 16) must fail on 0xffffffff * 0xffffffff. - dropped = text.replace('+ ((al * bl) >> 16)', '+ 0u') + # Carry-drop negative control on the helper itself: dropping ((la * lb) >> 16) must fail on 0xffffffff * 0xffffffff. + dropped = text.replace('+ ((la * lb) >> 16)', '+ 0u') assert dropped != text bad_helper = eval_emitted_helper(dropped) check('v_mul_hi_u32: dropping low-half carry mismatches 0xffffffff * 0xffffffff', From 02328b26187b43bdfc9f502ff6cdca1a3738ca92 Mon Sep 17 00:00:00 2001 From: Royoo <3230853833@qq.com> Date: Thu, 26 Nov 2026 00:07:26 +0800 Subject: [PATCH 5/5] shader: cover the reported vector multiply-high literal --- docs/experiments.md | 9 +++++++++ tests/startup_gfx2hlsl_mul_hi_check.py | 14 +++++++++++++- 2 files changed, 22 insertions(+), 1 deletion(-) diff --git a/docs/experiments.md b/docs/experiments.md index b50a29d1f0..3b841724f7 100644 --- a/docs/experiments.md +++ b/docs/experiments.md @@ -7470,6 +7470,15 @@ symbolic descriptors and reserved scalar encodings stay refused; an SGPR that held a compare mask may be overwritten and loses its mask mark. `s_mul_hi_i32` is still refused by name. +**Vector unsigned multiply-high.** The startup shader translator lowers +`v_mul_hi_u32` to the same halfword-product helper as `s_mul_hi_u32`. +Synthetic VOP3A instructions cover register inputs and the literal +`0xaaaaaaab`. FXC and DXC draws check the high word against a 64-bit reference. +The controls also detect an omitted carry or a replacement with the low word. +Build `offscreen_check`, then run +`ctest --preset dev --no-tests=error -j 1 -R '^startup_gfx2hlsl_mul_hi_' -V`. +[Refs #1792](https://github.com/R0Y00/Xbox2Windows/issues/1792) + **Scalar bit tests.** Startup translation sets SCC for `s_bitcmp0_b32` and `s_bitcmp1_b32` by comparing the selected bit of the first word to zero or one. Only the low five bits of the index are used. EXEC, VCC and SGPRs tracked diff --git a/tests/startup_gfx2hlsl_mul_hi_check.py b/tests/startup_gfx2hlsl_mul_hi_check.py index d9da8d2c67..dfa63187a2 100644 --- a/tests/startup_gfx2hlsl_mul_hi_check.py +++ b/tests/startup_gfx2hlsl_mul_hi_check.py @@ -49,6 +49,10 @@ ) PS_WORDS = PRE_WORDS + BODY_WORDS + POST_WORDS +# VOP3A uses source selector 255 followed by the literal DWORD (#1792). +LITERAL_SOURCE = 'v_mul_hi_u32 v12, v0, 0xaaaaaaab\n' +LITERAL_WORDS = bytes.fromhex('0c006ad500ff0100abaaaaaa') + SPECIAL = ( 0, 1, 2, 3, 0xffff, 0x10000, 0x10001, 0x0001ffff, 0x7fffffff, 0x80000000, 0x80000001, 0xdeadbeef, 0xcafebabe, 0x9e3779b9, 0x85ebca6b, 0xffff0000, 0xffff0001, 0xfffffffe, MASK, @@ -107,13 +111,19 @@ def run(a, b): return ret_e.run(env)[0] return run - + def controls(): _, text = translate() found = re.findall(r'^\s*v(1[2-5]) = mul_hi_u32\(v(\d+), v(\d+)\);$', text, re.M) check('v_mul_hi_u32: four lane calls emitted', found == [('12', '0', '4'), ('13', '1', '5'), ('14', '2', '6'), ('15', '3', '7')]) + literal_ps = PRE_WORDS + LITERAL_WORDS + BODY_WORDS[8:] + POST_WORDS + literal_text = G.Pipeline(vs_words([(0, 0, 0)] * 4), literal_ps, root_blob()).hlsl_ps() + literal_match = re.search(r'v12 = mul_hi_u32\(v0, (0[xX][0-9a-fA-F]+|[0-9]+)u\);', literal_text) + check('v_mul_hi_u32: encoded literal reaches the helper', + literal_match is not None and int(literal_match[1], 0) == 0xaaaaaaab) + helper = eval_emitted_helper(text) mismatch = next(((a, b, helper(a, b), ref_mul_hi_u32(a, b)) for a, b in GRID if helper(a, b) != ref_mul_hi_u32(a, b)), None) @@ -163,6 +173,8 @@ def check_binary(llvm_mc): built = assemble(llvm_mc, BODY_SOURCE) if built != BODY_WORDS: raise AssertionError('v_mul_hi_u32: assembled %s, recorded %s' % (built.hex(), BODY_WORDS.hex())) + if assemble(llvm_mc, LITERAL_SOURCE) != LITERAL_WORDS: + raise AssertionError('literal v_mul_hi_u32 fixture differs from llvm-mc') for name, source, words in (('prologue', PRE_SOURCE, PRE_WORDS), ('export', POST_SOURCE, POST_WORDS)): if assemble(llvm_mc, source) != words: raise AssertionError('%s fixture differs from llvm-mc' % name)