Various integer and bit operations.
This file provides macros or functions to do some basic integer and bit operations.
Native endian inline functions (XX = 16, 32, or 64):
- Unaligned native endian reads: readXXne(ptr)
- Unaligned native endian writes: writeXXne(ptr, num)
- Aligned native endian reads: aligned_readXXne(ptr)
- Aligned native endian writes: aligned_writeXXne(ptr, num)
Endianness-converting integer operations (these can be macros!) (XX = 16, 32, or 64; Y = b or l):
- Byte swapping: bswapXX(num)
- Byte order conversions to/from native (byteswaps if Y isn't the native endianness): convXXYe(num)
- Unaligned reads: readXXYe(ptr)
- Unaligned writes: writeXXYe(ptr, num)
- Aligned reads: aligned_readXXYe(ptr)
- Aligned writes: aligned_writeXXYe(ptr, num)
Since the above can macros, the arguments should have no side effects because they may be evaluated more than once.
Bit scan operations for non-zero 32-bit integers (inline functions):
- 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.