forge
Explore
Log in

Don't you dare go Hollow

Mi-grid writers fill whole rows and MiInfo carries u8 block sides

Browse files at this commit

77576dd8ff99eb1ea7929e78a55da11c122225aeAhmet Kaan GümüşParent: 5a5f194
  • perf
    • mi-grid writers fill whole rows and MiInfo carries u8 block sides
Show full message
perf(av1): mi-grid writers fill whole rows and MiInfo carries u8 block sides

The mode-info bookkeeping the parse thread runs per coded block wrote its
grids one 4x4 cell at a time, each write a bounds check: `fill_lf_grid_rect`
(6 grids), `fill_skip_grid_rect` (4), `record_uv_mode_mi`, `record_mi_rect`
and `record_inter_rect_mi`. A mi rect's cells are contiguous inside one grid
row, so each of those rows is one `fill_span` -- same cells, same values,
including the out-of-range drop the per-cell `get_mut`/`break` did.

`record_mi_rect`'s per-cell `array::from_fn` predicate is monotone in the
plane bound (`bound[1] == bound[2] >= bound[0]`), so the left/above neighbour
state is three contiguous runs, not a branch per cell.

`MiInfo::size`/`size_h` are 4x4-cell counts that never exceed 32; as `u8`
they take `Option<MiInfo>` from 48 to 28 bytes, shrinking both the per-frame
grid fill and the mv-stack scans' cache footprint.

Byte-exact: all 12 gate hashes unchanged. instructions:u on the 4K segment
570.74 G -> 565.02 G (-1.00%).
crates/ec-av1/src/decode.rsmodified+115 -168
@@ -3190,8 +3190,8 @@ fn record_intrabc_mi(mi_r: usize, mi_c: usize, n4: usize, dv: Option<(i32, i32)>
3190 is_new_mv: dv.is_some(),3190 is_new_mv: dv.is_some(),
3191 is_global_mv0: false,3191 is_global_mv0: false,
3192 is_global_mv1: false,3192 is_global_mv1: false,
3193- size: n4,3193+ size: n4 as u8,
3194- size_h: n4,3194+ size_h: n4 as u8,
3195 };3195 };
3196 for r in mi_r..mi_r + n4 {3196 for r in mi_r..mi_r + n4 {
3197 for c in mi_c..mi_c + n4 {3197 for c in mi_c..mi_c + n4 {
@@ -6001,6 +6001,21 @@ struct Neighbour {
6001 dc: Option<bool>,6001 dc: Option<bool>,
6002 }6002 }
6003 6003
6004+/// `dst[start .. start + n] = v`, with the same per-cell bounds behaviour the
6005+/// per-4x4-cell `get_mut` loops it replaces had: a cell past the end of the
6006+/// grid is dropped, never a panic. One `memset` per grid row instead of a
6007+/// bounds check per cell (lane-mi) -- the index span a row of a mi rect covers
6008+/// is contiguous, so this writes exactly the cells the cell loop did,
6009+/// including the ones a `mi_c + cc` past `skip_grid_cols_mi` folded into the
6010+/// next row.
6011+#[inline]
6012+fn fill_span<T: Copy>(dst: &mut [T], start: usize, n: usize, v: T) {
6013+ let end = (start + n).min(dst.len());
6014+ if start < end {
6015+ dst[start..end].fill(v);
6016+ }
6017+}
6018+
6004 fn neighbour_state(grid: &[i32]) -> Neighbour {6019 fn neighbour_state(grid: &[i32]) -> Neighbour {
6005 let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum();6020 let cul: u32 = grid.iter().map(|&l| l.unsigned_abs()).sum();
6006 Neighbour {6021 Neighbour {
@@ -6624,15 +6639,9 @@ impl Neighbours {
6624 let (mi_r, mi_c) = at_mi;6639 let (mi_r, mi_c) = at_mi;
6625 let (uv_w, uv_h) = ((w_mi * MI / 2).max(4) as u8, (h_mi * MI / 2).max(4) as u8);6640 let (uv_w, uv_h) = ((w_mi * MI / 2).max(4) as u8, (h_mi * MI / 2).max(4) as u8);
6626 for rr in 0..h_mi {6641 for rr in 0..h_mi {
6627- for cc in 0..w_mi {6642+ let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
6628- let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);6643+ fill_span(&mut self.uv_tx_grid, start, w_mi, uv_w);
6629- if let Some(cell) = self.uv_tx_grid.get_mut(idx) {6644+ fill_span(&mut self.uv_tx_h_grid, start, w_mi, uv_h);
6630- *cell = uv_w;
6631- }
6632- if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) {
6633- *cell = uv_h;
6634- }
6635- }
6636 }6645 }
6637 }6646 }
6638 6647
@@ -6661,27 +6670,13 @@ impl Neighbours {
6661 [cur[0].clamp(-63, 63) as i8; 4]6670 [cur[0].clamp(-63, 63) as i8; 4]
6662 };6671 };
6663 for rr in 0..h_mi {6672 for rr in 0..h_mi {
6664- for cc in 0..w_mi {6673+ let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
6665- let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);6674+ fill_span(&mut self.tx_grid, start, w_mi, tx_px);
6666- if let Some(cell) = self.tx_grid.get_mut(idx) {6675+ fill_span(&mut self.tx_h_grid, start, w_mi, tx_h_px);
6667- *cell = tx_px;6676+ fill_span(&mut self.uv_tx_grid, start, w_mi, uv_tx_w);
6668- }6677+ fill_span(&mut self.uv_tx_h_grid, start, w_mi, uv_tx_h);
6669- if let Some(cell) = self.tx_h_grid.get_mut(idx) {6678+ fill_span(&mut self.ref_grid, start, w_mi, ref_frame);
6670- *cell = tx_h_px;6679+ fill_span(&mut self.delta_lf_grid, start, w_mi, snapshot);
6671- }
6672- if let Some(cell) = self.uv_tx_grid.get_mut(idx) {
6673- *cell = uv_tx_w;
6674- }
6675- if let Some(cell) = self.uv_tx_h_grid.get_mut(idx) {
6676- *cell = uv_tx_h;
6677- }
6678- if let Some(cell) = self.ref_grid.get_mut(idx) {
6679- *cell = ref_frame;
6680- }
6681- if let Some(cell) = self.delta_lf_grid.get_mut(idx) {
6682- *cell = snapshot;
6683- }
6684- }
6685 }6680 }
6686 }6681 }
6687 6682
@@ -6706,15 +6701,9 @@ impl Neighbours {
6706 eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");6701 eprintln!("EC_LFLEAF mi_row={mi_r} mi_col={mi_c} w_mi={w_mi} h_mi={h_mi} tx_px={tx_px} tx_h_px={tx_h_px}");
6707 }6702 }
6708 for rr in 0..h_mi {6703 for rr in 0..h_mi {
6709- for cc in 0..w_mi {6704+ let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
6710- let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);6705+ fill_span(&mut self.tx_grid, start, w_mi, tx_px);
6711- if let Some(cell) = self.tx_grid.get_mut(idx) {6706+ fill_span(&mut self.tx_h_grid, start, w_mi, tx_h_px);
6712- *cell = tx_px;
6713- }
6714- if let Some(cell) = self.tx_h_grid.get_mut(idx) {
6715- *cell = tx_h_px;
6716- }
6717- }
6718 }6707 }
6719 }6708 }
6720 6709
@@ -6733,21 +6722,11 @@ impl Neighbours {
6733 RECT_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));6722 RECT_SKIP_BAND_HITS.with(|c| c.set(c.get() + 1));
6734 }6723 }
6735 for rr in 0..h_mi {6724 for rr in 0..h_mi {
6736- for cc in 0..w_mi {6725+ let start = (mi_r + rr) * self.skip_grid_cols_mi + mi_c;
6737- let idx = (mi_r + rr) * self.skip_grid_cols_mi + (mi_c + cc);6726+ fill_span(&mut self.skip_grid, start, w_mi, skip);
6738- if let Some(cell) = self.skip_grid.get_mut(idx) {6727+ fill_span(&mut self.skip_written, start, w_mi, true);
6739- *cell = skip;6728+ fill_span(&mut self.blk_org_grid, start, w_mi, [mi_r as u16, mi_c as u16]);
6740- }6729+ fill_span(&mut self.blk_dim_grid, start, w_mi, [w_mi as u8, h_mi as u8]);
6741- if let Some(cell) = self.skip_written.get_mut(idx) {
6742- *cell = true;
6743- }
6744- if let Some(org) = self.blk_org_grid.get_mut(idx) {
6745- *org = [mi_r as u16, mi_c as u16];
6746- }
6747- if let Some(dim) = self.blk_dim_grid.get_mut(idx) {
6748- *dim = [w_mi as u8, h_mi as u8];
6749- }
6750- }
6751 }6730 }
6752 }6731 }
6753 6732
@@ -6909,34 +6888,30 @@ impl Neighbours {
6909 self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED);6888 self.record_uv_mode_mi(r, c, w_mi, h_mi, DC_PRED);
6910 }6889 }
6911 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;6890 let altref = is_inter && ref_frame == crate::mvstack::ALTREF_FRAME;
6912- for cell in 0..w_mi {6891+ self.above_skip[c..c + w_mi].fill(skip);
6913- self.above_skip[c + cell] = skip;6892+ self.above_skip_mode[c..c + w_mi].fill(skip_mode);
6914- self.above_skip_mode[c + cell] = skip_mode;6893+ self.above_inter[c..c + w_mi].fill(is_inter);
6915- self.above_inter[c + cell] = is_inter;6894+ self.above_ref[c..c + w_mi].fill(ref_frame);
6916- self.above_ref[c + cell] = ref_frame;6895+ // lane-av1comp: no caller of `record_inter` ever decodes a
6917- // lane-av1comp: no caller of `record_inter` ever decodes a6896+ // compound block yet (see [`Self::above_ref1`]'s doc); the
6918- // compound block yet (see [`Self::above_ref1`]'s doc); the6897+ // parameter this becomes lands with `read_ref_frames`.
6919- // parameter this becomes lands with `read_ref_frames`.6898+ self.above_ref1[c..c + w_mi].fill(None);
6920- self.above_ref1[c + cell] = None;6899+ // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s
6921- // libaom `get_comp_group_idx_context`/`get_comp_index_context`'s6900+ // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads
6922- // single-ref special case: `ref_frame[0] == ALTREF_FRAME` reads6901+ // as `3`/`1` even though this block has no second reference.
6923- // as `3`/`1` even though this block has no second reference.6902+ // `record_compound_ctx` overwrites this with the real bit for an
6924- // `record_compound_ctx` overwrites this with the real bit for an6903+ // actual compound block's cells, called right after this one.
6925- // actual compound block's cells, called right after this one.6904+ self.above_comp_group_idx[c..c + w_mi].fill(if altref { 3 } else { 0 });
6926- self.above_comp_group_idx[c + cell] = if altref { 3 } else { 0 };6905+ self.above_compound_idx[c..c + w_mi].fill(u8::from(altref));
6927- self.above_compound_idx[c + cell] = u8::from(altref);6906+ self.above_filter[c..c + w_mi].fill(filter);
6928- self.above_filter[c + cell] = filter;6907+ self.left_skip[r..r + h_mi].fill(skip);
6929- }6908+ self.left_skip_mode[r..r + h_mi].fill(skip_mode);
6930- for cell in 0..h_mi {6909+ self.left_inter[r..r + h_mi].fill(is_inter);
6931- self.left_skip[r + cell] = skip;6910+ self.left_ref[r..r + h_mi].fill(ref_frame);
6932- self.left_skip_mode[r + cell] = skip_mode;6911+ self.left_ref1[r..r + h_mi].fill(None);
6933- self.left_inter[r + cell] = is_inter;6912+ self.left_comp_group_idx[r..r + h_mi].fill(if altref { 3 } else { 0 });
6934- self.left_ref[r + cell] = ref_frame;6913+ self.left_compound_idx[r..r + h_mi].fill(u8::from(altref));
6935- self.left_ref1[r + cell] = None;6914+ self.left_filter[r..r + h_mi].fill(filter);
6936- self.left_comp_group_idx[r + cell] = if altref { 3 } else { 0 };
6937- self.left_compound_idx[r + cell] = u8::from(altref);
6938- self.left_filter[r + cell] = filter;
6939- }
6940 }6915 }
6941 6916
6942 /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with6917 /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with
@@ -7222,27 +7197,14 @@ impl Neighbours {
7222 uv_mode: usize,7197 uv_mode: usize,
7223 ) {7198 ) {
7224 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);7199 let (last_r, last_c) = (mi_r + mi_h - 1, mi_c + mi_w - 1);
7225- for cell in 0..mi_w {7200+ fill_span(&mut self.uv_mode_col, mi_c, mi_w, (last_r, uv_mode));
7226- if let Some(slot) = self.uv_mode_col.get_mut(mi_c + cell) {7201+ fill_span(&mut self.uv_mode_row, mi_r, mi_h, (last_c, uv_mode));
7227- *slot = (last_r, uv_mode);
7228- }
7229- }
7230- for cell in 0..mi_h {
7231- if let Some(slot) = self.uv_mode_row.get_mut(mi_r + cell) {
7232- *slot = (last_c, uv_mode);
7233- }
7234- }
7235 // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block7202 // libaom writes one `MB_MODE_INFO` pointer into every mi cell a block
7236 // covers, so the chroma neighbour read below is a plain grid read.7203 // covers, so the chroma neighbour read below is a plain grid read.
7237 let stride = self.uv_grid_cols;7204 let stride = self.uv_grid_cols;
7205+ let n = stride.saturating_sub(mi_c).min(last_c + 1 - mi_c);
7238 for row in mi_r..=last_r {7206 for row in mi_r..=last_r {
7239- for col in mi_c..=last_c {7207+ fill_span(&mut self.uv_mode_grid, row * stride + mi_c, n, uv_mode as u8);
7240- if col < stride
7241- && let Some(cell) = self.uv_mode_grid.get_mut(row * stride + col)
7242- {
7243- *cell = uv_mode as u8;
7244- }
7245- }
7246 }7208 }
7247 }7209 }
7248 7210
@@ -7479,16 +7441,8 @@ impl Neighbours {
7479 if crate::envflags::env_flag!("EC_ECPUB") {7441 if crate::envflags::env_flag!("EC_ECPUB") {
7480 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);7442 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
7481 }7443 }
7482- for cell in 0..h_mi {7444+ fill_span(&mut self.left_side_mi, mi_r, h_mi, h);
7483- if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) {7445+ fill_span(&mut self.above_side_mi, mi_c, w_mi, w);
7484- *slot = h;
7485- }
7486- }
7487- for cell in 0..w_mi {
7488- if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) {
7489- *slot = w;
7490- }
7491- }
7492 // A chroma 4x4 unit straddling the true luma edge is still whole in7446 // A chroma 4x4 unit straddling the true luma edge is still whole in
7493 // chroma's own halved grid, so libaom rounds the luma bound up to the7447 // chroma's own halved grid, so libaom rounds the luma bound up to the
7494 // plane's own 4x4 unit before clamping a subsampled plane7448 // plane's own 4x4 unit before clamping a subsampled plane
@@ -7504,34 +7458,35 @@ impl Neighbours {
7504 round_up_even(self.mi_cols),7458 round_up_even(self.mi_cols),
7505 round_up_even(self.mi_cols),7459 round_up_even(self.mi_cols),
7506 ];7460 ];
7507- for cell in 0..h_mi {7461+ // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows
7508- // lane-sb128c r7: a 128x64 at the bottom frame edge names mi rows7462+ // past the padded side arrays (mi_rows 198, block rows 192..208);
7509- // past the padded side arrays (mi_rows 198, block rows 192..208);7463+ // libaom's own arrays are superblock-sized, so those cells simply
7510- // libaom's own arrays are superblock-sized, so those cells simply7464+ // have no reader -- [`fill_span`] drops them, as the `break` did.
7511- // have no reader. Same guard the `left_side_mi` loop above uses.7465+ // `bound_h[1] == bound_h[2] >= bound_h[0]`, so the per-cell plane
7512- let Some(left_slot) = self.left.get_mut(mi_r + cell) else {7466+ // predicate is three contiguous runs: all planes, chroma only, none
7513- break;7467+ // (lane-mi).
7514- };7468+ let luma_h = h_mi.min(bound_h[0].saturating_sub(mi_r));
7515- *left_slot = std::array::from_fn(|plane| {7469+ let chroma_h = h_mi.min(bound_h[1].saturating_sub(mi_r));
7516- if cell < h_mi.min(bound_h[plane].saturating_sub(mi_r)) {7470+ let uv_only = [Neighbour::default(), states[1], states[2]];
7517- states[plane]7471+ fill_span(&mut self.left, mi_r, luma_h, states);
7518- } else {7472+ fill_span(&mut self.left, mi_r + luma_h, chroma_h - luma_h, uv_only);
7519- Default::default()7473+ fill_span(
7520- }7474+ &mut self.left,
7521- });7475+ mi_r + chroma_h,
7522- }7476+ h_mi - chroma_h,
7523- for cell in 0..w_mi {7477+ [Neighbour::default(); 3],
7524- let Some(above_slot) = self.above.get_mut(mi_c + cell) else {7478+ );
7525- break;7479+ let luma_w = w_mi.min(bound_w[0].saturating_sub(mi_c));
7526- };7480+ let chroma_w = w_mi.min(bound_w[1].saturating_sub(mi_c));
7527- *above_slot = std::array::from_fn(|plane| {7481+ let uv_only_w = [Neighbour::default(), states[1], states[2]];
7528- if cell < w_mi.min(bound_w[plane].saturating_sub(mi_c)) {7482+ fill_span(&mut self.above, mi_c, luma_w, states);
7529- states[plane]7483+ fill_span(&mut self.above, mi_c + luma_w, chroma_w - luma_w, uv_only_w);
7530- } else {7484+ fill_span(
7531- Default::default()7485+ &mut self.above,
7532- }7486+ mi_c + chroma_w,
7533- });7487+ w_mi - chroma_w,
7534- }7488+ [Neighbour::default(); 3],
7489+ );
7535 }7490 }
7536 7491
7537 /// [`Self::record_mi`]'s plane-0 half only, for one luma transform unit7492 /// [`Self::record_mi`]'s plane-0 half only, for one luma transform unit
@@ -7676,16 +7631,8 @@ impl Neighbours {
7676 let (w_mi, h_mi) = (w / MI, h / MI);7631 let (w_mi, h_mi) = (w / MI, h / MI);
7677 self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode);7632 self.record_mode_mi(mi_r, mi_c, w_mi, h_mi, mode);
7678 self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode);7633 self.record_uv_mode_mi(mi_r, mi_c, w_mi, h_mi, uv_mode);
7679- for cell in 0..h_mi {7634+ fill_span(&mut self.left_side_mi, mi_r, h_mi, h);
7680- if let Some(slot) = self.left_side_mi.get_mut(mi_r + cell) {7635+ fill_span(&mut self.above_side_mi, mi_c, w_mi, w);
7681- *slot = h;
7682- }
7683- }
7684- for cell in 0..w_mi {
7685- if let Some(slot) = self.above_side_mi.get_mut(mi_c + cell) {
7686- *slot = w;
7687- }
7688- }
7689 let round_up_even = |n: usize| n.div_ceil(2) * 2;7636 let round_up_even = |n: usize| n.div_ceil(2) * 2;
7690 let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));7637 let (bound_h, bound_w) = (round_up_even(self.mi_rows), round_up_even(self.mi_cols));
7691 for (plane_idx, grid) in chroma_grids.into_iter().enumerate() {7638 for (plane_idx, grid) in chroma_grids.into_iter().enumerate() {
@@ -22050,7 +21997,7 @@ fn overlappable_above(
22050 let mut col = mi_col;21997 let mut col = mi_col;
22051 while col < end_col && out.len() < max_neighbors {21998 while col < end_col && out.len() < max_neighbors {
22052 let cell = grid.get(mi_row - 1, col);21999 let cell = grid.get(mi_row - 1, col);
22053- let mut step = cell.map_or(1, |c| c.size).max(1).min(SB_MI as usize);22000+ let mut step = cell.map_or(1, |c| c.size as usize).max(1).min(SB_MI as usize);
22054 let mut nb = cell;22001 let mut nb = cell;
22055 // lane-obmcrec r1: the mi the neighbour's `MiInfo` is actually taken22002 // lane-obmcrec r1: the mi the neighbour's `MiInfo` is actually taken
22056 // from -- the pair merge below moves it, and libaom reads that same22003 // from -- the pair merge below moves it, and libaom reads that same
@@ -22105,7 +22052,7 @@ fn overlappable_left(
22105 let cell = grid.get(row, mi_col - 1);22052 let cell = grid.get(row, mi_col - 1);
22106 // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's22053 // Vertical walk steps by the neighbour's HEIGHT -- a 32x16 strip's
22107 // width (8) would swallow the strip below it.22054 // width (8) would swallow the strip below it.
22108- let mut step = cell.map_or(1, |c| c.size_h).max(1).min(SB_MI as usize);22055+ let mut step = cell.map_or(1, |c| c.size_h as usize).max(1).min(SB_MI as usize);
22109 let mut nb = cell;22056 let mut nb = cell;
22110 // lane-obmcrec r1: see `overlappable_above`'s `src`.22057 // lane-obmcrec r1: see `overlappable_above`'s `src`.
22111 let mut src = row;22058 let mut src = row;
@@ -22202,7 +22149,7 @@ fn find_samples(
22202 'outer: {22149 'outer: {
22203 if up_available {22150 if up_available {
22204 let above = grid.get(mi_row - 1, mi_col);22151 let above = grid.get(mi_row - 1, mi_col);
22205- let superblock_width = above.map_or(1, |c| c.size).max(1);22152+ let superblock_width = above.map_or(1, |c| c.size as usize).max(1);
22206 if bw4 <= superblock_width {22153 if bw4 <= superblock_width {
22207 let col_offset = -((mi_col % superblock_width) as isize);22154 let col_offset = -((mi_col % superblock_width) as isize);
22208 if col_offset < 0 {22155 if col_offset < 0 {
@@ -22224,7 +22171,7 @@ fn find_samples(
22224 let limit = bw4.min(mi_cols.saturating_sub(mi_col));22171 let limit = bw4.min(mi_cols.saturating_sub(mi_col));
22225 while i < limit {22172 while i < limit {
22226 let cell = grid.get(mi_row - 1, mi_col + i);22173 let cell = grid.get(mi_row - 1, mi_col + i);
22227- let sw = cell.map_or(1, |c| c.size).max(1);22174+ let sw = cell.map_or(1, |c| c.size as usize).max(1);
22228 if let Some(info) = cell {22175 if let Some(info) = cell {
22229 if single_ref_match(info) {22176 if single_ref_match(info) {
22230 samples.push(rec(info, 0, -1, i as i32, 1));22177 samples.push(rec(info, 0, -1, i as i32, 1));
@@ -22240,7 +22187,7 @@ fn find_samples(
22240 22187
22241 if left_available {22188 if left_available {
22242 let left = grid.get(mi_row, mi_col - 1);22189 let left = grid.get(mi_row, mi_col - 1);
22243- let superblock_height = left.map_or(1, |c| c.size_h).max(1);22190+ let superblock_height = left.map_or(1, |c| c.size_h as usize).max(1);
22244 if bh4 <= superblock_height {22191 if bh4 <= superblock_height {
22245 let row_offset = -((mi_row % superblock_height) as isize);22192 let row_offset = -((mi_row % superblock_height) as isize);
22246 if row_offset < 0 {22193 if row_offset < 0 {
@@ -22259,7 +22206,7 @@ fn find_samples(
22259 let limit = bh4.min(mi_rows.saturating_sub(mi_row));22206 let limit = bh4.min(mi_rows.saturating_sub(mi_row));
22260 while i < limit {22207 while i < limit {
22261 let cell = grid.get(mi_row + i, mi_col - 1);22208 let cell = grid.get(mi_row + i, mi_col - 1);
22262- let sh = cell.map_or(1, |c| c.size_h).max(1);22209+ let sh = cell.map_or(1, |c| c.size_h as usize).max(1);
22263 if let Some(info) = cell {22210 if let Some(info) = cell {
22264 if single_ref_match(info) {22211 if single_ref_match(info) {
22265 samples.push(rec(info, i as i32, 1, 0, -1));22212 samples.push(rec(info, i as i32, 1, 0, -1));
@@ -22690,7 +22637,7 @@ nbmv=({},{}) nbref={} nbbsize={} filt={}",
22690 nb.mv.0,22637 nb.mv.0,
22691 nb.mv.1,22638 nb.mv.1,
22692 nb.ref_frame,22639 nb.ref_frame,
22693- ec_obmc_bsize(nb.size, nb.size_h),22640+ ec_obmc_bsize(nb.size as usize, nb.size_h as usize),
22694 sym(v_kind) | (sym(h_kind) << 16),22641 sym(v_kind) | (sym(h_kind) << 16),
22695 );22642 );
22696 }22643 }
@@ -23824,8 +23771,8 @@ fn decode_inter_block(
23824 mv1: Some(mv1),23771 mv1: Some(mv1),
23825 mv: mv0,23772 mv: mv0,
23826 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),23773 is_new_mv: matches!(compound_mode, 2 | 3 | 4 | 5 | 7),
23827- size: bw4,23774+ size: bw4 as u8,
23828- size_h: bh4,23775+ size_h: bh4 as u8,
23829 // libaom `is_global_mv_block`: per-ref-slot, mode23776 // libaom `is_global_mv_block`: per-ref-slot, mode
23830 // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's23777 // GLOBAL_GLOBALMV, block >= 8x8, and THAT slot's
23831 // own gm model > TRANSLATION (IDENTITY excluded23778 // own gm model > TRANSLATION (IDENTITY excluded
@@ -25386,8 +25333,8 @@ fn decode_inter_block(
25386 mv1: None,25333 mv1: None,
25387 mv,25334 mv,
25388 is_new_mv,25335 is_new_mv,
25389- size: bw4,25336+ size: bw4 as u8,
25390- size_h: bh4,25337+ size_h: bh4 as u8,
25391 is_global_mv0: is_global_mv_block,25338 is_global_mv0: is_global_mv_block,
25392 is_global_mv1: false,25339 is_global_mv1: false,
25393 },25340 },
@@ -26212,8 +26159,8 @@ fn decode_inter_block(
26212 mv1: None,26159 mv1: None,
26213 mv: (0, 0),26160 mv: (0, 0),
26214 is_new_mv: false,26161 is_new_mv: false,
26215- size: write_w / MI,26162+ size: (write_w / MI) as u8,
26216- size_h: write_h / MI,26163+ size_h: (write_h / MI) as u8,
26217 is_global_mv0: false,26164 is_global_mv0: false,
26218 is_global_mv1: false,26165 is_global_mv1: false,
26219 },26166 },
@@ -26436,8 +26383,8 @@ fn decode_inter_block(
26436 mv1: None,26383 mv1: None,
26437 mv: (0, 0),26384 mv: (0, 0),
26438 is_new_mv: false,26385 is_new_mv: false,
26439- size: side / 4,26386+ size: (side / 4) as u8,
26440- size_h: side / 4,26387+ size_h: (side / 4) as u8,
26441 is_global_mv0: false,26388 is_global_mv0: false,
26442 is_global_mv1: false,26389 is_global_mv1: false,
26443 },26390 },
@@ -27887,8 +27834,8 @@ fn decode_intra_sub8_leaf(
27887 mv1: None,27834 mv1: None,
27888 mv: (0, 0),27835 mv: (0, 0),
27889 is_new_mv: false,27836 is_new_mv: false,
27890- size: w_mi,27837+ size: w_mi as u8,
27891- size_h: h_mi,27838+ size_h: h_mi as u8,
27892 is_global_mv0: false,27839 is_global_mv0: false,
27893 is_global_mv1: false,27840 is_global_mv1: false,
27894 },27841 },
@@ -28592,8 +28539,8 @@ fn grid_stamp_rect(
28592 mv1: None,28539 mv1: None,
28593 mv,28540 mv,
28594 is_new_mv,28541 is_new_mv,
28595- size: w_mi,28542+ size: w_mi as u8,
28596- size_h: h_mi,28543+ size_h: h_mi as u8,
28597 is_global_mv0: false,28544 is_global_mv0: false,
28598 is_global_mv1: false,28545 is_global_mv1: false,
28599 },28546 },
crates/ec-av1/src/mvstack.rsmodified+14 -14
@@ -196,11 +196,11 @@ pub struct MiInfo {
196 /// inter -- libaom's `scan_row_mbmi` advances `processed_rows` from any196 /// inter -- libaom's `scan_row_mbmi` advances `processed_rows` from any
197 /// candidate's `bsize` regardless of whether it also casts a vote (that197 /// candidate's `bsize` regardless of whether it also casts a vote (that
198 /// requires a ref-frame match, checked separately in `add_ref_mv_candidate`).198 /// requires a ref-frame match, checked separately in `add_ref_mv_candidate`).
199- pub size: usize,199+ pub size: u8,
200 /// The unit's height in 4x4 mi cells (== `size` for every square block;200 /// The unit's height in 4x4 mi cells (== `size` for every square block;
201 /// differs only for rect partition strips, lane-rect r2). Row scans step201 /// differs only for rect partition strips, lane-rect r2). Row scans step
202 /// and weight by `size` (width), column scans by `size_h`.202 /// and weight by `size` (width), column scans by `size_h`.
203- pub size_h: usize,203+ pub size_h: u8,
204 }204 }
205 205
206 /// The whole frame's `mi` grid, one [`MiInfo`] per 4x4 unit, in raster order.206 /// The whole frame's `mi` grid, one [`MiInfo`] per 4x4 unit, in raster order.
@@ -549,7 +549,7 @@ fn scan_row(
549 i += 1;549 i += 1;
550 continue;550 continue;
551 };551 };
552- let n4 = info.size;552+ let n4 = info.size as usize;
553 let mut len = bw4.min(n4);553 let mut len = bw4.min(n4);
554 if use_step_16 {554 if use_step_16 {
555 len = len.max(4);555 len = len.max(4);
@@ -561,7 +561,7 @@ fn scan_row(
561 // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4561 // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4
562 // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.562 // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.
563 if bw4 >= 2 && bw4 <= n4 {563 if bw4 >= 2 && bw4 <= n4 {
564- let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);564+ let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h as usize);
565 weight = weight.max(inc as u32);565 weight = weight.max(inc as u32);
566 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;566 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
567 }567 }
@@ -637,7 +637,7 @@ fn scan_col(
637 i += 1;637 i += 1;
638 continue;638 continue;
639 };639 };
640- let n4 = info.size_h;640+ let n4 = info.size_h as usize;
641 let mut len = bh4.min(n4);641 let mut len = bh4.min(n4);
642 if use_step_16 {642 if use_step_16 {
643 len = len.max(4);643 len = len.max(4);
@@ -649,7 +649,7 @@ fn scan_col(
649 // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps649 // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps
650 // weight 2 and leaves `processed_cols` alone.650 // weight 2 and leaves `processed_cols` alone.
651 if bh4 >= 2 && bh4 <= n4 {651 if bh4 >= 2 && bh4 <= n4 {
652- let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);652+ let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size as usize);
653 weight = weight.max(inc as u32);653 weight = weight.max(inc as u32);
654 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;654 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
655 }655 }
@@ -1217,7 +1217,7 @@ pub fn find_mv_stack_with_sign_bias(
1217 let mut idx = 0usize;1217 let mut idx = 0usize;
1218 while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES {1218 while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES {
1219 let cand = grid.get(mi_row - 1, mi_col + idx);1219 let cand = grid.get(mi_row - 1, mi_col + idx);
1220- let step = cand.map_or(1, |c| c.size).max(1);1220+ let step = cand.map_or(1, |c| c.size as usize).max(1);
1221 if let Some(c) = cand {1221 if let Some(c) = cand {
1222 process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);1222 process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
1223 }1223 }
@@ -1228,7 +1228,7 @@ pub fn find_mv_stack_with_sign_bias(
1228 let mut idx = 0usize;1228 let mut idx = 0usize;
1229 while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES {1229 while idx < mi_size && candidates.len() < MAX_MV_REF_CANDIDATES {
1230 let cand = grid.get(mi_row + idx, mi_col - 1);1230 let cand = grid.get(mi_row + idx, mi_col - 1);
1231- let step = cand.map_or(1, |c| c.size_h).max(1);1231+ let step = cand.map_or(1, |c| c.size_h as usize).max(1);
1232 if let Some(c) = cand {1232 if let Some(c) = cand {
1233 process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);1233 process_single_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut candidates);
1234 }1234 }
@@ -1441,7 +1441,7 @@ fn scan_row_compound(
1441 i += 1;1441 i += 1;
1442 continue;1442 continue;
1443 };1443 };
1444- let n4 = info.size;1444+ let n4 = info.size as usize;
1445 let mut len = bw4.min(n4);1445 let mut len = bw4.min(n4);
1446 if use_step_16 {1446 if use_step_16 {
1447 len = len.max(4);1447 len = len.max(4);
@@ -1453,7 +1453,7 @@ fn scan_row_compound(
1453 // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:41453 // `xd->width >= mi_size_wide[BLOCK_8X8]` as well: a 4-wide block (a 1:4
1454 // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.1454 // strip, a sub-8x8 leaf) keeps weight 2 and leaves `processed_rows` alone.
1455 if bw4 >= 2 && bw4 <= n4 {1455 if bw4 >= 2 && bw4 <= n4 {
1456- let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h);1456+ let inc = ((-max_row_offset + row_offset + 1) as usize).min(info.size_h as usize);
1457 weight = weight.max(inc as u32);1457 weight = weight.max(inc as u32);
1458 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;1458 *processed_rows = (inc as isize - row_offset - 1).max(0) as usize;
1459 }1459 }
@@ -1504,7 +1504,7 @@ fn scan_col_compound(
1504 i += 1;1504 i += 1;
1505 continue;1505 continue;
1506 };1506 };
1507- let n4 = info.size_h;1507+ let n4 = info.size_h as usize;
1508 let mut len = bh4.min(n4);1508 let mut len = bh4.min(n4);
1509 if use_step_16 {1509 if use_step_16 {
1510 len = len.max(4);1510 len = len.max(4);
@@ -1516,7 +1516,7 @@ fn scan_col_compound(
1516 // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps1516 // mi_size_high[BLOCK_8X8]` gates this branch, so a 4-high block keeps
1517 // weight 2 and leaves `processed_cols` alone.1517 // weight 2 and leaves `processed_cols` alone.
1518 if bh4 >= 2 && bh4 <= n4 {1518 if bh4 >= 2 && bh4 <= n4 {
1519- let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size);1519+ let inc = ((-max_col_offset + col_offset + 1) as usize).min(info.size as usize);
1520 weight = weight.max(inc as u32);1520 weight = weight.max(inc as u32);
1521 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;1521 *processed_cols = (inc as isize - col_offset - 1).max(0) as usize;
1522 }1522 }
@@ -1995,7 +1995,7 @@ pub fn find_mv_stack_compound(
1995 let mut idx = 0usize;1995 let mut idx = 0usize;
1996 while idx < mi_size {1996 while idx < mi_size {
1997 let cand = grid.get(mi_row - 1, mi_col + idx);1997 let cand = grid.get(mi_row - 1, mi_col + idx);
1998- let step = cand.map_or(1, |c| c.size).max(1);1998+ let step = cand.map_or(1, |c| c.size as usize).max(1);
1999 if let Some(c) = cand {1999 if let Some(c) = cand {
2000 process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);2000 process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);
2001 }2001 }
@@ -2006,7 +2006,7 @@ pub fn find_mv_stack_compound(
2006 let mut idx = 0usize;2006 let mut idx = 0usize;
2007 while idx < mi_size {2007 while idx < mi_size {
2008 let cand = grid.get(mi_row + idx, mi_col - 1);2008 let cand = grid.get(mi_row + idx, mi_col - 1);
2009- let step = cand.map_or(1, |c| c.size_h).max(1);2009+ let step = cand.map_or(1, |c| c.size_h as usize).max(1);
2010 if let Some(c) = cand {2010 if let Some(c) = cand {
2011 process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);2011 process_compound_ref_mv_candidate(c, ref_frame, sign_bias_table, &mut lists);
2012 }2012 }
crates/ec-av1/src/tile.rsmodified+4 -4
@@ -2634,8 +2634,8 @@ fn write_inter_frame_leaf(
2634 mv1: None,2634 mv1: None,
2635 mv,2635 mv,
2636 is_new_mv,2636 is_new_mv,
2637- size: SUB_MI as usize,2637+ size: SUB_MI as usize as u8,
2638- size_h: SUB_MI as usize,2638+ size_h: SUB_MI as usize as u8,
2639 is_global_mv0: false,2639 is_global_mv0: false,
2640 is_global_mv1: false,2640 is_global_mv1: false,
2641 },2641 },
@@ -2666,8 +2666,8 @@ fn write_inter_frame_leaf(
2666 mv1: None,2666 mv1: None,
2667 mv: (0, 0),2667 mv: (0, 0),
2668 is_new_mv: false,2668 is_new_mv: false,
2669- size: SUB_MI as usize,2669+ size: SUB_MI as usize as u8,
2670- size_h: SUB_MI as usize,2670+ size_h: SUB_MI as usize as u8,
2671 is_global_mv0: false,2671 is_global_mv0: false,
2672 is_global_mv1: false,2672 is_global_mv1: false,
2673 },2673 },