comparison bswap.h @ 993:f8db9a2bae05 libavutil

Add av_ prefix to bswap macros
author mru
date Sat, 10 Jul 2010 22:12:30 +0000
parents a13125b5be3a
children 41878f66798f
comparison
equal deleted inserted replaced
992:a13125b5be3a 993:f8db9a2bae05
46 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16)) 46 #define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C((x) >> 16))
47 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32)) 47 #define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C((x) >> 32))
48 48
49 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x) 49 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
50 50
51 #ifndef bswap_16 51 #ifndef av_bswap16
52 static av_always_inline av_const uint16_t bswap_16(uint16_t x) 52 static av_always_inline av_const uint16_t av_bswap16(uint16_t x)
53 { 53 {
54 x= (x>>8) | (x<<8); 54 x= (x>>8) | (x<<8);
55 return x; 55 return x;
56 } 56 }
57 #endif 57 #endif
58 58
59 #ifndef bswap_32 59 #ifndef av_bswap32
60 static av_always_inline av_const uint32_t bswap_32(uint32_t x) 60 static av_always_inline av_const uint32_t av_bswap32(uint32_t x)
61 { 61 {
62 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); 62 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
63 x= (x>>16) | (x<<16); 63 x= (x>>16) | (x<<16);
64 return x; 64 return x;
65 } 65 }
66 #endif 66 #endif
67 67
68 #ifndef bswap_64 68 #ifndef av_bswap64
69 static inline uint64_t av_const bswap_64(uint64_t x) 69 static inline uint64_t av_const av_bswap64(uint64_t x)
70 { 70 {
71 #if 0 71 #if 0
72 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); 72 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
73 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); 73 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
74 return (x>>32) | (x<<32); 74 return (x>>32) | (x<<32);
76 union { 76 union {
77 uint64_t ll; 77 uint64_t ll;
78 uint32_t l[2]; 78 uint32_t l[2];
79 } w, r; 79 } w, r;
80 w.ll = x; 80 w.ll = x;
81 r.l[0] = bswap_32 (w.l[1]); 81 r.l[0] = av_bswap32 (w.l[1]);
82 r.l[1] = bswap_32 (w.l[0]); 82 r.l[1] = av_bswap32 (w.l[0]);
83 return r.ll; 83 return r.ll;
84 #endif 84 #endif
85 } 85 }
86 #endif 86 #endif
87 87
88 // be2ne ... big-endian to native-endian 88 // be2ne ... big-endian to native-endian
89 // le2ne ... little-endian to native-endian 89 // le2ne ... little-endian to native-endian
90 90
91 #if HAVE_BIGENDIAN 91 #if HAVE_BIGENDIAN
92 #define be2ne_16(x) (x) 92 #define av_be2ne16(x) (x)
93 #define be2ne_32(x) (x) 93 #define av_be2ne32(x) (x)
94 #define be2ne_64(x) (x) 94 #define av_be2ne64(x) (x)
95 #define le2ne_16(x) bswap_16(x) 95 #define av_le2ne16(x) av_bswap16(x)
96 #define le2ne_32(x) bswap_32(x) 96 #define av_le2ne32(x) av_bswap32(x)
97 #define le2ne_64(x) bswap_64(x) 97 #define av_le2ne64(x) av_bswap64(x)
98 #define AV_BE2NEC(s, x) (x) 98 #define AV_BE2NEC(s, x) (x)
99 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x) 99 #define AV_LE2NEC(s, x) AV_BSWAPC(s, x)
100 #else 100 #else
101 #define be2ne_16(x) bswap_16(x) 101 #define av_be2ne16(x) av_bswap16(x)
102 #define be2ne_32(x) bswap_32(x) 102 #define av_be2ne32(x) av_bswap32(x)
103 #define be2ne_64(x) bswap_64(x) 103 #define av_be2ne64(x) av_bswap64(x)
104 #define le2ne_16(x) (x) 104 #define av_le2ne16(x) (x)
105 #define le2ne_32(x) (x) 105 #define av_le2ne32(x) (x)
106 #define le2ne_64(x) (x) 106 #define av_le2ne64(x) (x)
107 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x) 107 #define AV_BE2NEC(s, x) AV_BSWAPC(s, x)
108 #define AV_LE2NEC(s, x) (x) 108 #define AV_LE2NEC(s, x) (x)
109 #endif 109 #endif
110 110
111 #define AV_BE2NE16C(x) AV_BE2NEC(16, x) 111 #define AV_BE2NE16C(x) AV_BE2NEC(16, x)