Mercurial > mplayer.hg
annotate libdvdread/bswap.h @ 20734:9f97c2b0340f
If parsing a seek head fails then mplayer should try continue parsing the file after the seek head.
author | mosu |
---|---|
date | Tue, 07 Nov 2006 18:14:30 +0000 |
parents | 1a4fcea7ab53 |
children | 8b9a98c1f351 |
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 | |
27 #if defined(WORDS_BIGENDIAN) | |
28 /* All bigendian systems are fine, just ignore the swaps. */ | |
29 #define B2N_16(x) (void)(x) | |
30 #define B2N_32(x) (void)(x) | |
31 #define B2N_64(x) (void)(x) | |
32 | |
33 #else | |
34 | |
15874 | 35 /* For __FreeBSD_version */ |
36 #if defined(HAVE_SYS_PARAM_H) | |
37 #include <sys/param.h> | |
38 #endif | |
39 | |
7029 | 40 #if defined(__linux__) |
41 #include <byteswap.h> | |
42 #define B2N_16(x) x = bswap_16(x) | |
43 #define B2N_32(x) x = bswap_32(x) | |
44 #define B2N_64(x) x = bswap_64(x) | |
45 | |
46 #elif defined(__NetBSD__) | |
47 #include <sys/endian.h> | |
48 #define B2N_16(x) BE16TOH(x) | |
49 #define B2N_32(x) BE32TOH(x) | |
50 #define B2N_64(x) BE64TOH(x) | |
51 | |
52 #elif defined(__OpenBSD__) | |
53 #include <sys/endian.h> | |
54 #define B2N_16(x) x = swap16(x) | |
55 #define B2N_32(x) x = swap32(x) | |
56 #define B2N_64(x) x = swap64(x) | |
57 | |
15874 | 58 #elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 |
59 #include <sys/endian.h> | |
60 #define B2N_16(x) x = be16toh(x) | |
61 #define B2N_32(x) x = be32toh(x) | |
62 #define B2N_64(x) x = be64toh(x) | |
63 | |
64 #elif defined(__DragonFly__) | |
65 #include <sys/endian.h> | |
66 #define B2N_16(x) x = be16toh(x) | |
67 #define B2N_32(x) x = be32toh(x) | |
68 #define B2N_64(x) x = be64toh(x) | |
69 | |
7033 | 70 #elif defined(ARCH_X86) |
71 inline static unsigned short bswap_16(unsigned short x) | |
72 { | |
73 __asm("xchgb %b0,%h0" : | |
74 "=q" (x) : | |
75 "0" (x)); | |
76 return x; | |
77 } | |
78 #define B2N_16(x) x = bswap_16(x) | |
79 | |
80 inline static unsigned int bswap_32(unsigned int x) | |
81 { | |
82 __asm( | |
83 #if __CPU__ > 386 | |
84 "bswap %0": | |
85 "=r" (x) : | |
86 #else | |
87 "xchgb %b0,%h0\n" | |
88 " rorl $16,%0\n" | |
89 " xchgb %b0,%h0": | |
90 "=q" (x) : | |
91 #endif | |
92 "0" (x)); | |
93 return x; | |
94 } | |
95 #define B2N_32(x) x = bswap_32(x) | |
96 | |
97 inline static unsigned long long int bswap_64(unsigned long long int x) | |
98 { | |
99 register union { __extension__ uint64_t __ll; | |
100 uint32_t __l[2]; } __x; | |
101 asm("xchgl %0,%1": | |
102 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
103 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
104 return __x.__ll; | |
105 } | |
106 #define B2N_64(x) x = bswap_64(x) | |
107 | |
7029 | 108 /* This is a slow but portable implementation, it has multiple evaluation |
109 * problems so beware. | |
15874 | 110 * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such |
7029 | 111 * functionality! |
112 */ | |
15874 | 113 |
7033 | 114 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) |
7029 | 115 #define B2N_16(x) \ |
116 x = ((((x) & 0xff00) >> 8) | \ | |
117 (((x) & 0x00ff) << 8)) | |
118 #define B2N_32(x) \ | |
119 x = ((((x) & 0xff000000) >> 24) | \ | |
120 (((x) & 0x00ff0000) >> 8) | \ | |
121 (((x) & 0x0000ff00) << 8) | \ | |
122 (((x) & 0x000000ff) << 24)) | |
123 #define B2N_64(x) \ | |
124 x = ((((x) & 0xff00000000000000) >> 56) | \ | |
125 (((x) & 0x00ff000000000000) >> 40) | \ | |
126 (((x) & 0x0000ff0000000000) >> 24) | \ | |
127 (((x) & 0x000000ff00000000) >> 8) | \ | |
128 (((x) & 0x00000000ff000000) << 8) | \ | |
129 (((x) & 0x0000000000ff0000) << 24) | \ | |
130 (((x) & 0x000000000000ff00) << 40) | \ | |
131 (((x) & 0x00000000000000ff) << 56)) | |
132 | |
133 #else | |
134 | |
135 /* If there isn't a header provided with your system with this functionality | |
136 * add the relevant || define( ) to the portable implementation above. | |
137 */ | |
138 #error "You need to add endian swap macros for you're system" | |
139 | |
140 #endif | |
141 | |
142 #endif /* WORDS_BIGENDIAN */ | |
143 | |
144 #endif /* BSWAP_H_INCLUDED */ |