Skip to content

Commit

Permalink
Add lsb index to V3Number::setMask
Browse files Browse the repository at this point in the history
  • Loading branch information
gezalore committed Oct 8, 2024
1 parent b873c23 commit 24cb6ec
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 14 deletions.
9 changes: 4 additions & 5 deletions src/V3Const.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
5 changes: 1 addition & 4 deletions src/V3Delayed.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
4 changes: 2 additions & 2 deletions src/V3Expand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions src/V3Number.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
3 changes: 2 additions & 1 deletion src/V3Number.h
Original file line number Diff line number Diff line change
Expand Up @@ -576,7 +576,8 @@ class V3Number final {
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;
Expand Down

0 comments on commit 24cb6ec

Please sign in to comment.