Mercurial > libavcodec.hg
annotate bswap.h @ 1202:8b49a7ee4e4e libavcodec
YUV formats/gray formats are correctly defined - added format loss information - preliminary JPEG YUV formats support
| author | bellard |
|---|---|
| date | Sun, 20 Apr 2003 16:18:44 +0000 |
| parents | 1e39f273ecd6 |
| children | e8c3884f2c7e |
| 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 | |
| 14 inline static unsigned short ByteSwap16(unsigned short x) | |
| 15 { | |
| 16 __asm("xchgb %b0,%h0" : | |
| 17 "=q" (x) : | |
| 18 "0" (x)); | |
| 19 return x; | |
| 20 } | |
| 21 #define bswap_16(x) ByteSwap16(x) | |
| 22 | |
| 23 inline static unsigned int ByteSwap32(unsigned int x) | |
| 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 | |
| 39 inline static unsigned long long int ByteSwap64(unsigned long long int x) | |
| 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 | |
| 50 #else | |
| 51 | |
| 52 #define bswap_16(x) (((x) & 0x00ff) << 8 | ((x) & 0xff00) >> 8) | |
| 53 | |
| 54 | |
| 55 // code from bits/byteswap.h (C) 1997, 1998 Free Software Foundation, Inc. | |
| 56 #define bswap_32(x) \ | |
| 57 ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >> 8) | \ | |
| 58 (((x) & 0x0000ff00) << 8) | (((x) & 0x000000ff) << 24)) | |
| 59 | |
|
433
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
60 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
|
61 { |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
62 union { |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
63 uint64_t ll; |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
64 uint32_t l[2]; |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
65 } w, r; |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
66 w.ll = x; |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
67 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
|
68 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
|
69 return r.ll; |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
70 } |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
71 #define bswap_64(x) ByteSwap64(x) |
|
133d2867d4b2
don't use inttypes.h - use inline function for bswap_64()
bellard
parents:
430
diff
changeset
|
72 |
| 424 | 73 #endif /* !ARCH_X86 */ |
| 74 | |
| 75 #endif /* !HAVE_BYTESWAP_H */ | |
| 76 | |
| 77 // be2me ... BigEndian to MachineEndian | |
| 78 // le2me ... LittleEndian to MachineEndian | |
| 79 | |
| 80 #ifdef WORDS_BIGENDIAN | |
| 81 #define be2me_16(x) (x) | |
| 82 #define be2me_32(x) (x) | |
| 83 #define be2me_64(x) (x) | |
| 84 #define le2me_16(x) bswap_16(x) | |
| 85 #define le2me_32(x) bswap_32(x) | |
| 86 #define le2me_64(x) bswap_64(x) | |
| 87 #else | |
| 88 #define be2me_16(x) bswap_16(x) | |
| 89 #define be2me_32(x) bswap_32(x) | |
| 90 #define be2me_64(x) bswap_64(x) | |
| 91 #define le2me_16(x) (x) | |
| 92 #define le2me_32(x) (x) | |
| 93 #define le2me_64(x) (x) | |
| 94 #endif | |
| 95 | |
| 96 #endif /* __BSWAP_H__ */ |
