1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20: #if !defined _BYTESWAP_H && !defined _NETINET_IN_H
21: # error "Never use <bits/byteswap.h> directly; include <byteswap.h> instead."
22: #endif
23:
24: #ifndef _BITS_BYTESWAP_H
25: #define _BITS_BYTESWAP_H 1
26:
27:
28: #define __bswap_constant_16(x) \
29: ((((x) >> 8) & 0xffu) | (((x) & 0xffu) << 8))
30:
31: #ifdef __GNUC__
32: # define __bswap_16(x) \
33: (__extension__ \
34: ({ unsigned short int __bsx = (x); __bswap_constant_16 (__bsx); }))
35: #else
36: static __inline unsigned short int
37: __bswap_16 (unsigned short int __bsx)
38: {
39: return __bswap_constant_16 (__bsx);
40: }
41: #endif
42:
43:
44: #define __bswap_constant_32(x) \
45: ((((x) & 0xff000000u) >> 24) | (((x) & 0x00ff0000u) >> 8) | \
46: (((x) & 0x0000ff00u) << 8) | (((x) & 0x000000ffu) << 24))
47:
48: #ifdef __GNUC__
49: # define __bswap_32(x) \
50: (__extension__ \
51: ({ register unsigned int __bsx = (x); __bswap_constant_32 (__bsx); }))
52: #else
53: static __inline unsigned int
54: __bswap_32 (unsigned int __bsx)
55: {
56: return __bswap_constant_32 (__bsx);
57: }
58: #endif
59:
60: #if defined __GNUC__ && __GNUC__ >= 2
61:
62: # define __bswap_constant_64(x) \
63: ((((x) & 0xff00000000000000ull) >> 56) \
64: | (((x) & 0x00ff000000000000ull) >> 40) \
65: | (((x) & 0x0000ff0000000000ull) >> 24) \
66: | (((x) & 0x000000ff00000000ull) >> 8) \
67: | (((x) & 0x00000000ff000000ull) << 8) \
68: | (((x) & 0x0000000000ff0000ull) << 24) \
69: | (((x) & 0x000000000000ff00ull) << 40) \
70: | (((x) & 0x00000000000000ffull) << 56))
71:
72: # define __bswap_64(x) \
73: (__extension__ \
74: ({ union { __extension__ unsigned long long int __ll; \
75: unsigned int __l[2]; } __w, __r; \
76: if (__builtin_constant_p (x)) \
77: __r.__ll = __bswap_constant_64 (x); \
78: else \
79: { \
80: __w.__ll = (x); \
81: __r.__l[0] = __bswap_32 (__w.__l[1]); \
82: __r.__l[1] = __bswap_32 (__w.__l[0]); \
83: } \
84: __r.__ll; }))
85: #endif
86:
87: #endif