]> git.sesse.net Git - ffmpeg/blob - libavcodec/ppc/h264_qpel.c
get_buffer(): do not initialize the data.
[ffmpeg] / libavcodec / ppc / h264_qpel.c
1 /*
2  * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
3  *
4  * This file is part of Libav.
5  *
6  * Libav 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  * Libav 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 Libav; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20
21 #include "config.h"
22 #include "libavutil/attributes.h"
23 #include "libavcodec/h264qpel.h"
24
25 #if HAVE_ALTIVEC
26 #include "libavutil/cpu.h"
27 #include "libavutil/intreadwrite.h"
28 #include "libavutil/ppc/types_altivec.h"
29 #include "libavutil/ppc/util_altivec.h"
30 #include "dsputil_altivec.h"
31
32 #define PUT_OP_U8_ALTIVEC(d, s, dst) d = s
33 #define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s)
34
35 #define OP_U8_ALTIVEC                          PUT_OP_U8_ALTIVEC
36 #define PREFIX_h264_qpel16_h_lowpass_altivec   put_h264_qpel16_h_lowpass_altivec
37 #define PREFIX_h264_qpel16_h_lowpass_num       altivec_put_h264_qpel16_h_lowpass_num
38 #define PREFIX_h264_qpel16_v_lowpass_altivec   put_h264_qpel16_v_lowpass_altivec
39 #define PREFIX_h264_qpel16_v_lowpass_num       altivec_put_h264_qpel16_v_lowpass_num
40 #define PREFIX_h264_qpel16_hv_lowpass_altivec  put_h264_qpel16_hv_lowpass_altivec
41 #define PREFIX_h264_qpel16_hv_lowpass_num      altivec_put_h264_qpel16_hv_lowpass_num
42 #include "h264_qpel_template.c"
43 #undef OP_U8_ALTIVEC
44 #undef PREFIX_h264_qpel16_h_lowpass_altivec
45 #undef PREFIX_h264_qpel16_h_lowpass_num
46 #undef PREFIX_h264_qpel16_v_lowpass_altivec
47 #undef PREFIX_h264_qpel16_v_lowpass_num
48 #undef PREFIX_h264_qpel16_hv_lowpass_altivec
49 #undef PREFIX_h264_qpel16_hv_lowpass_num
50
51 #define OP_U8_ALTIVEC                          AVG_OP_U8_ALTIVEC
52 #define PREFIX_h264_qpel16_h_lowpass_altivec   avg_h264_qpel16_h_lowpass_altivec
53 #define PREFIX_h264_qpel16_h_lowpass_num       altivec_avg_h264_qpel16_h_lowpass_num
54 #define PREFIX_h264_qpel16_v_lowpass_altivec   avg_h264_qpel16_v_lowpass_altivec
55 #define PREFIX_h264_qpel16_v_lowpass_num       altivec_avg_h264_qpel16_v_lowpass_num
56 #define PREFIX_h264_qpel16_hv_lowpass_altivec  avg_h264_qpel16_hv_lowpass_altivec
57 #define PREFIX_h264_qpel16_hv_lowpass_num      altivec_avg_h264_qpel16_hv_lowpass_num
58 #include "h264_qpel_template.c"
59 #undef OP_U8_ALTIVEC
60 #undef PREFIX_h264_qpel16_h_lowpass_altivec
61 #undef PREFIX_h264_qpel16_h_lowpass_num
62 #undef PREFIX_h264_qpel16_v_lowpass_altivec
63 #undef PREFIX_h264_qpel16_v_lowpass_num
64 #undef PREFIX_h264_qpel16_hv_lowpass_altivec
65 #undef PREFIX_h264_qpel16_hv_lowpass_num
66
67 #define H264_MC(OPNAME, SIZE, CODETYPE) \
68 static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, uint8_t *src, int stride){\
69     ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\
70 }\
71 \
72 static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){ \
73     DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
74     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
75     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
76 }\
77 \
78 static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
79     OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\
80 }\
81 \
82 static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
83     DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
84     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
85     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\
86 }\
87 \
88 static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
89     DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
90     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
91     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
92 }\
93 \
94 static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
95     OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\
96 }\
97 \
98 static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
99     DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
100     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
101     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\
102 }\
103 \
104 static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
105     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
106     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
107     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
108     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
109     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
110 }\
111 \
112 static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
113     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
114     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
115     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
116     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
117     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
118 }\
119 \
120 static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
121     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
122     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
123     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
124     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
125     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
126 }\
127 \
128 static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
129     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
130     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
131     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
132     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
133     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
134 }\
135 \
136 static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
137     DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
138     OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\
139 }\
140 \
141 static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
142     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
143     DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
144     DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
145     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
146     put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
147     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
148 }\
149 \
150 static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
151     DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
152     DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
153     DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
154     put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
155     put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
156     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
157 }\
158 \
159 static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
160     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
161     DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
162     DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
163     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
164     put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
165     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
166 }\
167 \
168 static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, uint8_t *src, int stride){\
169     DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
170     DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
171     DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
172     put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
173     put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
174     OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
175 }\
176
177 static inline void put_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
178                                     const uint8_t * src2, int dst_stride,
179                                     int src_stride1, int h)
180 {
181     int i;
182     vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align;
183
184     mask_ = vec_lvsl(0, src2);
185
186     for (i = 0; i < h; i++) {
187
188         tmp1 = vec_ld(i * src_stride1, src1);
189         mask = vec_lvsl(i * src_stride1, src1);
190         tmp2 = vec_ld(i * src_stride1 + 15, src1);
191
192         a = vec_perm(tmp1, tmp2, mask);
193
194         tmp1 = vec_ld(i * 16, src2);
195         tmp2 = vec_ld(i * 16 + 15, src2);
196
197         b = vec_perm(tmp1, tmp2, mask_);
198
199         tmp1 = vec_ld(0, dst);
200         mask = vec_lvsl(0, dst);
201         tmp2 = vec_ld(15, dst);
202
203         d = vec_avg(a, b);
204
205         edges = vec_perm(tmp2, tmp1, mask);
206
207         align = vec_lvsr(0, dst);
208
209         tmp2 = vec_perm(d, edges, align);
210         tmp1 = vec_perm(edges, d, align);
211
212         vec_st(tmp2, 15, dst);
213         vec_st(tmp1, 0 , dst);
214
215         dst += dst_stride;
216     }
217 }
218
219 static inline void avg_pixels16_l2_altivec( uint8_t * dst, const uint8_t * src1,
220                                     const uint8_t * src2, int dst_stride,
221                                     int src_stride1, int h)
222 {
223     int i;
224     vec_u8 a, b, d, tmp1, tmp2, mask, mask_, edges, align;
225
226     mask_ = vec_lvsl(0, src2);
227
228     for (i = 0; i < h; i++) {
229
230         tmp1 = vec_ld(i * src_stride1, src1);
231         mask = vec_lvsl(i * src_stride1, src1);
232         tmp2 = vec_ld(i * src_stride1 + 15, src1);
233
234         a = vec_perm(tmp1, tmp2, mask);
235
236         tmp1 = vec_ld(i * 16, src2);
237         tmp2 = vec_ld(i * 16 + 15, src2);
238
239         b = vec_perm(tmp1, tmp2, mask_);
240
241         tmp1 = vec_ld(0, dst);
242         mask = vec_lvsl(0, dst);
243         tmp2 = vec_ld(15, dst);
244
245         d = vec_avg(vec_perm(tmp1, tmp2, mask), vec_avg(a, b));
246
247         edges = vec_perm(tmp2, tmp1, mask);
248
249         align = vec_lvsr(0, dst);
250
251         tmp2 = vec_perm(d, edges, align);
252         tmp1 = vec_perm(edges, d, align);
253
254         vec_st(tmp2, 15, dst);
255         vec_st(tmp1, 0 , dst);
256
257         dst += dst_stride;
258     }
259 }
260
261 /* Implemented but could be faster
262 #define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h)
263 #define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h)
264  */
265
266 H264_MC(put_, 16, altivec)
267 H264_MC(avg_, 16, altivec)
268 #endif /* HAVE_ALTIVEC */
269
270 av_cold void ff_h264qpel_init_ppc(H264QpelContext *c, int bit_depth)
271 {
272 #if HAVE_ALTIVEC
273     const int high_bit_depth = bit_depth > 8;
274
275     if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
276     if (!high_bit_depth) {
277 #define dspfunc(PFX, IDX, NUM) \
278         c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \
279         c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \
280         c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \
281         c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \
282         c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \
283         c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \
284         c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \
285         c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \
286         c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \
287         c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \
288         c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \
289         c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \
290         c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \
291         c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \
292         c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \
293         c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec
294
295         dspfunc(put_h264_qpel, 0, 16);
296         dspfunc(avg_h264_qpel, 0, 16);
297 #undef dspfunc
298     }
299     }
300 #endif /* HAVE_ALTIVEC */
301 }