diff options
author | rfelker <rfelker@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-04-29 03:13:43 +0000 |
---|---|---|
committer | rfelker <rfelker@b3059339-0415-0410-9bf9-f77b7e298cf2> | 2003-04-29 03:13:43 +0000 |
commit | 44d654d3576e1be0889186ffb1bcb0d05bfccb75 (patch) | |
tree | 4d04b09de18a90966a9c4c7a39691946b88c5c8c /libmpcodecs | |
parent | eb0a6969bf5d2c7326a22b830f4d039759a06e12 (diff) | |
download | mpv-44d654d3576e1be0889186ffb1bcb0d05bfccb75.tar.bz2 mpv-44d654d3576e1be0889186ffb1bcb0d05bfccb75.tar.xz |
new mmx/mmx2/3dnow code for improved performance
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10021 b3059339-0415-0410-9bf9-f77b7e298cf2
Diffstat (limited to 'libmpcodecs')
-rw-r--r-- | libmpcodecs/vf_tfields.c | 172 |
1 files changed, 151 insertions, 21 deletions
diff --git a/libmpcodecs/vf_tfields.c b/libmpcodecs/vf_tfields.c index d51117dc31..a8b1a10353 100644 --- a/libmpcodecs/vf_tfields.c +++ b/libmpcodecs/vf_tfields.c @@ -4,6 +4,7 @@ #include "../config.h" #include "../mp_msg.h" +#include "../cpudetect.h" #include "img_format.h" #include "mp_image.h" @@ -56,30 +57,149 @@ static void deint(unsigned char *dest, int ds, unsigned char *src, int ss, int w } } -static void qpelup(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss) +#ifdef HAVE_3DNOW +static void qpel_3DNOW(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int up) { - int i, j; - memcpy(d, s, w); + int i, j, ssd=ss; + int crap1, crap2; + if (up) { + ssd = -ss; + memcpy(d, s, w); + d += ds; + s += ss; + } for (i=h-1; i; i--) { + asm( + "pxor %%mm7, %%mm7 \n\t" + "1: \n\t" + "movq (%%esi), %%mm0 \n\t" + "movq (%%esi,%%eax), %%mm1 \n\t" + "pavgusb %%mm0, %%mm1 \n\t" + "addl $8, %%esi \n\t" + "pavgusb %%mm0, %%mm1 \n\t" + "movq %%mm1, (%%edi) \n\t" + "addl $8, %%edi \n\t" + "decl %%ecx \n\t" + "jnz 1b \n\t" + : "=S"(crap1), "=D"(crap2) + : "c"(w>>3), "S"(s), "D"(d), "a"(ssd) + ); + for (j=(w&7); j<w; j++) + d[j] = (s[j+ssd] + 3*s[j])>>2; d += ds; s += ss; - for (j=0; j<w; j++) - d[j] = (s[j-ss] + 3*s[j])>>2; } + if (!up) memcpy(d, s, w); + asm volatile("emms \n\t" : : : "memory"); } +#endif -static void qpeldown(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss) +#ifdef HAVE_MMX2 +static void qpel_MMX2(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int up) { - int i, j; + int i, j, ssd=ss; + int crap1, crap2; + if (up) { + ssd = -ss; + memcpy(d, s, w); + d += ds; + s += ss; + } + for (i=h-1; i; i--) { + asm( + "pxor %%mm7, %%mm7 \n\t" + "1: \n\t" + "movq (%%esi), %%mm0 \n\t" + "movq (%%esi,%%eax), %%mm1 \n\t" + "pavgb %%mm0, %%mm1 \n\t" + "addl $8, %%esi \n\t" + "pavgb %%mm0, %%mm1 \n\t" + "movq %%mm1, (%%edi) \n\t" + "addl $8, %%edi \n\t" + "decl %%ecx \n\t" + "jnz 1b \n\t" + : "=S"(crap1), "=D"(crap2) + : "c"(w>>3), "S"(s), "D"(d), "a"(ssd) + ); + for (j=(w&7); j<w; j++) + d[j] = (s[j+ssd] + 3*s[j])>>2; + d += ds; + s += ss; + } + if (!up) memcpy(d, s, w); + asm volatile("emms \n\t" : : : "memory"); +} +#endif + +#ifdef HAVE_MMX +static void qpel_MMX(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int up) +{ + int i, j, ssd=ss; + int crap1, crap2; + if (up) { + ssd = -ss; + memcpy(d, s, w); + d += ds; + s += ss; + } + for (i=h-1; i; i--) { + asm( + "pxor %%mm7, %%mm7 \n\t" + "1: \n\t" + "movq (%%esi), %%mm0 \n\t" + "movq (%%esi), %%mm1 \n\t" + "movq (%%esi,%%eax), %%mm2 \n\t" + "movq (%%esi,%%eax), %%mm3 \n\t" + "addl $8, %%esi \n\t" + "punpcklbw %%mm7, %%mm0 \n\t" + "punpckhbw %%mm7, %%mm1 \n\t" + "punpcklbw %%mm7, %%mm2 \n\t" + "punpckhbw %%mm7, %%mm3 \n\t" + "paddw %%mm0, %%mm2 \n\t" + "paddw %%mm1, %%mm3 \n\t" + "paddw %%mm0, %%mm2 \n\t" + "paddw %%mm1, %%mm3 \n\t" + "paddw %%mm0, %%mm2 \n\t" + "paddw %%mm1, %%mm3 \n\t" + "psrlw $2, %%mm2 \n\t" + "psrlw $2, %%mm3 \n\t" + "packsswb %%mm3, %%mm2 \n\t" + "movq %%mm2, (%%edi) \n\t" + "addl $8, %%edi \n\t" + "decl %%ecx \n\t" + "jnz 1b \n\t" + : "=S"(crap1), "=D"(crap2) + : "c"(w>>3), "S"(s), "D"(d), "a"(ssd) + ); + for (j=(w&7); j<w; j++) + d[j] = (s[j+ssd] + 3*s[j])>>2; + d += ds; + s += ss; + } + if (!up) memcpy(d, s, w); + asm volatile("emms \n\t" : : : "memory"); +} +#endif + +static void qpel_C(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int up) +{ + int i, j, ssd=ss; + if (up) { + ssd = -ss; + memcpy(d, s, w); + d += ds; + s += ss; + } for (i=h-1; i; i--) { for (j=0; j<w; j++) - d[j] = (3*s[j] + s[j+ss])>>2; + d[j] = (s[j+ssd] + 3*s[j])>>2; d += ds; s += ss; } - memcpy(d, s, w); + if (!up) memcpy(d, s, w); } +static void (*qpel)(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss, int up); static int put_image(struct vf_instance_s* vf, mp_image_t *mpi) { @@ -155,27 +275,27 @@ static int put_image(struct vf_instance_s* vf, mp_image_t *mpi) dmpi = vf_get_image(vf->next, mpi->imgfmt, MP_IMGTYPE_TEMP, MP_IMGFLAG_ACCEPT_STRIDE, mpi->width, mpi->height/2); - qpeldown(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, - dmpi->stride[0], mpi->stride[0]*2); + qpel(dmpi->planes[0], mpi->planes[0], mpi->w, mpi->h/2, + dmpi->stride[0], mpi->stride[0]*2, 0); if (mpi->flags & MP_IMGFLAG_PLANAR) { - qpeldown(dmpi->planes[1], mpi->planes[1], + qpel(dmpi->planes[1], mpi->planes[1], mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[1], mpi->stride[1]*2); - qpeldown(dmpi->planes[2], mpi->planes[2], + dmpi->stride[1], mpi->stride[1]*2, 0); + qpel(dmpi->planes[2], mpi->planes[2], mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[2], mpi->stride[2]*2); + dmpi->stride[2], mpi->stride[2]*2, 0); } ret = vf_next_put_image(vf, dmpi); - qpelup(dmpi->planes[0], mpi->planes[0] + mpi->stride[0], - mpi->w, mpi->h/2, dmpi->stride[0], mpi->stride[0]*2); + qpel(dmpi->planes[0], mpi->planes[0] + mpi->stride[0], + mpi->w, mpi->h/2, dmpi->stride[0], mpi->stride[0]*2, 1); if (mpi->flags & MP_IMGFLAG_PLANAR) { - qpelup(dmpi->planes[1], mpi->planes[1] + mpi->stride[1], + qpel(dmpi->planes[1], mpi->planes[1] + mpi->stride[1], mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[1], mpi->stride[1]*2); - qpelup(dmpi->planes[2], mpi->planes[2] + mpi->stride[2], + dmpi->stride[1], mpi->stride[1]*2, 1); + qpel(dmpi->planes[2], mpi->planes[2] + mpi->stride[2], mpi->chroma_width, mpi->chroma_height/2, - dmpi->stride[2], mpi->stride[2]*2); + dmpi->stride[2], mpi->stride[2]*2, 1); } return vf_next_put_image(vf, dmpi) || ret; } @@ -224,6 +344,16 @@ static int open(vf_instance_t *vf, char* args) vf->priv = p = calloc(1, sizeof(struct vf_priv_s)); vf->priv->mode = 0; if (args) sscanf(args, "%d", &vf->priv->mode); + qpel = qpel_C; +#ifdef HAVE_MMX + if(gCpuCaps.hasMMX) qpel = qpel_MMX; +#endif +#ifdef HAVE_MMX2 + if(gCpuCaps.hasMMX2) qpel = qpel_MMX2; +#endif +#ifdef HAVE_3DNOW + if(gCpuCaps.has3DNow) qpel = qpel_3DNOW; +#endif return 1; } |