Skip to content

Commit

Permalink
mod recon: Use cbi index instead of mutable reference (#749)
Browse files Browse the repository at this point in the history
We can't hold a mutable reference to the `cbi` field while passing a
reference to the frame data to children. Instead we can store an index
and do the dereference when needed.
  • Loading branch information
rinon authored Feb 16, 2024
2 parents 4953df0 + 616dfcd commit 3a21597
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1720,7 +1720,7 @@ unsafe fn read_coef_tree<BD: BitDepth>(
let mut cf_ctx: u8 = 0;
let eob;
let cf: *mut BD::Coef;
let mut cbi = &mut Default::default();
let mut cbi_idx = 0;
if (*t).frame_thread.pass != 0 {
let p = (*t).frame_thread.pass & 1;
if ((*ts).frame_thread[p as usize].cf).is_null() {
Expand All @@ -1733,8 +1733,7 @@ unsafe fn read_coef_tree<BD: BitDepth>(
* cmp::min((*t_dim).h as c_int, 8 as c_int)
* 16) as isize,
) as *mut DynCoef;
cbi = &mut f.frame_thread.cbi
[((*t).by as isize * f.b4_stride + (*t).bx as isize) as usize];
cbi_idx = ((*t).by as isize * f.b4_stride + (*t).bx as isize) as usize;
} else {
cf = BD::select_mut(&mut (*t).cf).0.as_mut_ptr();
}
Expand Down Expand Up @@ -1779,10 +1778,12 @@ unsafe fn read_coef_tree<BD: BitDepth>(
}
});
if (*t).frame_thread.pass == 1 {
let cbi = &mut f.frame_thread.cbi[cbi_idx];
cbi.eob[0] = eob as i16;
cbi.txtp[0] = txtp as u8;
}
} else {
let cbi = &f.frame_thread.cbi[cbi_idx];
eob = cbi.eob[0] as c_int;
txtp = cbi.txtp[0] as TxfmType;
}
Expand Down Expand Up @@ -1900,7 +1901,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
y = init_y;
t.by += init_y;
while y < sub_h4 {
let cbi = &mut f.frame_thread.cbi[(t.by as isize * f.b4_stride) as usize..];
let cbi_idx = (t.by as isize * f.b4_stride) as usize;
let mut x_off = (init_x != 0) as c_int;
x = init_x;
t.bx += init_x;
Expand All @@ -1920,8 +1921,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
} else {
let mut cf_ctx: u8 = 0x40 as c_int as u8;
let mut txtp: TxfmType = DCT_DCT;
let ref mut fresh4 = cbi[t.bx as usize].eob[0];
*fresh4 = decode_coefs::<BD>(
let eob = decode_coefs::<BD>(
t,
&mut (*t.a).lcoef.0[(bx4 + x) as usize..],
&mut t.l.lcoef.0[(by4 + y) as usize..],
Expand All @@ -1933,8 +1933,9 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
(*ts).frame_thread[1].cf as *mut BD::Coef,
&mut txtp,
&mut cf_ctx,
) as i16;
let eob = *fresh4 as c_int;
) as c_int;
let cbi = &mut f.frame_thread.cbi[cbi_idx..][t.bx as usize];
cbi.eob[0] = eob as i16;
if debug_block_info!(f, t) {
printf(
b"Post-y-cf-blk[tx=%d,txtp=%d,eob=%d]: r=%d\n\0" as *const u8
Expand All @@ -1945,7 +1946,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
(*ts).msac.rng,
);
}
cbi[t.bx as usize].txtp[0] = txtp as u8;
cbi.txtp[0] = txtp as u8;
(*ts).frame_thread[1].cf = ((*ts).frame_thread[1].cf as *mut BD::Coef)
.offset(
(cmp::min((*t_dim).w as c_int, 8 as c_int)
Expand Down Expand Up @@ -1982,7 +1983,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
y = init_y >> ss_ver;
t.by += init_y;
while y < sub_ch4 {
let cbi = &mut f.frame_thread.cbi[(t.by as isize * f.b4_stride) as usize..];
let cbi_idx = (t.by as isize * f.b4_stride) as usize;
x = init_x >> ss_hor;
t.bx += init_x;
while x < sub_cw4 {
Expand All @@ -1993,8 +1994,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
[((by4 + (y << ss_ver)) * 32 + bx4 + (x << ss_hor)) as usize]
as TxfmType;
}
let ref mut fresh5 = cbi[t.bx as usize].eob[(1 + pl) as usize];
*fresh5 = decode_coefs::<BD>(
let eob = decode_coefs::<BD>(
t,
&mut (*t.a).ccoef.0[pl as usize][(cbx4 + x) as usize..],
&mut t.l.ccoef.0[pl as usize][(cby4 + y) as usize..],
Expand All @@ -2006,8 +2006,9 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
(*ts).frame_thread[1].cf as *mut BD::Coef,
&mut txtp,
&mut cf_ctx,
) as i16;
let eob = *fresh5 as c_int;
);
let cbi = &mut f.frame_thread.cbi[cbi_idx..][t.bx as usize];
cbi.eob[(1 + pl) as usize] = eob as i16;
if debug_block_info!(f, t) {
printf(
b"Post-uv-cf-blk[pl=%d,tx=%d,txtp=%d,eob=%d]: r=%d\n\0"
Expand All @@ -2020,7 +2021,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks<BD: BitDepth>(
(*ts).msac.rng,
);
}
cbi[t.bx as usize].txtp[(1 + pl) as usize] = txtp as u8;
cbi.txtp[(1 + pl) as usize] = txtp as u8;
(*ts).frame_thread[1].cf =
((*ts).frame_thread[1].cf as *mut BD::Coef).offset(
((*uv_t_dim).w as c_int * (*uv_t_dim).h as c_int * 16) as isize,
Expand Down Expand Up @@ -2726,7 +2727,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra<BD: BitDepth>(
* cmp::min((*t_dim).h as c_int, 8 as c_int)
* 16) as isize,
) as *mut DynCoef;
let cbi = &mut f.frame_thread.cbi
let cbi = &f.frame_thread.cbi
[(t.by as isize * f.b4_stride + t.bx as isize) as usize];
eob = cbi.eob[0] as c_int;
txtp = cbi.txtp[0] as TxfmType;
Expand Down

0 comments on commit 3a21597

Please sign in to comment.