forge
Explore
Log in

Don't you dare go Hollow

Pin unit_sse's chunked sums against the naive per-sample ones

Browse files at this commit

e92d1135486ba210b3e1c77b0236be0dd0b1ba46Ahmet Kaan GümüşParent: 95de47f
  • test
    • pin unit_sse's chunked sums against the naive per-sample ones
Show full message
test(av1): pin unit_sse's chunked sums against the naive per-sample ones
crates/ec-av1/src/filter_search.rsmodified+35 -0
@@ -521,3 +521,38 @@ thread_local! {
521 pub(crate) fn take_lr_histogram() -> (usize, usize) {521 pub(crate) fn take_lr_histogram() -> (usize, usize) {
522 LR_CHOSEN.with(|c| std::mem::take(&mut *c.borrow_mut()))522 LR_CHOSEN.with(|c| std::mem::take(&mut *c.borrow_mut()))
523 }523 }
524+
525+#[cfg(test)]
526+mod tests {
527+ use super::unit_sse;
528+
529+ /// [`unit_sse`]'s chunked, `u32`-accumulating shape against the naive
530+ /// per-sample reference it replaced -- per unit AND in total, on a plane
531+ /// whose width is not a whole number of units (the case where the last
532+ /// chunk is short) and with strides wider than the region scored.
533+ #[test]
534+ fn unit_sse_matches_the_naive_sum() {
535+ let (w, h, unit, sb_cols) = (100usize, 70usize, 32usize, 4usize);
536+ let (dec_w, src_w) = (w + 7, w + 13);
537+ let mut state = 0x1234_5678u32;
538+ let mut rnd = move || {
539+ state = state.wrapping_mul(1_664_525).wrapping_add(1_013_904_223);
540+ (state >> 24) as u8
541+ };
542+ let dec: Vec<u16> = (0..dec_w * h).map(|_| u16::from(rnd())).collect();
543+ let src: Vec<u8> = (0..src_w * h).map(|_| rnd()).collect();
544+ let mut want = vec![7u64; sb_cols * 4]; // a non-zero start: this accumulates
545+ let mut total = 0u64;
546+ for row in 0..h {
547+ let base = (row / unit) * sb_cols;
548+ for col in 0..w {
549+ let diff = i64::from(dec[row * dec_w + col]) - i64::from(src[row * src_w + col]);
550+ want[base + col / unit] += (diff * diff) as u64;
551+ total += (diff * diff) as u64;
552+ }
553+ }
554+ let mut got = vec![7u64; sb_cols * 4];
555+ assert_eq!(unit_sse(&dec, dec_w, &src, src_w, w, h, unit, sb_cols, &mut got), total);
556+ assert_eq!(got, want);
557+ }
558+}