comparison libmpdvdkit2/bswap.h @ 15874:483e955893b8

update libdvdread to v0.9.4
author aurel
date Thu, 30 Jun 2005 22:48:26 +0000
parents 3758536dcef3
children 0783dd397f74
comparison
equal deleted inserted replaced
15873:276da0bb6207 15874:483e955893b8
30 #define B2N_32(x) (void)(x) 30 #define B2N_32(x) (void)(x)
31 #define B2N_64(x) (void)(x) 31 #define B2N_64(x) (void)(x)
32 32
33 #else 33 #else
34 34
35 /* For __FreeBSD_version */
36 #if defined(HAVE_SYS_PARAM_H)
37 #include <sys/param.h>
38 #endif
39
35 #if defined(__linux__) 40 #if defined(__linux__)
36 #include <byteswap.h> 41 #include <byteswap.h>
37 #define B2N_16(x) x = bswap_16(x) 42 #define B2N_16(x) x = bswap_16(x)
38 #define B2N_32(x) x = bswap_32(x) 43 #define B2N_32(x) x = bswap_32(x)
39 #define B2N_64(x) x = bswap_64(x) 44 #define B2N_64(x) x = bswap_64(x)
47 #elif defined(__OpenBSD__) 52 #elif defined(__OpenBSD__)
48 #include <sys/endian.h> 53 #include <sys/endian.h>
49 #define B2N_16(x) x = swap16(x) 54 #define B2N_16(x) x = swap16(x)
50 #define B2N_32(x) x = swap32(x) 55 #define B2N_32(x) x = swap32(x)
51 #define B2N_64(x) x = swap64(x) 56 #define B2N_64(x) x = swap64(x)
57
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)
52 69
53 #elif defined(ARCH_X86) 70 #elif defined(ARCH_X86)
54 inline static unsigned short bswap_16(unsigned short x) 71 inline static unsigned short bswap_16(unsigned short x)
55 { 72 {
56 __asm("xchgb %b0,%h0" : 73 __asm("xchgb %b0,%h0" :
86 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); 103 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
87 return __x.__ll; 104 return __x.__ll;
88 } 105 }
89 #define B2N_64(x) x = bswap_64(x) 106 #define B2N_64(x) x = bswap_64(x)
90 107
91 #elif defined(__DragonFly__)
92 #include <sys/endian.h>
93 #define B2N_16(x) x = be16toh(x)
94 #define B2N_32(x) x = be32toh(x)
95 #define B2N_64(x) x = be64toh(x)
96
97 /* This is a slow but portable implementation, it has multiple evaluation 108 /* This is a slow but portable implementation, it has multiple evaluation
98 * problems so beware. 109 * problems so beware.
99 * FreeBSD and Solaris don't have <byteswap.h> or any other such 110 * Old FreeBSD's and Solaris don't have <byteswap.h> or any other such
100 * functionality! 111 * functionality!
101 */ 112 */
113
102 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__) 114 #elif defined(__FreeBSD__) || defined(__sun) || defined(__bsdi__) || defined(__CYGWIN__)
103 #define B2N_16(x) \ 115 #define B2N_16(x) \
104 x = ((((x) & 0xff00) >> 8) | \ 116 x = ((((x) & 0xff00) >> 8) | \
105 (((x) & 0x00ff) << 8)) 117 (((x) & 0x00ff) << 8))
106 #define B2N_32(x) \ 118 #define B2N_32(x) \