00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #include "config.h"
00022 #include "libavutil/attributes.h"
00023 #include "libavutil/cpu.h"
00024 #include "libavcodec/vp3dsp.h"
00025
00026 #if HAVE_ALTIVEC
00027
00028 #include "libavutil/ppc/types_altivec.h"
00029 #include "libavutil/ppc/util_altivec.h"
00030 #include "libavcodec/dsputil.h"
00031 #include "dsputil_altivec.h"
00032
00033 static const vec_s16 constants =
00034 {0, 64277, 60547, 54491, 46341, 36410, 25080, 12785};
00035 static const vec_u8 interleave_high =
00036 {0, 1, 16, 17, 4, 5, 20, 21, 8, 9, 24, 25, 12, 13, 28, 29};
00037
00038 #define IDCT_START \
00039 vec_s16 A, B, C, D, Ad, Bd, Cd, Dd, E, F, G, H;\
00040 vec_s16 Ed, Gd, Add, Bdd, Fd, Hd;\
00041 vec_s16 eight = vec_splat_s16(8);\
00042 vec_u16 four = vec_splat_u16(4);\
00043 \
00044 vec_s16 C1 = vec_splat(constants, 1);\
00045 vec_s16 C2 = vec_splat(constants, 2);\
00046 vec_s16 C3 = vec_splat(constants, 3);\
00047 vec_s16 C4 = vec_splat(constants, 4);\
00048 vec_s16 C5 = vec_splat(constants, 5);\
00049 vec_s16 C6 = vec_splat(constants, 6);\
00050 vec_s16 C7 = vec_splat(constants, 7);\
00051 \
00052 vec_s16 b0 = vec_ld(0x00, block);\
00053 vec_s16 b1 = vec_ld(0x10, block);\
00054 vec_s16 b2 = vec_ld(0x20, block);\
00055 vec_s16 b3 = vec_ld(0x30, block);\
00056 vec_s16 b4 = vec_ld(0x40, block);\
00057 vec_s16 b5 = vec_ld(0x50, block);\
00058 vec_s16 b6 = vec_ld(0x60, block);\
00059 vec_s16 b7 = vec_ld(0x70, block);
00060
00061
00062
00063
00064
00065 static inline vec_s16 M15(vec_s16 a, vec_s16 C)
00066 {
00067 return (vec_s16)vec_perm(vec_mule(a,C), vec_mulo(a,C), interleave_high);
00068 }
00069 static inline vec_s16 M16(vec_s16 a, vec_s16 C)
00070 {
00071 return vec_add(a, M15(a, C));
00072 }
00073
00074 #define IDCT_1D(ADD, SHIFT)\
00075 A = vec_add(M16(b1, C1), M15(b7, C7));\
00076 B = vec_sub(M15(b1, C7), M16(b7, C1));\
00077 C = vec_add(M16(b3, C3), M16(b5, C5));\
00078 D = vec_sub(M16(b5, C3), M16(b3, C5));\
00079 \
00080 Ad = M16(vec_sub(A, C), C4);\
00081 Bd = M16(vec_sub(B, D), C4);\
00082 \
00083 Cd = vec_add(A, C);\
00084 Dd = vec_add(B, D);\
00085 \
00086 E = ADD(M16(vec_add(b0, b4), C4));\
00087 F = ADD(M16(vec_sub(b0, b4), C4));\
00088 \
00089 G = vec_add(M16(b2, C2), M15(b6, C6));\
00090 H = vec_sub(M15(b2, C6), M16(b6, C2));\
00091 \
00092 Ed = vec_sub(E, G);\
00093 Gd = vec_add(E, G);\
00094 \
00095 Add = vec_add(F, Ad);\
00096 Bdd = vec_sub(Bd, H);\
00097 \
00098 Fd = vec_sub(F, Ad);\
00099 Hd = vec_add(Bd, H);\
00100 \
00101 b0 = SHIFT(vec_add(Gd, Cd));\
00102 b7 = SHIFT(vec_sub(Gd, Cd));\
00103 \
00104 b1 = SHIFT(vec_add(Add, Hd));\
00105 b2 = SHIFT(vec_sub(Add, Hd));\
00106 \
00107 b3 = SHIFT(vec_add(Ed, Dd));\
00108 b4 = SHIFT(vec_sub(Ed, Dd));\
00109 \
00110 b5 = SHIFT(vec_add(Fd, Bdd));\
00111 b6 = SHIFT(vec_sub(Fd, Bdd));
00112
00113 #define NOP(a) a
00114 #define ADD8(a) vec_add(a, eight)
00115 #define SHIFT4(a) vec_sra(a, four)
00116
00117 static void vp3_idct_put_altivec(uint8_t *dst, int stride, DCTELEM block[64])
00118 {
00119 vec_u8 t;
00120 IDCT_START
00121
00122
00123 vec_s16 v2048 = vec_sl(vec_splat_s16(1), vec_splat_u16(11));
00124 eight = vec_add(eight, v2048);
00125
00126 IDCT_1D(NOP, NOP)
00127 TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
00128 IDCT_1D(ADD8, SHIFT4)
00129
00130 #define PUT(a)\
00131 t = vec_packsu(a, a);\
00132 vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
00133 vec_ste((vec_u32)t, 4, (unsigned int *)dst);
00134
00135 PUT(b0) dst += stride;
00136 PUT(b1) dst += stride;
00137 PUT(b2) dst += stride;
00138 PUT(b3) dst += stride;
00139 PUT(b4) dst += stride;
00140 PUT(b5) dst += stride;
00141 PUT(b6) dst += stride;
00142 PUT(b7)
00143 }
00144
00145 static void vp3_idct_add_altivec(uint8_t *dst, int stride, DCTELEM block[64])
00146 {
00147 LOAD_ZERO;
00148 vec_u8 t, vdst;
00149 vec_s16 vdst_16;
00150 vec_u8 vdst_mask = vec_mergeh(vec_splat_u8(-1), vec_lvsl(0, dst));
00151
00152 IDCT_START
00153
00154 IDCT_1D(NOP, NOP)
00155 TRANSPOSE8(b0, b1, b2, b3, b4, b5, b6, b7);
00156 IDCT_1D(ADD8, SHIFT4)
00157
00158 #define ADD(a)\
00159 vdst = vec_ld(0, dst);\
00160 vdst_16 = (vec_s16)vec_perm(vdst, zero_u8v, vdst_mask);\
00161 vdst_16 = vec_adds(a, vdst_16);\
00162 t = vec_packsu(vdst_16, vdst_16);\
00163 vec_ste((vec_u32)t, 0, (unsigned int *)dst);\
00164 vec_ste((vec_u32)t, 4, (unsigned int *)dst);
00165
00166 ADD(b0) dst += stride;
00167 ADD(b1) dst += stride;
00168 ADD(b2) dst += stride;
00169 ADD(b3) dst += stride;
00170 ADD(b4) dst += stride;
00171 ADD(b5) dst += stride;
00172 ADD(b6) dst += stride;
00173 ADD(b7)
00174 }
00175
00176 #endif
00177
00178 av_cold void ff_vp3dsp_init_ppc(VP3DSPContext *c, int flags)
00179 {
00180 #if HAVE_ALTIVEC
00181 if (av_get_cpu_flags() & AV_CPU_FLAG_ALTIVEC) {
00182 c->idct_put = vp3_idct_put_altivec;
00183 c->idct_add = vp3_idct_add_altivec;
00184 c->idct_perm = FF_TRANSPOSE_IDCT_PERM;
00185 }
00186 #endif
00187 }