BeRTOS
|
#include <cfg/compiler.h>
Go to the source code of this file.
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. | |
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. | |
#define | ROTL(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(). | |
Functions | |
bool | is_aligned (const void *addr, size_t size) |
Check if a pointer is aligned to a certain power-of-2 size. |
Definition in file macros.h.