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"
33 #define mc_rep_func(name, bitd, step, W) \
34 void ff_hevc_put_hevc_##name##W##_##bitd##_sse4(int16_t *_dst, ptrdiff_t dststride, \
35 uint8_t *_src, ptrdiff_t _srcstride, int height, \
36 intptr_t mx, intptr_t my, int width) \
41 for (i = 0; i < W; i += step) { \
42 src = _src + (i * ((bitd + 7) / 8)); \
44 ff_hevc_put_hevc_##name##step##_##bitd##_sse4(dst, dststride, src, _srcstride, height, mx, my, width); \
47 #define mc_rep_uni_func(name, bitd, step, W) \
48 void ff_hevc_put_hevc_uni_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, \
49 uint8_t *_src, ptrdiff_t _srcstride, int height, \
50 intptr_t mx, intptr_t my, int width) \
55 for (i = 0; i < W; i += step) { \
56 src = _src + (i * ((bitd + 7) / 8)); \
57 dst = _dst + (i * ((bitd + 7) / 8)); \
58 ff_hevc_put_hevc_uni_##name##step##_##bitd##_sse4(dst, dststride, src, _srcstride, \
59 height, mx, my, width); \
62 #define mc_rep_bi_func(name, bitd, step, W) \
63 void ff_hevc_put_hevc_bi_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, uint8_t *_src, \
64 ptrdiff_t _srcstride, int16_t* _src2, ptrdiff_t _src2stride, \
65 int height, intptr_t mx, intptr_t my, int width) \
71 for (i = 0; i < W ; i += step) { \
72 src = _src + (i * ((bitd + 7) / 8)); \
73 dst = _dst + (i * ((bitd + 7) / 8)); \
75 ff_hevc_put_hevc_bi_##name##step##_##bitd##_sse4(dst, dststride, src, _srcstride, src2, \
76 _src2stride, height, mx, my, width); \
80 #define mc_rep_funcs(name, bitd, step, W) \
81 mc_rep_func(name, bitd, step, W); \
82 mc_rep_uni_func(name, bitd, step, W); \
83 mc_rep_bi_func(name, bitd, step, W)
86 mc_rep_funcs(pel_pixels, 8, 16, 64);
87 mc_rep_funcs(pel_pixels, 8, 16, 48);
88 mc_rep_funcs(pel_pixels, 8, 16, 32);
89 mc_rep_funcs(pel_pixels, 8, 8, 24);
91 mc_rep_funcs(pel_pixels,10, 8, 64);
92 mc_rep_funcs(pel_pixels,10, 8, 48);
93 mc_rep_funcs(pel_pixels,10, 8, 32);
94 mc_rep_funcs(pel_pixels,10, 8, 24);
95 mc_rep_funcs(pel_pixels,10, 8, 16);
96 mc_rep_funcs(pel_pixels,10, 4, 12);
98 mc_rep_funcs(epel_h, 8, 16, 64);
99 mc_rep_funcs(epel_h, 8, 16, 48);
100 mc_rep_funcs(epel_h, 8, 16, 32);
101 mc_rep_funcs(epel_h, 8, 8, 24);
102 mc_rep_funcs(epel_h,10, 8, 64);
103 mc_rep_funcs(epel_h,10, 8, 48);
104 mc_rep_funcs(epel_h,10, 8, 32);
105 mc_rep_funcs(epel_h,10, 8, 24);
106 mc_rep_funcs(epel_h,10, 8, 16);
107 mc_rep_funcs(epel_h,10, 4, 12);
108 mc_rep_funcs(epel_v, 8, 16, 64);
109 mc_rep_funcs(epel_v, 8, 16, 48);
110 mc_rep_funcs(epel_v, 8, 16, 32);
111 mc_rep_funcs(epel_v, 8, 8, 24);
112 mc_rep_funcs(epel_v,10, 8, 64);
113 mc_rep_funcs(epel_v,10, 8, 48);
114 mc_rep_funcs(epel_v,10, 8, 32);
115 mc_rep_funcs(epel_v,10, 8, 24);
116 mc_rep_funcs(epel_v,10, 8, 16);
117 mc_rep_funcs(epel_v,10, 4, 12);
118 mc_rep_funcs(epel_hv, 8, 8, 64);
119 mc_rep_funcs(epel_hv, 8, 8, 48);
120 mc_rep_funcs(epel_hv, 8, 8, 32);
121 mc_rep_funcs(epel_hv, 8, 8, 24);
122 mc_rep_funcs(epel_hv, 8, 8, 16);
123 mc_rep_funcs(epel_hv, 8, 4, 12);
124 mc_rep_funcs(epel_hv,10, 8, 64);
125 mc_rep_funcs(epel_hv,10, 8, 48);
126 mc_rep_funcs(epel_hv,10, 8, 32);
127 mc_rep_funcs(epel_hv,10, 8, 24);
128 mc_rep_funcs(epel_hv,10, 8, 16);
129 mc_rep_funcs(epel_hv,10, 4, 12);
131 mc_rep_funcs(qpel_h, 8, 16, 64);
132 mc_rep_funcs(qpel_h, 8, 16, 48);
133 mc_rep_funcs(qpel_h, 8, 16, 32);
134 mc_rep_funcs(qpel_h, 8, 8, 24);
135 mc_rep_funcs(qpel_h,10, 8, 64);
136 mc_rep_funcs(qpel_h,10, 8, 48);
137 mc_rep_funcs(qpel_h,10, 8, 32);
138 mc_rep_funcs(qpel_h,10, 8, 24);
139 mc_rep_funcs(qpel_h,10, 8, 16);
140 mc_rep_funcs(qpel_h,10, 4, 12);
141 mc_rep_funcs(qpel_v, 8, 16, 64);
142 mc_rep_funcs(qpel_v, 8, 16, 48);
143 mc_rep_funcs(qpel_v, 8, 16, 32);
144 mc_rep_funcs(qpel_v, 8, 8, 24);
145 mc_rep_funcs(qpel_v,10, 8, 64);
146 mc_rep_funcs(qpel_v,10, 8, 48);
147 mc_rep_funcs(qpel_v,10, 8, 32);
148 mc_rep_funcs(qpel_v,10, 8, 24);
149 mc_rep_funcs(qpel_v,10, 8, 16);
150 mc_rep_funcs(qpel_v,10, 4, 12);
151 mc_rep_funcs(qpel_hv, 8, 8, 64);
152 mc_rep_funcs(qpel_hv, 8, 8, 48);
153 mc_rep_funcs(qpel_hv, 8, 8, 32);
154 mc_rep_funcs(qpel_hv, 8, 8, 24);
155 mc_rep_funcs(qpel_hv, 8, 8, 16);
156 mc_rep_funcs(qpel_hv, 8, 4, 12);
157 mc_rep_funcs(qpel_hv,10, 8, 64);
158 mc_rep_funcs(qpel_hv,10, 8, 48);
159 mc_rep_funcs(qpel_hv,10, 8, 32);
160 mc_rep_funcs(qpel_hv,10, 8, 24);
161 mc_rep_funcs(qpel_hv,10, 8, 16);
162 mc_rep_funcs(qpel_hv,10, 4, 12);
164 #define mc_rep_uni_w(bitd, step, W) \
165 void ff_hevc_put_hevc_uni_w##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
166 int height, int denom, int _wx, int _ox) \
171 for (i = 0; i < W; i += step) { \
173 dst= _dst + (i * ((bitd + 7) / 8)); \
174 ff_hevc_put_hevc_uni_w##step##_##bitd##_sse4(dst, dststride, src, _srcstride, \
175 height, denom, _wx, _ox); \
179 mc_rep_uni_w(8, 6, 12);
180 mc_rep_uni_w(8, 8, 16);
181 mc_rep_uni_w(8, 8, 24);
182 mc_rep_uni_w(8, 8, 32);
183 mc_rep_uni_w(8, 8, 48);
184 mc_rep_uni_w(8, 8, 64);
186 mc_rep_uni_w(10, 6, 12);
187 mc_rep_uni_w(10, 8, 16);
188 mc_rep_uni_w(10, 8, 24);
189 mc_rep_uni_w(10, 8, 32);
190 mc_rep_uni_w(10, 8, 48);
191 mc_rep_uni_w(10, 8, 64);
193 #define mc_rep_bi_w(bitd, step, W) \
194 void ff_hevc_put_hevc_bi_w##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t dststride, int16_t *_src, ptrdiff_t _srcstride, \
195 int16_t *_src2, ptrdiff_t _src2stride, int height, \
196 int denom, int _wx0, int _wx1, int _ox0, int _ox1) \
202 for (i = 0; i < W; i += step) { \
205 dst = _dst + (i * ((bitd + 7) / 8)); \
206 ff_hevc_put_hevc_bi_w##step##_##bitd##_sse4(dst, dststride, src, _srcstride, src2, _src2stride, \
207 height, denom, _wx0, _wx1, _ox0, _ox1); \
211 mc_rep_bi_w(8, 6, 12);
212 mc_rep_bi_w(8, 8, 16);
213 mc_rep_bi_w(8, 8, 24);
214 mc_rep_bi_w(8, 8, 32);
215 mc_rep_bi_w(8, 8, 48);
216 mc_rep_bi_w(8, 8, 64);
218 mc_rep_bi_w(10, 6, 12);
219 mc_rep_bi_w(10, 8, 16);
220 mc_rep_bi_w(10, 8, 24);
221 mc_rep_bi_w(10, 8, 32);
222 mc_rep_bi_w(10, 8, 48);
223 mc_rep_bi_w(10, 8, 64);
225 #define mc_uni_w_func(name, bitd, W) \
226 void ff_hevc_put_hevc_uni_w_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t _dststride, \
227 uint8_t *_src, ptrdiff_t _srcstride, \
228 int height, int denom, \
230 intptr_t mx, intptr_t my, int width) \
232 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
233 ff_hevc_put_hevc_##name##W##_##bitd##_sse4(temp, 64, _src, _srcstride, height, mx, my, width); \
234 ff_hevc_put_hevc_uni_w##W##_##bitd##_sse4(_dst, _dststride, temp, 64, height, denom, _wx, _ox); \
237 #define mc_uni_w_funcs(name, bitd) \
238 mc_uni_w_func(name, bitd, 4); \
239 mc_uni_w_func(name, bitd, 8); \
240 mc_uni_w_func(name, bitd, 12); \
241 mc_uni_w_func(name, bitd, 16); \
242 mc_uni_w_func(name, bitd, 24); \
243 mc_uni_w_func(name, bitd, 32); \
244 mc_uni_w_func(name, bitd, 48); \
245 mc_uni_w_func(name, bitd, 64)
247 mc_uni_w_funcs(pel_pixels, 8);
248 mc_uni_w_func(pel_pixels, 8, 6);
249 mc_uni_w_funcs(epel_h, 8);
250 mc_uni_w_func(epel_h, 8, 6);
251 mc_uni_w_funcs(epel_v, 8);
252 mc_uni_w_func(epel_v, 8, 6);
253 mc_uni_w_funcs(epel_hv, 8);
254 mc_uni_w_func(epel_hv, 8, 6);
255 mc_uni_w_funcs(qpel_h, 8);
256 mc_uni_w_funcs(qpel_v, 8);
257 mc_uni_w_funcs(qpel_hv, 8);
259 mc_uni_w_funcs(pel_pixels, 10);
260 mc_uni_w_func(pel_pixels, 10, 6);
261 mc_uni_w_funcs(epel_h, 10);
262 mc_uni_w_func(epel_h, 10, 6);
263 mc_uni_w_funcs(epel_v, 10);
264 mc_uni_w_func(epel_v, 10, 6);
265 mc_uni_w_funcs(epel_hv, 10);
266 mc_uni_w_func(epel_hv, 10, 6);
267 mc_uni_w_funcs(qpel_h, 10);
268 mc_uni_w_funcs(qpel_v, 10);
269 mc_uni_w_funcs(qpel_hv, 10);
272 #define mc_bi_w_func(name, bitd, W) \
273 void ff_hevc_put_hevc_bi_w_##name##W##_##bitd##_sse4(uint8_t *_dst, ptrdiff_t _dststride, \
274 uint8_t *_src, ptrdiff_t _srcstride, \
275 int16_t *_src2, ptrdiff_t _src2stride, \
276 int height, int denom, \
277 int _wx0, int _wx1, int _ox0, int _ox1, \
278 intptr_t mx, intptr_t my, int width) \
280 LOCAL_ALIGNED_16(int16_t, temp, [71 * 64]); \
281 ff_hevc_put_hevc_##name##W##_##bitd##_sse4(temp, 64, _src, _srcstride, height, mx, my, width); \
282 ff_hevc_put_hevc_bi_w##W##_##bitd##_sse4(_dst, _dststride, temp, 64, _src2, _src2stride, \
283 height, denom, _wx0, _wx1, _ox0, _ox1); \
286 #define mc_bi_w_funcs(name, bitd) \
287 mc_bi_w_func(name, bitd, 4); \
288 mc_bi_w_func(name, bitd, 8); \
289 mc_bi_w_func(name, bitd, 12); \
290 mc_bi_w_func(name, bitd, 16); \
291 mc_bi_w_func(name, bitd, 24); \
292 mc_bi_w_func(name, bitd, 32); \
293 mc_bi_w_func(name, bitd, 48); \
294 mc_bi_w_func(name, bitd, 64)
296 mc_bi_w_funcs(pel_pixels, 8);
297 mc_bi_w_func(pel_pixels, 8, 6);
298 mc_bi_w_funcs(epel_h, 8);
299 mc_bi_w_func(epel_h, 8, 6);
300 mc_bi_w_funcs(epel_v, 8);
301 mc_bi_w_func(epel_v, 8, 6);
302 mc_bi_w_funcs(epel_hv, 8);
303 mc_bi_w_func(epel_hv, 8, 6);
304 mc_bi_w_funcs(qpel_h, 8);
305 mc_bi_w_funcs(qpel_v, 8);
306 mc_bi_w_funcs(qpel_hv, 8);
308 mc_bi_w_funcs(pel_pixels, 10);
309 mc_bi_w_func(pel_pixels, 10, 6);
310 mc_bi_w_funcs(epel_h, 10);
311 mc_bi_w_func(epel_h, 10, 6);
312 mc_bi_w_funcs(epel_v, 10);
313 mc_bi_w_func(epel_v, 10, 6);
314 mc_bi_w_funcs(epel_hv, 10);
315 mc_bi_w_func(epel_hv, 10, 6);
316 mc_bi_w_funcs(qpel_h, 10);
317 mc_bi_w_funcs(qpel_v, 10);
318 mc_bi_w_funcs(qpel_hv, 10);
323 #define EPEL_LINKS(pointer, my, mx, fname, bitd) \
324 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd ); \
325 PEL_LINK(pointer, 2, my , mx , fname##6 , bitd ); \
326 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd ); \
327 PEL_LINK(pointer, 4, my , mx , fname##12, bitd ); \
328 PEL_LINK(pointer, 5, my , mx , fname##16, bitd ); \
329 PEL_LINK(pointer, 6, my , mx , fname##24, bitd ); \
330 PEL_LINK(pointer, 7, my , mx , fname##32, bitd ); \
331 PEL_LINK(pointer, 8, my , mx , fname##48, bitd ); \
332 PEL_LINK(pointer, 9, my , mx , fname##64, bitd )
333 #define QPEL_LINKS(pointer, my, mx, fname, bitd) \
334 PEL_LINK(pointer, 1, my , mx , fname##4 , bitd ); \
335 PEL_LINK(pointer, 3, my , mx , fname##8 , bitd ); \
336 PEL_LINK(pointer, 4, my , mx , fname##12, bitd ); \
337 PEL_LINK(pointer, 5, my , mx , fname##16, bitd ); \
338 PEL_LINK(pointer, 6, my , mx , fname##24, bitd ); \
339 PEL_LINK(pointer, 7, my , mx , fname##32, bitd ); \
340 PEL_LINK(pointer, 8, my , mx , fname##48, bitd ); \
341 PEL_LINK(pointer, 9, my , mx , fname##64, bitd )
344 void ff_hevcdsp_init_x86(HEVCDSPContext *c, const int bit_depth)
346 int mm_flags = av_get_cpu_flags();
348 if (bit_depth == 8) {
349 if (EXTERNAL_MMX(mm_flags)) {
351 if (EXTERNAL_MMXEXT(mm_flags)) {
353 if (EXTERNAL_SSSE3(mm_flags) && ARCH_X86_64) {
355 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 8);
356 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 8);
357 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 8);
358 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 8);
360 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 8);
361 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 8);
362 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 8);
363 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 8);
368 } else if (bit_depth == 10) {
369 if (EXTERNAL_MMX(mm_flags)) {
370 if (EXTERNAL_MMXEXT(mm_flags) && ARCH_X86_64) {
372 if (EXTERNAL_SSSE3(mm_flags)) {
374 EPEL_LINKS(c->put_hevc_epel, 0, 0, pel_pixels, 10);
375 EPEL_LINKS(c->put_hevc_epel, 0, 1, epel_h, 10);
376 EPEL_LINKS(c->put_hevc_epel, 1, 0, epel_v, 10);
377 EPEL_LINKS(c->put_hevc_epel, 1, 1, epel_hv, 10);
379 QPEL_LINKS(c->put_hevc_qpel, 0, 0, pel_pixels, 10);
380 QPEL_LINKS(c->put_hevc_qpel, 0, 1, qpel_h, 10);
381 QPEL_LINKS(c->put_hevc_qpel, 1, 0, qpel_v, 10);
382 QPEL_LINKS(c->put_hevc_qpel, 1, 1, qpel_hv, 10);