31 return (a->getScoreInSite() == b->getScoreInSite()) ? a->getHash() > b->getHash()
32 : (a->getScoreInSite() > b->getScoreInSite());
38 std::cout <<
"priorityQueue[" <<
i - 1 <<
"]:\n" <<
priorityQueue[
i - 1] <<
"\n";
42 std::cout <<
"#" << j <<
": " <<
priorityQueue[j]->getScoreInSite() <<
"\n";
52 for (
unsigned int i = 0;
i < priorityQueue.size();
i++)
56 priorityQueue[validCnt] = priorityQueue[
i];
61 delete priorityQueue[
i];
62 priorityQueue[
i] =
nullptr;
65 if (determinedClusterInSite)
67 priorityQueue.resize(validCnt);
72 if (determinedClusterInSite)
75 for (
unsigned int i = 0;
i < priorityQueue.size();
i++)
78 for (
auto tmpPU : determinedClusterInSite->getPUs())
80 if (!priorityQueue[
i]->contains(tmpPU))
82 if (!priorityQueue[
i]->addPU(tmpPU,
true))
84 delete priorityQueue[
i];
85 priorityQueue[
i] =
nullptr;
98 priorityQueue[
i]->refreshId();
99 priorityQueue[
i]->updateScoreInSite();
101 priorityQueue[validCnt] = priorityQueue[
i];
105 priorityQueue.resize(validCnt);
111 std::set<PlacementInfo::PlacementUnit *, Packing_PUcompare> newNbr;
113 for (
auto tmpPU : neighborPUs)
125 bool detCompatible =
true;
126 if (determinedClusterInSite)
128 if (!determinedClusterInSite->contains(tmpPU))
131 detCompatible = (testDetCluster->
addPU(tmpPU,
true));
132 delete testDetCluster;
136 newNbr.insert(tmpPU);
139 neighborPUs = newNbr;
144 if (priorityQueue.size())
147 std::vector<PlacementInfo::PlacementUnit *> countedPUs;
149 for (
auto pair : PU2TopCnt)
150 countedPUs.push_back(pair.first);
152 std::vector<PlacementInfo::PlacementUnit *> PUsToAdd;
154 for (
auto PU : countedPUs)
158 assert(PU2TopCnt.find(PU) != PU2TopCnt.end());
162 if (determinedClusterInSite)
164 if (!determinedClusterInSite->contains(PU))
166 PUsToAdd.push_back(PU);
171 PUsToAdd.push_back(PU);
182 for (
auto PU : topCluster->
getPUs())
184 if (PU2TopCnt.find(PU) == PU2TopCnt.end())
195 for (
unsigned int i = 0;
i < priorityQueue.size();
i++)
197 bool changed =
false;
198 for (
auto tmpPU : PUsToAdd)
200 if (!priorityQueue[
i]->contains(tmpPU))
202 if (!priorityQueue[
i]->addPU(tmpPU,
true))
204 delete priorityQueue[
i];
205 priorityQueue[
i] =
nullptr;
214 if (priorityQueue[
i])
218 priorityQueue[
i]->refreshId();
219 priorityQueue[
i]->updateScoreInSite();
221 priorityQueue[validCnt] = priorityQueue[
i];
225 priorityQueue.resize(validCnt);
227 if (!determinedClusterInSite)
229 delete determinedClusterInSite;
235 for (
auto countedPair : PU2TopCnt)
240 determinedClusterInSite->removePUToConstructDetCluster(countedPair.first);
248 determinedClusterInSite->clusterHash();
249 determinedClusterInSite->refreshId();
250 determinedClusterInSite->updateScoreInSite();
251 detScore = determinedClusterInSite->getScoreInSite();
259 std::set<int> hashIdSet;
261 for (
auto tmpSeedCluster : seedClusters)
263 hashIdSet.insert(tmpSeedCluster->getHash());
265 for (
auto tmpSeedCluster : seedClusters)
267 for (
auto tmpPU : neighborPUs)
273 if (tmpCluster->
addPU(tmpPU))
278 if (hashIdSet.find(tmpCluster->
getHash()) != hashIdSet.end())
281 tmpCluster =
nullptr;
285 hashIdSet.insert(tmpCluster->
getHash());
286 priorityQueue.push_back(tmpCluster);
303 tmpCluster =
nullptr;
309 std::set<PlacementInfo::PlacementUnit *, Packing_PUcompare> *
312 float displacementUpperbound,
int PUNumThreshold,
const std::vector<PackingCLBSite *> &
PUId2PackingCLBSite,
315 assert(displacementLowerbound < displacementUpperbound);
319 std::set<PlacementInfo::PlacementUnit *, Packing_PUcompare> *res =
320 new std::set<PlacementInfo::PlacementUnit *, Packing_PUcompare>();
324 int binIdX, binIdY, clockRegionX, clockRegionY;
330 for (
auto sharedTypeId : sharedTypeIds)
332 std::vector<std::vector<PlacementInfo::PlacementBinInfo *>> &curBinGrid =
335 assert((
unsigned int)binIdY < curBinGrid.size());
337 assert((
unsigned int)binIdX < curBinGrid[binIdY].size());
339 std::queue<std::pair<int, int>> binXYqueue;
340 std::set<std::pair<int, int>> reachedBinXYs;
341 binXYqueue.emplace(binIdX, binIdY);
342 reachedBinXYs.emplace(binIdX, binIdY);
344 while (binXYqueue.size() > 0)
346 std::pair<int, int> curXY = binXYqueue.front();
348 int curbinIdX = curXY.first, curbinIdY = curXY.second;
352 if (bin2TargetXYDistance > displacementUpperbound)
354 for (
auto tmpCell : curBin->
getCells())
356 if (tmpCell->isLUT() || tmpCell->isFF())
360 if (tmpPU->isFixed() || tmpPU->isPacked())
372 float tmpPUDis = fabs(targetX - tmpPU->X()) +
y2xRatio * fabs(targetY - tmpPU->Y());
373 if (tmpPUDis > displacementLowerbound && tmpPUDis <= displacementUpperbound)
375 int PUClockRegionX, PUClockRegionY;
377 PUClockRegionX, PUClockRegionY);
378 if (PUClockRegionX == clockRegionX)
386 float tmpPUDis = fabs(targetX - tmpPU->X()) +
y2xRatio * fabs(targetY - tmpPU->Y());
387 if (tmpPUDis > displacementLowerbound && tmpPUDis <= displacementUpperbound)
389 int PUClockRegionX, PUClockRegionY;
391 tmpPU->X(), targetY, PUClockRegionX, PUClockRegionY);
392 if (PUClockRegionX == clockRegionX)
402 for (
int nextY = curbinIdY - 1; nextY <= curbinIdY + 1; nextY++)
404 for (
int nextX = curbinIdX - 1; nextX <= curbinIdX + 1; nextX++)
408 if (!((
unsigned int)nextY < curBinGrid.size()))
412 if (!((
unsigned int)nextX < curBinGrid[binIdY].size()))
416 if (nextBin2TargetXYDistance > displacementUpperbound)
418 std::pair<int, int> nextXY(nextX, nextY);
419 if (reachedBinXYs.find(nextXY) == reachedBinXYs.end())
421 reachedBinXYs.insert(nextXY);
422 binXYqueue.push(nextXY);
438 removeInvalidClustersFromPQ();
439 removeClustersIncompatibleWithDetClusterFromPQ();
440 removeInvalidPUsFromNeighborPUs();
441 updateConsistentPUsInTop();
443 seedClusters = priorityQueue;
444 if (seedClusters.size() == 0)
446 if (determinedClusterInSite)
454 seedClusters[0]->clusterHash();
477 findNewClustersWithNeighborPUs();
479 refreshPrioryQueue();
509 if (priorityQueue.size() >
PQSize)
512 float scoreThreshold = priorityQueue[
PQSize - 1]->getScoreInSite() * 0.99;
513 bool extendable =
true;
514 for (
unsigned int i =
PQSize;
i < priorityQueue.size();
i++)
516 if (extendable && priorityQueue[
i]->getScoreInSite() > scoreThreshold)
519 if (finalPQSize > 1.5 *
PQSize)
527 assert(priorityQueue[
i]);
528 delete priorityQueue[
i];
529 priorityQueue[
i] =
nullptr;
532 priorityQueue.resize(finalPQSize);
546 assert(checkIsPrePackedSite() && checkIsCarrySite());
547 assert(determinedClusterInSite->getSingleLUTs().size() + determinedClusterInSite->getPairedLUTs().size() <= 8);
549 for (
int i = 0;
i < 24;
i++)
550 finalMapToSlotsForCarrySite(
i);
552 for (
int targetFFSetId = 0; targetFFSetId < 4; targetFFSetId++)
554 if (determinedClusterInSite->evictFFsFromCarryHalfCLB(targetFFSetId))
556 for (
int i = 0;
i < 24;
i++)
557 finalMapToSlotsForCarrySite(
i);
558 determinedClusterInSite->recoverFFControlSets();
562 slotMapping = best_SlotMapping;
563 mappedCells = best_mappedCells;
564 mappedLUTs = best_mappedLUTs;
565 mappedFFs = best_mappedFFs;
573 int FFSwapOption[24][4] = {{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}, {0, 3, 2, 1},
574 {1, 0, 2, 3}, {1, 0, 3, 2}, {1, 2, 0, 3}, {1, 2, 3, 0}, {1, 3, 0, 2}, {1, 3, 2, 0},
575 {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 0, 3}, {2, 1, 3, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
576 {3, 0, 1, 2}, {3, 0, 2, 1}, {3, 1, 0, 2}, {3, 1, 2, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
582 mapCarryRelatedCellsToSlots(CARRYChain, CARRYChainSiteOffset);
583 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> FF2LUT;
584 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> LUT2FF;
585 auto singleLUTs = determinedClusterInSite->getSortedSingleLUTs();
586 auto pairedLUTs = determinedClusterInSite->getSortedPairedLUTs();
588 for (
int i = 0;
i < 2;
i++)
590 for (
int j = 0; j < 2; j++)
592 int halfCLBId =
i * 2 + j;
593 auto &CSFF = determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
594 int anotherHalfCLBId =
i * 2 + (1 - j);
596 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]];
597 if (!compatibleInOneHalfCLB(FFSwapOption[FFControlSetOrderId][halfCLBId],
598 FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]))
602 if (halfCLBId != FFSwapOption[FFControlSetOrderId][halfCLBId])
604 for (
auto FF : CSFF.getFFs())
612 if (anotherHalfCLBId != FFSwapOption[FFControlSetOrderId][anotherHalfCLBId])
614 for (
auto FF : anotherCSFF.getFFs())
626 for (
int i = 0;
i < 2;
i++)
628 for (
int j = 0; j < 2; j++)
630 for (
int k = 0; k < 4; k++)
632 if (!slotMapping.FFs[
i][j][k])
634 int halfCLBId =
i * 2 + j;
636 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
638 for (
auto tmpFF : CSFF.getFFs())
640 if (mappedFFs.find(tmpFF) == mappedFFs.end())
642 mappedFFs.insert(tmpFF);
643 mappedCells.insert(tmpFF);
644 slotMapping.FFs[
i][j][k] = tmpFF;
653 for (
auto &FFSet : determinedClusterInSite->getFFControlSets())
655 for (
auto curFF : FFSet.getFFs())
663 assert(pairMacro->
getCells().size() == 2);
664 assert(pairMacro->
getCells()[0]->isLUT());
665 assert(pairMacro->
getCells()[1]->isFF());
673 assert(fixedPairedLUTs.size() + determinedClusterInSite->getSingleLUTs().size() +
674 determinedClusterInSite->getPairedLUTs().size() <=
677 for (
int i = 0;
i < 2;
i++)
679 for (
int j = 0; j < 2; j++)
681 for (
int k = 0; k < 4; k++)
683 if (!slotMapping.LUTs[
i][j][k])
685 if (slotMapping.LUTs[
i][1 - j][k])
687 if (conflictLUTsContain(slotMapping.LUTs[
i][1 - j][k]))
689 for (
auto pair : pairedLUTs)
691 if (pair.first == slotMapping.LUTs[
i][1 - j][k])
693 slotMapping.LUTs[
i][1 - j][k] = pair.first;
694 slotMapping.LUTs[
i][j][k] = pair.second;
695 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
696 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
697 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
698 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
701 if (pair.second == slotMapping.LUTs[
i][1 - j][k])
703 slotMapping.LUTs[
i][1 - j][k] = pair.second;
704 slotMapping.LUTs[
i][j][k] = pair.first;
705 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
706 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
707 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
708 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
720 for (
int i = 0;
i < 2;
i++)
722 for (
int k = 0; k < 4; k++)
724 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
726 for (
auto pair : pairedLUTs)
728 if (mappedLUTs.find(pair.first) == mappedLUTs.end())
730 if (mappedLUTs.find(pair.second) != mappedLUTs.end())
732 for (
int i = 0;
i < 2;
i++)
734 for (
int j = 0; j < 2; j++)
736 for (
int k = 0; k < 4; k++)
738 if (slotMapping.LUTs[
i][j][k])
740 std::cout <<
"i,j,k:" <<
i <<
"," << j <<
"," << k <<
" "
741 << slotMapping.LUTs[
i][j][k] <<
"\n";
746 determinedClusterInSite->printMyself();
749 assert(mappedLUTs.find(pair.second) == mappedLUTs.end());
750 slotMapping.LUTs[
i][0][k] = pair.first;
751 slotMapping.LUTs[
i][1][k] = pair.second;
752 mappedLUTs.insert(slotMapping.LUTs[
i][0][k]);
753 mappedLUTs.insert(slotMapping.LUTs[
i][1][k]);
754 mappedCells.insert(slotMapping.LUTs[
i][0][k]);
755 mappedCells.insert(slotMapping.LUTs[
i][1][k]);
764 for (
int i = 0;
i < 2;
i++)
766 for (
int k = 0; k < 4; k++)
768 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
770 for (
auto tmpLUT : singleLUTs)
772 if (mappedLUTs.find(tmpLUT) == mappedLUTs.end())
774 assert(mappedLUTs.find(tmpLUT) == mappedLUTs.end());
775 slotMapping.LUTs[
i][0][k] = tmpLUT;
776 mappedLUTs.insert(tmpLUT);
777 mappedCells.insert(tmpLUT);
785 assert(fixedPairedLUTs.size() + determinedClusterInSite->getSingleLUTs().size() +
786 determinedClusterInSite->getPairedLUTs().size() <=
789 int LUTSwapOptions[4][4] = {{0, 1, 0, 1}, {1, 0, 0, 1}, {1, 0, 1, 0}, {0, 1, 1, 0}};
791 for (
int i0 = 0; i0 < 2; i0++)
793 for (
int k0 = 0; k0 < 4; k0++)
795 for (
int i1 = 0; i1 < 2; i1++)
797 for (
int k1 = 0; k1 < 4; k1++)
799 if (i0 == i1 && k0 == k1)
803 if ((isCarryMacro(slotMapping.LUTs[i0][0][k0]) || isCarryMacro(slotMapping.FFs[i0][0][k0]) ||
804 isCarryMacro(slotMapping.LUTs[i0][1][k0]) || isCarryMacro(slotMapping.FFs[i0][1][k0]) ||
805 isCarryMacro(slotMapping.LUTs[i1][0][k1]) || isCarryMacro(slotMapping.FFs[i1][0][k1]) ||
806 isCarryMacro(slotMapping.LUTs[i1][1][k1]) || isCarryMacro(slotMapping.FFs[i1][1][k1])))
808 float oriDirectInternalRoute_slack =
809 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][0][k0]) +
810 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][1][k0]) +
811 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][0][k1], slotMapping.FFs[i1][0][k1]) +
812 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][1][k1], slotMapping.FFs[i1][1][k1]);
814 float optDirectInternalRoute_slack = -100000000;
815 int optimalOption = -1;
816 for (
int optionId = 0; optionId < 4; optionId++)
819 float newDirectInternalRoute_slack =
820 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][LUTSwapOptions[optionId][0]][k1],
821 slotMapping.FFs[i0][0][k0]) +
822 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1],
823 slotMapping.FFs[i0][1][k0]) +
824 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][LUTSwapOptions[optionId][2]][k0],
825 slotMapping.FFs[i1][0][k1]) +
826 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][LUTSwapOptions[optionId][3]][k0],
827 slotMapping.FFs[i1][1][k1]);
828 if (
isLUT6(slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1]) ||
830 .LUTs[i0][LUTSwapOptions[optionId][3]][k0]))
832 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
834 optimalOption = optionId;
835 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
839 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
845 slotMapping.LUTs[i0][0][k0] = tmpLUT0;
847 slotMapping.LUTs[i0][1][k0] = tmpLUT1;
848 slotMapping.LUTs[i1][0][k1] = tmpLUT2;
850 slotMapping.LUTs[i1][1][k1] = tmpLUT3;
858 for (
int i = 0;
i < 2;
i++)
860 for (
int j = 0; j < 2; j++)
865 float oriDirectInternalRoute_slack =
866 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0], slotMapping.FFs[
i][j][0]) +
867 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1], slotMapping.FFs[
i][j][1]) +
868 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2], slotMapping.FFs[
i][j][2]) +
869 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3], slotMapping.FFs[
i][j][3]);
870 float optDirectInternalRoute_slack = -100000000;
871 int optimalOption = -1;
872 for (
int optionId = 0; optionId < 24; optionId++)
874 bool moveFFofCarry =
false;
875 for (
int checkFFId = 0; checkFFId < 4; checkFFId++)
877 if (FFSwapOption[optionId][checkFFId] != checkFFId)
879 if (isCarryMacro(slotMapping.FFs[
i][j][checkFFId]))
881 moveFFofCarry =
true;
888 float newDirectInternalRoute_slack =
889 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0],
890 slotMapping.FFs[
i][j][FFSwapOption[optionId][0]]) +
891 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1],
892 slotMapping.FFs[
i][j][FFSwapOption[optionId][1]]) +
893 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2],
894 slotMapping.FFs[
i][j][FFSwapOption[optionId][2]]) +
895 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3],
896 slotMapping.FFs[
i][j][FFSwapOption[optionId][3]]);
897 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
899 optimalOption = optionId;
900 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
903 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
909 slotMapping.FFs[
i][j][0] = tmpFF0;
910 slotMapping.FFs[
i][j][1] = tmpFF1;
911 slotMapping.FFs[
i][j][2] = tmpFF2;
912 slotMapping.FFs[
i][j][3] = tmpFF3;
918 if (determinedClusterInSite)
921 unsigned int FFCnt = 0;
922 for (
auto &CSFF : determinedClusterInSite->getFFControlSets())
923 FFCnt += CSFF.getFFs().size();
925 if (FFCnt != mappedFFs.size())
927 std::cout <<
"FFCnt: " << FFCnt <<
" mappedFFs.size():" << mappedFFs.size() <<
"\n";
928 determinedClusterInSite->printMyself();
929 for (
int i = 0;
i < 2;
i++)
931 for (
int k = 0; k < 4; k++)
933 for (
int j = 0; j < 2; j++)
935 std::cout <<
"i,k,j:" <<
i <<
"," << k <<
"," << j <<
":\n";
936 if (slotMapping.LUTs[
i][j][k])
937 std::cout << slotMapping.LUTs[
i][j][k] <<
"\n";
938 if (slotMapping.FFs[
i][j][k])
939 std::cout << slotMapping.FFs[
i][j][k] <<
"\n";
943 assert(FFCnt == mappedFFs.size());
947 std::map<DesignInfo::DesignCell *, std::array<int, 3>> cell2slot;
948 for (
int i = 0;
i < 2;
i++)
950 for (
int j = 0; j < 2; j++)
952 for (
int k = 0; k < 4; k++)
954 if (slotMapping.FFs[
i][j][k])
956 cell2slot[slotMapping.FFs[
i][j][k]] = std::array<int, 3>({
i, j, k});
958 if (slotMapping.LUTs[
i][j][k])
960 cell2slot[slotMapping.LUTs[
i][j][k]] = std::array<int, 3>({
i, j, k});
966 for (
int i0 = 0; i0 < 2; i0++)
968 for (
int j0 = 0; j0 < 2; j0++)
970 for (
int k0 = 0; k0 < 4; k0++)
972 if (!slotMapping.LUTs[i0][j0][k0])
974 if (LUT2FF.find(slotMapping.LUTs[i0][j0][k0]) != LUT2FF.end())
976 auto targetFF = LUT2FF[slotMapping.LUTs[i0][j0][k0]];
977 if (slotMapping.FFs[i0][j0][k0] ==
nullptr)
979 int halfCLBId0 = i0 * 2 + j0;
981 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId0]];
982 int i1 = cell2slot[targetFF].at(0);
983 int j1 = cell2slot[targetFF].at(1);
984 int k1 = cell2slot[targetFF].at(2);
985 int halfCLBId1 = i1 * 2 + j1;
987 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId1]];
988 if (CSFF0.compatibleWith(CSFF1.getCSId()))
990 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
991 FFSwapOption[FFControlSetOrderId][halfCLBId0])
992 determinedClusterInSite->moveFFFromCS1ToCS0(
993 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
994 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
995 slotMapping.FFs[i0][j0][k0] = targetFF;
996 slotMapping.FFs[i1][j1][k1] =
nullptr;
997 cell2slot[targetFF] = std::array<int, 3>({i0, j0, k0});
1006 for (
int i0 = 0; i0 < 2; i0++)
1008 for (
int j0 = 0; j0 < 2; j0++)
1010 for (
int k0 = 0; k0 < 4; k0++)
1012 if (!slotMapping.LUTs[i0][j0][k0])
1014 auto targetLUT = slotMapping.LUTs[i0][j0][k0];
1015 if (slotMapping.LUTs[i0][1 - j0][k0])
1017 if (LUT2FF.find(targetLUT) != LUT2FF.end())
1019 auto targetFF = LUT2FF[targetLUT];
1020 int i1 = cell2slot[targetFF].at(0);
1021 int j1 = cell2slot[targetFF].at(1);
1022 int k1 = cell2slot[targetFF].at(2);
1023 int halfCLBId1 = i1 * 2 + j1;
1025 if (i0 != i1 || j0 != j1 || k0 != k1)
1027 bool optimized =
false;
1028 for (
int ii = 0; ii < 2 && !optimized; ii++)
1030 for (
int jj = 0; jj < 2 && !optimized; jj++)
1032 bool compatible =
true;
1033 if (targetLUT->isLUT6() && jj == 1)
1035 int halfCLBId0 = ii * 2 + jj;
1036 for (
int kk = 0; kk < 4; kk++)
1038 if (slotMapping.FFs[ii][jj][kk])
1040 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo())
1042 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo()->getId() !=
1043 targetFF->getControlSetInfo()->getId())
1050 for (
int kk = 0; kk < 4; kk++)
1052 if (slotMapping.FFs[ii][1 - jj][kk])
1054 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo())
1056 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getCLK() !=
1057 targetFF->getControlSetInfo()->getCLK() ||
1058 slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getSR() !=
1059 targetFF->getControlSetInfo()->getSR())
1069 for (
int kk = 0; kk < 4; kk++)
1071 if (!slotMapping.LUTs[ii][jj][kk] && !slotMapping.FFs[ii][jj][kk])
1075 if (targetLUT->isLUT6())
1077 if (slotMapping.LUTs[ii][1 - jj][kk])
1082 if (slotMapping.LUTs[ii][1 - jj][kk] &&
1083 slotMapping.LUTs[ii][1 - jj][kk]->isLUT6())
1085 if (slotMapping.LUTs[ii][1 - jj][kk])
1088 getPairPinNum(targetLUT, slotMapping.LUTs[ii][1 - jj][kk]);
1094 slotMapping.LUTs[i0][j0][k0] =
nullptr;
1095 slotMapping.FFs[i1][j1][k1] =
nullptr;
1096 assert(!slotMapping.LUTs[ii][jj][kk]);
1097 assert(!slotMapping.FFs[ii][jj][kk]);
1098 slotMapping.LUTs[ii][jj][kk] = targetLUT;
1099 slotMapping.FFs[ii][jj][kk] = targetFF;
1101 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
1102 FFSwapOption[FFControlSetOrderId][halfCLBId0])
1103 determinedClusterInSite->moveFFFromCS1ToCS0(
1104 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
1105 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
1106 cell2slot[targetFF] = std::array<int, 3>({ii, jj, kk});
1107 cell2slot[targetLUT] = std::array<int, 3>({ii, jj, kk});
1123 float directConnectCnt = 0;
1124 for (
int i = 0;
i < 2;
i++)
1126 for (
int j = 0; j < 2; j++)
1128 for (
int k = 0; k < 4; k++)
1130 if (checkDirectLUTFFConnect(FF2LUT, slotMapping.LUTs[
i][j][k], slotMapping.FFs[
i][j][k]))
1132 auto srcCell = slotMapping.LUTs[
i][j][k];
1133 unsigned int srcCellId = srcCell->getCellId();
1134 auto srcNode = timingNodes[srcCellId];
1136 if (srcNode->getForwardLevel() < 0)
1139 (srcNode->getLatestInputArrival() - srcNode->getRequiredArrivalTime()) / clockPeriod + 20;
1140 directConnectCnt += slack;
1145 if (directConnectCnt > best_DirectConnect)
1147 best_SlotMapping = slotMapping;
1148 best_mappedCells = mappedCells;
1149 best_mappedLUTs = mappedLUTs;
1150 best_mappedFFs = mappedFFs;
1151 best_DirectConnect = directConnectCnt;
1157 int FFSwapOption[24][4] = {{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}, {0, 3, 2, 1},
1158 {1, 0, 2, 3}, {1, 0, 3, 2}, {1, 2, 0, 3}, {1, 2, 3, 0}, {1, 3, 0, 2}, {1, 3, 2, 0},
1159 {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 0, 3}, {2, 1, 3, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
1160 {3, 0, 1, 2}, {3, 0, 2, 1}, {3, 1, 0, 2}, {3, 1, 2, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
1163 mappedCells.clear();
1166 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> FF2LUT;
1167 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> LUT2FF;
1168 auto singleLUTs = determinedClusterInSite->getSortedSingleLUTs();
1169 auto pairedLUTs = determinedClusterInSite->getSortedPairedLUTs();
1171 for (
int i = 0;
i < 2;
i++)
1173 for (
int j = 0; j < 2; j++)
1175 int halfCLBId =
i * 2 + j;
1176 auto &CSFF = determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
1177 int anotherHalfCLBId =
i * 2 + (1 - j);
1179 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]];
1180 if (!compatibleInOneHalfCLB(FFSwapOption[FFControlSetOrderId][halfCLBId],
1181 FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]))
1185 if (halfCLBId != FFSwapOption[FFControlSetOrderId][halfCLBId])
1187 for (
auto FF : CSFF.getFFs())
1195 if (anotherHalfCLBId != FFSwapOption[FFControlSetOrderId][anotherHalfCLBId])
1197 for (
auto FF : anotherCSFF.getFFs())
1209 for (
int i = 0;
i < 2;
i++)
1211 for (
int j = 0; j < 2; j++)
1213 for (
int k = 0; k < 4; k++)
1215 if (!slotMapping.FFs[
i][j][k])
1217 int halfCLBId =
i * 2 + j;
1219 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
1221 for (
auto tmpFF : CSFF.getFFs())
1223 if (mappedFFs.find(tmpFF) == mappedFFs.end())
1225 mappedFFs.insert(tmpFF);
1226 mappedCells.insert(tmpFF);
1227 slotMapping.FFs[
i][j][k] = tmpFF;
1237 for (
auto &FFSet : determinedClusterInSite->getFFControlSets())
1239 for (
auto curFF : FFSet.getFFs())
1247 assert(pairMacro->
getCells().size() == 2);
1248 assert(pairMacro->
getCells()[0]->isLUT());
1249 assert(pairMacro->
getCells()[1]->isFF());
1257 assert(singleLUTs.size() + pairedLUTs.size() <= 8);
1259 for (
int i = 0;
i < 2;
i++)
1261 for (
int j = 0; j < 2; j++)
1263 for (
int k = 0; k < 4; k++)
1265 if (!slotMapping.LUTs[
i][j][k])
1267 if (slotMapping.LUTs[
i][1 - j][k])
1269 for (
auto pair : pairedLUTs)
1271 if (pair.first == slotMapping.LUTs[
i][1 - j][k])
1273 slotMapping.LUTs[
i][1 - j][k] = pair.first;
1274 slotMapping.LUTs[
i][j][k] = pair.second;
1275 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
1276 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
1277 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
1278 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
1281 if (pair.second == slotMapping.LUTs[
i][1 - j][k])
1283 slotMapping.LUTs[
i][1 - j][k] = pair.second;
1284 slotMapping.LUTs[
i][j][k] = pair.first;
1285 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
1286 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
1287 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
1288 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
1299 for (
int i = 0;
i < 2;
i++)
1301 for (
int k = 0; k < 4; k++)
1303 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
1305 for (
auto pair : pairedLUTs)
1307 if (mappedLUTs.find(pair.first) == mappedLUTs.end())
1309 if (mappedLUTs.find(pair.second) != mappedLUTs.end())
1311 for (
int i = 0;
i < 2;
i++)
1313 for (
int j = 0; j < 2; j++)
1315 for (
int k = 0; k < 4; k++)
1317 if (slotMapping.LUTs[
i][j][k])
1319 std::cout <<
"i,j,k:" <<
i <<
"," << j <<
"," << k <<
" "
1320 << slotMapping.LUTs[
i][j][k] <<
"\n";
1325 determinedClusterInSite->printMyself();
1328 assert(mappedLUTs.find(pair.second) == mappedLUTs.end());
1329 slotMapping.LUTs[
i][0][k] = pair.first;
1330 slotMapping.LUTs[
i][1][k] = pair.second;
1331 mappedLUTs.insert(slotMapping.LUTs[
i][0][k]);
1332 mappedLUTs.insert(slotMapping.LUTs[
i][1][k]);
1333 mappedCells.insert(slotMapping.LUTs[
i][0][k]);
1334 mappedCells.insert(slotMapping.LUTs[
i][1][k]);
1343 for (
int i = 0;
i < 2;
i++)
1345 for (
int k = 0; k < 4; k++)
1347 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
1349 for (
auto tmpLUT : singleLUTs)
1351 if (mappedLUTs.find(tmpLUT) == mappedLUTs.end())
1353 assert(mappedLUTs.find(tmpLUT) == mappedLUTs.end());
1354 slotMapping.LUTs[
i][0][k] = tmpLUT;
1355 mappedLUTs.insert(tmpLUT);
1356 mappedCells.insert(tmpLUT);
1367 assert(singleLUTs.size() + pairedLUTs.size() <= 8);
1368 if (determinedClusterInSite)
1371 unsigned int FFCnt = 0;
1372 for (
auto &CSFF : determinedClusterInSite->getFFControlSets())
1373 FFCnt += CSFF.getFFs().size();
1375 if (FFCnt != mappedFFs.size())
1377 std::cout <<
"FFCnt: " << FFCnt <<
" mappedFFs.size():" << mappedFFs.size() <<
"\n";
1378 determinedClusterInSite->printMyself();
1379 for (
int i = 0;
i < 2;
i++)
1381 for (
int k = 0; k < 4; k++)
1383 for (
int j = 0; j < 2; j++)
1385 std::cout <<
"i,k,j:" <<
i <<
"," << k <<
"," << j <<
":\n";
1386 if (slotMapping.LUTs[
i][j][k])
1387 std::cout << slotMapping.LUTs[
i][j][k] <<
"\n";
1388 if (slotMapping.FFs[
i][j][k])
1389 std::cout << slotMapping.FFs[
i][j][k] <<
"\n";
1393 assert(FFCnt == mappedFFs.size());
1397 for (
int i0 = 0; i0 < 2; i0++)
1399 for (
int k0 = 0; k0 < 4; k0++)
1401 if (!
isLUT6(slotMapping.LUTs[i0][0][k0]) && !
isLUT6(slotMapping.LUTs[i0][1][k0]))
1403 float oriDirectInternalRoute_slack =
1404 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][0][k0]) +
1405 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][1][k0]);
1408 float newDirectInternalRoute_slack =
1409 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][1][k0]) +
1410 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][0][k0]);
1412 if (oriDirectInternalRoute_slack < newDirectInternalRoute_slack)
1415 tmpLUT = slotMapping.LUTs[i0][0][k0];
1416 slotMapping.LUTs[i0][0][k0] = slotMapping.LUTs[i0][1][k0];
1417 slotMapping.LUTs[i0][1][k0] = tmpLUT;
1424 int LUTSwapOptions[4][4] = {{0, 1, 0, 1}, {1, 0, 0, 1}, {1, 0, 1, 0}, {0, 1, 1, 0}};
1426 for (
int attempt = 0; attempt < 2; attempt++)
1428 for (
int i0 = 0; i0 < 2; i0++)
1430 for (
int k0 = 0; k0 < 4; k0++)
1432 for (
int i1 = 0; i1 < 2; i1++)
1434 for (
int k1 = 0; k1 < 4; k1++)
1436 if (i0 == i1 && k0 == k1)
1440 float oriDirectInternalRoute_slack =
1441 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0],
1442 slotMapping.FFs[i0][0][k0]) +
1443 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0],
1444 slotMapping.FFs[i0][1][k0]) +
1445 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][0][k1],
1446 slotMapping.FFs[i1][0][k1]) +
1447 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][1][k1],
1448 slotMapping.FFs[i1][1][k1]);
1450 float optDirectInternalRoute_slack = -100000000;
1451 int optimalOption = -1;
1452 for (
int optionId = 0; optionId < 4; optionId++)
1455 float newDirectInternalRoute_slack =
1456 checkDirectLUTFFConnect_slack(FF2LUT,
1457 slotMapping.LUTs[i1][LUTSwapOptions[optionId][0]][k1],
1458 slotMapping.FFs[i0][0][k0]) +
1459 checkDirectLUTFFConnect_slack(FF2LUT,
1460 slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1],
1461 slotMapping.FFs[i0][1][k0]) +
1462 checkDirectLUTFFConnect_slack(FF2LUT,
1463 slotMapping.LUTs[i0][LUTSwapOptions[optionId][2]][k0],
1464 slotMapping.FFs[i1][0][k1]) +
1465 checkDirectLUTFFConnect_slack(FF2LUT,
1466 slotMapping.LUTs[i0][LUTSwapOptions[optionId][3]][k0],
1467 slotMapping.FFs[i1][1][k1]);
1468 if (
isLUT6(slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1]) ||
1469 isLUT6(slotMapping.LUTs[i0][LUTSwapOptions[optionId][3]]
1472 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
1474 optimalOption = optionId;
1475 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
1479 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
1482 slotMapping.LUTs[i1][LUTSwapOptions[optimalOption][0]][k1];
1484 slotMapping.LUTs[i1][LUTSwapOptions[optimalOption][1]][k1];
1486 slotMapping.LUTs[i0][LUTSwapOptions[optimalOption][2]][k0];
1488 slotMapping.LUTs[i0][LUTSwapOptions[optimalOption][3]][k0];
1489 slotMapping.LUTs[i0][0][k0] = tmpLUT0;
1490 assert(!
isLUT6(tmpLUT1));
1491 slotMapping.LUTs[i0][1][k0] = tmpLUT1;
1492 slotMapping.LUTs[i1][0][k1] = tmpLUT2;
1493 assert(!
isLUT6(tmpLUT3));
1494 slotMapping.LUTs[i1][1][k1] = tmpLUT3;
1503 for (
int i = 0;
i < 2;
i++)
1505 for (
int j = 0; j < 2; j++)
1507 float oriDirectInternalRoute_slack =
1508 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0], slotMapping.FFs[
i][j][0]) +
1509 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1], slotMapping.FFs[
i][j][1]) +
1510 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2], slotMapping.FFs[
i][j][2]) +
1511 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3], slotMapping.FFs[
i][j][3]);
1512 float optDirectInternalRoute_slack = -100000000;
1513 int optimalOption = -1;
1514 for (
int optionId = 0; optionId < 24; optionId++)
1516 float newDirectInternalRoute_slack =
1517 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0],
1518 slotMapping.FFs[
i][j][FFSwapOption[optionId][0]]) +
1519 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1],
1520 slotMapping.FFs[
i][j][FFSwapOption[optionId][1]]) +
1521 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2],
1522 slotMapping.FFs[
i][j][FFSwapOption[optionId][2]]) +
1523 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3],
1524 slotMapping.FFs[
i][j][FFSwapOption[optionId][3]]);
1525 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
1527 optimalOption = optionId;
1528 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
1531 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
1537 slotMapping.FFs[
i][j][0] = tmpFF0;
1538 slotMapping.FFs[
i][j][1] = tmpFF1;
1539 slotMapping.FFs[
i][j][2] = tmpFF2;
1540 slotMapping.FFs[
i][j][3] = tmpFF3;
1546 std::map<DesignInfo::DesignCell *, std::array<int, 3>> cell2slot;
1547 for (
int i = 0;
i < 2;
i++)
1549 for (
int j = 0; j < 2; j++)
1551 for (
int k = 0; k < 4; k++)
1553 if (slotMapping.FFs[
i][j][k])
1555 cell2slot[slotMapping.FFs[
i][j][k]] = std::array<int, 3>({
i, j, k});
1557 if (slotMapping.LUTs[
i][j][k])
1559 cell2slot[slotMapping.LUTs[
i][j][k]] = std::array<int, 3>({
i, j, k});
1566 for (
int i0 = 0; i0 < 2; i0++)
1568 for (
int j0 = 0; j0 < 2; j0++)
1570 for (
int k0 = 0; k0 < 4; k0++)
1572 if (!slotMapping.LUTs[i0][j0][k0])
1574 if (LUT2FF.find(slotMapping.LUTs[i0][j0][k0]) != LUT2FF.end())
1576 auto targetFF = LUT2FF[slotMapping.LUTs[i0][j0][k0]];
1577 if (slotMapping.FFs[i0][j0][k0] ==
nullptr)
1579 int halfCLBId0 = i0 * 2 + j0;
1581 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId0]];
1582 int i1 = cell2slot[targetFF].at(0);
1583 int j1 = cell2slot[targetFF].at(1);
1584 int k1 = cell2slot[targetFF].at(2);
1585 int halfCLBId1 = i1 * 2 + j1;
1587 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId1]];
1588 if (CSFF0.compatibleWith(CSFF1.getCSId()))
1590 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
1591 FFSwapOption[FFControlSetOrderId][halfCLBId0])
1592 determinedClusterInSite->moveFFFromCS1ToCS0(
1593 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
1594 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
1595 slotMapping.FFs[i0][j0][k0] = targetFF;
1596 slotMapping.FFs[i1][j1][k1] =
nullptr;
1597 cell2slot[targetFF] = std::array<int, 3>({i0, j0, k0});
1606 for (
int i0 = 0; i0 < 2; i0++)
1608 for (
int j0 = 0; j0 < 2; j0++)
1610 for (
int k0 = 0; k0 < 4; k0++)
1612 if (!slotMapping.LUTs[i0][j0][k0])
1614 auto targetLUT = slotMapping.LUTs[i0][j0][k0];
1615 if (slotMapping.LUTs[i0][1 - j0][k0])
1617 if (LUT2FF.find(targetLUT) != LUT2FF.end())
1619 auto targetFF = LUT2FF[targetLUT];
1620 int i1 = cell2slot[targetFF].at(0);
1621 int j1 = cell2slot[targetFF].at(1);
1622 int k1 = cell2slot[targetFF].at(2);
1623 int halfCLBId1 = i1 * 2 + j1;
1625 if (i0 != i1 || j0 != j1 || k0 != k1)
1627 bool optimized =
false;
1628 for (
int ii = 0; ii < 2 && !optimized; ii++)
1630 for (
int jj = 0; jj < 2 && !optimized; jj++)
1632 bool compatible =
true;
1633 if (targetLUT->isLUT6() && jj == 1)
1635 int halfCLBId0 = ii * 2 + jj;
1636 for (
int kk = 0; kk < 4; kk++)
1638 if (slotMapping.FFs[ii][jj][kk])
1640 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo())
1642 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo()->getId() !=
1643 targetFF->getControlSetInfo()->getId())
1650 for (
int kk = 0; kk < 4; kk++)
1652 if (slotMapping.FFs[ii][1 - jj][kk])
1654 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo())
1656 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getCLK() !=
1657 targetFF->getControlSetInfo()->getCLK() ||
1658 slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getSR() !=
1659 targetFF->getControlSetInfo()->getSR())
1669 for (
int kk = 0; kk < 4; kk++)
1671 if (!slotMapping.LUTs[ii][jj][kk] && !slotMapping.FFs[ii][jj][kk])
1675 if (targetLUT->isLUT6())
1677 if (slotMapping.LUTs[ii][1 - jj][kk])
1682 if (slotMapping.LUTs[ii][1 - jj][kk] &&
1683 slotMapping.LUTs[ii][1 - jj][kk]->isLUT6())
1685 if (slotMapping.LUTs[ii][1 - jj][kk])
1688 getPairPinNum(targetLUT, slotMapping.LUTs[ii][1 - jj][kk]);
1694 slotMapping.LUTs[i0][j0][k0] =
nullptr;
1695 slotMapping.FFs[i1][j1][k1] =
nullptr;
1696 assert(!slotMapping.LUTs[ii][jj][kk]);
1697 assert(!slotMapping.FFs[ii][jj][kk]);
1698 slotMapping.LUTs[ii][jj][kk] = targetLUT;
1699 slotMapping.FFs[ii][jj][kk] = targetFF;
1701 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
1702 FFSwapOption[FFControlSetOrderId][halfCLBId0])
1703 determinedClusterInSite->moveFFFromCS1ToCS0(
1704 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
1705 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
1706 cell2slot[targetFF] = std::array<int, 3>({ii, jj, kk});
1707 cell2slot[targetLUT] = std::array<int, 3>({ii, jj, kk});
1721 for (
int i0 = 0; i0 < 2; i0++)
1723 for (
int k0 = 0; k0 < 4; k0++)
1725 if (slotMapping.LUTs[i0][0][k0])
1727 if (slotMapping.LUTs[i0][0][k0]->isLUT6())
1729 assert(!slotMapping.LUTs[i0][1][k0]);
1731 else if (slotMapping.LUTs[i0][1][k0])
1733 assert(!slotMapping.LUTs[i0][1][k0]->isLUT6());
1734 int pairPinNum = getPairPinNum(slotMapping.LUTs[i0][1][k0], slotMapping.LUTs[i0][0][k0]);
1735 assert(pairPinNum <= 5);
1743 float directConnectCnt = 0;
1744 for (
int i = 0;
i < 2;
i++)
1746 for (
int j = 0; j < 2; j++)
1748 for (
int k = 0; k < 4; k++)
1750 if (checkDirectLUTFFConnect(FF2LUT, slotMapping.LUTs[
i][j][k], slotMapping.FFs[
i][j][k]))
1752 auto srcCell = slotMapping.LUTs[
i][j][k];
1753 unsigned int srcCellId = srcCell->getCellId();
1754 auto srcNode = timingNodes[srcCellId];
1756 if (srcNode->getForwardLevel() < 0)
1759 (srcNode->getLatestInputArrival() - srcNode->getRequiredArrivalTime()) / clockPeriod + 20;
1760 directConnectCnt += slack;
1765 if (directConnectCnt > best_DirectConnect)
1767 best_SlotMapping = slotMapping;
1768 best_mappedCells = mappedCells;
1769 best_mappedLUTs = mappedLUTs;
1770 best_mappedFFs = mappedFFs;
1771 best_DirectConnect = directConnectCnt;
1777 assert(muxF8Offset < 2);
1778 slotMapping.MuxF8[muxF8Offset] = MUXF8Macro->
getCells()[0];
1780 auto curMUXF8 = slotMapping.MuxF8[muxF8Offset];
1781 std::vector<DesignInfo::DesignCell *> virtualLUTs;
1782 std::vector<DesignInfo::DesignCell *> virtualFFs;
1783 std::vector<DesignInfo::DesignCell *> virtualMUXs;
1784 std::vector<DesignInfo::DesignCell *> LUTsInMacro;
1785 std::vector<DesignInfo::DesignCell *> FFsInMacro;
1786 std::vector<DesignInfo::DesignCell *> MUXsInMacro;
1787 for (
auto curCell : MUXF8Macro->
getCells())
1789 if (curCell->isVirtualCell())
1791 if (curCell->isMux())
1792 virtualMUXs.push_back(curCell);
1793 if (curCell->isFF())
1794 virtualFFs.push_back(curCell);
1795 if (curCell->isLUT())
1796 virtualLUTs.push_back(curCell);
1800 if (curCell->isMux())
1801 MUXsInMacro.push_back(curCell);
1802 if (curCell->isFF())
1803 FFsInMacro.push_back(curCell);
1804 if (curCell->isLUT())
1805 LUTsInMacro.push_back(curCell);
1812 if (!pinBeDriven->getDriverPin())
1814 if (pinBeDriven->getRefPinName() ==
"I0")
1816 auto I0MuxF7 = pinBeDriven->getDriverPin()->getCell();
1817 if (MUXF8Macro->
hasCell(I0MuxF7))
1820 slotMapping.MuxF7[muxF8Offset][1] = I0MuxF7;
1823 else if (pinBeDriven->getRefPinName() ==
"I1")
1825 auto I1MuxF7 = pinBeDriven->getDriverPin()->getCell();
1826 if (MUXF8Macro->
hasCell(I1MuxF7))
1829 slotMapping.MuxF7[muxF8Offset][0] = I1MuxF7;
1835 unsigned int fillVirtualCellCnt = 0;
1836 for (
int i = 0;
i < 2;
i++)
1838 if (!slotMapping.MuxF7[muxF8Offset][
i])
1840 assert(fillVirtualCellCnt < virtualMUXs.size());
1841 slotMapping.MuxF7[muxF8Offset][
i] = virtualMUXs[fillVirtualCellCnt];
1842 fillVirtualCellCnt++;
1845 assert(fillVirtualCellCnt == virtualMUXs.size());
1848 for (
int i = 0;
i < 2;
i++)
1850 auto curMuxF7 = slotMapping.MuxF7[muxF8Offset][
i];
1853 if (!pinBeDriven->getDriverPin())
1855 if (pinBeDriven->getRefPinName() ==
"I0")
1857 auto I0LUT = pinBeDriven->getDriverPin()->getCell();
1858 if (MUXF8Macro->
hasCell(I0LUT))
1860 assert(I0LUT->isLUT6());
1861 slotMapping.LUTs[muxF8Offset][0][
i * 2 + 1] = I0LUT;
1864 else if (pinBeDriven->getRefPinName() ==
"I1")
1866 auto I1LUT = pinBeDriven->getDriverPin()->getCell();
1867 if (MUXF8Macro->
hasCell(I1LUT))
1869 assert(I1LUT->isLUT6());
1870 slotMapping.LUTs[muxF8Offset][0][
i * 2] = I1LUT;
1877 fillVirtualCellCnt = 0;
1878 for (
int i = 0;
i < 4;
i++)
1880 if (!slotMapping.LUTs[muxF8Offset][0][
i])
1882 assert(fillVirtualCellCnt < virtualLUTs.size());
1883 slotMapping.LUTs[muxF8Offset][0][
i] = virtualLUTs[fillVirtualCellCnt];
1884 fillVirtualCellCnt++;
1887 assert(fillVirtualCellCnt == virtualLUTs.size());
1890 if (3 == virtualFFs.size())
1892 slotMapping.FFs[muxF8Offset][0][0] = virtualFFs[0];
1893 slotMapping.FFs[muxF8Offset][0][1] = virtualFFs[1];
1894 slotMapping.FFs[muxF8Offset][0][2] = virtualFFs[2];
1896 else if (2 == virtualFFs.size())
1898 assert(FFsInMacro.size() == 1);
1899 slotMapping.FFs[muxF8Offset][0][0] = virtualFFs[0];
1900 slotMapping.FFs[muxF8Offset][0][1] = virtualFFs[1];
1901 slotMapping.FFs[muxF8Offset][0][2] = FFsInMacro[0];
1905 assert(
false &&
"undefined situation");
1908 for (
auto tmpCell : MUXF8Macro->
getCells())
1910 mappedCells.insert(tmpCell);
1911 if (tmpCell->isLUT())
1912 mappedLUTs.insert(tmpCell);
1913 else if (tmpCell->isFF())
1914 mappedFFs.insert(tmpCell);
1920 assert(halfCLBOffset < 2);
1921 unsigned int F7Offset = 0;
1922 if (slotMapping.MuxF7[halfCLBOffset][F7Offset])
1924 if (slotMapping.MuxF7[halfCLBOffset][F7Offset])
1926 std::cout << determinedClusterInSite <<
"\n";
1929 assert(!slotMapping.MuxF7[halfCLBOffset][F7Offset]);
1930 slotMapping.MuxF7[halfCLBOffset][F7Offset] = MUXF7Macro->
getCells()[0];
1932 auto curMUXF7 = slotMapping.MuxF7[halfCLBOffset][F7Offset];
1933 std::vector<DesignInfo::DesignCell *> virtualLUTs;
1934 std::vector<DesignInfo::DesignCell *> virtualFFs;
1935 std::vector<DesignInfo::DesignCell *> virtualMUXs;
1936 std::vector<DesignInfo::DesignCell *> LUTsInMacro;
1937 std::vector<DesignInfo::DesignCell *> FFsInMacro;
1938 std::vector<DesignInfo::DesignCell *> MUXsInMacro;
1939 for (
auto curCell : MUXF7Macro->
getCells())
1941 if (curCell->isVirtualCell())
1943 if (curCell->isMux())
1944 virtualMUXs.push_back(curCell);
1945 if (curCell->isFF())
1946 virtualFFs.push_back(curCell);
1947 if (curCell->isLUT())
1948 virtualLUTs.push_back(curCell);
1952 if (curCell->isMux())
1953 MUXsInMacro.push_back(curCell);
1954 if (curCell->isFF())
1955 FFsInMacro.push_back(curCell);
1956 if (curCell->isLUT())
1957 LUTsInMacro.push_back(curCell);
1964 if (!pinBeDriven->getDriverPin())
1969 assert(pinBeDriven->getDriverPin());
1970 if (pinBeDriven->getRefPinName() ==
"I0")
1972 auto I0LUT = pinBeDriven->getDriverPin()->getCell();
1973 if (MUXF7Macro->
hasCell(I0LUT))
1975 assert(I0LUT->isLUT6());
1976 slotMapping.LUTs[halfCLBOffset][0][F7Offset * 2 + 1] = I0LUT;
1979 else if (pinBeDriven->getRefPinName() ==
"I1")
1981 if (!pinBeDriven->getDriverPin())
1986 assert(pinBeDriven->getDriverPin());
1987 auto I1LUT = pinBeDriven->getDriverPin()->getCell();
1988 if (MUXF7Macro->
hasCell(I1LUT))
1990 assert(I1LUT->isLUT6());
1991 slotMapping.LUTs[halfCLBOffset][0][F7Offset * 2] = I1LUT;
1997 unsigned int fillVirtualCellCnt = 0;
1998 assert(virtualLUTs.size() <= 2 &&
"There should be no more than two Virtual LUTs");
1999 for (
unsigned int i = F7Offset * 2;
i < F7Offset * 2 + 2;
i++)
2001 if (!slotMapping.LUTs[halfCLBOffset][0][
i])
2003 assert(fillVirtualCellCnt < virtualLUTs.size());
2004 slotMapping.LUTs[halfCLBOffset][0][
i] = virtualLUTs[fillVirtualCellCnt];
2005 fillVirtualCellCnt++;
2008 assert(fillVirtualCellCnt == virtualLUTs.size());
2011 if (1 == virtualFFs.size())
2013 slotMapping.FFs[halfCLBOffset][0][F7Offset * 2] = virtualFFs[0];
2017 assert(virtualFFs.size() <= 1 &&
"MUXF7 macro should only have one virtual FF.");
2020 if (1 == FFsInMacro.size())
2022 assert(FFsInMacro.size() == 1);
2023 slotMapping.FFs[halfCLBOffset][0][F7Offset * 2 + 1] = FFsInMacro[0];
2027 assert(FFsInMacro.size() <= 1 &&
"undefined situation");
2030 for (
auto tmpCell : MUXF7Macro->
getCells())
2032 mappedCells.insert(tmpCell);
2033 if (tmpCell->isLUT())
2034 mappedLUTs.insert(tmpCell);
2035 else if (tmpCell->isFF())
2036 mappedFFs.insert(tmpCell);
2042 assert(determinedClusterInSite);
2043 int resHalfCLB = -1;
2044 for (
int i = 0;
i < 4;
i++)
2046 for (
auto tmpFF : determinedClusterInSite->getFFControlSets()[
i].getFFs())
2048 if (MUXF8Macro->
hasCell(tmpFF))
2050 if (resHalfCLB == -1)
2053 assert(resHalfCLB ==
i);
2061 assert(!checkIsPrePackedSite() && checkIsMuxSite());
2062 assert(fixedPairedLUTs.size() == 0 && conflictLUTs.size() == 0);
2063 assert(determinedClusterInSite->getSingleLUTs().size() + determinedClusterInSite->getPairedLUTs().size() <= 8);
2065 for (
int i = 0;
i < 24;
i++)
2066 greedyMapMuxForCommonLUTFFInSite(
i);
2068 determinedClusterInSite->evictFFsFromMuxHalfCLB();
2070 for (
int i = 0;
i < 24;
i++)
2071 greedyMapMuxForCommonLUTFFInSite(
i);
2073 slotMapping = best_SlotMapping;
2074 mappedCells = best_mappedCells;
2075 mappedLUTs = best_mappedLUTs;
2076 mappedFFs = best_mappedFFs;
2077 moveLUTToLUT6Slot();
2082 int FFSwapOption[24][4] = {{0, 1, 2, 3}, {0, 1, 3, 2}, {0, 2, 1, 3}, {0, 2, 3, 1}, {0, 3, 1, 2}, {0, 3, 2, 1},
2083 {1, 0, 2, 3}, {1, 0, 3, 2}, {1, 2, 0, 3}, {1, 2, 3, 0}, {1, 3, 0, 2}, {1, 3, 2, 0},
2084 {2, 0, 1, 3}, {2, 0, 3, 1}, {2, 1, 0, 3}, {2, 1, 3, 0}, {2, 3, 0, 1}, {2, 3, 1, 0},
2085 {3, 0, 1, 2}, {3, 0, 2, 1}, {3, 1, 0, 2}, {3, 1, 2, 0}, {3, 2, 0, 1}, {3, 2, 1, 0}};
2088 mappedCells.clear();
2091 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> LUT2FF;
2092 std::map<DesignInfo::DesignCell *, DesignInfo::DesignCell *> FF2LUT;
2093 auto singleLUTs = determinedClusterInSite->getSortedSingleLUTs();
2094 auto pairedLUTs = determinedClusterInSite->getSortedPairedLUTs();
2096 for (
int i = 0;
i < 2;
i++)
2098 for (
int j = 0; j < 2; j++)
2100 int halfCLBId =
i * 2 + j;
2101 auto &CSFF = determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
2102 int anotherHalfCLBId =
i * 2 + (1 - j);
2104 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]];
2105 if (!compatibleInOneHalfCLB(FFSwapOption[FFControlSetOrderId][halfCLBId],
2106 FFSwapOption[FFControlSetOrderId][anotherHalfCLBId]))
2110 if (halfCLBId != FFSwapOption[FFControlSetOrderId][halfCLBId])
2112 for (
auto FF : CSFF.getFFs())
2120 if (anotherHalfCLBId != FFSwapOption[FFControlSetOrderId][anotherHalfCLBId])
2122 for (
auto FF : anotherCSFF.getFFs())
2133 for (
auto &FFSet : determinedClusterInSite->getFFControlSets())
2135 for (
auto curFF : FFSet.getFFs())
2143 assert(pairMacro->
getCells().size() == 2);
2144 assert(pairMacro->
getCells()[0]->isLUT());
2145 assert(pairMacro->
getCells()[1]->isFF());
2153 std::vector<PlacementInfo::PlacementMacro *> MUXF7Macros;
2154 std::vector<PlacementInfo::PlacementMacro *> MUXF8Macros;
2155 for (
auto tmpPU : determinedClusterInSite->getPUs())
2161 MUXF7Macros.push_back(tmpMacro);
2165 MUXF8Macros.push_back(tmpMacro);
2169 assert((MUXF7Macros.size() + 1) / 2 + MUXF8Macros.size() <= 2);
2171 for (
unsigned int i = 0;
i < MUXF8Macros.size();
i++)
2173 assert(MUXF8Macros[
i]->getCells().size() == 10);
2175 int targetHalfCLB = findMuxFromHalfCLB(MUXF8Macros[
i]);
2176 assert(targetHalfCLB % 2 == 0);
2177 mapMuxF8Macro(targetHalfCLB / 2, MUXF8Macros[
i]);
2180 for (
unsigned int i = 0;
i < MUXF7Macros.size();
i++)
2182 assert(MUXF7Macros[
i]->getCells().size() >= 4 && MUXF7Macros[
i]->getCells().size() <= 5);
2184 int targetHalfCLB = findMuxFromHalfCLB(MUXF7Macros[
i]);
2185 assert(targetHalfCLB % 2 == 0);
2186 mapMuxF7Macro(targetHalfCLB / 2, MUXF7Macros[
i]);
2190 for (
int i = 0;
i < 2;
i++)
2192 for (
int j = 0; j < 2; j++)
2194 for (
int k = 3; k >= 0; k--)
2196 if (!slotMapping.FFs[
i][j][k])
2198 int halfCLBId =
i * 2 + j;
2200 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId]];
2202 for (
auto tmpFF : CSFF.getFFs())
2204 if (mappedFFs.find(tmpFF) == mappedFFs.end())
2206 mappedFFs.insert(tmpFF);
2207 mappedCells.insert(tmpFF);
2208 slotMapping.FFs[
i][j][k] = tmpFF;
2217 assert(determinedClusterInSite->getSingleLUTs().size() + determinedClusterInSite->getPairedLUTs().size() <= 8);
2219 for (
int i = 0;
i < 2;
i++)
2221 for (
int j = 0; j < 2; j++)
2223 for (
int k = 0; k < 4; k++)
2225 if (!slotMapping.LUTs[
i][j][k])
2227 if (slotMapping.LUTs[
i][1 - j][k])
2229 for (
auto pair : pairedLUTs)
2231 if (pair.first == slotMapping.LUTs[
i][1 - j][k])
2233 slotMapping.LUTs[
i][1 - j][k] = pair.first;
2234 slotMapping.LUTs[
i][j][k] = pair.second;
2235 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
2236 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
2237 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
2238 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
2241 if (pair.second == slotMapping.LUTs[
i][1 - j][k])
2243 slotMapping.LUTs[
i][1 - j][k] = pair.second;
2244 slotMapping.LUTs[
i][j][k] = pair.first;
2245 mappedLUTs.insert(slotMapping.LUTs[
i][j][k]);
2246 mappedLUTs.insert(slotMapping.LUTs[
i][1 - j][k]);
2247 mappedCells.insert(slotMapping.LUTs[
i][j][k]);
2248 mappedCells.insert(slotMapping.LUTs[
i][1 - j][k]);
2259 for (
int i = 0;
i < 2;
i++)
2261 for (
int k = 0; k < 4; k++)
2263 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
2265 for (
auto pair : pairedLUTs)
2267 if (mappedLUTs.find(pair.first) == mappedLUTs.end())
2269 if (mappedLUTs.find(pair.second) != mappedLUTs.end())
2271 for (
int i = 0;
i < 2;
i++)
2273 for (
int j = 0; j < 2; j++)
2275 for (
int k = 0; k < 4; k++)
2277 if (slotMapping.LUTs[
i][j][k])
2279 std::cout <<
"i,j,k:" <<
i <<
"," << j <<
"," << k <<
" "
2280 << slotMapping.LUTs[
i][j][k] <<
"\n";
2285 determinedClusterInSite->printMyself();
2288 assert(mappedLUTs.find(pair.second) == mappedLUTs.end());
2289 slotMapping.LUTs[
i][0][k] = pair.first;
2290 slotMapping.LUTs[
i][1][k] = pair.second;
2291 mappedLUTs.insert(slotMapping.LUTs[
i][0][k]);
2292 mappedLUTs.insert(slotMapping.LUTs[
i][1][k]);
2293 mappedCells.insert(slotMapping.LUTs[
i][0][k]);
2294 mappedCells.insert(slotMapping.LUTs[
i][1][k]);
2303 for (
int i = 0;
i < 2;
i++)
2305 for (
int k = 0; k < 4; k++)
2307 if (!slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
2309 for (
auto tmpLUT : singleLUTs)
2311 if (mappedLUTs.find(tmpLUT) == mappedLUTs.end())
2313 assert(mappedLUTs.find(tmpLUT) == mappedLUTs.end());
2314 slotMapping.LUTs[
i][0][k] = tmpLUT;
2315 mappedLUTs.insert(tmpLUT);
2316 mappedCells.insert(tmpLUT);
2324 assert(determinedClusterInSite->getSingleLUTs().size() + determinedClusterInSite->getPairedLUTs().size() <= 8);
2326 for (
int i0 = 0; i0 < 2; i0++)
2328 for (
int k0 = 0; k0 < 4; k0++)
2330 if (!
isLUT6(slotMapping.LUTs[i0][0][k0]) && !
isLUT6(slotMapping.LUTs[i0][1][k0]))
2332 float oriDirectInternalRoute_slack =
2333 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][0][k0]) +
2334 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][1][k0]);
2337 float newDirectInternalRoute_slack =
2338 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][1][k0]) +
2339 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][0][k0]);
2341 if (oriDirectInternalRoute_slack < newDirectInternalRoute_slack)
2344 tmpLUT = slotMapping.LUTs[i0][0][k0];
2345 slotMapping.LUTs[i0][0][k0] = slotMapping.LUTs[i0][1][k0];
2346 slotMapping.LUTs[i0][1][k0] = tmpLUT;
2353 int LUTSwapOptions[4][4] = {{0, 1, 0, 1}, {1, 0, 0, 1}, {1, 0, 1, 0}, {0, 1, 1, 0}};
2355 for (
int i0 = 0; i0 < 2; i0++)
2357 for (
int k0 = 0; k0 < 4; k0++)
2359 for (
int i1 = 0; i1 < 2; i1++)
2361 for (
int k1 = 0; k1 < 4; k1++)
2363 if (i0 == i1 && k0 == k1)
2367 if ((isMuxMacro(slotMapping.LUTs[i0][0][k0]) || isMuxMacro(slotMapping.FFs[i0][0][k0]) ||
2368 isMuxMacro(slotMapping.LUTs[i0][1][k0]) || isMuxMacro(slotMapping.FFs[i0][1][k0]) ||
2369 isMuxMacro(slotMapping.LUTs[i1][0][k1]) || isMuxMacro(slotMapping.FFs[i1][0][k1]) ||
2370 isMuxMacro(slotMapping.LUTs[i1][1][k1]) || isMuxMacro(slotMapping.FFs[i1][1][k1])))
2372 float oriDirectInternalRoute_slack =
2373 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][0][k0], slotMapping.FFs[i0][0][k0]) +
2374 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][1][k0], slotMapping.FFs[i0][1][k0]) +
2375 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][0][k1], slotMapping.FFs[i1][0][k1]) +
2376 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][1][k1], slotMapping.FFs[i1][1][k1]);
2378 float optDirectInternalRoute_slack = -100000000;
2379 int optimalOption = -1;
2380 for (
int optionId = 0; optionId < 4; optionId++)
2383 float newDirectInternalRoute_slack =
2384 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][LUTSwapOptions[optionId][0]][k1],
2385 slotMapping.FFs[i0][0][k0]) +
2386 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1],
2387 slotMapping.FFs[i0][1][k0]) +
2388 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][LUTSwapOptions[optionId][2]][k0],
2389 slotMapping.FFs[i1][0][k1]) +
2390 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[i0][LUTSwapOptions[optionId][3]][k0],
2391 slotMapping.FFs[i1][1][k1]);
2392 if (
isLUT6(slotMapping.LUTs[i1][LUTSwapOptions[optionId][1]][k1]) ||
2394 .LUTs[i0][LUTSwapOptions[optionId][3]][k0]))
2396 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
2398 optimalOption = optionId;
2399 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
2403 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
2409 slotMapping.LUTs[i0][0][k0] = tmpLUT0;
2410 assert(!
isLUT6(tmpLUT1));
2411 slotMapping.LUTs[i0][1][k0] = tmpLUT1;
2412 slotMapping.LUTs[i1][0][k1] = tmpLUT2;
2413 assert(!
isLUT6(tmpLUT3));
2414 slotMapping.LUTs[i1][1][k1] = tmpLUT3;
2422 for (
int i = 0;
i < 2;
i++)
2424 for (
int j = 0; j < 2; j++)
2429 float oriDirectInternalRoute_slack =
2430 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0], slotMapping.FFs[
i][j][0]) +
2431 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1], slotMapping.FFs[
i][j][1]) +
2432 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2], slotMapping.FFs[
i][j][2]) +
2433 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3], slotMapping.FFs[
i][j][3]);
2434 float optDirectInternalRoute_slack = -100000000;
2435 int optimalOption = -1;
2436 for (
int optionId = 0; optionId < 24; optionId++)
2438 bool moveFFofMux =
false;
2439 for (
int checkFFId = 0; checkFFId < 4; checkFFId++)
2441 if (FFSwapOption[optionId][checkFFId] != checkFFId)
2443 if (isMuxMacro(slotMapping.FFs[
i][j][checkFFId]))
2452 float newDirectInternalRoute_slack =
2453 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][0],
2454 slotMapping.FFs[
i][j][FFSwapOption[optionId][0]]) +
2455 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][1],
2456 slotMapping.FFs[
i][j][FFSwapOption[optionId][1]]) +
2457 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][2],
2458 slotMapping.FFs[
i][j][FFSwapOption[optionId][2]]) +
2459 checkDirectLUTFFConnect_slack(FF2LUT, slotMapping.LUTs[
i][j][3],
2460 slotMapping.FFs[
i][j][FFSwapOption[optionId][3]]);
2461 if (newDirectInternalRoute_slack > optDirectInternalRoute_slack)
2463 optimalOption = optionId;
2464 optDirectInternalRoute_slack = newDirectInternalRoute_slack;
2467 if (oriDirectInternalRoute_slack < optDirectInternalRoute_slack)
2473 slotMapping.FFs[
i][j][0] = tmpFF0;
2474 slotMapping.FFs[
i][j][1] = tmpFF1;
2475 slotMapping.FFs[
i][j][2] = tmpFF2;
2476 slotMapping.FFs[
i][j][3] = tmpFF3;
2482 if (determinedClusterInSite)
2485 unsigned int FFCnt = 0;
2486 for (
auto &CSFF : determinedClusterInSite->getFFControlSets())
2487 FFCnt += CSFF.getFFs().size();
2489 if (FFCnt != mappedFFs.size())
2491 std::cout <<
"FFCnt: " << FFCnt <<
" mappedFFs.size():" << mappedFFs.size() <<
"\n";
2492 determinedClusterInSite->printMyself();
2493 for (
int i = 0;
i < 2;
i++)
2495 for (
int k = 0; k < 4; k++)
2497 for (
int j = 0; j < 2; j++)
2499 std::cout <<
"i,k,j:" <<
i <<
"," << k <<
"," << j <<
":\n";
2500 if (slotMapping.LUTs[
i][j][k])
2501 std::cout << slotMapping.LUTs[
i][j][k] <<
"\n";
2502 if (slotMapping.FFs[
i][j][k])
2503 std::cout << slotMapping.FFs[
i][j][k] <<
"\n";
2507 assert(FFCnt == mappedFFs.size());
2511 std::map<DesignInfo::DesignCell *, std::array<int, 3>> cell2slot;
2512 for (
int i = 0;
i < 2;
i++)
2514 for (
int j = 0; j < 2; j++)
2516 for (
int k = 0; k < 4; k++)
2518 if (slotMapping.FFs[
i][j][k])
2520 cell2slot[slotMapping.FFs[
i][j][k]] = std::array<int, 3>({
i, j, k});
2522 if (slotMapping.LUTs[
i][j][k])
2524 cell2slot[slotMapping.LUTs[
i][j][k]] = std::array<int, 3>({
i, j, k});
2530 for (
int i0 = 0; i0 < 2; i0++)
2532 for (
int j0 = 0; j0 < 2; j0++)
2534 for (
int k0 = 0; k0 < 4; k0++)
2536 if (!slotMapping.LUTs[i0][j0][k0])
2538 if (LUT2FF.find(slotMapping.LUTs[i0][j0][k0]) != LUT2FF.end())
2540 auto targetFF = LUT2FF[slotMapping.LUTs[i0][j0][k0]];
2541 if (slotMapping.FFs[i0][j0][k0] ==
nullptr)
2543 int halfCLBId0 = i0 * 2 + j0;
2545 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId0]];
2546 int i1 = cell2slot[targetFF].at(0);
2547 int j1 = cell2slot[targetFF].at(1);
2548 int k1 = cell2slot[targetFF].at(2);
2549 int halfCLBId1 = i1 * 2 + j1;
2551 determinedClusterInSite->getFFControlSets()[FFSwapOption[FFControlSetOrderId][halfCLBId1]];
2552 if (CSFF0.compatibleWith(CSFF1.getCSId()))
2554 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
2555 FFSwapOption[FFControlSetOrderId][halfCLBId0])
2556 determinedClusterInSite->moveFFFromCS1ToCS0(
2557 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
2558 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
2559 slotMapping.FFs[i0][j0][k0] = targetFF;
2560 slotMapping.FFs[i1][j1][k1] =
nullptr;
2561 cell2slot[targetFF] = std::array<int, 3>({i0, j0, k0});
2570 for (
int i0 = 0; i0 < 2; i0++)
2572 for (
int j0 = 0; j0 < 2; j0++)
2574 for (
int k0 = 0; k0 < 4; k0++)
2576 if (!slotMapping.LUTs[i0][j0][k0])
2578 auto targetLUT = slotMapping.LUTs[i0][j0][k0];
2579 if (slotMapping.LUTs[i0][1 - j0][k0])
2581 if (LUT2FF.find(targetLUT) != LUT2FF.end())
2583 auto targetFF = LUT2FF[targetLUT];
2584 int i1 = cell2slot[targetFF].at(0);
2585 int j1 = cell2slot[targetFF].at(1);
2586 int k1 = cell2slot[targetFF].at(2);
2587 int halfCLBId1 = i1 * 2 + j1;
2589 if (i0 != i1 || j0 != j1 || k0 != k1)
2591 bool optimized =
false;
2592 for (
int ii = 0; ii < 2 && !optimized; ii++)
2594 for (
int jj = 0; jj < 2 && !optimized; jj++)
2596 bool compatible =
true;
2597 if (targetLUT->isLUT6() && jj == 1)
2599 int halfCLBId0 = ii * 2 + jj;
2600 for (
int kk = 0; kk < 4; kk++)
2602 if (slotMapping.FFs[ii][jj][kk])
2604 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo())
2606 if (slotMapping.FFs[ii][jj][kk]->getControlSetInfo()->getId() !=
2607 targetFF->getControlSetInfo()->getId())
2614 for (
int kk = 0; kk < 4; kk++)
2616 if (slotMapping.FFs[ii][1 - jj][kk])
2618 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo())
2620 if (slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getCLK() !=
2621 targetFF->getControlSetInfo()->getCLK() ||
2622 slotMapping.FFs[ii][1 - jj][kk]->getControlSetInfo()->getSR() !=
2623 targetFF->getControlSetInfo()->getSR())
2633 for (
int kk = 0; kk < 4; kk++)
2635 if (!slotMapping.LUTs[ii][jj][kk] && !slotMapping.FFs[ii][jj][kk])
2639 if (targetLUT->isLUT6())
2641 if (slotMapping.LUTs[ii][1 - jj][kk])
2646 if (slotMapping.LUTs[ii][1 - jj][kk] &&
2647 slotMapping.LUTs[ii][1 - jj][kk]->isLUT6())
2649 if (slotMapping.LUTs[ii][1 - jj][kk])
2652 getPairPinNum(targetLUT, slotMapping.LUTs[ii][1 - jj][kk]);
2658 slotMapping.LUTs[i0][j0][k0] =
nullptr;
2659 slotMapping.FFs[i1][j1][k1] =
nullptr;
2660 assert(!slotMapping.LUTs[ii][jj][kk]);
2661 assert(!slotMapping.FFs[ii][jj][kk]);
2662 slotMapping.LUTs[ii][jj][kk] = targetLUT;
2663 slotMapping.FFs[ii][jj][kk] = targetFF;
2665 if (FFSwapOption[FFControlSetOrderId][halfCLBId1] !=
2666 FFSwapOption[FFControlSetOrderId][halfCLBId0])
2667 determinedClusterInSite->moveFFFromCS1ToCS0(
2668 targetFF, FFSwapOption[FFControlSetOrderId][halfCLBId1],
2669 FFSwapOption[FFControlSetOrderId][halfCLBId0]);
2670 cell2slot[targetFF] = std::array<int, 3>({ii, jj, kk});
2671 cell2slot[targetLUT] = std::array<int, 3>({ii, jj, kk});
2687 float directConnectCnt = 0;
2688 for (
int i = 0;
i < 2;
i++)
2690 for (
int j = 0; j < 2; j++)
2692 for (
int k = 0; k < 4; k++)
2694 if (checkDirectLUTFFConnect(FF2LUT, slotMapping.LUTs[
i][j][k], slotMapping.FFs[
i][j][k]))
2696 auto srcCell = slotMapping.LUTs[
i][j][k];
2697 unsigned int srcCellId = srcCell->getCellId();
2698 auto srcNode = timingNodes[srcCellId];
2700 if (srcNode->getForwardLevel() < 0)
2703 (srcNode->getLatestInputArrival() - srcNode->getRequiredArrivalTime()) / clockPeriod + 20;
2704 directConnectCnt += slack;
2709 if (directConnectCnt > best_DirectConnect)
2711 best_SlotMapping = slotMapping;
2712 best_mappedCells = mappedCells;
2713 best_mappedLUTs = mappedLUTs;
2714 best_mappedFFs = mappedFFs;
2715 best_DirectConnect = directConnectCnt;
2721 assert(!checkIsPrePackedSite() && !checkIsMuxSite());
2722 assert(fixedPairedLUTs.size() == 0 && conflictLUTs.size() == 0);
2723 assert(determinedClusterInSite->getSingleLUTs().size() + determinedClusterInSite->getPairedLUTs().size() <= 8);
2725 for (
int i = 0;
i < 24;
i++)
2726 finalMapToSlotsForCommonLUTFFInSite(
i);
2728 slotMapping = best_SlotMapping;
2729 mappedCells = best_mappedCells;
2730 mappedLUTs = best_mappedLUTs;
2731 mappedFFs = best_mappedFFs;
2732 moveLUTToLUT6Slot();
2737 if (!determinedClusterInSite)
2740 for (
int i = 0;
i < 2;
i++)
2742 for (
int k = 0; k < 4; k++)
2744 if (!slotMapping.LUTs[
i][0][k] && slotMapping.LUTs[
i][1][k])
2746 if (determinedClusterInSite->getSingleLUTs().find(slotMapping.LUTs[
i][1][k]) !=
2747 determinedClusterInSite->getSingleLUTs().end())
2749 slotMapping.LUTs[
i][0][k] = slotMapping.LUTs[
i][1][k];
2750 slotMapping.LUTs[
i][1][k] =
nullptr;
2759 LUTRAMMacro = _LUTRAMMacro;
2760 isLUTRAMSite =
true;
2767 CARRYChain = _CARRYChain;
2768 CARRYChainSiteOffset = siteOffset;
2770 mappedCells.clear();
2774 float siteHeight = 1.0;
2775 float lowerBound = siteHeight * CARRYChainSiteOffset - (1e-2);
2776 float uppwerBound = siteHeight * CARRYChainSiteOffset + (1e-2);
2777 for (
auto curCell : CARRYChain->getCells())
2780 if (offsetY > lowerBound && offsetY < uppwerBound)
2782 if (curCell->isCarry())
2784 carryCell = curCell;
2785 auto curCarry = curCell;
2786 slotMapping.Carry = curCarry;
2787 mappedCells.insert(curCarry);
2790 if (pinBeDriven->isUnconnected())
2792 if (!pinBeDriven->getDriverPin())
2795 if (pinBeDriven->getRefPinName().find(
"S[") == 0)
2799 pinBeDriven->getDriverPin()->getCell()->isLUT())
2802 pinBeDriven->getRefPinName()[pinBeDriven->getRefPinName().find(
"[") + 1] -
'0';
2803 slotMapping.LUTs[SPinCellId / 4][0][SPinCellId % 4] =
2804 pinBeDriven->getDriverPin()->getCell();
2805 mappedCells.insert(pinBeDriven->getDriverPin()->getCell());
2806 mappedLUTs.insert(pinBeDriven->getDriverPin()->getCell());
2813 else if (pinBeDriven->getRefPinName().find(
"DI[") == 0)
2817 pinBeDriven->getDriverPin()->getCell()->isLUT())
2820 pinBeDriven->getRefPinName()[pinBeDriven->getRefPinName().find(
"[") + 1] -
'0';
2821 slotMapping.LUTs[DIPinCellId / 4][1][DIPinCellId % 4] =
2822 pinBeDriven->getDriverPin()->getCell();
2823 mappedCells.insert(pinBeDriven->getDriverPin()->getCell());
2824 mappedLUTs.insert(pinBeDriven->getDriverPin()->getCell());
2832 std::vector<std::string> checkFFRefPins{
"O[",
"CO["};
2835 if (driverPin->isUnconnected())
2838 bool findMatchedInputPin =
false;
2839 for (
auto patternPin : checkFFRefPins)
2841 if (driverPin->getRefPinName().find(patternPin) == 0)
2843 findMatchedInputPin =
true;
2848 if (findMatchedInputPin)
2854 if (pinBeDriven->getCell()->isFF())
2857 if (pinBeDriven->getRefPinName().find(
"D") != std::string::npos)
2860 theFF = pinBeDriven->getCell();
2864 if (FFcnt == 1 && theFF)
2867 driverPin->getRefPinName()[driverPin->getRefPinName().find(
"[") + 1] -
'0';
2868 if (driverPin->getRefPinName().find(
"CO[") != std::string::npos)
2870 assert(!slotMapping.FFs[FFPinCellId / 4][1][FFPinCellId % 4]);
2871 slotMapping.FFs[FFPinCellId / 4][1][FFPinCellId % 4] = theFF;
2872 mappedCells.insert(theFF);
2873 mappedFFs.insert(theFF);
2878 else if (driverPin->getRefPinName().find(
"O[") != std::string::npos)
2880 assert(!slotMapping.FFs[FFPinCellId / 4][0][FFPinCellId % 4]);
2881 slotMapping.FFs[FFPinCellId / 4][0][FFPinCellId % 4] = theFF;
2882 mappedCells.insert(theFF);
2883 mappedFFs.insert(theFF);
2893 if (curCell->isVirtualCell())
2895 assert(mappedCells.find(curCell) == mappedCells.end());
2896 if (curCell->isLUT())
2898 assert(curCell->isLUT6());
2899 assert(curCell->getName().find(
'(') != std::string::npos);
2900 int slotId = curCell->getName()[curCell->getName().find(
'(') - 1] -
'0';
2901 assert(slotId < 8 && slotId >= 0);
2902 assert(!slotMapping.LUTs[slotId / 4][0][slotId % 4]);
2903 mappedCells.insert(curCell);
2904 mappedLUTs.insert(curCell);
2905 slotMapping.LUTs[slotId / 4][0][slotId % 4] = curCell;
2909 assert(curCell->isFF());
2910 assert(curCell->getName().find(
'(') != std::string::npos);
2911 int strOffset = curCell->getName().find(
'(');
2912 int slotId = curCell->getName()[strOffset - 1] -
'0';
2913 assert(curCell->getName()[strOffset - 2] ==
'2' || curCell->getName()[strOffset - 2] ==
'F');
2914 int oddCLB = curCell->getName()[strOffset - 2] ==
'2';
2915 assert(slotId < 8 && slotId >= 0);
2916 assert(!slotMapping.FFs[slotId / 4][oddCLB][slotId % 4]);
2917 mappedCells.insert(curCell);
2918 mappedFFs.insert(curCell);
2919 slotMapping.FFs[slotId / 4][oddCLB][slotId % 4] = curCell;
2925 fixedPairedLUTs.clear();
2926 conflictLUTs.clear();
2927 fixedLUTsInPairs.clear();
2929 for (
int i = 0;
i < 2;
i++)
2930 for (
int k = 0; k < 4; k++)
2932 if (slotMapping.LUTs[
i][0][k] && !slotMapping.LUTs[
i][1][k])
2934 conflictLUTs.insert(slotMapping.LUTs[
i][0][k]);
2936 else if (slotMapping.LUTs[
i][1][k] && !slotMapping.LUTs[
i][0][k])
2938 conflictLUTs.insert(slotMapping.LUTs[
i][1][k]);
2940 else if (slotMapping.LUTs[
i][1][k] && slotMapping.LUTs[
i][0][k])
2942 if (slotMapping.LUTs[
i][1][k]->getCellId() < slotMapping.LUTs[
i][0][k]->getCellId())
2944 fixedPairedLUTs.emplace(slotMapping.LUTs[
i][1][k], slotMapping.LUTs[
i][0][k]);
2945 fixedLUTsInPairs.insert(slotMapping.LUTs[
i][1][k]);
2946 fixedLUTsInPairs.insert(slotMapping.LUTs[
i][0][k]);
2950 fixedPairedLUTs.emplace(slotMapping.LUTs[
i][0][k], slotMapping.LUTs[
i][1][k]);
2951 fixedLUTsInPairs.insert(slotMapping.LUTs[
i][1][k]);
2952 fixedLUTsInPairs.insert(slotMapping.LUTs[
i][0][k]);