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
23 * byte swapping routines
26 #ifndef FFMPEG_BSWAP_H
27 #define FFMPEG_BSWAP_H
33 #ifdef HAVE_BYTESWAP_H
37 static av_always_inline av_const
uint16_t bswap_16(uint16_t x
)
40 asm("rorw $8, %0" : "+r"(x
));
41 #elif defined(ARCH_SH4)
42 asm("swap.b %0,%0" : "=r"(x
) : "0"(x
));
49 static av_always_inline av_const
uint32_t bswap_32(uint32_t x
)
53 asm("bswap %0" : "+r" (x
));
55 asm("rorw $8, %w0 \n\t"
60 #elif defined(ARCH_SH4)
65 #elif defined(ARCH_ARM)
67 asm ("eor %1, %0, %0, ror #16 \n\t"
68 "bic %1, %1, #0xFF0000 \n\t"
69 "mov %0, %0, ror #8 \n\t"
70 "eor %0, %0, %1, lsr #8 \n\t"
72 #elif defined(ARCH_BFIN)
74 asm("%1 = %0 >> 8 (V); \n\t"
75 "%0 = %0 << 8 (V); \n\t"
77 "%0 = PACK(%0.L, %0.H); \n\t"
78 : "+d"(x
), "=&d"(tmp
));
80 x
= ((x
<<8)&0xFF00FF00) | ((x
>>8)&0x00FF00FF);
86 static inline uint64_t av_const
bswap_64(uint64_t x
)
89 x
= ((x
<< 8)&0xFF00FF00FF00FF00ULL
) | ((x
>> 8)&0x00FF00FF00FF00FFULL
);
90 x
= ((x
<<16)&0xFFFF0000FFFF0000ULL
) | ((x
>>16)&0x0000FFFF0000FFFFULL
);
91 return (x
>>32) | (x
<<32);
92 #elif defined(ARCH_X86_64)
93 asm("bswap %0": "=r" (x
) : "0" (x
));
101 r
.l
[0] = bswap_32 (w
.l
[1]);
102 r
.l
[1] = bswap_32 (w
.l
[0]);
107 #endif /* !HAVE_BYTESWAP_H */
109 // be2me ... BigEndian to MachineEndian
110 // le2me ... LittleEndian to MachineEndian
112 #ifdef WORDS_BIGENDIAN
113 #define be2me_16(x) (x)
114 #define be2me_32(x) (x)
115 #define be2me_64(x) (x)
116 #define le2me_16(x) bswap_16(x)
117 #define le2me_32(x) bswap_32(x)
118 #define le2me_64(x) bswap_64(x)
120 #define be2me_16(x) bswap_16(x)
121 #define be2me_32(x) bswap_32(x)
122 #define be2me_64(x) bswap_64(x)
123 #define le2me_16(x) (x)
124 #define le2me_32(x) (x)
125 #define le2me_64(x) (x)
128 #endif /* FFMPEG_BSWAP_H */