Internals: Rename range lo/hi to match IEEE.

This commit is contained in:
Wilson Snyder 2013-01-17 20:29:20 -05:00
parent 385c166830
commit bbeb382cbb
5 changed files with 40 additions and 43 deletions

View File

@ -527,8 +527,8 @@ public:
// See also AstRange, which is a symbolic version of this
struct VNumRange {
int m_msb; // MSB, MSB always >= LSB
int m_lsb; // LSB
int m_hi; // HI part, HI always >= LO
int m_lo; // LO
union {
int mu_flags;
struct {
@ -537,38 +537,38 @@ struct VNumRange {
};
};
inline bool operator== (const VNumRange& rhs) const {
return m_msb == rhs.m_msb
&& m_lsb == rhs.m_lsb
return m_hi == rhs.m_hi
&& m_lo == rhs.m_lo
&& mu_flags == rhs.mu_flags; }
inline bool operator< (const VNumRange& rhs) const {
if ( (m_msb < rhs.m_msb)) return true;
if (!(m_msb == rhs.m_msb)) return false; // lhs > rhs
if ( (m_lsb < rhs.m_lsb)) return true;
if (!(m_lsb == rhs.m_lsb)) return false; // lhs > rhs
if ( (m_hi < rhs.m_hi)) return true;
if (!(m_hi == rhs.m_hi)) return false; // lhs > rhs
if ( (m_lo < rhs.m_lo)) return true;
if (!(m_lo == rhs.m_lo)) return false; // lhs > rhs
if ( (mu_flags < rhs.mu_flags)) return true;
if (!(mu_flags == rhs.mu_flags)) return false; // lhs > rhs
return false;
}
//
VNumRange() : m_msb(0), m_lsb(0), mu_flags(0) {}
VNumRange(int msb, int lsb, bool littleEndian)
: m_msb(0), m_lsb(0), mu_flags(0)
{ init(msb,lsb,littleEndian); }
VNumRange() : m_hi(0), m_lo(0), mu_flags(0) {}
VNumRange(int hi, int lo, bool littleEndian)
: m_hi(0), m_lo(0), mu_flags(0)
{ init(hi,lo,littleEndian); }
~VNumRange() {}
// MEMBERS
void init(int msb, int lsb, bool littleEndian) {
m_msb=msb; m_lsb=lsb; mu_flags=0; m_ranged=true; m_littleEndian=littleEndian;
void init(int hi, int lo, bool littleEndian) {
m_hi=hi; m_lo=lo; mu_flags=0; m_ranged=true; m_littleEndian=littleEndian;
}
int msb() const { return m_msb; }
int lsb() const { return m_lsb; }
int left() const { return littleEndian()?lsb():msb(); } // How to show a declaration
int right() const { return littleEndian()?msb():lsb(); }
int elements() const { return msb()-lsb()+1; }
int hi() const { return m_hi; }
int lo() const { return m_lo; }
int left() const { return littleEndian()?lo():hi(); } // How to show a declaration
int right() const { return littleEndian()?hi():lo(); }
int elements() const { return hi()-lo()+1; }
bool ranged() const { return m_ranged; }
bool littleEndian() const { return m_littleEndian; }
int msbMaxSelect() const { return (lsb()<0 ? msb()-lsb() : msb()); } // Maximum value a [] select may index
int hiMaxSelect() const { return (lo()<0 ? hi()-lo() : hi()); } // Maximum value a [] select may index
bool representableByWidth() const // Could be represented by just width=1, or [width-1:0]
{ return (!m_ranged || (m_lsb==0 && m_msb>=1 && !m_littleEndian)); }
{ return (!m_ranged || (m_lo==0 && m_hi>=1 && !m_littleEndian)); }
};
//######################################################################
@ -1559,7 +1559,6 @@ public:
}
int lsb() const { return 0; }
int msb() const { return dtypep()->width()-1; } // Packed classes look like arrays
int msbMaxSelect() const { return msb(); }
};
struct AstNodeArrayDType : public AstNodeDType {
@ -1602,7 +1601,6 @@ public:
int msb() const;
int lsb() const;
int elementsConst() const;
int msbMaxSelect() const { return (lsb()<0 ? msb()-lsb() : msb()); } // Maximum value a [] select may index
};
struct AstNodeSel : public AstNodeBiop {

View File

@ -343,7 +343,7 @@ private:
public:
ASTNODE_NODE_FUNCS(BasicDType, BASICDTYPE)
virtual void dump(ostream& str);
virtual V3Hash sameHash() const { return V3Hash(V3Hash(m.m_keyword), V3Hash(m.m_nrange.msb())); }
virtual V3Hash sameHash() const { return V3Hash(V3Hash(m.m_keyword), V3Hash(m.m_nrange.hi())); }
virtual bool same(AstNode* samep) const { // width/widthMin/numeric compared elsewhere
return samep->castBasicDType()->m == m; }
virtual string name() const { return m.m_keyword.ascii(); }
@ -368,11 +368,10 @@ public:
bool isZeroInit() const { return keyword().isZeroInit(); }
bool isRanged() const { return rangep() || m.m_nrange.ranged(); }
const VNumRange& nrange() const { return m.m_nrange; } // Generally the msb/lsb/etc funcs should be used instead
int msb() const { return (rangep() ? rangep()->msbConst() : m.m_nrange.msb()); }
int lsb() const { return (rangep() ? rangep()->lsbConst() : m.m_nrange.lsb()); }
int msb() const { return (rangep() ? rangep()->msbConst() : m.m_nrange.hi()); }
int lsb() const { return (rangep() ? rangep()->lsbConst() : m.m_nrange.lo()); }
int left() const { return littleEndian()?lsb():msb(); } // How to show a declaration
int right() const { return littleEndian()?msb():lsb(); }
int msbMaxSelect() const { return (lsb()<0 ? msb()-lsb() : msb()); } // Maximum value a [] select may index
bool littleEndian() const { return (rangep() ? rangep()->littleEndian() : m.m_nrange.littleEndian()); }
bool implicit() const { return keyword() == AstBasicDTypeKwd::LOGIC_IMPLICIT; }
void cvtRangeConst() { // Convert to smaller represenation

View File

@ -382,7 +382,7 @@ private:
&& nodep->lsbp()->castConst()
&& nodep->widthp()->castConst()
&& doit) {
int maxDeclBit = nodep->declRange().msbMaxSelect()*nodep->declElWidth() + (nodep->declElWidth()-1);
int maxDeclBit = nodep->declRange().hiMaxSelect()*nodep->declElWidth() + (nodep->declElWidth()-1);
if (nodep->lsbp()->castConst()->num().isFourState()
|| nodep->widthp()->castConst()->num().isFourState()) {
nodep->v3error("Selection index is constantly unknown or tristated: "
@ -398,9 +398,9 @@ private:
nodep->v3warn(SELRANGE, "Selection index out of range: "
<<(nodep->msbConst()/nodep->declElWidth())
<<":"<<(nodep->lsbConst()/nodep->declElWidth())
<<" outside "<<nodep->declRange().msbMaxSelect()<<":0"
<<(nodep->declRange().lsb()>=0 ? ""
:(" (adjusted +"+cvtToStr(-nodep->declRange().lsb())
<<" outside "<<nodep->declRange().hiMaxSelect()<<":0"
<<(nodep->declRange().lo()>=0 ? ""
:(" (adjusted +"+cvtToStr(-nodep->declRange().lo())
+" to account for negative lsb)")));
UINFO(1," Related Raw index is "<<nodep->msbConst()<<":"<<nodep->lsbConst()<<endl);
// Don't replace with zero, we'll do it later

View File

@ -442,8 +442,8 @@ private:
int fromlsb = 0;
int elw = nodep->declElWidth(); // Must adjust to tell user bit ranges
if (nodep->declRange().ranged()) {
frommsb = nodep->declRange().msbMaxSelect()*elw + (elw-1); // Corrected for negative lsb
fromlsb = nodep->declRange().lsb()*elw;
frommsb = nodep->declRange().hiMaxSelect()*elw + (elw-1); // Corrected for negative lsb
fromlsb = nodep->declRange().lo()*elw;
} else {
//nodep->v3fatalSrc("Should have been declRanged in V3WidthSel");
}

View File

@ -171,11 +171,11 @@ private:
} else {
if (fromRange.littleEndian()) {
// reg [1:3] was swapped to [3:1] (lsbEndianedp==3) and needs a SUB(3,under)
AstNode* newp = newSubNeg(fromRange.msb(), underp);
AstNode* newp = newSubNeg(fromRange.hi(), underp);
return newp;
} else {
// reg [3:1] needs a SUB(under,1)
AstNode* newp = newSubNeg(underp, fromRange.lsb());
AstNode* newp = newSubNeg(underp, fromRange.lo());
return newp;
}
}
@ -200,8 +200,8 @@ private:
if (AstUnpackArrayDType* adtypep = ddtypep->castUnpackArrayDType()) {
// SELBIT(array, index) -> ARRAYSEL(array, index)
AstNode* subp = rhsp;
if (fromRange.lsb()!=0 || fromRange.msb()<0) {
subp = newSubNeg (subp, fromRange.lsb());
if (fromRange.lo()!=0 || fromRange.hi()<0) {
subp = newSubNeg (subp, fromRange.lo());
}
AstArraySel* newp = new AstArraySel (nodep->fileline(),
fromp, subp);
@ -212,8 +212,8 @@ private:
else if (AstPackArrayDType* adtypep = ddtypep->castPackArrayDType()) {
// SELBIT(array, index) -> SEL(array, index*width-of-subindex, width-of-subindex)
AstNode* subp = rhsp;
if (fromRange.lsb()!=0 || fromRange.msb()<0) {
subp = newSubNeg (subp, fromRange.lsb());
if (fromRange.lo()!=0 || fromRange.hi()<0) {
subp = newSubNeg (subp, fromRange.lo());
}
if (!fromRange.elements() || (adtypep->width() % fromRange.elements())!=0)
adtypep->v3fatalSrc("Array extraction with width miscomputed "
@ -365,13 +365,13 @@ private:
// SELPLUS(from,lsb,width) -> SEL(from, (vector_msb-width+1)-sel, width)
newp = new AstSel (nodep->fileline(),
fromp,
newSubNeg((fromRange.msb()-width+1), rhsp),
newSubNeg((fromRange.hi()-width+1), rhsp),
widthp);
} else {
// SELPLUS(from,lsb,width) -> SEL(from, lsb-vector_lsb, width)
newp = new AstSel (nodep->fileline(),
fromp,
newSubNeg(rhsp, fromRange.lsb()),
newSubNeg(rhsp, fromRange.lo()),
widthp);
}
} else if (nodep->castSelMinus()) {
@ -379,13 +379,13 @@ private:
// SELMINUS(from,msb,width) -> SEL(from, msb-[bit])
newp = new AstSel (nodep->fileline(),
fromp,
newSubNeg(fromRange.msb(), rhsp),
newSubNeg(fromRange.hi(), rhsp),
widthp);
} else {
// SELMINUS(from,msb,width) -> SEL(from, msb-(width-1)-lsb#)
newp = new AstSel (nodep->fileline(),
fromp,
newSubNeg(rhsp, fromRange.lsb()+(width-1)),
newSubNeg(rhsp, fromRange.lo()+(width-1)),
widthp);
}
} else {