[machinst x64]: calculate extension modes in one place
This commit is contained in:
@@ -760,6 +760,19 @@ pub enum ExtMode {
|
||||
}
|
||||
|
||||
impl ExtMode {
|
||||
/// Calculate the `ExtMode` from passed bit lengths of the from/to types.
|
||||
pub(crate) fn new(from_bits: u16, to_bits: u16) -> Option<ExtMode> {
|
||||
match (from_bits, to_bits) {
|
||||
(1, 8) | (1, 16) | (1, 32) | (8, 16) | (8, 32) => Some(ExtMode::BL),
|
||||
(1, 64) | (8, 64) => Some(ExtMode::BQ),
|
||||
(16, 32) => Some(ExtMode::WL),
|
||||
(16, 64) => Some(ExtMode::WQ),
|
||||
(32, 64) => Some(ExtMode::LQ),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the source register size in bytes.
|
||||
pub(crate) fn src_size(&self) -> u8 {
|
||||
match self {
|
||||
ExtMode::BL | ExtMode::BQ => 1,
|
||||
@@ -767,6 +780,8 @@ impl ExtMode {
|
||||
ExtMode::LQ => 4,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the destination register size in bytes.
|
||||
pub(crate) fn dst_size(&self) -> u8 {
|
||||
match self {
|
||||
ExtMode::BL | ExtMode::WL => 4,
|
||||
|
||||
Reference in New Issue
Block a user