]> git.sesse.net Git - ffmpeg/blobdiff - libswscale/yuv2rgb_template.c
Some AltiVec functions in SwScaler produce different output than their
[ffmpeg] / libswscale / yuv2rgb_template.c
index d86bc4b940bf173280d5ec8ed6a11ef8f2205ab2..216ddd2803d13a68027178af7840a5a877914567 100644 (file)
@@ -1,7 +1,7 @@
 /*
- * yuv2rgb_mmx.c, Software YUV to RGB converter with Intel MMX "technology"
+ * yuv2rgb_mmx.c, software YUV to RGB converter with Intel MMX "technology"
  *
- * Copyright (C) 2000, Silicon Integrated System Corp.
+ * Copyright (C) 2000, Silicon Integrated System Corp
  *
  * Author: Olie Lho <ollie@sis.com.tw>
  *
 #undef EMMS
 #undef SFENCE
 
-#ifdef HAVE_3DNOW
-/* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
+#if HAVE_AMD3DNOW
+/* On K6 femms is faster than emms. On K7 femms is directly mapped to emms. */
 #define EMMS     "femms"
 #else
 #define EMMS     "emms"
 #endif
 
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
 #define MOVNTQ "movntq"
 #define SFENCE "sfence"
 #else
@@ -133,8 +133,8 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr
     h_size= (c->dstW+7)&~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],
+    __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ );
+    //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,21 +143,20 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr
         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];
-        /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
-           pixels in each iteration */
-        __asm__ __volatile__ (
+        c->blueDither= ff_dither8[y&1];
+        c->greenDither= ff_dither4[y&1];
+        c->redDither= ff_dither8[(y+1)&1];
+        /* This MMX assembly code deals with a SINGLE scan line at a time,
+         * it converts 8 pixels in each iteration. */
+        __asm__ volatile (
         /* load data for start of next scan line */
         "movd    (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
         "movd    (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
         "movq (%5, %0, 2), %%mm6;" /* Load 8  Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
         //".balign 16     \n\t"
         "1:             \n\t"
-        /* no speed diference on my p3@500 with prefetch,
-         * if it is faster for anyone with -benchmark then tell me
+        /* No speed difference on my p3@500 with prefetch,
+         * if it is faster for anyone with -benchmark then tell me.
         PREFETCH" 64(%0) \n\t"
         PREFETCH" 64(%1) \n\t"
         PREFETCH" 64(%2) \n\t"
@@ -165,9 +164,9 @@ static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStr
 YUV2RGB
 
 #ifdef DITHER1XBPP
-        "paddusb "MANGLE(b5Dither)", %%mm0;"
-        "paddusb "MANGLE(g6Dither)", %%mm2;"
-        "paddusb "MANGLE(r5Dither)", %%mm1;"
+        "paddusb "BLUE_DITHER"(%4), %%mm0;"
+        "paddusb "GREEN_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 */
@@ -180,7 +179,7 @@ YUV2RGB
         "movq %%mm0, %%mm5;" /* Copy B7-B0 */
         "movq %%mm2, %%mm7;" /* Copy G7-G0 */
 
-        /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+        /* convert RGB24 plane to RGB16 pack for pixel 0-3 */
         "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
         "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
 
@@ -190,7 +189,7 @@ YUV2RGB
         "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
         MOVNTQ "      %%mm0, (%1);" /* store pixel 0-3 */
 
-        /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+        /* convert RGB24 plane to RGB16 pack for pixel 0-3 */
         "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
         "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
 
@@ -211,7 +210,7 @@ YUV2RGB
         );
     }
 
-    __asm__ __volatile__ (EMMS);
+    __asm__ volatile (EMMS);
 
     return srcSliceH;
 }
@@ -228,8 +227,8 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr
     h_size= (c->dstW+7)&~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],
+    __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ );
+    //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,13 +237,12 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr
         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];
-        /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
-           pixels in each iteration */
-        __asm__ __volatile__ (
+        c->blueDither= ff_dither8[y&1];
+        c->greenDither= ff_dither8[y&1];
+        c->redDither= ff_dither8[(y+1)&1];
+        /* This MMX assembly code deals with a SINGLE scan line at a time,
+         * it converts 8 pixels in each iteration. */
+        __asm__ volatile (
         /* load data for start of next scan line */
         "movd    (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
         "movd    (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
@@ -254,9 +252,9 @@ static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStr
 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 */
@@ -271,7 +269,7 @@ YUV2RGB
         "movq %%mm0, %%mm5;" /* Copy B7-B0 */
         "movq %%mm2, %%mm7;" /* Copy G7-G0 */
 
-        /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+        /* convert RGB24 plane to RGB16 pack for pixel 0-3 */
         "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */
         "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
 
@@ -281,7 +279,7 @@ YUV2RGB
         "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
         MOVNTQ "      %%mm0, (%1);"  /* store pixel 0-3 */
 
-        /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
+        /* convert RGB24 plane to RGB16 pack for pixel 0-3 */
         "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */
         "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
 
@@ -301,7 +299,7 @@ YUV2RGB
         );
     }
 
-    __asm__ __volatile__ (EMMS);
+    __asm__ volatile (EMMS);
     return srcSliceH;
 }
 
@@ -317,7 +315,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr
     h_size= (c->dstW+7)&~7;
     if(h_size*3 > FFABS(dstStride[0])) h_size-=8;
 
-    __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+    __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ );
 
     for (y= 0; y<srcSliceH; y++ ) {
         uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0];
@@ -326,9 +324,9 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr
         uint8_t *pv = src[2] + (y>>1)*srcStride[2];
         long index= -h_size/2;
 
-        /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
-           pixels in each iteration */
-        __asm__ __volatile__ (
+        /* This MMX assembly code deals with a SINGLE scan line at a time,
+         * it converts 8 pixels in each iteration. */
+        __asm__ volatile (
         /* load data for start of next scan line */
         "movd    (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
         "movd    (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
@@ -337,7 +335,7 @@ static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStr
         "1:             \n\t"
 YUV2RGB
         /* mm0=B, %%mm2=G, %%mm1=R */
-#ifdef HAVE_MMX2
+#if HAVE_MMX2
         "movq "MANGLE(ff_M24A)", %%mm4     \n\t"
         "movq "MANGLE(ff_M24C)", %%mm7     \n\t"
         "pshufw $0x50, %%mm0, %%mm5     \n\t" /* B3 B2 B3 B2  B1 B0 B1 B0 */
@@ -447,7 +445,7 @@ YUV2RGB
         );
     }
 
-    __asm__ __volatile__ (EMMS);
+    __asm__ volatile (EMMS);
     return srcSliceH;
 }
 
@@ -463,7 +461,7 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStr
     h_size= (c->dstW+7)&~7;
     if(h_size*4 > FFABS(dstStride[0])) h_size-=8;
 
-    __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
+    __asm__ volatile ("pxor %mm4, %mm4;" /* zero mm4 */ );
 
     for (y= 0; y<srcSliceH; y++ ) {
         uint8_t *image = dst[0] + (y+srcSliceY)*dstStride[0];
@@ -472,9 +470,9 @@ static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStr
         uint8_t *pv = src[2] + (y>>1)*srcStride[2];
         long index= -h_size/2;
 
-        /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
-           pixels in each iteration */
-        __asm__ __volatile__ (
+        /* This MMX assembly code deals with a SINGLE scan line at a time,
+         * it converts 8 pixels in each iteration. */
+        __asm__ volatile (
         /* load data for start of next scan line */
         "movd    (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
         "movd    (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
@@ -533,6 +531,6 @@ YUV2RGB
         );
     }
 
-    __asm__ __volatile__ (EMMS);
+    __asm__ volatile (EMMS);
     return srcSliceH;
 }