61#define BIT(n) (1u << (n))
66 const T bit = Bit<T>(index);
67 return (value & bit) != 0;
84 const T bitsInT =
sizeof(
T)*CHAR_BIT;
85 const T allBits = (
T)~
T(0);
87 if(numBits >= bitsInT)
91 const T mask = (
T)((
T(1) << numBits)-1);
107inline T bits(
T num,
size_t lo_idx,
size_t hi_idx)
109 const size_t numBits = (hi_idx - lo_idx)+1;
110 T result =
T(num >> lo_idx);
111 result =
T(result & bit_mask<T>(numBits));
125 ASSERT(std::has_single_bit(
static_cast<std::make_unsigned_t<T>
>(multiple)));
126 const T result = (n + multiple-1) & ~(multiple-1);
127 ASSERT(n <= result && result < n+multiple);
135 ASSERT(std::has_single_bit(
static_cast<std::make_unsigned_t<T>
>(multiple)));
136 const T result = n & ~(multiple-1);
137 ASSERT(result <= n && n < result+multiple);
143#define ROUND_UP(n, multiple) (((n) + (multiple)-1) & ~((multiple)-1))
bool IsBitSet(T value, size_t index)
Definition: bits.h:64
T bits(T num, size_t lo_idx, size_t hi_idx)
extract the value of bits hi_idx:lo_idx within num
Definition: bits.h:107
T round_down(T n, T multiple)
Definition: bits.h:132
T Bit(size_t n)
value of bit number <n>.
Definition: bits.h:50
T bit_mask(size_t numBits)
a mask that includes the lowest N bits
Definition: bits.h:82
T round_up(T n, T multiple)
round number up/down to the next given multiple.
Definition: bits.h:122
#define ASSERT(expr)
same as ENSURE in debug mode, does nothing in release mode.
Definition: debug.h:250
#define T(string_literal)
Definition: secure_crt.cpp:81