annotate bswap.h @ 8197:b31caec933e9

OSD menus initial version
author albeu
date Thu, 14 Nov 2002 23:47:11 +0000
parents adaa83002b22
children 1911eb291dfb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
1 #ifndef __BSWAP_H__
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
2 #define __BSWAP_H__
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
3
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
4 #ifdef HAVE_CONFIG_H
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
5 #include "config.h"
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
6 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
7
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
8 #ifdef HAVE_BYTESWAP_H
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
9 #include <byteswap.h>
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
10 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
11
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
12 #include <inttypes.h>
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
13
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
14 #ifdef ARCH_X86
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
15 inline static unsigned short ByteSwap16(unsigned short x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
16 {
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
17 __asm("xchgb %b0,%h0" :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
18 "=q" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
19 "0" (x));
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
20 return x;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
21 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
22 #define bswap_16(x) ByteSwap16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
23
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
24 inline static unsigned int ByteSwap32(unsigned int x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
25 {
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
26 #if __CPU__ > 386
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
27 __asm("bswap %0":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
28 "=r" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
29 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
30 __asm("xchgb %b0,%h0\n"
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
31 " rorl $16,%0\n"
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
32 " xchgb %b0,%h0":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
33 "=q" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
34 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
35 "0" (x));
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
36 return x;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
37 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
38 #define bswap_32(x) ByteSwap32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
39
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
40 inline static unsigned long long int ByteSwap64(unsigned long long int x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
41 {
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
42 register union { __extension__ unsigned long long int __ll;
6922
adaa83002b22 Bswap fixes for 64bit cpus, thx to Falk Hueffner for the hint.
atmos4
parents: 1423
diff changeset
43 unsigned int __l[2]; } __x;
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
44 asm("xchgl %0,%1":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
45 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
46 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
47 return __x.__ll;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
48 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
49 #define bswap_64(x) ByteSwap64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
50
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
51 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
52
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
53 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
54
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
55
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
56 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
57 #define bswap_32(x) \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
58 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
59 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
60
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
61 #define bswap_64(x) \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
62 (__extension__ \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
63 ({ union { __extension__ unsigned long long int __ll; \
6922
adaa83002b22 Bswap fixes for 64bit cpus, thx to Falk Hueffner for the hint.
atmos4
parents: 1423
diff changeset
64 unsigned int __l[2]; } __w, __r; \
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
65 __w.__ll = (x); \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
66 __r.__l[0] = bswap_32 (__w.__l[1]); \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
67 __r.__l[1] = bswap_32 (__w.__l[0]); \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
68 __r.__ll; }))
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
69 #endif /* !ARCH_X86 */
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
70
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
71 #endif /* !HAVE_BYTESWAP_H */
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
72
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
73 // be2me ... BigEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
74 // le2me ... LittleEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
75
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
76 #ifdef WORDS_BIGENDIAN
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
77 #define be2me_16(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
78 #define be2me_32(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
79 #define be2me_64(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
80 #define le2me_16(x) bswap_16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
81 #define le2me_32(x) bswap_32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
82 #define le2me_64(x) bswap_64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
83 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
84 #define be2me_16(x) bswap_16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
85 #define be2me_32(x) bswap_32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
86 #define be2me_64(x) bswap_64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
87 #define le2me_16(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
88 #define le2me_32(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
89 #define le2me_64(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
90 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
91
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
92 #endif