From d09c901f67e47ce2cf7ca319373c045ab93add73 Mon Sep 17 00:00:00 2001 From: Miodrag Milanovic Date: Mon, 23 Dec 2024 09:37:23 +0100 Subject: [PATCH] Naive lut tree CPE pack --- himbaechel/uarch/gatemate/bitstream.cc | 2 ++ himbaechel/uarch/gatemate/constids.inc | 14 ++++++++ himbaechel/uarch/gatemate/pack.cc | 48 +++++++++++++++++++++++--- himbaechel/uarch/gatemate/pack.h | 1 + 4 files changed, 61 insertions(+), 4 deletions(-) diff --git a/himbaechel/uarch/gatemate/bitstream.cc b/himbaechel/uarch/gatemate/bitstream.cc index e1491fd5..48a09272 100644 --- a/himbaechel/uarch/gatemate/bitstream.cc +++ b/himbaechel/uarch/gatemate/bitstream.cc @@ -155,6 +155,8 @@ struct BitstreamBackend int x = getInTileIndex(ctx, pip.tile); if (boost::starts_with(word, "IM.")) boost::replace_all(word, "IM.", stringf("IM%d.", x)); + if (boost::starts_with(word, "OM.")) + boost::replace_all(word, "OM.", stringf("OM%d.", x)); if (boost::starts_with(word, "IOES.")) boost::replace_all(word, "IOES.", "IOES1."); cc.tiles[loc].add_word(word, int_to_bitvector(extra_data.value, extra_data.bits)); diff --git a/himbaechel/uarch/gatemate/constids.inc b/himbaechel/uarch/gatemate/constids.inc index 1ac219f1..930033d0 100644 --- a/himbaechel/uarch/gatemate/constids.inc +++ b/himbaechel/uarch/gatemate/constids.inc @@ -87,6 +87,17 @@ X(INPUT_ENABLE) X(OUT23_14_SEL) X(LVDS_EN) X(LVDS_IE) + +X(CC_L2T4) +X(CC_L2T5) +X(CC_LUT1) +X(CC_LUT2) +X(I0) +X(I1) +X(I2) +X(I3) +X(I4) +X(INIT) X(INIT_L00) X(INIT_L01) X(INIT_L02) @@ -95,3 +106,6 @@ X(INIT_L10) X(INIT_L11) X(INIT_L20) X(INIT_L30) +X(O1) +X(O2) + diff --git a/himbaechel/uarch/gatemate/pack.cc b/himbaechel/uarch/gatemate/pack.cc index e6b5aa48..90cdc432 100644 --- a/himbaechel/uarch/gatemate/pack.cc +++ b/himbaechel/uarch/gatemate/pack.cc @@ -33,6 +33,7 @@ void GateMatePacker::disconnect_if_gnd(CellInfo *cell, IdString input) cell->disconnectPort(input); } } + void GateMatePacker::pack_io() { // Trim nextpnr IOBs - assume IO buffer insertion has been done in synthesis @@ -276,14 +277,52 @@ void GateMatePacker::pack_io() } } +void GateMatePacker::pack_cpe() +{ + log_info("Packing CPEs..\n"); + for (auto &cell : ctx->cells) { + CellInfo &ci = *cell.second; + if (!ci.type.in(id_CC_L2T4, id_CC_L2T5, id_CC_LUT2, id_CC_LUT1)) + continue; + if (ci.type == id_CC_L2T5) { + ci.renamePort(id_I0, id_IN4); + ci.renamePort(id_I1, id_IN5); + ci.renamePort(id_I2, id_IN6); + ci.renamePort(id_I3, id_IN7); + + ci.renamePort(id_I4, id_IN1); + ci.renamePort(id_O, id_OUT1); + ci.params[id_INIT_L00] = Property(0b1010, 4); + ci.params[id_INIT_L01] = Property(0b0000, 4); + ci.params[id_INIT_L10] = Property(0b1010, 4); + ci.params[id_O1] = Property(0b11, 2); + } else { + ci.renamePort(id_I0, id_IN1); + ci.renamePort(id_I1, id_IN2); + ci.renamePort(id_I2, id_IN3); + ci.renamePort(id_I3, id_IN4); + ci.renamePort(id_O, id_OUT1); + ci.params[id_O1] = Property(0b11, 2); + ci.params[id_INIT_L20] = Property(0b1010, 4); + if (ci.type.in(id_CC_LUT1, id_CC_LUT2)) { + uint8_t val = int_or_default(ci.params, id_INIT, 0); + if (ci.type == id_CC_LUT1) + val = val << 2 | val; + ci.params[id_INIT_L00] = Property(val, 4); + ci.unsetParam(id_INIT); + ci.params[id_INIT_L10] = Property(0b1010, 4); + } + } + ci.type = id_CPE; + } +} + void GateMatePacker::pack_constants() { log_info("Packing constants..\n"); // Replace constants with LUTs - const dict vcc_params = { - {id_INIT_L00, Property(0xf, 4)}, {id_INIT_L01, Property(0xf, 4)}, {id_INIT_L02, Property(0xf, 4)}}; - const dict gnd_params = { - {id_INIT_L00, Property(0x0, 4)}, {id_INIT_L01, Property(0x0, 4)}, {id_INIT_L02, Property(0x0, 4)}}; + const dict vcc_params = {{id_INIT_L20, Property(0b1111, 4)}, {id_O1, Property(0b11, 2)}}; + const dict gnd_params = {{id_INIT_L20, Property(0b0000, 4)}, {id_O1, Property(0b11, 2)}}; h.replace_constants(CellTypePort(id_CPE, id_OUT1), CellTypePort(id_CPE, id_OUT1), vcc_params, gnd_params); } @@ -327,6 +366,7 @@ void GateMateImpl::pack() GateMatePacker packer(ctx, this); packer.pack_constants(); packer.pack_io(); + packer.pack_cpe(); packer.remove_constants(); } diff --git a/himbaechel/uarch/gatemate/pack.h b/himbaechel/uarch/gatemate/pack.h index 473e6fee..15a4fb48 100644 --- a/himbaechel/uarch/gatemate/pack.h +++ b/himbaechel/uarch/gatemate/pack.h @@ -29,6 +29,7 @@ struct GateMatePacker GateMatePacker(Context *ctx, GateMateImpl *uarch) : ctx(ctx), uarch(uarch) { h.init(ctx); }; void pack_io(); + void pack_cpe(); void pack_constants(); void disconnect_if_gnd(CellInfo *cell, IdString input);