]> git.sesse.net Git - ffmpeg/blob - libavcodec/x86/hevcdsp_init.c
Merge commit '8b0dd4942aac320d1ca3c40fa7ea1be342c71273'
[ffmpeg] / libavcodec / x86 / hevcdsp_init.c
1 /*
2  * Copyright (c) 2013 Seppo Tomperi
3  * Copyright (c) 2013 - 2014 Pierre-Edouard Lepere
4  *
5  *
6  * This file is part of ffmpeg.
7  *
8  * ffmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * ffmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with ffmpeg; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22
23 #include "config.h"
24 #include "libavutil/cpu.h"
25 #include "libavutil/x86/asm.h"
26 #include "libavutil/x86/cpu.h"
27 #include "libavcodec/get_bits.h" /* required for hevcdsp.h GetBitContext */
28 #include "libavcodec/hevcdsp.h"
29 #include "libavcodec/x86/hevcdsp.h"
30
31
32 #define LFC_FUNC(DIR, DEPTH, OPT)                                        \
33 void ff_hevc_ ## DIR ## _loop_filter_chroma_ ## DEPTH ## _ ## OPT(uint8_t *_pix, ptrdiff_t _stride, int *_tc, uint8_t *_no_p, uint8_t *_no_q);
34
35 #define LFL_FUNC(DIR, DEPTH, OPT)                                        \
36 void ff_hevc_ ## DIR ## _loop_filter_luma_ ## DEPTH ## _ ## OPT(uint8_t *_pix, ptrdiff_t stride, int *_beta, int *_tc, \
37 uint8_t *_no_p, uint8_t *_no_q);
38
39 #define LFC_FUNCS(type, depth, opt) \
40 LFC_FUNC(h, depth, opt)  \
41 LFC_FUNC(v, depth, opt)
42
43 #define LFL_FUNCS(type, depth, opt) \
44 LFL_FUNC(h, depth, opt)  \
45 LFL_FUNC(v, depth, opt)
46
47 LFC_FUNCS(uint8_t,   8, sse2)
48 LFC_FUNCS(uint8_t,  10, sse2)
49 LFL_FUNCS(uint8_t,   8, sse2)
50 LFL_FUNCS(uint8_t,  10, sse2)
51 LFL_FUNCS(uint8_t,   8, ssse3)
52 LFL_FUNCS(uint8_t,  10, ssse3)
53
54 #if HAVE_SSE2_EXTERNAL
55 void ff_hevc_idct32_dc_add_8_sse2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
56 {
57     ff_hevc_idct16_dc_add_8_sse2(dst, coeffs, stride);
58     ff_hevc_idct16_dc_add_8_sse2(dst+16, coeffs, stride);
59     ff_hevc_idct16_dc_add_8_sse2(dst+16*stride, coeffs, stride);
60     ff_hevc_idct16_dc_add_8_sse2(dst+16*stride+16, coeffs, stride);
61 }
62
63 void ff_hevc_idct16_dc_add_10_sse2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
64 {
65     ff_hevc_idct8_dc_add_10_sse2(dst, coeffs, stride);
66     ff_hevc_idct8_dc_add_10_sse2(dst+16, coeffs, stride);
67     ff_hevc_idct8_dc_add_10_sse2(dst+8*stride, coeffs, stride);
68     ff_hevc_idct8_dc_add_10_sse2(dst+8*stride+16, coeffs, stride);
69 }
70
71 void ff_hevc_idct32_dc_add_10_sse2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
72 {
73     ff_hevc_idct16_dc_add_10_sse2(dst, coeffs, stride);
74     ff_hevc_idct16_dc_add_10_sse2(dst+32, coeffs, stride);
75     ff_hevc_idct16_dc_add_10_sse2(dst+16*stride, coeffs, stride);
76     ff_hevc_idct16_dc_add_10_sse2(dst+16*stride+32, coeffs, stride);
77 }
78 #endif //HAVE_SSE2_EXTERNAL
79 #if HAVE_AVX_EXTERNAL
80 void ff_hevc_idct16_dc_add_10_avx(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
81 {
82     ff_hevc_idct8_dc_add_10_avx(dst, coeffs, stride);
83     ff_hevc_idct8_dc_add_10_avx(dst+16, coeffs, stride);
84     ff_hevc_idct8_dc_add_10_avx(dst+8*stride, coeffs, stride);
85     ff_hevc_idct8_dc_add_10_avx(dst+8*stride+16, coeffs, stride);
86 }
87
88 void ff_hevc_idct32_dc_add_10_avx(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
89 {
90     ff_hevc_idct16_dc_add_10_avx(dst, coeffs, stride);
91     ff_hevc_idct16_dc_add_10_avx(dst+32, coeffs, stride);
92     ff_hevc_idct16_dc_add_10_avx(dst+16*stride, coeffs, stride);
93     ff_hevc_idct16_dc_add_10_avx(dst+16*stride+32, coeffs, stride);
94 }
95 #endif //HAVE_AVX_EXTERNAL
96
97 #if HAVE_AVX2_EXTERNAL
98
99 void ff_hevc_idct32_dc_add_10_avx2(uint8_t *dst, int16_t *coeffs, ptrdiff_t stride)
100 {
101     ff_hevc_idct16_dc_add_10_avx2(dst, coeffs, stride);
102     ff_hevc_idct16_dc_add_10_avx2(dst+32, coeffs, stride);
103     ff_hevc_idct16_dc_add_10_avx2(dst+16*stride, coeffs, stride);
104     ff_hevc_idct16_dc_add_10_avx2(dst+16*stride+32, coeffs, stride);
105 }
106 #endif //HAVE_AVX2_EXTERNAL
107
108 #define mc_rep_func(name, bitd, step, W, opt) \
109 void ff_hevc_put_hevc_##name##W##_##bitd##_##opt(int16_t *_dst, ptrdiff_t dststride,                            \
110                                                 uint8_t *_src, ptrdiff_t _srcstride, int height,                \
111                                                 intptr_t mx, intptr_t my, int width)                            \
112 {                                                                                                               \
113     int i;                                                                                                      \
114     uint8_t *src;                                                                                               \
115     int16_t *dst;                                                                                               \
116     for (i = 0; i < W; i += step) {                                                                             \
117         src  = _src + (i * ((bitd + 7) / 8));                                                                   \
118         dst = _dst + i;                                                                                         \
119         ff_hevc_put_hevc_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride, height, mx, my, width); \
120     }                                                                                                           \
121 }
122 #define mc_rep_uni_func(name, bitd, step, W, opt) \
123 void ff_hevc_put_hevc_uni_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride,                        \
124                                                     uint8_t *_src, ptrdiff_t _srcstride, int height,            \
125                                                     intptr_t mx, intptr_t my, int width)                        \
126 {                                                                                                               \
127     int i;                                                                                                      \
128     uint8_t *src;                                                                                               \
129     uint8_t *dst;                                                                                               \
130     for (i = 0; i < W; i += step) {                                                                             \
131         src = _src + (i * ((bitd + 7) / 8));                                                                    \
132         dst = _dst + (i * ((bitd + 7) / 8));                                                                    \
133         ff_hevc_put_hevc_uni_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride,                     \
134                                                           height, mx, my, width);                               \
135     }                                                                                                           \
136 }
137 #define mc_rep_bi_func(name, bitd, step, W, opt) \
138 void ff_hevc_put_hevc_bi_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, uint8_t *_src,          \
139                                                    ptrdiff_t _srcstride, int16_t* _src2, ptrdiff_t _src2stride, \
140                                                    int height, intptr_t mx, intptr_t my, int width)             \
141 {                                                                                                               \
142     int i;                                                                                                      \
143     uint8_t  *src;                                                                                              \
144     uint8_t  *dst;                                                                                              \
145     int16_t  *src2;                                                                                             \
146     for (i = 0; i < W ; i += step) {                                                                            \
147         src  = _src + (i * ((bitd + 7) / 8));                                                                   \
148         dst  = _dst + (i * ((bitd + 7) / 8));                                                                   \
149         src2 = _src2 + i;                                                                                       \
150         ff_hevc_put_hevc_bi_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride, src2,                \
151                                                          _src2stride, height, mx, my, width);                   \
152     }                                                                                                           \
153 }
154
155 #define mc_rep_funcs(name, bitd, step, W, opt)        \
156     mc_rep_func(name, bitd, step, W, opt);            \
157     mc_rep_uni_func(name, bitd, step, W, opt);        \
158     mc_rep_bi_func(name, bitd, step, W, opt)
159
160
161 #if ARCH_X86_64 && HAVE_SSE4_EXTERNAL
162
163 mc_rep_funcs(pel_pixels, 8, 16, 64, sse4);
164 mc_rep_funcs(pel_pixels, 8, 16, 48, sse4);
165 mc_rep_funcs(pel_pixels, 8, 16, 32, sse4);
166 mc_rep_funcs(pel_pixels, 8,  8, 24, sse4);
167
168 mc_rep_funcs(pel_pixels,10,  8, 64, sse4);
169 mc_rep_funcs(pel_pixels,10,  8, 48, sse4);
170 mc_rep_funcs(pel_pixels,10,  8, 32, sse4);
171 mc_rep_funcs(pel_pixels,10,  8, 24, sse4);
172 mc_rep_funcs(pel_pixels,10,  8, 16, sse4);
173 mc_rep_funcs(pel_pixels,10,  4, 12, sse4);
174
175 mc_rep_funcs(epel_h, 8, 16, 64, sse4);
176 mc_rep_funcs(epel_h, 8, 16, 48, sse4);
177 mc_rep_funcs(epel_h, 8, 16, 32, sse4);
178 mc_rep_funcs(epel_h, 8,  8, 24, sse4);
179 mc_rep_funcs(epel_h,10,  8, 64, sse4);
180 mc_rep_funcs(epel_h,10,  8, 48, sse4);
181 mc_rep_funcs(epel_h,10,  8, 32, sse4);
182 mc_rep_funcs(epel_h,10,  8, 24, sse4);
183 mc_rep_funcs(epel_h,10,  8, 16, sse4);
184 mc_rep_funcs(epel_h,10,  4, 12, sse4);
185 mc_rep_funcs(epel_v, 8, 16, 64, sse4);
186 mc_rep_funcs(epel_v, 8, 16, 48, sse4);
187 mc_rep_funcs(epel_v, 8, 16, 32, sse4);
188 mc_rep_funcs(epel_v, 8,  8, 24, sse4);
189 mc_rep_funcs(epel_v,10,  8, 64, sse4);
190 mc_rep_funcs(epel_v,10,  8, 48, sse4);
191 mc_rep_funcs(epel_v,10,  8, 32, sse4);
192 mc_rep_funcs(epel_v,10,  8, 24, sse4);
193 mc_rep_funcs(epel_v,10,  8, 16, sse4);
194 mc_rep_funcs(epel_v,10,  4, 12, sse4);
195 mc_rep_funcs(epel_hv, 8,  8, 64, sse4);
196 mc_rep_funcs(epel_hv, 8,  8, 48, sse4);
197 mc_rep_funcs(epel_hv, 8,  8, 32, sse4);
198 mc_rep_funcs(epel_hv, 8,  8, 24, sse4);
199 mc_rep_funcs(epel_hv, 8,  8, 16, sse4);
200 mc_rep_funcs(epel_hv, 8,  4, 12, sse4);
201 mc_rep_funcs(epel_hv,10,  8, 64, sse4);
202 mc_rep_funcs(epel_hv,10,  8, 48, sse4);
203 mc_rep_funcs(epel_hv,10,  8, 32, sse4);
204 mc_rep_funcs(epel_hv,10,  8, 24, sse4);
205 mc_rep_funcs(epel_hv,10,  8, 16, sse4);
206 mc_rep_funcs(epel_hv,10,  4, 12, sse4);
207
208 mc_rep_funcs(qpel_h, 8, 16, 64, sse4);
209 mc_rep_funcs(qpel_h, 8, 16, 48, sse4);
210 mc_rep_funcs(qpel_h, 8, 16, 32, sse4);
211 mc_rep_funcs(qpel_h, 8,  8, 24, sse4);
212 mc_rep_funcs(qpel_h,10,  8, 64, sse4);
213 mc_rep_funcs(qpel_h,10,  8, 48, sse4);
214 mc_rep_funcs(qpel_h,10,  8, 32, sse4);
215 mc_rep_funcs(qpel_h,10,  8, 24, sse4);
216 mc_rep_funcs(qpel_h,10,  8, 16, sse4);
217 mc_rep_funcs(qpel_h,10,  4, 12, sse4);
218 mc_rep_funcs(qpel_v, 8, 16, 64, sse4);
219 mc_rep_funcs(qpel_v, 8, 16, 48, sse4);
220 mc_rep_funcs(qpel_v, 8, 16, 32, sse4);
221 mc_rep_funcs(qpel_v, 8,  8, 24, sse4);
222 mc_rep_funcs(qpel_v,10,  8, 64, sse4);
223 mc_rep_funcs(qpel_v,10,  8, 48, sse4);
224 mc_rep_funcs(qpel_v,10,  8, 32, sse4);
225 mc_rep_funcs(qpel_v,10,  8, 24, sse4);
226 mc_rep_funcs(qpel_v,10,  8, 16, sse4);
227 mc_rep_funcs(qpel_v,10,  4, 12, sse4);
228 mc_rep_funcs(qpel_hv, 8,  8, 64, sse4);
229 mc_rep_funcs(qpel_hv, 8,  8, 48, sse4);
230 mc_rep_funcs(qpel_hv, 8,  8, 32, sse4);
231 mc_rep_funcs(qpel_hv, 8,  8, 24, sse4);
232 mc_rep_funcs(qpel_hv, 8,  8, 16, sse4);
233 mc_rep_funcs(qpel_hv, 8,  4, 12, sse4);
234 mc_rep_funcs(qpel_hv,10,  8, 64, sse4);
235 mc_rep_funcs(qpel_hv,10,  8, 48, sse4);
236 mc_rep_funcs(qpel_hv,10,  8, 32, sse4);
237 mc_rep_funcs(qpel_hv,10,  8, 24, sse4);
238 mc_rep_funcs(qpel_hv,10,  8, 16, sse4);
239 mc_rep_funcs(qpel_hv,10,  4, 12, sse4);
240
241 #define mc_rep_uni_w(bitd, step, W, opt) \
242 void ff_hevc_put_hevc_uni_w##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride,\
243                                                int height, int denom,  int _wx, int _ox)                                \
244 {                                                                                                                       \
245     int i;                                                                                                              \
246     int16_t *src;                                                                                                       \
247     uint8_t *dst;                                                                                                       \
248     for (i = 0; i < W; i += step) {                                                                                     \
249         src= _src + i;                                                                                                  \
250         dst= _dst + (i * ((bitd + 7) / 8));                                                                             \
251         ff_hevc_put_hevc_uni_w##step##_##bitd##_##opt(dst, dststride, src, _srcstride,                                  \
252                                                      height, denom, _wx, _ox);                                          \
253     }                                                                                                                   \
254 }
255
256 mc_rep_uni_w(8, 6, 12, sse4);
257 mc_rep_uni_w(8, 8, 16, sse4);
258 mc_rep_uni_w(8, 8, 24, sse4);
259 mc_rep_uni_w(8, 8, 32, sse4);
260 mc_rep_uni_w(8, 8, 48, sse4);
261 mc_rep_uni_w(8, 8, 64, sse4);
262
263 mc_rep_uni_w(10, 6, 12, sse4);
264 mc_rep_uni_w(10, 8, 16, sse4);
265 mc_rep_uni_w(10, 8, 24, sse4);
266 mc_rep_uni_w(10, 8, 32, sse4);
267 mc_rep_uni_w(10, 8, 48, sse4);
268 mc_rep_uni_w(10, 8, 64, sse4);
269
270 #define mc_rep_bi_w(bitd, step, W, opt) \
271 void ff_hevc_put_hevc_bi_w##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
272                                               int16_t *_src2, ptrdiff_t _src2stride, int height,                        \
273                                               int denom,  int _wx0,  int _wx1, int _ox0, int _ox1)                      \
274 {                                                                                                                       \
275     int i;                                                                                                              \
276     int16_t *src;                                                                                                       \
277     int16_t *src2;                                                                                                      \
278     uint8_t *dst;                                                                                                       \
279     for (i = 0; i < W; i += step) {                                                                                     \
280         src  = _src  + i;                                                                                               \
281         src2 = _src2 + i;                                                                                               \
282         dst  = _dst  + (i * ((bitd + 7) / 8));                                                                          \
283         ff_hevc_put_hevc_bi_w##step##_##bitd##_##opt(dst, dststride, src, _srcstride, src2, _src2stride,                \
284                                                     height, denom, _wx0, _wx1, _ox0, _ox1);                             \
285     }                                                                                                                   \
286 }
287
288 mc_rep_bi_w(8, 6, 12, sse4);
289 mc_rep_bi_w(8, 8, 16, sse4);
290 mc_rep_bi_w(8, 8, 24, sse4);
291 mc_rep_bi_w(8, 8, 32, sse4);
292 mc_rep_bi_w(8, 8, 48, sse4);
293 mc_rep_bi_w(8, 8, 64, sse4);
294
295 mc_rep_bi_w(10, 6, 12, sse4);
296 mc_rep_bi_w(10, 8, 16, sse4);
297 mc_rep_bi_w(10, 8, 24, sse4);
298 mc_rep_bi_w(10, 8, 32, sse4);
299 mc_rep_bi_w(10, 8, 48, sse4);
300 mc_rep_bi_w(10, 8, 64, sse4);
301
302 #define mc_uni_w_func(name, bitd, W, opt) \
303 void ff_hevc_put_hevc_uni_w_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t _dststride,         \
304                                                       uint8_t *_src, ptrdiff_t _srcstride,          \
305                                                       int height, int denom,                        \
306                                                       int _wx, int _ox,                             \
307                                                       intptr_t mx, intptr_t my, int width)          \
308 {                                                                                                   \
309     LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]);                                                     \
310     ff_hevc_put_hevc_##name##W##_##bitd##_##opt(temp, 64, _src, _srcstride, height, mx, my, width); \
311     ff_hevc_put_hevc_uni_w##W##_##bitd##_##opt(_dst, _dststride, temp, 64, height, denom, _wx, _ox);\
312 }
313
314 #define mc_uni_w_funcs(name, bitd, opt)       \
315         mc_uni_w_func(name, bitd, 4, opt);    \
316         mc_uni_w_func(name, bitd, 8, opt);    \
317         mc_uni_w_func(name, bitd, 12, opt);   \
318         mc_uni_w_func(name, bitd, 16, opt);   \
319         mc_uni_w_func(name, bitd, 24, opt);   \
320         mc_uni_w_func(name, bitd, 32, opt);   \
321         mc_uni_w_func(name, bitd, 48, opt);   \
322         mc_uni_w_func(name, bitd, 64, opt)
323
324 mc_uni_w_funcs(pel_pixels, 8, sse4);
325 mc_uni_w_func(pel_pixels, 8, 6, sse4);
326 mc_uni_w_funcs(epel_h, 8, sse4);
327 mc_uni_w_func(epel_h, 8, 6, sse4);
328 mc_uni_w_funcs(epel_v, 8, sse4);
329 mc_uni_w_func(epel_v, 8, 6, sse4);
330 mc_uni_w_funcs(epel_hv, 8, sse4);
331 mc_uni_w_func(epel_hv, 8, 6, sse4);
332 mc_uni_w_funcs(qpel_h, 8, sse4);
333 mc_uni_w_funcs(qpel_v, 8, sse4);
334 mc_uni_w_funcs(qpel_hv, 8, sse4);
335
336 mc_uni_w_funcs(pel_pixels, 10, sse4);
337 mc_uni_w_func(pel_pixels, 10, 6, sse4);
338 mc_uni_w_funcs(epel_h, 10, sse4);
339 mc_uni_w_func(epel_h, 10, 6, sse4);
340 mc_uni_w_funcs(epel_v, 10, sse4);
341 mc_uni_w_func(epel_v, 10, 6, sse4);
342 mc_uni_w_funcs(epel_hv, 10, sse4);
343 mc_uni_w_func(epel_hv, 10, 6, sse4);
344 mc_uni_w_funcs(qpel_h, 10, sse4);
345 mc_uni_w_funcs(qpel_v, 10, sse4);
346 mc_uni_w_funcs(qpel_hv, 10, sse4);
347
348
349 #define mc_bi_w_func(name, bitd, W, opt) \
350 void ff_hevc_put_hevc_bi_w_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t _dststride,           \
351                                                      uint8_t *_src, ptrdiff_t _srcstride,            \
352                                                      int16_t *_src2, ptrdiff_t _src2stride,          \
353                                                      int height, int denom,                          \
354                                                      int _wx0, int _wx1, int _ox0, int _ox1,         \
355                                                      intptr_t mx, intptr_t my, int width)            \
356 {                                                                                                    \
357     LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]);                                                      \
358     ff_hevc_put_hevc_##name##W##_##bitd##_##opt(temp, 64, _src, _srcstride, height, mx, my, width);  \
359     ff_hevc_put_hevc_bi_w##W##_##bitd##_##opt(_dst, _dststride, temp, 64, _src2, _src2stride,        \
360                                              height, denom, _wx0, _wx1, _ox0, _ox1);                 \
361 }
362
363 #define mc_bi_w_funcs(name, bitd, opt)       \
364         mc_bi_w_func(name, bitd, 4, opt);    \
365         mc_bi_w_func(name, bitd, 8, opt);    \
366         mc_bi_w_func(name, bitd, 12, opt);   \
367         mc_bi_w_func(name, bitd, 16, opt);   \
368         mc_bi_w_func(name, bitd, 24, opt);   \
369         mc_bi_w_func(name, bitd, 32, opt);   \
370         mc_bi_w_func(name, bitd, 48, opt);   \
371         mc_bi_w_func(name, bitd, 64, opt)
372
373 mc_bi_w_funcs(pel_pixels, 8, sse4);
374 mc_bi_w_func(pel_pixels, 8, 6, sse4);
375 mc_bi_w_funcs(epel_h, 8, sse4);
376 mc_bi_w_func(epel_h, 8, 6, sse4);
377 mc_bi_w_funcs(epel_v, 8, sse4);
378 mc_bi_w_func(epel_v, 8, 6, sse4);
379 mc_bi_w_funcs(epel_hv, 8, sse4);
380 mc_bi_w_func(epel_hv, 8, 6, sse4);
381 mc_bi_w_funcs(qpel_h, 8, sse4);
382 mc_bi_w_funcs(qpel_v, 8, sse4);
383 mc_bi_w_funcs(qpel_hv, 8, sse4);
384
385 mc_bi_w_funcs(pel_pixels, 10, sse4);
386 mc_bi_w_func(pel_pixels, 10, 6, sse4);
387 mc_bi_w_funcs(epel_h, 10, sse4);
388 mc_bi_w_func(epel_h, 10, 6, sse4);
389 mc_bi_w_funcs(epel_v, 10, sse4);
390 mc_bi_w_func(epel_v, 10, 6, sse4);
391 mc_bi_w_funcs(epel_hv, 10, sse4);
392 mc_bi_w_func(epel_hv, 10, 6, sse4);
393 mc_bi_w_funcs(qpel_h, 10, sse4);
394 mc_bi_w_funcs(qpel_v, 10, sse4);
395 mc_bi_w_funcs(qpel_hv, 10, sse4);
396
397 #endif //ARCH_X86_64 && HAVE_SSE4_EXTERNAL
398
399
400 #define EPEL_LINKS(pointer, my, mx, fname, bitd, opt )           \
401         PEL_LINK(pointer, 1, my , mx , fname##4 ,  bitd, opt ); \
402         PEL_LINK(pointer, 2, my , mx , fname##6 ,  bitd, opt ); \
403         PEL_LINK(pointer, 3, my , mx , fname##8 ,  bitd, opt ); \
404         PEL_LINK(pointer, 4, my , mx , fname##12,  bitd, opt ); \
405         PEL_LINK(pointer, 5, my , mx , fname##16,  bitd, opt ); \
406         PEL_LINK(pointer, 6, my , mx , fname##24,  bitd, opt ); \
407         PEL_LINK(pointer, 7, my , mx , fname##32,  bitd, opt ); \
408         PEL_LINK(pointer, 8, my , mx , fname##48,  bitd, opt ); \
409         PEL_LINK(pointer, 9, my , mx , fname##64,  bitd, opt )
410 #define QPEL_LINKS(pointer, my, mx, fname, bitd, opt)           \
411         PEL_LINK(pointer, 1, my , mx , fname##4 ,  bitd, opt ); \
412         PEL_LINK(pointer, 3, my , mx , fname##8 ,  bitd, opt ); \
413         PEL_LINK(pointer, 4, my , mx , fname##12,  bitd, opt ); \
414         PEL_LINK(pointer, 5, my , mx , fname##16,  bitd, opt ); \
415         PEL_LINK(pointer, 6, my , mx , fname##24,  bitd, opt ); \
416         PEL_LINK(pointer, 7, my , mx , fname##32,  bitd, opt ); \
417         PEL_LINK(pointer, 8, my , mx , fname##48,  bitd, opt ); \
418         PEL_LINK(pointer, 9, my , mx , fname##64,  bitd, opt )
419
420
421 void ff_hevcdsp_init_x86(HEVCDSPContext *c, const int bit_depth)
422 {
423     int mm_flags = av_get_cpu_flags();
424
425     if (bit_depth == 8) {
426         if (EXTERNAL_MMXEXT(mm_flags)) {
427                 c->transform_dc_add[0]    =  ff_hevc_idct4_dc_add_8_mmxext;
428                 c->transform_dc_add[1]    =  ff_hevc_idct8_dc_add_8_mmxext;
429
430         }
431         if (EXTERNAL_SSE2(mm_flags)) {
432                     c->hevc_v_loop_filter_chroma = ff_hevc_v_loop_filter_chroma_8_sse2;
433                     c->hevc_h_loop_filter_chroma = ff_hevc_h_loop_filter_chroma_8_sse2;
434                     if (ARCH_X86_64) {
435                         c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_8_sse2;
436                         c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_8_sse2;
437                     }
438
439                     c->transform_dc_add[2]    =  ff_hevc_idct16_dc_add_8_sse2;
440                     c->transform_dc_add[3]    =  ff_hevc_idct32_dc_add_8_sse2;
441         }
442         if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
443                     c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_8_ssse3;
444                     c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_8_ssse3;
445         }
446         if (EXTERNAL_SSE4(mm_flags) && ARCH_X86_64) {
447
448             EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels,  8, sse4);
449             EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h,      8, sse4);
450             EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v,      8, sse4);
451             EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv,     8, sse4);
452
453             QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 8, sse4);
454             QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h,     8, sse4);
455             QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v,     8, sse4);
456             QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv,    8, sse4);
457         }
458         if (EXTERNAL_AVX2(mm_flags)) {
459             c->transform_dc_add[3]    =  ff_hevc_idct32_dc_add_8_avx2;
460         }
461     } else if (bit_depth == 10) {
462         if (EXTERNAL_MMXEXT(mm_flags)) {
463                 c->transform_dc_add[0]    =  ff_hevc_idct4_dc_add_10_mmxext;
464
465         }
466         if (EXTERNAL_SSE2(mm_flags)) {
467                     c->hevc_v_loop_filter_chroma = ff_hevc_v_loop_filter_chroma_10_sse2;
468                     c->hevc_h_loop_filter_chroma = ff_hevc_h_loop_filter_chroma_10_sse2;
469                     if (ARCH_X86_64) {
470                         c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_10_sse2;
471                         c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_10_sse2;
472                     }
473
474                     c->transform_dc_add[1]    =  ff_hevc_idct8_dc_add_10_sse2;
475                     c->transform_dc_add[2]    =  ff_hevc_idct16_dc_add_10_sse2;
476                     c->transform_dc_add[3]    =  ff_hevc_idct32_dc_add_10_sse2;
477                 }
478         if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
479                     c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_10_ssse3;
480                     c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_10_ssse3;
481         }
482         if (EXTERNAL_SSE4(mm_flags) && ARCH_X86_64) {
483
484             EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 10, sse4);
485             EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h,     10, sse4);
486             EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v,     10, sse4);
487             EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv,    10, sse4);
488
489             QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 10, sse4);
490             QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h,     10, sse4);
491             QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v,     10, sse4);
492             QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv,    10, sse4);
493         }
494         if (EXTERNAL_AVX(mm_flags)) {
495             c->transform_dc_add[1]    =  ff_hevc_idct8_dc_add_10_avx;
496             c->transform_dc_add[2]    =  ff_hevc_idct16_dc_add_10_avx;
497             c->transform_dc_add[3]    =  ff_hevc_idct32_dc_add_10_avx;
498         }
499         if (EXTERNAL_AVX2(mm_flags)) {
500             c->transform_dc_add[2]    =  ff_hevc_idct16_dc_add_10_avx2;
501             c->transform_dc_add[3]    =  ff_hevc_idct32_dc_add_10_avx2;
502
503         }
504     }
505 }