42#define FPGA_CUTS_MAX_COMPUTE 2000
45#define FPGA_CUTS_MAX_USE 1000
48static int s_HashPrimes[10] = { 109, 499, 557, 619, 631, 709, 797, 881, 907, 991 };
50static int bit_count[256] = {
51 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,
52 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
53 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
54 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
55 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,
56 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
57 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,
58 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8
61#define FPGA_COUNT_ONES(u) (bit_count[(u)&255]+bit_count[((u)>>8)&255]+bit_count[((u)>>16)&255]+bit_count[(u)>>24])
78static unsigned Fpga_CutTableHash(
Fpga_Node_t * ppNodes[],
int nNodes );
90#define Fpga_ListForEachCut( pList, pCut ) \
94#define Fpga_ListForEachCutSafe( pList, pCut, pCut2 ) \
96 pCut2 = pCut? pCut->pNext: NULL; \
99 pCut2 = pCut? pCut->pNext: NULL )
135 int nCuts, nNodes, i;
136 clock_t clk = clock();
139 assert(
p->nVarsMax > 1 &&
p->nVarsMax < 11 );
143 nNodes =
p->vAnds->nSize;
145 pTable = Fpga_CutTableStart(
p );
146 for ( i = 0; i < nNodes; i++ )
148 Extra_ProgressBarUpdate( pProgress, i,
"Cuts ..." );
149 pNode =
p->vAnds->pArray[i];
152 Fpga_CutCompute(
p, pTable, pNode );
155 Fpga_CutTableStop( pTable );
161 printf(
"Nodes = %6d. Total %d-cuts = %d. Cuts per node = %.1f. ",
162 p->nNodes,
p->nVarsMax, nCuts, ((
float)nCuts)/
p->nNodes );
163 ABC_PRT(
"Time", clock() - clk );
187 for ( i = 0; i <
p->nInputs; i++ )
192 pCut->
uSign = (1 << (i%31));
193 p->pInputs[i]->pCuts = pCut;
194 p->pInputs[i]->pCutBest = pCut;
228 pList = Fpga_CutMergeLists(
p, pTable, pList1, pList2,
234 if ( pNode->
pRepr == NULL )
236 for ( pTemp = pNode->
pNextE; pTemp; pTemp = pTemp->
pNextE )
239 pList = Fpga_CutUnionLists( pList, pTemp->
pCuts );
241 pList = Fpga_CutSortCuts(
p, pTable, pList );
248 pCut->
uSign = (1 << (pNode->
Num%31));
309 pPrev = pNode->
pCuts;
313 for ( pTemp = pNode->
pCuts->
pNext; pTemp != pCut; pTemp = pTemp->
pNext )
316 for ( i = 0; i < pTemp->
nLeaves; i++ )
318 for ( k = 0; k < pCut->
nLeaves; k++ )
359 Fpga_Cut_t * pCut, * pPrev, * pTemp1, * pTemp2;
360 int nNodes, Counter, i;
361 Fpga_Cut_t ** ppArray1, ** ppArray2, ** ppArray3;
362 int nCuts1, nCuts2, nCuts3, k, fComp3;
364 ppArray1 = pTable->pCuts1;
365 ppArray2 = pTable->pCuts2;
366 nCuts1 = Fpga_CutList2Array( ppArray1, pList1 );
367 nCuts2 = Fpga_CutList2Array( ppArray2, pList2 );
373 if ( nCuts1 > nCuts2 )
390 Fpga_CutTableRestart( pTable );
395 for ( i = 0; i < nCuts1; i++ )
397 for ( k = 0; k <= i; k++ )
399 pTemp1 = ppArray1[i];
400 pTemp2 = ppArray2[k];
411 nNodes = Fpga_CutMergeTwo( pTemp1, pTemp2, ppNodes,
p->nVarsMax );
415 pCut = Fpga_CutTableConsider(
p, pTable, ppNodes, nNodes );
425 pLists[(int)pCut->
nLeaves] = pCut;
431 for ( k = 0; k < i; k++ )
433 pTemp1 = ppArray1[k];
434 pTemp2 = ppArray2[i];
446 nNodes = Fpga_CutMergeTwo( pTemp1, pTemp2, ppNodes,
p->nVarsMax );
450 pCut = Fpga_CutTableConsider(
p, pTable, ppNodes, nNodes );
460 pLists[(int)pCut->
nLeaves] = pCut;
468 for ( i = nCuts1; i < nCuts2; i++ )
469 for ( k = 0; k < nCuts1; k++ )
471 pTemp1 = ppArray1[k];
472 pTemp2 = ppArray2[i];
486 nNodes = Fpga_CutMergeTwo( pTemp1, pTemp2, ppNodes,
p->nVarsMax );
490 pCut = Fpga_CutTableConsider(
p, pTable, ppNodes, nNodes );
500 pLists[(int)pCut->
nLeaves] = pCut;
509 ppListNew = &pListNew;
510 for ( i = 1; i <=
p->nVarsMax; i++ )
512 if ( pLists[i] == NULL )
515 for ( pPrev = pLists[i], pCut = pPrev->
pNext; pCut;
516 pPrev = pCut, pCut = pCut->
pNext );
518 *ppListNew = pLists[i];
519 ppListNew = &pPrev->
pNext;
523 pListNew = Fpga_CutSortCuts(
p, pTable, pListNew );
544 Fpga_Cut_t * pCut, * pPrev, * pTemp1, * pTemp2;
545 int nNodes, Counter, i;
548 Fpga_CutTableRestart( pTable );
551 for ( pTemp1 = pList1; pTemp1; pTemp1 = fPivot1? NULL: pTemp1->
pNext )
552 for ( pTemp2 = pList2; pTemp2; pTemp2 = fPivot2? NULL: pTemp2->
pNext )
555 nNodes = Fpga_CutMergeTwo( pTemp1, pTemp2, ppNodes,
p->nVarsMax );
559 pCut = Fpga_CutTableConsider(
p, pTable, ppNodes, nNodes );
567 pLists[(int)pCut->
nLeaves] = pCut;
576 ppListNew = &pListNew;
577 for ( i = 1; i <=
p->nVarsMax; i++ )
579 if ( pLists[i] == NULL )
582 for ( pPrev = pLists[i], pCut = pPrev->
pNext; pCut;
583 pPrev = pCut, pCut = pCut->
pNext );
585 *ppListNew = pLists[i];
586 ppListNew = &pPrev->
pNext;
590 pListNew = Fpga_CutSortCuts(
p, pTable, pListNew );
609 int nTotal, i, k, min, Counter;
615 if ( Counter > nNodesMax )
668 for ( i = 0; i < pCut2->
nLeaves; i++ )
671 for ( k = 0; k < pCut1->
nLeaves; k++ )
674 if ( k < pCut1->nLeaves )
677 if (
nTotal == nNodesMax )
684 for ( k = 0; k < pCut1->
nLeaves; k++ )
688 for ( i = 0; i <
nTotal - 1; i++ )
691 for ( k = i+1; k <
nTotal; k++ )
693 if ( ppNodes[k]->Num < ppNodes[min]->Num )
695 pNodeTemp = ppNodes[i];
696 ppNodes[i] = ppNodes[min];
697 ppNodes[min] = pNodeTemp;
724 pList2->
pNext = NULL;
745 for ( pTemp = pList; pTemp; pTemp = pTemp->
pNext )
747 for ( i = 0; i < nNodes; i++ )
748 if ( pTemp->
ppLeaves[i] != ppNodes[i] )
774 for ( i = 0; i < pMan->
nBins; i++ )
775 for ( pNode = pMan->
pBins[i]; pNode; pNode = pNode->
pNext )
776 for ( pCut = pNode->
pCuts; pCut; pCut = pCut->
pNext )
802 for ( i = 0; i < pMan->
nBins; i++ )
803 for ( pNode = pMan->
pBins[i]; pNode; pNode = pNode->
pNext )
804 for ( pCut = pNode->
pCuts; pCut; pCut = pCut->
pNext )
824 for ( i = 0; i < pMan->
nBins; i++ )
825 for ( pNode = pMan->
pBins[i]; pNode; pNode = pNode->
pNext )
826 for ( pCut = pNode->
pCuts; pCut; pCut = pCut->
pNext )
847 for ( Counter = 0, pTemp = pRoot->
pCuts; pTemp; pTemp = pTemp->
pNext, Counter++ )
849 printf(
"%2d : ", Counter + 1 );
850 Fpga_CutPrint_( pMan, pTemp, pRoot );
869 for ( Counter = 0, pTemp = pRoot->
pCuts; pTemp; pTemp = pTemp->
pNext, Counter++ )
871 printf(
"%2d : ", Counter + 1 );
872 Fpga_CutPrint_( pMan, pTemp, pRoot );
890 printf(
"(%3d) {", pRoot->
Num );
891 for ( i = 0; i < pMan->
nVarsMax; i++ )
963unsigned Fpga_CutTableHash(
Fpga_Node_t * ppNodes[],
int nNodes )
968 for ( i = 0; i < nNodes; i++ )
969 uRes += s_HashPrimes[i] * ppNodes[i]->Num;
991 Key = Fpga_CutTableHash(ppNodes, nNodes) %
p->nBins;
992 for ( b = Key;
p->pBins[b]; b = (b+1) %
p->nBins )
997 for ( i = 0; i < nNodes; i++ )
998 if ( pCut->
ppLeaves[i] != ppNodes[i] )
1023 Place = Fpga_CutTableLookup(
p, ppNodes, nNodes );
1031 for ( i = 0; i < nNodes; i++ )
1038 assert(
p->pBins[Place] == NULL );
1039 p->pBins[Place] = pCut;
1041 p->pCuts[
p->nCuts++ ] = Place;
1060 for ( i = 0; i <
p->nCuts; i++ )
1063 p->pBins[
p->pCuts[i] ] = NULL;
1083 if ( (*pC1)->nLeaves < (*pC2)->nLeaves )
1085 if ( (*pC1)->nLeaves > (*pC2)->nLeaves )
1112 nCuts = Fpga_CutList2Array(
p->pCuts1, pList );
1115 qsort( (
void *)
p->pCuts1, (
size_t)nCuts,
sizeof(
void *),
1116 (int (*)(
const void *,
const void *)) Fpga_CutSortCutsCompare );
1127 pListNew = Fpga_CutArray2List(
p->pCuts1, nCuts );
1145 for ( i = 0; pList; pList = pList->
pNext, i++ )
1166 ppListNew = &pListNew;
1167 for ( i = 0; i < nCuts; i++ )
1170 *ppListNew = pArray[i];
1171 ppListNew = &pArray[i]->
pNext;
#define ABC_ALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int nTotal
DECLARATIONS ///.
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
void Fpga_CutFree(Fpga_Man_t *p, Fpga_Cut_t *pCut)
#define FPGA_CUTS_MAX_USE
Fpga_Cut_t * Fpga_CutMergeLists2(Fpga_Man_t *p, Fpga_CutTable_t *pTable, Fpga_Cut_t *pList1, Fpga_Cut_t *pList2, int fComp1, int fComp2, int fPivot1, int fPivot2)
#define Fpga_ListForEachCutSafe(pList, pCut, pCut2)
typedefABC_NAMESPACE_IMPL_START struct Fpga_CutTableStrutct_t Fpga_CutTable_t
DECLARATIONS ///.
Fpga_Cut_t * Fpga_CutAlloc(Fpga_Man_t *p)
DECLARATIONS ///.
#define FPGA_COUNT_ONES(u)
void Fpga_MappingCreatePiCuts(Fpga_Man_t *p)
#define FPGA_CUTS_MAX_COMPUTE
void Fpga_CutsCleanSign(Fpga_Man_t *pMan)
int Fpga_CutCountAll(Fpga_Man_t *pMan)
#define Fpga_ListForEachCut(pList, pCut)
void Fpga_CutsCleanRoot(Fpga_Man_t *pMan)
void Fpga_MappingCuts(Fpga_Man_t *p)
FUNCTION DEFINITIONS ///.
#define Fpga_NodeReadRef(p)
#define Fpga_CutNotCond(p, c)
#define FPGA_MAX_LEAVES
INCLUDES ///.
struct Fpga_NodeStruct_t_ Fpga_Node_t
struct Fpga_ManStruct_t_ Fpga_Man_t
STRUCTURE DEFINITIONS ///.
int Fpga_NodeComparePhase(Fpga_Node_t *p1, Fpga_Node_t *p2)
struct Fpga_CutStruct_t_ Fpga_Cut_t
#define Fpga_IsComplement(p)
GLOBAL VARIABLES ///.
int Fpga_NodeIsAnd(Fpga_Node_t *p)
Fpga_Node_t * ppLeaves[FPGA_MAX_LEAVES+1]