Go to the source code of this file.
|
#define | BIT(n) (1u << (n)) |
| pretty much the same as Bit<unsigned>. More...
|
|
#define | IS_POW2(n) (((n) != 0) && ((n) & ((n)-1)) == 0) |
|
#define | ROUND_UP(n, multiple) (((n) + (multiple)-1) & ~((multiple)-1)) |
|
◆ BIT
#define BIT |
( |
|
n | ) |
(1u << (n)) |
pretty much the same as Bit<unsigned>.
this is intended for the initialization of enum values, where a compile-time constant is required.
◆ IS_POW2
#define IS_POW2 |
( |
|
n | ) |
(((n) != 0) && ((n) & ((n)-1)) == 0) |
◆ ROUND_UP
#define ROUND_UP |
( |
|
n, |
|
|
|
multiple |
|
) |
| (((n) + (multiple)-1) & ~((multiple)-1)) |
◆ Bit()
value of bit number <n>.
- Parameters
-
requirements:
- T should be an unsigned type
- n must be in [0, CHAR_BIT*sizeof(T)), else the result is undefined!
◆ bit_mask()
T bit_mask |
( |
size_t |
numBits | ) |
|
|
inline |
a mask that includes the lowest N bits
- Parameters
-
numBits | Number of bits in mask. |
◆ bits()
T bits |
( |
T |
num, |
|
|
size_t |
lo_idx, |
|
|
size_t |
hi_idx |
|
) |
| |
|
inline |
extract the value of bits hi_idx:lo_idx within num
example: bits(0x69, 2, 5) == 0x0A
- Parameters
-
num | number whose bits are to be extracted |
lo_idx | bit index of lowest bit to include |
hi_idx | bit index of highest bit to include |
- Returns
- value of extracted bits.
◆ ceil_log2()
ceil(log2(x))
- Parameters
-
- Returns
- ceiling of the base-2 logarithm (i.e. rounded up) or zero if the input is zero.
◆ ClearLeastSignificantBit()
T ClearLeastSignificantBit |
( |
T |
x | ) |
|
|
inline |
◆ floor_log2()
int floor_log2 |
( |
const float |
x | ) |
|
floor(log2(f)) fast, uses the FPU normalization hardware.
- Parameters
-
x | (float) input; MUST be > 0, else results are undefined. |
- Returns
- floor of the base-2 logarithm (i.e. rounded down).
◆ is_pow2()
- Returns
- whether the given number is a power of two.
◆ IsBitSet()
bool IsBitSet |
( |
T |
value, |
|
|
size_t |
index |
|
) |
| |
|
inline |
◆ LeastSignificantBit()
T LeastSignificantBit |
( |
T |
x | ) |
|
|
inline |
◆ MaxPowerOfTwoDivisor()
T MaxPowerOfTwoDivisor |
( |
T |
value | ) |
|
|
inline |
◆ PopulationCount()
static size_t PopulationCount |
( |
T |
x | ) |
|
|
inlinestatic |
◆ round_down()
T round_down |
( |
T |
n, |
|
|
T |
multiple |
|
) |
| |
|
inline |
◆ round_down_to_pow2()
T round_down_to_pow2 |
( |
T |
x | ) |
|
|
inline |
round down to next larger power of two.
◆ round_up()
T round_up |
( |
T |
n, |
|
|
T |
multiple |
|
) |
| |
|
inline |
round number up/down to the next given multiple.
- Parameters
-
n | Number to round. |
multiple | Must be a power of two. |
◆ round_up_to_pow2()
T round_up_to_pow2 |
( |
T |
x | ) |
|
|
inline |
round up to next larger power of two.
◆ SetBitsTo()
T SetBitsTo |
( |
T |
num, |
|
|
size_t |
lo_idx, |
|
|
size_t |
hi_idx, |
|
|
size_t |
value |
|
) |
| |
|
inline |
set the value of bits hi_idx:lo_idx
- Parameters
-
lo_idx | bit index of lowest bit to include |
hi_idx | bit index of highest bit to include |
value | new value to be assigned to these bits |
◆ SparsePopulationCount()
size_t SparsePopulationCount |
( |
T |
mask | ) |
|
|
inline |
- Returns
- number of 1-bits in mask. execution time is proportional to number of 1-bits in mask.