Mercurial > mplayer.hg
annotate dvdread/bswap.h @ 24077:9ce03980ed0c
added double click support in vo_macosx. Patch by Ulion <ulion2002@gmail.com>
author | nplourde |
---|---|
date | Sat, 18 Aug 2007 22:46:29 +0000 |
parents | b69c47dca975 |
children | 97a8394bec58 |
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 | |
28 #if defined(WORDS_BIGENDIAN) | |
29 /* All bigendian systems are fine, just ignore the swaps. */ | |
30 #define B2N_16(x) (void)(x) | |
31 #define B2N_32(x) (void)(x) | |
32 #define B2N_64(x) (void)(x) | |
33 | |
34 #else | |
35 | |
15874 | 36 /* For __FreeBSD_version */ |
37 #if defined(HAVE_SYS_PARAM_H) | |
38 #include <sys/param.h> | |
39 #endif | |
40 | |
7029 | 41 #if defined(__linux__) |
42 #include <byteswap.h> | |
43 #define B2N_16(x) x = bswap_16(x) | |
44 #define B2N_32(x) x = bswap_32(x) | |
45 #define B2N_64(x) x = bswap_64(x) | |
46 | |
47 #elif defined(__NetBSD__) | |
48 #include <sys/endian.h> | |
49 #define B2N_16(x) BE16TOH(x) | |
50 #define B2N_32(x) BE32TOH(x) | |
51 #define B2N_64(x) BE64TOH(x) | |
52 | |
53 #elif defined(__OpenBSD__) | |
54 #include <sys/endian.h> | |
55 #define B2N_16(x) x = swap16(x) | |
56 #define B2N_32(x) x = swap32(x) | |
57 #define B2N_64(x) x = swap64(x) | |
58 | |
15874 | 59 #elif defined(__FreeBSD__) && __FreeBSD_version >= 470000 |
60 #include <sys/endian.h> | |
61 #define B2N_16(x) x = be16toh(x) | |
62 #define B2N_32(x) x = be32toh(x) | |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
63 #if __FreeBSD_version >= 500000 |
15874 | 64 #define B2N_64(x) x = be64toh(x) |
24047
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
65 #else |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
66 #define B2N_64(x) \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
67 x = ((((x) & 0xff00000000000000) >> 56) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
68 (((x) & 0x00ff000000000000) >> 40) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
69 (((x) & 0x0000ff0000000000) >> 24) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
70 (((x) & 0x000000ff00000000) >> 8) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
71 (((x) & 0x00000000ff000000) << 8) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
72 (((x) & 0x0000000000ff0000) << 24) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
73 (((x) & 0x000000000000ff00) << 40) | \ |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
74 (((x) & 0x00000000000000ff) << 56)) |
de28f9e8cb00
Sync libdvdread with version 0.9.5 (functional changes).
diego
parents:
21592
diff
changeset
|
75 #endif /* _FreeBSD_version >= 500000 */ |
15874 | 76 |
77 #elif defined(__DragonFly__) | |
78 #include <sys/endian.h> | |
79 #define B2N_16(x) x = be16toh(x) | |
80 #define B2N_32(x) x = be32toh(x) | |
81 #define B2N_64(x) x = be64toh(x) | |
82 | |
24065 | 83 |
84 #elif defined(__APPLE__) || defined(__DARWIN__) | |
85 #include <libkern/OSByteOrder.h> | |
86 #define B2N_16(x) x = OSSwapBigToHostConstInt16(x) | |
87 #define B2N_32(x) x = OSSwapBigToHostConstInt32(x) | |
88 #define B2N_64(x) x = OSSwapBigToHostConstInt64(x) | |
89 | |
7033 | 90 #elif defined(ARCH_X86) |
91 inline static unsigned short bswap_16(unsigned short x) | |
92 { | |
93 __asm("xchgb %b0,%h0" : | |
94 "=q" (x) : | |
95 "0" (x)); | |
96 return x; | |
97 } | |
98 #define B2N_16(x) x = bswap_16(x) | |
99 | |
100 inline static unsigned int bswap_32(unsigned int x) | |
101 { | |
102 __asm( | |
21592
ae0f4c4e4d9d
__CPU__ will be x86-64 under amd64 and fail the check "#if __CPU__ > 386".
diego
parents:
20981
diff
changeset
|
103 #if __CPU__ != 386 |
7033 | 104 "bswap %0": |
105 "=r" (x) : | |
106 #else | |
107 "xchgb %b0,%h0\n" | |
108 " rorl $16,%0\n" | |
109 " xchgb %b0,%h0": | |
110 "=q" (x) : | |
111 #endif | |
112 "0" (x)); | |
113 return x; | |
114 } | |
115 #define B2N_32(x) x = bswap_32(x) | |
116 | |
117 inline static unsigned long long int bswap_64(unsigned long long int x) | |
118 { | |
119 register union { __extension__ uint64_t __ll; | |
120 uint32_t __l[2]; } __x; | |
121 asm("xchgl %0,%1": | |
122 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
123 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
124 return __x.__ll; | |
125 } | |
126 #define B2N_64(x) x = bswap_64(x) | |
127 | |
24065 | 128 #else |
129 #if defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(WIN32) || defined(__BEOS__) || defined(__INTERIX) || defined(__CYGWIN__) | |
130 /* These systems don't have swap macros */ | |
131 #else | |
132 /* If there isn't a header provided with your system with this functionality | |
133 * add the relevant || define( ) to the list above. | |
134 */ | |
135 #warning "You should add endian swap macros for your system" | |
136 #endif | |
137 | |
7029 | 138 /* This is a slow but portable implementation, it has multiple evaluation |
139 * problems so beware. | |
15874 | 140 * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such |
7029 | 141 * functionality! |
142 */ | |
15874 | 143 |
24050
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
144 #define B2N_16(x) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
145 x = ((((x) & 0xff00) >> 8) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
146 (((x) & 0x00ff) << 8)) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
147 #define B2N_32(x) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
148 x = ((((x) & 0xff000000) >> 24) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
149 (((x) & 0x00ff0000) >> 8) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
150 (((x) & 0x0000ff00) << 8) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
151 (((x) & 0x000000ff) << 24)) |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
152 #define B2N_64(x) \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
153 x = ((((x) & 0xff00000000000000) >> 56) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
154 (((x) & 0x00ff000000000000) >> 40) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
155 (((x) & 0x0000ff0000000000) >> 24) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
156 (((x) & 0x000000ff00000000) >> 8) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
157 (((x) & 0x00000000ff000000) << 8) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
158 (((x) & 0x0000000000ff0000) << 24) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
159 (((x) & 0x000000000000ff00) << 40) | \ |
1542693b2a30
Sync libdvdread with version 0.9.5 (cosmetic changes).
diego
parents:
24047
diff
changeset
|
160 (((x) & 0x00000000000000ff) << 56)) |
7029 | 161 |
162 | |
163 | |
164 #endif | |
165 | |
166 #endif /* WORDS_BIGENDIAN */ | |
167 | |
168 #endif /* BSWAP_H_INCLUDED */ |