Skip to content

Commit c2664c9

Browse files
authored
Merge pull request #734 from os-fpga/better_handling_of_internal_pin
pin_c: better handling of internal_pin
2 parents d5fcc12 + 8215d56 commit c2664c9

File tree

5 files changed

+76
-16
lines changed

5 files changed

+76
-16
lines changed

planning/src/file_readers/pln_csv_reader.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1734,6 +1734,26 @@ bool PcCsvReader::has_io_pin(const string& pin_name_or_ID) const noexcept {
17341734
return false;
17351735
}
17361736

1737+
vector<uint> PcCsvReader::get_gbox_rows(const string& device_gbox_name) const noexcept {
1738+
assert(!bcd_.empty());
1739+
assert(!device_gbox_name.empty());
1740+
if (device_gbox_name.empty())
1741+
return {};
1742+
1743+
vector<uint> result;
1744+
1745+
// tmp linear search
1746+
uint num_rows = numRows();
1747+
for (uint i = 0; i < num_rows; i++) {
1748+
const BCD& bcd = *bcd_[i];
1749+
if (bcd.match(device_gbox_name)) {
1750+
result.push_back(i);
1751+
}
1752+
}
1753+
1754+
return result;
1755+
}
1756+
17371757
bool PcCsvReader::hasCustomerInternalName(const string& nm) const noexcept {
17381758
assert(!bcd_.empty());
17391759
assert(!nm.empty());

planning/src/file_readers/pln_csv_reader.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ class PcCsvReader {
252252
}
253253

254254
bool has_io_pin(const string& pin_name_or_ID) const noexcept;
255+
vector<uint> get_gbox_rows(const string& device_gbox_name) const noexcept;
255256

256257
bool hasCustomerInternalName(const string& nm) const noexcept;
257258

planning/src/file_readers/pln_pcf_reader.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ struct PcfReader {
2626
void clearInternalPin() noexcept { internalPin_.clear(); }
2727
};
2828

29+
static inline bool is_internal_cmd(const Cmd* p) noexcept {
30+
assert(p);
31+
return p->hasInternalPin();
32+
}
33+
2934
vector<Cmd> commands_;
3035

3136
PcfReader() noexcept = default;

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

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

planning/src/pin_loc/pcf_place.cpp

Lines changed: 49 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -535,8 +535,10 @@ void PinPlacer::translate_pcf_cmds() {
535535
flush_out(false);
536536
}
537537

538-
void PinPlacer::get_pcf_directions( vector<string>& inps, vector<string>& outs,
539-
vector<string>& undefs, vector<string>& internals ) const noexcept {
538+
void PinPlacer::get_pcf_directions(
539+
vector<string>& inps, vector<string>& outs,
540+
vector<string>& undefs,
541+
vector<string>& internals ) const noexcept {
540542
inps.clear();
541543
outs.clear();
542544
undefs.clear();
@@ -568,6 +570,9 @@ void PinPlacer::get_pcf_directions( vector<string>& inps, vector<string>& outs,
568570
else
569571
undefs.push_back(pin);
570572
//
573+
if (cmdObj.hasInternalPin()) {
574+
internals.push_back(cmdObj.internalPin_);
575+
}
571576
}
572577
}
573578

@@ -598,6 +603,8 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
598603
logVec(outs, " [pcf_outputs] ");
599604
lprintf(" ___\n");
600605
if (not internals.empty()) {
606+
logVec(internals, " [pcf_internals] ");
607+
lprintf(" ___\n");
601608
}
602609
}
603610
}
@@ -626,24 +633,49 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
626633
flush_out(true);
627634
}
628635

636+
//lputs9();
637+
// -- do lines with -internal_pin first
638+
vector<const PcfReader::Cmd*> P;
639+
size_t num_cmds = pcf_pin_cmds_.size();
640+
P.reserve(num_cmds + 1);
641+
const PcfReader::Cmd* cmdA = pcf_pin_cmds_.data();
642+
uint cnt_internals = 0;
643+
for (uint i = 0; i < num_cmds; i++) {
644+
P.push_back(cmdA + i);
645+
if (P.back()->hasInternalPin())
646+
cnt_internals++;
647+
}
648+
if (tr >= 4) {
649+
lprintf("cnt_internals= %u num_cmds= %zu\n", cnt_internals, num_cmds);
650+
flush_out(true);
651+
}
652+
if (cnt_internals > 0 and cnt_internals < num_cmds) {
653+
if (tr >= 4) {
654+
lprintf("separating internals (%u) ..\n", cnt_internals);
655+
flush_out(true);
656+
}
657+
std::stable_partition(P.begin(), P.end(), PcfReader::is_internal_cmd);
658+
}
659+
629660
string internalPin;
661+
vector<uint> gbox_rows;
662+
630663
string udes_pn2; // translated according to --edits <config.json>
631664

632665
string row_str;
633666
int row_num = -1;
634667

635668
min_pt_row_ = UINT_MAX; max_pt_row_ = 0;
636669

637-
for (uint cmd_i = 0; cmd_i < pcf_pin_cmds_.size(); cmd_i++) {
670+
assert(P.size() == num_cmds);
671+
for (uint cmd_i = 0; cmd_i < num_cmds; cmd_i++) {
638672

639-
const PcfReader::Cmd& cmdObj = pcf_pin_cmds_[cmd_i];
673+
const PcfReader::Cmd& cmdObj = *P[cmd_i];
640674
const vector<string>& pcf_cmd = cmdObj.cmd_;
641675

642676
// only support io and clock for now
643677
if (pcf_cmd[0] != "set_io" && pcf_cmd[0] != "set_clk") continue;
644678

645-
internalPin.clear();
646-
647679
const string& udes_pn1 = pcf_cmd[1];
648680

649681
bool is_in_pin = (find_udes_input(udes_pn1) >= 0);
@@ -669,13 +701,6 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
669701
logVec(pcf_cmd, " cur pcf_cmd: ");
670702
}
671703

672-
for (size_t i = 1; i < pcf_cmd.size(); i++) {
673-
if (pcf_cmd[i] == "-internal_pin") {
674-
internalPin = pcf_cmd[++i];
675-
break;
676-
}
677-
}
678-
679704
row_str.clear();
680705
row_num = -1;
681706
for (size_t i = 1; i < pcf_cmd.size() - 1; i++) {
@@ -719,6 +744,15 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
719744
return false;
720745
}
721746

747+
internalPin.clear();
748+
if (cmdObj.hasInternalPin()) {
749+
internalPin = cmdObj.internalPin_;
750+
// gbox_rows = csv.get_gbox_rows(device_pin_name);
751+
// if (not gbox_rows.empty()) {
752+
// // search internalPin among gbox_rows
753+
// }
754+
}
755+
722756
const char* direction = "INPUT";
723757

724758
// lookup and write XYZ for 'udes_pin_name'
@@ -764,7 +798,7 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
764798
vector<uint> enabledRows = csv.get_enabled_rows_for_mode(mode);
765799
lprintf(" ---- BEGIN DEBUG_NOTE ---- mode %s (#%u %s) is enabled for %zu rows:\n",
766800
mode.c_str(), col_idx, col_label.c_str(), enabledRows.size());
767-
lputs9();
801+
//lputs9();
768802
for (uint r : enabledRows) {
769803
uint row = r + 2;
770804
const PcCsvReader::BCD& b = csv.getBCD(r);
@@ -821,7 +855,7 @@ bool PinPlacer::write_dot_place(const PcCsvReader& csv) {
821855
vector<uint> enabledRows = csv.get_enabled_rows_for_mode(mode);
822856
lprintf(" ---- BEGIN DEBUG_NOTE ---- mode %s (#%u %s) is enabled for %zu rows:\n",
823857
mode.c_str(), col_idx, col_label.c_str(), enabledRows.size());
824-
lputs9();
858+
//lputs9();
825859
for (uint r : enabledRows) {
826860
uint row = r + 2;
827861
const PcCsvReader::BCD& b = csv.getBCD(r);

0 commit comments

Comments
 (0)