Commit ec83ffd1 authored by Luca Barbato's avatar Luca Barbato Committed by David Michael Barr

Add a native impl of pred_dc_top

parent c69ac5c3
......@@ -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);
......
......@@ -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) {
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment