Diffstat (limited to 'noncore/multimedia/opieplayer2') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/multimedia/opieplayer2/bswap.h | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/noncore/multimedia/opieplayer2/bswap.h b/noncore/multimedia/opieplayer2/bswap.h new file mode 100644 index 0000000..fc159fb --- a/dev/null +++ b/noncore/multimedia/opieplayer2/bswap.h | |||
@@ -0,0 +1,181 @@ | |||
1 | #ifndef __BSWAP_H__ | ||
2 | #define __BSWAP_H__ | ||
3 | |||
4 | #ifdef HAVE_BYTESWAP_H | ||
5 | #include <byteswap.h> | ||
6 | #else | ||
7 | #include <inttypes.h> | ||
8 | |||
9 | |||
10 | #ifdef ARCH_X86 | ||
11 | inline static unsigned short ByteSwap16(unsigned short x) | ||
12 | { | ||
13 | __asm("xchgb %b0,%h0": | ||
14 | "=q" (x): | ||
15 | "0" (x)); | ||
16 | return x; | ||
17 | } | ||
18 | #define bswap_16(x) ByteSwap16(x) | ||
19 | |||
20 | inline static unsigned int ByteSwap32(unsigned int x) | ||
21 | { | ||
22 | #if __CPU__ > 386 | ||
23 | __asm("bswap%0": | ||
24 | "=r" (x) : | ||
25 | #else | ||
26 | __asm("xchgb%b0,%h0\n" | ||
27 | " rorl$16,%0\n" | ||
28 | " xchgb%b0,%h0": | ||
29 | "=q" (x) : | ||
30 | #endif | ||
31 | "0" (x)); | ||
32 | return x; | ||
33 | } | ||
34 | #define bswap_32(x) ByteSwap32(x) | ||
35 | |||
36 | inline static unsigned long long int ByteSwap64(unsigned long long int x) | ||
37 | { | ||
38 | register union { __extension__ unsigned long long int __ll; | ||
39 | unsigned long int __l[2]; } __x; | ||
40 | asm("xchgl%0,%1": | ||
41 | "=r"(__x.__l[0]),"=r"(__x.__l[1]): | ||
42 | "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | ||
43 | return __x.__ll; | ||
44 | } | ||
45 | #define bswap_64(x) ByteSwap64(x) | ||
46 | |||
47 | #else | ||
48 | |||
49 | #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | ||
50 | |||
51 | #define bswap_32(x) \ | ||
52 | ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | ||
53 | (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | ||
54 | |||
55 | #ifdef __GNUC__ | ||
56 | /* code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. */ | ||
57 | #define bswap_64(x) \ | ||
58 | (__extension__ \ | ||
59 | ({ union { __extension__ unsigned long long int __ll;\ | ||
60 | unsigned long int __l[2]; } __w, __r; \ | ||
61 | __w.__ll = (x); \ | ||
62 | __r.__l[0] = bswap_32 (__w.__l[1]); \ | ||
63 | __r.__l[1] = bswap_32 (__w.__l[0]); \ | ||
64 | __r.__ll; })) | ||
65 | #else | ||
66 | #define bswap_64(x) \ | ||
67 | ((((x) & 0xff00000000000000LL) >> 56) | \ | ||
68 | (((x) & 0x00ff000000000000LL) >> 40) | \ | ||
69 | (((x) & 0x0000ff0000000000LL) >> 24) | \ | ||
70 | (((x) & 0x000000ff00000000LL) >> 8) | \ | ||
71 | (((x) & 0x00000000ff000000LL) << 8) | \ | ||
72 | (((x) & 0x0000000000ff0000LL) << 24) | \ | ||
73 | (((x) & 0x000000000000ff00LL) << 40) | \ | ||
74 | (((x) & 0x00000000000000ffLL) << 56)) | ||
75 | #endif /* !__GNUC__ */ | ||
76 | |||
77 | #endif/* !ARCH_X86 */ | ||
78 | |||
79 | #endif/* !HAVE_BYTESWAP_H */ | ||
80 | |||
81 | /* be2me ... BigEndian to MachineEndian */ | ||
82 | /* le2me ... LittleEndian to MachineEndian */ | ||
83 | |||
84 | #ifdef WORDS_BIGENDIAN | ||
85 | #define be2me_16(x) (x) | ||
86 | #define be2me_32(x) (x) | ||
87 | #define be2me_64(x) (x) | ||
88 | #define le2me_16(x) bswap_16(x) | ||
89 | #define le2me_32(x) bswap_32(x) | ||
90 | #define le2me_64(x) bswap_64(x) | ||
91 | #else | ||
92 | #define be2me_16(x) bswap_16(x) | ||
93 | #define be2me_32(x) bswap_32(x) | ||
94 | #define be2me_64(x) bswap_64(x) | ||
95 | #define le2me_16(x) (x) | ||
96 | #define le2me_32(x) (x) | ||
97 | #define le2me_64(x) (x) | ||
98 | #endif | ||
99 | |||
100 | #define ABE_16(x) (be2me_16(*(uint16_t*)(x))) | ||
101 | #define ABE_32(x) (be2me_32(*(uint32_t*)(x))) | ||
102 | #define ABE_64(x) (be2me_64(*(uint64_t*)(x))) | ||
103 | #define ALE_16(x) (le2me_16(*(uint16_t*)(x))) | ||
104 | #define ALE_32(x) (le2me_32(*(uint32_t*)(x))) | ||
105 | #define ALE_64(x) (le2me_64(*(uint64_t*)(x))) | ||
106 | |||
107 | #ifdef ARCH_X86 | ||
108 | |||
109 | #define BE_16(x) ABE_16(x) | ||
110 | #define BE_32(x) ABE_32(x) | ||
111 | #define BE_64(x) ABE_64(x) | ||
112 | #define LE_16(x) ALE_16(x) | ||
113 | #define LE_32(x) ALE_32(x) | ||
114 | #define LE_64(x) ALE_64(x) | ||
115 | |||
116 | #else | ||
117 | |||
118 | #define BE_16(x) ((((uint8_t*)(x))[0] << 8) | ((uint8_t*)(x))[1]) | ||
119 | #define BE_32(x) ((((uint8_t*)(x))[0] << 24) | \ | ||
120 | (((uint8_t*)(x))[1] << 16) | \ | ||
121 | (((uint8_t*)(x))[2] << 8) | \ | ||
122 | ((uint8_t*)(x))[3]) | ||
123 | #define BE_64(x) ((uint64_t)(((uint8_t*)(x))[0] << 56) | \ | ||
124 | (uint64_t)(((uint8_t*)(x))[1] << 48) | \ | ||
125 | (uint64_t)(((uint8_t*)(x))[2] << 40) | \ | ||
126 | (uint64_t)(((uint8_t*)(x))[3] << 32) | \ | ||
127 | (uint64_t)(((uint8_t*)(x))[4] << 24) | \ | ||
128 | (uint64_t)(((uint8_t*)(x))[5] << 16) | \ | ||
129 | (uint64_t)(((uint8_t*)(x))[6] << 8) | \ | ||
130 | (uint64_t)((uint8_t*)(x))[7]) | ||
131 | #define LE_16(x) ((((uint8_t*)(x))[1] << 8) | ((uint8_t*)(x))[0]) | ||
132 | #define LE_32(x) ((((uint8_t*)(x))[3] << 24) | \ | ||
133 | (((uint8_t*)(x))[2] << 16) | \ | ||
134 | (((uint8_t*)(x))[1] << 8) | \ | ||
135 | ((uint8_t*)(x))[0]) | ||
136 | #define LE_64(x) ((uint64_t)(((uint8_t*)(x))[7] << 56) | \ | ||
137 | (uint64_t)(((uint8_t*)(x))[6] << 48) | \ | ||
138 | (uint64_t)(((uint8_t*)(x))[5] << 40) | \ | ||
139 | (uint64_t)(((uint8_t*)(x))[4] << 32) | \ | ||
140 | (uint64_t)(((uint8_t*)(x))[3] << 24) | \ | ||
141 | (uint64_t)(((uint8_t*)(x))[2] << 16) | \ | ||
142 | (uint64_t)(((uint8_t*)(x))[1] << 8) | \ | ||
143 | (uint64_t)((uint8_t*)(x))[0]) | ||
144 | |||
145 | #endif /* !ARCH_X86 */ | ||
146 | |||
147 | #ifdef WORDS_BIGENDIAN | ||
148 | #define ME_16(x) BE_16(x) | ||
149 | #define ME_32(x) BE_32(x) | ||
150 | #define ME_64(x) BE_64(x) | ||
151 | #define AME_16(x) ABE_16(x) | ||
152 | #define AME_32(x) ABE_32(x) | ||
153 | #define AME_64(x) ABE_64(x) | ||
154 | #else | ||
155 | #define ME_16(x) LE_16(x) | ||
156 | #define ME_32(x) LE_32(x) | ||
157 | #define ME_64(x) LE_64(x) | ||
158 | #define AME_16(x) ALE_16(x) | ||
159 | #define AME_32(x) ALE_32(x) | ||
160 | #define AME_64(x) ALE_64(x) | ||
161 | #endif | ||
162 | |||
163 | #define BE_FOURCC( ch0, ch1, ch2, ch3 ) \ | ||
164 | ( (uint32_t)(unsigned char)(ch3) | \ | ||
165 | ( (uint32_t)(unsigned char)(ch2) << 8 ) | \ | ||
166 | ( (uint32_t)(unsigned char)(ch1) << 16 ) | \ | ||
167 | ( (uint32_t)(unsigned char)(ch0) << 24 ) ) | ||
168 | |||
169 | #define LE_FOURCC( ch0, ch1, ch2, ch3 ) \ | ||
170 | ( (uint32_t)(unsigned char)(ch0) | \ | ||
171 | ( (uint32_t)(unsigned char)(ch1) << 8 ) | \ | ||
172 | ( (uint32_t)(unsigned char)(ch2) << 16 ) | \ | ||
173 | ( (uint32_t)(unsigned char)(ch3) << 24 ) ) | ||
174 | |||
175 | #ifdef WORDS_BIGENDIAN | ||
176 | #define ME_FOURCC BE_FOURCC | ||
177 | #else | ||
178 | #define ME_FOURCC LE_FOURCC | ||
179 | #endif | ||
180 | |||
181 | #endif | ||