ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
lpkCore.c
Go to the documentation of this file.
1
20
21#include "lpkInt.h"
22#include "bool/kit/cloud.h"
23#include "base/main/main.h"
24
26
27
31
35
47Abc_Ntk_t * Abc_NtkDecFromTruth( word * pTruth, int nVars, int nLutSize )
48{
49 extern Abc_Ntk_t * Abc_NtkLutmin( Abc_Ntk_t * pNtk, int nLutSize, int fReorder, int fVerbose );
50 Vec_Int_t * vCover = Vec_IntAlloc( 1 << 16 );
52 char * pSopCover = Abc_SopCreateFromTruthIsop( (Mem_Flex_t *)pTemp->pManFunc, nVars, pTruth, vCover );
53 Abc_Ntk_t * pNtk = Abc_NtkCreateWithNode( pSopCover );
54 Abc_Ntk_t * pNew = Abc_NtkLutmin( pNtk, nLutSize, 1, 0 );
55 Abc_NtkDelete( pTemp );
56 Abc_NtkDelete( pNtk );
57 Vec_IntFree( vCover );
58 if ( !Abc_NtkToAig(pNew) )
59 {
60 Abc_NtkDelete( pNew );
61 fprintf( stdout, "Converting to AIG has failed.\n" );
62 return NULL;
63 }
64 assert( Abc_NtkHasAig(pNew) );
65 return pNew;
66}
67Abc_Obj_t * Abc_NtkLutMinDecompose( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, word * pTruth, int nLutSize, int Required )
68{
69 Abc_Obj_t * pObj = NULL, * pFanin; int i, k;
70 Abc_Ntk_t * pNew = Abc_NtkDecFromTruth( pTruth, Vec_PtrSize(vLeaves), nLutSize );
71 Vec_Ptr_t * vNodes = Abc_NtkDfs( pNew, 0 );
72 assert( Abc_NtkHasAig(pNtk) );
73 // levels
74 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
75 Abc_NtkCi( pNew, i )->Level = pObj->Level;
76 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
77 {
78 pObj->Level = 0;
79 Abc_ObjForEachFanin( pObj, pFanin, k )
80 if ( pObj->Level < pFanin->Level )
81 pObj->Level = pFanin->Level;
82 pObj->Level++;
83 }
84 if ( (int)pObj->Level > Required )
85 {
86 Vec_PtrFree( vNodes );
87 Abc_NtkDelete( pNew );
88 return NULL;
89 }
90 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
91 Abc_NtkCi( pNew, i )->pCopy = pObj;
92 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
93 {
94 Abc_NtkDupObj( pNtk, pObj, 0 );
95 pObj->pCopy->Level = 0;
96 Abc_ObjForEachFanin( pObj, pFanin, k )
97 {
98 Abc_ObjAddFanin( pObj->pCopy, pFanin->pCopy );
99 if ( pObj->pCopy->Level < pFanin->pCopy->Level )
100 pObj->pCopy->Level = pFanin->pCopy->Level;
101 }
102 pObj->pCopy->Level++;
103 }
104 //printf( "Decomposed %d-input function, resulting in %d nodes.\n", Vec_PtrSize(vLeaves), Vec_PtrSize(vNodes) );
105 pObj = pObj->pCopy;
106 Vec_PtrFree( vNodes );
107 Abc_NtkDelete( pNew );
108 return pObj;
109}
110
111
124{
125 If_Par_t * pPars;
126 assert( p->pIfMan == NULL );
127 // set defaults
128 pPars = ABC_ALLOC( If_Par_t, 1 );
129 memset( pPars, 0, sizeof(If_Par_t) );
130 // user-controlable paramters
131 pPars->nLutSize = p->pPars->nLutSize;
132 pPars->nCutsMax = 16;
133 pPars->nFlowIters = 0; // 1
134 pPars->nAreaIters = 0; // 1
135 pPars->DelayTarget = -1;
136 pPars->Epsilon = (float)0.005;
137 pPars->fPreprocess = 0;
138 pPars->fArea = 1;
139 pPars->fFancy = 0;
140 pPars->fExpRed = 0; //
141 pPars->fLatchPaths = 0;
142 pPars->fVerbose = 0;
143 // internal parameters
144 pPars->fTruth = 1;
145 pPars->fUsePerm = 0;
146 pPars->nLatchesCi = 0;
147 pPars->nLatchesCo = 0;
148 pPars->pLutLib = NULL; // Abc_FrameReadLibLut();
149 pPars->pTimesArr = NULL;
150 pPars->pTimesArr = NULL;
151 pPars->fUseBdds = 0;
152 pPars->fUseSops = 0;
153 pPars->fUseCnfs = 0;
154 pPars->fUseMv = 0;
155 // start the mapping manager and set its parameters
156 p->pIfMan = If_ManStart( pPars );
157 If_ManSetupSetAll( p->pIfMan, 1000 );
158 p->pIfMan->pPars->pTimesArr = ABC_ALLOC( float, 32 );
159}
160
172int Lpk_NodeHasChanged( Lpk_Man_t * p, int iNode )
173{
174 Vec_Ptr_t * vNodes;
175 Abc_Obj_t * pTemp, * pTemp2;
176 int i;
177 vNodes = Vec_VecEntry( p->vVisited, iNode );
178 if ( Vec_PtrSize(vNodes) == 0 )
179 return 1;
180 Vec_PtrForEachEntryDouble( Abc_Obj_t *, Abc_Obj_t *, vNodes, pTemp, pTemp2, i )
181 {
182 // check if the node has changed
183 pTemp = Abc_NtkObj( p->pNtk, (int)(ABC_PTRUINT_T)pTemp );
184 if ( pTemp == NULL )
185 return 1;
186 // check if the number of fanouts has changed
187// if ( Abc_ObjFanoutNum(pTemp) != (int)Vec_PtrEntry(vNodes, i+1) )
188// return 1;
189// i++;
190 }
191 return 0;
192}
193
206{
207 extern Abc_Obj_t * Abc_NodeFromIf_rec( Abc_Ntk_t * pNtkNew, If_Man_t * pIfMan, If_Obj_t * pIfObj, Vec_Int_t * vCover );
208 Kit_DsdObj_t * pRoot;
209 If_Obj_t * pDriver, * ppLeaves[16];
210 Abc_Obj_t * pLeaf, * pObjNew;
211 int nGain, i;
212 abctime clk;
213 int nNodesBef;
214// int nOldShared;
215
216 // check special cases
217 pRoot = Kit_DsdNtkRoot( pNtk );
218 if ( pRoot->Type == KIT_DSD_CONST1 )
219 {
220 if ( Abc_LitIsCompl(pNtk->Root) )
221 pObjNew = Abc_NtkCreateNodeConst0( p->pNtk );
222 else
223 pObjNew = Abc_NtkCreateNodeConst1( p->pNtk );
224 Abc_NtkUpdate( p->pObj, pObjNew, p->vLevels );
225 p->nGainTotal += pCut->nNodes - pCut->nNodesDup;
226 return 1;
227 }
228 if ( pRoot->Type == KIT_DSD_VAR )
229 {
230 pObjNew = Abc_NtkObj( p->pNtk, pCut->pLeaves[ Abc_Lit2Var(pRoot->pFans[0]) ] );
231 if ( Abc_LitIsCompl(pNtk->Root) ^ Abc_LitIsCompl(pRoot->pFans[0]) )
232 pObjNew = Abc_NtkCreateNodeInv( p->pNtk, pObjNew );
233 Abc_NtkUpdate( p->pObj, pObjNew, p->vLevels );
234 p->nGainTotal += pCut->nNodes - pCut->nNodesDup;
235 return 1;
236 }
237 assert( pRoot->Type == KIT_DSD_AND || pRoot->Type == KIT_DSD_XOR || pRoot->Type == KIT_DSD_PRIME );
238
239 // start the mapping manager
240 if ( p->pIfMan == NULL )
241 Lpk_IfManStart( p );
242
243 // prepare the mapping manager
244 If_ManRestart( p->pIfMan );
245 // create the PI variables
246 for ( i = 0; i < p->pPars->nVarsMax; i++ )
247 ppLeaves[i] = If_ManCreateCi( p->pIfMan );
248 // set the arrival times
249 Lpk_CutForEachLeaf( p->pNtk, pCut, pLeaf, i )
250 p->pIfMan->pPars->pTimesArr[i] = (float)pLeaf->Level;
251 // prepare the PI cuts
252 If_ManSetupCiCutSets( p->pIfMan );
253 // create the internal nodes
254 p->fCalledOnce = 0;
255 p->nCalledSRed = 0;
256 pDriver = Lpk_MapTree_rec( p, pNtk, ppLeaves, pNtk->Root, NULL );
257 if ( pDriver == NULL )
258 return 0;
259 // create the PO node
260 If_ManCreateCo( p->pIfMan, If_Regular(pDriver) );
261
262 // perform mapping
263 p->pIfMan->pPars->fAreaOnly = 1;
264clk = Abc_Clock();
265 If_ManPerformMappingComb( p->pIfMan );
266p->timeMap += Abc_Clock() - clk;
267
268 // compute the gain in area
269 nGain = pCut->nNodes - pCut->nNodesDup - (int)p->pIfMan->AreaGlo;
270 if ( p->pPars->fVeryVerbose )
271 printf( " Mffc = %2d. Mapped = %2d. Gain = %3d. Depth increase = %d. SReds = %d.\n",
272 pCut->nNodes - pCut->nNodesDup, (int)p->pIfMan->AreaGlo, nGain, (int)p->pIfMan->RequiredGlo - (int)p->pObj->Level, p->nCalledSRed );
273
274 // quit if there is no gain
275 if ( !(nGain > 0 || (p->pPars->fZeroCost && nGain == 0)) )
276 return 0;
277
278 // quit if depth increases too much
279 if ( (int)p->pIfMan->RequiredGlo > Abc_ObjRequiredLevel(p->pObj) )
280 return 0;
281
282 // perform replacement
283 p->nGainTotal += nGain;
284 p->nChanges++;
285 if ( p->nCalledSRed )
286 p->nBenefited++;
287
288 nNodesBef = Abc_NtkNodeNum(p->pNtk);
289 // prepare the mapping manager
290 If_ManCleanNodeCopy( p->pIfMan );
291 If_ManCleanCutData( p->pIfMan );
292 // set the PIs of the cut
293 Lpk_CutForEachLeaf( p->pNtk, pCut, pLeaf, i )
294 If_ObjSetCopy( If_ManCi(p->pIfMan, i), pLeaf );
295 // get the area of mapping
296 pObjNew = Abc_NodeFromIf_rec( p->pNtk, p->pIfMan, If_Regular(pDriver), p->vCover );
297 pObjNew->pData = Hop_NotCond( (Hop_Obj_t *)pObjNew->pData, If_IsComplement(pDriver) );
298 // perform replacement
299 Abc_NtkUpdate( p->pObj, pObjNew, p->vLevels );
300//printf( "%3d : %d-%d=%d(%d) \n", p->nChanges, nNodesBef, Abc_NtkNodeNum(p->pNtk), nNodesBef-Abc_NtkNodeNum(p->pNtk), nGain );
301 return 1;
302}
303
316{
317// static int Count = 0;
318 Kit_DsdNtk_t * pDsdNtk;
319 Lpk_Cut_t * pCut;
320 unsigned * pTruth;
321 int i, k, nSuppSize, nCutNodes, RetValue;
322 abctime clk;
323
324 // compute the cuts
325clk = Abc_Clock();
326 if ( !Lpk_NodeCuts( p ) )
327 {
328p->timeCuts += Abc_Clock() - clk;
329 return 0;
330 }
331p->timeCuts += Abc_Clock() - clk;
332
333//return 0;
334
335 if ( p->pPars->fVeryVerbose )
336 printf( "Node %5d : Mffc size = %5d. Cuts = %5d.\n", p->pObj->Id, p->nMffc, p->nEvals );
337 // try the good cuts
338 p->nCutsTotal += p->nCuts;
339 p->nCutsUseful += p->nEvals;
340 for ( i = 0; i < p->nEvals; i++ )
341 {
342 // get the cut
343 pCut = p->pCuts + p->pEvals[i];
344 if ( p->pPars->fFirst && i == 1 )
345 break;
346
347 // skip bad cuts
348// printf( "Mffc size = %d. ", Abc_NodeMffcLabel(p->pObj) );
349 for ( k = 0; k < (int)pCut->nLeaves; k++ )
350 Abc_NtkObj(p->pNtk, pCut->pLeaves[k])->vFanouts.nSize++;
351 nCutNodes = Abc_NodeMffcLabel(p->pObj, NULL);
352// printf( "Mffc with cut = %d. ", nCutNodes );
353 for ( k = 0; k < (int)pCut->nLeaves; k++ )
354 Abc_NtkObj(p->pNtk, pCut->pLeaves[k])->vFanouts.nSize--;
355// printf( "Mffc cut = %d. ", (int)pCut->nNodes - (int)pCut->nNodesDup );
356// printf( "\n" );
357 if ( nCutNodes != (int)pCut->nNodes - (int)pCut->nNodesDup )
358 continue;
359
360 // compute the truth table
361clk = Abc_Clock();
362 pTruth = Lpk_CutTruth( p, pCut, 0 );
363 nSuppSize = Extra_TruthSupportSize(pTruth, pCut->nLeaves);
364p->timeTruth += Abc_Clock() - clk;
365
366 pDsdNtk = Kit_DsdDecompose( pTruth, pCut->nLeaves );
367// Kit_DsdVerify( pDsdNtk, pTruth, pCut->nLeaves );
368 // skip 16-input non-DSD because ISOP will not work
369 if ( Kit_DsdNtkRoot(pDsdNtk)->nFans == 16 )
370 {
371 Kit_DsdNtkFree( pDsdNtk );
372 continue;
373 }
374
375 // if DSD has nodes that require splitting to fit them into LUTs
376 // we can skip those cuts that cannot lead to improvement
377 // (a full DSD network requires V = Nmin * (K-1) + 1 for improvement)
378 if ( Kit_DsdNonDsdSizeMax(pDsdNtk) > p->pPars->nLutSize &&
379 nSuppSize >= ((int)pCut->nNodes - (int)pCut->nNodesDup - 1) * (p->pPars->nLutSize - 1) + 1 )
380 {
381 Kit_DsdNtkFree( pDsdNtk );
382 continue;
383 }
384
385 if ( p->pPars->fVeryVerbose )
386 {
387// char * pFileName;
388 printf( " C%02d: L= %2d/%2d V= %2d/%d N= %d W= %4.2f ",
389 i, pCut->nLeaves, nSuppSize, pCut->nNodes, pCut->nNodesDup, pCut->nLuts, pCut->Weight );
390 Kit_DsdPrint( stdout, pDsdNtk );
391 Kit_DsdPrintFromTruth( pTruth, pCut->nLeaves );
392// pFileName = Kit_TruthDumpToFile( pTruth, pCut->nLeaves, Count++ );
393// printf( "Saved truth table in file \"%s\".\n", pFileName );
394 }
395
396 // update the network
397clk = Abc_Clock();
398 RetValue = Lpk_ExploreCut( p, pCut, pDsdNtk );
399p->timeEval += Abc_Clock() - clk;
400 Kit_DsdNtkFree( pDsdNtk );
401 if ( RetValue )
402 break;
403 }
404 return 1;
405}
406
407
419void Lpk_ComputeSupports( Lpk_Man_t * p, Lpk_Cut_t * pCut, unsigned * pTruth )
420{
421 unsigned * pTruthInv;
422 int RetValue1, RetValue2;
423 pTruthInv = Lpk_CutTruth( p, pCut, 1 );
424 RetValue1 = Kit_CreateCloudFromTruth( p->pDsdMan->dd, pTruth, pCut->nLeaves, p->vBddDir );
425 RetValue2 = Kit_CreateCloudFromTruth( p->pDsdMan->dd, pTruthInv, pCut->nLeaves, p->vBddInv );
426 if ( RetValue1 && RetValue2 && Vec_IntSize(p->vBddDir) > 1 && Vec_IntSize(p->vBddInv) > 1 )
427 Kit_TruthCofSupports( p->vBddDir, p->vBddInv, pCut->nLeaves, p->vMemory, p->puSupps );
428 else
429 p->puSupps[0] = p->puSupps[1] = 0;
430}
431
444{
445// static int Count = 0;
446 int NodeCounts[16] = { 0, 0, 0, 0, 1, 3, 6, 14, 26, 57, 106, 230, 425, 1000000, 1000000, 1000000 };
447 Abc_Obj_t * pObjNew, * pLeaf;
448 Lpk_Cut_t * pCut;
449 unsigned * pTruth;
450 int nNodesBef, nNodesAft, nCutNodes;
451 int i, k;
452 abctime clk;
453 int Required = Abc_ObjRequiredLevel(p->pObj);
454// CloudNode * pFun2;//, * pFun1;
455
456 // compute the cuts
457clk = Abc_Clock();
458 if ( !Lpk_NodeCuts( p ) )
459 {
460p->timeCuts += Abc_Clock() - clk;
461 return 0;
462 }
463p->timeCuts += Abc_Clock() - clk;
464
465 if ( p->pPars->fVeryVerbose )
466 printf( "Node %5d : Mffc size = %5d. Cuts = %5d. Level = %2d. Req = %2d.\n",
467 p->pObj->Id, p->nMffc, p->nEvals, p->pObj->Level, Required );
468 // try the good cuts
469 p->nCutsTotal += p->nCuts;
470 p->nCutsUseful += p->nEvals;
471 for ( i = 0; i < p->nEvals; i++ )
472 {
473 // get the cut
474 pCut = p->pCuts + p->pEvals[i];
475 if ( p->pPars->fFirst && i == 1 )
476 break;
477// if ( pCut->Weight < 1.05 )
478// continue;
479
480 // skip bad cuts
481// printf( "Mffc size = %d. ", Abc_NodeMffcLabel(p->pObj) );
482 for ( k = 0; k < (int)pCut->nLeaves; k++ )
483 Abc_NtkObj(p->pNtk, pCut->pLeaves[k])->vFanouts.nSize++;
484 nCutNodes = Abc_NodeMffcLabel(p->pObj, NULL);
485// printf( "Mffc with cut = %d. ", nCutNodes );
486 for ( k = 0; k < (int)pCut->nLeaves; k++ )
487 Abc_NtkObj(p->pNtk, pCut->pLeaves[k])->vFanouts.nSize--;
488// printf( "Mffc cut = %d. ", (int)pCut->nNodes - (int)pCut->nNodesDup );
489// printf( "\n" );
490 if ( nCutNodes != (int)pCut->nNodes - (int)pCut->nNodesDup )
491 continue;
492
493 // collect nodes into the array
494 Vec_PtrClear( p->vLeaves );
495 for ( k = 0; k < (int)pCut->nLeaves; k++ )
496 Vec_PtrPush( p->vLeaves, Abc_NtkObj(p->pNtk, pCut->pLeaves[k]) );
497
498 // compute the truth table
499clk = Abc_Clock();
500 pTruth = Lpk_CutTruth( p, pCut, 0 );
501p->timeTruth += Abc_Clock() - clk;
502clk = Abc_Clock();
503 Lpk_ComputeSupports( p, pCut, pTruth );
504p->timeSupps += Abc_Clock() - clk;
505//clk = Abc_Clock();
506// pFun1 = Lpk_CutTruthBdd( p, pCut );
507//p->timeTruth2 += Abc_Clock() - clk;
508/*
509clk = Abc_Clock();
510 Cloud_Restart( p->pDsdMan->dd );
511 pFun2 = Kit_TruthToCloud( p->pDsdMan->dd, pTruth, pCut->nLeaves );
512 RetValue = Kit_CreateCloud( p->pDsdMan->dd, pFun2, p->vBddNodes );
513p->timeTruth3 += Abc_Clock() - clk;
514*/
515// if ( pFun1 != pFun2 )
516// printf( "Truth tables do not agree!\n" );
517// else
518// printf( "Fine!\n" );
519
520 if ( p->pPars->fVeryVerbose )
521 {
522// char * pFileName;
523 int nSuppSize = Extra_TruthSupportSize( pTruth, pCut->nLeaves );
524 printf( " C%02d: L= %2d/%2d V= %2d/%d N= %d W= %4.2f ",
525 i, pCut->nLeaves, nSuppSize, pCut->nNodes, pCut->nNodesDup, pCut->nLuts, pCut->Weight );
526 Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pLeaf, k )
527 printf( "%c=%d ", 'a'+k, Abc_ObjLevel(pLeaf) );
528 printf( "\n" );
529 Kit_DsdPrintFromTruth( pTruth, pCut->nLeaves );
530 printf( "\n" );
531// pFileName = Kit_TruthDumpToFile( pTruth, pCut->nLeaves, Count++ );
532// printf( "Saved truth table in file \"%s\".\n", pFileName );
533 }
534
535 // update the network
536 nNodesBef = Abc_NtkNodeNum(p->pNtk);
537clk = Abc_Clock();
538 pObjNew = Lpk_Decompose( p, p->pNtk, p->vLeaves, pTruth, p->puSupps, p->pPars->nLutSize,
539 (int)pCut->nNodes - (int)pCut->nNodesDup - 1 + (int)(p->pPars->fZeroCost > 0), Required );
540 if ( pObjNew == NULL && p->pPars->nLutSize == 4 && (int)pCut->nNodes > NodeCounts[Vec_PtrSize(p->vLeaves)] + !p->pPars->fZeroCost )
541 pObjNew = Abc_NtkLutMinDecompose( p->pNtk, p->vLeaves, (word *)pTruth, p->pPars->nLutSize, Required );
542p->timeEval += Abc_Clock() - clk;
543 nNodesAft = Abc_NtkNodeNum(p->pNtk);
544
545 // perform replacement
546 if ( pObjNew )
547 {
548 int nGain = (int)pCut->nNodes - (int)pCut->nNodesDup - (nNodesAft - nNodesBef);
549 //assert( nGain >= 1 - p->pPars->fZeroCost );
550 assert( Abc_ObjLevel(pObjNew) <= Required );
551/*
552 if ( nGain <= 0 )
553 {
554 int x = 0;
555 }
556 if ( Abc_ObjLevel(pObjNew) > Required )
557 {
558 int x = 0;
559 }
560*/
561 p->nGainTotal += nGain;
562 p->nChanges++;
563 if ( p->pPars->fVeryVerbose )
564 printf( "Performed resynthesis: Gain = %2d. Level = %2d. Req = %2d.\n", nGain, Abc_ObjLevel(pObjNew), Required );
565 Abc_NtkUpdate( p->pObj, pObjNew, p->vLevels );
566//printf( "%3d : %d-%d=%d(%d) \n", p->nChanges, nNodesBef, Abc_NtkNodeNum(p->pNtk), nNodesBef-Abc_NtkNodeNum(p->pNtk), nGain );
567 break;
568 }
569 }
570 return 1;
571}
572
585{
586 ProgressBar * pProgress = NULL; // Suppress "might be used uninitialized"
587 Lpk_Man_t * p;
588 Abc_Obj_t * pObj;
589 double Delta;
590// int * pnFanouts, nObjMax;
591 int i, Iter, nNodes, nNodesPrev;
592 abctime clk = Abc_Clock();
593 assert( Abc_NtkIsLogic(pNtk) );
594
595 // sweep dangling nodes as a preprocessing step
596 Abc_NtkSweep( pNtk, 0 );
597
598 // get the number of inputs
599 if ( Abc_FrameReadLibLut() )
600 pPars->nLutSize = ((If_LibLut_t *)Abc_FrameReadLibLut())->LutMax;
601 else
602 pPars->nLutSize = Abc_NtkGetFaninMax( pNtk );
603 if ( pPars->nLutSize > 6 )
604 pPars->nLutSize = 6;
605 if ( pPars->nLutSize < 3 )
606 pPars->nLutSize = 3;
607 // adjust the number of crossbars based on LUT size
608 if ( pPars->nVarsShared > pPars->nLutSize - 2 )
609 pPars->nVarsShared = pPars->nLutSize - 2;
610 // get the max number of LUTs tried
611 pPars->nVarsMax = pPars->nLutsMax * (pPars->nLutSize - 1) + 1; // V = N * (K-1) + 1
612 while ( pPars->nVarsMax > 16 )
613 {
614 pPars->nLutsMax--;
615 pPars->nVarsMax = pPars->nLutsMax * (pPars->nLutSize - 1) + 1;
616
617 }
618 if ( pPars->fVerbose )
619 {
620 printf( "Resynthesis for %d %d-LUTs with %d non-MFFC LUTs, %d crossbars, and %d-input cuts.\n",
621 pPars->nLutsMax, pPars->nLutSize, pPars->nLutsOver, pPars->nVarsShared, pPars->nVarsMax );
622 }
623
624
625 // convert into the AIG
626 if ( !Abc_NtkToAig(pNtk) )
627 {
628 fprintf( stdout, "Converting to BDD has failed.\n" );
629 return 0;
630 }
631 assert( Abc_NtkHasAig(pNtk) );
632
633 // set the number of levels
634 Abc_NtkLevel( pNtk );
635 Abc_NtkStartReverseLevels( pNtk, pPars->nGrowthLevel );
636
637 // start the manager
638 p = Lpk_ManStart( pPars );
639 p->pNtk = pNtk;
640 p->nNodesTotal = Abc_NtkNodeNum(pNtk);
641 p->vLevels = Vec_VecStart( pNtk->LevelMax );
642 if ( p->pPars->fSatur )
643 p->vVisited = Vec_VecStart( 0 );
644 if ( pPars->fVerbose )
645 {
646 p->nTotalNets = Abc_NtkGetTotalFanins(pNtk);
647 p->nTotalNodes = Abc_NtkNodeNum(pNtk);
648 }
649/*
650 // save the number of fanouts of all objects
651 nObjMax = Abc_NtkObjNumMax( pNtk );
652 pnFanouts = ABC_ALLOC( int, nObjMax );
653 memset( pnFanouts, 0, sizeof(int) * nObjMax );
654 Abc_NtkForEachObj( pNtk, pObj, i )
655 pnFanouts[pObj->Id] = Abc_ObjFanoutNum(pObj);
656*/
657
658 // iterate over the network
659 nNodesPrev = p->nNodesTotal;
660 for ( Iter = 1; ; Iter++ )
661 {
662 // expand storage for changed nodes
663 if ( p->pPars->fSatur )
664 Vec_VecExpand( p->vVisited, Abc_NtkObjNumMax(pNtk) + 1 );
665
666 // consider all nodes
667 nNodes = Abc_NtkObjNumMax(pNtk);
668 if ( !pPars->fVeryVerbose )
669 pProgress = Extra_ProgressBarStart( stdout, nNodes );
670 Abc_NtkForEachNode( pNtk, pObj, i )
671 {
672 // skip all except the final node
673 if ( pPars->fFirst )
674 {
675 if ( !Abc_ObjIsCo(Abc_ObjFanout0(pObj)) )
676 continue;
677 }
678 if ( i >= nNodes )
679 break;
680 if ( !pPars->fVeryVerbose )
681 Extra_ProgressBarUpdate( pProgress, i, NULL );
682 // skip the nodes that did not change
683 if ( p->pPars->fSatur && !Lpk_NodeHasChanged(p, pObj->Id) )
684 continue;
685 // resynthesize
686 p->pObj = pObj;
687 if ( p->pPars->fOldAlgo )
689 else
691 }
692 if ( !pPars->fVeryVerbose )
693 Extra_ProgressBarStop( pProgress );
694
695 // check the increase
696 Delta = 100.00 * (nNodesPrev - Abc_NtkNodeNum(pNtk)) / p->nNodesTotal;
697 if ( Delta < 0.05 )
698 break;
699 nNodesPrev = Abc_NtkNodeNum(pNtk);
700 if ( !p->pPars->fSatur )
701 break;
702
703 if ( pPars->fFirst )
704 break;
705 }
707/*
708 // report the fanout changes
709 Abc_NtkForEachObj( pNtk, pObj, i )
710 {
711 if ( i >= nObjMax )
712 continue;
713 if ( Abc_ObjFanoutNum(pObj) - pnFanouts[pObj->Id] == 0 )
714 continue;
715 printf( "%d ", Abc_ObjFanoutNum(pObj) - pnFanouts[pObj->Id] );
716 }
717 printf( "\n" );
718*/
719
720 if ( pPars->fVerbose )
721 {
722// Cloud_PrintInfo( p->pDsdMan->dd );
723 p->nTotalNets2 = Abc_NtkGetTotalFanins(pNtk);
724 p->nTotalNodes2 = Abc_NtkNodeNum(pNtk);
725 printf( "Node gain = %5d. (%.2f %%) ",
726 p->nTotalNodes-p->nTotalNodes2, 100.0*(p->nTotalNodes-p->nTotalNodes2)/p->nTotalNodes );
727 printf( "Edge gain = %5d. (%.2f %%) ",
728 p->nTotalNets-p->nTotalNets2, 100.0*(p->nTotalNets-p->nTotalNets2)/p->nTotalNets );
729 printf( "Muxes = %4d. Dsds = %4d.", p->nMuxes, p->nDsds );
730 printf( "\n" );
731 printf( "Nodes = %5d (%3d) Cuts = %5d (%4d) Changes = %5d Iter = %2d Benefit = %d.\n",
732 p->nNodesTotal, p->nNodesOver, p->nCutsTotal, p->nCutsUseful, p->nChanges, Iter, p->nBenefited );
733
734 printf( "Non-DSD:" );
735 for ( i = 3; i <= pPars->nVarsMax; i++ )
736 if ( p->nBlocks[i] )
737 printf( " %d=%d", i, p->nBlocks[i] );
738 printf( "\n" );
739
740 p->timeTotal = Abc_Clock() - clk;
741 p->timeEval = p->timeEval - p->timeMap;
742 p->timeOther = p->timeTotal - p->timeCuts - p->timeTruth - p->timeEval - p->timeMap;
743 ABC_PRTP( "Cuts ", p->timeCuts, p->timeTotal );
744 ABC_PRTP( "Truth ", p->timeTruth, p->timeTotal );
745 ABC_PRTP( "CSupps", p->timeSupps, p->timeTotal );
746 ABC_PRTP( "Eval ", p->timeEval, p->timeTotal );
747 ABC_PRTP( " MuxAn", p->timeEvalMuxAn, p->timeEval );
748 ABC_PRTP( " MuxSp", p->timeEvalMuxSp, p->timeEval );
749 ABC_PRTP( " DsdAn", p->timeEvalDsdAn, p->timeEval );
750 ABC_PRTP( " DsdSp", p->timeEvalDsdSp, p->timeEval );
751 ABC_PRTP( " Other", p->timeEval-p->timeEvalMuxAn-p->timeEvalMuxSp-p->timeEvalDsdAn-p->timeEvalDsdSp, p->timeEval );
752 ABC_PRTP( "Map ", p->timeMap, p->timeTotal );
753 ABC_PRTP( "Other ", p->timeOther, p->timeTotal );
754 ABC_PRTP( "TOTAL ", p->timeTotal, p->timeTotal );
755 }
756
757 Lpk_ManStop( p );
758 // check the resulting network
759 if ( !Abc_NtkCheck( pNtk ) )
760 {
761 printf( "Lpk_Resynthesize: The network check has failed.\n" );
762 return 0;
763 }
764 return 1;
765}
766
770
771
773
Abc_Obj_t * Abc_NodeFromIf_rec(Abc_Ntk_t *pNtkNew, If_Man_t *pIfMan, If_Obj_t *pIfObj, Vec_Int_t *vCover)
Definition abcIf.c:565
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkLutmin(Abc_Ntk_t *pNtkInit, int nLutSize, int fReorder, int fVerbose)
DECLARATIONS ///.
Definition abcLutmin.c:1249
ABC_DLL int Abc_NtkSweep(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcSweep.c:692
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_NtkGetFaninMax(Abc_Ntk_t *pNtk)
Definition abcUtil.c:486
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst1(Abc_Ntk_t *pNtk)
Definition abcObj.c:643
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition abcObj.c:342
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition abcTiming.c:1214
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeConst0(Abc_Ntk_t *pNtk)
Definition abcObj.c:612
ABC_DLL char * Abc_SopCreateFromTruthIsop(Mem_Flex_t *pMan, int nVars, word *pTruth, Vec_Int_t *vCover)
Definition abcSop.c:462
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
ABC_DLL int Abc_NodeMffcLabel(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition abcRefs.c:439
ABC_DLL void Abc_NtkUpdate(Abc_Obj_t *pObj, Abc_Obj_t *pObjNew, Vec_Vec_t *vLevels)
Definition abcTiming.c:1423
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition abcTiming.c:1302
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition abcTiming.c:1274
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition abcFunc.c:1333
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeInv(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition abcObj.c:674
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL int Abc_NtkGetTotalFanins(Abc_Ntk_t *pNtk)
Definition abcUtil.c:520
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
ABC_DLL Abc_Ntk_t * Abc_NtkCreateWithNode(char *pSop)
Definition abcNtk.c:1333
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibLut()
Definition mainFrame.c:57
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
ABC_NAMESPACE_IMPL_START typedef char ProgressBar
Definition bbrNtbdd.c:27
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
int Extra_TruthSupportSize(unsigned *pTruth, int nVars)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
void If_ManCleanCutData(If_Man_t *p)
Definition ifUtil.c:64
If_Obj_t * If_ManCreateCo(If_Man_t *p, If_Obj_t *pDriver)
Definition ifMan.c:356
struct If_Par_t_ If_Par_t
Definition if.h:78
void If_ManSetupCiCutSets(If_Man_t *p)
Definition ifMan.c:566
int If_ManPerformMappingComb(If_Man_t *p)
Definition ifCore.c:106
struct If_LibLut_t_ If_LibLut_t
Definition if.h:82
void If_ManRestart(If_Man_t *p)
Definition ifMan.c:185
void If_ManSetupSetAll(If_Man_t *p, int nCrossCut)
Definition ifMan.c:693
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
If_Man_t * If_ManStart(If_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition ifMan.c:50
If_Obj_t * If_ManCreateCi(If_Man_t *p)
Definition ifMan.c:334
struct If_Obj_t_ If_Obj_t
Definition if.h:79
void If_ManCleanNodeCopy(If_Man_t *p)
DECLARATIONS ///.
Definition ifUtil.c:45
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Kit_DsdNonDsdSizeMax(Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:1212
Kit_DsdNtk_t * Kit_DsdDecompose(unsigned *pTruth, int nVars)
Definition kitDsd.c:2315
void Kit_DsdPrint(FILE *pFile, Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:375
int Kit_CreateCloudFromTruth(CloudManager *dd, unsigned *pTruth, int nVars, Vec_Int_t *vNodes)
Definition kitCloud.c:209
void Kit_TruthCofSupports(Vec_Int_t *vBddDir, Vec_Int_t *vBddInv, int nVars, Vec_Int_t *vMemory, unsigned *puSupps)
Definition kitCloud.c:310
@ KIT_DSD_XOR
Definition kit.h:106
@ KIT_DSD_CONST1
Definition kit.h:103
@ KIT_DSD_PRIME
Definition kit.h:107
@ KIT_DSD_AND
Definition kit.h:105
@ KIT_DSD_VAR
Definition kit.h:104
void Kit_DsdNtkFree(Kit_DsdNtk_t *pNtk)
Definition kitDsd.c:164
struct Kit_DsdObj_t_ Kit_DsdObj_t
Definition kit.h:111
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition kitDsd.c:491
struct Kit_DsdNtk_t_ Kit_DsdNtk_t
Definition kit.h:124
Abc_Obj_t * Lpk_Decompose(Lpk_Man_t *p, Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, unsigned *pTruth, unsigned *puSupps, int nLutK, int AreaLim, int DelayLim)
FUNCTION DECLARATIONS ///.
Definition lpkAbcDec.c:258
int Lpk_Resynthesize(Abc_Ntk_t *pNtk, Lpk_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition lpkCore.c:584
int Lpk_NodeHasChanged(Lpk_Man_t *p, int iNode)
Definition lpkCore.c:172
Abc_Obj_t * Abc_NtkLutMinDecompose(Abc_Ntk_t *pNtk, Vec_Ptr_t *vLeaves, word *pTruth, int nLutSize, int Required)
Definition lpkCore.c:67
int Lpk_ResynthesizeNodeNew(Lpk_Man_t *p)
Definition lpkCore.c:443
int Lpk_ResynthesizeNode(Lpk_Man_t *p)
Definition lpkCore.c:315
void Lpk_ComputeSupports(Lpk_Man_t *p, Lpk_Cut_t *pCut, unsigned *pTruth)
Definition lpkCore.c:419
int Lpk_ExploreCut(Lpk_Man_t *p, Lpk_Cut_t *pCut, Kit_DsdNtk_t *pNtk)
Definition lpkCore.c:205
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkDecFromTruth(word *pTruth, int nVars, int nLutSize)
DECLARATIONS ///.
Definition lpkCore.c:47
void Lpk_IfManStart(Lpk_Man_t *p)
Definition lpkCore.c:123
int Lpk_NodeCuts(Lpk_Man_t *p)
Definition lpkCut.c:619
unsigned * Lpk_CutTruth(Lpk_Man_t *p, Lpk_Cut_t *pCut, int fInv)
Definition lpkCut.c:175
#define Lpk_CutForEachLeaf(pNtk, pCut, pObj, i)
MACRO DEFINITIONS ///.
Definition lpkInt.h:190
Lpk_Man_t * Lpk_ManStart(Lpk_Par_t *pPars)
DECLARATIONS ///.
Definition lpkMan.c:45
struct Lpk_Man_t_ Lpk_Man_t
Definition lpkInt.h:50
void Lpk_ManStop(Lpk_Man_t *p)
Definition lpkMan.c:95
If_Obj_t * Lpk_MapTree_rec(Lpk_Man_t *p, Kit_DsdNtk_t *pNtk, If_Obj_t **ppLeaves, int iLit, If_Obj_t *pResult)
Definition lpkMap.c:110
struct Lpk_Cut_t_ Lpk_Cut_t
Definition lpkInt.h:51
typedefABC_NAMESPACE_HEADER_START struct Lpk_Par_t_ Lpk_Par_t
INCLUDES ///.
Definition lpk.h:42
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
void * pManFunc
Definition abc.h:191
int LevelMax
Definition abc.h:195
void * pData
Definition abc.h:145
int Id
Definition abc.h:132
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned Level
Definition abc.h:142
float * pTimesArr
Definition if.h:176
int fLatchPaths
Definition if.h:121
int fUseSops
Definition if.h:163
float Epsilon
Definition if.h:111
int fTruth
Definition if.h:160
int nLutSize
Definition if.h:104
int fUseCnfs
Definition if.h:164
int fExpRed
Definition if.h:120
int nLatchesCo
Definition if.h:167
int nFlowIters
Definition if.h:106
int nAreaIters
Definition if.h:107
int fUseBdds
Definition if.h:162
int fUseMv
Definition if.h:165
int nCutsMax
Definition if.h:105
int fVerbose
Definition if.h:152
float DelayTarget
Definition if.h:110
int fPreprocess
Definition if.h:117
If_LibLut_t * pLutLib
Definition if.h:175
int nLatchesCi
Definition if.h:166
int fFancy
Definition if.h:119
int fUsePerm
Definition if.h:161
int fArea
Definition if.h:118
unsigned short Root
Definition kit.h:130
unsigned Type
Definition kit.h:115
unsigned short pFans[0]
Definition kit.h:120
unsigned nNodes
Definition lpkInt.h:56
unsigned nLuts
Definition lpkInt.h:58
float Weight
Definition lpkInt.h:63
int pLeaves[LPK_SIZE_MAX]
Definition lpkInt.h:65
unsigned nNodesDup
Definition lpkInt.h:57
unsigned nLeaves
Definition lpkInt.h:55
#define assert(ex)
Definition util_old.h:213
char * memset()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntryDouble(Type1, Type2, vVec, Entry1, Entry2, i)
Definition vecPtr.h:67
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55