From 55548603b88ccf0babd081bd636c73ca164da919 Mon Sep 17 00:00:00 2001 From: iximeow Date: Wed, 19 Jun 2024 10:46:49 -0700 Subject: hoist set_len calls to have fewer live values --- src/long_mode/display.rs | 36 ++++++++++++++++++++++++------------ 1 file changed, 24 insertions(+), 12 deletions(-) diff --git a/src/long_mode/display.rs b/src/long_mode/display.rs index a60b2fd..0188361 100644 --- a/src/long_mode/display.rs +++ b/src/long_mode/display.rs @@ -555,6 +555,10 @@ impl DisplaySink for alloc::string::String { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "6:", "cmp {rem:e}, 16", @@ -598,8 +602,6 @@ impl DisplaySink for alloc::string::String { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { @@ -633,6 +635,10 @@ impl DisplaySink for alloc::string::String { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "7:", "cmp {rem:e}, 8", @@ -667,8 +673,6 @@ impl DisplaySink for alloc::string::String { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { @@ -702,6 +706,10 @@ impl DisplaySink for alloc::string::String { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "8:", "cmp {rem:e}, 4", @@ -729,8 +737,6 @@ impl DisplaySink for alloc::string::String { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { @@ -926,6 +932,10 @@ impl DisplaySink for BigEnoughString { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "6:", "cmp {rem:e}, 16", @@ -969,8 +979,6 @@ impl DisplaySink for BigEnoughString { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { @@ -1002,6 +1010,10 @@ impl DisplaySink for BigEnoughString { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "7:", "cmp {rem:e}, 8", @@ -1036,8 +1048,6 @@ impl DisplaySink for BigEnoughString { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { @@ -1069,6 +1079,10 @@ impl DisplaySink for BigEnoughString { let mut rem = new_bytes.len() as isize; + // set_len early because there is no way to avoid the following asm!() writing that + // same number of bytes into buf + buf.set_len(buf.len() + new_bytes.len()); + core::arch::asm!( "8:", "cmp {rem:e}, 4", @@ -1096,8 +1110,6 @@ impl DisplaySink for BigEnoughString { buf = out(reg) _, options(nostack), ); - - buf.set_len(buf.len() + new_bytes.len()); } /* for i in 0..new_bytes.len() { -- cgit v1.1