annotate bswap.h @ 2672:be04f746d1fe libavcodec

arm alignment fix
author michael
date Thu, 12 May 2005 18:54:03 +0000
parents e26dc8cf7069
children aeea63c97878
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1106
1e39f273ecd6 per file doxy
michaelni
parents: 433
diff changeset
1 /**
1e39f273ecd6 per file doxy
michaelni
parents: 433
diff changeset
2 * @file bswap.h
1e39f273ecd6 per file doxy
michaelni
parents: 433
diff changeset
3 * byte swap.
1e39f273ecd6 per file doxy
michaelni
parents: 433
diff changeset
4 */
1e39f273ecd6 per file doxy
michaelni
parents: 433
diff changeset
5
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
6 #ifndef __BSWAP_H__
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
7 #define __BSWAP_H__
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
8
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
9 #ifdef HAVE_BYTESWAP_H
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
10 #include <byteswap.h>
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
11 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
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
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
20 static always_inline uint16_t bswap_16(uint16_t x)
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
21 {
2660
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
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
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
24 "0" (x));
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
25 return x;
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
26 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
27
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
28 static always_inline uint32_t bswap_32(uint32_t x)
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
29 {
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
30 #if __CPU__ > 386
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
31 __asm("bswap %0":
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
32 "=r" (x) :
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
33 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
34 __asm("xchgb %b0,%h0\n"
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
35 " rorl $16,%0\n"
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
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
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
38 #endif
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
39 "0" (x));
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
40 return x;
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
41 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
42
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
43 static inline uint64_t bswap_64(uint64_t x)
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
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
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
51 union {
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
52 uint64_t ll;
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
53 struct {
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
54 uint32_t l,h;
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
55 } l;
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
56 } r;
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
57 r.l.l = bswap_32 (x);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
58 r.l.h = bswap_32 (x>>32);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
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
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
61 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
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
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
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
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
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
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
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
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
91 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
92
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
93 static always_inline uint16_t bswap_16(uint16_t x){
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
94 return (x>>8) | (x<<8);
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
95 }
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
96
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
97 static always_inline uint32_t bswap_32(uint32_t x){
2660
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
98 x= ((x<<8)&0xFF00FF00) | ((x>>8)&0x00FF00FF);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
99 return (x>>16) | (x<<16);
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
100 }
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
101
2659
4023235edd2e change macros to inline functions
michael
parents: 2293
diff changeset
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
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
104 #if 0
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
105 x= ((x<< 8)&0xFF00FF00FF00FF00ULL) | ((x>> 8)&0x00FF00FF00FF00FFULL);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
106 x= ((x<<16)&0xFFFF0000FFFF0000ULL) | ((x>>16)&0x0000FFFF0000FFFFULL);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
107 return (x>>32) | (x<<32);
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
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
e26dc8cf7069 optimization
michael
parents: 2659
diff changeset
117 #endif
433
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
118 }
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
119 #endif /* !ARCH_X86 */
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
120
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
121 #endif /* !HAVE_BYTESWAP_H */
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
122
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
123 // be2me ... BigEndian to MachineEndian
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
124 // le2me ... LittleEndian to MachineEndian
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
125
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
126 #ifdef WORDS_BIGENDIAN
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
127 #define be2me_16(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
128 #define be2me_32(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
129 #define be2me_64(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
130 #define le2me_16(x) bswap_16(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
131 #define le2me_32(x) bswap_32(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
132 #define le2me_64(x) bswap_64(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
133 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
134 #define be2me_16(x) bswap_16(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
135 #define be2me_32(x) bswap_32(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
136 #define be2me_64(x) bswap_64(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
137 #define le2me_16(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
138 #define le2me_32(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
139 #define le2me_64(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
140 #endif
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
141
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
142 #endif /* __BSWAP_H__ */