idea (doesn't compile)
This commit is contained in:
+48
-53
@@ -9,8 +9,14 @@ pub struct RegH {
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct RegWH {
|
||||
pub regh: RegH,
|
||||
pub width: Width,
|
||||
}
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Reg64 {
|
||||
pub reg: Reg,
|
||||
pub widthh: WidthH,
|
||||
pub width: Width64,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
@@ -21,13 +27,10 @@ pub enum Width {
|
||||
B8,
|
||||
}
|
||||
|
||||
/// width that also specifies if high for 8 bit
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub enum WidthH {
|
||||
pub enum Width64 {
|
||||
B64,
|
||||
B32,
|
||||
B16,
|
||||
B8 { high: bool },
|
||||
}
|
||||
|
||||
def_regs! { RegWH;
|
||||
@@ -64,21 +67,29 @@ impl Reg {
|
||||
}
|
||||
}
|
||||
|
||||
impl RegWH {
|
||||
pub fn requires_rex(&self) -> bool {
|
||||
self.gt8()
|
||||
|| self.widthh == WidthH::B64
|
||||
|| (self.gt4() && self.widthh == WidthH::B8 { high: false })
|
||||
}
|
||||
}
|
||||
|
||||
impl RegH {
|
||||
pub fn requires_rex(&self, width: Width) -> bool {
|
||||
self.gt8() || width == Width::B64 || (self.gt4() && width == Width::B8 && !self.high)
|
||||
}
|
||||
}
|
||||
|
||||
impl WidthH {
|
||||
impl RegWH {
|
||||
const fn new(val: u8, width: Width, high: bool) -> Self {
|
||||
Self {
|
||||
regh: RegH {
|
||||
reg: Reg(val),
|
||||
high,
|
||||
},
|
||||
width,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn requires_rex(&self) -> bool {
|
||||
self.regh.requires_rex(self.width)
|
||||
}
|
||||
}
|
||||
|
||||
impl Width {
|
||||
pub const fn max(&self) -> u64 {
|
||||
match self {
|
||||
Self::B64 => u64::MAX,
|
||||
@@ -95,22 +106,6 @@ impl WidthH {
|
||||
Self::B8 { .. } => 1,
|
||||
}
|
||||
}
|
||||
/// greater than 8 bits
|
||||
pub const fn gt8(&self) -> bool {
|
||||
!matches!(self, Self::B8 { .. })
|
||||
}
|
||||
|
||||
pub const fn width(&self) -> Width {
|
||||
match self {
|
||||
WidthH::B64 => Width::B64,
|
||||
WidthH::B32 => Width::B32,
|
||||
WidthH::B16 => Width::B16,
|
||||
WidthH::B8 { .. } => Width::B8,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Width {
|
||||
/// greater than 8 bits
|
||||
pub const fn gt8(&self) -> bool {
|
||||
!matches!(self, Self::B8)
|
||||
@@ -129,26 +124,26 @@ impl From<RegH> for Reg {
|
||||
}
|
||||
}
|
||||
|
||||
impl From<RegWH> for RegH {
|
||||
fn from(value: RegWH) -> Self {
|
||||
Self {
|
||||
reg: value.reg,
|
||||
high: if let WidthH::B8 { high } = value.widthh {
|
||||
high
|
||||
} else {
|
||||
false
|
||||
},
|
||||
}
|
||||
impl From<Reg64> for Reg {
|
||||
fn from(value: Reg64) -> Self {
|
||||
value.reg
|
||||
}
|
||||
}
|
||||
|
||||
impl From<WidthH> for Width {
|
||||
fn from(value: WidthH) -> Self {
|
||||
impl From<RegWH> for RegH {
|
||||
fn from(value: RegWH) -> Self {
|
||||
value.regh
|
||||
}
|
||||
}
|
||||
|
||||
impl TryFrom<Width> for Width64 {
|
||||
type Error = ();
|
||||
|
||||
fn try_from(value: Width) -> Result<Self, Self::Error> {
|
||||
match value {
|
||||
WidthH::B64 => Self::B64,
|
||||
WidthH::B32 => Self::B32,
|
||||
WidthH::B16 => Self::B16,
|
||||
WidthH::B8 { .. } => Self::B8,
|
||||
Width::B64 => Ok(Self::B64),
|
||||
Width::B32 => Ok(Self::B32),
|
||||
_ => Err(()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -157,16 +152,16 @@ macro_rules! def_regs {
|
||||
($Struct: ident; $($val:literal : $B64:ident $B32:ident $B16:ident $B8:ident $($B8H:ident=$hval:expr)?,)*) => {
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $B64: $Struct = $Struct { reg: Reg($val), widthh: WidthH::B64 };
|
||||
pub const $B64: $Struct = $Struct::new($val, Width::B64, false);
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $B32: $Struct = $Struct { reg: Reg($val), widthh: WidthH::B32 };
|
||||
pub const $B32: $Struct = $Struct::new($val, Width::B32, false);
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $B16: $Struct = $Struct { reg: Reg($val), widthh: WidthH::B16 };
|
||||
pub const $B16: $Struct = $Struct::new($val, Width::B16, false);
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $B8 : $Struct = $Struct { reg: Reg($val), widthh: WidthH::B8 { high: false } };
|
||||
pub const $B8 : $Struct = $Struct::new($val, Width::B8 , false);
|
||||
$(
|
||||
#[allow(non_upper_case_globals)]
|
||||
pub const $B8H: $Struct = $Struct { reg: $hval.reg, widthh: WidthH::B8 { high: true } };
|
||||
pub const $B8H: $Struct = $Struct::new($hval.regh.reg.0, Width::B8, true);
|
||||
)?
|
||||
)*
|
||||
impl $Struct {
|
||||
@@ -191,10 +186,10 @@ macro_rules! def_regs {
|
||||
use def_regs;
|
||||
|
||||
impl std::ops::Deref for RegWH {
|
||||
type Target = Reg;
|
||||
type Target = RegH;
|
||||
|
||||
fn deref(&self) -> &Self::Target {
|
||||
&self.reg
|
||||
&self.regh
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user