HooverChessUtils_PgnReader 0.9.0
Loading...
Searching...
No Matches
Static Public Member Functions | Static Private Member Functions | List of all members
hoover_chess_utils::pgn_reader::BitTricks Struct Reference

Collection of bit tricks for 64-bit words. More...

#include <bittricks.h>

Static Public Member Functions

static constexpr std::uint64_t bits0ToN (std::uint8_t n) noexcept
 Generates a bit mask with bits 0 to N set.
 
static constexpr std::uint64_t rangeHalfOpen (std::uint8_t a, std::uint8_t b) noexcept
 Generates a half-open bit mask (min(a,b), max(a,b)].
 
static constexpr std::uint64_t isolateLowestSetBit (std::uint64_t mask) noexcept
 Isolates (extracts) the lowest bit set in bit mask.
 
static constexpr std::uint64_t isolateHighestSetBit (std::uint64_t mask) noexcept
 Isolates (extracts) the highest bit set in bit mask.
 
static std::uint64_t parallelExtract (std::uint64_t data, std::uint64_t mask) noexcept
 Extracts bits of data from bit locations specified by mask.
 
static std::uint64_t parallelDeposit (std::uint64_t data, std::uint64_t mask) noexcept
 Deposits bits of data to bit locations specified by mask.
 

Static Private Member Functions

static std::uint64_t parallelExtractPortable (std::uint64_t data, std::uint64_t mask) noexcept
 
static std::uint64_t parallelDepositPortable (std::uint64_t data, std::uint64_t mask) noexcept
 

Detailed Description

Collection of bit tricks for 64-bit words.

Member Function Documentation

◆ bits0ToN()

static constexpr std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::bits0ToN ( std::uint8_t  n)
inlinestaticconstexprnoexcept

Generates a bit mask with bits 0 to N set.

Parameters
[in]nThe highest bit to set. Range: [0, 63]
Returns
Bit mask with bits from 0 to N set

◆ isolateHighestSetBit()

static constexpr std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::isolateHighestSetBit ( std::uint64_t  mask)
inlinestaticconstexprnoexcept

Isolates (extracts) the highest bit set in bit mask.

Parameters
[in]maskBit mask
Returns
Bit mask with highest bit of mask set OR 0 if mask is 0.

◆ isolateLowestSetBit()

static constexpr std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::isolateLowestSetBit ( std::uint64_t  mask)
inlinestaticconstexprnoexcept

Isolates (extracts) the lowest bit set in bit mask.

Parameters
[in]maskBit mask
Returns
Bit mask with lowest bit of mask set OR 0 if mask is 0.

◆ parallelDeposit()

static std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::parallelDeposit ( std::uint64_t  data,
std::uint64_t  mask 
)
inlinestaticnoexcept

Deposits bits of data to bit locations specified by mask.

Parameters
[in]dataData word
[in]maskMask
Returns
Deposited bits

The following implementations are provided:

Build condition Description
HAVE_X86_BMI2 Fast implementation using x86 PDEP instruction
HAVE_AARCH64_SVE2_BITPERM Fast implementation using AArch64 BDEP instruction
Otherwise Generic portable implementation
See also
https://www.chessprogramming.org/BMI2#PDEP

◆ parallelDepositPortable()

static std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::parallelDepositPortable ( std::uint64_t  data,
std::uint64_t  mask 
)
staticprivatenoexcept

◆ parallelExtract()

static std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::parallelExtract ( std::uint64_t  data,
std::uint64_t  mask 
)
inlinestaticnoexcept

Extracts bits of data from bit locations specified by mask.

Parameters
[in]dataData word
[in]maskMask
Returns
Extracted bits from data

The following implementations are provided:

Build condition Description
HAVE_X86_BMI2 Fast implementation using x86 PEXT instruction
HAVE_AARCH64_SVE2_BITPERM Fast implementation using AArch64 BEXT instruction
Otherwise Generic portable implementation
See also
https://www.chessprogramming.org/BMI2#PEXT

◆ parallelExtractPortable()

static std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::parallelExtractPortable ( std::uint64_t  data,
std::uint64_t  mask 
)
staticprivatenoexcept

◆ rangeHalfOpen()

static constexpr std::uint64_t hoover_chess_utils::pgn_reader::BitTricks::rangeHalfOpen ( std::uint8_t  a,
std::uint8_t  b 
)
inlinestaticconstexprnoexcept

Generates a half-open bit mask (min(a,b), max(a,b)].

Parameters
[in]aBoundary of the bit mask. Range: [0, 63]
[in]bBoundary of the bit mask. Range: [0, 63]
Returns
Half-open bit mask (min(a,b), max(a,b)]

This function is intended to generate a half-open bit mask when it does not matter whether the boundaries are included. That is, the caller sets or resets the boundaries accordingly.

Illustration:

                  a       b
       ----------------------------------------------------------------
ret =  0000000000011111111000000000000000000000000000000000000000000000 

The documentation for this struct was generated from the following file: