[MPlayer-dev-eng] [PATCH] altivec fixes, part 1: alignment

Alan Curry pacman at TheWorld.com
Mon Feb 6 07:27:02 CET 2006


I have found some bugs in mplayer's altivec code, mostly affecting
postproc/yuv2rgb_altivec.c, in the function altivec_yuv2packedX(). This
function is used only when a more specific optimized converter is not
available, so the symptoms may not be noticed under normal circumstances. To
see the bugginess, try playing a YVU9 video with an altivec-enabled mplayer,
or play a YV12 video and resize it with -vf scale. Either way, you need to be
using a non-YUV-capable output device like -vo fbdev.

The first patch, included in this message, fixes a couple of places where
altivec operations were used on memory that had not been aligned on a 16-byte
boundary.

Index: postproc/swscale.c
===================================================================
RCS file: /cvsroot/mplayer/main/postproc/swscale.c,v
retrieving revision 1.161
diff -u -r1.161 swscale.c
--- postproc/swscale.c	13 Jan 2006 00:23:32 -0000	1.161
+++ postproc/swscale.c	6 Feb 2006 01:49:13 -0000
@@ -2132,10 +2132,11 @@
 	c->lumPixBuf= (int16_t**)memalign(4, c->vLumBufSize*2*sizeof(int16_t*));
 	c->chrPixBuf= (int16_t**)memalign(4, c->vChrBufSize*2*sizeof(int16_t*));
 	//Note we need at least one pixel more at the end because of the mmx code (just in case someone wanna replace the 4000/8000)
+	/* align at 16 bytes for AltiVec */
 	for(i=0; i<c->vLumBufSize; i++)
-		c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= (uint16_t*)memalign(8, 4000);
+		c->lumPixBuf[i]= c->lumPixBuf[i+c->vLumBufSize]= (uint16_t*)memalign(16, 4000);
 	for(i=0; i<c->vChrBufSize; i++)
-		c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= (uint16_t*)memalign(8, 8000);
+		c->chrPixBuf[i]= c->chrPixBuf[i+c->vChrBufSize]= (uint16_t*)memalign(16, 8000);
 
 	//try to avoid drawing green stuff between the right end and the stride end
 	for(i=0; i<c->vLumBufSize; i++) memset(c->lumPixBuf[i], 0, 4000);
Index: postproc/yuv2rgb_altivec.c
===================================================================
RCS file: /cvsroot/mplayer/main/postproc/yuv2rgb_altivec.c,v
retrieving revision 1.5
diff -u -r1.5 yuv2rgb_altivec.c
--- postproc/yuv2rgb_altivec.c	14 Nov 2005 00:30:37 -0000	1.5
+++ postproc/yuv2rgb_altivec.c	6 Feb 2006 01:49:30 -0000
@@ -68,6 +68,9 @@
 #include <inttypes.h>
 #include <assert.h>
 #include "config.h"
+#ifdef HAVE_MALLOC_H
+#include <malloc.h>
+#endif
 #include "rgb2rgb.h"
 #include "swscale.h"
 #include "swscale_internal.h"
@@ -788,8 +791,8 @@
 
   vector signed short *YCoeffs, *CCoeffs;
 
-  vYCoeffsBank = malloc (sizeof (vector signed short)*lumFilterSize*dstW);
-  vCCoeffsBank = malloc (sizeof (vector signed short)*chrFilterSize*dstW);
+  vYCoeffsBank = memalign (16, sizeof (vector signed short)*lumFilterSize*c->dstH);
+  vCCoeffsBank = memalign (16, sizeof (vector signed short)*chrFilterSize*c->dstH);
 
   for (i=0;i<lumFilterSize*dstW;i++) {
     tmp = c->vLumFilter[i];




More information about the MPlayer-dev-eng mailing list