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_LOOP_RESTORATION_H_
18 #define LIBGAV1_SRC_DSP_LOOP_RESTORATION_H_
19
20 // Pull in LIBGAV1_DspXXX defines representing the implementation status
21 // of each function. The resulting value of each can be used by each module to
22 // determine whether an implementation is needed at compile time.
23 // IWYU pragma: begin_exports
24
25 // ARM:
26 #include "src/dsp/arm/loop_restoration_neon.h"
27
28 // x86:
29 // Note includes should be sorted in logical order avx2/avx/sse4, etc.
30 // The order of includes is important as each tests for a superior version
31 // before setting the base.
32 // clang-format off
33 #include "src/dsp/x86/loop_restoration_avx2.h"
34 #include "src/dsp/x86/loop_restoration_sse4.h"
35 // clang-format on
36
37 // IWYU pragma: end_exports
38
39 namespace libgav1 {
40 namespace dsp {
41
42 enum {
43 // Precision of a division table (mtable)
44 kSgrProjScaleBits = 20,
45 kSgrProjReciprocalBits = 12,
46 // Core self-guided restoration precision bits.
47 kSgrProjSgrBits = 8,
48 // Precision bits of generated values higher than source before projection.
49 kSgrProjRestoreBits = 4
50 }; // anonymous enum
51
52 extern const uint8_t kSgrMaLookup[256];
53
54 // Initializes Dsp::loop_restorations. This function is not thread-safe.
55 void LoopRestorationInit_C();
56
57 template <typename T>
Circulate3PointersBy1(T * p[3])58 void Circulate3PointersBy1(T* p[3]) {
59 T* const p0 = p[0];
60 p[0] = p[1];
61 p[1] = p[2];
62 p[2] = p0;
63 }
64
65 template <typename T>
Circulate4PointersBy2(T * p[4])66 void Circulate4PointersBy2(T* p[4]) {
67 std::swap(p[0], p[2]);
68 std::swap(p[1], p[3]);
69 }
70
71 template <typename T>
Circulate5PointersBy2(T * p[5])72 void Circulate5PointersBy2(T* p[5]) {
73 T* const p0 = p[0];
74 T* const p1 = p[1];
75 p[0] = p[2];
76 p[1] = p[3];
77 p[2] = p[4];
78 p[3] = p0;
79 p[4] = p1;
80 }
81
82 } // namespace dsp
83 } // namespace libgav1
84
85 #endif // LIBGAV1_SRC_DSP_LOOP_RESTORATION_H_
86