forge
Explore
Log in

Don't you dare go Hollow

The coefficient writer splits a scan position by shifting, and a wall table for the film crop

Browse files at this commit

65aa140813b4411cc5f3db440a0a0c0d9e5761fcAhmet Kaan GümüşParent: 3847d87
  • perf
    • the coefficient writer splits a scan position by shifting, and a wall table for the film crop
Show full message
perf(av1): the coefficient writer splits a scan position by shifting, and a wall table for the film crop

`side` is 4, 8, 16 or 32, but it reaches `write_coeffs` as a runtime
value, so `pos / side` and `pos % side` compiled to a real integer
division and remainder once per coefficient -- inside the encoder's
largest self-time symbol. Same row and column by construction (the side
is a power of two, now debug-asserted).

640x384 gate clip, 4 frames, q 150/120/90/60 and both real-film 1920x768
crops at q 150/60: byte-identical to a b7990ec1 baseline binary.
1920x1080 4 frames q=120, instructions:u ABABx2: 59.344e9 -> 59.200e9
(-0.24%), on top of the CDEF written-map commit.

`filter_stage_wall_film` runs the same stage breakdown at 1920x768, and
`EC_AV1_WALL_CLIP` points the test loader at a clip outside the repo, so
the table can be read on a real film window as well as on the colour-bar
fixture. It answers which stage grows on film: the TILE SEARCH does
(285.9 -> 497.7 ms/frame, bars vs film A), while every filter stage is
flat or lower -- deblock replay 15.4 -> 10.0, plane copies 28.9 -> 23.7,
first decode 14.7 -> 17.2 ms/frame. Only the CDEF replay grows (13.0 ->
21.7), which is the film choosing non-zero strengths where bars do not.
crates/ec-av1/src/encoder.rsmodified+20 -2
@@ -1496,8 +1496,16 @@ mod tests {
1496 if !have_ffmpeg() {1496 if !have_ffmpeg() {
1497 return None;1497 return None;
1498 }1498 }
1499- let clip = std::path::Path::new(env!("CARGO_MANIFEST_DIR"))1499+ // lane-av1speed3: the wall tables below are read on REAL film as
1500- .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4");1500+ // well as on the colour-bar fixture (`bars` vs `film` in the BD
1501+ // gate's own vocabulary), and the film crop lives outside the repo --
1502+ // `EC_AV1_WALL_CLIP` names it. Unset everywhere else, so every other
1503+ // caller still gets the fixture.
1504+ let clip = match std::env::var("EC_AV1_WALL_CLIP") {
1505+ Ok(p) => std::path::PathBuf::from(p),
1506+ Err(_) => std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
1507+ .join("../../fixtures/video/h264-1080p-23.976-8bit.mp4"),
1508+ };
1501 if !clip.exists() {1509 if !clip.exists() {
1502 return None;1510 return None;
1503 }1511 }
@@ -2168,6 +2176,16 @@ mod tests {
2168 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);2176 filter_stage_wall(3840, 1608, 4, (2, 1), &[8, 12]);
2169 }2177 }
2170 2178
2179+ /// The same breakdown at the real films' own crop size. With
2180+ /// `EC_AV1_WALL_CLIP` pointing at a film window this is the film row; with
2181+ /// it unset it is the colour-bar fixture at the same size, which is what
2182+ /// makes the pair a comparison rather than a number.
2183+ #[test]
2184+ #[ignore = "wall measurement: minutes, run it with --ignored --nocapture"]
2185+ fn filter_stage_wall_film() {
2186+ filter_stage_wall(1920, 768, 4, (2, 1), &[8]);
2187+ }
2188+
2171 fn filter_stage_wall(2189 fn filter_stage_wall(
2172 width: usize,2190 width: usize,
2173 height: usize,2191 height: usize,
crates/ec-av1/src/tile.rsmodified+6 -1
@@ -4543,9 +4543,14 @@ fn write_coeffs(
4543 4543
4544 write_eob(enc, coding, eob, plane);4544 write_eob(enc, coding, eob, plane);
4545 4545
4546+ // lane-av1speed3: `side` is 4, 8, 16 or 32, but it is a runtime value --
4547+ // `pos / side` compiles to a real integer division, once per coefficient,
4548+ // in the encoder's largest self-time symbol. Same row and column.
4549+ debug_assert!(side.is_power_of_two(), "the scan splits a position by shifting");
4550+ let (shift, mask) = (side.trailing_zeros(), side - 1);
4546 for scan_idx in (0..eob).rev() {4551 for scan_idx in (0..eob).rev() {
4547 let pos = scan[scan_idx] as usize;4552 let pos = scan[scan_idx] as usize;
4548- let (row, col) = (pos / side, pos % side);4553+ let (row, col) = (pos >> shift, pos & mask);
4549 let level = grid[pos].abs();4554 let level = grid[pos].abs();
4550 if scan_idx == eob - 1 {4555 if scan_idx == eob - 1 {
4551 let ctx = eob_coeff_ctx(scan_idx, side * side);4556 let ctx = eob_coeff_ctx(scan_idx, side * side);