forge
Explore
Log in

Don't you dare go Hollow

ec-vp8: token-decision trace tooling (G n/band/ctx/prob annotations, env-gated) for the M2 cross-MB context hunt; unit suite stays green

Browse files at this commit

2e92feca815a23c88e6afd7518519da2c7a95fdeAhmet Kaan GümüşParent: d24d4c4
crates/ec-vp8/src/tokens.rsmodified+46 -12
@@ -147,6 +147,7 @@ impl TokenContexts {
147 /// type; `n0` the first coded position (1 for Y blocks after a Y2).147 /// type; `n0` the first coded position (1 for Y blocks after a Y2).
148 /// Returns the number of significant coefficients. Coefficients are148 /// Returns the number of significant coefficients. Coefficients are
149 /// written dequantized into `out` (natural order).149 /// written dequantized into `out` (natural order).
150+#[allow(unused_assignments)] // v is always read on every path that matters
150 fn get_coeffs(151 fn get_coeffs(
151 bc: &mut BoolDecoder<'_>,152 bc: &mut BoolDecoder<'_>,
152 probs_t: &[[[u8; 11]; 3]; 8],153 probs_t: &[[[u8; 11]; 3]; 8],
@@ -156,51 +157,85 @@ fn get_coeffs(
156 ac_factor: i16,157 ac_factor: i16,
157 out: &mut [i16; 16],158 out: &mut [i16; 16],
158 ) -> usize {159 ) -> usize {
160+ let trace = std::env::var_os("EC_VP8_TRACE").is_some();
161+ macro_rules! ann {
162+ ($n:expr, $band:expr, $ctx:expr, $node:expr) => {
163+ if trace {
164+ eprintln!("G n={} band={} ctx={} prob={}", $n, $band, $ctx, $node);
165+ }
166+ };
167+ }
159 let mut n = n0;168 let mut n = n0;
160- let mut p = &probs_t[BANDS[n0] as usize][ctx];169+ let mut band = BANDS[n0];
170+ let mut c = ctx;
171+ let mut p = &probs_t[band as usize][c];
172+ ann!(n, band, c, 0);
161 if !bc.read_bool(p[0]) {173 if !bc.read_bool(p[0]) {
162 return 0; // immediate EOB174 return 0; // immediate EOB
163 }175 }
164 loop {176 loop {
165 n += 1;177 n += 1;
166 let mut v: i32;178 let mut v: i32;
179+ ann!(n, band, c, 1);
167 if !bc.read_bool(p[1]) {180 if !bc.read_bool(p[1]) {
168- // DCT_0: next decision skips the EOB branch (§13.2).181+ // DCT_0: the next decision skips the EOB branch (§13.2).
169- p = &probs_t[BANDS[n] as usize][0];182+ c = 0;
183+ band = BANDS[n];
184+ p = &probs_t[band as usize][0];
170 } else {185 } else {
186+ ann!(n, band, c, 2);
171 if !bc.read_bool(p[2]) {187 if !bc.read_bool(p[2]) {
172- p = &probs_t[BANDS[n] as usize][1];188+ c = 1;
189+ band = BANDS[n];
190+ p = &probs_t[band as usize][1];
173 v = 1;191 v = 1;
174- } else if !bc.read_bool(p[3]) {192+ } else {
193+ ann!(n, band, c, 3);
194+ if !bc.read_bool(p[3]) {
195+ ann!(n, band, c, 4);
175 if !bc.read_bool(p[4]) {196 if !bc.read_bool(p[4]) {
176 v = 2;197 v = 2;
177 } else {198 } else {
199+ ann!(n, band, c, 5);
178 v = 3 + i32::from(bc.read_bool(p[5]));200 v = 3 + i32::from(bc.read_bool(p[5]));
179 }201 }
180- } else if !bc.read_bool(p[6]) {202+ let _ = v;
203+ } else {
204+ ann!(n, band, c, 6);
205+ if !bc.read_bool(p[6]) {
206+ ann!(n, band, c, 7);
181 if !bc.read_bool(p[7]) {207 if !bc.read_bool(p[7]) {
208+ ann!(n, band, c, 91);
182 v = 5 + i32::from(bc.read_bool(159));209 v = 5 + i32::from(bc.read_bool(159));
183 } else {210 } else {
211+ ann!(n, band, c, 161);
184 v = 7 + 2 * i32::from(bc.read_bool(165));212 v = 7 + 2 * i32::from(bc.read_bool(165));
213+ ann!(n, band, c, 162);
185 v += i32::from(bc.read_bool(145));214 v += i32::from(bc.read_bool(145));
186 }215 }
187 } else {216 } else {
188- // Categories 3..6: two tree bits pick the category, then217+ ann!(n, band, c, 8);
189- // DCTextra (§13.2).
190 let bit1 = usize::from(bc.read_bool(p[8]));218 let bit1 = usize::from(bc.read_bool(p[8]));
219+ ann!(n, band, c, 9);
191 let bit0 = usize::from(bc.read_bool(p[9 + bit1]));220 let bit0 = usize::from(bc.read_bool(p[9 + bit1]));
192 let cat = 2 * bit1 + bit0;221 let cat = 2 * bit1 + bit0;
193 v = 0;222 v = 0;
194- for &prob in CAT_EXTRA[cat] {223+ for (i, &prob) in CAT_EXTRA[cat].iter().enumerate() {
195 if prob == 0 {224 if prob == 0 {
196 break;225 break;
197 }226 }
227+ ann!(n, band, c, 30 + i);
198 v += v + i32::from(bc.read_bool(prob));228 v += v + i32::from(bc.read_bool(prob));
199 }229 }
200 v += 3 + (8 << cat);230 v += 3 + (8 << cat);
201 }231 }
232+ }
233+ c = 2;
234+ band = BANDS[n];
235+ p = &probs_t[band as usize][2];
202 236
203 // Sign flag, then dequantize (first coded position is DC).237 // Sign flag, then dequantize (first coded position is DC).
238+ ann!(n, band, c, 128);
204 let mag = if bc.read_bool(128) { -v } else { v };239 let mag = if bc.read_bool(128) { -v } else { v };
205 out[ZIGZAG[n - 1]] = if n - 1 == 0 {240 out[ZIGZAG[n - 1]] = if n - 1 == 0 {
206 (mag * i32::from(dc_factor)) as i16241 (mag * i32::from(dc_factor)) as i16
@@ -208,9 +243,7 @@ fn get_coeffs(
208 (mag * i32::from(ac_factor)) as i16243 (mag * i32::from(ac_factor)) as i16
209 };244 };
210 if n < 16 {245 if n < 16 {
211- // Non-zero coefficients set the magnitude context for246+ ann!(n, band, c, 0);
212- // the next coefficient (§13.3).
213- p = &probs_t[BANDS[n] as usize][2];
214 }247 }
215 if n == 16 || !bc.read_bool(p[0]) {248 if n == 16 || !bc.read_bool(p[0]) {
216 return n;249 return n;
@@ -221,6 +254,7 @@ fn get_coeffs(
221 }254 }
222 }255 }
223 }256 }
257+}
224 258
225 /// Decode all 25 blocks of one macroblock (dixie `decode_mb_tokens`):259 /// Decode all 25 blocks of one macroblock (dixie `decode_mb_tokens`):
226 /// Y2 first when present, then the 16 Y, then U, then V. A skipped MB260 /// Y2 first when present, then the 16 Y, then U, then V. A skipped MB