[MPlayer-dev-eng] [PATCH/RFC] libswscale using mmx even when disabled by configure

Diego Biurrun diego at biurrun.de
Thu Aug 3 23:50:08 CEST 2006


On Wed, Jul 19, 2006 at 01:02:13PM +0200, Diego Biurrun wrote:
> On Wed, Jul 19, 2006 at 01:13:43AM -0400, Rich Felker wrote:
> > while testing just now, i discovered that 3 files in libswscale try to
> > assemble mmx code even when mmx is explicitly disabled. they're
> > wrongly using ARCH_X86[_64] defines instead of HAVE_{MMX|MMX2|3DNOW}
> > to decide what to compile. i was having trouble sorting through all
> > the ifdef mess so i just undefined ARCH_X86 when mmx, mmx2, and 3dnow
> > are all disabled. this is not really a clean fix though.
> 
> Hey, there are much worse files ;-p
> 
> Why not check for HAVE_MMX (or whatever it's called) instead?  It's a
> few more checks, but it's the only way to be correct.

Here's a first stab at it, please report if it works as expected.

Diego
-------------- next part --------------
Index: libswscale/yuv2rgb.c
===================================================================
--- libswscale/yuv2rgb.c	(revision 19302)
+++ libswscale/yuv2rgb.c	(working copy)
@@ -154,7 +154,7 @@
 };
 #endif
 
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#ifdef HAVE_MMX
 
 /* hope these constant values are cache line aligned */
 uint64_t attribute_used __attribute__((aligned(8))) mmx_00ffw = 0x00ff00ff00ff00ffULL;
@@ -578,7 +578,7 @@
 
 SwsFunc yuv2rgb_get_func_ptr (SwsContext *c)
 {
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#if defined(HAVE_MMX2) || defined(HAVE_MMX)
     if(c->flags & SWS_CPU_CAPS_MMX2){
 	switch(c->dstFormat){
 	case IMGFMT_BGR32: return yuv420_rgb32_MMX2;
Index: libswscale/swscale.c
===================================================================
--- libswscale/swscale.c	(revision 19302)
+++ libswscale/swscale.c	(working copy)
@@ -1240,7 +1240,7 @@
         return 0;
 }
 
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#ifdef HAVE_MMX2
 static void initMMX2HScaler(int dstW, int xInc, uint8_t *funnyCode, int16_t *filter, int32_t *filterPos, int numSplits)
 {
 	uint8_t *fragmentA;
@@ -1411,7 +1411,7 @@
 	}
 	filterPos[i/2]= xpos>>16; // needed to jump to the next part
 }
-#endif // ARCH_X86 || ARCH_X86_64
+#endif /* HAVE_MMX2 */
 
 static void globalInit(void){
     // generating tables:
@@ -2114,11 +2114,11 @@
 				 (flags&SWS_BICUBLIN) ? (flags|SWS_BILINEAR) : flags,
 				 srcFilter->chrH, dstFilter->chrH, c->param);
 
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#define MAX_FUNNY_CODE_SIZE 10000
+#if defined(HAVE_MMX2)
 // can't downscale !!!
 		if(c->canMMX2BeUsed && (flags & SWS_FAST_BILINEAR))
 		{
-#define MAX_FUNNY_CODE_SIZE 10000
 #ifdef MAP_ANONYMOUS
 			c->funnyYCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
 			c->funnyUVCode = (uint8_t*)mmap(NULL, MAX_FUNNY_CODE_SIZE, PROT_EXEC | PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, 0, 0);
@@ -2135,7 +2135,7 @@
 			initMMX2HScaler(      dstW, c->lumXInc, c->funnyYCode , c->lumMmx2Filter, c->lumMmx2FilterPos, 8);
 			initMMX2HScaler(c->chrDstW, c->chrXInc, c->funnyUVCode, c->chrMmx2Filter, c->chrMmx2FilterPos, 4);
 		}
-#endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
+#endif /* defined(HAVE_MMX2) */
 	} // Init Horizontal stuff
 
 
Index: libswscale/rgb2rgb.c
===================================================================
--- libswscale/rgb2rgb.c	(revision 19302)
+++ libswscale/rgb2rgb.c	(working copy)
@@ -72,9 +72,11 @@
 			long srcStride1, long srcStride2,
 			long srcStride3, long dstStride);
 
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#if defined(HAVE_MMX)
 static const uint64_t mmx_null  __attribute__((aligned(8))) = 0x0000000000000000ULL;
 static const uint64_t mmx_one   __attribute__((aligned(8))) = 0xFFFFFFFFFFFFFFFFULL;
+#endif
+#if defined(ARCH_X86) || defined(ARCH_X86_64)
 static const uint64_t mask32b  attribute_used __attribute__((aligned(8))) = 0x000000FF000000FFULL;
 static const uint64_t mask32g  attribute_used __attribute__((aligned(8))) = 0x0000FF000000FF00ULL;
 static const uint64_t mask32r  attribute_used __attribute__((aligned(8))) = 0x00FF000000FF0000ULL;
@@ -195,7 +197,7 @@
 */
 
 void sws_rgb2rgb_init(int flags){
-#if defined(ARCH_X86) || defined(ARCH_X86_64)
+#if defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX)
 	if(flags & SWS_CPU_CAPS_MMX2){
 		rgb15to16= rgb15to16_MMX2;
 		rgb15to24= rgb15to24_MMX2;
@@ -287,7 +289,7 @@
 		vu9_to_vu12= vu9_to_vu12_MMX;
 		yvu9_to_yuy2= yvu9_to_yuy2_MMX;
 	}else
-#endif /* defined(ARCH_X86) || defined(ARCH_X86_64) */
+#endif /* defined(HAVE_MMX2) || defined(HAVE_3DNOW) || defined(HAVE_MMX) */
 	{
 		rgb15to16= rgb15to16_C;
 		rgb15to24= rgb15to24_C;


More information about the MPlayer-dev-eng mailing list