2 * copyright (c) 2006 Michael Niedermayer <michaelni@gmx.at>
4 * This file is part of FFmpeg.
6 * FFmpeg is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * FFmpeg is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with FFmpeg; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
29 #ifdef HAVE_BYTESWAP_H
36 /* rockbox' optimised inline functions */
37 #define bswap_16(x) swap16(x)
38 #define bswap_32(x) swap32(x)
40 static inline uint64_t ByteSwap64(uint64_t x
)
49 r
.l
.h
= bswap_32 (x
>>32);
52 #define bswap_64(x) ByteSwap64(x)
54 #elif defined(ARCH_X86)
55 static inline unsigned short ByteSwap16(unsigned short x
)
57 __asm("xchgb %b0,%h0" :
62 #define bswap_16(x) ByteSwap16(x)
64 static inline unsigned int ByteSwap32(unsigned int x
)
70 __asm("xchgb %b0,%h0\n"
78 #define bswap_32(x) ByteSwap32(x)
80 static inline unsigned long long int ByteSwap64(unsigned long long int x
)
82 register union { __extension__
uint64_t __ll
;
83 uint32_t __l
[2]; } __x
;
85 "=r"(__x
.__l
[0]),"=r"(__x
.__l
[1]):
86 "0"(bswap_32((unsigned long)x
)),"1"(bswap_32((unsigned long)(x
>>32))));
89 #define bswap_64(x) ByteSwap64(x)
91 #elif defined(ARCH_SH4)
93 static inline uint16_t ByteSwap16(uint16_t x
) {
94 __asm__("swap.b %0,%0":"=r"(x
):"0"(x
));
98 static inline uint32_t ByteSwap32(uint32_t x
) {
107 #define bswap_16(x) ByteSwap16(x)
108 #define bswap_32(x) ByteSwap32(x)
110 static inline uint64_t ByteSwap64(uint64_t x
)
118 r
.l
.l
= bswap_32 (x
);
119 r
.l
.h
= bswap_32 (x
>>32);
122 #define bswap_64(x) ByteSwap64(x)
126 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
128 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
129 #define bswap_32(x) \
130 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
131 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
133 static inline uint64_t ByteSwap64(uint64_t x
)
140 r
.l
[0] = bswap_32 (w
.l
[1]);
141 r
.l
[1] = bswap_32 (w
.l
[0]);
144 #define bswap_64(x) ByteSwap64(x)
146 #endif /* !ARCH_X86 */
148 #endif /* !HAVE_BYTESWAP_H */
150 // be2me ... BigEndian to MachineEndian
151 // le2me ... LittleEndian to MachineEndian
153 #ifdef WORDS_BIGENDIAN
154 #define be2me_16(x) (x)
155 #define be2me_32(x) (x)
156 #define be2me_64(x) (x)
157 #define le2me_16(x) bswap_16(x)
158 #define le2me_32(x) bswap_32(x)
159 #define le2me_64(x) bswap_64(x)
161 #define be2me_16(x) bswap_16(x)
162 #define be2me_32(x) bswap_32(x)
163 #define be2me_64(x) bswap_64(x)
164 #define le2me_16(x) (x)
165 #define le2me_32(x) (x)
166 #define le2me_64(x) (x)
169 #endif /* __BSWAP_H__ */