Defines |
#define | bswap16(num) (((uint16_t)(num) << 8) | ((uint16_t)(num) >> 8)) |
#define | bswap32(num) |
#define | bswap64(num) |
#define | conv16be(num) bswap16(num) |
#define | conv32be(num) bswap32(num) |
#define | conv64be(num) bswap64(num) |
#define | conv16le(num) ((uint16_t)(num)) |
#define | conv32le(num) ((uint32_t)(num)) |
#define | conv64le(num) ((uint64_t)(num)) |
#define | write16be(buf, num) write16ne((buf), conv16be(num)) |
#define | write16le(buf, num) write16ne((buf), conv16le(num)) |
#define | write32be(buf, num) write32ne((buf), conv32be(num)) |
#define | write32le(buf, num) write32ne((buf), conv32le(num)) |
#define | write64be(buf, num) write64ne((buf), conv64be(num)) |
#define | write64le(buf, num) write64ne((buf), conv64le(num)) |
#define | bsf32 ctz32 |
Functions |
static uint16_t | read16be (const uint8_t *buf) |
static uint16_t | read16le (const uint8_t *buf) |
static uint32_t | read32be (const uint8_t *buf) |
static uint32_t | read32le (const uint8_t *buf) |
static uint64_t | read64be (const uint8_t *buf) |
static uint64_t | read64le (const uint8_t *buf) |
static void | write16ne (uint8_t *buf, uint16_t num) |
static void | write32ne (uint8_t *buf, uint32_t num) |
static void | write64ne (uint8_t *buf, uint64_t num) |
static uint16_t | unaligned_read16be (const uint8_t *buf) |
static uint16_t | unaligned_read16le (const uint8_t *buf) |
static uint32_t | unaligned_read32be (const uint8_t *buf) |
static uint32_t | unaligned_read32le (const uint8_t *buf) |
static void | unaligned_write16be (uint8_t *buf, uint16_t num) |
static void | unaligned_write16le (uint8_t *buf, uint16_t num) |
static void | unaligned_write32be (uint8_t *buf, uint32_t num) |
static void | unaligned_write32le (uint8_t *buf, uint32_t num) |
static uint32_t | bsr32 (uint32_t n) |
static uint32_t | clz32 (uint32_t n) |
static uint32_t | ctz32 (uint32_t n) |
Various integer and bit operations.
This file provides macros or functions to do some basic integer and bit operations.
Endianness related integer operations (XX = 16, 32, or 64; Y = b or l):
- Byte swapping: bswapXX(num)
- Byte order conversions to/from native: convXXYe(num)
- Aligned reads: readXXYe(ptr)
- Aligned writes: writeXXYe(ptr, num)
- Unaligned reads (16/32-bit only): unaligned_readXXYe(ptr)
- Unaligned writes (16/32-bit only): unaligned_writeXXYe(ptr, num)
Since they can macros, the arguments should have no side effects since they may be evaluated more than once.
- Todo:
- PowerPC and possibly some other architectures support byte swapping load and store instructions. This file doesn't take advantage of those instructions.
Bit scan operations for non-zero 32-bit integers:
- Bit scan reverse (find highest non-zero bit): bsr32(num)
- Count leading zeros: clz32(num)
- Count trailing zeros: ctz32(num)
- Bit scan forward (simply an alias for ctz32()): bsf32(num)
The above bit scan operations return 0-31. If num is zero, the result is undefined.