]> git.sesse.net Git - ffmpeg/blob - libavcodec/arm/hevcdsp_init_neon.c
Merge commit '847190ebd99ffd57dc89bd568a33bf2d5c424129'
[ffmpeg] / libavcodec / arm / hevcdsp_init_neon.c
1 /*
2  * Copyright (c) 2014 Seppo Tomperi <seppo.tomperi@vtt.fi>
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "libavutil/attributes.h"
22 #include "libavutil/arm/cpu.h"
23 #include "libavcodec/hevcdsp.h"
24 #include "hevcdsp_arm.h"
25
26 void ff_hevc_v_loop_filter_luma_neon(uint8_t *_pix, ptrdiff_t _stride, int _beta, int *_tc, uint8_t *_no_p, uint8_t *_no_q);
27 void ff_hevc_h_loop_filter_luma_neon(uint8_t *_pix, ptrdiff_t _stride, int _beta, int *_tc, uint8_t *_no_p, uint8_t *_no_q);
28 void ff_hevc_v_loop_filter_chroma_neon(uint8_t *_pix, ptrdiff_t _stride, int *_tc, uint8_t *_no_p, uint8_t *_no_q);
29 void ff_hevc_h_loop_filter_chroma_neon(uint8_t *_pix, ptrdiff_t _stride, int *_tc, uint8_t *_no_p, uint8_t *_no_q);
30 void ff_hevc_add_residual_4x4_8_neon(uint8_t *_dst, int16_t *coeffs,
31                                      ptrdiff_t stride);
32 void ff_hevc_add_residual_4x4_10_neon(uint8_t *_dst, int16_t *coeffs,
33                                       ptrdiff_t stride);
34 void ff_hevc_add_residual_8x8_8_neon(uint8_t *_dst, int16_t *coeffs,
35                                      ptrdiff_t stride);
36 void ff_hevc_add_residual_8x8_10_neon(uint8_t *_dst, int16_t *coeffs,
37                                       ptrdiff_t stride);
38 void ff_hevc_add_residual_16x16_8_neon(uint8_t *_dst, int16_t *coeffs,
39                                        ptrdiff_t stride);
40 void ff_hevc_add_residual_16x16_10_neon(uint8_t *_dst, int16_t *coeffs,
41                                         ptrdiff_t stride);
42 void ff_hevc_add_residual_32x32_8_neon(uint8_t *_dst, int16_t *coeffs,
43                                        ptrdiff_t stride);
44 void ff_hevc_add_residual_32x32_10_neon(uint8_t *_dst, int16_t *coeffs,
45                                         ptrdiff_t stride);
46 void ff_hevc_idct_4x4_dc_8_neon(int16_t *coeffs);
47 void ff_hevc_idct_8x8_dc_8_neon(int16_t *coeffs);
48 void ff_hevc_idct_16x16_dc_8_neon(int16_t *coeffs);
49 void ff_hevc_idct_32x32_dc_8_neon(int16_t *coeffs);
50 void ff_hevc_idct_4x4_dc_10_neon(int16_t *coeffs);
51 void ff_hevc_idct_8x8_dc_10_neon(int16_t *coeffs);
52 void ff_hevc_idct_16x16_dc_10_neon(int16_t *coeffs);
53 void ff_hevc_idct_32x32_dc_10_neon(int16_t *coeffs);
54 void ff_hevc_idct_4x4_8_neon(int16_t *coeffs, int col_limit);
55 void ff_hevc_idct_8x8_8_neon(int16_t *coeffs, int col_limit);
56 void ff_hevc_idct_16x16_8_neon(int16_t *coeffs, int col_limit);
57 void ff_hevc_idct_32x32_8_neon(int16_t *coeffs, int col_limit);
58 void ff_hevc_idct_4x4_10_neon(int16_t *coeffs, int col_limit);
59 void ff_hevc_idct_8x8_10_neon(int16_t *coeffs, int col_limit);
60 void ff_hevc_idct_16x16_10_neon(int16_t *coeffs, int col_limit);
61 void ff_hevc_idct_32x32_10_neon(int16_t *coeffs, int col_limit);
62 void ff_hevc_transform_luma_4x4_neon_8(int16_t *coeffs);
63
64 #define PUT_PIXELS(name) \
65     void name(int16_t *dst, uint8_t *src, \
66                                 ptrdiff_t srcstride, int height, \
67                                 intptr_t mx, intptr_t my, int width)
68 PUT_PIXELS(ff_hevc_put_pixels_w2_neon_8);
69 PUT_PIXELS(ff_hevc_put_pixels_w4_neon_8);
70 PUT_PIXELS(ff_hevc_put_pixels_w6_neon_8);
71 PUT_PIXELS(ff_hevc_put_pixels_w8_neon_8);
72 PUT_PIXELS(ff_hevc_put_pixels_w12_neon_8);
73 PUT_PIXELS(ff_hevc_put_pixels_w16_neon_8);
74 PUT_PIXELS(ff_hevc_put_pixels_w24_neon_8);
75 PUT_PIXELS(ff_hevc_put_pixels_w32_neon_8);
76 PUT_PIXELS(ff_hevc_put_pixels_w48_neon_8);
77 PUT_PIXELS(ff_hevc_put_pixels_w64_neon_8);
78 #undef PUT_PIXELS
79
80 static void (*put_hevc_qpel_neon[4][4])(int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride,
81                                    int height, int width);
82 static void (*put_hevc_qpel_uw_neon[4][4])(uint8_t *dst, ptrdiff_t dststride, uint8_t *_src, ptrdiff_t _srcstride,
83                                    int width, int height, int16_t* src2, ptrdiff_t src2stride);
84 void ff_hevc_put_qpel_neon_wrapper(int16_t *dst, uint8_t *src, ptrdiff_t srcstride,
85                                    int height, intptr_t mx, intptr_t my, int width);
86 void ff_hevc_put_qpel_uni_neon_wrapper(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride,
87                                    int height, intptr_t mx, intptr_t my, int width);
88 void ff_hevc_put_qpel_bi_neon_wrapper(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride,
89                                        int16_t *src2,
90                                        int height, intptr_t mx, intptr_t my, int width);
91 #define QPEL_FUNC(name) \
92     void name(int16_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride, \
93                                    int height, int width)
94
95 QPEL_FUNC(ff_hevc_put_qpel_v1_neon_8);
96 QPEL_FUNC(ff_hevc_put_qpel_v2_neon_8);
97 QPEL_FUNC(ff_hevc_put_qpel_v3_neon_8);
98 QPEL_FUNC(ff_hevc_put_qpel_h1_neon_8);
99 QPEL_FUNC(ff_hevc_put_qpel_h2_neon_8);
100 QPEL_FUNC(ff_hevc_put_qpel_h3_neon_8);
101 QPEL_FUNC(ff_hevc_put_qpel_h1v1_neon_8);
102 QPEL_FUNC(ff_hevc_put_qpel_h1v2_neon_8);
103 QPEL_FUNC(ff_hevc_put_qpel_h1v3_neon_8);
104 QPEL_FUNC(ff_hevc_put_qpel_h2v1_neon_8);
105 QPEL_FUNC(ff_hevc_put_qpel_h2v2_neon_8);
106 QPEL_FUNC(ff_hevc_put_qpel_h2v3_neon_8);
107 QPEL_FUNC(ff_hevc_put_qpel_h3v1_neon_8);
108 QPEL_FUNC(ff_hevc_put_qpel_h3v2_neon_8);
109 QPEL_FUNC(ff_hevc_put_qpel_h3v3_neon_8);
110 #undef QPEL_FUNC
111
112 #define QPEL_FUNC_UW_PIX(name) \
113     void name(uint8_t *dst, ptrdiff_t dststride, uint8_t *_src, ptrdiff_t _srcstride, \
114                                    int height, intptr_t mx, intptr_t my, int width);
115 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w4_neon_8);
116 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w8_neon_8);
117 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w16_neon_8);
118 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w24_neon_8);
119 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w32_neon_8);
120 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w48_neon_8);
121 QPEL_FUNC_UW_PIX(ff_hevc_put_qpel_uw_pixels_w64_neon_8);
122 #undef QPEL_FUNC_UW_PIX
123
124 #define QPEL_FUNC_UW(name) \
125     void name(uint8_t *dst, ptrdiff_t dststride, uint8_t *_src, ptrdiff_t _srcstride, \
126                                    int width, int height, int16_t* src2, ptrdiff_t src2stride);
127 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_pixels_neon_8);
128 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_v1_neon_8);
129 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_v2_neon_8);
130 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_v3_neon_8);
131 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h1_neon_8);
132 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h2_neon_8);
133 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h3_neon_8);
134 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h1v1_neon_8);
135 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h1v2_neon_8);
136 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h1v3_neon_8);
137 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h2v1_neon_8);
138 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h2v2_neon_8);
139 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h2v3_neon_8);
140 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h3v1_neon_8);
141 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h3v2_neon_8);
142 QPEL_FUNC_UW(ff_hevc_put_qpel_uw_h3v3_neon_8);
143 #undef QPEL_FUNC_UW
144
145 void ff_hevc_put_qpel_neon_wrapper(int16_t *dst, uint8_t *src, ptrdiff_t srcstride,
146                                    int height, intptr_t mx, intptr_t my, int width) {
147
148     put_hevc_qpel_neon[my][mx](dst, MAX_PB_SIZE, src, srcstride, height, width);
149 }
150
151 void ff_hevc_put_qpel_uni_neon_wrapper(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride,
152                                    int height, intptr_t mx, intptr_t my, int width) {
153
154     put_hevc_qpel_uw_neon[my][mx](dst, dststride, src, srcstride, width, height, NULL, 0);
155 }
156
157 void ff_hevc_put_qpel_bi_neon_wrapper(uint8_t *dst, ptrdiff_t dststride, uint8_t *src, ptrdiff_t srcstride,
158                                        int16_t *src2,
159                                        int height, intptr_t mx, intptr_t my, int width) {
160     put_hevc_qpel_uw_neon[my][mx](dst, dststride, src, srcstride, width, height, src2, MAX_PB_SIZE);
161 }
162
163 av_cold void ff_hevc_dsp_init_neon(HEVCDSPContext *c, const int bit_depth)
164 {
165     if (bit_depth == 8) {
166         int x;
167         c->hevc_v_loop_filter_luma     = ff_hevc_v_loop_filter_luma_neon;
168         c->hevc_h_loop_filter_luma     = ff_hevc_h_loop_filter_luma_neon;
169         c->hevc_v_loop_filter_chroma   = ff_hevc_v_loop_filter_chroma_neon;
170         c->hevc_h_loop_filter_chroma   = ff_hevc_h_loop_filter_chroma_neon;
171         c->add_residual[0]             = ff_hevc_add_residual_4x4_8_neon;
172         c->add_residual[1]             = ff_hevc_add_residual_8x8_8_neon;
173         c->add_residual[2]             = ff_hevc_add_residual_16x16_8_neon;
174         c->add_residual[3]             = ff_hevc_add_residual_32x32_8_neon;
175         c->idct_dc[0]                  = ff_hevc_idct_4x4_dc_8_neon;
176         c->idct_dc[1]                  = ff_hevc_idct_8x8_dc_8_neon;
177         c->idct_dc[2]                  = ff_hevc_idct_16x16_dc_8_neon;
178         c->idct_dc[3]                  = ff_hevc_idct_32x32_dc_8_neon;
179         c->idct[0]                     = ff_hevc_idct_4x4_8_neon;
180         c->idct[1]                     = ff_hevc_idct_8x8_8_neon;
181         c->idct[2]                     = ff_hevc_idct_16x16_8_neon;
182         c->idct[3]                     = ff_hevc_idct_32x32_8_neon;
183         c->transform_4x4_luma          = ff_hevc_transform_luma_4x4_neon_8;
184         put_hevc_qpel_neon[1][0]       = ff_hevc_put_qpel_v1_neon_8;
185         put_hevc_qpel_neon[2][0]       = ff_hevc_put_qpel_v2_neon_8;
186         put_hevc_qpel_neon[3][0]       = ff_hevc_put_qpel_v3_neon_8;
187         put_hevc_qpel_neon[0][1]       = ff_hevc_put_qpel_h1_neon_8;
188         put_hevc_qpel_neon[0][2]       = ff_hevc_put_qpel_h2_neon_8;
189         put_hevc_qpel_neon[0][3]       = ff_hevc_put_qpel_h3_neon_8;
190         put_hevc_qpel_neon[1][1]       = ff_hevc_put_qpel_h1v1_neon_8;
191         put_hevc_qpel_neon[1][2]       = ff_hevc_put_qpel_h2v1_neon_8;
192         put_hevc_qpel_neon[1][3]       = ff_hevc_put_qpel_h3v1_neon_8;
193         put_hevc_qpel_neon[2][1]       = ff_hevc_put_qpel_h1v2_neon_8;
194         put_hevc_qpel_neon[2][2]       = ff_hevc_put_qpel_h2v2_neon_8;
195         put_hevc_qpel_neon[2][3]       = ff_hevc_put_qpel_h3v2_neon_8;
196         put_hevc_qpel_neon[3][1]       = ff_hevc_put_qpel_h1v3_neon_8;
197         put_hevc_qpel_neon[3][2]       = ff_hevc_put_qpel_h2v3_neon_8;
198         put_hevc_qpel_neon[3][3]       = ff_hevc_put_qpel_h3v3_neon_8;
199         put_hevc_qpel_uw_neon[1][0]      = ff_hevc_put_qpel_uw_v1_neon_8;
200         put_hevc_qpel_uw_neon[2][0]      = ff_hevc_put_qpel_uw_v2_neon_8;
201         put_hevc_qpel_uw_neon[3][0]      = ff_hevc_put_qpel_uw_v3_neon_8;
202         put_hevc_qpel_uw_neon[0][1]      = ff_hevc_put_qpel_uw_h1_neon_8;
203         put_hevc_qpel_uw_neon[0][2]      = ff_hevc_put_qpel_uw_h2_neon_8;
204         put_hevc_qpel_uw_neon[0][3]      = ff_hevc_put_qpel_uw_h3_neon_8;
205         put_hevc_qpel_uw_neon[1][1]      = ff_hevc_put_qpel_uw_h1v1_neon_8;
206         put_hevc_qpel_uw_neon[1][2]      = ff_hevc_put_qpel_uw_h2v1_neon_8;
207         put_hevc_qpel_uw_neon[1][3]      = ff_hevc_put_qpel_uw_h3v1_neon_8;
208         put_hevc_qpel_uw_neon[2][1]      = ff_hevc_put_qpel_uw_h1v2_neon_8;
209         put_hevc_qpel_uw_neon[2][2]      = ff_hevc_put_qpel_uw_h2v2_neon_8;
210         put_hevc_qpel_uw_neon[2][3]      = ff_hevc_put_qpel_uw_h3v2_neon_8;
211         put_hevc_qpel_uw_neon[3][1]      = ff_hevc_put_qpel_uw_h1v3_neon_8;
212         put_hevc_qpel_uw_neon[3][2]      = ff_hevc_put_qpel_uw_h2v3_neon_8;
213         put_hevc_qpel_uw_neon[3][3]      = ff_hevc_put_qpel_uw_h3v3_neon_8;
214         for (x = 0; x < 10; x++) {
215             c->put_hevc_qpel[x][1][0]         = ff_hevc_put_qpel_neon_wrapper;
216             c->put_hevc_qpel[x][0][1]         = ff_hevc_put_qpel_neon_wrapper;
217             c->put_hevc_qpel[x][1][1]         = ff_hevc_put_qpel_neon_wrapper;
218             c->put_hevc_qpel_uni[x][1][0]     = ff_hevc_put_qpel_uni_neon_wrapper;
219             c->put_hevc_qpel_uni[x][0][1]     = ff_hevc_put_qpel_uni_neon_wrapper;
220             c->put_hevc_qpel_uni[x][1][1]     = ff_hevc_put_qpel_uni_neon_wrapper;
221             c->put_hevc_qpel_bi[x][1][0]      = ff_hevc_put_qpel_bi_neon_wrapper;
222             c->put_hevc_qpel_bi[x][0][1]      = ff_hevc_put_qpel_bi_neon_wrapper;
223             c->put_hevc_qpel_bi[x][1][1]      = ff_hevc_put_qpel_bi_neon_wrapper;
224         }
225         c->put_hevc_qpel[0][0][0]  = ff_hevc_put_pixels_w2_neon_8;
226         c->put_hevc_qpel[1][0][0]  = ff_hevc_put_pixels_w4_neon_8;
227         c->put_hevc_qpel[2][0][0]  = ff_hevc_put_pixels_w6_neon_8;
228         c->put_hevc_qpel[3][0][0]  = ff_hevc_put_pixels_w8_neon_8;
229         c->put_hevc_qpel[4][0][0]  = ff_hevc_put_pixels_w12_neon_8;
230         c->put_hevc_qpel[5][0][0]  = ff_hevc_put_pixels_w16_neon_8;
231         c->put_hevc_qpel[6][0][0]  = ff_hevc_put_pixels_w24_neon_8;
232         c->put_hevc_qpel[7][0][0]  = ff_hevc_put_pixels_w32_neon_8;
233         c->put_hevc_qpel[8][0][0]  = ff_hevc_put_pixels_w48_neon_8;
234         c->put_hevc_qpel[9][0][0]  = ff_hevc_put_pixels_w64_neon_8;
235
236         c->put_hevc_qpel_uni[1][0][0]  = ff_hevc_put_qpel_uw_pixels_w4_neon_8;
237         c->put_hevc_qpel_uni[3][0][0]  = ff_hevc_put_qpel_uw_pixels_w8_neon_8;
238         c->put_hevc_qpel_uni[5][0][0]  = ff_hevc_put_qpel_uw_pixels_w16_neon_8;
239         c->put_hevc_qpel_uni[6][0][0]  = ff_hevc_put_qpel_uw_pixels_w24_neon_8;
240         c->put_hevc_qpel_uni[7][0][0]  = ff_hevc_put_qpel_uw_pixels_w32_neon_8;
241         c->put_hevc_qpel_uni[8][0][0]  = ff_hevc_put_qpel_uw_pixels_w48_neon_8;
242         c->put_hevc_qpel_uni[9][0][0]  = ff_hevc_put_qpel_uw_pixels_w64_neon_8;
243     }
244
245     if (bit_depth == 10) {
246         c->add_residual[0] = ff_hevc_add_residual_4x4_10_neon;
247         c->add_residual[1] = ff_hevc_add_residual_8x8_10_neon;
248         c->add_residual[2] = ff_hevc_add_residual_16x16_10_neon;
249         c->add_residual[3] = ff_hevc_add_residual_32x32_10_neon;
250
251         c->idct_dc[0] = ff_hevc_idct_4x4_dc_10_neon;
252         c->idct_dc[1] = ff_hevc_idct_8x8_dc_10_neon;
253         c->idct_dc[2] = ff_hevc_idct_16x16_dc_10_neon;
254         c->idct_dc[3] = ff_hevc_idct_32x32_dc_10_neon;
255
256         c->idct[0] = ff_hevc_idct_4x4_10_neon;
257         c->idct[1] = ff_hevc_idct_8x8_10_neon;
258         c->idct[2] = ff_hevc_idct_16x16_10_neon;
259         c->idct[3] = ff_hevc_idct_32x32_10_neon;
260     }
261 }