access_http: use the user agent provided by the user: fix #4162
[vlc/asuraparaju-public.git] / modules / codec / wmafixed / bswap.h
blobed6a9d13d41ab3b99f53aab5c88a1c91509941fa
1 /*
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
21 /**
22 * @file bswap.h
23 * byte swap.
26 #ifndef __BSWAP_H__
27 #define __BSWAP_H__
29 #ifdef HAVE_BYTESWAP_H
30 #include <byteswap.h>
31 #else
33 #undef ROCKBOX
34 #ifdef ROCKBOX
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)
42 union {
43 uint64_t ll;
44 struct {
45 uint32_t l,h;
46 } l;
47 } r;
48 r.l.l = bswap_32 (x);
49 r.l.h = bswap_32 (x>>32);
50 return r.ll;
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" :
58 "=q" (x) :
59 "0" (x));
60 return x;
62 #define bswap_16(x) ByteSwap16(x)
64 static inline unsigned int ByteSwap32(unsigned int x)
66 #if __CPU__ > 386
67 __asm("bswap %0":
68 "=r" (x) :
69 #else
70 __asm("xchgb %b0,%h0\n"
71 " rorl $16,%0\n"
72 " xchgb %b0,%h0":
73 "=q" (x) :
74 #endif
75 "0" (x));
76 return x;
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;
84 asm("xchgl %0,%1":
85 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
86 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
87 return __x.__ll;
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));
95 return x;
98 static inline uint32_t ByteSwap32(uint32_t x) {
99 __asm__(
100 "swap.b %0,%0\n"
101 "swap.w %0,%0\n"
102 "swap.b %0,%0\n"
103 :"=r"(x):"0"(x));
104 return x;
107 #define bswap_16(x) ByteSwap16(x)
108 #define bswap_32(x) ByteSwap32(x)
110 static inline uint64_t ByteSwap64(uint64_t x)
112 union {
113 uint64_t ll;
114 struct {
115 uint32_t l,h;
116 } l;
117 } r;
118 r.l.l = bswap_32 (x);
119 r.l.h = bswap_32 (x>>32);
120 return r.ll;
122 #define bswap_64(x) ByteSwap64(x)
124 #else
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)
135 union {
136 uint64_t ll;
137 uint32_t l[2];
138 } w, r;
139 w.ll = x;
140 r.l[0] = bswap_32 (w.l[1]);
141 r.l[1] = bswap_32 (w.l[0]);
142 return r.ll;
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)
160 #else
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)
167 #endif
169 #endif /* __BSWAP_H__ */