ef706b28734d3bd7b8278301545072722a7096e6
[ffmpeg.git] / libavcodec / arm / dsputil_init_neon.c
1 /*
2  * ARM NEON optimised DSP functions
3  * Copyright (c) 2008 Mans Rullgard <mans@mansr.com>
4  *
5  * This file is part of FFmpeg.
6  *
7  * FFmpeg 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  * FFmpeg 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 FFmpeg; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20  */
21
22 #include <stdint.h>
23
24 #include "libavcodec/avcodec.h"
25 #include "libavcodec/dsputil.h"
26 #include "dsputil_arm.h"
27
28 void ff_simple_idct_neon(DCTELEM *data);
29 void ff_simple_idct_put_neon(uint8_t *dest, int line_size, DCTELEM *data);
30 void ff_simple_idct_add_neon(uint8_t *dest, int line_size, DCTELEM *data);
31
32 void ff_vp3_idct_neon(DCTELEM *data);
33 void ff_vp3_idct_put_neon(uint8_t *dest, int line_size, DCTELEM *data);
34 void ff_vp3_idct_add_neon(uint8_t *dest, int line_size, DCTELEM *data);
35
36 void ff_put_pixels16_neon(uint8_t *, const uint8_t *, int, int);
37 void ff_put_pixels16_x2_neon(uint8_t *, const uint8_t *, int, int);
38 void ff_put_pixels16_y2_neon(uint8_t *, const uint8_t *, int, int);
39 void ff_put_pixels16_xy2_neon(uint8_t *, const uint8_t *, int, int);
40 void ff_put_pixels8_neon(uint8_t *, const uint8_t *, int, int);
41 void ff_put_pixels8_x2_neon(uint8_t *, const uint8_t *, int, int);
42 void ff_put_pixels8_y2_neon(uint8_t *, const uint8_t *, int, int);
43 void ff_put_pixels8_xy2_neon(uint8_t *, const uint8_t *, int, int);
44 void ff_put_pixels16_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
45 void ff_put_pixels16_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
46 void ff_put_pixels16_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
47 void ff_put_pixels8_x2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
48 void ff_put_pixels8_y2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
49 void ff_put_pixels8_xy2_no_rnd_neon(uint8_t *, const uint8_t *, int, int);
50
51 void ff_avg_pixels16_neon(uint8_t *, const uint8_t *, int, int);
52 void ff_avg_pixels8_neon(uint8_t *, const uint8_t *, int, int);
53
54 void ff_add_pixels_clamped_neon(const DCTELEM *, uint8_t *, int);
55 void ff_put_pixels_clamped_neon(const DCTELEM *, uint8_t *, int);
56 void ff_put_signed_pixels_clamped_neon(const DCTELEM *, uint8_t *, int);
57
58 void ff_put_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int);
59 void ff_put_h264_qpel16_mc10_neon(uint8_t *, uint8_t *, int);
60 void ff_put_h264_qpel16_mc20_neon(uint8_t *, uint8_t *, int);
61 void ff_put_h264_qpel16_mc30_neon(uint8_t *, uint8_t *, int);
62 void ff_put_h264_qpel16_mc01_neon(uint8_t *, uint8_t *, int);
63 void ff_put_h264_qpel16_mc11_neon(uint8_t *, uint8_t *, int);
64 void ff_put_h264_qpel16_mc21_neon(uint8_t *, uint8_t *, int);
65 void ff_put_h264_qpel16_mc31_neon(uint8_t *, uint8_t *, int);
66 void ff_put_h264_qpel16_mc02_neon(uint8_t *, uint8_t *, int);
67 void ff_put_h264_qpel16_mc12_neon(uint8_t *, uint8_t *, int);
68 void ff_put_h264_qpel16_mc22_neon(uint8_t *, uint8_t *, int);
69 void ff_put_h264_qpel16_mc32_neon(uint8_t *, uint8_t *, int);
70 void ff_put_h264_qpel16_mc03_neon(uint8_t *, uint8_t *, int);
71 void ff_put_h264_qpel16_mc13_neon(uint8_t *, uint8_t *, int);
72 void ff_put_h264_qpel16_mc23_neon(uint8_t *, uint8_t *, int);
73 void ff_put_h264_qpel16_mc33_neon(uint8_t *, uint8_t *, int);
74
75 void ff_put_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int);
76 void ff_put_h264_qpel8_mc10_neon(uint8_t *, uint8_t *, int);
77 void ff_put_h264_qpel8_mc20_neon(uint8_t *, uint8_t *, int);
78 void ff_put_h264_qpel8_mc30_neon(uint8_t *, uint8_t *, int);
79 void ff_put_h264_qpel8_mc01_neon(uint8_t *, uint8_t *, int);
80 void ff_put_h264_qpel8_mc11_neon(uint8_t *, uint8_t *, int);
81 void ff_put_h264_qpel8_mc21_neon(uint8_t *, uint8_t *, int);
82 void ff_put_h264_qpel8_mc31_neon(uint8_t *, uint8_t *, int);
83 void ff_put_h264_qpel8_mc02_neon(uint8_t *, uint8_t *, int);
84 void ff_put_h264_qpel8_mc12_neon(uint8_t *, uint8_t *, int);
85 void ff_put_h264_qpel8_mc22_neon(uint8_t *, uint8_t *, int);
86 void ff_put_h264_qpel8_mc32_neon(uint8_t *, uint8_t *, int);
87 void ff_put_h264_qpel8_mc03_neon(uint8_t *, uint8_t *, int);
88 void ff_put_h264_qpel8_mc13_neon(uint8_t *, uint8_t *, int);
89 void ff_put_h264_qpel8_mc23_neon(uint8_t *, uint8_t *, int);
90 void ff_put_h264_qpel8_mc33_neon(uint8_t *, uint8_t *, int);
91
92 void ff_avg_h264_qpel16_mc00_neon(uint8_t *, uint8_t *, int);
93
94 void ff_avg_h264_qpel8_mc00_neon(uint8_t *, uint8_t *, int);
95
96 void ff_put_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int);
97 void ff_put_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int);
98
99 void ff_avg_h264_chroma_mc8_neon(uint8_t *, uint8_t *, int, int, int, int);
100 void ff_avg_h264_chroma_mc4_neon(uint8_t *, uint8_t *, int, int, int, int);
101
102 void ff_h264_v_loop_filter_luma_neon(uint8_t *pix, int stride, int alpha,
103                                      int beta, int8_t *tc0);
104 void ff_h264_h_loop_filter_luma_neon(uint8_t *pix, int stride, int alpha,
105                                      int beta, int8_t *tc0);
106 void ff_h264_v_loop_filter_chroma_neon(uint8_t *pix, int stride, int alpha,
107                                        int beta, int8_t *tc0);
108 void ff_h264_h_loop_filter_chroma_neon(uint8_t *pix, int stride, int alpha,
109                                        int beta, int8_t *tc0);
110
111 void ff_weight_h264_pixels_16x16_neon(uint8_t *ds, int stride, int log2_den,
112                                       int weight, int offset);
113 void ff_weight_h264_pixels_16x8_neon(uint8_t *ds, int stride, int log2_den,
114                                      int weight, int offset);
115 void ff_weight_h264_pixels_8x16_neon(uint8_t *ds, int stride, int log2_den,
116                                      int weight, int offset);
117 void ff_weight_h264_pixels_8x8_neon(uint8_t *ds, int stride, int log2_den,
118                                     int weight, int offset);
119 void ff_weight_h264_pixels_8x4_neon(uint8_t *ds, int stride, int log2_den,
120                                     int weight, int offset);
121 void ff_weight_h264_pixels_4x8_neon(uint8_t *ds, int stride, int log2_den,
122                                     int weight, int offset);
123 void ff_weight_h264_pixels_4x4_neon(uint8_t *ds, int stride, int log2_den,
124                                     int weight, int offset);
125 void ff_weight_h264_pixels_4x2_neon(uint8_t *ds, int stride, int log2_den,
126                                     int weight, int offset);
127
128 void ff_biweight_h264_pixels_16x16_neon(uint8_t *dst, uint8_t *src, int stride,
129                                         int log2_den, int weightd, int weights,
130                                         int offset);
131 void ff_biweight_h264_pixels_16x8_neon(uint8_t *dst, uint8_t *src, int stride,
132                                        int log2_den, int weightd, int weights,
133                                        int offset);
134 void ff_biweight_h264_pixels_8x16_neon(uint8_t *dst, uint8_t *src, int stride,
135                                        int log2_den, int weightd, int weights,
136                                        int offset);
137 void ff_biweight_h264_pixels_8x8_neon(uint8_t *dst, uint8_t *src, int stride,
138                                       int log2_den, int weightd, int weights,
139                                       int offset);
140 void ff_biweight_h264_pixels_8x4_neon(uint8_t *dst, uint8_t *src, int stride,
141                                       int log2_den, int weightd, int weights,
142                                       int offset);
143 void ff_biweight_h264_pixels_4x8_neon(uint8_t *dst, uint8_t *src, int stride,
144                                       int log2_den, int weightd, int weights,
145                                       int offset);
146 void ff_biweight_h264_pixels_4x4_neon(uint8_t *dst, uint8_t *src, int stride,
147                                       int log2_den, int weightd, int weights,
148                                       int offset);
149 void ff_biweight_h264_pixels_4x2_neon(uint8_t *dst, uint8_t *src, int stride,
150                                       int log2_den, int weightd, int weights,
151                                       int offset);
152
153 void ff_h264_idct_add_neon(uint8_t *dst, DCTELEM *block, int stride);
154 void ff_h264_idct_dc_add_neon(uint8_t *dst, DCTELEM *block, int stride);
155 void ff_h264_idct_add16_neon(uint8_t *dst, const int *block_offset,
156                              DCTELEM *block, int stride,
157                              const uint8_t nnzc[6*8]);
158 void ff_h264_idct_add16intra_neon(uint8_t *dst, const int *block_offset,
159                                   DCTELEM *block, int stride,
160                                   const uint8_t nnzc[6*8]);
161 void ff_h264_idct_add8_neon(uint8_t **dest, const int *block_offset,
162                             DCTELEM *block, int stride,
163                             const uint8_t nnzc[6*8]);
164
165 void ff_vp3_v_loop_filter_neon(uint8_t *, int, int *);
166 void ff_vp3_h_loop_filter_neon(uint8_t *, int, int *);
167
168 void ff_vector_fmul_neon(float *dst, const float *src, int len);
169 void ff_vector_fmul_window_neon(float *dst, const float *src0,
170                                 const float *src1, const float *win,
171                                 float add_bias, int len);
172 void ff_vector_fmul_scalar_neon(float *dst, const float *src, float mul,
173                                 int len);
174 void ff_vector_fmul_sv_scalar_2_neon(float *dst, const float *src,
175                                      const float **vp, float mul, int len);
176 void ff_vector_fmul_sv_scalar_4_neon(float *dst, const float *src,
177                                      const float **vp, float mul, int len);
178 void ff_sv_fmul_scalar_2_neon(float *dst, const float **vp, float mul,
179                               int len);
180 void ff_sv_fmul_scalar_4_neon(float *dst, const float **vp, float mul,
181                               int len);
182 void ff_butterflies_float_neon(float *v1, float *v2, int len);
183 float ff_scalarproduct_float_neon(const float *v1, const float *v2, int len);
184 void ff_int32_to_float_fmul_scalar_neon(float *dst, const int *src,
185                                         float mul, int len);
186 void ff_vector_fmul_reverse_neon(float *dst, const float *src0,
187                                  const float *src1, int len);
188 void ff_vector_fmul_add_neon(float *dst, const float *src0, const float *src1,
189                              const float *src2, int len);
190
191 void ff_vector_clipf_neon(float *dst, const float *src, float min, float max,
192                           int len);
193 void ff_float_to_int16_neon(int16_t *, const float *, long);
194 void ff_float_to_int16_interleave_neon(int16_t *, const float **, long, int);
195
196 void ff_vorbis_inverse_coupling_neon(float *mag, float *ang, int blocksize);
197
198 void ff_dsputil_init_neon(DSPContext *c, AVCodecContext *avctx)
199 {
200     if (!avctx->lowres) {
201         if (avctx->idct_algo == FF_IDCT_AUTO ||
202             avctx->idct_algo == FF_IDCT_SIMPLENEON) {
203             c->idct_put              = ff_simple_idct_put_neon;
204             c->idct_add              = ff_simple_idct_add_neon;
205             c->idct                  = ff_simple_idct_neon;
206             c->idct_permutation_type = FF_PARTTRANS_IDCT_PERM;
207         } else if ((CONFIG_VP3_DECODER || CONFIG_VP5_DECODER ||
208                     CONFIG_VP6_DECODER) &&
209                    avctx->idct_algo == FF_IDCT_VP3) {
210             c->idct_put              = ff_vp3_idct_put_neon;
211             c->idct_add              = ff_vp3_idct_add_neon;
212             c->idct                  = ff_vp3_idct_neon;
213             c->idct_permutation_type = FF_TRANSPOSE_IDCT_PERM;
214         }
215     }
216
217     c->put_pixels_tab[0][0] = ff_put_pixels16_neon;
218     c->put_pixels_tab[0][1] = ff_put_pixels16_x2_neon;
219     c->put_pixels_tab[0][2] = ff_put_pixels16_y2_neon;
220     c->put_pixels_tab[0][3] = ff_put_pixels16_xy2_neon;
221     c->put_pixels_tab[1][0] = ff_put_pixels8_neon;
222     c->put_pixels_tab[1][1] = ff_put_pixels8_x2_neon;
223     c->put_pixels_tab[1][2] = ff_put_pixels8_y2_neon;
224     c->put_pixels_tab[1][3] = ff_put_pixels8_xy2_neon;
225
226     c->put_no_rnd_pixels_tab[0][0] = ff_put_pixels16_neon;
227     c->put_no_rnd_pixels_tab[0][1] = ff_put_pixels16_x2_no_rnd_neon;
228     c->put_no_rnd_pixels_tab[0][2] = ff_put_pixels16_y2_no_rnd_neon;
229     c->put_no_rnd_pixels_tab[0][3] = ff_put_pixels16_xy2_no_rnd_neon;
230     c->put_no_rnd_pixels_tab[1][0] = ff_put_pixels8_neon;
231     c->put_no_rnd_pixels_tab[1][1] = ff_put_pixels8_x2_no_rnd_neon;
232     c->put_no_rnd_pixels_tab[1][2] = ff_put_pixels8_y2_no_rnd_neon;
233     c->put_no_rnd_pixels_tab[1][3] = ff_put_pixels8_xy2_no_rnd_neon;
234
235     c->avg_pixels_tab[0][0] = ff_avg_pixels16_neon;
236     c->avg_pixels_tab[1][0] = ff_avg_pixels8_neon;
237
238     c->add_pixels_clamped = ff_add_pixels_clamped_neon;
239     c->put_pixels_clamped = ff_put_pixels_clamped_neon;
240     c->put_signed_pixels_clamped = ff_put_signed_pixels_clamped_neon;
241
242     if (CONFIG_H264_DECODER) {
243         c->put_h264_chroma_pixels_tab[0] = ff_put_h264_chroma_mc8_neon;
244         c->put_h264_chroma_pixels_tab[1] = ff_put_h264_chroma_mc4_neon;
245
246         c->avg_h264_chroma_pixels_tab[0] = ff_avg_h264_chroma_mc8_neon;
247         c->avg_h264_chroma_pixels_tab[1] = ff_avg_h264_chroma_mc4_neon;
248
249         c->put_h264_qpel_pixels_tab[0][ 0] = ff_put_h264_qpel16_mc00_neon;
250         c->put_h264_qpel_pixels_tab[0][ 1] = ff_put_h264_qpel16_mc10_neon;
251         c->put_h264_qpel_pixels_tab[0][ 2] = ff_put_h264_qpel16_mc20_neon;
252         c->put_h264_qpel_pixels_tab[0][ 3] = ff_put_h264_qpel16_mc30_neon;
253         c->put_h264_qpel_pixels_tab[0][ 4] = ff_put_h264_qpel16_mc01_neon;
254         c->put_h264_qpel_pixels_tab[0][ 5] = ff_put_h264_qpel16_mc11_neon;
255         c->put_h264_qpel_pixels_tab[0][ 6] = ff_put_h264_qpel16_mc21_neon;
256         c->put_h264_qpel_pixels_tab[0][ 7] = ff_put_h264_qpel16_mc31_neon;
257         c->put_h264_qpel_pixels_tab[0][ 8] = ff_put_h264_qpel16_mc02_neon;
258         c->put_h264_qpel_pixels_tab[0][ 9] = ff_put_h264_qpel16_mc12_neon;
259         c->put_h264_qpel_pixels_tab[0][10] = ff_put_h264_qpel16_mc22_neon;
260         c->put_h264_qpel_pixels_tab[0][11] = ff_put_h264_qpel16_mc32_neon;
261         c->put_h264_qpel_pixels_tab[0][12] = ff_put_h264_qpel16_mc03_neon;
262         c->put_h264_qpel_pixels_tab[0][13] = ff_put_h264_qpel16_mc13_neon;
263         c->put_h264_qpel_pixels_tab[0][14] = ff_put_h264_qpel16_mc23_neon;
264         c->put_h264_qpel_pixels_tab[0][15] = ff_put_h264_qpel16_mc33_neon;
265
266         c->put_h264_qpel_pixels_tab[1][ 0] = ff_put_h264_qpel8_mc00_neon;
267         c->put_h264_qpel_pixels_tab[1][ 1] = ff_put_h264_qpel8_mc10_neon;
268         c->put_h264_qpel_pixels_tab[1][ 2] = ff_put_h264_qpel8_mc20_neon;
269         c->put_h264_qpel_pixels_tab[1][ 3] = ff_put_h264_qpel8_mc30_neon;
270         c->put_h264_qpel_pixels_tab[1][ 4] = ff_put_h264_qpel8_mc01_neon;
271         c->put_h264_qpel_pixels_tab[1][ 5] = ff_put_h264_qpel8_mc11_neon;
272         c->put_h264_qpel_pixels_tab[1][ 6] = ff_put_h264_qpel8_mc21_neon;
273         c->put_h264_qpel_pixels_tab[1][ 7] = ff_put_h264_qpel8_mc31_neon;
274         c->put_h264_qpel_pixels_tab[1][ 8] = ff_put_h264_qpel8_mc02_neon;
275         c->put_h264_qpel_pixels_tab[1][ 9] = ff_put_h264_qpel8_mc12_neon;
276         c->put_h264_qpel_pixels_tab[1][10] = ff_put_h264_qpel8_mc22_neon;
277         c->put_h264_qpel_pixels_tab[1][11] = ff_put_h264_qpel8_mc32_neon;
278         c->put_h264_qpel_pixels_tab[1][12] = ff_put_h264_qpel8_mc03_neon;
279         c->put_h264_qpel_pixels_tab[1][13] = ff_put_h264_qpel8_mc13_neon;
280         c->put_h264_qpel_pixels_tab[1][14] = ff_put_h264_qpel8_mc23_neon;
281         c->put_h264_qpel_pixels_tab[1][15] = ff_put_h264_qpel8_mc33_neon;
282
283         c->avg_h264_qpel_pixels_tab[0][ 0] = ff_avg_h264_qpel16_mc00_neon;
284
285         c->avg_h264_qpel_pixels_tab[1][ 0] = ff_avg_h264_qpel8_mc00_neon;
286
287         c->h264_v_loop_filter_luma   = ff_h264_v_loop_filter_luma_neon;
288         c->h264_h_loop_filter_luma   = ff_h264_h_loop_filter_luma_neon;
289         c->h264_v_loop_filter_chroma = ff_h264_v_loop_filter_chroma_neon;
290         c->h264_h_loop_filter_chroma = ff_h264_h_loop_filter_chroma_neon;
291
292         c->weight_h264_pixels_tab[0] = ff_weight_h264_pixels_16x16_neon;
293         c->weight_h264_pixels_tab[1] = ff_weight_h264_pixels_16x8_neon;
294         c->weight_h264_pixels_tab[2] = ff_weight_h264_pixels_8x16_neon;
295         c->weight_h264_pixels_tab[3] = ff_weight_h264_pixels_8x8_neon;
296         c->weight_h264_pixels_tab[4] = ff_weight_h264_pixels_8x4_neon;
297         c->weight_h264_pixels_tab[5] = ff_weight_h264_pixels_4x8_neon;
298         c->weight_h264_pixels_tab[6] = ff_weight_h264_pixels_4x4_neon;
299         c->weight_h264_pixels_tab[7] = ff_weight_h264_pixels_4x2_neon;
300
301         c->biweight_h264_pixels_tab[0] = ff_biweight_h264_pixels_16x16_neon;
302         c->biweight_h264_pixels_tab[1] = ff_biweight_h264_pixels_16x8_neon;
303         c->biweight_h264_pixels_tab[2] = ff_biweight_h264_pixels_8x16_neon;
304         c->biweight_h264_pixels_tab[3] = ff_biweight_h264_pixels_8x8_neon;
305         c->biweight_h264_pixels_tab[4] = ff_biweight_h264_pixels_8x4_neon;
306         c->biweight_h264_pixels_tab[5] = ff_biweight_h264_pixels_4x8_neon;
307         c->biweight_h264_pixels_tab[6] = ff_biweight_h264_pixels_4x4_neon;
308         c->biweight_h264_pixels_tab[7] = ff_biweight_h264_pixels_4x2_neon;
309
310         c->h264_idct_add        = ff_h264_idct_add_neon;
311         c->h264_idct_dc_add     = ff_h264_idct_dc_add_neon;
312         c->h264_idct_add16      = ff_h264_idct_add16_neon;
313         c->h264_idct_add16intra = ff_h264_idct_add16intra_neon;
314         c->h264_idct_add8       = ff_h264_idct_add8_neon;
315     }
316
317     if (CONFIG_VP3_DECODER) {
318         c->vp3_v_loop_filter = ff_vp3_v_loop_filter_neon;
319         c->vp3_h_loop_filter = ff_vp3_h_loop_filter_neon;
320     }
321
322     c->vector_fmul                = ff_vector_fmul_neon;
323     c->vector_fmul_window         = ff_vector_fmul_window_neon;
324     c->vector_fmul_scalar         = ff_vector_fmul_scalar_neon;
325     c->butterflies_float          = ff_butterflies_float_neon;
326     c->scalarproduct_float        = ff_scalarproduct_float_neon;
327     c->int32_to_float_fmul_scalar = ff_int32_to_float_fmul_scalar_neon;
328     c->vector_fmul_reverse        = ff_vector_fmul_reverse_neon;
329     c->vector_fmul_add            = ff_vector_fmul_add_neon;
330     c->vector_clipf               = ff_vector_clipf_neon;
331
332     c->vector_fmul_sv_scalar[0] = ff_vector_fmul_sv_scalar_2_neon;
333     c->vector_fmul_sv_scalar[1] = ff_vector_fmul_sv_scalar_4_neon;
334
335     c->sv_fmul_scalar[0] = ff_sv_fmul_scalar_2_neon;
336     c->sv_fmul_scalar[1] = ff_sv_fmul_scalar_4_neon;
337
338     if (!(avctx->flags & CODEC_FLAG_BITEXACT)) {
339         c->float_to_int16            = ff_float_to_int16_neon;
340         c->float_to_int16_interleave = ff_float_to_int16_interleave_neon;
341     }
342
343     if (CONFIG_VORBIS_DECODER)
344         c->vorbis_inverse_coupling = ff_vorbis_inverse_coupling_neon;
345 }