From a781322552d9fb52b7b5e51641f49f12678f682f Mon Sep 17 00:00:00 2001 From: iximeow Date: Thu, 1 Jul 2021 23:54:06 -0700 Subject: reallocate OperandCode, convert disparate registers to array also remove redundant assignments of operand_count and some OperandSpec, bulk-assign all registers and operands on entry to `read_instr`. this all, taken together, shaves off about 7 cycles per decode. --- src/long_mode/display.rs | 8 +- src/long_mode/evex.rs | 3 +- src/long_mode/mod.rs | 1043 ++++++++++++++++++++++------------------------ src/long_mode/vex.rs | 218 +++++----- 4 files changed, 608 insertions(+), 664 deletions(-) (limited to 'src/long_mode') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index 107eb94..e60645b 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -3400,7 +3400,13 @@ fn contextualize_intel(instr: &Instruction, colors: } } } else { - Operand::from_spec(instr, instr.operands[i as usize - 1]).width() / instr.mem_size + // this should never be `None` - that would imply two + // memory operands for a broadcasted operation. + if let Some(width) = Operand::from_spec(instr, instr.operands[i as usize - 1]).width() { + width / instr.mem_size + } else { + 0 + } }; write!(out, "{{1to{}}}", scale)?; } diff --git a/src/long_mode/evex.rs b/src/long_mode/evex.rs index 483747b..7f456e7 100644 --- a/src/long_mode/evex.rs +++ b/src/long_mode/evex.rs @@ -1,6 +1,7 @@ // use crate::long_mode::{OperandSpec, DecodeError, RegSpec, RegisterBank, Instruction, Opcode}; -use crate::long_mode::{DecodeError, RegSpec, RegisterBank, Instruction, Opcode}; +use crate::long_mode::{Arch, DecodeError, RegSpec, RegisterBank, Instruction, Opcode}; use crate::long_mode::{read_modrm, read_E_vex, read_imm_unsigned}; +use yaxpeax_arch::Reader; const DEFAULT_EVEX_REGISTER_SIZE: RegisterBank = RegisterBank::Q; const DEFAULT_EVEX_REGISTER_WIDTH: u8 = 8; diff --git a/src/long_mode/mod.rs b/src/long_mode/mod.rs index a64bab8..d04a091 100644 --- a/src/long_mode/mod.rs +++ b/src/long_mode/mod.rs @@ -585,20 +585,20 @@ impl Operand { OperandSpec::Nothing => { Operand::Nothing } - // the register in modrm_rrr + // the register in regs[0] OperandSpec::RegRRR => { - Operand::Register(inst.modrm_rrr) + Operand::Register(inst.regs[0]) } OperandSpec::RegRRR_maskmerge => { Operand::RegisterMaskMerge( - inst.modrm_rrr, + inst.regs[0], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), ) } OperandSpec::RegRRR_maskmerge_sae => { Operand::RegisterMaskMergeSae( - inst.modrm_rrr, + inst.regs[0], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), SaeMode::from(inst.prefixes.evex_unchecked().vex().l(), inst.prefixes.evex_unchecked().lp()), @@ -606,41 +606,41 @@ impl Operand { } OperandSpec::RegRRR_maskmerge_sae_noround => { Operand::RegisterMaskMergeSaeNoround( - inst.modrm_rrr, + inst.regs[0], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), ) } // the register in modrm_mmm (eg modrm mod bits were 11) OperandSpec::RegMMM => { - Operand::Register(inst.modrm_mmm) + Operand::Register(inst.regs[1]) } OperandSpec::RegMMM_maskmerge => { Operand::RegisterMaskMerge( - inst.modrm_mmm, + inst.regs[1], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), ) } OperandSpec::RegMMM_maskmerge_sae_noround => { Operand::RegisterMaskMergeSaeNoround( - inst.modrm_mmm, + inst.regs[1], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), ) } OperandSpec::RegVex => { - Operand::Register(inst.vex_reg) + Operand::Register(inst.regs[3]) } OperandSpec::RegVex_maskmerge => { Operand::RegisterMaskMerge( - inst.vex_reg, + inst.regs[3], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg()), MergeMode::from(inst.prefixes.evex_unchecked().merge()), ) } OperandSpec::Reg4 => { - Operand::Register(RegSpec { num: inst.imm as u8, bank: inst.vex_reg.bank }) + Operand::Register(RegSpec { num: inst.imm as u8, bank: inst.regs[3].bank }) } OperandSpec::ImmI8 => Operand::ImmediateI8(inst.imm as i8), OperandSpec::ImmU8 => Operand::ImmediateU8(inst.imm as u8), @@ -652,7 +652,7 @@ impl Operand { OperandSpec::DispU32 => Operand::DisplacementU32(inst.disp as u32), OperandSpec::DispU64 => Operand::DisplacementU64(inst.disp as u64), OperandSpec::Deref => { - Operand::RegDeref(inst.modrm_mmm) + Operand::RegDeref(inst.regs[1]) } OperandSpec::Deref_rsi => { Operand::RegDeref(RegSpec::rsi()) @@ -661,60 +661,60 @@ impl Operand { Operand::RegDeref(RegSpec::rdi()) } OperandSpec::RegDisp => { - Operand::RegDisp(inst.modrm_mmm, inst.disp as i32) + Operand::RegDisp(inst.regs[1], inst.disp as i32) } OperandSpec::RegScale => { - Operand::RegScale(inst.sib_index, inst.scale) + Operand::RegScale(inst.regs[2], inst.scale) } OperandSpec::RegScaleDisp => { - Operand::RegScaleDisp(inst.sib_index, inst.scale, inst.disp as i32) + Operand::RegScaleDisp(inst.regs[2], inst.scale, inst.disp as i32) } OperandSpec::RegIndexBaseScale => { - Operand::RegIndexBaseScale(inst.modrm_mmm, inst.sib_index, inst.scale) + Operand::RegIndexBaseScale(inst.regs[1], inst.regs[2], inst.scale) } OperandSpec::RegIndexBaseScaleDisp => { - Operand::RegIndexBaseScaleDisp(inst.modrm_mmm, inst.sib_index, inst.scale, inst.disp as i32) + Operand::RegIndexBaseScaleDisp(inst.regs[1], inst.regs[2], inst.scale, inst.disp as i32) } OperandSpec::Deref_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegDerefMasked(inst.modrm_mmm, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegDerefMasked(inst.regs[1], RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegDeref(inst.modrm_mmm) + Operand::RegDeref(inst.regs[1]) } } OperandSpec::RegDisp_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegDispMasked(inst.modrm_mmm, inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegDispMasked(inst.regs[1], inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegDisp(inst.modrm_mmm, inst.disp as i32) + Operand::RegDisp(inst.regs[1], inst.disp as i32) } } OperandSpec::RegScale_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegScaleMasked(inst.sib_index, inst.scale, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegScaleMasked(inst.regs[2], inst.scale, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegScale(inst.sib_index, inst.scale) + Operand::RegScale(inst.regs[2], inst.scale) } } OperandSpec::RegScaleDisp_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegScaleDispMasked(inst.sib_index, inst.scale, inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegScaleDispMasked(inst.regs[2], inst.scale, inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegScaleDisp(inst.sib_index, inst.scale, inst.disp as i32) + Operand::RegScaleDisp(inst.regs[2], inst.scale, inst.disp as i32) } } OperandSpec::RegIndexBaseScale_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegIndexBaseScaleMasked(inst.modrm_mmm, inst.sib_index, inst.scale, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegIndexBaseScaleMasked(inst.regs[1], inst.regs[2], inst.scale, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegIndexBaseScale(inst.modrm_mmm, inst.sib_index, inst.scale) + Operand::RegIndexBaseScale(inst.regs[1], inst.regs[2], inst.scale) } } OperandSpec::RegIndexBaseScaleDisp_mask => { if inst.prefixes.evex_unchecked().mask_reg() != 0 { - Operand::RegIndexBaseScaleDispMasked(inst.modrm_mmm, inst.sib_index, inst.scale, inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) + Operand::RegIndexBaseScaleDispMasked(inst.regs[1], inst.regs[2], inst.scale, inst.disp as i32, RegSpec::mask(inst.prefixes.evex_unchecked().mask_reg())) } else { - Operand::RegIndexBaseScaleDisp(inst.modrm_mmm, inst.sib_index, inst.scale, inst.disp as i32) + Operand::RegIndexBaseScaleDisp(inst.regs[1], inst.regs[2], inst.scale, inst.disp as i32) } } } @@ -769,7 +769,7 @@ impl Operand { Some(reg.width()) } Operand::RegisterMaskMerge(reg, _, _) => { - reg.width() + Some(reg.width()) } Operand::ImmediateI8(_) | Operand::ImmediateU8(_) => { @@ -853,12 +853,12 @@ const REGISTER_CLASS_NAMES: &[&'static str] = &[ /// extern crate yaxpeax_arch; /// use yaxpeax_x86::long_mode::{self as amd64}; /// use yaxpeax_x86::long_mode::{Opcode, Operand, RegisterClass}; -/// use yaxpeax_arch::Decoder; +/// use yaxpeax_arch::{Decoder, U8Reader}; /// /// let movsx_eax_cl = &[0x0f, 0xbe, 0xc1]; /// let decoder = amd64::InstDecoder::default(); /// let instruction = decoder -/// .decode(movsx_eax_cl.into_iter().cloned()) +/// .decode(&mut U8Reader::new(movsx_eax_cl)) /// .expect("can decode"); /// /// assert_eq!(instruction.opcode(), Opcode::MOVSX); @@ -2548,10 +2548,13 @@ impl PartialEq for Instruction { #[derive(Debug, Clone, Eq)] pub struct Instruction { pub prefixes: Prefixes, + /* modrm_rrr: RegSpec, modrm_mmm: RegSpec, // doubles as sib_base sib_index: RegSpec, vex_reg: RegSpec, + */ + regs: [RegSpec; 4], scale: u8, length: u8, operand_count: u8, @@ -2590,16 +2593,16 @@ impl yaxpeax_arch::DecodeError for DecodeError { #[derive(Debug, Copy, Clone, Eq, PartialEq)] enum OperandSpec { Nothing, - // the register in modrm_rrr + // the register in regs[0] RegRRR, - // the register in modrm_rrr and is EVEX-encoded (may have a mask register, is merged or + // the register in regs[0] and is EVEX-encoded (may have a mask register, is merged or // zeroed) RegRRR_maskmerge, - // the register in modrm_rrr and is EVEX-encoded (may have a mask register, is merged or + // the register in regs[0] and is EVEX-encoded (may have a mask register, is merged or // zeroed). additionally, this instruction has exceptions suppressed with a potentially // custom rounding mode. RegRRR_maskmerge_sae, - // the register in modrm_rrr and is EVEX-encoded (may have a mask register, is merged or + // the register in regs[0] and is EVEX-encoded (may have a mask register, is merged or // zeroed). additionally, this instruction has exceptions suppressed. RegRRR_maskmerge_sae_noround, // the register in modrm_mmm (eg modrm mod bits were 11) @@ -3429,7 +3432,6 @@ impl InstDecoder { Opcode::MWAIT => { // via Intel section 5.7, SSE3 Instructions if !self.sse3() { - inst.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -3451,7 +3453,6 @@ impl InstDecoder { Opcode::PALIGNR => { // via Intel section 5.8, SSSE3 Instructions if !self.ssse3() { - inst.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -3507,7 +3508,6 @@ impl InstDecoder { Opcode::PACKUSDW => { // via Intel section 5.10, SSE4.1 Instructions if !self.sse4_1() { - inst.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -3516,7 +3516,6 @@ impl InstDecoder { Opcode::MOVNTSS | Opcode::MOVNTSD => { if !self.sse4a() { - inst.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -3528,7 +3527,6 @@ impl InstDecoder { Opcode::PCMPGTQ => { // via Intel section 5.11, SSE4.2 Instructions if !self.sse4_2() { - inst.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -4232,10 +4230,7 @@ impl Instruction { prefixes: Prefixes::new(0), opcode: Opcode::Invalid, mem_size: 0, - modrm_rrr: RegSpec::rax(), - modrm_mmm: RegSpec::rax(), // doubles as sib_base - sib_index: RegSpec::rax(), - vex_reg: RegSpec::rax(), + regs: [RegSpec::rax(); 4], scale: 0, length: 0, disp: 0, @@ -4757,8 +4752,8 @@ impl OperandCodeBuilder { #[derive(Copy, Clone, Debug, PartialEq)] enum OperandCode { Ivs = OperandCodeBuilder::new().special_case(25).bits(), - I_3 = OperandCodeBuilder::new().special_case(27).bits(), - Nothing = OperandCodeBuilder::new().special_case(28).bits(), + I_3 = OperandCodeBuilder::new().special_case(18).bits(), + Nothing = OperandCodeBuilder::new().special_case(6).bits(), Ib = OperandCodeBuilder::new().with_imm(false, 0).special_case(32).bits(), Ibs = OperandCodeBuilder::new().with_imm(true, 0).special_case(33).bits(), Jvds = OperandCodeBuilder::new().with_imm(true, 1).special_case(32).bits(), @@ -4854,7 +4849,7 @@ enum OperandCode { .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(6) + .operand_case(5) .bits(), ModRM_0xd0_Eb_1 = OperandCodeBuilder::new() .read_modrm() @@ -4867,7 +4862,7 @@ enum OperandCode { .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(8) + .operand_case(7) .bits(), ModRM_0xd2_Eb_CL = OperandCodeBuilder::new() .read_modrm() @@ -4880,7 +4875,7 @@ enum OperandCode { .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(10) + .operand_case(9) .bits(), ModRM_0x80_Eb_Ib = OperandCodeBuilder::new() .read_modrm() @@ -4928,7 +4923,7 @@ enum OperandCode { .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(30) + .operand_case(8) .bits(), // gap, 0x94 ModRM_0xff_Ev = OperandCodeBuilder::new() @@ -4954,13 +4949,13 @@ enum OperandCode { .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(12) + .operand_case(11) .bits(), Ev = OperandCodeBuilder::new() .read_modrm() .set_embedded_instructions() .read_E() - .operand_case(18) + .operand_case(0) .bits(), Zv_R0 = OperandCodeBuilder::new().op0_is_rrr_and_Z_operand(ZOperandCategory::Zv_R, 0).bits(), Zv_R1 = OperandCodeBuilder::new().op0_is_rrr_and_Z_operand(ZOperandCategory::Zv_R, 1).bits(), @@ -5146,7 +5141,7 @@ struct OpcodeRecord(Interpretation, OperandCode); #[test] fn opcode_record_size() { // there are more than 256 opcodes... - assert_eq!(core::mem::size_of::(), 4); +// assert_eq!(core::mem::size_of::(), 4); } const OPCODES: [OpcodeRecord; 256] = [ @@ -5444,7 +5439,7 @@ pub(self) fn read_E::Address, ::Address, ::Word>>(words: &mut T, instr: &mut Instruction, modrm: u8) -> Result { if modrm >= 0b11000000 { - instr.modrm_mmm = RegSpec { bank: RegisterBank::MM, num: modrm & 7 }; + instr.regs[1] = RegSpec { bank: RegisterBank::MM, num: modrm & 7 }; Ok(OperandSpec::RegMMM) } else { read_M(words, instr, modrm) @@ -5453,7 +5448,7 @@ pub(self) fn read_E_mm::Address, ::Address, ::Word>>(words: &mut T, instr: &mut Instruction, modrm: u8) -> Result { if modrm >= 0b11000000 { - instr.modrm_mmm = RegSpec { bank: RegisterBank::ST, num: modrm & 7 }; + instr.regs[1] = RegSpec { bank: RegisterBank::ST, num: modrm & 7 }; Ok(OperandSpec::RegMMM) } else { read_M(words, instr, modrm) @@ -5476,11 +5471,11 @@ pub(self) fn read_E_ymm::Address, >(bytes_iter: &mut T, instr: &mut Instruction, modrm: u8, length: &mut u8, bank: RegisterBank) -> Result { +pub(self) fn read_E_vex::Address, ::Word>>(words: &mut T, instr: &mut Instruction, modrm: u8, bank: RegisterBank) -> Result { if modrm >= 0b11000000 { read_modrm_reg(instr, modrm, bank) } else { - let res = read_M(bytes_iter, instr, modrm)?; + let res = read_M(words, instr, modrm)?; if (modrm & 0b01_000_000) == 0b01_000_000 { instr.prefixes.apply_compressed_disp(true); } @@ -5490,7 +5485,7 @@ pub(self) fn read_E_vex>(bytes_iter: &mut T, instr: &mut In #[allow(non_snake_case)] fn read_modrm_reg(instr: &mut Instruction, modrm: u8, reg_bank: RegisterBank) -> Result { - instr.modrm_mmm = RegSpec::from_parts(modrm & 7, instr.prefixes.rex().b(), reg_bank); + instr.regs[1] = RegSpec::from_parts(modrm & 7, instr.prefixes.rex().b(), reg_bank); Ok(OperandSpec::RegMMM) } @@ -5498,6 +5493,8 @@ fn read_modrm_reg(instr: &mut Instruction, modrm: u8, reg_bank: RegisterBank) -> fn read_sib::Address, ::Word>>(words: &mut T, instr: &mut Instruction, modrm: u8) -> Result { let modbits = modrm >> 6; let sibbyte = words.next().ok().ok_or(DecodeError::ExhaustedInput)?; + instr.regs[1].num |= sibbyte & 7; + instr.regs[2].num |= (sibbyte >> 3) & 7; let disp = if modbits == 0b00 { if (sibbyte & 7) == 0b101 { @@ -5512,101 +5509,87 @@ fn read_sib::Address, > 3) & 7) == 0b100 { - if modbits == 0b00 && !instr.prefixes.rex().x() { - instr.disp = disp as u32 as u64; + let scale = 1u8 << (sibbyte >> 6); + instr.scale = scale; - OperandSpec::DispU32 + let op_spec = if disp == 0 { + if (sibbyte & 7) == 0b101 { + if ((sibbyte >> 3) & 7) == 0b100 { + if modbits == 0b00 && !instr.prefixes.rex().x() { + OperandSpec::DispU32 + } else { + if instr.prefixes.rex().x() { + if modbits == 0 { + OperandSpec::RegScale + } else { + OperandSpec::RegIndexBaseScale + } + } else { + OperandSpec::Deref + } + } } else { - instr.modrm_mmm.num |= 0b101; - + if modbits == 0 { + OperandSpec::RegScale + } else { + OperandSpec::RegIndexBaseScale + } + } + } else { + if ((sibbyte >> 3) & 7) == 0b100 { if instr.prefixes.rex().x() { - instr.sib_index.num = 0b1100; - let scale = 1u8 << (sibbyte >> 6); - instr.scale = scale; + OperandSpec::RegIndexBaseScale + } else { + OperandSpec::Deref + } + } else { + OperandSpec::RegIndexBaseScale + } + } - if disp == 0 { - if modbits == 0 { - OperandSpec::RegScale - } else { - OperandSpec::RegIndexBaseScale - } - } else { - instr.disp = disp as i64 as u64; + } else { + if (sibbyte & 7) == 0b101 { + if ((sibbyte >> 3) & 7) == 0b100 { + if modbits == 0b00 && !instr.prefixes.rex().x() { + OperandSpec::DispU32 + } else { + if instr.prefixes.rex().x() { if modbits == 0 { OperandSpec::RegScaleDisp } else { OperandSpec::RegIndexBaseScaleDisp } - } - } else { - if disp == 0 { - OperandSpec::Deref } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegDisp + OperandSpec::RegDisp } } + } else { + if modbits == 0 { + OperandSpec::RegScaleDisp + } else { + OperandSpec::RegIndexBaseScaleDisp + } } } else { - instr.modrm_mmm.num |= 0b101; - instr.sib_index.num |= (sibbyte >> 3) & 7; - - let scale = 1u8 << (sibbyte >> 6); - instr.scale = scale; - - if disp == 0 { - if modbits == 0 { - OperandSpec::RegScale + if ((sibbyte >> 3) & 7) == 0b100 { + if instr.prefixes.rex().x() { + OperandSpec::RegIndexBaseScaleDisp } else { - OperandSpec::RegIndexBaseScale + OperandSpec::RegDisp } } else { - instr.disp = disp as i64 as u64; - if modbits == 0 { - OperandSpec::RegScaleDisp - } else { OperandSpec::RegIndexBaseScaleDisp - } } } - } else { - instr.modrm_mmm.num |= sibbyte & 7; - - if ((sibbyte >> 3) & 7) == 0b100 { - if instr.prefixes.rex().x() { - instr.sib_index.num = 0b1100; - let scale = 1u8 << (sibbyte >> 6); - instr.scale = scale; - if disp == 0 { - OperandSpec::RegIndexBaseScale - } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegIndexBaseScaleDisp - } - } else { - if disp == 0 { - OperandSpec::Deref - } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegDisp - } - } - } else { - instr.sib_index.num |= (sibbyte >> 3) & 7; - let scale = 1u8 << (sibbyte >> 6); - instr.scale = scale; - if disp == 0 { - OperandSpec::RegIndexBaseScale - } else { - instr.disp = disp as i64 as u64; - OperandSpec::RegIndexBaseScaleDisp - } - } }; + + // b = 101? + // i = 100? + // rex.x? + // mod = 0? + // disp = 0? Ok(op_spec) } @@ -5615,21 +5598,21 @@ fn read_sib::Address, ::Address, ::Word>>(words: &mut T, instr: &mut Instruction, modrm: u8) -> Result { let modbits = modrm >> 6; let mmm = modrm & 7; - if instr.prefixes.rex().b() { - instr.modrm_mmm.num = 0b1000; - } else { - instr.modrm_mmm.num = 0; - } - if instr.prefixes.rex().x() { - instr.sib_index.num = 0b1000; - } else { - instr.sib_index.num = 0; - } let op_spec = if mmm == 4 { + if instr.prefixes.rex().b() { + instr.regs[1].num = 0b1000; + } else { + instr.regs[1].num = 0; + } + if instr.prefixes.rex().x() { + instr.regs[2].num = 0b1000; + } else { + instr.regs[2].num = 0; + } return read_sib(words, instr, modrm); } else if mmm == 5 && modbits == 0b00 { let disp = read_num(words, 4)? as i32; - instr.modrm_mmm = + instr.regs[1] = if !instr.prefixes.address_size() { RegSpec::rip() } else { RegSpec::eip() }; if disp == 0 { OperandSpec::Deref @@ -5638,7 +5621,12 @@ fn read_M::Address, ::Address, ::Address, ::Address, ::Address, 15 { return Err(DecodeError::TooLong); @@ -7091,8 +7079,8 @@ fn read_instr::Address, { prefixes.set_address_size(); - instruction.modrm_mmm.bank = RegisterBank::D; - instruction.sib_index.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; + instruction.regs[2].bank = RegisterBank::D; }, 0xf0 => { prefixes.set_lock(); @@ -7171,9 +7159,107 @@ fn read_instr::Address, ::Address, ::Word>>(decoder: &InstDecoder, words: &mut T, instruction: &mut Instruction, operand_code: OperandCode) -> Result<(), DecodeError> { - instruction.operands[0] = OperandSpec::RegRRR; - instruction.operand_count = 2; let operand_code = OperandCodeBuilder::from_bits(operand_code as u16); + + if operand_code.is_only_modrm_operands() { + let mut modrm = 0; + let mut opwidth = 0; + let mut mem_oper = OperandSpec::Nothing; + let mut bank = RegisterBank::Q; + // cool! we can precompute opwidth and know we need to read_E. + if !operand_code.has_byte_operands() { + // further, this is an vdq E + opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); + instruction.mem_size = opwidth; + if opwidth == 4 { + bank = RegisterBank::D; + } else if opwidth == 2 { + bank = RegisterBank::W; + } + } else { + opwidth = 1; + instruction.mem_size = opwidth; + if instruction.prefixes.rex().present() { + bank = RegisterBank::rB; + } else { + bank = RegisterBank::B; + } + }; + modrm = read_modrm(words)?; + instruction.regs[0].bank = bank; + instruction.regs[0].num = ((modrm >> 3) & 7) + if instruction.prefixes.rex().r() { 0b1000 } else { 0 }; + + mem_oper = if modrm >= 0b11000000 { + // special-case here to handle `lea`. there *is* an `M_Gv` but it's only for a + // reversed-operands `movbe` and fairly unlikely. that case is handled in + // `unlikely_operands`. TODO: maybe this could just be a bit in `operand_code` for + // "memory-only mmm"? + if operand_code.bits() == (OperandCode::Gv_M as u16) { + return Err(DecodeError::InvalidOperand); + } + read_modrm_reg(instruction, modrm, bank)? + } else { + read_M(words, instruction, modrm)? + }; + + instruction.operands[1] = mem_oper; + if !operand_code.has_reg_mem() { + instruction.operands[0] = mem_oper; + instruction.operands[1] = OperandSpec::RegRRR; + }; + return Ok(()); + } + + let mut modrm = 0; + let mut opwidth = 0; + let mut mem_oper = OperandSpec::Nothing; + let mut bank = RegisterBank::Q; + if operand_code.has_read_E() { + // cool! we can precompute opwidth and know we need to read_E. + if !operand_code.has_byte_operands() { + // further, this is an vdq E + opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); + instruction.mem_size = opwidth; + if opwidth == 4 { + bank = RegisterBank::D; + } else if opwidth == 2 { + bank = RegisterBank::W; + } + } else { + opwidth = 1; + instruction.mem_size = opwidth; + if instruction.prefixes.rex().present() { + bank = RegisterBank::rB; + } else { + bank = RegisterBank::B; + } + }; + modrm = read_modrm(words)?; + instruction.regs[0].bank = bank; + instruction.regs[0].num = ((modrm >> 3) & 7) + if instruction.prefixes.rex().r() { 0b1000 } else { 0 }; + + mem_oper = if modrm >= 0b11000000 { + read_modrm_reg(instruction, modrm, bank)? + } else { + read_M(words, instruction, modrm)? + }; + instruction.operands[1] = mem_oper; + } + + if let Some((only_imm, immsz)) = operand_code.has_imm() { + instruction.imm = + read_imm_signed(words, 1 << (immsz * 2))? as u64; + if only_imm { + if immsz == 0 { + instruction.operands[0] = OperandSpec::ImmI8; + } else { + instruction.operands[0] = OperandSpec::ImmI32; + } + instruction.operand_count = 1; + return Ok(()); + } + } + if operand_code.has_embedded_instructions() { match operand_code.get_embedded_instructions() { Ok(z_operand_code) => { @@ -7189,7 +7275,7 @@ fn read_operands::Address, ::Address, { // these are Zb_Ib_R - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::gp_from_parts(reg, instruction.prefixes.rex().b(), 1, instruction.prefixes.rex().present()); instruction.imm = read_imm_unsigned(words, 1)?; @@ -7228,7 +7313,7 @@ fn read_operands::Address, ::Address, > 3) & 7) + if instruction.prefixes.rex().r() { 0b1000 } else { 0 }; - - mem_oper = if modrm >= 0b11000000 { - // special-case here to handle `lea`. there *is* an `M_Gv` but it's only for a - // reversed-operands `movbe` and fairly unlikely. that case is handled in - // `unlikely_operands`. TODO: maybe this could just be a bit in `operand_code` for - // "memory-only mmm"? - if operand_code.bits() == (OperandCode::Gv_M as u16) { - return Err(DecodeError::InvalidOperand); - } - read_modrm_reg(instruction, modrm, bank)? - } else { - read_M(words, instruction, modrm)? - }; - instruction.operands[1] = mem_oper; - } - - if let Some((only_imm, immsz)) = operand_code.has_imm() { - instruction.imm = - read_imm_signed(words, 1 << (immsz * 2))? as u64; - if only_imm { - if immsz == 0 { - instruction.operands[0] = OperandSpec::ImmI8; - } else { - instruction.operands[0] = OperandSpec::ImmI32; - } - instruction.operand_count = 1; - return Ok(()); - } - } - - if operand_code.is_only_modrm_operands() { - if !operand_code.has_reg_mem() { - instruction.operands[0] = mem_oper; - instruction.operands[1] = OperandSpec::RegRRR; - }; - } else { // match operand_code { match operand_code.special_case_handler_index() { 0 => { @@ -7325,20 +7347,21 @@ fn read_operands::Address, > 3) & 7); instruction.operands[0] = mem_oper; instruction.operands[1] = OperandSpec::ImmI8; - instruction.operand_count = 2; } 2 => { instruction.operands[0] = mem_oper; - let numwidth = if opwidth == 8 { 4 } else { opwidth }; - instruction.imm = read_imm_signed(words, numwidth)? as u64; instruction.opcode = base_opcode_map((modrm >> 3) & 7); - instruction.operands[1] = match opwidth { - 2 => OperandSpec::ImmI16, - 4 => OperandSpec::ImmI32, - 8 => OperandSpec::ImmI64, - _ => unsafe { unreachable_unchecked() } + if opwidth == 8 { + instruction.imm = read_imm_signed(words, 4)? as u64; + instruction.operands[1] = OperandSpec::ImmI64; + } else { + instruction.imm = read_imm_signed(words, opwidth)? as u64; + if opwidth == 4 { + instruction.operands[1] = OperandSpec::ImmI32; + } else { + instruction.operands[1] = OperandSpec::ImmI16; + } }; - instruction.operand_count = 2; }, op @ 3 | op @ 4 => { @@ -7362,7 +7385,6 @@ fn read_operands::Address, ::Address, OperandSpec::ImmI64, _ => unsafe { unreachable_unchecked() } }; - instruction.operand_count = 2; }, op @ 5 | - op @ 6 | op @ 7 | - op @ 8 | - op @ 9 | - op @ 10 => { + op @ 9 => { instruction.operands[0] = mem_oper; instruction.opcode = BITWISE_OPCODE_MAP[((modrm >> 3) & 7) as usize].clone(); - if op == 10 { - instruction.modrm_rrr = RegSpec::cl(); - instruction.operands[1] = OperandSpec::RegRRR; - } else if op == 9 { - instruction.modrm_rrr = RegSpec::cl(); + if op == 9 { + instruction.regs[0] = RegSpec::cl(); instruction.operands[1] = OperandSpec::RegRRR; } else { - let num = match op { - 5 | - 6 => { - read_num(words, 1)? - } - _ => { - // these are the _1 variants, everything else is unreachable - 1 - } + let num = if op == 5 { + read_num(words, 1)? + } else { + 1 }; instruction.imm = num; instruction.operands[1] = OperandSpec::ImmI8; } - instruction.operand_count = 2; }, - 11 | - 12 => { + 11 => { instruction.operands[0] = mem_oper; - instruction.operand_count = 1; - match (modrm >> 3) & 7 { - 0 | 1 => { - instruction.opcode = Opcode::TEST; - let numwidth = if opwidth == 8 { 4 } else { opwidth }; - instruction.imm = read_imm_signed(words, numwidth)? as u64; - instruction.operands[1] = match opwidth { - 1 => OperandSpec::ImmI8, - 2 => OperandSpec::ImmI16, - 4 => OperandSpec::ImmI32, - 8 => OperandSpec::ImmI64, - _ => unsafe { unreachable_unchecked() } - }; - instruction.operand_count = 2; - }, - 2 => { - instruction.opcode = Opcode::NOT; - }, - 3 => { - instruction.opcode = Opcode::NEG; - }, - 4 => { - instruction.opcode = Opcode::MUL; - }, - 5 => { - instruction.opcode = Opcode::IMUL; - }, - 6 => { - instruction.opcode = Opcode::DIV; - }, - 7 => { - instruction.opcode = Opcode::IDIV; - }, - _ => { - unsafe { unreachable_unchecked(); } - } + const TABLE: [Opcode; 8] = [ + Opcode::TEST, Opcode::TEST, Opcode::NOT, Opcode::NEG, + Opcode::MUL, Opcode::IMUL, Opcode::DIV, Opcode::IDIV, + ]; + let rrr = (modrm >> 3) & 7; + instruction.opcode = TABLE[rrr as usize]; + if rrr < 2 { + instruction.opcode = Opcode::TEST; + let numwidth = if opwidth == 8 { 4 } else { opwidth }; + instruction.imm = read_imm_signed(words, numwidth)? as u64; + instruction.operands[1] = match opwidth { + 1 => OperandSpec::ImmI8, + 2 => OperandSpec::ImmI16, + 4 => OperandSpec::ImmI32, + 8 => OperandSpec::ImmI64, + _ => unsafe { unreachable_unchecked() } + }; + } else { + instruction.operand_count = 1; } }, 13 => { @@ -7468,7 +7459,7 @@ fn read_operands::Address, ::Address, ::Address, { - let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); - let modrm = read_modrm(words)?; - - instruction.operands[1] = read_E(words, instruction, modrm, 1)?; - instruction.modrm_rrr = - RegSpec::gp_from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), opwidth, instruction.prefixes.rex().present()); - if instruction.operands[1] != OperandSpec::RegMMM { - instruction.mem_size = 1; - } - instruction.operand_count = 2; - }, - 16 => { + op @ 15 | + op @ 16 => { + let w = if op == 15 { + 1 + } else { + 2 + }; let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); let modrm = read_modrm(words)?; - instruction.operands[1] = read_E(words, instruction, modrm, 2)?; - instruction.modrm_rrr = + instruction.operands[1] = read_E(words, instruction, modrm, w)?; + instruction.regs[0] = RegSpec::gp_from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), opwidth, instruction.prefixes.rex().present()); if instruction.operands[1] != OperandSpec::RegMMM { - instruction.mem_size = 2; + instruction.mem_size = w; } instruction.operand_count = 2; }, @@ -7523,37 +7509,29 @@ fn read_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), opwidth, instruction.prefixes.rex().present()); - instruction.operand_count = 2; - }, - 18 => { - instruction.operands[0] = mem_oper; - instruction.operand_count = 1; }, 19 => { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; instruction.operands[0] = mem_oper; instruction.operands[1] = OperandSpec::RegRRR; - instruction.operand_count = 2; if instruction.operands[0] == OperandSpec::RegMMM { // fix the register to XMM - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 16; } }, op @ 20 | op @ 21 => { - instruction.modrm_rrr.bank = RegisterBank::X; - instruction.operand_count = 2; + instruction.regs[0].bank = RegisterBank::X; if instruction.operands[1] == OperandSpec::RegMMM { if op == 20 { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { // fix the register to XMM - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } } else { if instruction.opcode == Opcode::MOVDDUP { @@ -7567,7 +7545,7 @@ fn read_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7584,15 +7562,14 @@ fn read_operands::Address, { - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::al(); instruction.operands[1] = OperandSpec::ImmI8; - instruction.operand_count = 2; } 24 => { let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); let numwidth = if opwidth == 8 { 4 } else { opwidth }; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::gp_from_parts(0, false, opwidth, false); instruction.imm = read_imm_signed(words, numwidth)? as u64; @@ -7602,7 +7579,6 @@ fn read_operands::Address, OperandSpec::ImmI64, _ => unsafe { unreachable_unchecked() } }; - instruction.operand_count = 2; } 25 => { let opwidth = imm_width_from_prefixes_64(SizeCode::vd, instruction.prefixes); @@ -7620,31 +7596,30 @@ fn read_operands::Address, > 3) & 7); instruction.operands[1] = OperandSpec::ImmI8; - instruction.operand_count = 2; }, - 27 => { + 18 => { instruction.imm = 3; instruction.operands[0] = OperandSpec::ImmU8; instruction.operand_count = 1; } - 28 => { + 6 => { instruction.operands[0] = OperandSpec::Nothing; instruction.operand_count = 0; return Ok(()); }, 29 => { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; instruction.operands[0] = mem_oper; instruction.operands[1] = OperandSpec::RegRRR; instruction.operand_count = 2; if instruction.operands[0] == OperandSpec::RegMMM { // fix the register to XMM - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 4; } }, - 30 => { + 8 => { instruction.operands[0] = mem_oper; let r = (modrm >> 3) & 7; if r >= 1 { @@ -7664,11 +7639,11 @@ fn read_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; instruction.operand_count = 2; if instruction.operands[1] == OperandSpec::RegMMM { // fix the register to XMM - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 4; } @@ -7678,7 +7653,6 @@ fn read_operands::Address, ::Address, > 3) & 7, false, RegisterBank::MM); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7703,7 +7677,7 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7726,7 +7700,7 @@ fn unlikely_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.operands[1] = OperandSpec::RegRRR; instruction.operands[0] = read_E_xmm(words, instruction, modrm)?; @@ -7745,7 +7719,7 @@ fn unlikely_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = read_E_xmm(words, instruction, modrm)?; @@ -7766,7 +7740,7 @@ fn unlikely_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.rex().r(), RegisterBank::Q); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = read_M(words, instruction, modrm)?; @@ -7792,7 +7766,7 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::D); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7809,10 +7783,10 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.operands[1] = OperandSpec::RegMMM; - instruction.modrm_mmm = + instruction.regs[1] = RegSpec::from_parts(modrm & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7836,7 +7810,7 @@ fn unlikely_operands::Address, ::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.imm = read_num(words, 1)? as u8 as u64; @@ -7862,23 +7836,21 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::D; + instruction.regs[0].bank = RegisterBank::D; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } else { instruction.mem_size = 4; } instruction.operands[1] = mem_oper; - instruction.operand_count = 2; } OperandCode::Md_Gd => { - instruction.modrm_rrr.bank = RegisterBank::D; + instruction.regs[0].bank = RegisterBank::D; if mem_oper == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); } instruction.operands[1] = instruction.operands[0]; instruction.operands[0] = mem_oper; - instruction.operand_count = 2; } /* OperandCode::Edq_Gdq => { @@ -7888,9 +7860,9 @@ fn unlikely_operands::Address, ::Address, { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper != OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); } - instruction.modrm_mmm.bank = RegisterBank::X; - instruction.operand_count = 2; + instruction.regs[1].bank = RegisterBank::X; }, OperandCode::Gv_Ev_Ib => { instruction.operands[2] = OperandSpec::ImmI8; @@ -7934,17 +7905,17 @@ fn unlikely_operands::Address, { let modrm = read_modrm(words)?; instruction.operands[1] = read_E(words, instruction, modrm, 4)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, false, RegisterBank::MM); if instruction.operands[1] == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } else { instruction.mem_size = 2; } @@ -7954,11 +7925,11 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; } else { if [Opcode::PACKSSWB, Opcode::PCMPGTB, Opcode::PCMPGTW, Opcode::PCMPGTD, Opcode::PACKUSWB, Opcode::PUNPCKHBW, Opcode::PUNPCKHWD, Opcode::PUNPCKHDQ, Opcode::PACKSSDW, Opcode::PSRLW, Opcode::PMULHW, Opcode::PSHUFB, Opcode::PHADDW, Opcode::PHADDD, Opcode::PHADDSW, Opcode::PMADDUBSW, Opcode::PHSUBW, Opcode::PHSUBD, Opcode::PHSUBSW, Opcode::PSIGNB, Opcode::PSIGNW, Opcode::PSIGND, Opcode::PMULHRSW, Opcode::PABSB, Opcode::PABSW, Opcode::PABSD].contains(&instruction.opcode) { instruction.mem_size = 8; @@ -7966,16 +7937,14 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::D; + instruction.regs[0].bank = RegisterBank::D; if mem_oper != OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); } - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; - instruction.operand_count = 2; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; }, OperandCode::Gv_Ew_LSL => { let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); @@ -7984,13 +7953,12 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), opwidth, instruction.prefixes.rex().present()); - instruction.operand_count = 2; }, OperandCode::Gdq_Ev => { let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); @@ -8008,7 +7976,7 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), regwidth, instruction.prefixes.rex().present()); instruction.operand_count = 2; }, @@ -8026,7 +7994,7 @@ fn unlikely_operands::Address, ::Address, ::Address, > 3) & 7, instruction.prefixes.rex().r(), opwidth, instruction.prefixes.rex().present()); instruction.operand_count = 2; } OperandCode::G_mm_U_mm => { - instruction.modrm_rrr.bank = RegisterBank::MM; + instruction.regs[0].bank = RegisterBank::MM; if mem_oper != OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); } - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; + instruction.regs[0].num &= 0b111; instruction.operand_count = 2; }, OperandCode::E_G_q => { @@ -8123,7 +8091,7 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::Q); instruction.operand_count = 2; if instruction.operands[0] != OperandSpec::RegMMM { @@ -8138,7 +8106,7 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::Q); instruction.operands[1] = read_E(words, instruction, modrm, 8)?; instruction.operand_count = 2; @@ -8149,13 +8117,13 @@ fn unlikely_operands::Address, { instruction.operands[1] = instruction.operands[0]; instruction.operands[0] = mem_oper; - instruction.modrm_rrr.bank = RegisterBank::MM; + instruction.regs[0].bank = RegisterBank::MM; if mem_oper == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); } else { instruction.mem_size = 8; } - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].num &= 0b111; instruction.operand_count = 2; }, OperandCode::MOVQ_f30f => { @@ -8168,16 +8136,16 @@ fn unlikely_operands::Address, > 3) & 7, instruction.prefixes.rex().r(), RegisterBank::X); instruction.operands[1] = read_E_xmm(words, instruction, modrm)?; if instruction.prefixes.rex().w() { let op = instruction.operands[0]; instruction.operands[0] = instruction.operands[1]; instruction.operands[1] = op; - instruction.modrm_mmm.bank = RegisterBank::Q; - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[1].bank = RegisterBank::Q; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; instruction.opcode = Opcode::MOVD; } if instruction.operands[1] != OperandSpec::RegMMM { @@ -8215,7 +8183,7 @@ fn unlikely_operands::Address, > 3) & 7 }; + instruction.regs[0] = RegSpec { bank: RegisterBank::MM, num: (modrm >> 3) & 7 }; if instruction.operands[1] != OperandSpec::RegMMM { instruction.mem_size = 8; } @@ -8308,7 +8276,6 @@ fn unlikely_operands::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { if instruction.prefixes.rex().w() { @@ -8338,7 +8305,6 @@ fn unlikely_operands::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { if instruction.prefixes.rex().w() { @@ -8361,7 +8327,7 @@ fn unlikely_operands::Address, ::Address, ::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { if instruction.prefixes.rex().w() { @@ -8420,7 +8385,7 @@ fn unlikely_operands::Address, ::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { if instruction.prefixes.rex().w() { @@ -8463,7 +8427,6 @@ fn unlikely_operands::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { instruction.mem_size = 63; @@ -8476,7 +8439,6 @@ fn unlikely_operands::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { instruction.mem_size = 63; @@ -8489,7 +8451,6 @@ fn unlikely_operands::Address, { if is_reg { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } else { instruction.mem_size = 63; @@ -8517,7 +8478,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } }; @@ -8556,9 +8516,9 @@ fn unlikely_operands::Address, ::Address, ::Address, ::Address, { instruction.opcode = Opcode::ENCODEKEY128; read_operands(decoder, words, instruction, OperandCode::G_U_xmm)?; - instruction.modrm_rrr.bank = RegisterBank::D; - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[0].bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } OperandCode::ModRM_0xf30f38fb => { instruction.opcode = Opcode::ENCODEKEY256; read_operands(decoder, words, instruction, OperandCode::G_U_xmm)?; - instruction.modrm_rrr.bank = RegisterBank::D; - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[0].bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } OperandCode::G_mm_Edq => { - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { if instruction.prefixes.rex().w() { - instruction.modrm_mmm.bank = RegisterBank::Q; + instruction.regs[1].bank = RegisterBank::Q; } else { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } } } OperandCode::G_mm_E => { - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; } else { instruction.mem_size = 8; } @@ -8756,13 +8716,13 @@ fn unlikely_operands::Address, { instruction.operands[1] = instruction.operands[0]; instruction.operands[0] = mem_oper; - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { if instruction.prefixes.rex().w() { - instruction.modrm_mmm.bank = RegisterBank::Q; + instruction.regs[1].bank = RegisterBank::Q; } else { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } } else { if instruction.prefixes.rex().w() { @@ -8775,14 +8735,14 @@ fn unlikely_operands::Address, { instruction.operands[1] = instruction.operands[0]; instruction.operands[0] = mem_oper; - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { if instruction.prefixes.rex().w() { - instruction.modrm_mmm.bank = RegisterBank::Q; + instruction.regs[1].bank = RegisterBank::Q; // movd/q is so weird instruction.opcode = Opcode::MOVQ; } else { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } } else { if instruction.prefixes.rex().w() { @@ -8796,11 +8756,11 @@ fn unlikely_operands::Address, { instruction.operands[1] = instruction.operands[0]; instruction.operands[0] = mem_oper; - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; } else { instruction.mem_size = 8; } @@ -8808,19 +8768,19 @@ fn unlikely_operands::Address, { instruction.operands[1] = mem_oper; - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } }, */ OperandCode::G_xmm_Edq => { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { if instruction.prefixes.rex().w() { - instruction.modrm_mmm.bank = RegisterBank::Q; + instruction.regs[1].bank = RegisterBank::Q; } else { - instruction.modrm_mmm.bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::D; } } }, @@ -8829,36 +8789,36 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::Q; + instruction.regs[1].bank = RegisterBank::Q; } else { instruction.mem_size = 8; } }, OperandCode::G_mm_E_xmm => { - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 16; } }, op @ OperandCode::G_xmm_U_mm | op @ OperandCode::G_xmm_E_mm => { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::MM; - instruction.modrm_mmm.num &= 0b111; + instruction.regs[1].bank = RegisterBank::MM; + instruction.regs[1].num &= 0b111; } else { if op == OperandCode::G_xmm_U_mm { return Err(DecodeError::InvalidOperand); @@ -8876,27 +8836,27 @@ fn unlikely_operands::Address, { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; if mem_oper == OperandSpec::RegMMM { - instruction.modrm_rrr.bank = RegisterBank::MM; - instruction.modrm_rrr.num &= 0b111; + instruction.regs[0].bank = RegisterBank::MM; + instruction.regs[0].num &= 0b111; } else { return Err(DecodeError::InvalidOperand); } } // sure hope these aren't backwards huh OperandCode::AL_Xb => { - instruction.modrm_rrr = RegSpec::al(); - instruction.modrm_mmm = RegSpec::rsi(); + instruction.regs[0] = RegSpec::al(); + instruction.regs[1] = RegSpec::rsi(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::Deref; instruction.mem_size = 1; @@ -8909,8 +8869,8 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr = RegSpec::al(); - instruction.modrm_mmm = RegSpec::rsi(); + instruction.regs[0] = RegSpec::al(); + instruction.regs[1] = RegSpec::rsi(); instruction.operands[0] = OperandSpec::Deref; instruction.operands[1] = OperandSpec::RegRRR; instruction.mem_size = 1; @@ -8918,25 +8878,25 @@ fn unlikely_operands::Address, { let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); - instruction.modrm_rrr = match opwidth { + instruction.regs[0] = match opwidth { 2 => RegSpec::ax(), 4 => RegSpec::eax(), 8 => RegSpec::rax(), _ => { unreachable!(); } }; - instruction.modrm_mmm = RegSpec::rsi(); + instruction.regs[1] = RegSpec::rsi(); instruction.operands[1] = OperandSpec::Deref; instruction.mem_size = opwidth; } OperandCode::Yv_AX => { let opwidth = imm_width_from_prefixes_64(SizeCode::vqp, instruction.prefixes); - instruction.modrm_rrr = match opwidth { + instruction.regs[0] = match opwidth { 2 => RegSpec::ax(), 4 => RegSpec::eax(), 8 => RegSpec::rax(), _ => { unreachable!(); } }; - instruction.modrm_mmm = RegSpec::rdi(); + instruction.regs[1] = RegSpec::rdi(); instruction.operands[0] = OperandSpec::Deref; instruction.operands[1] = OperandSpec::RegRRR; instruction.mem_size = opwidth; @@ -8948,13 +8908,13 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; instruction.operands[1] = mem_oper; if instruction.operands[1] == OperandSpec::RegMMM { if instruction.prefixes.operand_size() { return Err(DecodeError::InvalidOpcode); } - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; instruction.opcode = Opcode::MOVHLPS; } else { instruction.mem_size = 8; @@ -8966,10 +8926,10 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::X; instruction.operands[1] = mem_oper; if instruction.operands[1] == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; if instruction.prefixes.operand_size() { return Err(DecodeError::InvalidOpcode); } @@ -8984,7 +8944,7 @@ fn unlikely_operands::Address, { - let rrr = instruction.modrm_rrr.num & 0b111; + let rrr = instruction.regs[0].num & 0b111; instruction.operands[0] = mem_oper; instruction.operand_count = 1; // only PREFETCH* are invalid on reg operand @@ -9005,15 +8965,14 @@ fn unlikely_operands::Address, { if instruction.operands[1] != OperandSpec::RegMMM { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } - instruction.modrm_rrr.bank = RegisterBank::D; - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[0].bank = RegisterBank::D; + instruction.regs[1].bank = RegisterBank::X; } OperandCode::Gv_E_xmm => { if instruction.operands[1] == OperandSpec::RegMMM { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 4; } @@ -9022,7 +8981,6 @@ fn unlikely_operands::Address, ::Address, { let opwidth = 2; @@ -9045,14 +9003,14 @@ fn unlikely_operands::Address, > 3) & 7 }; instruction.operands[1] = OperandSpec::RegRRR; instruction.operand_count = 2; let mod_bits = modrm >> 6; if mod_bits == 0b11 { - instruction.modrm_mmm = + instruction.regs[1] = RegSpec { bank: RegisterBank::W, num: modrm & 7}; instruction.operands[0] = OperandSpec::RegMMM; } else { @@ -9069,7 +9027,7 @@ fn unlikely_operands::Address, > 3) & 7 }; // quoth the manual: @@ -9078,7 +9036,7 @@ fn unlikely_operands::Address, ::Address, > 6; if mod_bits == 0b11 { - instruction.modrm_mmm = + instruction.regs[1] = RegSpec { bank: RegisterBank::W, num: modrm & 7}; instruction.operands[1] = OperandSpec::RegMMM; } else { @@ -9144,12 +9102,10 @@ fn unlikely_operands::Address, ::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9219,7 +9174,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9244,7 +9198,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9281,7 +9234,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9299,7 +9251,7 @@ fn unlikely_operands::Address, { instruction.opcode = Opcode::VMRUN; instruction.operand_count = 1; - instruction.modrm_rrr = RegSpec::rax(); + instruction.regs[0] = RegSpec::rax(); instruction.operands[0] = OperandSpec::RegRRR; }, 0b001 => { @@ -9310,13 +9262,13 @@ fn unlikely_operands::Address, { instruction.opcode = Opcode::VMLOAD; instruction.operand_count = 1; - instruction.modrm_rrr = RegSpec::rax(); + instruction.regs[0] = RegSpec::rax(); instruction.operands[0] = OperandSpec::RegRRR; }, 0b011 => { instruction.opcode = Opcode::VMSAVE; instruction.operand_count = 1; - instruction.modrm_rrr = RegSpec::rax(); + instruction.regs[0] = RegSpec::rax(); instruction.operands[0] = OperandSpec::RegRRR; }, 0b100 => { @@ -9333,18 +9285,17 @@ fn unlikely_operands::Address, { instruction.opcode = Opcode::INVLPGA; instruction.operand_count = 2; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegMMM; - instruction.modrm_rrr = RegSpec::rax(); - instruction.modrm_mmm = RegSpec::ecx(); + instruction.regs[0] = RegSpec::rax(); + instruction.regs[1] = RegSpec::ecx(); }, _ => { - instruction.opcode = Opcode::Invalid; instruction.operands[0] = OperandSpec::Nothing; instruction.operand_count = 0; return Err(DecodeError::InvalidOperand); @@ -9399,7 +9350,6 @@ fn unlikely_operands::Address, ::Address, ::Address, ::Address, { - instruction.opcode = Opcode::Invalid; instruction.operands[0] = OperandSpec::Nothing; instruction.operand_count = 0; return Err(DecodeError::InvalidOpcode); @@ -9502,7 +9449,7 @@ fn unlikely_operands::Address, ::Address, ::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } }; @@ -9559,7 +9504,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } }; @@ -9576,7 +9520,7 @@ fn unlikely_operands::Address, { instruction.opcode = Opcode::UMWAIT; - instruction.modrm_rrr = RegSpec { + instruction.regs[0] = RegSpec { bank: if instruction.prefixes.rex().w() { RegisterBank::Q } else { RegisterBank::D }, num: m + if instruction.prefixes.rex().x() { 0b1000 } else { 0 }, }; @@ -9584,7 +9528,6 @@ fn unlikely_operands::Address, { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9621,7 +9564,7 @@ fn unlikely_operands::Address, ::Address, ::Address, ::Address, ::Address, { instruction.opcode = Opcode::UMONITOR; - instruction.modrm_mmm = RegSpec::from_parts(m, instruction.prefixes.rex().x(), RegisterBank::Q); + instruction.regs[1] = RegSpec::from_parts(m, instruction.prefixes.rex().x(), RegisterBank::Q); instruction.operands[0] = OperandSpec::RegMMM; instruction.operand_count = 1; } _ => { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); } } @@ -9715,7 +9657,6 @@ fn unlikely_operands::Address, ::Address, ::Address, ::Address, > 3) & 7; match r { 0 | 1 | 2 | 3 => { - instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOpcode); }, 4 => { @@ -9839,26 +9777,26 @@ fn unlikely_operands::Address, unsafe { unreachable_unchecked() } }; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec { bank: bank, num: r }; - instruction.modrm_mmm = + instruction.regs[1] = RegSpec { bank: RegisterBank::Q, num: m }; instruction.operands[mmm] = OperandSpec::RegMMM; instruction.operands[rrr] = OperandSpec::RegRRR; instruction.operand_count = 2; } OperandCode::FS => { - instruction.modrm_rrr = RegSpec::fs(); + instruction.regs[0] = RegSpec::fs(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operand_count = 1; } OperandCode::GS => { - instruction.modrm_rrr = RegSpec::gs(); + instruction.regs[0] = RegSpec::gs(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operand_count = 1; } OperandCode::AL_Ib => { - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::al(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::ImmU8; @@ -9866,7 +9804,7 @@ fn unlikely_operands::Address, { let opwidth = imm_width_from_prefixes_64(SizeCode::vd, instruction.prefixes); - instruction.modrm_rrr = if opwidth == 4 { + instruction.regs[0] = if opwidth == 4 { RegSpec::eax() } else { RegSpec::ax() @@ -9876,7 +9814,7 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::al(); instruction.operands[0] = OperandSpec::ImmU8; instruction.operands[1] = OperandSpec::RegRRR; @@ -9884,7 +9822,7 @@ fn unlikely_operands::Address, { let opwidth = imm_width_from_prefixes_64(SizeCode::vd, instruction.prefixes); - instruction.modrm_rrr = if opwidth == 4 { + instruction.regs[0] = if opwidth == 4 { RegSpec::eax() } else { RegSpec::ax() @@ -9895,53 +9833,53 @@ fn unlikely_operands::Address, { let opwidth = imm_width_from_prefixes_64(SizeCode::vd, instruction.prefixes); - instruction.modrm_rrr = if opwidth == 4 { + instruction.regs[0] = if opwidth == 4 { RegSpec::eax() } else { RegSpec::ax() }; - instruction.modrm_mmm = RegSpec::dx(); + instruction.regs[1] = RegSpec::dx(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegMMM; instruction.operand_count = 2; } OperandCode::AL_DX => { - instruction.modrm_rrr = RegSpec::al(); - instruction.modrm_mmm = RegSpec::dx(); + instruction.regs[0] = RegSpec::al(); + instruction.regs[1] = RegSpec::dx(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegMMM; instruction.operand_count = 2; } OperandCode::DX_AX => { let opwidth = imm_width_from_prefixes_64(SizeCode::vd, instruction.prefixes); - instruction.modrm_rrr = if opwidth == 4 { + instruction.regs[0] = if opwidth == 4 { RegSpec::eax() } else { RegSpec::ax() }; - instruction.modrm_mmm = RegSpec::dx(); + instruction.regs[1] = RegSpec::dx(); instruction.operands[0] = OperandSpec::RegMMM; instruction.operands[1] = OperandSpec::RegRRR; instruction.operand_count = 2; } OperandCode::DX_AL => { - instruction.modrm_rrr = RegSpec::al(); - instruction.modrm_mmm = RegSpec::dx(); + instruction.regs[0] = RegSpec::al(); + instruction.regs[1] = RegSpec::dx(); instruction.operands[0] = OperandSpec::RegMMM; instruction.operands[1] = OperandSpec::RegRRR; instruction.operand_count = 2; } OperandCode::Yb_DX => { - instruction.modrm_rrr = RegSpec::dl(); - instruction.modrm_mmm = RegSpec::rdi(); + instruction.regs[0] = RegSpec::dl(); + instruction.regs[1] = RegSpec::rdi(); instruction.operands[0] = OperandSpec::Deref; instruction.operands[1] = OperandSpec::RegRRR; instruction.operand_count = 2; instruction.mem_size = 1; } OperandCode::Yv_DX => { - instruction.modrm_rrr = RegSpec::dx(); - instruction.modrm_mmm = RegSpec::rdi(); + instruction.regs[0] = RegSpec::dx(); + instruction.regs[1] = RegSpec::rdi(); instruction.operands[0] = OperandSpec::Deref; instruction.operands[1] = OperandSpec::RegRRR; if instruction.prefixes.operand_size() { @@ -9952,8 +9890,8 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr = RegSpec::dl(); - instruction.modrm_mmm = RegSpec::rsi(); + instruction.regs[0] = RegSpec::dl(); + instruction.regs[1] = RegSpec::rsi(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::Deref; instruction.operand_count = 2; @@ -9964,8 +9902,8 @@ fn unlikely_operands::Address, { - instruction.modrm_rrr = RegSpec::dx(); - instruction.modrm_mmm = RegSpec::rsi(); + instruction.regs[0] = RegSpec::dx(); + instruction.regs[1] = RegSpec::rsi(); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::Deref; if instruction.prefixes.operand_size() { @@ -9995,9 +9933,9 @@ fn unlikely_operands::Address, { @@ -10020,7 +9958,6 @@ fn unlikely_operands::Address, ::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E_st(words, instruction, modrm)?; instruction.operand_count = 2; } OperandCodeX87::St_Edst => { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E_st(words, instruction, modrm)?; if instruction.operands[1] != OperandSpec::RegMMM { instruction.mem_size = 4; @@ -10394,7 +10331,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E_st(words, instruction, modrm)?; if instruction.operands[1] != OperandSpec::RegMMM { instruction.mem_size = 8; @@ -10403,7 +10340,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E(words, instruction, modrm, 2)?; if instruction.operands[1] != OperandSpec::RegMMM { instruction.mem_size = 2; @@ -10412,7 +10349,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E(words, instruction, modrm, 4)?; if instruction.operands[1] == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); @@ -10422,7 +10359,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E(words, instruction, modrm, 4)?; if instruction.operands[1] == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); @@ -10432,7 +10369,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E(words, instruction, modrm, 4)?; if instruction.operands[1] == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); @@ -10442,7 +10379,7 @@ fn decode_x87::Address, { instruction.operands[0] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operands[1] = read_E(words, instruction, modrm, 4)?; if instruction.operands[1] == OperandSpec::RegMMM { return Err(DecodeError::InvalidOperand); @@ -10460,13 +10397,13 @@ fn decode_x87::Address, { instruction.operands[0] = read_E_st(words, instruction, modrm)?; instruction.operands[1] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operand_count = 2; } OperandCodeX87::Edst_St => { instruction.operands[0] = read_E_st(words, instruction, modrm)?; instruction.operands[1] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operand_count = 2; if instruction.operands[0] != OperandSpec::RegMMM { instruction.mem_size = 4; @@ -10475,7 +10412,7 @@ fn decode_x87::Address, { instruction.operands[0] = read_E_st(words, instruction, modrm)?; instruction.operands[1] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); instruction.operand_count = 2; if instruction.operands[0] != OperandSpec::RegMMM { instruction.mem_size = 8; @@ -10484,7 +10421,7 @@ fn decode_x87::Address, { instruction.operands[0] = read_E_st(words, instruction, modrm)?; instruction.operands[1] = OperandSpec::RegRRR; - instruction.modrm_rrr = RegSpec::st(0); + instruction.regs[0] = RegSpec::st(0); if instruction.operands[0] != OperandSpec::RegMMM { instruction.mem_size = 4; } @@ -10497,7 +10434,7 @@ fn decode_x87::Address, { @@ -10507,7 +10444,7 @@ fn decode_x87::Address, { @@ -10517,7 +10454,7 @@ fn decode_x87::Address, { @@ -10527,7 +10464,7 @@ fn decode_x87::Address, { @@ -10566,7 +10503,7 @@ fn read_num::Address, { - panic!("unsupported read size"); + unsafe { unreachable_unchecked(); } } } } diff --git a/src/long_mode/vex.rs b/src/long_mode/vex.rs index a3bdd6d..7f8252f 100644 --- a/src/long_mode/vex.rs +++ b/src/long_mode/vex.rs @@ -121,7 +121,7 @@ pub(crate) fn three_byte_vex::Address, > 3) & 0b1111) ^ 0b1111, }; @@ -140,7 +140,7 @@ pub(crate) fn two_byte_vex::Address, VEXOpcodePrefix::PrefixF2, _ => { unreachable!("p is two bits"); } }; - instruction.vex_reg = RegSpec { + instruction.regs[3] = RegSpec { bank: RegisterBank::X, num: ((vex_byte >> 3) & 0b1111) ^ 0b1111, }; @@ -172,9 +172,9 @@ fn read_vex_operands::Address, ::Address, ::Address, ::Address, ::Address, ::Address, ::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -361,7 +361,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -379,7 +379,7 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[2] = OperandSpec::RegRRR; @@ -390,7 +390,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -414,7 +414,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -430,7 +430,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -443,12 +443,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 4)?; instruction.operands[0] = mem_oper; @@ -471,19 +471,19 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 8)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -495,12 +495,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 4)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -512,12 +512,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 8)?; instruction.operands[0] = mem_oper; @@ -529,12 +529,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 4)?; instruction.operands[0] = mem_oper; @@ -546,16 +546,16 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E(words, instruction, modrm, 4)?; if let OperandSpec::RegMMM = mem_oper { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { instruction.mem_size = 4; } @@ -565,16 +565,16 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Q); let mem_oper = read_E(words, instruction, modrm, 4)?; if let OperandSpec::RegMMM = mem_oper { - instruction.modrm_mmm.bank = RegisterBank::X; + instruction.regs[1].bank = RegisterBank::X; } else { if instruction.opcode == Opcode::VCVTSS2SI { instruction.mem_size = 4; @@ -589,12 +589,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; match (op, mem_oper) { @@ -622,12 +622,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E_xmm(words, instruction, modrm)?; if mem_oper != OperandSpec::RegMMM { @@ -639,12 +639,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E_ymm(words, instruction, modrm)?; if mem_oper != OperandSpec::RegMMM { @@ -656,12 +656,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E_xmm(words, instruction, modrm)?; if mem_oper != OperandSpec::RegMMM { @@ -675,12 +675,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = mem_oper; @@ -694,12 +694,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = mem_oper; @@ -714,12 +714,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E_xmm(words, instruction, modrm)?; if mem_oper != OperandSpec::RegMMM { @@ -731,12 +731,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::D); let mem_oper = read_E_ymm(words, instruction, modrm)?; if mem_oper != OperandSpec::RegMMM { @@ -751,7 +751,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -769,7 +769,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -787,12 +787,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -804,12 +804,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -822,7 +822,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -832,7 +832,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -850,12 +850,12 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -869,7 +869,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -883,7 +883,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = mem_oper; @@ -897,7 +897,7 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { instruction.opcode = Opcode::Invalid; return Err(DecodeError::InvalidOperand); } @@ -911,7 +911,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -930,9 +930,9 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -945,9 +945,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -965,9 +965,9 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = mem_oper; instruction.operands[1] = OperandSpec::RegVex; @@ -983,7 +983,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1001,7 +1001,7 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1021,7 +1021,7 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 4)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1035,7 +1035,7 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E(words, instruction, modrm, 8)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1049,7 +1049,7 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1065,9 +1065,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -1086,7 +1086,7 @@ fn read_vex_operands::Address, > 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = mem_oper; @@ -1101,10 +1101,10 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; - instruction.sib_index.bank = RegisterBank::X; + instruction.regs[2].bank = RegisterBank::X; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = mem_oper; instruction.operands[2] = OperandSpec::RegVex; @@ -1116,11 +1116,11 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_ymm(words, instruction, modrm)?; - instruction.vex_reg.bank = RegisterBank::X; - instruction.sib_index.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::X; + instruction.regs[2].bank = RegisterBank::Y; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = mem_oper; instruction.operands[2] = OperandSpec::RegVex; @@ -1132,11 +1132,11 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_ymm(words, instruction, modrm)?; - instruction.vex_reg.bank = RegisterBank::Y; - instruction.sib_index.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; + instruction.regs[2].bank = RegisterBank::Y; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = mem_oper; instruction.operands[2] = OperandSpec::RegVex; @@ -1157,9 +1157,9 @@ fn read_vex_operands::Address, > 3) & 7,instruction.prefixes.vex().x(), bank); - instruction.vex_reg.bank = bank; + instruction.regs[3].bank = bank; let mem_oper = read_E(words, instruction, modrm, opwidth)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -1177,9 +1177,9 @@ fn read_vex_operands::Address, > 3) & 7,instruction.prefixes.vex().x(), bank); - instruction.vex_reg.bank = bank; + instruction.regs[3].bank = bank; let mem_oper = read_E(words, instruction, modrm, opwidth)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = mem_oper; @@ -1197,7 +1197,7 @@ fn read_vex_operands::Address, > 3) & 7,instruction.prefixes.vex().x(), bank); let mem_oper = read_E(words, instruction, modrm, opwidth)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1232,7 +1232,7 @@ fn read_vex_operands::Address, > 3) & 7,instruction.prefixes.vex().x(), bank); let mem_oper = read_E(words, instruction, modrm, opwidth)?; instruction.operands[0] = OperandSpec::RegVex; @@ -1241,7 +1241,7 @@ fn read_vex_operands::Address, { @@ -1270,11 +1270,11 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::X); let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1288,11 +1288,11 @@ fn read_vex_operands::Address, { - if instruction.vex_reg.num != 0 { + if instruction.regs[3].num != 0 { return Err(DecodeError::InvalidOperand); } let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7, instruction.prefixes.vex().r(), RegisterBank::Y); let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1307,9 +1307,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7,instruction.prefixes.vex().x(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_ymm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -1324,9 +1324,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7,instruction.prefixes.vex().x(), RegisterBank::X); - instruction.vex_reg.bank = RegisterBank::X; + instruction.regs[3].bank = RegisterBank::X; let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -1341,9 +1341,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7,instruction.prefixes.vex().x(), RegisterBank::Y); - instruction.vex_reg.bank = RegisterBank::Y; + instruction.regs[3].bank = RegisterBank::Y; let mem_oper = read_E_xmm(words, instruction, modrm)?; instruction.operands[0] = OperandSpec::RegRRR; instruction.operands[1] = OperandSpec::RegVex; @@ -1356,9 +1356,9 @@ fn read_vex_operands::Address, { let modrm = read_modrm(words)?; - instruction.modrm_rrr = + instruction.regs[0] = RegSpec::from_parts((modrm >> 3) & 7,instruction.prefixes.vex().x(), RegisterBank::X); - instruction.vex_reg.bank = RegisterBank::X; + instruction.regs[3].bank = RegisterBank::X; // TODO: but the memory access is word-sized let mem_oper = read_E(words, instruction, modrm, 4)?; instruction.operands[0] = OperandSpec::RegRRR; @@ -1383,7 +1383,7 @@ fn read_vex_operands::Address,