| 1 |
/* |
| 2 |
* nextpnr -- Next Generation Place and Route |
| 3 |
* |
| 4 |
* Copyright (C) 2020 Myrtle Shah <[email protected]> |
| 5 |
* Copyright (C) 2023 Hans Baier <[email protected]> |
| 6 |
* |
| 7 |
* Permission to use, copy, modify, and/or distribute this software for any |
| 8 |
* purpose with or without fee is hereby granted, provided that the above |
| 9 |
* copyright notice and this permission notice appear in all copies. |
| 10 |
* |
| 11 |
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
| 12 |
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
| 13 |
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
| 14 |
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
| 15 |
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
| 16 |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
| 17 |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
| 18 |
* |
| 19 |
*/ |
| 20 |
|
| 21 |
#include <boost/algorithm/string.hpp> |
| 22 |
#include "pack.h" |
| 23 |
|
| 24 |
#define HIMBAECHEL_CONSTIDS "uarch/xilinx/constids.inc" |
| 25 |
#include "himbaechel_constids.h" |
| 26 |
|
| 27 |
NEXTPNR_NAMESPACE_BEGIN |
| 28 |
|
| 29 |
static bool is_cascade_input(const PortInfo &port, const Context *ctx) |
| 30 |
{ |
| 31 |
if (port.name == id_CARRYCASCIN || port.name == id_MULTSIGNIN) |
| 32 |
return true; |
| 33 |
const std::string &str = port.name.c_str(ctx); |
| 34 |
return boost::starts_with(str, "ACIN") || boost::starts_with(str, "BCIN") || boost::starts_with(str, "PCIN"); |
| 35 |
} |
| 36 |
static bool is_cascade_output(const PortInfo &port, const Context *ctx) |
| 37 |
{ |
| 38 |
if (port.name == id_CARRYCASCOUT || port.name == id_MULTSIGNOUT) |
| 39 |
return true; |
| 40 |
const std::string &str = port.name.c_str(ctx); |
| 41 |
return boost::starts_with(str, "ACOUT") || boost::starts_with(str, "BCOUT") || boost::starts_with(str, "PCOUT"); |
| 42 |
} |
| 43 |
|
| 44 |
// Return : the number of DSP marked as cascaded |
| 45 |
unsigned XC7Packer::walk_dsp(CellInfo *root, CellInfo *current_cell, int constr_z) |
| 46 |
{ |
| 47 |
CellInfo *cascaded_cell = nullptr; |
| 48 |
unsigned num_casc = 0; |
| 49 |
|
| 50 |
auto check_illegal_fanout = [&](NetInfo *ni, std::string port) { |
| 51 |
if (ni->users.entries() > 1) |
| 52 |
log_error("Port %s connected to net %s has more than one user", port.c_str(), ni->name.c_str(ctx)); |
| 53 |
|
| 54 |
PortRef &user = *ni->users.begin(); |
| 55 |
if (user.cell->type != id_DSP48E1_DSP48E1) |
| 56 |
log_error("User %s of net %s is not a DSP block, but %s", user.cell->name.c_str(ctx), ni->name.c_str(ctx), |
| 57 |
user.cell->type.c_str(ctx)); |
| 58 |
}; |
| 59 |
|
| 60 |
// see if any cascade outputs are connected |
| 61 |
for (auto port : current_cell->ports) { |
| 62 |
if (!is_cascade_output(port.second, ctx)) |
| 63 |
continue; |
| 64 |
NetInfo *cout_net = port.second.net; |
| 65 |
|
| 66 |
if (cout_net == nullptr || cout_net->users.empty()) |
| 67 |
continue; |
| 68 |
|
| 69 |
check_illegal_fanout(cout_net, port.first.c_str(ctx)); |
| 70 |
PortRef &user = *cout_net->users.begin(); |
| 71 |
CellInfo *cout_cell = user.cell; |
| 72 |
NPNR_ASSERT(cout_cell != nullptr); |
| 73 |
|
| 74 |
if (cascaded_cell != nullptr && cout_cell != cascaded_cell) |
| 75 |
log_error("the cascading outputs of DSP block %s are connected to different cells", |
| 76 |
current_cell->name.c_str(ctx)); |
| 77 |
|
| 78 |
cascaded_cell = cout_cell; |
| 79 |
} |
| 80 |
|
| 81 |
if (cascaded_cell != nullptr) { |
| 82 |
auto is_lower_bel = constr_z == BEL_LOWER_DSP; |
| 83 |
|
| 84 |
cascaded_cell->cluster = root->name; |
| 85 |
root->constr_children.push_back(cascaded_cell); |
| 86 |
cascaded_cell->constr_x = 0; |
| 87 |
// The connected cell has to be above the current cell, |
| 88 |
// otherwise it cannot be routed, because the cascading ports |
| 89 |
// are only connected to the DSP above |
| 90 |
auto previous_y = (current_cell == root) ? 0 : current_cell->constr_y; |
| 91 |
cascaded_cell->constr_y = previous_y + (is_lower_bel ? -5 : 0); |
| 92 |
cascaded_cell->constr_z = constr_z; |
| 93 |
cascaded_cell->constr_abs_z = true; |
| 94 |
|
| 95 |
num_casc += 1; |
| 96 |
num_casc += walk_dsp(root, cascaded_cell, is_lower_bel ? BEL_UPPER_DSP : BEL_LOWER_DSP); |
| 97 |
} |
| 98 |
|
| 99 |
return num_casc; |
| 100 |
} |
| 101 |
|
| 102 |
void XC7Packer::pack_dsps() |
| 103 |
{ |
| 104 |
log_info("Packing DSPs..\n"); |
| 105 |
|
| 106 |
dict<IdString, XFormRule> dsp_rules; |
| 107 |
dsp_rules[id_DSP48E1].new_type = id_DSP48E1_DSP48E1; |
| 108 |
generic_xform(dsp_rules, true); |
| 109 |
|
| 110 |
std::vector<CellInfo *> all_dsps; |
| 111 |
|
| 112 |
// Clean connections of DSPs |
| 113 |
for (auto &cell : ctx->cells) { |
| 114 |
CellInfo *ci = cell.second.get(); |
| 115 |
|
| 116 |
auto add_const_pin = [&](PortInfo &port, std::string &pins, std::string &pin_name, std::string net) { |
| 117 |
if (port.net && port.net->name == ctx->id(net)) { |
| 118 |
ci->disconnectPort(port.name); |
| 119 |
pins += " " + pin_name; |
| 120 |
} |
| 121 |
}; |
| 122 |
|
| 123 |
if (ci->type == id_DSP48E1_DSP48E1) { |
| 124 |
all_dsps.push_back(ci); |
| 125 |
auto gnd_attr = ctx->id("DSP_GND_PINS"); |
| 126 |
auto vcc_attr = ctx->id("DSP_VCC_PINS"); |
| 127 |
|
| 128 |
auto gnd_pins = str_or_default(ci->attrs, gnd_attr, ""); |
| 129 |
auto vcc_pins = str_or_default(ci->attrs, vcc_attr, ""); |
| 130 |
|
| 131 |
for (auto &port : ci->ports) { |
| 132 |
std::string n = port.first.str(ctx); |
| 133 |
|
| 134 |
// Cascading inputs do not use routing resources, so disconnect them if constants |
| 135 |
if (is_cascade_input(port.second, ctx)) { |
| 136 |
if (port.second.net == nullptr) |
| 137 |
continue; |
| 138 |
if (port.second.net->name == ctx->id("$PACKER_GND_NET")) |
| 139 |
ci->disconnectPort(port.first); |
| 140 |
} |
| 141 |
|
| 142 |
// prjxray has extra bits for these ports to hardwire them to VCC/GND |
| 143 |
// as these seem to be interal to the tile, |
| 144 |
// this saves us from having to route those externally |
| 145 |
if (boost::starts_with(n, "D") || boost::starts_with(n, "RSTD") || |
| 146 |
// TODO: these seem to be inverted for unknown reasons |
| 147 |
// boost::starts_with(n, "INMODE") || |
| 148 |
// boost::starts_with(n, "ALUMODE2") || |
| 149 |
// boost::starts_with(n, "ALUMODE3") || |
| 150 |
boost::starts_with(n, "CARRYINSEL2") || boost::starts_with(n, "CED") || |
| 151 |
boost::starts_with(n, "CEAD") || boost::starts_with(n, "CEINMODE") || |
| 152 |
boost::starts_with(n, "CEALUMODE")) { |
| 153 |
add_const_pin(port.second, gnd_pins, n, "$PACKER_GND_NET"); |
| 154 |
add_const_pin(port.second, vcc_pins, n, "$PACKER_VCC_NET"); |
| 155 |
} |
| 156 |
} |
| 157 |
|
| 158 |
ci->attrs[gnd_attr] = gnd_pins; |
| 159 |
ci->attrs[vcc_attr] = vcc_pins; |
| 160 |
} |
| 161 |
} |
| 162 |
|
| 163 |
// Find the roots of cascaded DSP |
| 164 |
std::vector<CellInfo *> dsp_roots; |
| 165 |
for (auto ci : all_dsps) { |
| 166 |
bool cascade_input_used = false; |
| 167 |
for (auto port : ci->ports) { |
| 168 |
if (!is_cascade_input(port.second, ctx)) |
| 169 |
continue; |
| 170 |
if (port.second.net != nullptr) { |
| 171 |
cascade_input_used = true; |
| 172 |
break; |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
if (!cascade_input_used) { |
| 177 |
dsp_roots.push_back(ci); |
| 178 |
} |
| 179 |
} |
| 180 |
|
| 181 |
// Create clusters of cascaded DSPs |
| 182 |
unsigned num_casc = 0; |
| 183 |
for (auto root : dsp_roots) { |
| 184 |
root->constr_abs_z = true; |
| 185 |
root->constr_z = BEL_LOWER_DSP; |
| 186 |
unsigned loc_casc = walk_dsp(root, root, BEL_UPPER_DSP); |
| 187 |
if (loc_casc > 0) { |
| 188 |
root->cluster = root->name; |
| 189 |
} |
| 190 |
num_casc += loc_casc; |
| 191 |
} |
| 192 |
if (num_casc > 0) { |
| 193 |
log_info("Found %u cascaded DSP from %u roots\n", num_casc, (unsigned)dsp_roots.size()); |
| 194 |
} |
| 195 |
} |
| 196 |
|
| 197 |
NEXTPNR_NAMESPACE_END |