Sturk 1.0.2
Publish-subscribe C implementation.
|
Bits and bitfields. More...
Go to the source code of this file.
Macros | |
#define | st_bf_set(word, mask, val) (((word) & ~(mask)) | (val)) |
Set a bitfield in a word to a new value. | |
#define | ST_BIT(pos) (1 << (pos)) |
Create a bitmask for a single bit. | |
#define | ST_BITMASK(hi, lo) ((1 << (hi)) * 2 - (1 << (lo))) |
Create a contiguous bitmask. | |
#define | ST_BITFIELD(mask, val) ((val) << (__builtin_ffs(mask) - 1)) |
Create a bitfield. | |
Typedefs | |
typedef int | StBits |
The data type for bitwise operations. | |
Bits and bitfields.
This header file provides macros for operating with bits and bitfields. Use the StBits data type for bitwise operations as it avoids many issues related to integral promotion, which is a common source of bugs when doing bit manipulations.
Usage.
#define st_bf_set | ( | word, | |
mask, | |||
val | |||
) | (((word) & ~(mask)) | (val)) |
Set a bitfield in a word to a new value.
[in] | word | The word that contains the bitfield. |
[in] | mask | The bitmask of the bitfield. |
[in] | val | The new value of the bitfield. |
#define ST_BIT | ( | pos | ) | (1 << (pos)) |
Create a bitmask for a single bit.
This macro creates a bitmask for a bit at position pos.
#define ST_BITFIELD | ( | mask, | |
val | |||
) | ((val) << (__builtin_ffs(mask) - 1)) |
Create a bitfield.
[in] | mask | The bitmask of the bitfield. |
[in] | val | The value of the bitfield. |
#define ST_BITMASK | ( | hi, | |
lo | |||
) | ((1 << (hi)) * 2 - (1 << (lo))) |
Create a contiguous bitmask.
This macro creates a contiguous bitmask that spans from the hi (most significant bit) to the lo (least significant bit).