Skip to content

Commit 3d53695

Browse files
authored
Merge pull request #789 from os-fpga/checker_now_works_on_simple_cases
checker: clock separation check now works on simple cases
2 parents 40ec321 + 36d368f commit 3d53695

File tree

5 files changed

+167
-41
lines changed

5 files changed

+167
-41
lines changed

planning/src/file_readers/pln_blif_file.cpp

Lines changed: 84 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -439,8 +439,16 @@ bool BLIF_file::checkBlif() noexcept {
439439
flush_out(true);
440440
return false;
441441
}
442-
if (trace_ >= 4)
442+
if (trace_ >= 4) {
443443
lputs("(clock-data separation) checked OK.");
444+
if (trace_ >= 5) {
445+
flush_out(true);
446+
pg_.print(ls, " [[ final pinGraph ]]");
447+
flush_out(true);
448+
pg_.printEdges(ls, "[[ edges of pinGraph ]]");
449+
flush_out(true);
450+
}
451+
}
444452
}
445453
flush_out(true);
446454
}
@@ -1027,7 +1035,6 @@ bool BLIF_file::createNodes() noexcept {
10271035
Fio::split_spa(buf, V);
10281036
if (not V.empty()) nd.out_ = V.back();
10291037
}
1030-
// lputs9();
10311038
// fill inPins_, inSigs_:
10321039
nd.inPins_.clear();
10331040
nd.inSigs_.clear();
@@ -1324,7 +1331,6 @@ bool BLIF_file::linkNodes() noexcept {
13241331
lout() << pinToken << endl;
13251332
if (not par->isLatch()) {
13261333
// skipping latches for now
1327-
// lputs9();
13281334
err_msg_.reserve(224);
13291335
err_msg_ = "output port contacts fabric input: port= ",
13301336
err_msg_ += nd.out_;
@@ -1434,6 +1440,11 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
14341440
if (pg_.size() < 3)
14351441
return true;
14361442

1443+
if (trace_ >= 3) {
1444+
lprintf(" number of clock nodes = %u\n",
1445+
pg_.countClockNodes());
1446+
}
1447+
14371448
if (not pg_.hasClockNodes())
14381449
return true;
14391450

@@ -1448,8 +1459,43 @@ bool BLIF_file::checkClockSepar(vector<const Node*>& clocked) noexcept {
14481459
}
14491460
}
14501461
}
1462+
// -- paint nodes contacted by red edges
1463+
for (NW::cEI E(pg_); E.valid(); ++E) {
1464+
const NW::Edge& ed = *E;
1465+
if (ed.isRed()) {
1466+
pg_.nodeRef(ed.n1_).paintRed();
1467+
pg_.nodeRef(ed.n2_).paintRed();
1468+
}
1469+
}
1470+
// -- for red input ports, paint their outgoing edges Red
1471+
for (const Node* p : topInputs_) {
1472+
const Node& port = *p;
1473+
assert(port.nw_id_);
1474+
NW::Node& nw_node = pg_.nodeRefCk(port.nw_id_);
1475+
for (NW::OutgEI J(pg_, nw_node); J.valid(); ++J) {
1476+
uint eid = J->id_;
1477+
pg_.edgeRef(eid).paintRed();
1478+
}
1479+
}
14511480

1452-
return true;
1481+
writePinGraph("pin_graph_2.dot");
1482+
1483+
bool color_ok = true;
1484+
1485+
// -- check that end-points of red edges are red
1486+
for (NW::cEI E(pg_); E.valid(); ++E) {
1487+
const NW::Edge& ed = *E;
1488+
if (not ed.isRed())
1489+
continue;
1490+
const NW::Node& p1 = pg_.nodeRef(ed.n1_);
1491+
const NW::Node& p2 = pg_.nodeRef(ed.n2_);
1492+
if (!p1.isRed() or !p2.isRed()) {
1493+
color_ok = false;
1494+
break;
1495+
}
1496+
}
1497+
1498+
return color_ok;
14531499
}
14541500

14551501
struct qTup {
@@ -1472,7 +1518,6 @@ struct qTup {
14721518
};
14731519

14741520
bool BLIF_file::createPinGraph() noexcept {
1475-
auto& ls = lout();
14761521
pg_.clear();
14771522
if (!rd_ok_) return false;
14781523
if (topInputs_.empty() and topOutputs_.empty()) return false;
@@ -1486,23 +1531,25 @@ bool BLIF_file::createPinGraph() noexcept {
14861531
char nm_buf[512] = {};
14871532

14881533
// -- create pg-nodes for topInputs_
1489-
for (const Node* p : topInputs_) {
1490-
const Node& port = *p;
1534+
for (Node* p : topInputs_) {
1535+
Node& port = *p;
14911536
assert(!port.out_.empty());
14921537
nid = pg_.insK(port.id_);
14931538
assert(nid);
14941539
pg_.setNodeName(nid, port.out_);
14951540
pg_.nodeRef(nid).markInp(true);
1541+
port.nw_id_ = nid;
14961542
}
14971543

14981544
// -- create pg-nodes for topOutputs_
1499-
for (const Node* p : topOutputs_) {
1500-
const Node& port = *p;
1545+
for (Node* p : topOutputs_) {
1546+
Node& port = *p;
15011547
assert(!port.out_.empty());
15021548
nid = pg_.insK(port.id_);
15031549
assert(nid);
15041550
pg_.setNodeName(nid, port.out_);
15051551
pg_.nodeRef(nid).markOut(true);
1552+
port.nw_id_ = nid;
15061553
}
15071554

15081555
vector<qTup> Q;
@@ -1592,24 +1639,39 @@ bool BLIF_file::createPinGraph() noexcept {
15921639
}
15931640
}
15941641

1595-
if (1) {
1642+
pg_.setNwName("pin_graph");
15961643

1597-
flush_out(true);
1598-
pg_.setNwName("pin_graph");
1599-
pg_.dump("\t *** pin_graph for clock-data separation ***");
1600-
lprintf("\t pg_. numN()= %u numE()= %u\n", pg_.numN(), pg_.numE());
1601-
lputs();
1602-
pg_.printSum(ls, 0);
1603-
lputs();
1604-
pg_.dumpEdges("|edges|");
1605-
lputs();
1644+
// writePinGraph("pin_graph_1.dot");
16061645

1607-
bool wrDot_ok = pg_.writeDot("pinGraph.dot", nullptr, true, true);
1608-
lprintf("wrDot_ok:%i\n", wrDot_ok);
1646+
return true;
1647+
}
16091648

1649+
bool BLIF_file::writePinGraph(CStr fn) const noexcept {
1650+
auto& ls = lout();
1651+
flush_out(true);
1652+
pg_.print(ls, "\t *** pin_graph for clock-data separation ***");
1653+
lprintf("\t pg_. numN()= %u numE()= %u\n", pg_.numN(), pg_.numE());
1654+
lputs();
1655+
pg_.printSum(ls, 0);
1656+
lputs();
1657+
pg_.printEdges(ls, "|edges|");
1658+
flush_out(true);
1659+
1660+
if (!fn or !fn[0])
1661+
fn = "pinGraph.dot";
1662+
1663+
bool wrDot_ok = pg_.writeDot(fn, nullptr, true, true);
1664+
if (!wrDot_ok) {
1665+
flush_out(true); err_puts();
1666+
lprintf2("[Error] could not write pin_graph to file '%s'\n", fn);
1667+
err_puts(); flush_out(true);
16101668
}
16111669

1612-
return true;
1670+
lprintf("(writePinGraph) status:%i file: %s\n",
1671+
wrDot_ok, fn);
1672+
1673+
flush_out(true);
1674+
return wrDot_ok;
16131675
}
16141676

16151677
}

planning/src/file_readers/pln_blif_file.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ struct BLIF_file : public fio::MMapReader
1818
// Input ports are leaves.
1919
// Output ports are roots of fanin cones.
2020
struct Node {
21-
uint id_ = 0; // index+1 in pool
22-
uint lnum_ = 0; // line number in blif
21+
uint id_ = 0; // index+1 in pool
22+
uint nw_id_ = 0; // node-id in NW, for ports only
23+
24+
uint lnum_ = 0; // line number in blif
2325
uint parent_ = 0;
2426
uint depth_ = 0;
2527
vector<uint> chld_;
@@ -236,6 +238,7 @@ struct BLIF_file : public fio::MMapReader
236238

237239
bool createPinGraph() noexcept;
238240
bool linkPinGraph() noexcept;
241+
bool writePinGraph(CStr fn) const noexcept;
239242

240243
bool checkClockSepar(vector<const Node*>& clocked) noexcept;
241244

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 = "pln0304";
1+
static const char* _pln_VERSION_STR = "pln0306";
22

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

planning/src/util/nw/Nw.cpp

Lines changed: 62 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -144,12 +144,15 @@ void NW::rmNode(uint x) noexcept {
144144
rm.inval();
145145
}
146146

147-
void NW::getTopo(vecu& topo) noexcept {
147+
bool NW::getTopo(vecu& topo) noexcept {
148148
topo.clear();
149-
if (empty()) return;
150-
labelDepth();
149+
if (empty()) return true;
150+
bool ok = labelDepth();
151+
if (not ok)
152+
return false;
151153
getNodes(topo);
152154
sort_label(topo);
155+
return true;
153156
}
154157

155158
uint NW::getRadius() noexcept {
@@ -161,10 +164,12 @@ uint NW::getRadius() noexcept {
161164

162165
using Nd = NW::Node;
163166

164-
static void dfs_setD(NW& g, const Nd& fr, Nd& to) noexcept {
167+
static bool dfs_setD(NW& g, const Nd& fr, Nd& to) noexcept {
165168
assert(to.lbl_ == UINT_MAX);
166169
assert(fr.lbl_ != UINT_MAX);
167-
assert(to.par_ > 0 and to.par_ == fr.id_);
170+
assert(to.par_ > 0);
171+
if (to.par_ != fr.id_)
172+
return false;
168173

169174
to.lbl_ = fr.lbl_ + 1;
170175

@@ -173,11 +178,14 @@ static void dfs_setD(NW& g, const Nd& fr, Nd& to) noexcept {
173178
NW::Edge& e = g.edgeRef(ei);
174179
Nd& other = g.nodeRef(to.otherSide(e));
175180
if (other.id_ == fr.id_) continue;
176-
dfs_setD(g, to, other);
181+
if (not dfs_setD(g, to, other))
182+
return false;
177183
}
184+
185+
return true;
178186
}
179187

180-
void NW::labelDepth() noexcept {
188+
bool NW::labelDepth() noexcept {
181189
assert(not empty());
182190
uint rootId = first_rid();
183191
assert(rootId);
@@ -188,22 +196,25 @@ void NW::labelDepth() noexcept {
188196
for (NI I(*this); I.valid(); ++I) I->lbl_ = UINT_MAX;
189197
root.lbl_ = 0;
190198
if (size() == 1) {
191-
return;
199+
return true;
192200
}
193201
if (size() == 2) {
194202
for (NI I(*this); I.valid(); ++I) {
195203
Node& nd = *I;
196204
if (nd.id_ != rootId)
197205
nd.lbl_ = 1;
198206
}
199-
return;
207+
return true;
200208
}
201209

202210
for (int i = root.degree() - 1; i >= 0; i--) {
203211
Edge& e = edStor_[root.edges_[i]];
204212
Node& to = ndStor_[root.otherSide(e)];
205-
dfs_setD(*this, root, to);
213+
if (not dfs_setD(*this, root, to))
214+
return false;
206215
}
216+
217+
return true;
207218
}
208219

209220
upair NW::getMinMaxDeg() const noexcept {
@@ -372,10 +383,16 @@ void NW::Edge::eprint_dot(ostream& os, char arrow, const NW& g) const noexcept {
372383
replace_bus_for_dot(buf);
373384
os << buf;
374385

375-
if (inCell_) {
376-
os_printf(os, " [ style=dashed ] ");
377-
}
378-
os_printf(os, ";\n");
386+
char attrib[512] = {};
387+
::sprintf(attrib, " [%s %s",
388+
inCell_ ? "style=dashed" : "",
389+
color_ ? "color=" : ""
390+
);
391+
if (color_)
392+
::strcat(attrib, i2color(color_));
393+
::strcat(attrib, " ]");
394+
395+
os_printf(os, "%s;\n", attrib);
379396
}
380397

381398
uint NW::print(ostream& os, CStr msg) const noexcept {
@@ -581,6 +598,37 @@ void NW::beComplete() noexcept {
581598
}
582599
}
583600
assert(selfCheck());
601+
602+
for (EI I(*this); I.valid(); ++I) {
603+
Edge& e = *I;
604+
e.paint( e.id_ % (c_MAX_COLOR + 1) );
605+
}
606+
}
607+
608+
static const char* _colorNames[] = {
609+
"black",
610+
"red",
611+
"orange",
612+
"yellow",
613+
"green",
614+
"blue",
615+
"firebrick",
616+
"darkslategray",
617+
"purple",
618+
"aquamarine3",
619+
"chocolate4",
620+
"cadetblue4",
621+
"darkolivegreen4",
622+
"darkorchid4",
623+
"cyan",
624+
"goldenrod3",
625+
"black",
626+
"black",
627+
"black"
628+
};
629+
630+
CStr NW::i2color(uint i) noexcept {
631+
return _colorNames[ i % (c_MAX_COLOR + 1) ];
584632
}
585633

586634
}

planning/src/util/nw/Nw.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ struct NW {
3737
static constexpr uint c_Yellow = 3;
3838
static constexpr uint c_Green = 4;
3939
static constexpr uint c_Blue = 5;
40+
static constexpr uint c_firebrick = 6;
41+
static constexpr uint c_darkslategray = 7;
42+
static constexpr uint c_purple = 8;
43+
static constexpr uint c_aquamarine3 = 9;
44+
static constexpr uint c_chocolate4 = 10;
45+
static constexpr uint c_cadetblue4 = 11;
46+
static constexpr uint c_darkolivegreen4 = 12;
47+
static constexpr uint c_darkorchid4 = 13;
48+
static constexpr uint c_cyan = 14;
49+
static constexpr uint c_goldenrod3 = 15;
50+
static constexpr uint c_MAX_COLOR = 15;
4051

4152
struct Edge {
4253
uint id_ = 0;
@@ -437,20 +448,22 @@ struct NW {
437448
}
438449
inline void labelNodes(uint label, uint parent) noexcept;
439450
inline void labelRadius() noexcept;
440-
void labelDepth() noexcept;
451+
bool labelDepth() noexcept;
441452

442453
inline void sort_xy() noexcept;
443454
inline void sort_label(vecu& V) const noexcept;
444455
inline void sort_cid(vecu& V) const noexcept;
445456

446-
void getTopo(vecu& topo) noexcept;
457+
bool getTopo(vecu& topo) noexcept;
447458
uint getRadius() noexcept;
448459

449460
inline bool selfCheck() const noexcept { return true; }
450461
inline bool checkConn() const noexcept { return true; }
451462

452463
bool verifyOneRoot() const noexcept;
453464

465+
static CStr i2color(uint i) noexcept;
466+
454467
uint print(ostream& os, CStr msg = nullptr) const noexcept;
455468
uint dump(CStr msg = nullptr) const noexcept;
456469
uint printNodes(ostream& os, CStr msg, uint16_t forDot) const noexcept;

0 commit comments

Comments
 (0)