Ten headroom bits under the forward network, measured on BD
Browse files at this commit636712fa9c1c09b493428d6cfe0b048501d43e79Parent: 1be1614- perf
- ten headroom bits under the forward network, measured on BD
1 changed file +12 -5
crates/ec-av1/src/transform.rsmodified+12 -5
| @@ -1736,11 +1736,12 @@ const FORWARD_RANGE: usize = 32; | ||
| 1736 | 1736 | /// The network rounds to an integer at every butterfly, so its output LSB is |
| 1737 | 1737 | /// what the quantizer's input resolution costs: unshifted, one LSB at 4x4 is |
| 1738 | 1738 | /// four whole units of the `8 * orthonormal` scale the levels are formed on |
| 1739 | -/// -- coarser than a fine quantizer's own step. Six bits put that back at | |
| 1740 | -/// 1/16 of a unit and cost nothing: the widest case (a 13-bit residual | |
| 1741 | -/// through two 64-point passes, gain 32) stays under 2^25, well inside `i32` | |
| 1742 | -/// and far inside [`FORWARD_RANGE`]. | |
| 1743 | -const FORWARD_PRECISION_BITS: u32 = 6; | |
| 1739 | +/// -- coarser than a fine quantizer's own step, and worth 3.9 BD points on | |
| 1740 | +/// screen capture. Ten bits put it at 1/256 of a unit, which is where the BD | |
| 1741 | +/// gate stops moving (13 bits measured identical), and cost nothing: the | |
| 1742 | +/// widest case, a 12-bit residual through two 64-point passes (gain 32), | |
| 1743 | +/// stays under 2^27 -- inside `i32` and far inside [`FORWARD_RANGE`]. | |
| 1744 | +const FORWARD_PRECISION_BITS: u32 = 10; | |
| 1744 | 1745 | |
| 1745 | 1746 | /// [`forward_dct_n`]'s uniform gain at one size, measured from the network |
| 1746 | 1747 | /// itself rather than derived: an impulse through it is `g` times |
| @@ -1795,6 +1796,12 @@ pub fn forward_transform_2d(residual: &[i32], side: usize) -> Vec<f64> { | ||
| 1795 | 1796 | /// The row pass, in fixed point: each of `side` residual rows through |
| 1796 | 1797 | /// [`forward_dct_fixed`], at [`FORWARD_PRECISION_BITS`] extra precision and |
| 1797 | 1798 | /// the network's own gain (both of which [`forward_scale`] divides back out). |
| 1799 | +/// | |
| 1800 | +/// The `Vec` is per call on purpose: holding it in a thread-local scratch, as | |
| 1801 | +/// the inverse transform's row pass does, was MEASURED +5.0% instructions on | |
| 1802 | +/// the sequence bench -- a fresh zeroed allocation costs less here than the | |
| 1803 | +/// `memset` reusing one needs plus the thread-local access, because the | |
| 1804 | +/// zeroing is what the all-zero-row skip below reads. | |
| 1798 | 1805 | fn forward_rows(residual: &[i32], side: usize) -> Vec<i32> { |
| 1799 | 1806 | assert_eq!( |
| 1800 | 1807 | residual.len(), |