diff options
author | iximeow <me@iximeow.net> | 2024-06-18 13:59:33 -0700 |
---|---|---|
committer | iximeow <me@iximeow.net> | 2024-06-18 13:59:33 -0700 |
commit | 758ddc604b6300c48ae14dbdc8d48720124658f2 (patch) | |
tree | 935aa75f0455483974ca078a26c592bb18002981 /src/long_mode | |
parent | 49f54724a3b0b2497bd944f7638cb6e8ff1d18dc (diff) |
move away from fmt for visit_i64 and displacements too
Diffstat (limited to 'src/long_mode')
-rw-r--r-- | src/long_mode/display.rs | 56 |
1 files changed, 54 insertions, 2 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index e3f5b0a..0e09173 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -1121,7 +1121,31 @@ impl <T: DisplaySink, Y: YaxColors> crate::long_mode::OperandVisitor for Coloriz } fn visit_i64(&mut self, imm: i64) -> Result<Self::Ok, Self::Error> { self.f.span_enter(TokenType::Immediate); - write!(self.f, "{}", signed_i64_hex(imm))?; + let mut v = imm as u64; + if imm < 0 { + self.f.write_char('-')?; + v = -imm as u64; + } + self.f.write_fixed_size("0x")?; + let mut buf = [core::mem::MaybeUninit::<u8>::uninit(); 64]; + 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.. + self.f.write_fixed_size(s)?; self.f.span_end(TokenType::Immediate); Ok(()) } @@ -1207,7 +1231,35 @@ impl <T: DisplaySink, Y: YaxColors> crate::long_mode::OperandVisitor for Coloriz self.f.write_fixed_size("[")?; unsafe { self.f.write_lt_8(regspec_label(®))?; } self.f.write_fixed_size(" ")?; - format_number_i32(self.colors, self.f, disp, NumberStyleHint::HexSignedWithSignSplit)?; + + { + let mut v = disp as u32; + if disp < 0 { + self.f.write_fixed_size("- 0x")?; + v = -disp as u32; + } 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.. + self.f.write_fixed_size(s)?; + } self.f.write_fixed_size("]") } fn visit_deref(&mut self, reg: RegSpec) -> Result<Self::Ok, Self::Error> { |