Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

struct Dav1dLoopRestorationDSPContext: Deduplicate via type-erased fn pointers #332

Merged
merged 8 commits into from
Jul 20, 2023
Merged
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 1 addition & 22 deletions src/cdef_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,29 +238,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut pixel,
ptrdiff_t,
const_left_pixel_row,
*const pixel,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
libc::c_int,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const [pixel; 4];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/cdef_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,28 +239,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut pixel,
ptrdiff_t,
const_left_pixel_row,
*const pixel,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const [pixel; 4];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,28 +342,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut libc::c_void,
ptrdiff_t,
const_left_pixel_row,
*const libc::c_void,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const libc::c_void;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,28 +519,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut libc::c_void,
ptrdiff_t,
const_left_pixel_row,
*const libc::c_void,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const libc::c_void;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
23 changes: 1 addition & 22 deletions src/lf_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,29 +235,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut pixel,
ptrdiff_t,
const_left_pixel_row,
*const pixel,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
libc::c_int,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const [pixel; 4];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/lf_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -236,28 +236,8 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut pixel,
ptrdiff_t,
const_left_pixel_row,
*const pixel,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type const_left_pixel_row = *const [pixel; 4];
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -232,29 +232,9 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut libc::c_void,
ptrdiff_t,
const_left_pixel_row,
*const libc::c_void,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type pixel = ();
pub type const_left_pixel_row = *const libc::c_void;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
22 changes: 1 addition & 21 deletions src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,29 +105,9 @@ pub struct Dav1dDSPContext {
pub cdef: Dav1dCdefDSPContext,
pub lr: Dav1dLoopRestorationDSPContext,
}
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}
pub type looprestorationfilter_fn = Option<
unsafe extern "C" fn(
*mut libc::c_void,
ptrdiff_t,
const_left_pixel_row,
*const libc::c_void,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
) -> (),
>;
use crate::src::looprestoration::LooprestorationParams;
use crate::src::looprestoration::LrEdgeFlags;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;

pub type pixel = ();
pub type const_left_pixel_row = *const libc::c_void;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dCdefDSPContext {
Expand Down
113 changes: 113 additions & 0 deletions src/looprestoration.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::include::stddef::ptrdiff_t;
use crate::include::stdint::int16_t;
use crate::include::stdint::uint32_t;
use crate::src::align::Align16;
Expand All @@ -23,3 +24,115 @@ pub union LooprestorationParams {
pub filter: Align16<[[int16_t; 8]; 2]>,
pub sgr: LooprestorationParams_sgr,
}

type pixel = libc::c_void;
pub type const_left_pixel_row = *const libc::c_void; // *const [pixel; 4]

pub type looprestorationfilter_fn = Option<
randomPoison marked this conversation as resolved.
Show resolved Hide resolved
unsafe extern "C" fn(
*mut pixel,
ptrdiff_t,
const_left_pixel_row,
*const pixel,
libc::c_int,
libc::c_int,
*const LooprestorationParams,
LrEdgeFlags,
libc::c_int,
) -> (),
>;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dLoopRestorationDSPContext {
pub wiener: [looprestorationfilter_fn; 2],
pub sgr: [looprestorationfilter_fn; 3],
}

macro_rules! decl_looprestorationfilter_fn {
( $( fn $name:ident, )* ) => {
extern "C" {
$(
// TODO(randomPoison): Temporarily pub until init fns are deduplicated.
pub(crate) fn $name(
dst: *mut pixel,
dst_stride: ptrdiff_t,
left: const_left_pixel_row,
lpf: *const pixel,
w: libc::c_int,
h: libc::c_int,
params: *const LooprestorationParams,
edges: LrEdgeFlags,
bitdepth_max: libc::c_int,
);
)*
}
};
}

#[cfg(all(
feature = "bitdepth_8",
feature = "asm",
any(target_arch = "x86", target_arch = "x86_64"),
))]
decl_looprestorationfilter_fn! {
randomPoison marked this conversation as resolved.
Show resolved Hide resolved
fn dav1d_wiener_filter7_8bpc_sse2,
fn dav1d_wiener_filter5_8bpc_sse2,
fn dav1d_wiener_filter7_8bpc_ssse3,
fn dav1d_wiener_filter5_8bpc_ssse3,
fn dav1d_wiener_filter5_8bpc_avx2,
fn dav1d_wiener_filter7_8bpc_avx2,
fn dav1d_wiener_filter7_8bpc_avx512icl,
fn dav1d_sgr_filter_mix_8bpc_avx512icl,
fn dav1d_sgr_filter_3x3_8bpc_avx512icl,
fn dav1d_sgr_filter_5x5_8bpc_avx512icl,
fn dav1d_sgr_filter_mix_8bpc_avx2,
fn dav1d_sgr_filter_3x3_8bpc_avx2,
fn dav1d_sgr_filter_5x5_8bpc_avx2,
fn dav1d_sgr_filter_mix_8bpc_ssse3,
fn dav1d_sgr_filter_3x3_8bpc_ssse3,
fn dav1d_sgr_filter_5x5_8bpc_ssse3,
}

#[cfg(all(
feature = "bitdepth_16",
feature = "asm",
any(target_arch = "x86", target_arch = "x86_64"),
))]
decl_looprestorationfilter_fn! {
fn dav1d_wiener_filter5_16bpc_ssse3,
fn dav1d_wiener_filter7_16bpc_ssse3,
fn dav1d_wiener_filter5_16bpc_avx2,
fn dav1d_wiener_filter7_16bpc_avx2,
fn dav1d_wiener_filter5_16bpc_avx512icl,
fn dav1d_wiener_filter7_16bpc_avx512icl,
fn dav1d_sgr_filter_mix_16bpc_ssse3,
fn dav1d_sgr_filter_3x3_16bpc_ssse3,
fn dav1d_sgr_filter_5x5_16bpc_ssse3,
fn dav1d_sgr_filter_mix_16bpc_avx2,
fn dav1d_sgr_filter_3x3_16bpc_avx2,
fn dav1d_sgr_filter_5x5_16bpc_avx2,
fn dav1d_sgr_filter_5x5_16bpc_avx512icl,
fn dav1d_sgr_filter_3x3_16bpc_avx512icl,
fn dav1d_sgr_filter_mix_16bpc_avx512icl,
}

#[cfg(all(
feature = "bitdepth_8",
feature = "asm",
any(target_arch = "arm", target_arch = "aarch64"),
))]
decl_looprestorationfilter_fn! {
fn dav1d_wiener_filter7_8bpc_neon,
fn dav1d_wiener_filter5_8bpc_neon,
}

#[cfg(all(
feature = "bitdepth_16",
feature = "asm",
any(target_arch = "arm", target_arch = "aarch64"),
))]
decl_looprestorationfilter_fn! {
fn dav1d_wiener_filter7_16bpc_neon,
fn dav1d_wiener_filter5_16bpc_neon,
}
Loading