aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2022-04-21 02:27:38 -0700
committeriximeow <me@iximeow.net>2022-05-30 11:16:52 -0700
commit2444de11c44a61ef136fb1fbfc0d01c5b44c042a (patch)
tree3f78b27c5831348e7fb429e5b0287478e7d8b4c0
parent093781f2652416c28927c76b9ada05ba6450b330 (diff)
replace size lookup logic with a LUT
the match compiled into some indirect branch awfulness!! no thank you
-rw-r--r--src/long_mode/mod.rs19
1 files changed, 12 insertions, 7 deletions
diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs
index 2f3e510..5073c7d 100644
--- a/src/long_mode/mod.rs
+++ b/src/long_mode/mod.rs
@@ -6061,13 +6061,18 @@ fn read_M<
#[inline]
fn width_to_gp_reg_bank(width: u8, rex: bool) -> RegisterBank {
- match width {
- 1 => return if rex { RegisterBank::rB } else { RegisterBank::B },
- 2 => return RegisterBank::W,
- 4 => return RegisterBank::D,
- 8 => return RegisterBank::Q,
- _ => unsafe { unreachable_unchecked(); }
- }
+ // transform (width, rex) into an index into an index into a LUT, instead of branching as
+ // `match` would.
+ let index = (width.trailing_zeros() << 1) | (rex as u32);
+
+ const BANK_LUT: [RegisterBank; 8] = [
+ RegisterBank::B, RegisterBank::rB,
+ RegisterBank::W, RegisterBank::W,
+ RegisterBank::D, RegisterBank::D,
+ RegisterBank::Q, RegisterBank::Q,
+ ];
+
+ *BANK_LUT.get(index as usize).unwrap_or_else(|| unsafe { unreachable_unchecked() })
}
fn read_0f_opcode(opcode: u8, prefixes: &mut Prefixes) -> OpcodeRecord {