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