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 "config.h"
00031 #include "common.h"
00032
00033 #if ARCH_ARM
00034 # include "arm/bswap.h"
00035 #elif ARCH_BFIN
00036 # include "bfin/bswap.h"
00037 #elif ARCH_SH4
00038 # include "sh4/bswap.h"
00039 #elif ARCH_X86
00040 # include "x86/bswap.h"
00041 #endif
00042
00043 #ifndef bswap_16
00044 static av_always_inline av_const uint16_t bswap_16(uint16_t x)
00045 {
00046 x= (x>>8) | (x<<8);
00047 return x;
00048 }
00049 #endif
00050
00051 #ifndef bswap_32
00052 static av_always_inline av_const uint32_t bswap_32(uint32_t x)
00053 {
00054 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
00055 x= (x>>16) | (x<<16);
00056 return x;
00057 }
00058 #endif
00059
00060 #ifndef bswap_64
00061 static inline uint64_t av_const bswap_64(uint64_t x)
00062 {
00063 #if 0
00064 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
00065 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
00066 return (x>>32) | (x<<32);
00067 #else
00068 union {
00069 uint64_t ll;
00070 uint32_t l[2];
00071 } w, r;
00072 w.ll = x;
00073 r.l[0] = bswap_32 (w.l[1]);
00074 r.l[1] = bswap_32 (w.l[0]);
00075 return r.ll;
00076 #endif
00077 }
00078 #endif
00079
00080
00081
00082
00083 #ifdef WORDS_BIGENDIAN
00084 #define be2me_16(x) (x)
00085 #define be2me_32(x) (x)
00086 #define be2me_64(x) (x)
00087 #define le2me_16(x) bswap_16(x)
00088 #define le2me_32(x) bswap_32(x)
00089 #define le2me_64(x) bswap_64(x)
00090 #else
00091 #define be2me_16(x) bswap_16(x)
00092 #define be2me_32(x) bswap_32(x)
00093 #define be2me_64(x) bswap_64(x)
00094 #define le2me_16(x) (x)
00095 #define le2me_32(x) (x)
00096 #define le2me_64(x) (x)
00097 #endif
00098
00099 #endif