[FFmpeg-devel] [PATCH]Remove b5Dither and friends from libswscale

Carl Eugen Hoyos cehoyos
Tue Mar 25 13:30:23 CET 2008


Hi!

Attached is a patch that tries to get rid of b5Dither, g5Dither, g6Dither 
and r5Dither from libswscale.

Please comment, Carl Eugen
-------------- next part --------------
Index: libswscale/yuv2rgb.c
===================================================================
--- libswscale/yuv2rgb.c	(Revision 26271)
+++ libswscale/yuv2rgb.c	(Arbeitskopie)
@@ -163,13 +163,6 @@
 DECLARE_ASM_CONST(8, uint64_t, mmx_redmask) = 0xf8f8f8f8f8f8f8f8ULL;
 DECLARE_ASM_CONST(8, uint64_t, mmx_grnmask) = 0xfcfcfcfcfcfcfcfcULL;
 
-// the volatile is required because gcc otherwise optimizes some writes away not knowing that these
-// are read in the asm block
-static volatile uint64_t attribute_used __attribute__((aligned(8))) b5Dither;
-static volatile uint64_t attribute_used __attribute__((aligned(8))) g5Dither;
-static volatile uint64_t attribute_used __attribute__((aligned(8))) g6Dither;
-static volatile uint64_t attribute_used __attribute__((aligned(8))) r5Dither;
-
 #undef HAVE_MMX
 
 //MMX versions
Index: libswscale/swscale_internal.h
===================================================================
--- libswscale/swscale_internal.h	(Revision 26271)
+++ libswscale/swscale_internal.h	(Arbeitskopie)
@@ -111,6 +111,7 @@
 
 #define RED_DITHER            "0*8"
 #define GREEN_DITHER          "1*8"
+#define GREEN6_DITHER         "11*8+4*4*25*2+40"
 #define BLUE_DITHER           "2*8"
 #define Y_COEFF               "3*8"
 #define VR_COEFF              "4*8"
@@ -147,6 +148,7 @@
     uint64_t vRounder     __attribute__((aligned(8)));
     uint64_t u_temp       __attribute__((aligned(8)));
     uint64_t v_temp       __attribute__((aligned(8)));
+    uint64_t green6Dither __attribute__((aligned(8)));
 
 #ifdef HAVE_ALTIVEC
 
Index: libswscale/yuv2rgb_template.c
===================================================================
--- libswscale/yuv2rgb_template.c	(Revision 26271)
+++ libswscale/yuv2rgb_template.c	(Arbeitskopie)
@@ -134,7 +134,7 @@
     if(h_size*2 > FFABS(dstStride[0])) h_size-=8;
 
     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
-    //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
+    //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&c->blueDither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
     //srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
     for (y= 0; y<srcSliceH; y++ ) {
         uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0];
@@ -143,10 +143,10 @@
         uint8_t *pv = src[2] + (y>>1)*srcStride[2];
         long index= -h_size/2;
 
-        b5Dither= ff_dither8[y&1];
-        g6Dither= ff_dither4[y&1];
-        g5Dither= ff_dither8[y&1];
-        r5Dither= ff_dither8[(y+1)&1];
+        c->blueDither   = ff_dither8[y&1];
+        c->green6Dither = ff_dither4[y&1];
+        c->greenDither  = ff_dither8[y&1];
+        c->redDither    = ff_dither8[(y+1)&1];
         /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
            pixels in each iteration */
         __asm__ __volatile__ (
@@ -165,9 +165,9 @@
 YUV2RGB
 
 #ifdef DITHER1XBPP
-        "paddusb "MANGLE(b5Dither)", %%mm0;"
-        "paddusb "MANGLE(g6Dither)", %%mm2;"
-        "paddusb "MANGLE(r5Dither)", %%mm1;"
+        "paddusb "BLUE_DITHER"(%4),   %%mm0;"
+        "paddusb "GREEN6_DITHER"(%4), %%mm2;"
+        "paddusb "RED_DITHER"(%4),    %%mm1;"
 #endif
         /* mask unneeded bits off */
         "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */
@@ -229,7 +229,7 @@
     if(h_size*2 > FFABS(dstStride[0])) h_size-=8;
 
     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
-    //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&b5Dither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
+    //printf("%X %X %X %X %X %X %X %X %X %X\n", (int)&c->redDither, (int)&c->blueDither, (int)src[0], (int)src[1], (int)src[2], (int)dst[0],
     //srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
     for (y= 0; y<srcSliceH; y++ ) {
         uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0];
@@ -238,10 +238,10 @@
         uint8_t *pv = src[2] + (y>>1)*srcStride[2];
         long index= -h_size/2;
 
-        b5Dither= ff_dither8[y&1];
-        g6Dither= ff_dither4[y&1];
-        g5Dither= ff_dither8[y&1];
-        r5Dither= ff_dither8[(y+1)&1];
+        c->blueDither   = ff_dither8[y&1];
+        c->green6Dither = ff_dither4[y&1];
+        c->greenDither  = ff_dither8[y&1];
+        c->redDither    = ff_dither8[(y+1)&1];
         /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
            pixels in each iteration */
         __asm__ __volatile__ (
@@ -254,9 +254,9 @@
 YUV2RGB
 
 #ifdef DITHER1XBPP
-        "paddusb "MANGLE(b5Dither)", %%mm0  \n\t"
-        "paddusb "MANGLE(g5Dither)", %%mm2  \n\t"
-        "paddusb "MANGLE(r5Dither)", %%mm1  \n\t"
+        "paddusb "BLUE_DITHER"(%4),  %%mm0  \n\t"
+        "paddusb "GREEN_DITHER"(%4), %%mm2  \n\t"
+        "paddusb "RED_DITHER"(%4),   %%mm1  \n\t"
 #endif
 
         /* mask unneeded bits off */
Index: libswscale/swscale_template.c
===================================================================
--- libswscale/swscale_template.c	(Revision 26271)
+++ libswscale/swscale_template.c	(Arbeitskopie)
@@ -1067,9 +1067,9 @@
             YSCALEYUV2RGBX
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
-            "paddusb "MANGLE(g5Dither)", %%mm4\n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+            "paddusb "BLUE_DITHER"(%0),  %%mm2  \n\t"
+            "paddusb "GREEN_DITHER"(%0), %%mm4  \n\t"
+            "paddusb "RED_DITHER"(%0),   %%mm5  \n\t"
 #endif
 
             WRITEBGR15(%4, %5, %%REGa)
@@ -1080,9 +1080,9 @@
             YSCALEYUV2RGBX
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2\n\t"
-            "paddusb "MANGLE(g6Dither)", %%mm4\n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5\n\t"
+            "paddusb "BLUE_DITHER"(%0),   %%mm2 \n\t"
+            "paddusb "GREEN6_DITHER"(%0), %%mm4 \n\t"
+            "paddusb "RED_DITHER"(%0),    %%mm5 \n\t"
 #endif
 
             WRITEBGR16(%4, %5, %%REGa)
@@ -1127,9 +1127,9 @@
             YSCALEYUV2RGBX
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2  \n\t"
-            "paddusb "MANGLE(g5Dither)", %%mm4  \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5  \n\t"
+            "paddusb "BLUE_DITHER"(%0),  %%mm2  \n\t"
+            "paddusb "GREEN_DITHER"(%0), %%mm4  \n\t"
+            "paddusb "RED_DITHER"(%0),   %%mm5  \n\t"
 #endif
 
             WRITEBGR15(%4, %5, %%REGa)
@@ -1140,9 +1140,9 @@
             YSCALEYUV2RGBX
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2  \n\t"
-            "paddusb "MANGLE(g6Dither)", %%mm4  \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5  \n\t"
+            "paddusb "BLUE_DITHER"(%0),   %%mm2 \n\t"
+            "paddusb "GREEN6_DITHER"(%0), %%mm4 \n\t"
+            "paddusb "RED_DITHER"(%0),    %%mm5 \n\t"
 #endif
 
             WRITEBGR16(%4, %5, %%REGa)
@@ -1442,9 +1442,9 @@
                 YSCALEYUV2RGB(%%REGBP, %5)
                 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-                "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-                "paddusb "MANGLE(g5Dither)", %%mm4      \n\t"
-                "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+                "paddusb "BLUE_DITHER"(%5),  %%mm2      \n\t"
+                "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
+                "paddusb "RED_DITHER"(%5),   %%mm5      \n\t"
 #endif
 
                 WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
@@ -1463,9 +1463,9 @@
                 YSCALEYUV2RGB(%%REGBP, %5)
                 /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-                "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-                "paddusb "MANGLE(g6Dither)", %%mm4      \n\t"
-                "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+                "paddusb "BLUE_DITHER"(%5),   %%mm2     \n\t"
+                "paddusb "GREEN6_DITHER"(%5), %%mm4     \n\t"
+                "paddusb "RED_DITHER"(%5),    %%mm5     \n\t"
 #endif
 
                 WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
@@ -1553,9 +1553,9 @@
             YSCALEYUV2RGB1(%%REGBP, %5)
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-            "paddusb "MANGLE(g5Dither)", %%mm4      \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+            "paddusb "BLUE_DITHER"(%5),  %%mm2      \n\t"
+            "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
+            "paddusb "RED_DITHER"(%5),   %%mm5      \n\t"
 #endif
             WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
             "pop %%"REG_BP"                         \n\t"
@@ -1573,9 +1573,9 @@
             YSCALEYUV2RGB1(%%REGBP, %5)
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-            "paddusb "MANGLE(g6Dither)", %%mm4      \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+            "paddusb "BLUE_DITHER"(%5),   %%mm2     \n\t"
+            "paddusb "GREEN6_DITHER"(%5), %%mm4     \n\t"
+            "paddusb "RED_DITHER"(%5),    %%mm5     \n\t"
 #endif
 
             WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
@@ -1642,9 +1642,9 @@
             YSCALEYUV2RGB1b(%%REGBP, %5)
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-            "paddusb "MANGLE(g5Dither)", %%mm4      \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+            "paddusb "BLUE_DITHER"(%5),  %%mm2      \n\t"
+            "paddusb "GREEN_DITHER"(%5), %%mm4      \n\t"
+            "paddusb "RED_DITHER"(%5),   %%mm5      \n\t"
 #endif
             WRITEBGR15(%%REGb, 8280(%5), %%REGBP)
             "pop %%"REG_BP"                         \n\t"
@@ -1662,9 +1662,9 @@
             YSCALEYUV2RGB1b(%%REGBP, %5)
             /* mm2=B, %%mm4=G, %%mm5=R, %%mm7=0 */
 #ifdef DITHER1XBPP
-            "paddusb "MANGLE(b5Dither)", %%mm2      \n\t"
-            "paddusb "MANGLE(g6Dither)", %%mm4      \n\t"
-            "paddusb "MANGLE(r5Dither)", %%mm5      \n\t"
+            "paddusb "BLUE_DITHER"(%5),   %%mm2     \n\t"
+            "paddusb "GREEN6_DITHER"(%5), %%mm4     \n\t"
+            "paddusb "RED_DITHER"(%5),    %%mm5     \n\t"
 #endif
 
             WRITEBGR16(%%REGb, 8280(%5), %%REGBP)
@@ -3125,10 +3125,10 @@
         }
 
 #ifdef HAVE_MMX
-        b5Dither= ff_dither8[dstY&1];
-        g6Dither= ff_dither4[dstY&1];
-        g5Dither= ff_dither8[dstY&1];
-        r5Dither= ff_dither8[(dstY+1)&1];
+        c->blueDither   = ff_dither8[dstY&1];
+        c->green6Dither = ff_dither4[dstY&1];
+        c->greenDither  = ff_dither8[dstY&1];
+        c->redDither    = ff_dither8[(dstY+1)&1];
 #endif
         if (dstY < dstH-2)
         {



More information about the ffmpeg-devel mailing list