aboutsummaryrefslogtreecommitdiff
path: root/src/long_mode
diff options
context:
space:
mode:
authoriximeow <me@iximeow.net>2024-06-20 13:18:13 -0700
committeriximeow <me@iximeow.net>2024-06-20 13:18:13 -0700
commit70f767370feb9ca056e4baf32f37c6d8d8235e0c (patch)
treefbe3bcb067fa3d3b35dbaf7a0ba672245d4a4633 /src/long_mode
parent3c8271ae9d45bdae33f0d1d057fb5239c893b6c5 (diff)
swap printed size check and lzcnt
if printed_size == 0 then the value must be 0, but we can check if the value is 0 before doing all that stuff
Diffstat (limited to 'src/long_mode')
-rw-r--r--src/long_mode/display.rs48
1 files changed, 24 insertions, 24 deletions
diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs
index c69e648..ca5e580 100644
--- a/src/long_mode/display.rs
+++ b/src/long_mode/display.rs
@@ -891,12 +891,12 @@ impl DisplaySink for alloc::string::String {
/// followup step)
#[inline(always)]
fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
self.reserve(printed_size);
@@ -930,12 +930,12 @@ impl DisplaySink for alloc::string::String {
/// followup step)
#[inline(always)]
fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
self.reserve(printed_size);
@@ -969,12 +969,12 @@ impl DisplaySink for alloc::string::String {
/// followup step)
#[inline(always)]
fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
self.reserve(printed_size);
@@ -1008,12 +1008,12 @@ impl DisplaySink for alloc::string::String {
/// followup step)
#[inline(always)]
fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
self.reserve(printed_size);
@@ -1281,12 +1281,12 @@ impl<'buf> DisplaySink for InstructionTextSink<'buf> {
/// followup step)
#[inline(always)]
fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
let buf = unsafe { self.buf.as_mut_vec() };
let new_len = buf.len() + printed_size;
@@ -1318,12 +1318,12 @@ impl<'buf> DisplaySink for InstructionTextSink<'buf> {
/// followup step)
#[inline(always)]
fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
let buf = unsafe { self.buf.as_mut_vec() };
let new_len = buf.len() + printed_size;
@@ -1355,12 +1355,12 @@ impl<'buf> DisplaySink for InstructionTextSink<'buf> {
/// followup step)
#[inline(always)]
fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
let buf = unsafe { self.buf.as_mut_vec() };
let new_len = buf.len() + printed_size;
@@ -1392,12 +1392,12 @@ impl<'buf> DisplaySink for InstructionTextSink<'buf> {
/// followup step)
#[inline(always)]
fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> {
+ if v == 0 {
+ return self.write_fixed_size("0");
+ }
// we can fairly easily predict the size of a formatted string here with lzcnt, which also
// means we can write directly into the correct offsets of the output string.
let printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize;
- if printed_size == 0 {
- return self.write_fixed_size("0");
- }
let buf = unsafe { self.buf.as_mut_vec() };
let new_len = buf.len() + printed_size;