|
| template<typename T > |
| constexpr bool | sp::bitIsSet (T x, int bit) |
| | Return true iff the bitth bit of x is 1. More...
|
| |
| template<typename T > |
| constexpr T | sp::setBit (T x, int bit) |
| | Set a bit in x to 1, returning the result. More...
|
| |
| template<typename T > |
| constexpr T | sp::clearBit (T x, int bit) |
| | Set a bit in x to 0, returning the result. More...
|
| |
| template<typename T > |
| constexpr T | sp::assignBit (T x, int bit, bool value) |
| | Set bit bit of x to value ? 1 : 0, and return the result. More...
|
| |
| template<typename T > |
| constexpr T | sp::keepHighBits (T x, int KeepBits) |
| | Zero everything except the KeepBits-many high bits in x. More...
|
| |
| template<typename T > |
| constexpr T | sp::keepLowBits (T x, int KeepBits) |
| | Zero everything except the KeepBits-many low bits in x. More...
|
| |
| template<typename T = uint64_t, typename ValueT > |
| constexpr T | sp::bitfieldExtract (ValueT x, int start, int len=sizeof(T) *8) |
| | Extract a bitfield starting at bit start and extending for len bits. More...
|
| |
| template<typename ValueT , typename PayloadT > |
| constexpr ValueT | sp::bitfieldInsert (ValueT x, PayloadT value, int start, int len=bits< PayloadT >) |
| | Copy the least significant len bits of value into x at position start. More...
|
| |
| template<typename T > |
| constexpr T | sp::snipBit (T x, int bit) |
| | "cut" a bit out of x, shifting everything above it to the right. More...
|
| |
| template<typename I > |
| constexpr int | sp::bitsNeededForValue (I n) |
| | Calculate the number of bits needed to represent the given integer. More...
|
| |
| template<typename I > |
| constexpr I | sp::getLSBOnes (int count) |
| | Get a value with the count least significant bits set to one. More...
|
| |
| template<typename T > |
| constexpr T | sp::popcount (const T &arg) |
| | Population-count the object representation of any type. More...
|
| |
Utilities for bit-twiddling.
template<typename T = uint64_t, typename ValueT >
| constexpr T sp::bitfieldExtract |
( |
ValueT |
x, |
|
|
int |
start, |
|
|
int |
len = sizeof(T) * 8 |
|
) |
| |
|
constexpr |
Extract a bitfield starting at bit start and extending for len bits.
The result is shifted down to the least-significant position and returned.
Note that although this function looks hideously complicated, it does reliably compile to a BFE or an AND instruction, meaning you can safely use it to do bounds-checked bit-twiddling and so on.
- Template Parameters
-
| T | The type of the bifield member being extracted. |
| ValueT | The type of integer containing the bitfield (deduced) |