Mercurial > mplayer.hg
annotate dvdread/bswap.h @ 23077:17bf4f4b0715
Gui --> gui
author | diego |
---|---|
date | Mon, 23 Apr 2007 07:42:42 +0000 |
parents | ae0f4c4e4d9d |
children | de28f9e8cb00 |
rev | line source |
---|---|
7029 | 1 #ifndef BSWAP_H_INCLUDED |
2 #define BSWAP_H_INCLUDED | |
3 | |
4 /* | |
5 * Copyright (C) 2000, 2001 Billy Biggs <vektor@dumbterm.net>, | |
6 * Håkan Hjort <d95hjort@dtek.chalmers.se> | |
7 * | |
14938
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
7033
diff
changeset
|
8 * Modified for use with MPlayer, changes contained in libdvdread_changes.diff. |
18783 | 9 * detailed changelog at http://svn.mplayerhq.hu/mplayer/trunk/ |
14938
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
7033
diff
changeset
|
10 * $Id$ |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
7033
diff
changeset
|
11 * |
7029 | 12 * This program is free software; you can redistribute it and/or modify |
13 * it under the terms of the GNU General Public License as published by | |
14 * the Free Software Foundation; either version 2 of the License, or | |
15 * (at your option) any later version. | |
16 * | |
17 * This program is distributed in the hope that it will be useful, | |
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
20 * GNU General Public License for more details. | |
21 * | |
22 * You should have received a copy of the GNU General Public License | |
23 * along with this program; if not, write to the Free Software | |
24 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
25 */ | |
26 | |
20793 | 27 #include <config.h> |
28 | |
7029 | 29 #if defined(WORDS_BIGENDIAN) |
30 /* All bigendian systems are fine, just ignore the swaps. */ | |
31 #define B2N_16(x) (void)(x) | |
32 #define B2N_32(x) (void)(x) | |
33 #define B2N_64(x) (void)(x) | |
34 | |
35 #else | |
36 | |
15874 | 37 /* For __FreeBSD_version */ |
38 #if defined(HAVE_SYS_PARAM_H) | |
39 #include <sys/param.h> | |
40 #endif | |
41 | |
7029 | 42 #if defined(__linux__) |
43 #include <byteswap.h> | |
44 #define B2N_16(x) x = bswap_16(x) | |
45 #define B2N_32(x) x = bswap_32(x) | |
46 #define B2N_64(x) x = bswap_64(x) | |
47 | |
48 #elif defined(__NetBSD__) | |
49 #include <sys/endian.h> | |
50 #define B2N_16(x) BE16TOH(x) | |
51 #define B2N_32(x) BE32TOH(x) | |
52 #define B2N_64(x) BE64TOH(x) | |
53 | |
54 #elif defined(__OpenBSD__) | |
55 #include <sys/endian.h> | |
56 #define B2N_16(x) x = swap16(x) | |
57 #define B2N_32(x) x = swap32(x) | |
58 #define B2N_64(x) x = swap64(x) | |
59 | |
15874 | 60 #elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 |
61 #include <sys/endian.h> | |
62 #define B2N_16(x) x = be16toh(x) | |
63 #define B2N_32(x) x = be32toh(x) | |
64 #define B2N_64(x) x = be64toh(x) | |
65 | |
66 #elif defined(__DragonFly__) | |
67 #include <sys/endian.h> | |
68 #define B2N_16(x) x = be16toh(x) | |
69 #define B2N_32(x) x = be32toh(x) | |
70 #define B2N_64(x) x = be64toh(x) | |
71 | |
7033 | 72 #elif defined(ARCH_X86) |
73 inline static unsigned short bswap_16(unsigned short x) | |
74 { | |
75 __asm("xchgb %b0,%h0" : | |
76 "=q" (x) : | |
77 "0" (x)); | |
78 return x; | |
79 } | |
80 #define B2N_16(x) x = bswap_16(x) | |
81 | |
82 inline static unsigned int bswap_32(unsigned int x) | |
83 { | |
84 __asm( | |
21592
ae0f4c4e4d9d
__CPU__ will be x86-64 under amd64 and fail the check "#if __CPU__ > 386".
diego
parents:
20981
diff
changeset
|
85 #if __CPU__ != 386 |
7033 | 86 "bswap %0": |
87 "=r" (x) : | |
88 #else | |
89 "xchgb %b0,%h0\n" | |
90 " rorl $16,%0\n" | |
91 " xchgb %b0,%h0": | |
92 "=q" (x) : | |
93 #endif | |
94 "0" (x)); | |
95 return x; | |
96 } | |
97 #define B2N_32(x) x = bswap_32(x) | |
98 | |
99 inline static unsigned long long int bswap_64(unsigned long long int x) | |
100 { | |
101 register union { __extension__ uint64_t __ll; | |
102 uint32_t __l[2]; } __x; | |
103 asm("xchgl %0,%1": | |
104 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
105 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
106 return __x.__ll; | |
107 } | |
108 #define B2N_64(x) x = bswap_64(x) | |
109 | |
7029 | 110 /* This is a slow but portable implementation, it has multiple evaluation |
111 * problems so beware. | |
15874 | 112 * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such |
7029 | 113 * functionality! |
114 */ | |
15874 | 115 |
7033 | 116 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) |
7029 | 117 #define B2N_16(x) \ |
118 x = ((((x) & 0xff00) >> 8) | \ | |
119 (((x) & 0x00ff) << 8)) | |
120 #define B2N_32(x) \ | |
121 x = ((((x) & 0xff000000) >> 24) | \ | |
122 (((x) & 0x00ff0000) >> 8) | \ | |
123 (((x) & 0x0000ff00) << 8) | \ | |
124 (((x) & 0x000000ff) << 24)) | |
125 #define B2N_64(x) \ | |
126 x = ((((x) & 0xff00000000000000) >> 56) | \ | |
127 (((x) & 0x00ff000000000000) >> 40) | \ | |
128 (((x) & 0x0000ff0000000000) >> 24) | \ | |
129 (((x) & 0x000000ff00000000) >> 8) | \ | |
130 (((x) & 0x00000000ff000000) << 8) | \ | |
131 (((x) & 0x0000000000ff0000) << 24) | \ | |
132 (((x) & 0x000000000000ff00) << 40) | \ | |
133 (((x) & 0x00000000000000ff) << 56)) | |
134 | |
135 #else | |
136 | |
137 /* If there isn't a header provided with your system with this functionality | |
138 * add the relevant || define( ) to the portable implementation above. | |
139 */ | |
140 #error "You need to add endian swap macros for you're system" | |
141 | |
142 #endif | |
143 | |
144 #endif /* WORDS_BIGENDIAN */ | |
145 | |
146 #endif /* BSWAP_H_INCLUDED */ |