From 3729ba04d55d98858d9b7310a853d825f0b60b39 Mon Sep 17 00:00:00 2001 From: pes7 Date: Tue, 24 Nov 2026 20:20:03 +0400 Subject: [PATCH] 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) --- crates/victory-shader/src/gfx10/mod.rs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/crates/victory-shader/src/gfx10/mod.rs b/crates/victory-shader/src/gfx10/mod.rs index 57e6ea2..f89a382 100644 --- a/crates/victory-shader/src/gfx10/mod.rs +++ b/crates/victory-shader/src/gfx10/mod.rs @@ -56,12 +56,16 @@ pub struct Instruction { pub opcode: u16, /// Every dword of the instruction, including literals and extra dwords. pub words: Vec, + /// [`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 { _ => 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::>()?, + name: name(encoding, opcode), }) }