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 "config/aom_config.h"
15 #include "config/aom_dsp_rtcd.h"
16
17 #include "aom_dsp/aom_dsp_common.h"
18 #include "aom_ports/mem.h"
19
signed_char_clamp(int t)20 static INLINE int8_t signed_char_clamp(int t) {
21 return (int8_t)clamp(t, -128, 127);
22 }
23
signed_char_clamp_high(int t,int bd)24 static INLINE int16_t signed_char_clamp_high(int t, int bd) {
25 switch (bd) {
26 case 10: return (int16_t)clamp(t, -128 * 4, 128 * 4 - 1);
27 case 12: return (int16_t)clamp(t, -128 * 16, 128 * 16 - 1);
28 case 8:
29 default: return (int16_t)clamp(t, -128, 128 - 1);
30 }
31 }
32
33 // 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)34 static INLINE int8_t filter_mask2(uint8_t limit, uint8_t blimit, uint8_t p1,
35 uint8_t p0, uint8_t q0, uint8_t q1) {
36 int8_t mask = 0;
37 mask |= (abs(p1 - p0) > limit) * -1;
38 mask |= (abs(q1 - q0) > limit) * -1;
39 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
40 return ~mask;
41 }
42
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)43 static INLINE int8_t filter_mask(uint8_t limit, uint8_t blimit, uint8_t p3,
44 uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0,
45 uint8_t q1, uint8_t q2, uint8_t q3) {
46 int8_t mask = 0;
47 mask |= (abs(p3 - p2) > limit) * -1;
48 mask |= (abs(p2 - p1) > limit) * -1;
49 mask |= (abs(p1 - p0) > limit) * -1;
50 mask |= (abs(q1 - q0) > limit) * -1;
51 mask |= (abs(q2 - q1) > limit) * -1;
52 mask |= (abs(q3 - q2) > limit) * -1;
53 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
54 return ~mask;
55 }
56
filter_mask3_chroma(uint8_t limit,uint8_t blimit,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2)57 static INLINE int8_t filter_mask3_chroma(uint8_t limit, uint8_t blimit,
58 uint8_t p2, uint8_t p1, uint8_t p0,
59 uint8_t q0, uint8_t q1, uint8_t q2) {
60 int8_t mask = 0;
61 mask |= (abs(p2 - p1) > limit) * -1;
62 mask |= (abs(p1 - p0) > limit) * -1;
63 mask |= (abs(q1 - q0) > limit) * -1;
64 mask |= (abs(q2 - q1) > limit) * -1;
65 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
66 return ~mask;
67 }
68
flat_mask3_chroma(uint8_t thresh,uint8_t p2,uint8_t p1,uint8_t p0,uint8_t q0,uint8_t q1,uint8_t q2)69 static INLINE int8_t flat_mask3_chroma(uint8_t thresh, uint8_t p2, uint8_t p1,
70 uint8_t p0, uint8_t q0, uint8_t q1,
71 uint8_t q2) {
72 int8_t mask = 0;
73 mask |= (abs(p1 - p0) > thresh) * -1;
74 mask |= (abs(q1 - q0) > thresh) * -1;
75 mask |= (abs(p2 - p0) > thresh) * -1;
76 mask |= (abs(q2 - q0) > thresh) * -1;
77 return ~mask;
78 }
79
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)80 static INLINE int8_t flat_mask4(uint8_t thresh, uint8_t p3, uint8_t p2,
81 uint8_t p1, uint8_t p0, uint8_t q0, uint8_t q1,
82 uint8_t q2, uint8_t q3) {
83 int8_t mask = 0;
84 mask |= (abs(p1 - p0) > thresh) * -1;
85 mask |= (abs(q1 - q0) > thresh) * -1;
86 mask |= (abs(p2 - p0) > thresh) * -1;
87 mask |= (abs(q2 - q0) > thresh) * -1;
88 mask |= (abs(p3 - p0) > thresh) * -1;
89 mask |= (abs(q3 - q0) > thresh) * -1;
90 return ~mask;
91 }
92
93 // 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)94 static INLINE int8_t hev_mask(uint8_t thresh, uint8_t p1, uint8_t p0,
95 uint8_t q0, uint8_t q1) {
96 int8_t hev = 0;
97 hev |= (abs(p1 - p0) > thresh) * -1;
98 hev |= (abs(q1 - q0) > thresh) * -1;
99 return hev;
100 }
101
filter4(int8_t mask,uint8_t thresh,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1)102 static INLINE void filter4(int8_t mask, uint8_t thresh, uint8_t *op1,
103 uint8_t *op0, uint8_t *oq0, uint8_t *oq1) {
104 int8_t filter1, filter2;
105
106 const int8_t ps1 = (int8_t)*op1 ^ 0x80;
107 const int8_t ps0 = (int8_t)*op0 ^ 0x80;
108 const int8_t qs0 = (int8_t)*oq0 ^ 0x80;
109 const int8_t qs1 = (int8_t)*oq1 ^ 0x80;
110 const uint8_t hev = hev_mask(thresh, *op1, *op0, *oq0, *oq1);
111
112 // add outer taps if we have high edge variance
113 int8_t filter = signed_char_clamp(ps1 - qs1) & hev;
114
115 // inner taps
116 filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask;
117
118 // save bottom 3 bits so that we round one side +4 and the other +3
119 // if it equals 4 we'll set to adjust by -1 to account for the fact
120 // we'd round 3 the other way
121 filter1 = signed_char_clamp(filter + 4) >> 3;
122 filter2 = signed_char_clamp(filter + 3) >> 3;
123
124 *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
125 *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
126
127 // outer tap adjustments
128 filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
129
130 *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
131 *op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
132 }
133
aom_lpf_horizontal_4_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)134 void aom_lpf_horizontal_4_c(uint8_t *s, int p /* pitch */,
135 const uint8_t *blimit, const uint8_t *limit,
136 const uint8_t *thresh) {
137 int i;
138 int count = 4;
139
140 // loop filter designed to work using chars so that we can make maximum use
141 // of 8 bit simd instructions.
142 for (i = 0; i < count; ++i) {
143 const uint8_t p1 = s[-2 * p], p0 = s[-p];
144 const uint8_t q0 = s[0 * p], q1 = s[1 * p];
145 const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1);
146 filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p);
147 ++s;
148 }
149 }
150
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)151 void aom_lpf_horizontal_4_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
152 const uint8_t *limit0, const uint8_t *thresh0,
153 const uint8_t *blimit1, const uint8_t *limit1,
154 const uint8_t *thresh1) {
155 aom_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0);
156 aom_lpf_horizontal_4_c(s + 4, p, blimit1, limit1, thresh1);
157 }
158
aom_lpf_vertical_4_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)159 void aom_lpf_vertical_4_c(uint8_t *s, int pitch, const uint8_t *blimit,
160 const uint8_t *limit, const uint8_t *thresh) {
161 int i;
162 int count = 4;
163
164 // loop filter designed to work using chars so that we can make maximum use
165 // of 8 bit simd instructions.
166 for (i = 0; i < count; ++i) {
167 const uint8_t p1 = s[-2], p0 = s[-1];
168 const uint8_t q0 = s[0], q1 = s[1];
169 const int8_t mask = filter_mask2(*limit, *blimit, p1, p0, q0, q1);
170 filter4(mask, *thresh, s - 2, s - 1, s, s + 1);
171 s += pitch;
172 }
173 }
174
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)175 void aom_lpf_vertical_4_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
176 const uint8_t *limit0, const uint8_t *thresh0,
177 const uint8_t *blimit1, const uint8_t *limit1,
178 const uint8_t *thresh1) {
179 aom_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0);
180 aom_lpf_vertical_4_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1);
181 }
182
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)183 static INLINE void filter6(int8_t mask, uint8_t thresh, int8_t flat,
184 uint8_t *op2, uint8_t *op1, uint8_t *op0,
185 uint8_t *oq0, uint8_t *oq1, uint8_t *oq2) {
186 if (flat && mask) {
187 const uint8_t p2 = *op2, p1 = *op1, p0 = *op0;
188 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2;
189
190 // 5-tap filter [1, 2, 2, 2, 1]
191 *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3);
192 *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3);
193 *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3);
194 *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3);
195 } else {
196 filter4(mask, thresh, op1, op0, oq0, oq1);
197 }
198 }
199
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)200 static INLINE void filter8(int8_t mask, uint8_t thresh, int8_t flat,
201 uint8_t *op3, uint8_t *op2, uint8_t *op1,
202 uint8_t *op0, uint8_t *oq0, uint8_t *oq1,
203 uint8_t *oq2, uint8_t *oq3) {
204 if (flat && mask) {
205 const uint8_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
206 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
207
208 // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
209 *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
210 *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
211 *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
212 *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
213 *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
214 *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
215 } else {
216 filter4(mask, thresh, op1, op0, oq0, oq1);
217 }
218 }
219
aom_lpf_horizontal_6_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)220 void aom_lpf_horizontal_6_c(uint8_t *s, int p, const uint8_t *blimit,
221 const uint8_t *limit, const uint8_t *thresh) {
222 int i;
223 int count = 4;
224
225 // loop filter designed to work using chars so that we can make maximum use
226 // of 8 bit simd instructions.
227 for (i = 0; i < count; ++i) {
228 const uint8_t p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
229 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p];
230
231 const int8_t mask =
232 filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2);
233 const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2);
234 filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
235 s + 2 * p);
236 ++s;
237 }
238 }
239
aom_lpf_horizontal_6_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)240 void aom_lpf_horizontal_6_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
241 const uint8_t *limit0, const uint8_t *thresh0,
242 const uint8_t *blimit1, const uint8_t *limit1,
243 const uint8_t *thresh1) {
244 aom_lpf_horizontal_6_c(s, p, blimit0, limit0, thresh0);
245 aom_lpf_horizontal_6_c(s + 4, p, blimit1, limit1, thresh1);
246 }
247
aom_lpf_horizontal_8_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)248 void aom_lpf_horizontal_8_c(uint8_t *s, int p, const uint8_t *blimit,
249 const uint8_t *limit, const uint8_t *thresh) {
250 int i;
251 int count = 4;
252
253 // loop filter designed to work using chars so that we can make maximum use
254 // of 8 bit simd instructions.
255 for (i = 0; i < count; ++i) {
256 const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
257 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
258
259 const int8_t mask =
260 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
261 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
262 filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
263 s + 1 * p, s + 2 * p, s + 3 * p);
264 ++s;
265 }
266 }
267
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)268 void aom_lpf_horizontal_8_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
269 const uint8_t *limit0, const uint8_t *thresh0,
270 const uint8_t *blimit1, const uint8_t *limit1,
271 const uint8_t *thresh1) {
272 aom_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0);
273 aom_lpf_horizontal_8_c(s + 4, p, blimit1, limit1, thresh1);
274 }
275
aom_lpf_vertical_6_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)276 void aom_lpf_vertical_6_c(uint8_t *s, int pitch, const uint8_t *blimit,
277 const uint8_t *limit, const uint8_t *thresh) {
278 int i;
279 int count = 4;
280
281 for (i = 0; i < count; ++i) {
282 const uint8_t p2 = s[-3], p1 = s[-2], p0 = s[-1];
283 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2];
284 const int8_t mask =
285 filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2);
286 const int8_t flat = flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2);
287 filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2);
288 s += pitch;
289 }
290 }
291
aom_lpf_vertical_6_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)292 void aom_lpf_vertical_6_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
293 const uint8_t *limit0, const uint8_t *thresh0,
294 const uint8_t *blimit1, const uint8_t *limit1,
295 const uint8_t *thresh1) {
296 aom_lpf_vertical_6_c(s, pitch, blimit0, limit0, thresh0);
297 aom_lpf_vertical_6_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1);
298 }
299
aom_lpf_vertical_8_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)300 void aom_lpf_vertical_8_c(uint8_t *s, int pitch, const uint8_t *blimit,
301 const uint8_t *limit, const uint8_t *thresh) {
302 int i;
303 int count = 4;
304
305 for (i = 0; i < count; ++i) {
306 const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
307 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
308 const int8_t mask =
309 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
310 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
311 filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2,
312 s + 3);
313 s += pitch;
314 }
315 }
316
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)317 void aom_lpf_vertical_8_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
318 const uint8_t *limit0, const uint8_t *thresh0,
319 const uint8_t *blimit1, const uint8_t *limit1,
320 const uint8_t *thresh1) {
321 aom_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0);
322 aom_lpf_vertical_8_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1);
323 }
324
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)325 static INLINE void filter14(int8_t mask, uint8_t thresh, int8_t flat,
326 int8_t flat2, uint8_t *op6, uint8_t *op5,
327 uint8_t *op4, uint8_t *op3, uint8_t *op2,
328 uint8_t *op1, uint8_t *op0, uint8_t *oq0,
329 uint8_t *oq1, uint8_t *oq2, uint8_t *oq3,
330 uint8_t *oq4, uint8_t *oq5, uint8_t *oq6) {
331 if (flat2 && flat && mask) {
332 const uint8_t p6 = *op6, p5 = *op5, p4 = *op4, p3 = *op3, p2 = *op2,
333 p1 = *op1, p0 = *op0;
334 const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4,
335 q5 = *oq5, q6 = *oq6;
336
337 // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1]
338 *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0,
339 4);
340 *op4 = ROUND_POWER_OF_TWO(
341 p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4);
342 *op3 = ROUND_POWER_OF_TWO(
343 p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4);
344 *op2 = ROUND_POWER_OF_TWO(
345 p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3,
346 4);
347 *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 +
348 q0 + q1 + q2 + q3 + q4,
349 4);
350 *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 +
351 q0 * 2 + q1 + q2 + q3 + q4 + q5,
352 4);
353 *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 +
354 q1 * 2 + q2 + q3 + q4 + q5 + q6,
355 4);
356 *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 +
357 q2 * 2 + q3 + q4 + q5 + q6 * 2,
358 4);
359 *oq2 = ROUND_POWER_OF_TWO(
360 p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3,
361 4);
362 *oq3 = ROUND_POWER_OF_TWO(
363 p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4);
364 *oq4 = ROUND_POWER_OF_TWO(
365 p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4);
366 *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7,
367 4);
368 } else {
369 filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
370 }
371 }
372
mb_lpf_horizontal_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)373 static void mb_lpf_horizontal_edge_w(uint8_t *s, int p, const uint8_t *blimit,
374 const uint8_t *limit,
375 const uint8_t *thresh, int count) {
376 int i;
377 int step = 4;
378
379 // loop filter designed to work using chars so that we can make maximum use
380 // of 8 bit simd instructions.
381 for (i = 0; i < step * count; ++i) {
382 const uint8_t p6 = s[-7 * p], p5 = s[-6 * p], p4 = s[-5 * p],
383 p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
384 const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p],
385 q4 = s[4 * p], q5 = s[5 * p], q6 = s[6 * p];
386 const int8_t mask =
387 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
388 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
389 const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6);
390
391 filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p,
392 s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
393 s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p);
394 ++s;
395 }
396 }
397
aom_lpf_horizontal_14_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)398 void aom_lpf_horizontal_14_c(uint8_t *s, int p, const uint8_t *blimit,
399 const uint8_t *limit, const uint8_t *thresh) {
400 mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1);
401 }
402
aom_lpf_horizontal_14_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)403 void aom_lpf_horizontal_14_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
404 const uint8_t *limit0, const uint8_t *thresh0,
405 const uint8_t *blimit1, const uint8_t *limit1,
406 const uint8_t *thresh1) {
407 mb_lpf_horizontal_edge_w(s, p, blimit0, limit0, thresh0, 1);
408 mb_lpf_horizontal_edge_w(s + 4, p, blimit1, limit1, thresh1, 1);
409 }
410
mb_lpf_vertical_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)411 static void mb_lpf_vertical_edge_w(uint8_t *s, int p, const uint8_t *blimit,
412 const uint8_t *limit, const uint8_t *thresh,
413 int count) {
414 int i;
415
416 for (i = 0; i < count; ++i) {
417 const uint8_t p6 = s[-7], p5 = s[-6], p4 = s[-5], p3 = s[-4], p2 = s[-3],
418 p1 = s[-2], p0 = s[-1];
419 const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3], q4 = s[4],
420 q5 = s[5], q6 = s[6];
421 const int8_t mask =
422 filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
423 const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
424 const int8_t flat2 = flat_mask4(1, p6, p5, p4, p0, q0, q4, q5, q6);
425
426 filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4, s - 3,
427 s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6);
428 s += p;
429 }
430 }
431
aom_lpf_vertical_14_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)432 void aom_lpf_vertical_14_c(uint8_t *s, int p, const uint8_t *blimit,
433 const uint8_t *limit, const uint8_t *thresh) {
434 mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4);
435 }
436
aom_lpf_vertical_14_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)437 void aom_lpf_vertical_14_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
438 const uint8_t *limit0, const uint8_t *thresh0,
439 const uint8_t *blimit1, const uint8_t *limit1,
440 const uint8_t *thresh1) {
441 mb_lpf_vertical_edge_w(s, pitch, blimit0, limit0, thresh0, 4);
442 mb_lpf_vertical_edge_w(s + 4 * pitch, pitch, blimit1, limit1, thresh1, 4);
443 }
444
445 // 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)446 static INLINE int8_t highbd_filter_mask2(uint8_t limit, uint8_t blimit,
447 uint16_t p1, uint16_t p0, uint16_t q0,
448 uint16_t q1, int bd) {
449 int8_t mask = 0;
450 int16_t limit16 = (uint16_t)limit << (bd - 8);
451 int16_t blimit16 = (uint16_t)blimit << (bd - 8);
452 mask |= (abs(p1 - p0) > limit16) * -1;
453 mask |= (abs(q1 - q0) > limit16) * -1;
454 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
455 return ~mask;
456 }
457
458 // 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)459 static INLINE int8_t highbd_filter_mask(uint8_t limit, uint8_t blimit,
460 uint16_t p3, uint16_t p2, uint16_t p1,
461 uint16_t p0, uint16_t q0, uint16_t q1,
462 uint16_t q2, uint16_t q3, int bd) {
463 int8_t mask = 0;
464 int16_t limit16 = (uint16_t)limit << (bd - 8);
465 int16_t blimit16 = (uint16_t)blimit << (bd - 8);
466 mask |= (abs(p3 - p2) > limit16) * -1;
467 mask |= (abs(p2 - p1) > limit16) * -1;
468 mask |= (abs(p1 - p0) > limit16) * -1;
469 mask |= (abs(q1 - q0) > limit16) * -1;
470 mask |= (abs(q2 - q1) > limit16) * -1;
471 mask |= (abs(q3 - q2) > limit16) * -1;
472 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
473 return ~mask;
474 }
475
highbd_filter_mask3_chroma(uint8_t limit,uint8_t blimit,uint16_t p2,uint16_t p1,uint16_t p0,uint16_t q0,uint16_t q1,uint16_t q2,int bd)476 static INLINE int8_t highbd_filter_mask3_chroma(uint8_t limit, uint8_t blimit,
477 uint16_t p2, uint16_t p1,
478 uint16_t p0, uint16_t q0,
479 uint16_t q1, uint16_t q2,
480 int bd) {
481 int8_t mask = 0;
482 int16_t limit16 = (uint16_t)limit << (bd - 8);
483 int16_t blimit16 = (uint16_t)blimit << (bd - 8);
484 mask |= (abs(p2 - p1) > limit16) * -1;
485 mask |= (abs(p1 - p0) > limit16) * -1;
486 mask |= (abs(q1 - q0) > limit16) * -1;
487 mask |= (abs(q2 - q1) > limit16) * -1;
488 mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
489 return ~mask;
490 }
491
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)492 static INLINE int8_t highbd_flat_mask3_chroma(uint8_t thresh, uint16_t p2,
493 uint16_t p1, uint16_t p0,
494 uint16_t q0, uint16_t q1,
495 uint16_t q2, int bd) {
496 int8_t mask = 0;
497 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
498 mask |= (abs(p1 - p0) > thresh16) * -1;
499 mask |= (abs(q1 - q0) > thresh16) * -1;
500 mask |= (abs(p2 - p0) > thresh16) * -1;
501 mask |= (abs(q2 - q0) > thresh16) * -1;
502 return ~mask;
503 }
504
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)505 static INLINE int8_t highbd_flat_mask4(uint8_t thresh, uint16_t p3, uint16_t p2,
506 uint16_t p1, uint16_t p0, uint16_t q0,
507 uint16_t q1, uint16_t q2, uint16_t q3,
508 int bd) {
509 int8_t mask = 0;
510 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
511 mask |= (abs(p1 - p0) > thresh16) * -1;
512 mask |= (abs(q1 - q0) > thresh16) * -1;
513 mask |= (abs(p2 - p0) > thresh16) * -1;
514 mask |= (abs(q2 - q0) > thresh16) * -1;
515 mask |= (abs(p3 - p0) > thresh16) * -1;
516 mask |= (abs(q3 - q0) > thresh16) * -1;
517 return ~mask;
518 }
519
520 // Is there high edge variance internal edge:
521 // 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)522 static INLINE int16_t highbd_hev_mask(uint8_t thresh, uint16_t p1, uint16_t p0,
523 uint16_t q0, uint16_t q1, int bd) {
524 int16_t hev = 0;
525 int16_t thresh16 = (uint16_t)thresh << (bd - 8);
526 hev |= (abs(p1 - p0) > thresh16) * -1;
527 hev |= (abs(q1 - q0) > thresh16) * -1;
528 return hev;
529 }
530
highbd_filter4(int8_t mask,uint8_t thresh,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,int bd)531 static INLINE void highbd_filter4(int8_t mask, uint8_t thresh, uint16_t *op1,
532 uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
533 int bd) {
534 int16_t filter1, filter2;
535 // ^0x80 equivalent to subtracting 0x80 from the values to turn them
536 // into -128 to +127 instead of 0 to 255.
537 int shift = bd - 8;
538 const int16_t ps1 = (int16_t)*op1 - (0x80 << shift);
539 const int16_t ps0 = (int16_t)*op0 - (0x80 << shift);
540 const int16_t qs0 = (int16_t)*oq0 - (0x80 << shift);
541 const int16_t qs1 = (int16_t)*oq1 - (0x80 << shift);
542 const uint16_t hev = highbd_hev_mask(thresh, *op1, *op0, *oq0, *oq1, bd);
543
544 // Add outer taps if we have high edge variance.
545 int16_t filter = signed_char_clamp_high(ps1 - qs1, bd) & hev;
546
547 // Inner taps.
548 filter = signed_char_clamp_high(filter + 3 * (qs0 - ps0), bd) & mask;
549
550 // Save bottom 3 bits so that we round one side +4 and the other +3
551 // if it equals 4 we'll set to adjust by -1 to account for the fact
552 // we'd round 3 the other way.
553 filter1 = signed_char_clamp_high(filter + 4, bd) >> 3;
554 filter2 = signed_char_clamp_high(filter + 3, bd) >> 3;
555
556 *oq0 = signed_char_clamp_high(qs0 - filter1, bd) + (0x80 << shift);
557 *op0 = signed_char_clamp_high(ps0 + filter2, bd) + (0x80 << shift);
558
559 // Outer tap adjustments.
560 filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
561
562 *oq1 = signed_char_clamp_high(qs1 - filter, bd) + (0x80 << shift);
563 *op1 = signed_char_clamp_high(ps1 + filter, bd) + (0x80 << shift);
564 }
565
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)566 void aom_highbd_lpf_horizontal_4_c(uint16_t *s, int p /* pitch */,
567 const uint8_t *blimit, const uint8_t *limit,
568 const uint8_t *thresh, int bd) {
569 int i;
570 int count = 4;
571
572 // loop filter designed to work using chars so that we can make maximum use
573 // of 8 bit simd instructions.
574 for (i = 0; i < count; ++i) {
575 const uint16_t p1 = s[-2 * p];
576 const uint16_t p0 = s[-p];
577 const uint16_t q0 = s[0 * p];
578 const uint16_t q1 = s[1 * p];
579 const int8_t mask =
580 highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd);
581 highbd_filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p, bd);
582 ++s;
583 }
584 }
585
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)586 void aom_highbd_lpf_horizontal_4_dual_c(
587 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
588 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
589 const uint8_t *thresh1, int bd) {
590 aom_highbd_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0, bd);
591 aom_highbd_lpf_horizontal_4_c(s + 4, p, blimit1, limit1, thresh1, bd);
592 }
593
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)594 void aom_highbd_lpf_vertical_4_c(uint16_t *s, int pitch, const uint8_t *blimit,
595 const uint8_t *limit, const uint8_t *thresh,
596 int bd) {
597 int i;
598 int count = 4;
599
600 // loop filter designed to work using chars so that we can make maximum use
601 // of 8 bit simd instructions.
602 for (i = 0; i < count; ++i) {
603 const uint16_t p1 = s[-2], p0 = s[-1];
604 const uint16_t q0 = s[0], q1 = s[1];
605 const int8_t mask =
606 highbd_filter_mask2(*limit, *blimit, p1, p0, q0, q1, bd);
607 highbd_filter4(mask, *thresh, s - 2, s - 1, s, s + 1, bd);
608 s += pitch;
609 }
610 }
611
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)612 void aom_highbd_lpf_vertical_4_dual_c(
613 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
614 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
615 const uint8_t *thresh1, int bd) {
616 aom_highbd_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0, bd);
617 aom_highbd_lpf_vertical_4_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1,
618 bd);
619 }
620
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)621 static INLINE void highbd_filter6(int8_t mask, uint8_t thresh, int8_t flat,
622 uint16_t *op2, uint16_t *op1, uint16_t *op0,
623 uint16_t *oq0, uint16_t *oq1, uint16_t *oq2,
624 int bd) {
625 if (flat && mask) {
626 const uint16_t p2 = *op2, p1 = *op1, p0 = *op0;
627 const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2;
628
629 // 5-tap filter [1, 2, 2, 2, 1]
630 *op1 = ROUND_POWER_OF_TWO(p2 * 3 + p1 * 2 + p0 * 2 + q0, 3);
631 *op0 = ROUND_POWER_OF_TWO(p2 + p1 * 2 + p0 * 2 + q0 * 2 + q1, 3);
632 *oq0 = ROUND_POWER_OF_TWO(p1 + p0 * 2 + q0 * 2 + q1 * 2 + q2, 3);
633 *oq1 = ROUND_POWER_OF_TWO(p0 + q0 * 2 + q1 * 2 + q2 * 3, 3);
634 } else {
635 highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd);
636 }
637 }
638
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)639 static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, int8_t flat,
640 uint16_t *op3, uint16_t *op2, uint16_t *op1,
641 uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
642 uint16_t *oq2, uint16_t *oq3, int bd) {
643 if (flat && mask) {
644 const uint16_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
645 const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
646
647 // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
648 *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
649 *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
650 *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
651 *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
652 *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
653 *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
654 } else {
655 highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd);
656 }
657 }
658
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)659 void aom_highbd_lpf_horizontal_8_c(uint16_t *s, int p, const uint8_t *blimit,
660 const uint8_t *limit, const uint8_t *thresh,
661 int bd) {
662 int i;
663 int count = 4;
664
665 // loop filter designed to work using chars so that we can make maximum use
666 // of 8 bit simd instructions.
667 for (i = 0; i < count; ++i) {
668 const uint16_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
669 const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
670
671 const int8_t mask =
672 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
673 const int8_t flat =
674 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
675 highbd_filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p,
676 s - 1 * p, s, s + 1 * p, s + 2 * p, s + 3 * p, bd);
677 ++s;
678 }
679 }
680
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)681 void aom_highbd_lpf_horizontal_6_c(uint16_t *s, int p, const uint8_t *blimit,
682 const uint8_t *limit, const uint8_t *thresh,
683 int bd) {
684 int i;
685 int count = 4;
686
687 // loop filter designed to work using chars so that we can make maximum use
688 // of 8 bit simd instructions.
689 for (i = 0; i < count; ++i) {
690 const uint16_t p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
691 const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p];
692
693 const int8_t mask =
694 highbd_filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2, bd);
695 const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd);
696 highbd_filter6(mask, *thresh, flat, s - 3 * p, s - 2 * p, s - 1 * p, s,
697 s + 1 * p, s + 2 * p, bd);
698 ++s;
699 }
700 }
701
aom_highbd_lpf_horizontal_6_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)702 void aom_highbd_lpf_horizontal_6_dual_c(
703 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
704 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
705 const uint8_t *thresh1, int bd) {
706 aom_highbd_lpf_horizontal_6_c(s, p, blimit0, limit0, thresh0, bd);
707 aom_highbd_lpf_horizontal_6_c(s + 4, p, blimit1, limit1, thresh1, bd);
708 }
709
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)710 void aom_highbd_lpf_horizontal_8_dual_c(
711 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
712 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
713 const uint8_t *thresh1, int bd) {
714 aom_highbd_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0, bd);
715 aom_highbd_lpf_horizontal_8_c(s + 4, p, blimit1, limit1, thresh1, bd);
716 }
717
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)718 void aom_highbd_lpf_vertical_6_c(uint16_t *s, int pitch, const uint8_t *blimit,
719 const uint8_t *limit, const uint8_t *thresh,
720 int bd) {
721 int i;
722 int count = 4;
723
724 for (i = 0; i < count; ++i) {
725 const uint16_t p2 = s[-3], p1 = s[-2], p0 = s[-1];
726 const uint16_t q0 = s[0], q1 = s[1], q2 = s[2];
727 const int8_t mask =
728 highbd_filter_mask3_chroma(*limit, *blimit, p2, p1, p0, q0, q1, q2, bd);
729 const int8_t flat = highbd_flat_mask3_chroma(1, p2, p1, p0, q0, q1, q2, bd);
730 highbd_filter6(mask, *thresh, flat, s - 3, s - 2, s - 1, s, s + 1, s + 2,
731 bd);
732 s += pitch;
733 }
734 }
735
aom_highbd_lpf_vertical_6_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)736 void aom_highbd_lpf_vertical_6_dual_c(
737 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
738 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
739 const uint8_t *thresh1, int bd) {
740 aom_highbd_lpf_vertical_6_c(s, pitch, blimit0, limit0, thresh0, bd);
741 aom_highbd_lpf_vertical_6_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1,
742 bd);
743 }
744
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)745 void aom_highbd_lpf_vertical_8_c(uint16_t *s, int pitch, const uint8_t *blimit,
746 const uint8_t *limit, const uint8_t *thresh,
747 int bd) {
748 int i;
749 int count = 4;
750
751 for (i = 0; i < count; ++i) {
752 const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
753 const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
754 const int8_t mask =
755 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
756 const int8_t flat =
757 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
758 highbd_filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1,
759 s + 2, s + 3, bd);
760 s += pitch;
761 }
762 }
763
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)764 void aom_highbd_lpf_vertical_8_dual_c(
765 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
766 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
767 const uint8_t *thresh1, int bd) {
768 aom_highbd_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0, bd);
769 aom_highbd_lpf_vertical_8_c(s + 4 * pitch, pitch, blimit1, limit1, thresh1,
770 bd);
771 }
772
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)773 static INLINE void highbd_filter14(int8_t mask, uint8_t thresh, int8_t flat,
774 int8_t flat2, uint16_t *op6, uint16_t *op5,
775 uint16_t *op4, uint16_t *op3, uint16_t *op2,
776 uint16_t *op1, uint16_t *op0, uint16_t *oq0,
777 uint16_t *oq1, uint16_t *oq2, uint16_t *oq3,
778 uint16_t *oq4, uint16_t *oq5, uint16_t *oq6,
779 int bd) {
780 if (flat2 && flat && mask) {
781 const uint16_t p6 = *op6;
782 const uint16_t p5 = *op5;
783 const uint16_t p4 = *op4;
784 const uint16_t p3 = *op3;
785 const uint16_t p2 = *op2;
786 const uint16_t p1 = *op1;
787 const uint16_t p0 = *op0;
788 const uint16_t q0 = *oq0;
789 const uint16_t q1 = *oq1;
790 const uint16_t q2 = *oq2;
791 const uint16_t q3 = *oq3;
792 const uint16_t q4 = *oq4;
793 const uint16_t q5 = *oq5;
794 const uint16_t q6 = *oq6;
795
796 // 13-tap filter [1, 1, 1, 1, 1, 2, 2, 2, 1, 1, 1, 1, 1]
797 *op5 = ROUND_POWER_OF_TWO(p6 * 7 + p5 * 2 + p4 * 2 + p3 + p2 + p1 + p0 + q0,
798 4);
799 *op4 = ROUND_POWER_OF_TWO(
800 p6 * 5 + p5 * 2 + p4 * 2 + p3 * 2 + p2 + p1 + p0 + q0 + q1, 4);
801 *op3 = ROUND_POWER_OF_TWO(
802 p6 * 4 + p5 + p4 * 2 + p3 * 2 + p2 * 2 + p1 + p0 + q0 + q1 + q2, 4);
803 *op2 = ROUND_POWER_OF_TWO(
804 p6 * 3 + p5 + p4 + p3 * 2 + p2 * 2 + p1 * 2 + p0 + q0 + q1 + q2 + q3,
805 4);
806 *op1 = ROUND_POWER_OF_TWO(p6 * 2 + p5 + p4 + p3 + p2 * 2 + p1 * 2 + p0 * 2 +
807 q0 + q1 + q2 + q3 + q4,
808 4);
809 *op0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 * 2 +
810 q0 * 2 + q1 + q2 + q3 + q4 + q5,
811 4);
812 *oq0 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 * 2 +
813 q1 * 2 + q2 + q3 + q4 + q5 + q6,
814 4);
815 *oq1 = ROUND_POWER_OF_TWO(p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 * 2 +
816 q2 * 2 + q3 + q4 + q5 + q6 * 2,
817 4);
818 *oq2 = ROUND_POWER_OF_TWO(
819 p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 * 2 + q3 * 2 + q4 + q5 + q6 * 3,
820 4);
821 *oq3 = ROUND_POWER_OF_TWO(
822 p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 * 2 + q4 * 2 + q5 + q6 * 4, 4);
823 *oq4 = ROUND_POWER_OF_TWO(
824 p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 * 2 + q5 * 2 + q6 * 5, 4);
825 *oq5 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 * 2 + q6 * 7,
826 4);
827 } else {
828 highbd_filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3,
829 bd);
830 }
831 }
832
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)833 static void highbd_mb_lpf_horizontal_edge_w(uint16_t *s, int p,
834 const uint8_t *blimit,
835 const uint8_t *limit,
836 const uint8_t *thresh, int count,
837 int bd) {
838 int i;
839 int step = 4;
840
841 // loop filter designed to work using chars so that we can make maximum use
842 // of 8 bit simd instructions.
843 for (i = 0; i < step * count; ++i) {
844 const uint16_t p3 = s[-4 * p];
845 const uint16_t p2 = s[-3 * p];
846 const uint16_t p1 = s[-2 * p];
847 const uint16_t p0 = s[-p];
848 const uint16_t q0 = s[0 * p];
849 const uint16_t q1 = s[1 * p];
850 const uint16_t q2 = s[2 * p];
851 const uint16_t q3 = s[3 * p];
852 const int8_t mask =
853 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
854 const int8_t flat =
855 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
856
857 const int8_t flat2 =
858 highbd_flat_mask4(1, s[-7 * p], s[-6 * p], s[-5 * p], p0, q0, s[4 * p],
859 s[5 * p], s[6 * p], bd);
860
861 highbd_filter14(mask, *thresh, flat, flat2, s - 7 * p, s - 6 * p, s - 5 * p,
862 s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s, s + 1 * p,
863 s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p, bd);
864 ++s;
865 }
866 }
867
aom_highbd_lpf_horizontal_14_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)868 void aom_highbd_lpf_horizontal_14_c(uint16_t *s, int p, const uint8_t *blimit,
869 const uint8_t *limit, const uint8_t *thresh,
870 int bd) {
871 highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1, bd);
872 }
873
aom_highbd_lpf_horizontal_14_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)874 void aom_highbd_lpf_horizontal_14_dual_c(
875 uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
876 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
877 const uint8_t *thresh1, int bd) {
878 highbd_mb_lpf_horizontal_edge_w(s, p, blimit0, limit0, thresh0, 1, bd);
879 highbd_mb_lpf_horizontal_edge_w(s + 4, p, blimit1, limit1, thresh1, 1, bd);
880 }
881
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)882 static void highbd_mb_lpf_vertical_edge_w(uint16_t *s, int p,
883 const uint8_t *blimit,
884 const uint8_t *limit,
885 const uint8_t *thresh, int count,
886 int bd) {
887 int i;
888
889 for (i = 0; i < count; ++i) {
890 const uint16_t p3 = s[-4];
891 const uint16_t p2 = s[-3];
892 const uint16_t p1 = s[-2];
893 const uint16_t p0 = s[-1];
894 const uint16_t q0 = s[0];
895 const uint16_t q1 = s[1];
896 const uint16_t q2 = s[2];
897 const uint16_t q3 = s[3];
898 const int8_t mask =
899 highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
900 const int8_t flat =
901 highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
902 const int8_t flat2 =
903 highbd_flat_mask4(1, s[-7], s[-6], s[-5], p0, q0, s[4], s[5], s[6], bd);
904
905 highbd_filter14(mask, *thresh, flat, flat2, s - 7, s - 6, s - 5, s - 4,
906 s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5,
907 s + 6, bd);
908 s += p;
909 }
910 }
911
aom_highbd_lpf_vertical_14_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)912 void aom_highbd_lpf_vertical_14_c(uint16_t *s, int p, const uint8_t *blimit,
913 const uint8_t *limit, const uint8_t *thresh,
914 int bd) {
915 highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 4, bd);
916 }
917
aom_highbd_lpf_vertical_14_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)918 void aom_highbd_lpf_vertical_14_dual_c(
919 uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
920 const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
921 const uint8_t *thresh1, int bd) {
922 highbd_mb_lpf_vertical_edge_w(s, pitch, blimit0, limit0, thresh0, 4, bd);
923 highbd_mb_lpf_vertical_edge_w(s + 4 * pitch, pitch, blimit1, limit1, thresh1,
924 4, bd);
925 }
926