FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
vp9dsp.c
Go to the documentation of this file.
1 /*
2  * VP9 compatible video decoder
3  *
4  * Copyright (C) 2013 Ronald S. Bultje <rsbultje gmail com>
5  * Copyright (C) 2013 Clément Bœsch <u pkh me>
6  *
7  * This file is part of FFmpeg.
8  *
9  * FFmpeg is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public
11  * License as published by the Free Software Foundation; either
12  * version 2.1 of the License, or (at your option) any later version.
13  *
14  * FFmpeg is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17  * Lesser General Public License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with FFmpeg; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
22  */
23 
24 #include "libavutil/common.h"
25 #include "libavutil/intreadwrite.h"
26 #include "vp9dsp.h"
27 #include "rnd_avg.h"
28 
29 // FIXME see whether we can merge parts of this (perhaps at least 4x4 and 8x8)
30 // back with h264pred.[ch]
31 
32 static void vert_4x4_c(uint8_t *dst, ptrdiff_t stride,
33  const uint8_t *left, const uint8_t *top)
34 {
35  unsigned p4 = AV_RN32A(top);
36 
37  AV_WN32A(dst + stride * 0, p4);
38  AV_WN32A(dst + stride * 1, p4);
39  AV_WN32A(dst + stride * 2, p4);
40  AV_WN32A(dst + stride * 3, p4);
41 }
42 
43 static void vert_8x8_c(uint8_t *dst, ptrdiff_t stride,
44  const uint8_t *left, const uint8_t *top)
45 {
46  uint64_t p8 = AV_RN64A(top);
47  int y;
48 
49  for (y = 0; y < 8; y++) {
50  AV_WN64A(dst, p8);
51  dst += stride;
52  }
53 }
54 
55 static void vert_16x16_c(uint8_t *dst, ptrdiff_t stride,
56  const uint8_t *left, const uint8_t *top)
57 {
58  uint64_t p8a = AV_RN64A(top + 0), p8b = AV_RN64A(top + 8);
59  int y;
60 
61  for (y = 0; y < 16; y++) {
62  AV_WN64A(dst + 0, p8a);
63  AV_WN64A(dst + 8, p8b);
64  dst += stride;
65  }
66 }
67 
68 static void vert_32x32_c(uint8_t *dst, ptrdiff_t stride,
69  const uint8_t *left, const uint8_t *top)
70 {
71  uint64_t p8a = AV_RN64A(top + 0), p8b = AV_RN64A(top + 8),
72  p8c = AV_RN64A(top + 16), p8d = AV_RN64A(top + 24);
73  int y;
74 
75  for (y = 0; y < 32; y++) {
76  AV_WN64A(dst + 0, p8a);
77  AV_WN64A(dst + 8, p8b);
78  AV_WN64A(dst + 16, p8c);
79  AV_WN64A(dst + 24, p8d);
80  dst += stride;
81  }
82 }
83 
84 static void hor_4x4_c(uint8_t *dst, ptrdiff_t stride,
85  const uint8_t *left, const uint8_t *top)
86 {
87  AV_WN32A(dst + stride * 0, left[0] * 0x01010101U);
88  AV_WN32A(dst + stride * 1, left[1] * 0x01010101U);
89  AV_WN32A(dst + stride * 2, left[2] * 0x01010101U);
90  AV_WN32A(dst + stride * 3, left[3] * 0x01010101U);
91 }
92 
93 static void hor_8x8_c(uint8_t *dst, ptrdiff_t stride,
94  const uint8_t *left, const uint8_t *top)
95 {
96  int y;
97 
98  for (y = 0; y < 8; y++) {
99  AV_WN64A(dst, left[y] * 0x0101010101010101ULL);
100  dst += stride;
101  }
102 }
103 
104 static void hor_16x16_c(uint8_t *dst, ptrdiff_t stride,
105  const uint8_t *left, const uint8_t *top)
106 {
107  int y;
108 
109  for (y = 0; y < 16; y++) {
110  uint64_t p8 = left[y] * 0x0101010101010101ULL;
111 
112  AV_WN64A(dst + 0, p8);
113  AV_WN64A(dst + 8, p8);
114  dst += stride;
115  }
116 }
117 
118 static void hor_32x32_c(uint8_t *dst, ptrdiff_t stride,
119  const uint8_t *left, const uint8_t *top)
120 {
121  int y;
122 
123  for (y = 0; y < 32; y++) {
124  uint64_t p8 = left[y] * 0x0101010101010101ULL;
125 
126  AV_WN64A(dst + 0, p8);
127  AV_WN64A(dst + 8, p8);
128  AV_WN64A(dst + 16, p8);
129  AV_WN64A(dst + 24, p8);
130  dst += stride;
131  }
132 }
133 
134 static void tm_4x4_c(uint8_t *dst, ptrdiff_t stride,
135  const uint8_t *left, const uint8_t *top)
136 {
137  int y, tl = top[-1];
138 
139  for (y = 0; y < 4; y++) {
140  int l_m_tl = left[y] - tl;
141 
142  dst[0] = av_clip_uint8(top[0] + l_m_tl);
143  dst[1] = av_clip_uint8(top[1] + l_m_tl);
144  dst[2] = av_clip_uint8(top[2] + l_m_tl);
145  dst[3] = av_clip_uint8(top[3] + l_m_tl);
146  dst += stride;
147  }
148 }
149 
150 static void tm_8x8_c(uint8_t *dst, ptrdiff_t stride,
151  const uint8_t *left, const uint8_t *top)
152 {
153  int y, tl = top[-1];
154 
155  for (y = 0; y < 8; y++) {
156  int l_m_tl = left[y] - tl;
157 
158  dst[0] = av_clip_uint8(top[0] + l_m_tl);
159  dst[1] = av_clip_uint8(top[1] + l_m_tl);
160  dst[2] = av_clip_uint8(top[2] + l_m_tl);
161  dst[3] = av_clip_uint8(top[3] + l_m_tl);
162  dst[4] = av_clip_uint8(top[4] + l_m_tl);
163  dst[5] = av_clip_uint8(top[5] + l_m_tl);
164  dst[6] = av_clip_uint8(top[6] + l_m_tl);
165  dst[7] = av_clip_uint8(top[7] + l_m_tl);
166  dst += stride;
167  }
168 }
169 
170 static void tm_16x16_c(uint8_t *dst, ptrdiff_t stride,
171  const uint8_t *left, const uint8_t *top)
172 {
173  int y, tl = top[-1];
174 
175  for (y = 0; y < 16; y++) {
176  int l_m_tl = left[y] - tl;
177 
178  dst[ 0] = av_clip_uint8(top[ 0] + l_m_tl);
179  dst[ 1] = av_clip_uint8(top[ 1] + l_m_tl);
180  dst[ 2] = av_clip_uint8(top[ 2] + l_m_tl);
181  dst[ 3] = av_clip_uint8(top[ 3] + l_m_tl);
182  dst[ 4] = av_clip_uint8(top[ 4] + l_m_tl);
183  dst[ 5] = av_clip_uint8(top[ 5] + l_m_tl);
184  dst[ 6] = av_clip_uint8(top[ 6] + l_m_tl);
185  dst[ 7] = av_clip_uint8(top[ 7] + l_m_tl);
186  dst[ 8] = av_clip_uint8(top[ 8] + l_m_tl);
187  dst[ 9] = av_clip_uint8(top[ 9] + l_m_tl);
188  dst[10] = av_clip_uint8(top[10] + l_m_tl);
189  dst[11] = av_clip_uint8(top[11] + l_m_tl);
190  dst[12] = av_clip_uint8(top[12] + l_m_tl);
191  dst[13] = av_clip_uint8(top[13] + l_m_tl);
192  dst[14] = av_clip_uint8(top[14] + l_m_tl);
193  dst[15] = av_clip_uint8(top[15] + l_m_tl);
194  dst += stride;
195  }
196 }
197 
198 static void tm_32x32_c(uint8_t *dst, ptrdiff_t stride,
199  const uint8_t *left, const uint8_t *top)
200 {
201  int y, tl = top[-1];
202 
203  for (y = 0; y < 32; y++) {
204  int l_m_tl = left[y] - tl;
205 
206  dst[ 0] = av_clip_uint8(top[ 0] + l_m_tl);
207  dst[ 1] = av_clip_uint8(top[ 1] + l_m_tl);
208  dst[ 2] = av_clip_uint8(top[ 2] + l_m_tl);
209  dst[ 3] = av_clip_uint8(top[ 3] + l_m_tl);
210  dst[ 4] = av_clip_uint8(top[ 4] + l_m_tl);
211  dst[ 5] = av_clip_uint8(top[ 5] + l_m_tl);
212  dst[ 6] = av_clip_uint8(top[ 6] + l_m_tl);
213  dst[ 7] = av_clip_uint8(top[ 7] + l_m_tl);
214  dst[ 8] = av_clip_uint8(top[ 8] + l_m_tl);
215  dst[ 9] = av_clip_uint8(top[ 9] + l_m_tl);
216  dst[10] = av_clip_uint8(top[10] + l_m_tl);
217  dst[11] = av_clip_uint8(top[11] + l_m_tl);
218  dst[12] = av_clip_uint8(top[12] + l_m_tl);
219  dst[13] = av_clip_uint8(top[13] + l_m_tl);
220  dst[14] = av_clip_uint8(top[14] + l_m_tl);
221  dst[15] = av_clip_uint8(top[15] + l_m_tl);
222  dst[16] = av_clip_uint8(top[16] + l_m_tl);
223  dst[17] = av_clip_uint8(top[17] + l_m_tl);
224  dst[18] = av_clip_uint8(top[18] + l_m_tl);
225  dst[19] = av_clip_uint8(top[19] + l_m_tl);
226  dst[20] = av_clip_uint8(top[20] + l_m_tl);
227  dst[21] = av_clip_uint8(top[21] + l_m_tl);
228  dst[22] = av_clip_uint8(top[22] + l_m_tl);
229  dst[23] = av_clip_uint8(top[23] + l_m_tl);
230  dst[24] = av_clip_uint8(top[24] + l_m_tl);
231  dst[25] = av_clip_uint8(top[25] + l_m_tl);
232  dst[26] = av_clip_uint8(top[26] + l_m_tl);
233  dst[27] = av_clip_uint8(top[27] + l_m_tl);
234  dst[28] = av_clip_uint8(top[28] + l_m_tl);
235  dst[29] = av_clip_uint8(top[29] + l_m_tl);
236  dst[30] = av_clip_uint8(top[30] + l_m_tl);
237  dst[31] = av_clip_uint8(top[31] + l_m_tl);
238  dst += stride;
239  }
240 }
241 
242 static void dc_4x4_c(uint8_t *dst, ptrdiff_t stride,
243  const uint8_t *left, const uint8_t *top)
244 {
245  unsigned dc = 0x01010101U * ((left[0] + left[1] + left[2] + left[3] +
246  top[0] + top[1] + top[2] + top[3] + 4) >> 3);
247 
248  AV_WN32A(dst + stride * 0, dc);
249  AV_WN32A(dst + stride * 1, dc);
250  AV_WN32A(dst + stride * 2, dc);
251  AV_WN32A(dst + stride * 3, dc);
252 }
253 
254 static void dc_8x8_c(uint8_t *dst, ptrdiff_t stride,
255  const uint8_t *left, const uint8_t *top)
256 {
257  uint64_t dc = 0x0101010101010101ULL *
258  ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
259  left[6] + left[7] + top[0] + top[1] + top[2] + top[3] +
260  top[4] + top[5] + top[6] + top[7] + 8) >> 4);
261  int y;
262 
263  for (y = 0; y < 8; y++) {
264  AV_WN64A(dst, dc);
265  dst += stride;
266  }
267 }
268 
269 static void dc_16x16_c(uint8_t *dst, ptrdiff_t stride,
270  const uint8_t *left, const uint8_t *top)
271 {
272  uint64_t dc = 0x0101010101010101ULL *
273  ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
274  left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
275  left[13] + left[14] + left[15] + top[0] + top[1] + top[2] + top[3] +
276  top[4] + top[5] + top[6] + top[7] + top[8] + top[9] + top[10] +
277  top[11] + top[12] + top[13] + top[14] + top[15] + 16) >> 5);
278  int y;
279 
280  for (y = 0; y < 16; y++) {
281  AV_WN64A(dst + 0, dc);
282  AV_WN64A(dst + 8, dc);
283  dst += stride;
284  }
285 }
286 
287 static void dc_32x32_c(uint8_t *dst, ptrdiff_t stride,
288  const uint8_t *left, const uint8_t *top)
289 {
290  uint64_t dc = 0x0101010101010101ULL *
291  ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] + left[6] +
292  left[7] + left[8] + left[9] + left[10] + left[11] + left[12] +
293  left[13] + left[14] + left[15] + left[16] + left[17] + left[18] +
294  left[19] + left[20] + left[21] + left[22] + left[23] + left[24] +
295  left[25] + left[26] + left[27] + left[28] + left[29] + left[30] +
296  left[31] + top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
297  top[6] + top[7] + top[8] + top[9] + top[10] + top[11] + top[12] +
298  top[13] + top[14] + top[15] + top[16] + top[17] + top[18] + top[19] +
299  top[20] + top[21] + top[22] + top[23] + top[24] + top[25] + top[26] +
300  top[27] + top[28] + top[29] + top[30] + top[31] + 32) >> 6);
301  int y;
302 
303  for (y = 0; y < 32; y++) {
304  AV_WN64A(dst + 0, dc);
305  AV_WN64A(dst + 8, dc);
306  AV_WN64A(dst + 16, dc);
307  AV_WN64A(dst + 24, dc);
308  dst += stride;
309  }
310 }
311 
312 static void dc_left_4x4_c(uint8_t *dst, ptrdiff_t stride,
313  const uint8_t *left, const uint8_t *top)
314 {
315  unsigned dc = 0x01010101U * ((left[0] + left[1] + left[2] + left[3] + 2) >> 2);
316 
317  AV_WN32A(dst + stride * 0, dc);
318  AV_WN32A(dst + stride * 1, dc);
319  AV_WN32A(dst + stride * 2, dc);
320  AV_WN32A(dst + stride * 3, dc);
321 }
322 
323 static void dc_left_8x8_c(uint8_t *dst, ptrdiff_t stride,
324  const uint8_t *left, const uint8_t *top)
325 {
326  uint64_t dc = 0x0101010101010101ULL *
327  ((left[0] + left[1] + left[2] + left[3] +
328  left[4] + left[5] + left[6] + left[7] + 4) >> 3);
329  int y;
330 
331  for (y = 0; y < 8; y++) {
332  AV_WN64A(dst, dc);
333  dst += stride;
334  }
335 }
336 
337 static void dc_left_16x16_c(uint8_t *dst, ptrdiff_t stride,
338  const uint8_t *left, const uint8_t *top)
339 {
340  uint64_t dc = 0x0101010101010101ULL *
341  ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
342  left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
343  left[12] + left[13] + left[14] + left[15] + 8) >> 4);
344  int y;
345 
346  for (y = 0; y < 16; y++) {
347  AV_WN64A(dst + 0, dc);
348  AV_WN64A(dst + 8, dc);
349  dst += stride;
350  }
351 }
352 
353 static void dc_left_32x32_c(uint8_t *dst, ptrdiff_t stride,
354  const uint8_t *left, const uint8_t *top)
355 {
356  uint64_t dc = 0x0101010101010101ULL *
357  ((left[0] + left[1] + left[2] + left[3] + left[4] + left[5] +
358  left[6] + left[7] + left[8] + left[9] + left[10] + left[11] +
359  left[12] + left[13] + left[14] + left[15] + left[16] + left[17] +
360  left[18] + left[19] + left[20] + left[21] + left[22] + left[23] +
361  left[24] + left[25] + left[26] + left[27] + left[28] + left[29] +
362  left[30] + left[31] + 16) >> 5);
363  int y;
364 
365  for (y = 0; y < 32; y++) {
366  AV_WN64A(dst + 0, dc);
367  AV_WN64A(dst + 8, dc);
368  AV_WN64A(dst + 16, dc);
369  AV_WN64A(dst + 24, dc);
370  dst += stride;
371  }
372 }
373 
374 static void dc_top_4x4_c(uint8_t *dst, ptrdiff_t stride,
375  const uint8_t *left, const uint8_t *top)
376 {
377  unsigned dc = 0x01010101U * ((top[0] + top[1] + top[2] + top[3] + 2) >> 2);
378 
379  AV_WN32A(dst + stride * 0, dc);
380  AV_WN32A(dst + stride * 1, dc);
381  AV_WN32A(dst + stride * 2, dc);
382  AV_WN32A(dst + stride * 3, dc);
383 }
384 
385 static void dc_top_8x8_c(uint8_t *dst, ptrdiff_t stride,
386  const uint8_t *left, const uint8_t *top)
387 {
388  uint64_t dc = 0x0101010101010101ULL *
389  ((top[0] + top[1] + top[2] + top[3] +
390  top[4] + top[5] + top[6] + top[7] + 4) >> 3);
391  int y;
392 
393  for (y = 0; y < 8; y++) {
394  AV_WN64A(dst, dc);
395  dst += stride;
396  }
397 }
398 
399 static void dc_top_16x16_c(uint8_t *dst, ptrdiff_t stride,
400  const uint8_t *left, const uint8_t *top)
401 {
402  uint64_t dc = 0x0101010101010101ULL *
403  ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
404  top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
405  top[12] + top[13] + top[14] + top[15] + 8) >> 4);
406  int y;
407 
408  for (y = 0; y < 16; y++) {
409  AV_WN64A(dst + 0, dc);
410  AV_WN64A(dst + 8, dc);
411  dst += stride;
412  }
413 }
414 
415 static void dc_top_32x32_c(uint8_t *dst, ptrdiff_t stride,
416  const uint8_t *left, const uint8_t *top)
417 {
418  uint64_t dc = 0x0101010101010101ULL *
419  ((top[0] + top[1] + top[2] + top[3] + top[4] + top[5] +
420  top[6] + top[7] + top[8] + top[9] + top[10] + top[11] +
421  top[12] + top[13] + top[14] + top[15] + top[16] + top[17] +
422  top[18] + top[19] + top[20] + top[21] + top[22] + top[23] +
423  top[24] + top[25] + top[26] + top[27] + top[28] + top[29] +
424  top[30] + top[31] + 16) >> 5);
425  int y;
426 
427  for (y = 0; y < 32; y++) {
428  AV_WN64A(dst + 0, dc);
429  AV_WN64A(dst + 8, dc);
430  AV_WN64A(dst + 16, dc);
431  AV_WN64A(dst + 24, dc);
432  dst += stride;
433  }
434 }
435 
436 static void dc_128_4x4_c(uint8_t *dst, ptrdiff_t stride,
437  const uint8_t *left, const uint8_t *top)
438 {
439  AV_WN32A(dst + stride * 0, 0x80808080U);
440  AV_WN32A(dst + stride * 1, 0x80808080U);
441  AV_WN32A(dst + stride * 2, 0x80808080U);
442  AV_WN32A(dst + stride * 3, 0x80808080U);
443 }
444 
445 static void dc_128_8x8_c(uint8_t *dst, ptrdiff_t stride,
446  const uint8_t *left, const uint8_t *top)
447 {
448  int y;
449 
450  for (y = 0; y < 8; y++) {
451  AV_WN64A(dst, 0x8080808080808080ULL);
452  dst += stride;
453  }
454 }
455 
456 static void dc_128_16x16_c(uint8_t *dst, ptrdiff_t stride,
457  const uint8_t *left, const uint8_t *top)
458 {
459  int y;
460 
461  for (y = 0; y < 16; y++) {
462  AV_WN64A(dst + 0, 0x8080808080808080ULL);
463  AV_WN64A(dst + 8, 0x8080808080808080ULL);
464  dst += stride;
465  }
466 }
467 
468 static void dc_128_32x32_c(uint8_t *dst, ptrdiff_t stride,
469  const uint8_t *left, const uint8_t *top)
470 {
471  int y;
472 
473  for (y = 0; y < 32; y++) {
474  AV_WN64A(dst + 0, 0x8080808080808080ULL);
475  AV_WN64A(dst + 8, 0x8080808080808080ULL);
476  AV_WN64A(dst + 16, 0x8080808080808080ULL);
477  AV_WN64A(dst + 24, 0x8080808080808080ULL);
478  dst += stride;
479  }
480 }
481 
482 static void dc_127_4x4_c(uint8_t *dst, ptrdiff_t stride,
483  const uint8_t *left, const uint8_t *top)
484 {
485  AV_WN32A(dst + stride * 0, 0x7F7F7F7FU);
486  AV_WN32A(dst + stride * 1, 0x7F7F7F7FU);
487  AV_WN32A(dst + stride * 2, 0x7F7F7F7FU);
488  AV_WN32A(dst + stride * 3, 0x7F7F7F7FU);
489 }
490 
491 static void dc_127_8x8_c(uint8_t *dst, ptrdiff_t stride,
492  const uint8_t *left, const uint8_t *top)
493 {
494  int y;
495 
496  for (y = 0; y < 8; y++) {
497  AV_WN64A(dst, 0x7F7F7F7F7F7F7F7FULL);
498  dst += stride;
499  }
500 }
501 
502 static void dc_127_16x16_c(uint8_t *dst, ptrdiff_t stride,
503  const uint8_t *left, const uint8_t *top)
504 {
505  int y;
506 
507  for (y = 0; y < 16; y++) {
508  AV_WN64A(dst + 0, 0x7F7F7F7F7F7F7F7FULL);
509  AV_WN64A(dst + 8, 0x7F7F7F7F7F7F7F7FULL);
510  dst += stride;
511  }
512 }
513 
514 static void dc_127_32x32_c(uint8_t *dst, ptrdiff_t stride,
515  const uint8_t *left, const uint8_t *top)
516 {
517  int y;
518 
519  for (y = 0; y < 32; y++) {
520  AV_WN64A(dst + 0, 0x7F7F7F7F7F7F7F7FULL);
521  AV_WN64A(dst + 8, 0x7F7F7F7F7F7F7F7FULL);
522  AV_WN64A(dst + 16, 0x7F7F7F7F7F7F7F7FULL);
523  AV_WN64A(dst + 24, 0x7F7F7F7F7F7F7F7FULL);
524  dst += stride;
525  }
526 }
527 
528 static void dc_129_4x4_c(uint8_t *dst, ptrdiff_t stride,
529  const uint8_t *left, const uint8_t *top)
530 {
531  AV_WN32A(dst + stride * 0, 0x81818181U);
532  AV_WN32A(dst + stride * 1, 0x81818181U);
533  AV_WN32A(dst + stride * 2, 0x81818181U);
534  AV_WN32A(dst + stride * 3, 0x81818181U);
535 }
536 
537 static void dc_129_8x8_c(uint8_t *dst, ptrdiff_t stride,
538  const uint8_t *left, const uint8_t *top)
539 {
540  int y;
541 
542  for (y = 0; y < 8; y++) {
543  AV_WN64A(dst, 0x8181818181818181ULL);
544  dst += stride;
545  }
546 }
547 
548 static void dc_129_16x16_c(uint8_t *dst, ptrdiff_t stride,
549  const uint8_t *left, const uint8_t *top)
550 {
551  int y;
552 
553  for (y = 0; y < 16; y++) {
554  AV_WN64A(dst + 0, 0x8181818181818181ULL);
555  AV_WN64A(dst + 8, 0x8181818181818181ULL);
556  dst += stride;
557  }
558 }
559 
560 static void dc_129_32x32_c(uint8_t *dst, ptrdiff_t stride,
561  const uint8_t *left, const uint8_t *top)
562 {
563  int y;
564 
565  for (y = 0; y < 32; y++) {
566  AV_WN64A(dst + 0, 0x8181818181818181ULL);
567  AV_WN64A(dst + 8, 0x8181818181818181ULL);
568  AV_WN64A(dst + 16, 0x8181818181818181ULL);
569  AV_WN64A(dst + 24, 0x8181818181818181ULL);
570  dst += stride;
571  }
572 }
573 
574 #define DST(x, y) dst[(x) + (y) * stride]
575 
576 static void diag_downleft_4x4_c(uint8_t *dst, ptrdiff_t stride,
577  const uint8_t *left, const uint8_t *top)
578 {
579  int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
580  a4 = top[4], a5 = top[5], a6 = top[6], a7 = top[7];
581 
582  DST(0,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
583  DST(1,0) = DST(0,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
584  DST(2,0) = DST(1,1) = DST(0,2) = (a2 + a3 * 2 + a4 + 2) >> 2;
585  DST(3,0) = DST(2,1) = DST(1,2) = DST(0,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
586  DST(3,1) = DST(2,2) = DST(1,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
587  DST(3,2) = DST(2,3) = (a5 + a6 * 2 + a7 + 2) >> 2;
588  DST(3,3) = a7; // note: this is different from vp8 and such
589 }
590 
591 #define def_diag_downleft(size) \
592 static void diag_downleft_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
593  const uint8_t *left, const uint8_t *top) \
594 { \
595  int i, j; \
596  uint8_t v[size - 1]; \
597 \
598  for (i = 0; i < size - 2; i++) \
599  v[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
600  v[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
601 \
602  for (j = 0; j < size; j++) { \
603  memcpy(dst + j*stride, v + j, size - 1 - j); \
604  memset(dst + j*stride + size - 1 - j, top[size - 1], j + 1); \
605  } \
606 }
607 
611 
612 static void diag_downright_4x4_c(uint8_t *dst, ptrdiff_t stride,
613  const uint8_t *left, const uint8_t *top)
614 {
615  int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
616  l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
617 
618  DST(0,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
619  DST(0,2) = DST(1,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
620  DST(0,1) = DST(1,2) = DST(2,3) = (tl + l0 * 2 + l1 + 2) >> 2;
621  DST(0,0) = DST(1,1) = DST(2,2) = DST(3,3) = (l0 + tl * 2 + a0 + 2) >> 2;
622  DST(1,0) = DST(2,1) = DST(3,2) = (tl + a0 * 2 + a1 + 2) >> 2;
623  DST(2,0) = DST(3,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
624  DST(3,0) = (a1 + a2 * 2 + a3 + 2) >> 2;
625 }
626 
627 #define def_diag_downright(size) \
628 static void diag_downright_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
629  const uint8_t *left, const uint8_t *top) \
630 { \
631  int i, j; \
632  uint8_t v[size + size - 1]; \
633 \
634  for (i = 0; i < size - 2; i++) { \
635  v[i ] = (left[size - 1 - i] + left[size - 2 - i] * 2 + left[size - 3 - i] + 2) >> 2; \
636  v[size + 1 + i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
637  } \
638  v[size - 2] = (left[1] + left[0] * 2 + top[-1] + 2) >> 2; \
639  v[size - 1] = (left[0] + top[-1] * 2 + top[ 0] + 2) >> 2; \
640  v[size ] = (top[-1] + top[0] * 2 + top[ 1] + 2) >> 2; \
641 \
642  for (j = 0; j < size; j++) \
643  memcpy(dst + j*stride, v + size - 1 - j, size); \
644 }
645 
649 
650 static void vert_right_4x4_c(uint8_t *dst, ptrdiff_t stride,
651  const uint8_t *left, const uint8_t *top)
652 {
653  int tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
654  l0 = left[0], l1 = left[1], l2 = left[2];
655 
656  DST(0,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
657  DST(0,2) = (tl + l0 * 2 + l1 + 2) >> 2;
658  DST(0,0) = DST(1,2) = (tl + a0 + 1) >> 1;
659  DST(0,1) = DST(1,3) = (l0 + tl * 2 + a0 + 2) >> 2;
660  DST(1,0) = DST(2,2) = (a0 + a1 + 1) >> 1;
661  DST(1,1) = DST(2,3) = (tl + a0 * 2 + a1 + 2) >> 2;
662  DST(2,0) = DST(3,2) = (a1 + a2 + 1) >> 1;
663  DST(2,1) = DST(3,3) = (a0 + a1 * 2 + a2 + 2) >> 2;
664  DST(3,0) = (a2 + a3 + 1) >> 1;
665  DST(3,1) = (a1 + a2 * 2 + a3 + 2) >> 2;
666 }
667 
668 #define def_vert_right(size) \
669 static void vert_right_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
670  const uint8_t *left, const uint8_t *top) \
671 { \
672  int i, j; \
673  uint8_t ve[size + size/2 - 1], vo[size + size/2 - 1]; \
674 \
675  for (i = 0; i < size/2 - 2; i++) { \
676  vo[i] = (left[size - 4 - i*2] + left[size - 3 - i*2] * 2 + left[size - 2 - i*2] + 2) >> 2; \
677  ve[i] = (left[size - 5 - i*2] + left[size - 4 - i*2] * 2 + left[size - 3 - i*2] + 2) >> 2; \
678  } \
679  vo[size/2 - 2] = (left[0] + left[1] * 2 + left[2] + 2) >> 2; \
680  ve[size/2 - 2] = (top[-1] + left[0] * 2 + left[1] + 2) >> 2; \
681 \
682  ve[size/2 - 1] = (top[-1] + top[0] + 1) >> 1; \
683  vo[size/2 - 1] = (left[0] + top[-1] * 2 + top[0] + 2) >> 2; \
684  for (i = 0; i < size - 1; i++) { \
685  ve[size/2 + i] = (top[i] + top[i + 1] + 1) >> 1; \
686  vo[size/2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
687  } \
688 \
689  for (j = 0; j < size / 2; j++) { \
690  memcpy(dst + j*2 *stride, ve + size/2 - 1 - j, size); \
691  memcpy(dst + (j*2 + 1)*stride, vo + size/2 - 1 - j, size); \
692  } \
693 }
694 
696 def_vert_right(16)
697 def_vert_right(32)
698 
699 static void hor_down_4x4_c(uint8_t *dst, ptrdiff_t stride,
700  const uint8_t *left, const uint8_t *top)
701 {
702  int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3],
703  tl = top[-1], a0 = top[0], a1 = top[1], a2 = top[2];
704 
705  DST(2,0) = (tl + a0 * 2 + a1 + 2) >> 2;
706  DST(3,0) = (a0 + a1 * 2 + a2 + 2) >> 2;
707  DST(0,0) = DST(2,1) = (tl + l0 + 1) >> 1;
708  DST(1,0) = DST(3,1) = (a0 + tl * 2 + l0 + 2) >> 2;
709  DST(0,1) = DST(2,2) = (l0 + l1 + 1) >> 1;
710  DST(1,1) = DST(3,2) = (tl + l0 * 2 + l1 + 2) >> 2;
711  DST(0,2) = DST(2,3) = (l1 + l2 + 1) >> 1;
712  DST(1,2) = DST(3,3) = (l0 + l1 * 2 + l2 + 2) >> 2;
713  DST(0,3) = (l2 + l3 + 1) >> 1;
714  DST(1,3) = (l1 + l2 * 2 + l3 + 2) >> 2;
715 }
716 
717 #define def_hor_down(size) \
718 static void hor_down_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
719  const uint8_t *left, const uint8_t *top) \
720 { \
721  int i, j; \
722  uint8_t v[size * 3 - 2]; \
723 \
724  for (i = 0; i < size - 2; i++) { \
725  v[i*2 ] = (left[size - 2 - i] + left[size - 1 - i] + 1) >> 1; \
726  v[i*2 + 1] = (left[size - 3 - i] + left[size - 2 - i] * 2 + left[size - 1 - i] + 2) >> 2; \
727  v[size*2 + i] = (top[i - 1] + top[i] * 2 + top[i + 1] + 2) >> 2; \
728  } \
729  v[size*2 - 2] = (top[-1] + left[0] + 1) >> 1; \
730  v[size*2 - 4] = (left[0] + left[1] + 1) >> 1; \
731  v[size*2 - 1] = (top[0] + top[-1] * 2 + left[0] + 2) >> 2; \
732  v[size*2 - 3] = (top[-1] + left[0] * 2 + left[1] + 2) >> 2; \
733 \
734  for (j = 0; j < size; j++) \
735  memcpy(dst + j*stride, v + size*2 - 2 - j*2, size); \
736 }
737 
739 def_hor_down(16)
740 def_hor_down(32)
741 
742 static void vert_left_4x4_c(uint8_t *dst, ptrdiff_t stride,
743  const uint8_t *left, const uint8_t *top)
744 {
745  int a0 = top[0], a1 = top[1], a2 = top[2], a3 = top[3],
746  a4 = top[4], a5 = top[5], a6 = top[6];
747 
748  DST(0,0) = (a0 + a1 + 1) >> 1;
749  DST(0,1) = (a0 + a1 * 2 + a2 + 2) >> 2;
750  DST(1,0) = DST(0,2) = (a1 + a2 + 1) >> 1;
751  DST(1,1) = DST(0,3) = (a1 + a2 * 2 + a3 + 2) >> 2;
752  DST(2,0) = DST(1,2) = (a2 + a3 + 1) >> 1;
753  DST(2,1) = DST(1,3) = (a2 + a3 * 2 + a4 + 2) >> 2;
754  DST(3,0) = DST(2,2) = (a3 + a4 + 1) >> 1;
755  DST(3,1) = DST(2,3) = (a3 + a4 * 2 + a5 + 2) >> 2;
756  DST(3,2) = (a4 + a5 + 1) >> 1;
757  DST(3,3) = (a4 + a5 * 2 + a6 + 2) >> 2;
758 }
759 
760 #define def_vert_left(size) \
761 static void vert_left_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
762  const uint8_t *left, const uint8_t *top) \
763 { \
764  int i, j; \
765  uint8_t ve[size - 1], vo[size - 1]; \
766 \
767  for (i = 0; i < size - 2; i++) { \
768  ve[i] = (top[i] + top[i + 1] + 1) >> 1; \
769  vo[i] = (top[i] + top[i + 1] * 2 + top[i + 2] + 2) >> 2; \
770  } \
771  ve[size - 2] = (top[size - 2] + top[size - 1] + 1) >> 1; \
772  vo[size - 2] = (top[size - 2] + top[size - 1] * 3 + 2) >> 2; \
773 \
774  for (j = 0; j < size / 2; j++) { \
775  memcpy(dst + j*2 * stride, ve + j, size - j - 1); \
776  memset(dst + j*2 * stride + size - j - 1, top[size - 1], j + 1); \
777  memcpy(dst + (j*2 + 1) * stride, vo + j, size - j - 1); \
778  memset(dst + (j*2 + 1) * stride + size - j - 1, top[size - 1], j + 1); \
779  } \
780 }
781 
783 def_vert_left(16)
784 def_vert_left(32)
785 
786 static void hor_up_4x4_c(uint8_t *dst, ptrdiff_t stride,
787  const uint8_t *left, const uint8_t *top)
788 {
789  int l0 = left[0], l1 = left[1], l2 = left[2], l3 = left[3];
790 
791  DST(0,0) = (l0 + l1 + 1) >> 1;
792  DST(1,0) = (l0 + l1 * 2 + l2 + 2) >> 2;
793  DST(0,1) = DST(2,0) = (l1 + l2 + 1) >> 1;
794  DST(1,1) = DST(3,0) = (l1 + l2 * 2 + l3 + 2) >> 2;
795  DST(0,2) = DST(2,1) = (l2 + l3 + 1) >> 1;
796  DST(1,2) = DST(3,1) = (l2 + l3 * 3 + 2) >> 2;
797  DST(0,3) = DST(1,3) = DST(2,2) = DST(2,3) = DST(3,2) = DST(3,3) = l3;
798 }
799 
800 #define def_hor_up(size) \
801 static void hor_up_##size##x##size##_c(uint8_t *dst, ptrdiff_t stride, \
802  const uint8_t *left, const uint8_t *top) \
803 { \
804  int i, j; \
805  uint8_t v[size*2 - 2]; \
806 \
807  for (i = 0; i < size - 2; i++) { \
808  v[i*2 ] = (left[i] + left[i + 1] + 1) >> 1; \
809  v[i*2 + 1] = (left[i] + left[i + 1] * 2 + left[i + 2] + 2) >> 2; \
810  } \
811  v[size*2 - 4] = (left[size - 2] + left[size - 1] + 1) >> 1; \
812  v[size*2 - 3] = (left[size - 2] + left[size - 1] * 3 + 2) >> 2; \
813 \
814  for (j = 0; j < size / 2; j++) \
815  memcpy(dst + j*stride, v + j*2, size); \
816  for (j = size / 2; j < size; j++) { \
817  memcpy(dst + j*stride, v + j*2, size*2 - 2 - j*2); \
818  memset(dst + j*stride + size*2 - 2 - j*2, left[size - 1], \
819  2 + j*2 - size); \
820  } \
821 }
822 
824 def_hor_up(16)
825 def_hor_up(32)
826 
827 #undef DST
828 
829 static av_cold void vp9dsp_intrapred_init(VP9DSPContext *dsp)
830 {
831 #define init_intra_pred(tx, sz) \
832  dsp->intra_pred[tx][VERT_PRED] = vert_##sz##_c; \
833  dsp->intra_pred[tx][HOR_PRED] = hor_##sz##_c; \
834  dsp->intra_pred[tx][DC_PRED] = dc_##sz##_c; \
835  dsp->intra_pred[tx][DIAG_DOWN_LEFT_PRED] = diag_downleft_##sz##_c; \
836  dsp->intra_pred[tx][DIAG_DOWN_RIGHT_PRED] = diag_downright_##sz##_c; \
837  dsp->intra_pred[tx][VERT_RIGHT_PRED] = vert_right_##sz##_c; \
838  dsp->intra_pred[tx][HOR_DOWN_PRED] = hor_down_##sz##_c; \
839  dsp->intra_pred[tx][VERT_LEFT_PRED] = vert_left_##sz##_c; \
840  dsp->intra_pred[tx][HOR_UP_PRED] = hor_up_##sz##_c; \
841  dsp->intra_pred[tx][TM_VP8_PRED] = tm_##sz##_c; \
842  dsp->intra_pred[tx][LEFT_DC_PRED] = dc_left_##sz##_c; \
843  dsp->intra_pred[tx][TOP_DC_PRED] = dc_top_##sz##_c; \
844  dsp->intra_pred[tx][DC_128_PRED] = dc_128_##sz##_c; \
845  dsp->intra_pred[tx][DC_127_PRED] = dc_127_##sz##_c; \
846  dsp->intra_pred[tx][DC_129_PRED] = dc_129_##sz##_c
847 
848  init_intra_pred(TX_4X4, 4x4);
849  init_intra_pred(TX_8X8, 8x8);
850  init_intra_pred(TX_16X16, 16x16);
851  init_intra_pred(TX_32X32, 32x32);
852 
853 #undef init_intra_pred
854 }
855 
856 #define itxfm_wrapper(type_a, type_b, sz, bits) \
857 static void type_a##_##type_b##_##sz##x##sz##_add_c(uint8_t *dst, \
858  ptrdiff_t stride, \
859  int16_t *block, int eob) \
860 { \
861  int i, j; \
862  int16_t tmp[sz * sz], out[sz]; \
863  for (i = 0; i < sz; i++) \
864  type_a##sz##_1d(block + i, sz, tmp + i * sz, 0); \
865  memset(block, 0, sz * sz * sizeof(*block)); \
866  for (i = 0; i < sz; i++) { \
867  type_b##sz##_1d(tmp + i, sz, out, 1); \
868  for (j = 0; j < sz; j++) \
869  dst[j * stride] = av_clip_uint8(dst[j * stride] + \
870  (bits ? \
871  (out[j] + (1 << (bits - 1))) >> bits : \
872  out[j])); \
873  dst++; \
874  } \
875 }
876 
877 #define itxfm_wrap(sz, bits) \
878 itxfm_wrapper(idct, idct, sz, bits) \
879 itxfm_wrapper(iadst, idct, sz, bits) \
880 itxfm_wrapper(idct, iadst, sz, bits) \
881 itxfm_wrapper(iadst, iadst, sz, bits)
882 
883 #define IN(x) in[x * stride]
884 
885 static av_always_inline void idct4_1d(const int16_t *in, ptrdiff_t stride,
886  int16_t *out, int pass)
887 {
888  int t0, t1, t2, t3;
889 
890  t0 = ((IN(0) + IN(2)) * 11585 + (1 << 13)) >> 14;
891  t1 = ((IN(0) - IN(2)) * 11585 + (1 << 13)) >> 14;
892  t2 = (IN(1) * 6270 - IN(3) * 15137 + (1 << 13)) >> 14;
893  t3 = (IN(1) * 15137 + IN(3) * 6270 + (1 << 13)) >> 14;
894 
895  out[0] = t0 + t3;
896  out[1] = t1 + t2;
897  out[2] = t1 - t2;
898  out[3] = t0 - t3;
899 }
900 
901 static av_always_inline void iadst4_1d(const int16_t *in, ptrdiff_t stride,
902  int16_t *out, int pass)
903 {
904  int t0, t1, t2, t3;
905 
906  t0 = 5283 * IN(0) + 15212 * IN(2) + 9929 * IN(3);
907  t1 = 9929 * IN(0) - 5283 * IN(2) - 15212 * IN(3);
908  t2 = 13377 * (IN(0) - IN(2) + IN(3));
909  t3 = 13377 * IN(1);
910 
911  out[0] = (t0 + t3 + (1 << 13)) >> 14;
912  out[1] = (t1 + t3 + (1 << 13)) >> 14;
913  out[2] = (t2 + (1 << 13)) >> 14;
914  out[3] = (t0 + t1 - t3 + (1 << 13)) >> 14;
915 }
916 
918 
919 static av_always_inline void idct8_1d(const int16_t *in, ptrdiff_t stride,
920  int16_t *out, int pass)
921 {
922  int t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
923 
924  t0a = ((IN(0) + IN(4)) * 11585 + (1 << 13)) >> 14;
925  t1a = ((IN(0) - IN(4)) * 11585 + (1 << 13)) >> 14;
926  t2a = (IN(2) * 6270 - IN(6) * 15137 + (1 << 13)) >> 14;
927  t3a = (IN(2) * 15137 + IN(6) * 6270 + (1 << 13)) >> 14;
928  t4a = (IN(1) * 3196 - IN(7) * 16069 + (1 << 13)) >> 14;
929  t5a = (IN(5) * 13623 - IN(3) * 9102 + (1 << 13)) >> 14;
930  t6a = (IN(5) * 9102 + IN(3) * 13623 + (1 << 13)) >> 14;
931  t7a = (IN(1) * 16069 + IN(7) * 3196 + (1 << 13)) >> 14;
932 
933  t0 = t0a + t3a;
934  t1 = t1a + t2a;
935  t2 = t1a - t2a;
936  t3 = t0a - t3a;
937  t4 = t4a + t5a;
938  t5a = t4a - t5a;
939  t7 = t7a + t6a;
940  t6a = t7a - t6a;
941 
942  t5 = ((t6a - t5a) * 11585 + (1 << 13)) >> 14;
943  t6 = ((t6a + t5a) * 11585 + (1 << 13)) >> 14;
944 
945  out[0] = t0 + t7;
946  out[1] = t1 + t6;
947  out[2] = t2 + t5;
948  out[3] = t3 + t4;
949  out[4] = t3 - t4;
950  out[5] = t2 - t5;
951  out[6] = t1 - t6;
952  out[7] = t0 - t7;
953 }
954 
955 static av_always_inline void iadst8_1d(const int16_t *in, ptrdiff_t stride,
956  int16_t *out, int pass)
957 {
958  int t0, t0a, t1, t1a, t2, t2a, t3, t3a, t4, t4a, t5, t5a, t6, t6a, t7, t7a;
959 
960  t0a = 16305 * IN(7) + 1606 * IN(0);
961  t1a = 1606 * IN(7) - 16305 * IN(0);
962  t2a = 14449 * IN(5) + 7723 * IN(2);
963  t3a = 7723 * IN(5) - 14449 * IN(2);
964  t4a = 10394 * IN(3) + 12665 * IN(4);
965  t5a = 12665 * IN(3) - 10394 * IN(4);
966  t6a = 4756 * IN(1) + 15679 * IN(6);
967  t7a = 15679 * IN(1) - 4756 * IN(6);
968 
969  t0 = (t0a + t4a + (1 << 13)) >> 14;
970  t1 = (t1a + t5a + (1 << 13)) >> 14;
971  t2 = (t2a + t6a + (1 << 13)) >> 14;
972  t3 = (t3a + t7a + (1 << 13)) >> 14;
973  t4 = (t0a - t4a + (1 << 13)) >> 14;
974  t5 = (t1a - t5a + (1 << 13)) >> 14;
975  t6 = (t2a - t6a + (1 << 13)) >> 14;
976  t7 = (t3a - t7a + (1 << 13)) >> 14;
977 
978  t4a = 15137 * t4 + 6270 * t5;
979  t5a = 6270 * t4 - 15137 * t5;
980  t6a = 15137 * t7 - 6270 * t6;
981  t7a = 6270 * t7 + 15137 * t6;
982 
983  out[0] = t0 + t2;
984  out[7] = -(t1 + t3);
985  t2 = t0 - t2;
986  t3 = t1 - t3;
987 
988  out[1] = -((t4a + t6a + (1 << 13)) >> 14);
989  out[6] = (t5a + t7a + (1 << 13)) >> 14;
990  t6 = (t4a - t6a + (1 << 13)) >> 14;
991  t7 = (t5a - t7a + (1 << 13)) >> 14;
992 
993  out[3] = -(((t2 + t3) * 11585 + (1 << 13)) >> 14);
994  out[4] = ((t2 - t3) * 11585 + (1 << 13)) >> 14;
995  out[2] = ((t6 + t7) * 11585 + (1 << 13)) >> 14;
996  out[5] = -(((t6 - t7) * 11585 + (1 << 13)) >> 14);
997 }
998 
1000 
1001 static av_always_inline void idct16_1d(const int16_t *in, ptrdiff_t stride,
1002  int16_t *out, int pass)
1003 {
1004  int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
1005  int t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
1006  int t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
1007 
1008  t0a = ((IN(0) + IN(8)) * 11585 + (1 << 13)) >> 14;
1009  t1a = ((IN(0) - IN(8)) * 11585 + (1 << 13)) >> 14;
1010  t2a = (IN(4) * 6270 - IN(12) * 15137 + (1 << 13)) >> 14;
1011  t3a = (IN(4) * 15137 + IN(12) * 6270 + (1 << 13)) >> 14;
1012  t4a = (IN(2) * 3196 - IN(14) * 16069 + (1 << 13)) >> 14;
1013  t7a = (IN(2) * 16069 + IN(14) * 3196 + (1 << 13)) >> 14;
1014  t5a = (IN(10) * 13623 - IN(6) * 9102 + (1 << 13)) >> 14;
1015  t6a = (IN(10) * 9102 + IN(6) * 13623 + (1 << 13)) >> 14;
1016  t8a = (IN(1) * 1606 - IN(15) * 16305 + (1 << 13)) >> 14;
1017  t15a = (IN(1) * 16305 + IN(15) * 1606 + (1 << 13)) >> 14;
1018  t9a = (IN(9) * 12665 - IN(7) * 10394 + (1 << 13)) >> 14;
1019  t14a = (IN(9) * 10394 + IN(7) * 12665 + (1 << 13)) >> 14;
1020  t10a = (IN(5) * 7723 - IN(11) * 14449 + (1 << 13)) >> 14;
1021  t13a = (IN(5) * 14449 + IN(11) * 7723 + (1 << 13)) >> 14;
1022  t11a = (IN(13) * 15679 - IN(3) * 4756 + (1 << 13)) >> 14;
1023  t12a = (IN(13) * 4756 + IN(3) * 15679 + (1 << 13)) >> 14;
1024 
1025  t0 = t0a + t3a;
1026  t1 = t1a + t2a;
1027  t2 = t1a - t2a;
1028  t3 = t0a - t3a;
1029  t4 = t4a + t5a;
1030  t5 = t4a - t5a;
1031  t6 = t7a - t6a;
1032  t7 = t7a + t6a;
1033  t8 = t8a + t9a;
1034  t9 = t8a - t9a;
1035  t10 = t11a - t10a;
1036  t11 = t11a + t10a;
1037  t12 = t12a + t13a;
1038  t13 = t12a - t13a;
1039  t14 = t15a - t14a;
1040  t15 = t15a + t14a;
1041 
1042  t5a = ((t6 - t5) * 11585 + (1 << 13)) >> 14;
1043  t6a = ((t6 + t5) * 11585 + (1 << 13)) >> 14;
1044  t9a = ( t14 * 6270 - t9 * 15137 + (1 << 13)) >> 14;
1045  t14a = ( t14 * 15137 + t9 * 6270 + (1 << 13)) >> 14;
1046  t10a = (-(t13 * 15137 + t10 * 6270) + (1 << 13)) >> 14;
1047  t13a = ( t13 * 6270 - t10 * 15137 + (1 << 13)) >> 14;
1048 
1049  t0a = t0 + t7;
1050  t1a = t1 + t6a;
1051  t2a = t2 + t5a;
1052  t3a = t3 + t4;
1053  t4 = t3 - t4;
1054  t5 = t2 - t5a;
1055  t6 = t1 - t6a;
1056  t7 = t0 - t7;
1057  t8a = t8 + t11;
1058  t9 = t9a + t10a;
1059  t10 = t9a - t10a;
1060  t11a = t8 - t11;
1061  t12a = t15 - t12;
1062  t13 = t14a - t13a;
1063  t14 = t14a + t13a;
1064  t15a = t15 + t12;
1065 
1066  t10a = ((t13 - t10) * 11585 + (1 << 13)) >> 14;
1067  t13a = ((t13 + t10) * 11585 + (1 << 13)) >> 14;
1068  t11 = ((t12a - t11a) * 11585 + (1 << 13)) >> 14;
1069  t12 = ((t12a + t11a) * 11585 + (1 << 13)) >> 14;
1070 
1071  out[ 0] = t0a + t15a;
1072  out[ 1] = t1a + t14;
1073  out[ 2] = t2a + t13a;
1074  out[ 3] = t3a + t12;
1075  out[ 4] = t4 + t11;
1076  out[ 5] = t5 + t10a;
1077  out[ 6] = t6 + t9;
1078  out[ 7] = t7 + t8a;
1079  out[ 8] = t7 - t8a;
1080  out[ 9] = t6 - t9;
1081  out[10] = t5 - t10a;
1082  out[11] = t4 - t11;
1083  out[12] = t3a - t12;
1084  out[13] = t2a - t13a;
1085  out[14] = t1a - t14;
1086  out[15] = t0a - t15a;
1087 }
1088 
1089 static av_always_inline void iadst16_1d(const int16_t *in, ptrdiff_t stride,
1090  int16_t *out, int pass)
1091 {
1092  int t0, t1, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15;
1093  int t0a, t1a, t2a, t3a, t4a, t5a, t6a, t7a;
1094  int t8a, t9a, t10a, t11a, t12a, t13a, t14a, t15a;
1095 
1096  t0 = IN(15) * 16364 + IN(0) * 804;
1097  t1 = IN(15) * 804 - IN(0) * 16364;
1098  t2 = IN(13) * 15893 + IN(2) * 3981;
1099  t3 = IN(13) * 3981 - IN(2) * 15893;
1100  t4 = IN(11) * 14811 + IN(4) * 7005;
1101  t5 = IN(11) * 7005 - IN(4) * 14811;
1102  t6 = IN(9) * 13160 + IN(6) * 9760;
1103  t7 = IN(9) * 9760 - IN(6) * 13160;
1104  t8 = IN(7) * 11003 + IN(8) * 12140;
1105  t9 = IN(7) * 12140 - IN(8) * 11003;
1106  t10 = IN(5) * 8423 + IN(10) * 14053;
1107  t11 = IN(5) * 14053 - IN(10) * 8423;
1108  t12 = IN(3) * 5520 + IN(12) * 15426;
1109  t13 = IN(3) * 15426 - IN(12) * 5520;
1110  t14 = IN(1) * 2404 + IN(14) * 16207;
1111  t15 = IN(1) * 16207 - IN(14) * 2404;
1112 
1113  t0a = (t0 + t8 + (1 << 13)) >> 14;
1114  t1a = (t1 + t9 + (1 << 13)) >> 14;
1115  t2a = (t2 + t10 + (1 << 13)) >> 14;
1116  t3a = (t3 + t11 + (1 << 13)) >> 14;
1117  t4a = (t4 + t12 + (1 << 13)) >> 14;
1118  t5a = (t5 + t13 + (1 << 13)) >> 14;
1119  t6a = (t6 + t14 + (1 << 13)) >> 14;
1120  t7a = (t7 + t15 + (1 << 13)) >> 14;
1121  t8a = (t0 - t8 + (1 << 13)) >> 14;
1122  t9a = (t1 - t9 + (1 << 13)) >> 14;
1123  t10a = (t2 - t10 + (1 << 13)) >> 14;
1124  t11a = (t3 - t11 + (1 << 13)) >> 14;
1125  t12a = (t4 - t12 + (1 << 13)) >> 14;
1126  t13a = (t5 - t13 + (1 << 13)) >> 14;
1127  t14a = (t6 - t14 + (1 << 13)) >> 14;
1128  t15a = (t7 - t15 + (1 << 13)) >> 14;
1129 
1130  t8 = t8a * 16069 + t9a * 3196;
1131  t9 = t8a * 3196 - t9a * 16069;
1132  t10 = t10a * 9102 + t11a * 13623;
1133  t11 = t10a * 13623 - t11a * 9102;
1134  t12 = t13a * 16069 - t12a * 3196;
1135  t13 = t13a * 3196 + t12a * 16069;
1136  t14 = t15a * 9102 - t14a * 13623;
1137  t15 = t15a * 13623 + t14a * 9102;
1138 
1139  t0 = t0a + t4a;
1140  t1 = t1a + t5a;
1141  t2 = t2a + t6a;
1142  t3 = t3a + t7a;
1143  t4 = t0a - t4a;
1144  t5 = t1a - t5a;
1145  t6 = t2a - t6a;
1146  t7 = t3a - t7a;
1147  t8a = (t8 + t12 + (1 << 13)) >> 14;
1148  t9a = (t9 + t13 + (1 << 13)) >> 14;
1149  t10a = (t10 + t14 + (1 << 13)) >> 14;
1150  t11a = (t11 + t15 + (1 << 13)) >> 14;
1151  t12a = (t8 - t12 + (1 << 13)) >> 14;
1152  t13a = (t9 - t13 + (1 << 13)) >> 14;
1153  t14a = (t10 - t14 + (1 << 13)) >> 14;
1154  t15a = (t11 - t15 + (1 << 13)) >> 14;
1155 
1156  t4a = t4 * 15137 + t5 * 6270;
1157  t5a = t4 * 6270 - t5 * 15137;
1158  t6a = t7 * 15137 - t6 * 6270;
1159  t7a = t7 * 6270 + t6 * 15137;
1160  t12 = t12a * 15137 + t13a * 6270;
1161  t13 = t12a * 6270 - t13a * 15137;
1162  t14 = t15a * 15137 - t14a * 6270;
1163  t15 = t15a * 6270 + t14a * 15137;
1164 
1165  out[ 0] = t0 + t2;
1166  out[15] = -(t1 + t3);
1167  t2a = t0 - t2;
1168  t3a = t1 - t3;
1169  out[ 3] = -((t4a + t6a + (1 << 13)) >> 14);
1170  out[12] = (t5a + t7a + (1 << 13)) >> 14;
1171  t6 = (t4a - t6a + (1 << 13)) >> 14;
1172  t7 = (t5a - t7a + (1 << 13)) >> 14;
1173  out[ 1] = -(t8a + t10a);
1174  out[14] = t9a + t11a;
1175  t10 = t8a - t10a;
1176  t11 = t9a - t11a;
1177  out[ 2] = (t12 + t14 + (1 << 13)) >> 14;
1178  out[13] = -((t13 + t15 + (1 << 13)) >> 14);
1179  t14a = (t12 - t14 + (1 << 13)) >> 14;
1180  t15a = (t13 - t15 + (1 << 13)) >> 14;
1181 
1182  out[ 7] = ((t2a + t3a) * -11585 + (1 << 13)) >> 14;
1183  out[ 8] = ((t2a - t3a) * 11585 + (1 << 13)) >> 14;
1184  out[ 4] = ((t7 + t6) * 11585 + (1 << 13)) >> 14;
1185  out[11] = ((t7 - t6) * 11585 + (1 << 13)) >> 14;
1186  out[ 6] = ((t11 + t10) * 11585 + (1 << 13)) >> 14;
1187  out[ 9] = ((t11 - t10) * 11585 + (1 << 13)) >> 14;
1188  out[ 5] = ((t14a + t15a) * -11585 + (1 << 13)) >> 14;
1189  out[10] = ((t14a - t15a) * 11585 + (1 << 13)) >> 14;
1190 }
1191 
1193 
1194 static av_always_inline void idct32_1d(const int16_t *in, ptrdiff_t stride,
1195  int16_t *out, int pass)
1196 {
1197  int t0a = ((IN(0) + IN(16)) * 11585 + (1 << 13)) >> 14;
1198  int t1a = ((IN(0) - IN(16)) * 11585 + (1 << 13)) >> 14;
1199  int t2a = (IN( 8) * 6270 - IN(24) * 15137 + (1 << 13)) >> 14;
1200  int t3a = (IN( 8) * 15137 + IN(24) * 6270 + (1 << 13)) >> 14;
1201  int t4a = (IN( 4) * 3196 - IN(28) * 16069 + (1 << 13)) >> 14;
1202  int t7a = (IN( 4) * 16069 + IN(28) * 3196 + (1 << 13)) >> 14;
1203  int t5a = (IN(20) * 13623 - IN(12) * 9102 + (1 << 13)) >> 14;
1204  int t6a = (IN(20) * 9102 + IN(12) * 13623 + (1 << 13)) >> 14;
1205  int t8a = (IN( 2) * 1606 - IN(30) * 16305 + (1 << 13)) >> 14;
1206  int t15a = (IN( 2) * 16305 + IN(30) * 1606 + (1 << 13)) >> 14;
1207  int t9a = (IN(18) * 12665 - IN(14) * 10394 + (1 << 13)) >> 14;
1208  int t14a = (IN(18) * 10394 + IN(14) * 12665 + (1 << 13)) >> 14;
1209  int t10a = (IN(10) * 7723 - IN(22) * 14449 + (1 << 13)) >> 14;
1210  int t13a = (IN(10) * 14449 + IN(22) * 7723 + (1 << 13)) >> 14;
1211  int t11a = (IN(26) * 15679 - IN( 6) * 4756 + (1 << 13)) >> 14;
1212  int t12a = (IN(26) * 4756 + IN( 6) * 15679 + (1 << 13)) >> 14;
1213  int t16a = (IN( 1) * 804 - IN(31) * 16364 + (1 << 13)) >> 14;
1214  int t31a = (IN( 1) * 16364 + IN(31) * 804 + (1 << 13)) >> 14;
1215  int t17a = (IN(17) * 12140 - IN(15) * 11003 + (1 << 13)) >> 14;
1216  int t30a = (IN(17) * 11003 + IN(15) * 12140 + (1 << 13)) >> 14;
1217  int t18a = (IN( 9) * 7005 - IN(23) * 14811 + (1 << 13)) >> 14;
1218  int t29a = (IN( 9) * 14811 + IN(23) * 7005 + (1 << 13)) >> 14;
1219  int t19a = (IN(25) * 15426 - IN( 7) * 5520 + (1 << 13)) >> 14;
1220  int t28a = (IN(25) * 5520 + IN( 7) * 15426 + (1 << 13)) >> 14;
1221  int t20a = (IN( 5) * 3981 - IN(27) * 15893 + (1 << 13)) >> 14;
1222  int t27a = (IN( 5) * 15893 + IN(27) * 3981 + (1 << 13)) >> 14;
1223  int t21a = (IN(21) * 14053 - IN(11) * 8423 + (1 << 13)) >> 14;
1224  int t26a = (IN(21) * 8423 + IN(11) * 14053 + (1 << 13)) >> 14;
1225  int t22a = (IN(13) * 9760 - IN(19) * 13160 + (1 << 13)) >> 14;
1226  int t25a = (IN(13) * 13160 + IN(19) * 9760 + (1 << 13)) >> 14;
1227  int t23a = (IN(29) * 16207 - IN( 3) * 2404 + (1 << 13)) >> 14;
1228  int t24a = (IN(29) * 2404 + IN( 3) * 16207 + (1 << 13)) >> 14;
1229 
1230  int t0 = t0a + t3a;
1231  int t1 = t1a + t2a;
1232  int t2 = t1a - t2a;
1233  int t3 = t0a - t3a;
1234  int t4 = t4a + t5a;
1235  int t5 = t4a - t5a;
1236  int t6 = t7a - t6a;
1237  int t7 = t7a + t6a;
1238  int t8 = t8a + t9a;
1239  int t9 = t8a - t9a;
1240  int t10 = t11a - t10a;
1241  int t11 = t11a + t10a;
1242  int t12 = t12a + t13a;
1243  int t13 = t12a - t13a;
1244  int t14 = t15a - t14a;
1245  int t15 = t15a + t14a;
1246  int t16 = t16a + t17a;
1247  int t17 = t16a - t17a;
1248  int t18 = t19a - t18a;
1249  int t19 = t19a + t18a;
1250  int t20 = t20a + t21a;
1251  int t21 = t20a - t21a;
1252  int t22 = t23a - t22a;
1253  int t23 = t23a + t22a;
1254  int t24 = t24a + t25a;
1255  int t25 = t24a - t25a;
1256  int t26 = t27a - t26a;
1257  int t27 = t27a + t26a;
1258  int t28 = t28a + t29a;
1259  int t29 = t28a - t29a;
1260  int t30 = t31a - t30a;
1261  int t31 = t31a + t30a;
1262 
1263  t5a = ((t6 - t5) * 11585 + (1 << 13)) >> 14;
1264  t6a = ((t6 + t5) * 11585 + (1 << 13)) >> 14;
1265  t9a = ( t14 * 6270 - t9 * 15137 + (1 << 13)) >> 14;
1266  t14a = ( t14 * 15137 + t9 * 6270 + (1 << 13)) >> 14;
1267  t10a = (-(t13 * 15137 + t10 * 6270) + (1 << 13)) >> 14;
1268  t13a = ( t13 * 6270 - t10 * 15137 + (1 << 13)) >> 14;
1269  t17a = ( t30 * 3196 - t17 * 16069 + (1 << 13)) >> 14;
1270  t30a = ( t30 * 16069 + t17 * 3196 + (1 << 13)) >> 14;
1271  t18a = (-(t29 * 16069 + t18 * 3196) + (1 << 13)) >> 14;
1272  t29a = ( t29 * 3196 - t18 * 16069 + (1 << 13)) >> 14;
1273  t21a = ( t26 * 13623 - t21 * 9102 + (1 << 13)) >> 14;
1274  t26a = ( t26 * 9102 + t21 * 13623 + (1 << 13)) >> 14;
1275  t22a = (-(t25 * 9102 + t22 * 13623) + (1 << 13)) >> 14;
1276  t25a = ( t25 * 13623 - t22 * 9102 + (1 << 13)) >> 14;
1277 
1278  t0a = t0 + t7;
1279  t1a = t1 + t6a;
1280  t2a = t2 + t5a;
1281  t3a = t3 + t4;
1282  t4a = t3 - t4;
1283  t5 = t2 - t5a;
1284  t6 = t1 - t6a;
1285  t7a = t0 - t7;
1286  t8a = t8 + t11;
1287  t9 = t9a + t10a;
1288  t10 = t9a - t10a;
1289  t11a = t8 - t11;
1290  t12a = t15 - t12;
1291  t13 = t14a - t13a;
1292  t14 = t14a + t13a;
1293  t15a = t15 + t12;
1294  t16a = t16 + t19;
1295  t17 = t17a + t18a;
1296  t18 = t17a - t18a;
1297  t19a = t16 - t19;
1298  t20a = t23 - t20;
1299  t21 = t22a - t21a;
1300  t22 = t22a + t21a;
1301  t23a = t23 + t20;
1302  t24a = t24 + t27;
1303  t25 = t25a + t26a;
1304  t26 = t25a - t26a;
1305  t27a = t24 - t27;
1306  t28a = t31 - t28;
1307  t29 = t30a - t29a;
1308  t30 = t30a + t29a;
1309  t31a = t31 + t28;
1310 
1311  t10a = ((t13 - t10) * 11585 + (1 << 13)) >> 14;
1312  t13a = ((t13 + t10) * 11585 + (1 << 13)) >> 14;
1313  t11 = ((t12a - t11a) * 11585 + (1 << 13)) >> 14;
1314  t12 = ((t12a + t11a) * 11585 + (1 << 13)) >> 14;
1315  t18a = ( t29 * 6270 - t18 * 15137 + (1 << 13)) >> 14;
1316  t29a = ( t29 * 15137 + t18 * 6270 + (1 << 13)) >> 14;
1317  t19 = ( t28a * 6270 - t19a * 15137 + (1 << 13)) >> 14;
1318  t28 = ( t28a * 15137 + t19a * 6270 + (1 << 13)) >> 14;
1319  t20 = (-(t27a * 15137 + t20a * 6270) + (1 << 13)) >> 14;
1320  t27 = ( t27a * 6270 - t20a * 15137 + (1 << 13)) >> 14;
1321  t21a = (-(t26 * 15137 + t21 * 6270) + (1 << 13)) >> 14;
1322  t26a = ( t26 * 6270 - t21 * 15137 + (1 << 13)) >> 14;
1323 
1324  t0 = t0a + t15a;
1325  t1 = t1a + t14;
1326  t2 = t2a + t13a;
1327  t3 = t3a + t12;
1328  t4 = t4a + t11;
1329  t5a = t5 + t10a;
1330  t6a = t6 + t9;
1331  t7 = t7a + t8a;
1332  t8 = t7a - t8a;
1333  t9a = t6 - t9;
1334  t10 = t5 - t10a;
1335  t11a = t4a - t11;
1336  t12a = t3a - t12;
1337  t13 = t2a - t13a;
1338  t14a = t1a - t14;
1339  t15 = t0a - t15a;
1340  t16 = t16a + t23a;
1341  t17a = t17 + t22;
1342  t18 = t18a + t21a;
1343  t19a = t19 + t20;
1344  t20a = t19 - t20;
1345  t21 = t18a - t21a;
1346  t22a = t17 - t22;
1347  t23 = t16a - t23a;
1348  t24 = t31a - t24a;
1349  t25a = t30 - t25;
1350  t26 = t29a - t26a;
1351  t27a = t28 - t27;
1352  t28a = t28 + t27;
1353  t29 = t29a + t26a;
1354  t30a = t30 + t25;
1355  t31 = t31a + t24a;
1356 
1357  t20 = ((t27a - t20a) * 11585 + (1 << 13)) >> 14;
1358  t27 = ((t27a + t20a) * 11585 + (1 << 13)) >> 14;
1359  t21a = ((t26 - t21 ) * 11585 + (1 << 13)) >> 14;
1360  t26a = ((t26 + t21 ) * 11585 + (1 << 13)) >> 14;
1361  t22 = ((t25a - t22a) * 11585 + (1 << 13)) >> 14;
1362  t25 = ((t25a + t22a) * 11585 + (1 << 13)) >> 14;
1363  t23a = ((t24 - t23 ) * 11585 + (1 << 13)) >> 14;
1364  t24a = ((t24 + t23 ) * 11585 + (1 << 13)) >> 14;
1365 
1366  out[ 0] = t0 + t31;
1367  out[ 1] = t1 + t30a;
1368  out[ 2] = t2 + t29;
1369  out[ 3] = t3 + t28a;
1370  out[ 4] = t4 + t27;
1371  out[ 5] = t5a + t26a;
1372  out[ 6] = t6a + t25;
1373  out[ 7] = t7 + t24a;
1374  out[ 8] = t8 + t23a;
1375  out[ 9] = t9a + t22;
1376  out[10] = t10 + t21a;
1377  out[11] = t11a + t20;
1378  out[12] = t12a + t19a;
1379  out[13] = t13 + t18;
1380  out[14] = t14a + t17a;
1381  out[15] = t15 + t16;
1382  out[16] = t15 - t16;
1383  out[17] = t14a - t17a;
1384  out[18] = t13 - t18;
1385  out[19] = t12a - t19a;
1386  out[20] = t11a - t20;
1387  out[21] = t10 - t21a;
1388  out[22] = t9a - t22;
1389  out[23] = t8 - t23a;
1390  out[24] = t7 - t24a;
1391  out[25] = t6a - t25;
1392  out[26] = t5a - t26a;
1393  out[27] = t4 - t27;
1394  out[28] = t3 - t28a;
1395  out[29] = t2 - t29;
1396  out[30] = t1 - t30a;
1397  out[31] = t0 - t31;
1398 }
1399 
1401 
1402 static av_always_inline void iwht4_1d(const int16_t *in, ptrdiff_t stride,
1403  int16_t *out, int pass)
1404 {
1405  int t0, t1, t2, t3, t4;
1406 
1407  if (pass == 0) {
1408  t0 = IN(0) >> 2;
1409  t1 = IN(3) >> 2;
1410  t2 = IN(1) >> 2;
1411  t3 = IN(2) >> 2;
1412  } else {
1413  t0 = IN(0);
1414  t1 = IN(3);
1415  t2 = IN(1);
1416  t3 = IN(2);
1417  }
1418 
1419  t0 += t2;
1420  t3 -= t1;
1421  t4 = (t0 - t3) >> 1;
1422  t1 = t4 - t1;
1423  t2 = t4 - t2;
1424  t0 -= t1;
1425  t3 += t2;
1426 
1427  out[0] = t0;
1428  out[1] = t1;
1429  out[2] = t2;
1430  out[3] = t3;
1431 }
1432 
1433 itxfm_wrapper(iwht, iwht, 4, 0)
1434 
1435 #undef IN
1436 #undef itxfm_wrapper
1437 #undef itxfm_wrap
1438 
1439 static av_cold void vp9dsp_itxfm_init(VP9DSPContext *dsp)
1440 {
1441 #define init_itxfm(tx, sz) \
1442  dsp->itxfm_add[tx][DCT_DCT] = idct_idct_##sz##_add_c; \
1443  dsp->itxfm_add[tx][DCT_ADST] = iadst_idct_##sz##_add_c; \
1444  dsp->itxfm_add[tx][ADST_DCT] = idct_iadst_##sz##_add_c; \
1445  dsp->itxfm_add[tx][ADST_ADST] = iadst_iadst_##sz##_add_c
1446 
1447 #define init_idct(tx, nm) \
1448  dsp->itxfm_add[tx][DCT_DCT] = \
1449  dsp->itxfm_add[tx][ADST_DCT] = \
1450  dsp->itxfm_add[tx][DCT_ADST] = \
1451  dsp->itxfm_add[tx][ADST_ADST] = nm##_add_c
1452 
1453  init_itxfm(TX_4X4, 4x4);
1454  init_itxfm(TX_8X8, 8x8);
1455  init_itxfm(TX_16X16, 16x16);
1456  init_idct(TX_32X32, idct_idct_32x32);
1457  init_idct(4 /* lossless */, iwht_iwht_4x4);
1458 
1459 #undef init_itxfm
1460 #undef init_idct
1461 }
1462 
1463 static av_always_inline void loop_filter(uint8_t *dst, ptrdiff_t stride,
1464  int E, int I, int H,
1465  ptrdiff_t stridea, ptrdiff_t strideb,
1466  int wd)
1467 {
1468  int i;
1469 
1470  for (i = 0; i < 8; i++, dst += stridea) {
1471  int p7, p6, p5, p4;
1472  int p3 = dst[strideb * -4], p2 = dst[strideb * -3];
1473  int p1 = dst[strideb * -2], p0 = dst[strideb * -1];
1474  int q0 = dst[strideb * +0], q1 = dst[strideb * +1];
1475  int q2 = dst[strideb * +2], q3 = dst[strideb * +3];
1476  int q4, q5, q6, q7;
1477  int fm = FFABS(p3 - p2) <= I && FFABS(p2 - p1) <= I &&
1478  FFABS(p1 - p0) <= I && FFABS(q1 - q0) <= I &&
1479  FFABS(q2 - q1) <= I && FFABS(q3 - q2) <= I &&
1480  FFABS(p0 - q0) * 2 + (FFABS(p1 - q1) >> 1) <= E;
1481  int flat8out, flat8in;
1482 
1483  if (!fm)
1484  continue;
1485 
1486  if (wd >= 16) {
1487  p7 = dst[strideb * -8];
1488  p6 = dst[strideb * -7];
1489  p5 = dst[strideb * -6];
1490  p4 = dst[strideb * -5];
1491  q4 = dst[strideb * +4];
1492  q5 = dst[strideb * +5];
1493  q6 = dst[strideb * +6];
1494  q7 = dst[strideb * +7];
1495 
1496  flat8out = FFABS(p7 - p0) <= 1 && FFABS(p6 - p0) <= 1 &&
1497  FFABS(p5 - p0) <= 1 && FFABS(p4 - p0) <= 1 &&
1498  FFABS(q4 - q0) <= 1 && FFABS(q5 - q0) <= 1 &&
1499  FFABS(q6 - q0) <= 1 && FFABS(q7 - q0) <= 1;
1500  }
1501 
1502  if (wd >= 8)
1503  flat8in = FFABS(p3 - p0) <= 1 && FFABS(p2 - p0) <= 1 &&
1504  FFABS(p1 - p0) <= 1 && FFABS(q1 - q0) <= 1 &&
1505  FFABS(q2 - q0) <= 1 && FFABS(q3 - q0) <= 1;
1506 
1507  if (wd >= 16 && flat8out && flat8in) {
1508  dst[strideb * -7] = (p7 + p7 + p7 + p7 + p7 + p7 + p7 + p6 * 2 +
1509  p5 + p4 + p3 + p2 + p1 + p0 + q0 + 8) >> 4;
1510  dst[strideb * -6] = (p7 + p7 + p7 + p7 + p7 + p7 + p6 + p5 * 2 +
1511  p4 + p3 + p2 + p1 + p0 + q0 + q1 + 8) >> 4;
1512  dst[strideb * -5] = (p7 + p7 + p7 + p7 + p7 + p6 + p5 + p4 * 2 +
1513  p3 + p2 + p1 + p0 + q0 + q1 + q2 + 8) >> 4;
1514  dst[strideb * -4] = (p7 + p7 + p7 + p7 + p6 + p5 + p4 + p3 * 2 +
1515  p2 + p1 + p0 + q0 + q1 + q2 + q3 + 8) >> 4;
1516  dst[strideb * -3] = (p7 + p7 + p7 + p6 + p5 + p4 + p3 + p2 * 2 +
1517  p1 + p0 + q0 + q1 + q2 + q3 + q4 + 8) >> 4;
1518  dst[strideb * -2] = (p7 + p7 + p6 + p5 + p4 + p3 + p2 + p1 * 2 +
1519  p0 + q0 + q1 + q2 + q3 + q4 + q5 + 8) >> 4;
1520  dst[strideb * -1] = (p7 + p6 + p5 + p4 + p3 + p2 + p1 + p0 * 2 +
1521  q0 + q1 + q2 + q3 + q4 + q5 + q6 + 8) >> 4;
1522  dst[strideb * +0] = (p6 + p5 + p4 + p3 + p2 + p1 + p0 + q0 * 2 +
1523  q1 + q2 + q3 + q4 + q5 + q6 + q7 + 8) >> 4;
1524  dst[strideb * +1] = (p5 + p4 + p3 + p2 + p1 + p0 + q0 + q1 * 2 +
1525  q2 + q3 + q4 + q5 + q6 + q7 + q7 + 8) >> 4;
1526  dst[strideb * +2] = (p4 + p3 + p2 + p1 + p0 + q0 + q1 + q2 * 2 +
1527  q3 + q4 + q5 + q6 + q7 + q7 + q7 + 8) >> 4;
1528  dst[strideb * +3] = (p3 + p2 + p1 + p0 + q0 + q1 + q2 + q3 * 2 +
1529  q4 + q5 + q6 + q7 + q7 + q7 + q7 + 8) >> 4;
1530  dst[strideb * +4] = (p2 + p1 + p0 + q0 + q1 + q2 + q3 + q4 * 2 +
1531  q5 + q6 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
1532  dst[strideb * +5] = (p1 + p0 + q0 + q1 + q2 + q3 + q4 + q5 * 2 +
1533  q6 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
1534  dst[strideb * +6] = (p0 + q0 + q1 + q2 + q3 + q4 + q5 + q6 * 2 +
1535  q7 + q7 + q7 + q7 + q7 + q7 + q7 + 8) >> 4;
1536  } else if (wd >= 8 && flat8in) {
1537  dst[strideb * -3] = (p3 + p3 + p3 + 2 * p2 + p1 + p0 + q0 + 4) >> 3;
1538  dst[strideb * -2] = (p3 + p3 + p2 + 2 * p1 + p0 + q0 + q1 + 4) >> 3;
1539  dst[strideb * -1] = (p3 + p2 + p1 + 2 * p0 + q0 + q1 + q2 + 4) >> 3;
1540  dst[strideb * +0] = (p2 + p1 + p0 + 2 * q0 + q1 + q2 + q3 + 4) >> 3;
1541  dst[strideb * +1] = (p1 + p0 + q0 + 2 * q1 + q2 + q3 + q3 + 4) >> 3;
1542  dst[strideb * +2] = (p0 + q0 + q1 + 2 * q2 + q3 + q3 + q3 + 4) >> 3;
1543  } else {
1544  int hev = FFABS(p1 - p0) > H || FFABS(q1 - q0) > H;
1545 
1546  if (hev) {
1547  int f = av_clip_int8(3 * (q0 - p0) + av_clip_int8(p1 - q1)), f1, f2;
1548 
1549  f1 = FFMIN(f + 4, 127) >> 3;
1550  f2 = FFMIN(f + 3, 127) >> 3;
1551 
1552  dst[strideb * -1] = av_clip_uint8(p0 + f2);
1553  dst[strideb * +0] = av_clip_uint8(q0 - f1);
1554  } else {
1555  int f = av_clip_int8(3 * (q0 - p0)), f1, f2;
1556 
1557  f1 = FFMIN(f + 4, 127) >> 3;
1558  f2 = FFMIN(f + 3, 127) >> 3;
1559 
1560  dst[strideb * -1] = av_clip_uint8(p0 + f2);
1561  dst[strideb * +0] = av_clip_uint8(q0 - f1);
1562 
1563  f = (f1 + 1) >> 1;
1564  dst[strideb * -2] = av_clip_uint8(p1 + f);
1565  dst[strideb * +1] = av_clip_uint8(q1 - f);
1566  }
1567  }
1568  }
1569 }
1570 
1571 #define lf_8_fn(dir, wd, stridea, strideb) \
1572 static void loop_filter_##dir##_##wd##_8_c(uint8_t *dst, \
1573  ptrdiff_t stride, \
1574  int E, int I, int H) \
1575 { \
1576  loop_filter(dst, stride, E, I, H, stridea, strideb, wd); \
1577 }
1578 
1579 #define lf_8_fns(wd) \
1580 lf_8_fn(h, wd, stride, 1) \
1581 lf_8_fn(v, wd, 1, stride)
1582 
1584 lf_8_fns(8)
1585 lf_8_fns(16)
1586 
1587 #undef lf_8_fn
1588 #undef lf_8_fns
1589 
1590 #define lf_16_fn(dir, stridea) \
1591 static void loop_filter_##dir##_16_16_c(uint8_t *dst, \
1592  ptrdiff_t stride, \
1593  int E, int I, int H) \
1594 { \
1595  loop_filter_##dir##_16_8_c(dst, stride, E, I, H); \
1596  loop_filter_##dir##_16_8_c(dst + 8 * stridea, stride, E, I, H); \
1597 }
1598 
1599 lf_16_fn(h, stride)
1600 lf_16_fn(v, 1)
1601 
1602 #undef lf_16_fn
1603 
1604 #define lf_mix_fn(dir, wd1, wd2, stridea) \
1605 static void loop_filter_##dir##_##wd1##wd2##_16_c(uint8_t *dst, \
1606  ptrdiff_t stride, \
1607  int E, int I, int H) \
1608 { \
1609  loop_filter_##dir##_##wd1##_8_c(dst, stride, E & 0xff, I & 0xff, H & 0xff); \
1610  loop_filter_##dir##_##wd2##_8_c(dst + 8 * stridea, stride, E >> 8, I >> 8, H >> 8); \
1611 }
1612 
1613 #define lf_mix_fns(wd1, wd2) \
1614 lf_mix_fn(h, wd1, wd2, stride) \
1615 lf_mix_fn(v, wd1, wd2, 1)
1616 
1617 lf_mix_fns(4, 4)
1618 lf_mix_fns(4, 8)
1619 lf_mix_fns(8, 4)
1620 lf_mix_fns(8, 8)
1621 
1622 #undef lf_mix_fn
1623 #undef lf_mix_fns
1624 
1625 static av_cold void vp9dsp_loopfilter_init(VP9DSPContext *dsp)
1626 {
1627  dsp->loop_filter_8[0][0] = loop_filter_h_4_8_c;
1628  dsp->loop_filter_8[0][1] = loop_filter_v_4_8_c;
1629  dsp->loop_filter_8[1][0] = loop_filter_h_8_8_c;
1630  dsp->loop_filter_8[1][1] = loop_filter_v_8_8_c;
1631  dsp->loop_filter_8[2][0] = loop_filter_h_16_8_c;
1632  dsp->loop_filter_8[2][1] = loop_filter_v_16_8_c;
1633 
1634  dsp->loop_filter_16[0] = loop_filter_h_16_16_c;
1635  dsp->loop_filter_16[1] = loop_filter_v_16_16_c;
1636 
1637  dsp->loop_filter_mix2[0][0][0] = loop_filter_h_44_16_c;
1638  dsp->loop_filter_mix2[0][0][1] = loop_filter_v_44_16_c;
1639  dsp->loop_filter_mix2[0][1][0] = loop_filter_h_48_16_c;
1640  dsp->loop_filter_mix2[0][1][1] = loop_filter_v_48_16_c;
1641  dsp->loop_filter_mix2[1][0][0] = loop_filter_h_84_16_c;
1642  dsp->loop_filter_mix2[1][0][1] = loop_filter_v_84_16_c;
1643  dsp->loop_filter_mix2[1][1][0] = loop_filter_h_88_16_c;
1644  dsp->loop_filter_mix2[1][1][1] = loop_filter_v_88_16_c;
1645 }
1646 
1647 static av_always_inline void copy_c(uint8_t *dst, ptrdiff_t dst_stride,
1648  const uint8_t *src, ptrdiff_t src_stride,
1649  int w, int h)
1650 {
1651  do {
1652  memcpy(dst, src, w);
1653 
1654  dst += dst_stride;
1655  src += src_stride;
1656  } while (--h);
1657 }
1658 
1659 static av_always_inline void avg_c(uint8_t *dst, ptrdiff_t dst_stride,
1660  const uint8_t *src, ptrdiff_t src_stride,
1661  int w, int h)
1662 {
1663  do {
1664  int x;
1665 
1666  for (x = 0; x < w; x += 4)
1667  AV_WN32A(&dst[x], rnd_avg32(AV_RN32A(&dst[x]), AV_RN32(&src[x])));
1668 
1669  dst += dst_stride;
1670  src += src_stride;
1671  } while (--h);
1672 }
1673 
1674 #define fpel_fn(type, sz) \
1675 static void type##sz##_c(uint8_t *dst, ptrdiff_t dst_stride, \
1676  const uint8_t *src, ptrdiff_t src_stride, \
1677  int h, int mx, int my) \
1678 { \
1679  type##_c(dst, dst_stride, src, src_stride, sz, h); \
1680 }
1681 
1682 #define copy_avg_fn(sz) \
1683 fpel_fn(copy, sz) \
1684 fpel_fn(avg, sz)
1685 
1687 copy_avg_fn(32)
1688 copy_avg_fn(16)
1689 copy_avg_fn(8)
1690 copy_avg_fn(4)
1691 
1692 #undef fpel_fn
1693 #undef copy_avg_fn
1694 
1695 static const int8_t vp9_subpel_filters[3][15][8] = {
1696  [FILTER_8TAP_REGULAR] = {
1697  { 0, 1, -5, 126, 8, -3, 1, 0 },
1698  { -1, 3, -10, 122, 18, -6, 2, 0 },
1699  { -1, 4, -13, 118, 27, -9, 3, -1 },
1700  { -1, 4, -16, 112, 37, -11, 4, -1 },
1701  { -1, 5, -18, 105, 48, -14, 4, -1 },
1702  { -1, 5, -19, 97, 58, -16, 5, -1 },
1703  { -1, 6, -19, 88, 68, -18, 5, -1 },
1704  { -1, 6, -19, 78, 78, -19, 6, -1 },
1705  { -1, 5, -18, 68, 88, -19, 6, -1 },
1706  { -1, 5, -16, 58, 97, -19, 5, -1 },
1707  { -1, 4, -14, 48, 105, -18, 5, -1 },
1708  { -1, 4, -11, 37, 112, -16, 4, -1 },
1709  { -1, 3, -9, 27, 118, -13, 4, -1 },
1710  { 0, 2, -6, 18, 122, -10, 3, -1 },
1711  { 0, 1, -3, 8, 126, -5, 1, 0 },
1712  }, [FILTER_8TAP_SHARP] = {
1713  { -1, 3, -7, 127, 8, -3, 1, 0 },
1714  { -2, 5, -13, 125, 17, -6, 3, -1 },
1715  { -3, 7, -17, 121, 27, -10, 5, -2 },
1716  { -4, 9, -20, 115, 37, -13, 6, -2 },
1717  { -4, 10, -23, 108, 48, -16, 8, -3 },
1718  { -4, 10, -24, 100, 59, -19, 9, -3 },
1719  { -4, 11, -24, 90, 70, -21, 10, -4 },
1720  { -4, 11, -23, 80, 80, -23, 11, -4 },
1721  { -4, 10, -21, 70, 90, -24, 11, -4 },
1722  { -3, 9, -19, 59, 100, -24, 10, -4 },
1723  { -3, 8, -16, 48, 108, -23, 10, -4 },
1724  { -2, 6, -13, 37, 115, -20, 9, -4 },
1725  { -2, 5, -10, 27, 121, -17, 7, -3 },
1726  { -1, 3, -6, 17, 125, -13, 5, -2 },
1727  { 0, 1, -3, 8, 127, -7, 3, -1 },
1728  }, [FILTER_8TAP_SMOOTH] = {
1729  { -3, -1, 32, 64, 38, 1, -3, 0 },
1730  { -2, -2, 29, 63, 41, 2, -3, 0 },
1731  { -2, -2, 26, 63, 43, 4, -4, 0 },
1732  { -2, -3, 24, 62, 46, 5, -4, 0 },
1733  { -2, -3, 21, 60, 49, 7, -4, 0 },
1734  { -1, -4, 18, 59, 51, 9, -4, 0 },
1735  { -1, -4, 16, 57, 53, 12, -4, -1 },
1736  { -1, -4, 14, 55, 55, 14, -4, -1 },
1737  { -1, -4, 12, 53, 57, 16, -4, -1 },
1738  { 0, -4, 9, 51, 59, 18, -4, -1 },
1739  { 0, -4, 7, 49, 60, 21, -3, -2 },
1740  { 0, -4, 5, 46, 62, 24, -3, -2 },
1741  { 0, -4, 4, 43, 63, 26, -2, -2 },
1742  { 0, -3, 2, 41, 63, 29, -2, -2 },
1743  { 0, -3, 1, 38, 64, 32, -1, -3 },
1744  }
1745 };
1746 
1747 #define FILTER_8TAP(src, x, F, stride) \
1748  av_clip_uint8((F[0] * src[x + -3 * stride] + \
1749  F[1] * src[x + -2 * stride] + \
1750  F[2] * src[x + -1 * stride] + \
1751  F[3] * src[x + +0 * stride] + \
1752  F[4] * src[x + +1 * stride] + \
1753  F[5] * src[x + +2 * stride] + \
1754  F[6] * src[x + +3 * stride] + \
1755  F[7] * src[x + +4 * stride] + 64) >> 7)
1756 
1757 static av_always_inline void do_8tap_1d_c(uint8_t *dst, ptrdiff_t dst_stride,
1758  const uint8_t *src, ptrdiff_t src_stride,
1759  int w, int h, ptrdiff_t ds,
1760  const int8_t *filter, int avg)
1761 {
1762  do {
1763  int x;
1764 
1765  for (x = 0; x < w; x++)
1766  if (avg) {
1767  dst[x] = (dst[x] + FILTER_8TAP(src, x, filter, ds) + 1) >> 1;
1768  } else {
1769  dst[x] = FILTER_8TAP(src, x, filter, ds);
1770  }
1771 
1772  dst += dst_stride;
1773  src += src_stride;
1774  } while (--h);
1775 }
1776 
1777 #define filter_8tap_1d_fn(opn, opa, dir, ds) \
1778 static av_noinline void opn##_8tap_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
1779  const uint8_t *src, ptrdiff_t src_stride, \
1780  int w, int h, const int8_t *filter) \
1781 { \
1782  do_8tap_1d_c(dst, dst_stride, src, src_stride, w, h, ds, filter, opa); \
1783 }
1784 
1785 filter_8tap_1d_fn(put, 0, v, src_stride)
1786 filter_8tap_1d_fn(put, 0, h, 1)
1787 filter_8tap_1d_fn(avg, 1, v, src_stride)
1788 filter_8tap_1d_fn(avg, 1, h, 1)
1789 
1790 #undef filter_8tap_1d_fn
1791 
1792 static av_always_inline void do_8tap_2d_c(uint8_t *dst, ptrdiff_t dst_stride,
1793  const uint8_t *src, ptrdiff_t src_stride,
1794  int w, int h, const int8_t *filterx,
1795  const int8_t *filtery, int avg)
1796 {
1797  int tmp_h = h + 7;
1798  uint8_t tmp[64 * 71], *tmp_ptr = tmp;
1799 
1800  src -= src_stride * 3;
1801  do {
1802  int x;
1803 
1804  for (x = 0; x < w; x++)
1805  tmp_ptr[x] = FILTER_8TAP(src, x, filterx, 1);
1806 
1807  tmp_ptr += 64;
1808  src += src_stride;
1809  } while (--tmp_h);
1810 
1811  tmp_ptr = tmp + 64 * 3;
1812  do {
1813  int x;
1814 
1815  for (x = 0; x < w; x++)
1816  if (avg) {
1817  dst[x] = (dst[x] + FILTER_8TAP(tmp_ptr, x, filtery, 64) + 1) >> 1;
1818  } else {
1819  dst[x] = FILTER_8TAP(tmp_ptr, x, filtery, 64);
1820  }
1821 
1822  tmp_ptr += 64;
1823  dst += dst_stride;
1824  } while (--h);
1825 }
1826 
1827 #define filter_8tap_2d_fn(opn, opa) \
1828 static av_noinline void opn##_8tap_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
1829  const uint8_t *src, ptrdiff_t src_stride, \
1830  int w, int h, const int8_t *filterx, \
1831  const int8_t *filtery) \
1832 { \
1833  do_8tap_2d_c(dst, dst_stride, src, src_stride, w, h, filterx, filtery, opa); \
1834 }
1835 
1837 filter_8tap_2d_fn(avg, 1)
1838 
1839 #undef filter_8tap_2d_fn
1840 
1841 #undef FILTER_8TAP
1842 
1843 #define filter_fn_1d(sz, dir, dir_m, type, type_idx, avg) \
1844 static void avg##_8tap_##type##_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
1845  const uint8_t *src, ptrdiff_t src_stride, \
1846  int h, int mx, int my) \
1847 { \
1848  avg##_8tap_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, \
1849  vp9_subpel_filters[type_idx][dir_m - 1]); \
1850 }
1851 
1852 #define filter_fn_2d(sz, type, type_idx, avg) \
1853 static void avg##_8tap_##type##_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
1854  const uint8_t *src, ptrdiff_t src_stride, \
1855  int h, int mx, int my) \
1856 { \
1857  avg##_8tap_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, \
1858  vp9_subpel_filters[type_idx][mx - 1], \
1859  vp9_subpel_filters[type_idx][my - 1]); \
1860 }
1861 
1862 #define FILTER_BILIN(src, x, mxy, stride) \
1863  (src[x] + ((mxy * (src[x + stride] - src[x]) + 8) >> 4))
1864 
1865 static av_always_inline void do_bilin_1d_c(uint8_t *dst, ptrdiff_t dst_stride,
1866  const uint8_t *src, ptrdiff_t src_stride,
1867  int w, int h, ptrdiff_t ds, int mxy, int avg)
1868 {
1869  do {
1870  int x;
1871 
1872  for (x = 0; x < w; x++)
1873  if (avg) {
1874  dst[x] = (dst[x] + FILTER_BILIN(src, x, mxy, ds) + 1) >> 1;
1875  } else {
1876  dst[x] = FILTER_BILIN(src, x, mxy, ds);
1877  }
1878 
1879  dst += dst_stride;
1880  src += src_stride;
1881  } while (--h);
1882 }
1883 
1884 #define bilin_1d_fn(opn, opa, dir, ds) \
1885 static av_noinline void opn##_bilin_1d_##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
1886  const uint8_t *src, ptrdiff_t src_stride, \
1887  int w, int h, int mxy) \
1888 { \
1889  do_bilin_1d_c(dst, dst_stride, src, src_stride, w, h, ds, mxy, opa); \
1890 }
1891 
1892 bilin_1d_fn(put, 0, v, src_stride)
1893 bilin_1d_fn(put, 0, h, 1)
1894 bilin_1d_fn(avg, 1, v, src_stride)
1895 bilin_1d_fn(avg, 1, h, 1)
1896 
1897 #undef bilin_1d_fn
1898 
1899 static av_always_inline void do_bilin_2d_c(uint8_t *dst, ptrdiff_t dst_stride,
1900  const uint8_t *src, ptrdiff_t src_stride,
1901  int w, int h, int mx, int my, int avg)
1902 {
1903  uint8_t tmp[64 * 65], *tmp_ptr = tmp;
1904  int tmp_h = h + 1;
1905 
1906  do {
1907  int x;
1908 
1909  for (x = 0; x < w; x++)
1910  tmp_ptr[x] = FILTER_BILIN(src, x, mx, 1);
1911 
1912  tmp_ptr += 64;
1913  src += src_stride;
1914  } while (--tmp_h);
1915 
1916  tmp_ptr = tmp;
1917  do {
1918  int x;
1919 
1920  for (x = 0; x < w; x++)
1921  if (avg) {
1922  dst[x] = (dst[x] + FILTER_BILIN(tmp_ptr, x, my, 64) + 1) >> 1;
1923  } else {
1924  dst[x] = FILTER_BILIN(tmp_ptr, x, my, 64);
1925  }
1926 
1927  tmp_ptr += 64;
1928  dst += dst_stride;
1929  } while (--h);
1930 }
1931 
1932 #define bilin_2d_fn(opn, opa) \
1933 static av_noinline void opn##_bilin_2d_hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
1934  const uint8_t *src, ptrdiff_t src_stride, \
1935  int w, int h, int mx, int my) \
1936 { \
1937  do_bilin_2d_c(dst, dst_stride, src, src_stride, w, h, mx, my, opa); \
1938 }
1939 
1941 bilin_2d_fn(avg, 1)
1942 
1943 #undef bilin_2d_fn
1944 
1945 #undef FILTER_BILIN
1946 
1947 #define bilinf_fn_1d(sz, dir, dir_m, avg) \
1948 static void avg##_bilin_##sz##dir##_c(uint8_t *dst, ptrdiff_t dst_stride, \
1949  const uint8_t *src, ptrdiff_t src_stride, \
1950  int h, int mx, int my) \
1951 { \
1952  avg##_bilin_1d_##dir##_c(dst, dst_stride, src, src_stride, sz, h, dir_m); \
1953 }
1954 
1955 #define bilinf_fn_2d(sz, avg) \
1956 static void avg##_bilin_##sz##hv_c(uint8_t *dst, ptrdiff_t dst_stride, \
1957  const uint8_t *src, ptrdiff_t src_stride, \
1958  int h, int mx, int my) \
1959 { \
1960  avg##_bilin_2d_hv_c(dst, dst_stride, src, src_stride, sz, h, mx, my); \
1961 }
1962 
1963 #define filter_fn(sz, avg) \
1964 filter_fn_1d(sz, h, mx, regular, FILTER_8TAP_REGULAR, avg) \
1965 filter_fn_1d(sz, v, my, regular, FILTER_8TAP_REGULAR, avg) \
1966 filter_fn_2d(sz, regular, FILTER_8TAP_REGULAR, avg) \
1967 filter_fn_1d(sz, h, mx, smooth, FILTER_8TAP_SMOOTH, avg) \
1968 filter_fn_1d(sz, v, my, smooth, FILTER_8TAP_SMOOTH, avg) \
1969 filter_fn_2d(sz, smooth, FILTER_8TAP_SMOOTH, avg) \
1970 filter_fn_1d(sz, h, mx, sharp, FILTER_8TAP_SHARP, avg) \
1971 filter_fn_1d(sz, v, my, sharp, FILTER_8TAP_SHARP, avg) \
1972 filter_fn_2d(sz, sharp, FILTER_8TAP_SHARP, avg) \
1973 bilinf_fn_1d(sz, h, mx, avg) \
1974 bilinf_fn_1d(sz, v, my, avg) \
1975 bilinf_fn_2d(sz, avg)
1976 
1977 #define filter_fn_set(avg) \
1978 filter_fn(64, avg) \
1979 filter_fn(32, avg) \
1980 filter_fn(16, avg) \
1981 filter_fn(8, avg) \
1982 filter_fn(4, avg)
1983 
1984 filter_fn_set(put)
1985 filter_fn_set(avg)
1986 
1987 #undef filter_fn
1988 #undef filter_fn_set
1989 #undef filter_fn_1d
1990 #undef filter_fn_2d
1991 #undef bilinf_fn_1d
1992 #undef bilinf_fn_2d
1993 
1994 static av_cold void vp9dsp_mc_init(VP9DSPContext *dsp)
1995 {
1996 #define init_fpel(idx1, idx2, sz, type) \
1997  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][0][0] = type##sz##_c; \
1998  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][0][0] = type##sz##_c; \
1999  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][0][0] = type##sz##_c; \
2000  dsp->mc[idx1][FILTER_BILINEAR ][idx2][0][0] = type##sz##_c
2001 
2002 #define init_copy_avg(idx, sz) \
2003  init_fpel(idx, 0, sz, copy); \
2004  init_fpel(idx, 1, sz, avg)
2005 
2006  init_copy_avg(0, 64);
2007  init_copy_avg(1, 32);
2008  init_copy_avg(2, 16);
2009  init_copy_avg(3, 8);
2010  init_copy_avg(4, 4);
2011 
2012 #undef init_copy_avg
2013 #undef init_fpel
2014 
2015 #define init_subpel1(idx1, idx2, idxh, idxv, sz, dir, type) \
2016  dsp->mc[idx1][FILTER_8TAP_SMOOTH ][idx2][idxh][idxv] = type##_8tap_smooth_##sz##dir##_c; \
2017  dsp->mc[idx1][FILTER_8TAP_REGULAR][idx2][idxh][idxv] = type##_8tap_regular_##sz##dir##_c; \
2018  dsp->mc[idx1][FILTER_8TAP_SHARP ][idx2][idxh][idxv] = type##_8tap_sharp_##sz##dir##_c; \
2019  dsp->mc[idx1][FILTER_BILINEAR ][idx2][idxh][idxv] = type##_bilin_##sz##dir##_c
2020 
2021 #define init_subpel2(idx, idxh, idxv, dir, type) \
2022  init_subpel1(0, idx, idxh, idxv, 64, dir, type); \
2023  init_subpel1(1, idx, idxh, idxv, 32, dir, type); \
2024  init_subpel1(2, idx, idxh, idxv, 16, dir, type); \
2025  init_subpel1(3, idx, idxh, idxv, 8, dir, type); \
2026  init_subpel1(4, idx, idxh, idxv, 4, dir, type)
2027 
2028 #define init_subpel3(idx, type) \
2029  init_subpel2(idx, 1, 1, hv, type); \
2030  init_subpel2(idx, 0, 1, v, type); \
2031  init_subpel2(idx, 1, 0, h, type)
2032 
2033  init_subpel3(0, put);
2034  init_subpel3(1, avg);
2035 
2036 #undef init_subpel1
2037 #undef init_subpel2
2038 #undef init_subpel3
2039 }
2040 
2042 {
2043  vp9dsp_intrapred_init(dsp);
2044  vp9dsp_itxfm_init(dsp);
2045  vp9dsp_loopfilter_init(dsp);
2046  vp9dsp_mc_init(dsp);
2047 
2048  if (ARCH_X86) ff_vp9dsp_init_x86(dsp);
2049 }