From 939ba8292282da2f0f871c53db7157be4153beee Mon Sep 17 00:00:00 2001 From: LF2000 Builder Date: Tue, 24 Nov 2026 00:37:37 -0500 Subject: [PATCH] Shaders: print only the operands an instruction has in SP3 text The disassembly text showed operands that some instructions lack, and dropped VOP3P negation that applies to one half only: - s_memtime, s_memrealtime and s_get_waveid_in_workgroup printed the unused SMEM base and offset. - A global or scratch access with no SGPR base printed `null`, not `off`. - A MUBUF load with lds printed the unused vdata as a destination. - VOP1 SDWA printed src1_sel, though VOP1 has no second source. - VOP3P ops other than v_fma_mix with only neg_lo or only neg_hi set on a source printed as if the source were not negated. These now get LLVM's neg_lo:[..] and neg_hi:[..] suffixes; a source negated in both halves keeps `-src`. Expected operands come from llvm-mc -mcpu=gfx1030 (gfx1010 for s_get_waveid_in_workgroup). Only the text changes; translation reads Fields and is unaffected. Co-Authored-By: Claude Opus 5.5 (cherry picked from commit 6325df752c5638365c3e5a2b2f827ba0f3f145cb) --- crates/victory-shader/src/gfx10/sp3.rs | 76 ++++++++++++++++++++++++-- 1 file changed, 72 insertions(+), 4 deletions(-) diff --git a/crates/victory-shader/src/gfx10/sp3.rs b/crates/victory-shader/src/gfx10/sp3.rs index baf0e82..6f0795f 100644 --- a/crates/victory-shader/src/gfx10/sp3.rs +++ b/crates/victory-shader/src/gfx10/sp3.rs @@ -151,7 +151,11 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String { (_, 0) => soffset.to_string(), _ => format!("{soffset} offset:0x{:06x}", offset & 0x1F_FFFF), }; - out = format!("{data}, {base}, {off}"); + out = match name { + // The data is a counter or the wave ID; these have no address. + "s_memtime" | "s_memrealtime" | "s_get_waveid_in_workgroup" => data.to_string(), + _ => format!("{data}, {base}, {off}"), + }; } flags(&mut out, cache, false); } @@ -205,7 +209,12 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String { cache, } => { if let Some(data) = data { - out = format!("{data}, {addr}, {rsrc}, {soffset}"); + // An LDS load returns its data to LDS, so vdata is unused. + out = if *lds && name.contains("_load_") { + format!("{addr}, {rsrc}, {soffset}") + } else { + format!("{data}, {addr}, {rsrc}, {soffset}") + }; if *idxen { out.push_str(" idxen"); } @@ -299,7 +308,11 @@ fn operands(inst: &Instruction, name: &str, fields: &Fields) -> String { dst.iter() .map(|o| o.to_string()) .chain([addr]) - .chain(data.iter().chain(saddr).map(|o| o.to_string())), + .chain(data.iter().map(|o| o.to_string())) + .chain(saddr.map(|o| match o { + Operand::Scalar { code: NULL, .. } => "off".into(), + o => o.to_string(), + })), ); if *offset != 0 { let _ = write!(out, " inst_offset:{offset}"); @@ -590,6 +603,18 @@ fn valu(name: &str, v: &Valu, encoding: Encoding) -> String { suffix("bound_ctrl:1"); } } + if encoding == Encoding::Vop3p && !mix { + // `-src` above covers a source negated in both halves; LLVM syntax + // for the one-sided rest. + let n = v.src.len(); + for (field, only) in [("neg_lo", v.neg & !v.neg_hi), ("neg_hi", v.neg_hi & !v.neg)] { + if (0..n).any(|i| bit(only, i)) { + let bits: Vec = + (0..n).map(|i| u8::from(bit(only, i)).to_string()).collect(); + suffix(&format!("{field}:[{}]", bits.join(","))); + } + } + } if let Some(sdwa) = v.sdwa { if v.clamp { suffix("clamp"); @@ -610,7 +635,7 @@ fn valu(name: &str, v: &Valu, encoding: Encoding) -> String { unused[usize::from(sdwa.dst_unused & 3)] )); } - for (i, s) in sdwa.src_sel.iter().enumerate() { + for (i, s) in sdwa.src_sel.iter().take(v.src.len()).enumerate() { if *s != 6 { suffix(&format!("src{i}_sel:{}", sel[usize::from(s & 7)])); } @@ -840,6 +865,49 @@ mod tests { ); } + #[test] + fn one_sided_packed_negation_is_printed() { + // Encodings from llvm-mc -mcpu=gfx1030. A source negated in both + // halves keeps the `-` prefix; one-sided bits get LLVM's suffixes. + let got = [ + one(&[0xCC0F_4001, 0x1A02_0702], true), + one(&[0xCC0F_4001, 0x3A02_0702], true), + one(&[0xCC0F_4201, 0x1A02_0702], true), + one(&[0xCC0F_4101, 0x7A02_0702], true), + ]; + assert_eq!( + got, + [ + "v_pk_add_f16 v1, v2, v3", + "v_pk_add_f16 v1, v2, v3 neg_lo:[1,0]", + "v_pk_add_f16 v1, v2, v3 neg_hi:[0,1]", + "v_pk_add_f16 v1, -v2, v3 neg_lo:[0,1]", + ] + ); + } + + #[test] + fn fields_the_instruction_lacks_are_not_printed() { + // Encodings from llvm-mc -mcpu=gfx1030; s_get_waveid_in_workgroup is gfx1010 only. + let got = [ + one(&[0xF490_0500, 0], true), + one(&[0xF4A8_0140, 0], true), + one(&[0xDC30_8000, 0x007D_0002], true), + one(&[0xE031_1000, 0x0001_0001], true), + one(&[0x7E02_02F9, 0x0005_0602], true), + ]; + assert_eq!( + got, + [ + "s_memtime s[20:21]", + "s_get_waveid_in_workgroup s5", + "global_load_dword v0, v[2:3], off", + "buffer_load_dword v1, s[4:7], s0 offen lds", + "v_mov_b32 v1, v2 src0_sel:WORD_1", + ] + ); + } + #[test] fn image_d16_data_is_packed() { // Three f16 channels occupy two VGPRs; NSA lists the addresses.