annotate bswap.h @ 12648:c12639f67b24

Real codecs and Mac OS X, don't recommend installing Real player.
author diego
date Fri, 25 Jun 2004 16:53:48 +0000
parents 1911eb291dfb
children 821f464b4d90
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_BYTESWAP_H
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
5 #include <byteswap.h>
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
6 #else
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 #include <inttypes.h>
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
9
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
10 #ifdef ARCH_X86
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
11 static inline unsigned short ByteSwap16(unsigned short x)
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
12 {
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
13 __asm("xchgb %b0,%h0" :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
14 "=q" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
15 "0" (x));
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
16 return x;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
17 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
18 #define bswap_16(x) ByteSwap16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
19
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
20 static inline unsigned int ByteSwap32(unsigned int x)
1423
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 #if __CPU__ > 386
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
23 __asm("bswap %0":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
24 "=r" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
25 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
26 __asm("xchgb %b0,%h0\n"
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
27 " rorl $16,%0\n"
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
28 " xchgb %b0,%h0":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
29 "=q" (x) :
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
30 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
31 "0" (x));
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
32 return x;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
33 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
34 #define bswap_32(x) ByteSwap32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
35
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
36 static inline unsigned long long int ByteSwap64(unsigned long long int x)
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
37 {
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
38 register union { __extension__ uint64_t __ll;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
39 uint32_t __l[2]; } __x;
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
40 asm("xchgl %0,%1":
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
41 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
42 "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
43 return __x.__ll;
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
44 }
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
45 #define bswap_64(x) ByteSwap64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
46
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
47 #elif defined(ARCH_SH4)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
48
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
49 static inline uint16_t ByteSwap16(uint16_t x) {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
50 __asm__("swap.b %0,%0":"=r"(x):"0"(x));
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
51 return x;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
52 }
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
53
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
54 static inline uint32_t ByteSwap32(uint32_t x) {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
55 __asm__(
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
56 "swap.b %0,%0\n"
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
57 "swap.w %0,%0\n"
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
58 "swap.b %0,%0\n"
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
59 :"=r"(x):"0"(x));
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
60 return x;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
61 }
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
62
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
63 #define bswap_16(x) ByteSwap16(x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
64 #define bswap_32(x) ByteSwap32(x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
65
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
66 static inline uint64_t ByteSwap64(uint64_t x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
67 {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
68 union {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
69 uint64_t ll;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
70 struct {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
71 uint32_t l,h;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
72 } l;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
73 } r;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
74 r.l.l = bswap_32 (x);
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
75 r.l.h = bswap_32 (x>>32);
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
76 return r.ll;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
77 }
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
78 #define bswap_64(x) ByteSwap64(x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
79
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
80 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
81
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
82 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
83
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
84
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
85 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
86 #define bswap_32(x) \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
87 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
88 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
89
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
90 static inline uint64_t ByteSwap64(uint64_t x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
91 {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
92 union {
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
93 uint64_t ll;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
94 uint32_t l[2];
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
95 } w, r;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
96 w.ll = x;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
97 r.l[0] = bswap_32 (w.l[1]);
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
98 r.l[1] = bswap_32 (w.l[0]);
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
99 return r.ll;
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
100 }
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
101 #define bswap_64(x) ByteSwap64(x)
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
102
1423
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
103 #endif /* !ARCH_X86 */
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
104
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
105 #endif /* !HAVE_BYTESWAP_H */
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
106
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
107 // be2me ... BigEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
108 // le2me ... LittleEndian to MachineEndian
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
109
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
110 #ifdef WORDS_BIGENDIAN
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
111 #define be2me_16(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
112 #define be2me_32(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
113 #define be2me_64(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
114 #define le2me_16(x) bswap_16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
115 #define le2me_32(x) bswap_32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
116 #define le2me_64(x) bswap_64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
117 #else
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
118 #define be2me_16(x) bswap_16(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
119 #define be2me_32(x) bswap_32(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
120 #define be2me_64(x) bswap_64(x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
121 #define le2me_16(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
122 #define le2me_32(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
123 #define le2me_64(x) (x)
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
124 #endif
3a347b949c5d Furter compatibility with new ffmpeg stuff.
nick
parents: 1309
diff changeset
125
10481
1911eb291dfb sync with libavcodec (sh4 optim)
alex
parents: 6922
diff changeset
126 #endif /* __BSWAP_H__ */