00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00026 #include "config.h"
00027 #if HAVE_ALTIVEC_H
00028 #include <altivec.h>
00029 #endif
00030
00031 #include "libavutil/ppc/types_altivec.h"
00032 #include "libavcodec/dsputil.h"
00033
00034 #include "dsputil_altivec.h"
00035
00036 static int ssd_int8_vs_int16_altivec(const int8_t *pix1, const int16_t *pix2,
00037 int size) {
00038 int i, size16;
00039 vector signed char vpix1;
00040 vector signed short vpix2, vdiff, vpix1l,vpix1h;
00041 union { vector signed int vscore;
00042 int32_t score[4];
00043 } u;
00044 u.vscore = vec_splat_s32(0);
00045
00046
00047
00048 #define vec_unaligned_load(b) \
00049 vec_perm(vec_ld(0,b),vec_ld(15,b),vec_lvsl(0, b));
00050
00051 size16 = size >> 4;
00052 while(size16) {
00053
00054
00055
00056 vpix1 = vec_unaligned_load(pix1);
00057 vpix2 = vec_unaligned_load(pix2);
00058 pix2 += 8;
00059
00060 vpix1h = vec_unpackh(vpix1);
00061 vdiff = vec_sub(vpix1h, vpix2);
00062 vpix1l = vec_unpackl(vpix1);
00063
00064 vpix2 = vec_unaligned_load(pix2);
00065 u.vscore = vec_msum(vdiff, vdiff, u.vscore);
00066 vdiff = vec_sub(vpix1l, vpix2);
00067 u.vscore = vec_msum(vdiff, vdiff, u.vscore);
00068 pix1 += 16;
00069 pix2 += 8;
00070 size16--;
00071 }
00072 u.vscore = vec_sums(u.vscore, vec_splat_s32(0));
00073
00074 size %= 16;
00075 for (i = 0; i < size; i++) {
00076 u.score[3] += (pix1[i]-pix2[i])*(pix1[i]-pix2[i]);
00077 }
00078 return u.score[3];
00079 }
00080
00081 static int32_t scalarproduct_int16_altivec(const int16_t *v1, const int16_t *v2,
00082 int order)
00083 {
00084 int i;
00085 LOAD_ZERO;
00086 const vec_s16 *pv;
00087 register vec_s16 vec1;
00088 register vec_s32 res = vec_splat_s32(0), t;
00089 int32_t ires;
00090
00091 for(i = 0; i < order; i += 8){
00092 pv = (const vec_s16*)v1;
00093 vec1 = vec_perm(pv[0], pv[1], vec_lvsl(0, v1));
00094 t = vec_msum(vec1, vec_ld(0, v2), zero_s32v);
00095 res = vec_sums(t, res);
00096 v1 += 8;
00097 v2 += 8;
00098 }
00099 res = vec_splat(res, 3);
00100 vec_ste(res, 0, &ires);
00101 return ires;
00102 }
00103
00104 static int32_t scalarproduct_and_madd_int16_altivec(int16_t *v1, const int16_t *v2, const int16_t *v3, int order, int mul)
00105 {
00106 LOAD_ZERO;
00107 vec_s16 *pv1 = (vec_s16*)v1;
00108 register vec_s16 muls = {mul,mul,mul,mul,mul,mul,mul,mul};
00109 register vec_s16 t0, t1, i0, i1, i4;
00110 register vec_s16 i2 = vec_ld(0, v2), i3 = vec_ld(0, v3);
00111 register vec_s32 res = zero_s32v;
00112 register vec_u8 align = vec_lvsl(0, v2);
00113 int32_t ires;
00114 order >>= 4;
00115 do {
00116 i1 = vec_ld(16, v2);
00117 t0 = vec_perm(i2, i1, align);
00118 i2 = vec_ld(32, v2);
00119 t1 = vec_perm(i1, i2, align);
00120 i0 = pv1[0];
00121 i1 = pv1[1];
00122 res = vec_msum(t0, i0, res);
00123 res = vec_msum(t1, i1, res);
00124 i4 = vec_ld(16, v3);
00125 t0 = vec_perm(i3, i4, align);
00126 i3 = vec_ld(32, v3);
00127 t1 = vec_perm(i4, i3, align);
00128 pv1[0] = vec_mladd(t0, muls, i0);
00129 pv1[1] = vec_mladd(t1, muls, i1);
00130 pv1 += 2;
00131 v2 += 8;
00132 v3 += 8;
00133 } while(--order);
00134 res = vec_splat(vec_sums(res, zero_s32v), 3);
00135 vec_ste(res, 0, &ires);
00136 return ires;
00137 }
00138
00139 void ff_int_init_altivec(DSPContext* c, AVCodecContext *avctx)
00140 {
00141 c->ssd_int8_vs_int16 = ssd_int8_vs_int16_altivec;
00142 c->scalarproduct_int16 = scalarproduct_int16_altivec;
00143 c->scalarproduct_and_madd_int16 = scalarproduct_and_madd_int16_altivec;
00144 }