From ec6fe87e26b875d410671cbeead1dc547df16fbf Mon Sep 17 00:00:00 2001 From: Lofty Date: Mon, 5 Jun 2023 02:49:53 +0100 Subject: [PATCH] mistral: improve ALM packing in LABs --- mistral/lab.cc | 45 ++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 42 insertions(+), 3 deletions(-) diff --git a/mistral/lab.cc b/mistral/lab.cc index cff2c02a9d..1e3b90f02c 100644 --- a/mistral/lab.cc +++ b/mistral/lab.cc @@ -534,6 +534,15 @@ void Arch::update_alm_input_count(uint32_t lab, uint8_t alm) alm_data.unique_input_count = total_inputs; } +const std::array tdmux_set = { + 0, // A + 1, // B + 2, // C + 1, // D + 3, // E + 2, // F +}; + bool Arch::check_lab_input_count(uint32_t lab) const { // There are only 46 TD signals available to route signals from general routing to the ALM input. Currently, we @@ -544,10 +553,40 @@ bool Arch::check_lab_input_count(uint32_t lab) const // currently perfunctory place and route algorithms to achieve satisfactory runtimes. int count = 0; auto &lab_data = labs.at(lab); - for (int i = 0; i < 10; i++) { - count += lab_data.alms.at(i).unique_input_count; + pool> unique_inputs; + + for (int alm = 0; alm < 10; alm++) { + // TODO: duplication with above + auto &alm_data = labs.at(lab).alms.at(alm); + // Get cells into an array for fast access + std::array luts{getBoundBelCell(alm_data.lut_bels[0]), getBoundBelCell(alm_data.lut_bels[1])}; + std::array ffs{getBoundBelCell(alm_data.ff_bels[0]), getBoundBelCell(alm_data.ff_bels[1]), + getBoundBelCell(alm_data.ff_bels[2]), getBoundBelCell(alm_data.ff_bels[3])}; + for (int i = 0; i < 2; i++) { + if (!luts[i]) + continue; + + for (int j = 0; j < luts[i]->combInfo.lut_input_count; j++) + if (luts[i]->combInfo.lut_in[j]) + unique_inputs.insert(std::make_pair(luts[i]->combInfo.lut_in[j]->name, tdmux_set.at(j))); + } + for (int i = 0; i < 4; i++) { + const CellInfo *ff = ffs[i]; + if (!ff) + continue; + if (ff->ffInfo.sdata) { + unique_inputs.insert(std::make_pair(ff->ffInfo.sdata->name, tdmux_set.at(4))); + unique_inputs.insert(std::make_pair(ff->ffInfo.sdata->name, tdmux_set.at(5))); + } + // FF input doesn't consume routing resources if driven by associated LUT + if (ff->ffInfo.datain && (!luts[i / 2] || ff->ffInfo.datain != luts[i / 2]->combInfo.comb_out)) { + unique_inputs.insert(std::make_pair(ff->ffInfo.datain->name, tdmux_set.at(4))); + unique_inputs.insert(std::make_pair(ff->ffInfo.datain->name, tdmux_set.at(5))); + } + } } - return (count <= 42); + + return (unique_inputs.size() <= 42); } bool Arch::check_mlab_groups(uint32_t lab) const