8 * Bit map related macros. Usually provided by libc.
10 #include <sys/param.h>
13 # define NBBY CHAR_BIT
17 # define setbit(a,i) ((a)[(i)/NBBY] |= 1<<((i)%NBBY))
18 # define clrbit(a,i) ((a)[(i)/NBBY] &= ~(1<<((i)%NBBY)))
19 # define isset(a,i) ((a)[(i)/NBBY] & (1<<((i)%NBBY)))
20 # define isclr(a,i) (((a)[(i)/NBBY] & (1<<((i)%NBBY))) == 0)
23 #if !defined __BYTE_ORDER || !(__BYTE_ORDER == __LITTLE_ENDIAN) && !(__BYTE_ORDER == __BIG_ENDIAN)
24 #error missing __BYTE_ORDER
28 * Byte swab macros (based on linux/byteorder/swab.h)
32 (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \
33 (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) ))
37 (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \
38 (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \
39 (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \
40 (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) ))
44 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \
45 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \
46 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \
47 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \
48 (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \
49 (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \
50 (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \
51 (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) ))
54 #if (__BYTE_ORDER == __BIG_ENDIAN)
56 #define cpu_to_le16(x) swab16(x)
57 #define cpu_to_le32(x) swab32(x)
58 #define cpu_to_le64(x) swab64(x)
59 #define cpu_to_be16(x) (x)
60 #define cpu_to_be32(x) (x)
61 #define cpu_to_be64(x) (x)
63 #define le16_to_cpu(x) swab16(x)
64 #define le32_to_cpu(x) swab32(x)
65 #define le64_to_cpu(x) swab64(x)
66 #define be16_to_cpu(x) (x)
67 #define be32_to_cpu(x) (x)
68 #define be64_to_cpu(x) (x)
70 #else /* __BYTE_ORDER != __BIG_ENDIAN */
72 #define cpu_to_le16(x) (x)
73 #define cpu_to_le32(x) (x)
74 #define cpu_to_le64(x) (x)
75 #define cpu_to_be16(x) swab16(x)
76 #define cpu_to_be32(x) swab32(x)
77 #define cpu_to_be64(x) swab64(x)
79 #define le16_to_cpu(x) (x)
80 #define le32_to_cpu(x) (x)
81 #define le64_to_cpu(x) (x)
82 #define be16_to_cpu(x) swab16(x)
83 #define be32_to_cpu(x) swab32(x)
84 #define be64_to_cpu(x) swab64(x)
86 #endif /* __BYTE_ORDER */