Rename tpel_template.c ---> pel_template.c
[ffmpeg.git] / libavcodec / qpeldsp.c
1 /*
2  * quarterpel DSP functions
3  *
4  * This file is part of Libav.
5  *
6  * Libav is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * Libav is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 /**
22  * @file
23  * quarterpel DSP functions
24  */
25
26 #include <stddef.h>
27 #include <stdint.h>
28
29 #include "config.h"
30 #include "libavutil/attributes.h"
31 #include "copy_block.h"
32 #include "qpeldsp.h"
33
34 #define BIT_DEPTH 8
35 #include "hpel_template.c"
36 #include "pel_template.c"
37 #include "qpel_template.c"
38
39 #define QPEL_MC(r, OPNAME, RND, OP)                                           \
40 static void OPNAME ## mpeg4_qpel8_h_lowpass(uint8_t *dst, uint8_t *src,       \
41                                             int dstStride, int srcStride,     \
42                                             int h)                            \
43 {                                                                             \
44     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;                           \
45     int i;                                                                    \
46                                                                               \
47     for (i = 0; i < h; i++) {                                                 \
48         OP(dst[0], (src[0] + src[1]) * 20 - (src[0] + src[2]) * 6 + (src[1] + src[3]) * 3 - (src[2] + src[4])); \
49         OP(dst[1], (src[1] + src[2]) * 20 - (src[0] + src[3]) * 6 + (src[0] + src[4]) * 3 - (src[1] + src[5])); \
50         OP(dst[2], (src[2] + src[3]) * 20 - (src[1] + src[4]) * 6 + (src[0] + src[5]) * 3 - (src[0] + src[6])); \
51         OP(dst[3], (src[3] + src[4]) * 20 - (src[2] + src[5]) * 6 + (src[1] + src[6]) * 3 - (src[0] + src[7])); \
52         OP(dst[4], (src[4] + src[5]) * 20 - (src[3] + src[6]) * 6 + (src[2] + src[7]) * 3 - (src[1] + src[8])); \
53         OP(dst[5], (src[5] + src[6]) * 20 - (src[4] + src[7]) * 6 + (src[3] + src[8]) * 3 - (src[2] + src[8])); \
54         OP(dst[6], (src[6] + src[7]) * 20 - (src[5] + src[8]) * 6 + (src[4] + src[8]) * 3 - (src[3] + src[7])); \
55         OP(dst[7], (src[7] + src[8]) * 20 - (src[6] + src[8]) * 6 + (src[5] + src[7]) * 3 - (src[4] + src[6])); \
56         dst += dstStride;                                                     \
57         src += srcStride;                                                     \
58     }                                                                         \
59 }                                                                             \
60                                                                               \
61 static void OPNAME ## mpeg4_qpel8_v_lowpass(uint8_t *dst, uint8_t *src,       \
62                                             int dstStride, int srcStride)     \
63 {                                                                             \
64     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;                           \
65     const int w = 8;                                                          \
66     int i;                                                                    \
67                                                                               \
68     for (i = 0; i < w; i++) {                                                 \
69         const int src0 = src[0 * srcStride];                                  \
70         const int src1 = src[1 * srcStride];                                  \
71         const int src2 = src[2 * srcStride];                                  \
72         const int src3 = src[3 * srcStride];                                  \
73         const int src4 = src[4 * srcStride];                                  \
74         const int src5 = src[5 * srcStride];                                  \
75         const int src6 = src[6 * srcStride];                                  \
76         const int src7 = src[7 * srcStride];                                  \
77         const int src8 = src[8 * srcStride];                                  \
78         OP(dst[0 * dstStride], (src0 + src1) * 20 - (src0 + src2) * 6 + (src1 + src3) * 3 - (src2 + src4)); \
79         OP(dst[1 * dstStride], (src1 + src2) * 20 - (src0 + src3) * 6 + (src0 + src4) * 3 - (src1 + src5)); \
80         OP(dst[2 * dstStride], (src2 + src3) * 20 - (src1 + src4) * 6 + (src0 + src5) * 3 - (src0 + src6)); \
81         OP(dst[3 * dstStride], (src3 + src4) * 20 - (src2 + src5) * 6 + (src1 + src6) * 3 - (src0 + src7)); \
82         OP(dst[4 * dstStride], (src4 + src5) * 20 - (src3 + src6) * 6 + (src2 + src7) * 3 - (src1 + src8)); \
83         OP(dst[5 * dstStride], (src5 + src6) * 20 - (src4 + src7) * 6 + (src3 + src8) * 3 - (src2 + src8)); \
84         OP(dst[6 * dstStride], (src6 + src7) * 20 - (src5 + src8) * 6 + (src4 + src8) * 3 - (src3 + src7)); \
85         OP(dst[7 * dstStride], (src7 + src8) * 20 - (src6 + src8) * 6 + (src5 + src7) * 3 - (src4 + src6)); \
86         dst++;                                                                \
87         src++;                                                                \
88     }                                                                         \
89 }                                                                             \
90                                                                               \
91 static void OPNAME ## mpeg4_qpel16_h_lowpass(uint8_t *dst, uint8_t *src,      \
92                                              int dstStride, int srcStride,    \
93                                              int h)                           \
94 {                                                                             \
95     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;                           \
96     int i;                                                                    \
97                                                                               \
98     for (i = 0; i < h; i++) {                                                 \
99         OP(dst[0],  (src[0]  + src[1])  * 20 - (src[0]  + src[2])  * 6 + (src[1]  + src[3])  * 3 - (src[2]  + src[4]));  \
100         OP(dst[1],  (src[1]  + src[2])  * 20 - (src[0]  + src[3])  * 6 + (src[0]  + src[4])  * 3 - (src[1]  + src[5]));  \
101         OP(dst[2],  (src[2]  + src[3])  * 20 - (src[1]  + src[4])  * 6 + (src[0]  + src[5])  * 3 - (src[0]  + src[6]));  \
102         OP(dst[3],  (src[3]  + src[4])  * 20 - (src[2]  + src[5])  * 6 + (src[1]  + src[6])  * 3 - (src[0]  + src[7]));  \
103         OP(dst[4],  (src[4]  + src[5])  * 20 - (src[3]  + src[6])  * 6 + (src[2]  + src[7])  * 3 - (src[1]  + src[8]));  \
104         OP(dst[5],  (src[5]  + src[6])  * 20 - (src[4]  + src[7])  * 6 + (src[3]  + src[8])  * 3 - (src[2]  + src[9]));  \
105         OP(dst[6],  (src[6]  + src[7])  * 20 - (src[5]  + src[8])  * 6 + (src[4]  + src[9])  * 3 - (src[3]  + src[10])); \
106         OP(dst[7],  (src[7]  + src[8])  * 20 - (src[6]  + src[9])  * 6 + (src[5]  + src[10]) * 3 - (src[4]  + src[11])); \
107         OP(dst[8],  (src[8]  + src[9])  * 20 - (src[7]  + src[10]) * 6 + (src[6]  + src[11]) * 3 - (src[5]  + src[12])); \
108         OP(dst[9],  (src[9]  + src[10]) * 20 - (src[8]  + src[11]) * 6 + (src[7]  + src[12]) * 3 - (src[6]  + src[13])); \
109         OP(dst[10], (src[10] + src[11]) * 20 - (src[9]  + src[12]) * 6 + (src[8]  + src[13]) * 3 - (src[7]  + src[14])); \
110         OP(dst[11], (src[11] + src[12]) * 20 - (src[10] + src[13]) * 6 + (src[9]  + src[14]) * 3 - (src[8]  + src[15])); \
111         OP(dst[12], (src[12] + src[13]) * 20 - (src[11] + src[14]) * 6 + (src[10] + src[15]) * 3 - (src[9]  + src[16])); \
112         OP(dst[13], (src[13] + src[14]) * 20 - (src[12] + src[15]) * 6 + (src[11] + src[16]) * 3 - (src[10] + src[16])); \
113         OP(dst[14], (src[14] + src[15]) * 20 - (src[13] + src[16]) * 6 + (src[12] + src[16]) * 3 - (src[11] + src[15])); \
114         OP(dst[15], (src[15] + src[16]) * 20 - (src[14] + src[16]) * 6 + (src[13] + src[15]) * 3 - (src[12] + src[14])); \
115         dst += dstStride;                                                     \
116         src += srcStride;                                                     \
117     }                                                                         \
118 }                                                                             \
119                                                                               \
120 static void OPNAME ## mpeg4_qpel16_v_lowpass(uint8_t *dst, uint8_t *src,      \
121                                              int dstStride, int srcStride)    \
122 {                                                                             \
123     const uint8_t *cm = ff_crop_tab + MAX_NEG_CROP;                           \
124     const int w = 16;                                                         \
125     int i;                                                                    \
126                                                                               \
127     for (i = 0; i < w; i++) {                                                 \
128         const int src0  = src[0  * srcStride];                                \
129         const int src1  = src[1  * srcStride];                                \
130         const int src2  = src[2  * srcStride];                                \
131         const int src3  = src[3  * srcStride];                                \
132         const int src4  = src[4  * srcStride];                                \
133         const int src5  = src[5  * srcStride];                                \
134         const int src6  = src[6  * srcStride];                                \
135         const int src7  = src[7  * srcStride];                                \
136         const int src8  = src[8  * srcStride];                                \
137         const int src9  = src[9  * srcStride];                                \
138         const int src10 = src[10 * srcStride];                                \
139         const int src11 = src[11 * srcStride];                                \
140         const int src12 = src[12 * srcStride];                                \
141         const int src13 = src[13 * srcStride];                                \
142         const int src14 = src[14 * srcStride];                                \
143         const int src15 = src[15 * srcStride];                                \
144         const int src16 = src[16 * srcStride];                                \
145         OP(dst[0  * dstStride], (src0  + src1)  * 20 - (src0  + src2)  * 6 + (src1  + src3)  * 3 - (src2  + src4));  \
146         OP(dst[1  * dstStride], (src1  + src2)  * 20 - (src0  + src3)  * 6 + (src0  + src4)  * 3 - (src1  + src5));  \
147         OP(dst[2  * dstStride], (src2  + src3)  * 20 - (src1  + src4)  * 6 + (src0  + src5)  * 3 - (src0  + src6));  \
148         OP(dst[3  * dstStride], (src3  + src4)  * 20 - (src2  + src5)  * 6 + (src1  + src6)  * 3 - (src0  + src7));  \
149         OP(dst[4  * dstStride], (src4  + src5)  * 20 - (src3  + src6)  * 6 + (src2  + src7)  * 3 - (src1  + src8));  \
150         OP(dst[5  * dstStride], (src5  + src6)  * 20 - (src4  + src7)  * 6 + (src3  + src8)  * 3 - (src2  + src9));  \
151         OP(dst[6  * dstStride], (src6  + src7)  * 20 - (src5  + src8)  * 6 + (src4  + src9)  * 3 - (src3  + src10)); \
152         OP(dst[7  * dstStride], (src7  + src8)  * 20 - (src6  + src9)  * 6 + (src5  + src10) * 3 - (src4  + src11)); \
153         OP(dst[8  * dstStride], (src8  + src9)  * 20 - (src7  + src10) * 6 + (src6  + src11) * 3 - (src5  + src12)); \
154         OP(dst[9  * dstStride], (src9  + src10) * 20 - (src8  + src11) * 6 + (src7  + src12) * 3 - (src6  + src13)); \
155         OP(dst[10 * dstStride], (src10 + src11) * 20 - (src9  + src12) * 6 + (src8  + src13) * 3 - (src7  + src14)); \
156         OP(dst[11 * dstStride], (src11 + src12) * 20 - (src10 + src13) * 6 + (src9  + src14) * 3 - (src8  + src15)); \
157         OP(dst[12 * dstStride], (src12 + src13) * 20 - (src11 + src14) * 6 + (src10 + src15) * 3 - (src9  + src16)); \
158         OP(dst[13 * dstStride], (src13 + src14) * 20 - (src12 + src15) * 6 + (src11 + src16) * 3 - (src10 + src16)); \
159         OP(dst[14 * dstStride], (src14 + src15) * 20 - (src13 + src16) * 6 + (src12 + src16) * 3 - (src11 + src15)); \
160         OP(dst[15 * dstStride], (src15 + src16) * 20 - (src14 + src16) * 6 + (src13 + src15) * 3 - (src12 + src14)); \
161         dst++;                                                                \
162         src++;                                                                \
163     }                                                                         \
164 }                                                                             \
165                                                                               \
166 static void OPNAME ## qpel8_mc10_c(uint8_t *dst, uint8_t *src,                \
167                                    ptrdiff_t stride)                          \
168 {                                                                             \
169     uint8_t half[64];                                                         \
170                                                                               \
171     put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);             \
172     OPNAME ## pixels8_l2_8(dst, src, half, stride, stride, 8, 8);             \
173 }                                                                             \
174                                                                               \
175 static void OPNAME ## qpel8_mc20_c(uint8_t *dst, uint8_t *src,                \
176                                    ptrdiff_t stride)                          \
177 {                                                                             \
178     OPNAME ## mpeg4_qpel8_h_lowpass(dst, src, stride, stride, 8);             \
179 }                                                                             \
180                                                                               \
181 static void OPNAME ## qpel8_mc30_c(uint8_t *dst, uint8_t *src,                \
182                                    ptrdiff_t stride)                          \
183 {                                                                             \
184     uint8_t half[64];                                                         \
185                                                                               \
186     put ## RND ## mpeg4_qpel8_h_lowpass(half, src, 8, stride, 8);             \
187     OPNAME ## pixels8_l2_8(dst, src + 1, half, stride, stride, 8, 8);         \
188 }                                                                             \
189                                                                               \
190 static void OPNAME ## qpel8_mc01_c(uint8_t *dst, uint8_t *src,                \
191                                    ptrdiff_t stride)                          \
192 {                                                                             \
193     uint8_t full[16 * 9];                                                     \
194     uint8_t half[64];                                                         \
195                                                                               \
196     copy_block9(full, src, 16, stride, 9);                                    \
197     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
198     OPNAME ## pixels8_l2_8(dst, full, half, stride, 16, 8, 8);                \
199 }                                                                             \
200                                                                               \
201 static void OPNAME ## qpel8_mc02_c(uint8_t *dst, uint8_t *src,                \
202                                    ptrdiff_t stride)                          \
203 {                                                                             \
204     uint8_t full[16 * 9];                                                     \
205                                                                               \
206     copy_block9(full, src, 16, stride, 9);                                    \
207     OPNAME ## mpeg4_qpel8_v_lowpass(dst, full, stride, 16);                   \
208 }                                                                             \
209                                                                               \
210 static void OPNAME ## qpel8_mc03_c(uint8_t *dst, uint8_t *src,                \
211                                    ptrdiff_t stride)                          \
212 {                                                                             \
213     uint8_t full[16 * 9];                                                     \
214     uint8_t half[64];                                                         \
215                                                                               \
216     copy_block9(full, src, 16, stride, 9);                                    \
217     put ## RND ## mpeg4_qpel8_v_lowpass(half, full, 8, 16);                   \
218     OPNAME ## pixels8_l2_8(dst, full + 16, half, stride, 16, 8, 8);           \
219 }                                                                             \
220                                                                               \
221 void ff_ ## OPNAME ## qpel8_mc11_old_c(uint8_t *dst, uint8_t *src,            \
222                                        ptrdiff_t stride)                      \
223 {                                                                             \
224     uint8_t full[16 * 9];                                                     \
225     uint8_t halfH[72];                                                        \
226     uint8_t halfV[64];                                                        \
227     uint8_t halfHV[64];                                                       \
228                                                                               \
229     copy_block9(full, src, 16, stride, 9);                                    \
230     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
231     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);                  \
232     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
233     OPNAME ## pixels8_l4_8(dst, full, halfH, halfV, halfHV,                   \
234                            stride, 16, 8, 8, 8, 8);                           \
235 }                                                                             \
236                                                                               \
237 static void OPNAME ## qpel8_mc11_c(uint8_t *dst, uint8_t *src,                \
238                                    ptrdiff_t stride)                          \
239 {                                                                             \
240     uint8_t full[16 * 9];                                                     \
241     uint8_t halfH[72];                                                        \
242     uint8_t halfHV[64];                                                       \
243                                                                               \
244     copy_block9(full, src, 16, stride, 9);                                    \
245     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
246     put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);              \
247     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
248     OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);              \
249 }                                                                             \
250                                                                               \
251 void ff_ ## OPNAME ## qpel8_mc31_old_c(uint8_t *dst, uint8_t *src,            \
252                                        ptrdiff_t stride)                      \
253 {                                                                             \
254     uint8_t full[16 * 9];                                                     \
255     uint8_t halfH[72];                                                        \
256     uint8_t halfV[64];                                                        \
257     uint8_t halfHV[64];                                                       \
258                                                                               \
259     copy_block9(full, src, 16, stride, 9);                                    \
260     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
261     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full + 1, 8, 16);              \
262     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
263     OPNAME ## pixels8_l4_8(dst, full + 1, halfH, halfV, halfHV,               \
264                            stride, 16, 8, 8, 8, 8);                           \
265 }                                                                             \
266                                                                               \
267 static void OPNAME ## qpel8_mc31_c(uint8_t *dst, uint8_t *src,                \
268                                    ptrdiff_t stride)                          \
269 {                                                                             \
270     uint8_t full[16 * 9];                                                     \
271     uint8_t halfH[72];                                                        \
272     uint8_t halfHV[64];                                                       \
273                                                                               \
274     copy_block9(full, src, 16, stride, 9);                                    \
275     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
276     put ## RND ## pixels8_l2_8(halfH, halfH, full + 1, 8, 8, 16, 9);          \
277     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
278     OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);              \
279 }                                                                             \
280                                                                               \
281 void ff_ ## OPNAME ## qpel8_mc13_old_c(uint8_t *dst, uint8_t *src,            \
282                                        ptrdiff_t stride)                      \
283 {                                                                             \
284     uint8_t full[16 * 9];                                                     \
285     uint8_t halfH[72];                                                        \
286     uint8_t halfV[64];                                                        \
287     uint8_t halfHV[64];                                                       \
288                                                                               \
289     copy_block9(full, src, 16, stride, 9);                                    \
290     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
291     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);                  \
292     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
293     OPNAME ## pixels8_l4_8(dst, full + 16, halfH + 8, halfV, halfHV,          \
294                            stride, 16, 8, 8, 8, 8);                           \
295 }                                                                             \
296                                                                               \
297 static void OPNAME ## qpel8_mc13_c(uint8_t *dst, uint8_t *src,                \
298                                    ptrdiff_t stride)                          \
299 {                                                                             \
300     uint8_t full[16 * 9];                                                     \
301     uint8_t halfH[72];                                                        \
302     uint8_t halfHV[64];                                                       \
303                                                                               \
304     copy_block9(full, src, 16, stride, 9);                                    \
305     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
306     put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);              \
307     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
308     OPNAME ## pixels8_l2_8(dst, halfH + 8, halfHV, stride, 8, 8, 8);          \
309 }                                                                             \
310                                                                               \
311 void ff_ ## OPNAME ## qpel8_mc33_old_c(uint8_t *dst, uint8_t *src,            \
312                                        ptrdiff_t stride)                      \
313 {                                                                             \
314     uint8_t full[16 * 9];                                                     \
315     uint8_t halfH[72];                                                        \
316     uint8_t halfV[64];                                                        \
317     uint8_t halfHV[64];                                                       \
318                                                                               \
319     copy_block9(full, src, 16, stride, 9);                                    \
320     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
321     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full + 1, 8, 16);              \
322     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
323     OPNAME ## pixels8_l4_8(dst, full + 17, halfH + 8, halfV, halfHV,          \
324                            stride, 16, 8, 8, 8, 8);                           \
325 }                                                                             \
326                                                                               \
327 static void OPNAME ## qpel8_mc33_c(uint8_t *dst, uint8_t *src,                \
328                                    ptrdiff_t stride)                          \
329 {                                                                             \
330     uint8_t full[16 * 9];                                                     \
331     uint8_t halfH[72];                                                        \
332     uint8_t halfHV[64];                                                       \
333                                                                               \
334     copy_block9(full, src, 16, stride, 9);                                    \
335     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
336     put ## RND ## pixels8_l2_8(halfH, halfH, full + 1, 8, 8, 16, 9);          \
337     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
338     OPNAME ## pixels8_l2_8(dst, halfH + 8, halfHV, stride, 8, 8, 8);          \
339 }                                                                             \
340                                                                               \
341 static void OPNAME ## qpel8_mc21_c(uint8_t *dst, uint8_t *src,                \
342                                    ptrdiff_t stride)                          \
343 {                                                                             \
344     uint8_t halfH[72];                                                        \
345     uint8_t halfHV[64];                                                       \
346                                                                               \
347     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);            \
348     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
349     OPNAME ## pixels8_l2_8(dst, halfH, halfHV, stride, 8, 8, 8);              \
350 }                                                                             \
351                                                                               \
352 static void OPNAME ## qpel8_mc23_c(uint8_t *dst, uint8_t *src,                \
353                                    ptrdiff_t stride)                          \
354 {                                                                             \
355     uint8_t halfH[72];                                                        \
356     uint8_t halfHV[64];                                                       \
357                                                                               \
358     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);            \
359     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
360     OPNAME ## pixels8_l2_8(dst, halfH + 8, halfHV, stride, 8, 8, 8);          \
361 }                                                                             \
362                                                                               \
363 void ff_ ## OPNAME ## qpel8_mc12_old_c(uint8_t *dst, uint8_t *src,            \
364                                        ptrdiff_t stride)                      \
365 {                                                                             \
366     uint8_t full[16 * 9];                                                     \
367     uint8_t halfH[72];                                                        \
368     uint8_t halfV[64];                                                        \
369     uint8_t halfHV[64];                                                       \
370                                                                               \
371     copy_block9(full, src, 16, stride, 9);                                    \
372     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
373     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full, 8, 16);                  \
374     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
375     OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);              \
376 }                                                                             \
377                                                                               \
378 static void OPNAME ## qpel8_mc12_c(uint8_t *dst, uint8_t *src,                \
379                                    ptrdiff_t stride)                          \
380 {                                                                             \
381     uint8_t full[16 * 9];                                                     \
382     uint8_t halfH[72];                                                        \
383                                                                               \
384     copy_block9(full, src, 16, stride, 9);                                    \
385     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
386     put ## RND ## pixels8_l2_8(halfH, halfH, full, 8, 8, 16, 9);              \
387     OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);                   \
388 }                                                                             \
389                                                                               \
390 void ff_ ## OPNAME ## qpel8_mc32_old_c(uint8_t *dst, uint8_t *src,            \
391                                        ptrdiff_t stride)                      \
392 {                                                                             \
393     uint8_t full[16 * 9];                                                     \
394     uint8_t halfH[72];                                                        \
395     uint8_t halfV[64];                                                        \
396     uint8_t halfHV[64];                                                       \
397                                                                               \
398     copy_block9(full, src, 16, stride, 9);                                    \
399     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
400     put ## RND ## mpeg4_qpel8_v_lowpass(halfV, full + 1, 8, 16);              \
401     put ## RND ## mpeg4_qpel8_v_lowpass(halfHV, halfH, 8, 8);                 \
402     OPNAME ## pixels8_l2_8(dst, halfV, halfHV, stride, 8, 8, 8);              \
403 }                                                                             \
404                                                                               \
405 static void OPNAME ## qpel8_mc32_c(uint8_t *dst, uint8_t *src,                \
406                                    ptrdiff_t stride)                          \
407 {                                                                             \
408     uint8_t full[16 * 9];                                                     \
409     uint8_t halfH[72];                                                        \
410                                                                               \
411     copy_block9(full, src, 16, stride, 9);                                    \
412     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, full, 8, 16, 9);               \
413     put ## RND ## pixels8_l2_8(halfH, halfH, full + 1, 8, 8, 16, 9);          \
414     OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);                   \
415 }                                                                             \
416                                                                               \
417 static void OPNAME ## qpel8_mc22_c(uint8_t *dst, uint8_t *src,                \
418                                    ptrdiff_t stride)                          \
419 {                                                                             \
420     uint8_t halfH[72];                                                        \
421                                                                               \
422     put ## RND ## mpeg4_qpel8_h_lowpass(halfH, src, 8, stride, 9);            \
423     OPNAME ## mpeg4_qpel8_v_lowpass(dst, halfH, stride, 8);                   \
424 }                                                                             \
425                                                                               \
426 static void OPNAME ## qpel16_mc10_c(uint8_t *dst, uint8_t *src,               \
427                                     ptrdiff_t stride)                         \
428 {                                                                             \
429     uint8_t half[256];                                                        \
430                                                                               \
431     put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);          \
432     OPNAME ## pixels16_l2_8(dst, src, half, stride, stride, 16, 16);          \
433 }                                                                             \
434                                                                               \
435 static void OPNAME ## qpel16_mc20_c(uint8_t *dst, uint8_t *src,               \
436                                     ptrdiff_t stride)                         \
437 {                                                                             \
438     OPNAME ## mpeg4_qpel16_h_lowpass(dst, src, stride, stride, 16);           \
439 }                                                                             \
440                                                                               \
441 static void OPNAME ## qpel16_mc30_c(uint8_t *dst, uint8_t *src,               \
442                                     ptrdiff_t stride)                         \
443 {                                                                             \
444     uint8_t half[256];                                                        \
445                                                                               \
446     put ## RND ## mpeg4_qpel16_h_lowpass(half, src, 16, stride, 16);          \
447     OPNAME ## pixels16_l2_8(dst, src + 1, half, stride, stride, 16, 16);      \
448 }                                                                             \
449                                                                               \
450 static void OPNAME ## qpel16_mc01_c(uint8_t *dst, uint8_t *src,               \
451                                     ptrdiff_t stride)                         \
452 {                                                                             \
453     uint8_t full[24 * 17];                                                    \
454     uint8_t half[256];                                                        \
455                                                                               \
456     copy_block17(full, src, 24, stride, 17);                                  \
457     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
458     OPNAME ## pixels16_l2_8(dst, full, half, stride, 24, 16, 16);             \
459 }                                                                             \
460                                                                               \
461 static void OPNAME ## qpel16_mc02_c(uint8_t *dst, uint8_t *src,               \
462                                     ptrdiff_t stride)                         \
463 {                                                                             \
464     uint8_t full[24 * 17];                                                    \
465                                                                               \
466     copy_block17(full, src, 24, stride, 17);                                  \
467     OPNAME ## mpeg4_qpel16_v_lowpass(dst, full, stride, 24);                  \
468 }                                                                             \
469                                                                               \
470 static void OPNAME ## qpel16_mc03_c(uint8_t *dst, uint8_t *src,               \
471                                     ptrdiff_t stride)                         \
472 {                                                                             \
473     uint8_t full[24 * 17];                                                    \
474     uint8_t half[256];                                                        \
475                                                                               \
476     copy_block17(full, src, 24, stride, 17);                                  \
477     put ## RND ## mpeg4_qpel16_v_lowpass(half, full, 16, 24);                 \
478     OPNAME ## pixels16_l2_8(dst, full + 24, half, stride, 24, 16, 16);        \
479 }                                                                             \
480                                                                               \
481 void ff_ ## OPNAME ## qpel16_mc11_old_c(uint8_t *dst, uint8_t *src,           \
482                                         ptrdiff_t stride)                     \
483 {                                                                             \
484     uint8_t full[24 * 17];                                                    \
485     uint8_t halfH[272];                                                       \
486     uint8_t halfV[256];                                                       \
487     uint8_t halfHV[256];                                                      \
488                                                                               \
489     copy_block17(full, src, 24, stride, 17);                                  \
490     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
491     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);                \
492     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
493     OPNAME ## pixels16_l4_8(dst, full, halfH, halfV, halfHV,                  \
494                             stride, 24, 16, 16, 16, 16);                      \
495 }                                                                             \
496                                                                               \
497 static void OPNAME ## qpel16_mc11_c(uint8_t *dst, uint8_t *src,               \
498                                     ptrdiff_t stride)                         \
499 {                                                                             \
500     uint8_t full[24 * 17];                                                    \
501     uint8_t halfH[272];                                                       \
502     uint8_t halfHV[256];                                                      \
503                                                                               \
504     copy_block17(full, src, 24, stride, 17);                                  \
505     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
506     put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);          \
507     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
508     OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);          \
509 }                                                                             \
510                                                                               \
511 void ff_ ## OPNAME ## qpel16_mc31_old_c(uint8_t *dst, uint8_t *src,           \
512                                         ptrdiff_t stride)                     \
513 {                                                                             \
514     uint8_t full[24 * 17];                                                    \
515     uint8_t halfH[272];                                                       \
516     uint8_t halfV[256];                                                       \
517     uint8_t halfHV[256];                                                      \
518                                                                               \
519     copy_block17(full, src, 24, stride, 17);                                  \
520     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
521     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full + 1, 16, 24);            \
522     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
523     OPNAME ## pixels16_l4_8(dst, full + 1, halfH, halfV, halfHV,              \
524                             stride, 24, 16, 16, 16, 16);                      \
525 }                                                                             \
526                                                                               \
527 static void OPNAME ## qpel16_mc31_c(uint8_t *dst, uint8_t *src,               \
528                                     ptrdiff_t stride)                         \
529 {                                                                             \
530     uint8_t full[24 * 17];                                                    \
531     uint8_t halfH[272];                                                       \
532     uint8_t halfHV[256];                                                      \
533                                                                               \
534     copy_block17(full, src, 24, stride, 17);                                  \
535     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
536     put ## RND ## pixels16_l2_8(halfH, halfH, full + 1, 16, 16, 24, 17);      \
537     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
538     OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);          \
539 }                                                                             \
540                                                                               \
541 void ff_ ## OPNAME ## qpel16_mc13_old_c(uint8_t *dst, uint8_t *src,           \
542                                         ptrdiff_t stride)                     \
543 {                                                                             \
544     uint8_t full[24 * 17];                                                    \
545     uint8_t halfH[272];                                                       \
546     uint8_t halfV[256];                                                       \
547     uint8_t halfHV[256];                                                      \
548                                                                               \
549     copy_block17(full, src, 24, stride, 17);                                  \
550     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
551     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);                \
552     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
553     OPNAME ## pixels16_l4_8(dst, full + 24, halfH + 16, halfV, halfHV,        \
554                             stride, 24, 16, 16, 16, 16);                      \
555 }                                                                             \
556                                                                               \
557 static void OPNAME ## qpel16_mc13_c(uint8_t *dst, uint8_t *src,               \
558                                     ptrdiff_t stride)                         \
559 {                                                                             \
560     uint8_t full[24 * 17];                                                    \
561     uint8_t halfH[272];                                                       \
562     uint8_t halfHV[256];                                                      \
563                                                                               \
564     copy_block17(full, src, 24, stride, 17);                                  \
565     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
566     put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);          \
567     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
568     OPNAME ## pixels16_l2_8(dst, halfH + 16, halfHV, stride, 16, 16, 16);     \
569 }                                                                             \
570                                                                               \
571 void ff_ ## OPNAME ## qpel16_mc33_old_c(uint8_t *dst, uint8_t *src,           \
572                                         ptrdiff_t stride)                     \
573 {                                                                             \
574     uint8_t full[24 * 17];                                                    \
575     uint8_t halfH[272];                                                       \
576     uint8_t halfV[256];                                                       \
577     uint8_t halfHV[256];                                                      \
578                                                                               \
579     copy_block17(full, src, 24, stride, 17);                                  \
580     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
581     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full + 1, 16, 24);            \
582     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
583     OPNAME ## pixels16_l4_8(dst, full + 25, halfH + 16, halfV, halfHV,        \
584                             stride, 24, 16, 16, 16, 16);                      \
585 }                                                                             \
586                                                                               \
587 static void OPNAME ## qpel16_mc33_c(uint8_t *dst, uint8_t *src,               \
588                                     ptrdiff_t stride)                         \
589 {                                                                             \
590     uint8_t full[24 * 17];                                                    \
591     uint8_t halfH[272];                                                       \
592     uint8_t halfHV[256];                                                      \
593                                                                               \
594     copy_block17(full, src, 24, stride, 17);                                  \
595     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
596     put ## RND ## pixels16_l2_8(halfH, halfH, full + 1, 16, 16, 24, 17);      \
597     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
598     OPNAME ## pixels16_l2_8(dst, halfH + 16, halfHV, stride, 16, 16, 16);     \
599 }                                                                             \
600                                                                               \
601 static void OPNAME ## qpel16_mc21_c(uint8_t *dst, uint8_t *src,               \
602                                     ptrdiff_t stride)                         \
603 {                                                                             \
604     uint8_t halfH[272];                                                       \
605     uint8_t halfHV[256];                                                      \
606                                                                               \
607     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);         \
608     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
609     OPNAME ## pixels16_l2_8(dst, halfH, halfHV, stride, 16, 16, 16);          \
610 }                                                                             \
611                                                                               \
612 static void OPNAME ## qpel16_mc23_c(uint8_t *dst, uint8_t *src,               \
613                                     ptrdiff_t stride)                         \
614 {                                                                             \
615     uint8_t halfH[272];                                                       \
616     uint8_t halfHV[256];                                                      \
617                                                                               \
618     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);         \
619     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
620     OPNAME ## pixels16_l2_8(dst, halfH + 16, halfHV, stride, 16, 16, 16);     \
621 }                                                                             \
622                                                                               \
623 void ff_ ## OPNAME ## qpel16_mc12_old_c(uint8_t *dst, uint8_t *src,           \
624                                         ptrdiff_t stride)                     \
625 {                                                                             \
626     uint8_t full[24 * 17];                                                    \
627     uint8_t halfH[272];                                                       \
628     uint8_t halfV[256];                                                       \
629     uint8_t halfHV[256];                                                      \
630                                                                               \
631     copy_block17(full, src, 24, stride, 17);                                  \
632     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
633     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full, 16, 24);                \
634     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
635     OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);          \
636 }                                                                             \
637                                                                               \
638 static void OPNAME ## qpel16_mc12_c(uint8_t *dst, uint8_t *src,               \
639                                     ptrdiff_t stride)                         \
640 {                                                                             \
641     uint8_t full[24 * 17];                                                    \
642     uint8_t halfH[272];                                                       \
643                                                                               \
644     copy_block17(full, src, 24, stride, 17);                                  \
645     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
646     put ## RND ## pixels16_l2_8(halfH, halfH, full, 16, 16, 24, 17);          \
647     OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);                 \
648 }                                                                             \
649                                                                               \
650 void ff_ ## OPNAME ## qpel16_mc32_old_c(uint8_t *dst, uint8_t *src,           \
651                                         ptrdiff_t stride)                     \
652 {                                                                             \
653     uint8_t full[24 * 17];                                                    \
654     uint8_t halfH[272];                                                       \
655     uint8_t halfV[256];                                                       \
656     uint8_t halfHV[256];                                                      \
657                                                                               \
658     copy_block17(full, src, 24, stride, 17);                                  \
659     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
660     put ## RND ## mpeg4_qpel16_v_lowpass(halfV, full + 1, 16, 24);            \
661     put ## RND ## mpeg4_qpel16_v_lowpass(halfHV, halfH, 16, 16);              \
662     OPNAME ## pixels16_l2_8(dst, halfV, halfHV, stride, 16, 16, 16);          \
663 }                                                                             \
664                                                                               \
665 static void OPNAME ## qpel16_mc32_c(uint8_t *dst, uint8_t *src,               \
666                                     ptrdiff_t stride)                         \
667 {                                                                             \
668     uint8_t full[24 * 17];                                                    \
669     uint8_t halfH[272];                                                       \
670                                                                               \
671     copy_block17(full, src, 24, stride, 17);                                  \
672     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, full, 16, 24, 17);            \
673     put ## RND ## pixels16_l2_8(halfH, halfH, full + 1, 16, 16, 24, 17);      \
674     OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);                 \
675 }                                                                             \
676                                                                               \
677 static void OPNAME ## qpel16_mc22_c(uint8_t *dst, uint8_t *src,               \
678                                     ptrdiff_t stride)                         \
679 {                                                                             \
680     uint8_t halfH[272];                                                       \
681                                                                               \
682     put ## RND ## mpeg4_qpel16_h_lowpass(halfH, src, 16, stride, 17);         \
683     OPNAME ## mpeg4_qpel16_v_lowpass(dst, halfH, stride, 16);                 \
684 }
685
686 #define op_avg(a, b)        a = (((a) + cm[((b) + 16) >> 5] + 1) >> 1)
687 #define op_put(a, b)        a = cm[((b) + 16) >> 5]
688 #define op_put_no_rnd(a, b) a = cm[((b) + 15) >> 5]
689
690 QPEL_MC(0, put_, _, op_put)
691 QPEL_MC(1, put_no_rnd_, _no_rnd_, op_put_no_rnd)
692 QPEL_MC(0, avg_, _, op_avg)
693
694 #undef op_avg
695 #undef op_put
696 #undef op_put_no_rnd
697
698 void ff_put_pixels8x8_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
699 {
700     put_pixels8_8_c(dst, src, stride, 8);
701 }
702
703 void ff_avg_pixels8x8_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
704 {
705     avg_pixels8_8_c(dst, src, stride, 8);
706 }
707
708 void ff_put_pixels16x16_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
709 {
710     put_pixels16_8_c(dst, src, stride, 16);
711 }
712
713 void ff_avg_pixels16x16_c(uint8_t *dst, uint8_t *src, ptrdiff_t stride)
714 {
715     avg_pixels16_8_c(dst, src, stride, 16);
716 }
717
718 #define put_qpel8_mc00_c         ff_put_pixels8x8_c
719 #define avg_qpel8_mc00_c         ff_avg_pixels8x8_c
720 #define put_qpel16_mc00_c        ff_put_pixels16x16_c
721 #define avg_qpel16_mc00_c        ff_avg_pixels16x16_c
722 #define put_no_rnd_qpel8_mc00_c  ff_put_pixels8x8_c
723 #define put_no_rnd_qpel16_mc00_c ff_put_pixels16x16_c
724
725 void ff_put_pixels8_l2_8(uint8_t *dst, const uint8_t *src1, const uint8_t *src2,
726                          int dst_stride, int src_stride1, int src_stride2,
727                          int h)
728 {
729     put_pixels8_l2_8(dst, src1, src2, dst_stride, src_stride1, src_stride2, h);
730
731 }
732
733 av_cold void ff_qpeldsp_init(QpelDSPContext *c)
734 {
735 #define dspfunc(PFX, IDX, NUM)                              \
736     c->PFX ## _pixels_tab[IDX][0]  = PFX ## NUM ## _mc00_c; \
737     c->PFX ## _pixels_tab[IDX][1]  = PFX ## NUM ## _mc10_c; \
738     c->PFX ## _pixels_tab[IDX][2]  = PFX ## NUM ## _mc20_c; \
739     c->PFX ## _pixels_tab[IDX][3]  = PFX ## NUM ## _mc30_c; \
740     c->PFX ## _pixels_tab[IDX][4]  = PFX ## NUM ## _mc01_c; \
741     c->PFX ## _pixels_tab[IDX][5]  = PFX ## NUM ## _mc11_c; \
742     c->PFX ## _pixels_tab[IDX][6]  = PFX ## NUM ## _mc21_c; \
743     c->PFX ## _pixels_tab[IDX][7]  = PFX ## NUM ## _mc31_c; \
744     c->PFX ## _pixels_tab[IDX][8]  = PFX ## NUM ## _mc02_c; \
745     c->PFX ## _pixels_tab[IDX][9]  = PFX ## NUM ## _mc12_c; \
746     c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_c; \
747     c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_c; \
748     c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_c; \
749     c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_c; \
750     c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_c; \
751     c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_c
752
753     dspfunc(put_qpel, 0, 16);
754     dspfunc(put_qpel, 1, 8);
755
756     dspfunc(put_no_rnd_qpel, 0, 16);
757     dspfunc(put_no_rnd_qpel, 1, 8);
758
759     dspfunc(avg_qpel, 0, 16);
760     dspfunc(avg_qpel, 1, 8);
761
762     if (ARCH_X86)
763         ff_qpeldsp_init_x86(c);
764 }