ROSE 0.11.145.192
|
Bit-wise operations on integers.
Many of these are function templates for the best optimization, but we also provide non-template versions for those cases when the arguments are not known at compile time. The non-template versions typically have "2" appended to their names to indicate that they should be the second choice–used only when the template version cannot be used.
Classes | |
struct | GenMask |
Bit mask constant with bits 0 through n-1 set. More... | |
struct | SHL1 |
Bitmask constant with bit n set. More... | |
Functions | |
template<typename T > | |
T | shl1 (size_t n) |
Bitmask with bit n set. | |
template<typename T > | |
T | genMask (size_t n) |
Bitmask with bits 0 through N-1 set. | |
template<typename T > | |
T | genMask (size_t lobit, size_t hibit) |
Generate a bitmask. | |
template<typename T > | |
bool | isPowerOfTwo (T value) |
Returns true if the value is a power of two. | |
template<typename T > | |
T | log2max (T value) |
Returns the base-2 logorithm of value . | |
template<typename T > | |
T | log2 (T a) |
template<typename T > | |
bool | bitmask_subset (T m1, T m2) |
Determines if one bitmask is a subset of another. | |
template<typename T > | |
size_t | countSet (T val) |
Counts how many bits are set (one). | |
template<typename T > | |
size_t | countClear (T val) |
Counts how many bits are clear (zero). | |
template<typename T > | |
boost::optional< size_t > | msb_set (T val) |
Optionally returns the zero-origin position of the most significant set bit. | |
template<size_t NBits, typename T > | |
bool | signBit (T value) |
Returns true if the sign bit is set, false if clear. | |
template<typename T > | |
bool | signBit2 (T value, size_t width=8 *sizeof(T)) |
Returns true if the sign bit is set, false if clear. | |
template<size_t FromBits, size_t ToBits, typename T > | |
T | signExtend (T value) |
Sign extend value. | |
template<typename T > | |
T | signExtend2 (T value, size_t from_width, size_t to_width) |
Sign extend value. | |
template<size_t NBits, typename T > | |
T | shiftLeft (T value, size_t count) |
Shifts bits of value left by count bits. | |
template<typename T > | |
T | shiftLeft2 (T value, size_t count, size_t width=8 *sizeof(T)) |
Shifts bits of value left by count bits. | |
template<size_t NBits, typename T > | |
T | shiftRightLogical (T value, size_t count) |
Shifts bits of value right by count bits without sign extension. | |
template<typename T > | |
T | shiftRightLogical2 (T value, size_t count, size_t width=8 *sizeof(T)) |
Shifts bits of value right by count bits without sign extension. | |
template<size_t NBits, typename T > | |
T | shiftRightArithmetic (T value, size_t count) |
Shifts bits of value right by count bits with sign extension. | |
template<typename T > | |
T | shiftRightArithmetic2 (T value, size_t count, size_t width=8 *sizeof(T)) |
Shifts bits of value right by count bits with sign extension. | |
template<size_t NBits, typename T > | |
T | rotateLeft (T value, size_t count) |
Rotate the bits of the value left by count bits. | |
template<typename T > | |
T | rotateLeft2 (T value, size_t count, size_t width=8 *sizeof(T)) |
Rotate the bits of the value left by count bits. | |
template<size_t NBits, typename T > | |
T | rotateRight (T value, size_t count) |
Rotate bits of the value right by count bits. | |
template<typename T > | |
T | rotateRight2 (T value, size_t count, size_t width=8 *sizeof(T)) |
Rotate bits of the value right by count bits. | |
template<size_t lobit, size_t hibit, typename T > | |
T | shift_to (T value) |
Create a shifted value. | |
template<typename T > | |
T | shift_to2 (size_t lobit, size_t hibit, T value) |
Create a shifted value. | |
template<size_t lobit, size_t hibit, typename T > | |
T | extract (T bits) |
Extract bits from a value. | |
template<typename T > | |
T | extract2 (size_t lobit, size_t hibit, T bits) |
Extract bits from a value. | |
|
inline |
Bitmask with bit n
set.
Handles the case where n
is greater than the width of type T
.
Definition at line 43 of file integerOps.h.
|
inline |
Bitmask with bits 0 through N-1
set.
Definition at line 55 of file integerOps.h.
|
inline |
Generate a bitmask.
The return value has bits lobit
(inclusive) through hibit
(inclusive) set, and all other bits are clear.
Definition at line 62 of file integerOps.h.
|
inline |
Returns true if the sign bit is set, false if clear.
Definition at line 72 of file integerOps.h.
|
inline |
Returns true if the sign bit is set, false if clear.
Definition at line 77 of file integerOps.h.
Referenced by shiftRightArithmetic2(), and signExtend2().
|
inline |
Sign extend value.
If the bit FromBits-1
is set set for value
, then the result will have bits FromBits
through ToBits-1
also set (other bits are unchanged). If ToBits
is less than or equal to FromBits
then nothing happens.
Definition at line 88 of file integerOps.h.
|
inline |
Sign extend value.
If the bit FromBits-1
is set set for value
, then the result will have bits FromBits
through ToBits-1
also set (other bits are unchanged). If ToBits
is less than or equal to FromBits
then nothing happens.
Definition at line 93 of file integerOps.h.
References signBit2().
|
inline |
Shifts bits of value
left by count
bits.
Definition at line 103 of file integerOps.h.
|
inline |
Shifts bits of value
left by count
bits.
Definition at line 108 of file integerOps.h.
Referenced by Rose::BitPattern< T >::bits(), and Rose::BitPattern< T >::shift_left().
|
inline |
Shifts bits of value
right by count
bits without sign extension.
Definition at line 117 of file integerOps.h.
|
inline |
Shifts bits of value
right by count
bits without sign extension.
Definition at line 122 of file integerOps.h.
Referenced by Rose::BitPattern< T >::shift_left(), and shiftRightArithmetic2().
|
inline |
Shifts bits of value
right by count
bits with sign extension.
Definition at line 131 of file integerOps.h.
|
inline |
Shifts bits of value
right by count
bits with sign extension.
Definition at line 141 of file integerOps.h.
References shiftRightLogical2(), and signBit2().
|
inline |
Rotate the bits of the value left by count bits.
Definition at line 154 of file integerOps.h.
|
inline |
Rotate the bits of the value left by count bits.
Definition at line 160 of file integerOps.h.
|
inline |
Rotate bits of the value right by count
bits.
Definition at line 170 of file integerOps.h.
|
inline |
Rotate bits of the value right by count
bits.
Definition at line 176 of file integerOps.h.
|
inline |
Returns true if the value is a power of two.
Zero is considered a power of two.
Definition at line 184 of file integerOps.h.
|
inline |
Returns the base-2 logorithm of value
.
If value
is not a power of two then the return value is rounded up to the next integer. The value
is treated as an unsigned value. Returns zero if value
is zero.
Definition at line 201 of file integerOps.h.
|
inline |
Definition at line 220 of file integerOps.h.
|
inline |
Create a shifted value.
The return value is created by shifting value
to the specified position in the result. Other bits of the return value are clear. The hibit
is specified so that we can check at run-time that a valid value was specified (i.e., the value isn't too wide).
Definition at line 235 of file integerOps.h.
|
inline |
Create a shifted value.
The return value is created by shifting value
to the specified position in the result. Other bits of the return value are clear. The hibit
is specified so that we can check at run-time that a valid value was specified (i.e., the value isn't too wide).
Definition at line 242 of file integerOps.h.
|
inline |
Extract bits from a value.
Bits lobit
through hibit
, inclusive, are right shifted into the result and higher-order bits of the result are cleared.
Definition at line 255 of file integerOps.h.
|
inline |
Extract bits from a value.
Bits lobit
through hibit
, inclusive, are right shifted into the result and higher-order bits of the result are cleared.
Definition at line 261 of file integerOps.h.
|
inline |
Determines if one bitmask is a subset of another.
Returns true if the bits set in the first argument form a subset of the bits set in the second argument.
Definition at line 272 of file integerOps.h.
|
inline |
Counts how many bits are set (one).
Definition at line 279 of file integerOps.h.
Referenced by Rose::BitPattern< T >::nsignificant().
|
inline |
Counts how many bits are clear (zero).
Definition at line 291 of file integerOps.h.
|
inline |
Optionally returns the zero-origin position of the most significant set bit.
Returns nothing if no bits are set.
Definition at line 303 of file integerOps.h.
Referenced by Rose::BitPattern< T >::width().