Debian Codegraph @

.cargo/vendor/av-scenechange/src/analyze/intra/simd_x86.rs

raw
1 use v_frame::pixel::{Pixel, PixelType};
2
3 use super::IntraEdge;
4 use crate::{
5 cpu::CpuFeatureLevel,
6 data::{block::TxSize, plane::PlaneRegionMut, prediction::PredictionVariant},
7 };
8
9 macro_rules! decl_angular_ipred_fn {
10 ($($f:ident),+) => {
11 extern "C" {
12 $(
13 fn $f(
14 dst: *mut u8, stride: libc::ptrdiff_t, topleft: *const u8,
15 width: libc::c_int, height: libc::c_int, angle: libc::c_int,
16 );
17 )*
18 }
19 };
20 }
21
22 decl_angular_ipred_fn! {
23 avsc_ipred_dc_8bpc_ssse3,
24 avsc_ipred_dc_8bpc_avx2,
25 avsc_ipred_dc_8bpc_avx512icl,
26 avsc_ipred_dc_left_8bpc_ssse3,
27 avsc_ipred_dc_left_8bpc_avx2,
28 avsc_ipred_dc_left_8bpc_avx512icl,
29 avsc_ipred_dc_128_8bpc_ssse3,
30 avsc_ipred_dc_128_8bpc_avx2,
31 avsc_ipred_dc_128_8bpc_avx512icl,
32 avsc_ipred_dc_top_8bpc_ssse3,
33 avsc_ipred_dc_top_8bpc_avx2,
34 avsc_ipred_dc_top_8bpc_avx512icl
35 }
36
37 macro_rules! decl_angular_ipred_hbd_fn {
38 ($($f:ident),+) => {
39 extern "C" {
40 $(
41 fn $f(
42 dst: *mut u16, stride: libc::ptrdiff_t, topleft: *const u16,
43 width: libc::c_int, height: libc::c_int, angle: libc::c_int,
44 max_width: libc::c_int, max_height: libc::c_int,
45 bit_depth_max: libc::c_int,
46 );
47 )*
48 }
49 };
50 }
51
52 decl_angular_ipred_hbd_fn! {
53 avsc_ipred_dc_16bpc_ssse3,
54 avsc_ipred_dc_16bpc_avx2,
55 avsc_ipred_dc_left_16bpc_ssse3,
56 avsc_ipred_dc_left_16bpc_avx2,
57 avsc_ipred_dc_128_16bpc_ssse3,
58 avsc_ipred_dc_128_16bpc_avx2,
59 avsc_ipred_dc_top_16bpc_ssse3,
60 avsc_ipred_dc_top_16bpc_avx2
61 }
62
63 pub(super) fn dispatch_predict_dc_intra<T: Pixel>(
64 variant: PredictionVariant,
65 dst: &mut PlaneRegionMut<'_, T>,
66 tx_size: TxSize,
67 bit_depth: usize,
68 edge_buf: &IntraEdge<T>,
69 cpu: CpuFeatureLevel,
70 ) {
71 let call_rust = |dst: &mut PlaneRegionMut<'_, T>| {
72 super::rust::dispatch_predict_dc_intra(variant, dst, tx_size, bit_depth, edge_buf, cpu);
73 };
74
75 // SAFETY: Calls Assembly code.
76 unsafe {
77 let stride = T::to_asm_stride(dst.plane_cfg.stride) as libc::ptrdiff_t;
78 let w = tx_size.width() as libc::c_int;
79 let h = tx_size.height() as libc::c_int;
80
81 match T::type_enum() {
82 PixelType::U8 => {
83 let dst_ptr = dst.data_ptr_mut() as *mut _;
84 let edge_ptr = edge_buf.top_left_ptr() as *const _;
85 if cpu >= CpuFeatureLevel::AVX512ICL {
86 (match variant {
87 PredictionVariant::NONE => avsc_ipred_dc_128_8bpc_avx512icl,
88 PredictionVariant::LEFT => avsc_ipred_dc_left_8bpc_avx512icl,
89 PredictionVariant::TOP => avsc_ipred_dc_top_8bpc_avx512icl,
90 PredictionVariant::BOTH => avsc_ipred_dc_8bpc_avx512icl,
91 })(dst_ptr, stride, edge_ptr, w, h, 0);
92 } else if cpu >= CpuFeatureLevel::AVX2 {
93 (match variant {
94 PredictionVariant::NONE => avsc_ipred_dc_128_8bpc_avx2,
95 PredictionVariant::LEFT => avsc_ipred_dc_left_8bpc_avx2,
96 PredictionVariant::TOP => avsc_ipred_dc_top_8bpc_avx2,
97 PredictionVariant::BOTH => avsc_ipred_dc_8bpc_avx2,
98 })(dst_ptr, stride, edge_ptr, w, h, 0);
99 } else if cpu >= CpuFeatureLevel::SSSE3 {
100 (match variant {
101 PredictionVariant::NONE => avsc_ipred_dc_128_8bpc_ssse3,
102 PredictionVariant::LEFT => avsc_ipred_dc_left_8bpc_ssse3,
103 PredictionVariant::TOP => avsc_ipred_dc_top_8bpc_ssse3,
104 PredictionVariant::BOTH => avsc_ipred_dc_8bpc_ssse3,
105 })(dst_ptr, stride, edge_ptr, w, h, 0);
106 } else {
107 call_rust(dst)
108 }
109 }
110 PixelType::U16 => {
111 let dst_ptr = dst.data_ptr_mut() as *mut _;
112 let edge_ptr = edge_buf.top_left_ptr() as *const _;
113 let bd_max = (1 << bit_depth) - 1;
114 if cpu >= CpuFeatureLevel::AVX2 {
115 (match variant {
116 PredictionVariant::NONE => avsc_ipred_dc_128_16bpc_avx2,
117 PredictionVariant::LEFT => avsc_ipred_dc_left_16bpc_avx2,
118 PredictionVariant::TOP => avsc_ipred_dc_top_16bpc_avx2,
119 PredictionVariant::BOTH => avsc_ipred_dc_16bpc_avx2,
120 })(dst_ptr, stride, edge_ptr, w, h, 0, 0, 0, bd_max);
121 } else if cpu >= CpuFeatureLevel::SSSE3 {
122 (match variant {
123 PredictionVariant::NONE => avsc_ipred_dc_128_16bpc_ssse3,
124 PredictionVariant::LEFT => avsc_ipred_dc_left_16bpc_ssse3,
125 PredictionVariant::TOP => avsc_ipred_dc_top_16bpc_ssse3,
126 PredictionVariant::BOTH => avsc_ipred_dc_16bpc_ssse3,
127 })(dst_ptr, stride, edge_ptr, w, h, 0, 0, 0, bd_max);
128 } else {
129 call_rust(dst)
130 }
131 }
132 }
133 }
134 }