diff options
author | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-02-28 19:22:57 +0100 |
---|---|---|
committer | Johannes Stoelp <johannes.stoelp@gmail.com> | 2024-02-28 19:22:57 +0100 |
commit | 3929d9038f3da75dbba8678cc8f2ba703b83b331 (patch) | |
tree | 2fce16f892b751e4d91fce4ff0973fc18e33c604 /examples | |
parent | 6f45135b0d7a2f182593d05574da81565538fa33 (diff) | |
download | juicebox-asm-3929d9038f3da75dbba8678cc8f2ba703b83b331.tar.gz juicebox-asm-3929d9038f3da75dbba8678cc8f2ba703b83b331.zip |
tiny_vm: remove additional cache lookup after translating a new bb
Diffstat (limited to 'examples')
-rw-r--r-- | examples/tiny_vm.rs | 29 |
1 files changed, 17 insertions, 12 deletions
diff --git a/examples/tiny_vm.rs b/examples/tiny_vm.rs index b441a4a..86f5eaf 100644 --- a/examples/tiny_vm.rs +++ b/examples/tiny_vm.rs @@ -237,22 +237,27 @@ impl TinyVm { /// _basic blocks_ on demand. pub fn jit(&mut self) { 'outer: loop { - if let Some(bb_fn) = self.jit_cache[self.pc] { - match bb_fn(self.regs.as_mut_ptr(), self.dmem.as_mut_ptr()) { - JitRet(0, insn) => { - self.pc += insn as usize; - self.icnt += insn as usize; - break 'outer; - } - JitRet(insn, reenter_pc) => { - self.pc = reenter_pc as usize; - self.icnt += insn as usize; - } - } + let bb_fn = if let Some(bb_fn) = self.jit_cache[self.pc] { + bb_fn } else { let bb_fn = self.translate_next_bb(); self.jit_cache[self.pc] = Some(bb_fn); //println!("[0x{:02x}] translated bb at {:p}", self.pc, bb_fn); + bb_fn + }; + + match bb_fn(self.regs.as_mut_ptr(), self.dmem.as_mut_ptr()) { + // HALT instruction hit. + JitRet(0, insn) => { + self.pc += insn as usize; + self.icnt += insn as usize; + break 'outer; + } + // End of basic block, re-enter. + JitRet(insn, reenter_pc) => { + self.pc = reenter_pc as usize; + self.icnt += insn as usize; + } } } } |