Skip to content

Commit 5b6d2d0

Browse files
authored
Merge pull request #685 from os-fpga/pin_c_prep_4_fabric_eblif_sync_pln
pin_c: prepare for fabric eblif (sync w pln)
2 parents d6d3734 + e4d140a commit 5b6d2d0

File tree

5 files changed

+187
-36
lines changed

5 files changed

+187
-36
lines changed

pin_c/src/pin_loc/pcf_place.cpp

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -445,6 +445,50 @@ bool PinPlacer::read_pcf(const RapidCsvReader& csv) {
445445

446446
pcf_pin_cmds_ = std::move(rd_pcf.commands_);
447447

448+
// translate pin-references in cmds_
449+
if (pcf_pin_cmds_.size() and
450+
pin_names_translated_ and is_fabric_eblif_ and all_edits_.size()) {
451+
452+
if (tr >= 6) {
453+
lprintf(" ---- pcf_pin_cmds_ before translation (%zu):\n",
454+
pcf_pin_cmds_.size());
455+
for (const auto& cmd : pcf_pin_cmds_)
456+
logVec(cmd, " ");
457+
lprintf(" ---- \n");
458+
}
459+
460+
uint numInpTr = 0, numOutTr = 0;
461+
string was;
462+
for (auto& cmd : pcf_pin_cmds_) {
463+
if (cmd.size() < 2)
464+
continue;
465+
string& pinName = cmd[1];
466+
was = pinName;
467+
if (findIbufByOldPin(was)) {
468+
// input
469+
pinName = translatePinName(was, true);
470+
if (pinName != was) numInpTr++;
471+
} else if (findObufByOldPin(was)) {
472+
// output
473+
pinName = translatePinName(was, false);
474+
if (pinName != was) numOutTr++;
475+
}
476+
}
477+
478+
if (tr >= 3) {
479+
lprintf("PCF command translation: #input translations= %u #output translations= %u\n",
480+
numInpTr, numOutTr);
481+
}
482+
483+
if (tr >= 6) {
484+
lprintf(" ++++ pcf_pin_cmds_ after translation (%zu):\n",
485+
pcf_pin_cmds_.size());
486+
for (const auto& cmd : pcf_pin_cmds_)
487+
logVec(cmd, " ");
488+
lprintf(" ++++ \n");
489+
}
490+
}
491+
448492
if (tr >= 3) {
449493
flush_out(true);
450494
lputs("\t *** pin_c read_pcf SUCCEEDED ***");

pin_c/src/pin_loc/pin.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ struct Pin {
1616

1717
static constexpr uint MAX_PT_COLS = 128;
1818

19-
string udes_pin_name_;
19+
string orig_pin_name_; // never translated
20+
string udes_pin_name_; // maybe translated
2021
string trans_pin_name_; // translated due to netlist edits
2122

2223
string device_pin_name_;
@@ -42,13 +43,19 @@ struct Pin {
4243
}
4344

4445
Pin(const string& u, const string& d, const XYZ& xyz, uint r) noexcept
45-
: udes_pin_name_(u), device_pin_name_(d),
46+
: orig_pin_name_(u), udes_pin_name_(u),
47+
device_pin_name_(d),
4648
xyz_(xyz), pt_row_(r) {
4749
rx_modes_.reset();
4850
tx_modes_.reset();
4951
all_modes_.reset();
5052
}
5153

54+
void set_udes_pin_name(const string& pn) noexcept {
55+
orig_pin_name_ = pn;
56+
udes_pin_name_ = pn;
57+
}
58+
5259
bool is_translated() const noexcept {
5360
if (trans_pin_name_.empty())
5461
return false;
@@ -59,6 +66,7 @@ struct Pin {
5966
rx_modes_.reset();
6067
tx_modes_.reset();
6168
all_modes_.reset();
69+
orig_pin_name_.clear();
6270
udes_pin_name_.clear();
6371
trans_pin_name_.clear();
6472
device_pin_name_.clear();

pin_c/src/pin_loc/pin_placer.cpp

Lines changed: 55 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,7 @@ static string USAGE_MSG_2 =
129129
PinPlacer::PinPlacer(const cmd_line& cl)
130130
: cl_(cl) {
131131
pin_assign_def_order_ = true;
132-
auto_pcf_created_ = false;
133-
min_pt_row_ = UINT_MAX;
134-
max_pt_row_ = 0;
132+
resetState();
135133
}
136134

137135
PinPlacer::~PinPlacer() {
@@ -157,10 +155,22 @@ PinPlacer::~PinPlacer() {
157155
}
158156
}
159157

160-
bool PinPlacer::read_and_write() {
161-
flush_out(false);
158+
void PinPlacer::resetState() noexcept {
159+
auto_pcf_created_ = false;
160+
min_pt_row_ = UINT_MAX;
161+
max_pt_row_ = 0;
162+
no_more_inp_bumps_ = false;
163+
no_more_out_bumps_ = false;
164+
is_fabric_eblif_ = false;
165+
pin_names_translated_ = false;
162166
num_warnings_ = 0;
167+
num_critical_warnings_ = 0;
163168
clear_err_code();
169+
}
170+
171+
bool PinPlacer::read_and_write() {
172+
flush_out(false);
173+
resetState();
164174

165175
string xml_name = cl_.get_param("--xml");
166176
string csv_name = cl_.get_param("--csv");
@@ -227,7 +237,7 @@ bool PinPlacer::read_and_write() {
227237
!(csv_name.empty() || no_b_json || output_name.empty()) &&
228238
user_pcf_.empty();
229239

230-
if (tr >= 2) {
240+
if (tr >= 4) {
231241
ls << "\t usage_requirement_1 : " << boolalpha << usage_requirement_1 << endl;
232242
ls << "\t usage_requirement_2 : " << boolalpha << usage_requirement_2 << endl;
233243
}
@@ -307,29 +317,11 @@ bool PinPlacer::read_and_write() {
307317
if (has_edits) {
308318
// if auto-PCF and has_edits, translate and de-duplicate
309319
// user-design ports now, since edits.json could remove some design ports.
310-
for (Pin& pin : user_design_inputs_) {
311-
pin.trans_pin_name_ = translatePinName(pin.udes_pin_name_, true);
312-
if (pin.udes_pin_name_ == pin.trans_pin_name_)
313-
continue;
314-
if (tr >= 3) {
315-
lprintf("design input pin TRANSLATED for auto-PCF: %s --> %s\n",
316-
pin.udes_pin_name_.c_str(), pin.trans_pin_name_.c_str());
317-
}
318-
pin.udes_pin_name_ = pin.trans_pin_name_;
319-
}
320-
flush_out(true);
321-
for (Pin& pin : user_design_outputs_) {
322-
pin.trans_pin_name_ = translatePinName(pin.udes_pin_name_, false);
323-
if (pin.udes_pin_name_ == pin.trans_pin_name_)
324-
continue;
325-
if (tr >= 3) {
326-
lprintf("design output pin TRANSLATED for auto-PCF: %s --> %s\n",
327-
pin.udes_pin_name_.c_str(), pin.trans_pin_name_.c_str());
328-
}
329-
pin.udes_pin_name_ = pin.trans_pin_name_;
330-
}
331-
vector<string> dups;
320+
if (not pin_names_translated_)
321+
translatePinNames("(auto-PCF)");
322+
//
332323
// de-duplicate inputs
324+
vector<string> dups;
333325
if (user_design_inputs_.size() > 1) {
334326
bool done = false;
335327
while (not done) {
@@ -491,5 +483,40 @@ bool PinPlacer::read_and_write() {
491483
return true;
492484
}
493485

486+
uint PinPlacer::translatePinNames(const string& memo) noexcept {
487+
flush_out(false);
488+
uint16_t tr = ltrace();
489+
uint cnt = 0;
490+
CStr mem = memo.c_str();
491+
492+
for (Pin& pin : user_design_inputs_) {
493+
pin.trans_pin_name_ = translatePinName(pin.udes_pin_name_, true);
494+
if (pin.udes_pin_name_ == pin.trans_pin_name_)
495+
continue;
496+
if (tr >= 3) {
497+
lprintf("design input pin TRANSLATED %s: %s --> %s\n", mem,
498+
pin.udes_pin_name_.c_str(), pin.trans_pin_name_.c_str());
499+
}
500+
pin.udes_pin_name_ = pin.trans_pin_name_;
501+
cnt++;
502+
}
503+
504+
flush_out(true);
505+
for (Pin& pin : user_design_outputs_) {
506+
pin.trans_pin_name_ = translatePinName(pin.udes_pin_name_, false);
507+
if (pin.udes_pin_name_ == pin.trans_pin_name_)
508+
continue;
509+
if (tr >= 3) {
510+
lprintf("design output pin TRANSLATED %s: %s --> %s\n", mem,
511+
pin.udes_pin_name_.c_str(), pin.trans_pin_name_.c_str());
512+
}
513+
pin.udes_pin_name_ = pin.trans_pin_name_;
514+
cnt++;
515+
}
516+
517+
pin_names_translated_ = true;
518+
return cnt;
519+
}
520+
494521
} // namespace pln
495522

pin_c/src/pin_loc/pin_placer.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ struct PinPlacer {
135135

136136
PinPlacer(const cmd_line& cl);
137137
~PinPlacer();
138+
void resetState() noexcept;
138139

139140
bool read_and_write();
140141

@@ -206,6 +207,9 @@ struct PinPlacer {
206207
bool no_more_inp_bumps_ = false; // state for get_available_device_pin()
207208
bool no_more_out_bumps_ = false; //
208209

210+
bool is_fabric_eblif_ = false;
211+
bool pin_names_translated_ = false;
212+
209213
mutable uint num_warnings_ = 0, num_critical_warnings_ = 0;
210214
void incrCriticalWarnings() const noexcept { num_critical_warnings_++; }
211215

@@ -233,6 +237,7 @@ struct PinPlacer {
233237
EditItem* findIbufByOldPin(const string& old_pin) const noexcept;
234238

235239
string translatePinName(const string& pinName, bool is_input) const noexcept;
240+
uint translatePinNames(const string& memo) noexcept;
236241
};
237242

238243
}

pin_c/src/pin_loc/read_ports.cpp

Lines changed: 73 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,36 @@ using namespace std;
1111
using fio::Fio;
1212

1313
#define CERROR std::cerr << "[Error] "
14-
#define OUT_ERROR std::cout << "[Error] "
14+
#define OUT_ERROR lout() << "[Error] "
15+
16+
static bool s_is_fabric_eblif(const string& fn) noexcept {
17+
size_t len = fn.length();
18+
if (len < 12 or len > 5000)
19+
return false;
20+
char buf[len + 2] = {};
21+
::strcpy(buf, fn.c_str());
22+
23+
// replace '/' and '.' by spaces to use space-based tokenizer
24+
for (char* p = buf; *p; p++) {
25+
if (*p == '/' or *p == '.')
26+
*p = ' ';
27+
}
28+
29+
vector<string> W;
30+
Fio::split_spa(buf, W);
31+
if (W.size() < 2)
32+
return false;
33+
if (W.back() != "eblif")
34+
return false;
35+
36+
const string& f = W[W.size() - 2];
37+
if (f.length() < 7)
38+
return false;
39+
CStr s = f.c_str();
40+
41+
return s[0] == 'f' and s[1] == 'a' and s[2] == 'b' and
42+
s[3] == 'r' and s[4] == 'i' and s[5] == 'c' and s[6] == '_';
43+
}
1544

1645
bool PinPlacer::read_design_ports() {
1746
uint16_t tr = ltrace();
@@ -48,7 +77,7 @@ bool PinPlacer::read_design_ports() {
4877
}
4978
}
5079
} else {
51-
if (tr >= 1) lprintf("port_info cmd option not specified => using blif\n");
80+
if (tr >= 4) lprintf("port_info cmd option not specified => using blif\n");
5281
}
5382

5483
if (json_ifs.is_open()) {
@@ -80,7 +109,11 @@ bool PinPlacer::read_design_ports() {
80109
}
81110
BlifReader rd_blif;
82111
if (!rd_blif.read_blif(blif_fn)) {
112+
flush_out(true);
113+
err_puts();
83114
CERROR << err_lookup("PORT_INFO_PARSE_ERROR") << endl;
115+
OUT_ERROR << err_lookup("PORT_INFO_PARSE_ERROR") << endl;
116+
flush_out(true);
84117
return false;
85118
}
86119
raw_design_inputs_ = rd_blif.get_inputs();
@@ -95,38 +128,42 @@ bool PinPlacer::read_design_ports() {
95128
err_puts();
96129
return false;
97130
}
131+
132+
is_fabric_eblif_ = s_is_fabric_eblif(blif_fn);
98133
}
99134

100135
size_t sz = raw_design_inputs_.size();
101136
user_design_inputs_.clear();
102137
user_design_inputs_.resize(sz);
103138
for (size_t i = 0; i < sz; i++)
104-
user_design_inputs_[i].udes_pin_name_ = raw_design_inputs_[i];
139+
user_design_inputs_[i].set_udes_pin_name(raw_design_inputs_[i]);
105140

106141
sz = raw_design_outputs_.size();
107142
user_design_outputs_.clear();
108143
user_design_outputs_.resize(sz);
109144
for (size_t i = 0; i < sz; i++)
110-
user_design_outputs_[i].udes_pin_name_ = raw_design_outputs_[i];
145+
user_design_outputs_[i].set_udes_pin_name(raw_design_outputs_[i]);
111146

112147
if (tr >= 3) {
113148
flush_out(tr >= 5);
114149
lprintf(
115150
"DONE read_design_ports() #udes_inputs= %zu #udes_outputs= %zu\n",
116151
raw_design_inputs_.size(), raw_design_outputs_.size());
152+
if (tr >= 4)
153+
lprintf("is_fabric_eblif_: %s\n", is_fabric_eblif_ ? "TRUE" : "FALSE");
117154
}
118155

119156
if (tr >= 5) {
120157
flush_out(true);
121158

122159
sz = user_design_inputs_.size();
123-
lprintf(" ---- dumping user_design_inputs_ (%zu) ----\n", sz);
160+
lprintf(" ---- dumping user_design_inputs_ (before translation) (%zu) ----\n", sz);
124161
for (uint i = 0; i < sz; i++)
125162
lprintf(" inp-%u %s\n", i, user_design_input(i).c_str());
126163
lprintf(" ----\n");
127164

128165
sz = user_design_outputs_.size();
129-
lprintf(" ---- dumping user_design_outputs_ (%zu) ----\n", sz);
166+
lprintf(" ---- dumping user_design_outputs_ (before translation) (%zu) ----\n", sz);
130167
for (uint i = 0; i < sz; i++)
131168
lprintf(" out-%u %s\n", i, user_design_output(i).c_str());
132169
lprintf(" ----\n");
@@ -136,6 +173,36 @@ bool PinPlacer::read_design_ports() {
136173
raw_design_inputs_.size(), raw_design_outputs_.size());
137174
}
138175

176+
if (1) {
177+
translatePinNames("(read_design_ports)");
178+
179+
if (tr >= 5) {
180+
flush_out(true);
181+
182+
sz = user_design_inputs_.size();
183+
lprintf(" ---- dumping user_design_inputs_ (after translation) (%zu) ----\n", sz);
184+
for (uint i = 0; i < sz; i++) {
185+
const Pin& pin = user_design_inputs_[i];
186+
lprintf(" inp-%u %s (was %s)\n", i,
187+
pin.udes_pin_name_.c_str(), pin.orig_pin_name_.c_str());
188+
}
189+
lprintf(" --------\n");
190+
191+
sz = user_design_outputs_.size();
192+
lprintf(" ---- dumping user_design_outputs_ (after translation) (%zu) ----\n", sz);
193+
for (uint i = 0; i < sz; i++) {
194+
const Pin& pin = user_design_outputs_[i];
195+
lprintf(" out-%u %s (was %s)\n", i,
196+
pin.udes_pin_name_.c_str(), pin.orig_pin_name_.c_str());
197+
}
198+
lprintf(" --------\n");
199+
200+
lprintf(
201+
"DONE read-and-translate-design-ports #udes_inputs= %zu #udes_outputs= %zu\n",
202+
raw_design_inputs_.size(), raw_design_outputs_.size());
203+
}
204+
}
205+
139206
flush_out(true);
140207
return true;
141208
}

0 commit comments

Comments
 (0)