575f504d325c5b57127f437494a97a9785a5bcd9
2 * Copyright (c) 2004 Romain Dolbeau <romain@dolbeau.org>
4 * This file is part of FFmpeg.
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.
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.
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
22 #include "libavutil/attributes.h"
23 #include "libavutil/cpu.h"
24 #include "libavutil/intreadwrite.h"
25 #include "libavutil/ppc/cpu.h"
26 #include "libavutil/ppc/types_altivec.h"
27 #include "libavutil/ppc/util_altivec.h"
28 #include "libavcodec/h264qpel.h"
29 #include "hpeldsp_altivec.h"
33 #define PUT_OP_U8_ALTIVEC(d, s, dst) d = s
34 #define AVG_OP_U8_ALTIVEC(d, s, dst) d = vec_avg(dst, s)
36 #define OP_U8_ALTIVEC PUT_OP_U8_ALTIVEC
37 #define PREFIX_h264_qpel16_h_lowpass_altivec put_h264_qpel16_h_lowpass_altivec
38 #define PREFIX_h264_qpel16_h_lowpass_num altivec_put_h264_qpel16_h_lowpass_num
39 #define PREFIX_h264_qpel16_v_lowpass_altivec put_h264_qpel16_v_lowpass_altivec
40 #define PREFIX_h264_qpel16_v_lowpass_num altivec_put_h264_qpel16_v_lowpass_num
41 #define PREFIX_h264_qpel16_hv_lowpass_altivec put_h264_qpel16_hv_lowpass_altivec
42 #define PREFIX_h264_qpel16_hv_lowpass_num altivec_put_h264_qpel16_hv_lowpass_num
43 #include "h264qpel_template.c"
45 #undef PREFIX_h264_qpel16_h_lowpass_altivec
46 #undef PREFIX_h264_qpel16_h_lowpass_num
47 #undef PREFIX_h264_qpel16_v_lowpass_altivec
48 #undef PREFIX_h264_qpel16_v_lowpass_num
49 #undef PREFIX_h264_qpel16_hv_lowpass_altivec
50 #undef PREFIX_h264_qpel16_hv_lowpass_num
52 #define OP_U8_ALTIVEC AVG_OP_U8_ALTIVEC
53 #define PREFIX_h264_qpel16_h_lowpass_altivec avg_h264_qpel16_h_lowpass_altivec
54 #define PREFIX_h264_qpel16_h_lowpass_num altivec_avg_h264_qpel16_h_lowpass_num
55 #define PREFIX_h264_qpel16_v_lowpass_altivec avg_h264_qpel16_v_lowpass_altivec
56 #define PREFIX_h264_qpel16_v_lowpass_num altivec_avg_h264_qpel16_v_lowpass_num
57 #define PREFIX_h264_qpel16_hv_lowpass_altivec avg_h264_qpel16_hv_lowpass_altivec
58 #define PREFIX_h264_qpel16_hv_lowpass_num altivec_avg_h264_qpel16_hv_lowpass_num
59 #include "h264qpel_template.c"
61 #undef PREFIX_h264_qpel16_h_lowpass_altivec
62 #undef PREFIX_h264_qpel16_h_lowpass_num
63 #undef PREFIX_h264_qpel16_v_lowpass_altivec
64 #undef PREFIX_h264_qpel16_v_lowpass_num
65 #undef PREFIX_h264_qpel16_hv_lowpass_altivec
66 #undef PREFIX_h264_qpel16_hv_lowpass_num
68 #define H264_MC(OPNAME, SIZE, CODETYPE) \
69 static void OPNAME ## h264_qpel ## SIZE ## _mc00_ ## CODETYPE (uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
71 ff_ ## OPNAME ## pixels ## SIZE ## _ ## CODETYPE(dst, src, stride, SIZE);\
74 static void OPNAME ## h264_qpel ## SIZE ## _mc10_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
76 DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
77 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
78 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
81 static void OPNAME ## h264_qpel ## SIZE ## _mc20_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
83 OPNAME ## h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(dst, src, stride, stride);\
86 static void OPNAME ## h264_qpel ## SIZE ## _mc30_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
88 DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
89 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
90 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+1, half, stride, stride, SIZE);\
93 static void OPNAME ## h264_qpel ## SIZE ## _mc01_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
95 DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
96 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
97 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src, half, stride, stride, SIZE);\
100 static void OPNAME ## h264_qpel ## SIZE ## _mc02_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
102 OPNAME ## h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(dst, src, stride, stride);\
105 static void OPNAME ## h264_qpel ## SIZE ## _mc03_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
107 DECLARE_ALIGNED(16, uint8_t, half)[SIZE*SIZE];\
108 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(half, src, SIZE, stride);\
109 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, src+stride, half, stride, stride, SIZE);\
112 static void OPNAME ## h264_qpel ## SIZE ## _mc11_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
114 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
115 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
116 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
117 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
118 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
121 static void OPNAME ## h264_qpel ## SIZE ## _mc31_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
123 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
124 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
125 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
126 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
127 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
130 static void OPNAME ## h264_qpel ## SIZE ## _mc13_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
132 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
133 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
134 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
135 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
136 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
139 static void OPNAME ## h264_qpel ## SIZE ## _mc33_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
141 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
142 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
143 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
144 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
145 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfV, stride, SIZE, SIZE);\
148 static void OPNAME ## h264_qpel ## SIZE ## _mc22_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
150 DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
151 OPNAME ## h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(dst, tmp, src, stride, SIZE, stride);\
154 static void OPNAME ## h264_qpel ## SIZE ## _mc21_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
156 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
157 DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
158 DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
159 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src, SIZE, stride);\
160 put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
161 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
164 static void OPNAME ## h264_qpel ## SIZE ## _mc23_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
166 DECLARE_ALIGNED(16, uint8_t, halfH)[SIZE*SIZE];\
167 DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
168 DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
169 put_h264_qpel ## SIZE ## _h_lowpass_ ## CODETYPE(halfH, src + stride, SIZE, stride);\
170 put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
171 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfH, halfHV, stride, SIZE, SIZE);\
174 static void OPNAME ## h264_qpel ## SIZE ## _mc12_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
176 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
177 DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
178 DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
179 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src, SIZE, stride);\
180 put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
181 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
184 static void OPNAME ## h264_qpel ## SIZE ## _mc32_ ## CODETYPE(uint8_t *dst, const uint8_t *src, ptrdiff_t stride)\
186 DECLARE_ALIGNED(16, uint8_t, halfV)[SIZE*SIZE];\
187 DECLARE_ALIGNED(16, uint8_t, halfHV)[SIZE*SIZE];\
188 DECLARE_ALIGNED(16, int16_t, tmp)[SIZE*(SIZE+8)];\
189 put_h264_qpel ## SIZE ## _v_lowpass_ ## CODETYPE(halfV, src+1, SIZE, stride);\
190 put_h264_qpel ## SIZE ## _hv_lowpass_ ## CODETYPE(halfHV, tmp, src, SIZE, SIZE, stride);\
191 OPNAME ## pixels ## SIZE ## _l2_ ## CODETYPE(dst, halfV, halfHV, stride, SIZE, SIZE);\
195 #define put_unligned_store(s, dest) { \
196 tmp1 = vec_ld(0, dest); \
197 mask = vec_lvsl(0, dest); \
198 tmp2 = vec_ld(15, dest); \
199 edges = vec_perm(tmp2, tmp1, mask); \
200 align = vec_lvsr(0, dest); \
201 tmp2 = vec_perm(s, edges, align); \
202 tmp1 = vec_perm(edges, s, align); \
203 vec_st(tmp2, 15, dest); \
204 vec_st(tmp1, 0 , dest); \
207 #define put_unligned_store(s, dest) vec_vsx_st(s, 0, dest);
208 #endif /* HAVE_BIGENDIAN */
210 static inline void put_pixels16_l2_altivec( uint8_t * dst
, const uint8_t * src1
,
211 const uint8_t * src2
, int dst_stride
,
212 int src_stride1
, int h
)
215 vec_u8 a
, b
, d
, mask_
;
217 vec_u8 tmp1
, tmp2
, mask
, edges
, align
;
218 mask_
= vec_lvsl(0, src2
);
221 for (i
= 0; i
< h
; i
++) {
222 a
= unaligned_load(i
* src_stride1
, src1
);
223 b
= load_with_perm_vec(i
* 16, src2
, mask_
);
225 put_unligned_store(d
, dst
);
231 #define avg_unligned_store(s, dest){ \
232 tmp1 = vec_ld(0, dest); \
233 mask = vec_lvsl(0, dest); \
234 tmp2 = vec_ld(15, dest); \
235 a = vec_avg(vec_perm(tmp1, tmp2, mask), s); \
236 edges = vec_perm(tmp2, tmp1, mask); \
237 align = vec_lvsr(0, dest); \
238 tmp2 = vec_perm(a, edges, align); \
239 tmp1 = vec_perm(edges, a, align); \
240 vec_st(tmp2, 15, dest); \
241 vec_st(tmp1, 0 , dest); \
244 #define avg_unligned_store(s, dest){ \
245 a = vec_avg(vec_vsx_ld(0, dst), s); \
246 vec_vsx_st(a, 0, dst); \
248 #endif /* HAVE_BIGENDIAN */
250 static inline void avg_pixels16_l2_altivec( uint8_t * dst
, const uint8_t * src1
,
251 const uint8_t * src2
, int dst_stride
,
252 int src_stride1
, int h
)
255 vec_u8 a
, b
, d
, mask_
;
258 vec_u8 tmp1
, tmp2
, mask
, edges
, align
;
259 mask_
= vec_lvsl(0, src2
);
262 for (i
= 0; i
< h
; i
++) {
263 a
= unaligned_load(i
* src_stride1
, src1
);
264 b
= load_with_perm_vec(i
* 16, src2
, mask_
);
266 avg_unligned_store(d
, dst
);
271 /* Implemented but could be faster
272 #define put_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) put_pixels16_l2(d,s1,s2,ds,s1s,16,h)
273 #define avg_pixels16_l2_altivec(d,s1,s2,ds,s1s,h) avg_pixels16_l2(d,s1,s2,ds,s1s,16,h)
276 H264_MC(put_
, 16, altivec
)
277 H264_MC(avg_
, 16, altivec
)
278 #endif /* HAVE_ALTIVEC */
280 av_cold
void ff_h264qpel_init_ppc(H264QpelContext
*c
, int bit_depth
)
283 const int high_bit_depth
= bit_depth
> 8;
285 if (!PPC_ALTIVEC(av_get_cpu_flags()))
288 if (!high_bit_depth
) {
289 #define dspfunc(PFX, IDX, NUM) \
290 c->PFX ## _pixels_tab[IDX][ 0] = PFX ## NUM ## _mc00_altivec; \
291 c->PFX ## _pixels_tab[IDX][ 1] = PFX ## NUM ## _mc10_altivec; \
292 c->PFX ## _pixels_tab[IDX][ 2] = PFX ## NUM ## _mc20_altivec; \
293 c->PFX ## _pixels_tab[IDX][ 3] = PFX ## NUM ## _mc30_altivec; \
294 c->PFX ## _pixels_tab[IDX][ 4] = PFX ## NUM ## _mc01_altivec; \
295 c->PFX ## _pixels_tab[IDX][ 5] = PFX ## NUM ## _mc11_altivec; \
296 c->PFX ## _pixels_tab[IDX][ 6] = PFX ## NUM ## _mc21_altivec; \
297 c->PFX ## _pixels_tab[IDX][ 7] = PFX ## NUM ## _mc31_altivec; \
298 c->PFX ## _pixels_tab[IDX][ 8] = PFX ## NUM ## _mc02_altivec; \
299 c->PFX ## _pixels_tab[IDX][ 9] = PFX ## NUM ## _mc12_altivec; \
300 c->PFX ## _pixels_tab[IDX][10] = PFX ## NUM ## _mc22_altivec; \
301 c->PFX ## _pixels_tab[IDX][11] = PFX ## NUM ## _mc32_altivec; \
302 c->PFX ## _pixels_tab[IDX][12] = PFX ## NUM ## _mc03_altivec; \
303 c->PFX ## _pixels_tab[IDX][13] = PFX ## NUM ## _mc13_altivec; \
304 c->PFX ## _pixels_tab[IDX][14] = PFX ## NUM ## _mc23_altivec; \
305 c->PFX ## _pixels_tab[IDX][15] = PFX ## NUM ## _mc33_altivec
307 dspfunc(put_h264_qpel
, 0, 16);
308 dspfunc(avg_h264_qpel
, 0, 16);
311 #endif /* HAVE_ALTIVEC */