gem5
v19.0.0.0
|
#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 > | |
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 > | |
T | bits (T val, int bit) |
Extract the bit from this position from 'val' and right justify it. More... | |
template<class T > | |
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 > | |
T | 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 > | |
T | 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 > | |
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... | |
#define __has_builtin | ( | foo | ) | 0 |
|
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().
|
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().
|
inline |
Extract the bit from this position from 'val' and right justify it.
Definition at line 84 of file bitfield.hh.
References bits().
|
inline |
Count trailing zeros in a 32-bit value.
An | input value |
Definition at line 298 of file bitfield.hh.
Referenced by Gicv3CPUInterface::highestActiveGroup(), Gicv3CPUInterface::highestActivePriority(), TEST(), Gicv3CPUInterface::virtualDropPriority(), and Gicv3CPUInterface::virtualHighestActivePriority().
|
inline |
Count trailing zeros in a 64-bit value.
An | input value |
Definition at line 309 of file bitfield.hh.
Referenced by AddrRange::addIntlvBits(), AddrRange::granularity(), AddrRange::removeIntlvBits(), TEST(), and AddrRange::to_string().
|
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().
|
inline |
Returns the bit position of the MSB that is set in the input.
Definition at line 204 of file bitfield.hh.
References bits().
Referenced by ArmSemihosting::calcTickShift(), CopyEngine::CopyEngine(), HDLcd::createDmaEngine(), SparcISA::TLB::doMmuRegRead(), SparcISA::TLB::doMmuRegWrite(), X86ISA::Interrupts::findRegArrayMSB(), X86ISA::I8259::getVector(), X86ISA::I8259::handleEOI(), System::System(), TEST(), and X86ISA::I8259::write().
|
inline |
Returns val with bits first to last set to the LSBs of bit_val.
E.g.: first: 7 last: 4 val: 0xFFFF bit_val: 0x0000 returned: 0xFF0F
Definition at line 132 of file bitfield.hh.
References mask().
Referenced by AddrRange::addIntlvBits(), GenericTimerMem::ctrlWrite(), MipsISA::dspDpaq(), MipsISA::dspDpsq(), MipsISA::dspExtp(), MipsISA::dspExtpd(), MipsISA::dspExtr(), MipsISA::dspMaq(), MipsISA::dspMulsaq(), MipsISA::dspPrecrq(), MipsISA::dspPrecrqu(), ArmISA::ISA::initID32(), ArmISA::ISA::initID64(), insertBits(), X86ISA::ISA::readMiscReg(), AddrRange::removeIntlvBits(), replaceBits(), FastModel::CortexA76TC::setCCRegFlat(), TEST(), GenericTimerMem::timerWrite(), and Gicv3CPUInterface::virtualIncrementEOICount().
|
inline |
Overloaded for access to only one bit in value.
Definition at line 145 of file bitfield.hh.
References insertBits().
|
inline |
Checks if a number is a power of two, or zero.
Definition at line 239 of file bitfield.hh.
Referenced by TEST().
|
inline |
Generate a 64-bit mask of 'nbits' 1s, right justified.
Definition at line 60 of file bitfield.hh.
Referenced by bits(), insertBits(), mbits(), and sext().
|
inline |
Definition at line 102 of file bitfield.hh.
|
inline |
Mask off the given bits in place like bits() but without shifting.
msb = 63, lsb = 0
Definition at line 96 of file bitfield.hh.
References mask().
Referenced by IGbE::TxDescCache::actionAfterWb(), ArmISA::TableWalker::doLongDescriptor(), SparcISA::TLB::doMmuRegWrite(), SparcISA::TLB::GetTsbPtr(), ArmISA::TableWalker::L1Descriptor::l2Addr(), SparcISA::TLB::MakeTsbPtr(), ItsCommand::mapd(), mask(), V7LPageTableOps::nextLevelPointer(), V8PageTableOps4k::nextLevelPointer(), V8PageTableOps16k::nextLevelPointer(), V8PageTableOps64k::nextLevelPointer(), ArmISA::TableWalker::LongDescriptor::nextTableAddr(), ArmISA::TableWalker::L1Descriptor::paddr(), SparcISA::PageTableEntry::paddr(), ArmISA::TableWalker::L2Descriptor::paddr(), ArmISA::TableWalker::LongDescriptor::paddr(), Gicv3Its::pageAddress(), SparcISA::PageTableEntry::populate(), ArmISA::TableWalker::processWalk(), ArmISA::TableWalker::processWalkAArch64(), ArmISA::TableWalker::processWalkLPAE(), GicV2::readDistributor(), SparcISA::ISA::readMiscReg(), SparcISA::ISA::setMiscReg(), ArmISA::ISA::setMiscReg(), TEST(), SparcISA::TlbEntry::TlbEntry(), X86ISA::TLB::translateInt(), X86ISA::GpuTLB::translateInt(), and SparcISA::TLB::writeTagAccess().
|
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().
|
inline |
A convenience function to replace bits first to last of val with bit_val in place.
Definition at line 157 of file bitfield.hh.
References insertBits().
Referenced by MipsISA::ISA::configCP(), SparcISA::doNormalFault(), SparcISA::doREDFault(), ArmISA::EndBitUnion(), X86ISA::EndBitUnion(), DramGen::genStartAddr(), DramGen::getNextPacket(), DramRotGen::getNextPacket(), X86ISA::IntelMP::IntAssignment::IntAssignment(), ArmISA::MacroMemOp::MacroMemOp(), DRAMCtrl::minBankPrep(), X86ISA::IntelMP::Processor::Processor(), iGbReg::TxdOp::setDd(), BitfieldBackend::Unsigned< Storage, first, last >::setter(), BitfieldBackend::Signed< Storage, first, last >::setter(), X86ISA::SegDescriptorLimit::setter(), ArmISA::vcvtFpFpH(), ArmISA::vcvtFpHFp(), X86ISA::I8237::write(), and IdeController::writeConfig().
|
inline |
Overloaded function to allow to access only 1 bit.
Definition at line 166 of file bitfield.hh.
References insertBits().
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).
algorithm from http://graphics.stanford.edu/~seander/bithacks.html #ReverseBitsByLookupTable
val | variable lenght word |
size | number of bytes to mirror |
Definition at line 185 of file bitfield.hh.
References output(), and reverseLookUpTable.
|
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().
const uint8_t reverseLookUpTable[] |
Lookup table used for High Speed bit reversing.
Definition at line 43 of file bitfield.cc.
Referenced by reverseBits().