gem5  v19.0.0.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Macros | Functions | Variables
bitfield.hh File Reference
#include <inttypes.h>
#include <cassert>
#include <cstddef>
#include <type_traits>

Go to the source code of this file.

Macros

#define __has_builtin(foo)   0
 

Functions

uint64_t mask (int nbits)
 Generate a 64-bit mask of 'nbits' 1s, right justified. More...
 
template<class T >
bits (T val, int first, int last)
 Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it. More...
 
template<class T >
bits (T val, int bit)
 Extract the bit from this position from 'val' and right justify it. More...
 
template<class T >
mbits (T val, int first, int last)
 Mask off the given bits in place like bits() but without shifting. More...
 
uint64_t mask (int first, int last)
 
template<int N>
uint64_t sext (uint64_t val)
 Sign-extend an N-bit value to 64 bits. More...
 
template<class T , class B >
insertBits (T val, int first, int last, B bit_val)
 Returns val with bits first to last set to the LSBs of bit_val. More...
 
template<class T , class B >
insertBits (T val, int bit, B bit_val)
 Overloaded for access to only one bit in value. More...
 
template<class T , class B >
void replaceBits (T &val, int first, int last, B bit_val)
 A convenience function to replace bits first to last of val with bit_val in place. More...
 
template<class T , class B >
void replaceBits (T &val, int bit, B bit_val)
 Overloaded function to allow to access only 1 bit. More...
 
template<class T >
reverseBits (T val, std::size_t size=sizeof(T))
 Takes a variable lenght word and returns the mirrored version (Bit by bit, LSB=>MSB). More...
 
int findMsbSet (uint64_t val)
 Returns the bit position of the MSB that is set in the input. More...
 
int findLsbSet (uint64_t val)
 Returns the bit position of the LSB that is set in the input. More...
 
template<class T >
bool isPow2 (T v)
 Checks if a number is a power of two, or zero. More...
 
int popCount (uint64_t val)
 Returns the number of set ones in the provided value. More...
 
uint64_t alignToPowerOfTwo (uint64_t val)
 Align to the next highest power of two. More...
 
int ctz32 (uint32_t value)
 Count trailing zeros in a 32-bit value. More...
 
int ctz64 (uint64_t value)
 Count trailing zeros in a 64-bit value. More...
 

Variables

const uint8_t reverseLookUpTable []
 Lookup table used for High Speed bit reversing. More...
 

Macro Definition Documentation

◆ __has_builtin

#define __has_builtin (   foo)    0

Function Documentation

◆ alignToPowerOfTwo()

uint64_t alignToPowerOfTwo ( uint64_t  val)
inline

Align to the next highest power of two.

The number passed in is aligned to the next highest power of two, if it is not already a power of two. Please note that if 0 is passed in, 0 is returned.

This code has been modified from the following: http://graphics.stanford.edu/~seander/bithacks.html#RoundUpPowerOf2

Definition at line 278 of file bitfield.hh.

References X86ISA::val.

Referenced by MultiCompressor::compress(), PciVirtIO::PciVirtIO(), and TEST().

◆ bits() [1/2]

template<class T >
T bits ( val,
int  first,
int  last 
)
inline

Extract the bitfield from position 'first' to 'last' (inclusive) from 'val' and right justify it.

MSB is numbered 63, LSB is 0.

Definition at line 72 of file bitfield.hh.

References mask().

Referenced by SparcISA::PageTableEntry::_size(), AddrRange::addIntlvBits(), ArmISA::addPAC(), sc_gem5::VcdTraceFile::addTraceVal(), ArmISA::TableWalker::LongDescriptor::af(), ArmISA::TableWalker::L1Descriptor::ap(), ArmISA::TableWalker::L2Descriptor::ap(), ArmISA::TableWalker::LongDescriptor::ap(), ArmISA::TableWalker::LongDescriptor::apTable(), ArmISA::ArmStaticInst::ArmStaticInst(), ArmISA::TableWalker::LongDescriptor::attrIndx(), ArmISA::auth(), bits(), ArmISA::bitsToFp(), ArmISA::calculateTBI(), CopyEngine::CopyEngineChannel::channelRead(), ArmISA::TableWalker::checkAddrSizeFaultAArch64(), X86ISA::Interrupts::checkInterrupts(), X86ISA::Interrupts::checkInterruptsRaw(), DRAMCtrl::chooseNextFRFCFS(), ItsCommand::collectionOutOfRange(), ArmISA::TableWalker::LongDescriptor::contiguousHint(), SparcISA::PageTableEntry::cp(), ArmISA::ArmStaticInst::cpsrWriteByInstr(), CustomNoMaliGpu::CustomNoMaliGpu(), SparcISA::PageTableEntry::cv(), GenericPciHost::decodeAddress(), PseudoInst::decodeAddrOffset(), ArmISA::decodeMrsMsrBankedReg(), DictionaryCompressor< T >::MaskedPattern< mask >::decompress(), ElfObject::determineArch(), ImmOperand< SrcCType >::disassemble(), X86ISA::doCpuid(), ArmISA::TableWalker::doL1Descriptor(), ArmISA::TableWalker::doL2Descriptor(), ArmISA::TableWalker::L1Descriptor::domain(), SparcISA::TLB::doMmuRegRead(), SparcISA::TLB::doMmuRegWrite(), SMMUTranslationProcess::doReadCD(), SMMUTranslationProcess::doReadSTE(), X86ISA::Decoder::doVex2Of3State(), X86ISA::Decoder::doVex3Of3State(), MipsISA::dspDpaq(), MipsISA::dspDpsq(), MipsISA::dspExtp(), MipsISA::dspExtpd(), MipsISA::dspExtr(), MipsISA::dspPick(), MipsISA::dspShll(), MipsISA::dspShra(), MipsISA::dspShrl(), ArmISA::EndBitUnion(), X86ISA::EndBitUnion(), iGbReg::TxdOp::eop(), ArmISA::ArmStaticInst::extendReg64(), findLsbSet(), findMsbSet(), findNegative(), ArmISA::fixFpDFpSDest(), ArmISA::fixFpSFpDDest(), ArmISA::fplibFPToFixedJS(), ArmISA::fpRecipEstimate(), ArmISA::fprSqrtEstimate(), ArmISA::fpToBits(), MipsISA::genCCVector(), Gicv3CPUInterface::generateSGI(), iGbReg::TxdOp::getCso(), iGbReg::TxdOp::getCss(), ArmISA::AbortFault< DataAbort >::getFsr(), MultiperspectivePerceptron::SGHISTPATH::getHash(), GicV2::getIntConfig(), iGbReg::TxdOp::getLen(), X86ISA::Interrupts::getRegArrayBit(), ArmISA::getRestoredITBits(), MPP_StatisticalCorrector_8KB::getSizeInBits(), MPP_StatisticalCorrector_64KB::getSizeInBits(), TAGEBase::getSizeInBits(), Sparc32Process::getSyscallArg(), BitfieldBackend::Unsigned< Storage, first, last >::getter(), BitfieldBackend::Signed< Storage, first, last >::getter(), X86ISA::SegDescriptorLimit::getter(), iGbReg::TxdOp::getTsoLen(), iGbReg::TxdOp::getType(), X86ISA::I8259::getVector(), ArmISA::TableWalker::L1Descriptor::global(), ArmISA::TableWalker::L2Descriptor::global(), ArmISA::TableWalker::LongDescriptor::global(), BloomFilter::H3::hash(), BloomFilter::Bulk::hash(), BloomFilter::MultiBitSel::hash(), BloomFilter::Block::hash(), iGbReg::TxdOp::hdrlen(), Gicv3CPUInterface::hppviCanPreempt(), iGbReg::TxdOp::ic(), iGbReg::TxdOp::ide(), SparcISA::PageTableEntry::ie(), iGbReg::TxdOp::ifcs(), V7LPageTableOps::index(), V8PageTableOps4k::index(), V8PageTableOps16k::index(), V8PageTableOps64k::index(), ImmOperand< SrcCType >::init(), X86ISA::X86_64Process::initState(), PowerISA::PowerStaticInst::insertCRField(), ArmISA::TableWalker::L2Descriptor::invalid(), ItsCommand::invall(), RiscvISA::RiscvFault::invoke(), SparcISA::FastInstructionAccessMMUMiss::invoke(), SparcISA::FastDataAccessMMUMiss::invoke(), ArmISA::AbortFault< DataAbort >::invoke(), iGbReg::TxdOp::ip(), iGbReg::TxdOp::ipcse(), iGbReg::TxdOp::ipcso(), iGbReg::TxdOp::ipcss(), PowerISA::FloatOp::isDenormalized(), GicV2::isGroup0(), PowerISA::FloatOp::isInfinity(), PciDevice::isLargeBAR(), iGbReg::TxdOp::isLegacy(), GicV2::isLevelSensitive(), PowerISA::FloatOp::isNan(), MipsISA::isNan(), PowerISA::FloatOp::isNegative(), PowerISA::FloatOp::isNormalized(), PowerISA::FloatOp::isQnan(), MipsISA::isQnan(), ArmISA::UndefinedInstruction::iss(), ArmISA::SecureMonitorCall::iss(), PowerISA::FloatOp::isSnan(), MipsISA::isSnan(), V7LPageTableOps::isWritable(), V8PageTableOps4k::isWritable(), V8PageTableOps16k::isWritable(), V8PageTableOps64k::isWritable(), PowerISA::FloatOp::isZero(), iGbReg::TxdOp::ixsm(), ArmISA::TableWalker::L2Descriptor::large(), SparcISA::PageTableEntry::locked(), ArmISA::MacroMemOp::MacroMemOp(), SparcISA::TLB::MakeTsbPtr(), ItsCommand::mapc(), ItsCommand::mapd(), ItsCommand::mapi(), ItsCommand::mapti(), ArmISA::TableWalker::LongDescriptor::memAttr(), ArmISA::TableWalker::memAttrs(), ArmISA::TableWalker::memAttrsAArch64(), ArmISA::TableWalker::memAttrsLPAE(), SparcISA::Decoder::moreBytes(), ItsCommand::movall(), ItsCommand::movi(), iGbReg::TxdOp::mss(), ArmISA::TableWalker::LongDescriptor::nextDescAddr(), SparcISA::PageTableEntry::nofault(), sc_gem5::VcdTraceValTime::output(), sc_gem5::VcdTraceValInt< T >::output(), Gicv3Its::pageAddress(), V7LPageTableOps::pageMask(), V8PageTableOps4k::pageMask(), V8PageTableOps16k::pageMask(), V8PageTableOps64k::pageMask(), BloomFilter::Bulk::permute(), ArmISA::TableWalker::L1Descriptor::pfn(), SparcISA::PageTableEntry::pfn(), ArmISA::TableWalker::L2Descriptor::pfn(), ArmISA::TableWalker::LongDescriptor::pfn(), SparcISA::PageTableEntry::populate(), ArmISA::PredImmOp::PredImmOp(), MsrBase::printMsrBase(), SparcISA::PageTableEntry::priv(), ArmISA::Decoder::process(), ArmISA::TableWalker::processWalk(), ArmISA::TableWalker::processWalkAArch64(), ArmISA::TableWalker::processWalkLPAE(), ArmISA::purifyTaggedAddr(), ArmISA::TableWalker::LongDescriptor::pxn(), ArmISA::TableWalker::LongDescriptor::pxnTable(), X86ISA::LongModePTE::read(), FastModel::CortexA76TC::readCCRegFlat(), IdeController::readConfig(), GicV2::readCpu(), SparcISA::ISA::readMiscRegNoEffect(), PS2Keyboard::recv(), X86ISA::I8259::requestInterrupt(), Sp804::Timer::restartCounter(), iGbReg::TxdOp::rs(), ArmISA::TableWalker::LongDescriptor::rw(), ArmISA::TableWalker::LongDescriptor::rwTable(), ArmISA::ArmStaticInst::saturateOp(), ArmISA::TableWalker::L1Descriptor::secure(), ArmISA::TableWalker::LongDescriptor::secure(), ArmISA::TableWalker::LongDescriptor::secureTable(), PciDevice::serialize(), MultiperspectivePerceptron::setExtraBits(), SparcISA::ISA::setFSReg(), ArmISA::ISA::setMiscReg(), ArmISA::ISA::setMiscRegNoEffect(), X86ISA::Interrupts::setReg(), ArmISA::ArmFault::setSyndrome(), SparcProcess::setSyscallReturn(), X86ISA::SegDescriptorLimit::setter(), setThreadArea32Func(), sext(), ArmISA::TableWalker::LongDescriptor::sh(), ArmISA::TableWalker::L1Descriptor::shareable(), ArmISA::TableWalker::L2Descriptor::shareable(), ArmISA::ArmStaticInst::shiftReg64(), SparcISA::PageTableEntry::sideffect(), X86ISA::I8259::signalInterrupt(), ArmISA::simd_modified_imm(), MipsISA::simdPack(), MipsISA::simdUnpack(), ItsCommand::sizeOutOfRange(), ArmISA::ArmStaticInst::spsrWriteByInstr(), X86ISA::Walker::WalkerState::stepWalk(), ArmISA::stripPAC(), ArmISA::TableWalker::L1Descriptor::supersection(), iGbReg::TxdOp::tcp(), TEST(), ArmISA::TableWalker::L1Descriptor::texcb(), ArmISA::TableWalker::L2Descriptor::texcb(), AddrRange::to_string(), X86ISA::TLB::translate(), X86ISA::GpuTLB::translate(), SparcISA::TLB::translateData(), SparcISA::TLB::translateInst(), X86ISA::TLB::translateInt(), X86ISA::GpuTLB::translateInt(), iGbReg::TxdOp::tse(), iGbReg::TxdOp::tucse(), iGbReg::TxdOp::tucso(), iGbReg::TxdOp::tucss(), iGbReg::TxdOp::txsm(), ArmISA::TableWalker::LongDescriptor::type(), PciDevice::unserialize(), ArmISA::unsignedRecipEstimate(), ArmISA::unsignedRSqrtEstimate(), GicV2::updateIntState(), ArmISA::TLB::updateMiscReg(), ArmISA::TableWalker::LongDescriptor::user(), ArmISA::TableWalker::LongDescriptor::userTable(), iGbReg::TxdOp::utcmd(), SparcISA::TteTag::va(), SparcISA::TteTag::valid(), SparcISA::PageTableEntry::valid(), ArmISA::vcvtFpFpH(), ArmISA::vcvtFpHFp(), ArmISA::vfp_modified_imm(), Gicv3CPUInterface::virtualIncrementEOICount(), iGbReg::TxdOp::vle(), SparcISA::vtophys(), SparcISA::PageTableEntry::writable(), X86ISA::I8237::write(), Sp805::write(), X86ISA::I8259::write(), X86ISA::I8042::write(), CopyEngine::write(), Gicv3Redistributor::write(), Gicv3Distributor::write(), IGbE::write(), GicV2::writeDistributor(), Iob::writeIob(), Iob::writeJBus(), X86ISA::I82094AA::writeReg(), ArmISA::TableWalker::L1Descriptor::xn(), ArmISA::TableWalker::L2Descriptor::xn(), ArmISA::TableWalker::LongDescriptor::xn(), and ArmISA::TableWalker::LongDescriptor::xnTable().

◆ bits() [2/2]

template<class T >
T bits ( val,
int  bit 
)
inline

Extract the bit from this position from 'val' and right justify it.

Definition at line 84 of file bitfield.hh.

References bits().

◆ ctz32()

int ctz32 ( uint32_t  value)
inline

Count trailing zeros in a 32-bit value.

Parameters
Aninput value
Returns
The number of trailing zeros or 32 if the value is zero.

Definition at line 298 of file bitfield.hh.

Referenced by Gicv3CPUInterface::highestActiveGroup(), Gicv3CPUInterface::highestActivePriority(), TEST(), Gicv3CPUInterface::virtualDropPriority(), and Gicv3CPUInterface::virtualHighestActivePriority().

◆ ctz64()

int ctz64 ( uint64_t  value)
inline

Count trailing zeros in a 64-bit value.

Parameters
Aninput value
Returns
The number of trailing zeros or 64 if the value is zero.

Definition at line 309 of file bitfield.hh.

Referenced by AddrRange::addIntlvBits(), AddrRange::granularity(), AddrRange::removeIntlvBits(), TEST(), and AddrRange::to_string().

◆ findLsbSet()

int findLsbSet ( uint64_t  val)
inline

Returns the bit position of the LSB that is set in the input.

Definition at line 221 of file bitfield.hh.

References bits(), and X86ISA::val.

Referenced by WalkCache::pickSetIdx(), UFSHostDevice::requestHandler(), and TEST().

◆ findMsbSet()

int findMsbSet ( uint64_t  val)
inline

◆ insertBits() [1/2]

template<class T , class B >
T insertBits ( val,
int  first,
int  last,
bit_val 
)
inline

◆ insertBits() [2/2]

template<class T , class B >
T insertBits ( val,
int  bit,
bit_val 
)
inline

Overloaded for access to only one bit in value.

Definition at line 145 of file bitfield.hh.

References insertBits().

◆ isPow2()

template<class T >
bool isPow2 ( v)
inline

Checks if a number is a power of two, or zero.

Definition at line 239 of file bitfield.hh.

Referenced by TEST().

◆ mask() [1/2]

uint64_t mask ( int  nbits)
inline

Generate a 64-bit mask of 'nbits' 1s, right justified.

Definition at line 60 of file bitfield.hh.

References LL, and ULL.

Referenced by bits(), insertBits(), mbits(), and sext().

◆ mask() [2/2]

uint64_t mask ( int  first,
int  last 
)
inline

Definition at line 102 of file bitfield.hh.

References LL, and mbits().

◆ mbits()

template<class T >
T mbits ( val,
int  first,
int  last 
)
inline

◆ popCount()

int popCount ( uint64_t  val)
inline

Returns the number of set ones in the provided value.

PD algorithm from http://graphics.stanford.edu/~seander/bithacks.html#CountBitsSetParallel

Definition at line 249 of file bitfield.hh.

References RiscvISA::sum.

Referenced by AddrRange::addIntlvBits(), AddrRange::contains(), and TEST().

◆ replaceBits() [1/2]

template<class T , class B >
void replaceBits ( T &  val,
int  first,
int  last,
bit_val 
)
inline

◆ replaceBits() [2/2]

template<class T , class B >
void replaceBits ( T &  val,
int  bit,
bit_val 
)
inline

Overloaded function to allow to access only 1 bit.

Definition at line 166 of file bitfield.hh.

References insertBits().

◆ reverseBits()

template<class T >
T reverseBits ( val,
std::size_t  size = sizeof(T) 
)

Takes a variable lenght word and returns the mirrored version (Bit by bit, LSB=>MSB).

algorithm from http://graphics.stanford.edu/~seander/bithacks.html #ReverseBitsByLookupTable

Parameters
valvariable lenght word
sizenumber of bytes to mirror
Returns
mirrored word

Definition at line 185 of file bitfield.hh.

References output(), and reverseLookUpTable.

Referenced by crc32(), and TEST().

◆ sext()

template<int N>
uint64_t sext ( uint64_t  val)
inline

Sign-extend an N-bit value to 64 bits.

Definition at line 113 of file bitfield.hh.

References bits(), and mask().

Referenced by BitfieldBackend::Signed< Storage, first, last >::getter().

Variable Documentation

◆ reverseLookUpTable

const uint8_t reverseLookUpTable[]

Lookup table used for High Speed bit reversing.

Definition at line 43 of file bitfield.cc.

Referenced by reverseBits().


Generated on Fri Feb 28 2020 16:27:06 for gem5 by doxygen 1.8.13