Skip to content

Commit

Permalink
refactor to use create_cell_ptr only
Browse files Browse the repository at this point in the history
  • Loading branch information
mmicko committed Nov 28, 2024
1 parent f885321 commit ea478ee
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 43 deletions.
25 changes: 0 additions & 25 deletions himbaechel/uarch/ng-ultra/cells.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,6 @@

NEXTPNR_NAMESPACE_BEGIN

std::unique_ptr<CellInfo> NgUltraPacker::create_cell(IdString type, IdString name)
{
auto cell = std::make_unique<CellInfo>(ctx, name, type);

auto add_port = [&](const IdString id, PortType dir) {
cell->ports[id].name = id;
cell->ports[id].type = dir;
};
if (type == id_BEYOND_FE) {
add_port(id_I1, PORT_IN);
add_port(id_I2, PORT_IN);
add_port(id_I3, PORT_IN);
add_port(id_I4, PORT_IN);
add_port(id_LO, PORT_OUT);
add_port(id_DI, PORT_IN);
add_port(id_L, PORT_IN);
add_port(id_CK, PORT_IN);
add_port(id_R, PORT_IN);
add_port(id_DO, PORT_OUT);
} else {
log_error("Trying to create unknown cell type %s\n", type.c_str(ctx));
}
return cell;
}

CellInfo *NgUltraPacker::create_cell_ptr(IdString type, IdString name)
{
CellInfo *cell = ctx->createCell(name, type);
Expand Down
33 changes: 17 additions & 16 deletions himbaechel/uarch/ng-ultra/pack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,7 @@ void NgUltraPacker::flush_cells()
}
ctx->cells.erase(pcell);
}
for (auto &ncell : new_cells) {
ctx->cells[ncell->name] = std::move(ncell);
}
packed_cells.clear();
new_cells.clear();
}

void NgUltraPacker::pack_constants(void)
Expand Down Expand Up @@ -581,26 +577,29 @@ void NgUltraPacker::pack_lut_dffs(void)
log_info("Pack LUT-DFFs...\n");

int lut_only = 0, lut_and_ff = 0;
std::vector<CellInfo*> lut_list;
for (auto &cell : ctx->cells) {
CellInfo &ci = *cell.second;
if (!ci.type.in(id_NX_LUT))
continue;
if (!ci.params.count(id_lut_table))
log_error("Cell '%s' missing lut_table\n", ci.name.c_str(ctx));

std::unique_ptr<CellInfo> packed = create_cell(id_BEYOND_FE, ctx->idf("%s$fe", ci.name.c_str(ctx)));
packed_cells.insert(ci.name);
bind_attr_loc(packed.get(), &ci.attrs);
lut_list.push_back(&ci);
}
for (auto ci : lut_list) {
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx)));
bind_attr_loc(packed, &ci->attrs);

bool packed_dff = false;
NetInfo *o = ci.getPort(id_O);
NetInfo *o = ci->getPort(id_O);
if (o) {
CellInfo *dff = net_only_drives(ctx, o, is_dff, id_I, true);
if (dff) {
if (ctx->verbose)
log_info("found attached dff %s\n", dff->name.c_str(ctx));
lut_to_fe(&ci, packed.get(), false, ci.params[id_lut_table]);
dff_to_fe(dff, packed.get(), false);
lut_to_fe(ci, packed, false, ci->params[id_lut_table]);
dff_to_fe(dff, packed, false);
++lut_and_ff;
packed_cells.insert(dff->name);
if (ctx->verbose)
Expand All @@ -609,10 +608,9 @@ void NgUltraPacker::pack_lut_dffs(void)
}
}
if (!packed_dff) {
lut_to_fe(&ci, packed.get(), true, ci.params[id_lut_table]);
lut_to_fe(ci, packed, true, ci->params[id_lut_table]);
++lut_only;
}
new_cells.push_back(std::move(packed));
}
if (lut_only)
log_info(" %6d FEs used as LUT only\n", lut_only);
Expand All @@ -624,16 +622,19 @@ void NgUltraPacker::pack_lut_dffs(void)
void NgUltraPacker::pack_dffs(void)
{
int dff_only = 0;
std::vector<CellInfo*> dff_list;
for (auto &cell : ctx->cells) {
CellInfo &ci = *cell.second;
if (!ci.type.in(id_NX_DFF, id_NX_BFF))
continue;
std::unique_ptr<CellInfo> packed = create_cell(id_BEYOND_FE, ctx->idf("%s$fe", ci.name.c_str(ctx)));
packed_cells.insert(ci.name);
dff_to_fe(&ci, packed.get(), true);
bind_attr_loc(packed.get(), &ci.attrs);
dff_list.push_back(&ci);
}
for (auto ci : dff_list) {
CellInfo *packed = create_cell_ptr(id_BEYOND_FE, ctx->idf("%s$fe", ci->name.c_str(ctx)));
dff_to_fe(ci, packed, true);
bind_attr_loc(packed, &ci->attrs);
++dff_only;
new_cells.push_back(std::move(packed));
}
if (dff_only)
log_info(" %6d FEs used as DFF only\n", dff_only);
Expand Down
2 changes: 0 additions & 2 deletions himbaechel/uarch/ng-ultra/pack.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,12 @@ struct NgUltraPacker
void constrain_location(CellInfo *cell);
void extract_lowskew_signals(CellInfo *cell, dict<IdString,dict<IdString,std::vector<PortRef>>> &lowskew_signals);
// Cell creating
std::unique_ptr<CellInfo> create_cell(IdString type, IdString name);
CellInfo *create_cell_ptr(IdString type, IdString name);

Context *ctx;
NgUltraImpl *uarch;

pool<IdString> packed_cells;
std::vector<std::unique_ptr<CellInfo>> new_cells;
pool<IdString> global_lowskew;

HimbaechelHelpers h;
Expand Down

0 comments on commit ea478ee

Please sign in to comment.