forge
Explore
Log in

Don't you dare go Hollow

Merge branch 'lane-h265perf': hoist loop-invariant scan/size derivation out of encode_subblock

Browse files at this commit

e117d908d758a654d806ae2e6df7ba3bc5fd89a7Ahmet Kaan GümüşParent: 81586f2b54343a
Bit-exact (identical AU bytes), suite green; wall-clock inert at bench
scale -- kept for the removed redundant recompute. Real RDOQ lever
(estimated bit-cost table) goes to its own BD-gated lane.
crates/ec-h265/src/residual.rsmodified+19 -4
@@ -522,6 +522,10 @@ pub fn rdoq(
522522 enc,
523523 levels,
524524 n,
525+ log2_size,
526+ sub_wide,
527+ sub_scan,
528+ pos_scan,
525529 c_idx,
526530 scan_idx,
527531 false,
@@ -758,12 +762,23 @@ fn encode_subblock_range(
758762 greater1_ctx_in: u32,
759763 csbf: &[bool; 64],
760764 ) -> u32 {
765+ // Hoisted once for the whole range instead of re-derived by every
766+ // `encode_subblock` call: `log2_size`/`sub_wide`/the scan tables are the
767+ // same for every sub-block this loop visits.
768+ let log2_size = n.trailing_zeros();
769+ let sub_wide = n >> 2;
770+ let sub_scan = scan(log2_size - 2, scan_idx);
771+ let pos_scan = scan(2, scan_idx);
761772 let mut greater1_ctx = greater1_ctx_in;
762773 for i in (0..=from_sub).rev() {
763774 greater1_ctx = encode_subblock(
764775 enc,
765776 levels,
766777 n,
778+ log2_size,
779+ sub_wide,
780+ sub_scan,
781+ pos_scan,
767782 c_idx,
768783 scan_idx,
769784 sign_hiding,
@@ -786,6 +801,10 @@ fn encode_subblock(
786801 enc: &mut CabacEncoder,
787802 levels: &[i32],
788803 n: usize,
804+ log2_size: u32,
805+ sub_wide: usize,
806+ sub_scan: &'static [(u8, u8)],
807+ pos_scan: &'static [(u8, u8)],
789808 c_idx: usize,
790809 scan_idx: usize,
791810 sign_hiding: bool,
@@ -795,10 +814,6 @@ fn encode_subblock(
795814 csbf: &[bool; 64],
796815 greater1_ctx_in: u32,
797816 ) -> u32 {
798- let log2_size = n.trailing_zeros();
799- let sub_wide = n >> 2;
800- let sub_scan = scan(log2_size - 2, scan_idx);
801- let pos_scan = scan(2, scan_idx);
802817 let chroma = c_idx > 0;
803818 let mut greater1_ctx = greater1_ctx_in;
804819