Skip to content

Commit

Permalink
experimental: make init_edges calls safe
Browse files Browse the repository at this point in the history
  • Loading branch information
Folkert de Vries committed Feb 23, 2024
1 parent fbd360e commit 8fd0109
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions src/intra_edge.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ struct ModeSelMem {
pub nt: *mut EdgeTip,
}

unsafe fn init_edges(node: *mut EdgeNode, bl: BlockLevel, edge_flags: EdgeFlags) {
if bl == BL_8X8 {
let nt = &mut *(node as *mut EdgeTip);
init_edges_tip(nt, edge_flags)
} else {
let nwc = &mut *(node as *mut EdgeBranch);
init_edges_branch(nwc, bl, edge_flags)
}
}

fn init_edges_tip(nt: &mut EdgeTip, edge_flags: EdgeFlags) {
let node = &mut nt.node;

Expand Down Expand Up @@ -167,20 +157,25 @@ unsafe fn init_mode_node(
top_has_right: bool,
left_has_bottom: bool,
) {
init_edges(
&mut nwc.node,
// this is an invariant: this function is only called with BL_128X128 and BL_64X64.
// then this function recurses, decreasing the block level at each step, until bottoming out
// at BL_16x16.
assert!(bl != BL_8X8);

init_edges_branch(
nwc,
bl,
EdgeFlags::ALL_TOP_HAS_RIGHT.select(top_has_right)
| EdgeFlags::ALL_LEFT_HAS_BOTTOM.select(left_has_bottom),
);

if bl == BL_16X16 {
let nt = slice::from_raw_parts_mut(mem.nt, nwc.split.len());
mem.nt = mem.nt.offset(nt.len() as isize);
for (n, (split, nt)) in iter::zip(&mut nwc.split, nt).enumerate() {
*split = &mut nt.node;
init_edges(
&mut nt.node,
bl + 1,
init_edges_tip(
nt,
EdgeFlags::ALL_TOP_HAS_RIGHT.select(!(n == 3 || (n == 1 && !top_has_right)))
| EdgeFlags::ALL_LEFT_HAS_BOTTOM.select(n == 0 || (n == 2 && left_has_bottom)),
);
Expand Down

0 comments on commit 8fd0109

Please sign in to comment.