hint to the compiler/branch-predictor that
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.
This commit is contained in:
@@ -1622,7 +1622,12 @@ impl Machine {
|
|||||||
break;
|
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 => {
|
&Instruction::BreakFromDispatchLoop => {
|
||||||
break 'outer;
|
break 'outer;
|
||||||
}
|
}
|
||||||
@@ -6032,3 +6037,9 @@ impl Machine {
|
|||||||
std::process::ExitCode::SUCCESS
|
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}");
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user