Skip to content

Commit

Permalink
asm: remove EncodeMI helper
Browse files Browse the repository at this point in the history
* EncodeMI and EncodeM are identical after introducing explicitly
  sized memory operands
  • Loading branch information
johannst committed Dec 13, 2024
1 parent 758f014 commit f06967b
Showing 1 changed file with 4 additions and 28 deletions.
32 changes: 4 additions & 28 deletions src/asm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ impl Asm {
/// Encode a memory-immediate instruction.
pub(crate) fn encode_mi<M: Mem, T: Imm>(&mut self, opc: u8, opc_ext: u8, op1: M, op2: T)
where
Self: EncodeMI<M>,
Self: EncodeM<M>,
{
// MI operand encoding.
// op1 -> modrm.rm
Expand Down Expand Up @@ -234,8 +234,8 @@ impl Asm {
rm, /* rm */
);

let prefix = <Self as EncodeMI<M>>::legacy_prefix();
let rex = <Self as EncodeMI<M>>::rex(&op1);
let prefix = <Self as EncodeM<M>>::legacy_prefix();
let rex = <Self as EncodeM<M>>::rex(&op1);

self.emit_optional(&[prefix, rex]);
self.emit(&[opc, modrm]);
Expand Down Expand Up @@ -403,31 +403,7 @@ impl EncodeMR<Mem16> for Asm {
impl EncodeMR<Mem32> for Asm {}
impl EncodeMR<Mem64> for Asm {}

/// Encode helper for memory-immediate instructions.
pub(crate) trait EncodeMI<M: Mem> {
fn legacy_prefix() -> Option<u8> {
None
}

fn rex(op1: &M) -> Option<u8> {
if M::is_64() || op1.base().is_ext() || op1.index().is_ext() {
Some(rex(M::is_64(), 0, op1.index().idx(), op1.base().idx()))
} else {
None
}
}
}

impl EncodeMI<Mem8> for Asm {}
impl EncodeMI<Mem16> for Asm {
fn legacy_prefix() -> Option<u8> {
Some(0x66)
}
}
impl EncodeMI<Mem32> for Asm {}
impl EncodeMI<Mem64> for Asm {}

/// Encode helper for memory operand instructions.
/// Encode helper for memory perand instructions.
pub(crate) trait EncodeM<M: Mem> {
fn legacy_prefix() -> Option<u8> {
None
Expand Down

0 comments on commit f06967b

Please sign in to comment.