Mercurial > mplayer.hg
annotate libmpdvdkit2/bswap.h @ 15151:1edaf17d5205
messed ordering of switch branches, 10l for Ivan
author | henry |
---|---|
date | Wed, 13 Apr 2005 19:38:44 +0000 |
parents | 25df9508f9a8 |
children | 3758536dcef3 |
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. |
25df9508f9a8
Mark modified files as such to comply more closely with GPL ¡ø2a.
diego
parents:
7033
diff
changeset
|
9 * detailed CVS changelog at http://www.mplayerhq.hu/cgi-bin/cvsweb.cgi/main/ |
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 | |
35 #if defined(__linux__) | |
36 #include <byteswap.h> | |
37 #define B2N_16(x) x = bswap_16(x) | |
38 #define B2N_32(x) x = bswap_32(x) | |
39 #define B2N_64(x) x = bswap_64(x) | |
40 | |
41 #elif defined(__NetBSD__) | |
42 #include <sys/endian.h> | |
43 #define B2N_16(x) BE16TOH(x) | |
44 #define B2N_32(x) BE32TOH(x) | |
45 #define B2N_64(x) BE64TOH(x) | |
46 | |
47 #elif defined(__OpenBSD__) | |
48 #include <sys/endian.h> | |
49 #define B2N_16(x) x = swap16(x) | |
50 #define B2N_32(x) x = swap32(x) | |
51 #define B2N_64(x) x = swap64(x) | |
52 | |
7033 | 53 #elif defined(ARCH_X86) |
54 inline static unsigned short bswap_16(unsigned short x) | |
55 { | |
56 __asm("xchgb %b0,%h0" : | |
57 "=q" (x) : | |
58 "0" (x)); | |
59 return x; | |
60 } | |
61 #define B2N_16(x) x = bswap_16(x) | |
62 | |
63 inline static unsigned int bswap_32(unsigned int x) | |
64 { | |
65 __asm( | |
66 #if __CPU__ > 386 | |
67 "bswap %0": | |
68 "=r" (x) : | |
69 #else | |
70 "xchgb %b0,%h0\n" | |
71 " rorl $16,%0\n" | |
72 " xchgb %b0,%h0": | |
73 "=q" (x) : | |
74 #endif | |
75 "0" (x)); | |
76 return x; | |
77 } | |
78 #define B2N_32(x) x = bswap_32(x) | |
79 | |
80 inline static unsigned long long int bswap_64(unsigned long long int x) | |
81 { | |
82 register union { __extension__ uint64_t __ll; | |
83 uint32_t __l[2]; } __x; | |
84 asm("xchgl %0,%1": | |
85 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
86 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
87 return __x.__ll; | |
88 } | |
89 #define B2N_64(x) x = bswap_64(x) | |
90 | |
7029 | 91 /* This is a slow but portable implementation, it has multiple evaluation |
92 * problems so beware. | |
93 * FreeBSD and Solaris don't have <byteswap.h> or any other such | |
94 * functionality! | |
95 */ | |
96 | |
7033 | 97 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) |
7029 | 98 #define B2N_16(x) \ |
99 x = ((((x) & 0xff00) >> 8) | \ | |
100 (((x) & 0x00ff) << 8)) | |
101 #define B2N_32(x) \ | |
102 x = ((((x) & 0xff000000) >> 24) | \ | |
103 (((x) & 0x00ff0000) >> 8) | \ | |
104 (((x) & 0x0000ff00) << 8) | \ | |
105 (((x) & 0x000000ff) << 24)) | |
106 #define B2N_64(x) \ | |
107 x = ((((x) & 0xff00000000000000) >> 56) | \ | |
108 (((x) & 0x00ff000000000000) >> 40) | \ | |
109 (((x) & 0x0000ff0000000000) >> 24) | \ | |
110 (((x) & 0x000000ff00000000) >> 8) | \ | |
111 (((x) & 0x00000000ff000000) << 8) | \ | |
112 (((x) & 0x0000000000ff0000) << 24) | \ | |
113 (((x) & 0x000000000000ff00) << 40) | \ | |
114 (((x) & 0x00000000000000ff) << 56)) | |
115 | |
116 #else | |
117 | |
118 /* If there isn't a header provided with your system with this functionality | |
119 * add the relevant || define( ) to the portable implementation above. | |
120 */ | |
121 #error "You need to add endian swap macros for you're system" | |
122 | |
123 #endif | |
124 | |
125 #endif /* WORDS_BIGENDIAN */ | |
126 | |
127 #endif /* BSWAP_H_INCLUDED */ |