annotate bswap.h @ 1096:5e6e505d8997 libavcodec

field picture decoding support (16x16 MC blocks only as i dont have any samples which use other modes ...)
author michaelni
date Wed, 05 Mar 2003 17:48:19 +0000
parents 133d2867d4b2
children 1e39f273ecd6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
1 #ifndef __BSWAP_H__
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
2 #define __BSWAP_H__
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
3
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
4 #ifdef HAVE_BYTESWAP_H
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
5 #include <byteswap.h>
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
6 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
7
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
8 #ifdef ARCH_X86
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
9 inline static unsigned short ByteSwap16(unsigned short x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
10 {
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
11 __asm("xchgb %b0,%h0" :
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
12 "=q" (x) :
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
13 "0" (x));
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
14 return x;
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
15 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
16 #define bswap_16(x) ByteSwap16(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
17
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
18 inline static unsigned int ByteSwap32(unsigned int x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
19 {
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
20 #if __CPU__ > 386
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
21 __asm("bswap %0":
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
22 "=r" (x) :
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
23 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
24 __asm("xchgb %b0,%h0\n"
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
25 " rorl $16,%0\n"
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
26 " xchgb %b0,%h0":
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
27 "=q" (x) :
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
28 #endif
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
29 "0" (x));
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
30 return x;
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
31 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
32 #define bswap_32(x) ByteSwap32(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
33
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
34 inline static unsigned long long int ByteSwap64(unsigned long long int x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
35 {
433
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
36 register union { __extension__ uint64_t __ll;
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
37 uint32_t __l[2]; } __x;
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
38 asm("xchgl %0,%1":
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
39 "=r"(__x.__l[0]),"=r"(__x.__l[1]):
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
40 "0"(bswap_32((unsigned long)x)),"1"(bswap_32((unsigned long)(x>>32))));
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
41 return __x.__ll;
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
42 }
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
43 #define bswap_64(x) ByteSwap64(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
44
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
45 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
46
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
47 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
48
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
49
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
50 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc.
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
51 #define bswap_32(x) \
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
52 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
53 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24))
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
54
433
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
55 inline static uint64_t ByteSwap64(uint64_t x)
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
56 {
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
57 union {
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
58 uint64_t ll;
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
59 uint32_t l[2];
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
60 } w, r;
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
61 w.ll = x;
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
62 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
63 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
64 return r.ll;
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
65 }
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
66 #define bswap_64(x) ByteSwap64(x)
133d2867d4b2 don't use inttypes.h - use inline function for bswap_64()
bellard
parents: 430
diff changeset
67
424
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
68 #endif /* !ARCH_X86 */
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
69
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
70 #endif /* !HAVE_BYTESWAP_H */
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
71
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
72 // be2me ... BigEndian to MachineEndian
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
73 // le2me ... LittleEndian to MachineEndian
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
74
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
75 #ifdef WORDS_BIGENDIAN
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
76 #define be2me_16(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
77 #define be2me_32(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
78 #define be2me_64(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
79 #define le2me_16(x) bswap_16(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
80 #define le2me_32(x) bswap_32(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
81 #define le2me_64(x) bswap_64(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
82 #else
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
83 #define be2me_16(x) bswap_16(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
84 #define be2me_32(x) bswap_32(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
85 #define be2me_64(x) bswap_64(x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
86 #define le2me_16(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
87 #define le2me_32(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
88 #define le2me_64(x) (x)
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
89 #endif
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
90
92b8e1affb66 moved in libavcodec
glantau
parents:
diff changeset
91 #endif /* __BSWAP_H__ */