From 14126a2d38d54f07508c6aeae43948d319f8a8ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Wed, 2 Dec 2026 15:15:05 +0300 Subject: [PATCH] S5: decode dead_code allows removed; test-only items gated with cfg(test), unused ones deleted (sclamp, W14, square txfm_partition fns) --- crates/ec-av1/src/decode/cdef.rs | 2 +- crates/ec-av1/src/decode/coeffs.rs | 43 ++++-------------------- crates/ec-av1/src/decode/deblock.rs | 8 ----- crates/ec-av1/src/decode/deblock_simd.rs | 15 --------- crates/ec-av1/src/decode/frame_tile.rs | 3 +- crates/ec-av1/src/decode/key_tile.rs | 1 + crates/ec-av1/src/decode/mod.rs | 7 ++-- 7 files changed, 15 insertions(+), 64 deletions(-) diff --git a/crates/ec-av1/src/decode/cdef.rs b/crates/ec-av1/src/decode/cdef.rs index b03c8644..173ebd96 100644 --- a/crates/ec-av1/src/decode/cdef.rs +++ b/crates/ec-av1/src/decode/cdef.rs @@ -35,9 +35,9 @@ fn cdef_msb(x: i32) -> i32 { 31 - x.leading_zeros() as i32 } +#[cfg(test)] /// Spec 7.15.3's `constrain`: how much of a neighbour's difference from the /// centre sample a filter tap is allowed to contribute. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn cdef_constrain(diff: i32, threshold: i32, damping: i32) -> i32 { if threshold == 0 { return 0; diff --git a/crates/ec-av1/src/decode/coeffs.rs b/crates/ec-av1/src/decode/coeffs.rs index 47658cb8..6301eb0d 100644 --- a/crates/ec-av1/src/decode/coeffs.rs +++ b/crates/ec-av1/src/decode/coeffs.rs @@ -712,7 +712,6 @@ pub(super) struct Neighbours { pub(super) tile_col0_mi: usize, } -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates impl Neighbours { /// `cols`/`rows` are in [`SUB`] units; `mi_cols`/`mi_rows` are the frame's /// true (unpadded) size in 4x4 mode-info units. @@ -1534,6 +1533,7 @@ impl Neighbours { self.left_txfm.iter_mut().for_each(|t| *t = TXFM_CTX_INIT); } + #[cfg(test)] /// Records a block's `skip`/`is_inter`/`interp_filter` state for the next /// block that reads it as a neighbour -- [`crate::tile`]'s /// `record_inter`. `filter` is `[3, 3]` for an intra block (spec @@ -1541,7 +1541,6 @@ impl Neighbours { /// "no neighbour"). `ref_frame` is `-1` for an intra block, else the /// `1..=7` reference it coded (lane-av1refs's `single_ref_p*_ctx` needs /// the real value, not just `is_inter`). - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] @@ -1558,13 +1557,13 @@ impl Neighbours { self.record_inter_rect(at, side, side, skip, is_inter, ref_frame, filter, skip_mode); } + #[cfg(test)] /// [`Self::record_inter`] with independent above (`w_sub`, [`SUB`]-grid /// columns) / left (`h_sub`, [`SUB`]-grid rows) extents -- lane-partitions /// r1: a true rectangular strip's above-context span (its own width) and /// left-context span (its own height) differ, unlike every caller before /// this round (class neighbour-votes-all-its-fields). #[allow(clippy::too_many_arguments)] - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_inter_rect( &mut self, at: (usize, usize), @@ -1653,6 +1652,7 @@ impl Neighbours { self.left_filter[r..r + h_mi].fill(filter); } + #[cfg(test)] /// Overwrites [`Self::record_inter`]'s ALTREF-special-case default with /// a real compound block's own `comp_group_idx`/`compound_idx` bits /// (libaom `has_second_ref(mbmi)` branch of `get_comp_group_idx_context`/ @@ -1663,7 +1663,6 @@ impl Neighbours { /// this is the one caller that actually knows it) -- so the next block's /// [`NeighbourRef`](crate::mvstack::NeighbourRef) sees a real compound /// neighbour instead of `record_inter`'s single-ref default. - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_compound_ctx( &mut self, at: (usize, usize), @@ -1675,10 +1674,10 @@ impl Neighbours { self.record_compound_ctx_rect(at, side, side, ref1, comp_group_idx, compound_idx); } + #[cfg(test)] /// [`Self::record_compound_ctx`] with independent above/left extents, /// mirroring [`Self::record_inter_rect`] (lane-partitions r1). #[allow(clippy::too_many_arguments)] - #[allow(dead_code)] // read only from the `#[cfg(test)]` gates pub(super) fn record_compound_ctx_rect( &mut self, at: (usize, usize), @@ -3378,26 +3377,11 @@ pub(super) fn read_tx_size( max_tx >> depth } -/// `txfm_partition_context` (libaom `av1_common_int.h`): an inter block's -/// `txfm_split` context -- a category from the block's own largest square -/// transform and whether this unit already sits below it, times three, plus -/// the two neighbour terms (whether the transform last written above/left of -/// this unit is narrower/shorter than the unit itself). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn txfm_partition_ctx( - above_px: u8, - left_px: u8, - blk_max_px: usize, - tx_px: usize, -) -> usize { - txfm_partition_ctx_rect(above_px, left_px, blk_max_px, tx_px, tx_px) -} - -/// [`txfm_partition_ctx`] for a *rectangular* transform (lane-inter4 r2): +/// `txfm_partition_context` for a *rectangular* transform (lane-inter4 r2): /// libaom's `txfm_partition_context` compares the above context against /// `tx_size_wide` and the left one against `tx_size_high`, and takes its /// category from `txsize_sqr_up_map[tx_size]` -- all three collapse to one -/// side for a square transform, which is why the square form above is a +/// side for a square transform, which is why the square form is a /// special case of this one. pub(crate) fn txfm_partition_ctx_rect( above_px: u8, @@ -3418,20 +3402,7 @@ pub(crate) fn txfm_partition_ctx_rect( category * 3 + above + left } -/// `txfm_partition_update` (libaom `av1_common_int.h`): once a var-tx unit -/// resolves, every mi cell its *parent* unit (`txb_px`) spans records the -/// resolved transform's own size. -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn txfm_partition_update( - n: &mut Neighbours, - at_mi: (usize, usize), - tx_px: usize, - txb_px: usize, -) { - txfm_partition_update_rect(n, at_mi, (tx_px, tx_px), (txb_px, txb_px)); -} - -/// [`txfm_partition_update`] for a rectangular transform (lane-inter4 r2): +/// `txfm_partition_update` for a rectangular transform (lane-inter4 r2): /// the left column records `tx_size_high` over the parent's own height and /// the above row records `tx_size_wide` over its width. /// libaom `set_txfm_ctxs` + `txfm_partition_update` (`decodeframe.c`, end of diff --git a/crates/ec-av1/src/decode/deblock.rs b/crates/ec-av1/src/decode/deblock.rs index a09f8940..14b6171d 100644 --- a/crates/ec-av1/src/decode/deblock.rs +++ b/crates/ec-av1/src/decode/deblock.rs @@ -15,14 +15,6 @@ fn deblock_thresholds(level: i32, sharpness: u8) -> (i32, i32, i32) { (2 * (level + 2) + lim, lim, level >> 4) } -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates -pub(super) fn sclamp(v: i32, fctx: &crate::decode::FrameCtx) -> i32 { - // libaom's `signed_char_clamp_high`: the clamp range scales with - // `128 << (bit_depth - 8)` alongside the centering constant below. - let scale = 1i32 << (bit_depth(fctx) - 8); - v.clamp(-128 * scale, 128 * scale - 1) -} - fn round_pow2(v: i32, n: u32) -> i32 { (v + (1 << (n - 1))) >> n } diff --git a/crates/ec-av1/src/decode/deblock_simd.rs b/crates/ec-av1/src/decode/deblock_simd.rs index 764339f9..c52b5143 100644 --- a/crates/ec-av1/src/decode/deblock_simd.rs +++ b/crates/ec-av1/src/decode/deblock_simd.rs @@ -96,21 +96,6 @@ const W8: [[i16; 8]; 6] = [ [0, 0, 1, 1, 1, 2, 1, 2], [0, 0, 0, 1, 1, 1, 2, 3], ]; -#[allow(dead_code)] // superseded by the running-sum rows; kept as the weights' statement -const W14: [[i16; 14]; 12] = [ - [7, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], - [5, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0], - [4, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0, 0], - [3, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0, 0], - [2, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0, 0], - [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1, 0], - [0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1], - [0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 2], - [0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 3], - [0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 1, 4], - [0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 2, 5], - [0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 2, 2, 7], -]; /// One weighted tap sum, rounded by `shift` (3 for the divide-by-8 rows, /// 4 for `filter14`'s divide-by-16 ones). The sum is non-negative and diff --git a/crates/ec-av1/src/decode/frame_tile.rs b/crates/ec-av1/src/decode/frame_tile.rs index 5113eced..87ded993 100644 --- a/crates/ec-av1/src/decode/frame_tile.rs +++ b/crates/ec-av1/src/decode/frame_tile.rs @@ -4,6 +4,7 @@ use super::*; +#[cfg(test)] /// Decodes the payload [`crate::tile::sb_coeff_inter_frame_tile`] writes, /// against `reference` (the previous frame's own decoded picture, at this /// frame's true size -- a decoder's single-slot DPB, matching what this @@ -17,7 +18,6 @@ use super::*; /// or when `reference` is not this frame's own true size, or when the tile /// codes a 16x16 leaf whose own true edge cuts through it (round 2, same /// refusal [`crate::tile`]'s writer gives its encoder). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)] @@ -88,6 +88,7 @@ pub(crate) fn decode_inter_frame_tile( ) } +#[cfg(test)] /// [`decode_inter_frame_tile`] with this frame header's own `lr_params`, the /// inter sibling of [`decode_key_frame_tile_lr`]. #[allow(clippy::too_many_arguments)] diff --git a/crates/ec-av1/src/decode/key_tile.rs b/crates/ec-av1/src/decode/key_tile.rs index 3f2644a0..23eff624 100644 --- a/crates/ec-av1/src/decode/key_tile.rs +++ b/crates/ec-av1/src/decode/key_tile.rs @@ -2,6 +2,7 @@ use super::*; +#[cfg(test)] /// [`decode_key_frame_tile`] with this frame header's own `lr_params` (spec /// 5.9.20) instead of the no-restoration default -- the per-unit filters /// themselves live in the tile payload, so the header is all this needs. diff --git a/crates/ec-av1/src/decode/mod.rs b/crates/ec-av1/src/decode/mod.rs index 557a8fc5..85ee533e 100644 --- a/crates/ec-av1/src/decode/mod.rs +++ b/crates/ec-av1/src/decode/mod.rs @@ -126,7 +126,6 @@ pub(crate) struct FilterStages { /// Takes whatever the last capturing decode left (see /// [`FrameCtx::capture_stages`]). -#[allow(dead_code)] // read from the encoder's loop restoration search pub(crate) fn take_filter_stages(fctx: &FrameCtx) -> Option { fctx.stages.borrow_mut().take() } @@ -391,10 +390,12 @@ use crate::cdf_state::{Cdfs, MvComponentCdfs, TxbSet, TxbTables}; use crate::encode::{Picture, Reach}; use crate::intra::predict; use crate::mc; +#[cfg(test)] +use crate::mvstack::NO_SIGN_BIAS; use crate::msac::SymbolDecoder; use crate::mvstack::{ ALTREF_FRAME, ALTREF2_FRAME, BWDREF_FRAME, GOLDEN_FRAME, LAST_FRAME, LAST2_FRAME, LAST3_FRAME, - MiGrid, MiInfo, NO_REF1, NO_SIGN_BIAS, NeighbourRef, SignBiasTable, comp_reference_type_ctx, + MiGrid, MiInfo, NO_REF1, NeighbourRef, SignBiasTable, comp_reference_type_ctx, find_mv_stack_with_sign_bias, mv16, mv32, reference_mode_ctx, single_ref_p1_ctx, single_ref_p2_ctx, single_ref_p3_ctx, single_ref_p4_ctx, single_ref_p5_ctx, single_ref_p6_ctx, uni_comp_ref_p1_ctx, @@ -3205,6 +3206,7 @@ fn is_smooth_mode(mode: usize) -> bool { (crate::intra::SMOOTH_PRED as usize..=crate::intra::SMOOTH_H_PRED as usize).contains(&mode) } +#[cfg(test)] /// Decodes the payload [`crate::tile::sb_coeff_key_frame_tile`] writes, /// returning the picture it reconstructs to. /// @@ -3223,7 +3225,6 @@ fn is_smooth_mode(mode: usize) -> bool { /// 16x16, a directional mode's angle delta other than zero, chroma-from-luma), /// or when the tile payload runs out of the symbols this decode expects (a /// genuinely foreign stream). -#[allow(dead_code)] // read only from the `#[cfg(test)]` gates // Signature mirrors the spec's per-call inputs; a parameter struct would only move them. #[allow(clippy::too_many_arguments)]