diff --git a/himbaechel/uarch/gatemate/gatemate.cc b/himbaechel/uarch/gatemate/gatemate.cc index b9a28ebf..b77872c2 100644 --- a/himbaechel/uarch/gatemate/gatemate.cc +++ b/himbaechel/uarch/gatemate/gatemate.cc @@ -187,6 +187,97 @@ void GateMateImpl::preRoute() { ctx->assignArchInfo(); route_clock(); + + log_info("Routing multipliers...\n"); + + // I am fully aware the nextpnr API is absolutely not designed around naming specific pips. + // Unfortunately, this is the easiest way to describe the specific routing required. + // Myrtle, please forgive me. + for (auto &a_passthru : this->multiplier_a_passthrus) { + auto *lower = a_passthru.first; + auto *upper = a_passthru.second; + + auto *lower_out = lower->ports.at(id_OUT).net; + auto *upper_out = upper->ports.at(id_OUT).net; + + auto loc = ctx->getBelLocation(lower->bel); + log_info(" A passthrough at (%d, %d) has 4-group (%d, %d)\n", loc.x, loc.y, (loc.x - 3) % 4, (loc.y - 3) % 4); + log_info(" lower.OUT [OUT1] = %s\n", ctx->nameOfWire(ctx->getBelPinWire(lower->bel, id_OUT))); + log_info(" upper.OUT [OUT2] = %s\n", ctx->nameOfWire(ctx->getBelPinWire(upper->bel, id_OUT))); + + auto x_fourgroup = (loc.x - 3) % 4; + auto y_fourgroup = (loc.y - 3) % 4; + + auto find_downhill_pip = [&](WireId from, WireId to) { + NPNR_ASSERT(from != WireId()); + NPNR_ASSERT(to != WireId()); + for (auto pip : ctx->getPipsDownhill(from)) { + if (ctx->getPipDstWire(pip) == to) + return pip; + } + log_error("Couldn't find pip from %s to %s\n", ctx->nameOfWire(from), ctx->nameOfWire(to)); + }; + + if (x_fourgroup == 0 && y_fourgroup == 0) { + auto x1y1 = ctx->idf("X%dY%d", loc.x, loc.y); + auto x2y1 = ctx->idf("X%dY%d", loc.x + 1, loc.y); + auto x2y2 = ctx->idf("X%dY%d", loc.x + 1, loc.y + 1); + auto x4y2 = ctx->idf("X%dY%d", loc.x + 3, loc.y + 1); + + { + log_info(" routing net '%s'\n", lower_out->name.c_str(ctx)); + auto cpe_combout1 = ctx->getBelPinWire(lower->bel, id_OUT); + auto cpe_out1 = ctx->getWireByName(IdStringList::concat(x1y1, ctx->idf("CPE.OUT1_int"))); + auto sb_big = ctx->getWireByName(IdStringList::concat(x1y1, ctx->idf("SB_BIG.P05.D0"))); + auto in_mux = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("IM.P05.D0"))); + auto cpe_in5 = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("CPE.IN5"))); + auto cpe_in5_int = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("CPE.IN5_int"))); + + ctx->bindPip(find_downhill_pip(cpe_combout1, cpe_out1), lower_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(cpe_out1, sb_big), lower_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_big, in_mux), lower_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(in_mux, cpe_in5), lower_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(cpe_in5, cpe_in5_int), lower_out, STRENGTH_USER); + } + + { + log_info(" routing net '%s'\n", upper_out->name.c_str(ctx)); + auto cpe_combout2 = ctx->getBelPinWire(upper->bel, id_OUT); + auto cpe_out2_int = ctx->getWireByName(IdStringList::concat(x1y1, ctx->idf("CPE.OUT2_int"))); + auto sb_big = ctx->getWireByName(IdStringList::concat(x1y1, ctx->idf("SB_BIG.P01.D0"))); + auto in_mux = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("IM.P01.D0"))); + auto cpe_in1 = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("CPE.IN1"))); + auto cpe_in1_int = ctx->getWireByName(IdStringList::concat(x2y1, ctx->idf("CPE.IN1_int"))); + + ctx->bindPip(find_downhill_pip(cpe_combout2, cpe_out2_int), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(cpe_out2_int, sb_big), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_big, in_mux), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(in_mux, cpe_in1), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(cpe_in1, cpe_in1_int), upper_out, STRENGTH_USER); + + auto out_mux_d0 = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("OM.P12.D0"))); + auto out_mux_y = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("OM.P12.Y"))); + auto sb_sml = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("SB_SML.P12.Y1_int"))); + auto sb_big_d2_1 = ctx->getWireByName(IdStringList::concat(x4y2, ctx->idf("SB_BIG.P12.D2_1"))); + auto sb_big_y1 = ctx->getWireByName(IdStringList::concat(x4y2, ctx->idf("SB_BIG.P12.Y1"))); + auto sb_big_ydiag = ctx->getWireByName(IdStringList::concat(x4y2, ctx->idf("SB_BIG.P12.YDIAG"))); + auto in_mux_p12 = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("IM.P12.D2"))); + auto in_mux_p04 = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("IM.P04.D7"))); + auto in_mux_p08 = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("IM.P08.Y"))); + auto cpe_in8_int = ctx->getWireByName(IdStringList::concat(x2y2, ctx->idf("CPE.IN8_int"))); + + ctx->bindPip(find_downhill_pip(out_mux_d0, out_mux_y), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(out_mux_y, sb_sml), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_sml, sb_big_d2_1), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_big_d2_1, sb_big_y1), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_big_y1, sb_big_ydiag), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(sb_big_ydiag, in_mux_p12), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(in_mux_p12, in_mux_p04), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(in_mux_p04, in_mux_p08), upper_out, STRENGTH_USER); + ctx->bindPip(find_downhill_pip(in_mux_p08, cpe_in8_int), upper_out, STRENGTH_USER); + } + } + } } void GateMateImpl::postRoute() diff --git a/himbaechel/uarch/gatemate/gatemate.h b/himbaechel/uarch/gatemate/gatemate.h index 43ecf246..148dce55 100644 --- a/himbaechel/uarch/gatemate/gatemate.h +++ b/himbaechel/uarch/gatemate/gatemate.h @@ -73,6 +73,7 @@ struct GateMateImpl : HimbaechelAPI int dies; int preferred_die; std::vector multipliers; + std::vector> multiplier_a_passthrus; private: bool getChildPlacement(const BaseClusterInfo *cluster, Loc root_loc, diff --git a/himbaechel/uarch/gatemate/pack.cc b/himbaechel/uarch/gatemate/pack.cc index 393f56c7..f2caef1d 100644 --- a/himbaechel/uarch/gatemate/pack.cc +++ b/himbaechel/uarch/gatemate/pack.cc @@ -397,7 +397,7 @@ void GateMateImpl::pack() packer.pack_misc(); packer.pack_ram(); packer.pack_serdes(); - // packer.pack_mult(); + packer.pack_mult(); packer.pack_addf(); packer.pack_cpe(); packer.remove_constants(); diff --git a/himbaechel/uarch/gatemate/pack_mult.cc b/himbaechel/uarch/gatemate/pack_mult.cc index 0195bafa..06226fa9 100644 --- a/himbaechel/uarch/gatemate/pack_mult.cc +++ b/himbaechel/uarch/gatemate/pack_mult.cc @@ -412,6 +412,8 @@ void GateMatePacker::pack_mult() a_passthru_comp->connectPort(id_COMPOUT, comp_conn); a_passthru_lines->connectPort(id_COMPOUT, comp_conn); + uarch->multiplier_a_passthrus.push_back({a_passthru_lower, a_passthru_upper}); + return APassThroughCell{a_passthru_lower, a_passthru_upper, a_passthru_comp, a_passthru_lines, name}; };