x86: hevc: Fix linking with both yasm and optimizations disabled
[libav.git] / libavcodec / x86 / hevcdsp_init.c
CommitLineData
1a880b2f
PEL
1/*
2 * Copyright (c) 2013 Seppo Tomperi
3 * Copyright (c) 2013 - 2014 Pierre-Edouard Lepere
4 *
5 * This file is part of Libav.
6 *
7 * Libav is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * Libav is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with Libav; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22#include "config.h"
23
24#include "libavutil/cpu.h"
25#include "libavutil/x86/cpu.h"
26
27#include "libavcodec/hevcdsp.h"
28
29#define LFC_FUNC(DIR, DEPTH, OPT) \
30void ff_hevc_ ## DIR ## _loop_filter_chroma_ ## DEPTH ## _ ## OPT(uint8_t *pix, ptrdiff_t stride, int *tc, uint8_t *no_p, uint8_t *no_q);
31
32#define LFL_FUNC(DIR, DEPTH, OPT) \
33void ff_hevc_ ## DIR ## _loop_filter_luma_ ## DEPTH ## _ ## OPT(uint8_t *pix, ptrdiff_t stride, int beta, int *tc, uint8_t *no_p, uint8_t *no_q);
34
35#define LFC_FUNCS(type, depth) \
36 LFC_FUNC(h, depth, sse2) \
37 LFC_FUNC(v, depth, sse2)
38
39#define LFL_FUNCS(type, depth) \
40 LFL_FUNC(h, depth, ssse3) \
41 LFL_FUNC(v, depth, ssse3)
42
43LFC_FUNCS(uint8_t, 8)
44LFC_FUNCS(uint8_t, 10)
45LFL_FUNCS(uint8_t, 8)
46LFL_FUNCS(uint8_t, 10)
47
e7078e84
AK
48#define GET_PIXELS(width, depth, cf) \
49void ff_hevc_get_pixels_ ## width ## _ ## depth ## _ ## cf(int16_t *dst, ptrdiff_t dststride, \
50 uint8_t *src, ptrdiff_t srcstride, \
51 int height, int mx, int my, int16_t *mcbuffer);
52
53GET_PIXELS(4, 8, sse2)
54GET_PIXELS(8, 8, sse2)
55GET_PIXELS(12, 8, sse2)
56GET_PIXELS(16, 8, sse2)
57GET_PIXELS(24, 8, sse2)
58GET_PIXELS(32, 8, sse2)
59GET_PIXELS(48, 8, sse2)
60GET_PIXELS(64, 8, sse2)
61
62GET_PIXELS(4, 10, sse2)
63GET_PIXELS(8, 10, sse2)
64GET_PIXELS(12, 10, sse2)
65GET_PIXELS(16, 10, sse2)
66GET_PIXELS(24, 10, sse2)
67GET_PIXELS(32, 10, sse2)
68GET_PIXELS(48, 10, sse2)
69GET_PIXELS(64, 10, sse2)
70
71/* those are independent of the bit depth, so declared separately */
72#define INTERP_HV_FUNC(width, cf) \
73void ff_hevc_qpel_hv_ ## width ## _ ## cf(int16_t *dst, ptrdiff_t dststride, \
74 int16_t *src, ptrdiff_t srcstride, \
75 int height, int mx, int my, int16_t *mcbuffer); \
76void ff_hevc_epel_hv_ ## width ## _ ## cf(int16_t *dst, ptrdiff_t dststride, \
77 int16_t *src, ptrdiff_t srcstride, \
78 int height, int mx, int my, int16_t *mcbuffer);
79
80INTERP_HV_FUNC(4, avx)
81INTERP_HV_FUNC(8, avx)
82INTERP_HV_FUNC(12, avx)
83INTERP_HV_FUNC(16, avx)
84INTERP_HV_FUNC(24, avx)
85INTERP_HV_FUNC(32, avx)
86INTERP_HV_FUNC(48, avx)
87INTERP_HV_FUNC(64, avx)
88
257b30af 89#if ARCH_X86_64 && HAVE_AVX_EXTERNAL
e7078e84
AK
90#define QPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv) \
91static void hevc_qpel_hv_ ## width ## _ ## depth ## _ ## cf_hv(int16_t *dst, ptrdiff_t dststride, \
92 uint8_t *src, ptrdiff_t srcstride, \
93 int height, int mx, int my, int16_t *mcbuffer) \
94{ \
95 const ptrdiff_t stride = FFALIGN(width + 7, 8); \
96 ff_hevc_qpel_h_ ## width ## _ ## depth ## _ ## cf_h(mcbuffer, 2 * stride, src - 3 * srcstride, srcstride, \
97 height + 7, mx, my, mcbuffer); \
98 ff_hevc_qpel_hv_ ## width ## _ ## cf_hv(dst, dststride, mcbuffer + 3 * stride, 2 * stride, \
99 height, mx, my, mcbuffer); \
100}
101#else
102#define QPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
257b30af 103#endif /* ARCH_X86_64 && HAVE_AVX_EXTERNAL */
e7078e84
AK
104
105#define QPEL_FUNCS(width, depth, cf_h, cf_v, cf_hv) \
106void ff_hevc_qpel_h_ ## width ## _ ## depth ## _ ## cf_h(int16_t *dst, ptrdiff_t dststride, \
107 uint8_t *src, ptrdiff_t srcstride, \
108 int height, int mx, int my, int16_t *mcbuffer); \
109void ff_hevc_qpel_v_ ## width ## _ ## depth ## _ ## cf_v(int16_t *dst, ptrdiff_t dststride, \
110 uint8_t *src, ptrdiff_t srcstride, \
111 int height, int mx, int my, int16_t *mcbuffer); \
112QPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
113
114QPEL_FUNCS(4, 8, ssse3, ssse3, avx)
115QPEL_FUNCS(8, 8, ssse3, ssse3, avx)
116QPEL_FUNCS(12, 8, ssse3, ssse3, avx)
117QPEL_FUNCS(16, 8, ssse3, ssse3, avx)
118QPEL_FUNCS(24, 8, ssse3, ssse3, avx)
119QPEL_FUNCS(32, 8, ssse3, ssse3, avx)
120QPEL_FUNCS(48, 8, ssse3, ssse3, avx)
121QPEL_FUNCS(64, 8, ssse3, ssse3, avx)
122
123QPEL_FUNCS(4, 10, avx, avx, avx)
124QPEL_FUNCS(8, 10, avx, avx, avx)
125QPEL_FUNCS(12, 10, avx, avx, avx)
126QPEL_FUNCS(16, 10, avx, avx, avx)
127QPEL_FUNCS(24, 10, avx, avx, avx)
128QPEL_FUNCS(32, 10, avx, avx, avx)
129QPEL_FUNCS(48, 10, avx, avx, avx)
130QPEL_FUNCS(64, 10, avx, avx, avx)
131
257b30af 132#if ARCH_X86_64 && HAVE_AVX_EXTERNAL
e7078e84
AK
133#define EPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv) \
134static void hevc_epel_hv_ ## width ## _ ## depth ## _ ## cf_hv(int16_t *dst, ptrdiff_t dststride, \
135 uint8_t *src, ptrdiff_t srcstride, \
136 int height, int mx, int my, int16_t *mcbuffer) \
137{ \
138 const ptrdiff_t stride = FFALIGN(width + 3, 8); \
139 ff_hevc_epel_h_ ## width ## _ ## depth ## _ ## cf_h(mcbuffer, 2 * stride, src - srcstride, srcstride, \
140 height + 3, mx, my, mcbuffer); \
141 ff_hevc_epel_hv_ ## width ## _ ## cf_hv(dst, dststride, mcbuffer + stride, 2 * stride, \
142 height, mx, my, mcbuffer); \
143}
144#else
145#define EPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
257b30af 146#endif /* ARCH_X86_64 && HAVE_AVX_EXTERNAL */
e7078e84
AK
147
148#define EPEL_FUNCS(width, depth, cf_h, cf_v, cf_hv) \
149void ff_hevc_epel_h_ ## width ## _ ## depth ## _ ## cf_h(int16_t *dst, ptrdiff_t dststride, \
150 uint8_t *src, ptrdiff_t srcstride, \
151 int height, int mx, int my, int16_t *mcbuffer); \
152void ff_hevc_epel_v_ ## width ## _ ## depth ## _ ## cf_v(int16_t *dst, ptrdiff_t dststride, \
153 uint8_t *src, ptrdiff_t srcstride, \
154 int height, int mx, int my, int16_t *mcbuffer); \
155EPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
156
157EPEL_FUNCS(4, 8, ssse3, ssse3, avx)
158EPEL_FUNCS(8, 8, ssse3, ssse3, avx)
159EPEL_FUNCS(12, 8, ssse3, ssse3, avx)
160EPEL_FUNCS(16, 8, ssse3, ssse3, avx)
161EPEL_FUNCS(24, 8, ssse3, ssse3, avx)
162EPEL_FUNCS(32, 8, ssse3, ssse3, avx)
163
164EPEL_FUNCS(4, 10, avx, avx, avx)
165EPEL_FUNCS(8, 10, avx, avx, avx)
166EPEL_FUNCS(12, 10, avx, avx, avx)
167EPEL_FUNCS(16, 10, avx, avx, avx)
168EPEL_FUNCS(24, 10, avx, avx, avx)
169EPEL_FUNCS(32, 10, avx, avx, avx)
170
171#define PUT_PRED(width, depth, cf_uw, cf_w) \
172void ff_hevc_put_unweighted_pred_ ## width ## _ ## depth ## _ ## cf_uw(uint8_t *dst, ptrdiff_t dststride, \
173 int16_t *src, ptrdiff_t srcstride, \
174 int height); \
175void ff_hevc_put_unweighted_pred_avg_ ## width ## _ ## depth ## _ ## cf_uw(uint8_t *dst, ptrdiff_t dststride, \
176 int16_t *src1, int16_t *src2, \
177 ptrdiff_t srcstride, int height); \
178void ff_hevc_put_weighted_pred_ ## width ## _ ## depth ## _ ## cf_w(uint8_t denom, int16_t weight, int16_t offset, \
179 uint8_t *dst, ptrdiff_t dststride, \
180 int16_t *src, ptrdiff_t srcstride, \
181 int height); \
182void ff_hevc_put_weighted_pred_avg_ ## width ## _ ## depth ## _ ## cf_w(uint8_t denom, int16_t weight0, int16_t weight1, \
183 int16_t offset0, int16_t offset1, \
184 uint8_t *dst, ptrdiff_t dststride, \
185 int16_t *src0, int16_t *src1, ptrdiff_t srcstride, \
186 int height);
187
188PUT_PRED(4, 8, sse2, sse4)
189PUT_PRED(8, 8, sse2, sse4)
190PUT_PRED(12, 8, sse2, sse4)
191PUT_PRED(16, 8, sse2, sse4)
192PUT_PRED(24, 8, sse2, sse4)
193PUT_PRED(32, 8, sse2, sse4)
194PUT_PRED(48, 8, sse2, sse4)
195PUT_PRED(64, 8, sse2, sse4)
196
197PUT_PRED(4, 10, sse2, sse4)
198PUT_PRED(8, 10, sse2, sse4)
199PUT_PRED(12, 10, sse2, sse4)
200PUT_PRED(16, 10, sse2, sse4)
201PUT_PRED(24, 10, sse2, sse4)
202PUT_PRED(32, 10, sse2, sse4)
203PUT_PRED(48, 10, sse2, sse4)
204PUT_PRED(64, 10, sse2, sse4)
205
1a880b2f
PEL
206void ff_hevc_dsp_init_x86(HEVCDSPContext *c, const int bit_depth)
207{
208 int cpu_flags = av_get_cpu_flags();
209
e7078e84
AK
210#define SET_LUMA_FUNCS(tabname, funcname, depth, cf) \
211 c->tabname[0] = funcname ## _4_ ## depth ## _ ## cf; \
212 c->tabname[1] = funcname ## _8_ ## depth ## _ ## cf; \
213 c->tabname[2] = funcname ## _12_ ## depth ## _ ## cf; \
214 c->tabname[3] = funcname ## _16_ ## depth ## _ ## cf; \
215 c->tabname[4] = funcname ## _24_ ## depth ## _ ## cf; \
216 c->tabname[5] = funcname ## _32_ ## depth ## _ ## cf; \
217 c->tabname[6] = funcname ## _48_ ## depth ## _ ## cf; \
218 c->tabname[7] = funcname ## _64_ ## depth ## _ ## cf;
219
220#define SET_CHROMA_FUNCS(tabname, funcname, depth, cf) \
221 c->tabname[1] = funcname ## _4_ ## depth ## _ ## cf; \
222 c->tabname[3] = funcname ## _8_ ## depth ## _ ## cf; \
223 c->tabname[4] = funcname ## _12_ ## depth ## _ ## cf; \
224 c->tabname[5] = funcname ## _16_ ## depth ## _ ## cf; \
225 c->tabname[6] = funcname ## _24_ ## depth ## _ ## cf; \
226 c->tabname[7] = funcname ## _32_ ## depth ## _ ## cf;
227
228#define SET_QPEL_FUNCS(v, h, depth, cf, name) SET_LUMA_FUNCS (put_hevc_qpel[v][h], name, depth, cf)
229#define SET_EPEL_FUNCS(v, h, depth, cf, name) SET_CHROMA_FUNCS(put_hevc_epel[v][h], name, depth, cf)
230
1a880b2f
PEL
231 if (bit_depth == 8) {
232 if (EXTERNAL_SSE2(cpu_flags)) {
233 c->hevc_v_loop_filter_chroma = ff_hevc_v_loop_filter_chroma_8_sse2;
234 c->hevc_h_loop_filter_chroma = ff_hevc_h_loop_filter_chroma_8_sse2;
e7078e84
AK
235
236 SET_QPEL_FUNCS(0, 0, 8, sse2, ff_hevc_get_pixels);
237 SET_EPEL_FUNCS(0, 0, 8, sse2, ff_hevc_get_pixels);
238
239 SET_LUMA_FUNCS(put_unweighted_pred, ff_hevc_put_unweighted_pred, 8, sse2);
240 SET_LUMA_FUNCS(put_unweighted_pred_avg, ff_hevc_put_unweighted_pred_avg, 8, sse2);
241 SET_CHROMA_FUNCS(put_unweighted_pred_chroma, ff_hevc_put_unweighted_pred, 8, sse2);
242 SET_CHROMA_FUNCS(put_unweighted_pred_avg_chroma, ff_hevc_put_unweighted_pred_avg, 8, sse2);
1a880b2f 243 }
e7078e84
AK
244 if (EXTERNAL_SSSE3(cpu_flags)) {
245 SET_QPEL_FUNCS(0, 1, 8, ssse3, ff_hevc_qpel_h);
246 SET_QPEL_FUNCS(1, 0, 8, ssse3, ff_hevc_qpel_v);
247 SET_EPEL_FUNCS(0, 1, 8, ssse3, ff_hevc_epel_h);
248 SET_EPEL_FUNCS(1, 0, 8, ssse3, ff_hevc_epel_v);
1a880b2f
PEL
249 }
250 } else if (bit_depth == 10) {
251 if (EXTERNAL_SSE2(cpu_flags)) {
252 c->hevc_v_loop_filter_chroma = ff_hevc_v_loop_filter_chroma_10_sse2;
253 c->hevc_h_loop_filter_chroma = ff_hevc_h_loop_filter_chroma_10_sse2;
e7078e84
AK
254
255 SET_QPEL_FUNCS(0, 0, 10, sse2, ff_hevc_get_pixels);
256 SET_EPEL_FUNCS(0, 0, 10, sse2, ff_hevc_get_pixels);
257
258 SET_LUMA_FUNCS(put_unweighted_pred, ff_hevc_put_unweighted_pred, 10, sse2);
259 SET_LUMA_FUNCS(put_unweighted_pred_avg, ff_hevc_put_unweighted_pred_avg, 10, sse2);
260 SET_CHROMA_FUNCS(put_unweighted_pred_chroma, ff_hevc_put_unweighted_pred, 10, sse2);
261 SET_CHROMA_FUNCS(put_unweighted_pred_avg_chroma, ff_hevc_put_unweighted_pred_avg, 10, sse2);
262 }
263 }
264
265#if ARCH_X86_64
266 if (bit_depth == 8) {
267 if (EXTERNAL_SSSE3(cpu_flags)) {
268 c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_8_ssse3;
269 c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_8_ssse3;
270 }
271
272 if (EXTERNAL_SSE4(cpu_flags)) {
273 SET_LUMA_FUNCS(weighted_pred, ff_hevc_put_weighted_pred, 8, sse4);
274 SET_CHROMA_FUNCS(weighted_pred_chroma, ff_hevc_put_weighted_pred, 8, sse4);
275 SET_LUMA_FUNCS(weighted_pred_avg, ff_hevc_put_weighted_pred_avg, 8, sse4);
276 SET_CHROMA_FUNCS(weighted_pred_avg_chroma, ff_hevc_put_weighted_pred_avg, 8, sse4);
1a880b2f 277 }
e7078e84
AK
278
279 if (EXTERNAL_AVX(cpu_flags)) {
257b30af 280#if HAVE_AVX_EXTERNAL
e7078e84
AK
281 SET_QPEL_FUNCS(1, 1, 8, avx, hevc_qpel_hv);
282 SET_EPEL_FUNCS(1, 1, 8, avx, hevc_epel_hv);
257b30af 283#endif /* HAVE_AVX_EXTERNAL */
e7078e84
AK
284 }
285 } else if (bit_depth == 10) {
286 if (EXTERNAL_SSSE3(cpu_flags)) {
1a880b2f
PEL
287 c->hevc_v_loop_filter_luma = ff_hevc_v_loop_filter_luma_10_ssse3;
288 c->hevc_h_loop_filter_luma = ff_hevc_h_loop_filter_luma_10_ssse3;
289 }
e7078e84
AK
290 if (EXTERNAL_SSE4(cpu_flags)) {
291 SET_LUMA_FUNCS(weighted_pred, ff_hevc_put_weighted_pred, 10, sse4);
292 SET_CHROMA_FUNCS(weighted_pred_chroma, ff_hevc_put_weighted_pred, 10, sse4);
293 SET_LUMA_FUNCS(weighted_pred_avg, ff_hevc_put_weighted_pred_avg, 10, sse4);
294 SET_CHROMA_FUNCS(weighted_pred_avg_chroma, ff_hevc_put_weighted_pred_avg, 10, sse4);
295 }
296 if (EXTERNAL_AVX(cpu_flags)) {
257b30af 297#if HAVE_AVX_EXTERNAL
e7078e84
AK
298 SET_QPEL_FUNCS(0, 1, 10, avx, ff_hevc_qpel_h);
299 SET_QPEL_FUNCS(1, 0, 10, avx, ff_hevc_qpel_v);
300 SET_QPEL_FUNCS(1, 1, 10, avx, hevc_qpel_hv);
301 SET_EPEL_FUNCS(0, 1, 10, avx, ff_hevc_epel_h);
302 SET_EPEL_FUNCS(1, 0, 10, avx, ff_hevc_epel_v);
303 SET_EPEL_FUNCS(1, 1, 10, avx, hevc_epel_hv);
257b30af 304#endif /* HAVE_AVX_EXTERNAL */
e7078e84 305 }
1a880b2f 306 }
e7078e84 307#endif /* ARCH_X86_64 */
1a880b2f 308}