freetype-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Git][freetype/freetype][master] * src/pcf/pcfutil.c ({Two,Four}ByteSwap


From: Alexei Podtelezhnikov (@apodtele)
Subject: [Git][freetype/freetype][master] * src/pcf/pcfutil.c ({Two,Four}ByteSwap): Use builtins or shifts.
Date: Tue, 15 Nov 2022 04:04:12 +0000

Alexei Podtelezhnikov pushed to branch master at FreeType / FreeType

Commits:

  • 47e61d02
    by Alexei Podtelezhnikov at 2022-11-14T22:53:14-05:00
    * src/pcf/pcfutil.c ({Two,Four}ByteSwap): Use builtins or shifts.
    
    We trust glibc which uses shifts or builtins to swap bytes.  This
    must be more efficient.
    

1 changed file:

Changes:

  • src/pcf/pcfutil.c
    ... ... @@ -57,6 +57,33 @@ in this Software without prior written authorization from The Open Group.
    57 57
       }
    
    58 58
     
    
    59 59
     
    
    60
    +#if defined( __clang__ ) || ( defined( __GNUC__ )                &&  \
    
    61
    +    ( __GNUC__ > 4 || ( __GNUC__ == 4 && __GNUC_MINOR__ >= 8 ) ) )
    
    62
    +
    
    63
    +#define BSWAP16( x )  __builtin_bswap16( x )
    
    64
    +#define BSWAP32( x )  __builtin_bswap32( x )
    
    65
    +
    
    66
    +#elif defined( _MSC_VER ) && _MSC_VER >= 1300
    
    67
    +
    
    68
    +#pragma intrinsic( _byteswap_ushort )
    
    69
    +#pragma intrinsic( _byteswap_ulong )
    
    70
    +
    
    71
    +#define BSWAP16( x )  _byteswap_ushort( x )
    
    72
    +#define BSWAP32( x )  _byteswap_ulong( x )
    
    73
    +
    
    74
    +#else
    
    75
    +
    
    76
    +#define BSWAP16( x )                             \
    
    77
    +        (FT_UInt16)( ( ( ( x ) >> 8 ) & 0xff ) | \
    
    78
    +                     ( ( ( x ) & 0xff ) << 8 ) )
    
    79
    +#define BSWAP32( x )                   \
    
    80
    +        (FT_UInt32)( ( ( ( x ) & 0xff000000u ) >> 24 ) | \
    
    81
    +                     ( ( ( x ) & 0x00ff0000u ) >> 8  ) | \
    
    82
    +                     ( ( ( x ) & 0x0000ff00u ) << 8  ) | \
    
    83
    +                     ( ( ( x ) & 0x000000ffu ) << 24 ) )
    
    84
    +
    
    85
    +#endif
    
    86
    +
    
    60 87
       /*
    
    61 88
        * Invert byte order within each 16-bits of an array.
    
    62 89
        */
    
    ... ... @@ -65,15 +92,11 @@ in this Software without prior written authorization from The Open Group.
    65 92
       TwoByteSwap( unsigned char*  buf,
    
    66 93
                    size_t          nbytes )
    
    67 94
       {
    
    68
    -    for ( ; nbytes >= 2; nbytes -= 2, buf += 2 )
    
    69
    -    {
    
    70
    -      unsigned char  c;
    
    95
    +    FT_UInt16*  b = (FT_UInt16*)buf;
    
    71 96
     
    
    72 97
     
    
    73
    -      c      = buf[0];
    
    74
    -      buf[0] = buf[1];
    
    75
    -      buf[1] = c;
    
    76
    -    }
    
    98
    +    for ( ; nbytes >= 2; nbytes -= 2, b++ )
    
    99
    +      *b = BSWAP16( *b );
    
    77 100
       }
    
    78 101
     
    
    79 102
       /*
    
    ... ... @@ -84,19 +107,11 @@ in this Software without prior written authorization from The Open Group.
    84 107
       FourByteSwap( unsigned char*  buf,
    
    85 108
                     size_t          nbytes )
    
    86 109
       {
    
    87
    -    for ( ; nbytes >= 4; nbytes -= 4, buf += 4 )
    
    88
    -    {
    
    89
    -      unsigned char  c;
    
    90
    -
    
    110
    +    FT_UInt32*  b = (FT_UInt32*)buf;
    
    91 111
     
    
    92
    -      c      = buf[0];
    
    93
    -      buf[0] = buf[3];
    
    94
    -      buf[3] = c;
    
    95 112
     
    
    96
    -      c      = buf[1];
    
    97
    -      buf[1] = buf[2];
    
    98
    -      buf[2] = c;
    
    99
    -    }
    
    113
    +    for ( ; nbytes >= 4; nbytes -= 4, b++ )
    
    114
    +      *b = BSWAP32( *b );
    
    100 115
       }
    
    101 116
     
    
    102 117
     
    


  • reply via email to

    [Prev in Thread] Current Thread [Next in Thread]