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
34 # define LEGACY_REGS "=Q"
36 # define LEGACY_REGS "=q"
40 static av_always_inline uint16_t bswap_16(uint16_t x)
48 static av_always_inline uint32_t bswap_32(uint32_t x)
54 __asm("xchgb %b0,%h0\n"
63 static inline uint64_t bswap_64(uint64_t x)
78 r.l.h = bswap_32 (x>>32);
83 #elif defined(ARCH_SH4)
85 static av_always_inline uint16_t bswap_16(uint16_t x) {
86 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
90 static av_always_inline uint32_t bswap_32(uint32_t x) {
99 static inline uint64_t bswap_64(uint64_t x)
107 r.l.l = bswap_32 (x);
108 r.l.h = bswap_32 (x>>32);
113 static av_always_inline uint16_t bswap_16(uint16_t x){
114 return (x>>8) | (x<<8);
118 static av_always_inline uint32_t bswap_32(uint32_t x){
121 "eor %1, %0, %0, ror #16 \n\t"
122 "bic %1, %1, #0xFF0000 \n\t"
123 "mov %0, %0, ror #8 \n\t"
124 "eor %0, %0, %1, lsr #8 \n\t"
129 static av_always_inline uint32_t bswap_32(uint32_t x){
130 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
131 return (x>>16) | (x<<16);
135 static inline uint64_t bswap_64(uint64_t x)
138 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
139 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
140 return (x>>32) | (x<<32);
147 r.l[0] = bswap_32 (w.l[1]);
148 r.l[1] = bswap_32 (w.l[0]);
152 #endif /* defined(ARCH_X86) */
154 #endif /* !HAVE_BYTESWAP_H */
156 // be2me ... BigEndian to MachineEndian
157 // le2me ... LittleEndian to MachineEndian
159 #ifdef WORDS_BIGENDIAN
160 #define be2me_16(x) (x)
161 #define be2me_32(x) (x)
162 #define be2me_64(x) (x)
163 #define le2me_16(x) bswap_16(x)
164 #define le2me_32(x) bswap_32(x)
165 #define le2me_64(x) bswap_64(x)
167 #define be2me_16(x) bswap_16(x)
168 #define be2me_32(x) bswap_32(x)
169 #define be2me_64(x) bswap_64(x)
170 #define le2me_16(x) (x)
171 #define le2me_32(x) (x)
172 #define le2me_64(x) (x)
175 #endif /* __BSWAP_H__ */