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) \
33 void ff_hevc_put_hevc_##name##W##_##bitd##_sse4(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##_sse4(dst, dststride, src, _srcstride, height, mx, my, width); \
46 #define mc_rep_uni_func(name, bitd, step, W) \
47 void ff_hevc_put_hevc_uni_##name##W##_##bitd##_sse4(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##_sse4(dst, dststride, src, _srcstride, \
58 height, mx, my, width); \
61 #define mc_rep_bi_func(name, bitd, step, W) \
62 void ff_hevc_put_hevc_bi_##name##W##_##bitd##_sse4(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##_sse4(dst, dststride, src, _srcstride, src2, \
75 _src2stride, height, mx, my, width); \
79 #define mc_rep_funcs(name, bitd, step, W) \
80 mc_rep_func(name, bitd, step, W); \
81 mc_rep_uni_func(name, bitd, step, W); \
82 mc_rep_bi_func(name, bitd, step, W)
85 mc_rep_funcs(pel_pixels, 8, 16, 64);
86 mc_rep_funcs(pel_pixels, 8, 16, 48);
87 mc_rep_funcs(pel_pixels, 8, 16, 32);
88 mc_rep_funcs(pel_pixels, 8, 8, 24);
90 mc_rep_funcs(pel_pixels,10, 8, 64);
91 mc_rep_funcs(pel_pixels,10, 8, 48);
92 mc_rep_funcs(pel_pixels,10, 8, 32);
93 mc_rep_funcs(pel_pixels,10, 8, 24);
94 mc_rep_funcs(pel_pixels,10, 8, 16);
95 mc_rep_funcs(pel_pixels,10, 4, 12);
97 mc_rep_funcs(epel_h, 8, 16, 64);
98 mc_rep_funcs(epel_h, 8, 16, 48);
99 mc_rep_funcs(epel_h, 8, 16, 32);
100 mc_rep_funcs(epel_h, 8, 8, 24);
101 mc_rep_funcs(epel_h,10, 8, 64);
102 mc_rep_funcs(epel_h,10, 8, 48);
103 mc_rep_funcs(epel_h,10, 8, 32);
104 mc_rep_funcs(epel_h,10, 8, 24);
105 mc_rep_funcs(epel_h,10, 8, 16);
106 mc_rep_funcs(epel_h,10, 4, 12);
107 mc_rep_funcs(epel_v, 8, 16, 64);
108 mc_rep_funcs(epel_v, 8, 16, 48);
109 mc_rep_funcs(epel_v, 8, 16, 32);
110 mc_rep_funcs(epel_v, 8, 8, 24);
111 mc_rep_funcs(epel_v,10, 8, 64);
112 mc_rep_funcs(epel_v,10, 8, 48);
113 mc_rep_funcs(epel_v,10, 8, 32);
114 mc_rep_funcs(epel_v,10, 8, 24);
115 mc_rep_funcs(epel_v,10, 8, 16);
116 mc_rep_funcs(epel_v,10, 4, 12);
117 mc_rep_funcs(epel_hv, 8, 8, 64);
118 mc_rep_funcs(epel_hv, 8, 8, 48);
119 mc_rep_funcs(epel_hv, 8, 8, 32);
120 mc_rep_funcs(epel_hv, 8, 8, 24);
121 mc_rep_funcs(epel_hv, 8, 8, 16);
122 mc_rep_funcs(epel_hv, 8, 4, 12);
123 mc_rep_funcs(epel_hv,10, 8, 64);
124 mc_rep_funcs(epel_hv,10, 8, 48);
125 mc_rep_funcs(epel_hv,10, 8, 32);
126 mc_rep_funcs(epel_hv,10, 8, 24);
127 mc_rep_funcs(epel_hv,10, 8, 16);
128 mc_rep_funcs(epel_hv,10, 4, 12);
130 mc_rep_funcs(qpel_h, 8, 16, 64);
131 mc_rep_funcs(qpel_h, 8, 16, 48);
132 mc_rep_funcs(qpel_h, 8, 16, 32);
133 mc_rep_funcs(qpel_h, 8, 8, 24);
134 mc_rep_funcs(qpel_h,10, 8, 64);
135 mc_rep_funcs(qpel_h,10, 8, 48);
136 mc_rep_funcs(qpel_h,10, 8, 32);
137 mc_rep_funcs(qpel_h,10, 8, 24);
138 mc_rep_funcs(qpel_h,10, 8, 16);
139 mc_rep_funcs(qpel_h,10, 4, 12);
140 mc_rep_funcs(qpel_v, 8, 16, 64);
141 mc_rep_funcs(qpel_v, 8, 16, 48);
142 mc_rep_funcs(qpel_v, 8, 16, 32);
143 mc_rep_funcs(qpel_v, 8, 8, 24);
144 mc_rep_funcs(qpel_v,10, 8, 64);
145 mc_rep_funcs(qpel_v,10, 8, 48);
146 mc_rep_funcs(qpel_v,10, 8, 32);
147 mc_rep_funcs(qpel_v,10, 8, 24);
148 mc_rep_funcs(qpel_v,10, 8, 16);
149 mc_rep_funcs(qpel_v,10, 4, 12);
150 mc_rep_funcs(qpel_hv, 8, 8, 64);
151 mc_rep_funcs(qpel_hv, 8, 8, 48);
152 mc_rep_funcs(qpel_hv, 8, 8, 32);
153 mc_rep_funcs(qpel_hv, 8, 8, 24);
154 mc_rep_funcs(qpel_hv, 8, 8, 16);
155 mc_rep_funcs(qpel_hv, 8, 4, 12);
156 mc_rep_funcs(qpel_hv,10, 8, 64);
157 mc_rep_funcs(qpel_hv,10, 8, 48);
158 mc_rep_funcs(qpel_hv,10, 8, 32);
159 mc_rep_funcs(qpel_hv,10, 8, 24);
160 mc_rep_funcs(qpel_hv,10, 8, 16);
161 mc_rep_funcs(qpel_hv,10, 4, 12);
163 #define mc_rep_uni_w(bitd, step, W) \
164 void ff_hevc_put_hevc_uni_w##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
165 int height, int denom, int _wx, int _ox) \
170 for (i = 0; i < W; i += step) { \
172 dst= _dst + (i * ((bitd + 7) / 8)); \
173 ff_hevc_put_hevc_uni_w##step##_##bitd##_sse4(dst, dststride, src, _srcstride, \
174 height, denom, _wx, _ox); \
178 mc_rep_uni_w(8, 6, 12);
179 mc_rep_uni_w(8, 8, 16);
180 mc_rep_uni_w(8, 8, 24);
181 mc_rep_uni_w(8, 8, 32);
182 mc_rep_uni_w(8, 8, 48);
183 mc_rep_uni_w(8, 8, 64);
185 mc_rep_uni_w(10, 6, 12);
186 mc_rep_uni_w(10, 8, 16);
187 mc_rep_uni_w(10, 8, 24);
188 mc_rep_uni_w(10, 8, 32);
189 mc_rep_uni_w(10, 8, 48);
190 mc_rep_uni_w(10, 8, 64);
192 #define mc_rep_bi_w(bitd, step, W) \
193 void ff_hevc_put_hevc_bi_w##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
194 int16_t *_src2, ptrdiff_t _src2stride, int height, \
195 int denom, int _wx0, int _wx1, int _ox0, int _ox1) \
201 for (i = 0; i < W; i += step) { \
204 dst = _dst + (i * ((bitd + 7) / 8)); \
205 ff_hevc_put_hevc_bi_w##step##_##bitd##_sse4(dst, dststride, src, _srcstride, src2, _src2stride, \
206 height, denom, _wx0, _wx1, _ox0, _ox1); \
210 mc_rep_bi_w(8, 6, 12);
211 mc_rep_bi_w(8, 8, 16);
212 mc_rep_bi_w(8, 8, 24);
213 mc_rep_bi_w(8, 8, 32);
214 mc_rep_bi_w(8, 8, 48);
215 mc_rep_bi_w(8, 8, 64);
217 mc_rep_bi_w(10, 6, 12);
218 mc_rep_bi_w(10, 8, 16);
219 mc_rep_bi_w(10, 8, 24);
220 mc_rep_bi_w(10, 8, 32);
221 mc_rep_bi_w(10, 8, 48);
222 mc_rep_bi_w(10, 8, 64);
224 #define mc_uni_w_func(name, bitd, W) \
225 void ff_hevc_put_hevc_uni_w_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t _dststride, \
226 uint8_t *_src, ptrdiff_t _srcstride, \
227 int height, int denom, \
229 intptr_t mx, intptr_t my, int width) \
231 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
232 ff_hevc_put_hevc_##name##W##_##bitd##_sse4(temp, 64, _src, _srcstride, height, mx, my, width); \
233 ff_hevc_put_hevc_uni_w##W##_##bitd##_sse4(_dst, _dststride, temp, 64, height, denom, _wx, _ox); \
236 #define mc_uni_w_funcs(name, bitd) \
237 mc_uni_w_func(name, bitd, 4); \
238 mc_uni_w_func(name, bitd, 8); \
239 mc_uni_w_func(name, bitd, 12); \
240 mc_uni_w_func(name, bitd, 16); \
241 mc_uni_w_func(name, bitd, 24); \
242 mc_uni_w_func(name, bitd, 32); \
243 mc_uni_w_func(name, bitd, 48); \
244 mc_uni_w_func(name, bitd, 64)
246 mc_uni_w_funcs(pel_pixels, 8);
247 mc_uni_w_func(pel_pixels, 8, 6);
248 mc_uni_w_funcs(epel_h, 8);
249 mc_uni_w_func(epel_h, 8, 6);
250 mc_uni_w_funcs(epel_v, 8);
251 mc_uni_w_func(epel_v, 8, 6);
252 mc_uni_w_funcs(epel_hv, 8);
253 mc_uni_w_func(epel_hv, 8, 6);
254 mc_uni_w_funcs(qpel_h, 8);
255 mc_uni_w_funcs(qpel_v, 8);
256 mc_uni_w_funcs(qpel_hv, 8);
258 mc_uni_w_funcs(pel_pixels, 10);
259 mc_uni_w_func(pel_pixels, 10, 6);
260 mc_uni_w_funcs(epel_h, 10);
261 mc_uni_w_func(epel_h, 10, 6);
262 mc_uni_w_funcs(epel_v, 10);
263 mc_uni_w_func(epel_v, 10, 6);
264 mc_uni_w_funcs(epel_hv, 10);
265 mc_uni_w_func(epel_hv, 10, 6);
266 mc_uni_w_funcs(qpel_h, 10);
267 mc_uni_w_funcs(qpel_v, 10);
268 mc_uni_w_funcs(qpel_hv, 10);
271 #define mc_bi_w_func(name, bitd, W) \
272 void ff_hevc_put_hevc_bi_w_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t _dststride, \
273 uint8_t *_src, ptrdiff_t _srcstride, \
274 int16_t *_src2, ptrdiff_t _src2stride, \
275 int height, int denom, \
276 int _wx0, int _wx1, int _ox0, int _ox1, \
277 intptr_t mx, intptr_t my, int width) \
279 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
280 ff_hevc_put_hevc_##name##W##_##bitd##_sse4(temp, 64, _src, _srcstride, height, mx, my, width); \
281 ff_hevc_put_hevc_bi_w##W##_##bitd##_sse4(_dst, _dststride, temp, 64, _src2, _src2stride, \
282 height, denom, _wx0, _wx1, _ox0, _ox1); \
285 #define mc_bi_w_funcs(name, bitd) \
286 mc_bi_w_func(name, bitd, 4); \
287 mc_bi_w_func(name, bitd, 8); \
288 mc_bi_w_func(name, bitd, 12); \
289 mc_bi_w_func(name, bitd, 16); \
290 mc_bi_w_func(name, bitd, 24); \
291 mc_bi_w_func(name, bitd, 32); \
292 mc_bi_w_func(name, bitd, 48); \
293 mc_bi_w_func(name, bitd, 64)
295 mc_bi_w_funcs(pel_pixels, 8);
296 mc_bi_w_func(pel_pixels, 8, 6);
297 mc_bi_w_funcs(epel_h, 8);
298 mc_bi_w_func(epel_h, 8, 6);
299 mc_bi_w_funcs(epel_v, 8);
300 mc_bi_w_func(epel_v, 8, 6);
301 mc_bi_w_funcs(epel_hv, 8);
302 mc_bi_w_func(epel_hv, 8, 6);
303 mc_bi_w_funcs(qpel_h, 8);
304 mc_bi_w_funcs(qpel_v, 8);
305 mc_bi_w_funcs(qpel_hv, 8);
307 mc_bi_w_funcs(pel_pixels, 10);
308 mc_bi_w_func(pel_pixels, 10, 6);
309 mc_bi_w_funcs(epel_h, 10);
310 mc_bi_w_func(epel_h, 10, 6);
311 mc_bi_w_funcs(epel_v, 10);
312 mc_bi_w_func(epel_v, 10, 6);
313 mc_bi_w_funcs(epel_hv, 10);
314 mc_bi_w_func(epel_hv, 10, 6);
315 mc_bi_w_funcs(qpel_h, 10);
316 mc_bi_w_funcs(qpel_v, 10);
317 mc_bi_w_funcs(qpel_hv, 10);
320 #define EPEL_LINKS(pointer, my, mx, fname, bitd) \
321 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd ); \
322 PEL_LINK(pointer, 2, my , mx , fname##6 , bitd ); \
323 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd ); \
324 PEL_LINK(pointer, 4, my , mx , fname##12, bitd ); \
325 PEL_LINK(pointer, 5, my , mx , fname##16, bitd ); \
326 PEL_LINK(pointer, 6, my , mx , fname##24, bitd ); \
327 PEL_LINK(pointer, 7, my , mx , fname##32, bitd ); \
328 PEL_LINK(pointer, 8, my , mx , fname##48, bitd ); \
329 PEL_LINK(pointer, 9, my , mx , fname##64, bitd )
330 #define QPEL_LINKS(pointer, my, mx, fname, bitd) \
331 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd ); \
332 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd ); \
333 PEL_LINK(pointer, 4, my , mx , fname##12, bitd ); \
334 PEL_LINK(pointer, 5, my , mx , fname##16, bitd ); \
335 PEL_LINK(pointer, 6, my , mx , fname##24, bitd ); \
336 PEL_LINK(pointer, 7, my , mx , fname##32, bitd ); \
337 PEL_LINK(pointer, 8, my , mx , fname##48, bitd ); \
338 PEL_LINK(pointer, 9, my , mx , fname##64, bitd )
341 void ff_hevcdsp_init_x86(HEVCDSPContext *c, const int bit_depth)
343 int mm_flags = av_get_cpu_flags();
345 if (bit_depth == 8) {
346 if (EXTERNAL_MMX(mm_flags)) {
348 if (EXTERNAL_MMXEXT(mm_flags)) {
350 if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
352 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 8);
353 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 8);
354 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 8);
355 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 8);
357 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 8);
358 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 8);
359 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 8);
360 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 8);
365 } else if (bit_depth == 10) {
366 if (EXTERNAL_MMX(mm_flags)) {
367 if (EXTERNAL_MMXEXT(mm_flags) && ARCH_X86_64) {
369 if (EXTERNAL_SSSE3(mm_flags)) {
371 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 10);
372 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 10);
373 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 10);
374 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 10);
376 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 10);
377 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 10);
378 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 10);
379 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 10);