Mercurial > libavutil.hg
comparison bswap.h @ 914:66b39cb91dde libavutil
bswap: add macros to byteswap constants
The normal byteswap functions might use inline asm which is suboptimal
with constants (and cannot be used in static initialisers), so special
macros for constants only is needed.
We should not rely on the gcc __builtin_constant_p() test since it is
not always available.
author | mru |
---|---|
date | Thu, 29 Apr 2010 14:41:20 +0000 |
parents | 0795a743bda1 |
children | e0e9e51684ef |
comparison
equal
deleted
inserted
replaced
913:de7b577403bc | 914:66b39cb91dde |
---|---|
39 #elif ARCH_SH4 | 39 #elif ARCH_SH4 |
40 # include "sh4/bswap.h" | 40 # include "sh4/bswap.h" |
41 #elif ARCH_X86 | 41 #elif ARCH_X86 |
42 # include "x86/bswap.h" | 42 # include "x86/bswap.h" |
43 #endif | 43 #endif |
44 | |
45 #define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff)) | |
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)) | |
48 | |
49 #define AV_BSWAPC(s, x) AV_BSWAP##s##C(x) | |
44 | 50 |
45 #ifndef bswap_16 | 51 #ifndef bswap_16 |
46 static av_always_inline av_const uint16_t bswap_16(uint16_t x) | 52 static av_always_inline av_const uint16_t bswap_16(uint16_t x) |
47 { | 53 { |
48 x= (x>>8) | (x<<8); | 54 x= (x>>8) | (x<<8); |
87 #define be2me_32(x) (x) | 93 #define be2me_32(x) (x) |
88 #define be2me_64(x) (x) | 94 #define be2me_64(x) (x) |
89 #define le2me_16(x) bswap_16(x) | 95 #define le2me_16(x) bswap_16(x) |
90 #define le2me_32(x) bswap_32(x) | 96 #define le2me_32(x) bswap_32(x) |
91 #define le2me_64(x) bswap_64(x) | 97 #define le2me_64(x) bswap_64(x) |
98 #define AV_BE2MEC(s, x) (x) | |
99 #define AV_LE2MEC(s, x) AV_BSWAPC(s, x) | |
92 #else | 100 #else |
93 #define be2me_16(x) bswap_16(x) | 101 #define be2me_16(x) bswap_16(x) |
94 #define be2me_32(x) bswap_32(x) | 102 #define be2me_32(x) bswap_32(x) |
95 #define be2me_64(x) bswap_64(x) | 103 #define be2me_64(x) bswap_64(x) |
96 #define le2me_16(x) (x) | 104 #define le2me_16(x) (x) |
97 #define le2me_32(x) (x) | 105 #define le2me_32(x) (x) |
98 #define le2me_64(x) (x) | 106 #define le2me_64(x) (x) |
107 #define AV_BE2MEC(s, x) AV_BSWAPC(s, x) | |
108 #define AV_LE2MEC(s, x) (x) | |
99 #endif | 109 #endif |
100 | 110 |
111 #define AV_BE2ME16C(x) AV_BE2MEC(16, x) | |
112 #define AV_BE2ME32C(x) AV_BE2MEC(32, x) | |
113 #define AV_BE2ME64C(x) AV_BE2MEC(64, x) | |
114 #define AV_LE2ME16C(x) AV_LE2MEC(16, x) | |
115 #define AV_LE2ME32C(x) AV_LE2MEC(32, x) | |
116 #define AV_LE2ME64C(x) AV_LE2MEC(64, x) | |
117 | |
101 #endif /* AVUTIL_BSWAP_H */ | 118 #endif /* AVUTIL_BSWAP_H */ |