xref: /aosp_15_r20/external/libgav1/src/dsp/convolve.h (revision 095378508e87ed692bf8dfeb34008b65b3735891)
1 /*
2  * Copyright 2019 The libgav1 Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBGAV1_SRC_DSP_CONVOLVE_H_
18 #define LIBGAV1_SRC_DSP_CONVOLVE_H_
19 
20 #include <cassert>
21 
22 // Pull in LIBGAV1_DspXXX defines representing the implementation status
23 // of each function. The resulting value of each can be used by each module to
24 // determine whether an implementation is needed at compile time.
25 // IWYU pragma: begin_exports
26 
27 // ARM:
28 #include "src/dsp/arm/convolve_neon.h"
29 
30 // x86:
31 // Note includes should be sorted in logical order avx2/avx/sse4, etc.
32 // The order of includes is important as each tests for a superior version
33 // before setting the base.
34 // clang-format off
35 #include "src/dsp/x86/convolve_avx2.h"
36 #include "src/dsp/x86/convolve_sse4.h"
37 // clang-format on
38 
39 // IWYU pragma: end_exports
40 
41 namespace libgav1 {
42 namespace dsp {
43 
44 // Initializes Dsp::convolve and Dsp::convolve_scale. This function is not
45 // thread-safe.
46 void ConvolveInit_C();
47 
GetNumTapsInFilter(const int filter_index)48 inline int GetNumTapsInFilter(const int filter_index) {
49   if (filter_index < 2) {
50     // Despite the names these only use 6 taps.
51     // kInterpolationFilterEightTap
52     // kInterpolationFilterEightTapSmooth
53     return 6;
54   }
55 
56   if (filter_index == 2) {
57     // kInterpolationFilterEightTapSharp
58     return 8;
59   }
60 
61   if (filter_index == 3) {
62     // kInterpolationFilterBilinear
63     return 2;
64   }
65 
66   assert(filter_index > 3);
67   // For small sizes (width/height <= 4) the large filters are replaced with 4
68   // tap options.
69   // If the original filters were |kInterpolationFilterEightTap| or
70   // |kInterpolationFilterEightTapSharp| then it becomes
71   // |kInterpolationFilterSwitchable|.
72   // If it was |kInterpolationFilterEightTapSmooth| then it becomes an unnamed 4
73   // tap filter.
74   return 4;
75 }
76 
77 }  // namespace dsp
78 }  // namespace libgav1
79 
80 #endif  // LIBGAV1_SRC_DSP_CONVOLVE_H_
81