Skip to content

Commit e4110a5

Browse files
authored
Merge pull request #763 from os-fpga/pinc_translate_design_clock_EDA3041
pin_c: translate design_clock EDA-3041
2 parents 4c47317 + c46000b commit e4110a5

File tree

4 files changed

+77
-8
lines changed

4 files changed

+77
-8
lines changed

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

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

planning/src/pin_loc/map_clocks.cpp

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515

1616
#include <map>
1717
#include <filesystem>
18-
#include <unistd.h>
18+
19+
#undef h
20+
#undef H
1921

2022
namespace pln {
2123

@@ -24,6 +26,43 @@ using fio::Fio;
2426

2527
#define CERROR std::cerr << "[Error] "
2628

29+
const PinPlacer::EditItem* PinPlacer::findTerminalLink(const string& pinName) const noexcept {
30+
if (pinName.empty() or all_edits_.empty())
31+
return nullptr;
32+
size_t h = str::hashf(pinName.c_str());
33+
34+
int found_old = -1, cnt_old = 0;
35+
int found_new = -1, cnt_new = 0;
36+
37+
const EditItem* A = all_edits_.data();
38+
for (int i = int(all_edits_.size()) - 1; i >= 0; i--) {
39+
const EditItem& itm = A[i];
40+
//if ( strstr(itm.c_old(), "design_clk_9") or strstr(itm.c_new(), "design_clk_9"))
41+
// lputs9();
42+
if (itm.oldPinHash_ == h and itm.oldPin_ == pinName) {
43+
found_old = i;
44+
cnt_old++;
45+
continue;
46+
}
47+
if (itm.newPinHash_ == h and itm.newPin_ == pinName) {
48+
found_new = i;
49+
cnt_new++;
50+
}
51+
}
52+
53+
// if found > 1 times, then the link is not terminal
54+
if (cnt_old == 1) {
55+
assert(found_old >= 0);
56+
return A + found_old;
57+
}
58+
if (cnt_new == 1) {
59+
assert(found_new >= 0);
60+
return A + found_new;
61+
}
62+
63+
return nullptr;
64+
}
65+
2766
int PinPlacer::map_clocks() {
2867
clk_map_file_.clear();
2968
uint16_t tr = ltrace();
@@ -227,9 +266,28 @@ int PinPlacer::write_clocks_logical_to_physical() {
227266
if (tr >= 6)
228267
lprintf("\t uclk: %s is_post_edit:%i\n", cs, is_post_edit);
229268
if (not is_post_edit) {
230-
postEdit_uclk = translateClockName(uclk);
269+
bool is_input = true;
270+
const EditItem* terminal_link = findTerminalLink(uclk);
271+
if (terminal_link) {
272+
const EditItem& tl = *terminal_link;
273+
if (tl.dir_ < 0)
274+
is_input = false;
275+
if (tr >= 6) {
276+
lprintf(
277+
"\t (tl) %zu mod: %s js_dir:%s dir:%i old: %s new: %s is_inp:%i\n",
278+
tl.nameHash(), tl.c_mod(), tl.c_jsdir(), tl.dir_, tl.c_old(), tl.c_new(), is_input);
279+
}
280+
}
281+
postEdit_uclk = translatePinName(uclk, is_input);
231282
if (tr >= 6)
232283
lprintf("\t\t ..... postEdit_uclk: %s\n", postEdit_uclk.c_str());
284+
if (postEdit_uclk != uclk) {
285+
udes_clocks.back() = postEdit_uclk;
286+
if (tr >= 5) {
287+
lprintf("clock mapping: translated design_clock value from '%s' to '%s'\n",
288+
cs, postEdit_uclk.c_str());
289+
}
290+
}
233291
}
234292
j++;
235293
continue;

planning/src/pin_loc/pin_placer.h

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,11 @@ struct PinPlacer {
2626
string js_dir_; // "OUT", "IN"
2727
string location_; // "HR_5_0_0P"
2828
string mode_; // "Mode_BP_SDR_A_TX"
29+
2930
string oldPin_; // "dout",
30-
string newPin_; // newPin_ is always inside fabric, for both ibuf and obuf
31+
string newPin_; // newPin_ is always inside fabric
32+
33+
size_t oldPinHash_ = 0, newPinHash_ = 0;
3134

3235
vector<string> Q_bus_, D_bus_;
3336

@@ -66,6 +69,11 @@ struct PinPlacer {
6669
bool hasPins() const noexcept { return !oldPin_.empty() and !newPin_.empty(); }
6770
void swapPins() noexcept { std::swap(oldPin_, newPin_); }
6871

72+
void setHash() noexcept {
73+
oldPinHash_ = str::hashf(c_old());
74+
newPinHash_ = str::hashf(c_new());
75+
}
76+
6977
struct CmpOldPin {
7078
bool operator()(const EditItem* a, const EditItem* b) const noexcept {
7179
return a->oldPin_ < b->oldPin_;
@@ -271,10 +279,7 @@ struct PinPlacer {
271279
string translatePinName(const string& pinName, bool is_input) const noexcept;
272280
uint translatePinNames(const string& memo) noexcept;
273281

274-
string translateClockName(const string& clkName) const noexcept {
275-
assert(not clkName.empty());
276-
return translatePinName(clkName, true);
277-
}
282+
const EditItem* findTerminalLink(const string& pinName) const noexcept;
278283
};
279284

280285
}

planning/src/pin_loc/read_ports.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,6 +587,9 @@ static bool s_read_json_items(const nlohmann::ordered_json& from,
587587
}
588588
}
589589

590+
for (PinPlacer::EditItem& itm : items)
591+
itm.setHash();
592+
590593
return not items.empty();
591594
}
592595

@@ -954,6 +957,9 @@ void PinPlacer::set_edit_dirs(bool initial) noexcept {
954957
}
955958
}
956959

960+
for (EditItem& itm : all_edits_)
961+
itm.setHash();
962+
957963
link_edits();
958964
}
959965

0 commit comments

Comments
 (0)