1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
3 *
4 * This source code is subject to the terms of the BSD 2 Clause License and
5 * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
6 * was not distributed with this source code in the LICENSE file, you can
7 * obtain it at www.aomedia.org/license/software. If the Alliance for Open
8 * Media Patent License 1.0 was not distributed with this source code in the
9 * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
10 */
11
12 #include <stdlib.h>
13
14 #include "./aom_config.h"
15 #include "./aom_dsp_rtcd.h"
16 #include "aom_dsp/aom_dsp_common.h"
17 #include "aom_ports/mem.h"
18
signed_char_clamp(int t)19 static INLINE int8_t signed_char_clamp(int t) {
20 return (int8_t)clamp(t, -128, 127);
21 }
22
23 #define PARALLEL_DEBLOCKING_11_TAP 0
24 #define PARALLEL_DEBLOCKING_9_TAP 0
25
26 #if CONFIG_DEBLOCK_13TAP
27 #define PARALLEL_DEBLOCKING_13_TAP 1
28 #define PARALLEL_DEBLOCKING_5_TAP_CHROMA 1
29 #else
30 #define PARALLEL_DEBLOCKING_13_TAP 0
31 #define PARALLEL_DEBLOCKING_5_TAP_CHROMA 0
32 #endif
33
34 #if CONFIG_HIGHBITDEPTH
signed_char_clamp_high(int t,int bd)35 static INLINE int16_t signed_char_clamp_high(int t, int bd) {
36 switch (bd) {
37 case 10: return (int16_t)clamp(t, -128 * 4, 128 * 4 - 1);
38 case 12: return (int16_t)clamp(t, -128 * 16, 128 * 16 - 1);
39 case 8:
40 default: return (int16_t)clamp(t, -128, 128 - 1);
41 }
42 }
43 #endif
44 #if CONFIG_PARALLEL_DEBLOCKING
45 // should we apply any filter at all: 11111111 yes, 00000000 no
filter_mask2(uint8_t limit,uint8_t blimit,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1)46 static INLINE int8_t filter_mask2(uint8_t limit, uint8_t blimit, uint8_t p1,
47 uint8_t p0, uint8_t q0, uint8_t q1) {
48 int8_t mask = 0;
49 mask |= (abs(p1 - p0) > limit) * -1;
50 mask |= (abs(q1 - q0) > limit) * -1;
51 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
52 return ~mask;
53 }
54 #endif // CONFIG_PARALLEL_DEBLOCKING
filter_mask(uint8_t limit,uint8_t blimit,uint8_t p3,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2,uint8_t q3)55 static INLINE int8_t filter_mask(uint8_t limit, uint8_t blimit, uint8_t p3,
56 uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0,
57 uint8_t q1, uint8_t q2, uint8_t q3) {
58 int8_t mask = 0;
59 mask |= (abs(p3 - p2) > limit) * -1;
60 mask |= (abs(p2 - p1) > limit) * -1;
61 mask |= (abs(p1 - p0) > limit) * -1;
62 mask |= (abs(q1 - q0) > limit) * -1;
63 mask |= (abs(q2 - q1) > limit) * -1;
64 mask |= (abs(q3 - q2) > limit) * -1;
65 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
66 return ~mask;
67 }
68
69 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
flat_mask3_chroma(uint8_t thresh,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2)70 static INLINE int8_t flat_mask3_chroma(uint8_t thresh, uint8_t p2, uint8_t p1,
71 uint8_t p0, uint8_t q0, uint8_t q1,
72 uint8_t q2) {
73 int8_t mask = 0;
74 mask |= (abs(p1 - p0) > thresh) * -1;
75 mask |= (abs(q1 - q0) > thresh) * -1;
76 mask |= (abs(p2 - p0) > thresh) * -1;
77 mask |= (abs(q2 - q0) > thresh) * -1;
78 return ~mask;
79 }
80 #endif
81
flat_mask4(uint8_t thresh,uint8_t p3,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2,uint8_t q3)82 static INLINE int8_t flat_mask4(uint8_t thresh, uint8_t p3, uint8_t p2,
83 uint8_t p1, uint8_t p0, uint8_t q0, uint8_t q1,
84 uint8_t q2, uint8_t q3) {
85 int8_t mask = 0;
86 mask |= (abs(p1 - p0) > thresh) * -1;
87 mask |= (abs(q1 - q0) > thresh) * -1;
88 mask |= (abs(p2 - p0) > thresh) * -1;
89 mask |= (abs(q2 - q0) > thresh) * -1;
90 mask |= (abs(p3 - p0) > thresh) * -1;
91 mask |= (abs(q3 - q0) > thresh) * -1;
92 return ~mask;
93 }
94
95 #if PARALLEL_DEBLOCKING_9_TAP
flat_mask2(uint8_t thresh,uint8_t p4,uint8_t p0,uint8_t q0,uint8_t q4)96 static INLINE int8_t flat_mask2(uint8_t thresh, uint8_t p4, uint8_t p0,
97 uint8_t q0, uint8_t q4) {
98 int8_t mask = 0;
99 mask |= (abs(p4 - p0) > thresh) * -1;
100 mask |= (abs(q4 - q0) > thresh) * -1;
101 return ~mask;
102 }
103 #endif
104
105 #if PARALLEL_DEBLOCKING_11_TAP
flat_mask3(uint8_t thresh,uint8_t p5,uint8_t p4,uint8_t p0,uint8_t q0,uint8_t q4,uint8_t q5)106 static INLINE int8_t flat_mask3(uint8_t thresh, uint8_t p5, uint8_t p4,
107 uint8_t p0, uint8_t q0, uint8_t q4,
108 uint8_t q5) {
109 int8_t mask = 0;
110 mask |= (abs(p4 - p0) > thresh) * -1;
111 mask |= (abs(q4 - q0) > thresh) * -1;
112 mask |= (abs(p5 - p0) > thresh) * -1;
113 mask |= (abs(q5 - q0) > thresh) * -1;
114 return ~mask;
115 }
116 #endif
117
flat_mask5(uint8_t thresh,uint8_t p4,uint8_t p3,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2,uint8_t q3,uint8_t q4)118 static INLINE int8_t flat_mask5(uint8_t thresh, uint8_t p4, uint8_t p3,
119 uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0,
120 uint8_t q1, uint8_t q2, uint8_t q3,
121 uint8_t q4) {
122 int8_t mask = ~flat_mask4(thresh, p3, p2, p1, p0, q0, q1, q2, q3);
123 mask |= (abs(p4 - p0) > thresh) * -1;
124 mask |= (abs(q4 - q0) > thresh) * -1;
125 return ~mask;
126 }
127
128 // is there high edge variance internal edge: 11111111 yes, 00000000 no
hev_mask(uint8_t thresh,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1)129 static INLINE int8_t hev_mask(uint8_t thresh, uint8_t p1, uint8_t p0,
130 uint8_t q0, uint8_t q1) {
131 int8_t hev = 0;
132 hev |= (abs(p1 - p0) > thresh) * -1;
133 hev |= (abs(q1 - q0) > thresh) * -1;
134 return hev;
135 }
136
filter4(int8_t mask,uint8_t thresh,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1)137 static INLINE void filter4(int8_t mask, uint8_t thresh, uint8_t *op1,
138 uint8_t *op0, uint8_t *oq0, uint8_t *oq1) {
139 int8_t filter1, filter2;
140
141 const int8_t ps1 = (int8_t)*op1 ^ 0x80;
142 const int8_t ps0 = (int8_t)*op0 ^ 0x80;
143 const int8_t qs0 = (int8_t)*oq0 ^ 0x80;
144 const int8_t qs1 = (int8_t)*oq1 ^ 0x80;
145 const uint8_t hev = hev_mask(thresh, *op1, *op0, *oq0, *oq1);
146
147 // add outer taps if we have high edge variance
148 int8_t filter = signed_char_clamp(ps1 - qs1) & hev;
149
150 // inner taps
151 filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask;
152
153 // save bottom 3 bits so that we round one side +4 and the other +3
154 // if it equals 4 we'll set to adjust by -1 to account for the fact
155 // we'd round 3 the other way
156 filter1 = signed_char_clamp(filter + 4) >> 3;
157 filter2 = signed_char_clamp(filter + 3) >> 3;
158
159 *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
160 *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
161
162 // outer tap adjustments
163 filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
164
165 *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
166 *op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
167 }
168
aom_lpf_horizontal_4_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)169 void aom_lpf_horizontal_4_c(uint8_t *s, int p /* pitch */,
170 const uint8_t *blimit, const uint8_t *limit,
171 const uint8_t *thresh) {
172 int i;
173 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
174 int count = 4;
175 #else
176 int count = 8;
177 #endif
178
179 // loop filter designed to work using chars so that we can make maximum use
180 // of 8 bit simd instructions.
181 for (i = 0; i < count; ++i) {
182 #if !CONFIG_PARALLEL_DEBLOCKING
183 const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
184 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
185 const int8_t mask =
186 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
187 #else // CONFIG_PARALLEL_DEBLOCKING
188 const uint8_t p1 = s[-2 * p], p0 = s[-p];
189 const uint8_t q0 = s[0 * p], q1 = s[1 * p];
190 const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1);
191 #endif // !CONFIG_PARALLEL_DEBLOCKING
192 filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p);
193 ++s;
194 }
195 }
196
aom_lpf_horizontal_4_dual_c(uint8_t * s,int p,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1)197 void aom_lpf_horizontal_4_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
198 const uint8_t *limit0, const uint8_t *thresh0,
199 const uint8_t *blimit1, const uint8_t *limit1,
200 const uint8_t *thresh1) {
201 aom_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0);
202 aom_lpf_horizontal_4_c(s + 8, p, blimit1, limit1, thresh1);
203 }
204
aom_lpf_vertical_4_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)205 void aom_lpf_vertical_4_c(uint8_t *s, int pitch, const uint8_t *blimit,
206 const uint8_t *limit, const uint8_t *thresh) {
207 int i;
208 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
209 int count = 4;
210 #else
211 int count = 8;
212 #endif
213
214 // loop filter designed to work using chars so that we can make maximum use
215 // of 8 bit simd instructions.
216 for (i = 0; i < count; ++i) {
217 #if !CONFIG_PARALLEL_DEBLOCKING
218 const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
219 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
220 const int8_t mask =
221 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
222 #else // CONFIG_PARALLEL_DEBLOCKING
223 const uint8_t p1 = s[-2], p0 = s[-1];
224 const uint8_t q0 = s[0], q1 = s[1];
225 const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1);
226 #endif // !CONFIG_PARALLEL_DEBLOCKING
227 filter4(mask, *thresh, s - 2, s - 1, s, s + 1);
228 s += pitch;
229 }
230 }
231
aom_lpf_vertical_4_dual_c(uint8_t * s,int pitch,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1)232 void aom_lpf_vertical_4_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
233 const uint8_t *limit0, const uint8_t *thresh0,
234 const uint8_t *blimit1, const uint8_t *limit1,
235 const uint8_t *thresh1) {
236 aom_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0);
237 aom_lpf_vertical_4_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1);
238 }
239
240 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
filter6(int8_t mask,uint8_t thresh,int8_t flat,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2)241 static INLINE void filter6(int8_t mask, uint8_t thresh, int8_t flat,
242 uint8_t *op2, uint8_t *op1, uint8_t *op0,
243 uint8_t *oq0, uint8_t *oq1, uint8_t *oq2) {
244 if (flat && mask) {
245 const uint8_t p2 = *op2, p1 = *op1, p0 = *op0;
246 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2;
247
248 // 5-tap filter [1, 2, 2, 2, 1]
249 *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3);
250 *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3);
251 *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3);
252 *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3);
253 } else {
254 filter4(mask, thresh, op1, op0, oq0, oq1);
255 }
256 }
257 #endif
258
filter8(int8_t mask,uint8_t thresh,int8_t flat,uint8_t * op3,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2,uint8_t * oq3)259 static INLINE void filter8(int8_t mask, uint8_t thresh, int8_t flat,
260 uint8_t *op3, uint8_t *op2, uint8_t *op1,
261 uint8_t *op0, uint8_t *oq0, uint8_t *oq1,
262 uint8_t *oq2, uint8_t *oq3) {
263 if (flat && mask) {
264 const uint8_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
265 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
266
267 // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
268 *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
269 *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
270 *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
271 *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
272 *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
273 *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
274 } else {
275 filter4(mask, thresh, op1, op0, oq0, oq1);
276 }
277 }
278
279 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
aom_lpf_horizontal_6_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)280 void aom_lpf_horizontal_6_c(uint8_t *s, int p, const uint8_t *blimit,
281 const uint8_t *limit, const uint8_t *thresh) {
282 int i;
283 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
284 int count = 4;
285 #else
286 int count = 8;
287 #endif
288
289 // loop filter designed to work using chars so that we can make maximum use
290 // of 8 bit simd instructions.
291 for (i = 0; i < count; ++i) {
292 const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
293 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
294
295 const int8_t mask =
296 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
297 const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2);
298 filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
299 s + 2 * p);
300 ++s;
301 }
302 }
303 #endif
304
aom_lpf_horizontal_8_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)305 void aom_lpf_horizontal_8_c(uint8_t *s, int p, const uint8_t *blimit,
306 const uint8_t *limit, const uint8_t *thresh) {
307 int i;
308 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
309 int count = 4;
310 #else
311 int count = 8;
312 #endif
313
314 // loop filter designed to work using chars so that we can make maximum use
315 // of 8 bit simd instructions.
316 for (i = 0; i < count; ++i) {
317 const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
318 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
319
320 const int8_t mask =
321 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
322 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
323 filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
324 s + 1 * p, s + 2 * p, s + 3 * p);
325 ++s;
326 }
327 }
328
aom_lpf_horizontal_8_dual_c(uint8_t * s,int p,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1)329 void aom_lpf_horizontal_8_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
330 const uint8_t *limit0, const uint8_t *thresh0,
331 const uint8_t *blimit1, const uint8_t *limit1,
332 const uint8_t *thresh1) {
333 aom_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0);
334 aom_lpf_horizontal_8_c(s + 8, p, blimit1, limit1, thresh1);
335 }
336
337 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
aom_lpf_vertical_6_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)338 void aom_lpf_vertical_6_c(uint8_t *s, int pitch, const uint8_t *blimit,
339 const uint8_t *limit, const uint8_t *thresh) {
340 int i;
341 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
342 int count = 4;
343 #else
344 int count = 8;
345 #endif
346
347 for (i = 0; i < count; ++i) {
348 const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
349 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
350 const int8_t mask =
351 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
352 const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2);
353 filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2);
354 s += pitch;
355 }
356 }
357 #endif
358
aom_lpf_vertical_8_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)359 void aom_lpf_vertical_8_c(uint8_t *s, int pitch, const uint8_t *blimit,
360 const uint8_t *limit, const uint8_t *thresh) {
361 int i;
362 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
363 int count = 4;
364 #else
365 int count = 8;
366 #endif
367
368 for (i = 0; i < count; ++i) {
369 const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
370 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
371 const int8_t mask =
372 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
373 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
374 filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2,
375 s + 3);
376 s += pitch;
377 }
378 }
379
aom_lpf_vertical_8_dual_c(uint8_t * s,int pitch,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1)380 void aom_lpf_vertical_8_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
381 const uint8_t *limit0, const uint8_t *thresh0,
382 const uint8_t *blimit1, const uint8_t *limit1,
383 const uint8_t *thresh1) {
384 aom_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0);
385 aom_lpf_vertical_8_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1);
386 }
387
388 #if PARALLEL_DEBLOCKING_13_TAP
filter14(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint8_t * op6,uint8_t * op5,uint8_t * op4,uint8_t * op3,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2,uint8_t * oq3,uint8_t * oq4,uint8_t * oq5,uint8_t * oq6)389 static INLINE void filter14(int8_t mask, uint8_t thresh, int8_t flat,
390 int8_t flat2, uint8_t *op6, uint8_t *op5,
391 uint8_t *op4, uint8_t *op3, uint8_t *op2,
392 uint8_t *op1, uint8_t *op0, uint8_t *oq0,
393 uint8_t *oq1, uint8_t *oq2, uint8_t *oq3,
394 uint8_t *oq4, uint8_t *oq5, uint8_t *oq6) {
395 if (flat2 && flat && mask) {
396 const uint8_t p6 = *op6, p5 = *op5, p4 = *op4, p3 = *op3, p2 = *op2,
397 p1 = *op1, p0 = *op0;
398 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4,
399 q5 = *oq5, q6 = *oq6;
400
401 // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1]
402 *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0,
403 4);
404 *op4 = ROUND_POWER_OF_TWO(
405 p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4);
406 *op3 = ROUND_POWER_OF_TWO(
407 p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4);
408 *op2 = ROUND_POWER_OF_TWO(
409 p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3,
410 4);
411 *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 +
412 q0 + q1 + q2 + q3 + q4,
413 4);
414 *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 +
415 q0 * 2 + q1 + q2 + q3 + q4 + q5,
416 4);
417 *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 +
418 q1 * 2 + q2 + q3 + q4 + q5 + q6,
419 4);
420 *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 +
421 q2 * 2 + q3 + q4 + q5 + q6 * 2,
422 4);
423 *oq2 = ROUND_POWER_OF_TWO(
424 p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3,
425 4);
426 *oq3 = ROUND_POWER_OF_TWO(
427 p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4);
428 *oq4 = ROUND_POWER_OF_TWO(
429 p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4);
430 *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7,
431 4);
432 } else {
433 filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
434 }
435 }
436 #endif
437
438 #if PARALLEL_DEBLOCKING_11_TAP
filter12(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint8_t * op5,uint8_t * op4,uint8_t * op3,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2,uint8_t * oq3,uint8_t * oq4,uint8_t * oq5)439 static INLINE void filter12(int8_t mask, uint8_t thresh, int8_t flat,
440 int8_t flat2, uint8_t *op5, uint8_t *op4,
441 uint8_t *op3, uint8_t *op2, uint8_t *op1,
442 uint8_t *op0, uint8_t *oq0, uint8_t *oq1,
443 uint8_t *oq2, uint8_t *oq3, uint8_t *oq4,
444 uint8_t *oq5) {
445 if (flat2 && flat && mask) {
446 const uint8_t p5 = *op5, p4 = *op4, p3 = *op3, p2 = *op2, p1 = *op1,
447 p0 = *op0;
448 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4,
449 q5 = *oq5;
450
451 // 11-tap filter [1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1]
452 *op4 = (p5 * 5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + 6) / 12;
453 *op3 = (p5 * 4 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + 6) / 12;
454 *op2 = (p5 * 3 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + 6) / 12;
455 *op1 = (p5 * 2 + p4 + p3 + p2 + p1 * 2 + p0 + q0 + q1 + q2 + q3 + 6) / 12;
456 *op0 = (p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 + q1 + q2 + q3 + q4 + 6) / 12;
457 *oq0 = (p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 + q2 + q3 + q4 + q5 + 6) / 12;
458 *oq1 = (p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 + q3 + q4 + q5 * 2 + 6) / 12;
459 *oq2 = (p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 * 3 + 6) / 12;
460 *oq3 = (p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 * 4 + 6) / 12;
461 *oq4 = (p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 5 + 6) / 12;
462 } else {
463 filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
464 }
465 }
466 #endif
467
468 #if PARALLEL_DEBLOCKING_9_TAP
filter10(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint8_t * op4,uint8_t * op3,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2,uint8_t * oq3,uint8_t * oq4)469 static INLINE void filter10(int8_t mask, uint8_t thresh, int8_t flat,
470 int8_t flat2, uint8_t *op4, uint8_t *op3,
471 uint8_t *op2, uint8_t *op1, uint8_t *op0,
472 uint8_t *oq0, uint8_t *oq1, uint8_t *oq2,
473 uint8_t *oq3, uint8_t *oq4) {
474 if (flat2 && flat && mask) {
475 const uint8_t p4 = *op4, p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
476 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4;
477
478 // 9-tap filter [1, 1, 1, 1, 2, 1, 1, 1, 1]
479 *op3 = (p4 * 4 + p3 * 2 + p2 + p1 + p0 + q0 + 5) / 10;
480 *op2 = (p4 * 3 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + 5) / 10;
481 *op1 = (p4 * 2 + p3 + p2 + p1 * 2 + p0 + q0 + q1 + q2 + 5) / 10;
482 *op0 = (p4 + p3 + p2 + p1 + p0 * 2 + q0 + q1 + q2 + q3 + 5) / 10;
483 *oq0 = (p3 + p2 + p1 + p0 + q0 * 2 + q1 + q2 + q3 + q4 + 5) / 10;
484 *oq1 = (p2 + p1 + p0 + q0 + q1 * 2 + q2 + q3 + q4 * 2 + 5) / 10;
485 *oq2 = (p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 * 3 + 5) / 10;
486 *oq3 = (p0 + q0 + q1 + q2 + q3 * 2 + q4 * 4 + 5) / 10;
487 } else {
488 filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
489 }
490 }
491 #endif
492
filter16(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint8_t * op7,uint8_t * op6,uint8_t * op5,uint8_t * op4,uint8_t * op3,uint8_t * op2,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1,uint8_t * oq2,uint8_t * oq3,uint8_t * oq4,uint8_t * oq5,uint8_t * oq6,uint8_t * oq7)493 static INLINE void filter16(int8_t mask, uint8_t thresh, int8_t flat,
494 int8_t flat2, uint8_t *op7, uint8_t *op6,
495 uint8_t *op5, uint8_t *op4, uint8_t *op3,
496 uint8_t *op2, uint8_t *op1, uint8_t *op0,
497 uint8_t *oq0, uint8_t *oq1, uint8_t *oq2,
498 uint8_t *oq3, uint8_t *oq4, uint8_t *oq5,
499 uint8_t *oq6, uint8_t *oq7) {
500 if (flat2 && flat && mask) {
501 const uint8_t p7 = *op7, p6 = *op6, p5 = *op5, p4 = *op4, p3 = *op3,
502 p2 = *op2, p1 = *op1, p0 = *op0;
503
504 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4,
505 q5 = *oq5, q6 = *oq6, q7 = *oq7;
506
507 // 15-tap filter [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]
508 *op6 = ROUND_POWER_OF_TWO(
509 p7 * 7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 + q0, 4);
510 *op5 = ROUND_POWER_OF_TWO(
511 p7 * 6 + p6 + p5 * 2 + p4 + p3 + p2 + p1 + p0 + q0 + q1, 4);
512 *op4 = ROUND_POWER_OF_TWO(
513 p7 * 5 + p6 + p5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + q1 + q2, 4);
514 *op3 = ROUND_POWER_OF_TWO(
515 p7 * 4 + p6 + p5 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + q2 + q3, 4);
516 *op2 = ROUND_POWER_OF_TWO(
517 p7 * 3 + p6 + p5 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + q3 + q4,
518 4);
519 *op1 = ROUND_POWER_OF_TWO(p7 * 2 + p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 +
520 q0 + q1 + q2 + q3 + q4 + q5,
521 4);
522 *op0 = ROUND_POWER_OF_TWO(p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 +
523 q1 + q2 + q3 + q4 + q5 + q6,
524 4);
525 *oq0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 +
526 q2 + q3 + q4 + q5 + q6 + q7,
527 4);
528 *oq1 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 +
529 q3 + q4 + q5 + q6 + q7 * 2,
530 4);
531 *oq2 = ROUND_POWER_OF_TWO(
532 p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 + q6 + q7 * 3,
533 4);
534 *oq3 = ROUND_POWER_OF_TWO(
535 p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 + q6 + q7 * 4, 4);
536 *oq4 = ROUND_POWER_OF_TWO(
537 p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 + q6 + q7 * 5, 4);
538 *oq5 = ROUND_POWER_OF_TWO(
539 p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 * 6, 4);
540 *oq6 = ROUND_POWER_OF_TWO(
541 p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 * 7, 4);
542 } else {
543 filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
544 }
545 }
546
mb_lpf_horizontal_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)547 static void mb_lpf_horizontal_edge_w(uint8_t *s, int p, const uint8_t *blimit,
548 const uint8_t *limit,
549 const uint8_t *thresh, int count) {
550 int i;
551 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
552 int step = 4;
553 #else
554 int step = 8;
555 #endif
556
557 // loop filter designed to work using chars so that we can make maximum use
558 // of 8 bit simd instructions.
559 for (i = 0; i < step * count; ++i) {
560 const uint8_t p7 = s[-8 * p], p6 = s[-7 * p], p5 = s[-6 * p],
561 p4 = s[-5 * p], p3 = s[-4 * p], p2 = s[-3 * p],
562 p1 = s[-2 * p], p0 = s[-p];
563 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p],
564 q4 = s[4 * p], q5 = s[5 * p], q6 = s[6 * p], q7 = s[7 * p];
565 const int8_t mask =
566 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
567 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
568
569 #if PARALLEL_DEBLOCKING_13_TAP
570 (void)p7;
571 (void)q7;
572 const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6);
573
574 filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p,
575 s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
576 s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p);
577
578 #elif PARALLEL_DEBLOCKING_11_TAP
579 const int8_t flat2 = flat_mask3(1, p5, p4, p0, q0, q4, q5);
580
581 filter12(mask, *thresh, flat, flat2, s - 6 * p, s - 5 * p, s - 4 * p,
582 s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p, s + 2 * p,
583 s + 3 * p, s + 4 * p, s + 5 * p);
584
585 #elif PARALLEL_DEBLOCKING_9_TAP
586 const int8_t flat2 = flat_mask2(1, p4, p0, q0, q4);
587
588 filter10(mask, *thresh, flat, flat2, s - 5 * p, s - 4 * p, s - 3 * p,
589 s - 2 * p, s - 1 * p, s, s + 1 * p, s + 2 * p, s + 3 * p,
590 s + 4 * p);
591 #else
592 const int8_t flat2 = flat_mask5(1, p7, p6, p5, p4, p0, q0, q4, q5, q6, q7);
593
594 filter16(mask, *thresh, flat, flat2, s - 8 * p, s - 7 * p, s - 6 * p,
595 s - 5 * p, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
596 s + 1 * p, s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p,
597 s + 7 * p);
598 #endif
599
600 ++s;
601 }
602 }
603
aom_lpf_horizontal_edge_8_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)604 void aom_lpf_horizontal_edge_8_c(uint8_t *s, int p, const uint8_t *blimit,
605 const uint8_t *limit, const uint8_t *thresh) {
606 mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1);
607 }
608
aom_lpf_horizontal_edge_16_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)609 void aom_lpf_horizontal_edge_16_c(uint8_t *s, int p, const uint8_t *blimit,
610 const uint8_t *limit, const uint8_t *thresh) {
611 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
612 mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1);
613 #else
614 mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 2);
615 #endif
616 }
617
mb_lpf_vertical_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)618 static void mb_lpf_vertical_edge_w(uint8_t *s, int p, const uint8_t *blimit,
619 const uint8_t *limit, const uint8_t *thresh,
620 int count) {
621 int i;
622
623 for (i = 0; i < count; ++i) {
624 const uint8_t p7 = s[-8], p6 = s[-7], p5 = s[-6], p4 = s[-5], p3 = s[-4],
625 p2 = s[-3], p1 = s[-2], p0 = s[-1];
626 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3], q4 = s[4],
627 q5 = s[5], q6 = s[6], q7 = s[7];
628 const int8_t mask =
629 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
630 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
631
632 #if PARALLEL_DEBLOCKING_13_TAP
633 (void)p7;
634 (void)q7;
635 const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6);
636
637 filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4, s - 3,
638 s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6);
639 #elif PARALLEL_DEBLOCKING_11_TAP
640 const int8_t flat2 = flat_mask3(1, p5, p4, p0, q0, q4, q5);
641
642 filter12(mask, *thresh, flat, flat2, s - 6, s - 5, s - 4, s - 3, s - 2,
643 s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5);
644 #elif PARALLEL_DEBLOCKING_9_TAP
645 const int8_t flat2 = flat_mask2(1, p4, p0, q0, q4);
646
647 filter10(mask, *thresh, flat, flat2, s - 5, s - 4, s - 3, s - 2, s - 1, s,
648 s + 1, s + 2, s + 3, s + 4);
649
650 #else
651 const int8_t flat2 = flat_mask5(1, p7, p6, p5, p4, p0, q0, q4, q5, q6, q7);
652
653 filter16(mask, *thresh, flat, flat2, s - 8, s - 7, s - 6, s - 5, s - 4,
654 s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6,
655 s + 7);
656 #endif
657
658 s += p;
659 }
660 }
661
aom_lpf_vertical_16_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)662 void aom_lpf_vertical_16_c(uint8_t *s, int p, const uint8_t *blimit,
663 const uint8_t *limit, const uint8_t *thresh) {
664 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
665 mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4);
666 #else
667 mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 8);
668 #endif
669 }
670
aom_lpf_vertical_16_dual_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)671 void aom_lpf_vertical_16_dual_c(uint8_t *s, int p, const uint8_t *blimit,
672 const uint8_t *limit, const uint8_t *thresh) {
673 mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 16);
674 }
675
676 #if CONFIG_HIGHBITDEPTH
677 #if CONFIG_PARALLEL_DEBLOCKING
678 // Should we apply any filter at all: 11111111 yes, 00000000 no ?
highbd_filter_mask2(uint8_t limit,uint8_t blimit,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,int bd)679 static INLINE int8_t highbd_filter_mask2(uint8_t limit, uint8_t blimit,
680 uint16_t p1, uint16_t p0, uint16_t q0,
681 uint16_t q1, int bd) {
682 int8_t mask = 0;
683 int16_t limit16 = (uint16_t)limit << (bd - 8);
684 int16_t blimit16 = (uint16_t)blimit << (bd - 8);
685 mask |= (abs(p1 - p0) > limit16) * -1;
686 mask |= (abs(q1 - q0) > limit16) * -1;
687 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
688 return ~mask;
689 }
690 #endif // CONFIG_PARALLEL_DEBLOCKING
691
692 // Should we apply any filter at all: 11111111 yes, 00000000 no ?
highbd_filter_mask(uint8_t limit,uint8_t blimit,uint16_t p3,uint16_t p2,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,uint16_t q2,uint16_t q3,int bd)693 static INLINE int8_t highbd_filter_mask(uint8_t limit, uint8_t blimit,
694 uint16_t p3, uint16_t p2, uint16_t p1,
695 uint16_t p0, uint16_t q0, uint16_t q1,
696 uint16_t q2, uint16_t q3, int bd) {
697 int8_t mask = 0;
698 int16_t limit16 = (uint16_t)limit << (bd - 8);
699 int16_t blimit16 = (uint16_t)blimit << (bd - 8);
700 mask |= (abs(p3 - p2) > limit16) * -1;
701 mask |= (abs(p2 - p1) > limit16) * -1;
702 mask |= (abs(p1 - p0) > limit16) * -1;
703 mask |= (abs(q1 - q0) > limit16) * -1;
704 mask |= (abs(q2 - q1) > limit16) * -1;
705 mask |= (abs(q3 - q2) > limit16) * -1;
706 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
707 return ~mask;
708 }
709
710 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
highbd_flat_mask3_chroma(uint8_t thresh,uint16_t p2,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,uint16_t q2,int bd)711 static INLINE int8_t highbd_flat_mask3_chroma(uint8_t thresh, uint16_t p2,
712 uint16_t p1, uint16_t p0,
713 uint16_t q0, uint16_t q1,
714 uint16_t q2, int bd) {
715 int8_t mask = 0;
716 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
717 mask |= (abs(p1 - p0) > thresh16) * -1;
718 mask |= (abs(q1 - q0) > thresh16) * -1;
719 mask |= (abs(p2 - p0) > thresh16) * -1;
720 mask |= (abs(q2 - q0) > thresh16) * -1;
721 return ~mask;
722 }
723 #endif
724
highbd_flat_mask4(uint8_t thresh,uint16_t p3,uint16_t p2,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,uint16_t q2,uint16_t q3,int bd)725 static INLINE int8_t highbd_flat_mask4(uint8_t thresh, uint16_t p3, uint16_t p2,
726 uint16_t p1, uint16_t p0, uint16_t q0,
727 uint16_t q1, uint16_t q2, uint16_t q3,
728 int bd) {
729 int8_t mask = 0;
730 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
731 mask |= (abs(p1 - p0) > thresh16) * -1;
732 mask |= (abs(q1 - q0) > thresh16) * -1;
733 mask |= (abs(p2 - p0) > thresh16) * -1;
734 mask |= (abs(q2 - q0) > thresh16) * -1;
735 mask |= (abs(p3 - p0) > thresh16) * -1;
736 mask |= (abs(q3 - q0) > thresh16) * -1;
737 return ~mask;
738 }
739
highbd_flat_mask5(uint8_t thresh,uint16_t p4,uint16_t p3,uint16_t p2,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,uint16_t q2,uint16_t q3,uint16_t q4,int bd)740 static INLINE int8_t highbd_flat_mask5(uint8_t thresh, uint16_t p4, uint16_t p3,
741 uint16_t p2, uint16_t p1, uint16_t p0,
742 uint16_t q0, uint16_t q1, uint16_t q2,
743 uint16_t q3, uint16_t q4, int bd) {
744 int8_t mask = ~highbd_flat_mask4(thresh, p3, p2, p1, p0, q0, q1, q2, q3, bd);
745 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
746 mask |= (abs(p4 - p0) > thresh16) * -1;
747 mask |= (abs(q4 - q0) > thresh16) * -1;
748 return ~mask;
749 }
750
751 // Is there high edge variance internal edge:
752 // 11111111_11111111 yes, 00000000_00000000 no ?
highbd_hev_mask(uint8_t thresh,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,int bd)753 static INLINE int16_t highbd_hev_mask(uint8_t thresh, uint16_t p1, uint16_t p0,
754 uint16_t q0, uint16_t q1, int bd) {
755 int16_t hev = 0;
756 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
757 hev |= (abs(p1 - p0) > thresh16) * -1;
758 hev |= (abs(q1 - q0) > thresh16) * -1;
759 return hev;
760 }
761
highbd_filter4(int8_t mask,uint8_t thresh,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,int bd)762 static INLINE void highbd_filter4(int8_t mask, uint8_t thresh, uint16_t *op1,
763 uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
764 int bd) {
765 int16_t filter1, filter2;
766 // ^0x80 equivalent to subtracting 0x80 from the values to turn them
767 // into -128 to +127 instead of 0 to 255.
768 int shift = bd - 8;
769 const int16_t ps1 = (int16_t)*op1 - (0x80 << shift);
770 const int16_t ps0 = (int16_t)*op0 - (0x80 << shift);
771 const int16_t qs0 = (int16_t)*oq0 - (0x80 << shift);
772 const int16_t qs1 = (int16_t)*oq1 - (0x80 << shift);
773 const uint16_t hev = highbd_hev_mask(thresh, *op1, *op0, *oq0, *oq1, bd);
774
775 // Add outer taps if we have high edge variance.
776 int16_t filter = signed_char_clamp_high(ps1 - qs1, bd) & hev;
777
778 // Inner taps.
779 filter = signed_char_clamp_high(filter + 3 * (qs0 - ps0), bd) & mask;
780
781 // Save bottom 3 bits so that we round one side +4 and the other +3
782 // if it equals 4 we'll set to adjust by -1 to account for the fact
783 // we'd round 3 the other way.
784 filter1 = signed_char_clamp_high(filter + 4, bd) >> 3;
785 filter2 = signed_char_clamp_high(filter + 3, bd) >> 3;
786
787 *oq0 = signed_char_clamp_high(qs0 - filter1, bd) + (0x80 << shift);
788 *op0 = signed_char_clamp_high(ps0 + filter2, bd) + (0x80 << shift);
789
790 // Outer tap adjustments.
791 filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
792
793 *oq1 = signed_char_clamp_high(qs1 - filter, bd) + (0x80 << shift);
794 *op1 = signed_char_clamp_high(ps1 + filter, bd) + (0x80 << shift);
795 }
796
aom_highbd_lpf_horizontal_4_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)797 void aom_highbd_lpf_horizontal_4_c(uint16_t *s, int p /* pitch */,
798 const uint8_t *blimit, const uint8_t *limit,
799 const uint8_t *thresh, int bd) {
800 int i;
801 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
802 int count = 4;
803 #else
804 int count = 8;
805 #endif
806
807 // loop filter designed to work using chars so that we can make maximum use
808 // of 8 bit simd instructions.
809 for (i = 0; i < count; ++i) {
810 #if !CONFIG_PARALLEL_DEBLOCKING
811 const uint16_t p3 = s[-4 * p];
812 const uint16_t p2 = s[-3 * p];
813 const uint16_t p1 = s[-2 * p];
814 const uint16_t p0 = s[-p];
815 const uint16_t q0 = s[0 * p];
816 const uint16_t q1 = s[1 * p];
817 const uint16_t q2 = s[2 * p];
818 const uint16_t q3 = s[3 * p];
819 const int8_t mask =
820 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
821 #else // CONFIG_PARALLEL_DEBLOCKING
822 const uint16_t p1 = s[-2 * p];
823 const uint16_t p0 = s[-p];
824 const uint16_t q0 = s[0 * p];
825 const uint16_t q1 = s[1 * p];
826 const int8_t mask =
827 highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd);
828 #endif // !CONFIG_PARALLEL_DEBLOCKING
829 highbd_filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p, bd);
830 ++s;
831 }
832 }
833
aom_highbd_lpf_horizontal_4_dual_c(uint16_t * s,int p,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1,int bd)834 void aom_highbd_lpf_horizontal_4_dual_c(
835 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
836 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
837 const uint8_t *thresh1, int bd) {
838 aom_highbd_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0, bd);
839 aom_highbd_lpf_horizontal_4_c(s + 8, p, blimit1, limit1, thresh1, bd);
840 }
841
aom_highbd_lpf_vertical_4_c(uint16_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)842 void aom_highbd_lpf_vertical_4_c(uint16_t *s, int pitch, const uint8_t *blimit,
843 const uint8_t *limit, const uint8_t *thresh,
844 int bd) {
845 int i;
846 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
847 int count = 4;
848 #else
849 int count = 8;
850 #endif
851
852 // loop filter designed to work using chars so that we can make maximum use
853 // of 8 bit simd instructions.
854 for (i = 0; i < count; ++i) {
855 #if !CONFIG_PARALLEL_DEBLOCKING
856 const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
857 const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
858 const int8_t mask =
859 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
860 #else // CONFIG_PARALLEL_DEBLOCKING
861 const uint16_t p1 = s[-2], p0 = s[-1];
862 const uint16_t q0 = s[0], q1 = s[1];
863 const int8_t mask =
864 highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd);
865 #endif // !CONFIG_PARALLEL_DEBLOCKING
866 highbd_filter4(mask, *thresh, s - 2, s - 1, s, s + 1, bd);
867 s += pitch;
868 }
869 }
870
aom_highbd_lpf_vertical_4_dual_c(uint16_t * s,int pitch,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1,int bd)871 void aom_highbd_lpf_vertical_4_dual_c(
872 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
873 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
874 const uint8_t *thresh1, int bd) {
875 aom_highbd_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0, bd);
876 aom_highbd_lpf_vertical_4_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1,
877 bd);
878 }
879
880 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
highbd_filter6(int8_t mask,uint8_t thresh,int8_t flat,uint16_t * op2,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,uint16_t * oq2,int bd)881 static INLINE void highbd_filter6(int8_t mask, uint8_t thresh, int8_t flat,
882 uint16_t *op2, uint16_t *op1, uint16_t *op0,
883 uint16_t *oq0, uint16_t *oq1, uint16_t *oq2,
884 int bd) {
885 if (flat && mask) {
886 const uint16_t p2 = *op2, p1 = *op1, p0 = *op0;
887 const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2;
888
889 // 5-tap filter [1, 2, 2, 2, 1]
890 *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3);
891 *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3);
892 *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3);
893 *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3);
894 } else {
895 highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd);
896 }
897 }
898 #endif
899
highbd_filter8(int8_t mask,uint8_t thresh,int8_t flat,uint16_t * op3,uint16_t * op2,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,uint16_t * oq2,uint16_t * oq3,int bd)900 static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, int8_t flat,
901 uint16_t *op3, uint16_t *op2, uint16_t *op1,
902 uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
903 uint16_t *oq2, uint16_t *oq3, int bd) {
904 if (flat && mask) {
905 const uint16_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
906 const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
907
908 // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
909 *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
910 *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
911 *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
912 *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
913 *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
914 *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
915 } else {
916 highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd);
917 }
918 }
919
aom_highbd_lpf_horizontal_8_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)920 void aom_highbd_lpf_horizontal_8_c(uint16_t *s, int p, const uint8_t *blimit,
921 const uint8_t *limit, const uint8_t *thresh,
922 int bd) {
923 int i;
924 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
925 int count = 4;
926 #else
927 int count = 8;
928 #endif
929
930 // loop filter designed to work using chars so that we can make maximum use
931 // of 8 bit simd instructions.
932 for (i = 0; i < count; ++i) {
933 const uint16_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
934 const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
935
936 const int8_t mask =
937 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
938 const int8_t flat =
939 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
940 highbd_filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p,
941 s - 1 * p, s, s + 1 * p, s + 2 * p, s + 3 * p, bd);
942 ++s;
943 }
944 }
945
946 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
aom_highbd_lpf_horizontal_6_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)947 void aom_highbd_lpf_horizontal_6_c(uint16_t *s, int p, const uint8_t *blimit,
948 const uint8_t *limit, const uint8_t *thresh,
949 int bd) {
950 int i;
951 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
952 int count = 4;
953 #else
954 int count = 8;
955 #endif
956
957 // loop filter designed to work using chars so that we can make maximum use
958 // of 8 bit simd instructions.
959 for (i = 0; i < count; ++i) {
960 const uint16_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
961 const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
962
963 const int8_t mask =
964 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
965 const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd);
966 highbd_filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s,
967 s + 1 * p, s + 2 * p, bd);
968 ++s;
969 }
970 }
971 #endif
972
aom_highbd_lpf_horizontal_8_dual_c(uint16_t * s,int p,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1,int bd)973 void aom_highbd_lpf_horizontal_8_dual_c(
974 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
975 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
976 const uint8_t *thresh1, int bd) {
977 aom_highbd_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0, bd);
978 aom_highbd_lpf_horizontal_8_c(s + 8, p, blimit1, limit1, thresh1, bd);
979 }
980
981 #if PARALLEL_DEBLOCKING_5_TAP_CHROMA
aom_highbd_lpf_vertical_6_c(uint16_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)982 void aom_highbd_lpf_vertical_6_c(uint16_t *s, int pitch, const uint8_t *blimit,
983 const uint8_t *limit, const uint8_t *thresh,
984 int bd) {
985 int i;
986 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
987 int count = 4;
988 #else
989 int count = 8;
990 #endif
991
992 for (i = 0; i < count; ++i) {
993 const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
994 const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
995 const int8_t mask =
996 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
997 const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd);
998 highbd_filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2,
999 bd);
1000 s += pitch;
1001 }
1002 }
1003 #endif
1004
aom_highbd_lpf_vertical_8_c(uint16_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)1005 void aom_highbd_lpf_vertical_8_c(uint16_t *s, int pitch, const uint8_t *blimit,
1006 const uint8_t *limit, const uint8_t *thresh,
1007 int bd) {
1008 int i;
1009 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
1010 int count = 4;
1011 #else
1012 int count = 8;
1013 #endif
1014
1015 for (i = 0; i < count; ++i) {
1016 const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
1017 const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
1018 const int8_t mask =
1019 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1020 const int8_t flat =
1021 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1022 highbd_filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1,
1023 s + 2, s + 3, bd);
1024 s += pitch;
1025 }
1026 }
1027
aom_highbd_lpf_vertical_8_dual_c(uint16_t * s,int pitch,const uint8_t * blimit0,const uint8_t * limit0,const uint8_t * thresh0,const uint8_t * blimit1,const uint8_t * limit1,const uint8_t * thresh1,int bd)1028 void aom_highbd_lpf_vertical_8_dual_c(
1029 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
1030 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
1031 const uint8_t *thresh1, int bd) {
1032 aom_highbd_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0, bd);
1033 aom_highbd_lpf_vertical_8_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1,
1034 bd);
1035 }
1036
1037 #if PARALLEL_DEBLOCKING_13_TAP
highbd_filter14(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint16_t * op6,uint16_t * op5,uint16_t * op4,uint16_t * op3,uint16_t * op2,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,uint16_t * oq2,uint16_t * oq3,uint16_t * oq4,uint16_t * oq5,uint16_t * oq6,int bd)1038 static INLINE void highbd_filter14(int8_t mask, uint8_t thresh, int8_t flat,
1039 int8_t flat2, uint16_t *op6, uint16_t *op5,
1040 uint16_t *op4, uint16_t *op3, uint16_t *op2,
1041 uint16_t *op1, uint16_t *op0, uint16_t *oq0,
1042 uint16_t *oq1, uint16_t *oq2, uint16_t *oq3,
1043 uint16_t *oq4, uint16_t *oq5, uint16_t *oq6,
1044 int bd) {
1045 if (flat2 && flat && mask) {
1046 const uint16_t p6 = *op6;
1047 const uint16_t p5 = *op5;
1048 const uint16_t p4 = *op4;
1049 const uint16_t p3 = *op3;
1050 const uint16_t p2 = *op2;
1051 const uint16_t p1 = *op1;
1052 const uint16_t p0 = *op0;
1053 const uint16_t q0 = *oq0;
1054 const uint16_t q1 = *oq1;
1055 const uint16_t q2 = *oq2;
1056 const uint16_t q3 = *oq3;
1057 const uint16_t q4 = *oq4;
1058 const uint16_t q5 = *oq5;
1059 const uint16_t q6 = *oq6;
1060
1061 // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1]
1062 *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0,
1063 4);
1064 *op4 = ROUND_POWER_OF_TWO(
1065 p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4);
1066 *op3 = ROUND_POWER_OF_TWO(
1067 p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4);
1068 *op2 = ROUND_POWER_OF_TWO(
1069 p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3,
1070 4);
1071 *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 +
1072 q0 + q1 + q2 + q3 + q4,
1073 4);
1074 *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 +
1075 q0 * 2 + q1 + q2 + q3 + q4 + q5,
1076 4);
1077 *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 +
1078 q1 * 2 + q2 + q3 + q4 + q5 + q6,
1079 4);
1080 *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 +
1081 q2 * 2 + q3 + q4 + q5 + q6 * 2,
1082 4);
1083 *oq2 = ROUND_POWER_OF_TWO(
1084 p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3,
1085 4);
1086 *oq3 = ROUND_POWER_OF_TWO(
1087 p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4);
1088 *oq4 = ROUND_POWER_OF_TWO(
1089 p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4);
1090 *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7,
1091 4);
1092 } else {
1093 highbd_filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3,
1094 bd);
1095 }
1096 }
1097 #endif
1098
highbd_filter16(int8_t mask,uint8_t thresh,int8_t flat,int8_t flat2,uint16_t * op7,uint16_t * op6,uint16_t * op5,uint16_t * op4,uint16_t * op3,uint16_t * op2,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,uint16_t * oq2,uint16_t * oq3,uint16_t * oq4,uint16_t * oq5,uint16_t * oq6,uint16_t * oq7,int bd)1099 static INLINE void highbd_filter16(int8_t mask, uint8_t thresh, int8_t flat,
1100 int8_t flat2, uint16_t *op7, uint16_t *op6,
1101 uint16_t *op5, uint16_t *op4, uint16_t *op3,
1102 uint16_t *op2, uint16_t *op1, uint16_t *op0,
1103 uint16_t *oq0, uint16_t *oq1, uint16_t *oq2,
1104 uint16_t *oq3, uint16_t *oq4, uint16_t *oq5,
1105 uint16_t *oq6, uint16_t *oq7, int bd) {
1106 if (flat2 && flat && mask) {
1107 const uint16_t p7 = *op7;
1108 const uint16_t p6 = *op6;
1109 const uint16_t p5 = *op5;
1110 const uint16_t p4 = *op4;
1111 const uint16_t p3 = *op3;
1112 const uint16_t p2 = *op2;
1113 const uint16_t p1 = *op1;
1114 const uint16_t p0 = *op0;
1115 const uint16_t q0 = *oq0;
1116 const uint16_t q1 = *oq1;
1117 const uint16_t q2 = *oq2;
1118 const uint16_t q3 = *oq3;
1119 const uint16_t q4 = *oq4;
1120 const uint16_t q5 = *oq5;
1121 const uint16_t q6 = *oq6;
1122 const uint16_t q7 = *oq7;
1123
1124 // 15-tap filter [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]
1125 *op6 = ROUND_POWER_OF_TWO(
1126 p7 * 7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 + q0, 4);
1127 *op5 = ROUND_POWER_OF_TWO(
1128 p7 * 6 + p6 + p5 * 2 + p4 + p3 + p2 + p1 + p0 + q0 + q1, 4);
1129 *op4 = ROUND_POWER_OF_TWO(
1130 p7 * 5 + p6 + p5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + q1 + q2, 4);
1131 *op3 = ROUND_POWER_OF_TWO(
1132 p7 * 4 + p6 + p5 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + q2 + q3, 4);
1133 *op2 = ROUND_POWER_OF_TWO(
1134 p7 * 3 + p6 + p5 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + q3 + q4,
1135 4);
1136 *op1 = ROUND_POWER_OF_TWO(p7 * 2 + p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 +
1137 q0 + q1 + q2 + q3 + q4 + q5,
1138 4);
1139 *op0 = ROUND_POWER_OF_TWO(p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 +
1140 q1 + q2 + q3 + q4 + q5 + q6,
1141 4);
1142 *oq0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 +
1143 q2 + q3 + q4 + q5 + q6 + q7,
1144 4);
1145 *oq1 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 +
1146 q3 + q4 + q5 + q6 + q7 * 2,
1147 4);
1148 *oq2 = ROUND_POWER_OF_TWO(
1149 p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 + q6 + q7 * 3,
1150 4);
1151 *oq3 = ROUND_POWER_OF_TWO(
1152 p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 + q6 + q7 * 4, 4);
1153 *oq4 = ROUND_POWER_OF_TWO(
1154 p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 + q6 + q7 * 5, 4);
1155 *oq5 = ROUND_POWER_OF_TWO(
1156 p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 * 6, 4);
1157 *oq6 = ROUND_POWER_OF_TWO(
1158 p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 * 7, 4);
1159 } else {
1160 highbd_filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3,
1161 bd);
1162 }
1163 }
1164
highbd_mb_lpf_horizontal_edge_w(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count,int bd)1165 static void highbd_mb_lpf_horizontal_edge_w(uint16_t *s, int p,
1166 const uint8_t *blimit,
1167 const uint8_t *limit,
1168 const uint8_t *thresh, int count,
1169 int bd) {
1170 int i;
1171 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
1172 int step = 4;
1173 #else
1174 int step = 8;
1175 #endif
1176
1177 // loop filter designed to work using chars so that we can make maximum use
1178 // of 8 bit simd instructions.
1179 for (i = 0; i < step * count; ++i) {
1180 const uint16_t p3 = s[-4 * p];
1181 const uint16_t p2 = s[-3 * p];
1182 const uint16_t p1 = s[-2 * p];
1183 const uint16_t p0 = s[-p];
1184 const uint16_t q0 = s[0 * p];
1185 const uint16_t q1 = s[1 * p];
1186 const uint16_t q2 = s[2 * p];
1187 const uint16_t q3 = s[3 * p];
1188 const int8_t mask =
1189 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1190 const int8_t flat =
1191 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1192
1193 #if PARALLEL_DEBLOCKING_13_TAP
1194 const int8_t flat2 =
1195 highbd_flat_mask4(1, s[-7 * p], s[-6 * p], s[-5 * p], p0, q0, s[4 * p],
1196 s[5 * p], s[6 * p], bd);
1197
1198 highbd_filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p,
1199 s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
1200 s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p, bd);
1201 #else
1202 const int8_t flat2 =
1203 highbd_flat_mask5(1, s[-8 * p], s[-7 * p], s[-6 * p], s[-5 * p], p0, q0,
1204 s[4 * p], s[5 * p], s[6 * p], s[7 * p], bd);
1205
1206 highbd_filter16(mask, *thresh, flat, flat2, s - 8 * p, s - 7 * p, s - 6 * p,
1207 s - 5 * p, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
1208 s + 1 * p, s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p,
1209 s + 6 * p, s + 7 * p, bd);
1210 #endif
1211 ++s;
1212 }
1213 }
1214
aom_highbd_lpf_horizontal_edge_8_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)1215 void aom_highbd_lpf_horizontal_edge_8_c(uint16_t *s, int p,
1216 const uint8_t *blimit,
1217 const uint8_t *limit,
1218 const uint8_t *thresh, int bd) {
1219 highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1, bd);
1220 }
1221
aom_highbd_lpf_horizontal_edge_16_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)1222 void aom_highbd_lpf_horizontal_edge_16_c(uint16_t *s, int p,
1223 const uint8_t *blimit,
1224 const uint8_t *limit,
1225 const uint8_t *thresh, int bd) {
1226 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
1227 highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1, bd);
1228 #else
1229 highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 2, bd);
1230 #endif
1231 }
1232
highbd_mb_lpf_vertical_edge_w(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count,int bd)1233 static void highbd_mb_lpf_vertical_edge_w(uint16_t *s, int p,
1234 const uint8_t *blimit,
1235 const uint8_t *limit,
1236 const uint8_t *thresh, int count,
1237 int bd) {
1238 int i;
1239
1240 for (i = 0; i < count; ++i) {
1241 const uint16_t p3 = s[-4];
1242 const uint16_t p2 = s[-3];
1243 const uint16_t p1 = s[-2];
1244 const uint16_t p0 = s[-1];
1245 const uint16_t q0 = s[0];
1246 const uint16_t q1 = s[1];
1247 const uint16_t q2 = s[2];
1248 const uint16_t q3 = s[3];
1249 const int8_t mask =
1250 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1251 const int8_t flat =
1252 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
1253 #if PARALLEL_DEBLOCKING_13_TAP
1254 const int8_t flat2 =
1255 highbd_flat_mask4(1, s[-7], s[-6], s[-5], p0, q0, s[4], s[5], s[6], bd);
1256
1257 highbd_filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4,
1258 s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5,
1259 s + 6, bd);
1260 #else
1261 const int8_t flat2 = highbd_flat_mask5(1, s[-8], s[-7], s[-6], s[-5], p0,
1262 q0, s[4], s[5], s[6], s[7], bd);
1263
1264 highbd_filter16(mask, *thresh, flat, flat2, s - 8, s - 7, s - 6, s - 5,
1265 s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4,
1266 s + 5, s + 6, s + 7, bd);
1267 #endif
1268 s += p;
1269 }
1270 }
1271
aom_highbd_lpf_vertical_16_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)1272 void aom_highbd_lpf_vertical_16_c(uint16_t *s, int p, const uint8_t *blimit,
1273 const uint8_t *limit, const uint8_t *thresh,
1274 int bd) {
1275 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
1276 highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4, bd);
1277 #else
1278 highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 8, bd);
1279 #endif
1280 }
1281
aom_highbd_lpf_vertical_16_dual_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)1282 void aom_highbd_lpf_vertical_16_dual_c(uint16_t *s, int p,
1283 const uint8_t *blimit,
1284 const uint8_t *limit,
1285 const uint8_t *thresh, int bd) {
1286 #if CONFIG_PARALLEL_DEBLOCKING && CONFIG_CB4X4
1287 highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 8, bd);
1288 #else
1289 highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 16, bd);
1290 #endif
1291 }
1292 #endif // CONFIG_HIGHBITDEPTH
1293