Mercurial > libavcodec.hg
annotate bswap.h @ 2659:4023235edd2e libavcodec
change macros to inline functions
remove redundant operations
remove silly 2 layer bswap_XX/ByteSwapXX system
author | michael |
---|---|
date | Tue, 10 May 2005 10:05:44 +0000 |
parents | 15cfba1b97b5 |
children | e26dc8cf7069 |
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 { |
22 __asm("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
|
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 |
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
51 register union { __extension__ uint64_t __ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
52 uint32_t __l[2]; } __x; |
424 | 53 asm("xchgl %0,%1": |
54 "=r"(__x.__l[0]),"=r"(__x.__l[1]): | |
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
|
55 "0"(bswap_32((uint32_t)x)),"1"(bswap_32((uint32_t)(x>>32)))); |
424 | 56 return __x.__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
|
57 #endif |
424 | 58 } |
59 | |
1259
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
60 #elif defined(ARCH_SH4) |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
61 |
2659 | 62 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
|
63 __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
|
64 return x; |
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 |
2659 | 67 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
|
68 __asm__( |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
69 "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
|
70 "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
|
71 "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
|
72 :"=r"(x):"0"(x)); |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
73 return x; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
74 } |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
75 |
2659 | 76 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
|
77 { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
78 union { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
79 uint64_t ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
80 struct { |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
81 uint32_t l,h; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
82 } l; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
83 } r; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
84 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
|
85 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
|
86 return r.ll; |
e8c3884f2c7e
sh4 optimized idct & bswap patch by (BERO <bero at geocities dot co dot jp>)
michaelni
parents:
1106
diff
changeset
|
87 } |
424 | 88 #else |
89 | |
2659 | 90 static always_inline uint16_t bswap_16(uint16_t x){ |
91 return (x>>8) | (x<<8); | |
92 } | |
424 | 93 |
2659 | 94 static always_inline uint32_t bswap_32(uint32_t x){ |
95 return (x >> 24) | ((x & 0x00ff0000) >> 8) | ((x & 0x0000ff00) << 8) | (x << 24); | |
96 } | |
424 | 97 |
2659 | 98 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
|
99 { |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
100 union { |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
101 uint64_t ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
102 uint32_t l[2]; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
103 } w, r; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
104 w.ll = x; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
105 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
|
106 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
|
107 return r.ll; |
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
108 } |
424 | 109 #endif /* !ARCH_X86 */ |
110 | |
111 #endif /* !HAVE_BYTESWAP_H */ | |
112 | |
113 // be2me ... BigEndian to MachineEndian | |
114 // le2me ... LittleEndian to MachineEndian | |
115 | |
116 #ifdef WORDS_BIGENDIAN | |
117 #define be2me_16(x) (x) | |
118 #define be2me_32(x) (x) | |
119 #define be2me_64(x) (x) | |
120 #define le2me_16(x) bswap_16(x) | |
121 #define le2me_32(x) bswap_32(x) | |
122 #define le2me_64(x) bswap_64(x) | |
123 #else | |
124 #define be2me_16(x) bswap_16(x) | |
125 #define be2me_32(x) bswap_32(x) | |
126 #define be2me_64(x) bswap_64(x) | |
127 #define le2me_16(x) (x) | |
128 #define le2me_32(x) (x) | |
129 #define le2me_64(x) (x) | |
130 #endif | |
131 | |
132 #endif /* __BSWAP_H__ */ |