Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature - Adds MMX to the x86 machinecode emitter #8

Merged
merged 1 commit into from
Dec 30, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/x86.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ macro_rules! exclude_operand_sizes {
}
}

#[allow(clippy::upper_case_acronyms)]
#[allow(dead_code, clippy::upper_case_acronyms)]
#[derive(Copy, Clone, PartialEq, Eq)]
#[repr(u8)]
pub enum X86Register {
Expand All @@ -33,6 +33,14 @@ pub enum X86Register {
R13 = 13,
R14 = 14,
R15 = 15,
MM0 = 16,
MM1 = 17,
MM2 = 18,
MM3 = 19,
MM4 = 20,
MM5 = 21,
MM6 = 22,
MM7 = 23,
}
use X86Register::*;

Expand Down Expand Up @@ -266,6 +274,36 @@ impl X86Instruction {
}
}

/// Move to / from / between MMX (float mantissa)
#[allow(dead_code)]
#[inline]
pub const fn mov_mmx(size: OperandSize, source: X86Register, destination: X86Register) -> Self {
exclude_operand_sizes!(
size,
OperandSize::S0 | OperandSize::S8 | OperandSize::S16 | OperandSize::S32
);
if (destination as u8) & 16 != 0 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we write here for clarity that the bit mask tells us we have an MMX register?

// If the destination is a MMX register
Self {
size,
opcode_escape_sequence: 1,
opcode: if (source as u8) & 16 != 0 { 0x6F } else { 0x6E },
first_operand: (destination as u8) & 0xF,
second_operand: (source as u8) & 0xF,
..Self::DEFAULT
}
} else {
Self {
size,
opcode_escape_sequence: 1,
opcode: 0x7E,
first_operand: (source as u8) & 0xF,
second_operand: (destination as u8) & 0xF,
..Self::DEFAULT
}
}
}

/// Conditionally move source to destination
#[inline]
pub const fn cmov(
Expand Down
Loading