Another logf fix in voice_thread.c
[kugel-rb.git] / apps / codecs / lib / ffmpeg_bswap.h
blob24a2aab7ea39ece7b3a8f997bdf67bf421994172
1 /**
2 * @file bswap.h
3 * byte swap.
4 */
6 #ifndef __BSWAP_H__
7 #define __BSWAP_H__
9 #ifdef HAVE_BYTESWAP_H
10 #include <byteswap.h>
11 #else
13 #ifdef ROCKBOX
14 #include "codecs.h"
16 /* rockbox' optimised inline functions */
17 #define bswap_16(x) swap16(x)
18 #define bswap_32(x) swap32(x)
20 static inline uint64_t ByteSwap64(uint64_t x)
22 union {
23 uint64_t ll;
24 struct {
25 uint32_t l,h;
26 } l;
27 } r;
28 r.l.l = bswap_32 (x);
29 r.l.h = bswap_32 (x>>32);
30 return r.ll;
32 #define bswap_64(x) ByteSwap64(x)
34 #elif defined(ARCH_X86)
35 static inline unsigned short ByteSwap16(unsigned short x)
37 __asm("xchgb %b0,%h0" :
38 "=q" (x) :
39 "0" (x));
40 return x;
42 #define bswap_16(x) ByteSwap16(x)
44 static inline unsigned int ByteSwap32(unsigned int x)
46 #if __CPU__ > 386
47 __asm("bswap %0":
48 "=r" (x) :
49 #else
50 __asm("xchgb %b0,%h0\n"
51 " rorl $16,%0\n"
52 " xchgb %b0,%h0":
53 "=q" (x) :
54 #endif
55 "0" (x));
56 return x;
58 #define bswap_32(x) ByteSwap32(x)
60 static inline unsigned long long int ByteSwap64(unsigned long long int x)
62 register union { __extension__ uint64_t __ll;
63 uint32_t __l[2]; } __x;
64 asm("xchgl %0,%1":
65 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
66 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
67 return __x.__ll;
69 #define bswap_64(x) ByteSwap64(x)
71 #elif defined(ARCH_SH4)
73 static inline uint16_t ByteSwap16(uint16_t x) {
74 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
75 return x;
78 static inline uint32_t ByteSwap32(uint32_t x) {
79 __asm__(
80 "swap.b %0,%0\n"
81 "swap.w %0,%0\n"
82 "swap.b %0,%0\n"
83 :"=r"(x):"0"(x));
84 return x;
87 #define bswap_16(x) ByteSwap16(x)
88 #define bswap_32(x) ByteSwap32(x)
90 static inline uint64_t ByteSwap64(uint64_t x)
92 union {
93 uint64_t ll;
94 struct {
95 uint32_t l,h;
96 } l;
97 } r;
98 r.l.l = bswap_32 (x);
99 r.l.h = bswap_32 (x>>32);
100 return r.ll;
102 #define bswap_64(x) ByteSwap64(x)
104 #else
106 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
109 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
110 #define bswap_32(x) \
111 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
112 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
114 static inline uint64_t ByteSwap64(uint64_t x)
116 union {
117 uint64_t ll;
118 uint32_t l[2];
119 } w, r;
120 w.ll = x;
121 r.l[0] = bswap_32 (w.l[1]);
122 r.l[1] = bswap_32 (w.l[0]);
123 return r.ll;
125 #define bswap_64(x) ByteSwap64(x)
127 #endif /* !ARCH_X86 */
129 #endif /* !HAVE_BYTESWAP_H */
131 // be2me ... BigEndian to MachineEndian
132 // le2me ... LittleEndian to MachineEndian
134 #ifdef ROCKBOX_BIG_ENDIAN
135 #define be2me_16(x) (x)
136 #define be2me_32(x) (x)
137 #define be2me_64(x) (x)
138 #define le2me_16(x) bswap_16(x)
139 #define le2me_32(x) bswap_32(x)
140 #define le2me_64(x) bswap_64(x)
141 #else
142 #define be2me_16(x) bswap_16(x)
143 #define be2me_32(x) bswap_32(x)
144 #define be2me_64(x) bswap_64(x)
145 #define le2me_16(x) (x)
146 #define le2me_32(x) (x)
147 #define le2me_64(x) (x)
148 #endif
150 #endif /* __BSWAP_H__ */