gfx10: resolve the opcode name once, at decode time

`Instruction::name()` binary-searches the opcode table, and the pipeline
asks about every instruction eight times per translation: `ir::build`,
`structure`, `resource` (which has the most call sites), `io` and
`lower`. The answer cannot change - the encoding and opcode are decoded
from the words and never rewritten - so resolve it once when the
instruction is built and read the field after that.

Measured with the synthetic bench from #1002 (no game data), sixteen
interleaved rounds per arm, best of each, nanoseconds per instruction, at
256/1k/4k/16k instructions:

  resource     17 -> 9, 15 -> 7, 24 -> 16, 23 -> 15    (0.47-0.67)
  lower       511 -> 479, 428 -> 411, 440 -> 401, 477 -> 428  (0.90-0.96)
  io           27 -> 23, 26 -> 21, 26 -> 22, 30 -> 22   (0.73-0.85)
  whole       926 -> 881, 920 -> 874, 958 -> 921, 1019 -> 939 (0.92-0.96)

`decode` pays the one search it used to be spared (112 -> 115 at 16k,
inside the run-to-run spread); every stage after it reads a field. The
emitted DXIL is byte-identical at all four sizes.

cargo test --workspace --locked: 342 passed, 0 failed, 7 ignored.
Both clippy configurations clean; cargo xtask policy ok.

(cherry picked from commit 146dfef67a3ecd2c4fd8f9cff8de149c65dfe6f0)
This commit is contained in:
pes7 authored and local committed 2026-11-25 01:03:03 -06:00
1 parent 137bdb5567
commit 3729ba04d5
1 file changed
+8 -2
+8 -2
View File
@@ -56,12 +56,16 @@ pub struct Instruction {
pub opcode: u16,
/// Every dword of the instruction, including literals and extra dwords.
pub words: Vec<u32>,
/// [`name`] of `encoding` and `opcode`, resolved once at decode time.
/// The translator asks about every instruction eight times; the table is
/// a binary search.
name: Option<&'static str>,
}
impl Instruction {
/// AMD's name for the opcode, if it is in our table.
pub fn name(&self) -> Option<&'static str> {
name(self.encoding, self.opcode)
self.name
}
}
@@ -282,11 +286,13 @@ fn instruction(code: &[u8], offset: usize) -> Result<Instruction, ShaderError> {
_ => return Err(isa(offset, "unknown encoding")),
}
};
let opcode = opcode as u16;
Ok(Instruction {
offset,
encoding,
opcode: opcode as u16,
opcode,
words: (0..len).map(word).collect::<Result<_, _>>()?,
name: name(encoding, opcode),
})
}