From 0e9f4402cb686da817ef876abd764676e262759a Mon Sep 17 00:00:00 2001 From: mlokr Date: Sat, 21 Sep 2024 08:19:27 +0200 Subject: [PATCH] fixing hbbytecode having the std mentioned --- Cargo.lock | 1 - hbbytecode/src/lib.rs | 5 +++-- hblang/Cargo.toml | 2 +- hblang/README.md | 8 ++++++++ hblang/src/son.rs | 20 +++++++++++++++++++- 5 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 6d2d8a287..78d343353 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -173,7 +173,6 @@ version = "0.10.2" source = "git+https://github.com/jakubDoka/regalloc2#52b2bbe908e78af1715de88f562f62a83e36ca96" dependencies = [ "hashbrown", - "log", "rustc-hash", "smallvec", ] diff --git a/hbbytecode/src/lib.rs b/hbbytecode/src/lib.rs index da1f4b538..b93a0cde9 100644 --- a/hbbytecode/src/lib.rs +++ b/hbbytecode/src/lib.rs @@ -35,7 +35,7 @@ impl TryFrom for Instr { } if value < NAMES.len() as u8 { - unsafe { Ok(std::mem::transmute::(value)) } + unsafe { Ok(core::mem::transmute::(value)) } } else { failed(value) } @@ -50,8 +50,9 @@ unsafe fn encode(instr: T) -> (usize, [u8; instrs::MAX_SIZE]) { } #[inline] +#[cfg(feature = "disasm")] fn decode(binary: &mut &[u8]) -> Option { - let (front, rest) = std::mem::take(binary).split_at_checked(core::mem::size_of::())?; + let (front, rest) = core::mem::take(binary).split_at_checked(core::mem::size_of::())?; *binary = rest; unsafe { Some(core::ptr::read(front.as_ptr() as *const T)) } } diff --git a/hblang/Cargo.toml b/hblang/Cargo.toml index d059410c2..2570c22d0 100644 --- a/hblang/Cargo.toml +++ b/hblang/Cargo.toml @@ -10,7 +10,7 @@ path = "src/main.rs" [dependencies] hbbytecode = { version = "0.1.0", path = "../hbbytecode" } hbvm = { path = "../hbvm", features = ["nightly"] } -regalloc2 = { git = "https://github.com/jakubDoka/regalloc2", features = ["trace-log"] } +regalloc2 = { git = "https://github.com/jakubDoka/regalloc2", features = [] } [dev-dependencies] env_logger = "0.11.5" diff --git a/hblang/README.md b/hblang/README.md index 1da553142..9e50fa771 100644 --- a/hblang/README.md +++ b/hblang/README.md @@ -504,6 +504,14 @@ main := fn(): int { if y == width break } } + + width += 1 + + loop { + if width < y break + y += 1 + } + return i } ``` diff --git a/hblang/src/son.rs b/hblang/src/son.rs index ce7cc868a..33cca843c 100644 --- a/hblang/src/son.rs +++ b/hblang/src/son.rs @@ -1818,7 +1818,25 @@ impl Codegen { std::mem::swap(&mut env.preferred_regs_by_class, &mut env.non_preferred_regs_by_class); }; let options = regalloc2::RegallocOptions { verbose_log: false, validate_ssa: true }; - let output = regalloc2::run(&func, &env, &options).unwrap_or_else(|err| panic!("{err}")); + let iters = std::time::SystemTime::now() + .duration_since(std::time::SystemTime::UNIX_EPOCH) + .unwrap() + .as_nanos() as u32 + % 300 + + 300; + let mut output = + regalloc2::run(&func, &env, &options).unwrap_or_else(|err| panic!("{err}")); + let now = std::time::Instant::now(); + for i in 0..iters { + output = regalloc2::run(&func, &env, &options).unwrap_or_else(|err| panic!("{err}")); + if (iters + i) % 2 == 0 { + std::mem::swap( + &mut env.preferred_regs_by_class, + &mut env.non_preferred_regs_by_class, + ); + } + } + eprintln!("took: {:?}", now.elapsed().checked_div(iters).unwrap()); let mut saved_regs = HashMap::::default(); let mut atr = |allc: regalloc2::Allocation| {