Internals: Rename widthToFit, no functional change.

This commit is contained in:
Wilson Snyder 2025-04-28 21:54:58 -04:00
parent 5083972536
commit 3658e5f0f1
6 changed files with 17 additions and 17 deletions

View File

@ -953,7 +953,7 @@ class AstConst final : public AstNodeExpr {
} else if (m_num.isString()) {
dtypeSetString();
} else {
dtypeSetLogicUnsized(m_num.width(), (m_num.sized() ? 0 : m_num.widthMin()),
dtypeSetLogicUnsized(m_num.width(), (m_num.sized() ? 0 : m_num.widthToFit()),
VSigning::fromBool(m_num.isSigned()));
}
m_num.nodep(this);
@ -1000,14 +1000,14 @@ public:
: ASTGEN_SUPER_Const(fl)
, m_num(this, 32, num) {
m_num.width(32, false);
dtypeSetLogicUnsized(32, m_num.widthMin(), VSigning::UNSIGNED);
dtypeSetLogicUnsized(32, m_num.widthToFit(), VSigning::UNSIGNED);
}
class Signed32 {}; // for creator type-overload selection
AstConst(FileLine* fl, Signed32, int32_t num) // Signed 32-bit integer of specified value
: ASTGEN_SUPER_Const(fl)
, m_num(this, 32, num) {
m_num.width(32, true);
dtypeSetLogicUnsized(32, m_num.widthMin(), VSigning::SIGNED);
dtypeSetLogicUnsized(32, m_num.widthToFit(), VSigning::SIGNED);
}
class Unsized64 {}; // for creator type-overload selection
AstConst(FileLine* fl, Unsized64, uint64_t num)

View File

@ -317,7 +317,7 @@ class ConstBitOpTreeVisitor final : public VNVisitorConst {
if (needsMasking) {
// Reduce the masked term to the minimum known width,
// to use the smallest RedXor formula
const int widthMin = maskNum.widthMin();
const int widthMin = maskNum.widthToFit();
resultp->dtypeChgWidth(widthMin, widthMin);
}
resultp = new AstRedXor{fl, resultp};
@ -1098,7 +1098,7 @@ class ConstVisitor final : public VNVisitor {
// Compute how many significant bits are in the mask
const AstConst* const constp = VN_AS(nodep->lhsp(), Const);
const uint32_t significantBits = constp->num().widthMin();
const uint32_t significantBits = constp->num().widthToFit();
AstOr* const orp = VN_AS(nodep->rhsp(), Or);
@ -3551,13 +3551,13 @@ class ConstVisitor final : public VNVisitor {
TREEOPA("AstNodeCond{$condp.isNeqZero, $thenp.castConst, $elsep.castConst}", "replaceWChild(nodep,$thenp)");
TREEOP ("AstNodeCond{$condp, operandsSame($thenp,,$elsep)}","replaceWChild(nodep,$thenp)");
// This visit function here must allow for short-circuiting.
TREEOPS("AstCond {$condp.isZero}", "replaceWIteratedThs(nodep)");
TREEOPS("AstCond {$condp.isNeqZero}", "replaceWIteratedRhs(nodep)");
TREEOP ("AstCond{$condp.castNot, $thenp, $elsep}", "AstCond{$condp->castNot()->lhsp(), $elsep, $thenp}");
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp.isAllOnes, $elsep}", "AstLogOr {$condp, $elsep}"); // a?1:b == a||b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp, $elsep.isZero, !$elsep.isClassHandleValue}", "AstLogAnd{$condp, $thenp}"); // a?b:0 == a&&b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp, $elsep.isAllOnes}", "AstLogOr {AstNot{$condp}, $thenp}"); // a?b:1 == ~a||b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp.isZero, !$thenp.isClassHandleValue, $elsep}", "AstLogAnd{AstNot{$condp}, $elsep}"); // a?0:b == ~a&&b
TREEOPS("AstCond{$condp.isZero}", "replaceWIteratedThs(nodep)");
TREEOPS("AstCond{$condp.isNeqZero}", "replaceWIteratedRhs(nodep)");
TREEOP ("AstCond{$condp.castNot, $thenp, $elsep}", "AstCond{$condp->castNot()->lhsp(), $elsep, $thenp}");
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp.isAllOnes, $elsep}", "AstLogOr {$condp, $elsep}"); // a?1:b == a||b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp, $elsep.isZero, !$elsep.isClassHandleValue}", "AstLogAnd{$condp, $thenp}"); // a?b:0 == a&&b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp, $elsep.isAllOnes}", "AstLogOr {AstNot{$condp}, $thenp}"); // a?b:1 == ~a||b
TREEOP ("AstNodeCond{$condp.width1, $thenp.width1, $thenp.isZero, !$thenp.isClassHandleValue, $elsep}", "AstLogAnd{AstNot{$condp}, $elsep}"); // a?0:b == ~a&&b
TREEOP ("AstNodeCond{!$condp.width1, operandBoolShift(nodep->condp())}", "replaceBoolShift(nodep->condp())");
// Prefer constants on left, since that often needs a shift, it lets
// constant red remove the shift

View File

@ -495,7 +495,7 @@ void EmitCFunc::emitConstant(AstConst* nodep, AstVarRef* assigntop, const string
} else if (nodep->num().isString()) {
emitConstantString(nodep);
} else if (nodep->isWide()) {
int upWidth = nodep->num().widthMin();
int upWidth = nodep->num().widthToFit();
int chunks = 0;
if (upWidth > EMITC_NUM_CONSTW * VL_EDATASIZE) {
// Output e.g. 8 words in groups of e.g. 8

View File

@ -372,7 +372,7 @@ void V3Number::create(const char* sourcep) {
// If was unsized, trim width per IEEE 1800-2023 5.7.1
if (!userSized && !m_data.m_autoExtend) {
width(std::max(32, base_align * ((widthMin() + base_align - 1) / base_align)), false);
width(std::max(32, base_align * ((widthToFit() + base_align - 1) / base_align)), false);
}
// Z or X extend specific width values. Spec says we don't 1 extend.
@ -1131,7 +1131,7 @@ int V3Number::countZ(int lsb, int nbits) const VL_MT_SAFE {
return count;
}
int V3Number::widthMin() const {
int V3Number::widthToFit() const {
for (int bit = width() - 1; bit > 0; bit--) {
if (!bitIs0(bit)) return bit + 1;
}

View File

@ -584,7 +584,7 @@ public:
string displayed(AstNode* nodep, const string& vformat) const VL_MT_STABLE;
static bool displayedFmtLegal(char format, bool isScan); // Is this a valid format letter?
int width() const VL_MT_SAFE { return m_data.width(); }
int widthMin() const; // Minimum width that can represent this number (~== log2(num)+1)
int widthToFit() const; // Minimum width that can represent this number (~== log2(num)+1)
bool sized() const VL_MT_SAFE { return m_data.m_sized; }
bool autoExtend() const VL_MT_SAFE { return m_data.m_autoExtend; }
bool isFromString() const { return m_data.m_fromString; }

View File

@ -1325,7 +1325,7 @@ class WidthVisitor final : public VNVisitor {
} else if (nodep->num().sized()) {
nodep->dtypeChgWidth(nodep->num().width(), nodep->num().width());
} else {
nodep->dtypeChgWidth(nodep->num().width(), nodep->num().widthMin());
nodep->dtypeChgWidth(nodep->num().width(), nodep->num().widthToFit());
}
}
// We don't size the constant until we commit the widths, as need parameters