annotate dvdread/bswap.h @ 21759:8e1f3387d864

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