forge
Explore
Log in

Don't you dare go Hollow

Make the gate hit-counters thread-local so a delta is the test's own

Browse files at this commit

5c21ffafc526a37c71923b9fed85fcda8bed90cfAhmet Kaan GümüşParent: 0169a4e
  • fix
    • make the gate hit-counters thread-local so a delta is the test's own
Show full message
fix(av1): make the gate hit-counters thread-local so a delta is the test's own

The firing counters were process-global atomics and cargo runs tests in
parallel threads, so a gate's `hits() > before` delta could be satisfied by a
SIBLING gate's increments -- the gate would pass without its own feature ever
firing, which is the vacuous-gate failure this batch has already fixed twice by
other means. Eleven gates took that delta without holding the counter lock.

Measured before the fix: the free-partition gate reported rect_partition_hits=9
and partab_hits=2 alone, and 18 and 4 inside the full suite. Same stream, same
decode, double the count -- the difference was other tests.

Serializing those eleven on the existing lock fixed the correctness and took
the suite from 67 s to over 600 s, because it serializes every slow aomenc gate
against every other. Thread-local counters give the same isolation with no
serialization at all: the decoder runs single-threaded, so each test thread's
counts are inherently its own, and the added locks come back out.

After: the same gate reports 9 and 2 in both contexts. Full lib suite 232
passed / 0 failed in 67 s.
crates/ec-av1/src/decode.rsmodified+168 -92
@@ -56,18 +56,24 @@ const BLOCK_MI: u32 = 8;
56 /// tests read (before/after, not the absolute value) to prove a stream56 /// tests read (before/after, not the absolute value) to prove a stream
57 /// actually exercised the filter-intra predictor rather than silently57 /// actually exercised the filter-intra predictor rather than silently
58 /// skipping it.58 /// skipping it.
59-static FILTER_INTRA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);59+thread_local! {
60+ static FILTER_INTRA_HITS: std::cell::Cell<usize> =
61+ const { std::cell::Cell::new(0) };
62+}
60 63
61 /// Current value of [`FILTER_INTRA_HITS`].64 /// Current value of [`FILTER_INTRA_HITS`].
62 pub(crate) fn filter_intra_hits() -> usize {65 pub(crate) fn filter_intra_hits() -> usize {
63- FILTER_INTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)66+ FILTER_INTRA_HITS.with(|c| c.get())
64 }67 }
65 68
66 /// How many 4-pixel deblocking edge groups [`edge_params`] has actually69 /// How many 4-pixel deblocking edge groups [`edge_params`] has actually
67 /// selected for filtering, across every call in the process -- the same70 /// selected for filtering, across every call in the process -- the same
68 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream71 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
69 /// exercised `apply_deblock` rather than every edge landing on level 0.72 /// exercised `apply_deblock` rather than every edge landing on level 0.
70-static DEBLOCK_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);73+thread_local! {
74+ static DEBLOCK_HITS: std::cell::Cell<usize> =
75+ const { std::cell::Cell::new(0) };
76+}
71 /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`,77 /// lane-comppin r4: decode-order picture counter for `EC_AV1_PREFILT_DUMP`,
72 /// mirroring stream.rs's `pictures_decoded` so the two dumps index78 /// mirroring stream.rs's `pictures_decoded` so the two dumps index
73 /// identically against aomdec's own `ec_frame_idx` in decodeframe.c.79 /// identically against aomdec's own `ec_frame_idx` in decodeframe.c.
@@ -76,7 +82,7 @@ static PREFILT_PICTURE_IDX: std::sync::atomic::AtomicUsize =
76 82
77 /// Current value of [`DEBLOCK_HITS`].83 /// Current value of [`DEBLOCK_HITS`].
78 pub(crate) fn deblock_hits() -> usize {84 pub(crate) fn deblock_hits() -> usize {
79- DEBLOCK_HITS.load(std::sync::atomic::Ordering::Relaxed)85+ DEBLOCK_HITS.with(|c| c.get())
80 }86 }
81 87
82 /// How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than88 /// How many [`read_tx_size`] reads resolved a `tx_depth` strictly less than
@@ -85,11 +91,14 @@ pub(crate) fn deblock_hits() -> usize {
85 /// actually exercised a *split* transform under `TxMode::Select` rather than91 /// actually exercised a *split* transform under `TxMode::Select` rather than
86 /// every block coincidentally resolving `depth=0` (indistinguishable from92 /// every block coincidentally resolving `depth=0` (indistinguishable from
87 /// `TxMode::Largest` pixel-wise).93 /// `TxMode::Largest` pixel-wise).
88-static TX_DEPTH_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);94+thread_local! {
95+ static TX_DEPTH_HITS: std::cell::Cell<usize> =
96+ const { std::cell::Cell::new(0) };
97+}
89 98
90 /// Current value of [`TX_DEPTH_HITS`].99 /// Current value of [`TX_DEPTH_HITS`].
91 pub(crate) fn tx_depth_hits() -> usize {100 pub(crate) fn tx_depth_hits() -> usize {
92- TX_DEPTH_HITS.load(std::sync::atomic::Ordering::Relaxed)101+ TX_DEPTH_HITS.with(|c| c.get())
93 }102 }
94 103
95 /// How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`104 /// How many [`read_coeffs`] reads resolved a `tx_type` outside `TX_CLASS_2D`
@@ -98,24 +107,33 @@ pub(crate) fn tx_depth_hits() -> usize {
98 /// [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split107 /// [`TX_DEPTH_HITS`], proving a stream actually exercised the class-split
99 /// `eob_pt`/1D-neighbour context path rather than every block coincidentally108 /// `eob_pt`/1D-neighbour context path rather than every block coincidentally
100 /// landing on `DCT_DCT`.109 /// landing on `DCT_DCT`.
101-static TX_CLASS1_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);110+thread_local! {
111+ static TX_CLASS1_HITS: std::cell::Cell<usize> =
112+ const { std::cell::Cell::new(0) };
113+}
102 114
103 /// How many `uv_mode` reads resolved to a directional chroma mode (neither115 /// How many `uv_mode` reads resolved to a directional chroma mode (neither
104 /// `DC_PRED` nor `UV_CFL_PRED`), across every call in the process -- the same116 /// `DC_PRED` nor `UV_CFL_PRED`), across every call in the process -- the same
105 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream117 /// before/after counter pattern as [`FILTER_INTRA_HITS`], proving a stream
106 /// actually exercised chroma's own directional predictor.118 /// actually exercised chroma's own directional predictor.
107-static DIRECTIONAL_UV_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);119+thread_local! {
120+ static DIRECTIONAL_UV_HITS: std::cell::Cell<usize> =
121+ const { std::cell::Cell::new(0) };
122+}
108 123
109 /// Current value of [`DIRECTIONAL_UV_HITS`].124 /// Current value of [`DIRECTIONAL_UV_HITS`].
110 pub(crate) fn directional_uv_hits() -> usize {125 pub(crate) fn directional_uv_hits() -> usize {
111- DIRECTIONAL_UV_HITS.load(std::sync::atomic::Ordering::Relaxed)126+ DIRECTIONAL_UV_HITS.with(|c| c.get())
112 }127 }
113 128
114 /// How many `angle_delta`/`angle_delta_uv` symbols this decoder has read as129 /// How many `angle_delta`/`angle_delta_uv` symbols this decoder has read as
115 /// something other than [`ANGLE_DELTA_ZERO`], across every call in the130 /// something other than [`ANGLE_DELTA_ZERO`], across every call in the
116 /// process -- the same before/after counter pattern as [`FILTER_INTRA_HITS`],131 /// process -- the same before/after counter pattern as [`FILTER_INTRA_HITS`],
117 /// proving a stream actually exercised a nonzero angle delta.132 /// proving a stream actually exercised a nonzero angle delta.
118-static ANGLE_DELTA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);133+thread_local! {
134+ static ANGLE_DELTA_HITS: std::cell::Cell<usize> =
135+ const { std::cell::Cell::new(0) };
136+}
119 137
120 /// How many [`read_single_ref`] reads resolved to a reference other than138 /// How many [`read_single_ref`] reads resolved to a reference other than
121 /// `LAST_FRAME`, across every call in the process -- the same before/after139 /// `LAST_FRAME`, across every call in the process -- the same before/after
@@ -123,11 +141,14 @@ static ANGLE_DELTA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::Ato
123 /// exercised a non-`LAST_FRAME` reference (`GOLDEN_FRAME`, this decoder's141 /// exercised a non-`LAST_FRAME` reference (`GOLDEN_FRAME`, this decoder's
124 /// only other supported one so far) rather than every block coincidentally142 /// only other supported one so far) rather than every block coincidentally
125 /// resolving `LAST_FRAME`.143 /// resolving `LAST_FRAME`.
126-static NON_LAST_REF_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);144+thread_local! {
145+ static NON_LAST_REF_HITS: std::cell::Cell<usize> =
146+ const { std::cell::Cell::new(0) };
147+}
127 148
128 /// Current value of [`NON_LAST_REF_HITS`].149 /// Current value of [`NON_LAST_REF_HITS`].
129 pub(crate) fn non_last_ref_hits() -> usize {150 pub(crate) fn non_last_ref_hits() -> usize {
130- NON_LAST_REF_HITS.load(std::sync::atomic::Ordering::Relaxed)151+ NON_LAST_REF_HITS.with(|c| c.get())
131 }152 }
132 153
133 /// Per-reference [`NON_LAST_REF_HITS`] breakdown (lane-av1refs): one counter154 /// Per-reference [`NON_LAST_REF_HITS`] breakdown (lane-av1refs): one counter
@@ -136,51 +157,80 @@ pub(crate) fn non_last_ref_hits() -> usize {
136 /// can prove THAT reference fired rather than any non-`LAST_FRAME` one --157 /// can prove THAT reference fired rather than any non-`LAST_FRAME` one --
137 /// `NON_LAST_REF_HITS` alone cannot tell a `LAST2_FRAME` gate from a158 /// `NON_LAST_REF_HITS` alone cannot tell a `LAST2_FRAME` gate from a
138 /// `GOLDEN_FRAME` draw it did not ask for.159 /// `GOLDEN_FRAME` draw it did not ask for.
139-static LAST2_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);160+thread_local! {
140-static LAST3_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);161+ static LAST2_HITS: std::cell::Cell<usize> =
141-static GOLDEN_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);162+ const { std::cell::Cell::new(0) };
142-static BWDREF_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);163+}
143-static ALTREF2_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);164+thread_local! {
144-static ALTREF_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);165+ static LAST3_HITS: std::cell::Cell<usize> =
166+ const { std::cell::Cell::new(0) };
167+}
168+thread_local! {
169+ static GOLDEN_HITS: std::cell::Cell<usize> =
170+ const { std::cell::Cell::new(0) };
171+}
172+thread_local! {
173+ static BWDREF_HITS: std::cell::Cell<usize> =
174+ const { std::cell::Cell::new(0) };
175+}
176+thread_local! {
177+ static ALTREF2_HITS: std::cell::Cell<usize> =
178+ const { std::cell::Cell::new(0) };
179+}
180+thread_local! {
181+ static ALTREF_HITS: std::cell::Cell<usize> =
182+ const { std::cell::Cell::new(0) };
183+}
145 184
146 /// How many [`read_comp_mode`] reads resolved `COMPOUND_REFERENCE` (lane-av1comp)185 /// How many [`read_comp_mode`] reads resolved `COMPOUND_REFERENCE` (lane-av1comp)
147 /// -- proves a `reference_select` stream actually reached a block that picked186 /// -- proves a `reference_select` stream actually reached a block that picked
148 /// compound, not just that the header bit was set. Every such block is187 /// compound, not just that the header bit was set. Every such block is
149 /// refused after this fires ([`decode_inter_block`]/[`decode_inter_block8`]),188 /// refused after this fires ([`decode_inter_block`]/[`decode_inter_block8`]),
150 /// so this only ever counts attempted reads, never a completed decode.189 /// so this only ever counts attempted reads, never a completed decode.
151-static COMP_MODE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);190+thread_local! {
191+ static COMP_MODE_HITS: std::cell::Cell<usize> =
192+ const { std::cell::Cell::new(0) };
193+}
152 194
153 /// Current value of [`COMP_MODE_HITS`].195 /// Current value of [`COMP_MODE_HITS`].
154 pub(crate) fn comp_mode_hits() -> usize {196 pub(crate) fn comp_mode_hits() -> usize {
155- COMP_MODE_HITS.load(std::sync::atomic::Ordering::Relaxed)197+ COMP_MODE_HITS.with(|c| c.get())
156 }198 }
157 199
158 /// How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) --200 /// How many blocks decoded `skip_mode == 1` (lane-av1comp round 14) --
159 /// proves a real `skip_mode_present` stream actually reached a block that201 /// proves a real `skip_mode_present` stream actually reached a block that
160 /// picked it, not just that the frame header bit was set.202 /// picked it, not just that the frame header bit was set.
161-static SKIP_MODE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);203+thread_local! {
204+ static SKIP_MODE_HITS: std::cell::Cell<usize> =
205+ const { std::cell::Cell::new(0) };
206+}
162 207
163 /// Current value of [`SKIP_MODE_HITS`].208 /// Current value of [`SKIP_MODE_HITS`].
164 pub(crate) fn skip_mode_hits() -> usize {209 pub(crate) fn skip_mode_hits() -> usize {
165- SKIP_MODE_HITS.load(std::sync::atomic::Ordering::Relaxed)210+ SKIP_MODE_HITS.with(|c| c.get())
166 }211 }
167 212
168 /// lane-motionmode: how many blocks actually decoded `obmc_selected == true`213 /// lane-motionmode: how many blocks actually decoded `obmc_selected == true`
169 /// (as opposed to just reaching an eligible `read_motion_mode` symbol read)214 /// (as opposed to just reaching an eligible `read_motion_mode` symbol read)
170 /// -- the gate's own proof that a real aomenc `--enable-obmc=1` stream215 /// -- the gate's own proof that a real aomenc `--enable-obmc=1` stream
171 /// reached [`obmc_blend`], not just the header bit.216 /// reached [`obmc_blend`], not just the header bit.
172-static OBMC_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);217+thread_local! {
218+ static OBMC_HITS: std::cell::Cell<usize> =
219+ const { std::cell::Cell::new(0) };
220+}
173 221
174 /// Current value of [`OBMC_HITS`].222 /// Current value of [`OBMC_HITS`].
175 pub(crate) fn obmc_hits() -> usize {223 pub(crate) fn obmc_hits() -> usize {
176- OBMC_HITS.load(std::sync::atomic::Ordering::Relaxed)224+ OBMC_HITS.with(|c| c.get())
177 }225 }
178 226
179 /// lane-motionmode round 3: same proof as [`OBMC_HITS`], narrowed to227 /// lane-motionmode round 3: same proof as [`OBMC_HITS`], narrowed to
180 /// `decode_inter_block8`'s own 8x8-leaf `read_motion_mode` -- a subset of228 /// `decode_inter_block8`'s own 8x8-leaf `read_motion_mode` -- a subset of
181 /// [`OBMC_HITS`] (both fire together on an 8x8 hit), lets the gate tell an229 /// [`OBMC_HITS`] (both fire together on an 8x8 hit), lets the gate tell an
182 /// 8x8-leaf OBMC block apart from a 16x16+ one.230 /// 8x8-leaf OBMC block apart from a 16x16+ one.
183-static OBMC_HITS_8: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);231+thread_local! {
232+ static OBMC_HITS_8: std::cell::Cell<usize> = const { std::cell::Cell::new(0) };
233+}
184 234
185 /// lane-warp round 1: how many blocks resolved `motion_mode_allowed` to235 /// lane-warp round 1: how many blocks resolved `motion_mode_allowed` to
186 /// `WARPED_CAUSAL`-eligible (3-symbol read, `num_proj_ref >= 1` under236 /// `WARPED_CAUSAL`-eligible (3-symbol read, `num_proj_ref >= 1` under
@@ -188,21 +238,27 @@ static OBMC_HITS_8: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUs
188 /// -- the gate's proof that a fixture really exercises the alphabet this238 /// -- the gate's proof that a fixture really exercises the alphabet this
189 /// round changed, even though the block itself still refuses (warp239 /// round changed, even though the block itself still refuses (warp
190 /// estimation/filter not ported).240 /// estimation/filter not ported).
191-static WARP_SELECTED_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);241+thread_local! {
242+ static WARP_SELECTED_HITS: std::cell::Cell<usize> =
243+ const { std::cell::Cell::new(0) };
244+}
192 245
193 /// Current value of [`WARP_SELECTED_HITS`].246 /// Current value of [`WARP_SELECTED_HITS`].
194 pub(crate) fn warp_selected_hits() -> usize {247 pub(crate) fn warp_selected_hits() -> usize {
195- WARP_SELECTED_HITS.load(std::sync::atomic::Ordering::Relaxed)248+ WARP_SELECTED_HITS.with(|c| c.get())
196 }249 }
197 250
198 /// How many blocks decoded `interintra == 1` with the non-wedge blended251 /// How many blocks decoded `interintra == 1` with the non-wedge blended
199 /// prediction applied (lane-interintra r1) -- the gate's proof that a252 /// prediction applied (lane-interintra r1) -- the gate's proof that a
200 /// stream actually exercised interintra.253 /// stream actually exercised interintra.
201-static INTERINTRA_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);254+thread_local! {
255+ static INTERINTRA_HITS: std::cell::Cell<usize> =
256+ const { std::cell::Cell::new(0) };
257+}
202 258
203 /// Current value of [`INTERINTRA_HITS`].259 /// Current value of [`INTERINTRA_HITS`].
204 pub(crate) fn interintra_hits() -> usize {260 pub(crate) fn interintra_hits() -> usize {
205- INTERINTRA_HITS.load(std::sync::atomic::Ordering::Relaxed)261+ INTERINTRA_HITS.with(|c| c.get())
206 }262 }
207 263
208 /// How many blocks decoded `comp_group_idx == 1` (masked COMPOUND_REFERENCE,264 /// How many blocks decoded `comp_group_idx == 1` (masked COMPOUND_REFERENCE,
@@ -210,39 +266,47 @@ pub(crate) fn interintra_hits() -> usize {
210 /// `mask_type` consumed entropy-exact -- lane-maskcomp r1's proof that a266 /// `mask_type` consumed entropy-exact -- lane-maskcomp r1's proof that a
211 /// gate fixture actually exercises this alphabet, even though the block267 /// gate fixture actually exercises this alphabet, even though the block
212 /// still refuses (the mask blend itself is unported).268 /// still refuses (the mask blend itself is unported).
213-static MASKED_COMPOUND_HITS: std::sync::atomic::AtomicUsize =269+thread_local! {
214- std::sync::atomic::AtomicUsize::new(0);270+ static MASKED_COMPOUND_HITS: std::cell::Cell<usize> =
271+ const { std::cell::Cell::new(0) };
272+}
215 273
216 /// Current value of [`MASKED_COMPOUND_HITS`].274 /// Current value of [`MASKED_COMPOUND_HITS`].
217 pub(crate) fn masked_compound_hits() -> usize {275 pub(crate) fn masked_compound_hits() -> usize {
218- MASKED_COMPOUND_HITS.load(std::sync::atomic::Ordering::Relaxed)276+ MASKED_COMPOUND_HITS.with(|c| c.get())
219 }277 }
220 278
221 /// How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==279 /// How many blocks decoded a real `COMPOUND_WEDGE` block (`comp_group_idx ==
222 /// 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture280 /// 1`, `compound_type == 0`) -- lane-wedge r3's proof a gate fixture
223 /// actually exercised the wedge blend, not just the DIFFWTD half of281 /// actually exercised the wedge blend, not just the DIFFWTD half of
224 /// `MASKED_COMPOUND_HITS`.282 /// `MASKED_COMPOUND_HITS`.
225-static WEDGE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);283+thread_local! {
284+ static WEDGE_HITS: std::cell::Cell<usize> =
285+ const { std::cell::Cell::new(0) };
286+}
226 287
227 /// Current value of [`WEDGE_HITS`].288 /// Current value of [`WEDGE_HITS`].
228 pub(crate) fn wedge_hits() -> usize {289 pub(crate) fn wedge_hits() -> usize {
229- WEDGE_HITS.load(std::sync::atomic::Ordering::Relaxed)290+ WEDGE_HITS.with(|c| c.get())
230 }291 }
231 292
232 /// How many blocks decoded a real wedge-INTERINTRA block293 /// How many blocks decoded a real wedge-INTERINTRA block
233 /// (`interintra == 1 && use_wedge_interintra == 1`) -- lane-wii r2's proof294 /// (`interintra == 1 && use_wedge_interintra == 1`) -- lane-wii r2's proof
234 /// a gate fixture exercised the wedge blend (fixed sign 0), not just the295 /// a gate fixture exercised the wedge blend (fixed sign 0), not just the
235 /// smooth arm counted by `INTERINTRA_HITS`.296 /// smooth arm counted by `INTERINTRA_HITS`.
236-static WII_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);297+thread_local! {
298+ static WII_HITS: std::cell::Cell<usize> =
299+ const { std::cell::Cell::new(0) };
300+}
237 301
238 /// Current value of [`WII_HITS`].302 /// Current value of [`WII_HITS`].
239 pub(crate) fn wii_hits() -> usize {303 pub(crate) fn wii_hits() -> usize {
240- WII_HITS.load(std::sync::atomic::Ordering::Relaxed)304+ WII_HITS.with(|c| c.get())
241 }305 }
242 306
243 /// Current value of [`OBMC_HITS_8`].307 /// Current value of [`OBMC_HITS_8`].
244 pub(crate) fn obmc_hits_8() -> usize {308 pub(crate) fn obmc_hits_8() -> usize {
245- OBMC_HITS_8.load(std::sync::atomic::Ordering::Relaxed)309+ OBMC_HITS_8.with(|c| c.get())
246 }310 }
247 311
248 /// lane-rectgate r1: how many 32x32 quadrants actually decoded a312 /// lane-rectgate r1: how many 32x32 quadrants actually decoded a
@@ -252,47 +316,56 @@ pub(crate) fn obmc_hits_8() -> usize {
252 /// never writes" refusal below) -- the gate's proof that a free-partition316 /// never writes" refusal below) -- the gate's proof that a free-partition
253 /// aomenc stream actually exercised a non-`NONE`/`SPLIT` partition rather than317 /// aomenc stream actually exercised a non-`NONE`/`SPLIT` partition rather than
254 /// coincidentally never selecting one.318 /// coincidentally never selecting one.
255-static EXTENDED_PARTITION_HITS: std::sync::atomic::AtomicUsize =319+thread_local! {
256- std::sync::atomic::AtomicUsize::new(0);320+ static EXTENDED_PARTITION_HITS: std::cell::Cell<usize> =
321+ const { std::cell::Cell::new(0) };
322+}
257 323
258 /// Current value of [`EXTENDED_PARTITION_HITS`].324 /// Current value of [`EXTENDED_PARTITION_HITS`].
259 pub(crate) fn extended_partition_hits() -> usize {325 pub(crate) fn extended_partition_hits() -> usize {
260- EXTENDED_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)326+ EXTENDED_PARTITION_HITS.with(|c| c.get())
261 }327 }
262 328
263 /// lane-partitions r1: how many 32x32 quadrants decoded a real329 /// lane-partitions r1: how many 32x32 quadrants decoded a real
264 /// `PARTITION_HORZ`/`PARTITION_VERT` (two true rectangular strips, unlike330 /// `PARTITION_HORZ`/`PARTITION_VERT` (two true rectangular strips, unlike
265 /// `PARTITION_HORZ_B`'s square-context stand-in) -- the free-partition331 /// `PARTITION_HORZ_B`'s square-context stand-in) -- the free-partition
266 /// gate's proof this round's arms actually fired.332 /// gate's proof this round's arms actually fired.
267-static RECT_PARTITION_HITS: std::sync::atomic::AtomicUsize =333+thread_local! {
268- std::sync::atomic::AtomicUsize::new(0);334+ static RECT_PARTITION_HITS: std::cell::Cell<usize> =
335+ const { std::cell::Cell::new(0) };
336+}
269 337
270 /// Current value of [`RECT_PARTITION_HITS`].338 /// Current value of [`RECT_PARTITION_HITS`].
271 pub(crate) fn rect_partition_hits() -> usize {339 pub(crate) fn rect_partition_hits() -> usize {
272- RECT_PARTITION_HITS.load(std::sync::atomic::Ordering::Relaxed)340+ RECT_PARTITION_HITS.with(|c| c.get())
273 }341 }
274 342
275 /// lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded343 /// lane-rectwire r2: how many `PARTITION_HORZ`/`VERT` strips actually decoded
276 /// real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the344 /// real (non-skip) coefficients through [`read_coeffs_rect`] -- proves the
277 /// rect coefficient reader itself fired, not just the strip-level partition345 /// rect coefficient reader itself fired, not just the strip-level partition
278 /// symbol [`RECT_PARTITION_HITS`] already counts.346 /// symbol [`RECT_PARTITION_HITS`] already counts.
279-static RECT_COEFF_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);347+thread_local! {
348+ static RECT_COEFF_HITS: std::cell::Cell<usize> =
349+ const { std::cell::Cell::new(0) };
350+}
280 351
281 /// Current value of [`RECT_COEFF_HITS`].352 /// Current value of [`RECT_COEFF_HITS`].
282 pub(crate) fn rect_coeff_hits() -> usize {353 pub(crate) fn rect_coeff_hits() -> usize {
283- RECT_COEFF_HITS.load(std::sync::atomic::Ordering::Relaxed)354+ RECT_COEFF_HITS.with(|c| c.get())
284 }355 }
285 356
286 /// lane-partab r1: how many 32x32 quadrants decoded an AB partition357 /// lane-partab r1: how many 32x32 quadrants decoded an AB partition
287 /// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one358 /// (PARTITION_HORZ_A / VERT_A / VERT_B -- two 16x16 squares plus one
288 /// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the359 /// 16x32/32x16 strip). Like [`RECT_PARTITION_HITS`], this is the
289 /// free-partition gate's proof this round's arms actually fired.360 /// free-partition gate's proof this round's arms actually fired.
290-static PARTAB_HITS: std::sync::atomic::AtomicUsize =361+thread_local! {
291- std::sync::atomic::AtomicUsize::new(0);362+ static PARTAB_HITS: std::cell::Cell<usize> =
363+ const { std::cell::Cell::new(0) };
364+}
292 365
293 /// Current value of [`PARTAB_HITS`].366 /// Current value of [`PARTAB_HITS`].
294 pub(crate) fn partab_hits() -> usize {367 pub(crate) fn partab_hits() -> usize {
295- PARTAB_HITS.load(std::sync::atomic::Ordering::Relaxed)368+ PARTAB_HITS.with(|c| c.get())
296 }369 }
297 370
298 /// How many [`read_inter_compound_mode`] reads actually happened371 /// How many [`read_inter_compound_mode`] reads actually happened
@@ -301,11 +374,14 @@ pub(crate) fn partab_hits() -> usize {
301 /// mvstack build), not just that `comp_mode` fired. Still refused right374 /// mvstack build), not just that `comp_mode` fired. Still refused right
302 /// after (no MV assignment or MC wired), so this only counts attempted375 /// after (no MV assignment or MC wired), so this only counts attempted
303 /// reads.376 /// reads.
304-static COMPOUND_MODE_HITS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);377+thread_local! {
378+ static COMPOUND_MODE_HITS: std::cell::Cell<usize> =
379+ const { std::cell::Cell::new(0) };
380+}
305 381
306 /// Current value of [`COMPOUND_MODE_HITS`].382 /// Current value of [`COMPOUND_MODE_HITS`].
307 pub(crate) fn compound_mode_hits() -> usize {383 pub(crate) fn compound_mode_hits() -> usize {
308- COMPOUND_MODE_HITS.load(std::sync::atomic::Ordering::Relaxed)384+ COMPOUND_MODE_HITS.with(|c| c.get())
309 }385 }
310 386
311 /// How many query blocks folded in at least one temporal MV candidate387 /// How many query blocks folded in at least one temporal MV candidate
@@ -390,7 +466,7 @@ pub(crate) fn ref_hits(ref_frame: i8) -> usize {
390 ALTREF_FRAME => &ALTREF_HITS,466 ALTREF_FRAME => &ALTREF_HITS,
391 other => panic!("ref_hits: no per-reference counter for ref_frame {other}"),467 other => panic!("ref_hits: no per-reference counter for ref_frame {other}"),
392 };468 };
393- c.load(std::sync::atomic::Ordering::Relaxed)469+ c.with(|v| v.get())
394 }470 }
395 471
396 thread_local! {472 thread_local! {
@@ -418,12 +494,12 @@ pub(crate) fn set_enable_edge_filter(value: bool) {
418 494
419 /// Current value of [`ANGLE_DELTA_HITS`].495 /// Current value of [`ANGLE_DELTA_HITS`].
420 pub(crate) fn angle_delta_hits() -> usize {496 pub(crate) fn angle_delta_hits() -> usize {
421- ANGLE_DELTA_HITS.load(std::sync::atomic::Ordering::Relaxed)497+ ANGLE_DELTA_HITS.with(|c| c.get())
422 }498 }
423 499
424 /// Current value of [`TX_CLASS1_HITS`].500 /// Current value of [`TX_CLASS1_HITS`].
425 pub(crate) fn tx_class1_hits() -> usize {501 pub(crate) fn tx_class1_hits() -> usize {
426- TX_CLASS1_HITS.load(std::sync::atomic::Ordering::Relaxed)502+ TX_CLASS1_HITS.with(|c| c.get())
427 }503 }
428 const SUB_MI: u32 = 4;504 const SUB_MI: u32 = 4;
429 const MI: usize = 4;505 const MI: usize = 4;
@@ -944,7 +1020,7 @@ fn read_coeffs(
944 1020
945 let class = TxClass::of(tx_type);1021 let class = TxClass::of(tx_type);
946 if class != TxClass::TwoD {1022 if class != TxClass::TwoD {
947- TX_CLASS1_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1023+ TX_CLASS1_HITS.with(|c| c.set(c.get() + 1));
948 }1024 }
949 let eob = read_eob(dec, coding, class);1025 let eob = read_eob(dec, coding, class);
950 if trace {1026 if trace {
@@ -1894,7 +1970,7 @@ fn read_intra_mode_rect(
1894 return Err(unsupported("a smooth or paeth chroma mode (round 2)"));1970 return Err(unsupported("a smooth or paeth chroma mode (round 2)"));
1895 }1971 }
1896 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {1972 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
1897- DIRECTIONAL_UV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1973+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
1898 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])1974 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
1899 } else {1975 } else {
1900 01976 0
@@ -1906,7 +1982,7 @@ fn read_intra_mode_rect(
1906 {1982 {
1907 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;1983 let use_filter_intra = dec.symbol(&mut cdfs.filter_intra[class]) != 0;
1908 if use_filter_intra {1984 if use_filter_intra {
1909- FILTER_INTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);1985+ FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
1910 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);1986 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
1911 filter_intra = Some(fi_mode);1987 filter_intra = Some(fi_mode);
1912 }1988 }
@@ -2020,7 +2096,7 @@ fn decode_block_rect(
2020 let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);2096 let ctx = tx_size_context_rect(neighbours, (mi_r, mi_c), bw, bh);
2021 let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);2097 let depth = dec.symbol(&mut cdfs.tx_size_cat2[ctx]);
2022 if depth != 0 {2098 if depth != 0 {
2023- TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2099+ TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
2024 // A split transform is predicted per transform unit, each taking its2100 // A split transform is predicted per transform unit, each taking its
2025 // edges from the previous unit's reconstruction (the square path's own2101 // edges from the previous unit's reconstruction (the square path's own
2026 // per-TU loop does exactly that). Predicting the whole strip in one2102 // per-TU loop does exactly that). Predicting the whole strip in one
@@ -2217,12 +2293,12 @@ fn decode_block_rect(
2217 None,2293 None,
2218 );2294 );
2219 neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]);2295 neighbours.record_rect(at, bw, bh, mode, &[luma_levels, u_levels, v_levels]);
2220- RECT_COEFF_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2296+ RECT_COEFF_HITS.with(|c| c.set(c.get() + 1));
2221 }2297 }
2222 }2298 }
2223 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);2299 neighbours.fill_skip_grid_rect((mi_r, mi_c), bw / MI, bh / MI, skip);
2224 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);2300 neighbours.fill_lf_grid_rect((mi_r, mi_c), bw / MI, bh / MI, tx_w as u8, tx_h as u8, 0);
2225- RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2301+ RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
2226 Ok(())2302 Ok(())
2227 }2303 }
2228 2304
@@ -2233,7 +2309,7 @@ fn decode_block_rect(
2233 fn read_angle_delta(dec: &mut SymbolDecoder, cdf: &mut [u16]) -> i32 {2309 fn read_angle_delta(dec: &mut SymbolDecoder, cdf: &mut [u16]) -> i32 {
2234 let symbol = dec.symbol(cdf);2310 let symbol = dec.symbol(cdf);
2235 if symbol != ANGLE_DELTA_ZERO {2311 if symbol != ANGLE_DELTA_ZERO {
2236- ANGLE_DELTA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2312+ ANGLE_DELTA_HITS.with(|c| c.set(c.get() + 1));
2237 }2313 }
2238 symbol as i32 - ANGLE_DELTA_ZERO as i322314 symbol as i32 - ANGLE_DELTA_ZERO as i32
2239 }2315 }
@@ -2330,7 +2406,7 @@ fn read_intra_mode(
2330 // so a CFL block (uv_mode==13, outside `V_PRED..=D67_PRED`) already takes2406 // so a CFL block (uv_mode==13, outside `V_PRED..=D67_PRED`) already takes
2331 // the `else` branch below and never reads one either way.2407 // the `else` branch below and never reads one either way.
2332 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {2408 let angle_delta_uv = if (V_PRED..=D67_PRED).contains(&uv_mode) {
2333- DIRECTIONAL_UV_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2409+ DIRECTIONAL_UV_HITS.with(|c| c.set(c.get() + 1));
2334 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])2410 read_angle_delta(dec, &mut cdfs.angle_delta[uv_mode - V_PRED])
2335 } else {2411 } else {
2336 02412 0
@@ -2381,7 +2457,7 @@ fn read_intra_mode(
2381 );2457 );
2382 }2458 }
2383 if use_filter_intra {2459 if use_filter_intra {
2384- FILTER_INTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);2460+ FILTER_INTRA_HITS.with(|c| c.set(c.get() + 1));
2385 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);2461 let fi_mode = dec.symbol(&mut cdfs.filter_intra_mode);
2386 if trace {2462 if trace {
2387 eprintln!("TRACE filter_intra_mode value={fi_mode}");2463 eprintln!("TRACE filter_intra_mode value={fi_mode}");
@@ -3709,7 +3785,7 @@ fn read_tx_size(
3709 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"),3785 _ => unreachable!("decode_block/decode_leaf8 only call this at 8/16/32/64"),
3710 };3786 };
3711 if depth != 0 {3787 if depth != 0 {
3712- TX_DEPTH_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);3788+ TX_DEPTH_HITS.with(|c| c.set(c.get() + 1));
3713 }3789 }
3714 side >> depth3790 side >> depth
3715 }3791 }
@@ -3845,7 +3921,7 @@ fn edge_params(
3845 [4, 8, 14, 14, 14][dim]3921 [4, 8, 14, 14, 14][dim]
3846 };3922 };
3847 let level = if cur_level != 0 { cur_level } else { pv_level };3923 let level = if cur_level != 0 { cur_level } else { pv_level };
3848- DEBLOCK_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);3924+ DEBLOCK_HITS.with(|c| c.set(c.get() + 1));
3849 Some((len, level))3925 Some((len, level))
3850 }3926 }
3851 3927
@@ -5190,7 +5266,7 @@ fn read_single_ref(
5190 }5266 }
5191 };5267 };
5192 if ref_frame != LAST_FRAME {5268 if ref_frame != LAST_FRAME {
5193- NON_LAST_REF_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);5269+ NON_LAST_REF_HITS.with(|c| c.set(c.get() + 1));
5194 let c = match ref_frame {5270 let c = match ref_frame {
5195 LAST2_FRAME => &LAST2_HITS,5271 LAST2_FRAME => &LAST2_HITS,
5196 LAST3_FRAME => &LAST3_HITS,5272 LAST3_FRAME => &LAST3_HITS,
@@ -5200,7 +5276,7 @@ fn read_single_ref(
5200 ALTREF_FRAME => &ALTREF_HITS,5276 ALTREF_FRAME => &ALTREF_HITS,
5201 _ => unreachable!("read_single_ref only ever returns LAST_FRAME..=ALTREF_FRAME"),5277 _ => unreachable!("read_single_ref only ever returns LAST_FRAME..=ALTREF_FRAME"),
5202 };5278 };
5203- c.fetch_add(1, std::sync::atomic::Ordering::Relaxed);5279+ c.with(|v| v.set(v.get() + 1));
5204 }5280 }
5205 ref_frame5281 ref_frame
5206 }5282 }
@@ -5851,7 +5927,7 @@ fn read_comp_mode(
5851 let ctx = reference_mode_ctx(above, left);5927 let ctx = reference_mode_ctx(above, left);
5852 let compound = dec.symbol(&mut cdfs.comp_mode[ctx]) == 1;5928 let compound = dec.symbol(&mut cdfs.comp_mode[ctx]) == 1;
5853 if compound {5929 if compound {
5854- COMP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);5930+ COMP_MODE_HITS.with(|c| c.set(c.get() + 1));
5855 }5931 }
5856 compound5932 compound
5857 }5933 }
@@ -5955,7 +6031,7 @@ fn read_inter_compound_mode(
5955 ref_mv_ctx: usize,6031 ref_mv_ctx: usize,
5956 ) -> u8 {6032 ) -> u8 {
5957 let ctx = cdf::COMPOUND_MODE_CTX_MAP[ref_mv_ctx >> 1][new_mv_ctx.min(4)];6033 let ctx = cdf::COMPOUND_MODE_CTX_MAP[ref_mv_ctx >> 1][new_mv_ctx.min(4)];
5958- COMPOUND_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);6034+ COMPOUND_MODE_HITS.with(|c| c.set(c.get() + 1));
5959 dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u86035 dec.symbol(&mut cdfs.inter_compound_mode[ctx]) as u8
5960 }6036 }
5961 6037
@@ -6235,7 +6311,7 @@ fn decode_inter_block(
6235 );6311 );
6236 }6312 }
6237 if skip_mode {6313 if skip_mode {
6238- SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);6314+ SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
6239 }6315 }
6240 6316
6241 let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);6317 let skip_ctx = usize::from(neighbours.above_skip[c]) + usize::from(neighbours.left_skip[r]);
@@ -6483,7 +6559,7 @@ fn decode_inter_block(
6483 // verified vs independent C dump (wedge.rs).6559 // verified vs independent C dump (wedge.rs).
6484 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);6560 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
6485 let wedge_sign = dec.literal(1);6561 let wedge_sign = dec.literal(1);
6486- WEDGE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);6562+ WEDGE_HITS.with(|c| c.set(c.get() + 1));
6487 wedge_mask = Some(6563 wedge_mask = Some(
6488 crate::wedge::wedge_masks()6564 crate::wedge::wedge_masks()
6489 .codebook(side)6565 .codebook(side)
@@ -6494,7 +6570,7 @@ fn decode_inter_block(
6494 let mask_type = dec.literal(1);6570 let mask_type = dec.literal(1);
6495 diffwtd_mask_type = Some(mask_type as u8);6571 diffwtd_mask_type = Some(mask_type as u8);
6496 }6572 }
6497- MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);6573+ MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
6498 }6574 }
6499 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r176575 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): r16/r17
6500 // called this a `predict_compound_intermediate`/`combine_compound`6576 // called this a `predict_compound_intermediate`/`combine_compound`
@@ -7166,7 +7242,7 @@ fn decode_inter_block(
7166 // NO sign symbol follows -- libaom fixes7242 // NO sign symbol follows -- libaom fixes
7167 // INTERINTRA_WEDGE_SIGN 0 (blockd.h).7243 // INTERINTRA_WEDGE_SIGN 0 (blockd.h).
7168 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);7244 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[wedge_bsize]);
7169- WII_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);7245+ WII_HITS.with(|c| c.set(c.get() + 1));
7170 wedge_mask = Some((7246 wedge_mask = Some((
7171 crate::wedge::wedge_masks()7247 crate::wedge::wedge_masks()
7172 .codebook(side)7248 .codebook(side)
@@ -7174,7 +7250,7 @@ fn decode_inter_block(
7174 side,7250 side,
7175 ));7251 ));
7176 } else {7252 } else {
7177- INTERINTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);7253+ INTERINTRA_HITS.with(|c| c.set(c.get() + 1));
7178 }7254 }
7179 interintra_mode = Some(ii);7255 interintra_mode = Some(ii);
7180 }7256 }
@@ -7263,11 +7339,11 @@ fn decode_inter_block(
7263 0 => {}7339 0 => {}
7264 1 => {7340 1 => {
7265 obmc_selected = true;7341 obmc_selected = true;
7266- OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);7342+ OBMC_HITS.with(|c| c.set(c.get() + 1));
7267 }7343 }
7268 _ => {7344 _ => {
7269 warped_selected = true;7345 warped_selected = true;
7270- WARP_SELECTED_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);7346+ WARP_SELECTED_HITS.with(|c| c.set(c.get() + 1));
7271 let mut samples = find_samples(7347 let mut samples = find_samples(
7272 grid,7348 grid,
7273 mi_row,7349 mi_row,
@@ -7316,7 +7392,7 @@ fn decode_inter_block(
7316 } else {7392 } else {
7317 obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1;7393 obmc_selected = dec.symbol(&mut cdfs.obmc[bsize_idx]) == 1;
7318 if obmc_selected {7394 if obmc_selected {
7319- OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);7395+ OBMC_HITS.with(|c| c.set(c.get() + 1));
7320 }7396 }
7321 }7397 }
7322 }7398 }
@@ -7962,7 +8038,7 @@ fn decode_inter_block8(
7962 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);8038 usize::from(neighbours.above_skip_mode[c]) + usize::from(neighbours.left_skip_mode[r]);
7963 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;8039 let skip_mode = skip_mode_present && dec.symbol(&mut cdfs.skip_mode[skip_mode_ctx]) == 1;
7964 if skip_mode {8040 if skip_mode {
7965- SKIP_MODE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8041+ SKIP_MODE_HITS.with(|c| c.set(c.get() + 1));
7966 }8042 }
7967 8043
7968 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);8044 let skip_ctx = usize::from(above_skip) + usize::from(left_skip);
@@ -8079,7 +8155,7 @@ fn decode_inter_block8(
8079 // leaf's own comment.8155 // leaf's own comment.
8080 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);8156 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
8081 let wedge_sign = dec.literal(1);8157 let wedge_sign = dec.literal(1);
8082- WEDGE_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8158+ WEDGE_HITS.with(|c| c.set(c.get() + 1));
8083 wedge_mask = Some(8159 wedge_mask = Some(
8084 crate::wedge::wedge_masks()8160 crate::wedge::wedge_masks()
8085 .codebook(SIDE)8161 .codebook(SIDE)
@@ -8089,7 +8165,7 @@ fn decode_inter_block8(
8089 let mask_type = dec.literal(1);8165 let mask_type = dec.literal(1);
8090 diffwtd_mask_type = Some(mask_type as u8);8166 diffwtd_mask_type = Some(mask_type as u8);
8091 }8167 }
8092- MASKED_COMPOUND_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8168+ MASKED_COMPOUND_HITS.with(|c| c.set(c.get() + 1));
8093 }8169 }
8094 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same8170 // corner-cut (lane-av1comp r16/r17, lane-av1blend r1): same
8095 // reference-slot defect as the 16x16 leaf's own mask above8171 // reference-slot defect as the 16x16 leaf's own mask above
@@ -8471,7 +8547,7 @@ fn decode_inter_block8(
8471 // lane-wii r2: same adapting `wedge_index` symbol as the8547 // lane-wii r2: same adapting `wedge_index` symbol as the
8472 // 16/32 leaf, fixed sign 0 -- see that site's comment.8548 // 16/32 leaf, fixed sign 0 -- see that site's comment.
8473 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);8549 let wedge_index = dec.symbol(&mut cdfs.wedge_idx[3]);
8474- WII_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8550+ WII_HITS.with(|c| c.set(c.get() + 1));
8475 wedge_mask = Some((8551 wedge_mask = Some((
8476 crate::wedge::wedge_masks()8552 crate::wedge::wedge_masks()
8477 .codebook(SIDE)8553 .codebook(SIDE)
@@ -8479,7 +8555,7 @@ fn decode_inter_block8(
8479 SIDE,8555 SIDE,
8480 ));8556 ));
8481 } else {8557 } else {
8482- INTERINTRA_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8558+ INTERINTRA_HITS.with(|c| c.set(c.get() + 1));
8483 }8559 }
8484 interintra_mode = Some(ii);8560 interintra_mode = Some(ii);
8485 }8561 }
@@ -8509,11 +8585,11 @@ fn decode_inter_block8(
8509 0 => {}8585 0 => {}
8510 1 => {8586 1 => {
8511 obmc_selected = true;8587 obmc_selected = true;
8512- OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8588+ OBMC_HITS.with(|c| c.set(c.get() + 1));
8513- OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8589+ OBMC_HITS_8.with(|c| c.set(c.get() + 1));
8514 }8590 }
8515 _ => {8591 _ => {
8516- WARP_SELECTED_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8592+ WARP_SELECTED_HITS.with(|c| c.set(c.get() + 1));
8517 return Err(unsupported(8593 return Err(unsupported(
8518 "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): \8594 "an 8x8 leaf that coded WARPED_CAUSAL (motion_mode == 2): \
8519 av1_find_projection/the affine warp filter are not \8595 av1_find_projection/the affine warp filter are not \
@@ -8525,8 +8601,8 @@ fn decode_inter_block8(
8525 // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3.8601 // `default_obmc_cdf`'s own index: square bsize 8/16/32/64 -> 0/1/2/3.
8526 obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1;8602 obmc_selected = dec.symbol(&mut cdfs.obmc[0]) == 1;
8527 if obmc_selected {8603 if obmc_selected {
8528- OBMC_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8604+ OBMC_HITS.with(|c| c.set(c.get() + 1));
8529- OBMC_HITS_8.fetch_add(1, std::sync::atomic::Ordering::Relaxed);8605+ OBMC_HITS_8.with(|c| c.set(c.get() + 1));
8530 }8606 }
8531 }8607 }
8532 }8608 }
@@ -9459,7 +9535,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9459 // mi-granular `left_side_mi` rows of a last-block-in-9535 // mi-granular `left_side_mi` rows of a last-block-in-
9460 // tile strip leak 32-vs-16 only until the per-tile9536 // tile strip leak 32-vs-16 only until the per-tile
9461 // `Neighbours::new` reset.9537 // `Neighbours::new` reset.
9462- EXTENDED_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);9538+ EXTENDED_PARTITION_HITS.with(|c| c.set(c.get() + 1));
9463 let at32 = at;9539 let at32 = at;
9464 decode_inter_block(9540 decode_inter_block(
9465 &mut dec,9541 &mut dec,
@@ -9628,7 +9704,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9628 // (mvstack.rs, `motion_mode_eligible`) now derive from9704 // (mvstack.rs, `motion_mode_eligible`) now derive from
9629 // `write_w`/`write_h`'s true 32x16 footprint -- the9705 // `write_w`/`write_h`'s true 32x16 footprint -- the
9630 // pin's fix (r1's finding).9706 // pin's fix (r1's finding).
9631- RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);9707+ RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
9632 decode_inter_block(9708 decode_inter_block(
9633 &mut dec,9709 &mut dec,
9634 &mut cdfs,9710 &mut cdfs,
@@ -9729,7 +9805,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9729 PARTITION_VERT => {9805 PARTITION_VERT => {
9730 // lane-rect r2: mirror of PARTITION_HORZ above with9806 // lane-rect r2: mirror of PARTITION_HORZ above with
9731 // width/height swapped.9807 // width/height swapped.
9732- RECT_PARTITION_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);9808+ RECT_PARTITION_HITS.with(|c| c.set(c.get() + 1));
9733 decode_inter_block(9809 decode_inter_block(
9734 &mut dec,9810 &mut dec,
9735 &mut cdfs,9811 &mut cdfs,
@@ -9831,7 +9907,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9831 // lane-partab r1: two 16x16 squares on top + a true9907 // lane-partab r1: two 16x16 squares on top + a true
9832 // 32x16 strip below (libaom decode_partition9908 // 32x16 strip below (libaom decode_partition
9833 // PARTITION_HORZ_A: TL, TR, bottom strip).9909 // PARTITION_HORZ_A: TL, TR, bottom strip).
9834- PARTAB_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);9910+ PARTAB_HITS.with(|c| c.set(c.get() + 1));
9835 decode_inter_block(9911 decode_inter_block(
9836 &mut dec,9912 &mut dec,
9837 &mut cdfs,9913 &mut cdfs,
@@ -9988,7 +10064,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
9988 PARTITION_VERT_A => {10064 PARTITION_VERT_A => {
9989 // lane-partab r1: mirror of PARTITION_HORZ_A with10065 // lane-partab r1: mirror of PARTITION_HORZ_A with
9990 // width/height swapped (TL, BL, right 16x32 strip).10066 // width/height swapped (TL, BL, right 16x32 strip).
9991- PARTAB_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);10067+ PARTAB_HITS.with(|c| c.set(c.get() + 1));
9992 decode_inter_block(10068 decode_inter_block(
9993 &mut dec,10069 &mut dec,
9994 &mut cdfs,10070 &mut cdfs,
@@ -10146,7 +10222,7 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
10146 // lane-partab r1: true 16x32 strip on the left + two10222 // lane-partab r1: true 16x32 strip on the left + two
10147 // 16x16 squares on the right (libaom decode_partition10223 // 16x16 squares on the right (libaom decode_partition
10148 // PARTITION_VERT_B: left strip, TR, BR).10224 // PARTITION_VERT_B: left strip, TR, BR).
10149- PARTAB_HITS.fetch_add(1, std::sync::atomic::Ordering::Relaxed);10225+ PARTAB_HITS.with(|c| c.set(c.get() + 1));
10150 decode_inter_block(10226 decode_inter_block(
10151 &mut dec,10227 &mut dec,
10152 &mut cdfs,10228 &mut cdfs,