Mercurial > mplayer.hg
annotate bswap.h @ 14740:fa2103220331
fix sync tag after update by Reynaldo
author | gabrov |
---|---|
date | Sun, 20 Feb 2005 09:45:10 +0000 |
parents | 821f464b4d90 |
children | 28b8fc8278e0 |
rev | line source |
---|---|
1423 | 1 #ifndef __BSWAP_H__ |
2 #define __BSWAP_H__ | |
3 | |
4 #ifdef HAVE_BYTESWAP_H | |
5 #include <byteswap.h> | |
6 #else | |
7 | |
8 #include <inttypes.h> | |
9 | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
10 #ifdef ARCH_X86_64 |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
11 # define LEGACY_REGS "=Q" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
12 #else |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
13 # define LEGACY_REGS "=q" |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
14 #endif |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
15 |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
16 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
17 static inline uint16_t ByteSwap16(uint16_t x) |
1423 | 18 { |
19 __asm("xchgb %b0,%h0" : | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
20 LEGACY_REGS (x) : |
1423 | 21 "0" (x)); |
22 return x; | |
23 } | |
24 #define bswap_16(x) ByteSwap16(x) | |
25 | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
26 static inline uint32_t ByteSwap32(uint32_t x) |
1423 | 27 { |
28 #if __CPU__ > 386 | |
29 __asm("bswap %0": | |
30 "=r" (x) : | |
31 #else | |
32 __asm("xchgb %b0,%h0\n" | |
33 " rorl $16,%0\n" | |
34 " xchgb %b0,%h0": | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
35 LEGACY_REGS (x) : |
1423 | 36 #endif |
37 "0" (x)); | |
38 return x; | |
39 } | |
40 #define bswap_32(x) ByteSwap32(x) | |
41 | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
42 static inline uint64_t ByteSwap64(uint64_t x) |
1423 | 43 { |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
44 #ifdef ARCH_X86_64 |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
45 __asm("bswap %0": |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
46 "=r" (x) : |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
47 "0" (x)); |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
48 return x; |
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
49 #else |
10481 | 50 register union { __extension__ uint64_t __ll; |
51 uint32_t __l[2]; } __x; | |
1423 | 52 asm("xchgl %0,%1": |
53 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
54 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
55 return __x.__ll; | |
13720
821f464b4d90
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64
aurel
parents:
10481
diff
changeset
|
56 #endif |
1423 | 57 } |
58 #define bswap_64(x) ByteSwap64(x) | |
59 | |
10481 | 60 #elif defined(ARCH_SH4) |
61 | |
62 static inline uint16_t ByteSwap16(uint16_t x) { | |
63 __asm__("swap.b %0,%0":"=r"(x):"0"(x)); | |
64 return x; | |
65 } | |
66 | |
67 static inline uint32_t ByteSwap32(uint32_t x) { | |
68 __asm__( | |
69 "swap.b %0,%0\n" | |
70 "swap.w %0,%0\n" | |
71 "swap.b %0,%0\n" | |
72 :"=r"(x):"0"(x)); | |
73 return x; | |
74 } | |
75 | |
76 #define bswap_16(x) ByteSwap16(x) | |
77 #define bswap_32(x) ByteSwap32(x) | |
78 | |
79 static inline uint64_t ByteSwap64(uint64_t x) | |
80 { | |
81 union { | |
82 uint64_t ll; | |
83 struct { | |
84 uint32_t l,h; | |
85 } l; | |
86 } r; | |
87 r.l.l = bswap_32 (x); | |
88 r.l.h = bswap_32 (x>>32); | |
89 return r.ll; | |
90 } | |
91 #define bswap_64(x) ByteSwap64(x) | |
92 | |
1423 | 93 #else |
94 | |
95 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | |
96 | |
97 | |
98 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
99 #define bswap_32(x) \ | |
100 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
101 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
102 | |
10481 | 103 static inline uint64_t ByteSwap64(uint64_t x) |
104 { | |
105 union { | |
106 uint64_t ll; | |
107 uint32_t l[2]; | |
108 } w, r; | |
109 w.ll = x; | |
110 r.l[0] = bswap_32 (w.l[1]); | |
111 r.l[1] = bswap_32 (w.l[0]); | |
112 return r.ll; | |
113 } | |
114 #define bswap_64(x) ByteSwap64(x) | |
115 | |
1423 | 116 #endif /* !ARCH_X86 */ |
117 | |
118 #endif /* !HAVE_BYTESWAP_H */ | |
119 | |
120 // be2me ... BigEndian to MachineEndian | |
121 // le2me ... LittleEndian to MachineEndian | |
122 | |
123 #ifdef WORDS_BIGENDIAN | |
124 #define be2me_16(x) (x) | |
125 #define be2me_32(x) (x) | |
126 #define be2me_64(x) (x) | |
127 #define le2me_16(x) bswap_16(x) | |
128 #define le2me_32(x) bswap_32(x) | |
129 #define le2me_64(x) bswap_64(x) | |
130 #else | |
131 #define be2me_16(x) bswap_16(x) | |
132 #define be2me_32(x) bswap_32(x) | |
133 #define be2me_64(x) bswap_64(x) | |
134 #define le2me_16(x) (x) | |
135 #define le2me_32(x) (x) | |
136 #define le2me_64(x) (x) | |
137 #endif | |
138 | |
10481 | 139 #endif /* __BSWAP_H__ */ |