forge
Explore
Log in

Don't you dare go Hollow

Read every EC_* debug flag once instead of per block

Browse files at this commit

ba458d2edaac38c0efb91a7a3e4d12eec6bde640Ahmet Kaan GümüşParent: 5165af7
  • perf
    • read every EC_* debug flag once instead of per block
Show full message
perf(av1): read every EC_* debug flag once instead of per block

`std::env::var*` is a getenv + strlen + CStr validation on every call, and
this crate reads its trace flags from per-block, per-TU and per-MC-call
paths -- 11.6% of a 1080p10 decode's self time went to that, with the two
worst sites inside the motion-compensation kernels themselves.

Nothing in the crate or its tests calls `set_var`, so each name is a
process constant. New `envflags` module: `env_flag!(NAME)` keeps one
`LazyLock<bool>` per CALL SITE (atomic load after the first call, no
hashing), `envflags::var` serves the value sites from a single snapshot of
the environment. Semantics are unchanged at every site -- `is_some()`,
`is_none()` and the `Result<String, VarError>` shape are preserved -- and
the decoder's output is byte-identical.

160 sites in decode.rs, 2 in mc.rs. Header/tool-lookup sites that run once
per stream are left alone. 1080p10 299-frame segment, interleaved medians
of 3: 24.47 s -> 22.03 s (12.2 -> 13.6 fps), output byte-exact.
(cherry picked from commit 318e0cce54fe7697a2d23c02d3b0d385f0e1401a)
crates/ec-av1/src/decode.rsmodified+167 -167
@@ -76,7 +76,7 @@ thread_local! {
76 pub fn set_coeff_trace_frame(idx: usize) {76 pub fn set_coeff_trace_frame(idx: usize) {
77 COEFF_TRACE_FRAME.with(|c| {77 COEFF_TRACE_FRAME.with(|c| {
78 if c.get().is_none() {78 if c.get().is_none() {
79- let want = match std::env::var("EC_TRACE_COEFF_FRAME") {79+ let want = match crate::envflags::var("EC_TRACE_COEFF_FRAME") {
80 Ok(v) => v.parse::<usize>().unwrap_or(usize::MAX),80 Ok(v) => v.parse::<usize>().unwrap_or(usize::MAX),
81 // unset: keep tracing every frame, as before this rung existed81 // unset: keep tracing every frame, as before this rung existed
82 Err(_) => usize::MAX - 1,82 Err(_) => usize::MAX - 1,
@@ -85,13 +85,13 @@ pub fn set_coeff_trace_frame(idx: usize) {
85 }85 }
86 });86 });
87 COEFF_TRACE_CUR.with(|c| c.set(idx));87 COEFF_TRACE_CUR.with(|c| c.set(idx));
88- if std::env::var_os("EC_TRACE_COEFF").is_some() {88+ if crate::envflags::env_flag!("EC_TRACE_COEFF") {
89 eprintln!("EC_COEFF_FRAME decode_idx={idx}");89 eprintln!("EC_COEFF_FRAME decode_idx={idx}");
90 }90 }
91 }91 }
92 92
93 pub(crate) fn coeff_trace_on() -> bool {93 pub(crate) fn coeff_trace_on() -> bool {
94- if std::env::var_os("EC_TRACE_COEFF").is_none() {94+ if !crate::envflags::env_flag!("EC_TRACE_COEFF") {
95 return false;95 return false;
96 }96 }
97 match COEFF_TRACE_FRAME.with(|c| c.get()) {97 match COEFF_TRACE_FRAME.with(|c| c.get()) {
@@ -1200,7 +1200,7 @@ pub(crate) fn vartx_rect_leaf4_hits() -> [usize; 2] {
1200 1200
1201 /// Records one rectangular var-tx leaf.1201 /// Records one rectangular var-tx leaf.
1202 fn vartx_rect_leaf_hit(tw: usize, th: usize) {1202 fn vartx_rect_leaf_hit(tw: usize, th: usize) {
1203- if std::env::var_os("EC_VARTXLEAF").is_some() {1203+ if crate::envflags::env_flag!("EC_VARTXLEAF") {
1204 eprintln!("EC_VARTXLEAF tw={tw} th={th}");1204 eprintln!("EC_VARTXLEAF tw={tw} th={th}");
1205 }1205 }
1206 let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS };1206 let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS };
@@ -1779,7 +1779,7 @@ thread_local! {
1779 /// `EC_DEBUG_PAL=1` traces every arm and every consumption with its call site.1779 /// `EC_DEBUG_PAL=1` traces every arm and every consumption with its call site.
1780 #[track_caller]1780 #[track_caller]
1781 fn set_palette_pred(buf: Vec<u16>) {1781 fn set_palette_pred(buf: Vec<u16>) {
1782- if std::env::var_os("EC_DEBUG_PAL").is_some() {1782+ if crate::envflags::env_flag!("EC_DEBUG_PAL") {
1783 let stale = PALETTE_PRED.with(|c| c.borrow().is_some());1783 let stale = PALETTE_PRED.with(|c| c.borrow().is_some());
1784 eprintln!(1784 eprintln!(
1785 "PALSET len={} stale={stale} at {}",1785 "PALSET len={} stale={stale} at {}",
@@ -1793,7 +1793,7 @@ fn set_palette_pred(buf: Vec<u16>) {
1793 #[track_caller]1793 #[track_caller]
1794 fn take_palette_pred() -> Option<Vec<u16>> {1794 fn take_palette_pred() -> Option<Vec<u16>> {
1795 let got = PALETTE_PRED.with(|c| c.borrow_mut().take());1795 let got = PALETTE_PRED.with(|c| c.borrow_mut().take());
1796- if std::env::var_os("EC_DEBUG_PAL").is_some() {1796+ if crate::envflags::env_flag!("EC_DEBUG_PAL") {
1797 eprintln!(1797 eprintln!(
1798 "PALTAKE len={:?} at {}",1798 "PALTAKE len={:?} at {}",
1799 got.as_ref().map(Vec::len),1799 got.as_ref().map(Vec::len),
@@ -3274,7 +3274,7 @@ pub(crate) fn build_motion_field(
3274 field.set(row, col, saved);3274 field.set(row, col, saved);
3275 }3275 }
3276 }3276 }
3277- if std::env::var_os("EC_TRACE_TPL").is_some() {3277+ if crate::envflags::env_flag!("EC_TRACE_TPL") {
3278 eprintln!("EC_TPL_SAVED oh={order_hint}");3278 eprintln!("EC_TPL_SAVED oh={order_hint}");
3279 for (r, row) in field.occupancy().iter().enumerate() {3279 for (r, row) in field.occupancy().iter().enumerate() {
3280 eprintln!("EC_TPL_SAVED r{r} {row}");3280 eprintln!("EC_TPL_SAVED r{r} {row}");
@@ -3591,7 +3591,7 @@ const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9];
3591 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];3591 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];
3592 3592
3593 fn trace_edge(mi_r: usize, mi_c: usize, bsize: u32, ctx: usize, rng: u32) {3593 fn trace_edge(mi_r: usize, mi_c: usize, bsize: u32, ctx: usize, rng: u32) {
3594- if std::env::var_os("EC_AV1_TRACE").is_some() {3594+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
3595 eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}");3595 eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}");
3596 }3596 }
3597 }3597 }
@@ -3776,7 +3776,7 @@ fn base_ctx(
3776 // once; `base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain`3776 // once; `base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain`
3777 // pins the rule against the tables over their whole 5x5 domain.3777 // pins the rule against the tables over their whole 5x5 domain.
3778 if let Some((w, h)) = rect_shape {3778 if let Some((w, h)) = rect_shape {
3779- if std::env::var_os("EC_NZOFF_DUMP").is_some() {3779+ if crate::envflags::env_flag!("EC_NZOFF_DUMP") {
3780 eprintln!("NZOFF side={side} shape={w}x{h} row={row} col={col}");3780 eprintln!("NZOFF side={side} shape={w}x{h} row={row} col={col}");
3781 }3781 }
3782 if w < h && row < 2 {3782 if w < h && row < 2 {
@@ -4118,7 +4118,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
4118 const GROUP_START: [usize; 12] = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513];4118 const GROUP_START: [usize; 12] = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513];
4119 const OFFSET_BITS: [u32; 12] = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];4119 const OFFSET_BITS: [u32; 12] = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
4120 4120
4121- let trace = std::env::var_os("EC_AV1_TRACE").is_some();4121+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
4122 // libaom's `eob_flag_cdf*` tables carry a second dimension the 2D scan4122 // libaom's `eob_flag_cdf*` tables carry a second dimension the 2D scan
4123 // never touches: `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/`H_DCT`) adapt4123 // never touches: `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/`H_DCT`) adapt
4124 // a wholly separate CDF from every other tx_type (`decodetxb.c`'s4124 // a wholly separate CDF from every other tx_type (`decodetxb.c`'s
@@ -4129,7 +4129,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
4129 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,4129 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
4130 (_, Some(class1)) => class1,4130 (_, Some(class1)) => class1,
4131 };4131 };
4132- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {4132+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
4133 let (range, value) = dec.debug_state();4133 let (range, value) = dec.debug_state();
4134 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");4134 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
4135 }4135 }
@@ -4213,10 +4213,10 @@ fn read_coeffs(
4213 // caller's block genuinely is `side` x `side`.4213 // caller's block genuinely is `side` x `side`.
4214 rect_shape: Option<(usize, usize)>,4214 rect_shape: Option<(usize, usize)>,
4215 ) -> Result<(Vec<i32>, TxType)> {4215 ) -> Result<(Vec<i32>, TxType)> {
4216- let trace = std::env::var_os("EC_AV1_TRACE").is_some();4216+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
4217 let side = coding.side;4217 let side = coding.side;
4218 let mut grid = vec![0i32; side * side];4218 let mut grid = vec![0i32; side * side];
4219- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {4219+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
4220 let (range, value) = dec.debug_state();4220 let (range, value) = dec.debug_state();
4221 eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");4221 eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");
4222 }4222 }
@@ -4234,7 +4234,7 @@ fn read_coeffs(
4234 all_zero as i324234 all_zero as i32
4235 );4235 );
4236 }4236 }
4237- if std::env::var_os("EC_AV1_TELL").is_some() {4237+ if crate::envflags::env_flag!("EC_AV1_TELL") {
4238 eprintln!(4238 eprintln!(
4239 "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}",4239 "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}",
4240 all_zero as u8, dec.debug_bitpos(), dec.debug_state().04240 all_zero as u8, dec.debug_bitpos(), dec.debug_state().0
@@ -4243,7 +4243,7 @@ fn read_coeffs(
4243 if trace {4243 if trace {
4244 eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);4244 eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);
4245 }4245 }
4246- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {4246+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
4247 let (range, value) = dec.debug_state();4247 let (range, value) = dec.debug_state();
4248 eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");4248 eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");
4249 }4249 }
@@ -4261,7 +4261,7 @@ fn read_coeffs(
4261 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two4261 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two
4262 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).4262 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).
4263 let len = tx_type_cdf.len();4263 let len = tx_type_cdf.len();
4264- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() && len == 3 {4264+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") && len == 3 {
4265 eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");4265 eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");
4266 }4266 }
4267 let t = dec.symbol(tx_type_cdf);4267 let t = dec.symbol(tx_type_cdf);
@@ -4269,7 +4269,7 @@ fn read_coeffs(
4269 let (rng, _) = dec.debug_state();4269 let (rng, _) = dec.debug_state();
4270 eprintln!("EC_COEFF_STEP tag=tx_type len={len} rng={rng}");4270 eprintln!("EC_COEFF_STEP tag=tx_type len={len} rng={rng}");
4271 }4271 }
4272- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {4272+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
4273 let (range, value) = dec.debug_state();4273 let (range, value) = dec.debug_state();
4274 eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}");4274 eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}");
4275 }4275 }
@@ -5228,7 +5228,7 @@ impl Neighbours {
5228 // TX_32X32 -- independent of this block's luma `tx_depth`.5228 // TX_32X32 -- independent of this block's luma `tx_depth`.
5229 let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;5229 let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;
5230 let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;5230 let uv_tx_h = ((h_mi * MI / 2).max(4).min(32)) as u8;
5231- if std::env::var_os("EC_TXGRID_TRACE").is_some() {5231+ if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
5232 eprintln!("EC_LFGRID 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}");5232 eprintln!("EC_LFGRID 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}");
5233 }5233 }
5234 let cur = CURRENT_DELTA_LF.with(|c| c.get());5234 let cur = CURRENT_DELTA_LF.with(|c| c.get());
@@ -5279,7 +5279,7 @@ impl Neighbours {
5279 tx_h_px: u8,5279 tx_h_px: u8,
5280 ) {5280 ) {
5281 let (mi_r, mi_c) = at_mi;5281 let (mi_r, mi_c) = at_mi;
5282- if std::env::var_os("EC_TXGRID_TRACE").is_some() {5282+ if crate::envflags::env_flag!("EC_TXGRID_TRACE") {
5283 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}");5283 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}");
5284 }5284 }
5285 for rr in 0..h_mi {5285 for rr in 0..h_mi {
@@ -5649,7 +5649,7 @@ impl Neighbours {
5649 left_coded |= left.level != 0;5649 left_coded |= left.level != 0;
5650 vote += dc_vote(left.dc);5650 vote += dc_vote(left.dc);
5651 }5651 }
5652- if std::env::var_os("EC_DCDUMP").is_some() {5652+ if crate::envflags::env_flag!("EC_DCDUMP") {
5653 let ab: Vec<String> = (0..w_mi)5653 let ab: Vec<String> = (0..w_mi)
5654 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))5654 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
5655 .collect();5655 .collect();
@@ -5692,7 +5692,7 @@ impl Neighbours {
5692 left |= self.left[mi_r + cell][0].level;5692 left |= self.left[mi_r + cell][0].level;
5693 }5693 }
5694 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];5694 let ctx = SKIP_CONTEXTS[(top as usize).min(4)][(left as usize).min(4)];
5695- if std::env::var_os("EC_ECDUMP").is_some() {5695+ if crate::envflags::env_flag!("EC_ECDUMP") {
5696 let ab: Vec<String> =5696 let ab: Vec<String> =
5697 (0..w_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();5697 (0..w_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();
5698 let lf: Vec<String> =5698 let lf: Vec<String> =
@@ -5702,7 +5702,7 @@ impl Neighbours {
5702 ab.join(","), lf.join(",")5702 ab.join(","), lf.join(",")
5703 );5703 );
5704 }5704 }
5705- if std::env::var_os("EC_AV1_TRACE").is_some() {5705+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
5706 eprintln!(5706 eprintln!(
5707 "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",5707 "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",
5708 self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()5708 self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()
@@ -6046,7 +6046,7 @@ impl Neighbours {
6046 let (mi_r, mi_c) = at_mi;6046 let (mi_r, mi_c) = at_mi;
6047 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));6047 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));
6048 let (w_mi, h_mi) = (w / MI, h / MI);6048 let (w_mi, h_mi) = (w / MI, h / MI);
6049- if std::env::var_os("EC_ECPUB").is_some() {6049+ if crate::envflags::env_flag!("EC_ECPUB") {
6050 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);6050 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
6051 }6051 }
6052 for cell in 0..h_mi {6052 for cell in 0..h_mi {
@@ -6154,7 +6154,7 @@ impl Neighbours {
6154 grid: &[i32],6154 grid: &[i32],
6155 ) {6155 ) {
6156 let state = neighbour_state(grid);6156 let state = neighbour_state(grid);
6157- if std::env::var_os("EC_ECPUB").is_some() {6157+ if crate::envflags::env_flag!("EC_ECPUB") {
6158 eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level);6158 eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level);
6159 }6159 }
6160 for cell in 0..h_px / MI {6160 for cell in 0..h_px / MI {
@@ -6653,7 +6653,7 @@ fn decode_color_index_map_wh(
6653 bh: usize,6653 bh: usize,
6654 uv: bool,6654 uv: bool,
6655 ) -> Vec<u8> {6655 ) -> Vec<u8> {
6656- let trace = std::env::var_os("EC_AV1_TRACE").is_some();6656+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
6657 let mut map = vec![0u8; bw * bh];6657 let mut map = vec![0u8; bw * bh];
6658 if trace {6658 if trace {
6659 let (rng, _) = dec.debug_state();6659 let (rng, _) = dec.debug_state();
@@ -6734,7 +6734,7 @@ fn read_intra_mode_rect(
6734 Option<PaletteY>,6734 Option<PaletteY>,
6735 Option<PaletteUv>,6735 Option<PaletteUv>,
6736 )> {6736 )> {
6737- let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();6737+ let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
6738 if ec_istep {6738 if ec_istep {
6739 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line6739 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
6740 // (decodemv.c:818), printed at the same point: before the first6740 // (decodemv.c:818), printed at the same point: before the first
@@ -6904,7 +6904,7 @@ fn read_intra_mode_rect(
6904 }6904 }
6905 }6905 }
6906 let mut filter_intra = None;6906 let mut filter_intra = None;
6907- if std::env::var_os("EC_AV1_TRACE").is_some() {6907+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
6908 let (rng, _) = dec.debug_state();6908 let (rng, _) = dec.debug_state();
6909 eprintln!(6909 eprintln!(
6910 "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \6910 "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \
@@ -6921,7 +6921,7 @@ fn read_intra_mode_rect(
6921 && let Some(class) = filter_intra_size_class_rect(bw, bh)6921 && let Some(class) = filter_intra_size_class_rect(bw, bh)
6922 {6922 {
6923 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;6923 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
6924- if std::env::var_os("EC_AV1_TRACE").is_some() {6924+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
6925 eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);6925 eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);
6926 }6926 }
6927 istep!("use_filter_intra", use_filter_intra as i32);6927 istep!("use_filter_intra", use_filter_intra as i32);
@@ -7028,7 +7028,7 @@ fn tx_size_context_rect(
7028 let (own_w, own_h) = (own_w.min(64), own_h.min(64));7028 let (own_w, own_h) = (own_w.min(64), own_h.min(64));
7029 let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w;7029 let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w;
7030 let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h;7030 let left = mi_c > n.tile_col0_mi && tx_h_px_at(n, false, mi_r, mi_c - 1) as usize >= own_h;
7031- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {7031+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
7032 eprintln!(7032 eprintln!(
7033 "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}",7033 "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}",
7034 if mi_r > n.tile_row0_mi { tx_px_at(n, false, mi_r - 1, mi_c) } else { 0 },7034 if mi_r > n.tile_row0_mi { tx_px_at(n, false, mi_r - 1, mi_c) } else { 0 },
@@ -7335,7 +7335,7 @@ fn decode_rect_split(
7335 // (`av1_get_ext_tx_set_type` resolves EXT_TX_SET_DCTONLY once7335 // (`av1_get_ext_tx_set_type` resolves EXT_TX_SET_DCTONLY once
7336 // the square-up size is TX_64X64), and this unit covers its7336 // the square-up size is TX_64X64), and this unit covers its
7337 // whole block, so `get_txb_ctx` gives txb_skip ctx 0 flat.7337 // whole block, so `get_txb_ctx` gives txb_skip ctx 0 flat.
7338- if std::env::var_os("EC_RECT64TU").is_some() {7338+ if crate::envflags::env_flag!("EC_RECT64TU") {
7339 eprintln!("EC_RECT64TU mi={tu_mi:?} tx={tx_w}x{tx_h} mode={}", m.mode);7339 eprintln!("EC_RECT64TU mi={tu_mi:?} tx={tx_w}x{tx_h} mode={}", m.mode);
7340 }7340 }
7341 RECT64_CORNER_TU_HITS.with(|c| {7341 RECT64_CORNER_TU_HITS.with(|c| {
@@ -7571,7 +7571,7 @@ fn decode_rect_split(
7571 );7571 );
7572 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);7572 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);
7573 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);7573 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
7574- if std::env::var_os("EC_AV1_TRACE").is_some() {7574+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
7575 let (rng, _) = dec.debug_state();7575 let (rng, _) = dec.debug_state();
7576 eprintln!(7576 eprintln!(
7577 "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} \7577 "TRACE_RECT_SPLIT mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} \
@@ -7702,7 +7702,7 @@ fn decode_intra_rect_in_inter(
7702 }7702 }
7703 neighbours.above_side[c] = bw;7703 neighbours.above_side[c] = bw;
7704 neighbours.left_side[r] = bh;7704 neighbours.left_side[r] = bh;
7705- if std::env::var_os("EC_INTRA16X4").is_some() {7705+ if crate::envflags::env_flag!("EC_INTRA16X4") {
7706 eprintln!(7706 eprintln!(
7707 "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",7707 "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",
7708 mi_c * MI,7708 mi_c * MI,
@@ -7793,7 +7793,7 @@ fn decode_intra_rect_in_inter(
7793 (8, 32) => (1, 2),7793 (8, 32) => (1, 2),
7794 (16, 64) => (2, 3),7794 (16, 64) => (2, 3),
7795 _ => {7795 _ => {
7796- if std::env::var_os("EC_OBMCREC").is_some() {7796+ if crate::envflags::env_flag!("EC_OBMCREC") {
7797 eprintln!(7797 eprintln!(
7798 "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}"7798 "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}"
7799 );7799 );
@@ -7886,7 +7886,7 @@ fn decode_intra_rect_in_inter(
7886 // lane-t900 r1: this arm read six mode symbols with no ladder rung of its7886 // lane-t900 r1: this arm read six mode symbols with no ladder rung of its
7887 // own, so a cross-decoder bisection could only see the block's first7887 // own, so a cross-decoder bisection could only see the block's first
7888 // coefficient. Same names/format as [`read_tx_size`]'s rung.7888 // coefficient. Same names/format as [`read_tx_size`]'s rung.
7889- let step_trace = std::env::var_os("EC_TRACE_MODE_STEP").is_some();7889+ let step_trace = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
7890 if step_trace {7890 if step_trace {
7891 eprintln!(7891 eprintln!(
7892 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}",7892 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=y_mode val={mode} grp={size_group} rng={}",
@@ -8016,7 +8016,7 @@ fn decode_intra_rect_in_inter(
8016 // lane-intrasplit r3: print EVERY intra strip with its depth, not only the8016 // lane-intrasplit r3: print EVERY intra strip with its depth, not only the
8017 // split ones -- a `depth=0`-only stream is a witness gap in the SOURCE, and8017 // split ones -- a `depth=0`-only stream is a witness gap in the SOURCE, and
8018 // the two are indistinguishable when the diagnostic fires on splits alone.8018 // the two are indistinguishable when the diagnostic fires on splits alone.
8019- if std::env::var_os("EC_SPLITSTRIP").is_some() {8019+ if crate::envflags::env_flag!("EC_SPLITSTRIP") {
8020 eprintln!("EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}");8020 eprintln!("EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}");
8021 }8021 }
8022 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);8022 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
@@ -8184,7 +8184,7 @@ fn decode_block_rect(
8184 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)8184 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)
8185 };8185 };
8186 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);8186 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
8187- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {8187+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
8188 eprintln!(8188 eprintln!(
8189 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",8189 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
8190 dec.debug_state().08190 dec.debug_state().0
@@ -8201,7 +8201,7 @@ fn decode_block_rect(
8201 // unit's reconstruction inside this same strip (spec 5.11.36) --8201 // unit's reconstruction inside this same strip (spec 5.11.36) --
8202 // [`decode_rect_split`], the unit named by [`depth_to_tx_wh`].8202 // [`decode_rect_split`], the unit named by [`depth_to_tx_wh`].
8203 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);8203 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
8204- if std::env::var_os("EC_SBPART_DUMP64").is_some() {8204+ if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
8205 eprintln!(8205 eprintln!(
8206 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \8206 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
8207 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \8207 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
@@ -8266,7 +8266,7 @@ fn decode_block_rect(
8266 let (cpx, cpy) = (px / 2, py / 2);8266 let (cpx, cpy) = (px / 2, py / 2);
8267 let (chroma_w, chroma_h) = (bw / 2, bh / 2);8267 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
8268 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);8268 let reach = Reach::of_rect(bw, bh, px, py, y.width, y.height);
8269- if std::env::var_os("EC_AV1_TRACE").is_some() {8269+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
8270 let (rng, _) = dec.debug_state();8270 let (rng, _) = dec.debug_state();
8271 eprintln!(8271 eprintln!(
8272 "TRACE_RECT_IMODE mi_row={mi_r} mi_col={mi_c} mode={mode} uv_mode={uv_mode} \8272 "TRACE_RECT_IMODE mi_row={mi_r} mi_col={mi_c} mode={mode} uv_mode={uv_mode} \
@@ -8404,7 +8404,7 @@ fn decode_block_rect(
8404 dc_sign_ctx(around[0].2),8404 dc_sign_ctx(around[0].2),
8405 TxType::DctDct,8405 TxType::DctDct,
8406 )?;8406 )?;
8407- if std::env::var_os("EC_AV1_TRACE").is_some() {8407+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
8408 let (rng, _) = dec.debug_state();8408 let (rng, _) = dec.debug_state();
8409 eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}");8409 eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}");
8410 }8410 }
@@ -8448,7 +8448,7 @@ fn decode_block_rect(
8448 dc_sign_ctx(around[1].2),8448 dc_sign_ctx(around[1].2),
8449 u_default_tx,8449 u_default_tx,
8450 )?;8450 )?;
8451- if std::env::var_os("EC_AV1_TRACE").is_some() {8451+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
8452 let (rng, _) = dec.debug_state();8452 let (rng, _) = dec.debug_state();
8453 eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}");8453 eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}");
8454 }8454 }
@@ -8491,7 +8491,7 @@ fn decode_block_rect(
8491 dc_sign_ctx(around[2].2),8491 dc_sign_ctx(around[2].2),
8492 v_default_tx,8492 v_default_tx,
8493 )?;8493 )?;
8494- if std::env::var_os("EC_AV1_TRACE").is_some() {8494+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
8495 let (rng, _) = dec.debug_state();8495 let (rng, _) = dec.debug_state();
8496 eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}");8496 eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}");
8497 }8497 }
@@ -8530,7 +8530,7 @@ fn decode_block_rect(
8530 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);8530 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
8531 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);8531 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
8532 RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));8532 RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
8533- if std::env::var_os("EC_AV1_TRACE").is_some() {8533+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
8534 eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}");8534 eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}");
8535 }8535 }
8536 Ok(())8536 Ok(())
@@ -8574,7 +8574,7 @@ fn decode_leaf_rect(
8574 reduced_tx_set: bool,8574 reduced_tx_set: bool,
8575 ) -> Result<usize> {8575 ) -> Result<usize> {
8576 let _ = base_q_idx;8576 let _ = base_q_idx;
8577- if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {8577+ if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
8578 eprintln!(8578 eprintln!(
8579 "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}",8579 "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}",
8580 dec.debug_state().08580 dec.debug_state().0
@@ -8656,7 +8656,7 @@ fn decode_leaf_rect(
8656 palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));8656 palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
8657 let (pal_uv_size, pal_uv_colors) =8657 let (pal_uv_size, pal_uv_colors) =
8658 palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));8658 palette_uv.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.u_colors));
8659- if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {8659+ if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
8660 eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");8660 eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");
8661 }8661 }
8662 if filter_intra.is_some() {8662 if filter_intra.is_some() {
@@ -8800,7 +8800,7 @@ fn decode_leaf_rect(
8800 let (l_levels, luma_tx_type) = read_coeffs_rect(8800 let (l_levels, luma_tx_type) = read_coeffs_rect(
8801 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,8801 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,
8802 )?;8802 )?;
8803- if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {8803+ if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
8804 let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect();8804 let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect();
8805 eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}");8805 eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}");
8806 }8806 }
@@ -9024,7 +9024,7 @@ fn decode_block_rect4(
9024 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)9024 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)
9025 };9025 };
9026 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);9026 let d = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
9027- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {9027+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
9028 eprintln!(9028 eprintln!(
9029 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",9029 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
9030 dec.debug_state().09030 dec.debug_state().0
@@ -9548,7 +9548,7 @@ fn decode_rect4_16_strip(
9548 tx_size_context_rect(neighbours, lmi, bw, bh)9548 tx_size_context_rect(neighbours, lmi, bw, bh)
9549 };9549 };
9550 let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]);9550 let d = dec.symbol(&mut cdfs.tx_size_cat1[ctx]);
9551- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {9551+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
9552 eprintln!(9552 eprintln!(
9553 "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",9553 "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",
9554 lmi.0,9554 lmi.0,
@@ -10053,7 +10053,7 @@ fn decode_block_rect64(
10053 // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF10053 // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF
10054 // here was a wrong-table read of a real symbol.10054 // here was a wrong-table read of a real symbol.
10055 let d = dec.symbol(&mut cdfs.tx_size_cat3[ctx]);10055 let d = dec.symbol(&mut cdfs.tx_size_cat3[ctx]);
10056- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {10056+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
10057 eprintln!(10057 eprintln!(
10058 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}",10058 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}",
10059 dec.debug_state().010059 dec.debug_state().0
@@ -10087,7 +10087,7 @@ fn decode_block_rect64(
10087 };10087 };
10088 which.with(|c| c.set(c.get() + 1));10088 which.with(|c| c.set(c.get() + 1));
10089 }10089 }
10090- if std::env::var_os("EC_SBPART_DUMP64").is_some() {10090+ if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
10091 eprintln!(10091 eprintln!(
10092 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \10092 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
10093 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \10093 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
@@ -10293,7 +10293,7 @@ fn decode_block_rect64(
10293 if cur != i32::from(base_q_idx) {10293 if cur != i32::from(base_q_idx) {
10294 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));10294 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
10295 }10295 }
10296- if std::env::var_os("EC_AV1_TRACE").is_some() {10296+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
10297 eprintln!(10297 eprintln!(
10298 "TRACE rect64_dequant plane=0 base_q_idx={base_q_idx} current_q_idx={cur}"10298 "TRACE rect64_dequant plane=0 base_q_idx={base_q_idx} current_q_idx={cur}"
10299 );10299 );
@@ -10322,7 +10322,7 @@ fn decode_block_rect64(
10322 filter_intra,10322 filter_intra,
10323 smooth_neighbor,10323 smooth_neighbor,
10324 );10324 );
10325- if std::env::var_os("EC_SBPART_DUMP64").is_some() {10325+ if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
10326 let leftcol: Vec<u16> = if px > 0 {10326 let leftcol: Vec<u16> = if px > 0 {
10327 (py..py + bh).map(|row| y.data[row * y.width + px - 1]).collect()10327 (py..py + bh).map(|row| y.data[row * y.width + px - 1]).collect()
10328 } else {10328 } else {
@@ -10376,7 +10376,7 @@ fn decode_block_rect64(
10376 if cur != i32::from(base_q_idx) {10376 if cur != i32::from(base_q_idx) {
10377 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));10377 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
10378 }10378 }
10379- if std::env::var_os("EC_AV1_TRACE").is_some() {10379+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
10380 eprintln!(10380 eprintln!(
10381 "TRACE rect64_dequant plane=1 base_q_idx={base_q_idx} current_q_idx={cur}"10381 "TRACE rect64_dequant plane=1 base_q_idx={base_q_idx} current_q_idx={cur}"
10382 );10382 );
@@ -10430,7 +10430,7 @@ fn decode_block_rect64(
10430 if cur != i32::from(base_q_idx) {10430 if cur != i32::from(base_q_idx) {
10431 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));10431 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
10432 }10432 }
10433- if std::env::var_os("EC_AV1_TRACE").is_some() {10433+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
10434 eprintln!(10434 eprintln!(
10435 "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"10435 "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"
10436 );10436 );
@@ -10486,7 +10486,7 @@ fn decode_block_rect64(
10486 (16, 64) => SB_RECT4_VERT_HITS.with(|c| c.set(c.get() + 1)),10486 (16, 64) => SB_RECT4_VERT_HITS.with(|c| c.set(c.get() + 1)),
10487 _ => {}10487 _ => {}
10488 }10488 }
10489- if std::env::var_os("EC_AV1_TRACE").is_some() {10489+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
10490 let (rng, _) = dec.debug_state();10490 let (rng, _) = dec.debug_state();
10491 eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}");10491 eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}");
10492 }10492 }
@@ -10543,12 +10543,12 @@ fn read_intra_mode(
10543 Option<PaletteY>,10543 Option<PaletteY>,
10544 Option<PaletteUv>,10544 Option<PaletteUv>,
10545 )> {10545 )> {
10546- let trace = std::env::var_os("EC_AV1_TRACE").is_some();10546+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
10547 // lane-tiny r2: EC_ISTEP-format trace (same "name=... val=... rng=..."10547 // lane-tiny r2: EC_ISTEP-format trace (same "name=... val=... rng=..."
10548 // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints10548 // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints
10549 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for10549 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for
10550 // line against the instrumented aomdec, not just `tell()`.10550 // line against the instrumented aomdec, not just `tell()`.
10551- let ec_istep = std::env::var_os("EC_TRACE_MODE_STEP").is_some();10551+ let ec_istep = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
10552 if ec_istep {10552 if ec_istep {
10553 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line10553 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
10554 // (decodemv.c:818), printed at the same point: before the first10554 // (decodemv.c:818), printed at the same point: before the first
@@ -10935,7 +10935,7 @@ fn dump_stage16(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf, fw: usize,
10935 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed10935 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
10936 // `.f0` name kept only the LAST frame, so a mid-sequence divergence could10936 // `.f0` name kept only the LAST frame, so a mid-sequence divergence could
10937 // not be read out at all.10937 // not be read out at all.
10938- if let Ok(path) = std::env::var(var)10938+ if let Ok(path) = crate::envflags::var(var)
10939 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))10939 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
10940 {10940 {
10941 for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] {10941 for (p, w, h) in [(y, fw, fh), (u, fw.div_ceil(2), fh.div_ceil(2)), (v, fw.div_ceil(2), fh.div_ceil(2))] {
@@ -10967,7 +10967,7 @@ fn dump_stage_idx(var: &str) -> usize {
10967 10967
10968 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {10968 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
10969 use std::io::Write;10969 use std::io::Write;
10970- if let Ok(path) = std::env::var(var)10970+ if let Ok(path) = crate::envflags::var(var)
10971 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))10971 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
10972 {10972 {
10973 for p in [y, u, v] {10973 for p in [y, u, v] {
@@ -11132,7 +11132,7 @@ impl PlaneBuf {
11132 buf11132 buf
11133 } else {11133 } else {
11134 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);11134 let (above, left, corner) = self.edges_rect(x, y, bw, bh, reach);
11135- if std::env::var_os("EC_DEBUG_EDGES").is_some() {11135+ if crate::envflags::env_flag!("EC_DEBUG_EDGES") {
11136 eprintln!(11136 eprintln!(
11137 "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",11137 "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",
11138 above.as_ref().map(|a| (a.len(), a[0])),11138 above.as_ref().map(|a| (a.len(), a[0])),
@@ -11171,7 +11171,7 @@ impl PlaneBuf {
11171 };11171 };
11172 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's11172 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
11173 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).11173 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
11174- if std::env::var_os("EC_PRED").is_some() {11174+ if crate::envflags::env_flag!("EC_PRED") {
11175 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();11175 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
11176 let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();11176 let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
11177 let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();11177 let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
@@ -11273,7 +11273,7 @@ impl PlaneBuf {
11273 };11273 };
11274 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's11274 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
11275 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).11275 // EC_PRED/EC_PREDND rungs (x/y are this plane's pixel origin).
11276- if std::env::var_os("EC_PRED").is_some() {11276+ if crate::envflags::env_flag!("EC_PRED") {
11277 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();11277 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
11278 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();11278 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
11279 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();11279 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
@@ -11418,7 +11418,7 @@ fn read_plane(
11418 };11418 };
11419 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);11419 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
11420 let residual = dequant_and_inverse_typed(&levels, side, bit_depth(), block_q_idx(), dc_delta, ac_delta, tx_type);11420 let residual = dequant_and_inverse_typed(&levels, side, bit_depth(), block_q_idx(), dc_delta, ac_delta, tx_type);
11421- if std::env::var_os("EC_AV1_TRACE").is_some() {11421+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
11422 eprintln!(11422 eprintln!(
11423 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",11423 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
11424 );11424 );
@@ -11530,7 +11530,7 @@ fn decode_block(
11530 }11530 }
11531 let smooth_neighbor_uv =11531 let smooth_neighbor_uv =
11532 neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);11532 neighbours.smooth_uv_neighbour(r * (SUB / MI), c * (SUB / MI), r, c);
11533- if std::env::var_os("EC_AV1_TRACE").is_some() {11533+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
11534 eprintln!(11534 eprintln!(
11535 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \11535 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
11536 angle_delta_uv={angle_delta_uv}"11536 angle_delta_uv={angle_delta_uv}"
@@ -11830,7 +11830,7 @@ fn decode_block(
11830 None,11830 None,
11831 smooth_neighbor_uv,11831 smooth_neighbor_uv,
11832 )?;11832 )?;
11833- if std::env::var_os("EC_AV1_TRACE").is_some() {11833+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
11834 eprintln!(11834 eprintln!(
11835 "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",11835 "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",
11836 &u.data[cpy * u.width + cpx..][..chroma_side]11836 &u.data[cpy * u.width + cpx..][..chroma_side]
@@ -11963,7 +11963,7 @@ fn decode_block(
11963 Some(tu_skip_ctx),11963 Some(tu_skip_ctx),
11964 smooth_neighbor,11964 smooth_neighbor,
11965 )?;11965 )?;
11966- if std::env::var_os("EC_AV1_TRACE").is_some() {11966+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
11967 eprintln!(11967 eprintln!(
11968 "TRACE tu_bitpos mi=({},{}) tell={}",11968 "TRACE tu_bitpos mi=({},{}) tell={}",
11969 tu_mi.0,11969 tu_mi.0,
@@ -12900,7 +12900,7 @@ fn decode_leaf8(
12900 Some(tu_skip_ctx),12900 Some(tu_skip_ctx),
12901 smooth_neighbor,12901 smooth_neighbor,
12902 )?;12902 )?;
12903- if std::env::var_os("EC_AV1_TRACE").is_some() {12903+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
12904 eprintln!(12904 eprintln!(
12905 "TRACE tu_bitpos mi=({},{}) tell={}",12905 "TRACE tu_bitpos mi=({},{}) tell={}",
12906 tu_mi.0,12906 tu_mi.0,
@@ -13059,8 +13059,8 @@ fn read_intra_mode_sub8(
13059 mi_r: usize,13059 mi_r: usize,
13060 mi_c: usize,13060 mi_c: usize,
13061 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {13061 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {
13062- let trace = std::env::var_os("EC_AV1_TRACE").is_some();13062+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
13063- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {13063+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
13064 eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0);13064 eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0);
13065 }13065 }
13066 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;13066 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
@@ -13901,7 +13901,7 @@ fn apply_deblock(
13901 ) {13901 ) {
13902 // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel13902 // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel
13903 // mismatch between the raw reconstruction and post-filter output.13903 // mismatch between the raw reconstruction and post-filter output.
13904- if std::env::var_os("EC_AV1_DEBUG_SKIP_DEBLOCK").is_some() {13904+ if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_DEBLOCK") {
13905 return;13905 return;
13906 }13906 }
13907 if lf.level[0] != 0 || lf.level[1] != 0 {13907 if lf.level[0] != 0 || lf.level[1] != 0 {
@@ -13986,7 +13986,7 @@ fn tx_size_context_txfm_rect(
13986 if has_left && n.left_inter[mi_r] {13986 if has_left && n.left_inter[mi_r] {
13987 left = n.left_side_mi[mi_r] >= own_h;13987 left = n.left_side_mi[mi_r] >= own_h;
13988 }13988 }
13989- if std::env::var_os("EC_TXCTX").is_some() {13989+ if crate::envflags::env_flag!("EC_TXCTX") {
13990 eprintln!(13990 eprintln!(
13991 "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \13991 "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \
13992 above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \13992 above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
@@ -14046,7 +14046,7 @@ fn tx_size_context_txfm(n: &Neighbours, (mi_r, mi_c): (usize, usize), side: usiz
14046 if has_left && n.left_inter[mi_r] {14046 if has_left && n.left_inter[mi_r] {
14047 left = n.left_side_mi[mi_r] >= side;14047 left = n.left_side_mi[mi_r] >= side;
14048 }14048 }
14049- if std::env::var_os("EC_TXCTX").is_some() {14049+ if crate::envflags::env_flag!("EC_TXCTX") {
14050 eprintln!(14050 eprintln!(
14051 "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \14051 "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \
14052 above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \14052 above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
@@ -14105,7 +14105,7 @@ fn read_tx_size(
14105 }14105 }
14106 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"),14106 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"),
14107 };14107 };
14108- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {14108+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
14109 let (rng, _) = dec.debug_state();14109 let (rng, _) = dec.debug_state();
14110 let (mi_r, mi_c) = at_mi;14110 let (mi_r, mi_c) = at_mi;
14111 eprintln!(14111 eprintln!(
@@ -14213,7 +14213,7 @@ fn txfm_partition_update_rect(
14213 (tx_w, tx_h): (usize, usize),14213 (tx_w, tx_h): (usize, usize),
14214 (txb_w, txb_h): (usize, usize),14214 (txb_w, txb_h): (usize, usize),
14215 ) {14215 ) {
14216- if std::env::var_os("EC_TXUPD").is_some() {14216+ if crate::envflags::env_flag!("EC_TXUPD") {
14217 eprintln!("EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})", mi_r, mi_c);14217 eprintln!("EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})", mi_r, mi_c);
14218 }14218 }
14219 for i in 0..txb_h / MI {14219 for i in 0..txb_h / MI {
@@ -14239,7 +14239,7 @@ fn set_txfm_ctxs(
14239 h_mi: usize,14239 h_mi: usize,
14240 skip_inter: bool,14240 skip_inter: bool,
14241 ) {14241 ) {
14242- if std::env::var_os("EC_TXUPD").is_some() {14242+ if crate::envflags::env_flag!("EC_TXUPD") {
14243 eprintln!("EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}");14243 eprintln!("EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}");
14244 }14244 }
14245 let bw = if skip_inter { w_mi * MI } else { tx_px };14245 let bw = if skip_inter { w_mi * MI } else { tx_px };
@@ -14348,7 +14348,7 @@ fn read_var_tx_size(
14348 );14348 );
14349 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;14349 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
14350 TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));14350 TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));
14351- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {14351+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
14352 let (rng, _) = dec.debug_state();14352 let (rng, _) = dec.debug_state();
14353 eprintln!(14353 eprintln!(
14354 "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",14354 "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",
@@ -14795,7 +14795,7 @@ fn read_block_tx_size_rect(
14795 );14795 );
14796 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;14796 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
14797 TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));14797 TXFM_SPLIT_READS.with(|c| c.set(c.get() + 1));
14798- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {14798+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
14799 let (rng, _) = dec.debug_state();14799 let (rng, _) = dec.debug_state();
14800 eprintln!(14800 eprintln!(
14801 "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}",14801 "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}",
@@ -14943,7 +14943,7 @@ fn read_inter_plane_rect(
14943 ac_delta,14943 ac_delta,
14944 tx_type,14944 tx_type,
14945 );14945 );
14946- if std::env::var_os("EC_TRACE_TXTYPE").is_some() {14946+ if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
14947 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");14947 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
14948 }14948 }
14949 // `reconstruct_mc_rect` reads both buffers at the square prediction14949 // `reconstruct_mc_rect` reads both buffers at the square prediction
@@ -15649,7 +15649,7 @@ fn deblock_plane(
15649 plane.true_height.min(ch),15649 plane.true_height.min(ch),
15650 plane.width,15650 plane.width,
15651 );15651 );
15652- if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() {15652+ if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") {
15653 eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);15653 eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);
15654 }15654 }
15655 let mut y0 = 0usize;15655 let mut y0 = 0usize;
@@ -15657,7 +15657,7 @@ fn deblock_plane(
15657 let mut x0 = 4usize;15657 let mut x0 = 4usize;
15658 while x0 < tw {15658 while x0 < tw {
15659 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {15659 if let Some((len, level)) = edge_params(lf, n, plane_idx, 0, chroma, x0, y0) {
15660- if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() && plane_idx == 0 {15660+ if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") && plane_idx == 0 {
15661 eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");15661 eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
15662 }15662 }
15663 filter_edge(15663 filter_edge(
@@ -15679,7 +15679,7 @@ fn deblock_plane(
15679 let mut y0 = 4usize;15679 let mut y0 = 4usize;
15680 while y0 < th {15680 while y0 < th {
15681 if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) {15681 if let Some((len, level)) = edge_params(lf, n, plane_idx, 1, chroma, x0, y0) {
15682- if std::env::var_os("EC_AV1_DEBLOCK_TRACE").is_some()15682+ if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE")
15683 && plane_idx == 015683 && plane_idx == 0
15684 && x0 == 4415684 && x0 == 44
15685 {15685 {
@@ -15715,7 +15715,7 @@ fn apply_cdef(
15715 (frame_w, frame_h): (usize, usize),15715 (frame_w, frame_h): (usize, usize),
15716 ) {15716 ) {
15717 // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.15717 // lane-part32 r2 debug rung, env-gated: see `apply_deblock`'s sibling.
15718- if std::env::var_os("EC_AV1_DEBUG_SKIP_CDEF").is_some() {15718+ if crate::envflags::env_flag!("EC_AV1_DEBUG_SKIP_CDEF") {
15719 return;15719 return;
15720 }15720 }
15721 // lane-cdefstrip r1 instrument, BEFORE either early return so it is valid15721 // lane-cdefstrip r1 instrument, BEFORE either early return so it is valid
@@ -15739,7 +15739,7 @@ fn apply_cdef(
15739 })15739 })
15740 }) {15740 }) {
15741 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));15741 CDEF_UNWRITTEN_SKIP_UNITS.with(|c2| c2.set(c2.get() + 1));
15742- if std::env::var_os("EC_AV1_DEBUG_CDEF_BAND").is_some() {15742+ if crate::envflags::env_flag!("EC_AV1_DEBUG_CDEF_BAND") {
15743 eprintln!("cdef band unwritten at mi ({r},{c}) px ({},{})", r * 4, c * 4);15743 eprintln!("cdef band unwritten at mi ({r},{c}) px ({},{})", r * 4, c * 4);
15744 }15744 }
15745 }15745 }
@@ -15831,7 +15831,7 @@ fn apply_cdef(
15831 let y_dir = if y_pri_strength != 0 { dir } else { 0 };15831 let y_dir = if y_pri_strength != 0 { dir } else { 0 };
15832 let t = cdef_adjust_strength(y_pri_strength, var);15832 let t = cdef_adjust_strength(y_pri_strength, var);
15833 // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit.15833 // lane-cdef r1 rung: one line per filtered 8x8 luma CDEF unit.
15834- if std::env::var_os("EC_AV1_CDEF_DBG").is_some() {15834+ if crate::envflags::env_flag!("EC_AV1_CDEF_DBG") {
15835 eprintln!(15835 eprintln!(
15836 "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}"15836 "EC_CDEF mi_r={mi_r} mi_c={mi_c} x={ox} y={oy} sidx={sidx} dir={dir} var={var} t={t} pri={y_pri_strength} sec={y_sec_strength} damp={damping}"
15837 );15837 );
@@ -16215,7 +16215,7 @@ fn read_sb128_root(
16215 let part128 = if has_cols128 && has_rows128 {16215 let part128 = if has_cols128 && has_rows128 {
16216 PART128_SYMBOLS.with(|c| c.set(c.get() + 1));16216 PART128_SYMBOLS.with(|c| c.set(c.get() + 1));
16217 let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);16217 let p = dec.symbol(&mut cdfs.partition_w128[ctx128]);
16218- if std::env::var_os("EC_AV1_TRACE").is_some() {16218+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16219 eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");16219 eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
16220 }16220 }
16221 p16221 p
@@ -16443,7 +16443,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16443 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));16443 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
16444 QUANT_DELTAS.with(|c| c.set(deltas));16444 QUANT_DELTAS.with(|c| c.set(deltas));
16445 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));16445 CURRENT_DELTA_LF.with(|c| c.set([0; 4]));
16446- if std::env::var_os("EC_AV1_TRACE").is_some() {16446+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16447 eprintln!(16447 eprintln!(
16448 "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",16448 "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",
16449 tile_bytes.len(),16449 tile_bytes.len(),
@@ -16792,7 +16792,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16792 // three-way write exactly.16792 // three-way write exactly.
16793 let part = if has_cols && has_rows {16793 let part = if has_cols && has_rows {
16794 let p = dec.symbol(&mut cdfs.partition_w64[ctx]);16794 let p = dec.symbol(&mut cdfs.partition_w64[ctx]);
16795- if std::env::var_os("EC_AV1_TRACE").is_some() {16795+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16796 eprintln!("TRACE partition_w64 ctx={ctx} value={p}");16796 eprintln!("TRACE partition_w64 ctx={ctx} value={p}");
16797 }16797 }
16798 p16798 p
@@ -16868,7 +16868,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16868 );16868 );
16869 let part32 = if has_cols32 && has_rows32 {16869 let part32 = if has_cols32 && has_rows32 {
16870 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);16870 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
16871- if std::env::var_os("EC_AV1_TRACE").is_some() {16871+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16872 let (rng, _) = dec.debug_state();16872 let (rng, _) = dec.debug_state();
16873 eprintln!(16873 eprintln!(
16874 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}",16874 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}",
@@ -16954,7 +16954,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
16954 let ctx16 = neighbours.partition_ctx(at16, SUB);16954 let ctx16 = neighbours.partition_ctx(at16, SUB);
16955 if has_cols16 && has_rows16 {16955 if has_cols16 && has_rows16 {
16956 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);16956 let part16 = dec.symbol(&mut cdfs.partition_w16[ctx16]);
16957- if std::env::var_os("EC_AV1_TRACE").is_some() {16957+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
16958 eprintln!(16958 eprintln!(
16959 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}",16959 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}",
16960 at16.0, at16.116960 at16.0, at16.1
@@ -17279,7 +17279,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17279 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);17279 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
17280 let part8 =17280 let part8 =
17281 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);17281 dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
17282- if std::env::var_os("EC_AV1_TRACE").is_some() {17282+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
17283 eprintln!(17283 eprintln!(
17284 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"17284 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"
17285 );17285 );
@@ -17470,7 +17470,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
17470 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);17470 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
17471 let pre8 = dec.debug_state().0;17471 let pre8 = dec.debug_state().0;
17472 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);17472 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
17473- if std::env::var_os("EC_AV1_TRACE").is_some() {17473+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
17474 eprintln!(17474 eprintln!(
17475 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"17475 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
17476 );17476 );
@@ -18229,9 +18229,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18229 // in reconstruction (this dump) vs is introduced by the loop filter18229 // in reconstruction (this dump) vs is introduced by the loop filter
18230 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).18230 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
18231 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.18231 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
18232- if std::env::var_os("EC_OBMC").is_some()18232+ if crate::envflags::env_flag!("EC_OBMC")
18233- || std::env::var_os("EC_TRACE_MODE").is_some()18233+ || crate::envflags::env_flag!("EC_TRACE_MODE")
18234- || std::env::var_os("EC_PRED").is_some()18234+ || crate::envflags::env_flag!("EC_PRED")
18235 {18235 {
18236 eprintln!(18236 eprintln!(
18237 "EC_PICT idx={}",18237 "EC_PICT idx={}",
@@ -18239,7 +18239,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18239 );18239 );
18240 }18240 }
18241 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);18241 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
18242- if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {18242+ if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
18243 use std::io::Write;18243 use std::io::Write;
18244 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);18244 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
18245 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {18245 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
@@ -18251,7 +18251,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18251 } else {18251 } else {
18252 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);18252 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
18253 }18253 }
18254- if let Ok(path) = std::env::var("EC_AV1_PREFILT_WIDE_DUMP") {18254+ if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_WIDE_DUMP") {
18255 use std::io::Write;18255 use std::io::Write;
18256 static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);18256 static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
18257 let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);18257 let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -18336,7 +18336,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18336 LAST_FRAME_WIDE_MARGIN.with(|m| {18336 LAST_FRAME_WIDE_MARGIN.with(|m| {
18337 *m.borrow_mut() = if true_width > fw || true_height > fh {18337 *m.borrow_mut() = if true_width > fw || true_height > fh {
18338 let yc = crop(&y, true_width, true_height);18338 let yc = crop(&y, true_width, true_height);
18339- if let Ok(path) = std::env::var("EC_AV1_MARGIN_DUMP") {18339+ if let Ok(path) = crate::envflags::var("EC_AV1_MARGIN_DUMP") {
18340 use std::io::Write;18340 use std::io::Write;
18341 static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);18341 static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
18342 let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);18342 let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -18433,7 +18433,7 @@ fn resolve_interp_filter(
18433 // `h_kind`/`v_kind` argument order, which is why this function returns18433 // `h_kind`/`v_kind` argument order, which is why this function returns
18434 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).18434 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).
18435 let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);18435 let ctx0 = switchable_interp_ctx(above[0], left[0], 0, is_compound);
18436- if std::env::var_os("EC_AV1_IFDBG").is_some() {18436+ if crate::envflags::env_flag!("EC_AV1_IFDBG") {
18437 eprintln!(18437 eprintln!(
18438 "IFDBG dir=0 ctx={ctx0} above={above:?} left={left:?} cdf={:?}",18438 "IFDBG dir=0 ctx={ctx0} above={above:?} left={left:?} cdf={:?}",
18439 &cdfs.switchable_interp[ctx0][..3]18439 &cdfs.switchable_interp[ctx0][..3]
@@ -18442,7 +18442,7 @@ fn resolve_interp_filter(
18442 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;18442 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
18443 let sym1 = if enable_dual_filter {18443 let sym1 = if enable_dual_filter {
18444 let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);18444 let ctx1 = switchable_interp_ctx(above[1], left[1], 1, is_compound);
18445- if std::env::var_os("EC_AV1_IFDBG").is_some() {18445+ if crate::envflags::env_flag!("EC_AV1_IFDBG") {
18446 eprintln!(18446 eprintln!(
18447 "IFDBG dir=1 ctx={ctx1} above={above:?} left={left:?} cdf={:?} sym0={sym0}",18447 "IFDBG dir=1 ctx={ctx1} above={above:?} left={left:?} cdf={:?} sym0={sym0}",
18448 &cdfs.switchable_interp[ctx1][..3]18448 &cdfs.switchable_interp[ctx1][..3]
@@ -18455,7 +18455,7 @@ fn resolve_interp_filter(
18455 if enable_dual_filter && sym0 != sym1 {18455 if enable_dual_filter && sym0 != sym1 {
18456 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));18456 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));
18457 }18457 }
18458- if std::env::var_os("EC_TRACE_MODE").is_some() {18458+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
18459 eprintln!(18459 eprintln!(
18460 "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",18460 "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
18461 dec.debug_state().018461 dec.debug_state().0
@@ -18742,7 +18742,7 @@ fn read_inter_plane(
18742 None,18742 None,
18743 )?;18743 )?;
18744 note_chroma_class1(plane_idx, tx_type);18744 note_chroma_class1(plane_idx, tx_type);
18745- if std::env::var_os("EC_TRACE_TXTYPE").is_some() {18745+ if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
18746 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");18746 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
18747 }18747 }
18748 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but18748 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
@@ -19007,7 +19007,7 @@ fn find_samples(
19007 // sample candidates in libaom's own order (above, left, top-left,19007 // sample candidates in libaom's own order (above, left, top-left,
19008 // top-right) -- `num_proj_ref >= 1` is what picks the 3-symbol19008 // top-right) -- `num_proj_ref >= 1` is what picks the 3-symbol
19009 // motion_mode alphabet over the 2-symbol obmc one.19009 // motion_mode alphabet over the 2-symbol obmc one.
19010- let proj_dbg = std::env::var("EC_PROJ_MI")19010+ let proj_dbg = crate::envflags::var("EC_PROJ_MI")
19011 .is_ok_and(|v| v == format!("{mi_row},{mi_col}"));19011 .is_ok_and(|v| v == format!("{mi_row},{mi_col}"));
19012 let single_ref_match = |info: &MiInfo| {19012 let single_ref_match = |info: &MiInfo| {
19013 let m = info.ref_frame == ref_frame && info.ref_frame1.is_none();19013 let m = info.ref_frame == ref_frame && info.ref_frame1.is_none();
@@ -19246,7 +19246,7 @@ fn obmcrec_probe(
19246 cell: Option<MiInfo>,19246 cell: Option<MiInfo>,
19247 fixed: bool,19247 fixed: bool,
19248 ) {19248 ) {
19249- if (syms[0] <= 2 && syms[1] <= 2) || std::env::var_os("EC_OBMCREC").is_none() {19249+ if (syms[0] <= 2 && syms[1] <= 2) || !crate::envflags::env_flag!("EC_OBMCREC") {
19250 return;19250 return;
19251 }19251 }
19252 eprintln!(19252 eprintln!(
@@ -19501,7 +19501,7 @@ fn ec_obmc_trace(
19501 h_kind: mc::InterpFilterKind,19501 h_kind: mc::InterpFilterKind,
19502 v_kind: mc::InterpFilterKind,19502 v_kind: mc::InterpFilterKind,
19503 ) {19503 ) {
19504- if std::env::var_os("EC_OBMC").is_none() {19504+ if !crate::envflags::env_flag!("EC_OBMC") {
19505 return;19505 return;
19506 }19506 }
19507 let sym = |k: mc::InterpFilterKind| match k {19507 let sym = |k: mc::InterpFilterKind| match k {
@@ -19612,7 +19612,7 @@ fn obmc_blend(
19612 // lane-t900 r13 rung: EC_MCB="<plane>:<px>:<py>[:<frame>]" (chroma plane19612 // lane-t900 r13 rung: EC_MCB="<plane>:<px>:<py>[:<frame>]" (chroma plane
19613 // 1 only) prints this block's chroma prediction rows before and after the19613 // 1 only) prints this block's chroma prediction rows before and after the
19614 // OBMC blend, matching the instrumented aomdec's EC_MCB dump.19614 // OBMC blend, matching the instrumented aomdec's EC_MCB dump.
19615- let ec_mcb: Option<(usize, usize, i64)> = std::env::var("EC_MCB").ok().and_then(|v| {19615+ let ec_mcb: Option<(usize, usize, i64)> = crate::envflags::var("EC_MCB").ok().and_then(|v| {
19616 let f: Vec<&str> = v.split(':').collect();19616 let f: Vec<&str> = v.split(':').collect();
19617 if f.len() < 3 || f[0] != "1" {19617 if f.len() < 3 || f[0] != "1" {
19618 return None;19618 return None;
@@ -20268,11 +20268,11 @@ fn decode_inter_block(
20268 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the20268 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the
20269 // block's own dims, never on the square prediction buffer this reader20269 // block's own dims, never on the square prediction buffer this reader
20270 // allocates.20270 // allocates.
20271- if std::env::var_os("EC_MC_TRACE").is_some() {20271+ if crate::envflags::env_flag!("EC_MC_TRACE") {
20272 eprintln!("EC_IB px={px} py={py} side={side} w={write_w} h={write_h}");20272 eprintln!("EC_IB px={px} py={py} side={side} w={write_w} h={write_h}");
20273 }20273 }
20274 20274
20275- if std::env::var_os("EC_AV1_TELL").is_some() {20275+ if crate::envflags::env_flag!("EC_AV1_TELL") {
20276 eprintln!(20276 eprintln!(
20277 "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}",20277 "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}",
20278 rmi, cmi, dec.debug_bitpos(), dec.debug_state().020278 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -20283,7 +20283,7 @@ fn decode_inter_block(
20283 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read20283 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
20284 // MSAC tell so it can be diffed against an equivalent hook in libaom's20284 // MSAC tell so it can be diffed against an equivalent hook in libaom's
20285 // own `read_skip_mode`/`av1_get_skip_mode_context`.20285 // own `read_skip_mode`/`av1_get_skip_mode_context`.
20286- if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() {20286+ if crate::envflags::env_flag!("EC_AV1_SKIPMODE_DUMP") {
20287 eprintln!(20287 eprintln!(
20288 "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}",20288 "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}",
20289 dec.debug_bitpos()20289 dec.debug_bitpos()
@@ -20300,7 +20300,7 @@ fn decode_inter_block(
20300 let comp_allowed = write_w.min(write_h) >= 8;20300 let comp_allowed = write_w.min(write_h) >= 8;
20301 let skip_mode =20301 let skip_mode =
20302 skip_mode_present && comp_allowed && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;20302 skip_mode_present && comp_allowed && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
20303- if std::env::var_os("EC_AV1_SKIPMODE_DUMP").is_some() {20303+ if crate::envflags::env_flag!("EC_AV1_SKIPMODE_DUMP") {
20304 eprintln!(20304 eprintln!(
20305 "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}",20305 "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}",
20306 dec.debug_bitpos()20306 dec.debug_bitpos()
@@ -20334,7 +20334,7 @@ fn decode_inter_block(
20334 // chunk). An INTRA block at that size inside an inter frame takes the20334 // chunk). An INTRA block at that size inside an inter frame takes the
20335 // intra tail below, which still codes one whole-block chroma unit and one20335 // intra tail below, which still codes one whole-block chroma unit and one
20336 // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it.20336 // `read_tx_size` at 128 -- refuse by name instead of mis-decoding it.
20337- if std::env::var_os("EC_TRACE_MODE").is_some() {20337+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
20338 eprintln!(20338 eprintln!(
20339 "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}",20339 "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}",
20340 rmi,20340 rmi,
@@ -20363,7 +20363,7 @@ fn decode_inter_block(
20363 && !rect_inter_residual_supported(write_w, write_h)20363 && !rect_inter_residual_supported(write_w, write_h)
20364 && (is_inter || (write_w == side && write_h == side))20364 && (is_inter || (write_w == side && write_h == side))
20365 {20365 {
20366- if std::env::var_os("EC_RECTRES").is_some() {20366+ if crate::envflags::env_flag!("EC_RECTRES") {
20367 eprintln!(20367 eprintln!(
20368 "EC_RECTRES w={write_w} h={write_h} side={side} skip={} is_inter={} mi_row={rmi} mi_col={cmi}",20368 "EC_RECTRES w={write_w} h={write_h} side={side} skip={} is_inter={} mi_row={rmi} mi_col={cmi}",
20369 u8::from(skip),20369 u8::from(skip),
@@ -20374,7 +20374,7 @@ fn decode_inter_block(
20374 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",20374 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
20375 ));20375 ));
20376 }20376 }
20377- if std::env::var_os("EC_AV1_TELL").is_some() {20377+ if crate::envflags::env_flag!("EC_AV1_TELL") {
20378 eprintln!(20378 eprintln!(
20379 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",20379 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
20380 rmi, cmi, dec.debug_bitpos(), dec.debug_state().020380 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -20426,7 +20426,7 @@ fn decode_inter_block(
20426 uni: neighbours.left_ref1[rmi]20426 uni: neighbours.left_ref1[rmi]
20427 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),20427 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
20428 });20428 });
20429- if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {20429+ if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
20430 eprintln!(20430 eprintln!(
20431 "EC_PRECOMP r={r} c={c} skip_mode={skip_mode} skip={skip} reference_select={reference_select} tell={}",20431 "EC_PRECOMP r={r} c={c} skip_mode={skip_mode} skip={skip} reference_select={reference_select} tell={}",
20432 dec.debug_bitpos()20432 dec.debug_bitpos()
@@ -20509,7 +20509,7 @@ fn decode_inter_block(
20509 force_integer_mv,20509 force_integer_mv,
20510 (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),20510 (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),
20511 );20511 );
20512- if std::env::var_os("EC_TRACE_MODE").is_some() {20512+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
20513 eprintln!(20513 eprintln!(
20514 "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}",20514 "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}",
20515 compound_mode + 17,20515 compound_mode + 17,
@@ -20653,7 +20653,7 @@ fn decode_inter_block(
20653 } else {20653 } else {
20654 020654 0
20655 };20655 };
20656- if std::env::var_os("EC_TRACE_MODE").is_some() {20656+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
20657 eprintln!(20657 eprintln!(
20658 "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",20658 "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
20659 dec.debug_state().020659 dec.debug_state().0
@@ -20940,7 +20940,7 @@ fn decode_inter_block(
20940 ref_order_hints[(ref1 - LAST_FRAME) as usize],20940 ref_order_hints[(ref1 - LAST_FRAME) as usize],
20941 );20941 );
20942 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);20942 let idx = dec.symbol(&mut cdfs.compound_idx[idx_ctx]);
20943- if std::env::var_os("EC_TRACE_MODE").is_some() {20943+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
20944 eprintln!(20944 eprintln!(
20945 "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",20945 "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
20946 dec.debug_state().020946 dec.debug_state().0
@@ -20961,7 +20961,7 @@ fn decode_inter_block(
20961 (8, 8, 1u8)20961 (8, 8, 1u8)
20962 };20962 };
20963 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));20963 compound_ctx = Some((ref1, comp_group_idx as u8, compound_idx));
20964- if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {20964+ if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
20965 eprintln!(20965 eprintln!(
20966 "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",20966 "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize={side} mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
20967 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()20967 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
@@ -21601,7 +21601,7 @@ fn decode_inter_block(
21601 neighbours.left_ref1[rmi],21601 neighbours.left_ref1[rmi],
21602 );21602 );
21603 ref_frame_for_lf = ref_frame;21603 ref_frame_for_lf = ref_frame;
21604- if std::env::var_os("EC_AV1_TELL").is_some() {21604+ if crate::envflags::env_flag!("EC_AV1_TELL") {
21605 let (mi_row, mi_col) = (rmi, cmi);21605 let (mi_row, mi_col) = (rmi, cmi);
21606 eprintln!(21606 eprintln!(
21607 "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}",21607 "TELL mi_row={mi_row} mi_col={mi_col} label=post_ref_frame ref={ref_frame} tell={} range={}",
@@ -21739,7 +21739,7 @@ fn decode_inter_block(
21739 };21739 };
21740 (mv, false)21740 (mv, false)
21741 };21741 };
21742- if std::env::var_os("EC_TRACE_MODE").is_some() {21742+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
21743 for (i, e) in stack.entries.iter().enumerate() {21743 for (i, e) in stack.entries.iter().enumerate() {
21744 eprintln!(21744 eprintln!(
21745 "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",21745 "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",
@@ -21766,7 +21766,7 @@ fn decode_inter_block(
21766 let is_global_mv_block = is_globalmv && gm_model as u8 > 1 && min_bw_bh4 >= 2;21766 let is_global_mv_block = is_globalmv && gm_model as u8 > 1 && min_bw_bh4 >= 2;
21767 let gm_nontrans =21767 let gm_nontrans =
21768 is_globalmv && gm_model != ec_av1_syntax::WarpModel::Translation && min_bw_bh4 >= 2;21768 is_globalmv && gm_model != ec_av1_syntax::WarpModel::Translation && min_bw_bh4 >= 2;
21769- if std::env::var_os("EC_AV1_TELL").is_some() {21769+ if crate::envflags::env_flag!("EC_AV1_TELL") {
21770 eprintln!(21770 eprintln!(
21771 "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",21771 "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",
21772 dec.debug_bitpos(), dec.debug_state().021772 dec.debug_bitpos(), dec.debug_state().0
@@ -21845,7 +21845,7 @@ fn decode_inter_block(
21845 interintra_mode = Some(ii);21845 interintra_mode = Some(ii);
21846 }21846 }
21847 }21847 }
21848- if std::env::var_os("EC_AV1_TELL").is_some() {21848+ if crate::envflags::env_flag!("EC_AV1_TELL") {
21849 eprintln!(21849 eprintln!(
21850 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}",21850 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}",
21851 dec.debug_bitpos(), dec.debug_state().021851 dec.debug_bitpos(), dec.debug_state().0
@@ -21893,7 +21893,7 @@ fn decode_inter_block(
21893 // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility21893 // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility
21894 // mismatch is otherwise invisible (a skipped symbol prints21894 // mismatch is otherwise invisible (a skipped symbol prints
21895 // nothing).21895 // nothing).
21896- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {21896+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
21897 eprintln!(21897 eprintln!(
21898 "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \21898 "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \
21899 ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}",21899 ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}",
@@ -22025,7 +22025,7 @@ fn decode_inter_block(
22025 mi_rows as usize,22025 mi_rows as usize,
22026 ref_frame,22026 ref_frame,
22027 );22027 );
22028- if std::env::var_os("EC_WARP_DEBUG").is_some() {22028+ if crate::envflags::env_flag!("EC_WARP_DEBUG") {
22029 eprintln!(22029 eprintln!(
22030 "EC_WARP_DEBUG findSamples mi_row={mi_row} mi_col={mi_col} bsize={side} num_proj_ref={}",22030 "EC_WARP_DEBUG findSamples mi_row={mi_row} mi_col={mi_col} bsize={side} num_proj_ref={}",
22031 samples.len()22031 samples.len()
@@ -22049,7 +22049,7 @@ fn decode_inter_block(
22049 mi_row as i32,22049 mi_row as i32,
22050 mi_col as i32,22050 mi_col as i32,
22051 );22051 );
22052- if std::env::var_os("EC_WARP_DEBUG").is_some() {22052+ if crate::envflags::env_flag!("EC_WARP_DEBUG") {
22053 eprintln!(22053 eprintln!(
22054 "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}",22054 "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}",
22055 samples.len(), mv.0, mv.1, warp_params22055 samples.len(), mv.0, mv.1, warp_params
@@ -22070,7 +22070,7 @@ fn decode_inter_block(
22070 // motion_mode vs 2-symbol obmc) and the range after -- the22070 // motion_mode vs 2-symbol obmc) and the range after -- the
22071 // two give the same value with a different narrowing (class22071 // two give the same value with a different narrowing (class
22072 // wrong-alphabet-same-value).22072 // wrong-alphabet-same-value).
22073- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {22073+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
22074 eprintln!(22074 eprintln!(
22075 "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \22075 "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \
22076 scaled={} fimv={} obmc={} warped={} rng={}",22076 scaled={} fimv={} obmc={} warped={} rng={}",
@@ -22106,7 +22106,7 @@ fn decode_inter_block(
22106 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));22106 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));
22107 }22107 }
22108 }22108 }
22109- if std::env::var_os("EC_AV1_TELL").is_some() {22109+ if crate::envflags::env_flag!("EC_AV1_TELL") {
22110 eprintln!(22110 eprintln!(
22111 "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",22111 "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",
22112 motion_mode_eligible as u8, dec.debug_bitpos(), dec.debug_state().022112 motion_mode_eligible as u8, dec.debug_bitpos(), dec.debug_state().0
@@ -22149,13 +22149,13 @@ fn decode_inter_block(
22149 );22149 );
22150 block_filter = resolved_filter;22150 block_filter = resolved_filter;
22151 globalmv_for_lf = is_globalmv;22151 globalmv_for_lf = is_globalmv;
22152- if std::env::var_os("EC_AV1_TELL").is_some() {22152+ if crate::envflags::env_flag!("EC_AV1_TELL") {
22153 eprintln!(22153 eprintln!(
22154 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}",22154 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}",
22155 dec.debug_bitpos(), dec.debug_state().022155 dec.debug_bitpos(), dec.debug_state().0
22156 );22156 );
22157 }22157 }
22158- if std::env::var_os("EC_AV1_TRACE").is_some() {22158+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
22159 eprintln!(22159 eprintln!(
22160 "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}",22160 "EC_TRACE mi_row={mi_row} mi_col={mi_col} skip={} is_inter=1 mv=({},{}) is_new_mv={is_new_mv} bsize={side} ref={ref_frame} filter={:?} motion_mode_eligible={} obmc_selected={} warped={} tell={}",
22161 skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos()22161 skip as u8, mv.0, mv.1, block_filter, motion_mode_eligible as u8, obmc_selected as u8, warp_params.is_some() as u8, dec.debug_bitpos()
@@ -22908,7 +22908,7 @@ fn decode_inter_block(
22908 .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)22908 .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)
22909 .map(|s| (s.horz, s.has_chroma));22909 .map(|s| (s.horz, s.has_chroma));
22910 if write_w.min(write_h) < 8 && strip16.is_none() {22910 if write_w.min(write_h) < 8 && strip16.is_none() {
22911- if std::env::var_os("EC_INTRA16X4").is_some() {22911+ if crate::envflags::env_flag!("EC_INTRA16X4") {
22912 let (idx, hc, prev_inter) = match strip_chroma {22912 let (idx, hc, prev_inter) = match strip_chroma {
22913 Some(s) => (22913 Some(s) => (
22914 if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 },22914 if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 },
@@ -22989,7 +22989,7 @@ fn decode_inter_block(
22989 return Ok(());22989 return Ok(());
22990 }22990 }
22991 let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);22991 let mode = dec.symbol(&mut cdfs.y_mode[size_group_wh(write_w, write_h)]);
22992- if std::env::var_os("EC_IIS").is_some() {22992+ if crate::envflags::env_flag!("EC_IIS") {
22993 eprintln!(22993 eprintln!(
22994 "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}",22994 "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}",
22995 size_group_wh(write_w, write_h)22995 size_group_wh(write_w, write_h)
@@ -23442,7 +23442,7 @@ fn decode_inter_block(
23442 // equivalent post-content point (added at the matching call site)23442 // equivalent post-content point (added at the matching call site)
23443 // narrows the ladder to this block's own tail instead of the next23443 // narrows the ladder to this block's own tail instead of the next
23444 // block's partition read.23444 // block's partition read.
23445- if std::env::var_os("EC_AV1_TELL").is_some() {23445+ if crate::envflags::env_flag!("EC_AV1_TELL") {
23446 eprintln!(23446 eprintln!(
23447 "TELL mi_row={} mi_col={} label=block_end tell={} range={}",23447 "TELL mi_row={} mi_col={} label=block_end tell={} range={}",
23448 rmi, cmi, dec.debug_bitpos(), dec.debug_state().023448 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -23778,7 +23778,7 @@ fn decode_inter_sub8_split4(
23778 );23778 );
23779 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;23779 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
23780 if !is_inter {23780 if !is_inter {
23781- if std::env::var_os("EC_SUB8INTRA").is_some() {23781+ if crate::envflags::env_flag!("EC_SUB8INTRA") {
23782 eprintln!(23782 eprintln!(
23783 "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",23783 "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
23784 i == 3,23784 i == 3,
@@ -23824,7 +23824,7 @@ fn decode_inter_sub8_split4(
23824 // Same print point as the oracle's `EC_MODE` (entry of23824 // Same print point as the oracle's `EC_MODE` (entry of
23825 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the23825 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
23826 // two range ladders line up element for element.23826 // two range ladders line up element for element.
23827- if std::env::var_os("EC_TRACE_MODE").is_some() {23827+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
23828 eprintln!(23828 eprintln!(
23829 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",23829 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
23830 dec.debug_state().023830 dec.debug_state().0
@@ -23921,7 +23921,7 @@ fn decode_inter_sub8_split4(
23921 };23921 };
23922 // Same print point as the oracle's `EC_MODE_MV` (right after23922 // Same print point as the oracle's `EC_MODE_MV` (right after
23923 // `assign_mv`), the second rung of the sub-8x8 range ladder.23923 // `assign_mv`), the second rung of the sub-8x8 range ladder.
23924- if std::env::var_os("EC_TRACE_MODE").is_some() {23924+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
23925 eprintln!(23925 eprintln!(
23926 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",23926 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
23927 mv.0,23927 mv.0,
@@ -23946,7 +23946,7 @@ fn decode_inter_sub8_split4(
23946 } else {23946 } else {
23947 [3, 3]23947 [3, 3]
23948 };23948 };
23949- if std::env::var_os("EC_AV1_IFDBG").is_some() {23949+ if crate::envflags::env_flag!("EC_AV1_IFDBG") {
23950 eprintln!(23950 eprintln!(
23951 "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \23951 "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
23952 above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",23952 above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
@@ -23976,7 +23976,7 @@ fn decode_inter_sub8_split4(
23976 left_filter_ctx,23976 left_filter_ctx,
23977 false,23977 false,
23978 );23978 );
23979- if std::env::var_os("EC_TRACE_MODE").is_some() {23979+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
23980 eprintln!(23980 eprintln!(
23981 "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \23981 "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
23982 ref0={ref_frame} mv0=({},{}) stack={} rng={}",23982 ref0={ref_frame} mv0=({},{}) stack={} rng={}",
@@ -24226,7 +24226,7 @@ fn decode_intra_sub8_leaf(
24226 .mode_above_mi(lmi.0, lmi.1)24226 .mode_above_mi(lmi.0, lmi.1)
24227 .unwrap_or(above_mode);24227 .unwrap_or(above_mode);
24228 let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode);24228 let leaf_left = neighbours.mode_left_mi(lmi.0, lmi.1).unwrap_or(left_mode);
24229- let step = std::env::var_os("EC_TRACE_MODE_STEP").is_some();24229+ let step = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
24230 // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`24230 // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`
24231 // (libaom common_data.h:61).24231 // (libaom common_data.h:61).
24232 let mode = dec.symbol(&mut cdfs.y_mode[0]);24232 let mode = dec.symbol(&mut cdfs.y_mode[0]);
@@ -24734,7 +24734,7 @@ fn decode_inter_sub8_rect2(
24734 );24734 );
24735 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;24735 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
24736 if !is_inter {24736 if !is_inter {
24737- if std::env::var_os("EC_SUB8INTRA").is_some() {24737+ if crate::envflags::env_flag!("EC_SUB8INTRA") {
24738 eprintln!(24738 eprintln!(
24739 "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",24739 "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
24740 bw,24740 bw,
@@ -24773,7 +24773,7 @@ fn decode_inter_sub8_rect2(
24773 }24773 }
24774 continue;24774 continue;
24775 }24775 }
24776- if std::env::var_os("EC_TRACE_MODE").is_some() {24776+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
24777 eprintln!(24777 eprintln!(
24778 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",24778 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
24779 dec.debug_state().024779 dec.debug_state().0
@@ -24868,7 +24868,7 @@ fn decode_inter_sub8_rect2(
24868 };24868 };
24869 (mv, false)24869 (mv, false)
24870 };24870 };
24871- if std::env::var_os("EC_TRACE_MODE").is_some() {24871+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
24872 eprintln!(24872 eprintln!(
24873 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",24873 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
24874 mv.0,24874 mv.0,
@@ -24935,7 +24935,7 @@ fn decode_inter_sub8_rect2(
24935 leaves.push((0, 0, bw, bh));24935 leaves.push((0, 0, bw, bh));
24936 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);24936 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
24937 }24937 }
24938- if std::env::var_os("EC_TRACE_MODE").is_some() {24938+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
24939 eprintln!(24939 eprintln!(
24940 "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \24940 "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
24941 ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",24941 ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
@@ -25406,7 +25406,7 @@ fn decode_inter_block8(
25406 // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,25406 // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
25407 // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder25407 // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
25408 // diffs line for line against a real aomdec.25408 // diffs line for line against a real aomdec.
25409- if std::env::var_os("EC_TRACE_MODE").is_some() {25409+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
25410 eprintln!(25410 eprintln!(
25411 "EC_MODE mi_row={} mi_col={} rng={}",25411 "EC_MODE mi_row={} mi_col={} rng={}",
25412 leaf_mi.0,25412 leaf_mi.0,
@@ -25519,7 +25519,7 @@ fn decode_inter_block8(
25519 comp_stack.ref_mv_ctx,25519 comp_stack.ref_mv_ctx,
25520 )25520 )
25521 };25521 };
25522- if std::env::var_os("EC_TRACE_MODE").is_some() {25522+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
25523 eprintln!(25523 eprintln!(
25524 "EC_LEAFMODE mi_row={} mi_col={} cmode={} stack={} newmv_ctx={} refmv_ctx={} rng={}",25524 "EC_LEAFMODE mi_row={} mi_col={} cmode={} stack={} newmv_ctx={} refmv_ctx={} rng={}",
25525 leaf_mi.0,25525 leaf_mi.0,
@@ -25548,7 +25548,7 @@ fn decode_inter_block8(
25548 // lane-inter8 r3: byte-format-identical to the oracle's25548 // lane-inter8 r3: byte-format-identical to the oracle's
25549 // rung-4 `EC_MODE_VAL`, so the leaf's mode+mv VALUE ladder25549 // rung-4 `EC_MODE_VAL`, so the leaf's mode+mv VALUE ladder
25550 // diffs line for line against a real aomdec.25550 // diffs line for line against a real aomdec.
25551- if std::env::var_os("EC_TRACE_MODE").is_some() {25551+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
25552 eprintln!(25552 eprintln!(
25553 "EC_MODE_VAL mi_row={} mi_col={} mode={} ref0={} ref1={} mv0=({},{}) rng={}",25553 "EC_MODE_VAL mi_row={} mi_col={} mode={} ref0={} ref1={} mv0=({},{}) rng={}",
25554 leaf_mi.0,25554 leaf_mi.0,
@@ -25643,7 +25643,7 @@ fn decode_inter_block8(
25643 (8, 8, 1u8)25643 (8, 8, 1u8)
25644 };25644 };
25645 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));25645 compound_ctx8 = Some((ref0, ref1, comp_group_idx as u8, compound_idx));
25646- if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {25646+ if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
25647 eprintln!(25647 eprintln!(
25648 "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",25648 "EC_COMPIDX mi_row={mi_row} mi_col={mi_col} bsize=8 mode={compound_mode} mv0=({},{}) mv1=({},{}) ref0={ref0} ref1={ref1} comp_group_idx={comp_group_idx} compound_idx={compound_idx} tell={}",
25649 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()25649 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
@@ -26138,7 +26138,7 @@ fn decode_inter_block8(
26138 // lane-interp3 r2: same per-entry EC_STACK ladder26138 // lane-interp3 r2: same per-entry EC_STACK ladder
26139 // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack26139 // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack
26140 // diffs line for line against the oracle's.26140 // diffs line for line against the oracle's.
26141- if std::env::var_os("EC_TRACE_MODE").is_some() {26141+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
26142 for (i, e) in stack.entries.iter().enumerate() {26142 for (i, e) in stack.entries.iter().enumerate() {
26143 eprintln!(26143 eprintln!(
26144 "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",26144 "EC_STACK mi_row={mi_row} mi_col={mi_col} ref={ref_frame} i={i} this=({},{}) comp=(0,0) w={}",
@@ -26375,7 +26375,7 @@ fn decode_inter_block8(
26375 false,26375 false,
26376 );26376 );
26377 leaf_filter_syms = resolved_filter;26377 leaf_filter_syms = resolved_filter;
26378- if std::env::var_os("EC_TRACE_MODE").is_some() {26378+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
26379 eprintln!(26379 eprintln!(
26380 "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}",26380 "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}",
26381 leaf_mi.0,26381 leaf_mi.0,
@@ -26397,7 +26397,7 @@ fn decode_inter_block8(
26397 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));26397 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));
26398 }26398 }
26399 }26399 }
26400- if std::env::var_os("EC_TRACE_MODE").is_some() {26400+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
26401 eprintln!(26401 eprintln!(
26402 "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}",26402 "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}",
26403 leaf_mi.0,26403 leaf_mi.0,
@@ -26685,7 +26685,7 @@ fn decode_inter_block8(
26685 // but `DC_PRED` was refused here, which is what blocked the low-cq26685 // but `DC_PRED` was refused here, which is what blocked the low-cq
26686 // CDEF arms and the 10-bit gates.26686 // CDEF arms and the 10-bit gates.
26687 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);26687 let uv_mode = dec.symbol(&mut cdfs.uv_mode_cfl[mode]);
26688- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {26688+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
26689 eprintln!(26689 eprintln!(
26690 "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}",26690 "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}",
26691 leaf_mi.0,26691 leaf_mi.0,
@@ -26758,7 +26758,7 @@ fn decode_inter_block8(
26758 // prints `use_filter_intra` for an intra block inside an INTER frame26758 // prints `use_filter_intra` for an intra block inside an INTER frame
26759 // and nothing else, so this leaf needs the same two lines for a26759 // and nothing else, so this leaf needs the same two lines for a
26760 // range-ladder diff against it.26760 // range-ladder diff against it.
26761- let ec_istep8 = std::env::var_os("EC_TRACE_MODE_STEP").is_some();26761+ let ec_istep8 = crate::envflags::env_flag!("EC_TRACE_MODE_STEP");
26762 if mode == DC_PRED26762 if mode == DC_PRED
26763 && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)26763 && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)
26764 && let Some(class) = filter_intra_size_class(SIDE)26764 && let Some(class) = filter_intra_size_class(SIDE)
@@ -27482,7 +27482,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
27482 // lane-comppin r9: tile-entry range, the earliest point comparable27482 // lane-comppin r9: tile-entry range, the earliest point comparable
27483 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the27483 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the
27484 // first ladder rung before any symbol (partition or otherwise) is read.27484 // first ladder rung before any symbol (partition or otherwise) is read.
27485- if std::env::var_os("EC_AV1_TELL").is_some() {27485+ if crate::envflags::env_flag!("EC_AV1_TELL") {
27486 eprintln!(27486 eprintln!(
27487 "TELL label=tile_init tell={} range={}",27487 "TELL label=tile_init tell={} range={}",
27488 dec.debug_bitpos(),27488 dec.debug_bitpos(),
@@ -27927,9 +27927,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
27927 let part64 = match (has_cols, has_rows) {27927 let part64 = match (has_cols, has_rows) {
27928 (true, true) => {27928 (true, true) => {
27929 let pre_rng = dec.debug_state().0;27929 let pre_rng = dec.debug_state().0;
27930- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }27930+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }
27931 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);27931 let p = dec.symbol(&mut cdfs.partition_w64[sb_ctx]);
27932- if std::env::var_os("EC_AV1_TRACE").is_some() {27932+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
27933 eprintln!(27933 eprintln!(
27934 "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",27934 "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",
27935 sb_r * SB_MI,27935 sb_r * SB_MI,
@@ -27942,7 +27942,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
27942 // lane-golomb r1 (class `parsed-then-discarded`): the gathered27942 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
27943 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT27943 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
27944 // (libaom `ec_read_partition_impl`).27944 // (libaom `ec_read_partition_impl`).
27945- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }27945+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=12 ctx={} rng={}", sb_r as usize * SB_MI as usize, sb_c as usize * SB_MI as usize, sb_ctx, dec.debug_state().0); }
27946 if bump_edge32_bit(27946 if bump_edge32_bit(
27947 4,27947 4,
27948 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),27948 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
@@ -28245,7 +28245,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28245 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),28245 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),
28246 );28246 );
28247 let part32 = if has_cols32 && has_rows32 {28247 let part32 = if has_cols32 && has_rows32 {
28248- if std::env::var_os("EC_AV1_TRACE").is_some() {28248+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
28249 eprintln!(28249 eprintln!(
28250 "TRACE part32_pre mi=({},{}) rng={}",28250 "TRACE part32_pre mi=({},{}) rng={}",
28251 r32 * BLOCK_MI,28251 r32 * BLOCK_MI,
@@ -28253,9 +28253,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28253 dec.debug_state().028253 dec.debug_state().0
28254 );28254 );
28255 }28255 }
28256- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", (r32 as usize), (c32 as usize), ctx32, dec.debug_state().0); }28256+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=9 ctx={} rng={}", (r32 as usize), (c32 as usize), ctx32, dec.debug_state().0); }
28257 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);28257 let p = dec.symbol(&mut cdfs.partition_w32[ctx32]);
28258- if std::env::var_os("EC_AV1_TRACE").is_some() {28258+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
28259 eprintln!(28259 eprintln!(
28260 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}",28260 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}",
28261 r32 * BLOCK_MI,28261 r32 * BLOCK_MI,
@@ -28269,7 +28269,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28269 // lane-golomb r1 (class `parsed-then-discarded`): the gathered28269 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
28270 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT28270 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
28271 // (libaom `ec_read_partition_impl`).28271 // (libaom `ec_read_partition_impl`).
28272- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", r32 as usize * BLOCK_MI as usize, c32 as usize * BLOCK_MI as usize, ctx32, dec.debug_state().0); }28272+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=9 ctx={} rng={}", r32 as usize * BLOCK_MI as usize, c32 as usize * BLOCK_MI as usize, ctx32, dec.debug_state().0); }
28273 if {28273 if {
28274 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));28274 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
28275 bump_edge32(b.min(1) as usize);28275 bump_edge32(b.min(1) as usize);
@@ -28371,9 +28371,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28371 // inter leaves through the very same loop the28371 // inter leaves through the very same loop the
28372 // straddling case has always used.28372 // straddling case has always used.
28373 let part16 = if has_cols16 && has_rows16 {28373 let part16 = if has_cols16 && has_rows16 {
28374- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", (sr as usize*SUB_MI as usize), (sc as usize*SUB_MI as usize), ctx16, dec.debug_state().0); }28374+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=6 ctx={} rng={}", (sr as usize*SUB_MI as usize), (sc as usize*SUB_MI as usize), ctx16, dec.debug_state().0); }
28375 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);28375 let p = dec.symbol(&mut cdfs.partition_w16[ctx16]);
28376- if std::env::var_os("EC_AV1_TRACE").is_some() {28376+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
28377 let (rng, _) = dec.debug_state();28377 let (rng, _) = dec.debug_state();
28378 eprintln!(28378 eprintln!(
28379 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}",28379 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}",
@@ -28395,7 +28395,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28395 // lane-golomb r1 (class `parsed-then-discarded`): the gathered28395 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
28396 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT28396 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
28397 // (libaom `ec_read_partition_impl`).28397 // (libaom `ec_read_partition_impl`).
28398- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", sr as usize * SUB_MI as usize, sc as usize * SUB_MI as usize, ctx16, dec.debug_state().0); }28398+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PARTG mi_row={} mi_col={} bsize=6 ctx={} rng={}", sr as usize * SUB_MI as usize, sc as usize * SUB_MI as usize, ctx16, dec.debug_state().0); }
28399 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {28399 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {
28400 PARTITION_SPLIT28400 PARTITION_SPLIT
28401 } else {28401 } else {
@@ -28779,7 +28779,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
28779 for (mr, mc) in leaf_positions {28779 for (mr, mc) in leaf_positions {
28780 let leaf_mi = (mr as usize, mc as usize);28780 let leaf_mi = (mr as usize, mc as usize);
28781 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);28781 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
28782- if std::env::var_os("EC_TRACE_PART").is_some() { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); }28782+ if crate::envflags::env_flag!("EC_TRACE_PART") { eprintln!("EC_PART mi_row={} mi_col={} bsize=3 ctx={} rng={}", leaf_mi.0, leaf_mi.1, leaf_ctx, dec.debug_state().0); }
28783 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);28783 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
28784 if part8 == PARTITION_SPLIT {28784 if part8 == PARTITION_SPLIT {
28785 // lane-intersub8: four BLOCK_4X4 inter28785 // lane-intersub8: four BLOCK_4X4 inter
@@ -29901,9 +29901,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29901 // in reconstruction (this dump) vs is introduced by the loop filter29901 // in reconstruction (this dump) vs is introduced by the loop filter
29902 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).29902 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
29903 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.29903 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
29904- if std::env::var_os("EC_OBMC").is_some()29904+ if crate::envflags::env_flag!("EC_OBMC")
29905- || std::env::var_os("EC_TRACE_MODE").is_some()29905+ || crate::envflags::env_flag!("EC_TRACE_MODE")
29906- || std::env::var_os("EC_PRED").is_some()29906+ || crate::envflags::env_flag!("EC_PRED")
29907 {29907 {
29908 eprintln!(29908 eprintln!(
29909 "EC_PICT idx={}",29909 "EC_PICT idx={}",
@@ -29911,7 +29911,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
29911 );29911 );
29912 }29912 }
29913 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);29913 dump_stage16("EC_AV1_PREFILT_DUMP16", &y, &u, &v, frame_width as usize, frame_height as usize);
29914- if let Ok(path) = std::env::var("EC_AV1_PREFILT_DUMP") {29914+ if let Ok(path) = crate::envflags::var("EC_AV1_PREFILT_DUMP") {
29915 use std::io::Write;29915 use std::io::Write;
29916 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);29916 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
29917 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {29917 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
@@ -30631,8 +30631,8 @@ mod tests {
30631 .is_ok_and(|s| s.success());30631 .is_ok_and(|s| s.success());
30632 assert!(30632 assert!(
30633 present30633 present
30634- || (std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_none()30634+ || (!crate::envflags::env_flag!("EC_AV1_REQUIRE_FFMPEG")
30635- && std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none()),30635+ && !crate::envflags::env_flag!("EC_AV1_REQUIRE_AOMENC")),
30636 "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH"30636 "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH"
30637 );30637 );
30638 present30638 present
crates/ec-av1/src/envflags.rsadded+53 -0
@@ -0,0 +1,53 @@
1+//! Process-constant snapshot of the environment (lane-perf1).
2+//!
3+//! Every `EC_*` debug/trace flag in this crate is read on per-block, per-TU or
4+//! even per-MC-call paths, and `std::env::var*` is a `getenv` + `strlen` +
5+//! `CStr` validation every time: 11.6% of `decode_probe`'s self time. Nothing
6+//! in the crate or its tests calls `set_var` (`grep -rn set_var crates/ec-av1`
7+//! = 0 hits), so each name is a process constant and may be read once.
8+//!
9+//! [`env_flag!`] is the zero-syscall form for `is_some()`/`is_none()` checks:
10+//! it keeps one `LazyLock<bool>` per CALL SITE, so a hot check compiles to an
11+//! atomic load. [`var`] keeps the `Result<String, VarError>` shape of
12+//! `std::env::var` for the sites that want the value, off one snapshot map.
13+
14+use std::collections::HashMap;
15+use std::env::VarError;
16+use std::sync::LazyLock;
17+
18+static ENV: LazyLock<HashMap<String, String>> = LazyLock::new(|| std::env::vars().collect());
19+
20+/// `std::env::var`'s contract, served from the snapshot. Non-UTF-8 values are
21+/// dropped by `std::env::vars()`; the crate only reads `EC_*` flags and paths.
22+pub(crate) fn var(name: &str) -> Result<String, VarError> {
23+ ENV.get(name).cloned().ok_or(VarError::NotPresent)
24+}
25+
26+/// `true` iff `name` is present in the environment. Prefer [`env_flag!`] on
27+/// hot paths -- this one still hashes the name per call.
28+pub(crate) fn is_set(name: &str) -> bool {
29+ ENV.contains_key(name)
30+}
31+
32+/// One `LazyLock<bool>` per call site: `std::env::var_os(N).is_some()` with no
33+/// syscall and no hashing after the first call.
34+macro_rules! env_flag {
35+ ($name:literal) => {{
36+ static FLAG: std::sync::LazyLock<bool> =
37+ std::sync::LazyLock::new(|| $crate::envflags::is_set($name));
38+ *FLAG
39+ }};
40+}
41+pub(crate) use env_flag;
42+
43+#[cfg(test)]
44+mod tests {
45+ #[test]
46+ fn snapshot_matches_process_env() {
47+ // PATH is set for every test process; a name no one exports is absent.
48+ assert_eq!(super::is_set("PATH"), std::env::var_os("PATH").is_some());
49+ assert_eq!(super::var("PATH").ok(), std::env::var("PATH").ok());
50+ assert!(!super::is_set("EC_AV1_ENVFLAGS_NEVER_SET"));
51+ assert!(!env_flag!("EC_AV1_ENVFLAGS_NEVER_SET"));
52+ }
53+}
crates/ec-av1/src/lib.rsmodified+1 -0
@@ -19,6 +19,7 @@ mod compound;
19 pub mod decode;19 pub mod decode;
20 pub mod encode;20 pub mod encode;
21 pub mod encoder;21 pub mod encoder;
22+mod envflags;
22 mod film_grain;23 mod film_grain;
23 pub mod frame;24 pub mod frame;
24 mod gate_coverage;25 mod gate_coverage;
crates/ec-av1/src/mc.rsmodified+2 -2
@@ -375,7 +375,7 @@ pub fn predict_with_filters_kern(
375 let xfrac = x_q4.rem_euclid(16) as usize;375 let xfrac = x_q4.rem_euclid(16) as usize;
376 let y0 = y_q4.div_euclid(16);376 let y0 = y_q4.div_euclid(16);
377 let yfrac = y_q4.rem_euclid(16) as usize;377 let yfrac = y_q4.rem_euclid(16) as usize;
378- if std::env::var_os("EC_MC_TRACE").is_some() && block_w >= 4 {378+ if crate::envflags::env_flag!("EC_MC_TRACE") && block_w >= 4 {
379 eprintln!(379 eprintln!(
380 "EC_MC_CALL x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} xfrac={xfrac} yfrac={yfrac} hk={h_kind:?} vk={v_kind:?} tw={true_width} th={true_height} stride={stride}"380 "EC_MC_CALL x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} xfrac={xfrac} yfrac={yfrac} hk={h_kind:?} vk={v_kind:?} tw={true_width} th={true_height} stride={stride}"
381 );381 );
@@ -774,7 +774,7 @@ pub fn predict_compound_intermediate_kern(
774 774
775 let y0 = y_q4.div_euclid(16);775 let y0 = y_q4.div_euclid(16);
776 let yfrac = y_q4.rem_euclid(16) as usize;776 let yfrac = y_q4.rem_euclid(16) as usize;
777- if std::env::var_os("EC_MC_TRACE").is_some() {777+ if crate::envflags::env_flag!("EC_MC_TRACE") {
778 eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}");778 eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}");
779 }779 }
780 780