From 1216e4534b2a05f09c73403bd40950f322f5d822 Mon Sep 17 00:00:00 2001 From: Stephen Crane Date: Thu, 15 Feb 2024 17:13:49 -0800 Subject: [PATCH] `mod recon`: Use cbi index instead of mutable reference 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. --- src/recon.rs | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/src/recon.rs b/src/recon.rs index d1206e00c..e569ce94d 100644 --- a/src/recon.rs +++ b/src/recon.rs @@ -1720,7 +1720,7 @@ unsafe fn read_coef_tree( 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() { @@ -1733,8 +1733,7 @@ unsafe fn read_coef_tree( * 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(); } @@ -1779,10 +1778,12 @@ unsafe fn read_coef_tree( } }); 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; } @@ -1900,7 +1901,8 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( 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 = &mut f.frame_thread.cbi[(t.by as isize * f.b4_stride) as usize..] + [t.bx as usize]; let mut x_off = (init_x != 0) as c_int; x = init_x; t.bx += init_x; @@ -1920,8 +1922,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( } 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::( + let eob = decode_coefs::( t, &mut (*t.a).lcoef.0[(bx4 + x) as usize..], &mut t.l.lcoef.0[(by4 + y) as usize..], @@ -1933,8 +1934,8 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( (*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; + 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 @@ -1945,7 +1946,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( (*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) @@ -1982,7 +1983,8 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( 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 = &mut f.frame_thread.cbi[(t.by as isize * f.b4_stride) as usize..] + [t.bx as usize]; x = init_x >> ss_hor; t.bx += init_x; while x < sub_cw4 { @@ -1993,8 +1995,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( [((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::( + let eob = decode_coefs::( 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..], @@ -2006,8 +2007,8 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( (*ts).frame_thread[1].cf as *mut BD::Coef, &mut txtp, &mut cf_ctx, - ) as i16; - let eob = *fresh5 as c_int; + ); + 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" @@ -2020,7 +2021,7 @@ pub(crate) unsafe fn rav1d_read_coef_blocks( (*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, @@ -2726,7 +2727,7 @@ pub(crate) unsafe fn rav1d_recon_b_intra( * 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;