source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/byteorder/swab.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 2.1 KB
Line 
1#ifndef _LINUX_BYTEORDER_SWAB_H
2#define _LINUX_BYTEORDER_SWAB_H
3
4/*
5 * linux/byteorder/swab.h
6 * Byte-swapping, independently from CPU endianness
7 *      swabXX[ps]?(foo)
8 *
9 * Francois-Rene Rideau <fare@tunes.org> 19971205
10 *    separated swab functions from cpu_to_XX,
11 *    to clean up support for bizarre-endian architectures.
12 *
13 * See asm-i386/byteorder.h and suches for examples of how to provide
14 * architecture-dependent optimized versions
15 *
16 */
17
18/* for userspace, just use glibc macros */
19
20#include <byteswap.h>
21
22/* __bswap_constant_{16,32} are missing in generic <bits/byteswap.h> in glibc,
23 * thus available only on x86 and few other archs */
24#ifndef __bswap_constant_16
25#define __bswap_constant_16(x) \
26     ((((x) >> 8) & 0xff) | (((x) & 0xff) << 8))
27#endif
28#ifndef __bswap_constant_32
29#define __bswap_constant_32(x) \
30     ((((x) & 0xff000000) >> 24) | (((x) & 0x00ff0000) >>  8) |               \
31      (((x) & 0x0000ff00) <<  8) | (((x) & 0x000000ff) << 24))
32#endif
33#if (!defined(__bswap_constant_64)) && defined __GNUC__ && __GNUC__ >= 2
34/* Swap bytes in 64 bit value.  */
35#define __bswap_constant_64(x) \
36     ((((x) & 0xff00000000000000ull) >> 56)                                   \
37      | (((x) & 0x00ff000000000000ull) >> 40)                                 \
38      | (((x) & 0x0000ff0000000000ull) >> 24)                                 \
39      | (((x) & 0x000000ff00000000ull) >> 8)                                  \
40      | (((x) & 0x00000000ff000000ull) << 8)                                  \
41      | (((x) & 0x0000000000ff0000ull) << 24)                                 \
42      | (((x) & 0x000000000000ff00ull) << 40)                                 \
43      | (((x) & 0x00000000000000ffull) << 56))
44#endif
45
46#define ___constant_swab16(x) __bswap_constant_16(x)
47#define ___constant_swab32(x) __bswap_constant_32(x)
48#define ___constant_swab64(x) __bswap_constant_64(x)
49
50#define __swab16(x) bswap_16(x)
51#define __swab32(x) bswap_32(x)
52#define __swab64(x) bswap_64(x)
53
54#define __swab16p(x) __swab16(*(x))
55#define __swab32p(x) __swab32(*(x))
56#define __swab64p(x) __swab64(*(x))
57
58#define __swab16s(x) do { *(x) = __swab16p((x)); } while (0)
59#define __swab32s(x) do { *(x) = __swab32p((x)); } while (0)
60#define __swab64s(x) do { *(x) = __swab64p((x)); } while (0)
61
62#endif /* _LINUX_BYTEORDER_SWAB_H */
Note: See TracBrowser for help on using the repository browser.