From 55a64ffa7fddc9d8372e4072c554a676e2f0fc17 Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 19 Jun 2024 14:29:18 -0700 Subject: better testing for alternate sinks, fix hex formatting bug.... --- src/long_mode/display.rs | 60 +++++++++++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 16 deletions(-) (limited to 'src/long_mode') diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index da138bb..198a930 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -758,11 +758,15 @@ impl DisplaySink for alloc::string::String { fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } + self.reserve(printed_size); let buf = unsafe { self.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -791,11 +795,15 @@ impl DisplaySink for alloc::string::String { fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } + self.reserve(printed_size); let buf = unsafe { self.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -826,11 +834,15 @@ impl DisplaySink for alloc::string::String { fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } + self.reserve(printed_size); let buf = unsafe { self.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -860,11 +872,15 @@ impl DisplaySink for alloc::string::String { fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } + self.reserve(printed_size); let buf = unsafe { self.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -1140,10 +1156,13 @@ impl DisplaySink for BigEnoughString { fn write_u8(&mut self, mut v: u8) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((8 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } let buf = unsafe { self.content.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -1172,10 +1191,13 @@ impl DisplaySink for BigEnoughString { fn write_u16(&mut self, mut v: u16) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((16 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } let buf = unsafe { self.content.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -1205,10 +1227,13 @@ impl DisplaySink for BigEnoughString { fn write_u32(&mut self, mut v: u32) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((32 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } let buf = unsafe { self.content.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; @@ -1238,10 +1263,13 @@ impl DisplaySink for BigEnoughString { fn write_u64(&mut self, mut v: u64) -> Result<(), core::fmt::Error> { // 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()) >> 2) + 1) as usize; + let mut printed_size = ((64 - v.leading_zeros() + 3) >> 2) as usize; + if printed_size == 0 { + printed_size = 1; + } let buf = unsafe { self.content.as_mut_vec() }; - let p = buf.as_mut_ptr(); + let p = unsafe { buf.as_mut_ptr().offset(buf.len() as isize) }; let mut curr = printed_size; loop { let digit = v % 16; -- cgit v1.1