Internals: Add V3Number width-and-opAssign. No functional change.

This commit is contained in:
Wilson Snyder
2025-04-30 08:08:44 -04:00
parent 5ca62de167
commit 4e667fabb7
5 changed files with 10 additions and 10 deletions
+1 -2
View File
@@ -1368,8 +1368,7 @@ class ConstVisitor final : public VNVisitor {
nodep->rhsp(smallerp); nodep->rhsp(smallerp);
constp->unlinkFrBack(); constp->unlinkFrBack();
V3Number num{constp, subsize}; V3Number num{constp, subsize, constp->num()};
num.opAssign(constp->num());
nodep->lhsp(new AstConst{constp->fileline(), num}); nodep->lhsp(new AstConst{constp->fileline(), num});
VL_DO_DANGLING(pushDeletep(constp), constp); VL_DO_DANGLING(pushDeletep(constp), constp);
if (debug() >= 9) nodep->dumpTree("- BI(EXTEND)-ou: "); if (debug() >= 9) nodep->dumpTree("- BI(EXTEND)-ou: ");
+5
View File
@@ -466,6 +466,11 @@ public:
V3Number(AstNode* nodep, int width) { // 0=unsized V3Number(AstNode* nodep, int width) { // 0=unsized
init(nodep, width, width > 0); init(nodep, width, width > 0);
} }
// Construct with value, changing to new width
V3Number(AstNode* nodep, int width, const V3Number& value) {
init(nodep, width, width > 0);
opAssign(value);
}
V3Number(AstNode* nodep, int width, uint32_t value, bool sized = true) { V3Number(AstNode* nodep, int width, uint32_t value, bool sized = true) {
init(nodep, width, sized); init(nodep, width, sized);
m_data.num()[0].m_value = value; m_data.num()[0].m_value = value;
+1 -2
View File
@@ -603,8 +603,7 @@ private:
// but in reality it would yield '0's without V3Table, so force 'x' bits to '0', // but in reality it would yield '0's without V3Table, so force 'x' bits to '0',
// to ensure the result is the same with and without V3Table. // to ensure the result is the same with and without V3Table.
if (!m_params && VN_IS(nodep, Sel) && valuep->num().isAnyX()) { if (!m_params && VN_IS(nodep, Sel) && valuep->num().isAnyX()) {
V3Number num{valuep, valuep->width()}; V3Number num{valuep, valuep->width(), valuep->num()};
num.opAssign(valuep->num());
valuep->num().opBitsOne(num); valuep->num().opBitsOne(num);
} }
} }
+2 -4
View File
@@ -6764,8 +6764,7 @@ class WidthVisitor final : public VNVisitor {
if (nodep->rhsp()->width() > 32) { if (nodep->rhsp()->width() > 32) {
if (shiftp && shiftp->num().mostSetBitP1() <= 32) { if (shiftp && shiftp->num().mostSetBitP1() <= 32) {
// If (number)<<96'h1, then make it into (number)<<32'h1 // If (number)<<96'h1, then make it into (number)<<32'h1
V3Number num(shiftp, 32, 0); V3Number num{shiftp, 32, shiftp->num()};
num.opAssign(shiftp->num());
AstNode* const shiftrhsp = nodep->rhsp(); AstNode* const shiftrhsp = nodep->rhsp();
nodep->rhsp()->replaceWith(new AstConst{shiftrhsp->fileline(), num}); nodep->rhsp()->replaceWith(new AstConst{shiftrhsp->fileline(), num});
VL_DO_DANGLING(shiftrhsp->deleteTree(), shiftrhsp); VL_DO_DANGLING(shiftrhsp->deleteTree(), shiftrhsp);
@@ -6935,8 +6934,7 @@ class WidthVisitor final : public VNVisitor {
const int expWidth = expDTypep->width(); const int expWidth = expDTypep->width();
if (constp && !constp->num().isNegative()) { if (constp && !constp->num().isNegative()) {
// Save later constant propagation work, just right-size it. // Save later constant propagation work, just right-size it.
V3Number num(nodep, expWidth); V3Number num{nodep, expWidth, constp->num()};
num.opAssign(constp->num());
num.isSigned(false); num.isSigned(false);
AstNodeExpr* const newp = new AstConst{nodep->fileline(), num}; AstNodeExpr* const newp = new AstConst{nodep->fileline(), num};
constp->replaceWith(newp); constp->replaceWith(newp);
+1 -2
View File
@@ -30,8 +30,7 @@ public:
static AstConst* newIfConstCommitSize(AstConst* nodep) { static AstConst* newIfConstCommitSize(AstConst* nodep) {
if (((nodep->dtypep()->width() != nodep->num().width()) || !nodep->num().sized()) if (((nodep->dtypep()->width() != nodep->num().width()) || !nodep->num().sized())
&& !nodep->num().isString()) { // Need to force the number from unsized to sized && !nodep->num().isString()) { // Need to force the number from unsized to sized
V3Number num{nodep, nodep->dtypep()->width()}; V3Number num{nodep, nodep->dtypep()->width(), nodep->num()};
num.opAssign(nodep->num());
num.isSigned(nodep->isSigned()); num.isSigned(nodep->isSigned());
AstConst* const newp = new AstConst{nodep->fileline(), num}; AstConst* const newp = new AstConst{nodep->fileline(), num};
newp->dtypeFrom(nodep); newp->dtypeFrom(nodep);