Mercurial > libavcodec.hg
annotate bswap.h @ 2672:be04f746d1fe libavcodec
arm alignment fix
author | michael |
---|---|
date | Thu, 12 May 2005 18:54:03 +0000 |
parents | e26dc8cf7069 |
children | aeea63c97878 |
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 | |
2293
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
13 #ifdef ARCH_X86_64 |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
14 # define LEGACY_REGS "=Q" |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
15 #else |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
16 # define LEGACY_REGS "=q" |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
17 #endif |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
18 |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
19 #if defined(ARCH_X86) || defined(ARCH_X86_64) |
2659 | 20 static always_inline uint16_t bswap_16(uint16_t x) |
424 | 21 { |
2660 | 22 __asm("rorw $8, %0" : |
2293
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
23 LEGACY_REGS (x) : |
424 | 24 "0" (x)); |
25 return x; | |
26 } | |
27 | |
2659 | 28 static always_inline uint32_t bswap_32(uint32_t x) |
424 | 29 { |
30 #if __CPU__ > 386 | |
31 __asm("bswap %0": | |
32 "=r" (x) : | |
33 #else | |
34 __asm("xchgb %b0,%h0\n" | |
35 " rorl $16,%0\n" | |
36 " xchgb %b0,%h0": | |
2293
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
37 LEGACY_REGS (x) : |
424 | 38 #endif |
39 "0" (x)); | |
40 return x; | |
41 } | |
42 | |
2659 | 43 static inline uint64_t bswap_64(uint64_t x) |
424 | 44 { |
2293
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
45 #ifdef ARCH_X86_64 |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
46 __asm("bswap %0": |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
47 "=r" (x) : |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
48 "0" (x)); |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
49 return x; |
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
50 #else |
2660 | 51 union { |
52 uint64_t ll; | |
53 struct { | |
54 uint32_t l,h; | |
55 } l; | |
56 } r; | |
57 r.l.l = bswap_32 (x); | |
58 r.l.h = bswap_32 (x>>32); | |
59 return r.ll; | |
2293
15cfba1b97b5
adapting existing mmx/mmx2/sse/3dnow optimizations so they work on x86_64 patch by (Aurelien Jacobs <aurel at gnuage dot org>)
michael
parents:
1378
diff
changeset
|
60 #endif |
424 | 61 } |
62 | |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
63 #elif defined(ARCH_SH4) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
64 |
2659 | 65 static always_inline uint16_t bswap_16(uint16_t x) { |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
66 __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
|
67 return x; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
68 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
69 |
2659 | 70 static always_inline uint32_t bswap_32(uint32_t x) { |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
71 __asm__( |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
72 "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
|
73 "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
|
74 "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
|
75 :"=r"(x):"0"(x)); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
76 return x; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
77 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
78 |
2659 | 79 static inline uint64_t bswap_64(uint64_t x) |
1259
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 union { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
82 uint64_t ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
83 struct { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
84 uint32_t l,h; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
85 } l; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
86 } r; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
87 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
|
88 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
|
89 return r.ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
90 } |
424 | 91 #else |
92 | |
2659 | 93 static always_inline uint16_t bswap_16(uint16_t x){ |
94 return (x>>8) | (x<<8); | |
95 } | |
424 | 96 |
2659 | 97 static always_inline uint32_t bswap_32(uint32_t x){ |
2660 | 98 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF); |
99 return (x>>16) | (x<<16); | |
2659 | 100 } |
424 | 101 |
2659 | 102 static inline uint64_t bswap_64(uint64_t x) |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
103 { |
2660 | 104 #if 0 |
105 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL); | |
106 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL); | |
107 return (x>>32) | (x<<32); | |
108 #else | |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
109 union { |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
110 uint64_t ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
111 uint32_t l[2]; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
112 } w, r; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
113 w.ll = x; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
114 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
|
115 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
|
116 return r.ll; |
2660 | 117 #endif |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
118 } |
424 | 119 #endif /* !ARCH_X86 */ |
120 | |
121 #endif /* !HAVE_BYTESWAP_H */ | |
122 | |
123 // be2me ... BigEndian to MachineEndian | |
124 // le2me ... LittleEndian to MachineEndian | |
125 | |
126 #ifdef WORDS_BIGENDIAN | |
127 #define be2me_16(x) (x) | |
128 #define be2me_32(x) (x) | |
129 #define be2me_64(x) (x) | |
130 #define le2me_16(x) bswap_16(x) | |
131 #define le2me_32(x) bswap_32(x) | |
132 #define le2me_64(x) bswap_64(x) | |
133 #else | |
134 #define be2me_16(x) bswap_16(x) | |
135 #define be2me_32(x) bswap_32(x) | |
136 #define be2me_64(x) bswap_64(x) | |
137 #define le2me_16(x) (x) | |
138 #define le2me_32(x) (x) | |
139 #define le2me_64(x) (x) | |
140 #endif | |
141 | |
142 #endif /* __BSWAP_H__ */ |