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! {
7676 pub fn set_coeff_trace_frame(idx: usize) {
7777 COEFF_TRACE_FRAME.with(|c| {
7878 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") {
8080 Ok(v) => v.parse::<usize>().unwrap_or(usize::MAX),
8181 // unset: keep tracing every frame, as before this rung existed
8282 Err(_) => usize::MAX - 1,
@@ -85,13 +85,13 @@ pub fn set_coeff_trace_frame(idx: usize) {
8585 }
8686 });
8787 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") {
8989 eprintln!("EC_COEFF_FRAME decode_idx={idx}");
9090 }
9191 }
9292
9393 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") {
9595 return false;
9696 }
9797 match COEFF_TRACE_FRAME.with(|c| c.get()) {
@@ -1200,7 +1200,7 @@ pub(crate) fn vartx_rect_leaf4_hits() -> [usize; 2] {
12001200
12011201 /// Records one rectangular var-tx leaf.
12021202 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") {
12041204 eprintln!("EC_VARTXLEAF tw={tw} th={th}");
12051205 }
12061206 let cell = if tw.min(th) == 4 { &VARTX_RECT_LEAF4_HITS } else { &VARTX_RECT_LEAF_HITS };
@@ -1779,7 +1779,7 @@ thread_local! {
17791779 /// `EC_DEBUG_PAL=1` traces every arm and every consumption with its call site.
17801780 #[track_caller]
17811781 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") {
17831783 let stale = PALETTE_PRED.with(|c| c.borrow().is_some());
17841784 eprintln!(
17851785 "PALSET len={} stale={stale} at {}",
@@ -1793,7 +1793,7 @@ fn set_palette_pred(buf: Vec<u16>) {
17931793 #[track_caller]
17941794 fn take_palette_pred() -> Option<Vec<u16>> {
17951795 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") {
17971797 eprintln!(
17981798 "PALTAKE len={:?} at {}",
17991799 got.as_ref().map(Vec::len),
@@ -3274,7 +3274,7 @@ pub(crate) fn build_motion_field(
32743274 field.set(row, col, saved);
32753275 }
32763276 }
3277- if std::env::var_os("EC_TRACE_TPL").is_some() {
3277+ if crate::envflags::env_flag!("EC_TRACE_TPL") {
32783278 eprintln!("EC_TPL_SAVED oh={order_hint}");
32793279 for (r, row) in field.occupancy().iter().enumerate() {
32803280 eprintln!("EC_TPL_SAVED r{r} {row}");
@@ -3591,7 +3591,7 @@ const VERT_ALIKE: [usize; 6] = [2, PARTITION_SPLIT, 4, 6, 7, 9];
35913591 const HORZ_ALIKE: [usize; 6] = [1, PARTITION_SPLIT, 4, 5, 6, 8];
35923592
35933593 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") {
35953595 eprintln!("OUR_PART mi_row={mi_r} mi_col={mi_c} bsize={bsize} ctx={ctx} rng={rng}");
35963596 }
35973597 }
@@ -3776,7 +3776,7 @@ fn base_ctx(
37763776 // once; `base_ctx_rect_offsets_match_the_transcribed_tables_over_the_whole_domain`
37773777 // pins the rule against the tables over their whole 5x5 domain.
37783778 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") {
37803780 eprintln!("NZOFF side={side} shape={w}x{h} row={row} col={col}");
37813781 }
37823782 if w < h && row < 2 {
@@ -4118,7 +4118,7 @@ fn read_eob(dec: &mut SymbolDecoder, coding: &mut TxbTables, class: TxClass) ->
41184118 const GROUP_START: [usize; 12] = [0, 1, 2, 3, 5, 9, 17, 33, 65, 129, 257, 513];
41194119 const OFFSET_BITS: [u32; 12] = [0, 0, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9];
41204120
4121- let trace = std::env::var_os("EC_AV1_TRACE").is_some();
4121+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
41224122 // libaom's `eob_flag_cdf*` tables carry a second dimension the 2D scan
41234123 // never touches: `TX_CLASS_HORIZ`/`TX_CLASS_VERT` (`V_DCT`/`H_DCT`) adapt
41244124 // 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) ->
41294129 (TxClass::TwoD, _) | (_, None) => coding.eob_pt,
41304130 (_, Some(class1)) => class1,
41314131 };
4132- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
4132+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
41334133 let (range, value) = dec.debug_state();
41344134 eprintln!("EC_AV1_EOBPT_CDF {eob_pt:?} range={range} value={value}");
41354135 }
@@ -4213,10 +4213,10 @@ fn read_coeffs(
42134213 // caller's block genuinely is `side` x `side`.
42144214 rect_shape: Option<(usize, usize)>,
42154215 ) -> 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");
42174217 let side = coding.side;
42184218 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") {
42204220 let (range, value) = dec.debug_state();
42214221 eprintln!("EC_AV1_STATE_BEFORE_TXBSKIP range={range} value={value}");
42224222 }
@@ -4234,7 +4234,7 @@ fn read_coeffs(
42344234 all_zero as i32
42354235 );
42364236 }
4237- if std::env::var_os("EC_AV1_TELL").is_some() {
4237+ if crate::envflags::env_flag!("EC_AV1_TELL") {
42384238 eprintln!(
42394239 "TELL label=post_txb_skip ctx={skip_ctx} all_zero={} tell={} range={}",
42404240 all_zero as u8, dec.debug_bitpos(), dec.debug_state().0
@@ -4243,7 +4243,7 @@ fn read_coeffs(
42434243 if trace {
42444244 eprintln!("TRACE all_zero ctx={skip_ctx} value={}", all_zero as i32);
42454245 }
4246- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
4246+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
42474247 let (range, value) = dec.debug_state();
42484248 eprintln!("EC_AV1_STATE_AFTER_TXBSKIP range={range} value={value}");
42494249 }
@@ -4261,7 +4261,7 @@ fn read_coeffs(
42614261 // share their symbol order with (`Tx_Type_Inter_Inv_Set3`'s two
42624262 // members are a prefix of `Tx_Type_Intra_Inv_Set2`'s five).
42634263 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 {
42654265 eprintln!("EC_AV1_TXTYPE32_CDF {tx_type_cdf:?}");
42664266 }
42674267 let t = dec.symbol(tx_type_cdf);
@@ -4269,7 +4269,7 @@ fn read_coeffs(
42694269 let (rng, _) = dec.debug_state();
42704270 eprintln!("EC_COEFF_STEP tag=tx_type len={len} rng={rng}");
42714271 }
4272- if std::env::var_os("EC_AV1_EOBPT_CDF").is_some() {
4272+ if crate::envflags::env_flag!("EC_AV1_EOBPT_CDF") {
42734273 let (range, value) = dec.debug_state();
42744274 eprintln!("EC_AV1_STATE_AFTER_TXTYPE range={range} value={value}");
42754275 }
@@ -5228,7 +5228,7 @@ impl Neighbours {
52285228 // TX_32X32 -- independent of this block's luma `tx_depth`.
52295229 let uv_tx_w = ((w_mi * MI / 2).max(4).min(32)) as u8;
52305230 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") {
52325232 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}");
52335233 }
52345234 let cur = CURRENT_DELTA_LF.with(|c| c.get());
@@ -5279,7 +5279,7 @@ impl Neighbours {
52795279 tx_h_px: u8,
52805280 ) {
52815281 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") {
52835283 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}");
52845284 }
52855285 for rr in 0..h_mi {
@@ -5649,7 +5649,7 @@ impl Neighbours {
56495649 left_coded |= left.level != 0;
56505650 vote += dc_vote(left.dc);
56515651 }
5652- if std::env::var_os("EC_DCDUMP").is_some() {
5652+ if crate::envflags::env_flag!("EC_DCDUMP") {
56535653 let ab: Vec<String> = (0..w_mi)
56545654 .map(|k| format!("{:?}/{}", self.above[mi_c + k][plane].dc, self.above[mi_c + k][plane].level))
56555655 .collect();
@@ -5692,7 +5692,7 @@ impl Neighbours {
56925692 left |= self.left[mi_r + cell][0].level;
56935693 }
56945694 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") {
56965696 let ab: Vec<String> =
56975697 (0..w_mi).map(|k| self.above[mi_c + k][0].level.to_string()).collect();
56985698 let lf: Vec<String> =
@@ -5702,7 +5702,7 @@ impl Neighbours {
57025702 ab.join(","), lf.join(",")
57035703 );
57045704 }
5705- if std::env::var_os("EC_AV1_TRACE").is_some() {
5705+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
57065706 eprintln!(
57075707 "TRACE luma_skip_ctx mi=({mi_r},{mi_c}) side_mi={side_mi} top={top} left={left} ctx={ctx} band={:?}",
57085708 self.left.iter().map(|e| e[0].level).collect::<Vec<_>>()
@@ -6046,7 +6046,7 @@ impl Neighbours {
60466046 let (mi_r, mi_c) = at_mi;
60476047 let states: [Neighbour; 3] = std::array::from_fn(|plane| neighbour_state(&grids[plane]));
60486048 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") {
60506050 eprintln!("EC_ECPUB blk mi=({mi_r},{mi_c}) wh=({w},{h}) lvl={}", states[0].level);
60516051 }
60526052 for cell in 0..h_mi {
@@ -6154,7 +6154,7 @@ impl Neighbours {
61546154 grid: &[i32],
61556155 ) {
61566156 let state = neighbour_state(grid);
6157- if std::env::var_os("EC_ECPUB").is_some() {
6157+ if crate::envflags::env_flag!("EC_ECPUB") {
61586158 eprintln!("EC_ECPUB tu mi=({mi_r},{mi_c}) wh=({w_px},{h_px}) lvl={}", state.level);
61596159 }
61606160 for cell in 0..h_px / MI {
@@ -6653,7 +6653,7 @@ fn decode_color_index_map_wh(
66536653 bh: usize,
66546654 uv: bool,
66556655 ) -> Vec<u8> {
6656- let trace = std::env::var_os("EC_AV1_TRACE").is_some();
6656+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
66576657 let mut map = vec![0u8; bw * bh];
66586658 if trace {
66596659 let (rng, _) = dec.debug_state();
@@ -6734,7 +6734,7 @@ fn read_intra_mode_rect(
67346734 Option<PaletteY>,
67356735 Option<PaletteUv>,
67366736 )> {
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");
67386738 if ec_istep {
67396739 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
67406740 // (decodemv.c:818), printed at the same point: before the first
@@ -6904,7 +6904,7 @@ fn read_intra_mode_rect(
69046904 }
69056905 }
69066906 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") {
69086908 let (rng, _) = dec.debug_state();
69096909 eprintln!(
69106910 "TRACE_RECT_PREFI mode={mode} uv_mode={uv_mode} enable_filter_intra={} \
@@ -6921,7 +6921,7 @@ fn read_intra_mode_rect(
69216921 && let Some(class) = filter_intra_size_class_rect(bw, bh)
69226922 {
69236923 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") {
69256925 eprintln!("TRACE_RECT_USEFI value={}", use_filter_intra as i32);
69266926 }
69276927 istep!("use_filter_intra", use_filter_intra as i32);
@@ -7028,7 +7028,7 @@ fn tx_size_context_rect(
70287028 let (own_w, own_h) = (own_w.min(64), own_h.min(64));
70297029 let above = mi_r > n.tile_row0_mi && tx_px_at(n, false, mi_r - 1, mi_c) as usize >= own_w;
70307030 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") {
70327032 eprintln!(
70337033 "EC_TXCTX mi_row={mi_r} mi_col={mi_c} w={own_w} h={own_h} above_px={} left_px={} ctx={}",
70347034 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(
73357335 // (`av1_get_ext_tx_set_type` resolves EXT_TX_SET_DCTONLY once
73367336 // the square-up size is TX_64X64), and this unit covers its
73377337 // 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") {
73397339 eprintln!("EC_RECT64TU mi={tu_mi:?} tx={tx_w}x{tx_h} mode={}", m.mode);
73407340 }
73417341 RECT64_CORNER_TU_HITS.with(|c| {
@@ -7571,7 +7571,7 @@ fn decode_rect_split(
75717571 );
75727572 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, m.skip);
75737573 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") {
75757575 let (rng, _) = dec.debug_state();
75767576 eprintln!(
75777577 "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(
77027702 }
77037703 neighbours.above_side[c] = bw;
77047704 neighbours.left_side[r] = bh;
7705- if std::env::var_os("EC_INTRA16X4").is_some() {
7705+ if crate::envflags::env_flag!("EC_INTRA16X4") {
77067706 eprintln!(
77077707 "EC_INTRA16X4 decoded mi={mi_r},{mi_c} px={},{} horz={horz} has_chroma={has_chroma} skip={skip} mode={mode} uv={uv:?}",
77087708 mi_c * MI,
@@ -7793,7 +7793,7 @@ fn decode_intra_rect_in_inter(
77937793 (8, 32) => (1, 2),
77947794 (16, 64) => (2, 3),
77957795 _ => {
7796- if std::env::var_os("EC_OBMCREC").is_some() {
7796+ if crate::envflags::env_flag!("EC_OBMCREC") {
77977797 eprintln!(
77987798 "OBMCREC intra-in-inter shape bw={bw} bh={bh} mi=({mi_r},{mi_c}) skip={skip}"
77997799 );
@@ -7886,7 +7886,7 @@ fn decode_intra_rect_in_inter(
78867886 // lane-t900 r1: this arm read six mode symbols with no ladder rung of its
78877887 // own, so a cross-decoder bisection could only see the block's first
78887888 // 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");
78907890 if step_trace {
78917891 eprintln!(
78927892 "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(
80168016 // lane-intrasplit r3: print EVERY intra strip with its depth, not only the
80178017 // split ones -- a `depth=0`-only stream is a witness gap in the SOURCE, and
80188018 // 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") {
80208020 eprintln!("EC_SPLITSTRIP mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} depth={depth}");
80218021 }
80228022 let (tx_w, tx_h) = depth_to_tx_wh(bw, bh, depth);
@@ -8184,7 +8184,7 @@ fn decode_block_rect(
81848184 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)
81858185 };
81868186 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") {
81888188 eprintln!(
81898189 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
81908190 dec.debug_state().0
@@ -8201,7 +8201,7 @@ fn decode_block_rect(
82018201 // unit's reconstruction inside this same strip (spec 5.11.36) --
82028202 // [`decode_rect_split`], the unit named by [`depth_to_tx_wh`].
82038203 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") {
82058205 eprintln!(
82068206 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
82078207 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
@@ -8266,7 +8266,7 @@ fn decode_block_rect(
82668266 let (cpx, cpy) = (px / 2, py / 2);
82678267 let (chroma_w, chroma_h) = (bw / 2, bh / 2);
82688268 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") {
82708270 let (rng, _) = dec.debug_state();
82718271 eprintln!(
82728272 "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(
84048404 dc_sign_ctx(around[0].2),
84058405 TxType::DctDct,
84068406 )?;
8407- if std::env::var_os("EC_AV1_TRACE").is_some() {
8407+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
84088408 let (rng, _) = dec.debug_state();
84098409 eprintln!("TRACE_RECT_COEFF plane=0 mi_row={mi_r} mi_col={mi_c} rng={rng}");
84108410 }
@@ -8448,7 +8448,7 @@ fn decode_block_rect(
84488448 dc_sign_ctx(around[1].2),
84498449 u_default_tx,
84508450 )?;
8451- if std::env::var_os("EC_AV1_TRACE").is_some() {
8451+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
84528452 let (rng, _) = dec.debug_state();
84538453 eprintln!("TRACE_RECT_COEFF plane=1 mi_row={mi_r} mi_col={mi_c} rng={rng}");
84548454 }
@@ -8491,7 +8491,7 @@ fn decode_block_rect(
84918491 dc_sign_ctx(around[2].2),
84928492 v_default_tx,
84938493 )?;
8494- if std::env::var_os("EC_AV1_TRACE").is_some() {
8494+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
84958495 let (rng, _) = dec.debug_state();
84968496 eprintln!("TRACE_RECT_COEFF plane=2 mi_row={mi_r} mi_col={mi_c} rng={rng}");
84978497 }
@@ -8530,7 +8530,7 @@ fn decode_block_rect(
85308530 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
85318531 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
85328532 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") {
85348534 eprintln!("TRACE_RECT32_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh}");
85358535 }
85368536 Ok(())
@@ -8574,7 +8574,7 @@ fn decode_leaf_rect(
85748574 reduced_tx_set: bool,
85758575 ) -> Result<usize> {
85768576 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") {
85788578 eprintln!(
85798579 "decode_leaf_rect: leaf_mi={leaf_mi:?} bw={bw} bh={bh} outer_at={outer_at:?} rng={}",
85808580 dec.debug_state().0
@@ -8656,7 +8656,7 @@ fn decode_leaf_rect(
86568656 palette_y.as_ref().map_or((0, [0u16; 8]), |p| (p.size, p.colors));
86578657 let (pal_uv_size, pal_uv_colors) =
86588658 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") {
86608660 eprintln!(" skip={skip} mode={mode} angle_delta_y={angle_delta_y} uv_mode={uv_mode}");
86618661 }
86628662 if filter_intra.is_some() {
@@ -8800,7 +8800,7 @@ fn decode_leaf_rect(
88008800 let (l_levels, luma_tx_type) = read_coeffs_rect(
88018801 dec, &mut luma_coding, luma_scan, bw, bh, 0, dc_sign_ctx(around[0].2), TxType::DctDct,
88028802 )?;
8803- if std::env::var_os("EC_AV1_RECTX_TRACE").is_some() {
8803+ if crate::envflags::env_flag!("EC_AV1_RECTX_TRACE") {
88048804 let nz: Vec<(usize, i32)> = l_levels.iter().copied().enumerate().filter(|(_, v)| *v != 0).collect();
88058805 eprintln!(" luma_tx_type={luma_tx_type:?} nz_levels={nz:?}");
88068806 }
@@ -9024,7 +9024,7 @@ fn decode_block_rect4(
90249024 tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh)
90259025 };
90269026 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") {
90289028 eprintln!(
90299029 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=2 rng={}",
90309030 dec.debug_state().0
@@ -9548,7 +9548,7 @@ fn decode_rect4_16_strip(
95489548 tx_size_context_rect(neighbours, lmi, bw, bh)
95499549 };
95509550 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") {
95529552 eprintln!(
95539553 "EC_ISTEP mi_row={} mi_col={} name=tx_depth val={d} ctx={ctx} cat=1 rng={}",
95549554 lmi.0,
@@ -10053,7 +10053,7 @@ fn decode_block_rect64(
1005310053 // block uses), not the 2 a 32x16 strip uses. Reading the cat-2 CDF
1005410054 // here was a wrong-table read of a real symbol.
1005510055 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") {
1005710057 eprintln!(
1005810058 "EC_ISTEP mi_row={mi_r} mi_col={mi_c} name=tx_depth val={d} ctx={ctx} cat=3 rng={}",
1005910059 dec.debug_state().0
@@ -10087,7 +10087,7 @@ fn decode_block_rect64(
1008710087 };
1008810088 which.with(|c| c.set(c.get() + 1));
1008910089 }
10090- if std::env::var_os("EC_SBPART_DUMP64").is_some() {
10090+ if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
1009110091 eprintln!(
1009210092 "DUMP64SPLIT mi_r={mi_r} mi_c={mi_c} px={px} py={py} bw={bw} bh={bh} \
1009310093 depth={depth} tx={tx_w}x{tx_h} mode={mode} uv={uv_predict_mode} skip={skip} \
@@ -10293,7 +10293,7 @@ fn decode_block_rect64(
1029310293 if cur != i32::from(base_q_idx) {
1029410294 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
1029510295 }
10296- if std::env::var_os("EC_AV1_TRACE").is_some() {
10296+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1029710297 eprintln!(
1029810298 "TRACE rect64_dequant plane=0 base_q_idx={base_q_idx} current_q_idx={cur}"
1029910299 );
@@ -10322,7 +10322,7 @@ fn decode_block_rect64(
1032210322 filter_intra,
1032310323 smooth_neighbor,
1032410324 );
10325- if std::env::var_os("EC_SBPART_DUMP64").is_some() {
10325+ if crate::envflags::env_flag!("EC_SBPART_DUMP64") {
1032610326 let leftcol: Vec<u16> = if px > 0 {
1032710327 (py..py + bh).map(|row| y.data[row * y.width + px - 1]).collect()
1032810328 } else {
@@ -10376,7 +10376,7 @@ fn decode_block_rect64(
1037610376 if cur != i32::from(base_q_idx) {
1037710377 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
1037810378 }
10379- if std::env::var_os("EC_AV1_TRACE").is_some() {
10379+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1038010380 eprintln!(
1038110381 "TRACE rect64_dequant plane=1 base_q_idx={base_q_idx} current_q_idx={cur}"
1038210382 );
@@ -10430,7 +10430,7 @@ fn decode_block_rect64(
1043010430 if cur != i32::from(base_q_idx) {
1043110431 RECT64_QIDX_DRIFT_HITS.with(|c| c.set(c.get() + 1));
1043210432 }
10433- if std::env::var_os("EC_AV1_TRACE").is_some() {
10433+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1043410434 eprintln!(
1043510435 "TRACE rect64_dequant plane=2 base_q_idx={base_q_idx} current_q_idx={cur}"
1043610436 );
@@ -10486,7 +10486,7 @@ fn decode_block_rect64(
1048610486 (16, 64) => SB_RECT4_VERT_HITS.with(|c| c.set(c.get() + 1)),
1048710487 _ => {}
1048810488 }
10489- if std::env::var_os("EC_AV1_TRACE").is_some() {
10489+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1049010490 let (rng, _) = dec.debug_state();
1049110491 eprintln!("TRACE_RECT64_END mi_row={mi_r} mi_col={mi_c} bw={bw} bh={bh} rng={rng}");
1049210492 }
@@ -10543,12 +10543,12 @@ fn read_intra_mode(
1054310543 Option<PaletteY>,
1054410544 Option<PaletteUv>,
1054510545 )> {
10546- let trace = std::env::var_os("EC_AV1_TRACE").is_some();
10546+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
1054710547 // lane-tiny r2: EC_ISTEP-format trace (same "name=... val=... rng=..."
1054810548 // shape the oracle's own `ec_read_intra_frame_mode_info_impl` prints
1054910549 // under `EC_TRACE_MODE_STEP`) so a range ladder can be diffed line for
1055010550 // 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");
1055210552 if ec_istep {
1055310553 // Mirrors the oracle's own `EC_IMODE mi_row=.. mi_col=.. rng=..` line
1055410554 // (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,
1093510935 // decode-order picture like EC_AV1_PREFILT_DUMP already does -- a fixed
1093610936 // `.f0` name kept only the LAST frame, so a mid-sequence divergence could
1093710937 // not be read out at all.
10938- if let Ok(path) = std::env::var(var)
10938+ if let Ok(path) = crate::envflags::var(var)
1093910939 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
1094010940 {
1094110941 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 {
1096710967
1096810968 fn dump_stage(var: &str, y: &PlaneBuf, u: &PlaneBuf, v: &PlaneBuf) {
1096910969 use std::io::Write;
10970- if let Ok(path) = std::env::var(var)
10970+ if let Ok(path) = crate::envflags::var(var)
1097110971 && let Ok(mut f) = std::fs::File::create(format!("{path}.f{}", dump_stage_idx(var)))
1097210972 {
1097310973 for p in [y, u, v] {
@@ -11132,7 +11132,7 @@ impl PlaneBuf {
1113211132 buf
1113311133 } else {
1113411134 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") {
1113611136 eprintln!(
1113711137 "EDGES x={x} y={y} bw={bw} bh={bh} mode={mode} above={:?} left_len={:?} left0={:?} corner={corner:?} tx0={} ty0={} truew={} trueh={}",
1113811138 above.as_ref().map(|a| (a.len(), a[0])),
@@ -11171,7 +11171,7 @@ impl PlaneBuf {
1117111171 };
1117211172 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
1117311173 // 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") {
1117511175 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
1117611176 let row0: Vec<u16> = prediction[..bw.min(8)].to_vec();
1117711177 let col0: Vec<u16> = (0..bh.min(8)).map(|r| prediction[r * bw]).collect();
@@ -11273,7 +11273,7 @@ impl PlaneBuf {
1127311273 };
1127411274 // lane-hgkf r2: per-TU prediction trace, the twin of aomdec's
1127511275 // 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") {
1127711277 let sum: i64 = prediction.iter().map(|&v| i64::from(v)).sum();
1127811278 let row0: Vec<u16> = prediction[..side.min(8)].to_vec();
1127911279 let col0: Vec<u16> = (0..side.min(8)).map(|r| prediction[r * side]).collect();
@@ -11418,7 +11418,7 @@ fn read_plane(
1141811418 };
1141911419 let (dc_delta, ac_delta) = plane_q_delta(plane_idx);
1142011420 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") {
1142211422 eprintln!(
1142311423 "TRACE dequant plane={plane_idx} base_q_idx={base_q_idx} tx_type={tx_type:?} side={side} levels={levels:?} residual={residual:?}",
1142411424 );
@@ -11530,7 +11530,7 @@ fn decode_block(
1153011530 }
1153111531 let smooth_neighbor_uv =
1153211532 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") {
1153411534 eprintln!(
1153511535 "TRACE block px={px} py={py} side={side} mode={mode} uv_mode={uv_mode} \
1153611536 angle_delta_uv={angle_delta_uv}"
@@ -11830,7 +11830,7 @@ fn decode_block(
1183011830 None,
1183111831 smooth_neighbor_uv,
1183211832 )?;
11833- if std::env::var_os("EC_AV1_TRACE").is_some() {
11833+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1183411834 eprintln!(
1183511835 "TRACE u-write cpx={cpx} cpy={cpy} chroma_side={chroma_side} row0={:?}",
1183611836 &u.data[cpy * u.width + cpx..][..chroma_side]
@@ -11963,7 +11963,7 @@ fn decode_block(
1196311963 Some(tu_skip_ctx),
1196411964 smooth_neighbor,
1196511965 )?;
11966- if std::env::var_os("EC_AV1_TRACE").is_some() {
11966+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1196711967 eprintln!(
1196811968 "TRACE tu_bitpos mi=({},{}) tell={}",
1196911969 tu_mi.0,
@@ -12900,7 +12900,7 @@ fn decode_leaf8(
1290012900 Some(tu_skip_ctx),
1290112901 smooth_neighbor,
1290212902 )?;
12903- if std::env::var_os("EC_AV1_TRACE").is_some() {
12903+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
1290412904 eprintln!(
1290512905 "TRACE tu_bitpos mi=({},{}) tell={}",
1290612906 tu_mi.0,
@@ -13059,8 +13059,8 @@ fn read_intra_mode_sub8(
1305913059 mi_r: usize,
1306013060 mi_c: usize,
1306113061 ) -> Result<(bool, usize, i32, Option<(usize, i32, Option<(i32, i32)>)>, Option<usize>)> {
13062- let trace = std::env::var_os("EC_AV1_TRACE").is_some();
13063- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
13062+ let trace = crate::envflags::env_flag!("EC_AV1_TRACE");
13063+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1306413064 eprintln!("EC_IMODE mi_row={mi_r} mi_col={mi_c} fn=sub8 rng={}", dec.debug_state().0);
1306513065 }
1306613066 let skip = dec.symbol(&mut cdfs.skip[skip_ctx]) != 0;
@@ -13901,7 +13901,7 @@ fn apply_deblock(
1390113901 ) {
1390213902 // lane-part32 r2 debug rung, env-gated: bisecting a widespread pixel
1390313903 // 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") {
1390513905 return;
1390613906 }
1390713907 if lf.level[0] != 0 || lf.level[1] != 0 {
@@ -13986,7 +13986,7 @@ fn tx_size_context_txfm_rect(
1398613986 if has_left && n.left_inter[mi_r] {
1398713987 left = n.left_side_mi[mi_r] >= own_h;
1398813988 }
13989- if std::env::var_os("EC_TXCTX").is_some() {
13989+ if crate::envflags::env_flag!("EC_TXCTX") {
1399013990 eprintln!(
1399113991 "EC_TXCTX mi={mi_r},{mi_c} own={own_w}x{own_h} ha={has_above} hl={has_left} \
1399213992 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
1404614046 if has_left && n.left_inter[mi_r] {
1404714047 left = n.left_side_mi[mi_r] >= side;
1404814048 }
14049- if std::env::var_os("EC_TXCTX").is_some() {
14049+ if crate::envflags::env_flag!("EC_TXCTX") {
1405014050 eprintln!(
1405114051 "EC_TXCTX mi={mi_r},{mi_c} own={side} ha={has_above} hl={has_left} \
1405214052 above_txfm={} left_txfm={} above_inter={} left_inter={} above_side={} left_side={} \
@@ -14105,7 +14105,7 @@ fn read_tx_size(
1410514105 }
1410614106 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64/128"),
1410714107 };
14108- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
14108+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
1410914109 let (rng, _) = dec.debug_state();
1411014110 let (mi_r, mi_c) = at_mi;
1411114111 eprintln!(
@@ -14213,7 +14213,7 @@ fn txfm_partition_update_rect(
1421314213 (tx_w, tx_h): (usize, usize),
1421414214 (txb_w, txb_h): (usize, usize),
1421514215 ) {
14216- if std::env::var_os("EC_TXUPD").is_some() {
14216+ if crate::envflags::env_flag!("EC_TXUPD") {
1421714217 eprintln!("EC_TXUPD rect mi=({},{}) tx=({tx_w},{tx_h}) txb=({txb_w},{txb_h})", mi_r, mi_c);
1421814218 }
1421914219 for i in 0..txb_h / MI {
@@ -14239,7 +14239,7 @@ fn set_txfm_ctxs(
1423914239 h_mi: usize,
1424014240 skip_inter: bool,
1424114241 ) {
14242- if std::env::var_os("EC_TXUPD").is_some() {
14242+ if crate::envflags::env_flag!("EC_TXUPD") {
1424314243 eprintln!("EC_TXUPD ctxs mi=({mi_r},{mi_c}) tx={tx_px} wh=({w_mi},{h_mi}) skip_inter={skip_inter}");
1424414244 }
1424514245 let bw = if skip_inter { w_mi * MI } else { tx_px };
@@ -14348,7 +14348,7 @@ fn read_var_tx_size(
1434814348 );
1434914349 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
1435014350 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") {
1435214352 let (rng, _) = dec.debug_state();
1435314353 eprintln!(
1435414354 "EC_ISTEP mi_row={} mi_col={} name=txfm_split val={} ctx={ctx} rng={rng}",
@@ -14795,7 +14795,7 @@ fn read_block_tx_size_rect(
1479514795 );
1479614796 let split = dec.symbol(&mut cdfs.txfm_partition[ctx]) == 1;
1479714797 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") {
1479914799 let (rng, _) = dec.debug_state();
1480014800 eprintln!(
1480114801 "EC_ISTEP mi_row={} mi_col={} name=txfm_split_rect val={} ctx={ctx} rng={rng}",
@@ -14943,7 +14943,7 @@ fn read_inter_plane_rect(
1494314943 ac_delta,
1494414944 tx_type,
1494514945 );
14946- if std::env::var_os("EC_TRACE_TXTYPE").is_some() {
14946+ if crate::envflags::env_flag!("EC_TRACE_TXTYPE") {
1494714947 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} w={w} h={h} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
1494814948 }
1494914949 // `reconstruct_mc_rect` reads both buffers at the square prediction
@@ -15649,7 +15649,7 @@ fn deblock_plane(
1564915649 plane.true_height.min(ch),
1565015650 plane.width,
1565115651 );
15652- if std::env::var_os("EC_AV1_DEBLOCK_TRACE_V").is_some() {
15652+ if crate::envflags::env_flag!("EC_AV1_DEBLOCK_TRACE_V") {
1565315653 eprintln!("DEBLOCK plane={plane_idx} tw={tw} th={th} stride={stride} true={}x{} crop={cw}x{ch}", plane.true_width, plane.true_height);
1565415654 }
1565515655 let mut y0 = 0usize;
@@ -15657,7 +15657,7 @@ fn deblock_plane(
1565715657 let mut x0 = 4usize;
1565815658 while x0 < tw {
1565915659 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 {
1566115661 eprintln!("VEDGE x0={x0} y0={y0} len={len} level={level}");
1566215662 }
1566315663 filter_edge(
@@ -15679,7 +15679,7 @@ fn deblock_plane(
1567915679 let mut y0 = 4usize;
1568015680 while y0 < th {
1568115681 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")
1568315683 && plane_idx == 0
1568415684 && x0 == 44
1568515685 {
@@ -15715,7 +15715,7 @@ fn apply_cdef(
1571515715 (frame_w, frame_h): (usize, usize),
1571615716 ) {
1571715717 // 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") {
1571915719 return;
1572015720 }
1572115721 // lane-cdefstrip r1 instrument, BEFORE either early return so it is valid
@@ -15739,7 +15739,7 @@ fn apply_cdef(
1573915739 })
1574015740 }) {
1574115741 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") {
1574315743 eprintln!("cdef band unwritten at mi ({r},{c}) px ({},{})", r * 4, c * 4);
1574415744 }
1574515745 }
@@ -15831,7 +15831,7 @@ fn apply_cdef(
1583115831 let y_dir = if y_pri_strength != 0 { dir } else { 0 };
1583215832 let t = cdef_adjust_strength(y_pri_strength, var);
1583315833 // 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") {
1583515835 eprintln!(
1583615836 "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}"
1583715837 );
@@ -16215,7 +16215,7 @@ fn read_sb128_root(
1621516215 let part128 = if has_cols128 && has_rows128 {
1621616216 PART128_SYMBOLS.with(|c| c.set(c.get() + 1));
1621716217 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") {
1621916219 eprintln!("TRACE partition_w128 ctx={ctx128} value={p}");
1622016220 }
1622116221 p
@@ -16443,7 +16443,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1644316443 CURRENT_Q_IDX.with(|c| c.set(i32::from(base_q_idx)));
1644416444 QUANT_DELTAS.with(|c| c.set(deltas));
1644516445 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") {
1644716447 eprintln!(
1644816448 "TRACE key_tile_bytes tile={tile_num} len={} first8={:02x?} base_q_idx={base_q_idx} mi_cols={mi_cols} mi_rows={mi_rows}",
1644916449 tile_bytes.len(),
@@ -16792,7 +16792,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1679216792 // three-way write exactly.
1679316793 let part = if has_cols && has_rows {
1679416794 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") {
1679616796 eprintln!("TRACE partition_w64 ctx={ctx} value={p}");
1679716797 }
1679816798 p
@@ -16868,7 +16868,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1686816868 );
1686916869 let part32 = if has_cols32 && has_rows32 {
1687016870 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") {
1687216872 let (rng, _) = dec.debug_state();
1687316873 eprintln!(
1687416874 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p} rng={rng}",
@@ -16954,7 +16954,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1695416954 let ctx16 = neighbours.partition_ctx(at16, SUB);
1695516955 if has_cols16 && has_rows16 {
1695616956 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") {
1695816958 eprintln!(
1695916959 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={part16}",
1696016960 at16.0, at16.1
@@ -17279,7 +17279,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1727917279 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
1728017280 let part8 =
1728117281 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") {
1728317283 eprintln!(
1728417284 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8}"
1728517285 );
@@ -17470,7 +17470,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1747017470 let leaf_ctx = neighbours.partition_ctx_mi(leaf_mi, 8);
1747117471 let pre8 = dec.debug_state().0;
1747217472 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") {
1747417474 eprintln!(
1747517475 "TRACE partition_w8 mi=({mr},{mc}) ctx={leaf_ctx} value={part8} pre_rng={pre8}"
1747617476 );
@@ -18229,9 +18229,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1822918229 // in reconstruction (this dump) vs is introduced by the loop filter
1823018230 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
1823118231 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
18232- if std::env::var_os("EC_OBMC").is_some()
18233- || std::env::var_os("EC_TRACE_MODE").is_some()
18234- || std::env::var_os("EC_PRED").is_some()
18232+ if crate::envflags::env_flag!("EC_OBMC")
18233+ || crate::envflags::env_flag!("EC_TRACE_MODE")
18234+ || crate::envflags::env_flag!("EC_PRED")
1823518235 {
1823618236 eprintln!(
1823718237 "EC_PICT idx={}",
@@ -18239,7 +18239,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1823918239 );
1824018240 }
1824118241 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") {
1824318243 use std::io::Write;
1824418244 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
1824518245 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(
1825118251 } else {
1825218252 PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
1825318253 }
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") {
1825518255 use std::io::Write;
1825618256 static IDX2: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
1825718257 let idx = IDX2.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -18336,7 +18336,7 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
1833618336 LAST_FRAME_WIDE_MARGIN.with(|m| {
1833718337 *m.borrow_mut() = if true_width > fw || true_height > fh {
1833818338 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") {
1834018340 use std::io::Write;
1834118341 static IDX: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
1834218342 let idx = IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
@@ -18433,7 +18433,7 @@ fn resolve_interp_filter(
1843318433 // `h_kind`/`v_kind` argument order, which is why this function returns
1843418434 // `(h, v, ..)` but reads `dir0` (`v`) before `dir1` (`h`).
1843518435 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") {
1843718437 eprintln!(
1843818438 "IFDBG dir=0 ctx={ctx0} above={above:?} left={left:?} cdf={:?}",
1843918439 &cdfs.switchable_interp[ctx0][..3]
@@ -18442,7 +18442,7 @@ fn resolve_interp_filter(
1844218442 let sym0 = dec.symbol(&mut cdfs.switchable_interp[ctx0]) as u8;
1844318443 let sym1 = if enable_dual_filter {
1844418444 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") {
1844618446 eprintln!(
1844718447 "IFDBG dir=1 ctx={ctx1} above={above:?} left={left:?} cdf={:?} sym0={sym0}",
1844818448 &cdfs.switchable_interp[ctx1][..3]
@@ -18455,7 +18455,7 @@ fn resolve_interp_filter(
1845518455 if enable_dual_filter && sym0 != sym1 {
1845618456 DUAL_FILTER_DIFF_HITS.with(|c| c.set(c.get() + 1));
1845718457 }
18458- if std::env::var_os("EC_TRACE_MODE").is_some() {
18458+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
1845918459 eprintln!(
1846018460 "EC_IF ctx0={ctx0} above={above:?} left={left:?} sym0={sym0} sym1={sym1} rng={}",
1846118461 dec.debug_state().0
@@ -18742,7 +18742,7 @@ fn read_inter_plane(
1874218742 None,
1874318743 )?;
1874418744 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") {
1874618746 eprintln!("OUR_TXTYPE plane={plane_idx} x={x} y={y} side={side} tx_type={tx_type:?} inh={inherited_luma_tx_type:?}");
1874718747 }
1874818748 // lane-inter8 r1: a 64-point transform covers the whole 64x64 area but
@@ -19007,7 +19007,7 @@ fn find_samples(
1900719007 // sample candidates in libaom's own order (above, left, top-left,
1900819008 // top-right) -- `num_proj_ref >= 1` is what picks the 3-symbol
1900919009 // 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")
1901119011 .is_ok_and(|v| v == format!("{mi_row},{mi_col}"));
1901219012 let single_ref_match = |info: &MiInfo| {
1901319013 let m = info.ref_frame == ref_frame && info.ref_frame1.is_none();
@@ -19246,7 +19246,7 @@ fn obmcrec_probe(
1924619246 cell: Option<MiInfo>,
1924719247 fixed: bool,
1924819248 ) {
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") {
1925019250 return;
1925119251 }
1925219252 eprintln!(
@@ -19501,7 +19501,7 @@ fn ec_obmc_trace(
1950119501 h_kind: mc::InterpFilterKind,
1950219502 v_kind: mc::InterpFilterKind,
1950319503 ) {
19504- if std::env::var_os("EC_OBMC").is_none() {
19504+ if !crate::envflags::env_flag!("EC_OBMC") {
1950519505 return;
1950619506 }
1950719507 let sym = |k: mc::InterpFilterKind| match k {
@@ -19612,7 +19612,7 @@ fn obmc_blend(
1961219612 // lane-t900 r13 rung: EC_MCB="<plane>:<px>:<py>[:<frame>]" (chroma plane
1961319613 // 1 only) prints this block's chroma prediction rows before and after the
1961419614 // 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| {
1961619616 let f: Vec<&str> = v.split(':').collect();
1961719617 if f.len() < 3 || f[0] != "1" {
1961819618 return None;
@@ -20268,11 +20268,11 @@ fn decode_inter_block(
2026820268 // bails per PLANE at `block_width < 8 || block_height < 8` -- on the
2026920269 // block's own dims, never on the square prediction buffer this reader
2027020270 // allocates.
20271- if std::env::var_os("EC_MC_TRACE").is_some() {
20271+ if crate::envflags::env_flag!("EC_MC_TRACE") {
2027220272 eprintln!("EC_IB px={px} py={py} side={side} w={write_w} h={write_h}");
2027320273 }
2027420274
20275- if std::env::var_os("EC_AV1_TELL").is_some() {
20275+ if crate::envflags::env_flag!("EC_AV1_TELL") {
2027620276 eprintln!(
2027720277 "TELL mi_row={} mi_col={} label=block_entry side={side} tell={} range={}",
2027820278 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -20283,7 +20283,7 @@ fn decode_inter_block(
2028320283 // lane-comppin r3: skip_mode desync isolation -- dump ctx + the pre-read
2028420284 // MSAC tell so it can be diffed against an equivalent hook in libaom's
2028520285 // 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") {
2028720287 eprintln!(
2028820288 "EC_SKIPMODE r={r} c={c} ctx={skip_mode_ctx} skip_mode_present={skip_mode_present} tell_before={}",
2028920289 dec.debug_bitpos()
@@ -20300,7 +20300,7 @@ fn decode_inter_block(
2030020300 let comp_allowed = write_w.min(write_h) >= 8;
2030120301 let skip_mode =
2030220302 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") {
2030420304 eprintln!(
2030520305 "EC_SKIPMODE r={r} c={c} result={skip_mode} tell_after={}",
2030620306 dec.debug_bitpos()
@@ -20334,7 +20334,7 @@ fn decode_inter_block(
2033420334 // chunk). An INTRA block at that size inside an inter frame takes the
2033520335 // intra tail below, which still codes one whole-block chroma unit and one
2033620336 // `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") {
2033820338 eprintln!(
2033920339 "EC_MODE mi_row={} mi_col={} rng={} is_inter={} skip={} side={side}",
2034020340 rmi,
@@ -20363,7 +20363,7 @@ fn decode_inter_block(
2036320363 && !rect_inter_residual_supported(write_w, write_h)
2036420364 && (is_inter || (write_w == side && write_h == side))
2036520365 {
20366- if std::env::var_os("EC_RECTRES").is_some() {
20366+ if crate::envflags::env_flag!("EC_RECTRES") {
2036720367 eprintln!(
2036820368 "EC_RECTRES w={write_w} h={write_h} side={side} skip={} is_inter={} mi_row={rmi} mi_col={cmi}",
2036920369 u8::from(skip),
@@ -20374,7 +20374,7 @@ fn decode_inter_block(
2037420374 "a non-skip rectangular (HORZ/VERT/HORZ_B) strip needs rectangular residual coding",
2037520375 ));
2037620376 }
20377- if std::env::var_os("EC_AV1_TELL").is_some() {
20377+ if crate::envflags::env_flag!("EC_AV1_TELL") {
2037820378 eprintln!(
2037920379 "TELL mi_row={} mi_col={} label=post_is_inter skip_mode={skip_mode} skip={skip} is_inter={is_inter} tell={} range={}",
2038020380 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -20426,7 +20426,7 @@ fn decode_inter_block(
2042620426 uni: neighbours.left_ref1[rmi]
2042720427 .is_some_and(|r1| is_uni_comp_ref(neighbours.left_ref[rmi], r1)),
2042820428 });
20429- if std::env::var_os("EC_AV1_COMPIDX_DUMP").is_some() {
20429+ if crate::envflags::env_flag!("EC_AV1_COMPIDX_DUMP") {
2043020430 eprintln!(
2043120431 "EC_PRECOMP r={r} c={c} skip_mode={skip_mode} skip={skip} reference_select={reference_select} tell={}",
2043220432 dec.debug_bitpos()
@@ -20509,7 +20509,7 @@ fn decode_inter_block(
2050920509 force_integer_mv,
2051020510 (gm_table[(ref0 - LAST_FRAME) as usize], gm_table[(ref1 - LAST_FRAME) as usize]),
2051120511 );
20512- if std::env::var_os("EC_TRACE_MODE").is_some() {
20512+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2051320513 eprintln!(
2051420514 "EC_MODE_VAL mi_row={mi_row} mi_col={mi_col} mode={} ref0={ref0} ref1={ref1} mv0=({},{}) stack={} rng={}",
2051520515 compound_mode + 17,
@@ -20653,7 +20653,7 @@ fn decode_inter_block(
2065320653 } else {
2065420654 0
2065520655 };
20656- if std::env::var_os("EC_TRACE_MODE").is_some() {
20656+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2065720657 eprintln!(
2065820658 "EC_CGI mi_row={rmi} mi_col={cmi} ctx={group_ctx} val={comp_group_idx} rng={}",
2065920659 dec.debug_state().0
@@ -20940,7 +20940,7 @@ fn decode_inter_block(
2094020940 ref_order_hints[(ref1 - LAST_FRAME) as usize],
2094120941 );
2094220942 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") {
2094420944 eprintln!(
2094520945 "EC_CIDX mi_row={rmi} mi_col={cmi} ctx={idx_ctx} val={idx} rng={}",
2094620946 dec.debug_state().0
@@ -20961,7 +20961,7 @@ fn decode_inter_block(
2096120961 (8, 8, 1u8)
2096220962 };
2096320963 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") {
2096520965 eprintln!(
2096620966 "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={}",
2096720967 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
@@ -21601,7 +21601,7 @@ fn decode_inter_block(
2160121601 neighbours.left_ref1[rmi],
2160221602 );
2160321603 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") {
2160521605 let (mi_row, mi_col) = (rmi, cmi);
2160621606 eprintln!(
2160721607 "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(
2173921739 };
2174021740 (mv, false)
2174121741 };
21742- if std::env::var_os("EC_TRACE_MODE").is_some() {
21742+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2174321743 for (i, e) in stack.entries.iter().enumerate() {
2174421744 eprintln!(
2174521745 "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(
2176621766 let is_global_mv_block = is_globalmv && gm_model as u8 > 1 && min_bw_bh4 >= 2;
2176721767 let gm_nontrans =
2176821768 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") {
2177021770 eprintln!(
2177121771 "TELL mi_row={mi_row} mi_col={mi_col} label=post_assign_mv tell={} range={}",
2177221772 dec.debug_bitpos(), dec.debug_state().0
@@ -21845,7 +21845,7 @@ fn decode_inter_block(
2184521845 interintra_mode = Some(ii);
2184621846 }
2184721847 }
21848- if std::env::var_os("EC_AV1_TELL").is_some() {
21848+ if crate::envflags::env_flag!("EC_AV1_TELL") {
2184921849 eprintln!(
2185021850 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interintra tell={} range={}",
2185121851 dec.debug_bitpos(), dec.debug_state().0
@@ -21893,7 +21893,7 @@ fn decode_inter_block(
2189321893 // as aomdec's `EC_ISTEP2 name=motion_mode` -- an eligibility
2189421894 // mismatch is otherwise invisible (a skipped symbol prints
2189521895 // nothing).
21896- if std::env::var_os("EC_TRACE_MODE_STEP").is_some() {
21896+ if crate::envflags::env_flag!("EC_TRACE_MODE_STEP") {
2189721897 eprintln!(
2189821898 "EC_MM mi_row={mi_row} mi_col={mi_col} w={write_w} h={write_h} elig={} \
2189921899 ab={} lf={} sw={} skipmode={} ii={} gmb={} rng={}",
@@ -22025,7 +22025,7 @@ fn decode_inter_block(
2202522025 mi_rows as usize,
2202622026 ref_frame,
2202722027 );
22028- if std::env::var_os("EC_WARP_DEBUG").is_some() {
22028+ if crate::envflags::env_flag!("EC_WARP_DEBUG") {
2202922029 eprintln!(
2203022030 "EC_WARP_DEBUG findSamples mi_row={mi_row} mi_col={mi_col} bsize={side} num_proj_ref={}",
2203122031 samples.len()
@@ -22049,7 +22049,7 @@ fn decode_inter_block(
2204922049 mi_row as i32,
2205022050 mi_col as i32,
2205122051 );
22052- if std::env::var_os("EC_WARP_DEBUG").is_some() {
22052+ if crate::envflags::env_flag!("EC_WARP_DEBUG") {
2205322053 eprintln!(
2205422054 "EC_WARP_DEBUG projection mi_row={mi_row} mi_col={mi_col} num_proj_ref(final)={} mv=({},{}) params={:?}",
2205522055 samples.len(), mv.0, mv.1, warp_params
@@ -22070,7 +22070,7 @@ fn decode_inter_block(
2207022070 // motion_mode vs 2-symbol obmc) and the range after -- the
2207122071 // two give the same value with a different narrowing (class
2207222072 // 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") {
2207422074 eprintln!(
2207522075 "EC_MM2 mi_row={mi_row} mi_col={mi_col} row={bsize_idx} warp_elig={} \
2207622076 scaled={} fimv={} obmc={} warped={} rng={}",
@@ -22106,7 +22106,7 @@ fn decode_inter_block(
2210622106 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));
2210722107 }
2210822108 }
22109- if std::env::var_os("EC_AV1_TELL").is_some() {
22109+ if crate::envflags::env_flag!("EC_AV1_TELL") {
2211022110 eprintln!(
2211122111 "TELL mi_row={mi_row} mi_col={mi_col} label=post_motion_mode eligible={} tell={} range={}",
2211222112 motion_mode_eligible as u8, dec.debug_bitpos(), dec.debug_state().0
@@ -22149,13 +22149,13 @@ fn decode_inter_block(
2214922149 );
2215022150 block_filter = resolved_filter;
2215122151 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") {
2215322153 eprintln!(
2215422154 "TELL mi_row={mi_row} mi_col={mi_col} label=post_interp_filter tell={} range={}",
2215522155 dec.debug_bitpos(), dec.debug_state().0
2215622156 );
2215722157 }
22158- if std::env::var_os("EC_AV1_TRACE").is_some() {
22158+ if crate::envflags::env_flag!("EC_AV1_TRACE") {
2215922159 eprintln!(
2216022160 "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={}",
2216122161 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(
2290822908 .filter(|_| write_w.min(write_h) == 4 && write_w.max(write_h) == 16)
2290922909 .map(|s| (s.horz, s.has_chroma));
2291022910 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") {
2291222912 let (idx, hc, prev_inter) = match strip_chroma {
2291322913 Some(s) => (
2291422914 if s.horz { rmi - s.pair_mi.0 } else { cmi - s.pair_mi.1 },
@@ -22989,7 +22989,7 @@ fn decode_inter_block(
2298922989 return Ok(());
2299022990 }
2299122991 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") {
2299322993 eprintln!(
2299422994 "TRACE iis px={px} py={py} side={side} w={write_w} h={write_h} sg={} mode={mode} skip={skip}",
2299522995 size_group_wh(write_w, write_h)
@@ -23442,7 +23442,7 @@ fn decode_inter_block(
2344223442 // equivalent post-content point (added at the matching call site)
2344323443 // narrows the ladder to this block's own tail instead of the next
2344423444 // block's partition read.
23445- if std::env::var_os("EC_AV1_TELL").is_some() {
23445+ if crate::envflags::env_flag!("EC_AV1_TELL") {
2344623446 eprintln!(
2344723447 "TELL mi_row={} mi_col={} label=block_end tell={} range={}",
2344823448 rmi, cmi, dec.debug_bitpos(), dec.debug_state().0
@@ -23778,7 +23778,7 @@ fn decode_inter_sub8_split4(
2377823778 );
2377923779 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
2378023780 if !is_inter {
23781- if std::env::var_os("EC_SUB8INTRA").is_some() {
23781+ if crate::envflags::env_flag!("EC_SUB8INTRA") {
2378223782 eprintln!(
2378323783 "EC_SUB8INTRA shape=4x4 sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
2378423784 i == 3,
@@ -23824,7 +23824,7 @@ fn decode_inter_sub8_split4(
2382423824 // Same print point as the oracle's `EC_MODE` (entry of
2382523825 // `read_inter_block_mode_info`, i.e. after skip / is_inter), so the
2382623826 // 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") {
2382823828 eprintln!(
2382923829 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
2383023830 dec.debug_state().0
@@ -23921,7 +23921,7 @@ fn decode_inter_sub8_split4(
2392123921 };
2392223922 // Same print point as the oracle's `EC_MODE_MV` (right after
2392323923 // `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") {
2392523925 eprintln!(
2392623926 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
2392723927 mv.0,
@@ -23946,7 +23946,7 @@ fn decode_inter_sub8_split4(
2394623946 } else {
2394723947 [3, 3]
2394823948 };
23949- if std::env::var_os("EC_AV1_IFDBG").is_some() {
23949+ if crate::envflags::env_flag!("EC_AV1_IFDBG") {
2395023950 eprintln!(
2395123951 "IFDBG4 mi=({rmi},{cmi}) ref={ref_frame} above_ref={} above_ref1={:?} \
2395223952 above_filt={:?} left_ref={} left_ref1={:?} left_filt={:?}",
@@ -23976,7 +23976,7 @@ fn decode_inter_sub8_split4(
2397623976 left_filter_ctx,
2397723977 false,
2397823978 );
23979- if std::env::var_os("EC_TRACE_MODE").is_some() {
23979+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2398023980 eprintln!(
2398123981 "EC_MODE_VAL4 mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
2398223982 ref0={ref_frame} mv0=({},{}) stack={} rng={}",
@@ -24226,7 +24226,7 @@ fn decode_intra_sub8_leaf(
2422624226 .mode_above_mi(lmi.0, lmi.1)
2422724227 .unwrap_or(above_mode);
2422824228 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");
2423024230 // `size_group_lookup[BLOCK_8X4] == size_group_lookup[BLOCK_4X8] == 0`
2423124231 // (libaom common_data.h:61).
2423224232 let mode = dec.symbol(&mut cdfs.y_mode[0]);
@@ -24734,7 +24734,7 @@ fn decode_inter_sub8_rect2(
2473424734 );
2473524735 let is_inter = dec.symbol(&mut cdfs.intra_inter[ii_ctx]) == 1;
2473624736 if !is_inter {
24737- if std::env::var_os("EC_SUB8INTRA").is_some() {
24737+ if crate::envflags::env_flag!("EC_SUB8INTRA") {
2473824738 eprintln!(
2473924739 "EC_SUB8INTRA shape={}x{} sub={i} has_chroma={} skip={skip} mi={rmi},{cmi} tx_select={}",
2474024740 bw,
@@ -24773,7 +24773,7 @@ fn decode_inter_sub8_rect2(
2477324773 }
2477424774 continue;
2477524775 }
24776- if std::env::var_os("EC_TRACE_MODE").is_some() {
24776+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2477724777 eprintln!(
2477824778 "EC_MODE mi_row={rmi} mi_col={cmi} rng={}",
2477924779 dec.debug_state().0
@@ -24868,7 +24868,7 @@ fn decode_inter_sub8_rect2(
2486824868 };
2486924869 (mv, false)
2487024870 };
24871- if std::env::var_os("EC_TRACE_MODE").is_some() {
24871+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2487224872 eprintln!(
2487324873 "EC_MODE_MV mi_row={rmi} mi_col={cmi} mv0=({},{}) rng={}",
2487424874 mv.0,
@@ -24935,7 +24935,7 @@ fn decode_inter_sub8_rect2(
2493524935 leaves.push((0, 0, bw, bh));
2493624936 set_txfm_ctxs(neighbours, lmi, bw.max(bh), w_mi, h_mi, skip);
2493724937 }
24938- if std::env::var_os("EC_TRACE_MODE").is_some() {
24938+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2493924939 eprintln!(
2494024940 "EC_MODE_VALR mi_row={rmi} mi_col={cmi} newmv={is_new_mv} globalmv={is_globalmv} \
2494124941 ref0={ref_frame} mv0=({},{}) stack={} leaves={} rng={}",
@@ -25406,7 +25406,7 @@ fn decode_inter_block8(
2540625406 // lane-inter8 r1: mirrors the oracle's `EC_MODE` (instrument rung 4,
2540725407 // `read_inter_block_mode_info`) so an 8x8 leaf's mode-info range ladder
2540825408 // 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") {
2541025410 eprintln!(
2541125411 "EC_MODE mi_row={} mi_col={} rng={}",
2541225412 leaf_mi.0,
@@ -25519,7 +25519,7 @@ fn decode_inter_block8(
2551925519 comp_stack.ref_mv_ctx,
2552025520 )
2552125521 };
25522- if std::env::var_os("EC_TRACE_MODE").is_some() {
25522+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2552325523 eprintln!(
2552425524 "EC_LEAFMODE mi_row={} mi_col={} cmode={} stack={} newmv_ctx={} refmv_ctx={} rng={}",
2552525525 leaf_mi.0,
@@ -25548,7 +25548,7 @@ fn decode_inter_block8(
2554825548 // lane-inter8 r3: byte-format-identical to the oracle's
2554925549 // rung-4 `EC_MODE_VAL`, so the leaf's mode+mv VALUE ladder
2555025550 // 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") {
2555225552 eprintln!(
2555325553 "EC_MODE_VAL mi_row={} mi_col={} mode={} ref0={} ref1={} mv0=({},{}) rng={}",
2555425554 leaf_mi.0,
@@ -25643,7 +25643,7 @@ fn decode_inter_block8(
2564325643 (8, 8, 1u8)
2564425644 };
2564525645 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") {
2564725647 eprintln!(
2564825648 "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={}",
2564925649 mv0.0, mv0.1, mv1.0, mv1.1, dec.debug_bitpos()
@@ -26138,7 +26138,7 @@ fn decode_inter_block8(
2613826138 // lane-interp3 r2: same per-entry EC_STACK ladder
2613926139 // [`decode_inter_block`]'s single-ref arm prints, so this leaf's stack
2614026140 // 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") {
2614226142 for (i, e) in stack.entries.iter().enumerate() {
2614326143 eprintln!(
2614426144 "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(
2637526375 false,
2637626376 );
2637726377 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") {
2637926379 eprintln!(
2638026380 "EC_MODE_VAL8 mi_row={} mi_col={} newmv={is_new_mv} globalmv={is_globalmv} ref0={ref_frame} mv0=({},{}) stack={} rng={}",
2638126381 leaf_mi.0,
@@ -26397,7 +26397,7 @@ fn decode_inter_block8(
2639726397 AFFINE_GM_HITS.with(|c| c.set(c.get() + 1));
2639826398 }
2639926399 }
26400- if std::env::var_os("EC_TRACE_MODE").is_some() {
26400+ if crate::envflags::env_flag!("EC_TRACE_MODE") {
2640126401 eprintln!(
2640226402 "EC_WARP8 mi_row={} mi_col={} warp={} globalblk={is_global_mv_block}",
2640326403 leaf_mi.0,
@@ -26685,7 +26685,7 @@ fn decode_inter_block8(
2668526685 // but `DC_PRED` was refused here, which is what blocked the low-cq
2668626686 // CDEF arms and the 10-bit gates.
2668726687 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") {
2668926689 eprintln!(
2669026690 "EC_ISTEP8 mi_row={} mi_col={} name=modes y={mode} uv={uv_mode} fi_enabled={} rng={}",
2669126691 leaf_mi.0,
@@ -26758,7 +26758,7 @@ fn decode_inter_block8(
2675826758 // prints `use_filter_intra` for an intra block inside an INTER frame
2675926759 // and nothing else, so this leaf needs the same two lines for a
2676026760 // 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");
2676226762 if mode == DC_PRED
2676326763 && ENABLE_FILTER_INTRA_INTER.with(std::cell::Cell::get)
2676426764 && let Some(class) = filter_intra_size_class(SIDE)
@@ -27482,7 +27482,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2748227482 // lane-comppin r9: tile-entry range, the earliest point comparable
2748327483 // against aomdec's own `r->ec.rng` right after `aom_reader_init` -- the
2748427484 // 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") {
2748627486 eprintln!(
2748727487 "TELL label=tile_init tell={} range={}",
2748827488 dec.debug_bitpos(),
@@ -27927,9 +27927,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2792727927 let part64 = match (has_cols, has_rows) {
2792827928 (true, true) => {
2792927929 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); }
2793127931 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") {
2793327933 eprintln!(
2793427934 "TRACE partition_w64 mi=({},{}) ctx={sb_ctx} value={p} pre_rng={pre_rng}",
2793527935 sb_r * SB_MI,
@@ -27942,7 +27942,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2794227942 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
2794327943 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
2794427944 // (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); }
2794627946 if bump_edge32_bit(
2794727947 4,
2794827948 dec.symbol_fixed(&gather(&cdfs.partition_w64[sb_ctx], VERT_ALIKE)),
@@ -28245,7 +28245,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2824528245 has_half(r32 * BLOCK_MI, BLOCK_MI, mi_rows),
2824628246 );
2824728247 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") {
2824928249 eprintln!(
2825028250 "TRACE part32_pre mi=({},{}) rng={}",
2825128251 r32 * BLOCK_MI,
@@ -28253,9 +28253,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2825328253 dec.debug_state().0
2825428254 );
2825528255 }
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); }
2825728257 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") {
2825928259 eprintln!(
2826028260 "TRACE partition_w32 mi=({},{}) ctx={ctx32} value={p}",
2826128261 r32 * BLOCK_MI,
@@ -28269,7 +28269,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2826928269 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
2827028270 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
2827128271 // (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); }
2827328273 if {
2827428274 let b = dec.symbol_fixed(&gather(&cdfs.partition_w32[ctx32], VERT_ALIKE));
2827528275 bump_edge32(b.min(1) as usize);
@@ -28371,9 +28371,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2837128371 // inter leaves through the very same loop the
2837228372 // straddling case has always used.
2837328373 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); }
2837528375 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") {
2837728377 let (rng, _) = dec.debug_state();
2837828378 eprintln!(
2837928379 "TRACE partition_w16 mi=({},{}) ctx={ctx16} value={p} rng={rng}",
@@ -28395,7 +28395,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2839528395 // lane-golomb r1 (class `parsed-then-discarded`): the gathered
2839628396 // bit IS the partition -- 0 means PARTITION_HORZ, only 1 means SPLIT
2839728397 // (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); }
2839928399 if dec.symbol_fixed(&gather(&cdfs.partition_w16[ctx16], VERT_ALIKE)) == 1 {
2840028400 PARTITION_SPLIT
2840128401 } else {
@@ -28779,7 +28779,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2877928779 for (mr, mc) in leaf_positions {
2878028780 let leaf_mi = (mr as usize, mc as usize);
2878128781 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); }
2878328783 let part8 = dec.symbol(&mut cdfs.partition_w8[leaf_ctx]);
2878428784 if part8 == PARTITION_SPLIT {
2878528785 // lane-intersub8: four BLOCK_4X4 inter
@@ -29901,9 +29901,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2990129901 // in reconstruction (this dump) vs is introduced by the loop filter
2990229902 // (EC_AV1_DECODE_ORDER_DUMP's post-filter dump).
2990329903 // Decode-order frame marker for the EC_OBMC / EC_TRACE_MODE ladders.
29904- if std::env::var_os("EC_OBMC").is_some()
29905- || std::env::var_os("EC_TRACE_MODE").is_some()
29906- || std::env::var_os("EC_PRED").is_some()
29904+ if crate::envflags::env_flag!("EC_OBMC")
29905+ || crate::envflags::env_flag!("EC_TRACE_MODE")
29906+ || crate::envflags::env_flag!("EC_PRED")
2990729907 {
2990829908 eprintln!(
2990929909 "EC_PICT idx={}",
@@ -29911,7 +29911,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
2991129911 );
2991229912 }
2991329913 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") {
2991529915 use std::io::Write;
2991629916 let idx = PREFILT_PICTURE_IDX.fetch_add(1, std::sync::atomic::Ordering::SeqCst);
2991729917 if let Ok(mut f) = std::fs::File::create(format!("{path}.f{idx}")) {
@@ -30631,8 +30631,8 @@ mod tests {
3063130631 .is_ok_and(|s| s.success());
3063230632 assert!(
3063330633 present
30634- || (std::env::var_os("EC_AV1_REQUIRE_FFMPEG").is_none()
30635- && std::env::var_os("EC_AV1_REQUIRE_AOMENC").is_none()),
30634+ || (!crate::envflags::env_flag!("EC_AV1_REQUIRE_FFMPEG")
30635+ && !crate::envflags::env_flag!("EC_AV1_REQUIRE_AOMENC")),
3063630636 "EC_AV1_REQUIRE_FFMPEG/EC_AV1_REQUIRE_AOMENC is set but no working ffmpeg on PATH"
3063730637 );
3063830638 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;
1919 pub mod decode;
2020 pub mod encode;
2121 pub mod encoder;
22+mod envflags;
2223 mod film_grain;
2324 pub mod frame;
2425 mod gate_coverage;
crates/ec-av1/src/mc.rsmodified+2 -2
@@ -375,7 +375,7 @@ pub fn predict_with_filters_kern(
375375 let xfrac = x_q4.rem_euclid(16) as usize;
376376 let y0 = y_q4.div_euclid(16);
377377 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 {
379379 eprintln!(
380380 "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}"
381381 );
@@ -774,7 +774,7 @@ pub fn predict_compound_intermediate_kern(
774774
775775 let y0 = y_q4.div_euclid(16);
776776 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") {
778778 eprintln!("EC_MC_COMP x_q4={x_q4} y_q4={y_q4} w={block_w} h={block_h} hk={h_kind:?} vk={v_kind:?}");
779779 }
780780