From 29536aa3c9a406d994e5b49305659715ee63cbb3 Mon Sep 17 00:00:00 2001 From: R0D4X Date: Wed, 25 Nov 2026 16:21:07 +0100 Subject: [PATCH] startup: lower v_mul_hi_i32 and s_mul_hi_i32 in gfx2hlsl --- .github/workflows/windows.yml | 2 + CMakeLists.txt | 9 + tests/startup_gfx2hlsl_mul_hi_i32_check.py | 303 +++++++++++++++++++++ tools/startup/gfx2hlsl.py | 18 +- 4 files changed, 326 insertions(+), 6 deletions(-) create mode 100644 tests/startup_gfx2hlsl_mul_hi_i32_check.py diff --git a/.github/workflows/windows.yml b/.github/workflows/windows.yml index d8ce371448..862d5cd52f 100644 --- a/.github/workflows/windows.yml +++ b/.github/workflows/windows.yml @@ -113,6 +113,7 @@ jobs: (["tests/startup_gfx2hlsl_join_symbols_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_swap_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_shift64_check.py", "binary", "llvm-mc-15"], {}), + (["tests/startup_gfx2hlsl_mul_hi_i32_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_vopc_sdwa_check.py", "binary", "llvm-mc-15"], {}), (["tests/startup_gfx2hlsl_vopc_sdwa_check.py", "decode", "libLLVM-15.so.1"], {}), (["tests/startup_gfx2hlsl_sop2_complement_check.py", "binary", "llvm-mc-15"], {}), @@ -255,6 +256,7 @@ jobs: tests/startup_compute_translate_check.py \ tests/startup_gfx2hlsl_swap_check.py \ tests/startup_gfx2hlsl_shift64_check.py \ + tests/startup_gfx2hlsl_mul_hi_i32_check.py \ tests/startup_gfx2hlsl_vopc_sdwa_check.py \ tests/startup_gfx2hlsl_cmp16_check.py \ tests/startup_gfx2hlsl_draw_skip_check.py \ diff --git a/CMakeLists.txt b/CMakeLists.txt index 417d155511..8de5e77678 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3389,6 +3389,15 @@ if(EXISTS "${INTAKE_PYTHON}") "$" ${adapter} $<$:${STARTUP_FXC}>) set_tests_properties(startup_gfx2hlsl_shift64_${adapter} PROPERTIES TIMEOUT 180 SKIP_RETURN_CODE 77) endforeach() + # gfx2hlsl signed multiply-high (v_mul_hi_i32, s_mul_hi_i32): helper math, refusals, mutations and draws. + add_test(NAME startup_gfx2hlsl_mul_hi_i32_controls COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mul_hi_i32_check.py") + foreach(adapter IN ITEMS warp hardware) + add_test(NAME startup_gfx2hlsl_mul_hi_i32_${adapter} COMMAND "${INTAKE_PYTHON}" -B + "${CMAKE_SOURCE_DIR}/tests/startup_gfx2hlsl_mul_hi_i32_check.py" draw "${DXC_EXECUTABLE}" + "$" ${adapter} $<$:${STARTUP_FXC}>) + set_tests_properties(startup_gfx2hlsl_mul_hi_i32_${adapter} PROPERTIES TIMEOUT 120 SKIP_RETURN_CODE 77) + endforeach() # XG slots 2 and 8 for a texture given the 4 KiB allocation answer (src/startup_stubs/small_texture_4k.h): # the copy must stay in front of a guard page; the mutated run is not limited and must fail. add_test(NAME startup_small_texture_4k_xg COMMAND "${INTAKE_PYTHON}" -B diff --git a/tests/startup_gfx2hlsl_mul_hi_i32_check.py b/tests/startup_gfx2hlsl_mul_hi_i32_check.py new file mode 100644 index 0000000000..5965576845 --- /dev/null +++ b/tests/startup_gfx2hlsl_mul_hi_i32_check.py @@ -0,0 +1,303 @@ +"""Signed 32x32->high-32 multiply (v_mul_hi_i32, s_mul_hi_i32) in tools/startup/gfx2hlsl.py. + + (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_i32 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 signed 64-bit reference ((s32(a) * s32(b)) >> 32) & 0xffffffff. +The emitted mul_hi_i32 helper (built on the existing mul_hi_u32 helper in Pipeline.common()) is parsed and evaluated +in 32-bit unsigned arithmetic over a 361-pair edge grid including INT_MIN * INT_MIN, INT_MIN * -1, -1 * -1, and mixed +signs. Controls verify s_mul_hi_i32 decoding/lowering (SCC unchanged, lane-mask/descriptor/bounds refusals), exec-masked +emission, modifier/arity refusals, and mutations replacing mul_hi_i32 with mul_hi_u32 (unsigned high product) or +dropping one sign-correction term on both CPU evaluation and desktop GPU draws. +""" +import re +import struct +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_i32 v%d, v%d, v%d\n' % (12 + lane, lane, 4 + lane) for lane in range(4)) +BODY_WORDS = bytes.fromhex( + '0c006cd500090200' + '0d006cd5010b0200' + '0e006cd5020d0200' + '0f006cd5030f0200' +) +PS_WORDS = PRE_WORDS + BODY_WORDS + POST_WORDS + +SCALAR_SOURCE = 's_mul_hi_i32 s12, s10, s11\n' +SCALAR_WORDS = struct.pack(' hi 0x00000000 (unsigned: 0xfffffffe) + (0x80000000, 0x80000000, 0), # INT_MIN * INT_MIN -> hi 0x40000000 (unsigned: 0x40000000, 1-term drop: 0xc0000000) + (0x80000000, 0x00000002, 0), # INT_MIN * 2 -> hi 0xffffffff (unsigned: 0x00000001) + (0xdeadbeef, 0x7fffffff, 0), # neg * INT_MAX -> hi 0xef56df77 (unsigned: 0x6f56df77) + (0x80000000, 0xffffffff, 0), # INT_MIN * -1 -> hi 0x00000000 + (0x00000000, 0xffffffff, 0), # 0 * -1 -> hi 0x00000000 + (0x7fffffff, 0x7fffffff, 0), # INT_MAX * INT_MAX -> hi 0x3fffffff + (0x00000001, 0x80000000, 0), # 1 * INT_MIN -> hi 0xffffffff + (0xdeadbeef, 0xcafebabe, 0), # neg * neg -> hi 0x0b164486 + (0x9e3779b9, 0x85ebca6b, 0), # neg * neg -> hi 0x2ec3a0c2 + (0xffff0000, 0x00010001, 0), # -65536 * 65537 -> hi 0xffffffff + (0x00010001, 0x00010001, 0), # pos * pos -> hi 0x00000001 +] + + +def s32(v): + v &= MASK + return v - (1 << 32) if v & 0x80000000 else v + + +def ref_mul_hi_i32(a, b): + return ((s32(a) * s32(b)) >> 32) & MASK + + +def ref_mul_hi_u32(a, b): + return ((a & MASK) * (b & MASK)) >> 32 + + +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_i32\((v\d+), (v\d+)\)', r'mul_hi_u32(\1, \2)', text) + assert mutated != text, text + text = mutated + return pipe, text + + +def eval_emitted_helpers(ps_text): + """Parse the emitted mul_hi_u32 and mul_hi_i32 helpers and return a 32-bit evaluator for mul_hi_i32.""" + mu = re.search(r'uint mul_hi_u32\(uint a, uint b\) \{ (.*?) \}', ps_text) + assert mu, 'mul_hi_u32 helper missing from generated HLSL' + u_stmts = [part.strip() for part in mu.group(1).split(';') if part.strip()] + u_decls = [] + for stmt in u_stmts[:-1]: + assert stmt.startswith('uint '), stmt + for item in stmt[5:].split(','): + name, rhs = [x.strip() for x in item.split('=', 1)] + u_decls.append((name, Expr(rhs))) + assert u_stmts[-1].startswith('return '), u_stmts[-1] + u_ret = Expr(u_stmts[-1][7:]) + + def run_u(a, b): + env = {'a': a & MASK, 'b': b & MASK} + for name, expr in u_decls: + env[name] = expr.run(env)[0] + return u_ret.run(env)[0] + + mi = re.search(r'uint mul_hi_i32\(uint a, uint b\) \{ return ([^;]+); \}', ps_text) + assert mi, 'mul_hi_i32 helper missing from generated HLSL' + i_expr_text = mi.group(1) + assert 'mul_hi_u32(a, b)' in i_expr_text, i_expr_text + i_expr = Expr(i_expr_text.replace('mul_hi_u32(a, b)', 'u')) + + def run_i(a, b): + return i_expr.run({'a': a & MASK, 'b': b & MASK, 'u': run_u(a, b)})[0] + + return run_i + + +class ScalarProbe(Probe): + def __init__(self): + super().__init__() + self.masks = set() + self.scc_effect = None + + +def scalar_refused(line): + try: + ScalarProbe().one(line.split(' ', 1)[0], line) + except G.Unsupported: + return True + return False + + +def controls(): + _, text = translate() + found = re.findall(r'^\s*v(1[2-5]) = mul_hi_i32\(v(\d+), v(\d+)\);$', text, re.M) + check('v_mul_hi_i32: four lane calls emitted', + found == [('12', '0', '4'), ('13', '1', '5'), ('14', '2', '6'), ('15', '3', '7')]) + + helper = eval_emitted_helpers(text) + mismatch = next(((a, b, helper(a, b), ref_mul_hi_i32(a, b)) for a, b in GRID + if helper(a, b) != ref_mul_hi_i32(a, b)), None) + check('v_mul_hi_i32: emitted helper matches reference on %d edge pairs' % len(GRID), mismatch is None) + + # Sign-correction negative controls: dropping either sign term must mismatch. + drop_a = text.replace('((a >> 31) != 0u ? b : 0u)', '0u') + drop_b = text.replace('((b >> 31) != 0u ? a : 0u)', '0u') + assert drop_a != text and drop_b != text + check('mul_hi_i32: dropping a-sign correction mismatches INT_MIN * 2', + eval_emitted_helpers(drop_a)(0x80000000, 2) != ref_mul_hi_i32(0x80000000, 2)) + check('mul_hi_i32: dropping b-sign correction mismatches 2 * INT_MIN', + eval_emitted_helpers(drop_b)(2, 0x80000000) != ref_mul_hi_i32(2, 0x80000000)) + + # Draw set 0 mutation: substituting mul_hi_u32 for mul_hi_i32 produces distinct words. + mutated = translate(mutate=True)[1] + check('v_mul_hi_i32: mutated text calls mul_hi_u32 on all four lanes', + re.findall(r'^\s*v(1[2-5]) = mul_hi_u32\(v(\d+), v(\d+)\);$', mutated, re.M) + == [('12', '0', '4'), ('13', '1', '5'), ('14', '2', '6'), ('15', '3', '7')]) + first = DRAW[:4] + ref_first = [ref_mul_hi_i32(a, b) for a, b, _ in first] + mut_first = [ref_mul_hi_u32(a, b) for a, b, _ in first] + check('v_mul_hi_i32: draw set 0 unsigned mutation reads %s (differs from %s)' + % (words_text(mut_first), words_text(ref_first)), mut_first != ref_first) + + # Accepted vector operand forms (VGPR, SGPR, inline constant, literal) and exec-masked emission. + check('v_mul_hi_i32: accepted operand forms translate', not any(refused(a) for a in ( + 'v_mul_hi_i32 v1, v2, v3', 'v_mul_hi_i32 v1, s0, v3', + 'v_mul_hi_i32 v1, v2, -1', 'v_mul_hi_i32 v1, v2, 0x80000000'))) + masked = Probe() + masked.exec_known = False + masked.one('v_mul_hi_i32', 'v_mul_hi_i32 v1, v2, v3') + check('exec-masked v_mul_hi_i32 guards assignment', + masked.lines == ['if (exec & 1) v1 = mul_hi_i32(v2, v3);']) + + # Vector refusals: modifiers and wrong operand counts. + check('v_mul_hi_i32: modifiers and operand modifiers refused', all(refused(a) for a in ( + 'v_mul_hi_i32 v1, v2, v3 clamp', 'v_mul_hi_i32 v1, v2, v3 mul:2', + 'v_mul_hi_i32 v1, v2, v3 div:2', 'v_mul_hi_i32 v1, v2, v3 op_sel:[1,0,0,0]', + 'v_mul_hi_i32 v1, -v2, v3', 'v_mul_hi_i32 v1, |v2|, v3', + 'v_mul_hi_i32 v1, v2, -v3', 'v_mul_hi_i32 v1, v2, |v3|'))) + check('v_mul_hi_i32: wrong operand counts refused', all(refused(a) for a in ( + 'v_mul_hi_i32 v1', 'v_mul_hi_i32 v1, v2', 'v_mul_hi_i32 v1, v2, v3, v4'))) + + # Scalar s_mul_hi_i32: decode, lowering (SCC unchanged), SGPR-over-mask overwrite, and refusals. + decoded = G.decode(SCALAR_WORDS) + check('s_mul_hi_i32: SOP2 encoding decodes', + len(decoded) == 1 and decoded[0][2] == 's_mul_hi_i32' and decoded[0][3] == 's_mul_hi_i32 s12, s10, s11') + sp = ScalarProbe() + sp.one('s_mul_hi_i32', 's_mul_hi_i32 s12, s10, s11') + check('s_mul_hi_i32: lowers to mul_hi_i32 without touching scc', + sp.lines == ['s12 = mul_hi_i32(s10, s11);']) + sp_lit = ScalarProbe() + sp_lit.one('s_mul_hi_i32', 's_mul_hi_i32 s12, s10, 0x80000001') + check('s_mul_hi_i32: literal source translates', + sp_lit.lines == ['s12 = mul_hi_i32(s10, 0x80000001u);']) + # Overwriting an SGPR that previously held a compare mask succeeds and drops its mask mark. + sp_over = ScalarProbe() + sp_over.masks.add(12) + sp_over.one('s_mul_hi_i32', 's_mul_hi_i32 s12, s10, s11') + check('s_mul_hi_i32: overwriting mask-marked SGPR drops mask mark', 12 not in sp_over.masks) + # Reading a mask-marked SGPR as source must be refused. + sp_mask_src = ScalarProbe() + sp_mask_src.masks.add(10) + mask_src_refused = False + try: + sp_mask_src.one('s_mul_hi_i32', 's_mul_hi_i32 s12, s10, s11') + except G.Unsupported: + mask_src_refused = True + check('s_mul_hi_i32: mask-marked SGPR source refused', mask_src_refused) + check('s_mul_hi_i32: lane-mask, vcc/exec, out-of-range and wrong-count forms refused', all(scalar_refused(a) for a in ( + 's_mul_hi_i32 vcc_lo, s10, s11', 's_mul_hi_i32 exec_lo, s10, s11', + 's_mul_hi_i32 s12, vcc_lo, s11', 's_mul_hi_i32 s12, s10, exec_lo', + 's_mul_hi_i32 s106, s10, s11', 's_mul_hi_i32 s12, s106, s11', + 's_mul_hi_i32 s12, s10', 's_mul_hi_i32 s12, s10, s11, s13'))) + sym_p = ScalarProbe() + sym_p.sym[10] = ('ptr', ('vbtab',)) + sym_refused = False + try: + sym_p.one('s_mul_hi_i32', 's_mul_hi_i32 s12, s10, s11') + except G.Unsupported: + sym_refused = True + check('s_mul_hi_i32: symbolic pointer source refused', sym_refused) + + +def check_binary(llvm_mc): + for label, source, words in ( + ('v_mul_hi_i32 body', BODY_SOURCE, BODY_WORDS), + ('s_mul_hi_i32', SCALAR_SOURCE, SCALAR_WORDS), + ('prologue', PRE_SOURCE, PRE_WORDS), + ('export', POST_SOURCE, POST_WORDS), + ): + built = assemble(llvm_mc, source) + if built != words: + raise AssertionError('%s: assembled %s, recorded %s' % (label, built.hex(), words.hex())) + 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_i32_%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_i32_%d_%s' % (index, kind), vs_profile, directory) + expected = words_text(ref_mul_hi_i32(a, b) for a, b, _ in chunk) + run = draw(renderer, adapter, vs, good_ps, expected) + if run.returncode: + raise AssertionError('%s v_mul_hi_i32 inputs %s\n%s\n%s' % (kind, chunk, run.stdout, run.stderr)) + print('%s v_mul_hi_i32 %s: %s' % (kind, [('%x' % a, '%x' % b) for a, b, _ in chunk], expected), + flush=True) + if index: + continue + wrong = words_text(ref_mul_hi_u32(a, b) for a, b, _ in chunk) + bad_ps = compile_hlsl(compiler, kind, translate(mutate=True)[1], + 'mutated_mul_hi_i32_%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_i32 mutation did not read %s\n%s\n%s' + % (kind, wrong, run.stdout, run.stderr)) + print('%s v_mul_hi_i32 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 eccba084ee..9a5ca86be1 100644 --- a/tools/startup/gfx2hlsl.py +++ b/tools/startup/gfx2hlsl.py @@ -2374,18 +2374,21 @@ def low(tok): srcs = [str(sopk_imm(srcs[0], True))] # D.i32 = signext(SIMM16) shift_add = base in SHIFT_ADD word_complement = base in ('s_nand_b32', 's_nor_b32', 's_xnor_b32') - # s_mul_hi_u32 needs the whole 32-bit word of each source, like the halfword pack. - word_pack = base in ('s_pack_hh_b32_b16', 's_sext_i32_i8', 's_sext_i32_i16', 's_mul_hi_u32') + # s_mul_hi_{u,i}32 need the whole 32-bit word of each source, like the halfword pack. + word_pack = base in ('s_pack_hh_b32_b16', 's_sext_i32_i8', 's_sext_i32_i16', 's_mul_hi_u32', 's_mul_hi_i32') if shift_add or word_complement or word_pack: - # The per-lane mask cannot supply the full word needed by these operations. s_mul_hi_u32 into an + # The per-lane mask cannot supply the full word needed by these operations. s_mul_hi_{u,i}32 into an # SGPR that held a mask replaces it with a plain word (set_s drops the mark), so only vcc/exec count. - mask_dest = (dname in ('exec', 'exec_lo', 'exec_hi', 'vcc', 'vcc_lo', 'vcc_hi') if base == 's_mul_hi_u32' + mask_dest = (dname in ('exec', 'exec_lo', 'exec_hi', 'vcc', 'vcc_lo', 'vcc_hi') + if base in ('s_mul_hi_u32', 's_mul_hi_i32') else self.is_lane_mask(dname)) if mask_dest or any(self.is_lane_mask(t) for t in srcs): raise Unsupported('%s on a lane mask' % base) if shift_add and dname != 'm0' and (not dst or dst[0] != 's' or dst[1] != dst[2] or dst[1] > 105): raise Unsupported('%s destination %s' % (base, dname)) if word_pack: + if base in ('s_mul_hi_u32', 's_mul_hi_i32') and len(srcs) != 2: + raise Unsupported('%s with %d operands, expected 3' % (base, len(ops))) if dname != 'm0' and (dst is None or dst[0] != 's' or dst[1] > 105): raise Unsupported('%s destination %s' % (base, dname)) for source in srcs: @@ -4764,7 +4767,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_i32': (2, 'mul_hi_i32({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})))'), @@ -4814,8 +4817,9 @@ def declarations(self): 's_min_i32': ('uint(min(int({0}), int({1})))', None), 's_max_i32': ('uint(max(int({0}), int({1})))', None), 's_bfe_u32': ('({0} >> ({1} & 31)) & ((({1} >> 16) & 127) >= 32 ? 0xffffffffu : ((1u << (({1} >> 16) & 31)) - 1))', '$ != 0'), 's_brev_b32': ('reversebits({0})', None), - # s_mul_hi_u32: high 32 bits of the unsigned 64-bit product; SCC unchanged. + # s_mul_hi_{u,i}32: high 32 bits of the unsigned/signed 64-bit product; SCC unchanged. 's_mul_hi_u32': ('mul_hi_u32({0}, {1})', None), + 's_mul_hi_i32': ('mul_hi_i32({0}, {1})', None), # s_sext_i32_iN: sign-extend the low N bits of S0; SCC unchanged. 's_sext_i32_i8': ('uint(int({0} << 24) >> 24)', None), 's_sext_i32_i16': ('uint(int({0} << 16) >> 16)', None), @@ -5082,6 +5086,8 @@ def common(self): 'uint mul_hi_u32(uint a, uint b) { uint la = a & 0xffffu, lb = b & 0xffffu;' ' uint middle = (a >> 16) * lb + ((la * lb) >> 16);' ' return (a >> 16) * (b >> 16) + (middle >> 16) + (((middle & 0xffffu) + la * (b >> 16)) >> 16); }', + 'uint mul_hi_i32(uint a, uint b) { return mul_hi_u32(a, b) - ((a >> 31) != 0u ? b : 0u)' + ' - ((b >> 31) != 0u ? a : 0u); }', # The ten binary32 classes v_cmp_class_f32 tests, from the raw encoding (#1795). 'uint class32(float value) { uint bits = asuint(value), magnitude = bits & 0x7fffffffu;' ' bool negative = bits >= 0x80000000u;'