diff options
author | Karel Zak | 2007-12-17 13:18:12 +0100 |
---|---|---|
committer | Karel Zak | 2007-12-17 13:18:12 +0100 |
commit | 1ed3367f6167c3e5371ce4a24e61a4194c5f99fc (patch) | |
tree | 0ee7715b4b8ed66a0f239db05c404efd66f458b3 /include/bitops.h | |
parent | fdisk: fix building for AVR32 and CRIS (diff) | |
download | kernel-qcow2-util-linux-1ed3367f6167c3e5371ce4a24e61a4194c5f99fc.tar.gz kernel-qcow2-util-linux-1ed3367f6167c3e5371ce4a24e61a4194c5f99fc.tar.xz kernel-qcow2-util-linux-1ed3367f6167c3e5371ce4a24e61a4194c5f99fc.zip |
include: add bitops.h with swab{16,32,64} macros
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'include/bitops.h')
-rw-r--r-- | include/bitops.h | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/include/bitops.h b/include/bitops.h new file mode 100644 index 000000000..4ae0ff8e4 --- /dev/null +++ b/include/bitops.h @@ -0,0 +1,51 @@ +#ifndef BITOPS_H +#define BITOPS_H + +#include <linux/posix_types.h> +#include <stdint.h> + +/* + * Byte swab macros (based on linux/byteorder/swab.h) + */ +#define swab16(x) \ + ((uint16_t)( \ + (((uint16_t)(x) & (uint16_t)0x00ffU) << 8) | \ + (((uint16_t)(x) & (uint16_t)0xff00U) >> 8) )) + +#define swab32(x) \ + ((uint32_t)( \ + (((uint32_t)(x) & (uint32_t)0x000000ffUL) << 24) | \ + (((uint32_t)(x) & (uint32_t)0x0000ff00UL) << 8) | \ + (((uint32_t)(x) & (uint32_t)0x00ff0000UL) >> 8) | \ + (((uint32_t)(x) & (uint32_t)0xff000000UL) >> 24) )) + +#define swab64(x) \ + ((uint64_t)( \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000000000ffULL) << 56) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000000000ff00ULL) << 40) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000000000ff0000ULL) << 24) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x00000000ff000000ULL) << 8) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x000000ff00000000ULL) >> 8) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x0000ff0000000000ULL) >> 24) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0x00ff000000000000ULL) >> 40) | \ + (uint64_t)(((uint64_t)(x) & (uint64_t)0xff00000000000000ULL) >> 56) )) + + +#ifdef WORDS_BIGENDIAN +#define cpu_to_le16(x) swab16(x) +#define cpu_to_le32(x) swab32(x) +#define cpu_to_le64(x) swab64(x) +#define cpu_to_be16(x) (x) +#define cpu_to_be32(x) (x) +#define cpu_to_be64(x) (x) +#else +#define cpu_to_le16(x) (x) +#define cpu_to_le32(x) (x) +#define cpu_to_le64(x) (x) +#define cpu_to_be16(x) swab16(x) +#define cpu_to_be32(x) swab32(x) +#define cpu_to_be64(x) swab64(x) +#endif + +#endif /* BITOPS_H */ + |