forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-migrid' (088359d4): mode-info cell mvs stored as i16 pairs (spec MV width), cell 24 -> 16 bytes with the Option niche kept; a separate packed storage type measured worse and was dropped; byte-exact

Browse files at this commit

351fda03e04b84157f6cd1eccffd811b2f30212fAhmet Kaan GümüşParent: 5e5cc093ec98b7
crates/ec-av1/src/decode.rsmodified+37 -37
@@ -221,7 +221,7 @@ use crate::msac::SymbolDecoder;
221221 use crate::mvstack::{
222222 ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME,
223223 MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx,
224- find_mv_stack_with_sign_bias, reference_mode_ctx,
224+ find_mv_stack_with_sign_bias, mv16, mv32, 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,
227227 };
@@ -3380,7 +3380,7 @@ fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>
33803380 is_inter: dv.is_some(),
33813381 ref_frame: 0,
33823382 ref_frame1: NO_REF1,
3383- mv: dv.unwrap_or((0, 0)),
3383+ mv: mv16(dv.unwrap_or((0, 0))),
33843384 mv1: (0, 0),
33853385 is_new_mv: dv.is_some(),
33863386 is_global_mv0: false,
@@ -4854,8 +4854,8 @@ pub(crate) fn build_motion_field(
48544854 // projected with the wrong reference distance.
48554855 let mut saved: Option<crate::motion_field::SavedMv> = None;
48564856 for (rf, mv) in [
4857- (info.ref_frame, Some(info.mv)),
4858- (info.ref_frame1.max(0), Some(info.mv1)),
4857+ (info.ref_frame, Some(mv32(info.mv))),
4858+ (info.ref_frame1.max(0), Some(mv32(info.mv1))),
48594859 ] {
48604860 let (Some(mv), true) = (mv, rf > 0) else {
48614861 continue;
@@ -22667,7 +22667,7 @@ fn overlappable_above(
2266722667 // neighbour PREDICTION at a frame edge, which picks the
2266822668 // 4-tap kernel below 8 px (class narrow-block-sharp-kernel);
2266922669 // the destination clip stays in `obmc_blend`.
22670- out.push((col - mi_col, step.min(bw4), *info, src - mi_col));
22670+ out.push((col - mi_col, step.min(bw4), info, src - mi_col));
2267122671 }
2267222672 }
2267322673 col += step;
@@ -22716,7 +22716,7 @@ fn overlappable_left(
2271622716 }
2271722717 // lane-t900 r14: `AOMMIN(xd->height, mi_step)` -- see
2271822718 // `overlappable_above`.
22719- out.push((row - mi_row, step.min(bh4), *info, src - mi_row));
22719+ out.push((row - mi_row, step.min(bh4), info, src - mi_row));
2272022720 }
2272122721 }
2272222722 row += step;
@@ -22787,7 +22787,7 @@ fn find_samples(
2278722787 // neighbour donates its sample at ITS center (aom pts y=-72 for a
2278822788 // 32x16 above strip; the square assumption put it at -136).
2278922789 let nb_bh = (info.size_h * 4) as i32;
22790- crate::warp::record_sample(nb_bw, nb_bh, info.mv, row_offset, sign_r, col_offset, sign_c)
22790+ crate::warp::record_sample(nb_bw, nb_bh, mv32(info.mv), row_offset, sign_r, col_offset, sign_c)
2279122791 };
2279222792
2279322793 'outer: {
@@ -22803,8 +22803,8 @@ fn find_samples(
2280322803 do_tr = false;
2280422804 }
2280522805 if let Some(info) = above {
22806- if single_ref_match(info) {
22807- samples.push(rec(info, 0, -1, col_offset as i32, 1));
22806+ if single_ref_match(&info) {
22807+ samples.push(rec(&info, 0, -1, col_offset as i32, 1));
2280822808 if samples.len() >= MAX {
2280922809 break 'outer;
2281022810 }
@@ -22817,8 +22817,8 @@ fn find_samples(
2281722817 let cell = grid.get(mi_row - 1, mi_col + i);
2281822818 let sw = cell.map_or(1, |c| c.size as usize).max(1);
2281922819 if let Some(info) = cell {
22820- if single_ref_match(info) {
22821- samples.push(rec(info, 0, -1, i as i32, 1));
22820+ if single_ref_match(&info) {
22821+ samples.push(rec(&info, 0, -1, i as i32, 1));
2282222822 if samples.len() >= MAX {
2282322823 break 'outer;
2282422824 }
@@ -22838,8 +22838,8 @@ fn find_samples(
2283822838 do_tl = false;
2283922839 }
2284022840 if let Some(info) = left {
22841- if single_ref_match(info) {
22842- samples.push(rec(info, row_offset as i32, 1, 0, -1));
22841+ if single_ref_match(&info) {
22842+ samples.push(rec(&info, row_offset as i32, 1, 0, -1));
2284322843 if samples.len() >= MAX {
2284422844 break 'outer;
2284522845 }
@@ -22852,8 +22852,8 @@ fn find_samples(
2285222852 let cell = grid.get(mi_row + i, mi_col - 1);
2285322853 let sh = cell.map_or(1, |c| c.size_h as usize).max(1);
2285422854 if let Some(info) = cell {
22855- if single_ref_match(info) {
22856- samples.push(rec(info, i as i32, 1, 0, -1));
22855+ if single_ref_match(&info) {
22856+ samples.push(rec(&info, i as i32, 1, 0, -1));
2285722857 if samples.len() >= MAX {
2285822858 break 'outer;
2285922859 }
@@ -22866,8 +22866,8 @@ fn find_samples(
2286622866
2286722867 if do_tl && left_available && up_available {
2286822868 if let Some(info) = grid.get(mi_row - 1, mi_col - 1) {
22869- if single_ref_match(info) {
22870- samples.push(rec(info, 0, -1, 0, -1));
22869+ if single_ref_match(&info) {
22870+ samples.push(rec(&info, 0, -1, 0, -1));
2287122871 if samples.len() >= MAX {
2287222872 break 'outer;
2287322873 }
@@ -22890,8 +22890,8 @@ fn find_samples(
2289022890 let tr_col = mi_col + bw4;
2289122891 if mi_row > 0 && tr_col < mi_cols {
2289222892 if let Some(info) = grid.get(mi_row - 1, tr_col) {
22893- if single_ref_match(info) {
22894- samples.push(rec(info, 0, -1, bw4 as i32, 1));
22893+ if single_ref_match(&info) {
22894+ samples.push(rec(&info, 0, -1, bw4 as i32, 1));
2289522895 }
2289622896 }
2289722897 }
@@ -23425,7 +23425,7 @@ fn obmc_blend(
2342523425 let above_syms = neighbours.above_filter[mi_col + src4];
2342623426 obmcrec_probe(
2342723427 "above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, above_syms,
23428- grid.get(mi_row - 1, mi_col + src4).copied(), interp_fixed.is_some(),
23428+ grid.get(mi_row - 1, mi_col + src4), interp_fixed.is_some(),
2342923429 );
2343023430 let (h_kind, v_kind) = neighbour_filter(interp_fixed, above_syms)?;
2343123431 ec_obmc_trace("above", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
@@ -23437,7 +23437,7 @@ fn obmc_blend(
2343723437 let (bw, bh, ox) = (span4 * 4, overlap_above, off4 * 4);
2343823438 // lane-t900 r14: the prediction is `op_mi_size` wide (kernel choice
2343923439 // included); only the WRITE is clipped to this block's own buffer.
23440- obmc_neighbour_pred(ny, px + ox, py, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);
23440+ obmc_neighbour_pred(ny, px + ox, py, mv32(nb.mv), bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);
2344123441 obmc_blend_v(pred_y, side, ox, 0, bw.min(write_w - ox), bh, bw, &tmp_y);
2344223442 if !skip_chroma_above {
2344323443 // lane-t900 r13 (measured, NOT a defect): libaom's min-4 clamp
@@ -23449,9 +23449,9 @@ fn obmc_blend(
2344923449 // 13 B -> 11007 B.
2345023450 let (cbw, cbh, cox) = (bw / 2, overlap_above / 2, ox / 2);
2345123451 let cw = cbw.min(write_w / 2 - cox);
23452- obmc_neighbour_pred(nu, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);
23452+ obmc_neighbour_pred(nu, cpx + cox, cpy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);
2345323453 obmc_blend_v(pred_u, chroma_side, cox, 0, cw, cbh, cbw, &tmp_u);
23454- obmc_neighbour_pred(nv, cpx + cox, cpy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);
23454+ obmc_neighbour_pred(nv, cpx + cox, cpy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);
2345523455 obmc_blend_v(pred_v, chroma_side, cox, 0, cw, cbh, cbw, &tmp_v);
2345623456 }
2345723457 }
@@ -23461,7 +23461,7 @@ fn obmc_blend(
2346123461 let left_syms = neighbours.left_filter[mi_row + src4];
2346223462 obmcrec_probe(
2346323463 "left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, left_syms,
23464- grid.get(mi_row + src4, mi_col - 1).copied(), interp_fixed.is_some(),
23464+ grid.get(mi_row + src4, mi_col - 1), interp_fixed.is_some(),
2346523465 );
2346623466 let (h_kind, v_kind) = neighbour_filter(interp_fixed, left_syms)?;
2346723467 ec_obmc_trace("left", mi_row, mi_col, write_w, write_h, off4, span4, &nb, h_kind, v_kind);
@@ -23471,10 +23471,10 @@ fn obmc_blend(
2347123471 OBMC_EDGE_SPAN_HITS.with(|c| c.set(c.get() + 1));
2347223472 }
2347323473 let (bw, bh, oy) = (overlap_left, span4 * 4, off4 * 4);
23474- obmc_neighbour_pred(ny, px, py + oy, nb.mv, bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);
23474+ obmc_neighbour_pred(ny, px, py + oy, mv32(nb.mv), bw, bh, true, h_kind, v_kind, nb_scale, &mut tmp_y, fctx);
2347523475 obmc_blend_h(pred_y, side, 0, oy, bw, bh.min(write_h - oy), &tmp_y);
2347623476 let (cbw, cbh, coy) = (overlap_left / 2, bh / 2, oy / 2);
23477- obmc_neighbour_pred(nu, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);
23477+ obmc_neighbour_pred(nu, cpx, cpy + coy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_u, fctx);
2347823478 if let Some((_, _, idx)) = ec_mcb {
2347923479 eprintln!(
2348023480 "OUR_MCB left f={idx} off4={off4} span4={span4} cbw={cbw} cbh={cbh} coy={coy} mv=({},{}) ref0={}",
@@ -23487,7 +23487,7 @@ fn obmc_blend(
2348723487 }
2348823488 let ch = cbh.min(write_h / 2 - coy);
2348923489 obmc_blend_h(pred_u, chroma_side, 0, coy, cbw, ch, &tmp_u);
23490- obmc_neighbour_pred(nv, cpx, cpy + coy, nb.mv, cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);
23490+ obmc_neighbour_pred(nv, cpx, cpy + coy, mv32(nb.mv), cbw, cbh, false, h_kind, v_kind, nb_scale, &mut tmp_v, fctx);
2349123491 obmc_blend_h(pred_v, chroma_side, 0, coy, cbw, ch, &tmp_v);
2349223492 }
2349323493 if let Some((_, _, idx)) = ec_mcb {
@@ -24412,8 +24412,8 @@ fn decode_inter_block(
2441224412 is_inter: true,
2441324413 ref_frame: ref0,
2441424414 ref_frame1: ref1,
24415- mv1,
24416- mv: mv0,
24415+ mv1: mv16(mv1),
24416+ mv: mv16(mv0),
2441724417 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
2441824418 size: bw4 as u8,
2441924419 size_h: bh4 as u8,
@@ -25986,7 +25986,7 @@ fn decode_inter_block(
2598625986 // num_proj_ref.
2598725987 ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 },
2598825988 mv1: (0, 0),
25989- mv,
25989+ mv: mv16(mv),
2599025990 is_new_mv,
2599125991 size: bw4 as u8,
2599225992 size_h: bh4 as u8,
@@ -27965,7 +27965,7 @@ fn decode_inter_sub8_split4(
2796527965 ref_frame,
2796627966 ref_frame1: NO_REF1,
2796727967 mv1: (0, 0),
27968- mv,
27968+ mv: mv16(mv),
2796927969 is_new_mv,
2797027970 size: 1,
2797127971 size_h: 1,
@@ -29208,7 +29208,7 @@ fn grid_stamp_rect(
2920829208 ref_frame,
2920929209 ref_frame1: NO_REF1,
2921029210 mv1: (0, 0),
29211- mv,
29211+ mv: mv16(mv),
2921229212 is_new_mv,
2921329213 size: w_mi as u8,
2921429214 size_h: h_mi as u8,
@@ -29786,8 +29786,8 @@ fn decode_inter_block8(
2978629786 is_inter: true,
2978729787 ref_frame: ref0,
2978829788 ref_frame1: ref1,
29789- mv1,
29790- mv: mv0,
29789+ mv1: mv16(mv1),
29790+ mv: mv16(mv0),
2979129791 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
2979229792 size: 2,
2979329793 size_h: 2,
@@ -30464,7 +30464,7 @@ fn decode_inter_block8(
3046430464 // them out of warp-sample gathering (see 16/32 site).
3046530465 ref_frame1: if interintra_mode.is_some() { 0 } else { NO_REF1 },
3046630466 mv1: (0, 0),
30467- mv,
30467+ mv: mv16(mv),
3046830468 is_new_mv,
3046930469 size: 2,
3047030470 size_h: 2,
@@ -35742,12 +35742,12 @@ mod tests {
3574235742
3574335743 let mut grid = MiGrid::new(mi_cols as usize, mi_rows as usize);
3574435744 let (above_mv, left_mv) = ((4, 4), (8, 8));
35745- let neighbour = |mv| MiInfo {
35745+ let neighbour = |mv: (i32, i32)| MiInfo {
3574635746 is_inter: true,
3574735747 ref_frame: LAST_FRAME,
3574835748 ref_frame1: NO_REF1,
3574935749 mv1: (0, 0),
35750- mv,
35750+ mv: mv16(mv),
3575135751 is_new_mv: false,
3575235752 size: 1,
3575335753 size_h: 1,
crates/ec-av1/src/encode.rsmodified+4 -4
@@ -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, NO_REF1, find_mv_stack};
31+use crate::mvstack::{MiGrid, MiInfo, MvStack, NO_REF1, find_mv_stack, mv16};
3232 use crate::obu::temporal_delimiter;
3333 use crate::quant::ac_q;
3434 use crate::sequence::sequence_header_obu;
@@ -3099,7 +3099,7 @@ pub(crate) fn encode_inter_frame(
30993099 ref_frame: LAST_FRAME,
31003100 ref_frame1: NO_REF1,
31013101 mv1: (0, 0),
3102- mv: info.mv,
3102+ mv: mv16(info.mv),
31033103 is_new_mv: matches!(info.mode, InterMode::NewMv),
31043104 size: 8,
31053105 size_h: 8,
@@ -3197,7 +3197,7 @@ pub(crate) fn encode_inter_frame(
31973197 ref_frame: LAST_FRAME,
31983198 ref_frame1: NO_REF1,
31993199 mv1: (0, 0),
3200- mv: info.mv,
3200+ mv: mv16(info.mv),
32013201 is_new_mv: matches!(info.mode, InterMode::NewMv),
32023202 size: 4,
32033203 size_h: 4,
@@ -3257,7 +3257,7 @@ pub(crate) fn encode_inter_frame(
32573257 ref_frame: LAST_FRAME,
32583258 ref_frame1: NO_REF1,
32593259 mv1: (0, 0),
3260- mv: info.mv,
3260+ mv: mv16(info.mv),
32613261 is_new_mv: matches!(
32623262 info.mode,
32633263 InterMode::NewMv
crates/ec-av1/src/mvstack.rsmodified+63 -38
@@ -161,6 +161,23 @@ pub struct TplArgs<'a> {
161161 /// -- as absent without an `Option` tag word per grid cell.
162162 pub const NO_REF1: i8 = -1;
163163
164+/// lane-migrid: widen a stored [`MiInfo`] motion vector to the `(i32, i32)`
165+/// every consumer computes in.
166+pub fn mv32(mv: (i16, i16)) -> (i32, i32) {
167+ (i32::from(mv.0), i32::from(mv.1))
168+}
169+
170+/// lane-migrid: narrow a computed motion vector to [`MiInfo`]'s stored
171+/// width -- libaom's own `MV` (`int16_t row, col`), which is the spec's MV
172+/// range, so this is not a narrowing of anything the spec can produce.
173+pub fn mv16(mv: (i32, i32)) -> (i16, i16) {
174+ debug_assert!(
175+ i16::try_from(mv.0).is_ok() && i16::try_from(mv.1).is_ok(),
176+ "mv outside the spec's i16 range: {mv:?}"
177+ );
178+ (mv.0 as i16, mv.1 as i16)
179+}
180+
164181 /// One 4x4 `mi` unit's motion state, as the encode loop will have filled it
165182 /// in by the time it asks for a block's MV stack.
166183 #[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -181,10 +198,13 @@ pub struct MiInfo {
181198 /// in this slot).
182199 pub ref_frame1: i8,
183200 /// The unit's motion vector, `(row, col)`, in the spec's 1/8-pel units.
184- pub mv: (i32, i32),
201+ /// lane-migrid: `i16`, which is libaom's own `MV` (`int16_t row, col`)
202+ /// and the spec's MV range -- two of these plus the byte-sized fields
203+ /// make the grid cell 16 bytes instead of 24.
204+ pub mv: (i16, i16),
185205 /// The unit's second motion vector, matching `ref_frame1` (spec
186206 /// `Mvs[1]`) — `Some` only for a compound-coded unit, `None` otherwise.
187- pub mv1: (i32, i32),
207+ pub mv1: (i16, i16),
188208 /// Whether this unit's own mode was `NEWMV` (spec's
189209 /// `have_newmv_in_inter_mode`, compound modes excluded since this module
190210 /// has no compound candidates). Feeds `NewMvContext` (7.10.2.8): a
@@ -297,7 +317,7 @@ impl MiGrid {
297317
298318 /// The unit at `(row, col)`, or `None` when it is outside the grid, hasn't
299319 /// been coded, or sits outside the current tile's own bounds ([`Self::set_tile_bounds`]).
300- pub fn get(&self, row: usize, col: usize) -> Option<&MiInfo> {
320+ pub fn get(&self, row: usize, col: usize) -> Option<MiInfo> {
301321 if row < self.rows
302322 && col < self.cols
303323 && row >= self.tile_row0
@@ -305,7 +325,7 @@ impl MiGrid {
305325 && col >= self.tile_col0
306326 && col < self.tile_col1
307327 {
308- self.cells[row * self.cols + col].as_ref()
328+ self.cells[row * self.cols + col]
309329 } else {
310330 None
311331 }
@@ -319,9 +339,9 @@ impl MiGrid {
319339 /// only the last tile's columns into the motion field and every other
320340 /// tile's temporal candidates silently vanished from the next frame's
321341 /// MV stack.
322- pub fn get_frame(&self, row: usize, col: usize) -> Option<&MiInfo> {
342+ pub fn get_frame(&self, row: usize, col: usize) -> Option<MiInfo> {
323343 if row < self.rows && col < self.cols {
324- self.cells[row * self.cols + col].as_ref()
344+ self.cells[row * self.cols + col]
325345 } else {
326346 None
327347 }
@@ -579,13 +599,13 @@ fn process_single_ref_mv_candidate(
579599 // reads `candidate->mv[rf_idx]` unconditionally here -- unlike
580600 // `add_ref_mv_candidate`'s row/col/corner scans, this extension pass
581601 // never checks `is_global_mv_block`/substitutes `gm_mv_candidates`.
582- let mut slots = [(candidate.ref_frame, candidate.mv); 2];
602+ let mut slots = [(candidate.ref_frame, mv32(candidate.mv)); 2];
583603 let mut n_slots = 1;
584604 // `mv1` is meaningful only for a compound neighbour (`ref_frame1 > 0`);
585605 // an interintra one stores `INTRA_FRAME` (0) with no second MV, and used
586606 // to be excluded here by its `mv1` being `None`.
587607 if candidate.ref_frame1 > 0 {
588- slots[1] = (candidate.ref_frame1, candidate.mv1);
608+ slots[1] = (candidate.ref_frame1, mv32(candidate.mv1));
589609 n_slots = 2;
590610 }
591611 for &(rf, mv) in &slots[..n_slots] {
@@ -679,7 +699,7 @@ fn scan_row(
679699 weight = weight.max(inc as u32);
680700 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
681701 }
682- if let Some(mv) = single_ref_match(info, ref_frame, gm) {
702+ if let Some(mv) = single_ref_match(&info, ref_frame, gm) {
683703 found = true;
684704 add_candidate(candidates, mv, len as u32 * weight);
685705 *newmv_count += u32::from(info.is_new_mv);
@@ -706,13 +726,13 @@ fn single_ref_match(info: &MiInfo, ref_frame: i8, gm: &GmMvTable) -> Option<(i32
706726 Some(if info.is_global_mv0 {
707727 gm_mv(gm, ref_frame)
708728 } else {
709- info.mv
729+ mv32(info.mv)
710730 })
711731 } else if info.ref_frame1 > 0 && info.ref_frame1 == ref_frame {
712732 if info.is_global_mv1 {
713733 Some(gm_mv(gm, ref_frame))
714734 } else {
715- Some(info.mv1)
735+ Some(mv32(info.mv1))
716736 }
717737 } else {
718738 None
@@ -767,7 +787,7 @@ fn scan_col(
767787 weight = weight.max(inc as u32);
768788 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
769789 }
770- if let Some(mv) = single_ref_match(info, ref_frame, gm) {
790+ if let Some(mv) = single_ref_match(&info, ref_frame, gm) {
771791 found = true;
772792 add_candidate(candidates, mv, len as u32 * weight);
773793 *newmv_count += u32::from(info.is_new_mv);
@@ -875,7 +895,7 @@ fn scan_top_right(
875895 };
876896 let col = mi_col + bw4;
877897 if let Some(info) = grid.get(row, col)
878- && let Some(mv) = single_ref_match(info, ref_frame, gm)
898+ && let Some(mv) = single_ref_match(&info, ref_frame, gm)
879899 {
880900 add_candidate(candidates, mv, CORNER_WEIGHT);
881901 *newmv_count += u32::from(info.is_new_mv);
@@ -903,7 +923,7 @@ fn scan_corner(
903923 return false;
904924 };
905925 if let Some(info) = grid.get(row, col)
906- && let Some(mv) = single_ref_match(info, ref_frame, gm)
926+ && let Some(mv) = single_ref_match(&info, ref_frame, gm)
907927 {
908928 add_candidate(candidates, mv, CORNER_WEIGHT);
909929 *newmv_count += u32::from(info.is_new_mv);
@@ -1346,7 +1366,7 @@ pub fn find_mv_stack_with_sign_bias(
13461366 let cand = grid.get(mi_row - 1, mi_col + idx);
13471367 let step = cand.map_or(1, |c| c.size as usize).max(1);
13481368 if let Some(c) = cand {
1349- process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
1369+ process_single_ref_mv_candidate(&c, ref_frame, sign_bias_table, &mut candidates);
13501370 }
13511371 idx += step;
13521372 }
@@ -1357,7 +1377,7 @@ pub fn find_mv_stack_with_sign_bias(
13571377 let cand = grid.get(mi_row + idx, mi_col - 1);
13581378 let step = cand.map_or(1, |c| c.size_h as usize).max(1);
13591379 if let Some(c) = cand {
1360- process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
1380+ process_single_ref_mv_candidate(&c, ref_frame, sign_bias_table, &mut candidates);
13611381 }
13621382 idx += step;
13631383 }
@@ -1588,8 +1608,8 @@ fn scan_row_compound(
15881608 found = true;
15891609 add_compound_candidate(
15901610 candidates,
1591- if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1592- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
1611+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { mv32(info.mv) },
1612+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { mv32(info.mv1) },
15931613 len as u32 * weight,
15941614 );
15951615 *newmv_count += u32::from(info.is_new_mv);
@@ -1651,8 +1671,8 @@ fn scan_col_compound(
16511671 found = true;
16521672 add_compound_candidate(
16531673 candidates,
1654- if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1655- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
1674+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { mv32(info.mv) },
1675+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { mv32(info.mv1) },
16561676 len as u32 * weight,
16571677 );
16581678 *newmv_count += u32::from(info.is_new_mv);
@@ -1685,8 +1705,8 @@ fn scan_top_right_compound(
16851705 {
16861706 add_compound_candidate(
16871707 candidates,
1688- if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1689- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
1708+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { mv32(info.mv) },
1709+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { mv32(info.mv1) },
16901710 CORNER_WEIGHT,
16911711 );
16921712 *newmv_count += u32::from(info.is_new_mv);
@@ -1715,8 +1735,8 @@ fn scan_corner_compound(
17151735 {
17161736 add_compound_candidate(
17171737 candidates,
1718- if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { info.mv },
1719- if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { info.mv1 },
1738+ if info.is_global_mv0 { gm_mv(gm, ref_frame.0) } else { mv32(info.mv) },
1739+ if info.is_global_mv1 { gm_mv(gm, ref_frame.1) } else { mv32(info.mv1) },
17201740 CORNER_WEIGHT,
17211741 );
17221742 *newmv_count += u32::from(info.is_new_mv);
@@ -1757,11 +1777,11 @@ fn process_compound_ref_mv_candidate(
17571777 return;
17581778 }
17591779 let slots = [
1760- Some((candidate.ref_frame, candidate.mv)),
1780+ Some((candidate.ref_frame, mv32(candidate.mv))),
17611781 // An interintra neighbour stores INTRA_FRAME (0) here; libaom's
17621782 // ref-diff scan requires `can_rf > INTRA_FRAME`
17631783 // (process_compound_ref_mv_candidate), so it contributes nothing.
1764- (candidate.ref_frame1 > 0).then_some((candidate.ref_frame1, candidate.mv1)),
1784+ (candidate.ref_frame1 > 0).then_some((candidate.ref_frame1, mv32(candidate.mv1))),
17651785 ];
17661786 for (candidate_ref, candidate_mv) in slots.into_iter().flatten() {
17671787 for (i, side_ref) in [ref_frame.0, ref_frame.1].into_iter().enumerate() {
@@ -2126,7 +2146,7 @@ pub fn find_mv_stack_compound(
21262146 let cand = grid.get(mi_row - 1, mi_col + idx);
21272147 let step = cand.map_or(1, |c| c.size as usize).max(1);
21282148 if let Some(c) = cand {
2129- process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);
2149+ process_compound_ref_mv_candidate(&c, ref_frame, sign_bias_table, &mut lists);
21302150 }
21312151 idx += step;
21322152 }
@@ -2137,7 +2157,7 @@ pub fn find_mv_stack_compound(
21372157 let cand = grid.get(mi_row + idx, mi_col - 1);
21382158 let step = cand.map_or(1, |c| c.size_h as usize).max(1);
21392159 if let Some(c) = cand {
2140- process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);
2160+ process_compound_ref_mv_candidate(&c, ref_frame, sign_bias_table, &mut lists);
21412161 }
21422162 idx += step;
21432163 }
@@ -2526,7 +2546,7 @@ mod tests {
25262546 #[test]
25272547 fn mi_info_stays_small_enough_for_a_4k_grid() {
25282548 assert!(
2529- std::mem::size_of::<Option<MiInfo>>() <= 32,
2549+ std::mem::size_of::<Option<MiInfo>>() <= 16,
25302550 "Option<MiInfo> grew to {} bytes",
25312551 std::mem::size_of::<Option<MiInfo>>()
25322552 );
@@ -2540,10 +2560,13 @@ mod tests {
25402560 /// the scan's memory traffic. `ref_frame1`/`mv1` are validity-tagged by
25412561 /// `ref_frame1 == NO_REF1` rather than by two `Option` tags (32 bytes ->
25422562 /// 24), and `is_inter` keeps a niche so the grid's `Option<MiInfo>` costs
2543- /// no extra word.
2563+ /// no extra word. lane-migrid: the two motion vectors ride as `i16`
2564+ /// pairs -- libaom's own `MV` (`int16_t row, col`), i.e. the spec's MV
2565+ /// range -- which takes the cell from 24 bytes to 16 and the grid's
2566+ /// index arithmetic from a multiply to a shift.
25442567 #[test]
25452568 fn mi_info_cell_stays_compact() {
2546- assert_eq!(std::mem::size_of::<MiInfo>(), 24);
2569+ assert_eq!(std::mem::size_of::<MiInfo>(), 16);
25472570 assert_eq!(
25482571 std::mem::size_of::<Option<MiInfo>>(),
25492572 std::mem::size_of::<MiInfo>()
@@ -2556,7 +2579,7 @@ mod tests {
25562579 ref_frame: 1,
25572580 ref_frame1: NO_REF1,
25582581 mv1: (0, 0),
2559- mv,
2582+ mv: mv16(mv),
25602583 is_new_mv: false,
25612584 // 1: smaller than every `bw4`/`bh4` these small-grid tests use,
25622585 // so it never trips the extended-scan coverage boost -- these
@@ -2689,11 +2712,13 @@ mod tests {
26892712 // A 4x4-mi frame (16x16 px), block 1x1 mi at (1, 1): room for one
26902713 // neighbour above and one to the left, tight edges on every side.
26912714 let mut grid = MiGrid::new(4, 4);
2692- grid.set(0, 1, inter((100_000, 100_000)));
2715+ // lane-migrid: far outside this 16x16-px frame, but inside the
2716+ // spec's own MV width (`MiInfo` stores libaom's `int16_t` mv).
2717+ grid.set(0, 1, inter((30_000, 30_000)));
26932718
26942719 let stack = find_mv_stack(&grid, 1, 1, 1, 1, 1, 4, 4);
26952720
2696- // Unclamped this candidate is (100000, 100000); spec 7.10.2.14 caps
2721+ // Unclamped this candidate is (30000, 30000); spec 7.10.2.14 caps
26972722 // it at the frame edge (2 mi below/right) plus the block's own 4x4
26982723 // span plus MV_BORDER (128), all in 1/8-pel: (2*4)*8 + 1*4*8 + 128 =
26992724 // 64 + 32 + 128 = 224.
@@ -2810,7 +2835,7 @@ mod tests {
28102835 let stack = find_mv_stack(&grid, mi_row, mi_col, 2, 2, 1, 32, 32);
28112836
28122837 assert_eq!(stack.entries.len(), 1);
2813- assert_eq!(stack.entries[0].mv, mv);
2838+ assert_eq!(stack.entries[0].mv, mv32(mv));
28142839 assert_eq!(stack.entries[0].weight, 12 + REF_CAT_LEVEL);
28152840 }
28162841
@@ -2849,7 +2874,7 @@ mod tests {
28492874 ref_frame: 1,
28502875 ref_frame1: NO_REF1,
28512876 mv1: (0, 0),
2852- mv,
2877+ mv: mv16(mv),
28532878 is_new_mv: false,
28542879 size: 8,
28552880 size_h: 8,
@@ -3088,8 +3113,8 @@ mod tests {
30883113 is_inter: true,
30893114 ref_frame: COMP_PAIR.0,
30903115 ref_frame1: COMP_PAIR.1,
3091- mv: mv0,
3092- mv1,
3116+ mv: mv16(mv0),
3117+ mv1: mv16(mv1),
30933118 is_new_mv: false,
30943119 size: 1,
30953120 size_h: 1,
crates/ec-av1/src/tile.rsmodified+6 -6
@@ -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, NO_REF1, find_mv_stack, single_ref_ctx};
19+use crate::mvstack::{MiGrid, MiInfo, NO_REF1, find_mv_stack, mv16, 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`
@@ -2436,7 +2436,7 @@ pub fn sb_coeff_inter_frame_tile(
24362436 ref_frame: LAST_FRAME,
24372437 ref_frame1: NO_REF1,
24382438 mv1: (0, 0),
2439- mv,
2439+ mv: mv16(mv),
24402440 is_new_mv,
24412441 size: 8,
24422442 size_h: 8,
@@ -2457,7 +2457,7 @@ pub fn sb_coeff_inter_frame_tile(
24572457 ref_frame: LAST_FRAME,
24582458 ref_frame1: NO_REF1,
24592459 mv1: (0, 0),
2460- mv,
2460+ mv: mv16(mv),
24612461 is_new_mv,
24622462 size: 8,
24632463 size_h: 8,
@@ -2632,7 +2632,7 @@ fn write_inter_frame_leaf(
26322632 ref_frame: LAST_FRAME,
26332633 ref_frame1: NO_REF1,
26342634 mv1: (0, 0),
2635- mv,
2635+ mv: mv16(mv),
26362636 is_new_mv,
26372637 size: SUB_MI as usize as u8,
26382638 size_h: SUB_MI as usize as u8,
@@ -2830,7 +2830,7 @@ fn write_inter_frame_leaf8(
28302830 ref_frame: LAST_FRAME,
28312831 ref_frame1: NO_REF1,
28322832 mv1: (0, 0),
2833- mv,
2833+ mv: mv16(mv),
28342834 is_new_mv,
28352835 size: 2,
28362836 size_h: 2,
@@ -5140,7 +5140,7 @@ mod tests {
51405140 ref_frame: 1,
51415141 ref_frame1: NO_REF1,
51425142 mv1: (0, 0),
5143- mv,
5143+ mv: mv16(mv),
51445144 is_new_mv,
51455145 size: 8,
51465146 size_h: 8,