Skip to content

Commit f9d78c9

Browse files
committed
ram: added tapcell insertion, cleaned up names
Signed-off-by: braydenl9988 <[email protected]>
1 parent a43c6df commit f9d78c9

File tree

7 files changed

+139
-21
lines changed

7 files changed

+139
-21
lines changed

src/ram/include/ram/ram.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,9 @@ class RamGen
4646
int read_ports,
4747
odb::dbMaster* storage_cell,
4848
odb::dbMaster* tristate_cell,
49-
odb::dbMaster* inv_cell);
49+
odb::dbMaster* inv_cell,
50+
odb::dbMaster* tapcell,
51+
int max_tap_dist);
5052

5153
private:
5254
void findMasters();
@@ -104,6 +106,7 @@ class RamGen
104106
odb::dbMaster* and2_cell_{nullptr};
105107
odb::dbMaster* clock_gate_cell_{nullptr};
106108
odb::dbMaster* buffer_cell_{nullptr};
109+
odb::dbMaster* tapcell_{nullptr};
107110
};
108111

109112
} // namespace ram

src/ram/src/layout.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ void Cell::addInst(dbInst* inst)
3434

3535
void Cell::cellInit()
3636
{
37+
if (width_ > 0 || height_ > 0) {
38+
width_ = 0;
39+
height_ = 0;
40+
}
3741
for (auto& inst : insts_) {
3842
Rect inst_box = inst->getBBox()->getBox();
3943
width_ += inst_box.dx();
@@ -166,6 +170,18 @@ void Grid::addLayout(std::unique_ptr<Layout> layout)
166170
layouts_.push_back(std::move(layout));
167171
}
168172

173+
bool Grid::insertLayout(std::unique_ptr<Layout> layout, int index)
174+
{
175+
if (index == layouts_.size()) {
176+
layouts_.push_back(std::move(layout));
177+
} else if (index < layouts_.size()){
178+
layouts_.insert(layouts_.begin() + index, std::move(layout));
179+
} else if (index > layouts_.size()) {
180+
return false;
181+
}
182+
return true;
183+
}
184+
169185
void Grid::addCell(std::unique_ptr<Cell> cell, int track)
170186
{
171187
if (track >= layouts_.size()) {
@@ -226,6 +242,16 @@ int Grid::numLayouts() const
226242
return layouts_.size();
227243
}
228244

245+
int Grid::getLayoutWidth(int index) const
246+
{
247+
return layouts_[index]->getWidth();
248+
}
249+
250+
int Grid::getLayoutHeight(int index) const
251+
{
252+
return layouts_[index]->getHeight();
253+
}
254+
229255
int Grid::getRowWidth() const
230256
{
231257
int row_width = 0;

src/ram/src/layout.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,8 @@ class Grid
8282

8383
void addLayout(std::unique_ptr<Layout> layout);
8484

85+
bool insertLayout(std::unique_ptr<Layout> layout, int index);
86+
8587
void addCell(std::unique_ptr<Cell> cell, int track);
8688

8789
void gridInit();
@@ -96,6 +98,10 @@ class Grid
9698

9799
int numLayouts() const;
98100

101+
int getLayoutWidth(int index) const;
102+
103+
int getLayoutHeight(int index) const;
104+
99105
int getRowWidth() const;
100106

101107
private:

src/ram/src/ram.cpp

Lines changed: 52 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,9 @@ void RamGen::generate(const int bytes_per_word,
371371
const int read_ports,
372372
dbMaster* storage_cell,
373373
dbMaster* tristate_cell,
374-
dbMaster* inv_cell)
374+
dbMaster* inv_cell,
375+
dbMaster* tapcell,
376+
int max_tap_dist)
375377
{
376378
const int bits_per_word = bytes_per_word * 8;
377379
const std::string ram_name
@@ -382,10 +384,12 @@ void RamGen::generate(const int bytes_per_word,
382384
storage_cell_ = storage_cell;
383385
tristate_cell_ = tristate_cell;
384386
inv_cell_ = inv_cell;
387+
tapcell_ = tapcell;
385388
and2_cell_ = nullptr;
386389
clock_gate_cell_ = nullptr;
387390
buffer_cell_ = nullptr;
388391
findMasters();
392+
max_tap_dist *= 10;
389393

390394
auto chip = db_->getChip();
391395
if (!chip) {
@@ -503,40 +507,40 @@ void RamGen::generate(const int bytes_per_word,
503507
}
504508

505509
for (int bit = 0; bit < 8; ++bit) {
506-
auto buffer_cell = std::make_unique<Cell>();
507-
makeCellInst(buffer_cell.get(),
510+
auto buffer_grid_cell = std::make_unique<Cell>();
511+
makeCellInst(buffer_grid_cell.get(),
508512
"buffer",
509513
fmt::format("in[{}]", bit),
510514
buffer_cell_,
511515
{{"A", D_bTerms[bit]->getNet()}, {"X", D_nets[bit]}});
512-
ram_grid.addCell(std::move(buffer_cell), bit);
516+
ram_grid.addCell(std::move(buffer_grid_cell), bit);
513517
}
514518
}
515519

516520
auto cell_inv_layout = std::make_unique<Layout>(odb::vertical);
517521
// check for AND gate, specific case for 2 words
518522
if (num_inputs > 1) {
519523
for (int i = num_inputs - 1; i >= 0; --i) {
520-
auto inv_cell = std::make_unique<Cell>();
521-
makeCellInst(inv_cell.get(),
524+
auto inv_grid_cell = std::make_unique<Cell>();
525+
makeCellInst(inv_grid_cell.get(),
522526
"decoder",
523527
fmt::format("inv_{}", i),
524528
inv_cell_,
525529
{{"A", addr[i]->getNet()}, {"Y", inv_addr[i]}});
526-
cell_inv_layout->addCell(std::move(inv_cell));
530+
cell_inv_layout->addCell(std::move(inv_grid_cell));
527531
for (int filler_count = 0; filler_count < num_inputs - 1;
528532
++filler_count) {
529533
cell_inv_layout->addCell(nullptr);
530534
}
531535
}
532536
} else {
533-
auto inv_cell = std::make_unique<Cell>();
534-
makeCellInst(inv_cell.get(),
537+
auto inv_grid_cell = std::make_unique<Cell>();
538+
makeCellInst(inv_grid_cell.get(),
535539
"decoder",
536540
fmt::format("inv_{}", 0),
537541
inv_cell_,
538542
{{"A", addr[0]->getNet()}, {"Y", inv_addr[0]}});
539-
cell_inv_layout->addCell(std::move(inv_cell));
543+
cell_inv_layout->addCell(std::move(inv_grid_cell));
540544
}
541545

542546
ram_grid.addLayout(std::move(cell_inv_layout));
@@ -546,6 +550,44 @@ void RamGen::generate(const int bytes_per_word,
546550
ram_grid.setOrigin(ram_origin);
547551
ram_grid.gridInit();
548552

553+
if (tapcell_) {
554+
if (ram_grid.getRowWidth() <= max_tap_dist) {
555+
auto tapcell_layout = std::make_unique<Layout>(odb::vertical);
556+
for (int i = 0; i < word_count; ++i) {
557+
auto tapcell_cell = std::make_unique<Cell>();
558+
makeCellInst(tapcell_cell.get(),
559+
"tapcell",
560+
fmt::format("cell_{}", i),
561+
tapcell_,
562+
{});
563+
tapcell_layout->addCell(std::move(tapcell_cell));
564+
}
565+
ram_grid.insertLayout(std::move(tapcell_layout), 0);
566+
} else {
567+
int nearest_tap = 0;
568+
for (int col = 0; col < ram_grid.numLayouts(); ++col) {
569+
if (nearest_tap >= max_tap_dist) {
570+
auto tapcell_layout = std::make_unique<Layout>(odb::vertical);
571+
for (int i = 0; i < word_count; ++i) {
572+
auto tapcell_cell = std::make_unique<Cell>();
573+
makeCellInst(tapcell_cell.get(),
574+
"tapcell",
575+
fmt::format("cell{}_{}", col, i),
576+
tapcell_,
577+
{});
578+
tapcell_layout->addCell(std::move(tapcell_cell));
579+
}
580+
ram_grid.insertLayout(std::move(tapcell_layout), col);
581+
++col;
582+
nearest_tap = 0;
583+
}
584+
nearest_tap += ram_grid.getLayoutWidth(col);
585+
}
586+
}
587+
}
588+
589+
ram_grid.gridInit();
590+
549591
auto db_libs = db_->getLibs().begin();
550592
auto db_sites = *(db_libs->getSites().begin());
551593
auto sites_width = db_sites->getWidth();

src/ram/src/ram.i

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,9 @@ generate_ram_netlist_cmd(int bytes_per_word,
2020
const char* storage_cell_name,
2121
const char* tristate_cell_name,
2222
const char* inv_cell_name,
23-
const int read_ports)
23+
const int read_ports,
24+
const char* tapcell_name,
25+
const int max_tap_dist)
2426
{
2527
auto* app = ord::OpenRoad::openRoad();
2628
auto* ram_gen = app->getRamGen();
@@ -58,8 +60,21 @@ generate_ram_netlist_cmd(int bytes_per_word,
5860
inv_cell_name);
5961
}
6062
}
63+
64+
odb::dbMaster* tapcell = nullptr;
65+
if (tapcell_name[0] != '\0') {
66+
tapcell = db->findMaster(tapcell_name);
67+
if (!tapcell) {
68+
app->getLogger()->error(utl::RAM,
69+
19,
70+
"Tapcell {} can't be found",
71+
tapcell_name);
72+
}
73+
}
74+
6175
ram_gen->generate(bytes_per_word, word_count, read_ports,
62-
storage_cell, tristate_cell, inv_cell);
76+
storage_cell, tristate_cell, inv_cell, tapcell,
77+
max_tap_dist);
6378
}
6479

6580
} //namespace_ram

src/ram/src/ram.tcl

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@ sta::define_cmd_args "generate_ram_netlist" {-bytes_per_word bits
66
[-storage_cell name]
77
[-tristate_cell name]
88
[-inv_cell name]
9-
[-read_ports count]}
9+
[-read_ports count]
10+
[-tapcell name]
11+
[-max_tap_dist value]}
1012

1113
proc generate_ram_netlist { args } {
1214
sta::parse_key_args "generate_ram_netlist" args \
13-
keys {-bytes_per_word -word_count -storage_cell -tristate_cell -inv_cell
14-
-read_ports } flags {}
15+
keys { -bytes_per_word -word_count -storage_cell -tristate_cell -inv_cell
16+
-read_ports -tapcell -max_tap_dist } flags {}
1517

1618
if { [info exists keys(-bytes_per_word)] } {
1719
set bytes_per_word $keys(-bytes_per_word)
@@ -45,8 +47,19 @@ proc generate_ram_netlist { args } {
4547
set read_ports $keys(-read_ports)
4648
}
4749

50+
set tapcell ""
51+
set max_tap_dist 0
52+
if { [info exists keys(-tapcell)] } {
53+
if { [info exists keys(-max_tap_dist)] } {
54+
set max_tap_dist $keys(-max_tap_dist)
55+
} else {
56+
utl::error RAM 21 "The -max_tap_dist argument must be specified with tapcell."
57+
}
58+
set tapcell $keys(-tapcell)
59+
}
60+
4861
ram::generate_ram_netlist_cmd $bytes_per_word $word_count $storage_cell \
49-
$tristate_cell $inv_cell $read_ports
62+
$tristate_cell $inv_cell $read_ports $tapcell $max_tap_dist
5063
}
5164

5265
sta::define_cmd_args "generate_ram" {-bytes_per_word bits
@@ -60,13 +73,16 @@ sta::define_cmd_args "generate_ram" {-bytes_per_word bits
6073
-routing_layer config
6174
-ver_layer config
6275
-hor_layer config
63-
-filler_cells fillers}
76+
-filler_cells fillers
77+
[-tapcell name]
78+
[-max_tap_dist value]}
6479

6580
# user arguments for generate ram arguments
6681
proc generate_ram { args } {
6782
sta::parse_key_args "generate_ram" args \
68-
keys {-bytes_per_word -word_count -storage_cell -tristate_cell -inv_cell -read_ports
69-
-power_pin -ground_pin -routing_layer -ver_layer -hor_layer -filler_cells} flags {}
83+
keys { -bytes_per_word -word_count -storage_cell -tristate_cell -inv_cell -read_ports
84+
-power_pin -ground_pin -routing_layer -ver_layer -hor_layer -filler_cells
85+
-tapcell -max_tap_dist} flags {}
7086

7187
sta::check_argc_eq0 "generate_ram" $args
7288

@@ -95,6 +111,14 @@ proc generate_ram { args } {
95111
lappend ram_netlist_args -inv_cell $keys(-inv_cell)
96112
}
97113

114+
if { [info exists keys(-tapcell)] } {
115+
lappend ram_netlist_args -tapcell $keys(-tapcell)
116+
}
117+
118+
if { [info exists keys(-max_tap_dist)] } {
119+
lappend ram_netlist_args -max_tap_dist $keys(-max_tap_dist)
120+
}
121+
98122
generate_ram_netlist {*}$ram_netlist_args
99123

100124
ord::design_created

src/ram/test/make_8x8.tcl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,9 @@ generate_ram \
1818
-ver_layer {met2 0.48 40} \
1919
-hor_layer {met3 0.48 20} \
2020
-filler_cells {sky130_fd_sc_hd__fill_1 sky130_fd_sc_hd__fill_2 \
21-
sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8}
21+
sky130_fd_sc_hd__fill_4 sky130_fd_sc_hd__fill_8} \
22+
-tapcell sky130_fd_sc_hd__tap_1 \
23+
-max_tap_dist 3000
2224

2325
set lef_file [make_result_file make_8x8.lef]
2426
write_abstract_lef $lef_file

0 commit comments

Comments
 (0)