From 3cc7541e0b6229b08d475a009147402249e3c37d Mon Sep 17 00:00:00 2001 From: marquezini Date: Mon, 23 Nov 2026 09:07:02 -0300 Subject: [PATCH] xshader: GFX10 FLAT opcode 0x0e is load_dwordx4, 0x0f is load_dwordx3 The FLAT/GLOBAL table had the two swapped. GFX10 uses the same order as MUBUF (LLVM FLATInstructions.td, FLAT_Real_Base_gfx10 and FLAT_Real_AllAddr_gfx10). A global_load_dwordx3 from a code-section table was translated as four loads and also overwrote the register after its destination range; a dwordx4 load left its last register unwritten. --- crates/tombox-xshader/src/rdna2/mnem.rs | 4 ++-- crates/tombox-xshader/tests/synthetic.rs | 26 ++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/crates/tombox-xshader/src/rdna2/mnem.rs b/crates/tombox-xshader/src/rdna2/mnem.rs index 1583e13..bb8063d 100644 --- a/crates/tombox-xshader/src/rdna2/mnem.rs +++ b/crates/tombox-xshader/src/rdna2/mnem.rs @@ -290,8 +290,8 @@ pub fn lookup(enc: Enc, op: u32) -> Option<&'static str> { Enc::Flat => match op & 0x7f { 0x0c => Some("flat_load_dword"), 0x0d => Some("flat_load_dwordx2"), - 0x0e => Some("flat_load_dwordx3"), - 0x0f => Some("flat_load_dwordx4"), + 0x0e => Some("flat_load_dwordx4"), + 0x0f => Some("flat_load_dwordx3"), _ => None, }, Enc::Ds => match op { diff --git a/crates/tombox-xshader/tests/synthetic.rs b/crates/tombox-xshader/tests/synthetic.rs index 950ebde..52c53b6 100644 --- a/crates/tombox-xshader/tests/synthetic.rs +++ b/crates/tombox-xshader/tests/synthetic.rs @@ -447,3 +447,29 @@ fn one_wave_compute_lds_phases_get_group_barriers() { let t = translate(&ex).expect("translate"); assert!(!t.hlsl.contains("wave_lds_sync"), "{}", t.hlsl); } + +/// GFX10 FLAT/GLOBAL opcode 0x0e is `load_dwordx4` and 0x0f is `load_dwordx3` (the same +/// order as MUBUF; LLVM `FLATInstructions.td`, `FLAT_Real_Base_gfx10` and +/// `FLAT_Real_AllAddr_gfx10`). With the two swapped, a dwordx3 load from a code-section +/// table also overwrote the register after its destination range. +#[test] +fn global_load_dwordx3_and_dwordx4_write_their_own_register_count() { + for (op, mnemonic, count) in [(0x0e_u32, "flat_load_dwordx4", 4u8), (0x0f, "flat_load_dwordx3", 3)] { + let words = [ + 0xbe80_1f00, // s_getpc_b64 s[0:1] + 0x7e00_0200, // v_mov_b32 v0, s0 + 0x7e02_0201, // v_mov_b32 v1, s1 + 0xdc00_8000 | op << 18, 0x047d_0000, // global_load_dwordx{4,3} v[4:..], v[0:1], off + 0xbf8c_0000, // s_waitcnt 0 + S_ENDPGM, + ]; + let ex = shader(Stage::Compute, &words, vec![], vec![], None); + let t = translate(&ex).expect("translate"); + for v in 4..8u8 { + let written = t.hlsl.contains(&format!("v{v} = t")); + assert_eq!(written, v < 4 + count, "{mnemonic} (op {op:#x}) and v{v} +{}", t.hlsl); + } + assert_eq!(tombox_xshader::rdna2::disassemble(&ex.isa)[3].mnemonic, mnemonic); + } +}