Gather a coefficient's context neighbours without per-neighbour edge tests
Browse files at this commit02bd8ae4cb9ad7bf47b3311b419939e091058cbaParent: fb3fa69- perf
- gather a coefficient's context neighbours without per-neighbour edge tests
1 changed file +25 -8
- crates/ec-av1/src/tile.rs +25 -8
crates/ec-av1/src/tile.rsmodified+25 -8
| @@ -2473,10 +2473,22 @@ fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | |||
| 2473 | if row == 0 && col == 0 { | 2473 | if row == 0 && col == 0 { |
| 2474 | return 0; | 2474 | return 0; |
| 2475 | } | 2475 | } |
| 2476 | - let mag: i32 = [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)] | 2476 | + // A coefficient two rows and two columns clear of the far edges reaches |
| 2477 | - .iter() | 2477 | + // all five neighbours, so the gather is five loads off one index with no |
| 2478 | - .map(|&(dr, dc)| neighbour(grid, side, row + dr, col + dc).abs().min(3)) | 2478 | + // per-neighbour edge test -- which is where this writer spends a third of |
| 2479 | - .sum(); | 2479 | + // its coefficient loop. |
| 2480 | + let p = row * side + col; | ||
| 2481 | + let mag: i32 = if row + 2 < side && col + 2 < side { | ||
| 2482 | + [p + side, p + 1, p + side + 1, p + 2 * side, p + 2] | ||
| 2483 | + .iter() | ||
| 2484 | + .map(|&i| grid[i].abs().min(3)) | ||
| 2485 | + .sum() | ||
| 2486 | + } else { | ||
| 2487 | + [(1, 0), (0, 1), (1, 1), (2, 0), (0, 2)] | ||
| 2488 | + .iter() | ||
| 2489 | + .map(|&(dr, dc)| neighbour(grid, side, row + dr, col + dc).abs().min(3)) | ||
| 2490 | + .sum() | ||
| 2491 | + }; | ||
| 2480 | let offset = cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize; | 2492 | let offset = cdf::NZ_MAP_CTX_OFFSET_32[row.min(4)][col.min(4)] as usize; |
| 2481 | (((mag + 1) >> 1).min(4) as usize) + offset | 2493 | (((mag + 1) >> 1).min(4) as usize) + offset |
| 2482 | } | 2494 | } |
| @@ -2485,10 +2497,15 @@ fn base_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | |||
| 2485 | /// of its three closest neighbours below and to the right, uncapped, and a | 2497 | /// of its three closest neighbours below and to the right, uncapped, and a |
| 2486 | /// term separating the DC, the corner of the transform, and the rest. | 2498 | /// term separating the DC, the corner of the transform, and the rest. |
| 2487 | fn br_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { | 2499 | fn br_ctx(grid: &[i32], side: usize, row: usize, col: usize) -> usize { |
| 2488 | - let mag: i32 = [(1, 0), (0, 1), (1, 1)] | 2500 | + let p = row * side + col; |
| 2489 | - .iter() | 2501 | + let mag: i32 = if row + 1 < side && col + 1 < side { |
| 2490 | - .map(|&(dr, dc)| neighbour(grid, side, row + dr, col + dc).abs()) | 2502 | + grid[p + side].abs() + grid[p + 1].abs() + grid[p + side + 1].abs() |
| 2491 | - .sum(); | 2503 | + } else { |
| 2504 | + [(1, 0), (0, 1), (1, 1)] | ||
| 2505 | + .iter() | ||
| 2506 | + .map(|&(dr, dc)| neighbour(grid, side, row + dr, col + dc).abs()) | ||
| 2507 | + .sum() | ||
| 2508 | + }; | ||
| 2492 | let mag = (((mag + 1) >> 1).min(6)) as usize; | 2509 | let mag = (((mag + 1) >> 1).min(6)) as usize; |
| 2493 | if row == 0 && col == 0 { | 2510 | if row == 0 && col == 0 { |
| 2494 | mag | 2511 | mag |