Mercurial > mplayer.hg
comparison libmpdvdkit2/bswap.h @ 7033:596919e4f601
apply mplayer-specific patches
author | arpi |
---|---|
date | Fri, 16 Aug 2002 22:50:22 +0000 |
parents | 9db58ffbd73c |
children | 25df9508f9a8 |
comparison
equal
deleted
inserted
replaced
7032:fd2d4be9ed6f | 7033:596919e4f601 |
---|---|
17 * | 17 * |
18 * You should have received a copy of the GNU General Public License | 18 * You should have received a copy of the GNU General Public License |
19 * along with this program; if not, write to the Free Software | 19 * along with this program; if not, write to the Free Software |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
21 */ | 21 */ |
22 | |
23 #include <config.h> | |
24 | 22 |
25 #if defined(WORDS_BIGENDIAN) | 23 #if defined(WORDS_BIGENDIAN) |
26 /* All bigendian systems are fine, just ignore the swaps. */ | 24 /* All bigendian systems are fine, just ignore the swaps. */ |
27 #define B2N_16(x) (void)(x) | 25 #define B2N_16(x) (void)(x) |
28 #define B2N_32(x) (void)(x) | 26 #define B2N_32(x) (void)(x) |
46 #include <sys/endian.h> | 44 #include <sys/endian.h> |
47 #define B2N_16(x) x = swap16(x) | 45 #define B2N_16(x) x = swap16(x) |
48 #define B2N_32(x) x = swap32(x) | 46 #define B2N_32(x) x = swap32(x) |
49 #define B2N_64(x) x = swap64(x) | 47 #define B2N_64(x) x = swap64(x) |
50 | 48 |
49 #elif defined(ARCH_X86) | |
50 inline static unsigned short bswap_16(unsigned short x) | |
51 { | |
52 __asm("xchgb %b0,%h0" : | |
53 "=q" (x) : | |
54 "0" (x)); | |
55 return x; | |
56 } | |
57 #define B2N_16(x) x = bswap_16(x) | |
58 | |
59 inline static unsigned int bswap_32(unsigned int x) | |
60 { | |
61 __asm( | |
62 #if __CPU__ > 386 | |
63 "bswap %0": | |
64 "=r" (x) : | |
65 #else | |
66 "xchgb %b0,%h0\n" | |
67 " rorl $16,%0\n" | |
68 " xchgb %b0,%h0": | |
69 "=q" (x) : | |
70 #endif | |
71 "0" (x)); | |
72 return x; | |
73 } | |
74 #define B2N_32(x) x = bswap_32(x) | |
75 | |
76 inline static unsigned long long int bswap_64(unsigned long long int x) | |
77 { | |
78 register union { __extension__ uint64_t __ll; | |
79 uint32_t __l[2]; } __x; | |
80 asm("xchgl %0,%1": | |
81 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
82 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
83 return __x.__ll; | |
84 } | |
85 #define B2N_64(x) x = bswap_64(x) | |
86 | |
51 /* This is a slow but portable implementation, it has multiple evaluation | 87 /* This is a slow but portable implementation, it has multiple evaluation |
52 * problems so beware. | 88 * problems so beware. |
53 * FreeBSD and Solaris don't have <byteswap.h> or any other such | 89 * FreeBSD and Solaris don't have <byteswap.h> or any other such |
54 * functionality! | 90 * functionality! |
55 */ | 91 */ |
56 | 92 |
57 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) | 93 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) |
58 #define B2N_16(x) \ | 94 #define B2N_16(x) \ |
59 x = ((((x) & 0xff00) >> 8) | \ | 95 x = ((((x) & 0xff00) >> 8) | \ |
60 (((x) & 0x00ff) << 8)) | 96 (((x) & 0x00ff) << 8)) |
61 #define B2N_32(x) \ | 97 #define B2N_32(x) \ |
62 x = ((((x) & 0xff000000) >> 24) | \ | 98 x = ((((x) & 0xff000000) >> 24) | \ |