mirror of
https://github.com/verilator/verilator.git
synced 2024-12-29 10:47:34 +00:00
Add lsb index to V3Number::setMask (#5522)
This commit is contained in:
parent
b873c23cf2
commit
8f1ea09558
@ -1162,11 +1162,10 @@ class ConstVisitor final : public VNVisitor {
|
||||
} else if (const AstShiftL* const shiftp = VN_CAST(nodep->rhsp(), ShiftL)) {
|
||||
if (const AstConst* const scp = VN_CAST(shiftp->rhsp(), Const)) {
|
||||
// Check if mask is full over the non-zero bits
|
||||
V3Number maskLo{nodep, nodep->width()};
|
||||
V3Number maskHi{nodep, nodep->width()};
|
||||
maskLo.setMask(nodep->width() - scp->num().toUInt());
|
||||
maskHi.opShiftL(maskLo, scp->num());
|
||||
return checkMask(maskHi);
|
||||
V3Number mask{nodep, nodep->width()};
|
||||
const uint32_t shiftAmount = scp->num().toUInt();
|
||||
mask.setMask(nodep->width() - shiftAmount, shiftAmount);
|
||||
return checkMask(mask);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
@ -531,10 +531,7 @@ class DelayedVisitor final : public VNVisitor {
|
||||
// Constant mask we can compute here
|
||||
if (AstConst* const cLsbp = VN_CAST(sLsbp, Const)) {
|
||||
AstConst* const cp = new AstConst{flp, AstConst::DTyped{}, eDTypep};
|
||||
cp->num().setAllBits0();
|
||||
const int lsb = cLsbp->toSInt();
|
||||
const int msb = lsb + sWidthp->toSInt() - 1;
|
||||
for (int bit = lsb; bit <= msb; ++bit) cp->num().setBit(bit, '1');
|
||||
cp->num().setMask(sWidthp->toSInt(), cLsbp->toSInt());
|
||||
return cp;
|
||||
}
|
||||
|
||||
|
@ -551,7 +551,7 @@ class ExpandVisitor final : public VNVisitor {
|
||||
const int lsb = lhsp->lsbConst();
|
||||
const int msb = lhsp->msbConst();
|
||||
V3Number maskset{nodep, destp->widthMin()};
|
||||
for (int bit = lsb; bit < (msb + 1); bit++) maskset.setBit(bit, 1);
|
||||
maskset.setMask(msb + 1 - lsb, lsb);
|
||||
V3Number maskold{nodep, destp->widthMin()};
|
||||
maskold.opNot(maskset);
|
||||
if (destwide) {
|
||||
@ -654,7 +654,7 @@ class ExpandVisitor final : public VNVisitor {
|
||||
fixCloneLvalue(oldvalp);
|
||||
|
||||
V3Number maskwidth{nodep, destp->widthMin()};
|
||||
for (int bit = 0; bit < lhsp->widthConst(); bit++) maskwidth.setBit(bit, 1);
|
||||
maskwidth.setMask(lhsp->widthConst());
|
||||
|
||||
if (destp->isQuad() && !rhsp->isQuad()) rhsp = new AstCCast{nfl, rhsp, nodep};
|
||||
if (!ones) {
|
||||
|
@ -511,9 +511,9 @@ V3Number& V3Number::setValue1() {
|
||||
return *this;
|
||||
}
|
||||
|
||||
V3Number& V3Number::setMask(int nbits) {
|
||||
V3Number& V3Number::setMask(int nbits, int lsb) {
|
||||
setZero();
|
||||
for (int bit = 0; bit < nbits; bit++) setBit(bit, 1);
|
||||
for (int bit = lsb; bit < lsb + nbits; bit++) setBit(bit, 1);
|
||||
return *this;
|
||||
}
|
||||
|
||||
|
@ -576,7 +576,8 @@ public:
|
||||
V3Number& setAllBits0();
|
||||
V3Number& setAllBits1();
|
||||
V3Number& setValue1();
|
||||
V3Number& setMask(int nbits); // IE if nbits=1, then 0b1, if 2->0b11, if 3->0b111 etc
|
||||
// IE if nbits=1, then 0b1, if 2->0b11, if 3->0b111 etc
|
||||
V3Number& setMask(int nbits, int lsb = 0);
|
||||
|
||||
// ACCESSORS
|
||||
string ascii(bool prefixed = true, bool cleanVerilog = false) const VL_MT_STABLE;
|
||||
|
Loading…
Reference in New Issue
Block a user