annotate libmpdvdkit2/bswap.h @ 11434:5084f09ba20e

Fix pthread & lrmi segfault issue. ("Oleg I. Vdovikin" <vdovikin@jscc.ru>)
author ranma
date Tue, 11 Nov 2003 10:39:36 +0000
parents 596919e4f601
children 25df9508f9a8
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 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
8 * This program is free software; you can redistribute it and/or modify
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
9 * it under the terms of the GNU General Public License as published by
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
11 * (at your option) any later version.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
12 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
13 * This program is distributed in the hope that it will be useful,
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
16 * GNU General Public License for more details.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
17 *
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
19 * along with this program; if not, write to the Free Software
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
21 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
22
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
23 #if defined(WORDS_BIGENDIAN)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
24 /* All bigendian systems are fine, just ignore the swaps. */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
25 #define B2N_16(x) (void)(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
26 #define B2N_32(x) (void)(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
27 #define B2N_64(x) (void)(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
28
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
29 #else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
30
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
31 #if defined(__linux__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
32 #include <byteswap.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
33 #define B2N_16(x) x = bswap_16(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
34 #define B2N_32(x) x = bswap_32(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
35 #define B2N_64(x) x = bswap_64(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
36
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
37 #elif defined(__NetBSD__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
38 #include <sys/endian.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
39 #define B2N_16(x) BE16TOH(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
40 #define B2N_32(x) BE32TOH(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
41 #define B2N_64(x) BE64TOH(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
42
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
43 #elif defined(__OpenBSD__)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
44 #include <sys/endian.h>
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
45 #define B2N_16(x) x = swap16(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
46 #define B2N_32(x) x = swap32(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
47 #define B2N_64(x) x = swap64(x)
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
48
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
49 #elif defined(ARCH_X86)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
50 inline static unsigned short bswap_16(unsigned short x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
51 {
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
52 __asm("xchgb %b0,%h0" :
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
53 "=q" (x) :
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
54 "0" (x));
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
55 return x;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
56 }
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
57 #define B2N_16(x) x = bswap_16(x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
58
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
59 inline static unsigned int bswap_32(unsigned int x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
60 {
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
61 __asm(
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
62 #if __CPU__ > 386
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
63 "bswap %0":
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
64 "=r" (x) :
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
65 #else
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
66 "xchgb %b0,%h0\n"
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
67 " rorl $16,%0\n"
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
68 " xchgb %b0,%h0":
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
69 "=q" (x) :
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
70 #endif
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
71 "0" (x));
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
72 return x;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
73 }
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
74 #define B2N_32(x) x = bswap_32(x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
75
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
76 inline static unsigned long long int bswap_64(unsigned long long int x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
77 {
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
78 register union { __extension__ uint64_t __ll;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
79 uint32_t __l[2]; } __x;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
80 asm("xchgl %0,%1":
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
81 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
82 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
83 return __x.__ll;
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
84 }
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
85 #define B2N_64(x) x = bswap_64(x)
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
86
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
87 /* This is a slow but portable implementation, it has multiple evaluation
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
88 * problems so beware.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
89 * FreeBSD and Solaris don't have <byteswap.h> or any other such
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
90 * functionality!
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
91 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
92
7033
596919e4f601 apply mplayer-specific patches
arpi
parents: 7029
diff changeset
93 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__)
7029
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
94 #define B2N_16(x) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
95 x = ((((x) & 0xff00) >> 8) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
96 (((x) & 0x00ff) << 8))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
97 #define B2N_32(x) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
98 x = ((((x) & 0xff000000) >> 24) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
99 (((x) & 0x00ff0000) >> 8) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
100 (((x) & 0x0000ff00) << 8) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
101 (((x) & 0x000000ff) << 24))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
102 #define B2N_64(x) \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
103 x = ((((x) & 0xff00000000000000) >> 56) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
104 (((x) & 0x00ff000000000000) >> 40) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
105 (((x) & 0x0000ff0000000000) >> 24) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
106 (((x) & 0x000000ff00000000) >> 8) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
107 (((x) & 0x00000000ff000000) << 8) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
108 (((x) & 0x0000000000ff0000) << 24) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
109 (((x) & 0x000000000000ff00) << 40) | \
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
110 (((x) & 0x00000000000000ff) << 56))
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
111
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
112 #else
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
113
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
114 /* If there isn't a header provided with your system with this functionality
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
115 * add the relevant || define( ) to the portable implementation above.
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
116 */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
117 #error "You need to add endian swap macros for you're system"
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
118
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
119 #endif
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
120
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
121 #endif /* WORDS_BIGENDIAN */
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
122
9db58ffbd73c importing libdvdread 0.9.3 files
arpi
parents:
diff changeset
123 #endif /* BSWAP_H_INCLUDED */