Skip to content

Commit 8258504

Browse files
authored
Merge pull request #770 from os-fpga/checker_added_NW_class
checker: added class 'Nw' (Network) for clock-data checking in blif
2 parents 814c7ea + 1000b19 commit 8258504

File tree

5 files changed

+1450
-12
lines changed

5 files changed

+1450
-12
lines changed

planning/src/RS/rsCheck.cpp

Lines changed: 61 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,24 @@
11
#include "RS/rsCheck.h"
22
#include "file_readers/pln_blif_file.h"
33
#include "file_readers/pln_csv_reader.h"
4+
#include "util/nw/Nw.h"
45

56
namespace pln {
67

78
using std::string;
89
using std::endl;
910

11+
static void nw_test_01();
12+
1013
static bool do_check_blif(CStr cfn) {
1114
assert(cfn);
1215
uint16_t tr = ltrace();
1316
auto& ls = lout();
1417

18+
if (::getenv("pln_nw_test_01")) {
19+
nw_test_01();
20+
}
21+
1522
BLIF_file bfile(string{cfn});
1623

1724
if (tr >= 4)
@@ -46,13 +53,13 @@ static bool do_check_blif(CStr cfn) {
4653
bfile.numInputs(), bfile.numOutputs(), bfile.topModel_.c_str());
4754

4855
if (tr >= 4) {
49-
lputs();
56+
flush_out(true);
5057
bfile.printInputs(ls);
51-
lputs();
58+
flush_out(true);
5259
bfile.printOutputs(ls);
5360
}
5461

55-
lputs();
62+
flush_out(true);
5663
ls << ">>>>> checking BLIF " << cfn << " ..." << endl;
5764

5865
bool chk_ok = bfile.checkBlif();
@@ -159,5 +166,56 @@ bool do_check(const rsOpts& opts, bool blif_vs_csv) {
159166
return status;
160167
}
161168

169+
// DEBUG new NW code:
170+
static void nw_test_01() {
171+
flush_out(true);
172+
pln::NW g;
173+
uint64_t key_cnt = 100;
174+
uint nid = g.insP(XY{0, 0}, key_cnt++);
175+
assert(nid > 0);
176+
assert(g.hasNode(nid));
177+
178+
g.addRoot(nid);
179+
g.insP(XY{200, 0}, key_cnt++);
180+
g.insP(XY{200, 200}, key_cnt++);
181+
g.insP(XY{0, 200}, key_cnt++);
182+
183+
g.beComplete();
184+
185+
g.dump("\t g is a complete graph");
186+
lprintf("\t g. numN()= %u numE()= %u\n", g.numN(), g.numE());
187+
assert(g.numE() == 6);
188+
189+
pln::vecu topo;
190+
g.getTopo(topo);
191+
192+
flush_out(true);
193+
lputs("==== **** DOT ****");
194+
195+
g.dumpDot("g");
196+
std::ofstream fos("g.dot");
197+
if (fos.is_open()) {
198+
g.printDot(fos, nullptr, false);
199+
lputs(" written g.dot");
200+
fos.close();
201+
} else {
202+
flush_out(true);
203+
lprintf2("[Error] NOT fos.is_open()\n");
204+
flush_out(true);
205+
}
206+
207+
flush_out(true);
208+
lputs("==== **** METIS ****");
209+
210+
g.dumpMetis(true);
211+
212+
flush_out(true);
213+
214+
bool wr_ok = g.writeMetis("g.met", true);
215+
lprintf("wr_ok:%i\n", wr_ok);
216+
if (wr_ok)
217+
lputs(" written g.met");
218+
}
219+
162220
}
163221

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

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

planning/src/util/geo/xyz.h

Lines changed: 77 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
11
// class XY - 2D Point
22
// class XYZ - 3D Point
33
#pragma once
4+
#ifndef _pln_util_geo_XYZ_H_1c192a5bf5646b833_
5+
#define _pln_util_geo_XYZ_H_1c192a5bf5646b833_
6+
47
#include "util/geo/iv.h"
58

9+
#undef XY
10+
#undef XYZ
11+
612
namespace pln {
713

14+
using ipair = std::pair<int, int>;
15+
816
struct XY {
917
int x_ = INT_MIN, y_ = INT_MIN;
1018

1119
XY() noexcept = default;
1220
XY(int a, int b) noexcept : x_(a), y_(b) {}
21+
XY(ipair p) noexcept : x_(p.first), y_(p.second) {}
1322

1423
bool valid() const noexcept { return x_ != INT_MIN; }
1524
bool nonNeg() const noexcept { return x_ >= 0; }
@@ -25,6 +34,12 @@ struct XY {
2534
y_ = 0;
2635
}
2736

37+
void moveRel(int dx, int dy) noexcept {
38+
x_ += dx;
39+
y_ += dy;
40+
}
41+
void moveRel(XY d) noexcept { moveRel(d.x_, d.y_); }
42+
2843
void negate() noexcept {
2944
x_ = -x_;
3045
y_ = -y_;
@@ -68,6 +83,11 @@ struct XY {
6883
y_ -= p.y_;
6984
}
7085

86+
void operator = (ipair p) noexcept {
87+
x_ = p.first;
88+
y_ = p.second;
89+
}
90+
7191
static constexpr int p_round(double x) noexcept {
7292
if (x >= 0) {
7393
if (x >= double(INT_MAX) - 0.5) return INT_MAX;
@@ -107,14 +127,41 @@ struct XY {
107127
return double(p.x_ - x_) * (p.x_ - x_) + double(p.y_ - y_) * (p.y_ - y_);
108128
}
109129

110-
std::string toString() const noexcept {
111-
std::string s{"("};
112-
s += std::to_string(x_);
113-
s.push_back(' ');
114-
s += std::to_string(y_);
115-
s.push_back(')');
116-
return s;
130+
uint64_t cantorHash() const noexcept {
131+
uint64_t a = x_;
132+
uint64_t b = y_;
133+
return ((a + b) >> 1) * (a + b + 1) + b;
134+
}
135+
uint64_t fnvHash() const noexcept {
136+
uint64_t a = x_;
137+
uint64_t b = y_;
138+
constexpr uint64_t m = 0xc6a4a7935bd1e995;
139+
return (a ^ (b * m + (a << 6) + (a >> 2))) + 0xe6546b64;
117140
}
141+
142+
static inline std::string i2s(int i) noexcept { return std::to_string(i); }
143+
144+
static inline std::string conc(const std::string& a, char ch, const std::string& b) noexcept {
145+
std::string z;
146+
z.reserve(a.length() + b.length() + 2);
147+
z = a;
148+
z.push_back(ch);
149+
z += b;
150+
return z;
151+
}
152+
153+
static inline std::string conc(char a, const std::string& s, char b) noexcept {
154+
std::string z;
155+
z.reserve(s.length() + 3);
156+
z.push_back(a);
157+
z += s;
158+
z.push_back(b);
159+
return z;
160+
}
161+
162+
std::string x_spc_y() const noexcept { return conc( i2s(x_), ' ', i2s(y_) ); }
163+
std::string x_com_y() const noexcept { return conc( i2s(x_), ',', i2s(y_) ); }
164+
std::string toString() const noexcept { return conc( '(', x_spc_y(), ')' ); }
118165
};
119166

120167
struct XYZ : public XY {
@@ -137,6 +184,7 @@ struct XYZ : public XY {
137184
z_ = c;
138185
}
139186
void set3(XYZ u) noexcept { *this = u; }
187+
void setZ(int zz) noexcept { z_ = zz; }
140188

141189
bool operator==(XYZ u) const noexcept {
142190
return x_ == u.x_ && y_ == u.y_ && z_ == u.z_;
@@ -152,6 +200,17 @@ struct XYZ : public XY {
152200
}
153201

154202
int dist3D(XYZ u) const noexcept { return dist(u) + std::abs(z_ - u.z_); }
203+
204+
std::string toString() const noexcept {
205+
std::string s{"("};
206+
s += std::to_string(x_);
207+
s.push_back(' ');
208+
s += std::to_string(y_);
209+
s.push_back(' ');
210+
s += std::to_string(z_);
211+
s.push_back(')');
212+
return s;
213+
}
155214
};
156215

157216
inline std::ostream& operator<<(std::ostream& os, XY p) {
@@ -167,11 +226,21 @@ inline std::ostream& operator<<(std::ostream& os, const XYZ& u) {
167226
inline int64_t dot(XY a, XY b) noexcept { return a.dot(b); }
168227
inline int64_t det(XY a, XY b) noexcept { return a.det(b); }
169228

229+
inline XY operator-(XY a, XY b) noexcept {
230+
return XY(a.x_ - b.x_, a.y_ - b.y_);
231+
}
232+
inline XY operator+(XY a, XY b) noexcept {
233+
return XY(a.x_ + b.x_, a.y_ + b.y_);
234+
}
235+
170236
inline int abc_ori(XY a, XY b, XY c) noexcept {
171237
int64_t det = XY::det3(a, b, c);
172238
if (det > 0) return 1;
173239
if (det < 0) return -1;
174240
return 0;
175241
}
176242

177-
} // namespace pln
243+
}
244+
245+
#endif
246+

0 commit comments

Comments
 (0)