new mmx/mmx2/3dnow code for improved performance

git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@10021 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
rfelker 2003-04-29 03:13:43 +00:00
parent eb0a6969bf
commit 44d654d357
1 changed files with 160 additions and 30 deletions

View File

@ -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);
for (i=h-1; i; i--) {
d += ds;
s += ss;
for (j=0; j<w; j++)
d[j] = (s[j-ss] + 3*s[j])>>2;
}
}
static void qpeldown(unsigned char *d, unsigned char *s, int w, int h, int ds, int ss)
{
int i, j;
for (i=h-1; i; i--) {
for (j=0; j<w; j++)
d[j] = (3*s[j] + s[j+ss])>>2;
int i, j, ssd=ss;
int crap1, crap2;
if (up) {
ssd = -ss;
memcpy(d, s, w);
d += ds;
s += ss;
}
memcpy(d, s, w);
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;
}
if (!up) memcpy(d, s, w);
asm volatile("emms \n\t" : : : "memory");
}
#endif
#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, 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] = (s[j+ssd] + 3*s[j])>>2;
d += ds;
s += ss;
}
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;
}