x86: hevc: Fix linking with both yasm and optimizations disabled
[libav.git] / libavcodec / x86 / hevcdsp_init.c
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) \
30 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);
31
32 #define LFL_FUNC(DIR, DEPTH, OPT) \
33 void 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
43 LFC_FUNCS(uint8_t, 8)
44 LFC_FUNCS(uint8_t, 10)
45 LFL_FUNCS(uint8_t, 8)
46 LFL_FUNCS(uint8_t, 10)
47
48 #define GET_PIXELS(width, depth, cf) \
49 void 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
53 GET_PIXELS(4, 8, sse2)
54 GET_PIXELS(8, 8, sse2)
55 GET_PIXELS(12, 8, sse2)
56 GET_PIXELS(16, 8, sse2)
57 GET_PIXELS(24, 8, sse2)
58 GET_PIXELS(32, 8, sse2)
59 GET_PIXELS(48, 8, sse2)
60 GET_PIXELS(64, 8, sse2)
61
62 GET_PIXELS(4, 10, sse2)
63 GET_PIXELS(8, 10, sse2)
64 GET_PIXELS(12, 10, sse2)
65 GET_PIXELS(16, 10, sse2)
66 GET_PIXELS(24, 10, sse2)
67 GET_PIXELS(32, 10, sse2)
68 GET_PIXELS(48, 10, sse2)
69 GET_PIXELS(64, 10, sse2)
70
71 /* those are independent of the bit depth, so declared separately */
72 #define INTERP_HV_FUNC(width, cf) \
73 void 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); \
76 void 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
80 INTERP_HV_FUNC(4, avx)
81 INTERP_HV_FUNC(8, avx)
82 INTERP_HV_FUNC(12, avx)
83 INTERP_HV_FUNC(16, avx)
84 INTERP_HV_FUNC(24, avx)
85 INTERP_HV_FUNC(32, avx)
86 INTERP_HV_FUNC(48, avx)
87 INTERP_HV_FUNC(64, avx)
88
89 #if ARCH_X86_64 && HAVE_AVX_EXTERNAL
90 #define QPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv) \
91 static 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)
103 #endif /* ARCH_X86_64 && HAVE_AVX_EXTERNAL */
104
105 #define QPEL_FUNCS(width, depth, cf_h, cf_v, cf_hv) \
106 void 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); \
109 void 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); \
112 QPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
113
114 QPEL_FUNCS(4, 8, ssse3, ssse3, avx)
115 QPEL_FUNCS(8, 8, ssse3, ssse3, avx)
116 QPEL_FUNCS(12, 8, ssse3, ssse3, avx)
117 QPEL_FUNCS(16, 8, ssse3, ssse3, avx)
118 QPEL_FUNCS(24, 8, ssse3, ssse3, avx)
119 QPEL_FUNCS(32, 8, ssse3, ssse3, avx)
120 QPEL_FUNCS(48, 8, ssse3, ssse3, avx)
121 QPEL_FUNCS(64, 8, ssse3, ssse3, avx)
122
123 QPEL_FUNCS(4, 10, avx, avx, avx)
124 QPEL_FUNCS(8, 10, avx, avx, avx)
125 QPEL_FUNCS(12, 10, avx, avx, avx)
126 QPEL_FUNCS(16, 10, avx, avx, avx)
127 QPEL_FUNCS(24, 10, avx, avx, avx)
128 QPEL_FUNCS(32, 10, avx, avx, avx)
129 QPEL_FUNCS(48, 10, avx, avx, avx)
130 QPEL_FUNCS(64, 10, avx, avx, avx)
131
132 #if ARCH_X86_64 && HAVE_AVX_EXTERNAL
133 #define EPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv) \
134 static 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)
146 #endif /* ARCH_X86_64 && HAVE_AVX_EXTERNAL */
147
148 #define EPEL_FUNCS(width, depth, cf_h, cf_v, cf_hv) \
149 void 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); \
152 void 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); \
155 EPEL_FUNC_HV(width, depth, cf_h, cf_v, cf_hv)
156
157 EPEL_FUNCS(4, 8, ssse3, ssse3, avx)
158 EPEL_FUNCS(8, 8, ssse3, ssse3, avx)
159 EPEL_FUNCS(12, 8, ssse3, ssse3, avx)
160 EPEL_FUNCS(16, 8, ssse3, ssse3, avx)
161 EPEL_FUNCS(24, 8, ssse3, ssse3, avx)
162 EPEL_FUNCS(32, 8, ssse3, ssse3, avx)
163
164 EPEL_FUNCS(4, 10, avx, avx, avx)
165 EPEL_FUNCS(8, 10, avx, avx, avx)
166 EPEL_FUNCS(12, 10, avx, avx, avx)
167 EPEL_FUNCS(16, 10, avx, avx, avx)
168 EPEL_FUNCS(24, 10, avx, avx, avx)
169 EPEL_FUNCS(32, 10, avx, avx, avx)
170
171 #define PUT_PRED(width, depth, cf_uw, cf_w) \
172 void 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); \
175 void 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); \
178 void 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); \
182 void 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
188 PUT_PRED(4, 8, sse2, sse4)
189 PUT_PRED(8, 8, sse2, sse4)
190 PUT_PRED(12, 8, sse2, sse4)
191 PUT_PRED(16, 8, sse2, sse4)
192 PUT_PRED(24, 8, sse2, sse4)
193 PUT_PRED(32, 8, sse2, sse4)
194 PUT_PRED(48, 8, sse2, sse4)
195 PUT_PRED(64, 8, sse2, sse4)
196
197 PUT_PRED(4, 10, sse2, sse4)
198 PUT_PRED(8, 10, sse2, sse4)
199 PUT_PRED(12, 10, sse2, sse4)
200 PUT_PRED(16, 10, sse2, sse4)
201 PUT_PRED(24, 10, sse2, sse4)
202 PUT_PRED(32, 10, sse2, sse4)
203 PUT_PRED(48, 10, sse2, sse4)
204 PUT_PRED(64, 10, sse2, sse4)
205
206 void ff_hevc_dsp_init_x86(HEVCDSPContext *c, const int bit_depth)
207 {
208 int cpu_flags = av_get_cpu_flags();
209
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
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;
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);
243 }
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);
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;
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);
277 }
278
279 if (EXTERNAL_AVX(cpu_flags)) {
280 #if HAVE_AVX_EXTERNAL
281 SET_QPEL_FUNCS(1, 1, 8, avx, hevc_qpel_hv);
282 SET_EPEL_FUNCS(1, 1, 8, avx, hevc_epel_hv);
283 #endif /* HAVE_AVX_EXTERNAL */
284 }
285 } else if (bit_depth == 10) {
286 if (EXTERNAL_SSSE3(cpu_flags)) {
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 }
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)) {
297 #if HAVE_AVX_EXTERNAL
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);
304 #endif /* HAVE_AVX_EXTERNAL */
305 }
306 }
307 #endif /* ARCH_X86_64 */
308 }