decompiler
1.0.0
|
Classes for specifying addresses and other low-level constants. More...
#include "space.hh"
Classes | |
class | Address |
A low-level machine address for labelling bytes and data. More... | |
class | SeqNum |
A class for uniquely labelling and comparing PcodeOps. More... | |
class | Range |
A contiguous range of bytes in some address space. More... | |
class | RangeList |
A disjoint set of Ranges, possibly across multiple address spaces. More... | |
Functions | |
uintb | calc_mask (int4 size) |
Calculate a mask for a given byte size. More... | |
uintb | pcode_right (uintb val, int4 sa) |
uintb | pcode_left (uintb val, int4 sa) |
uintb | minimalmask (uintb val) |
Calculate smallest mask that covers the given value. More... | |
bool | signbit_negative (uintb val, int4 size) |
Return true if the sign-bit is set. More... | |
uintb | uintb_negate (uintb in, int4 size) |
Negate the sized value. More... | |
uintb | sign_extend (uintb in, int4 sizein, int4 sizeout) |
Sign-extend a value between two byte sizes. More... | |
void | sign_extend (intb &val, int4 bit) |
Sign extend above given bit. More... | |
void | zero_extend (intb &val, int4 bit) |
Clear all bits above given bit. More... | |
void | byte_swap (intb &val, int4 size) |
Swap bytes in the given value. More... | |
uintb | byte_swap (uintb val, int4 size) |
Return the given value with bytes swapped. More... | |
int4 | leastsigbit_set (uintb val) |
Return index of least significant bit set in given value. More... | |
int4 | mostsigbit_set (uintb val) |
Return index of most significant bit set in given value. More... | |
int4 | popcount (uintb val) |
Return the number of one bits in the given value. More... | |
int4 | count_leading_zeros (uintb val) |
Return the number of leading zero bits in the given value. More... | |
uintb | coveringmask (uintb val) |
Return a mask that covers the given value. More... | |
int4 | bit_transitions (uintb val, int4 sz) |
Calculate the number of bit transitions in the sized value. More... | |
void | mult64to128 (uint8 *res, uint8 x, uint8 y) |
Multiply 2 unsigned 64-bit values, producing a 128-bit value. More... | |
void | unsignedSubtract128 (uint8 *a, uint8 *b) |
Subtract (in-place) a 128-bit value from a base 128-value. More... | |
int4 | unsignedCompare128 (uint8 *a, uint8 *b) |
Compare two unsigned 128-bit values. More... | |
int4 | power2Divide (int4 n, uint8 divisor, uint8 &q, uint8 &r) |
Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor. More... | |
Variables | |
uintb | uintbmasks [] |
Precalculated masks indexed by size. | |
Classes for specifying addresses and other low-level constants.
All addresses are absolute and there are are no registers in CPUI. However, all addresses are prefixed with an "immutable" pointer, which can specify a separate RAM space, a register space, an i/o space etc. Thus a translation from a real machine language will typically simulate registers by placing them in their own space, separate from RAM. Indirection (i.e. pointers) must be simulated through the LOAD and STORE ops.
int4 bit_transitions | ( | uintb | val, |
int4 | sz | ||
) |
Calculate the number of bit transitions in the sized value.
Treat val as a constant of size sz. Scanning across the bits of val return the number of transitions (from 0->1 or 1->0) If there are 2 or less transitions, this is an indication of a bit flag or a mask
val | is the given value |
sz | is the size to treat the value as |
Referenced by ActionConstantPtr::isPointer(), minimalmask(), and CircleRange::setNZMask().
void byte_swap | ( | intb & | val, |
int4 | size | ||
) |
Swap bytes in the given value.
Swap the least significant size bytes in val
val | is a reference to the value to swap |
size | is the number of bytes to swap |
Referenced by MemoryImage::find(), EmulatePcodeOp::getLoadImageValue(), EmulateSnippet::getLoadImageValue(), MemoryBank::getPage(), minimalmask(), and MemoryBank::setPage().
uintb byte_swap | ( | uintb | val, |
int4 | size | ||
) |
Return the given value with bytes swapped.
Swap the least significant size bytes in val
val | is the value to swap |
size | is the number of bytes to swap |
|
inline |
Calculate a mask for a given byte size.
size | is the desired size in bytes |
References uintbmasks.
Referenced by AddTreeState::AddTreeState(), ActionStackPtrFlow::analyzeExtraPop(), RuleCollectTerms::applyOp(), RuleOrMask::applyOp(), RuleNegateIdentity::applyOp(), RuleShiftBitops::applyOp(), RuleRightShiftAnd::applyOp(), RulePullsubMulti::applyOp(), RulePullsubIndirect::applyOp(), RuleHighOrderAnd::applyOp(), RuleAndDistribute::applyOp(), RuleAndCommute::applyOp(), RuleAndPiece::applyOp(), RuleAndCompare::applyOp(), RuleDoubleShift::applyOp(), RuleShiftCompare::applyOp(), RuleBoolZext::applyOp(), RuleSborrow::applyOp(), RuleSignShift::applyOp(), RuleTestSign::applyOp(), RuleTransformCpool::applyOp(), Rule2Comp2Mult::applyOp(), RuleCarryElim::applyOp(), RuleSub2Add::applyOp(), RuleSubCommute::applyOp(), RuleConcatCommute::applyOp(), RuleShiftAnd::applyOp(), RuleSubZext::applyOp(), RuleHumptyOr::applyOp(), RuleEmbed::applyOp(), RuleLess2Zero::applyOp(), RuleLessEqual2Zero::applyOp(), RuleSLess2Zero::applyOp(), RuleEqual2Zero::applyOp(), RuleEqual2Constant::applyOp(), RuleMultNegOne::applyOp(), RuleAddUnsigned::applyOp(), RuleDivTermAdd2::applyOp(), RuleSignDiv2::applyOp(), RuleSignNearMult::applyOp(), RuleModOpt::applyOp(), RuleSubvarAnd::applyOp(), RuleSubvarSubpiece::applyOp(), RuleSubvarCompZero::applyOp(), RuleSubvarZext::applyOp(), RuleSubvarSext::applyOp(), RuleFuncPtrEncoding::applyOp(), RuleThreeWayCompare::applyOp(), Funcdata::calcNZMask(), JumpBasic::calcRange(), AddrSpace::calcScaleMask(), ActionStackPtrFlow::checkClog(), ValueSetSolver::checkRelativeConstant(), CircleRange::CircleRange(), Funcdata::collapseIntMultMult(), RuleThreeWayCompare::detectThreeWay(), Funcdata::distributeIntMultAdd(), OpBehaviorIntAdd::evaluateBinary(), OpBehaviorIntSub::evaluateBinary(), OpBehaviorIntCarry::evaluateBinary(), OpBehaviorIntLeft::evaluateBinary(), OpBehaviorIntRight::evaluateBinary(), OpBehaviorIntSright::evaluateBinary(), OpBehaviorIntMult::evaluateBinary(), OpBehaviorSubpiece::evaluateBinary(), JumpTable::foldInNormalization(), ActionDeadCode::gatherConsumedReturn(), AliasChecker::gatherOffset(), RuleSLess2Zero::getHiBit(), EmulatePcodeOp::getLoadImageValue(), EmulateSnippet::getLoadImageValue(), PcodeOp::getNZMaskLocal(), ContextDatabase::getTrackedValue(), MemoryBank::getValue(), EquateSymbol::isValueClose(), ActionDeadCode::markConsumedParameters(), minimalmask(), TransformManager::newConstant(), TransformManager::newSplit(), FloatFormat::opTrunc(), Funcdata::opUndoPtradd(), ActionDeadCode::propagateConsumed(), CircleRange::pullBack(), CircleRange::pullBackBinary(), CircleRange::pullBackUnary(), PrintC::push_integer(), ActionDeadCode::pushConsumed(), PrintC::pushEquate(), CircleRange::pushForwardBinary(), CircleRange::pushForwardUnary(), OpBehaviorIntAdd::recoverInputBinary(), OpBehaviorIntSub::recoverInputBinary(), OpBehaviorIntLeft::recoverInputBinary(), OpBehaviorIntZext::recoverInputUnary(), OpBehaviorIntSext::recoverInputUnary(), Funcdata::replaceLessequal(), SegmentedResolver::resolve(), TypeFactory::setEnumValues(), CircleRange::setFull(), CircleRange::setNZMask(), CircleRange::setRange(), SubvariableFlow::setReplacement(), MemoryBank::setValue(), sign_extend(), SubvariableFlow::traceBackward(), SubvariableFlow::traceBackwardSext(), SubvariableFlow::traceForward(), SubvariableFlow::traceForwardSext(), ActionLikelyTrash::traceTrash(), Funcdata::transferVarnodeProperties(), and uintb_negate().
int4 count_leading_zeros | ( | uintb | val | ) |
Return the number of leading zero bits in the given value.
Count the number of more significant zero bits before the most significant one bit in the representation of the given value;
val | is the given value |
Referenced by RuleDivOpt::findForm(), CircleRange::getMaxInfo(), minimalmask(), CircleRange::pushForwardBinary(), and JumpValuesRange::truncate().
uintb coveringmask | ( | uintb | val | ) |
Return a mask that covers the given value.
Return smallest number of form 2^n-1, bigger or equal to the given value
val | is the given value |
Referenced by JumpBasic::calcRange(), PcodeOp::getNZMaskLocal(), minimalmask(), and ActionDeadCode::propagateConsumed().
int4 leastsigbit_set | ( | uintb | val | ) |
Return index of least significant bit set in given value.
The least significant bit is index 0.
val | is the given value |
Referenced by SubvariableFlow::addConstant(), SubvariableFlow::addSuggestedPatch(), RuleShiftBitops::applyOp(), RuleDoubleShift::applyOp(), RuleShiftCompare::applyOp(), RuleShiftAnd::applyOp(), RuleSubvarCompZero::applyOp(), RulePopcountBoolXor::applyOp(), PcodeOp::getNZMaskLocal(), SubvariableFlow::getReplacementAddress(), CircleRange::minimalContainer(), minimalmask(), ActionDeadCode::propagateConsumed(), CircleRange::setNZMask(), SubvariableFlow::SubvariableFlow(), SubvariableFlow::traceBackward(), and SubvariableFlow::traceForward().
|
inline |
Calculate smallest mask that covers the given value.
Calculcate a mask that covers either the least significant byte, uint2, uint4, or uint8, whatever is smallest.
val | is the given value |
References bit_transitions(), byte_swap(), calc_mask(), count_leading_zeros(), coveringmask(), leastsigbit_set(), mostsigbit_set(), mult64to128(), popcount(), power2Divide(), sign_extend(), signbit_negative(), uintb_negate(), unsignedCompare128(), unsignedSubtract128(), and zero_extend().
Referenced by JumpTable::foldInNormalization(), ActionDeadCode::gatherConsumedReturn(), and ActionDeadCode::markConsumedParameters().
int4 mostsigbit_set | ( | uintb | val | ) |
Return index of most significant bit set in given value.
The least significant bit is index 0.
val | is the given value |
Referenced by RulePopcountBoolXor::applyOp(), PrintLanguage::formatBinary(), PcodeOp::getNZMaskLocal(), CircleRange::minimalContainer(), minimalmask(), CircleRange::pullBack(), GuardRecord::quasiCopy(), SubvariableFlow::SubvariableFlow(), and StringManager::writeUtf8().
void mult64to128 | ( | uint8 * | res, |
uint8 | x, | ||
uint8 | y | ||
) |
Multiply 2 unsigned 64-bit values, producing a 128-bit value.
TODO: Remove once we import a full multiprecision library.
res | points to the result array (2 uint8 pieces) |
x | is the first 64-bit value |
y | is the second 64-bit value |
Referenced by minimalmask(), and power2Divide().
|
inline |
Perform a CPUI_INT_LEFT on the given val
val | is the value to shift |
sa | is the number of bits to shift |
Referenced by RuleShiftBitops::applyOp(), and PcodeOp::getNZMaskLocal().
|
inline |
Perform a CPUI_INT_RIGHT on the given val
val | is the value to shift |
sa | is the number of bits to shift |
Referenced by RuleShiftBitops::applyOp(), and PcodeOp::getNZMaskLocal().
int4 popcount | ( | uintb | val | ) |
Return the number of one bits in the given value.
Count the number (population) bits set.
val | is the given value |
Referenced by RulePopcountBoolXor::applyOp(), OpBehaviorPopcount::evaluateUnary(), PcodeOp::getNZMaskLocal(), and minimalmask().
int4 power2Divide | ( | int4 | n, |
uint8 | divisor, | ||
uint8 & | q, | ||
uint8 & | r | ||
) |
Unsigned division of a power of 2 (upto 2^127) by a 64-bit divisor.
The result must be less than 2^64. The remainder is calculated.
n | is the power of 2 for the numerand |
divisor | is the 64-bit divisor |
q | is the passed back 64-bit quotient |
r | is the passed back 64-bit remainder |
References mult64to128(), unsignedCompare128(), and unsignedSubtract128().
Referenced by RuleDivOpt::calcDivisor(), and minimalmask().
uintb sign_extend | ( | uintb | in, |
int4 | sizein, | ||
int4 | sizeout | ||
) |
Sign-extend a value between two byte sizes.
Take the first sizein bytes of the given in and sign-extend this to sizeout bytes, keeping any more significant bytes zero
in | is the given value |
sizein | is the size to treat that value as an input |
sizeout | is the size to sign-extend the value to |
References calc_mask().
Referenced by MapState::addRange(), RuleSubCommute::applyOp(), AddTreeState::buildMultiples(), ScopeLocal::buildVariableName(), AddTreeState::calcSubtype(), AddTreeState::checkMultTerm(), AddTreeState::checkTerm(), OpBehaviorIntSdiv::evaluateBinary(), OpBehaviorIntSrem::evaluateBinary(), OpBehaviorIntSext::evaluateUnary(), AddTreeState::findArrayHint(), PcodeOp::getNZMaskLocal(), MapState::initialize(), EquateSymbol::isValueClose(), minimalmask(), FloatFormat::opInt2Float(), CircleRange::pullBackUnary(), PrintC::pushEquate(), CircleRange::pushForwardBinary(), CircleRange::pushForwardUnary(), Funcdata::replaceLessequal(), and SubvariableFlow::setReplacement().
void sign_extend | ( | intb & | val, |
int4 | bit | ||
) |
Sign extend above given bit.
Sign extend val starting at bit
val | is a reference to the value to be sign-extended |
bit | is the index of the bit to extend from (0=least significant bit) |
bool signbit_negative | ( | uintb | val, |
int4 | size | ||
) |
Return true if the sign-bit is set.
Treat the given val as a constant of size bytes
val | is the given value |
size | is the size in bytes |
Referenced by RuleSlessToLess::applyOp(), RuleDivTermAdd::applyOp(), OpBehaviorIntSright::evaluateBinary(), CastStrategyC::localExtensionType(), minimalmask(), and ConditionMarker::sameOpComplement().
uintb uintb_negate | ( | uintb | in, |
int4 | size | ||
) |
Negate the sized value.
Treat the given in as a constant of size bytes. Negate this constant keeping the upper bytes zero.
in | is the given value |
size | is the size in bytes |
References calc_mask().
Referenced by RuleSborrow::applyOp(), RuleEqual2Zero::applyOp(), AddTreeState::buildExtra(), OpBehaviorInt2Comp::evaluateUnary(), OpBehaviorIntNegate::evaluateUnary(), and minimalmask().
int4 unsignedCompare128 | ( | uint8 * | a, |
uint8 * | b | ||
) |
Compare two unsigned 128-bit values.
TODO: Remove once we import a full multiprecision library. Given a first and second value, return -1, 0, or 1 depending on whether the first value is less, equal, or greater than the second value.
a | is the first 128-bit value (as an array of 2 uint8 elements) |
b | is the second 128-bit value |
Referenced by minimalmask(), and power2Divide().
void unsignedSubtract128 | ( | uint8 * | a, |
uint8 * | b | ||
) |
Subtract (in-place) a 128-bit value from a base 128-value.
The base value is altered in place. TODO: Remove once we import a full multiprecision library.
a | is the base 128-bit value being subtracted from in-place |
b | is the other 128-bit value being subtracted |
Referenced by minimalmask(), and power2Divide().
void zero_extend | ( | intb & | val, |
int4 | bit | ||
) |
Clear all bits above given bit.
Zero extend val starting at bit
val | is a reference to the value to be zero extended |
bit | is the index of the bit to extend from (0=least significant bit) |
Referenced by OpBehaviorIntSdiv::evaluateBinary(), OpBehaviorIntSrem::evaluateBinary(), and minimalmask().