Mercurial > libavcodec.hg
annotate bswap.h @ 1838:8cdbb74c2f4b libavcodec
10l (vdpart fix)
author | michael |
---|---|
date | Thu, 26 Feb 2004 19:11:21 +0000 |
parents | 1831d86117a3 |
children | 15cfba1b97b5 |
rev | line source |
---|---|
1106 | 1 /** |
2 * @file bswap.h | |
3 * byte swap. | |
4 */ | |
5 | |
424 | 6 #ifndef __BSWAP_H__ |
7 #define __BSWAP_H__ | |
8 | |
9 #ifdef HAVE_BYTESWAP_H | |
10 #include <byteswap.h> | |
11 #else | |
12 | |
13 #ifdef ARCH_X86 | |
1378 | 14 static inline unsigned short ByteSwap16(unsigned short x) |
424 | 15 { |
16 __asm("xchgb %b0,%h0" : | |
17 "=q" (x) : | |
18 "0" (x)); | |
19 return x; | |
20 } | |
21 #define bswap_16(x) ByteSwap16(x) | |
22 | |
1378 | 23 static inline unsigned int ByteSwap32(unsigned int x) |
424 | 24 { |
25 #if __CPU__ > 386 | |
26 __asm("bswap %0": | |
27 "=r" (x) : | |
28 #else | |
29 __asm("xchgb %b0,%h0\n" | |
30 " rorl $16,%0\n" | |
31 " xchgb %b0,%h0": | |
32 "=q" (x) : | |
33 #endif | |
34 "0" (x)); | |
35 return x; | |
36 } | |
37 #define bswap_32(x) ByteSwap32(x) | |
38 | |
1378 | 39 static inline unsigned long long int ByteSwap64(unsigned long long int x) |
424 | 40 { |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
41 register union { __extension__ uint64_t __ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
42 uint32_t __l[2]; } __x; |
424 | 43 asm("xchgl %0,%1": |
44 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
45 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32)))); | |
46 return __x.__ll; | |
47 } | |
48 #define bswap_64(x) ByteSwap64(x) | |
49 | |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
50 #elif defined(ARCH_SH4) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
51 |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
52 static inline uint16_t ByteSwap16(uint16_t x) { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
53 __asm__("swap.b %0,%0":"=r"(x):"0"(x)); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
54 return x; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
55 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
56 |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
57 static inline uint32_t ByteSwap32(uint32_t x) { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
58 __asm__( |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
59 "swap.b %0,%0\n" |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
60 "swap.w %0,%0\n" |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
61 "swap.b %0,%0\n" |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
62 :"=r"(x):"0"(x)); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
63 return x; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
64 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
65 |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
66 #define bswap_16(x) ByteSwap16(x) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
67 #define bswap_32(x) ByteSwap32(x) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
68 |
1378 | 69 static inline uint64_t ByteSwap64(uint64_t x) |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
70 { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
71 union { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
72 uint64_t ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
73 struct { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
74 uint32_t l,h; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
75 } l; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
76 } r; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
77 r.l.l = bswap_32 (x); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
78 r.l.h = bswap_32 (x>>32); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
79 return r.ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
80 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
81 #define bswap_64(x) ByteSwap64(x) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
82 |
424 | 83 #else |
84 | |
85 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | |
86 | |
87 | |
88 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
89 #define bswap_32(x) \ | |
90 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
91 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
92 | |
1378 | 93 static inline uint64_t ByteSwap64(uint64_t x) |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
94 { |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
95 union { |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
96 uint64_t ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
97 uint32_t l[2]; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
98 } w, r; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
99 w.ll = x; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
100 r.l[0] = bswap_32 (w.l[1]); |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
101 r.l[1] = bswap_32 (w.l[0]); |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
102 return r.ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
103 } |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
104 #define bswap_64(x) ByteSwap64(x) |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
105 |
424 | 106 #endif /* !ARCH_X86 */ |
107 | |
108 #endif /* !HAVE_BYTESWAP_H */ | |
109 | |
110 // be2me ... BigEndian to MachineEndian | |
111 // le2me ... LittleEndian to MachineEndian | |
112 | |
113 #ifdef WORDS_BIGENDIAN | |
114 #define be2me_16(x) (x) | |
115 #define be2me_32(x) (x) | |
116 #define be2me_64(x) (x) | |
117 #define le2me_16(x) bswap_16(x) | |
118 #define le2me_32(x) bswap_32(x) | |
119 #define le2me_64(x) bswap_64(x) | |
120 #else | |
121 #define be2me_16(x) bswap_16(x) | |
122 #define be2me_32(x) bswap_32(x) | |
123 #define be2me_64(x) bswap_64(x) | |
124 #define le2me_16(x) (x) | |
125 #define le2me_32(x) (x) | |
126 #define le2me_64(x) (x) | |
127 #endif | |
128 | |
129 #endif /* __BSWAP_H__ */ |