From ec83ffd1a17f5b3a64240b4b9aed44c1d66b9d0b Mon Sep 17 00:00:00 2001 From: Luca Barbato <lu_zero@gentoo.org> Date: Sun, 21 Oct 2018 15:13:10 +0200 Subject: [PATCH] Add a native impl of pred_dc_top --- benches/predict.rs | 17 +++++++++++++++++ src/partition.rs | 2 +- src/predict.rs | 46 ++++++++++++++++++++++++++++++++++------------ 3 files changed, 52 insertions(+), 13 deletions(-) diff --git a/benches/predict.rs b/benches/predict.rs index 89729db8..4d4c67bc 100644 --- a/benches/predict.rs +++ b/benches/predict.rs @@ -27,6 +27,7 @@ pub fn generate_block(rng: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>, Vec<u16>) { pub fn pred_bench(c: &mut Criterion) { c.bench_function("intra_dc_4x4", |b| intra_dc_4x4(b)); + c.bench_function("intra_dc_top_4x4", |b| intra_dc_top_4x4(b)); c.bench_function("intra_h_4x4", |b| intra_h_4x4(b)); c.bench_function("intra_v_4x4", |b| intra_v_4x4(b)); c.bench_function("intra_paeth_4x4", |b| intra_paeth_4x4(b)); @@ -52,6 +53,22 @@ pub fn intra_dc_4x4(b: &mut Bencher) { }) } +pub fn intra_dc_top_4x4(b: &mut Bencher) { + let mut ra = ChaChaRng::from_seed([0; 32]); + let (mut block, above, left) = generate_block(&mut ra); + + b.iter(|| { + for _ in 0..MAX_ITER { + Block4x4::pred_dc_top( + &mut block, + BLOCK_SIZE.width(), + &above[..4], + &left[..4] + ); + } + }) +} + pub fn intra_h_4x4(b: &mut Bencher) { let mut rng = ChaChaRng::from_seed([0; 32]); let (mut block, _above, left) = generate_block(&mut rng); diff --git a/src/partition.rs b/src/partition.rs index b1dfd6d5..bd692688 100644 --- a/src/partition.rs +++ b/src/partition.rs @@ -922,7 +922,7 @@ impl PredictionMode { (_, 0) => B::pred_dc_left(slice, stride, above_slice, left_slice, bit_depth), (0, _) => - B::pred_dc_top(slice, stride, above_slice, left_slice, bit_depth), + B::pred_dc_top(slice, stride, above_slice, left_slice), _ => B::pred_dc(slice, stride, above_slice, left_slice) }, PredictionMode::H_PRED => match (x, y) { diff --git a/src/predict.rs b/src/predict.rs index 1a01683f..5107f517 100644 --- a/src/predict.rs +++ b/src/predict.rs @@ -113,6 +113,7 @@ extern { above: *const u16, left: *const u16, bd: libc::c_int ); + #[cfg(test)] fn highbd_dc_top_predictor( dst: *mut u16, stride: libc::ptrdiff_t, bw: libc::c_int, bh: libc::c_int, above: *const u16, left: *const u16, bd: libc::c_int @@ -249,19 +250,12 @@ pub trait Intra: Dim { #[cfg_attr(feature = "comparative_bench", inline(never))] fn pred_dc_top( - output: &mut [u16], stride: usize, above: &[u16], left: &[u16], - bit_depth: usize + output: &mut [u16], stride: usize, above: &[u16], _left: &[u16] ) { - unsafe { - highbd_dc_top_predictor( - output.as_mut_ptr(), - stride as libc::ptrdiff_t, - Self::W as libc::c_int, - Self::H as libc::c_int, - above.as_ptr(), - left.as_ptr(), - bit_depth as libc::c_int - ); + let sum = above[..Self::W].iter().fold(0u32, |acc, &v| acc + v as u32); + let avg = ((sum + (Self::W >> 1) as u32) / Self::W as u32) as u16; + for line in output.chunks_mut(stride).take(Self::H) { + line[..Self::W].iter_mut().for_each(|v| *v = avg); } } @@ -546,6 +540,22 @@ pub mod test { } } + fn pred_dc_top_4x4( + output: &mut [u16], stride: usize, above: &[u16], left: &[u16] + ) { + unsafe { + highbd_dc_top_predictor( + output.as_mut_ptr(), + stride as libc::ptrdiff_t, + 4, + 4, + above.as_ptr(), + left.as_ptr(), + 8 + ); + } + } + pub fn pred_h_4x4( output: &mut [u16], stride: usize, above: &[u16], left: &[u16] ) { @@ -667,6 +677,15 @@ pub mod test { (o1, o2) } + fn do_dc_top_pred(ra: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>) { + let (above, left, mut o1, mut o2) = setup_pred(ra); + + pred_dc_top_4x4(&mut o1, 32, &above[..4], &left[..4]); + Block4x4::pred_dc_top(&mut o2, 32, &above[..4], &left[..4]); + + (o1, o2) + } + fn do_h_pred(ra: &mut ChaChaRng) -> (Vec<u16>, Vec<u16>) { let (above, left, mut o1, mut o2) = setup_pred(ra); @@ -769,6 +788,9 @@ pub mod test { let (o1, o2) = do_dc_pred(&mut ra); assert_eq!(o1, o2); + let (o1, o2) = do_dc_top_pred(&mut ra); + assert_eq!(o1, o2); + let (o1, o2) = do_h_pred(&mut ra); assert_eq!(o1, o2); -- GitLab