00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #include "libavutil/cpu.h"
00024 #include "libavutil/mem.h"
00025 #include "libavutil/ppc/types_altivec.h"
00026 #include "libavutil/ppc/util_altivec.h"
00027 #include "libavcodec/vp8dsp.h"
00028 #include "dsputil_altivec.h"
00029
00030 #define REPT4(...) { __VA_ARGS__, __VA_ARGS__, __VA_ARGS__, __VA_ARGS__ }
00031
00032
00033 static const vec_s8 h_subpel_filters_inner[7] =
00034 {
00035 REPT4( -6, 123, 12, -1),
00036 REPT4(-11, 108, 36, -8),
00037 REPT4( -9, 93, 50, -6),
00038 REPT4(-16, 77, 77, -16),
00039 REPT4( -6, 50, 93, -9),
00040 REPT4( -8, 36, 108, -11),
00041 REPT4( -1, 12, 123, -6),
00042 };
00043
00044
00045
00046
00047 static const vec_s8 h_subpel_filters_outer[3] =
00048 {
00049 REPT4(0, 0, 2, 1),
00050 REPT4(0, 0, 3, 3),
00051 REPT4(0, 0, 1, 2),
00052 };
00053
00054 #define LOAD_H_SUBPEL_FILTER(i) \
00055 vec_s8 filter_inner = h_subpel_filters_inner[i]; \
00056 vec_s8 filter_outerh = h_subpel_filters_outer[(i)>>1]; \
00057 vec_s8 filter_outerl = vec_sld(filter_outerh, filter_outerh, 2)
00058
00059 #define FILTER_H(dstv, off) \
00060 a = vec_ld((off)-is6tap-1, src); \
00061 b = vec_ld((off)-is6tap-1+15, src); \
00062 \
00063 pixh = vec_perm(a, b, permh##off); \
00064 pixl = vec_perm(a, b, perml##off); \
00065 filth = vec_msum(filter_inner, pixh, c64); \
00066 filtl = vec_msum(filter_inner, pixl, c64); \
00067 \
00068 if (is6tap) { \
00069 outer = vec_perm(a, b, perm_6tap##off); \
00070 filth = vec_msum(filter_outerh, outer, filth); \
00071 filtl = vec_msum(filter_outerl, outer, filtl); \
00072 } \
00073 if (w == 4) \
00074 filtl = filth; \
00075 dstv = vec_packs(filth, filtl); \
00076 dstv = vec_sra(dstv, c7)
00077
00078 static av_always_inline
00079 void put_vp8_epel_h_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
00080 uint8_t *src, ptrdiff_t src_stride,
00081 int h, int mx, int w, int is6tap)
00082 {
00083 LOAD_H_SUBPEL_FILTER(mx-1);
00084 vec_u8 align_vec0, align_vec8, permh0, permh8, filt;
00085 vec_u8 perm_6tap0, perm_6tap8, perml0, perml8;
00086 vec_u8 a, b, pixh, pixl, outer;
00087 vec_s16 f16h, f16l;
00088 vec_s32 filth, filtl;
00089
00090 vec_u8 perm_inner6 = { 1,2,3,4, 2,3,4,5, 3,4,5,6, 4,5,6,7 };
00091 vec_u8 perm_inner4 = { 0,1,2,3, 1,2,3,4, 2,3,4,5, 3,4,5,6 };
00092 vec_u8 perm_inner = is6tap ? perm_inner6 : perm_inner4;
00093 vec_u8 perm_outer = { 4,9, 0,5, 5,10, 1,6, 6,11, 2,7, 7,12, 3,8 };
00094 vec_s32 c64 = vec_sl(vec_splat_s32(1), vec_splat_u32(6));
00095 vec_u16 c7 = vec_splat_u16(7);
00096
00097 align_vec0 = vec_lvsl( -is6tap-1, src);
00098 align_vec8 = vec_lvsl(8-is6tap-1, src);
00099
00100 permh0 = vec_perm(align_vec0, align_vec0, perm_inner);
00101 permh8 = vec_perm(align_vec8, align_vec8, perm_inner);
00102 perm_inner = vec_add(perm_inner, vec_splat_u8(4));
00103 perml0 = vec_perm(align_vec0, align_vec0, perm_inner);
00104 perml8 = vec_perm(align_vec8, align_vec8, perm_inner);
00105 perm_6tap0 = vec_perm(align_vec0, align_vec0, perm_outer);
00106 perm_6tap8 = vec_perm(align_vec8, align_vec8, perm_outer);
00107
00108 while (h --> 0) {
00109 FILTER_H(f16h, 0);
00110
00111 if (w == 16) {
00112 FILTER_H(f16l, 8);
00113 filt = vec_packsu(f16h, f16l);
00114 vec_st(filt, 0, dst);
00115 } else {
00116 filt = vec_packsu(f16h, f16h);
00117 vec_ste((vec_u32)filt, 0, (uint32_t*)dst);
00118 if (w == 8)
00119 vec_ste((vec_u32)filt, 4, (uint32_t*)dst);
00120 }
00121 src += src_stride;
00122 dst += dst_stride;
00123 }
00124 }
00125
00126
00127 static const vec_u8 v_subpel_filters[7] =
00128 {
00129 { 0, 6, 123, 12, 1, 0 },
00130 { 2, 11, 108, 36, 8, 1 },
00131 { 0, 9, 93, 50, 6, 0 },
00132 { 3, 16, 77, 77, 16, 3 },
00133 { 0, 6, 50, 93, 9, 0 },
00134 { 1, 8, 36, 108, 11, 2 },
00135 { 0, 1, 12, 123, 6, 0 },
00136 };
00137
00138 #define LOAD_V_SUBPEL_FILTER(i) \
00139 vec_u8 subpel_filter = v_subpel_filters[i]; \
00140 vec_u8 f0 = vec_splat(subpel_filter, 0); \
00141 vec_u8 f1 = vec_splat(subpel_filter, 1); \
00142 vec_u8 f2 = vec_splat(subpel_filter, 2); \
00143 vec_u8 f3 = vec_splat(subpel_filter, 3); \
00144 vec_u8 f4 = vec_splat(subpel_filter, 4); \
00145 vec_u8 f5 = vec_splat(subpel_filter, 5)
00146
00147 #define FILTER_V(dstv, vec_mul) \
00148 s1f = (vec_s16)vec_mul(s1, f1); \
00149 s2f = (vec_s16)vec_mul(s2, f2); \
00150 s3f = (vec_s16)vec_mul(s3, f3); \
00151 s4f = (vec_s16)vec_mul(s4, f4); \
00152 s2f = vec_subs(s2f, s1f); \
00153 s3f = vec_subs(s3f, s4f); \
00154 if (is6tap) { \
00155 s0f = (vec_s16)vec_mul(s0, f0); \
00156 s5f = (vec_s16)vec_mul(s5, f5); \
00157 s2f = vec_adds(s2f, s0f); \
00158 s3f = vec_adds(s3f, s5f); \
00159 } \
00160 dstv = vec_adds(s2f, s3f); \
00161 dstv = vec_adds(dstv, c64); \
00162 dstv = vec_sra(dstv, c7)
00163
00164 static av_always_inline
00165 void put_vp8_epel_v_altivec_core(uint8_t *dst, ptrdiff_t dst_stride,
00166 uint8_t *src, ptrdiff_t src_stride,
00167 int h, int my, int w, int is6tap)
00168 {
00169 LOAD_V_SUBPEL_FILTER(my-1);
00170 vec_u8 s0, s1, s2, s3, s4, s5, filt, align_vech, perm_vec, align_vecl;
00171 vec_s16 s0f, s1f, s2f, s3f, s4f, s5f, f16h, f16l;
00172 vec_s16 c64 = vec_sl(vec_splat_s16(1), vec_splat_u16(6));
00173 vec_u16 c7 = vec_splat_u16(7);
00174
00175
00176
00177 align_vech = vec_lvsl(0, src);
00178 align_vecl = vec_sld(align_vech, align_vech, 8);
00179 if (w ==16)
00180 perm_vec = vec_mergeh(align_vech, align_vecl);
00181 else
00182 perm_vec = vec_mergeh(align_vech, align_vech);
00183
00184 if (is6tap)
00185 s0 = load_with_perm_vec(-2*src_stride, src, perm_vec);
00186 s1 = load_with_perm_vec(-1*src_stride, src, perm_vec);
00187 s2 = load_with_perm_vec( 0*src_stride, src, perm_vec);
00188 s3 = load_with_perm_vec( 1*src_stride, src, perm_vec);
00189 if (is6tap)
00190 s4 = load_with_perm_vec( 2*src_stride, src, perm_vec);
00191
00192 src += (2+is6tap)*src_stride;
00193
00194 while (h --> 0) {
00195 if (is6tap)
00196 s5 = load_with_perm_vec(0, src, perm_vec);
00197 else
00198 s4 = load_with_perm_vec(0, src, perm_vec);
00199
00200 FILTER_V(f16h, vec_mule);
00201
00202 if (w == 16) {
00203 FILTER_V(f16l, vec_mulo);
00204 filt = vec_packsu(f16h, f16l);
00205 vec_st(filt, 0, dst);
00206 } else {
00207 filt = vec_packsu(f16h, f16h);
00208 if (w == 4)
00209 filt = (vec_u8)vec_splat((vec_u32)filt, 0);
00210 else
00211 vec_ste((vec_u32)filt, 4, (uint32_t*)dst);
00212 vec_ste((vec_u32)filt, 0, (uint32_t*)dst);
00213 }
00214
00215 if (is6tap)
00216 s0 = s1;
00217 s1 = s2;
00218 s2 = s3;
00219 s3 = s4;
00220 if (is6tap)
00221 s4 = s5;
00222
00223 dst += dst_stride;
00224 src += src_stride;
00225 }
00226 }
00227
00228 #define EPEL_FUNCS(WIDTH, TAPS) \
00229 static av_noinline \
00230 void put_vp8_epel ## WIDTH ## _h ## TAPS ## _altivec(uint8_t *dst, ptrdiff_t dst_stride, uint8_t *src, ptrdiff_t src_stride, int h, int mx, int my) \
00231 { \
00232 put_vp8_epel_h_altivec_core(dst, dst_stride, src, src_stride, h, mx, WIDTH, TAPS == 6); \
00233 } \
00234 \
00235 static av_noinline \
00236 void put_vp8_epel ## WIDTH ## _v ## TAPS ## _altivec(uint8_t *dst, ptrdiff_t dst_stride, uint8_t *src, ptrdiff_t src_stride, int h, int mx, int my) \
00237 { \
00238 put_vp8_epel_v_altivec_core(dst, dst_stride, src, src_stride, h, my, WIDTH, TAPS == 6); \
00239 }
00240
00241 #define EPEL_HV(WIDTH, HTAPS, VTAPS) \
00242 static void put_vp8_epel ## WIDTH ## _h ## HTAPS ## v ## VTAPS ## _altivec(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s, int h, int mx, int my) \
00243 { \
00244 DECLARE_ALIGNED(16, uint8_t, tmp)[(2*WIDTH+5)*16]; \
00245 if (VTAPS == 6) { \
00246 put_vp8_epel ## WIDTH ## _h ## HTAPS ## _altivec(tmp, 16, src-2*stride, stride, h+5, mx, my); \
00247 put_vp8_epel ## WIDTH ## _v ## VTAPS ## _altivec(dst, stride, tmp+2*16, 16, h, mx, my); \
00248 } else { \
00249 put_vp8_epel ## WIDTH ## _h ## HTAPS ## _altivec(tmp, 16, src-stride, stride, h+4, mx, my); \
00250 put_vp8_epel ## WIDTH ## _v ## VTAPS ## _altivec(dst, stride, tmp+16, 16, h, mx, my); \
00251 } \
00252 }
00253
00254 EPEL_FUNCS(16,6)
00255 EPEL_FUNCS(8, 6)
00256 EPEL_FUNCS(8, 4)
00257 EPEL_FUNCS(4, 6)
00258 EPEL_FUNCS(4, 4)
00259
00260 EPEL_HV(16, 6,6)
00261 EPEL_HV(8, 6,6)
00262 EPEL_HV(8, 4,6)
00263 EPEL_HV(8, 6,4)
00264 EPEL_HV(8, 4,4)
00265 EPEL_HV(4, 6,6)
00266 EPEL_HV(4, 4,6)
00267 EPEL_HV(4, 6,4)
00268 EPEL_HV(4, 4,4)
00269
00270 static void put_vp8_pixels16_altivec(uint8_t *dst, ptrdiff_t stride, uint8_t *src, ptrdiff_t s, int h, int mx, int my)
00271 {
00272 ff_put_pixels16_altivec(dst, src, stride, h);
00273 }
00274
00275 av_cold void ff_vp8dsp_init_altivec(VP8DSPContext *c)
00276 {
00277 if (!(av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC))
00278 return;
00279
00280 c->put_vp8_epel_pixels_tab[0][0][0] = put_vp8_pixels16_altivec;
00281 c->put_vp8_epel_pixels_tab[0][0][2] = put_vp8_epel16_h6_altivec;
00282 c->put_vp8_epel_pixels_tab[0][2][0] = put_vp8_epel16_v6_altivec;
00283 c->put_vp8_epel_pixels_tab[0][2][2] = put_vp8_epel16_h6v6_altivec;
00284
00285 c->put_vp8_epel_pixels_tab[1][0][2] = put_vp8_epel8_h6_altivec;
00286 c->put_vp8_epel_pixels_tab[1][2][0] = put_vp8_epel8_v6_altivec;
00287 c->put_vp8_epel_pixels_tab[1][0][1] = put_vp8_epel8_h4_altivec;
00288 c->put_vp8_epel_pixels_tab[1][1][0] = put_vp8_epel8_v4_altivec;
00289
00290 c->put_vp8_epel_pixels_tab[1][2][2] = put_vp8_epel8_h6v6_altivec;
00291 c->put_vp8_epel_pixels_tab[1][1][1] = put_vp8_epel8_h4v4_altivec;
00292 c->put_vp8_epel_pixels_tab[1][1][2] = put_vp8_epel8_h6v4_altivec;
00293 c->put_vp8_epel_pixels_tab[1][2][1] = put_vp8_epel8_h4v6_altivec;
00294
00295 c->put_vp8_epel_pixels_tab[2][0][2] = put_vp8_epel4_h6_altivec;
00296 c->put_vp8_epel_pixels_tab[2][2][0] = put_vp8_epel4_v6_altivec;
00297 c->put_vp8_epel_pixels_tab[2][0][1] = put_vp8_epel4_h4_altivec;
00298 c->put_vp8_epel_pixels_tab[2][1][0] = put_vp8_epel4_v4_altivec;
00299
00300 c->put_vp8_epel_pixels_tab[2][2][2] = put_vp8_epel4_h6v6_altivec;
00301 c->put_vp8_epel_pixels_tab[2][1][1] = put_vp8_epel4_h4v4_altivec;
00302 c->put_vp8_epel_pixels_tab[2][1][2] = put_vp8_epel4_h6v4_altivec;
00303 c->put_vp8_epel_pixels_tab[2][2][1] = put_vp8_epel4_h4v6_altivec;
00304 }