2 * Copyright (c) 2013 Seppo Tomperi
3 * Copyright (c) 2013 - 2014 Pierre-Edouard Lepere
6 * This file is part of ffmpeg.
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.
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.
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
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"
32 #define mc_rep_func(name, bitd, step, W, opt) \
33 void ff_hevc_put_hevc_##name##W##_##bitd##_##opt(int16_t *_dst, ptrdiff_t dststride, \
34 uint8_t *_src, ptrdiff_t _srcstride, int height, \
35 intptr_t mx, intptr_t my, int width) \
40 for (i = 0; i < W; i += step) { \
41 src = _src + (i * ((bitd + 7) / 8)); \
43 ff_hevc_put_hevc_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride, height, mx, my, width); \
46 #define mc_rep_uni_func(name, bitd, step, W, opt) \
47 void ff_hevc_put_hevc_uni_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, \
48 uint8_t *_src, ptrdiff_t _srcstride, int height, \
49 intptr_t mx, intptr_t my, int width) \
54 for (i = 0; i < W; i += step) { \
55 src = _src + (i * ((bitd + 7) / 8)); \
56 dst = _dst + (i * ((bitd + 7) / 8)); \
57 ff_hevc_put_hevc_uni_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride, \
58 height, mx, my, width); \
61 #define mc_rep_bi_func(name, bitd, step, W, opt) \
62 void ff_hevc_put_hevc_bi_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, uint8_t *_src, \
63 ptrdiff_t _srcstride, int16_t* _src2, ptrdiff_t _src2stride, \
64 int height, intptr_t mx, intptr_t my, int width) \
70 for (i = 0; i < W ; i += step) { \
71 src = _src + (i * ((bitd + 7) / 8)); \
72 dst = _dst + (i * ((bitd + 7) / 8)); \
74 ff_hevc_put_hevc_bi_##name##step##_##bitd##_##opt(dst, dststride, src, _srcstride, src2, \
75 _src2stride, height, mx, my, width); \
79 #define mc_rep_funcs(name, bitd, step, W, opt) \
80 mc_rep_func(name, bitd, step, W, opt); \
81 mc_rep_uni_func(name, bitd, step, W, opt); \
82 mc_rep_bi_func(name, bitd, step, W, opt)
85 #if ARCH_X86_64 && HAVE_SSE4_EXTERNAL
87 mc_rep_funcs(pel_pixels, 8, 16, 64, sse4);
88 mc_rep_funcs(pel_pixels, 8, 16, 48, sse4);
89 mc_rep_funcs(pel_pixels, 8, 16, 32, sse4);
90 mc_rep_funcs(pel_pixels, 8, 8, 24, sse4);
92 mc_rep_funcs(pel_pixels,10, 8, 64, sse4);
93 mc_rep_funcs(pel_pixels,10, 8, 48, sse4);
94 mc_rep_funcs(pel_pixels,10, 8, 32, sse4);
95 mc_rep_funcs(pel_pixels,10, 8, 24, sse4);
96 mc_rep_funcs(pel_pixels,10, 8, 16, sse4);
97 mc_rep_funcs(pel_pixels,10, 4, 12, sse4);
99 mc_rep_funcs(epel_h, 8, 16, 64, sse4);
100 mc_rep_funcs(epel_h, 8, 16, 48, sse4);
101 mc_rep_funcs(epel_h, 8, 16, 32, sse4);
102 mc_rep_funcs(epel_h, 8, 8, 24, sse4);
103 mc_rep_funcs(epel_h,10, 8, 64, sse4);
104 mc_rep_funcs(epel_h,10, 8, 48, sse4);
105 mc_rep_funcs(epel_h,10, 8, 32, sse4);
106 mc_rep_funcs(epel_h,10, 8, 24, sse4);
107 mc_rep_funcs(epel_h,10, 8, 16, sse4);
108 mc_rep_funcs(epel_h,10, 4, 12, sse4);
109 mc_rep_funcs(epel_v, 8, 16, 64, sse4);
110 mc_rep_funcs(epel_v, 8, 16, 48, sse4);
111 mc_rep_funcs(epel_v, 8, 16, 32, sse4);
112 mc_rep_funcs(epel_v, 8, 8, 24, sse4);
113 mc_rep_funcs(epel_v,10, 8, 64, sse4);
114 mc_rep_funcs(epel_v,10, 8, 48, sse4);
115 mc_rep_funcs(epel_v,10, 8, 32, sse4);
116 mc_rep_funcs(epel_v,10, 8, 24, sse4);
117 mc_rep_funcs(epel_v,10, 8, 16, sse4);
118 mc_rep_funcs(epel_v,10, 4, 12, sse4);
119 mc_rep_funcs(epel_hv, 8, 8, 64, sse4);
120 mc_rep_funcs(epel_hv, 8, 8, 48, sse4);
121 mc_rep_funcs(epel_hv, 8, 8, 32, sse4);
122 mc_rep_funcs(epel_hv, 8, 8, 24, sse4);
123 mc_rep_funcs(epel_hv, 8, 8, 16, sse4);
124 mc_rep_funcs(epel_hv, 8, 4, 12, sse4);
125 mc_rep_funcs(epel_hv,10, 8, 64, sse4);
126 mc_rep_funcs(epel_hv,10, 8, 48, sse4);
127 mc_rep_funcs(epel_hv,10, 8, 32, sse4);
128 mc_rep_funcs(epel_hv,10, 8, 24, sse4);
129 mc_rep_funcs(epel_hv,10, 8, 16, sse4);
130 mc_rep_funcs(epel_hv,10, 4, 12, sse4);
132 mc_rep_funcs(qpel_h, 8, 16, 64, sse4);
133 mc_rep_funcs(qpel_h, 8, 16, 48, sse4);
134 mc_rep_funcs(qpel_h, 8, 16, 32, sse4);
135 mc_rep_funcs(qpel_h, 8, 8, 24, sse4);
136 mc_rep_funcs(qpel_h,10, 8, 64, sse4);
137 mc_rep_funcs(qpel_h,10, 8, 48, sse4);
138 mc_rep_funcs(qpel_h,10, 8, 32, sse4);
139 mc_rep_funcs(qpel_h,10, 8, 24, sse4);
140 mc_rep_funcs(qpel_h,10, 8, 16, sse4);
141 mc_rep_funcs(qpel_h,10, 4, 12, sse4);
142 mc_rep_funcs(qpel_v, 8, 16, 64, sse4);
143 mc_rep_funcs(qpel_v, 8, 16, 48, sse4);
144 mc_rep_funcs(qpel_v, 8, 16, 32, sse4);
145 mc_rep_funcs(qpel_v, 8, 8, 24, sse4);
146 mc_rep_funcs(qpel_v,10, 8, 64, sse4);
147 mc_rep_funcs(qpel_v,10, 8, 48, sse4);
148 mc_rep_funcs(qpel_v,10, 8, 32, sse4);
149 mc_rep_funcs(qpel_v,10, 8, 24, sse4);
150 mc_rep_funcs(qpel_v,10, 8, 16, sse4);
151 mc_rep_funcs(qpel_v,10, 4, 12, sse4);
152 mc_rep_funcs(qpel_hv, 8, 8, 64, sse4);
153 mc_rep_funcs(qpel_hv, 8, 8, 48, sse4);
154 mc_rep_funcs(qpel_hv, 8, 8, 32, sse4);
155 mc_rep_funcs(qpel_hv, 8, 8, 24, sse4);
156 mc_rep_funcs(qpel_hv, 8, 8, 16, sse4);
157 mc_rep_funcs(qpel_hv, 8, 4, 12, sse4);
158 mc_rep_funcs(qpel_hv,10, 8, 64, sse4);
159 mc_rep_funcs(qpel_hv,10, 8, 48, sse4);
160 mc_rep_funcs(qpel_hv,10, 8, 32, sse4);
161 mc_rep_funcs(qpel_hv,10, 8, 24, sse4);
162 mc_rep_funcs(qpel_hv,10, 8, 16, sse4);
163 mc_rep_funcs(qpel_hv,10, 4, 12, sse4);
165 #define mc_rep_uni_w(bitd, step, W, opt) \
166 void ff_hevc_put_hevc_uni_w##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride,\
167 int height, int denom, int _wx, int _ox) \
172 for (i = 0; i < W; i += step) { \
174 dst= _dst + (i * ((bitd + 7) / 8)); \
175 ff_hevc_put_hevc_uni_w##step##_##bitd##_##opt(dst, dststride, src, _srcstride, \
176 height, denom, _wx, _ox); \
180 mc_rep_uni_w(8, 6, 12, sse4);
181 mc_rep_uni_w(8, 8, 16, sse4);
182 mc_rep_uni_w(8, 8, 24, sse4);
183 mc_rep_uni_w(8, 8, 32, sse4);
184 mc_rep_uni_w(8, 8, 48, sse4);
185 mc_rep_uni_w(8, 8, 64, sse4);
187 mc_rep_uni_w(10, 6, 12, sse4);
188 mc_rep_uni_w(10, 8, 16, sse4);
189 mc_rep_uni_w(10, 8, 24, sse4);
190 mc_rep_uni_w(10, 8, 32, sse4);
191 mc_rep_uni_w(10, 8, 48, sse4);
192 mc_rep_uni_w(10, 8, 64, sse4);
194 #define mc_rep_bi_w(bitd, step, W, opt) \
195 void ff_hevc_put_hevc_bi_w##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
196 int16_t *_src2, ptrdiff_t _src2stride, int height, \
197 int denom, int _wx0, int _wx1, int _ox0, int _ox1) \
203 for (i = 0; i < W; i += step) { \
206 dst = _dst + (i * ((bitd + 7) / 8)); \
207 ff_hevc_put_hevc_bi_w##step##_##bitd##_##opt(dst, dststride, src, _srcstride, src2, _src2stride, \
208 height, denom, _wx0, _wx1, _ox0, _ox1); \
212 mc_rep_bi_w(8, 6, 12, sse4);
213 mc_rep_bi_w(8, 8, 16, sse4);
214 mc_rep_bi_w(8, 8, 24, sse4);
215 mc_rep_bi_w(8, 8, 32, sse4);
216 mc_rep_bi_w(8, 8, 48, sse4);
217 mc_rep_bi_w(8, 8, 64, sse4);
219 mc_rep_bi_w(10, 6, 12, sse4);
220 mc_rep_bi_w(10, 8, 16, sse4);
221 mc_rep_bi_w(10, 8, 24, sse4);
222 mc_rep_bi_w(10, 8, 32, sse4);
223 mc_rep_bi_w(10, 8, 48, sse4);
224 mc_rep_bi_w(10, 8, 64, sse4);
226 #define mc_uni_w_func(name, bitd, W, opt) \
227 void ff_hevc_put_hevc_uni_w_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t _dststride, \
228 uint8_t *_src, ptrdiff_t _srcstride, \
229 int height, int denom, \
231 intptr_t mx, intptr_t my, int width) \
233 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
234 ff_hevc_put_hevc_##name##W##_##bitd##_##opt(temp, 64, _src, _srcstride, height, mx, my, width); \
235 ff_hevc_put_hevc_uni_w##W##_##bitd##_##opt(_dst, _dststride, temp, 64, height, denom, _wx, _ox);\
238 #define mc_uni_w_funcs(name, bitd, opt) \
239 mc_uni_w_func(name, bitd, 4, opt); \
240 mc_uni_w_func(name, bitd, 8, opt); \
241 mc_uni_w_func(name, bitd, 12, opt); \
242 mc_uni_w_func(name, bitd, 16, opt); \
243 mc_uni_w_func(name, bitd, 24, opt); \
244 mc_uni_w_func(name, bitd, 32, opt); \
245 mc_uni_w_func(name, bitd, 48, opt); \
246 mc_uni_w_func(name, bitd, 64, opt)
248 mc_uni_w_funcs(pel_pixels, 8, sse4);
249 mc_uni_w_func(pel_pixels, 8, 6, sse4);
250 mc_uni_w_funcs(epel_h, 8, sse4);
251 mc_uni_w_func(epel_h, 8, 6, sse4);
252 mc_uni_w_funcs(epel_v, 8, sse4);
253 mc_uni_w_func(epel_v, 8, 6, sse4);
254 mc_uni_w_funcs(epel_hv, 8, sse4);
255 mc_uni_w_func(epel_hv, 8, 6, sse4);
256 mc_uni_w_funcs(qpel_h, 8, sse4);
257 mc_uni_w_funcs(qpel_v, 8, sse4);
258 mc_uni_w_funcs(qpel_hv, 8, sse4);
260 mc_uni_w_funcs(pel_pixels, 10, sse4);
261 mc_uni_w_func(pel_pixels, 10, 6, sse4);
262 mc_uni_w_funcs(epel_h, 10, sse4);
263 mc_uni_w_func(epel_h, 10, 6, sse4);
264 mc_uni_w_funcs(epel_v, 10, sse4);
265 mc_uni_w_func(epel_v, 10, 6, sse4);
266 mc_uni_w_funcs(epel_hv, 10, sse4);
267 mc_uni_w_func(epel_hv, 10, 6, sse4);
268 mc_uni_w_funcs(qpel_h, 10, sse4);
269 mc_uni_w_funcs(qpel_v, 10, sse4);
270 mc_uni_w_funcs(qpel_hv, 10, sse4);
273 #define mc_bi_w_func(name, bitd, W, opt) \
274 void ff_hevc_put_hevc_bi_w_##name##W##_##bitd##_##opt(uint8_t *_dst, ptrdiff_t _dststride, \
275 uint8_t *_src, ptrdiff_t _srcstride, \
276 int16_t *_src2, ptrdiff_t _src2stride, \
277 int height, int denom, \
278 int _wx0, int _wx1, int _ox0, int _ox1, \
279 intptr_t mx, intptr_t my, int width) \
281 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
282 ff_hevc_put_hevc_##name##W##_##bitd##_##opt(temp, 64, _src, _srcstride, height, mx, my, width); \
283 ff_hevc_put_hevc_bi_w##W##_##bitd##_##opt(_dst, _dststride, temp, 64, _src2, _src2stride, \
284 height, denom, _wx0, _wx1, _ox0, _ox1); \
287 #define mc_bi_w_funcs(name, bitd, opt) \
288 mc_bi_w_func(name, bitd, 4, opt); \
289 mc_bi_w_func(name, bitd, 8, opt); \
290 mc_bi_w_func(name, bitd, 12, opt); \
291 mc_bi_w_func(name, bitd, 16, opt); \
292 mc_bi_w_func(name, bitd, 24, opt); \
293 mc_bi_w_func(name, bitd, 32, opt); \
294 mc_bi_w_func(name, bitd, 48, opt); \
295 mc_bi_w_func(name, bitd, 64, opt)
297 mc_bi_w_funcs(pel_pixels, 8, sse4);
298 mc_bi_w_func(pel_pixels, 8, 6, sse4);
299 mc_bi_w_funcs(epel_h, 8, sse4);
300 mc_bi_w_func(epel_h, 8, 6, sse4);
301 mc_bi_w_funcs(epel_v, 8, sse4);
302 mc_bi_w_func(epel_v, 8, 6, sse4);
303 mc_bi_w_funcs(epel_hv, 8, sse4);
304 mc_bi_w_func(epel_hv, 8, 6, sse4);
305 mc_bi_w_funcs(qpel_h, 8, sse4);
306 mc_bi_w_funcs(qpel_v, 8, sse4);
307 mc_bi_w_funcs(qpel_hv, 8, sse4);
309 mc_bi_w_funcs(pel_pixels, 10, sse4);
310 mc_bi_w_func(pel_pixels, 10, 6, sse4);
311 mc_bi_w_funcs(epel_h, 10, sse4);
312 mc_bi_w_func(epel_h, 10, 6, sse4);
313 mc_bi_w_funcs(epel_v, 10, sse4);
314 mc_bi_w_func(epel_v, 10, 6, sse4);
315 mc_bi_w_funcs(epel_hv, 10, sse4);
316 mc_bi_w_func(epel_hv, 10, 6, sse4);
317 mc_bi_w_funcs(qpel_h, 10, sse4);
318 mc_bi_w_funcs(qpel_v, 10, sse4);
319 mc_bi_w_funcs(qpel_hv, 10, sse4);
321 #endif //ARCH_X86_64 && HAVE_SSE4_EXTERNAL
324 #define EPEL_LINKS(pointer, my, mx, fname, bitd, opt ) \
325 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd, sse4 ); \
326 PEL_LINK(pointer, 2, my , mx , fname##6 , bitd, sse4 ); \
327 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd, sse4 ); \
328 PEL_LINK(pointer, 4, my , mx , fname##12, bitd, sse4 ); \
329 PEL_LINK(pointer, 5, my , mx , fname##16, bitd, sse4 ); \
330 PEL_LINK(pointer, 6, my , mx , fname##24, bitd, sse4 ); \
331 PEL_LINK(pointer, 7, my , mx , fname##32, bitd, sse4 ); \
332 PEL_LINK(pointer, 8, my , mx , fname##48, bitd, sse4 ); \
333 PEL_LINK(pointer, 9, my , mx , fname##64, bitd, sse4 )
334 #define QPEL_LINKS(pointer, my, mx, fname, bitd, sse4) \
335 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd, sse4 ); \
336 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd, sse4 ); \
337 PEL_LINK(pointer, 4, my , mx , fname##12, bitd, sse4 ); \
338 PEL_LINK(pointer, 5, my , mx , fname##16, bitd, sse4 ); \
339 PEL_LINK(pointer, 6, my , mx , fname##24, bitd, sse4 ); \
340 PEL_LINK(pointer, 7, my , mx , fname##32, bitd, sse4 ); \
341 PEL_LINK(pointer, 8, my , mx , fname##48, bitd, sse4 ); \
342 PEL_LINK(pointer, 9, my , mx , fname##64, bitd, sse4 )
345 void ff_hevcdsp_init_x86(HEVCDSPContext *c, const int bit_depth)
347 int mm_flags = av_get_cpu_flags();
349 if (bit_depth == 8) {
350 if (EXTERNAL_SSE4(mm_flags) && ARCH_X86_64) {
352 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 8, sse4);
353 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 8, sse4);
354 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 8, sse4);
355 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 8, sse4);
357 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 8, sse4);
358 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 8, sse4);
359 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 8, sse4);
360 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 8, sse4);
363 } else if (bit_depth == 10) {
364 if (EXTERNAL_SSE4(mm_flags) && ARCH_X86_64) {
366 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 10, sse4);
367 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 10, sse4);
368 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 10, sse4);
369 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 10, sse4);
371 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 10, sse4);
372 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 10, sse4);
373 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 10, sse4);
374 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 10, sse4);