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(
522 enc,522 enc,
523 levels,523 levels,
524 n,524 n,
525+ log2_size,
526+ sub_wide,
527+ sub_scan,
528+ pos_scan,
525 c_idx,529 c_idx,
526 scan_idx,530 scan_idx,
527 false,531 false,
@@ -758,12 +762,23 @@ fn encode_subblock_range(
758 greater1_ctx_in: u32,762 greater1_ctx_in: u32,
759 csbf: &[bool; 64],763 csbf: &[bool; 64],
760 ) -> u32 {764 ) -> 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);
761 let mut greater1_ctx = greater1_ctx_in;772 let mut greater1_ctx = greater1_ctx_in;
762 for i in (0..=from_sub).rev() {773 for i in (0..=from_sub).rev() {
763 greater1_ctx = encode_subblock(774 greater1_ctx = encode_subblock(
764 enc,775 enc,
765 levels,776 levels,
766 n,777 n,
778+ log2_size,
779+ sub_wide,
780+ sub_scan,
781+ pos_scan,
767 c_idx,782 c_idx,
768 scan_idx,783 scan_idx,
769 sign_hiding,784 sign_hiding,
@@ -786,6 +801,10 @@ fn encode_subblock(
786 enc: &mut CabacEncoder,801 enc: &mut CabacEncoder,
787 levels: &[i32],802 levels: &[i32],
788 n: usize,803 n: usize,
804+ log2_size: u32,
805+ sub_wide: usize,
806+ sub_scan: &'static [(u8, u8)],
807+ pos_scan: &'static [(u8, u8)],
789 c_idx: usize,808 c_idx: usize,
790 scan_idx: usize,809 scan_idx: usize,
791 sign_hiding: bool,810 sign_hiding: bool,
@@ -795,10 +814,6 @@ fn encode_subblock(
795 csbf: &[bool; 64],814 csbf: &[bool; 64],
796 greater1_ctx_in: u32,815 greater1_ctx_in: u32,
797 ) -> u32 {816 ) -> 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);
802 let chroma = c_idx > 0;817 let chroma = c_idx > 0;
803 let mut greater1_ctx = greater1_ctx_in;818 let mut greater1_ctx = greater1_ctx_in;
804 819