|
ADS
Algorithms and Data Structures
|
The broadword tricks of Knuth (section 7.1.3 of The Art of Computer Programming), beyond the book: operations on the 64 bits of a word as on a vector of bits, with a few instructions and no loop over the bits. More...
#include "ADS/Contract.h"#include <cstdint>#include <utility>#include "ADS/combinatorial/impl/Bitwise.tpp"Go to the source code of this file.
Namespaces | |
| namespace | ADS |
Typedefs | |
| using | ADS::Word = std::uint64_t |
| a word of 64 bits | |
Functions | |
| constexpr int | ADS::sidewaysSum (Word x) |
| the number of 1 bits of \( x \), \( \nu( x ) \) | |
| constexpr int | ADS::ruler (Word x) |
| the number of trailing zeros of \( x \), \( \rho( x ) \) | |
| constexpr int | ADS::lambda (Word x) |
| the place of the leading 1 of \( x \), \( \lambda( x ) = \lfloor \log_2 x \rfloor \) | |
| constexpr Word | ADS::rightmostOne (Word x) |
| the rightmost 1 of \( x \) alone, 0 if \( x = 0 \) | |
| constexpr Word | ADS::smearRight (Word x) |
| \( x \) with the 0 bits below its rightmost 1 set, 0 if \( x = 0 \) | |
| constexpr Word | ADS::reverseBits (Word x) |
| the bits of \( x \) in reverse order | |
| constexpr Word | ADS::gray (Word x) |
| the Gray code of \( x \) | |
| constexpr Word | ADS::grayInverse (Word g) |
| the \( x \) whose Gray code is \( g \) | |
| constexpr Word | ADS::nextSameWeight (Word x) |
| the next larger word with as many 1 bits as \( x \) | |
| constexpr Word | ADS::interleave (std::uint32_t x, std::uint32_t y) |
| the Morton code of \( ( x , y ) \), the bits of \( x \) in the even places and those of \( y \) in the odd ones | |
| constexpr std::pair< std::uint32_t, std::uint32_t > | ADS::deinterleave (Word z) |
| the \( ( x , y ) \) of the Morton code \( z \) | |
| constexpr bool | ADS::hasZeroByte (Word x) |
| whether one of the 8 bytes of \( x \) is 0 | |
The broadword tricks of Knuth (section 7.1.3 of The Art of Computer Programming), beyond the book: operations on the 64 bits of a word as on a vector of bits, with a few instructions and no loop over the bits.
The constants are written in hexadecimal with their repeated byte, e.g., \( \mathtt{0x5555 \ldots 55} \) the word of 8 bytes \( \mathtt{0x55} \), and \( \& \), \( \mid \), \( \oplus \), \( \lnot \), \( \gg \) and \( \ll \) are the operations of C++ on the bits.
The contracts [see Contract.h]: ruler() and lambda() need \( x \ne 0 \), and nextSameWeight() a word whose next one does not overflow. The functions are defined in Bitwise.tpp.