Sign-extend SOPK immediates and preserve SALU SCC semantics in ffx_dispatch_aot #231
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/234"
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 KomaGuy on 2026-11-21T18:52:38Z.
Change
Align RDNA 2 scalar ALU (
SALU) lowering intools/ffx_dispatch_aot.pyandtools/ffx_scratch_reference.pywith the AMD RDNA 2 ISA specification for 16-bit signedSOPKimmediates andSCCstatus-flag updates:SOPKimmediates (simm16): LLVM's AMDGPU disassembler prints negative 16-bitSOPKimmediates as unsigned 16-bit hex tokens (0x8000–0xffff). Previouslyword()zero-extended them (s_movk_i32 s0, -1emitted0xffffu,s_addk_i32 s4, -2added+65534, ands_mulk_i32 s7, -3multiplied by+65533), corrupting bits[31:16].simm16()now sign-extends 16-bit immediates to 32-bit two's complement in bothffx_dispatch_aot.pyandffx_scratch_reference.pyand rejects out-of-range immediates.SCCsemantics across scalar ALU instructions:s_add_u32(sadd_u) ands_lshl4_add_u32(slshl4_add_u, capturing both shifted-out bitsa >> 28and post-shift carryr < (a << 4)).s_addk_i32(sadd_i) ands_sub_i32(ssub_i).S0 < S1/S0 > S1):s_min_u32,s_max_u32,s_min_i32, ands_max_i32(scc = 0on ties or whenS1wins).scc = dest != 0u):s_and_b32,s_or_b32,s_xor_b32,s_lshl_b32/s_lshr_b32(with 5-bit shift-count masking),s_abs_i32(sabs_i, two's-complement wrap-safe on0x80000000), ands_bfe_u32/s_bfe_i32.SCCoperations:s_mov_b32,s_mov_b64,s_movk_i32,s_mulk_i32,s_mul_i32,s_mul_hi_u32,s_brev_b32,s_cselect_b32, and all vector (v_*) instructions leavesccuntouched.s_cmp_eq_i32/s_cmp_lg_i32handling inpredecessor()matchingtranslate().Verification
Tested on Linux x86_64 (Python 3.13.5, LLVM 19.1.7, Clang 19.1.7) on top of
03c61dc:python3 -B tests/ffx_dispatch_aot_check.py llvm-mc-19 llvm-objcopy-19 libLLVM-19.so— passed (boundary cross-checks against 64-bit/arbitrary-precision RDNA 2 ISA models, negative controls rejecting out-of-rangeSOPKimmediates, assembledgfx1013fixtures verifying1 -> 0and0 -> 1SCCtransitions and SGPR aliasing throughs_cselect_b32andv_cndmask_b32_e64 ..., src_sccin bothtranslateandpredecessor, andffx_scratch_reference.networkSOPKparity).python3 -B tests/pixel_aot_check.py binary llvm-mc-19 llvm-objcopy-19 libLLVM-19.so— passed.python3 -B tests/script_state_check.py,tests/bcpack_check.py,tests/resource_ranges_check.py,tests/dxcontainer_part_offsets_check.py,tests/layout_chunks_check.py— all passed.tests/ffx_dispatch_io.hlsliinteger helpers as C++20 withclang++-19 -std=c++20 -O2 -Wall -Wextra -Wpedantic -Werror -fsanitize=undefined,addressacross all signed/unsigned boundary pairs (including0x80000000,0x10000000 << 4, and aliased destinations) — 0 warnings, 0 sanitizer errors.cs_6_0), WARP, and hardware checks were not run locally on Linux; relying on thebuild-and-testWindows CI job to verify desktop compilation and WARP execution.Evidence and follow-up
tests/ffx_dispatch_aot_check.pyare original MIT-licensedgfx1013assembly snippets assembled from source at test time withllvm-mc.SCCdefinitions follow the AMD RDNA 2 Instruction Set Architecture Reference Guide.Checklist