[Mplayer-cvslog] CVS: main/libmpcodecs vf_tfields.c,1.3,1.4
Richard Felker CVS
rfelker at mplayerhq.hu
Tue Apr 29 05:14:11 CEST 2003
Update of /cvsroot/mplayer/main/libmpcodecs
In directory mail:/var/tmp.root/cvs-serv16038/libmpcodecs
Modified Files:
vf_tfields.c
Log Message:
new mmx/mmx2/3dnow code for improved performance
Index: vf_tfields.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpcodecs/vf_tfields.c,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- vf_tfields.c 28 Apr 2003 02:53:50 -0000 1.3
+++ vf_tfields.c 29 Apr 2003 03:13:43 -0000 1.4
@@ -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 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 @@
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 @@
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;
}
More information about the MPlayer-cvslog
mailing list