| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2023 Myrtle Shah <[email protected]> |
| 5 |
* |
| 6 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 7 |
* purpose with or without fee is hereby granted, provided that the above |
| 8 |
* copyright notice and this permission notice appear in all copies. |
| 9 |
* |
| 10 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 11 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 12 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 13 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 14 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 15 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 16 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 17 |
* |
| 18 |
*/ |
| 19 |
|
| 20 |
#include <algorithm> |
| 21 |
#include <boost/optional.hpp> |
| 22 |
#include <iterator> |
| 23 |
#include <queue> |
| 24 |
#include <unordered_set> |
| 25 |
#include "chain_utils.h" |
| 26 |
#include "design_utils.h" |
| 27 |
#include "extra_data.h" |
| 28 |
#include "log.h" |
| 29 |
#include "nextpnr.h" |
| 30 |
#include "pack.h" |
| 31 |
#include "pins.h" |
| 32 |
|
| 33 |
#define HIMBAECHEL_CONSTIDS "uarch/xilinx/constids.inc" |
| 34 |
#include "himbaechel_constids.h" |
| 35 |
|
| 36 |
NEXTPNR_NAMESPACE_BEGIN |
| 37 |
|
| 38 |
CellInfo *XilinxPacker::create_dram_lut(const std::string &name, CellInfo *base, const DRAMControlSet &ctrlset, |
| 39 |
std::vector<NetInfo *> address, NetInfo *di, NetInfo *dout, int z) |
| 40 |
{ |
| 41 |
CellInfo *dram_lut = create_cell(id_RAMD64E, ctx->id(name)); |
| 42 |
for (int i = 0; i < int(address.size()); i++) |
| 43 |
dram_lut->connectPort(ctx->idf("RADR%d", i), address[i]); |
| 44 |
dram_lut->connectPort(id_I, di); |
| 45 |
dram_lut->connectPort(id_O, dout); |
| 46 |
dram_lut->connectPort(id_CLK, ctrlset.wclk); |
| 47 |
dram_lut->connectPort(id_WE, ctrlset.we); |
| 48 |
for (int i = 0; i < int(ctrlset.wa.size()); i++) |
| 49 |
dram_lut->connectPort(ctx->idf("WADR%d", i), ctrlset.wa[i]); |
| 50 |
dram_lut->params[id_IS_WCLK_INVERTED] = ctrlset.wclk_inv ? 1 : 0; |
| 51 |
|
| 52 |
xform_cell(dram_rules, dram_lut); |
| 53 |
|
| 54 |
dram_lut->constr_abs_z = true; |
| 55 |
dram_lut->constr_z = (z << 4) | BEL_6LUT; |
| 56 |
if (base != nullptr) { |
| 57 |
dram_lut->cluster = base->name; |
| 58 |
dram_lut->constr_x = 0; |
| 59 |
dram_lut->constr_y = 0; |
| 60 |
base->constr_children.push_back(dram_lut); |
| 61 |
} |
| 62 |
if (base == nullptr) { |
| 63 |
dram_lut->cluster = dram_lut->name; |
| 64 |
} |
| 65 |
return dram_lut; |
| 66 |
} |
| 67 |
|
| 68 |
CellInfo *XilinxPacker::create_dram32_lut(const std::string &name, CellInfo *base, const DRAMControlSet &ctrlset, |
| 69 |
std::vector<NetInfo *> address, NetInfo *di, NetInfo *dout, bool o5, int z) |
| 70 |
{ |
| 71 |
CellInfo *dram_lut = create_cell(id_RAMD32, ctx->id(name)); |
| 72 |
for (int i = 0; i < int(address.size()); i++) |
| 73 |
dram_lut->connectPort(ctx->idf("RADR%d", i), address[i]); |
| 74 |
dram_lut->connectPort(id_I, di); |
| 75 |
dram_lut->connectPort(id_O, dout); |
| 76 |
dram_lut->connectPort(id_CLK, ctrlset.wclk); |
| 77 |
dram_lut->connectPort(id_WE, ctrlset.we); |
| 78 |
for (int i = 0; i < int(ctrlset.wa.size()); i++) |
| 79 |
dram_lut->connectPort(ctx->idf("WADR%d", i), ctrlset.wa[i]); |
| 80 |
dram_lut->params[id_IS_WCLK_INVERTED] = ctrlset.wclk_inv ? 1 : 0; |
| 81 |
|
| 82 |
xform_cell(o5 ? dram32_5_rules : dram32_6_rules, dram_lut); |
| 83 |
|
| 84 |
dram_lut->constr_abs_z = true; |
| 85 |
dram_lut->constr_z = (z << 4) | (o5 ? BEL_5LUT : BEL_6LUT); |
| 86 |
if (base != nullptr) { |
| 87 |
dram_lut->cluster = base->name; |
| 88 |
dram_lut->constr_x = 0; |
| 89 |
dram_lut->constr_y = 0; |
| 90 |
base->constr_children.push_back(dram_lut); |
| 91 |
} |
| 92 |
if (base == nullptr) { |
| 93 |
dram_lut->cluster = dram_lut->name; |
| 94 |
} |
| 95 |
return dram_lut; |
| 96 |
} |
| 97 |
|
| 98 |
void XilinxPacker::create_muxf_tree(CellInfo *base, const std::string &name_base, const std::vector<NetInfo *> &data, |
| 99 |
const std::vector<NetInfo *> &select, NetInfo *out, int zoffset) |
| 100 |
{ |
| 101 |
int levels = 0; |
| 102 |
if (data.size() <= 2) |
| 103 |
levels = 1; |
| 104 |
else if (data.size() <= 4) |
| 105 |
levels = 2; |
| 106 |
else if (data.size() <= 8) |
| 107 |
levels = 3; |
| 108 |
else |
| 109 |
NPNR_ASSERT_FALSE("muxf tree too large"); |
| 110 |
NPNR_ASSERT(int(select.size()) == levels); |
| 111 |
std::vector<std::vector<NetInfo *>> int_data; |
| 112 |
CellInfo *mux_root = nullptr; |
| 113 |
int_data.push_back(data); |
| 114 |
for (int i = 0; i < levels; i++) { |
| 115 |
IdString mux_type; |
| 116 |
if (i == 0) |
| 117 |
mux_type = id_MUXF7; |
| 118 |
else if (i == 1) |
| 119 |
mux_type = id_MUXF8; |
| 120 |
else if (i == 2) |
| 121 |
mux_type = id_MUXF9; |
| 122 |
else |
| 123 |
NPNR_ASSERT_FALSE("unknown muxf type"); |
| 124 |
int_data.emplace_back(); |
| 125 |
auto &last = int_data.at(int_data.size() - 2); |
| 126 |
for (int j = 0; j < int(last.size()) / 2; j++) { |
| 127 |
NetInfo *output = |
| 128 |
(i == (levels - 1)) |
| 129 |
? out |
| 130 |
: create_internal_net(base->name, stringf("%s_muxq_%d_%d", name_base.c_str(), i, j), false); |
| 131 |
int_data.back().push_back(output); |
| 132 |
auto mux = create_cell(mux_type, |
| 133 |
int_name(base->name, stringf("%s_muxf_%d_%d", name_base.c_str(), i, j), false)); |
| 134 |
mux->connectPort(id_I0, last.at(j * 2)); |
| 135 |
mux->connectPort(id_I1, last.at(j * 2 + 1)); |
| 136 |
mux->connectPort(id_S, select.at(i)); |
| 137 |
mux->connectPort(id_O, output); |
| 138 |
if (i == (levels - 1)) |
| 139 |
mux_root = mux; |
| 140 |
} |
| 141 |
} |
| 142 |
constrain_muxf_tree(mux_root, base, zoffset); |
| 143 |
} |
| 144 |
|
| 145 |
void XilinxPacker::pack_dram() |
| 146 |
{ |
| 147 |
|
| 148 |
log_info("Packing DRAM..\n"); |
| 149 |
|
| 150 |
dict<DRAMControlSet, std::vector<CellInfo *>> dram_groups; |
| 151 |
dict<IdString, DRAMType> dram_types; |
| 152 |
|
| 153 |
dram_types[id_RAM32X1S] = {5, 1, 0}; |
| 154 |
dram_types[id_RAM32X1D] = {5, 1, 1}; |
| 155 |
dram_types[id_RAM64X1S] = {6, 1, 0}; |
| 156 |
dram_types[id_RAM64X1D] = {6, 1, 1}; |
| 157 |
dram_types[id_RAM128X1S] = {7, 1, 0}; |
| 158 |
dram_types[id_RAM128X1D] = {7, 1, 1}; |
| 159 |
dram_types[id_RAM256X1S] = {8, 1, 0}; |
| 160 |
dram_types[id_RAM256X1D] = {8, 1, 1}; |
| 161 |
dram_types[id_RAM512X1S] = {9, 1, 0}; |
| 162 |
dram_types[id_RAM512X1D] = {9, 1, 1}; |
| 163 |
|
| 164 |
// Transform from RAMD64E UNISIM to SLICE_LUTX bel |
| 165 |
dram_rules[id_RAMD64E].new_type = id_SLICE_LUTX; |
| 166 |
dram_rules[id_RAMD64E].param_xform[id_IS_CLK_INVERTED] = id_IS_WCLK_INVERTED; |
| 167 |
dram_rules[id_RAMD64E].set_attrs.emplace_back(id_X_LUT_AS_DRAM, "1"); |
| 168 |
for (int i = 0; i < 6; i++) |
| 169 |
dram_rules[id_RAMD64E].port_xform[ctx->idf("RADR%d", i)] = ctx->idf("A%d", i + 1); |
| 170 |
for (int i = 0; i < 8; i++) |
| 171 |
dram_rules[id_RAMD64E].port_xform[ctx->idf("WADR%d", i)] = ctx->idf("WA%d", i + 1); |
| 172 |
dram_rules[id_RAMD64E].port_xform[id_I] = id_DI1; |
| 173 |
dram_rules[id_RAMD64E].port_xform[id_O] = id_O6; |
| 174 |
|
| 175 |
// Rules for upper and lower RAMD32E |
| 176 |
dram32_6_rules[id_RAMD32].new_type = id_SLICE_LUTX; |
| 177 |
dram32_6_rules[id_RAMD32].param_xform[id_IS_CLK_INVERTED] = id_IS_WCLK_INVERTED; |
| 178 |
dram32_6_rules[id_RAMD32].set_attrs.emplace_back(id_X_LUT_AS_DRAM, "1"); |
| 179 |
for (int i = 0; i < 5; i++) |
| 180 |
dram32_6_rules[id_RAMD32].port_xform[ctx->idf("RADR%d", i)] = ctx->idf("A%d", i + 1); |
| 181 |
for (int i = 0; i < 5; i++) |
| 182 |
dram32_6_rules[id_RAMD32].port_xform[ctx->idf("WADR%d", i)] = ctx->idf("WA%d", i + 1); |
| 183 |
dram32_6_rules[id_RAMD32].port_xform[id_I] = id_DI2; |
| 184 |
dram32_6_rules[id_RAMD32].port_xform[id_O] = id_O6; |
| 185 |
|
| 186 |
dram32_5_rules = dram32_6_rules; |
| 187 |
dram32_5_rules[id_RAMD32].port_xform[id_I] = id_DI1; |
| 188 |
dram32_5_rules[id_RAMD32].port_xform[id_O] = id_O5; |
| 189 |
|
| 190 |
// Optimise DRAM with tied-low inputs, to more efficiently routeable tied-high inputs |
| 191 |
int inverted_ports = 0; |
| 192 |
for (auto &cell : ctx->cells) { |
| 193 |
CellInfo *ci = cell.second.get(); |
| 194 |
auto dt_iter = dram_types.find(ci->type); |
| 195 |
if (dt_iter == dram_types.end()) |
| 196 |
continue; |
| 197 |
auto &dt = dt_iter->second; |
| 198 |
for (int i = 0; i < std::min(dt.abits, 6); i++) { |
| 199 |
IdString aport = ctx->idf(dt.abits <= 6 ? "A%d" : "A[%d]", i); |
| 200 |
if (!ci->ports.count(aport)) |
| 201 |
continue; |
| 202 |
NetInfo *anet = ci->getPort(aport); |
| 203 |
if (anet == nullptr || anet->name != ctx->id("$PACKER_GND_NET")) |
| 204 |
continue; |
| 205 |
IdString raport; |
| 206 |
if (dt.rports >= 1) { |
| 207 |
NPNR_ASSERT(dt.rports == 1); // FIXME |
| 208 |
raport = ctx->idf(dt.abits <= 6 ? "DPRA%d" : "DPRA[%d]", i); |
| 209 |
NetInfo *ranet = ci->getPort(raport); |
| 210 |
if (ranet == nullptr || ranet->name != ctx->id("$PACKER_GND_NET")) |
| 211 |
continue; |
| 212 |
} |
| 213 |
ci->disconnectPort(aport); |
| 214 |
if (raport != IdString()) |
| 215 |
ci->disconnectPort(raport); |
| 216 |
ci->connectPort(aport, ctx->nets[ctx->id("$PACKER_VCC_NET")].get()); |
| 217 |
if (raport != IdString()) |
| 218 |
ci->connectPort(raport, ctx->nets[ctx->id("$PACKER_VCC_NET")].get()); |
| 219 |
++inverted_ports; |
| 220 |
if (ci->params.count(id_INIT)) { |
| 221 |
Property &init = ci->params[id_INIT]; |
| 222 |
for (int j = 0; j < int(init.str.size()); j++) { |
| 223 |
if (j & (1 << i)) |
| 224 |
init.str[j] = init.str[j & ~(1 << i)]; |
| 225 |
} |
| 226 |
init.update_intval(); |
| 227 |
} |
| 228 |
} |
| 229 |
} |
| 230 |
log_info(" Transformed %d tied-low DRAM address inputs to be tied-high\n", inverted_ports); |
| 231 |
|
| 232 |
for (auto &cell : ctx->cells) { |
| 233 |
CellInfo *ci = cell.second.get(); |
| 234 |
auto dt_iter = dram_types.find(ci->type); |
| 235 |
if (dt_iter == dram_types.end()) |
| 236 |
continue; |
| 237 |
auto &dt = dt_iter->second; |
| 238 |
DRAMControlSet dcs; |
| 239 |
for (int i = 0; i < dt.abits; i++) |
| 240 |
dcs.wa.push_back(ci->getPort(ctx->idf((dt.abits <= 6 || ci->type == id_RAM128X1S) ? "A%d" : "A[%d]", i))); |
| 241 |
dcs.wclk = ci->getPort(id_WCLK); |
| 242 |
dcs.we = ci->getPort(id_WE); |
| 243 |
dcs.wclk_inv = bool_or_default(ci->params, id_IS_WCLK_INVERTED); |
| 244 |
dcs.memtype = ci->type; |
| 245 |
dram_groups[dcs].push_back(ci); |
| 246 |
} |
| 247 |
|
| 248 |
int height = /*ctx->xc7 ? 4 : 8*/ 4; |
| 249 |
// Grouped DRAM |
| 250 |
for (auto &group : dram_groups) { |
| 251 |
auto &cs = group.first; |
| 252 |
if (cs.memtype == id_RAM64X1D) { |
| 253 |
int z = height - 1; |
| 254 |
CellInfo *base = nullptr; |
| 255 |
for (auto cell : group.second) { |
| 256 |
NPNR_ASSERT(cell->type == id_RAM64X1D); // FIXME |
| 257 |
|
| 258 |
int z_size = 0; |
| 259 |
if (cell->getPort(id_SPO) != nullptr) |
| 260 |
z_size++; |
| 261 |
if (cell->getPort(id_DPO) != nullptr) |
| 262 |
z_size++; |
| 263 |
|
| 264 |
if (z == (height - 1) || (z - z_size + 1) < 0) { |
| 265 |
z = (height - 1); |
| 266 |
// Topmost cell is the write address input |
| 267 |
std::vector<NetInfo *> address(cs.wa.begin(), cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6)); |
| 268 |
base = create_dram_lut(cell->name.str(ctx) + "/ADDR", nullptr, cs, address, nullptr, nullptr, z); |
| 269 |
z--; |
| 270 |
} |
| 271 |
|
| 272 |
NetInfo *dpo = cell->getPort(id_DPO); |
| 273 |
NetInfo *spo = cell->getPort(id_SPO); |
| 274 |
cell->disconnectPort(id_DPO); |
| 275 |
cell->disconnectPort(id_SPO); |
| 276 |
|
| 277 |
NetInfo *di = cell->getPort(id_D); |
| 278 |
if (spo != nullptr) { |
| 279 |
if (z == (height - 2)) { |
| 280 |
// Can fold DPO into address buffer |
| 281 |
base->connectPort(id_O6, spo); |
| 282 |
base->connectPort(id_DI1, di); |
| 283 |
if (cell->params.count(id_INIT)) |
| 284 |
base->params[id_INIT] = cell->params[id_INIT]; |
| 285 |
} else { |
| 286 |
std::vector<NetInfo *> address(cs.wa.begin(), |
| 287 |
cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6)); |
| 288 |
CellInfo *dpr = create_dram_lut(cell->name.str(ctx) + "/SP", base, cs, address, di, spo, z); |
| 289 |
if (cell->params.count(id_INIT)) |
| 290 |
dpr->params[id_INIT] = cell->params[id_INIT]; |
| 291 |
z--; |
| 292 |
} |
| 293 |
} |
| 294 |
|
| 295 |
if (dpo != nullptr) { |
| 296 |
std::vector<NetInfo *> address; |
| 297 |
for (int i = 0; i < 6; i++) |
| 298 |
address.push_back(cell->getPort(ctx->id("DPRA" + std::to_string(i)))); |
| 299 |
CellInfo *dpr = create_dram_lut(cell->name.str(ctx) + "/DP", base, cs, address, di, dpo, z); |
| 300 |
if (cell->params.count(id_INIT)) |
| 301 |
dpr->params[id_INIT] = cell->params[id_INIT]; |
| 302 |
z--; |
| 303 |
} |
| 304 |
|
| 305 |
packed_cells.insert(cell->name); |
| 306 |
} |
| 307 |
} else if (cs.memtype == id_RAM64X1S) { |
| 308 |
int z = height - 1; |
| 309 |
CellInfo *base = nullptr; |
| 310 |
for (auto cell : group.second) { |
| 311 |
NPNR_ASSERT(cell->type == id_RAM64X1S); // FIXME |
| 312 |
|
| 313 |
if (z == (height - 1) || (z - 1) < 0) { |
| 314 |
z = (height - 1); |
| 315 |
base = nullptr; |
| 316 |
} |
| 317 |
|
| 318 |
std::vector<NetInfo *> address(cs.wa.begin(), cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6)); |
| 319 |
CellInfo *ram = create_dram_lut(cell->name.str(ctx) + "/ADDR", base, cs, address, cell->getPort(id_D), |
| 320 |
cell->getPort(id_O), z); |
| 321 |
if (cell->params.count(id_INIT)) |
| 322 |
ram->params[id_INIT] = cell->params[id_INIT]; |
| 323 |
if (base == nullptr) |
| 324 |
base = ram; |
| 325 |
z--; |
| 326 |
packed_cells.insert(cell->name); |
| 327 |
} |
| 328 |
} else if (cs.memtype == id_RAM32X1D) { |
| 329 |
int z = (height - 1); |
| 330 |
CellInfo *base = nullptr; |
| 331 |
for (auto cell : group.second) { |
| 332 |
NPNR_ASSERT(cell->type == id_RAM32X1D); |
| 333 |
|
| 334 |
int z_size = 0; |
| 335 |
if (cell->getPort(id_SPO) != nullptr) |
| 336 |
z_size++; |
| 337 |
if (cell->getPort(id_DPO) != nullptr) |
| 338 |
z_size++; |
| 339 |
|
| 340 |
if (z == (height - 1) || (z - z_size + 1) < 0) { |
| 341 |
z = (height - 1); |
| 342 |
// Topmost cell is the write address input |
| 343 |
std::vector<NetInfo *> address(cs.wa.begin(), cs.wa.begin() + std::min<size_t>(cs.wa.size(), 5)); |
| 344 |
address.push_back(ctx->nets[ctx->id("$PACKER_GND_NET")].get()); |
| 345 |
base = create_dram_lut(cell->name.str(ctx) + "/ADDR", nullptr, cs, address, nullptr, nullptr, z); |
| 346 |
z--; |
| 347 |
} |
| 348 |
|
| 349 |
NetInfo *dpo = cell->getPort(id_DPO); |
| 350 |
NetInfo *spo = cell->getPort(id_SPO); |
| 351 |
cell->disconnectPort(id_DPO); |
| 352 |
cell->disconnectPort(id_SPO); |
| 353 |
|
| 354 |
NetInfo *di = cell->getPort(id_D); |
| 355 |
if (spo != nullptr) { |
| 356 |
if (z == (height - 2)) { |
| 357 |
// Can fold DPO into address buffer |
| 358 |
base->connectPort(id_O6, spo); |
| 359 |
base->connectPort(id_DI1, di); |
| 360 |
if (cell->params.count(id_INIT)) |
| 361 |
base->params[id_INIT] = cell->params[id_INIT]; |
| 362 |
} else { |
| 363 |
std::vector<NetInfo *> address(cs.wa.begin(), |
| 364 |
cs.wa.begin() + std::min<size_t>(cs.wa.size(), 5)); |
| 365 |
address.push_back(ctx->nets[ctx->id("$PACKER_GND_NET")].get()); |
| 366 |
CellInfo *dpr = create_dram_lut(cell->name.str(ctx) + "/SP", base, cs, address, di, spo, z); |
| 367 |
if (cell->params.count(id_INIT)) |
| 368 |
dpr->params[id_INIT] = cell->params[id_INIT]; |
| 369 |
z--; |
| 370 |
} |
| 371 |
} |
| 372 |
|
| 373 |
if (dpo != nullptr) { |
| 374 |
std::vector<NetInfo *> address; |
| 375 |
for (int i = 0; i < 5; i++) |
| 376 |
address.push_back(cell->getPort(ctx->idf("DPRA%d", i))); |
| 377 |
address.push_back(ctx->nets[ctx->id("$PACKER_GND_NET")].get()); |
| 378 |
CellInfo *dpr = create_dram_lut(cell->name.str(ctx) + "/DP", base, cs, address, di, dpo, z); |
| 379 |
if (cell->params.count(id_INIT)) |
| 380 |
dpr->params[id_INIT] = cell->params[id_INIT]; |
| 381 |
z--; |
| 382 |
} |
| 383 |
|
| 384 |
packed_cells.insert(cell->name); |
| 385 |
} |
| 386 |
} else if (cs.memtype.in(id_RAM128X1D, id_RAM256X1D)) { |
| 387 |
// Split these cells into write and read ports and associated mux tree |
| 388 |
bool m256 = cs.memtype == id_RAM256X1D; |
| 389 |
for (CellInfo *ci : group.second) { |
| 390 |
auto init = get_or_default(ci->params, id_INIT, Property(0, m256 ? 256 : 128)); |
| 391 |
std::vector<NetInfo *> spo_pre, dpo_pre; |
| 392 |
int z = (height - 1); |
| 393 |
|
| 394 |
NetInfo *dpo = ci->getPort(id_DPO); |
| 395 |
NetInfo *spo = ci->getPort(id_SPO); |
| 396 |
ci->disconnectPort(id_DPO); |
| 397 |
ci->disconnectPort(id_SPO); |
| 398 |
|
| 399 |
// Low 6 bits of address - connect directly to RAM cells |
| 400 |
std::vector<NetInfo *> addressw_64(cs.wa.begin(), cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6)); |
| 401 |
// Upper bits of address - feed decode muxes |
| 402 |
std::vector<NetInfo *> addressw_high(cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6), cs.wa.end()); |
| 403 |
CellInfo *base = nullptr; |
| 404 |
// Combined write address/SPO read cells |
| 405 |
for (int i = 0; i < (m256 ? 4 : 2); i++) { |
| 406 |
NetInfo *spo_i = create_internal_net(ci->name, stringf("SPO_%d", i), false); |
| 407 |
CellInfo *spr = create_dram_lut(ci->name.str(ctx) + "/ADDR" + std::to_string(i), base, cs, |
| 408 |
addressw_64, ci->getPort(id_D), spo_i, z); |
| 409 |
if (base == nullptr) |
| 410 |
base = spr; |
| 411 |
spo_pre.push_back(spo_i); |
| 412 |
spr->params[id_INIT] = init.extract(i * 64, 64); |
| 413 |
z--; |
| 414 |
} |
| 415 |
// Decode mux tree using MUXF[78] |
| 416 |
create_muxf_tree(base, "SPO", spo_pre, addressw_high, spo, m256 ? 4 : 2); |
| 417 |
|
| 418 |
std::vector<NetInfo *> addressr_64, addressr_high; |
| 419 |
for (int i = 0; i < (m256 ? 8 : 7); i++) { |
| 420 |
(i >= 6 ? addressr_high : addressr_64) |
| 421 |
.push_back(ci->getPort(ctx->id("DPRA[" + std::to_string(i) + "]"))); |
| 422 |
} |
| 423 |
// Read-only port cells |
| 424 |
for (int i = 0; i < (m256 ? 4 : 2); i++) { |
| 425 |
NetInfo *dpo_i = create_internal_net(ci->name, stringf("DPO_%d", i), false); |
| 426 |
CellInfo *dpr = create_dram_lut(ci->name.str(ctx) + "/DPR" + std::to_string(i), base, cs, |
| 427 |
addressr_64, ci->getPort(id_D), dpo_i, z); |
| 428 |
dpo_pre.push_back(dpo_i); |
| 429 |
dpr->params[id_INIT] = init.extract(i * 64, 64); |
| 430 |
z--; |
| 431 |
} |
| 432 |
// Decode mux tree using MUXF[78] |
| 433 |
create_muxf_tree(base, "DPO", dpo_pre, addressr_high, dpo, 0); |
| 434 |
|
| 435 |
packed_cells.insert(ci->name); |
| 436 |
} |
| 437 |
} else if (cs.memtype.in(id_RAM128X1S, id_RAM256X1S)) { |
| 438 |
bool m256 = cs.memtype == id_RAM256X1S; |
| 439 |
for (CellInfo *ci : group.second) { |
| 440 |
auto init = get_or_default(ci->params, id_INIT, Property(0, m256 ? 256 : 128)); |
| 441 |
std::vector<NetInfo *> o_pre; |
| 442 |
int z = (height - 1); |
| 443 |
|
| 444 |
NetInfo *o = ci->getPort(id_O); |
| 445 |
ci->disconnectPort(id_O); |
| 446 |
|
| 447 |
// Low 6 bits of address - connect directly to RAM cells |
| 448 |
std::vector<NetInfo *> addressw_64(cs.wa.begin(), cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6)); |
| 449 |
// Upper bits of address - feed decode muxes |
| 450 |
std::vector<NetInfo *> addressw_high(cs.wa.begin() + std::min<size_t>(cs.wa.size(), 6), cs.wa.end()); |
| 451 |
CellInfo *base = nullptr; |
| 452 |
// Combined write address/SPO read cells |
| 453 |
for (int i = 0; i < (m256 ? 4 : 2); i++) { |
| 454 |
NetInfo *spo_i = create_internal_net(ci->name, stringf("O_%d", i), false); |
| 455 |
CellInfo *spr = create_dram_lut(ci->name.str(ctx) + "/ADDR" + std::to_string(i), base, cs, |
| 456 |
addressw_64, ci->getPort(id_D), spo_i, z); |
| 457 |
if (base == nullptr) |
| 458 |
base = spr; |
| 459 |
o_pre.push_back(spo_i); |
| 460 |
spr->params[id_INIT] = init.extract(i * 64, 64); |
| 461 |
z--; |
| 462 |
} |
| 463 |
// Decode mux tree using MUXF[78] |
| 464 |
create_muxf_tree(base, "O", o_pre, addressw_high, o, m256 ? 0 : 2); |
| 465 |
packed_cells.insert(ci->name); |
| 466 |
} |
| 467 |
} |
| 468 |
} |
| 469 |
// Whole-SLICE DRAM |
| 470 |
for (auto &cell : ctx->cells) { |
| 471 |
CellInfo *ci = cell.second.get(); |
| 472 |
if (ci->type.in(id_RAM64M, id_RAM32M)) { |
| 473 |
bool is_64 = (cell.second->type == id_RAM64M); |
| 474 |
int abits = is_64 ? 6 : 5; |
| 475 |
int dbits = is_64 ? 1 : 2; |
| 476 |
DRAMControlSet dcs; |
| 477 |
for (int i = 0; i < abits; i++) |
| 478 |
dcs.wa.push_back(ci->getPort(ctx->idf("ADDRD[%d]", i))); |
| 479 |
dcs.wclk = ci->getPort(id_WCLK); |
| 480 |
dcs.we = ci->getPort(id_WE); |
| 481 |
dcs.wclk_inv = bool_or_default(ci->params, id_IS_WCLK_INVERTED); |
| 482 |
CellInfo *base = nullptr; |
| 483 |
int zoffset = /*ctx->xc7 ? 0 : 4*/ 0; |
| 484 |
for (int i = 0; i < 4; i++) { |
| 485 |
std::vector<NetInfo *> address; |
| 486 |
for (int j = 0; j < abits; j++) { |
| 487 |
address.push_back(ci->getPort(ctx->idf("ADDR%c[%d]", 'A' + i, j))); |
| 488 |
} |
| 489 |
if (is_64) { |
| 490 |
NetInfo *di = ci->getPort(ctx->idf("DI%c", 'A' + i)); |
| 491 |
NetInfo *dout = ci->getPort(ctx->idf("DO%c", 'A' + i)); |
| 492 |
ci->disconnectPort(ctx->idf("DI%c", 'A' + i)); |
| 493 |
ci->disconnectPort(ctx->idf("DO%c", 'A' + i)); |
| 494 |
CellInfo *dram = create_dram_lut(stringf("%s/DPR%d", ctx->nameOf(ci), i), base, dcs, address, di, |
| 495 |
dout, zoffset + i); |
| 496 |
if (base == nullptr) |
| 497 |
base = dram; |
| 498 |
if (ci->params.count(ctx->idf("INIT%c", 'A' + i))) |
| 499 |
dram->params[id_INIT] = ci->params[ctx->idf("INIT%c", 'A' + i)]; |
| 500 |
} else { |
| 501 |
for (int j = 0; j < dbits; j++) { |
| 502 |
NetInfo *di = ci->getPort(ctx->idf("DI%c[%d]", 'A' + i, j)); |
| 503 |
NetInfo *dout = ci->getPort(ctx->idf("DO%c[%d]", 'A' + i, j)); |
| 504 |
ci->disconnectPort(ctx->idf("DI%c[%d]", 'A' + i, j)); |
| 505 |
ci->disconnectPort(ctx->idf("DO%c[%d]", 'A' + i, j)); |
| 506 |
CellInfo *dram = create_dram32_lut(stringf("%s/DPR%d_%d", ctx->nameOf(ci), i, j), base, dcs, |
| 507 |
address, di, dout, (j == 0), zoffset + i); |
| 508 |
if (base == nullptr) |
| 509 |
base = dram; |
| 510 |
if (ci->params.count(ctx->idf("INIT%c", 'A' + i))) { |
| 511 |
auto orig_init = ci->params.at(ctx->idf("INIT%c", 'A' + i)).extract(0, 64).as_bits(); |
| 512 |
std::string init; |
| 513 |
for (int k = 0; k < 32; k++) { |
| 514 |
init.push_back(orig_init.at(k * 2 + j)); |
| 515 |
} |
| 516 |
dram->params[id_INIT] = Property::from_string(init); |
| 517 |
} |
| 518 |
} |
| 519 |
} |
| 520 |
} |
| 521 |
packed_cells.insert(ci->name); |
| 522 |
} |
| 523 |
} |
| 524 |
|
| 525 |
flush_cells(); |
| 526 |
} |
| 527 |
|
| 528 |
NEXTPNR_NAMESPACE_END |