1 /*
2  *  Copyright (c) 2015 The WebM project authors. All Rights Reserved.
3  *
4  *  Use of this source code is governed by a BSD-style license
5  *  that can be found in the LICENSE file in the root of the source
6  *  tree. An additional intellectual property rights grant can be found
7  *  in the file PATENTS.  All contributing project authors may
8  *  be found in the AUTHORS file in the root of the source tree.
9  */
10 
11 #include <stdlib.h>
12 
13 #include "vpx_dsp_rtcd.h"
14 #include "vpx_dsp_common.h"
15 #include "mem.h"
16 
signed_char_clamp(int t)17 static INLINE int8_t signed_char_clamp(int t) {
18   return (int8_t)clamp(t, -128, 127);
19 }
20 
21 #if CONFIG_VP9_HIGHBITDEPTH
signed_char_clamp_high(int t,int bd)22 static INLINE int16_t signed_char_clamp_high(int t, int bd) {
23   switch (bd) {
24     case 10: return (int16_t)clamp(t, -128 * 4, 128 * 4 - 1);
25     case 12: return (int16_t)clamp(t, -128 * 16, 128 * 16 - 1);
26     case 8:
27     default: return (int16_t)clamp(t, -128, 128 - 1);
28   }
29 }
30 #endif
31 
32 // Should we apply any filter at all: 11111111 yes, 00000000 no
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)33 static INLINE int8_t filter_mask(uint8_t limit, uint8_t blimit, uint8_t p3,
34                                  uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0,
35                                  uint8_t q1, uint8_t q2, uint8_t q3) {
36   int8_t mask = 0;
37   mask |= (abs(p3 - p2) > limit) * -1;
38   mask |= (abs(p2 - p1) > limit) * -1;
39   mask |= (abs(p1 - p0) > limit) * -1;
40   mask |= (abs(q1 - q0) > limit) * -1;
41   mask |= (abs(q2 - q1) > limit) * -1;
42   mask |= (abs(q3 - q2) > limit) * -1;
43   mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit) * -1;
44   return ~mask;
45 }
46 
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)47 static INLINE int8_t flat_mask4(uint8_t thresh, uint8_t p3, uint8_t p2,
48                                 uint8_t p1, uint8_t p0, uint8_t q0, uint8_t q1,
49                                 uint8_t q2, uint8_t q3) {
50   int8_t mask = 0;
51   mask |= (abs(p1 - p0) > thresh) * -1;
52   mask |= (abs(q1 - q0) > thresh) * -1;
53   mask |= (abs(p2 - p0) > thresh) * -1;
54   mask |= (abs(q2 - q0) > thresh) * -1;
55   mask |= (abs(p3 - p0) > thresh) * -1;
56   mask |= (abs(q3 - q0) > thresh) * -1;
57   return ~mask;
58 }
59 
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)60 static INLINE int8_t flat_mask5(uint8_t thresh, uint8_t p4, uint8_t p3,
61                                 uint8_t p2, uint8_t p1, uint8_t p0, uint8_t q0,
62                                 uint8_t q1, uint8_t q2, uint8_t q3,
63                                 uint8_t q4) {
64   int8_t mask = ~flat_mask4(thresh, p3, p2, p1, p0, q0, q1, q2, q3);
65   mask |= (abs(p4 - p0) > thresh) * -1;
66   mask |= (abs(q4 - q0) > thresh) * -1;
67   return ~mask;
68 }
69 
70 // 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)71 static INLINE int8_t hev_mask(uint8_t thresh, uint8_t p1, uint8_t p0,
72                               uint8_t q0, uint8_t q1) {
73   int8_t hev = 0;
74   hev |= (abs(p1 - p0) > thresh) * -1;
75   hev |= (abs(q1 - q0) > thresh) * -1;
76   return hev;
77 }
78 
filter4(int8_t mask,uint8_t thresh,uint8_t * op1,uint8_t * op0,uint8_t * oq0,uint8_t * oq1)79 static INLINE void filter4(int8_t mask, uint8_t thresh, uint8_t *op1,
80                            uint8_t *op0, uint8_t *oq0, uint8_t *oq1) {
81   int8_t filter1, filter2;
82 
83   const int8_t ps1 = (int8_t)*op1 ^ 0x80;
84   const int8_t ps0 = (int8_t)*op0 ^ 0x80;
85   const int8_t qs0 = (int8_t)*oq0 ^ 0x80;
86   const int8_t qs1 = (int8_t)*oq1 ^ 0x80;
87   const uint8_t hev = hev_mask(thresh, *op1, *op0, *oq0, *oq1);
88 
89   // add outer taps if we have high edge variance
90   int8_t filter = signed_char_clamp(ps1 - qs1) & hev;
91 
92   // inner taps
93   filter = signed_char_clamp(filter + 3 * (qs0 - ps0)) & mask;
94 
95   // save bottom 3 bits so that we round one side +4 and the other +3
96   // if it equals 4 we'll set it to adjust by -1 to account for the fact
97   // we'd round it by 3 the other way
98   filter1 = signed_char_clamp(filter + 4) >> 3;
99   filter2 = signed_char_clamp(filter + 3) >> 3;
100 
101   *oq0 = signed_char_clamp(qs0 - filter1) ^ 0x80;
102   *op0 = signed_char_clamp(ps0 + filter2) ^ 0x80;
103 
104   // outer tap adjustments
105   filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
106 
107   *oq1 = signed_char_clamp(qs1 - filter) ^ 0x80;
108   *op1 = signed_char_clamp(ps1 + filter) ^ 0x80;
109 }
110 
eb_vp9_lpf_horizontal_4_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)111 void eb_vp9_lpf_horizontal_4_c(uint8_t *s, int p /* pitch */,
112                             const uint8_t *blimit, const uint8_t *limit,
113                             const uint8_t *thresh) {
114   int i;
115 
116   // loop filter designed to work using chars so that we can make maximum use
117   // of 8 bit simd instructions.
118   for (i = 0; i < 8; ++i) {
119     const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
120     const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
121     const int8_t mask =
122         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
123     filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p);
124     ++s;
125   }
126 }
127 
eb_vp9_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)128 void eb_vp9_lpf_horizontal_4_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
129                                  const uint8_t *limit0, const uint8_t *thresh0,
130                                  const uint8_t *blimit1, const uint8_t *limit1,
131                                  const uint8_t *thresh1) {
132   eb_vp9_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0);
133   eb_vp9_lpf_horizontal_4_c(s + 8, p, blimit1, limit1, thresh1);
134 }
135 
eb_vp9_lpf_vertical_4_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)136 void eb_vp9_lpf_vertical_4_c(uint8_t *s, int pitch, const uint8_t *blimit,
137                           const uint8_t *limit, const uint8_t *thresh) {
138   int i;
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 < 8; ++i) {
143     const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
144     const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
145     const int8_t mask =
146         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
147     filter4(mask, *thresh, s - 2, s - 1, s, s + 1);
148     s += pitch;
149   }
150 }
151 
eb_vp9_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)152 void eb_vp9_lpf_vertical_4_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
153                                const uint8_t *limit0, const uint8_t *thresh0,
154                                const uint8_t *blimit1, const uint8_t *limit1,
155                                const uint8_t *thresh1) {
156   eb_vp9_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0);
157   eb_vp9_lpf_vertical_4_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1);
158 }
159 
filter8(int8_t mask,uint8_t thresh,uint8_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)160 static INLINE void filter8(int8_t mask, uint8_t thresh, uint8_t flat,
161                            uint8_t *op3, uint8_t *op2, uint8_t *op1,
162                            uint8_t *op0, uint8_t *oq0, uint8_t *oq1,
163                            uint8_t *oq2, uint8_t *oq3) {
164   if (flat && mask) {
165     const uint8_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
166     const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
167 
168     // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
169     *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
170     *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
171     *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
172     *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
173     *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
174     *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
175   } else {
176     filter4(mask, thresh, op1, op0, oq0, oq1);
177   }
178 }
179 
eb_vp9_lpf_horizontal_8_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)180 void eb_vp9_lpf_horizontal_8_c(uint8_t *s, int p, const uint8_t *blimit,
181                             const uint8_t *limit, const uint8_t *thresh) {
182   int i;
183 
184   // loop filter designed to work using chars so that we can make maximum use
185   // of 8 bit simd instructions.
186   for (i = 0; i < 8; ++i) {
187     const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
188     const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
189 
190     const int8_t mask =
191         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
192     const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
193     filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
194             s + 1 * p, s + 2 * p, s + 3 * p);
195     ++s;
196   }
197 }
198 
eb_vp9_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)199 void eb_vp9_lpf_horizontal_8_dual_c(uint8_t *s, int p, const uint8_t *blimit0,
200                                  const uint8_t *limit0, const uint8_t *thresh0,
201                                  const uint8_t *blimit1, const uint8_t *limit1,
202                                  const uint8_t *thresh1) {
203   eb_vp9_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0);
204   eb_vp9_lpf_horizontal_8_c(s + 8, p, blimit1, limit1, thresh1);
205 }
206 
eb_vp9_lpf_vertical_8_c(uint8_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)207 void eb_vp9_lpf_vertical_8_c(uint8_t *s, int pitch, const uint8_t *blimit,
208                           const uint8_t *limit, const uint8_t *thresh) {
209   int i;
210 
211   for (i = 0; i < 8; ++i) {
212     const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
213     const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
214     const int8_t mask =
215         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
216     const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
217     filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2,
218             s + 3);
219     s += pitch;
220   }
221 }
222 
eb_vp9_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)223 void eb_vp9_lpf_vertical_8_dual_c(uint8_t *s, int pitch, const uint8_t *blimit0,
224                                const uint8_t *limit0, const uint8_t *thresh0,
225                                const uint8_t *blimit1, const uint8_t *limit1,
226                                const uint8_t *thresh1) {
227   eb_vp9_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0);
228   eb_vp9_lpf_vertical_8_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1);
229 }
230 
filter16(int8_t mask,uint8_t thresh,uint8_t flat,uint8_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)231 static INLINE void filter16(int8_t mask, uint8_t thresh, uint8_t flat,
232                             uint8_t flat2, uint8_t *op7, uint8_t *op6,
233                             uint8_t *op5, uint8_t *op4, uint8_t *op3,
234                             uint8_t *op2, uint8_t *op1, uint8_t *op0,
235                             uint8_t *oq0, uint8_t *oq1, uint8_t *oq2,
236                             uint8_t *oq3, uint8_t *oq4, uint8_t *oq5,
237                             uint8_t *oq6, uint8_t *oq7) {
238   if (flat2 && flat && mask) {
239     const uint8_t p7 = *op7, p6 = *op6, p5 = *op5, p4 = *op4, p3 = *op3,
240                   p2 = *op2, p1 = *op1, p0 = *op0;
241 
242     const uint8_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3, q4 = *oq4,
243                   q5 = *oq5, q6 = *oq6, q7 = *oq7;
244 
245     // 15-tap filter [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]
246     *op6 = ROUND_POWER_OF_TWO(
247         p7 * 7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 + q0, 4);
248     *op5 = ROUND_POWER_OF_TWO(
249         p7 * 6 + p6 + p5 * 2 + p4 + p3 + p2 + p1 + p0 + q0 + q1, 4);
250     *op4 = ROUND_POWER_OF_TWO(
251         p7 * 5 + p6 + p5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + q1 + q2, 4);
252     *op3 = ROUND_POWER_OF_TWO(
253         p7 * 4 + p6 + p5 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + q2 + q3, 4);
254     *op2 = ROUND_POWER_OF_TWO(
255         p7 * 3 + p6 + p5 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + q3 + q4,
256         4);
257     *op1 = ROUND_POWER_OF_TWO(p7 * 2 + p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 +
258                                   q0 + q1 + q2 + q3 + q4 + q5,
259                               4);
260     *op0 = ROUND_POWER_OF_TWO(p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 +
261                                   q1 + q2 + q3 + q4 + q5 + q6,
262                               4);
263     *oq0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 +
264                                   q2 + q3 + q4 + q5 + q6 + q7,
265                               4);
266     *oq1 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 +
267                                   q3 + q4 + q5 + q6 + q7 * 2,
268                               4);
269     *oq2 = ROUND_POWER_OF_TWO(
270         p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 + q6 + q7 * 3,
271         4);
272     *oq3 = ROUND_POWER_OF_TWO(
273         p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 + q6 + q7 * 4, 4);
274     *oq4 = ROUND_POWER_OF_TWO(
275         p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 + q6 + q7 * 5, 4);
276     *oq5 = ROUND_POWER_OF_TWO(
277         p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 * 6, 4);
278     *oq6 = ROUND_POWER_OF_TWO(
279         p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 * 7, 4);
280   } else {
281     filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3);
282   }
283 }
284 
mb_lpf_horizontal_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)285 static void mb_lpf_horizontal_edge_w(uint8_t *s, int p, const uint8_t *blimit,
286                                      const uint8_t *limit,
287                                      const uint8_t *thresh, int count) {
288   int i;
289 
290   // loop filter designed to work using chars so that we can make maximum use
291   // of 8 bit simd instructions.
292   for (i = 0; i < 8 * count; ++i) {
293     const uint8_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
294     const uint8_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
295     const int8_t mask =
296         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
297     const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
298     const int8_t flat2 =
299         flat_mask5(1, s[-8 * p], s[-7 * p], s[-6 * p], s[-5 * p], p0, q0,
300                    s[4 * p], s[5 * p], s[6 * p], s[7 * p]);
301 
302     filter16(mask, *thresh, flat, flat2, s - 8 * p, s - 7 * p, s - 6 * p,
303              s - 5 * p, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
304              s + 1 * p, s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p, s + 6 * p,
305              s + 7 * p);
306     ++s;
307   }
308 }
309 
eb_vp9_lpf_horizontal_16_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)310 void eb_vp9_lpf_horizontal_16_c(uint8_t *s, int p, const uint8_t *blimit,
311                              const uint8_t *limit, const uint8_t *thresh) {
312   mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1);
313 }
314 
eb_vp9_lpf_horizontal_16_dual_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)315 void eb_vp9_lpf_horizontal_16_dual_c(uint8_t *s, int p, const uint8_t *blimit,
316                                   const uint8_t *limit, const uint8_t *thresh) {
317   mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 2);
318 }
319 
mb_lpf_vertical_edge_w(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int count)320 static void mb_lpf_vertical_edge_w(uint8_t *s, int p, const uint8_t *blimit,
321                                    const uint8_t *limit, const uint8_t *thresh,
322                                    int count) {
323   int i;
324 
325   for (i = 0; i < count; ++i) {
326     const uint8_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
327     const uint8_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
328     const int8_t mask =
329         filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3);
330     const int8_t flat = flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3);
331     const int8_t flat2 = flat_mask5(1, s[-8], s[-7], s[-6], s[-5], p0, q0, s[4],
332                                     s[5], s[6], s[7]);
333 
334     filter16(mask, *thresh, flat, flat2, s - 8, s - 7, s - 6, s - 5, s - 4,
335              s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4, s + 5, s + 6,
336              s + 7);
337     s += p;
338   }
339 }
340 
eb_vp9_lpf_vertical_16_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)341 void eb_vp9_lpf_vertical_16_c(uint8_t *s, int p, const uint8_t *blimit,
342                            const uint8_t *limit, const uint8_t *thresh) {
343   mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 8);
344 }
345 
eb_vp9_lpf_vertical_16_dual_c(uint8_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh)346 void eb_vp9_lpf_vertical_16_dual_c(uint8_t *s, int p, const uint8_t *blimit,
347                                 const uint8_t *limit, const uint8_t *thresh) {
348   mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 16);
349 }
350 
351 #if CONFIG_VP9_HIGHBITDEPTH
352 // 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)353 static INLINE int8_t highbd_filter_mask(uint8_t limit, uint8_t blimit,
354                                         uint16_t p3, uint16_t p2, uint16_t p1,
355                                         uint16_t p0, uint16_t q0, uint16_t q1,
356                                         uint16_t q2, uint16_t q3, int bd) {
357   int8_t mask = 0;
358   int16_t limit16 = (uint16_t)limit << (bd - 8);
359   int16_t blimit16 = (uint16_t)blimit << (bd - 8);
360   mask |= (abs(p3 - p2) > limit16) * -1;
361   mask |= (abs(p2 - p1) > limit16) * -1;
362   mask |= (abs(p1 - p0) > limit16) * -1;
363   mask |= (abs(q1 - q0) > limit16) * -1;
364   mask |= (abs(q2 - q1) > limit16) * -1;
365   mask |= (abs(q3 - q2) > limit16) * -1;
366   mask |= (abs(p0 - q0) * 2 + abs(p1 - q1) / 2 > blimit16) * -1;
367   return ~mask;
368 }
369 
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)370 static INLINE int8_t highbd_flat_mask4(uint8_t thresh, uint16_t p3, uint16_t p2,
371                                        uint16_t p1, uint16_t p0, uint16_t q0,
372                                        uint16_t q1, uint16_t q2, uint16_t q3,
373                                        int bd) {
374   int8_t mask = 0;
375   int16_t thresh16 = (uint16_t)thresh << (bd - 8);
376   mask |= (abs(p1 - p0) > thresh16) * -1;
377   mask |= (abs(q1 - q0) > thresh16) * -1;
378   mask |= (abs(p2 - p0) > thresh16) * -1;
379   mask |= (abs(q2 - q0) > thresh16) * -1;
380   mask |= (abs(p3 - p0) > thresh16) * -1;
381   mask |= (abs(q3 - q0) > thresh16) * -1;
382   return ~mask;
383 }
384 
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)385 static INLINE int8_t highbd_flat_mask5(uint8_t thresh, uint16_t p4, uint16_t p3,
386                                        uint16_t p2, uint16_t p1, uint16_t p0,
387                                        uint16_t q0, uint16_t q1, uint16_t q2,
388                                        uint16_t q3, uint16_t q4, int bd) {
389   int8_t mask = ~highbd_flat_mask4(thresh, p3, p2, p1, p0, q0, q1, q2, q3, bd);
390   int16_t thresh16 = (uint16_t)thresh << (bd - 8);
391   mask |= (abs(p4 - p0) > thresh16) * -1;
392   mask |= (abs(q4 - q0) > thresh16) * -1;
393   return ~mask;
394 }
395 
396 // Is there high edge variance internal edge:
397 // 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)398 static INLINE int16_t highbd_hev_mask(uint8_t thresh, uint16_t p1, uint16_t p0,
399                                       uint16_t q0, uint16_t q1, int bd) {
400   int16_t hev = 0;
401   int16_t thresh16 = (uint16_t)thresh << (bd - 8);
402   hev |= (abs(p1 - p0) > thresh16) * -1;
403   hev |= (abs(q1 - q0) > thresh16) * -1;
404   return hev;
405 }
406 
highbd_filter4(int8_t mask,uint8_t thresh,uint16_t * op1,uint16_t * op0,uint16_t * oq0,uint16_t * oq1,int bd)407 static INLINE void highbd_filter4(int8_t mask, uint8_t thresh, uint16_t *op1,
408                                   uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
409                                   int bd) {
410   int16_t filter1, filter2;
411   // ^0x80 equivalent to subtracting 0x80 from the values to turn them
412   // into -128 to +127 instead of 0 to 255.
413   int shift = bd - 8;
414   const int16_t ps1 = (int16_t)*op1 - (0x80 << shift);
415   const int16_t ps0 = (int16_t)*op0 - (0x80 << shift);
416   const int16_t qs0 = (int16_t)*oq0 - (0x80 << shift);
417   const int16_t qs1 = (int16_t)*oq1 - (0x80 << shift);
418   const uint16_t hev = highbd_hev_mask(thresh, *op1, *op0, *oq0, *oq1, bd);
419 
420   // Add outer taps if we have high edge variance.
421   int16_t filter = signed_char_clamp_high(ps1 - qs1, bd) & hev;
422 
423   // Inner taps.
424   filter = signed_char_clamp_high(filter + 3 * (qs0 - ps0), bd) & mask;
425 
426   // Save bottom 3 bits so that we round one side +4 and the other +3
427   // if it equals 4 we'll set it to adjust by -1 to account for the fact
428   // we'd round it by 3 the other way.
429   filter1 = signed_char_clamp_high(filter + 4, bd) >> 3;
430   filter2 = signed_char_clamp_high(filter + 3, bd) >> 3;
431 
432   *oq0 = signed_char_clamp_high(qs0 - filter1, bd) + (0x80 << shift);
433   *op0 = signed_char_clamp_high(ps0 + filter2, bd) + (0x80 << shift);
434 
435   // Outer tap adjustments.
436   filter = ROUND_POWER_OF_TWO(filter1, 1) & ~hev;
437 
438   *oq1 = signed_char_clamp_high(qs1 - filter, bd) + (0x80 << shift);
439   *op1 = signed_char_clamp_high(ps1 + filter, bd) + (0x80 << shift);
440 }
441 
vpx_highbd_lpf_horizontal_4_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)442 void vpx_highbd_lpf_horizontal_4_c(uint16_t *s, int p /* pitch */,
443                                    const uint8_t *blimit, const uint8_t *limit,
444                                    const uint8_t *thresh, int bd) {
445   int i;
446 
447   // loop filter designed to work using chars so that we can make maximum use
448   // of 8 bit simd instructions.
449   for (i = 0; i < 8; ++i) {
450     const uint16_t p3 = s[-4 * p];
451     const uint16_t p2 = s[-3 * p];
452     const uint16_t p1 = s[-2 * p];
453     const uint16_t p0 = s[-p];
454     const uint16_t q0 = s[0 * p];
455     const uint16_t q1 = s[1 * p];
456     const uint16_t q2 = s[2 * p];
457     const uint16_t q3 = s[3 * p];
458     const int8_t mask =
459         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
460     highbd_filter4(mask, *thresh, s - 2 * p, s - 1 * p, s, s + 1 * p, bd);
461     ++s;
462   }
463 }
464 
vpx_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)465 void vpx_highbd_lpf_horizontal_4_dual_c(
466     uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
467     const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
468     const uint8_t *thresh1, int bd) {
469   vpx_highbd_lpf_horizontal_4_c(s, p, blimit0, limit0, thresh0, bd);
470   vpx_highbd_lpf_horizontal_4_c(s + 8, p, blimit1, limit1, thresh1, bd);
471 }
472 
vpx_highbd_lpf_vertical_4_c(uint16_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)473 void vpx_highbd_lpf_vertical_4_c(uint16_t *s, int pitch, const uint8_t *blimit,
474                                  const uint8_t *limit, const uint8_t *thresh,
475                                  int bd) {
476   int i;
477 
478   // loop filter designed to work using chars so that we can make maximum use
479   // of 8 bit simd instructions.
480   for (i = 0; i < 8; ++i) {
481     const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
482     const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
483     const int8_t mask =
484         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
485     highbd_filter4(mask, *thresh, s - 2, s - 1, s, s + 1, bd);
486     s += pitch;
487   }
488 }
489 
vpx_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)490 void vpx_highbd_lpf_vertical_4_dual_c(
491     uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
492     const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
493     const uint8_t *thresh1, int bd) {
494   vpx_highbd_lpf_vertical_4_c(s, pitch, blimit0, limit0, thresh0, bd);
495   vpx_highbd_lpf_vertical_4_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1,
496                               bd);
497 }
498 
highbd_filter8(int8_t mask,uint8_t thresh,uint8_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)499 static INLINE void highbd_filter8(int8_t mask, uint8_t thresh, uint8_t flat,
500                                   uint16_t *op3, uint16_t *op2, uint16_t *op1,
501                                   uint16_t *op0, uint16_t *oq0, uint16_t *oq1,
502                                   uint16_t *oq2, uint16_t *oq3, int bd) {
503   if (flat && mask) {
504     const uint16_t p3 = *op3, p2 = *op2, p1 = *op1, p0 = *op0;
505     const uint16_t q0 = *oq0, q1 = *oq1, q2 = *oq2, q3 = *oq3;
506 
507     // 7-tap filter [1, 1, 1, 2, 1, 1, 1]
508     *op2 = ROUND_POWER_OF_TWO(p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0, 3);
509     *op1 = ROUND_POWER_OF_TWO(p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1, 3);
510     *op0 = ROUND_POWER_OF_TWO(p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2, 3);
511     *oq0 = ROUND_POWER_OF_TWO(p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3, 3);
512     *oq1 = ROUND_POWER_OF_TWO(p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3, 3);
513     *oq2 = ROUND_POWER_OF_TWO(p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3, 3);
514   } else {
515     highbd_filter4(mask, thresh, op1, op0, oq0, oq1, bd);
516   }
517 }
518 
vpx_highbd_lpf_horizontal_8_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)519 void vpx_highbd_lpf_horizontal_8_c(uint16_t *s, int p, const uint8_t *blimit,
520                                    const uint8_t *limit, const uint8_t *thresh,
521                                    int bd) {
522   int i;
523 
524   // loop filter designed to work using chars so that we can make maximum use
525   // of 8 bit simd instructions.
526   for (i = 0; i < 8; ++i) {
527     const uint16_t p3 = s[-4 * p], p2 = s[-3 * p], p1 = s[-2 * p], p0 = s[-p];
528     const uint16_t q0 = s[0 * p], q1 = s[1 * p], q2 = s[2 * p], q3 = s[3 * p];
529 
530     const int8_t mask =
531         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
532     const int8_t flat =
533         highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
534     highbd_filter8(mask, *thresh, flat, s - 4 * p, s - 3 * p, s - 2 * p,
535                    s - 1 * p, s, s + 1 * p, s + 2 * p, s + 3 * p, bd);
536     ++s;
537   }
538 }
539 
vpx_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)540 void vpx_highbd_lpf_horizontal_8_dual_c(
541     uint16_t *s, int p, const uint8_t *blimit0, const uint8_t *limit0,
542     const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
543     const uint8_t *thresh1, int bd) {
544   vpx_highbd_lpf_horizontal_8_c(s, p, blimit0, limit0, thresh0, bd);
545   vpx_highbd_lpf_horizontal_8_c(s + 8, p, blimit1, limit1, thresh1, bd);
546 }
547 
vpx_highbd_lpf_vertical_8_c(uint16_t * s,int pitch,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)548 void vpx_highbd_lpf_vertical_8_c(uint16_t *s, int pitch, const uint8_t *blimit,
549                                  const uint8_t *limit, const uint8_t *thresh,
550                                  int bd) {
551   int i;
552 
553   for (i = 0; i < 8; ++i) {
554     const uint16_t p3 = s[-4], p2 = s[-3], p1 = s[-2], p0 = s[-1];
555     const uint16_t q0 = s[0], q1 = s[1], q2 = s[2], q3 = s[3];
556     const int8_t mask =
557         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
558     const int8_t flat =
559         highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
560     highbd_filter8(mask, *thresh, flat, s - 4, s - 3, s - 2, s - 1, s, s + 1,
561                    s + 2, s + 3, bd);
562     s += pitch;
563   }
564 }
565 
vpx_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)566 void vpx_highbd_lpf_vertical_8_dual_c(
567     uint16_t *s, int pitch, const uint8_t *blimit0, const uint8_t *limit0,
568     const uint8_t *thresh0, const uint8_t *blimit1, const uint8_t *limit1,
569     const uint8_t *thresh1, int bd) {
570   vpx_highbd_lpf_vertical_8_c(s, pitch, blimit0, limit0, thresh0, bd);
571   vpx_highbd_lpf_vertical_8_c(s + 8 * pitch, pitch, blimit1, limit1, thresh1,
572                               bd);
573 }
574 
highbd_filter16(int8_t mask,uint8_t thresh,uint8_t flat,uint8_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)575 static INLINE void highbd_filter16(int8_t mask, uint8_t thresh, uint8_t flat,
576                                    uint8_t flat2, uint16_t *op7, uint16_t *op6,
577                                    uint16_t *op5, uint16_t *op4, uint16_t *op3,
578                                    uint16_t *op2, uint16_t *op1, uint16_t *op0,
579                                    uint16_t *oq0, uint16_t *oq1, uint16_t *oq2,
580                                    uint16_t *oq3, uint16_t *oq4, uint16_t *oq5,
581                                    uint16_t *oq6, uint16_t *oq7, int bd) {
582   if (flat2 && flat && mask) {
583     const uint16_t p7 = *op7;
584     const uint16_t p6 = *op6;
585     const uint16_t p5 = *op5;
586     const uint16_t p4 = *op4;
587     const uint16_t p3 = *op3;
588     const uint16_t p2 = *op2;
589     const uint16_t p1 = *op1;
590     const uint16_t p0 = *op0;
591     const uint16_t q0 = *oq0;
592     const uint16_t q1 = *oq1;
593     const uint16_t q2 = *oq2;
594     const uint16_t q3 = *oq3;
595     const uint16_t q4 = *oq4;
596     const uint16_t q5 = *oq5;
597     const uint16_t q6 = *oq6;
598     const uint16_t q7 = *oq7;
599 
600     // 15-tap filter [1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1]
601     *op6 = ROUND_POWER_OF_TWO(
602         p7 * 7 + p6 * 2 + p5 + p4 + p3 + p2 + p1 + p0 + q0, 4);
603     *op5 = ROUND_POWER_OF_TWO(
604         p7 * 6 + p6 + p5 * 2 + p4 + p3 + p2 + p1 + p0 + q0 + q1, 4);
605     *op4 = ROUND_POWER_OF_TWO(
606         p7 * 5 + p6 + p5 + p4 * 2 + p3 + p2 + p1 + p0 + q0 + q1 + q2, 4);
607     *op3 = ROUND_POWER_OF_TWO(
608         p7 * 4 + p6 + p5 + p4 + p3 * 2 + p2 + p1 + p0 + q0 + q1 + q2 + q3, 4);
609     *op2 = ROUND_POWER_OF_TWO(
610         p7 * 3 + p6 + p5 + p4 + p3 + p2 * 2 + p1 + p0 + q0 + q1 + q2 + q3 + q4,
611         4);
612     *op1 = ROUND_POWER_OF_TWO(p7 * 2 + p6 + p5 + p4 + p3 + p2 + p1 * 2 + p0 +
613                                   q0 + q1 + q2 + q3 + q4 + q5,
614                               4);
615     *op0 = ROUND_POWER_OF_TWO(p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 + q0 +
616                                   q1 + q2 + q3 + q4 + q5 + q6,
617                               4);
618     *oq0 = ROUND_POWER_OF_TWO(p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 + q1 +
619                                   q2 + q3 + q4 + q5 + q6 + q7,
620                               4);
621     *oq1 = ROUND_POWER_OF_TWO(p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 + q2 +
622                                   q3 + q4 + q5 + q6 + q7 * 2,
623                               4);
624     *oq2 = ROUND_POWER_OF_TWO(
625         p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 + q3 + q4 + q5 + q6 + q7 * 3,
626         4);
627     *oq3 = ROUND_POWER_OF_TWO(
628         p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 + q4 + q5 + q6 + q7 * 4, 4);
629     *oq4 = ROUND_POWER_OF_TWO(
630         p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 + q5 + q6 + q7 * 5, 4);
631     *oq5 = ROUND_POWER_OF_TWO(
632         p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 + q6 + q7 * 6, 4);
633     *oq6 = ROUND_POWER_OF_TWO(
634         p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 + q7 * 7, 4);
635   } else {
636     highbd_filter8(mask, thresh, flat, op3, op2, op1, op0, oq0, oq1, oq2, oq3,
637                    bd);
638   }
639 }
640 
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)641 static void highbd_mb_lpf_horizontal_edge_w(uint16_t *s, int p,
642                                             const uint8_t *blimit,
643                                             const uint8_t *limit,
644                                             const uint8_t *thresh, int count,
645                                             int bd) {
646   int i;
647 
648   // loop filter designed to work using chars so that we can make maximum use
649   // of 8 bit simd instructions.
650   for (i = 0; i < 8 * count; ++i) {
651     const uint16_t p3 = s[-4 * p];
652     const uint16_t p2 = s[-3 * p];
653     const uint16_t p1 = s[-2 * p];
654     const uint16_t p0 = s[-p];
655     const uint16_t q0 = s[0 * p];
656     const uint16_t q1 = s[1 * p];
657     const uint16_t q2 = s[2 * p];
658     const uint16_t q3 = s[3 * p];
659     const int8_t mask =
660         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
661     const int8_t flat =
662         highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
663     const int8_t flat2 =
664         highbd_flat_mask5(1, s[-8 * p], s[-7 * p], s[-6 * p], s[-5 * p], p0, q0,
665                           s[4 * p], s[5 * p], s[6 * p], s[7 * p], bd);
666 
667     highbd_filter16(mask, *thresh, flat, flat2, s - 8 * p, s - 7 * p, s - 6 * p,
668                     s - 5 * p, s - 4 * p, s - 3 * p, s - 2 * p, s - 1 * p, s,
669                     s + 1 * p, s + 2 * p, s + 3 * p, s + 4 * p, s + 5 * p,
670                     s + 6 * p, s + 7 * p, bd);
671     ++s;
672   }
673 }
674 
vpx_highbd_lpf_horizontal_16_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)675 void vpx_highbd_lpf_horizontal_16_c(uint16_t *s, int p, const uint8_t *blimit,
676                                     const uint8_t *limit, const uint8_t *thresh,
677                                     int bd) {
678   highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 1, bd);
679 }
680 
vpx_highbd_lpf_horizontal_16_dual_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)681 void vpx_highbd_lpf_horizontal_16_dual_c(uint16_t *s, int p,
682                                          const uint8_t *blimit,
683                                          const uint8_t *limit,
684                                          const uint8_t *thresh, int bd) {
685   highbd_mb_lpf_horizontal_edge_w(s, p, blimit, limit, thresh, 2, bd);
686 }
687 
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)688 static void highbd_mb_lpf_vertical_edge_w(uint16_t *s, int p,
689                                           const uint8_t *blimit,
690                                           const uint8_t *limit,
691                                           const uint8_t *thresh, int count,
692                                           int bd) {
693   int i;
694 
695   for (i = 0; i < count; ++i) {
696     const uint16_t p3 = s[-4];
697     const uint16_t p2 = s[-3];
698     const uint16_t p1 = s[-2];
699     const uint16_t p0 = s[-1];
700     const uint16_t q0 = s[0];
701     const uint16_t q1 = s[1];
702     const uint16_t q2 = s[2];
703     const uint16_t q3 = s[3];
704     const int8_t mask =
705         highbd_filter_mask(*limit, *blimit, p3, p2, p1, p0, q0, q1, q2, q3, bd);
706     const int8_t flat =
707         highbd_flat_mask4(1, p3, p2, p1, p0, q0, q1, q2, q3, bd);
708     const int8_t flat2 = highbd_flat_mask5(1, s[-8], s[-7], s[-6], s[-5], p0,
709                                            q0, s[4], s[5], s[6], s[7], bd);
710 
711     highbd_filter16(mask, *thresh, flat, flat2, s - 8, s - 7, s - 6, s - 5,
712                     s - 4, s - 3, s - 2, s - 1, s, s + 1, s + 2, s + 3, s + 4,
713                     s + 5, s + 6, s + 7, bd);
714     s += p;
715   }
716 }
717 
vpx_highbd_lpf_vertical_16_c(uint16_t * s,int p,const uint8_t * blimit,const uint8_t * limit,const uint8_t * thresh,int bd)718 void vpx_highbd_lpf_vertical_16_c(uint16_t *s, int p, const uint8_t *blimit,
719                                   const uint8_t *limit, const uint8_t *thresh,
720                                   int bd) {
721   highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 8, bd);
722 }
723 
vpx_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)724 void vpx_highbd_lpf_vertical_16_dual_c(uint16_t *s, int p,
725                                        const uint8_t *blimit,
726                                        const uint8_t *limit,
727                                        const uint8_t *thresh, int bd) {
728   highbd_mb_lpf_vertical_edge_w(s, p, blimit, limit, thresh, 16, bd);
729 }
730 #endif  // CONFIG_VP9_HIGHBITDEPTH
731