aboutsummaryrefslogtreecommitdiffstats
path: root/libavutil
diff options
context:
space:
mode:
authorMåns Rullgård <mans@mansr.com>2010-04-29 14:41:20 +0000
committerMåns Rullgård <mans@mansr.com>2010-04-29 14:41:20 +0000
commit547b7bcbb77d7f5b2cbcbce8d734ea43617194ab (patch)
treedefd31a209f6fc16151819b44ec611787db9112e /libavutil
parentfaa2989e0f016fa44d41bc1047dee4f421ab088a (diff)
downloadffmpeg-547b7bcbb77d7f5b2cbcbce8d734ea43617194ab.tar.gz
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. Originally committed as revision 22990 to svn://svn.ffmpeg.org/ffmpeg/trunk
Diffstat (limited to 'libavutil')
-rw-r--r--libavutil/bswap.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/libavutil/bswap.h b/libavutil/bswap.h
index f2023c01bc..2d36f2e2ea 100644
--- a/libavutil/bswap.h
+++ b/libavutil/bswap.h
@@ -42,6 +42,12 @@
# include "x86/bswap.h"
#endif
+#define AV_BSWAP16C(x) (((x) << 8 & 0xff00) | ((x) >> 8 & 0x00ff))
+#define AV_BSWAP32C(x) (AV_BSWAP16C(x) << 16 | AV_BSWAP16C(x >> 16))
+#define AV_BSWAP64C(x) (AV_BSWAP32C(x) << 32 | AV_BSWAP32C(x >> 32))
+
+#define AV_BSWAPC(s, x) AV_BSWAP##s##C(x)
+
#ifndef bswap_16
static av_always_inline av_const uint16_t bswap_16(uint16_t x)
{
@@ -89,6 +95,8 @@ static inline uint64_t av_const bswap_64(uint64_t x)
#define le2me_16(x) bswap_16(x)
#define le2me_32(x) bswap_32(x)
#define le2me_64(x) bswap_64(x)
+#define AV_BE2MEC(s, x) (x)
+#define AV_LE2MEC(s, x) AV_BSWAPC(s, x)
#else
#define be2me_16(x) bswap_16(x)
#define be2me_32(x) bswap_32(x)
@@ -96,6 +104,15 @@ static inline uint64_t av_const bswap_64(uint64_t x)
#define le2me_16(x) (x)
#define le2me_32(x) (x)
#define le2me_64(x) (x)
+#define AV_BE2MEC(s, x) AV_BSWAPC(s, x)
+#define AV_LE2MEC(s, x) (x)
#endif
+#define AV_BE2ME16C(x) AV_BE2MEC(16, x)
+#define AV_BE2ME32C(x) AV_BE2MEC(32, x)
+#define AV_BE2ME64C(x) AV_BE2MEC(64, x)
+#define AV_LE2ME16C(x) AV_LE2MEC(16, x)
+#define AV_LE2ME32C(x) AV_LE2MEC(32, x)
+#define AV_LE2ME64C(x) AV_LE2MEC(64, x)
+
#endif /* AVUTIL_BSWAP_H */