macros.h File Reference
Common and handy function macros. More...
#include <cfg/compiler.h>
Go to the source code of this file.
Defines | |
| #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 | 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 | 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 | MAKE_ID(a, b, c, d) |
| Make an id from 4 letters, useful for file formats and kfile ids. | |
Integer round macros. | |
Round x to a multiple of base.
| |
| #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. | |
Typedefs | |
| typedef uint32_t | id_t |
| Type for id generated by MAKE_ID(). | |
Detailed Description
Common and handy function macros.
- Version:
- Id
- macros.h 2506 2009-04-15 08:29:07Z duplo
Definition in file macros.h.
Define Documentation
| #define BV | ( | x | ) | (1<<(x)) |
| #define DIV_ROUND | ( | dividend, | |||
| divisor | ) | (((dividend) + (divisor) / 2) / (divisor)) |
| #define IS_POW2 | ( | x | ) | (!(bool)((x) & ((x)-1))) |
| #define MINMAX | ( | min, | |||
| x, | |||||
| max | ) | (MIN(MAX(min, x), max)) |
| #define ROUND_UP2 | ( | x, | |||
| pad | ) | (((x) + ((pad) - 1)) & ~((pad) - 1)) |
| #define SWAP_T | ( | a, | |||
| b, | |||||
| T | ) |
