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