Skip to content

Commit f4a53b5

Browse files
authored
Merge pull request #771 from os-fpga/checker_pin_graph_for_clockdata
checker: create pin-graph for clock-data
2 parents 8258504 + d044f61 commit f4a53b5

File tree

6 files changed

+209
-26
lines changed

6 files changed

+209
-26
lines changed

planning/src/file_readers/pln_Fio.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// File IO - namespace fio
22
#include "file_readers/pln_Fio.h"
33
#include "file_readers/pln_tinyxml2.h"
4+
#include "util/geo/iv.h"
45

56
#include <alloca.h>
67
#include <errno.h>
@@ -769,11 +770,11 @@ uint64_t MMapReader::hashSum() const noexcept {
769770
for (size_t i = 0; i < k; i += i8) {
770771
char* p = buf_ + i;
771772
uint64_t a = *((uint64_t*)p);
772-
sum = hashf::hashCombine(a, sum);
773+
sum = hashComb(a, sum);
773774
}
774775

775776
while (r) {
776-
sum = hashf::hashCombine(buf_[sz_ - r], sum);
777+
sum = hashComb(buf_[sz_ - r], sum);
777778
r--;
778779
}
779780

@@ -1308,7 +1309,7 @@ uint64_t LineReader::hashSum() const noexcept {
13081309
uint64_t sum = 0;
13091310
reIterate2();
13101311
do {
1311-
sum = hashf::hashCombine(getHash(curLine2_), sum);
1312+
sum = hashComb(getHash(curLine2_), sum);
13121313
} while (advanceLine2());
13131314
return sum;
13141315
}

planning/src/file_readers/pln_Fio.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,6 @@ inline bool file_exists_accessible(const string& fn) noexcept {
163163

164164
namespace hashf {
165165

166-
constexpr uint64_t hashCombine(uint64_t a, uint64_t b) noexcept {
167-
constexpr uint64_t m = 0xc6a4a7935bd1e995;
168-
return (a ^ (b * m + (a << 6) + (a >> 2))) + 0xe6546b64;
169-
}
170-
171166
// Fowler,Noll,Vo FNV-64 hash function
172167
inline size_t hf_FNV64(CStr z) noexcept
173168
{

planning/src/file_readers/pln_blif_file.cpp

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#include "file_readers/pln_blif_file.h"
2+
#include "util/nw/Nw.h"
23

34
namespace pln {
45

@@ -159,12 +160,6 @@ void BLIF_file::Node::place_output_at_back(vector<string>& dat) noexcept {
159160
size_t dsz = dat.size();
160161
if (dsz < 3) return;
161162
CStr cs = dat.back().c_str();
162-
//if (1) {
163-
// lprintf("\t ||||| place_output_at_back() dat.size()= %zu\n", dsz);
164-
// lprintf("\t ||||| kw_= %s prim:%s\n", kw_.c_str(), primt_name(ptype_));
165-
// if (lnum_ == 76)
166-
// lputs9();
167-
//}
168163
if (starts_w_R_eq(cs)) {
169164
std::swap(dat[dsz - 2], dat[dsz - 1]);
170165
}
@@ -389,12 +384,12 @@ bool BLIF_file::checkBlif() noexcept {
389384
}
390385

391386
if (trace_ >= 3) {
392-
lputs();
387+
flush_out(true);
393388
printNodes(ls);
394389
}
395390

396391
// 5. no undriven output ports
397-
for (Node* port : topOutputs_) {
392+
for (const Node* port : topOutputs_) {
398393
assert(port->isRoot());
399394
assert(port->inDeg() == 0);
400395
if (port->outDeg() == 0) {
@@ -404,6 +399,21 @@ bool BLIF_file::checkBlif() noexcept {
404399
}
405400
}
406401

402+
// 6. clock-data separation
403+
if (!topInputs_.empty() and !topOutputs_.empty()) {
404+
NW pinG;
405+
pinG.trace_ = trace_;
406+
for (const Node* port : topOutputs_) {
407+
assert(port->isRoot());
408+
assert(port->inDeg() == 0);
409+
pinG.insK(port->hashCode());
410+
}
411+
if (trace_ >= 4) {
412+
flush_out(true);
413+
pinG.printSum(ls, 0);
414+
}
415+
}
416+
407417
chk_ok_ = true;
408418
return true;
409419
}

planning/src/file_readers/pln_blif_file.h

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
#include "file_readers/pln_Fio.h"
66
#include "file_readers/pln_primitives.h"
7+
#include "util/geo/xyz.h"
78

89
namespace pln {
910

@@ -40,6 +41,12 @@ struct BLIF_file : public fio::MMapReader
4041
if (keyword) kw_ = keyword;
4142
}
4243

44+
uint64_t outHash() const noexcept { return str::hashf(out_.c_str()); }
45+
46+
uint64_t hashCode() const noexcept {
47+
return hashComb(id_, is_top_, outHash());
48+
}
49+
4350
bool isTopPort() const noexcept { return is_top_ != 0; }
4451
bool isTopInput() const noexcept { return is_top_ < 0; }
4552
bool isTopOutput() const noexcept { return is_top_ > 0; }
@@ -98,8 +105,6 @@ struct BLIF_file : public fio::MMapReader
98105

99106
CStr cOut() const noexcept { return out_.empty() ? "{e}" : out_.c_str(); }
100107

101-
// CStr cType() const noexcept { return data_.empty() ? "{e}" : data_.front().c_str(); }
102-
103108
CStr cPrimType() const noexcept { return ptype_ == A_ZERO ? "{e}" : primt_name(ptype_); }
104109

105110
struct CmpOut {

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

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

planning/src/util/geo/iv.h

Lines changed: 179 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// class Iv - Interval
22
#pragma once
3+
#ifndef _PLN_util_geo_IV_h_b6e76e5fa705cfb_
4+
#define _PLN_util_geo_IV_h_b6e76e5fa705cfb_
35

46
#include <algorithm>
57
#include <cassert>
@@ -17,12 +19,36 @@
1719
#include <memory>
1820
#include <numeric>
1921
#include <string>
22+
#include <string_view>
2023
#include <type_traits>
2124
#include <utility>
2225
#include <vector>
2326

2427
namespace pln {
2528

29+
constexpr uint64_t hashComb(uint64_t a, uint64_t b) noexcept {
30+
constexpr uint64_t m = 0xc6a4a7935bd1e995;
31+
return (a ^ (b * m + (a << 6) + (a >> 2))) + 0xe6546b64;
32+
}
33+
34+
constexpr uint64_t hashComb(uint64_t a, uint64_t b, uint64_t c) noexcept {
35+
return hashComb(a, hashComb(b, c));
36+
}
37+
38+
inline constexpr int protectedAdd(int a, int b) noexcept {
39+
int64_t c = int64_t(a) + int64_t(b);
40+
if (c > INT_MAX) return INT_MAX;
41+
if (c < INT_MIN) return INT_MIN;
42+
return c;
43+
}
44+
45+
inline constexpr int protectedSub(int a, int b) noexcept {
46+
int64_t c = int64_t(a) - int64_t(b);
47+
if (c > INT_MAX) return INT_MAX;
48+
if (c < INT_MIN) return INT_MIN;
49+
return c;
50+
}
51+
2652
inline constexpr int64_t add64(int a, int b) noexcept {
2753
return int64_t(a) + int64_t(b);
2854
}
@@ -31,6 +57,32 @@ inline constexpr int64_t sub64(int a, int b) noexcept {
3157
return int64_t(a) - int64_t(b);
3258
}
3359

60+
inline constexpr int protectedRound(double x) noexcept {
61+
if (x >= 0) {
62+
if (x >= double(INT_MAX) - 0.5) return INT_MAX;
63+
return x + 0.5;
64+
}
65+
if (x <= double(INT_MIN) + 0.5) return INT_MIN;
66+
return x - 0.5;
67+
}
68+
69+
inline constexpr int inlineRound(double x) noexcept {
70+
return x >= 0 ? x + 0.5 : x - 0.5;
71+
}
72+
73+
inline constexpr int64_t inlineRound64(double x) noexcept {
74+
return x >= 0 ? int64_t(x + 0.5) : int64_t(x - 0.5);
75+
}
76+
77+
inline constexpr int64_t protectedRound64(double x) noexcept {
78+
if (x >= 0) {
79+
if (x >= double(LLONG_MAX) - 0.5) return LLONG_MAX;
80+
return int64_t(x + 0.5);
81+
}
82+
if (x <= double(LLONG_MIN) + 0.5) return LLONG_MIN;
83+
return int64_t(x - 0.5);
84+
}
85+
3486
struct Iv {
3587
int a_ = INT_MIN, b_ = INT_MIN;
3688

@@ -42,11 +94,13 @@ struct Iv {
4294
a_ = a;
4395
b_ = b;
4496
}
45-
void setZero() noexcept {
97+
void toZero() noexcept {
4698
a_ = 0;
4799
b_ = 0;
48100
}
49101

102+
uint64_t hashCode() const noexcept { return hashComb(a_, b_); }
103+
50104
int len() const noexcept { return b_ - a_; }
51105
bool isLen0() const noexcept { return a_ == b_; }
52106
bool valid() const noexcept { return b_ != INT_MIN; }
@@ -60,35 +114,153 @@ struct Iv {
60114
void invert() noexcept { std::swap(a_, b_); }
61115
int center() const noexcept { return add64(a_, b_) / 2; }
62116

117+
void bloat(int lo, int hi) noexcept {
118+
assert(valid() and normal());
119+
assert(lo >= 0 and hi >= 0);
120+
a_ -= lo;
121+
b_ += hi;
122+
assert(valid() and normal());
123+
}
124+
125+
void bloat(int delta) noexcept {
126+
assert(delta >= 0);
127+
bloat(delta, delta);
128+
}
129+
130+
void moveTo(int t) noexcept {
131+
assert(valid() and normal());
132+
int l = len();
133+
a_ = t;
134+
b_ = t + l;
135+
}
136+
void moveRel(int dt) noexcept {
137+
assert(valid() and normal());
138+
a_ += dt;
139+
b_ += dt;
140+
}
141+
142+
inline void unite(Iv i) noexcept;
143+
inline void unite(int t) noexcept;
144+
145+
bool intersects(Iv iv) const noexcept {
146+
return intersects(a_, b_, iv.a_, iv.b_);
147+
}
148+
inline static bool intersects(int a, int b, int c, int d) noexcept;
149+
150+
bool overlaps(Iv iv) const noexcept { return overlaps(a_, b_, iv.a_, iv.b_); }
151+
inline static bool overlaps(int a, int b, int c, int d) noexcept;
152+
153+
inline static int ovLen(int a, int b, int c, int d, int* p1 = nullptr,
154+
int* p2 = nullptr) noexcept;
155+
int ovLen(Iv iv, int* p1 = nullptr, int* p2 = nullptr) const noexcept {
156+
return ovLen(a_, b_, iv.a_, iv.b_, p1, p2);
157+
}
158+
63159
static bool inside(int t, int a, int b) noexcept {
64160
if (a > b) std::swap(a, b);
65-
return t >= a && t <= b;
161+
return t >= a and t <= b;
66162
}
67163
static bool insideNorm(int t, int a, int b) noexcept {
68164
assert(normal(a, b));
69-
return t >= a && t <= b;
165+
return t >= a and t <= b;
70166
}
71167

72168
static bool insideOpen(int t, int a, int b) noexcept {
73169
if (a > b) std::swap(a, b);
74-
return t > a && t < b;
170+
return t > a and t < b;
75171
}
76172
static bool insideOpenNorm(int t, int a, int b) noexcept {
77173
assert(normal(a, b));
78-
return t > a && t < b;
174+
return t > a and t < b;
175+
}
176+
177+
bool covers(Iv iv) const noexcept {
178+
assert(valid() and normal());
179+
assert(iv.valid());
180+
return insideNorm(iv.a_, a_, b_) and insideNorm(iv.b_, a_, b_);
181+
}
182+
bool strictlyCovers(Iv iv) const noexcept {
183+
assert(valid() and normal());
184+
assert(iv.valid());
185+
return insideOpenNorm(iv.a_, a_, b_) and insideOpenNorm(iv.b_, a_, b_);
79186
}
80187

81188
bool operator<(Iv i) const noexcept {
82189
if (a_ < i.a_) return true;
83190
if (a_ > i.a_) return false;
84191
return b_ < i.b_;
85192
}
86-
bool operator==(Iv i) const noexcept { return a_ == i.a_ && b_ == i.b_; }
193+
bool operator==(Iv i) const noexcept { return a_ == i.a_ and b_ == i.b_; }
87194
bool operator!=(Iv i) const noexcept { return not operator==(i); }
88195
};
89196
inline std::ostream& operator<<(std::ostream& os, Iv iv) {
90197
os << "(iv " << iv.a_ << ' ' << iv.b_ << ')';
91198
return os;
92199
}
93200

94-
} // namespace pln
201+
inline bool Iv::intersects(int a, int b, int c, int d) noexcept {
202+
assert(a < b and c < d);
203+
if (c < a) {
204+
std::swap(a, c);
205+
std::swap(b, d);
206+
}
207+
if (d < b) return true;
208+
if (c > b) return false;
209+
return true;
210+
}
211+
212+
inline bool Iv::overlaps(int a, int b, int c, int d) noexcept {
213+
assert(a < b and c < d);
214+
if (c < a) {
215+
std::swap(a, c);
216+
std::swap(b, d);
217+
}
218+
if (d <= b) return true;
219+
if (c >= b) return false;
220+
return true;
221+
}
222+
223+
inline int Iv::ovLen(int a, int b, int c, int d, int* p1, int* p2) noexcept {
224+
assert(a < b and c < d);
225+
if (c < a) {
226+
std::swap(a, c);
227+
std::swap(b, d);
228+
}
229+
if (d <= b) {
230+
if (p1) *p1 = c;
231+
if (p2) *p2 = d;
232+
return d - c;
233+
}
234+
if (c >= b) return 0;
235+
236+
if (p1) *p1 = c;
237+
if (p2) *p2 = b;
238+
return b - c;
239+
}
240+
241+
inline void Iv::unite(Iv i) noexcept {
242+
assert(i.valid());
243+
i.normalize();
244+
if (valid()) {
245+
assert(normal());
246+
if (i.a_ < a_) a_ = i.a_;
247+
if (i.b_ > b_) b_ = i.b_;
248+
return;
249+
}
250+
set(i);
251+
}
252+
253+
inline void Iv::unite(int t) noexcept {
254+
if (valid()) {
255+
assert(normal());
256+
if (t < a_) a_ = t;
257+
if (t > b_) b_ = t;
258+
return;
259+
}
260+
set(t, t);
261+
}
262+
263+
}
264+
265+
#endif
266+

0 commit comments

Comments
 (0)