Defines |
#define | ALIGN_UP(value, align) |
| Align value to the next align boundary.
|
#define | MINMAX(min, x, max) (MIN(MAX(min, x), max)) |
| Bound x between min and max.
|
#define | SHUFFLE(array, len) |
| Shuffle the content of array that counts len elements.
|
#define | SWAP_T(a, b, T) |
| Macro to swap a with b, with explicit type T for dumb C89 compilers.
|
#define | REVERSE_UINT8(b) ((uint8_t)((((b) * 0x0802UL & 0x22110UL) | ((b) * 0x8020UL & 0x88440UL)) * 0x10101UL >> 16)) |
| Reverse the bits contained in b (LSB becomes the MSB and so on).
|
#define | BV(x) (1<<(x)) |
| Convert a bit value to a binary flag.
|
#define | BV32(x) ((uint32_t)1<<(x)) |
| Same as BV() but with 32 bit result.
|
#define | BV16(x) ((uint16_t)1<<(x)) |
| Same as BV() but with 16 bit result.
|
#define | BV8(x) ((uint8_t)1<<(x)) |
| Same as BV() but with 8 bit result.
|
#define | DIV_ROUND(dividend, divisor) (((dividend) + (divisor) / 2) / (divisor)) |
| Perform an integer division rounding the result to the nearest int value.
|
#define | DIV_ROUNDUP(dividend, divisor) (((dividend) + (divisor) - 1) / (divisor)) |
| Perform an integer division rounding the result to the upper int value.
|
#define | INT_MULT(a, f, prec) (((a) * (long)((f) * (1 << (prec)) + 0.5)) >> (prec)) |
| Perform a multiply between the integer a and the float constant f.
|
#define | ROUND_UP2(x, pad) (((x) + ((pad) - 1)) & ~((pad) - 1)) |
| Round up x to an even multiple of the 2's power pad.
|
#define | IS_POW2(x) (!(bool)((x) & ((x)-1))) |
| Check if x is an integer power of 2.
|
#define | UINT8_LOG2(x) |
| Calculate a compile-time log2 for a uint8_t.
|
#define | UINT16_LOG2(x) ((x < 256) ? UINT8_LOG2(x) : UINT8_LOG2((x) >> 8) + 8) |
| Calculate a compile-time log2 for a uint16_t.
|
#define | UINT32_LOG2(x) ((x < 65536UL) ? UINT16_LOG2(x) : UINT16_LOG2((x) >> 16) + 16) |
| Calculate a compile-time log2 for a uint32_t.
|
#define | PP_COUNT(...) PP_COUNT__(__VA_ARGS__,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0) |
| Count the number of arguments (up to 16).
|
#define | BIT_CHANGE(reg,...) BIT_CHANGE__(reg, 0, __VA_ARGS__) |
| This macro allows for efficient and compact bit toggling in a hardware register.
|
#define | BIT_CHANGE_BV(reg,...) BIT_CHANGE__(reg, 1, __VA_ARGS__) |
| Similar to BIT_CHANGE(), but get bits instead of masks (and applies BV() to convert them to masks).
|
#define | MAKE_ID(a, b, c, d) |
| Make an id from 4 letters, useful for file formats and kfile ids.
|
Typedefs |
typedef uint32_t | id_t |
| Type for id generated by MAKE_ID().
|
Functions |
bool | is_aligned (const void *addr, size_t size) |
| Check if a pointer is aligned to a certain power-of-2 size.
|
Integer round macros. |
Round x to a multiple of base.
- Note:
- If x is signed these macros generate a lot of code.
|
#define | ROUND_DOWN(x, base) ( (x) - ((x) % (base)) ) |
#define | ROUND_UP(x, base) ( ((x) + (base) - 1) - (((x) + (base) - 1) % (base)) ) |
#define | ROUND_NEAREST(x, base) ( ((x) + (base) / 2) - (((x) + (base) / 2) % (base)) ) |
#define | ROTR(var, rot) (((var) >> (rot)) | ((var) << ((sizeof(var) * 8) - (rot)))) |
| Macro for rotating bit left or right.
|
#define | ROTL(var, rot) (((var) << (rot)) | ((var) >> ((sizeof(var) * 8) - (rot)))) |
| Macro for rotating bit left or right.
|
Common and handy function macros.
#define INT_MULT |
( |
|
a, |
|
|
|
f, |
|
|
|
prec |
|
) |
| (((a) * (long)((f) * (1 << (prec)) + 0.5)) >> (prec)) |
Perform a multiply between the integer a and the float constant f.
This macro can be used in order to avoid floating point arithmetics in expressions like this:
int a, b;
a = b * 0.5579652750;
This macro rounds the floating point constant to a fraction, usign (2 ^ prec) as the denominator. For instance, with prec = 8, the constant 0.5579652750 will be rounded to: (143 / 256) = 0.55859375 So, the former code will be transformed to:
Since the denominator is a power of 2, we rely on the compiler to optimize this to a right shift. So, when you have to multiply an integer by a float constant, this macro will not use the floating point arithmentics. The operation will be converted to a mul + shift, with a huge performance boost.
- Note:
- f MUST be a constant in order gain performance benefits.
- Parameters:
-
a | integer you want to multiply |
f | floating point constant which you want to multply with a |
prec | conversion precision, ranges from 1 to the number of bits in a long. The higher, the better the approximation of the float constant will be. |
Definition at line 232 of file macros.h.