Debian Codegraph @

.cargo/vendor/av-scenechange/src/data/mc/simd_neon.rs

raw
1 use v_frame::{
2 pixel::{Pixel, PixelType},
3 plane::PlaneSlice,
4 };
5
6 use crate::{
7 cpu::CpuFeatureLevel,
8 data::{
9 mc::{FilterMode, FilterMode::*},
10 plane::PlaneRegionMut,
11 },
12 };
13
14 #[allow(clippy::too_many_arguments)]
15 pub fn put_8tap_internal<T: Pixel>(
16 dst: &mut PlaneRegionMut<'_, T>,
17 src: PlaneSlice<'_, T>,
18 width: usize,
19 height: usize,
20 col_frac: i32,
21 row_frac: i32,
22 bit_depth: usize,
23 cpu: CpuFeatureLevel,
24 ) {
25 let call_rust = |dst: &mut PlaneRegionMut<'_, T>| {
26 super::rust::put_8tap_internal(dst, src, width, height, col_frac, row_frac, bit_depth, cpu);
27 };
28
29 unsafe {
30 // SAFETY: The assembly only supports even heights and valid uncropped
31 // widths
32 assert_eq!(height & 1, 0);
33 assert!(width.is_power_of_two() && (2..=128).contains(&width));
34
35 // SAFETY: Check bounds of dst
36 assert!(dst.rect().width >= width && dst.rect().height >= height);
37
38 // SAFETY: Check bounds of src
39 assert!(src.accessible(width + 4, height + 4));
40 assert!(src.accessible_neg(3, 3));
41
42 match T::type_enum() {
43 PixelType::U8 => match PUT_FNS[cpu.as_index()]
44 [get_2d_mode_idx(FilterMode::REGULAR, FilterMode::REGULAR)]
45 {
46 Some(func) => (func)(
47 dst.data_ptr_mut() as *mut _,
48 T::to_asm_stride(dst.plane_cfg.stride),
49 src.as_ptr() as *const _,
50 T::to_asm_stride(src.plane.cfg.stride),
51 width as i32,
52 height as i32,
53 col_frac,
54 row_frac,
55 ),
56 None => call_rust(dst),
57 },
58 PixelType::U16 if bit_depth > 8 => {
59 match PUT_HBD_FNS[cpu.as_index()]
60 [get_2d_mode_idx(FilterMode::REGULAR, FilterMode::REGULAR)]
61 {
62 Some(func) => (func)(
63 dst.data_ptr_mut() as *mut _,
64 T::to_asm_stride(dst.plane_cfg.stride),
65 src.as_ptr() as *const _,
66 T::to_asm_stride(src.plane.cfg.stride),
67 width as i32,
68 height as i32,
69 col_frac,
70 row_frac,
71 (1 << bit_depth) - 1,
72 ),
73 None => call_rust(dst),
74 }
75 }
76 _ => call_rust(dst),
77 }
78 }
79 }
80
81 // gets an index that can be mapped to a function for a pair of filter modes
82 const fn get_2d_mode_idx(mode_x: FilterMode, mode_y: FilterMode) -> usize {
83 (mode_x as usize + 4 * (mode_y as usize)) & 15
84 }
85
86 type PutFn = unsafe extern "C" fn(
87 dst: *mut u8,
88 dst_stride: isize,
89 src: *const u8,
90 src_stride: isize,
91 width: i32,
92 height: i32,
93 col_frac: i32,
94 row_frac: i32,
95 );
96
97 type PutHBDFn = unsafe extern "C" fn(
98 dst: *mut u16,
99 dst_stride: isize,
100 src: *const u16,
101 src_stride: isize,
102 width: i32,
103 height: i32,
104 col_frac: i32,
105 row_frac: i32,
106 bitdepth_max: i32,
107 );
108
109 macro_rules! decl_mc_fns {
110 ($(($mode_x:expr, $mode_y:expr, $func_name:ident)),+) => {
111 extern "C" {
112 $(
113 fn $func_name(
114 dst: *mut u8, dst_stride: isize, src: *const u8, src_stride: isize,
115 w: i32, h: i32, mx: i32, my: i32,
116 );
117 )*
118 }
119
120 static PUT_FNS_NEON: [Option<PutFn>; 16] = {
121 let mut out: [Option<PutFn>; 16] = [None; 16];
122 $(
123 out[get_2d_mode_idx($mode_x, $mode_y)] = Some($func_name);
124 )*
125 out
126 };
127 }
128 }
129
130 decl_mc_fns!(
131 (REGULAR, REGULAR, avsc_put_8tap_regular_8bpc_neon),
132 (REGULAR, SMOOTH, avsc_put_8tap_regular_smooth_8bpc_neon),
133 (REGULAR, SHARP, avsc_put_8tap_regular_sharp_8bpc_neon),
134 (SMOOTH, REGULAR, avsc_put_8tap_smooth_regular_8bpc_neon),
135 (SMOOTH, SMOOTH, avsc_put_8tap_smooth_8bpc_neon),
136 (SMOOTH, SHARP, avsc_put_8tap_smooth_sharp_8bpc_neon),
137 (SHARP, REGULAR, avsc_put_8tap_sharp_regular_8bpc_neon),
138 (SHARP, SMOOTH, avsc_put_8tap_sharp_smooth_8bpc_neon),
139 (SHARP, SHARP, avsc_put_8tap_sharp_8bpc_neon),
140 (BILINEAR, BILINEAR, avsc_put_bilin_8bpc_neon)
141 );
142
143 cpu_function_lookup_table!(
144 PUT_FNS: [[Option<PutFn>; 16]],
145 default: [None; 16],
146 [NEON]
147 );
148
149 macro_rules! decl_mc_hbd_fns {
150 ($(($mode_x:expr, $mode_y:expr, $func_name:ident)),+) => {
151 extern "C" {
152 $(
153 fn $func_name(
154 dst: *mut u16, dst_stride: isize, src: *const u16, src_stride: isize,
155 w: i32, h: i32, mx: i32, my: i32, bitdepth_max: i32,
156 );
157 )*
158 }
159
160 static PUT_HBD_FNS_NEON: [Option<PutHBDFn>; 16] = {
161 let mut out: [Option<PutHBDFn>; 16] = [None; 16];
162 $(
163 out[get_2d_mode_idx($mode_x, $mode_y)] = Some($func_name);
164 )*
165 out
166 };
167 }
168 }
169
170 decl_mc_hbd_fns!(
171 (REGULAR, REGULAR, avsc_put_8tap_regular_16bpc_neon),
172 (REGULAR, SMOOTH, avsc_put_8tap_regular_smooth_16bpc_neon),
173 (REGULAR, SHARP, avsc_put_8tap_regular_sharp_16bpc_neon),
174 (SMOOTH, REGULAR, avsc_put_8tap_smooth_regular_16bpc_neon),
175 (SMOOTH, SMOOTH, avsc_put_8tap_smooth_16bpc_neon),
176 (SMOOTH, SHARP, avsc_put_8tap_smooth_sharp_16bpc_neon),
177 (SHARP, REGULAR, avsc_put_8tap_sharp_regular_16bpc_neon),
178 (SHARP, SMOOTH, avsc_put_8tap_sharp_smooth_16bpc_neon),
179 (SHARP, SHARP, avsc_put_8tap_sharp_16bpc_neon),
180 (BILINEAR, BILINEAR, avsc_put_bilin_16bpc_neon)
181 );
182
183 cpu_function_lookup_table!(
184 PUT_HBD_FNS: [[Option<PutHBDFn>; 16]],
185 default: [None; 16],
186 [NEON]
187 );