00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00026 #ifndef AVUTIL_BSWAP_H
00027 #define AVUTIL_BSWAP_H
00028 
00029 #include <stdint.h>
00030 #include "libavutil/avconfig.h"
00031 #include "attributes.h"
00032 
00033 #ifdef HAVE_AV_CONFIG_H
00034 
00035 #include "config.h"
00036 
00037 #if   ARCH_ARM
00038 #   include "arm/bswap.h"
00039 #elif ARCH_AVR32
00040 #   include "avr32/bswap.h"
00041 #elif ARCH_BFIN
00042 #   include "bfin/bswap.h"
00043 #elif ARCH_SH4
00044 #   include "sh4/bswap.h"
00045 #elif ARCH_X86
00046 #   include "x86/bswap.h"
00047 #endif
00048 
00049 #endif 
00050 
00051 #define AV_BSWAP16C(x) (((x) << 8 & 0xff00)  | ((x) >> 8 & 0x00ff))
00052 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
00053 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
00054 
00055 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
00056 
00057 #ifndef av_bswap16
00058 static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
00059 {
00060     x= (x>>8) | (x<<8);
00061     return x;
00062 }
00063 #endif
00064 
00065 #ifndef av_bswap32
00066 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
00067 {
00068     x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
00069     x= (x>>16) | (x<<16);
00070     return x;
00071 }
00072 #endif
00073 
00074 #ifndef av_bswap64
00075 static inline uint64_t av_const av_bswap64(uint64_t x)
00076 {
00077 #if 0
00078     x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
00079     x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
00080     return (x>>32) | (x<<32);
00081 #else
00082     union {
00083         uint64_t ll;
00084         uint32_t l[2];
00085     } w, r;
00086     w.ll = x;
00087     r.l[0] = av_bswap32 (w.l[1]);
00088     r.l[1] = av_bswap32 (w.l[0]);
00089     return r.ll;
00090 #endif
00091 }
00092 #endif
00093 
00094 
00095 
00096 
00097 #if AV_HAVE_BIGENDIAN
00098 #define av_be2ne16(x) (x)
00099 #define av_be2ne32(x) (x)
00100 #define av_be2ne64(x) (x)
00101 #define av_le2ne16(x) av_bswap16(x)
00102 #define av_le2ne32(x) av_bswap32(x)
00103 #define av_le2ne64(x) av_bswap64(x)
00104 #define AV_BE2NEC(s, x) (x)
00105 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
00106 #else
00107 #define av_be2ne16(x) av_bswap16(x)
00108 #define av_be2ne32(x) av_bswap32(x)
00109 #define av_be2ne64(x) av_bswap64(x)
00110 #define av_le2ne16(x) (x)
00111 #define av_le2ne32(x) (x)
00112 #define av_le2ne64(x) (x)
00113 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
00114 #define AV_LE2NEC(s, x) (x)
00115 #endif
00116 
00117 #define AV_BE2NE16C(x) AV_BE2NEC(16, x)
00118 #define AV_BE2NE32C(x) AV_BE2NEC(32, x)
00119 #define AV_BE2NE64C(x) AV_BE2NEC(64, x)
00120 #define AV_LE2NE16C(x) AV_LE2NEC(16, x)
00121 #define AV_LE2NE32C(x) AV_LE2NEC(32, x)
00122 #define AV_LE2NE64C(x) AV_LE2NEC(64, x)
00123 
00124 #endif