Skip to content

Commit

Permalink
fn sgr...: Misc cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Jul 24, 2023
1 parent 759a302 commit ff71f18
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 51 deletions.
45 changes: 18 additions & 27 deletions src/looprestoration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -725,11 +725,11 @@ pub(crate) unsafe extern "C" fn selfguided_filter<BD: BitDepth>(
}

// TODO(randomPoison): Temporarily pub until init logic is deduplicated.
pub(crate) unsafe extern "C" fn sgr_5x5_c<BD: BitDepth>(
mut p: *mut libc::c_void,
pub(crate) unsafe extern "C" fn sgr_5x5_c_erased<BD: BitDepth>(
p: *mut libc::c_void,
stride: ptrdiff_t,
left: *const libc::c_void,
mut lpf: *const libc::c_void,
lpf: *const libc::c_void,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand All @@ -753,7 +753,7 @@ unsafe fn sgr_5x5_rust<BD: BitDepth>(
mut p: *mut BD::Pixel,
stride: ptrdiff_t,
left: *const [BD::Pixel; 4],
mut lpf: *const BD::Pixel,
lpf: *const BD::Pixel,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand All @@ -779,13 +779,10 @@ unsafe fn sgr_5x5_rust<BD: BitDepth>(
let mut i = 0;
while i < w {
let v = w0 * dst[(j * 384 + i) as usize].as_::<libc::c_int>();
*p.offset(i as isize) = iclip(
*p.offset(i as isize) = bd.iclip_pixel(
(*p.offset(i as isize)).as_::<libc::c_int>()
+ (v + ((1 as libc::c_int) << 10) >> 11),
0 as libc::c_int,
bd.bitdepth_max().as_(),
)
.as_();
);
i += 1;
}
p = p.offset(BD::pxstride(stride as usize) as isize);
Expand All @@ -794,11 +791,11 @@ unsafe fn sgr_5x5_rust<BD: BitDepth>(
}

// TODO(randomPoison): Temporarily pub until init logic is deduplicated.
pub(crate) unsafe extern "C" fn sgr_3x3_c<BD: BitDepth>(
mut p: *mut libc::c_void,
pub(crate) unsafe extern "C" fn sgr_3x3_c_erased<BD: BitDepth>(
p: *mut libc::c_void,
stride: ptrdiff_t,
left: *const libc::c_void,
mut lpf: *const libc::c_void,
lpf: *const libc::c_void,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand All @@ -822,7 +819,7 @@ unsafe fn sgr_3x3_rust<BD: BitDepth>(
mut p: *mut BD::Pixel,
stride: ptrdiff_t,
left: *const [BD::Pixel; 4],
mut lpf: *const BD::Pixel,
lpf: *const BD::Pixel,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand All @@ -848,13 +845,10 @@ unsafe fn sgr_3x3_rust<BD: BitDepth>(
let mut i = 0;
while i < w {
let v = w1 * dst[(j * 384 + i) as usize].as_::<libc::c_int>();
*p.offset(i as isize) = iclip(
*p.offset(i as isize) = bd.iclip_pixel(
(*p.offset(i as isize)).as_::<libc::c_int>()
+ (v + ((1 as libc::c_int) << 10) >> 11),
0 as libc::c_int,
bd.bitdepth_max().as_(),
)
.as_();
);
i += 1;
}
p = p.offset(BD::pxstride(stride as usize) as isize);
Expand All @@ -863,11 +857,11 @@ unsafe fn sgr_3x3_rust<BD: BitDepth>(
}

// TODO(randomPoison): Temporarily pub until init logic is deduplicated.
pub(crate) unsafe extern "C" fn sgr_mix_c<BD: BitDepth>(
mut p: *mut libc::c_void,
pub(crate) unsafe extern "C" fn sgr_mix_c_erased<BD: BitDepth>(
p: *mut libc::c_void,
stride: ptrdiff_t,
left: *const libc::c_void,
mut lpf: *const libc::c_void,
lpf: *const libc::c_void,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand All @@ -891,7 +885,7 @@ unsafe fn sgr_mix_rust<BD: BitDepth>(
mut p: *mut BD::Pixel,
stride: ptrdiff_t,
left: *const [BD::Pixel; 4],
mut lpf: *const BD::Pixel,
lpf: *const BD::Pixel,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
Expand Down Expand Up @@ -930,13 +924,10 @@ unsafe fn sgr_mix_rust<BD: BitDepth>(
while i < w {
let v = w0 * dst0[(j * 384 + i) as usize].as_::<libc::c_int>()
+ w1 * dst1[(j * 384 + i) as usize].as_::<libc::c_int>();
*p.offset(i as isize) = iclip(
*p.offset(i as isize) = bd.iclip_pixel(
(*p.offset(i as isize)).as_::<libc::c_int>()
+ (v + ((1 as libc::c_int) << 10) >> 11),
0 as libc::c_int,
bd.bitdepth_max().as_(),
)
.as_();
);
i += 1;
}
p = p.offset(BD::pxstride(stride as usize) as isize);
Expand Down
25 changes: 13 additions & 12 deletions src/looprestoration_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,17 +131,18 @@ pub type pixel = uint16_t;
pub type coef = int32_t;
pub type const_left_pixel_row = *const [pixel; 4];

#[cfg(feature = "asm")]
cfg_if! {
if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::LooprestorationParams;
}
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64")))]
#[rustfmt::skip]
use crate::{
src::looprestoration::LrEdgeFlags,
src::looprestoration::LooprestorationParams,
};

use crate::src::looprestoration::sgr_3x3_c_erased;
use crate::src::looprestoration::sgr_5x5_c_erased;
use crate::src::looprestoration::sgr_mix_c_erased;
use crate::src::looprestoration::wiener_c_erased;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;
use crate::src::looprestoration::{sgr_3x3_c, sgr_5x5_c, sgr_mix_c};

#[inline]
unsafe extern "C" fn PXSTRIDE(x: ptrdiff_t) -> ptrdiff_t {
Expand Down Expand Up @@ -673,9 +674,9 @@ pub unsafe extern "C" fn dav1d_loop_restoration_dsp_init_16bpc(
) {
(*c).wiener[1] = wiener_c_erased::<BitDepth16>;
(*c).wiener[0] = (*c).wiener[1];
(*c).sgr[0] = sgr_5x5_c::<BitDepth16>;
(*c).sgr[1] = sgr_3x3_c::<BitDepth16>;
(*c).sgr[2] = sgr_mix_c::<BitDepth16>;
(*c).sgr[0] = sgr_5x5_c_erased::<BitDepth16>;
(*c).sgr[1] = sgr_3x3_c_erased::<BitDepth16>;
(*c).sgr[2] = sgr_mix_c_erased::<BitDepth16>;

#[cfg(feature = "asm")]
cfg_if! {
Expand Down
25 changes: 13 additions & 12 deletions src/looprestoration_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,18 +126,19 @@ extern "C" {
pub type pixel = uint8_t;
pub type coef = int16_t;
pub type const_left_pixel_row = *const [pixel; 4];
use crate::src::looprestoration::sgr_3x3_c_erased;
use crate::src::looprestoration::sgr_5x5_c_erased;
use crate::src::looprestoration::sgr_mix_c_erased;
use crate::src::looprestoration::wiener_c_erased;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;
use crate::src::looprestoration::{sgr_3x3_c, sgr_5x5_c, sgr_mix_c};

#[cfg(feature = "asm")]
cfg_if! {
if #[cfg(any(target_arch = "arm", target_arch = "aarch64"))] {
use crate::include::stddef::*;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::LooprestorationParams;
}
}
#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64")))]
#[rustfmt::skip]
use crate::{
include::stddef::ptrdiff_t,
src::looprestoration::LrEdgeFlags,
src::looprestoration::LooprestorationParams,
};

#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))]
#[inline(always)]
Expand Down Expand Up @@ -634,9 +635,9 @@ pub unsafe extern "C" fn dav1d_loop_restoration_dsp_init_8bpc(
) {
(*c).wiener[1] = wiener_c_erased::<BitDepth8>;
(*c).wiener[0] = (*c).wiener[1];
(*c).sgr[0] = sgr_5x5_c::<BitDepth8>;
(*c).sgr[1] = sgr_3x3_c::<BitDepth8>;
(*c).sgr[2] = sgr_mix_c::<BitDepth8>;
(*c).sgr[0] = sgr_5x5_c_erased::<BitDepth8>;
(*c).sgr[1] = sgr_3x3_c_erased::<BitDepth8>;
(*c).sgr[2] = sgr_mix_c_erased::<BitDepth8>;

#[cfg(feature = "asm")]
cfg_if! {
Expand Down

0 comments on commit ff71f18

Please sign in to comment.