Skip to content

Commit

Permalink
Port C code changes to Rust
Browse files Browse the repository at this point in the history
  • Loading branch information
Frank Bossen committed Jul 17, 2024
1 parent f3c7b67 commit 3ae38b3
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 3 deletions.
19 changes: 18 additions & 1 deletion build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ mod asm {
if let Arch::Arm(arch) = arch {
define(Define::bool("ARCH_ARM", arch == ArchArm::Arm32));
define(Define::bool("ARCH_AARCH64", arch == ArchArm::Arm64));

if arch == ArchArm::Arm64 {
define(Define::bool("HAVE_DOTPROD", features.contains("dotprod")));
}
if arch == ArchArm::Arm64 {
define(Define::bool("HAVE_I8MM", features.contains("i8mm")));
}
}

if let Arch::X86(arch) = arch {
Expand Down Expand Up @@ -199,6 +206,7 @@ mod asm {
][..];

let arm_generic = &["itx", "msac", "refmvs", "looprestoration_common"][..];
let arm_dotprod = &["mc_dotprod"][..];
let arm_bpc8 = &[
"cdef",
"filmgrain",
Expand Down Expand Up @@ -243,11 +251,20 @@ mod asm {
#[cfg(feature = "bitdepth_16")]
arm_bpc16,
][..];
let arm64_all = &[
arm_generic,
arm_dotprod,
#[cfg(feature = "bitdepth_8")]
arm_bpc8,
#[cfg(feature = "bitdepth_16")]
arm_bpc16,
][..];

let asm_file_names = match arch {
Arch::X86(ArchX86::X86_32) => x86_all,
Arch::X86(ArchX86::X86_64) => x86_64_all,
Arch::Arm(..) => arm_all,
Arch::Arm(ArchArm::Arm32) => arm_all,
Arch::Arm(ArchArm::Arm64) => arm64_all,
};

let asm_file_dir = match arch {
Expand Down
10 changes: 8 additions & 2 deletions include/common/bitdepth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -457,7 +457,10 @@ macro_rules! bd_fn {
///
/// Similar to [`bd_fn!`] except that it selects which [`BitDepth`] `fn`
/// based on `$bpc:literal bpc` instead of `$BD:ty`.
#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(all(
feature = "asm",
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
macro_rules! bpc_fn {
($bpc:literal bpc, $name:ident, $asm:ident) => {{
use $crate::include::common::bitdepth::fn_identity;
Expand Down Expand Up @@ -487,7 +490,10 @@ macro_rules! fn_identity {
))]
pub(crate) use bd_fn;

#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))]
#[cfg(all(
feature = "asm",
any(target_arch = "x86", target_arch = "x86_64", target_arch = "aarch64")
))]
pub(crate) use bpc_fn;

#[allow(unused)]
Expand Down
67 changes: 67 additions & 0 deletions src/mc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ use crate::include::common::bitdepth::bd_fn;
#[cfg(all(feature = "asm", any(target_arch = "x86", target_arch = "x86_64")))]
use crate::include::common::bitdepth::{bpc_fn, BPC};

#[cfg(all(feature = "asm", target_arch = "aarch64"))]
use crate::include::common::bitdepth::bpc_fn;

#[inline(never)]
fn put_rust<BD: BitDepth>(
dst: Rav1dPictureDataComponentOffset,
Expand Down Expand Up @@ -2300,6 +2303,70 @@ impl Rav1dMCDSPContext {
self.warp8x8t = bd_fn!(warp8x8t::decl_fn, BD, warp_affine_8x8t, neon);
self.emu_edge = bd_fn!(emu_edge::decl_fn, BD, emu_edge, neon);

#[cfg(target_feature = "dotprod")]
if BD::BITDEPTH == 8 {
if !flags.contains(CpuFlags::DOTPROD) {
return self;
}

self.mc = enum_map!(Filter2d => mc::Fn; match key {
Regular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular, neon_dotprod),
RegularSmooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular_smooth, neon_dotprod),
RegularSharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular_sharp, neon_dotprod),
SmoothRegular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth_regular, neon_dotprod),
Smooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth, neon_dotprod),
SmoothSharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth_sharp, neon_dotprod),
SharpRegular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp_regular, neon_dotprod),
SharpSmooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp_smooth, neon_dotprod),
Sharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp, neon_dotprod),
Bilinear => bpc_fn!(mc::decl_fn, 8 bpc, put_bilin, neon),
});
self.mct = enum_map!(Filter2d => mct::Fn; match key {
Regular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular, neon_dotprod),
RegularSmooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular_smooth, neon_dotprod),
RegularSharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular_sharp, neon_dotprod),
SmoothRegular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth_regular, neon_dotprod),
Smooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth, neon_dotprod),
SmoothSharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth_sharp, neon_dotprod),
SharpRegular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp_regular, neon_dotprod),
SharpSmooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp_smooth, neon_dotprod),
Sharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp, neon_dotprod),
Bilinear => bpc_fn!(mct::decl_fn, 8 bpc, prep_bilin, neon),
});
}

#[cfg(target_feature = "i8mm")]
if BD::BITDEPTH == 8 {
if !flags.contains(CpuFlags::I8MM) {
return self;
}

self.mc = enum_map!(Filter2d => mc::Fn; match key {
Regular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular, neon_i8mm),
RegularSmooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular_smooth, neon_i8mm),
RegularSharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_regular_sharp, neon_i8mm),
SmoothRegular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth_regular, neon_i8mm),
Smooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth, neon_i8mm),
SmoothSharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_smooth_sharp, neon_i8mm),
SharpRegular8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp_regular, neon_i8mm),
SharpSmooth8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp_smooth, neon_i8mm),
Sharp8Tap => bpc_fn!(mc::decl_fn, 8 bpc, put_8tap_sharp, neon_i8mm),
Bilinear => bpc_fn!(mc::decl_fn, 8 bpc, put_bilin, neon),
});
self.mct = enum_map!(Filter2d => mct::Fn; match key {
Regular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular, neon_i8mm),
RegularSmooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular_smooth, neon_i8mm),
RegularSharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_regular_sharp, neon_i8mm),
SmoothRegular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth_regular, neon_i8mm),
Smooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth, neon_i8mm),
SmoothSharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_smooth_sharp, neon_i8mm),
SharpRegular8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp_regular, neon_i8mm),
SharpSmooth8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp_smooth, neon_i8mm),
Sharp8Tap => bpc_fn!(mct::decl_fn, 8 bpc, prep_8tap_sharp, neon_i8mm),
Bilinear => bpc_fn!(mct::decl_fn, 8 bpc, prep_bilin, neon),
});
}

self
}

Expand Down

0 comments on commit 3ae38b3

Please sign in to comment.