Skip to content

Commit fd944fe

Browse files
committed
checker: improved node ID/name generation for PinGraph
1 parent 4247e7f commit fd944fe

File tree

6 files changed

+107
-33
lines changed

6 files changed

+107
-33
lines changed

planning/src/file_io/pln_blif_file.cpp

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -422,6 +422,8 @@ bool BLIF_file::checkBlif() noexcept {
422422

423423
// 6. clock-data separation
424424
if (!topInputs_.empty() and !topOutputs_.empty()) {
425+
if (trace_ >= 5)
426+
pg_.setTrace(trace_);
425427
vector<const BNode*> clocked;
426428
collectClockedNodes(clocked);
427429
uint clocked_sz = clocked.size();
@@ -1656,7 +1658,8 @@ bool BLIF_file::createPinGraph() noexcept {
16561658
assert(nid);
16571659
pg_.nodeRef(nid).markInp(true);
16581660
assert(not pg_.nodeRef(nid).isNamed());
1659-
pg_.setNodeName(nid, port.out_);
1661+
//pg_.setNodeName(nid, port.out_);
1662+
pg_.setNodeName3(nid, port.id_, port.lnum_, port.out_.c_str());
16601663
port.nw_id_ = nid;
16611664
pg2blif_.emplace(nid, port.id_);
16621665
}
@@ -1669,7 +1672,8 @@ bool BLIF_file::createPinGraph() noexcept {
16691672
assert(nid);
16701673
pg_.nodeRef(nid).markOut(true);
16711674
assert(not pg_.nodeRef(nid).isNamed());
1672-
pg_.setNodeName(nid, port.out_);
1675+
//pg_.setNodeName(nid, port.out_);
1676+
pg_.setNodeName3(nid, port.id_, port.lnum_, port.out_.c_str());
16731677
port.nw_id_ = nid;
16741678
pg2blif_.emplace(nid, port.id_);
16751679
}
@@ -1716,7 +1720,7 @@ bool BLIF_file::createPinGraph() noexcept {
17161720
}
17171721

17181722
assert(par.cell_hc_);
1719-
key = hashComb(par.cell_hc_, pinIndex);
1723+
key = hashCantor(par.id_, pinIndex+1);
17201724
assert(key);
17211725
assert(not pg_.hasKey(key));
17221726
kid = pg_.insK(key);
@@ -1731,9 +1735,12 @@ bool BLIF_file::createPinGraph() noexcept {
17311735
par.lnum_, par.id_, pinIndex);
17321736

17331737
assert(not pg_.nodeRef(kid).inp_flag_);
1734-
pg_.setNodeName(kid, nm_buf);
1738+
pg_.setNodeName3(kid, par.id_, par.lnum_);
17351739
pg_.nodeRef(kid).markClk(is_clock);
17361740

1741+
if (trace_ >= 6)
1742+
lprintf(" ALT nodeName %s --> %s\n", pg_.cnodeName(kid), nm_buf);
1743+
17371744
eid = pg_.linK(port.id_, key);
17381745
assert(eid);
17391746

@@ -1756,17 +1763,21 @@ bool BLIF_file::createPinGraph() noexcept {
17561763
BNode& bnode = bnodeRef(q.cellId_);
17571764
assert(not bnode.isTopPort());
17581765

1759-
uint64_t qk = bnode.cellHash0(); // hashComb(q.cellId_, q.outNet_);
1766+
uint64_t qk = bnode.cellHash0();
17601767
assert(qk);
17611768
kid = pg_.insK(qk);
17621769
eid = pg_.linkNodes(q.inpNid_, kid, true);
17631770

17641771
::snprintf(nm_buf, 510, "nd%u_L%u_Q%u",
17651772
kid, bnode.lnum_, q.cellId_);
1773+
17661774
assert(not pg_.nodeRef(kid).inp_flag_);
1767-
pg_.setNodeName(kid, nm_buf);
1775+
pg_.setNodeName3(kid, bnode.id_, bnode.lnum_);
17681776
bnode.nw_id_ = kid;
17691777
pg2blif_.emplace(kid, bnode.id_);
1778+
1779+
if (trace_ >= 6)
1780+
lprintf(" ALT nodeName %s --> %s\n", pg_.cnodeName(kid), nm_buf);
17701781
}
17711782
}
17721783

@@ -1789,17 +1800,18 @@ bool BLIF_file::createPinGraph() noexcept {
17891800
if (not pr_pin_is_clock(cn.ptype_, inp))
17901801
continue;
17911802
assert(cn.cell_hc_);
1792-
key = hashComb(cn.cell_hc_, inp);
1803+
key = hashCantor(cn.id_, i + 1);
17931804
assert(key);
1794-
assert(not pg_.hasKey(key));
1805+
// assert(not pg_.hasKey(key));
17951806
kid = pg_.insK(key);
17961807
assert(kid);
17971808
pg_.nodeRef(kid).markClk(true);
17981809

17991810
::snprintf(nm_buf, 510, "nd%u_L%u_cn",
18001811
kid, cn.lnum_);
1812+
18011813
assert(not pg_.nodeRef(kid).inp_flag_);
1802-
pg_.setNodeName(kid, nm_buf);
1814+
pg_.setNodeName4(kid, cn.id_, cn.lnum_, i+1, cn.cPrimType());
18031815
pg2blif_.emplace(kid, cn.id_);
18041816

18051817
const string& inet = cn.inSigs_[i];
@@ -1829,7 +1841,7 @@ bool BLIF_file::createPinGraph() noexcept {
18291841
return false;
18301842
}
18311843

1832-
uint64_t opin_key = driver->cellHash0(); // hashComb(driver->id_, driver->out_);
1844+
uint64_t opin_key = driver->cellHash0();
18331845
assert(opin_key);
18341846
uint opin_nid = pg_.findNode(opin_key);
18351847
if (opin_nid) {
@@ -1847,8 +1859,10 @@ bool BLIF_file::createPinGraph() noexcept {
18471859
assert(not outPin.empty());
18481860
::strcat(nm_buf, outPin.c_str());
18491861
}
1862+
18501863
assert(not pg_.nodeRef(opin_nid).inp_flag_);
1851-
pg_.setNodeName(opin_nid, nm_buf);
1864+
pg_.setNodeName3(opin_nid, driver->id_,
1865+
driver->lnum_, driver->out_.c_str());
18521866
pg2blif_.emplace(opin_nid, driver->id_);
18531867
}
18541868

@@ -1874,7 +1888,7 @@ bool BLIF_file::createPinGraph() noexcept {
18741888
return false;
18751889
}
18761890

1877-
uint64_t ipin_key = hashComb(dn.id_, inp1);
1891+
uint64_t ipin_key = hashCantor(dn.id_, 1);
18781892
assert(ipin_key);
18791893
uint ipin_nid = pg_.findNode(ipin_key);
18801894
if (ipin_nid) {
@@ -1893,7 +1907,7 @@ bool BLIF_file::createPinGraph() noexcept {
18931907
::strcat(nm_buf, inpPin.c_str());
18941908
}
18951909
assert(not pg_.nodeRef(ipin_nid).inp_flag_);
1896-
pg_.setNodeName(ipin_nid, nm_buf);
1910+
pg_.setNodeName3(ipin_nid, dn.id_, dn.lnum_, dn.out_.c_str());
18971911
pg2blif_.emplace(ipin_nid, dn.id_);
18981912
}
18991913

@@ -1951,7 +1965,7 @@ bool BLIF_file::createPinGraph() noexcept {
19511965
}
19521966
else {
19531967

1954-
drv_drv_outKey = drv_drv->cellHash0(); // hashComb(drv_drv->cell_hc_, drv_drv->out_);
1968+
drv_drv_outKey = drv_drv->cellHash0();
19551969
assert(drv_drv_outKey);
19561970
drv_drv_outNid = pg_.insK(drv_drv_outKey);
19571971
assert(drv_drv_outNid);
@@ -1967,8 +1981,10 @@ bool BLIF_file::createPinGraph() noexcept {
19671981
assert(not outPin.empty());
19681982
::strcat(nm_buf, outPin.c_str());
19691983
}
1984+
19701985
assert(not pg_.nodeRef(drv_drv_outNid).inp_flag_);
1971-
pg_.setNodeName(drv_drv_outNid, nm_buf);
1986+
pg_.setNodeName3(drv_drv_outNid, drv_drv->id_,
1987+
drv_drv->lnum_, drv_drv->out_.c_str());
19721988
}
19731989

19741990
}

planning/src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
static const char* _pln_VERSION_STR = "pln0329";
1+
static const char* _pln_VERSION_STR = "pln0330";
22

33
#include "RS/rsEnv.h"
44
#include "util/pln_log.h"

planning/src/util/geo/iv.h

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,18 @@ inline uint64_t hashComb(uint64_t a, const std::string& s) noexcept {
4444
return hashComb(a, str::hashf(s));
4545
}
4646

47-
inline constexpr int protectedAdd(int a, int b) noexcept {
47+
inline constexpr uint64_t hashCantor(uint64_t a, uint64_t b) noexcept {
48+
return ((a + b) >> 1) * (a + b + 1) + b;
49+
}
50+
51+
inline constexpr int protAdd(int a, int b) noexcept {
4852
int64_t c = int64_t(a) + int64_t(b);
4953
if (c > INT_MAX) return INT_MAX;
5054
if (c < INT_MIN) return INT_MIN;
5155
return c;
5256
}
5357

54-
inline constexpr int protectedSub(int a, int b) noexcept {
58+
inline constexpr int protSub(int a, int b) noexcept {
5559
int64_t c = int64_t(a) - int64_t(b);
5660
if (c > INT_MAX) return INT_MAX;
5761
if (c < INT_MIN) return INT_MIN;
@@ -66,7 +70,7 @@ inline constexpr int64_t sub64(int a, int b) noexcept {
6670
return int64_t(a) - int64_t(b);
6771
}
6872

69-
inline constexpr int protectedRound(double x) noexcept {
73+
inline constexpr int protRound(double x) noexcept {
7074
if (x >= 0) {
7175
if (x >= double(INT_MAX) - 0.5) return INT_MAX;
7276
return x + 0.5;
@@ -75,15 +79,15 @@ inline constexpr int protectedRound(double x) noexcept {
7579
return x - 0.5;
7680
}
7781

78-
inline constexpr int inlineRound(double x) noexcept {
82+
inline constexpr int fastRound(double x) noexcept {
7983
return x >= 0 ? x + 0.5 : x - 0.5;
8084
}
8185

82-
inline constexpr int64_t inlineRound64(double x) noexcept {
86+
inline constexpr int64_t fastRound64(double x) noexcept {
8387
return x >= 0 ? int64_t(x + 0.5) : int64_t(x - 0.5);
8488
}
8589

86-
inline constexpr int64_t protectedRound64(double x) noexcept {
90+
inline constexpr int64_t protRound64(double x) noexcept {
8791
if (x >= 0) {
8892
if (x >= double(LLONG_MAX) - 0.5) return LLONG_MAX;
8993
return int64_t(x + 0.5);

planning/src/util/nw/Nw.cpp

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,28 @@
1313

1414
namespace pln {
1515

16+
void NW::clear() noexcept {
17+
nids_.clear();
18+
rids_.clear();
19+
ndStor_.clear();
20+
edStor_.clear();
21+
nw_name_.clear();
22+
ndStor_.emplace_back();
23+
edStor_.emplace_back();
24+
}
25+
26+
void NW::setTrace(int t) noexcept {
27+
if (t <= 0) {
28+
trace_ = 0;
29+
return;
30+
}
31+
if (t >= USHRT_MAX) {
32+
trace_ = USHRT_MAX;
33+
return;
34+
}
35+
trace_ = t;
36+
}
37+
1638
uint NW::insK(uint64_t k) noexcept {
1739
assert(k);
1840
if (empty()) return addNode(k);

planning/src/util/nw/Nw.h

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,8 @@ struct NW {
250250
NW(const NW& g) noexcept;
251251
NW& operator=(const NW& g) noexcept;
252252

253+
void setTrace(int t) noexcept;
254+
253255
void reserve(uint cap) noexcept {
254256
if (!cap) return;
255257
assert(cap < uint(INT_MAX));
@@ -332,6 +334,13 @@ struct NW {
332334

333335
void setNodeName(uint id, CStr nm) noexcept;
334336
void setNodeName(uint id, const string& nm) noexcept { setNodeName(id, nm.c_str()); }
337+
void setNodeName3(uint id, uint B, uint L, CStr a = nullptr) noexcept;
338+
void setNodeName4(uint id, uint B, uint L, uint ipin, CStr a = nullptr) noexcept;
339+
340+
CStr cnodeName(uint id) const noexcept {
341+
assert(hasNode(id));
342+
return nodeRef(id).name_.c_str();
343+
}
335344

336345
void setNwName(CStr nm) noexcept {
337346
if (nm and nm[0])
@@ -356,7 +365,7 @@ struct NW {
356365
void getIncoE(const Node& nd, vecu& E) const noexcept;
357366
void getOutgE(const Node& nd, vecu& E) const noexcept;
358367

359-
inline void clear() noexcept;
368+
void clear() noexcept;
360369
void clearEdges() noexcept;
361370

362371
const Node* parPtr(const Node& nd) const noexcept {
@@ -722,15 +731,6 @@ struct NW::ChldNI : public NW::OutgEI {
722731
}
723732
};
724733

725-
inline void NW::clear() noexcept {
726-
nids_.clear();
727-
rids_.clear();
728-
ndStor_.clear();
729-
edStor_.clear();
730-
ndStor_.emplace_back();
731-
edStor_.emplace_back();
732-
}
733-
734734
inline uint NW::addNode(const XY& p, uint64_t k) noexcept {
735735
if (ndStor_.empty()) ndStor_.emplace_back();
736736

planning/src/util/nw/Nw_node.cpp

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,46 @@ void NW::setNodeName(uint id, CStr nm) noexcept {
9696
// lputs1();
9797

9898
if (nm) {
99-
lprintf(" (setNodeName) %u --> %s\n", id, nm);
99+
if (trace_ >= 6)
100+
lprintf(" (setNodeName) %u --> %s\n", id, nm);
100101
nodeRefCk(id).name_ = nm;
101102
return;
102103
}
103104

104105
nodeRefCk(id).name_.clear();
105106
}
106107

108+
void NW::setNodeName3(uint id, uint B, uint L, CStr a) noexcept {
109+
char buf[128];
110+
Node& nd = nodeRefCk(id);
111+
char c = 'n';
112+
if (nd.inp_flag_)
113+
c = 'i';
114+
else if (nd.out_flag_)
115+
c = 'o';
116+
::sprintf(buf, "%c%uB%uL%u_", c, id, B, L);
117+
nd.name_ = str::concat(buf, a);
118+
119+
if (trace_ >= 6)
120+
lprintf(" (setNodeName3) %u --> %s\n", id, nd.name_.c_str());
121+
}
122+
123+
void NW::setNodeName4(uint id, uint B, uint L, uint ipin, CStr a) noexcept {
124+
char buf[128];
125+
Node& nd = nodeRefCk(id);
126+
char c = 'n';
127+
if (nd.inp_flag_)
128+
c = 'i';
129+
else if (nd.out_flag_)
130+
c = 'o';
131+
::sprintf(buf, "%c%uB%uL%u_p%u", c, id, B, L, ipin);
132+
133+
nd.name_ = str::concat(buf, a);
134+
135+
if (trace_ >= 6)
136+
lprintf(" (setNodeName4) %u --> %s\n", id, nd.name_.c_str());
137+
}
138+
107139
uint NW::countRedEdges() const noexcept {
108140
uint cnt = 0;
109141
for (cEI I(*this); I.valid(); ++I) {

0 commit comments

Comments
 (0)