forge
Explore
Log in

Don't you dare go Hollow

U5: remove EC_VP8_TRACE and EC_VP8_DEBUG gates from ec-vp8

Browse files at this commit

1e371cb774f2df9c364a9eab14dd091292d0e241Ahmet Kaan GümüşParent: db2cc75
Per-read and per-MB eprintln diagnostics and their cached env lookups.
tokens::get_coeffs loses the trace macro; the now-unused context cursor goes with it. Output bits unchanged.
crates/ec-vp8/src/bool.rsmodified+0 -3
@@ -111,9 +111,6 @@ impl<'a> BoolDecoder<'a> {
111 self.value |= self.next_byte();111 self.value |= self.next_byte();
112 }112 }
113 }113 }
114- if crate::trace_enabled() {
115- eprintln!("B {} {} {} {}", self.pos, self.bit_count, prob, u8::from(bit));
116- }
117 bit114 bit
118 }115 }
119 116
crates/ec-vp8/src/decode.rsmodified+0 -56
@@ -396,9 +396,6 @@ impl Decoder {
396 // `r` (0-based) reads partition `r % n` like the reference.396 // `r` (0-based) reads partition `r % n` like the reference.
397 let part = (row - 1) % partitions.len();397 let part = (row - 1) % partitions.len();
398 for col in 1..=self.mb_cols {398 for col in 1..=self.mb_cols {
399- if crate::trace_enabled() {
400- eprintln!("M {} {}", row - 1, col - 1);
401- }
402 let mb = self.mbi(row, col).clone();399 let mb = self.mbi(row, col).clone();
403 let has_y2 = mb.has_y2();400 let has_y2 = mb.has_y2();
404 let seg_i = usize::from(header.segmentation.enabled) * usize::from(mb.segment_id);401 let seg_i = usize::from(header.segmentation.enabled) * usize::from(mb.segment_id);
@@ -411,9 +408,6 @@ impl Decoder {
411 y2_dc: dq.y2_dc,408 y2_dc: dq.y2_dc,
412 y2_ac: dq.y2_ac,409 y2_ac: dq.y2_ac,
413 };410 };
414- if crate::trace_enabled() {
415- eprintln!("T {} {} hy2={}", row - 1, col - 1, has_y2);
416- }
417 let probs = self.state.coeff_probs;411 let probs = self.state.coeff_probs;
418 let coeffs = if mb.skip {412 let coeffs = if mb.skip {
419 tokens::skip_mb_tokens(&mut self.token_ctxs, col - 1, has_y2)413 tokens::skip_mb_tokens(&mut self.token_ctxs, col - 1, has_y2)
@@ -606,9 +600,6 @@ impl Decoder {
606 self.token_ctxs.reset_above_row();600 self.token_ctxs.reset_above_row();
607 601
608 // Phase 1: every mode record of the frame, row-major (§16).602 // Phase 1: every mode record of the frame, row-major (§16).
609- if crate::trace_enabled() {
610- eprintln!("STAGE modes");
611- }
612 for row in 1..=self.mb_rows {603 for row in 1..=self.mb_rows {
613 for col in 1..=self.mb_cols {604 for col in 1..=self.mb_cols {
614 let mut mb = MbInfo::default();605 let mut mb = MbInfo::default();
@@ -758,9 +749,6 @@ impl Decoder {
758 let left = self.mv_neighbor(row, col - 1, sign_bias);749 let left = self.mv_neighbor(row, col - 1, sign_bias);
759 let aboveleft = self.mv_neighbor(row - 1, col - 1, sign_bias);750 let aboveleft = self.mv_neighbor(row - 1, col - 1, sign_bias);
760 let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias);751 let (mut near_mvs, cnt) = modes::find_near_mvs(above, left, aboveleft, to_bias);
761- if crate::trace_enabled() {
762- eprintln!("CNT r={} c={} cnt={:?} mvs={:?}", row - 1, col - 1, cnt, near_mvs);
763- }
764 752
765 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) {753 if !d.read_bool(modes::MODE_CONTEXTS[cnt[modes::CNT_INTRA] as usize][0]) {
766 mb.mv_ref = 0; // ZEROMV754 mb.mv_ref = 0; // ZEROMV
@@ -868,24 +856,6 @@ impl Decoder {
868 mv856 mv
869 }857 }
870 };858 };
871- if crate::trace_enabled() {
872- eprintln!(
873- "SP r={} c={} j={} k={} l=({},{}) a=({},{}) ctx={} mv=({},{}) best=({},{})",
874- row - 1,
875- col - 1,
876- j,
877- k,
878- leftmv.0,
879- leftmv.1,
880- abovemv.0,
881- abovemv.1,
882- ctx,
883- blockmv.0,
884- blockmv.1,
885- best.0,
886- best.1
887- );
888- }
889 mb.mv_clamp |= modes::mv_out_of_bounds(blockmv, edges);859 mb.mv_clamp |= modes::mv_out_of_bounds(blockmv, edges);
890 let count = modes::MBSPLIT_FILL_COUNT[s];860 let count = modes::MBSPLIT_FILL_COUNT[s];
891 for &off in &modes::MBSPLIT_FILL_OFFSET[s][j * count..(j + 1) * count] {861 for &off in &modes::MBSPLIT_FILL_OFFSET[s][j * count..(j + 1) * count] {
@@ -911,12 +881,6 @@ impl Decoder {
911 if mb.ref_frame == 0 {881 if mb.ref_frame == 0 {
912 return self.reconstruct_intra_mb(row, col, mb, coeffs);882 return self.reconstruct_intra_mb(row, col, mb, coeffs);
913 }883 }
914- if crate::trace_enabled() {
915- eprintln!(
916- "IMB r={} c={} ref={} mvref={} mv=({},{}) clamp={} skip={}",
917- row, col, mb.ref_frame, mb.mv_ref, mb.mv.0, mb.mv.1, mb.mv_clamp, mb.skip
918- );
919- }
920 let reff = self.refs[usize::from(mb.ref_frame)]884 let reff = self.refs[usize::from(mb.ref_frame)]
921 .as_ref()885 .as_ref()
922 .ok_or_else(|| Error::corrupt("VP8 inter MB refers to an empty reference slot"))?;886 .ok_or_else(|| Error::corrupt("VP8 inter MB refers to an empty reference slot"))?;
@@ -1005,14 +969,6 @@ impl Decoder {
1005 &mut pv, 16, 8, 8, self.mc_bilinear,969 &mut pv, 16, 8, 8, self.mc_bilinear,
1006 );970 );
1007 }971 }
1008- if crate::trace_enabled() && row == 0 && col == 0 {
1009- eprintln!(
1010- "CHROMA pred_u[0..8]={:?} refu_vis[0..8]={:?} coeffs.u0dcsum={}",
1011- &pu[0..8],
1012- &reff.u[MC_BORDER * reff.uv_stride + MC_BORDER..MC_BORDER * reff.uv_stride + MC_BORDER + 8],
1013- coeffs.u[0].iter().sum::<i16>()
1014- );
1015- }
1016 972
1017 // Residual: every block adds onto its MC prediction.973 // Residual: every block adds onto its MC prediction.
1018 let y_dcs: [i16; 16] = if coeffs.has_y2 {974 let y_dcs: [i16; 16] = if coeffs.has_y2 {
@@ -1126,18 +1082,6 @@ impl Decoder {
1126 } else {1082 } else {
1127 [0; 16]1083 [0; 16]
1128 };1084 };
1129- if crate::debug_enabled() {
1130- eprintln!(
1131- "MB({row},{col}) ymode={} uv={} y2={:?} y2has={} y0[:4]={:?} eobs24={} dcs={:?}",
1132- y_mode,
1133- uv_mode,
1134- coeffs.y2,
1135- coeffs.has_y2,
1136- &coeffs.y[0][..4],
1137- coeffs.eobs[24],
1138- &y_dcs[..4]
1139- );
1140- }
1141 1085
1142 if y_mode == modes::YMode::BPred.as_u8() {1086 if y_mode == modes::YMode::BPred.as_u8() {
1143 for b in 0..16usize {1087 for b in 0..16usize {
crates/ec-vp8/src/header.rsmodified+0 -8
@@ -396,9 +396,6 @@ impl FrameHeader {
396 128396 128
397 };397 };
398 // Interframe-only probability updates.398 // Interframe-only probability updates.
399- if crate::trace_enabled() {
400- eprintln!("STAGE interprobs");
401- }
402 let mut ymode_probs_updated = false;399 let mut ymode_probs_updated = false;
403 let mut uv_mode_probs_updated = false;400 let mut uv_mode_probs_updated = false;
404 let (prob_intra, prob_last, prob_gf) = if !key {401 let (prob_intra, prob_last, prob_gf) = if !key {
@@ -431,11 +428,6 @@ impl FrameHeader {
431 }428 }
432 }429 }
433 }430 }
434- if crate::trace_enabled() {
435- eprintln!("YUV ymode = {:?} uv = {:?}", state.ymode_probs, state.uv_mode_probs);
436- eprintln!("MVT c0 = {:?}", state.mv_probs[0]);
437- eprintln!("MVT c1 = {:?}", state.mv_probs[1]);
438- }
439 probs431 probs
440 } else {432 } else {
441 (112, 86, 140) // placeholders; only read on inter frames433 (112, 86, 140) // placeholders; only read on inter frames
crates/ec-vp8/src/lib.rsmodified+0 -34
@@ -30,37 +30,3 @@ pub mod transform;
30 30
31 pub use ec_core::{Error, Result};31 pub use ec_core::{Error, Result};
32 pub use header::PersistedState;32 pub use header::PersistedState;
33-
34-/// Whether `EC_VP8_TRACE` decision tracing is enabled, resolved once per
35-/// process. A `var_os` per bool read was 46% of the decode profile (each
36-/// call locks std's ENV lock and allocates); `OnceLock::get_or_init` was
37-/// no better, so the hot path is a single relaxed atomic load.
38-pub(crate) fn trace_enabled() -> bool {
39- use std::sync::atomic::{AtomicU8, Ordering};
40- static STATE: AtomicU8 = AtomicU8::new(0);
41- match STATE.load(Ordering::Relaxed) {
42- 0 => {
43- let on = std::env::var_os("EC_VP8_TRACE").is_some();
44- STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed);
45- on
46- }
47- 1 => false,
48- _ => true,
49- }
50-}
51-
52-/// Whether `EC_VP8_DEBUG` per-macroblock dumps are enabled (same shape as
53-/// [`trace_enabled`]; the check sits in the per-MB reconstruct path).
54-pub(crate) fn debug_enabled() -> bool {
55- use std::sync::atomic::{AtomicU8, Ordering};
56- static STATE: AtomicU8 = AtomicU8::new(0);
57- match STATE.load(Ordering::Relaxed) {
58- 0 => {
59- let on = std::env::var_os("EC_VP8_DEBUG").is_some();
60- STATE.store(if on { 2 } else { 1 }, Ordering::Relaxed);
61- on
62- }
63- 1 => false,
64- _ => true,
65- }
66-}
crates/ec-vp8/src/tokens.rsmodified+17 -43
@@ -156,75 +156,55 @@ fn get_coeffs(
156 ac_factor: i16,156 ac_factor: i16,
157 out: &mut [i16; 16],157 out: &mut [i16; 16],
158 ) -> usize {158 ) -> usize {
159- let trace = crate::trace_enabled();
160- // One token decision: decode the bool, then — under EC_VP8_TRACE —
161- // print the consulted (n, band, ctx, prob) and the decoded bit so the
162- // stream can be diffed read-for-read against scripts/vp8ref_model.py.
163- macro_rules! g {
164- ($n:expr, $band:expr, $c:expr, $prob:expr) => {{
165- let bit = bc.read_bool($prob);
166- if trace {
167- eprintln!(
168- "G n={} band={} ctx={} prob={} bit={}",
169- $n, $band, $c, $prob, u8::from(bit)
170- );
171- }
172- bit
173- }};
174- }
175 let mut n = n0;159 let mut n = n0;
176 let mut band = BANDS[n0];160 let mut band = BANDS[n0];
177- let mut c = ctx;161+ let mut p = &probs_t[band as usize][ctx];
178- let mut p = &probs_t[band as usize][c];162+ if !bc.read_bool(p[0]) {
179- if !g!(n, band, c, p[0]) {
180 return 0; // immediate EOB163 return 0; // immediate EOB
181 }164 }
182 loop {165 loop {
183 n += 1;166 n += 1;
184 let mut v: i32;167 let mut v: i32;
185- if !g!(n, band, c, p[1]) {168+ if !bc.read_bool(p[1]) {
186 // DCT_0: the next decision skips the EOB branch (§13.2) and169 // DCT_0: the next decision skips the EOB branch (§13.2) and
187 // libvpx forces the context to 0 after a zero token.170 // libvpx forces the context to 0 after a zero token.
188- c = 0;
189 band = BANDS[n];171 band = BANDS[n];
190 p = &probs_t[band as usize][0];172 p = &probs_t[band as usize][0];
191 } else {173 } else {
192- if !g!(n, band, c, p[2]) {174+ if !bc.read_bool(p[2]) {
193- c = 1;
194 band = BANDS[n];175 band = BANDS[n];
195 p = &probs_t[band as usize][1];176 p = &probs_t[band as usize][1];
196 v = 1;177 v = 1;
197 } else {178 } else {
198- if !g!(n, band, c, p[3]) {179+ if !bc.read_bool(p[3]) {
199- if !g!(n, band, c, p[4]) {180+ if !bc.read_bool(p[4]) {
200 v = 2;181 v = 2;
201 } else {182 } else {
202- v = 3 + i32::from(g!(n, band, c, p[5]));183+ v = 3 + i32::from(bc.read_bool(p[5]));
203 }184 }
204 } else {185 } else {
205- if !g!(n, band, c, p[6]) {186+ if !bc.read_bool(p[6]) {
206- if !g!(n, band, c, p[7]) {187+ if !bc.read_bool(p[7]) {
207- v = 5 + i32::from(g!(n, band, c, 159u8));188+ v = 5 + i32::from(bc.read_bool(159u8));
208 } else {189 } else {
209- v = 7 + 2 * i32::from(g!(n, band, c, 165u8));190+ v = 7 + 2 * i32::from(bc.read_bool(165u8));
210- v += i32::from(g!(n, band, c, 145u8));191+ v += i32::from(bc.read_bool(145u8));
211 }192 }
212 } else {193 } else {
213- let bit1 = usize::from(g!(n, band, c, p[8]));194+ let bit1 = usize::from(bc.read_bool(p[8]));
214- let bit0 = usize::from(g!(n, band, c, p[9 + bit1]));195+ let bit0 = usize::from(bc.read_bool(p[9 + bit1]));
215 let cat = 2 * bit1 + bit0;196 let cat = 2 * bit1 + bit0;
216 v = 0;197 v = 0;
217 for &prob in CAT_EXTRA[cat].iter() {198 for &prob in CAT_EXTRA[cat].iter() {
218 if prob == 0 {199 if prob == 0 {
219 break;200 break;
220 }201 }
221- let g = i32::from(g!(n, band, c, prob));202+ let g = i32::from(bc.read_bool(prob));
222 v = v + v + g;203 v = v + v + g;
223 }204 }
224 v += 3 + (8 << cat);205 v += 3 + (8 << cat);
225 }206 }
226 }207 }
227- c = 2;
228 band = BANDS[n];208 band = BANDS[n];
229 p = &probs_t[band as usize][2];209 p = &probs_t[band as usize][2];
230 }210 }
@@ -232,14 +212,14 @@ fn get_coeffs(
232 // Sign flag, then dequantize (first coded position is DC).212 // Sign flag, then dequantize (first coded position is DC).
233 // Shared by the ONE and magnitude paths, exactly like the213 // Shared by the ONE and magnitude paths, exactly like the
234 // reference walk (libvpx detokenize.c GetCoeffs).214 // reference walk (libvpx detokenize.c GetCoeffs).
235- let neg = g!(n, band, c, 128u8);215+ let neg = bc.read_bool(128u8);
236 let mag = if neg { -v } else { v };216 let mag = if neg { -v } else { v };
237 out[ZIGZAG[n - 1]] = if n - 1 == 0 {217 out[ZIGZAG[n - 1]] = if n - 1 == 0 {
238 (mag * i32::from(dc_factor)) as i16218 (mag * i32::from(dc_factor)) as i16
239 } else {219 } else {
240 (mag * i32::from(ac_factor)) as i16220 (mag * i32::from(ac_factor)) as i16
241 };221 };
242- if n < 16 && !g!(n, band, c, p[0]) {222+ if n < 16 && !bc.read_bool(p[0]) {
243 return n; // EOB223 return n; // EOB
244 }224 }
245 }225 }
@@ -269,13 +249,7 @@ pub(crate) fn decode_mb_tokens(
269 let n0 = usize::from($ptype == 0);249 let n0 = usize::from($ptype == 0);
270 let (l, a) = ctxs.ctx_pair(mb_col, $idx);250 let (l, a) = ctxs.ctx_pair(mb_col, $idx);
271 let ctx = (usize::from(l) + usize::from(a)).min(2);251 let ctx = (usize::from(l) + usize::from(a)).min(2);
272- if crate::trace_enabled() {
273- eprintln!("TB {} ctx={} l={} a={}", $idx, ctx, l, a);
274- }
275 let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot);252 let eob = get_coeffs(bc, &probs[$ptype], ctx, n0, $dc, $ac, $slot);
276- if crate::trace_enabled() {
277- eprintln!("TBE {} eob={}", $idx, eob);
278- }
279 out.eobs[$idx] = eob as u8;253 out.eobs[$idx] = eob as u8;
280 let t = u8::from(eob > 0);254 let t = u8::from(eob > 0);
281 ctxs.set_ctx(mb_col, $idx, t);255 ctxs.set_ctx(mb_col, $idx, t);