we expect p to be in bound
if we are suffiently certain that p can never be oob
unsafe get_unchecked could be used to
eliminate bounds checking all together
which should improve performance further.
break;
}
- match &self.code[self.machine_st.p] {
+ let Some(inst) = self.code.get(self.machine_st.p) else {
+ // a seperate function marked #[cold] to make the compiler/branch-predictor prefer the happy path
+ handle_code_index_oob(self.code.len(), self.machine_st.p);
+ };
+
+ match inst {
&Instruction::BreakFromDispatchLoop => {
break 'outer;
}
std::process::ExitCode::SUCCESS
}
}
+
+#[cold] // this is a seperate function so that we can annotate it as cold
+#[track_caller]
+fn handle_code_index_oob(code_len: usize, p: usize) -> ! {
+ panic!("code pointer p = {p} is oob for code area of size {code_len}");
+}