forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-mvstack2' (ca82eb33): mv stacks on an inline small-vector (no heap per block), MiGrid published per block by row fills, MiInfo 32 -> 24 bytes with a slot-1 sentinel (Option niche kept, pinned by test); byte-exact, -0.5% instructions and -1.4% task-clock at the composed setting. Conflict with lane-mf resolved: banded motion-field build keeps the sentinel slot-1 read

Browse files at this commit

a63d087c5d2b4b54dca4cccd3ac608e957b7ee8dAhmet Kaan GümüşParent: 413bfc95ba1d08
crates/ec-av1/src/decode.rsmodified+184 -202
@@ -220,7 +220,7 @@ use crate::mc;
220220 use crate::msac::SymbolDecoder;
221221 use crate::mvstack::{
222222 ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME,
223- MiGrid, MiInfo, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx,
223+ MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx,
224224 find_mv_stack_with_sign_bias, reference_mode_ctx,
225225 single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx,
226226 single_ref_p6_ctx, uni_comp_ref_p1_ctx,
@@ -3316,9 +3316,9 @@ fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>
33163316 let info = crate::mvstack::MiInfo {
33173317 is_inter: dv.is_some(),
33183318 ref_frame: 0,
3319- ref_frame1: None,
3319+ ref_frame1: NO_REF1,
33203320 mv: dv.unwrap_or((0, 0)),
3321- mv1: None,
3321+ mv1: (0, 0),
33223322 is_new_mv: dv.is_some(),
33233323 is_global_mv0: false,
33243324 is_global_mv1: false,
@@ -4792,7 +4792,7 @@ pub(crate) fn build_motion_field(
47924792 let mut saved: Option<crate::motion_field::SavedMv> = None;
47934793 for (rf, mv) in [
47944794 (info.ref_frame, Some(info.mv)),
4795- (info.ref_frame1.unwrap_or(0), info.mv1),
4795+ (info.ref_frame1.max(0), Some(info.mv1)),
47964796 ] {
47974797 let (Some(mv), true) = (mv, rf > 0) else {
47984798 continue;
@@ -22623,7 +22623,7 @@ fn find_samples(
2262322623 && crate::envflags::var("EC_PROJ_MI")
2262422624 .is_ok_and(|v| v == format!("{mi_row},{mi_col}"));
2262522625 let single_ref_match = |info: &MiInfo| {
22626- let m = info.ref_frame == ref_frame && info.ref_frame1.is_none();
22626+ let m = info.ref_frame == ref_frame && info.ref_frame1 == NO_REF1;
2262722627 if proj_dbg {
2262822628 eprintln!(
2262922629 "EC_PROJ cand ref={} ref1={:?} size={} size_h={} is_inter={} want={ref_frame} match={m}",
@@ -24256,31 +24256,29 @@ fn decode_inter_block(
2425624256 // too -- a square `bw4`x`bw4` stamp here claims a rect strip's
2425724257 // NEXT strip's own rows/cols before it decodes, corrupting
2425824258 // every later mvstack scan that reads this cell back.
24259- for dr in 0..bh4 {
24260- for dc in 0..bw4 {
24261- grid.set(
24262- mi_row + dr,
24263- mi_col + dc,
24264- MiInfo {
24265- is_inter: true,
24266- ref_frame: ref0,
24267- ref_frame1: Some(ref1),
24268- mv1: Some(mv1),
24269- mv: mv0,
24270- is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
24271- size: bw4 as u8,
24272- size_h: bh4 as u8,
24273- // libaom `is_global_mv_block`: per-ref-slot, mode
24274- // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's
24275- // own gm model > TRANSLATION (IDENTITY excluded
24276- // too -- the two-predicate trap, distinct from
24277- // `gm_nontrans` above which allows IDENTITY).
24278- is_global_mv0,
24279- is_global_mv1,
24280- },
24281- );
24282- }
24283- }
24259+ grid.fill_rect(
24260+ mi_row,
24261+ mi_col,
24262+ bh4,
24263+ bw4,
24264+ MiInfo {
24265+ is_inter: true,
24266+ ref_frame: ref0,
24267+ ref_frame1: ref1,
24268+ mv1,
24269+ mv: mv0,
24270+ is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
24271+ size: bw4 as u8,
24272+ size_h: bh4 as u8,
24273+ // libaom `is_global_mv_block`: per-ref-slot, mode
24274+ // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's
24275+ // own gm model > TRANSLATION (IDENTITY excluded
24276+ // too -- the two-predicate trap, distinct from
24277+ // `gm_nontrans` above which allows IDENTITY).
24278+ is_global_mv0,
24279+ is_global_mv1,
24280+ },
24281+ );
2428424282 // spec 5.11.25's `comp_group_idx`/`compound_idx`: only read when
2428524283 // masked compound / distance-weighted compound are actually
2428624284 // enabled for this stream -- `is_any_masked_compound_used_here`
@@ -25812,32 +25810,30 @@ fn decode_inter_block(
2581225810 // lane-rect r2: see the compound path's matching comment above --
2581325811 // `grid` must be stamped with the block's true bh4/bw4 span, not
2581425812 // a square `bw4`x`bw4` guess.
25815- for dr in 0..bh4 {
25816- for dc in 0..bw4 {
25817- grid.set(
25818- mi_row + dr,
25819- mi_col + dc,
25820- MiInfo {
25821- is_inter: true,
25822- ref_frame,
25823- // An interintra block records ref_frame[1] ==
25824- // INTRA_FRAME (0): warp-sample gathering
25825- // (libaom av1_findSamples, mvref_common.c:1155)
25826- // requires ref_frame[1] == NONE_FRAME, so such a
25827- // neighbour must not donate samples or count in
25828- // num_proj_ref.
25829- ref_frame1: interintra_mode.map(|_| 0),
25830- mv1: None,
25831- mv,
25832- is_new_mv,
25833- size: bw4 as u8,
25834- size_h: bh4 as u8,
25835- is_global_mv0: is_global_mv_block,
25836- is_global_mv1: false,
25837- },
25838- );
25839- }
25840- }
25813+ grid.fill_rect(
25814+ mi_row,
25815+ mi_col,
25816+ bh4,
25817+ bw4,
25818+ MiInfo {
25819+ is_inter: true,
25820+ ref_frame,
25821+ // An interintra block records ref_frame[1] ==
25822+ // INTRA_FRAME (0): warp-sample gathering
25823+ // (libaom av1_findSamples, mvref_common.c:1155)
25824+ // requires ref_frame[1] == NONE_FRAME, so such a
25825+ // neighbour must not donate samples or count in
25826+ // num_proj_ref.
25827+ ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 },
25828+ mv1: (0, 0),
25829+ mv,
25830+ is_new_mv,
25831+ size: bw4 as u8,
25832+ size_h: bh4 as u8,
25833+ is_global_mv0: is_global_mv_block,
25834+ is_global_mv1: false,
25835+ },
25836+ );
2584125837 mode_for_tx = 0;
2584225838 uv_predict_mode = DC_PRED;
2584325839
@@ -26644,26 +26640,24 @@ fn decode_inter_block(
2664426640 // lane's `r * SUB_MI` re-derivation would snap a sub-SUB strip to
2664526641 // its enclosing 16-px cell.
2664626642 let (mi_r0, mi_c0) = (rmi, cmi);
26647- for dr in 0..write_h / MI {
26648- for dc in 0..write_w / MI {
26649- grid.set(
26650- mi_r0 + dr,
26651- mi_c0 + dc,
26652- MiInfo {
26653- is_inter: false,
26654- ref_frame: -1,
26655- ref_frame1: None,
26656- mv1: None,
26657- mv: (0, 0),
26658- is_new_mv: false,
26659- size: (write_w / MI) as u8,
26660- size_h: (write_h / MI) as u8,
26661- is_global_mv0: false,
26662- is_global_mv1: false,
26663- },
26664- );
26665- }
26666- }
26643+ grid.fill_rect(
26644+ mi_r0,
26645+ mi_c0,
26646+ write_h / MI,
26647+ write_w / MI,
26648+ MiInfo {
26649+ is_inter: false,
26650+ ref_frame: -1,
26651+ ref_frame1: NO_REF1,
26652+ mv1: (0, 0),
26653+ mv: (0, 0),
26654+ is_new_mv: false,
26655+ size: (write_w / MI) as u8,
26656+ size_h: (write_h / MI) as u8,
26657+ is_global_mv0: false,
26658+ is_global_mv1: false,
26659+ },
26660+ );
2666726661 neighbours.record_inter_rect_mi(
2666826662 at,
2666926663 write_w / MI,
@@ -26868,26 +26862,24 @@ fn decode_inter_block(
2686826862 ref_frame_for_lf = 0;
2686926863 globalmv_for_lf = false;
2687026864 let (mi_row, mi_col) = (rmi, cmi);
26871- for dr in 0..side / 4 {
26872- for dc in 0..side / 4 {
26873- grid.set(
26874- mi_row + dr,
26875- mi_col + dc,
26876- MiInfo {
26877- is_inter: false,
26878- ref_frame: -1,
26879- ref_frame1: None,
26880- mv1: None,
26881- mv: (0, 0),
26882- is_new_mv: false,
26883- size: (side / 4) as u8,
26884- size_h: (side / 4) as u8,
26885- is_global_mv0: false,
26886- is_global_mv1: false,
26887- },
26888- );
26889- }
26890- }
26865+ grid.fill_rect(
26866+ mi_row,
26867+ mi_col,
26868+ side / 4,
26869+ side / 4,
26870+ MiInfo {
26871+ is_inter: false,
26872+ ref_frame: -1,
26873+ ref_frame1: NO_REF1,
26874+ mv1: (0, 0),
26875+ mv: (0, 0),
26876+ is_new_mv: false,
26877+ size: (side / 4) as u8,
26878+ size_h: (side / 4) as u8,
26879+ is_global_mv0: false,
26880+ is_global_mv1: false,
26881+ },
26882+ );
2689126883
2689226884 // lane-intrainter r1: an intra block in an inter frame reads the same
2689326885 // `tx_depth` symbol a key-frame block does, and when it splits, the
@@ -27787,8 +27779,8 @@ fn decode_inter_sub8_split4(
2778727779 MiInfo {
2778827780 is_inter: true,
2778927781 ref_frame,
27790- ref_frame1: None,
27791- mv1: None,
27782+ ref_frame1: NO_REF1,
27783+ mv1: (0, 0),
2779227784 mv,
2779327785 is_new_mv,
2779427786 size: 1,
@@ -28319,26 +28311,24 @@ fn decode_intra_sub8_leaf(
2831928311 // intra-in-inter block writes them: `is_inter = 0`, `INTRA_FRAME` ref, no
2832028312 // interpolation filter, no skip mode.
2832128313 neighbours.record_inter_rect_mi(lmi, w_mi, h_mi, skip, false, 0, [3, 3], false);
28322- for dr in 0..h_mi {
28323- for dc in 0..w_mi {
28324- grid.set(
28325- lmi.0 + dr,
28326- lmi.1 + dc,
28327- MiInfo {
28328- is_inter: false,
28329- ref_frame: -1,
28330- ref_frame1: None,
28331- mv1: None,
28332- mv: (0, 0),
28333- is_new_mv: false,
28334- size: w_mi as u8,
28335- size_h: h_mi as u8,
28336- is_global_mv0: false,
28337- is_global_mv1: false,
28338- },
28339- );
28340- }
28341- }
28314+ grid.fill_rect(
28315+ lmi.0,
28316+ lmi.1,
28317+ h_mi,
28318+ w_mi,
28319+ MiInfo {
28320+ is_inter: false,
28321+ ref_frame: -1,
28322+ ref_frame1: NO_REF1,
28323+ mv1: (0, 0),
28324+ mv: (0, 0),
28325+ is_new_mv: false,
28326+ size: w_mi as u8,
28327+ size_h: h_mi as u8,
28328+ is_global_mv0: false,
28329+ is_global_mv1: false,
28330+ },
28331+ );
2834228332 SUB8_INTRA_RECT_HITS.with(|h| {
2834328333 let mut s = h.get();
2834428334 s[usize::from(vert)] += 1;
@@ -29024,26 +29014,24 @@ fn grid_stamp_rect(
2902429014 mv: (i32, i32),
2902529015 is_new_mv: bool,
2902629016 ) {
29027- for dr in 0..h_mi {
29028- for dc in 0..w_mi {
29029- grid.set(
29030- mi_row + dr,
29031- mi_col + dc,
29032- MiInfo {
29033- is_inter: true,
29034- ref_frame,
29035- ref_frame1: None,
29036- mv1: None,
29037- mv,
29038- is_new_mv,
29039- size: w_mi as u8,
29040- size_h: h_mi as u8,
29041- is_global_mv0: false,
29042- is_global_mv1: false,
29043- },
29044- );
29045- }
29046- }
29017+ grid.fill_rect(
29018+ mi_row,
29019+ mi_col,
29020+ h_mi,
29021+ w_mi,
29022+ MiInfo {
29023+ is_inter: true,
29024+ ref_frame,
29025+ ref_frame1: NO_REF1,
29026+ mv1: (0, 0),
29027+ mv,
29028+ is_new_mv,
29029+ size: w_mi as u8,
29030+ size_h: h_mi as u8,
29031+ is_global_mv0: false,
29032+ is_global_mv1: false,
29033+ },
29034+ );
2904729035 }
2904829036
2904929037 /// Decodes one 8x8 leaf of a straddling 16x16 inter-frame block
@@ -29605,26 +29593,24 @@ fn decode_inter_block8(
2960529593 COMPOUND_WARP_HITS.with(|c| c.set(c.get() + 1));
2960629594 COMPOUND_WARP_HITS_8.with(|c| c.set(c.get() + 1));
2960729595 }
29608- for dr in 0..2 {
29609- for dc in 0..2 {
29610- grid.set(
29611- mi_row + dr,
29612- mi_col + dc,
29613- MiInfo {
29614- is_inter: true,
29615- ref_frame: ref0,
29616- ref_frame1: Some(ref1),
29617- mv1: Some(mv1),
29618- mv: mv0,
29619- is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
29620- size: 2,
29621- size_h: 2,
29622- is_global_mv0: is_global_mv0_c,
29623- is_global_mv1: is_global_mv1_c,
29624- },
29625- );
29626- }
29627- }
29596+ grid.fill_rect(
29597+ mi_row,
29598+ mi_col,
29599+ 2,
29600+ 2,
29601+ MiInfo {
29602+ is_inter: true,
29603+ ref_frame: ref0,
29604+ ref_frame1: ref1,
29605+ mv1,
29606+ mv: mv0,
29607+ is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
29608+ size: 2,
29609+ size_h: 2,
29610+ is_global_mv0: is_global_mv0_c,
29611+ is_global_mv1: is_global_mv1_c,
29612+ },
29613+ );
2962829614 mode_for_tx = 0;
2962929615
2963029616 let mut inter0_y = vec![0i32; SIDE * SIDE];
@@ -30282,28 +30268,26 @@ fn decode_inter_block8(
3028230268 warp_params.is_some(),
3028330269 );
3028430270 }
30285- for dr in 0..2 {
30286- for dc in 0..2 {
30287- grid.set(
30288- mi_row + dr,
30289- mi_col + dc,
30290- MiInfo {
30291- is_inter: true,
30292- ref_frame,
30293- // INTRA_FRAME marker for interintra blocks -- keeps
30294- // them out of warp-sample gathering (see 16/32 site).
30295- ref_frame1: interintra_mode.map(|_| 0),
30296- mv1: None,
30297- mv,
30298- is_new_mv,
30299- size: 2,
30300- size_h: 2,
30301- is_global_mv0: is_global_mv_block,
30302- is_global_mv1: false,
30303- },
30304- );
30305- }
30306- }
30271+ grid.fill_rect(
30272+ mi_row,
30273+ mi_col,
30274+ 2,
30275+ 2,
30276+ MiInfo {
30277+ is_inter: true,
30278+ ref_frame,
30279+ // INTRA_FRAME marker for interintra blocks -- keeps
30280+ // them out of warp-sample gathering (see 16/32 site).
30281+ ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 },
30282+ mv1: (0, 0),
30283+ mv,
30284+ is_new_mv,
30285+ size: 2,
30286+ size_h: 2,
30287+ is_global_mv0: is_global_mv_block,
30288+ is_global_mv1: false,
30289+ },
30290+ );
3030730291 mode_for_tx = 0;
3030830292
3030930293 // lane-scaledref r1: this leaf's own prediction is always `Regular`
@@ -30746,26 +30730,24 @@ fn decode_inter_block8(
3074630730 });
3074730731 mode_for_tx = mode;
3074830732 let (mi_row, mi_col) = leaf_mi;
30749- for dr in 0..2 {
30750- for dc in 0..2 {
30751- grid.set(
30752- mi_row + dr,
30753- mi_col + dc,
30754- MiInfo {
30755- is_inter: false,
30756- ref_frame: -1,
30757- ref_frame1: None,
30758- mv1: None,
30759- mv: (0, 0),
30760- is_new_mv: false,
30761- size: 2,
30762- size_h: 2,
30763- is_global_mv0: false,
30764- is_global_mv1: false,
30765- },
30766- );
30767- }
30768- }
30733+ grid.fill_rect(
30734+ mi_row,
30735+ mi_col,
30736+ 2,
30737+ 2,
30738+ MiInfo {
30739+ is_inter: false,
30740+ ref_frame: -1,
30741+ ref_frame1: NO_REF1,
30742+ mv1: (0, 0),
30743+ mv: (0, 0),
30744+ is_new_mv: false,
30745+ size: 2,
30746+ size_h: 2,
30747+ is_global_mv0: false,
30748+ is_global_mv1: false,
30749+ },
30750+ );
3076930751
3077030752 // lane-leaf8tx r1: the 8x8 leaf's own intra `tx_depth` (libaom
3077130753 // `read_tx_size` -> `read_selected_tx_size`, max depth 1 at
@@ -35541,8 +35523,8 @@ mod tests {
3554135523 let neighbour = |mv| MiInfo {
3554235524 is_inter: true,
3554335525 ref_frame: LAST_FRAME,
35544- ref_frame1: None,
35545- mv1: None,
35526+ ref_frame1: NO_REF1,
35527+ mv1: (0, 0),
3554635528 mv,
3554735529 is_new_mv: false,
3554835530 size: 1,
crates/ec-av1/src/encode.rsmodified+13 -13
@@ -28,7 +28,7 @@ use crate::frame::frame_obu;
2828 use crate::intra::{D67_PRED, DC_PRED, KEY_FRAME_MODES, V_PRED};
2929 use crate::mc;
3030 use crate::motion;
31-use crate::mvstack::{MiGrid, MiInfo, MvStack, find_mv_stack};
31+use crate::mvstack::{MiGrid, MiInfo, MvStack, NO_REF1, find_mv_stack};
3232 use crate::obu::temporal_delimiter;
3333 use crate::quant::ac_q;
3434 use crate::sequence::sequence_header_obu;
@@ -3097,8 +3097,8 @@ pub(crate) fn encode_inter_frame(
30973097 Some(info) => MiInfo {
30983098 is_inter: true,
30993099 ref_frame: LAST_FRAME,
3100- ref_frame1: None,
3101- mv1: None,
3100+ ref_frame1: NO_REF1,
3101+ mv1: (0, 0),
31023102 mv: info.mv,
31033103 is_new_mv: matches!(info.mode, InterMode::NewMv),
31043104 size: 8,
@@ -3113,8 +3113,8 @@ pub(crate) fn encode_inter_frame(
31133113 None => MiInfo {
31143114 is_inter: false,
31153115 ref_frame: -1,
3116- ref_frame1: None,
3117- mv1: None,
3116+ ref_frame1: NO_REF1,
3117+ mv1: (0, 0),
31183118 mv: (0, 0),
31193119 is_new_mv: false,
31203120 size: 8,
@@ -3195,8 +3195,8 @@ pub(crate) fn encode_inter_frame(
31953195 Some(info) => MiInfo {
31963196 is_inter: true,
31973197 ref_frame: LAST_FRAME,
3198- ref_frame1: None,
3199- mv1: None,
3198+ ref_frame1: NO_REF1,
3199+ mv1: (0, 0),
32003200 mv: info.mv,
32013201 is_new_mv: matches!(info.mode, InterMode::NewMv),
32023202 size: 4,
@@ -3207,8 +3207,8 @@ pub(crate) fn encode_inter_frame(
32073207 None => MiInfo {
32083208 is_inter: false,
32093209 ref_frame: -1,
3210- ref_frame1: None,
3211- mv1: None,
3210+ ref_frame1: NO_REF1,
3211+ mv1: (0, 0),
32123212 mv: (0, 0),
32133213 is_new_mv: false,
32143214 size: 4,
@@ -3255,8 +3255,8 @@ pub(crate) fn encode_inter_frame(
32553255 Some(info) => MiInfo {
32563256 is_inter: true,
32573257 ref_frame: LAST_FRAME,
3258- ref_frame1: None,
3259- mv1: None,
3258+ ref_frame1: NO_REF1,
3259+ mv1: (0, 0),
32603260 mv: info.mv,
32613261 is_new_mv: matches!(
32623262 info.mode,
@@ -3270,8 +3270,8 @@ pub(crate) fn encode_inter_frame(
32703270 None => MiInfo {
32713271 is_inter: false,
32723272 ref_frame: -1,
3273- ref_frame1: None,
3274- mv1: None,
3273+ ref_frame1: NO_REF1,
3274+ mv1: (0, 0),
32753275 mv: (0, 0),
32763276 is_new_mv: false,
32773277 size: 2,
crates/ec-av1/src/mvstack.rsmodified+183 -65
@@ -155,6 +155,12 @@ pub struct TplArgs<'a> {
155155 pub allow_high_precision_mv: bool,
156156 }
157157
158+/// [`MiInfo::ref_frame1`]'s "this unit was not coded compound" value. Slot 1
159+/// only ever holds a real reference (`0`..=`7`, `0` being `INTRA_FRAME` for
160+/// an interintra unit), so `-1` tags the slot -- and with it [`MiInfo::mv1`]
161+/// -- as absent without an `Option` tag word per grid cell.
162+pub const NO_REF1: i8 = -1;
163+
158164 /// One 4x4 `mi` unit's motion state, as the encode loop will have filled it
159165 /// in by the time it asks for a block's MV stack.
160166 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -173,12 +179,12 @@ pub struct MiInfo {
173179 /// desync (a `new_mv_ctx` fed by a `newmv_count`/`nearest_match` that
174180 /// silently dropped a compound neighbour's vote whenever its match sat
175181 /// in this slot).
176- pub ref_frame1: Option<i8>,
182+ pub ref_frame1: i8,
177183 /// The unit's motion vector, `(row, col)`, in the spec's 1/8-pel units.
178184 pub mv: (i32, i32),
179185 /// The unit's second motion vector, matching `ref_frame1` (spec
180186 /// `Mvs[1]`) — `Some` only for a compound-coded unit, `None` otherwise.
181- pub mv1: Option<(i32, i32)>,
187+ pub mv1: (i32, i32),
182188 /// Whether this unit's own mode was `NEWMV` (spec's
183189 /// `have_newmv_in_inter_mode`, compound modes excluded since this module
184190 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a
@@ -272,6 +278,23 @@ impl MiGrid {
272278 }
273279 }
274280
281+ /// Records one block's whole `bh4` x `bw4` footprint at once. Every
282+ /// caller published a block cell-by-cell through [`Self::set`]; the rows
283+ /// are contiguous, so this fills each of them with one `slice::fill` of
284+ /// the (`Copy`) cell instead, the way the neighbour grids' own span fills
285+ /// do.
286+ pub fn fill_rect(&mut self, row: usize, col: usize, h: usize, w: usize, info: MiInfo) {
287+ if col >= self.cols || row >= self.rows {
288+ return;
289+ }
290+ let w = w.min(self.cols - col);
291+ let cell = Some(info);
292+ for r in row..(row + h).min(self.rows) {
293+ let base = r * self.cols + col;
294+ self.cells[base..base + w].fill(cell);
295+ }
296+ }
297+
275298 /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't
276299 /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]).
277300 pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {
@@ -307,7 +330,7 @@ impl MiGrid {
307330
308331 /// One entry of the reference MV stack: a candidate motion vector and the
309332 /// total weight the neighbours that agreed on it contributed.
310-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
333+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
311334 pub struct StackEntry {
312335 /// The candidate `(row, col)` motion vector.
313336 pub mv: (i32, i32),
@@ -315,6 +338,85 @@ pub struct StackEntry {
315338 pub weight: u32,
316339 }
317340
341+/// A fixed-capacity, heap-free candidate list. The MV stack is rebuilt for
342+/// EVERY inter block, so the `Vec` this replaces was one malloc/free pair per
343+/// block (plus one for `drl_ctx`); capacity is a spec constant
344+/// ([`MAX_STACK_SIZE`]), so the storage is inline and `Deref` hands every
345+/// consumer the same slice API a `Vec` did.
346+#[derive(Clone, Copy, Debug)]
347+pub struct SmallVec<T: Copy, const N: usize> {
348+ len: u8,
349+ buf: [T; N],
350+}
351+
352+impl<T: Copy + Default, const N: usize> Default for SmallVec<T, N> {
353+ fn default() -> Self {
354+ Self {
355+ len: 0,
356+ buf: [T::default(); N],
357+ }
358+ }
359+}
360+
361+impl<T: Copy, const N: usize> SmallVec<T, N> {
362+ /// Appends `v`. Callers gate on [`MAX_STACK_SIZE`] before pushing (the
363+ /// spec drops the overflowing candidate at insertion), so a full list
364+ /// here is a bug, not a stream property.
365+ pub fn push(&mut self, v: T) {
366+ debug_assert!((self.len as usize) < N);
367+ self.buf[self.len as usize] = v;
368+ self.len += 1;
369+ }
370+
371+ /// `Vec::truncate`.
372+ pub fn truncate(&mut self, n: usize) {
373+ if n < self.len as usize {
374+ self.len = n as u8;
375+ }
376+ }
377+}
378+
379+impl<T: Copy + Default, const N: usize> FromIterator<T> for SmallVec<T, N> {
380+ fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self {
381+ let mut out = Self::default();
382+ for v in iter {
383+ out.push(v);
384+ }
385+ out
386+ }
387+}
388+
389+impl<T: Copy, const N: usize> std::ops::Deref for SmallVec<T, N> {
390+ type Target = [T];
391+ fn deref(&self) -> &[T] {
392+ &self.buf[..self.len as usize]
393+ }
394+}
395+
396+impl<T: Copy, const N: usize> std::ops::DerefMut for SmallVec<T, N> {
397+ fn deref_mut(&mut self) -> &mut [T] {
398+ &mut self.buf[..self.len as usize]
399+ }
400+}
401+
402+impl<T: Copy + PartialEq, const N: usize> PartialEq for SmallVec<T, N> {
403+ fn eq(&self, other: &Self) -> bool {
404+ **self == **other
405+ }
406+}
407+
408+impl<T: Copy + Eq, const N: usize> Eq for SmallVec<T, N> {}
409+
410+/// The single-reference MV stack's own list type.
411+pub type StackVec = SmallVec<StackEntry, MAX_STACK_SIZE>;
412+
413+/// The compound MV stack's own list type.
414+pub type CompoundStackVec = SmallVec<CompoundStackEntry, MAX_STACK_SIZE>;
415+
416+/// `drl_ctx`: one context per adjacent stack pair, so at most
417+/// `MAX_STACK_SIZE - 1` of them.
418+pub type DrlVec = SmallVec<usize, MAX_STACK_SIZE>;
419+
318420 /// The result of [`find_mv_stack`]: the sorted candidate list, the two
319421 /// predictors a `NEARESTMV`/`NEARMV` block reads from it, the predictor a
320422 /// `NEWMV` residual is coded against, and the symbol contexts the block's
@@ -323,7 +425,7 @@ pub struct StackEntry {
323425 pub struct MvStack {
324426 /// The candidates, highest weight first (ties keep scan order: above,
325427 /// then left, then top-right).
326- pub entries: Vec<StackEntry>,
428+ pub entries: StackVec,
327429 /// `RefStackMv[0]`, or `(0, 0)` when the stack is empty.
328430 pub nearest_mv: (i32, i32),
329431 /// `RefStackMv[1]`, or `(0, 0)` when the stack has fewer than two
@@ -340,7 +442,7 @@ pub struct MvStack {
340442 pub zero_mv_ctx: usize,
341443 /// Context for each `drl_mode` symbol between consecutive stack
342444 /// entries, `entries.len().saturating_sub(1)` long.
343- pub drl_ctx: Vec<usize>,
445+ pub drl_ctx: DrlVec,
344446 }
345447
346448 /// Spec 7.10.2.8's threshold a candidate's weight is compared against to
@@ -377,7 +479,7 @@ const MVREF_ROW_COLS: usize = 3;
377479 /// Adds one candidate MV with `weight` to `candidates`, merging it into an
378480 /// existing entry with the same MV rather than duplicating it (spec
379481 /// `add_ref_mv_candidate`, 7.10.2.5).
380-fn add_candidate(candidates: &mut Vec<StackEntry>, mv: (i32, i32), weight: u32) {
482+fn add_candidate(candidates: &mut StackVec, mv: (i32, i32), weight: u32) {
381483 if let Some(entry) = candidates.iter_mut().find(|e| e.mv == mv) {
382484 entry.weight += weight;
383485 } else if candidates.len() >= MAX_STACK_SIZE {
@@ -468,7 +570,7 @@ fn process_single_ref_mv_candidate(
468570 candidate: &MiInfo,
469571 ref_frame: i8,
470572 sign_bias_table: &SignBiasTable,
471- candidates: &mut Vec<StackEntry>,
573+ candidates: &mut StackVec,
472574 ) {
473575 if !candidate.is_inter {
474576 return;
@@ -479,8 +581,11 @@ fn process_single_ref_mv_candidate(
479581 // never checks `is_global_mv_block`/substitutes `gm_mv_candidates`.
480582 let mut slots = [(candidate.ref_frame, candidate.mv); 2];
481583 let mut n_slots = 1;
482- if let (Some(rf1), Some(mv1)) = (candidate.ref_frame1, candidate.mv1) {
483- slots[1] = (rf1, mv1);
584+ // `mv1` is meaningful only for a compound neighbour (`ref_frame1 > 0`);
585+ // an interintra one stores `INTRA_FRAME` (0) with no second MV, and used
586+ // to be excluded here by its `mv1` being `None`.
587+ if candidate.ref_frame1 > 0 {
588+ slots[1] = (candidate.ref_frame1, candidate.mv1);
484589 n_slots = 2;
485590 }
486591 for &(rf, mv) in &slots[..n_slots] {
@@ -538,7 +643,7 @@ fn scan_row(
538643 max_row_offset: isize,
539644 ref_frame: i8,
540645 gm: &GmMvTable,
541- candidates: &mut Vec<StackEntry>,
646+ candidates: &mut StackVec,
542647 newmv_count: &mut u32,
543648 processed_rows: &mut usize,
544649 ) -> bool {
@@ -603,11 +708,11 @@ fn single_ref_match(info: &MiInfo, ref_frame: i8, gm: &GmMvTable) -> Option<(i32
603708 } else {
604709 info.mv
605710 })
606- } else if info.ref_frame1 == Some(ref_frame) {
711+ } else if info.ref_frame1 > 0 && info.ref_frame1 == ref_frame {
607712 if info.is_global_mv1 {
608713 Some(gm_mv(gm, ref_frame))
609714 } else {
610- info.mv1
715+ Some(info.mv1)
611716 }
612717 } else {
613718 None
@@ -626,7 +731,7 @@ fn scan_col(
626731 max_col_offset: isize,
627732 ref_frame: i8,
628733 gm: &GmMvTable,
629- candidates: &mut Vec<StackEntry>,
734+ candidates: &mut StackVec,
630735 newmv_count: &mut u32,
631736 processed_cols: &mut usize,
632737 ) -> bool {
@@ -762,7 +867,7 @@ fn scan_top_right(
762867 bw4: usize,
763868 ref_frame: i8,
764869 gm: &GmMvTable,
765- candidates: &mut Vec<StackEntry>,
870+ candidates: &mut StackVec,
766871 newmv_count: &mut u32,
767872 ) -> bool {
768873 let Some(row) = mi_row.checked_sub(1) else {
@@ -791,7 +896,7 @@ fn scan_corner(
791896 mi_col: usize,
792897 ref_frame: i8,
793898 gm: &GmMvTable,
794- candidates: &mut Vec<StackEntry>,
899+ candidates: &mut StackVec,
795900 newmv_count: &mut u32,
796901 ) -> bool {
797902 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {
@@ -919,7 +1024,7 @@ pub fn find_mv_stack_with_sign_bias(
9191024 ) -> MvStack {
9201025 // lane-alloc: the stack is capped at MAX_STACK_SIZE entries, so the pushes
9211026 // below grew (and memcpy'd) a fresh allocation up to 4 times per block.
922- let mut candidates = Vec::with_capacity(MAX_STACK_SIZE);
1027+ let mut candidates = StackVec::default();
9231028 let mut newmv_count = 0u32;
9241029
9251030 // libaom's `max_row_offset`/`max_col_offset` (`setup_ref_mv_list`): how
@@ -1011,7 +1116,7 @@ pub fn find_mv_stack_with_sign_bias(
10111116 // av1_find_mv_stack boosts only the entries the immediate scan found —
10121117 // exactly `candidates` at this point, before the corner probe (below)
10131118 // can add anything else (mvref_common.c ~line 544-545).
1014- for entry in &mut candidates {
1119+ for entry in candidates.iter_mut() {
10151120 entry.weight += REF_CAT_LEVEL;
10161121 }
10171122
@@ -1371,7 +1476,7 @@ pub fn find_mv_stack_with_sign_bias(
13711476 /// combined weight — spec 7.10.2's compound half of `add_ref_mv_candidate`
13721477 /// (libaom `mvref_common.c`, the `is_compound` branch of `scan_row_mbmi`/
13731478 /// `scan_col_mbmi`/`scan_blk_mbmi`).
1374-#[derive(Clone, Copy, Debug, PartialEq, Eq)]
1479+#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
13751480 pub struct CompoundStackEntry {
13761481 /// The candidate's vote for `RefFrame[0]`'s motion vector.
13771482 pub mv0: (i32, i32),
@@ -1386,7 +1491,7 @@ pub struct CompoundStackEntry {
13861491 #[derive(Clone, Debug, PartialEq, Eq)]
13871492 pub struct CompoundMvStack {
13881493 /// The candidates, highest weight first.
1389- pub entries: Vec<CompoundStackEntry>,
1494+ pub entries: CompoundStackVec,
13901495 /// `RefStackMv[0]` for both refs, or `((0,0),(0,0))` when the stack is
13911496 /// empty.
13921497 pub nearest_mv: ((i32, i32), (i32, i32)),
@@ -1403,12 +1508,12 @@ pub struct CompoundMvStack {
14031508 /// Context for the compound `zero_mv` symbol.
14041509 pub zero_mv_ctx: usize,
14051510 /// Context for each `drl_mode` symbol between consecutive stack entries.
1406- pub drl_ctx: Vec<usize>,
1511+ pub drl_ctx: DrlVec,
14071512 }
14081513
14091514 /// [`add_candidate`], doubled: dedupes on the whole `(mv0, mv1)` pair.
14101515 fn add_compound_candidate(
1411- candidates: &mut Vec<CompoundStackEntry>,
1516+ candidates: &mut CompoundStackVec,
14121517 mv0: (i32, i32),
14131518 mv1: (i32, i32),
14141519 weight: u32,
@@ -1443,7 +1548,7 @@ fn scan_row_compound(
14431548 max_row_offset: isize,
14441549 ref_frame: (i8, i8),
14451550 gm: &GmMvTable,
1446- candidates: &mut Vec<CompoundStackEntry>,
1551+ candidates: &mut CompoundStackVec,
14471552 newmv_count: &mut u32,
14481553 processed_rows: &mut usize,
14491554 ) -> bool {
@@ -1479,12 +1584,12 @@ fn scan_row_compound(
14791584 weight = weight.max(inc as u32);
14801585 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
14811586 }
1482- if info.is_inter && info.ref_frame == ref_frame.0 && info.ref_frame1 == Some(ref_frame.1) {
1587+ if info.is_inter && info.ref_frame == ref_frame.0 && info.ref_frame1 > 0 && info.ref_frame1 == ref_frame.1 {
14831588 found = true;
14841589 add_compound_candidate(
14851590 candidates,
14861591 if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1487- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1592+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
14881593 len as u32 * weight,
14891594 );
14901595 *newmv_count += u32::from(info.is_new_mv);
@@ -1506,7 +1611,7 @@ fn scan_col_compound(
15061611 max_col_offset: isize,
15071612 ref_frame: (i8, i8),
15081613 gm: &GmMvTable,
1509- candidates: &mut Vec<CompoundStackEntry>,
1614+ candidates: &mut CompoundStackVec,
15101615 newmv_count: &mut u32,
15111616 processed_cols: &mut usize,
15121617 ) -> bool {
@@ -1542,12 +1647,12 @@ fn scan_col_compound(
15421647 weight = weight.max(inc as u32);
15431648 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
15441649 }
1545- if info.is_inter && info.ref_frame == ref_frame.0 && info.ref_frame1 == Some(ref_frame.1) {
1650+ if info.is_inter && info.ref_frame == ref_frame.0 && info.ref_frame1 > 0 && info.ref_frame1 == ref_frame.1 {
15461651 found = true;
15471652 add_compound_candidate(
15481653 candidates,
15491654 if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1550- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1655+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
15511656 len as u32 * weight,
15521657 );
15531658 *newmv_count += u32::from(info.is_new_mv);
@@ -1566,7 +1671,7 @@ fn scan_top_right_compound(
15661671 bw4: usize,
15671672 ref_frame: (i8, i8),
15681673 gm: &GmMvTable,
1569- candidates: &mut Vec<CompoundStackEntry>,
1674+ candidates: &mut CompoundStackVec,
15701675 newmv_count: &mut u32,
15711676 ) -> bool {
15721677 let Some(row) = mi_row.checked_sub(1) else {
@@ -1576,12 +1681,12 @@ fn scan_top_right_compound(
15761681 if let Some(info) = grid.get(row, col)
15771682 && info.is_inter
15781683 && info.ref_frame == ref_frame.0
1579- && info.ref_frame1 == Some(ref_frame.1)
1684+ && info.ref_frame1 > 0 && info.ref_frame1 == ref_frame.1
15801685 {
15811686 add_compound_candidate(
15821687 candidates,
15831688 if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1584- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1689+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
15851690 CORNER_WEIGHT,
15861691 );
15871692 *newmv_count += u32::from(info.is_new_mv);
@@ -1597,7 +1702,7 @@ fn scan_corner_compound(
15971702 mi_col: usize,
15981703 ref_frame: (i8, i8),
15991704 gm: &GmMvTable,
1600- candidates: &mut Vec<CompoundStackEntry>,
1705+ candidates: &mut CompoundStackVec,
16011706 newmv_count: &mut u32,
16021707 ) -> bool {
16031708 let (Some(row), Some(col)) = (mi_row.checked_sub(1), mi_col.checked_sub(1)) else {
@@ -1606,12 +1711,12 @@ fn scan_corner_compound(
16061711 if let Some(info) = grid.get(row, col)
16071712 && info.is_inter
16081713 && info.ref_frame == ref_frame.0
1609- && info.ref_frame1 == Some(ref_frame.1)
1714+ && info.ref_frame1 > 0 && info.ref_frame1 == ref_frame.1
16101715 {
16111716 add_compound_candidate(
16121717 candidates,
16131718 if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1614- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1.unwrap_or((0, 0)) },
1719+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
16151720 CORNER_WEIGHT,
16161721 );
16171722 *newmv_count += u32::from(info.is_new_mv);
@@ -1653,13 +1758,10 @@ fn process_compound_ref_mv_candidate(
16531758 }
16541759 let slots = [
16551760 Some((candidate.ref_frame, candidate.mv)),
1656- candidate
1657- .ref_frame1
1658- // An interintra neighbour stores INTRA_FRAME (0) here; libaom's
1659- // ref-diff scan requires `can_rf > INTRA_FRAME`
1660- // (process_compound_ref_mv_candidate), so it contributes nothing.
1661- .filter(|&rf1| rf1 > 0)
1662- .map(|rf1| (rf1, candidate.mv1.unwrap_or((0, 0)))),
1761+ // An interintra neighbour stores INTRA_FRAME (0) here; libaom's
1762+ // ref-diff scan requires `can_rf > INTRA_FRAME`
1763+ // (process_compound_ref_mv_candidate), so it contributes nothing.
1764+ (candidate.ref_frame1 > 0).then_some((candidate.ref_frame1, candidate.mv1)),
16631765 ];
16641766 for (candidate_ref, candidate_mv) in slots.into_iter().flatten() {
16651767 for (i, side_ref) in [ref_frame.0, ref_frame.1].into_iter().enumerate() {
@@ -1748,7 +1850,7 @@ pub fn find_mv_stack_compound(
17481850 gm: &GmMvTable,
17491851 tpl: Option<CompoundTplArgs>,
17501852 ) -> CompoundMvStack {
1751- let mut candidates: Vec<CompoundStackEntry> = Vec::with_capacity(MAX_STACK_SIZE);
1853+ let mut candidates = CompoundStackVec::default();
17521854 let mut newmv_count = 0u32;
17531855
17541856 let row_adj = bh4 < 2 && mi_row % 2 == 1;
@@ -1828,7 +1930,7 @@ pub fn find_mv_stack_compound(
18281930 let row_matched = found_above || found_top_right;
18291931 let nearest_match = usize::from(row_matched) + usize::from(found_left);
18301932
1831- for entry in &mut candidates {
1933+ for entry in candidates.iter_mut() {
18321934 entry.weight += REF_CAT_LEVEL;
18331935 }
18341936
@@ -2432,12 +2534,28 @@ mod tests {
24322534
24332535 use super::*;
24342536
2537+
2538+ /// lane-mvstack2: the mi grid is one cell per 4x4 unit of the frame and
2539+ /// `find_mv_stack` walks it for every inter block, so the cell's SIZE is
2540+ /// the scan's memory traffic. `ref_frame1`/`mv1` are validity-tagged by
2541+ /// `ref_frame1 == NO_REF1` rather than by two `Option` tags (32 bytes ->
2542+ /// 24), and `is_inter` keeps a niche so the grid's `Option<MiInfo>` costs
2543+ /// no extra word.
2544+ #[test]
2545+ fn mi_info_cell_stays_compact() {
2546+ assert_eq!(std::mem::size_of::<MiInfo>(), 24);
2547+ assert_eq!(
2548+ std::mem::size_of::<Option<MiInfo>>(),
2549+ std::mem::size_of::<MiInfo>()
2550+ );
2551+ }
2552+
24352553 fn inter(mv: (i32, i32)) -> MiInfo {
24362554 MiInfo {
24372555 is_inter: true,
24382556 ref_frame: 1,
2439- ref_frame1: None,
2440- mv1: None,
2557+ ref_frame1: NO_REF1,
2558+ mv1: (0, 0),
24412559 mv,
24422560 is_new_mv: false,
24432561 // 1: smaller than every `bw4`/`bh4` these small-grid tests use,
@@ -2595,8 +2713,8 @@ mod tests {
25952713 MiInfo {
25962714 is_inter: true,
25972715 ref_frame: 1,
2598- ref_frame1: None,
2599- mv1: None,
2716+ ref_frame1: NO_REF1,
2717+ mv1: (0, 0),
26002718 mv: (4, 4),
26012719 is_new_mv: true,
26022720 size: 1,
@@ -2635,7 +2753,7 @@ mod tests {
26352753 assert_eq!(stack.entries.len(), 2);
26362754 assert_eq!(stack.entries[0].mv, (4, 4));
26372755 assert_eq!(stack.entries[1].mv, (8, 8));
2638- assert_eq!(stack.drl_ctx, vec![1]);
2756+ assert_eq!(&stack.drl_ctx[..], &[1]);
26392757 }
26402758
26412759 #[test]
@@ -2678,8 +2796,8 @@ mod tests {
26782796 MiInfo {
26792797 is_inter: true,
26802798 ref_frame: 1,
2681- ref_frame1: None,
2682- mv1: None,
2799+ ref_frame1: NO_REF1,
2800+ mv1: (0, 0),
26832801 mv,
26842802 is_new_mv: false,
26852803 size: 8,
@@ -2710,8 +2828,8 @@ mod tests {
27102828 MiInfo {
27112829 is_inter: false,
27122830 ref_frame: -1,
2713- ref_frame1: None,
2714- mv1: None,
2831+ ref_frame1: NO_REF1,
2832+ mv1: (0, 0),
27152833 mv: (0, 0),
27162834 is_new_mv: false,
27172835 size: 8,
@@ -2729,8 +2847,8 @@ mod tests {
27292847 MiInfo {
27302848 is_inter: true,
27312849 ref_frame: 1,
2732- ref_frame1: None,
2733- mv1: None,
2850+ ref_frame1: NO_REF1,
2851+ mv1: (0, 0),
27342852 mv,
27352853 is_new_mv: false,
27362854 size: 8,
@@ -2969,9 +3087,9 @@ mod tests {
29693087 MiInfo {
29703088 is_inter: true,
29713089 ref_frame: COMP_PAIR.0,
2972- ref_frame1: Some(COMP_PAIR.1),
3090+ ref_frame1: COMP_PAIR.1,
29733091 mv: mv0,
2974- mv1: Some(mv1),
3092+ mv1,
29753093 is_new_mv: false,
29763094 size: 1,
29773095 size_h: 1,
@@ -2992,9 +3110,9 @@ mod tests {
29923110 MiInfo {
29933111 is_inter: true,
29943112 ref_frame: LAST_FRAME,
2995- ref_frame1: Some(GOLDEN_FRAME),
3113+ ref_frame1: GOLDEN_FRAME,
29963114 mv: (9, 9),
2997- mv1: Some((9, 9)),
3115+ mv1: (9, 9),
29983116 is_new_mv: false,
29993117 size: 1,
30003118 size_h: 1,
@@ -3095,9 +3213,9 @@ mod tests {
30953213 let candidate = MiInfo {
30963214 is_inter: true,
30973215 ref_frame: LAST_FRAME,
3098- ref_frame1: None,
3216+ ref_frame1: NO_REF1,
30993217 mv: (5, 5),
3100- mv1: None,
3218+ mv1: (0, 0),
31013219 is_new_mv: false,
31023220 size: 1,
31033221 size_h: 1,
@@ -3124,9 +3242,9 @@ mod tests {
31243242 MiInfo {
31253243 is_inter: true,
31263244 ref_frame: LAST_FRAME,
3127- ref_frame1: None,
3245+ ref_frame1: NO_REF1,
31283246 mv: (7, 7),
3129- mv1: None,
3247+ mv1: (0, 0),
31303248 is_new_mv: false,
31313249 size: 8,
31323250 size_h: 8,
@@ -3140,9 +3258,9 @@ mod tests {
31403258 MiInfo {
31413259 is_inter: true,
31423260 ref_frame: ALTREF_FRAME,
3143- ref_frame1: None,
3261+ ref_frame1: NO_REF1,
31443262 mv: (-3, -3),
3145- mv1: None,
3263+ mv1: (0, 0),
31463264 is_new_mv: false,
31473265 size: 8,
31483266 size_h: 8,
@@ -3197,7 +3315,7 @@ mod tests {
31973315 /// candidate would survive and evict a scanned one.
31983316 #[test]
31993317 fn the_ninth_distinct_candidate_is_dropped_at_insertion_not_after_sorting() {
3200- let mut candidates = Vec::new();
3318+ let mut candidates = StackVec::default();
32013319 for i in 0..MAX_STACK_SIZE as i32 {
32023320 add_candidate(&mut candidates, (i, i), 2);
32033321 }
@@ -3211,7 +3329,7 @@ mod tests {
32113329 add_candidate(&mut candidates, (0, 0), 6);
32123330 assert_eq!(candidates[0].weight, 8);
32133331
3214- let mut comp = Vec::new();
3332+ let mut comp = CompoundStackVec::default();
32153333 for i in 0..MAX_STACK_SIZE as i32 {
32163334 add_compound_candidate(&mut comp, (i, i), (i, -i), 2);
32173335 }
crates/ec-av1/src/tile.rsmodified+17 -17
@@ -16,7 +16,7 @@ use ec_core::{Error, Result};
1616 use crate::cdf;
1717 use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables};
1818 use crate::msac::SymbolEncoder;
19-use crate::mvstack::{MiGrid, MiInfo, find_mv_stack, single_ref_ctx};
19+use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, single_ref_ctx};
2020
2121 /// round-4 av1-truesize debugging aid: prints `msg()` to stderr when the
2222 /// `EC_RNG` environment variable is set, mirroring the `EC_PART`/`EC_TOK`
@@ -2434,8 +2434,8 @@ pub fn sb_coeff_inter_frame_tile(
24342434 MiInfo {
24352435 is_inter: true,
24362436 ref_frame: LAST_FRAME,
2437- ref_frame1: None,
2438- mv1: None,
2437+ ref_frame1: NO_REF1,
2438+ mv1: (0, 0),
24392439 mv,
24402440 is_new_mv,
24412441 size: 8,
@@ -2455,8 +2455,8 @@ pub fn sb_coeff_inter_frame_tile(
24552455 MiInfo {
24562456 is_inter: true,
24572457 ref_frame: LAST_FRAME,
2458- ref_frame1: None,
2459- mv1: None,
2458+ ref_frame1: NO_REF1,
2459+ mv1: (0, 0),
24602460 mv,
24612461 is_new_mv,
24622462 size: 8,
@@ -2487,8 +2487,8 @@ pub fn sb_coeff_inter_frame_tile(
24872487 MiInfo {
24882488 is_inter: false,
24892489 ref_frame: -1,
2490- ref_frame1: None,
2491- mv1: None,
2490+ ref_frame1: NO_REF1,
2491+ mv1: (0, 0),
24922492 mv: (0, 0),
24932493 is_new_mv: false,
24942494 size: 8,
@@ -2630,8 +2630,8 @@ fn write_inter_frame_leaf(
26302630 MiInfo {
26312631 is_inter: true,
26322632 ref_frame: LAST_FRAME,
2633- ref_frame1: None,
2634- mv1: None,
2633+ ref_frame1: NO_REF1,
2634+ mv1: (0, 0),
26352635 mv,
26362636 is_new_mv,
26372637 size: SUB_MI as usize as u8,
@@ -2662,8 +2662,8 @@ fn write_inter_frame_leaf(
26622662 MiInfo {
26632663 is_inter: false,
26642664 ref_frame: -1,
2665- ref_frame1: None,
2666- mv1: None,
2665+ ref_frame1: NO_REF1,
2666+ mv1: (0, 0),
26672667 mv: (0, 0),
26682668 is_new_mv: false,
26692669 size: SUB_MI as usize as u8,
@@ -2828,8 +2828,8 @@ fn write_inter_frame_leaf8(
28282828 MiInfo {
28292829 is_inter: true,
28302830 ref_frame: LAST_FRAME,
2831- ref_frame1: None,
2832- mv1: None,
2831+ ref_frame1: NO_REF1,
2832+ mv1: (0, 0),
28332833 mv,
28342834 is_new_mv,
28352835 size: 2,
@@ -2860,8 +2860,8 @@ fn write_inter_frame_leaf8(
28602860 MiInfo {
28612861 is_inter: false,
28622862 ref_frame: -1,
2863- ref_frame1: None,
2864- mv1: None,
2863+ ref_frame1: NO_REF1,
2864+ mv1: (0, 0),
28652865 mv: (0, 0),
28662866 is_new_mv: false,
28672867 size: 2,
@@ -5138,8 +5138,8 @@ mod tests {
51385138 MiInfo {
51395139 is_inter: true,
51405140 ref_frame: 1,
5141- ref_frame1: None,
5142- mv1: None,
5141+ ref_frame1: NO_REF1,
5142+ mv1: (0, 0),
51435143 mv,
51445144 is_new_mv,
51455145 size: 8,