1cfg_if::cfg_if! {
11 if #[cfg(nasm_x86_64)] {
12 use crate::asm::x86::sad_plane::*;
13 } else {
14 use self::rust::*;
15 }
16}
17
18use v_frame::plane::Plane;
19
20use crate::cpu_features::CpuFeatureLevel;
21use crate::util::{CastFromPrimitive, Pixel};
22
23pub(crate) mod rust {
24 use super::*;
25 use crate::cpu_features::CpuFeatureLevel;
26
27 #[inline]
28 pub(crate) fn sad_plane_internal<T: Pixel>(
29 src: &Plane<T>, dst: &Plane<T>, _cpu: CpuFeatureLevel,
30 ) -> u64 {
31 debug_assert!(src.cfg.width == dst.cfg.width);
32 debug_assert!(src.cfg.height == dst.cfg.height);
33
34 src
35 .rows_iter()
36 .zip(dst.rows_iter())
37 .map(|(src, dst)| {
38 src
39 .iter()
40 .zip(dst.iter())
41 .map(|(&p1, &p2)| i32::cast_from(p1).abs_diff(i32::cast_from(p2)))
42 .sum::<u32>() as u64
43 })
44 .sum()
45 }
46}
47
48pub(crate) fn sad_plane<T: Pixel>(
53 src: &Plane<T>, dst: &Plane<T>, cpu: CpuFeatureLevel,
54) -> u64 {
55 sad_plane_internal(src, dst, cpu)
56}