Debian Codegraph @

.cargo/vendor/av-scenechange/src/data/sad/simd_x86.rs

raw
1 use v_frame::{
2 pixel::{Pixel, PixelType},
3 plane::Plane,
4 };
5
6 use crate::CpuFeatureLevel;
7
8 macro_rules! decl_sad_plane_fn {
9 ($($f:ident),+) => {
10 extern "C" {
11 $(
12 fn $f(
13 src: *const u8, dst: *const u8, stride: libc::size_t,
14 width: libc::size_t, rows: libc::size_t
15 ) -> u64;
16 )*
17 }
18 };
19 }
20
21 decl_sad_plane_fn!(avsc_sad_plane_8bpc_sse2, avsc_sad_plane_8bpc_avx2);
22
23 pub(super) fn sad_plane_internal<T: Pixel>(
24 src: &Plane<T>,
25 dst: &Plane<T>,
26 cpu: CpuFeatureLevel,
27 ) -> u64 {
28 use std::mem;
29
30 assert_eq!(src.cfg.width, dst.cfg.width);
31 assert_eq!(src.cfg.stride, dst.cfg.stride);
32 assert_eq!(src.cfg.height, dst.cfg.height);
33 assert!(src.cfg.width <= src.cfg.stride);
34
35 match T::type_enum() {
36 PixelType::U8 => {
37 // helper macro to reduce boilerplate
38 macro_rules! call_asm {
39 ($func:ident, $src:expr, $dst:expr, $cpu:expr) => {
40 // SAFETY: Calls Assembly code.
41 unsafe {
42 let result = $func(
43 mem::transmute::<*const T, *const u8>(src.data_origin().as_ptr()),
44 mem::transmute::<*const T, *const u8>(dst.data_origin().as_ptr()),
45 src.cfg.stride,
46 src.cfg.width,
47 src.cfg.height,
48 );
49
50 result
51 }
52 };
53 }
54
55 if cpu >= CpuFeatureLevel::AVX2 {
56 call_asm!(avsc_sad_plane_8bpc_avx2, src, dst, cpu)
57 } else if cpu >= CpuFeatureLevel::SSE2 {
58 call_asm!(avsc_sad_plane_8bpc_sse2, src, dst, cpu)
59 } else {
60 super::rust::sad_plane_internal(src, dst, cpu)
61 }
62 }
63 PixelType::U16 => super::rust::sad_plane_internal(src, dst, cpu),
64 }
65 }