openalbridge/endianness.h
changeset 2415 35d09cbf819a
parent 2261 57e99c908e7c
equal deleted inserted replaced
2414:fd9ca82077d8 2415:35d09cbf819a
    23 
    23 
    24 
    24 
    25 #ifdef __CPLUSPLUS
    25 #ifdef __CPLUSPLUS
    26 extern "C" {
    26 extern "C" {
    27 #endif 
    27 #endif 
       
    28 
       
    29 
       
    30 /* check compiler requirements */
       
    31 #if !defined(__BIG_ENDIAN__) && !defined(__LITTLE_ENDIAN__)
       
    32 #error Do not know the endianess of this architecture
       
    33 #endif
       
    34 
       
    35 
       
    36 /* use byteswap macros from the host system, hopefully optimized ones ;-) 
       
    37  * or define our own version, simple, stupid, straight-forward... */
       
    38 #ifdef HAVE_BYTESWAP_H
       
    39 #include <byteswap.h>
       
    40 #else        
       
    41 #define bswap_16(x)	((((x) & 0xFF00) >> 8) | (((x) & 0x00FF) << 8))
       
    42 #define bswap_32(x)	((((x) & 0xFF000000) >> 24) | (((x) & 0x00FF0000) >> 8)  | \
       
    43 (((x) & 0x0000FF00) << 8)  | (((x) & 0x000000FF) << 24) )
       
    44 #endif /* HAVE_BYTESWAP_H */
       
    45 
       
    46 
       
    47 /* swap numbers accordingly to architecture automatically */
       
    48 #ifdef __LITTLE_ENDIAN__
       
    49 #define ENDIAN_LITTLE_32(x) x
       
    50 #define ENDIAN_BIG_32(x)    bswap_32(x)
       
    51 #define ENDIAN_LITTLE_16(x) x
       
    52 #define ENDIAN_BIG_16(x)    bswap_16(x)
       
    53 #elif __BIG_ENDIAN__
       
    54 #define ENDIAN_LITTLE_32(x) bswap_32(x)
       
    55 #define ENDIAN_BIG_32(x)    x
       
    56 #define ENDIAN_LITTLE_16(x) bswap_16(x)
       
    57 #define ENDIAN_BIG_16(x)    x    
       
    58 #endif
    28         
    59         
    29     int invert_endianness(uint32_t number);
    60         
    30     
       
    31 #ifdef __CPLUSPLUS
    61 #ifdef __CPLUSPLUS
    32 }
    62 }
    33 #endif
    63 #endif
    34 
    64 
    35 #endif /*_OALB_ENDIANNESS_H*/
    65 #endif /*_OALB_ENDIANNESS_H*/