give immediates a sign & fix stuff

This commit is contained in:
2026-06-12 17:08:42 -04:00
parent e199620856
commit 7280f7b071
7 changed files with 282 additions and 150 deletions
+9 -28
View File
@@ -52,8 +52,10 @@ impl Reg {
}
/// if self has 64 bit width, changes width to 32 bit
pub fn lower64(&mut self) {
self.width.lower64()
pub fn lower64(&self) -> Self {
let mut new = *self;
new.width = new.width.min(Width::B32);
new
}
pub fn requires_rex(&self) -> bool {
@@ -76,7 +78,7 @@ impl Reg {
}
impl Width {
pub const fn max(&self) -> u64 {
pub const fn max_val(&self) -> u64 {
match self {
Self::B64 => u64::MAX,
Self::B32 => u32::MAX as u64,
@@ -85,10 +87,8 @@ impl Width {
}
}
pub fn lower64(&mut self) {
if matches!(self, Width::B64) {
*self = Width::B32;
}
pub fn min(self, other: Self) -> Self {
if self <= other { self } else { other }
}
pub const fn bytes(&self) -> usize {
@@ -100,27 +100,6 @@ impl Width {
}
}
pub const fn fit(val: u64) -> Self {
const B8: u64 = 1 << 8;
const B16: u64 = 1 << 16;
const B32: u64 = 1 << 32;
match val {
..B8 => Self::B8,
B8..B16 => Self::B16,
B16..B32 => Self::B32,
B32.. => Self::B64,
}
}
pub const fn fiti(val: u64) -> Self {
match val {
..0x80 => Self::B8,
0x80..0x8000 => Self::B16,
0x8000..0x8000_0000 => Self::B32,
0x8000_0000.. => Self::B64,
}
}
/// greater than 8 bits
pub const fn gt8(&self) -> bool {
!matches!(self, Self::B8)
@@ -205,6 +184,8 @@ macro_rules! def_regs {
use def_regs;
use crate::arch::x86_64::Imm;
impl From<Reg> for Width {
fn from(value: Reg) -> Self {
value.width