Changeset 828

Show
Ignore:
Timestamp:
03/12/08 23:55:59 (4 months ago)
Author:
astrange
Message:

Factor out some common YUV code and mark stuff unlikely() if it is.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/ColorConversions.c

    r827 r828  
    2424#include <sys/sysctl.h> 
    2525 
     26#ifndef GOOD_COMPILER 
     27#define noinline __attribute__((noinline)) 
     28#else 
     29#define noinline 
     30#endif 
     31 
     32#define unlikely(x) __builtin_expect(x, 0) 
     33 
    2634//----------------------------------------------------------------- 
    2735// FastY420 
     
    5866// have a decent OS/QT version. 
    5967//----------------------------------------------------------------- 
     68 
     69static void noinline Y420toY422_lastrow(UInt8 *o, const UInt8 *yc, const UInt8 *uc, const UInt8 *vc, unsigned halfWidth) 
     70{ 
     71        unsigned x; 
     72        for(x=0; x < halfWidth; x++) 
     73        { 
     74                unsigned x4 = x*4, x2 = x*2; 
     75                o[x4] = uc[x]; 
     76                o[x4+1] = yc[x2]; 
     77                o[x4+2] = vc[x]; 
     78                o[x4+3] = yc[x2+1]; 
     79        } 
     80} 
     81 
     82#define HandleLastRow(o, yc, uc, vc, halfWidth, height) if (unlikely(height & 1)) Y420toY422_lastrow(o, yc, uc, vc, halfWidth) 
    6083 
    6184#ifdef __BIG_ENDIAN__ 
     
    104127                 baseAddr += outRB * 2; 
    105128         } 
    106         if(height & 1) 
    107         { 
    108                 int x; 
    109                 for(x=0; x < halfWidth; x++) 
    110                 { 
    111                         unsigned x4 = x*4, x2 = x*2; 
    112                         baseAddr[x4] = inU[x]; 
    113                         baseAddr[x4+1] = inY[x2]; 
    114                         baseAddr[x4+2] = inV[x]; 
    115                         baseAddr[x4+3] = inY[x2+1]; 
    116                 } 
    117         }        
     129         
     130        HandleLastRow(baseAddr, inY, inU, inV, halfWidth, height); 
    118131 } 
    119132 
     
    166179                vc += rV; 
    167180        } 
    168         if(height & 1) 
    169         { 
    170                 unsigned halfwidth = width / 2; 
    171                 for(x=0; x < halfwidth; x++) 
    172                 { 
    173                         unsigned x4 = x*4, x2 = x*2; 
    174                         o[x4] = uc[x]; 
    175                         o[x4+1] = yc[x2]; 
    176                         o[x4+2] = vc[x]; 
    177                         o[x4+3] = yc[x2+1]; 
    178                 } 
    179         }        
     181         
     182        HandleLastRow(o, yc, uc, vc, width / 2, height); 
    180183} 
    181184 
     
    213216                asm volatile( 
    214217                        "\n0:                   \n\t" 
     218                        "movdqa         (%2),   %%xmm0  \n\t" 
     219                        "movdqa         16(%2), %%xmm2  \n\t" 
     220                        "movdqa         (%3),           %%xmm1  \n\t" 
     221                        "movdqa         16(%3), %%xmm3  \n\t" 
    215222                        "movdqu         (%4),   %%xmm4  \n\t" 
    216223                        "movdqu         (%5),   %%xmm5  \n\t" 
     224                        "addl           $32,    %2              \n\t" 
     225                        "addl           $32,    %3              \n\t" 
    217226                        "addl           $16,    %4              \n\t" 
    218227                        "addl           $16,    %5              \n\t" 
    219                         "movdqa         (%2),   %%xmm0  \n\t" 
    220                         "movdqa         16(%2), %%xmm2  \n\t" 
    221                         "addl           $32,    %2              \n\t" 
    222                         "movdqa         (%3),           %%xmm1  \n\t" 
    223                         "movdqa         16(%3), %%xmm3  \n\t" 
    224                         "addl           $32,    %3              \n\t" 
    225228                        "movdqa         %%xmm4, %%xmm6  \n\t" 
    226229                        "punpcklbw      %%xmm5, %%xmm4  \n\t" /*chroma_l*/ 
     
    252255                        "dec            %6                              \n\t" 
    253256                        "jnz            0b                              \n\t" 
    254                         : 
    255257                        : "r" (ov), "r" (ov2), 
    256258                        "r" (yv), "r" (yv2), "r" (uv), "r" (vv), 
    257                         "c" (vWidth) 
     259                        "r" (vWidth) 
    258260                        ); 
    259261#else 
     
    294296                vc += rV; 
    295297        } 
    296         if(height & 1) 
    297         { 
    298                 for(x=0; x < halfwidth; x++) 
    299                 { 
    300                         unsigned x4 = x*4, x2 = x*2; 
    301                         o[x4] = uc[x]; 
    302                         o[x4+1] = yc[x2]; 
    303                         o[x4+2] = vc[x]; 
    304                         o[x4+3] = yc[x2+1]; 
    305                 } 
    306         } 
    307 
    308  
    309  
    310 static void __attribute__((noinline)) Y420toY422_x86_scalar(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
     298         
     299        _mm_sfence(); 
     300         
     301        HandleLastRow(o, yc, uc, vc, halfwidth, height); 
     302
     303 
     304 
     305static void noinline Y420toY422_x86_scalar(UInt8 * o, unsigned outRB, unsigned width, unsigned height, AVFrame * picture) 
    311306{ 
    312307        UInt8           *yc = picture->data[0], *u = picture->data[1], *v = picture->data[2]; 
     
    332327                v += rV; 
    333328        } 
    334         if(height & 1) 
    335         { 
    336                 for(x=0; x < halfwidth; x++) 
    337                 { 
    338                         unsigned x4 = x*4, x2 = x*2; 
    339                         o[x4] = u[x]; 
    340                         o[x4+1] = yc[x2]; 
    341                         o[x4+2] = v[x]; 
    342                         o[x4+3] = yc[x2+1]; 
    343                 } 
    344         } 
     329 
     330        HandleLastRow(o, yc, u, v, halfwidth, height); 
    345331} 
    346332 
     
    350336 
    351337        //make sure the ffmpeg picture buffers are aligned enough, they're only guaranteed to be 8-byte for some reason... 
    352         if ((yc | picture->linesize[0]) % 16 == 0) { 
    353                 Y420toY422_sse2(o, outRB, width, height, picture); 
    354                 _mm_sfence(); 
    355         } else Y420toY422_x86_scalar(o, outRB, width, height, picture); 
     338        if (!unlikely((yc | picture->linesize[0]) % 16)) Y420toY422_sse2(o, outRB, width, height, picture);  
     339        else Y420toY422_x86_scalar(o, outRB, width, height, picture); 
    356340} 
    357341#endif 
  • trunk/Perian.xcodeproj/project.pbxproj

    r814 r828  
    110110                3D211A300B6B1AD80051299D /* SubParsing.m.rl in Sources */ = {isa = PBXBuildFile; fileRef = 3D211A2F0B6B1AD80051299D /* SubParsing.m.rl */; }; 
    111111                3D41BEB40BCD3B510069E7C2 /* libuniversaldetector.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3D41BE9A0BCD3B330069E7C2 /* libuniversaldetector.a */; }; 
    112                 3D4A7A990B5533BC004C5D6A /* ColorConversions.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */; settings = {COMPILER_FLAGS = "-O3 -fno-reorder-blocks -fweb"; }; }; 
     112                3D4A7A990B5533BC004C5D6A /* ColorConversions.c in Sources */ = {isa = PBXBuildFile; fileRef = 3D4A7A980B5533BC004C5D6A /* ColorConversions.c */; settings = {COMPILER_FLAGS = "-O3 -fweb -fno-reorder-blocks -fomit-frame-pointer"; }; }; 
    113113                3DAD32DA0B6DB26100DA0A72 /* StdIOCallback.cpp in Sources */ = {isa = PBXBuildFile; fileRef = 61CB114D0ACDF3C2007994BD /* StdIOCallback.cpp */; }; 
    114114                3DB2BB290B6C92F000416863 /* SubATSUIRenderer.m in Sources */ = {isa = PBXBuildFile; fileRef = 3DB2BB280B6C92F000416863 /* SubATSUIRenderer.m */; }; 
     
    18581858                                DEAD_CODE_STRIPPING = YES; 
    18591859                                EXPORTED_SYMBOLS_FILE = "$(SOURCE_ROOT)/exportedSymbols"; 
    1860                                 GCC_DYNAMIC_NO_PIC = NO; 
    18611860                                GCC_ENABLE_FIX_AND_CONTINUE = YES; 
    18621861                                GCC_ENABLE_OBJC_GC = YES; 
     
    19011900                                EXPORTED_SYMBOLS_FILE = "$(SOURCE_ROOT)/exportedSymbols"; 
    19021901                                GCC_ALTIVEC_EXTENSIONS = YES; 
    1903                                 GCC_DYNAMIC_NO_PIC = NO; 
    19041902                                GCC_ENABLE_FIX_AND_CONTINUE = NO; 
    19051903                                GCC_ENABLE_OBJC_GC = YES; 
     
    20272025                                EXPORTED_SYMBOLS_FILE = "$(SOURCE_ROOT)/exportedSymbols"; 
    20282026                                GCC_ALTIVEC_EXTENSIONS = YES; 
    2029                                 GCC_DYNAMIC_NO_PIC = NO; 
    20302027                                GCC_ENABLE_FIX_AND_CONTINUE = NO; 
    20312028                                GCC_ENABLE_OBJC_GC = YES;