Skip to content

Commit

Permalink
struct Dav1dInvTxfmDSPContext: Type-erase fn ptrs and deduplicate (
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison authored Aug 29, 2023
1 parent 6ece9fc commit b6de7e2
Show file tree
Hide file tree
Showing 18 changed files with 765 additions and 17,360 deletions.
8 changes: 1 addition & 7 deletions src/cdef_apply_tmpl_16.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,16 +245,10 @@ use crate::src::cdef::CDEF_HAVE_BOTTOM;
use crate::src::cdef::CDEF_HAVE_LEFT;
use crate::src::cdef::CDEF_HAVE_RIGHT;
use crate::src::cdef::CDEF_HAVE_TOP;
use crate::src::itx::Dav1dInvTxfmDSPContext;
use crate::src::loopfilter::Dav1dLoopFilterDSPContext;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dInvTxfmDSPContext {
pub itxfm_add: [[itxfm_fn; 17]; 19],
}
pub type itxfm_fn =
Option<unsafe extern "C" fn(*mut pixel, ptrdiff_t, *mut coef, libc::c_int, libc::c_int) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMCDSPContext {
pub mc: [mc_fn; 10],
pub mc_scaled: [mc_scaled_fn; 10],
Expand Down
8 changes: 1 addition & 7 deletions src/cdef_apply_tmpl_8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,16 +246,10 @@ use crate::src::cdef::CDEF_HAVE_BOTTOM;
use crate::src::cdef::CDEF_HAVE_LEFT;
use crate::src::cdef::CDEF_HAVE_RIGHT;
use crate::src::cdef::CDEF_HAVE_TOP;
use crate::src::itx::Dav1dInvTxfmDSPContext;
use crate::src::loopfilter::Dav1dLoopFilterDSPContext;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dInvTxfmDSPContext {
pub itxfm_add: [[itxfm_fn; 17]; 19],
}
pub type itxfm_fn =
Option<unsafe extern "C" fn(*mut pixel, ptrdiff_t, *mut coef, libc::c_int) -> ()>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMCDSPContext {
pub mc: [mc_fn; 10],
pub mc_scaled: [mc_scaled_fn; 10],
Expand Down
9 changes: 1 addition & 8 deletions src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,18 +342,11 @@ pub struct Dav1dDSPContext {
pub lr: Dav1dLoopRestorationDSPContext,
}
use crate::src::cdef::Dav1dCdefDSPContext;
use crate::src::itx::Dav1dInvTxfmDSPContext;
use crate::src::loopfilter::Dav1dLoopFilterDSPContext;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dInvTxfmDSPContext {
pub itxfm_add: [[itxfm_fn; 17]; 19],
}
pub type itxfm_fn = Option<
unsafe extern "C" fn(*mut libc::c_void, ptrdiff_t, *mut libc::c_void, libc::c_int) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMCDSPContext {
pub mc: [mc_fn; 10],
pub mc_scaled: [mc_scaled_fn; 10],
Expand Down
9 changes: 1 addition & 8 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -464,18 +464,11 @@ pub struct Dav1dDSPContext {
pub lr: Dav1dLoopRestorationDSPContext,
}
use crate::src::cdef::Dav1dCdefDSPContext;
use crate::src::itx::Dav1dInvTxfmDSPContext;
use crate::src::loopfilter::Dav1dLoopFilterDSPContext;
use crate::src::looprestoration::Dav1dLoopRestorationDSPContext;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dInvTxfmDSPContext {
pub itxfm_add: [[itxfm_fn; 17]; 19],
}
pub type itxfm_fn = Option<
unsafe extern "C" fn(*mut libc::c_void, ptrdiff_t, *mut libc::c_void, libc::c_int) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dMCDSPContext {
pub mc: [mc_fn; 10],
pub mc_scaled: [mc_scaled_fn; 10],
Expand Down
276 changes: 276 additions & 0 deletions src/itx.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::include::common::bitdepth::AsPrimitive;
use crate::include::common::bitdepth::BitDepth;
use crate::include::common::bitdepth::DynCoef;
use crate::include::common::bitdepth::DynPixel;
use crate::include::common::intops::iclip;
use crate::include::common::intops::imin;
use crate::include::stddef::*;
Expand Down Expand Up @@ -137,3 +139,277 @@ pub unsafe extern "C" fn inv_txfm_add_rust<BD: BitDepth>(
dst = dst.offset(BD::pxstride(stride) as isize);
}
}

pub type itxfm_fn = Option<
unsafe extern "C" fn(*mut DynPixel, ptrdiff_t, *mut DynCoef, libc::c_int, libc::c_int) -> (),
>;
#[derive(Copy, Clone)]
#[repr(C)]
pub struct Dav1dInvTxfmDSPContext {
pub itxfm_add: [[itxfm_fn; 17]; 19],
}

#[cfg(feature = "asm")]
macro_rules! decl_itx_fn {
($name:ident) => {
// TODO(legare): Temporarily pub until init fns are deduplicated.
pub(crate) fn $name(
dst: *mut DynPixel,
dst_stride: ptrdiff_t,
coeff: *mut DynCoef,
eob: libc::c_int,
bitdepth_max: libc::c_int,
);
};

($prefix:ident, $opt:ident) => {
paste::paste! {
decl_itx_fn!($prefix, _8bpc, $opt);
decl_itx_fn!($prefix, _16bpc, $opt);
}
};

($prefix:ident, $bpc:ident, $opt:ident) => {
paste::paste! {
decl_itx_fn!([<$prefix $bpc $opt>]);
}
};
}

#[cfg(feature = "asm")]
macro_rules! decl_itx2_fns {
($wxh:ident, $opt:ident) => {
paste::paste! {
decl_itx_fn!([<dav1d_inv_txfm_add_dct_dct $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_identity $wxh>], $opt);
}
};

($wxh:ident, $bpc:ident, $opt:ident) => {
paste::paste! {
decl_itx_fn!([<dav1d_inv_txfm_add_dct_dct $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_identity $wxh>], $bpc, $opt);
}
};
}

#[cfg(feature = "asm")]
macro_rules! decl_itx12_fns {
($wxh:ident, $opt:ident) => {
paste::paste! {
decl_itx2_fns!($wxh, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_adst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_flipadst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_identity $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_dct $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_adst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_flipadst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_dct $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_adst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_flipadst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_dct $wxh>], $opt);
}
};

($wxh:ident, $bpc:ident, $opt:ident) => {
paste::paste! {
decl_itx2_fns!($wxh, $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_adst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_flipadst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_dct_identity $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_dct $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_adst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_flipadst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_dct $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_adst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_flipadst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_dct $wxh>], $bpc, $opt);
}
};
}

#[cfg(feature = "asm")]
macro_rules! decl_itx16_fns {
($wxh:ident, $opt:ident) => {
paste::paste! {
decl_itx12_fns!($wxh, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_identity $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_identity $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_adst $wxh>], $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_flipadst $wxh>], $opt);
}
};

($wxh:ident, $bpc:ident, $opt:ident) => {
paste::paste! {
decl_itx12_fns!($wxh, $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_adst_identity $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_flipadst_identity $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_adst $wxh>], $bpc, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_identity_flipadst $wxh>], $bpc, $opt);
}
};
}

#[cfg(feature = "asm")]
macro_rules! decl_itx17_fns {
($wxh:ident, $opt:ident) => {
paste::paste! {
decl_itx16_fns!($wxh, $opt);
decl_itx_fn!([<dav1d_inv_txfm_add_wht_wht $wxh>], $opt);
}
};
}

#[cfg(feature = "asm")]
macro_rules! decl_itx_fns {
($ext:ident) => {
decl_itx17_fns!(_4x4, $ext);
decl_itx16_fns!(_4x8, $ext);
decl_itx16_fns!(_4x16, $ext);
decl_itx16_fns!(_8x4, $ext);
decl_itx16_fns!(_8x8, $ext);
decl_itx16_fns!(_8x16, $ext);
decl_itx2_fns!(_8x32, $ext);
decl_itx16_fns!(_16x4, $ext);
decl_itx16_fns!(_16x8, $ext);
decl_itx12_fns!(_16x16, $ext);
decl_itx2_fns!(_16x32, $ext);
decl_itx2_fns!(_32x8, $ext);
decl_itx2_fns!(_32x16, $ext);
decl_itx2_fns!(_32x32, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_16x64, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_32x64, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x16, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x32, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x64, $ext);
};

($bpc:ident, $ext:ident) => {
decl_itx16_fns!(_4x4, $bpc, $ext);
decl_itx16_fns!(_4x8, $bpc, $ext);
decl_itx16_fns!(_4x16, $bpc, $ext);
decl_itx16_fns!(_8x4, $bpc, $ext);
decl_itx16_fns!(_8x8, $bpc, $ext);
decl_itx16_fns!(_8x16, $bpc, $ext);
decl_itx2_fns!(_8x32, $bpc, $ext);
decl_itx16_fns!(_16x4, $bpc, $ext);
decl_itx16_fns!(_16x8, $bpc, $ext);
decl_itx12_fns!(_16x16, $bpc, $ext);
decl_itx2_fns!(_16x32, $bpc, $ext);
decl_itx2_fns!(_32x8, $bpc, $ext);
decl_itx2_fns!(_32x16, $bpc, $ext);
decl_itx2_fns!(_32x32, $bpc, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_16x64, $bpc, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_32x64, $bpc, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x16, $bpc, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x32, $bpc, $ext);
decl_itx_fn!(dav1d_inv_txfm_add_dct_dct_64x64, $bpc, $ext);
};
}

#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))]
extern "C" {
decl_itx_fns!(_avx512icl);
decl_itx_fns!(_10bpc, _avx512icl);
decl_itx_fns!(_avx2);
decl_itx_fns!(_10bpc, _avx2);
decl_itx_fns!(_12bpc, _avx2);
decl_itx_fns!(_sse4);
decl_itx_fns!(_ssse3);
decl_itx_fn!(dav1d_inv_txfm_add_wht_wht_4x4, _sse2);
}

#[cfg(all(feature = "asm", any(target_arch = "arm", target_arch = "aarch64")))]
extern "C" {
decl_itx_fns!(_neon);
}

macro_rules! inv_txfm_fn {
($type1:ident, $type2:ident, $w:literal, $h:literal, $shift:literal, $has_dconly:literal) => {
paste::paste! {
// TODO(legare): Temporarily pub until init fns are deduplicated.
pub(crate) unsafe extern "C" fn [<inv_txfm_add_ $type1 _ $type2 _ $w x $h _c_erased>] <BD: BitDepth> (
mut dst: *mut DynPixel,
stride: ptrdiff_t,
coeff: *mut DynCoef,
eob: libc::c_int,
bitdepth_max: libc::c_int,
) {
use crate::src::itx_1d::*;
inv_txfm_add_rust(
dst.cast(),
stride,
coeff.cast(),
eob,
$w,
$h,
$shift,
Some([<dav1d_inv_ $type1 $w _1d_c>]),
Some([<dav1d_inv_ $type2 $h _1d_c>]),
$has_dconly as libc::c_int,
BD::from_c(bitdepth_max),
);
}
}
};
}

macro_rules! inv_txfm_fn64 {
($w:literal, $h:literal, $shift:literal) => {
inv_txfm_fn!(dct, dct, $w, $h, $shift, true);
};
}

macro_rules! inv_txfm_fn32 {
($w:literal, $h:literal, $shift:literal) => {
inv_txfm_fn64!($w, $h, $shift);
inv_txfm_fn!(identity, identity, $w, $h, $shift, false);
};
}

macro_rules! inv_txfm_fn16 {
($w:literal, $h:literal, $shift:literal) => {
inv_txfm_fn32!($w, $h, $shift);
inv_txfm_fn!(adst, dct, $w, $h, $shift, false);
inv_txfm_fn!(dct, adst, $w, $h, $shift, false);
inv_txfm_fn!(adst, adst, $w, $h, $shift, false);
inv_txfm_fn!(dct, flipadst, $w, $h, $shift, false);
inv_txfm_fn!(flipadst, dct, $w, $h, $shift, false);
inv_txfm_fn!(adst, flipadst, $w, $h, $shift, false);
inv_txfm_fn!(flipadst, adst, $w, $h, $shift, false);
inv_txfm_fn!(flipadst, flipadst, $w, $h, $shift, false);
inv_txfm_fn!(identity, dct, $w, $h, $shift, false);
inv_txfm_fn!(dct, identity, $w, $h, $shift, false);
};
}

macro_rules! inv_txfm_fn84 {
($w:literal, $h:literal, $shift:literal) => {
inv_txfm_fn16!($w, $h, $shift);
inv_txfm_fn!(identity, flipadst, $w, $h, $shift, false);
inv_txfm_fn!(flipadst, identity, $w, $h, $shift, false);
inv_txfm_fn!(identity, adst, $w, $h, $shift, false);
inv_txfm_fn!(adst, identity, $w, $h, $shift, false);
};
}

inv_txfm_fn84!(4, 4, 0);
inv_txfm_fn84!(4, 8, 0);
inv_txfm_fn84!(4, 16, 1);
inv_txfm_fn84!(8, 4, 0);
inv_txfm_fn84!(8, 8, 1);
inv_txfm_fn84!(8, 16, 1);
inv_txfm_fn32!(8, 32, 2);
inv_txfm_fn84!(16, 4, 1);
inv_txfm_fn84!(16, 8, 1);
inv_txfm_fn16!(16, 16, 2);
inv_txfm_fn32!(16, 32, 1);
inv_txfm_fn64!(16, 64, 2);
inv_txfm_fn32!(32, 8, 2);
inv_txfm_fn32!(32, 16, 1);
inv_txfm_fn32!(32, 32, 2);
inv_txfm_fn64!(32, 64, 1);
inv_txfm_fn64!(64, 16, 2);
inv_txfm_fn64!(64, 32, 1);
inv_txfm_fn64!(64, 64, 2);
Loading

0 comments on commit b6de7e2

Please sign in to comment.