aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode/display.rs
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-18 17:01:58 -0700
committeriximeow <me@iximeow.net>2024-06-18 17:01:58 -0700
commitbebba5add1ea460db29cd0268f3365fae3cabbdd (patch)
tree2dc43562741986b8a3d421ed67e4c2e966ebd534 /src/long_mode/display.rs
parent93145713adafffff8f4058bef7b4b37fa55406f4 (diff)
slightly more centralized hex formatting
Diffstat (limited to 'src/long_mode/display.rs')
-rw-r--r--src/long_mode/display.rs48
1 files changed, 8 insertions, 40 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index c7f0f4d..6d3be36 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -1385,7 +1385,11 @@ impl <T: DisplaySink, Y: YaxColors> crate::long_mode::OperandVisitor for Coloriz
self.f.write_char(name[1] as char)?;
self.f.write_char(':')?;
}
- write!(self.f, "[{}]", self.colors.address(u32_hex(imm)))
+ self.f.write_fixed_size("[")?;
+ self.f.write_fixed_size("0x")?;
+ self.f.write_u32(imm)?;
+ self.f.write_fixed_size("]")?;
+ Ok(())
}
fn visit_abs_u64(&mut self, imm: u64) -> Result<Self::Ok, Self::Error> {
unsafe { self.f.write_lt_8(MEM_SIZE_STRINGS[self.instr.mem_size as usize])? };
@@ -1476,27 +1480,9 @@ impl <T: DisplaySink, Y: YaxColors> crate::long_mode::OperandVisitor for Coloriz
} else {
self.f.write_fixed_size("+ 0x")?;
}
- let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); 8];
- let mut curr = buf.len();
- loop {
- let digit = v % 16;
- let c = c_to_hex(digit as u8);
- curr -= 1;
- buf[curr].write(c);
- v = v / 16;
- if v == 0 {
- break;
- }
- }
- let buf = &buf[curr..];
- let s = unsafe {
- core::mem::transmute::<&[core::mem::MaybeUninit<u8>], &str>(buf)
- };
-
- // not actually fixed size, but this should optimize right i hope..
- unsafe { self.f.write_lt_16(s)?; }
+ self.f.write_u32(v);
}
- write!(self.f, "]")
+ self.f.write_char(']')
}
fn visit_index_base_scale(&mut self, base: RegSpec, index: RegSpec, scale: u8) -> Result<Self::Ok, Self::Error> {
unsafe { self.f.write_lt_8(MEM_SIZE_STRINGS[self.instr.mem_size as usize])? };
@@ -1540,25 +1526,7 @@ impl <T: DisplaySink, Y: YaxColors> crate::long_mode::OperandVisitor for Coloriz
} else {
self.f.write_fixed_size("+ 0x")?;
}
- let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); 8];
- let mut curr = buf.len();
- loop {
- let digit = v % 16;
- let c = c_to_hex(digit as u8);
- curr -= 1;
- buf[curr].write(c);
- v = v / 16;
- if v == 0 {
- break;
- }
- }
- let buf = &buf[curr..];
- let s = unsafe {
- core::mem::transmute::<&[core::mem::MaybeUninit<u8>], &str>(buf)
- };
-
- // not actually fixed size, but this should optimize right i hope..
- unsafe { self.f.write_lt_16(s)?; }
+ self.f.write_u32(v)?;
}
self.f.write_fixed_size("]")
}