Main Page | Modules | Class Hierarchy | Class List | Directories | File List | Class Members | File Members | Related Pages

yuv2rgb_template.c

00001 
00002 /*
00003  * yuv2rgb_mmx.c, Software YUV to RGB coverter with Intel MMX "technology"
00004  *
00005  * Copyright (C) 2000, Silicon Integrated System Corp.
00006  * All Rights Reserved.
00007  *
00008  * Author: Olie Lho <[email protected]>
00009  *
00010  * This file is part of mpeg2dec, a free MPEG-2 video decoder
00011  *
00012  * mpeg2dec is free software; you can redistribute it and/or modify
00013  * it under the terms of the GNU General Public License as published by
00014  * the Free Software Foundation; either version 2, or (at your option)
00015  * any later version.
00016  *
00017  * mpeg2dec is distributed in the hope that it will be useful,
00018  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00019  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00020  * GNU General Public License for more details.
00021  *
00022  * You should have received a copy of the GNU General Public License
00023  * along with GNU Make; see the file COPYING. If not, write to
00024  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
00025  *
00026  * 15,24 bpp and dithering from Michael Niedermayer ([email protected])
00027  * MMX/MMX2 Template stuff from Michael Niedermayer (needed for fast movntq support)
00028  * context / deglobalize stuff by Michael Niedermayer
00029  */
00030 
00031 #undef MOVNTQ
00032 #undef EMMS
00033 #undef SFENCE
00034 
00035 #ifdef HAVE_3DNOW
00036 /* On K6 femms is faster of emms. On K7 femms is directly mapped on emms. */
00037 #define EMMS     "femms"
00038 #else
00039 #define EMMS     "emms"
00040 #endif
00041 
00042 #ifdef HAVE_MMX2
00043 #define MOVNTQ "movntq"
00044 #define SFENCE "sfence"
00045 #else
00046 #define MOVNTQ "movq"
00047 #define SFENCE "/nop"
00048 #endif
00049 
00050 #define YUV2RGB \
00051                      /* Do the multiply part of the conversion for even and odd pixels,
00052                         register usage:
00053                         mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
00054                         mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
00055                         mm6 -> Y even, mm7 -> Y odd */\
00056                      /* convert the chroma part */\
00057                      "punpcklbw %%mm4, %%mm0;" /* scatter 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \
00058                      "punpcklbw %%mm4, %%mm1;" /* scatter 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \
00059 \
00060                      "psllw $3, %%mm0;" /* Promote precision */ \
00061                      "psllw $3, %%mm1;" /* Promote precision */ \
00062 \
00063                      "psubsw "U_OFFSET"(%4), %%mm0;" /* Cb -= 128 */ \
00064                      "psubsw "V_OFFSET"(%4), %%mm1;" /* Cr -= 128 */ \
00065 \
00066                      "movq %%mm0, %%mm2;" /* Copy 4 Cb 00 u3 00 u2 00 u1 00 u0 */ \
00067                      "movq %%mm1, %%mm3;" /* Copy 4 Cr 00 v3 00 v2 00 v1 00 v0 */ \
00068 \
00069                      "pmulhw "UG_COEFF"(%4), %%mm2;" /* Mul Cb with green coeff -> Cb green */ \
00070                      "pmulhw "VG_COEFF"(%4), %%mm3;" /* Mul Cr with green coeff -> Cr green */ \
00071 \
00072                      "pmulhw "UB_COEFF"(%4), %%mm0;" /* Mul Cb -> Cblue 00 b3 00 b2 00 b1 00 b0 */\
00073                      "pmulhw "VR_COEFF"(%4), %%mm1;" /* Mul Cr -> Cred 00 r3 00 r2 00 r1 00 r0 */\
00074 \
00075                      "paddsw %%mm3, %%mm2;" /* Cb green + Cr green -> Cgreen */\
00076 \
00077                      /* convert the luma part */\
00078                      "movq %%mm6, %%mm7;" /* Copy 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */\
00079                      "pand "MANGLE(mmx_00ffw)", %%mm6;" /* get Y even 00 Y6 00 Y4 00 Y2 00 Y0 */\
00080 \
00081                      "psrlw $8, %%mm7;" /* get Y odd 00 Y7 00 Y5 00 Y3 00 Y1 */\
00082 \
00083                      "psllw $3, %%mm6;" /* Promote precision */\
00084                      "psllw $3, %%mm7;" /* Promote precision */\
00085 \
00086                      "psubw "Y_OFFSET"(%4), %%mm6;" /* Y -= 16 */\
00087                      "psubw "Y_OFFSET"(%4), %%mm7;" /* Y -= 16 */\
00088 \
00089                      "pmulhw "Y_COEFF"(%4), %%mm6;" /* Mul 4 Y even 00 y6 00 y4 00 y2 00 y0 */\
00090                      "pmulhw "Y_COEFF"(%4), %%mm7;" /* Mul 4 Y odd 00 y7 00 y5 00 y3 00 y1 */\
00091 \
00092                      /* Do the addition part of the conversion for even and odd pixels,
00093                         register usage:
00094                         mm0 -> Cblue, mm1 -> Cred, mm2 -> Cgreen even pixels,
00095                         mm3 -> Cblue, mm4 -> Cred, mm5 -> Cgreen odd pixels,
00096                         mm6 -> Y even, mm7 -> Y odd */\
00097                      "movq %%mm0, %%mm3;" /* Copy Cblue */\
00098                      "movq %%mm1, %%mm4;" /* Copy Cred */\
00099                      "movq %%mm2, %%mm5;" /* Copy Cgreen */\
00100 \
00101                      "paddsw %%mm6, %%mm0;" /* Y even + Cblue 00 B6 00 B4 00 B2 00 B0 */\
00102                      "paddsw %%mm7, %%mm3;" /* Y odd + Cblue 00 B7 00 B5 00 B3 00 B1 */\
00103 \
00104                      "paddsw %%mm6, %%mm1;" /* Y even + Cred 00 R6 00 R4 00 R2 00 R0 */\
00105                      "paddsw %%mm7, %%mm4;" /* Y odd + Cred 00 R7 00 R5 00 R3 00 R1 */\
00106 \
00107                      "paddsw %%mm6, %%mm2;" /* Y even + Cgreen 00 G6 00 G4 00 G2 00 G0 */\
00108                      "paddsw %%mm7, %%mm5;" /* Y odd + Cgreen 00 G7 00 G5 00 G3 00 G1 */\
00109 \
00110                      /* Limit RGB even to 0..255 */\
00111                      "packuswb %%mm0, %%mm0;" /* B6 B4 B2 B0  B6 B4 B2 B0 */\
00112                      "packuswb %%mm1, %%mm1;" /* R6 R4 R2 R0  R6 R4 R2 R0 */\
00113                      "packuswb %%mm2, %%mm2;" /* G6 G4 G2 G0  G6 G4 G2 G0 */\
00114 \
00115                      /* Limit RGB odd to 0..255 */\
00116                      "packuswb %%mm3, %%mm3;" /* B7 B5 B3 B1  B7 B5 B3 B1 */\
00117                      "packuswb %%mm4, %%mm4;" /* R7 R5 R3 R1  R7 R5 R3 R1 */\
00118                      "packuswb %%mm5, %%mm5;" /* G7 G5 G3 G1  G7 G5 G3 G1 */\
00119 \
00120                      /* Interleave RGB even and odd */\
00121                      "punpcklbw %%mm3, %%mm0;" /* B7 B6 B5 B4 B3 B2 B1 B0 */\
00122                      "punpcklbw %%mm4, %%mm1;" /* R7 R6 R5 R4 R3 R2 R1 R0 */\
00123                      "punpcklbw %%mm5, %%mm2;" /* G7 G6 G5 G4 G3 G2 G1 G0 */\
00124 
00125 
00126 static inline int RENAME(yuv420_rgb16)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00127              int srcSliceH, uint8_t* dst[], int dstStride[]){
00128     int y, h_size;
00129 
00130     if(c->srcFormat == IMGFMT_422P){
00131         srcStride[1] *= 2;
00132         srcStride[2] *= 2;
00133     }
00134 
00135     h_size= (c->dstW+7)&~7;
00136     if(h_size*2 > dstStride[0]) h_size-=8;
00137     
00138     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
00139 //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],
00140 //srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
00141     for (y= 0; y<srcSliceH; y++ ) {
00142         uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
00143         uint8_t *_py = src[0] + y*srcStride[0];
00144         uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
00145         uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
00146         int index= -h_size/2;
00147 
00148         b5Dither= dither8[y&1];
00149         g6Dither= dither4[y&1];
00150         g5Dither= dither8[y&1];
00151         r5Dither= dither8[(y+1)&1];
00152             /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
00153                pixels in each iteration */
00154             __asm__ __volatile__ (
00155         /* load data for start of next scan line */
00156                      "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00157                      "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00158                      "movq (%5, %0, 2), %%mm6;" /* Load 8  Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00159 //                  ".balign 16                 \n\t"
00160                     "1:                         \n\t"
00161 /* no speed diference on my p3@500 with prefetch,
00162  * if it is faster for anyone with -benchmark then tell me
00163                         PREFETCH" 64(%0) \n\t"
00164                         PREFETCH" 64(%1) \n\t"
00165                         PREFETCH" 64(%2) \n\t"
00166 */
00167 YUV2RGB
00168 
00169 #ifdef DITHER1XBPP
00170                         "paddusb "MANGLE(b5Dither)", %%mm0;"
00171                         "paddusb "MANGLE(g6Dither)", %%mm2;"
00172                         "paddusb "MANGLE(r5Dither)", %%mm1;"
00173 #endif
00174                      /* mask unneeded bits off */
00175                      "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */
00176                      "pand "MANGLE(mmx_grnmask)", %%mm2;" /* g7g6g5g4 g3g2_0_0 g7g6g5g4 g3g2_0_0 */
00177                      "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */
00178 
00179                      "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */
00180                      "pxor %%mm4, %%mm4;" /* zero mm4 */
00181 
00182                      "movq %%mm0, %%mm5;" /* Copy B7-B0 */
00183                      "movq %%mm2, %%mm7;" /* Copy G7-G0 */
00184 
00185                      /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
00186                      "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
00187                      "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
00188 
00189                      "psllw $3, %%mm2;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */
00190                      "por %%mm2, %%mm0;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */
00191 
00192                      "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00193                      MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */
00194 
00195                      /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
00196                      "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3g2_0_0 */
00197                      "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
00198 
00199                      "psllw $3, %%mm7;" /* 0_0_0_0 0_g7g6g5 g4g3g2_0 0_0_0_0 */
00200                      "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00201 
00202                      "por %%mm7, %%mm5;" /* r7r6r5r4 r3g7g6g5 g4g3g2b7 b6b5b4b3 */
00203                      "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00204 
00205                      MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */
00206                      
00207                      "addl $16, %1                      \n\t"
00208                      "addl $4, %0                       \n\t"
00209                      " js 1b                            \n\t"
00210                      
00211                      : "+r" (index), "+r" (_image)
00212                      : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
00213                      );
00214     }
00215 
00216     __asm__ __volatile__ (EMMS);
00217     
00218     return srcSliceH;
00219 }
00220 
00221 static inline int RENAME(yuv420_rgb15)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00222              int srcSliceH, uint8_t* dst[], int dstStride[]){
00223     int y, h_size;
00224 
00225     if(c->srcFormat == IMGFMT_422P){
00226         srcStride[1] *= 2;
00227         srcStride[2] *= 2;
00228     }
00229 
00230     h_size= (c->dstW+7)&~7;
00231     if(h_size*2 > dstStride[0]) h_size-=8;
00232     
00233     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
00234 //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],
00235 //srcStride[0],srcStride[1],srcStride[2],dstStride[0]);
00236     for (y= 0; y<srcSliceH; y++ ) {
00237         uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
00238         uint8_t *_py = src[0] + y*srcStride[0];
00239         uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
00240         uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
00241         int index= -h_size/2;
00242 
00243         b5Dither= dither8[y&1];
00244         g6Dither= dither4[y&1];
00245         g5Dither= dither8[y&1];
00246         r5Dither= dither8[(y+1)&1];
00247             /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
00248                pixels in each iteration */
00249             __asm__ __volatile__ (
00250         /* load data for start of next scan line */
00251                      "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00252                      "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00253                      "movq (%5, %0, 2), %%mm6;" /* Load 8  Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00254 //                  ".balign 16                 \n\t"
00255                     "1:                         \n\t"
00256 YUV2RGB
00257 
00258 #ifdef DITHER1XBPP
00259                         "paddusb "MANGLE(b5Dither)", %%mm0      \n\t"
00260                         "paddusb "MANGLE(g5Dither)", %%mm2      \n\t"
00261                         "paddusb "MANGLE(r5Dither)", %%mm1      \n\t"
00262 #endif
00263 
00264                      /* mask unneeded bits off */
00265                      "pand "MANGLE(mmx_redmask)", %%mm0;" /* b7b6b5b4 b3_0_0_0 b7b6b5b4 b3_0_0_0 */
00266                      "pand "MANGLE(mmx_redmask)", %%mm2;" /* g7g6g5g4 g3_0_0_0 g7g6g5g4 g3_0_0_0 */
00267                      "pand "MANGLE(mmx_redmask)", %%mm1;" /* r7r6r5r4 r3_0_0_0 r7r6r5r4 r3_0_0_0 */
00268 
00269                      "psrlw $3,%%mm0;" /* 0_0_0_b7 b6b5b4b3 0_0_0_b7 b6b5b4b3 */
00270                      "psrlw $1,%%mm1;"            /* 0_r7r6r5  r4r3_0_0 0_r7r6r5 r4r3_0_0 */
00271                      "pxor %%mm4, %%mm4;" /* zero mm4 */
00272 
00273                      "movq %%mm0, %%mm5;" /* Copy B7-B0 */
00274                      "movq %%mm2, %%mm7;" /* Copy G7-G0 */
00275 
00276                      /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
00277                      "punpcklbw %%mm4, %%mm2;" /* 0_0_0_0 0_0_0_0 g7g6g5g4 g3_0_0_0 */
00278                      "punpcklbw %%mm1, %%mm0;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
00279 
00280                      "psllw $2, %%mm2;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */
00281                      "por %%mm2, %%mm0;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */
00282 
00283                      "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00284                      MOVNTQ " %%mm0, (%1);" /* store pixel 0-3 */
00285 
00286                      /* convert rgb24 plane to rgb16 pack for pixel 0-3 */
00287                      "punpckhbw %%mm4, %%mm7;" /* 0_0_0_0 0_0_0_0 0_g7g6g5 g4g3_0_0 */
00288                      "punpckhbw %%mm1, %%mm5;" /* r7r6r5r4 r3_0_0_0 0_0_0_b7 b6b5b4b3 */
00289 
00290                      "psllw $2, %%mm7;" /* 0_0_0_0 0_0_g7g6 g5g4g3_0 0_0_0_0 */
00291                      "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00292 
00293                      "por %%mm7, %%mm5;" /* 0_r7r6r5 r4r3g7g6 g5g4g3b7 b6b5b4b3 */
00294                      "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00295 
00296                      MOVNTQ " %%mm5, 8 (%1);" /* store pixel 4-7 */
00297                      
00298                      "addl $16, %1                      \n\t"
00299                      "addl $4, %0                       \n\t"
00300                      " js 1b                            \n\t"
00301                      : "+r" (index), "+r" (_image)
00302                      : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
00303                      );
00304     }
00305 
00306     __asm__ __volatile__ (EMMS);
00307     return srcSliceH;
00308 }
00309 
00310 static inline int RENAME(yuv420_rgb24)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00311              int srcSliceH, uint8_t* dst[], int dstStride[]){
00312     int y, h_size;
00313 
00314     if(c->srcFormat == IMGFMT_422P){
00315         srcStride[1] *= 2;
00316         srcStride[2] *= 2;
00317     }
00318 
00319     h_size= (c->dstW+7)&~7;
00320     if(h_size*3 > dstStride[0]) h_size-=8;
00321     
00322     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
00323 
00324     for (y= 0; y<srcSliceH; y++ ) {
00325         uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
00326         uint8_t *_py = src[0] + y*srcStride[0];
00327         uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
00328         uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
00329         int index= -h_size/2;
00330 
00331             /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
00332                pixels in each iteration */
00333             __asm__ __volatile__ (
00334         /* load data for start of next scan line */
00335                      "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00336                      "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00337                      "movq (%5, %0, 2), %%mm6;" /* Load 8  Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00338 //                  ".balign 16                 \n\t"
00339                     "1:                         \n\t"
00340 YUV2RGB
00341         /* mm0=B, %%mm2=G, %%mm1=R */
00342 #ifdef HAVE_MMX2
00343                         "movq "MANGLE(M24A)", %%mm4     \n\t"
00344                         "movq "MANGLE(M24C)", %%mm7     \n\t"
00345                         "pshufw $0x50, %%mm0, %%mm5     \n\t" /* B3 B2 B3 B2  B1 B0 B1 B0 */
00346                         "pshufw $0x50, %%mm2, %%mm3     \n\t" /* G3 G2 G3 G2  G1 G0 G1 G0 */
00347                         "pshufw $0x00, %%mm1, %%mm6     \n\t" /* R1 R0 R1 R0  R1 R0 R1 R0 */
00348 
00349                         "pand %%mm4, %%mm5              \n\t" /*    B2        B1       B0 */
00350                         "pand %%mm4, %%mm3              \n\t" /*    G2        G1       G0 */
00351                         "pand %%mm7, %%mm6              \n\t" /*       R1        R0       */
00352 
00353                         "psllq $8, %%mm3                \n\t" /* G2        G1       G0    */
00354                         "por %%mm5, %%mm6               \n\t"
00355                         "por %%mm3, %%mm6               \n\t"
00356                         MOVNTQ" %%mm6, (%1)             \n\t"
00357 
00358                         "psrlq $8, %%mm2                \n\t" /* 00 G7 G6 G5  G4 G3 G2 G1 */
00359                         "pshufw $0xA5, %%mm0, %%mm5     \n\t" /* B5 B4 B5 B4  B3 B2 B3 B2 */
00360                         "pshufw $0x55, %%mm2, %%mm3     \n\t" /* G4 G3 G4 G3  G4 G3 G4 G3 */
00361                         "pshufw $0xA5, %%mm1, %%mm6     \n\t" /* R5 R4 R5 R4  R3 R2 R3 R2 */
00362 
00363                         "pand "MANGLE(M24B)", %%mm5     \n\t" /* B5       B4        B3    */
00364                         "pand %%mm7, %%mm3              \n\t" /*       G4        G3       */
00365                         "pand %%mm4, %%mm6              \n\t" /*    R4        R3       R2 */
00366 
00367                         "por %%mm5, %%mm3               \n\t" /* B5    G4 B4     G3 B3    */
00368                         "por %%mm3, %%mm6               \n\t"
00369                         MOVNTQ" %%mm6, 8(%1)            \n\t"
00370 
00371                         "pshufw $0xFF, %%mm0, %%mm5     \n\t" /* B7 B6 B7 B6  B7 B6 B6 B7 */
00372                         "pshufw $0xFA, %%mm2, %%mm3     \n\t" /* 00 G7 00 G7  G6 G5 G6 G5 */
00373                         "pshufw $0xFA, %%mm1, %%mm6     \n\t" /* R7 R6 R7 R6  R5 R4 R5 R4 */
00374                         "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00375 
00376                         "pand %%mm7, %%mm5              \n\t" /*       B7        B6       */
00377                         "pand %%mm4, %%mm3              \n\t" /*    G7        G6       G5 */
00378                         "pand "MANGLE(M24B)", %%mm6     \n\t" /* R7       R6        R5    */
00379                         "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00380 \
00381                         "por %%mm5, %%mm3               \n\t"
00382                         "por %%mm3, %%mm6               \n\t"
00383                         MOVNTQ" %%mm6, 16(%1)           \n\t"
00384                         "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00385                         "pxor %%mm4, %%mm4              \n\t"
00386 
00387 #else
00388 
00389                         "pxor %%mm4, %%mm4              \n\t"
00390                         "movq %%mm0, %%mm5              \n\t" /* B */
00391                         "movq %%mm1, %%mm6              \n\t" /* R */
00392                         "punpcklbw %%mm2, %%mm0         \n\t" /* GBGBGBGB 0 */
00393                         "punpcklbw %%mm4, %%mm1         \n\t" /* 0R0R0R0R 0 */
00394                         "punpckhbw %%mm2, %%mm5         \n\t" /* GBGBGBGB 2 */
00395                         "punpckhbw %%mm4, %%mm6         \n\t" /* 0R0R0R0R 2 */
00396                         "movq %%mm0, %%mm7              \n\t" /* GBGBGBGB 0 */
00397                         "movq %%mm5, %%mm3              \n\t" /* GBGBGBGB 2 */
00398                         "punpcklwd %%mm1, %%mm7         \n\t" /* 0RGB0RGB 0 */
00399                         "punpckhwd %%mm1, %%mm0         \n\t" /* 0RGB0RGB 1 */
00400                         "punpcklwd %%mm6, %%mm5         \n\t" /* 0RGB0RGB 2 */
00401                         "punpckhwd %%mm6, %%mm3         \n\t" /* 0RGB0RGB 3 */
00402 
00403                         "movq %%mm7, %%mm2              \n\t" /* 0RGB0RGB 0 */
00404                         "movq %%mm0, %%mm6              \n\t" /* 0RGB0RGB 1 */
00405                         "movq %%mm5, %%mm1              \n\t" /* 0RGB0RGB 2 */
00406                         "movq %%mm3, %%mm4              \n\t" /* 0RGB0RGB 3 */
00407 
00408                         "psllq $40, %%mm7               \n\t" /* RGB00000 0 */
00409                         "psllq $40, %%mm0               \n\t" /* RGB00000 1 */
00410                         "psllq $40, %%mm5               \n\t" /* RGB00000 2 */
00411                         "psllq $40, %%mm3               \n\t" /* RGB00000 3 */
00412 
00413                         "punpckhdq %%mm2, %%mm7         \n\t" /* 0RGBRGB0 0 */
00414                         "punpckhdq %%mm6, %%mm0         \n\t" /* 0RGBRGB0 1 */
00415                         "punpckhdq %%mm1, %%mm5         \n\t" /* 0RGBRGB0 2 */
00416                         "punpckhdq %%mm4, %%mm3         \n\t" /* 0RGBRGB0 3 */
00417 
00418                         "psrlq $8, %%mm7                \n\t" /* 00RGBRGB 0 */
00419                         "movq %%mm0, %%mm6              \n\t" /* 0RGBRGB0 1 */
00420                         "psllq $40, %%mm0               \n\t" /* GB000000 1 */
00421                         "por %%mm0, %%mm7               \n\t" /* GBRGBRGB 0 */
00422                         MOVNTQ" %%mm7, (%1)             \n\t"
00423 
00424                         "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00425 
00426                         "psrlq $24, %%mm6               \n\t" /* 0000RGBR 1 */
00427                         "movq %%mm5, %%mm1              \n\t" /* 0RGBRGB0 2 */
00428                         "psllq $24, %%mm5               \n\t" /* BRGB0000 2 */
00429                         "por %%mm5, %%mm6               \n\t" /* BRGBRGBR 1 */
00430                         MOVNTQ" %%mm6, 8(%1)            \n\t"
00431 
00432                         "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00433 
00434                         "psrlq $40, %%mm1               \n\t" /* 000000RG 2 */
00435                         "psllq $8, %%mm3                \n\t" /* RGBRGB00 3 */
00436                         "por %%mm3, %%mm1               \n\t" /* RGBRGBRG 2 */
00437                         MOVNTQ" %%mm1, 16(%1)           \n\t"
00438 
00439                         "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00440                         "pxor %%mm4, %%mm4              \n\t"
00441 #endif
00442                      
00443                      "addl $24, %1                      \n\t"
00444                      "addl $4, %0                       \n\t"
00445                      " js 1b                            \n\t"
00446                      
00447                      : "+r" (index), "+r" (_image)
00448                      : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
00449                      );
00450     }
00451 
00452     __asm__ __volatile__ (EMMS);
00453     return srcSliceH;
00454 }
00455 
00456 static inline int RENAME(yuv420_rgb32)(SwsContext *c, uint8_t* src[], int srcStride[], int srcSliceY,
00457              int srcSliceH, uint8_t* dst[], int dstStride[]){
00458     int y, h_size;
00459 
00460     if(c->srcFormat == IMGFMT_422P){
00461         srcStride[1] *= 2;
00462         srcStride[2] *= 2;
00463     }
00464 
00465     h_size= (c->dstW+7)&~7;
00466     if(h_size*4 > dstStride[0]) h_size-=8;
00467     
00468     __asm__ __volatile__ ("pxor %mm4, %mm4;" /* zero mm4 */ );
00469 
00470     for (y= 0; y<srcSliceH; y++ ) {
00471         uint8_t *_image = dst[0] + (y+srcSliceY)*dstStride[0];
00472         uint8_t *_py = src[0] + y*srcStride[0];
00473         uint8_t *_pu = src[1] + (y>>1)*srcStride[1];
00474         uint8_t *_pv = src[2] + (y>>1)*srcStride[2];
00475         int index= -h_size/2;
00476 
00477             /* this mmx assembly code deals with SINGLE scan line at a time, it convert 8
00478                pixels in each iteration */
00479             __asm__ __volatile__ (
00480         /* load data for start of next scan line */
00481                      "movd (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00482                      "movd (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00483                      "movq (%5, %0, 2), %%mm6;" /* Load 8  Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00484 //                  ".balign 16                 \n\t"
00485                     "1:                         \n\t"
00486 YUV2RGB
00487                      /* convert RGB plane to RGB packed format,
00488                         mm0 -> B, mm1 -> R, mm2 -> G, mm3 -> 0,
00489                         mm4 -> GB, mm5 -> AR pixel 4-7,
00490                         mm6 -> GB, mm7 -> AR pixel 0-3 */
00491                      "pxor %%mm3, %%mm3;" /* zero mm3 */
00492 
00493                      "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
00494                      "movq %%mm1, %%mm7;" /* R7 R6 R5 R4 R3 R2 R1 R0 */
00495 
00496                      "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
00497                      "movq %%mm1, %%mm5;" /* R7 R6 R5 R4 R3 R2 R1 R0 */
00498 
00499                      "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */
00500                      "punpcklbw %%mm3, %%mm7;" /* 00 R3 00 R2 00 R1 00 R0 */
00501 
00502                      "punpcklwd %%mm7, %%mm6;" /* 00 R1 B1 G1 00 R0 B0 G0 */
00503                      MOVNTQ " %%mm6, (%1);" /* Store ARGB1 ARGB0 */
00504 
00505                      "movq %%mm0, %%mm6;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
00506                      "punpcklbw %%mm2, %%mm6;" /* G3 B3 G2 B2 G1 B1 G0 B0 */
00507 
00508                      "punpckhwd %%mm7, %%mm6;" /* 00 R3 G3 B3 00 R2 B3 G2 */
00509                      MOVNTQ " %%mm6, 8 (%1);" /* Store ARGB3 ARGB2 */
00510 
00511                      "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */
00512                      "punpckhbw %%mm3, %%mm5;" /* 00 R7 00 R6 00 R5 00 R4 */
00513 
00514                      "punpcklwd %%mm5, %%mm4;" /* 00 R5 B5 G5 00 R4 B4 G4 */
00515                      MOVNTQ " %%mm4, 16 (%1);" /* Store ARGB5 ARGB4 */
00516 
00517                      "movq %%mm0, %%mm4;" /* B7 B6 B5 B4 B3 B2 B1 B0 */
00518                      "punpckhbw %%mm2, %%mm4;" /* G7 B7 G6 B6 G5 B5 G4 B4 */
00519 
00520                      "punpckhwd %%mm5, %%mm4;" /* 00 R7 G7 B7 00 R6 B6 G6 */
00521                      MOVNTQ " %%mm4, 24 (%1);" /* Store ARGB7 ARGB6 */
00522 
00523                      "movd 4 (%2, %0), %%mm0;" /* Load 4 Cb 00 00 00 00 u3 u2 u1 u0 */
00524                      "movd 4 (%3, %0), %%mm1;" /* Load 4 Cr 00 00 00 00 v3 v2 v1 v0 */
00525 
00526                      "pxor %%mm4, %%mm4;" /* zero mm4 */
00527                      "movq 8 (%5, %0, 2), %%mm6;" /* Load 8 Y Y7 Y6 Y5 Y4 Y3 Y2 Y1 Y0 */
00528 
00529                      "addl $32, %1                      \n\t"
00530                      "addl $4, %0                       \n\t"
00531                      " js 1b                            \n\t"
00532                      
00533                      : "+r" (index), "+r" (_image)
00534                      : "r" (_pu - index), "r" (_pv - index), "r"(&c->redDither), "r" (_py - 2*index)
00535                      );
00536     }
00537 
00538     __asm__ __volatile__ (EMMS);
00539     return srcSliceH;
00540 }

Generated on Tue Dec 20 10:14:55 2005 for vlc-0.8.4a by  doxygen 1.4.2