ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
abcLut.c
Go to the documentation of this file.
1
20
21#include "base/abc/abc.h"
22#include "opt/cut/cut.h"
23
25
26#define LARGE_LEVEL 1000000
27
31
32#define SCL_LUT_MAX 6 // the maximum LUT size
33#define SCL_VARS_MAX 15 // the maximum number of variables
34#define SCL_NODE_MAX 1000 // the maximum number of nodes
35
38{
39 // paramers
40 int nLutSize; // the LUT size
41 int nCutSizeMax; // the max number of leaves of the cone
42 int nNodesMax; // the max number of divisors in the cone
43 int nWords; // the number of machine words in sim info
44 // structural representation of the cone
45 Vec_Ptr_t * vLeaves; // leaves of the cut
46 Vec_Ptr_t * vVolume; // volume of the cut
47 int pBSet[SCL_VARS_MAX]; // bound set
48 // functional representation of the cone
49 unsigned * uTruth; // truth table of the cone
50 // representation of truth tables
51 unsigned ** uVars; // elementary truth tables
52 unsigned ** uSims; // truth tables of the nodes
53 unsigned ** uCofs; // truth tables of the cofactors
54};
55
56static Vec_Ptr_t * s_pLeaves = NULL;
57
58static Cut_Man_t * Abc_NtkStartCutManForScl( Abc_Ntk_t * pNtk, int nLutSize );
59static Abc_ManScl_t * Abc_ManSclStart( int nLutSize, int nCutSizeMax, int nNodesMax );
60static void Abc_ManSclStop( Abc_ManScl_t * p );
61static void Abc_NodeLutMap( Cut_Man_t * pManCuts, Abc_Obj_t * pObj );
62
63static Abc_Obj_t * Abc_NodeSuperChoiceLut( Abc_ManScl_t * pManScl, Abc_Obj_t * pObj );
64static int Abc_NodeDecomposeStep( Abc_ManScl_t * pManScl );
65
69
81int Abc_NtkSuperChoiceLut( Abc_Ntk_t * pNtk, int nLutSize, int nCutSizeMax, int fVerbose )
82{
83 ProgressBar * pProgress;
84 Abc_ManCut_t * pManCut;
85 Abc_ManScl_t * pManScl;
86 Cut_Man_t * pManCuts;
87 Abc_Obj_t * pObj, * pFanin, * pObjTop;
88 int i, LevelMax, nNodes;
89 int nNodesTried, nNodesDec, nNodesExist, nNodesUsed;
90
91 assert( Abc_NtkIsSopLogic(pNtk) );
92 if ( nLutSize < 3 || nLutSize > SCL_LUT_MAX )
93 {
94 printf( "LUT size (%d) does not belong to the interval: 3 <= LUT size <= %d\n", nLutSize, SCL_LUT_MAX );
95 return 0;
96 }
97 if ( nCutSizeMax <= nLutSize || nCutSizeMax > SCL_VARS_MAX )
98 {
99 printf( "Cut size (%d) does not belong to the interval: LUT size (%d) < Cut size <= %d\n", nCutSizeMax, nLutSize, SCL_VARS_MAX );
100 return 0;
101 }
102
103 assert( nLutSize <= SCL_LUT_MAX );
104 assert( nCutSizeMax <= SCL_VARS_MAX );
105 nNodesTried = nNodesDec = nNodesExist = nNodesUsed = 0;
106
107 // set the delays of the CIs
108 Abc_NtkForEachCi( pNtk, pObj, i )
109 pObj->Level = 0;
110
111//Abc_NtkLevel( pNtk );
112
113 // start the managers
114 pManScl = Abc_ManSclStart( nLutSize, nCutSizeMax, 1000 );
115 pManCuts = Abc_NtkStartCutManForScl( pNtk, nLutSize );
116 pManCut = Abc_NtkManCutStart( nCutSizeMax, 100000, 100000, 100000 );
117 s_pLeaves = Abc_NtkManCutReadCutSmall( pManCut );
118 pManScl->vVolume = Abc_NtkManCutReadVisited( pManCut );
119
120 // process each internal node (assuming topological order of nodes!!!)
121 nNodes = Abc_NtkObjNumMax(pNtk);
122 pProgress = Extra_ProgressBarStart( stdout, nNodes );
123 Abc_NtkForEachObj( pNtk, pObj, i )
124 {
125// if ( i != nNodes-1 )
126// continue;
127 Extra_ProgressBarUpdate( pProgress, i, NULL );
128 if ( i >= nNodes )
129 break;
130 if ( Abc_ObjFaninNum(pObj) != 2 )
131 continue;
132 nNodesTried++;
133
134 // map this node using regular cuts
135// pObj->Level = 0;
136 Abc_NodeLutMap( pManCuts, pObj );
137 // compute the cut
138 pManScl->vLeaves = Abc_NodeFindCut( pManCut, pObj, 0 );
139 if ( Vec_PtrSize(pManScl->vLeaves) <= nLutSize )
140 continue;
141 // get the volume of the cut
142 if ( Vec_PtrSize(pManScl->vVolume) > SCL_NODE_MAX )
143 continue;
144 nNodesDec++;
145
146 // decompose the cut
147 pObjTop = Abc_NodeSuperChoiceLut( pManScl, pObj );
148 if ( pObjTop == NULL )
149 continue;
150 nNodesExist++;
151
152 // if there is no delay improvement, skip; otherwise, update level
153 if ( pObjTop->Level >= pObj->Level )
154 {
155 Abc_NtkDeleteObj_rec( pObjTop, 1 );
156 continue;
157 }
158 pObj->Level = pObjTop->Level;
159 nNodesUsed++;
160 }
161 Extra_ProgressBarStop( pProgress );
162
163 // delete the managers
164 Abc_ManSclStop( pManScl );
165 Abc_NtkManCutStop( pManCut );
166 Cut_ManStop( pManCuts );
167
168 // get the largest arrival time
169 LevelMax = 0;
170 Abc_NtkForEachCo( pNtk, pObj, i )
171 {
172 pFanin = Abc_ObjFanin0( pObj );
173 // skip inv/buf
174 if ( Abc_ObjFaninNum(pFanin) == 1 )
175 pFanin = Abc_ObjFanin0( pFanin );
176 // get the new level
177 LevelMax = Abc_MaxInt( LevelMax, (int)pFanin->Level );
178 }
179
180 if ( fVerbose )
181 printf( "Try = %d. Dec = %d. Exist = %d. Use = %d. SUPER = %d levels of %d-LUTs.\n",
182 nNodesTried, nNodesDec, nNodesExist, nNodesUsed, LevelMax, nLutSize );
183// if ( fVerbose )
184// printf( "The network is superchoiced for %d levels of %d-LUTs.\n", LevelMax, nLutSize );
185
186 // clean the data field
187 Abc_NtkForEachObj( pNtk, pObj, i )
188 pObj->pNext = NULL;
189
190 // check
191 if ( !Abc_NtkCheck( pNtk ) )
192 {
193 printf( "Abc_NtkSuperChoiceLut: The network check has failed.\n" );
194 return 0;
195 }
196 return 1;
197}
198
210void Abc_NodeLutMap( Cut_Man_t * pManCuts, Abc_Obj_t * pObj )
211{
212 Cut_Cut_t * pCut;
213 Abc_Obj_t * pFanin;
214 int i, DelayMax;
215 pCut = (Cut_Cut_t *)Abc_NodeGetCutsRecursive( pManCuts, pObj, 0, 0 );
216 assert( pCut != NULL );
217 assert( pObj->Level == 0 );
218 // go through the cuts
219 pObj->Level = LARGE_LEVEL;
220 for ( pCut = pCut->pNext; pCut; pCut = pCut->pNext )
221 {
222 DelayMax = 0;
223 for ( i = 0; i < (int)pCut->nLeaves; i++ )
224 {
225 pFanin = Abc_NtkObj( pObj->pNtk, pCut->pLeaves[i] );
226// assert( Abc_ObjIsCi(pFanin) || pFanin->Level > 0 ); // should hold if node ordering is topological
227 if ( DelayMax < (int)pFanin->Level )
228 DelayMax = pFanin->Level;
229 }
230 if ( (int)pObj->Level > DelayMax )
231 pObj->Level = DelayMax;
232 }
233 assert( pObj->Level < LARGE_LEVEL );
234 pObj->Level++;
235// printf( "%d(%d) ", pObj->Id, pObj->Level );
236}
237
249Cut_Man_t * Abc_NtkStartCutManForScl( Abc_Ntk_t * pNtk, int nLutSize )
250{
251 static Cut_Params_t Params, * pParams = &Params;
252 Cut_Man_t * pManCut;
253 Abc_Obj_t * pObj;
254 int i;
255 // start the cut manager
256 memset( pParams, 0, sizeof(Cut_Params_t) );
257 pParams->nVarsMax = nLutSize; // the max cut size ("k" of the k-feasible cuts)
258 pParams->nKeepMax = 500; // the max number of cuts kept at a node
259 pParams->fTruth = 0; // compute truth tables
260 pParams->fFilter = 1; // filter dominated cuts
261 pParams->fSeq = 0; // compute sequential cuts
262 pParams->fDrop = 0; // drop cuts on the fly
263 pParams->fVerbose = 0; // the verbosiness flag
264 pParams->nIdsMax = Abc_NtkObjNumMax( pNtk );
265 pManCut = Cut_ManStart( pParams );
266 if ( pParams->fDrop )
268 // set cuts for PIs
269 Abc_NtkForEachCi( pNtk, pObj, i )
270 if ( Abc_ObjFanoutNum(pObj) > 0 )
271 Cut_NodeSetTriv( pManCut, pObj->Id );
272 return pManCut;
273}
274
286Abc_ManScl_t * Abc_ManSclStart( int nLutSize, int nCutSizeMax, int nNodesMax )
287{
288 Abc_ManScl_t * p;
289 int i, k;
290 assert( sizeof(unsigned) == 4 );
291 p = ABC_ALLOC( Abc_ManScl_t, 1 );
292 memset( p, 0, sizeof(Abc_ManScl_t) );
293 p->nLutSize = nLutSize;
294 p->nCutSizeMax = nCutSizeMax;
295 p->nNodesMax = nNodesMax;
296 p->nWords = Extra_TruthWordNum(nCutSizeMax);
297 // allocate simulation info
298 p->uVars = (unsigned **)Extra_ArrayAlloc( nCutSizeMax, p->nWords, 4 );
299 p->uSims = (unsigned **)Extra_ArrayAlloc( nNodesMax, p->nWords, 4 );
300 p->uCofs = (unsigned **)Extra_ArrayAlloc( 2 << nLutSize, p->nWords, 4 );
301 memset( p->uVars[0], 0, nCutSizeMax * p->nWords * 4 );
302 // assign elementary truth tables
303 for ( k = 0; k < p->nCutSizeMax; k++ )
304 for ( i = 0; i < p->nWords * 32; i++ )
305 if ( i & (1 << k) )
306 p->uVars[k][i>>5] |= (1 << (i&31));
307 // other data structures
308// p->vBound = Vec_IntAlloc( nCutSizeMax );
309 return p;
310}
311
323void Abc_ManSclStop( Abc_ManScl_t * p )
324{
325// Vec_IntFree( p->vBound );
326 ABC_FREE( p->uVars );
327 ABC_FREE( p->uSims );
328 ABC_FREE( p->uCofs );
329 ABC_FREE( p );
330}
331
332
345{
346 Abc_Obj_t * pObj;
347 unsigned * puData0, * puData1, * puData = NULL;
348 char * pSop;
349 int i, k;
350 // set elementary truth tables
351 Vec_PtrForEachEntry( Abc_Obj_t *, pManScl->vLeaves, pObj, i )
352 pObj->pNext = (Abc_Obj_t *)pManScl->uVars[i];
353 // compute truth tables for internal nodes
354 Vec_PtrForEachEntry( Abc_Obj_t *, pManScl->vVolume, pObj, i )
355 {
356 // set storage for the node's simulation info
357 pObj->pNext = (Abc_Obj_t *)pManScl->uSims[i];
358 // get pointer to the simulation info
359 puData = (unsigned *)pObj->pNext;
360 puData0 = (unsigned *)Abc_ObjFanin0(pObj)->pNext;
361 puData1 = (unsigned *)Abc_ObjFanin1(pObj)->pNext;
362 // simulate
363 pSop = (char *)pObj->pData;
364 if ( pSop[0] == '0' && pSop[1] == '0' )
365 for ( k = 0; k < pManScl->nWords; k++ )
366 puData[k] = ~puData0[k] & ~puData1[k];
367 else if ( pSop[0] == '0' )
368 for ( k = 0; k < pManScl->nWords; k++ )
369 puData[k] = ~puData0[k] & puData1[k];
370 else if ( pSop[1] == '0' )
371 for ( k = 0; k < pManScl->nWords; k++ )
372 puData[k] = puData0[k] & ~puData1[k];
373 else
374 for ( k = 0; k < pManScl->nWords; k++ )
375 puData[k] = puData0[k] & puData1[k];
376 }
377 return puData;
378}
379
392{
393 if ( pObj->fMarkC )
394 return;
395 pObj->fMarkC = 1;
396 assert( Abc_ObjFaninNum(pObj) == 2 );
397 Abc_NodeSuperChoiceCollect2_rec( Abc_ObjFanin0(pObj), vVolume );
398 Abc_NodeSuperChoiceCollect2_rec( Abc_ObjFanin1(pObj), vVolume );
399 Vec_PtrPush( vVolume, pObj );
400}
401
413void Abc_NodeSuperChoiceCollect2( Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVolume )
414{
415 Abc_Obj_t * pObj;
416 int i;
417 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
418 pObj->fMarkC = 1;
419 Vec_PtrClear( vVolume );
420 Abc_NodeSuperChoiceCollect2_rec( pRoot, vVolume );
421 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
422 pObj->fMarkC = 0;
423 Vec_PtrForEachEntry( Abc_Obj_t *, vVolume, pObj, i )
424 pObj->fMarkC = 0;
425}
426
439{
440 if ( pObj->fMarkB )
441 {
442 Vec_PtrPush( vLeaves, pObj );
443 pObj->fMarkB = 0;
444 }
445 if ( pObj->fMarkC )
446 return;
447 pObj->fMarkC = 1;
448 assert( Abc_ObjFaninNum(pObj) == 2 );
449 Abc_NodeSuperChoiceCollect_rec( Abc_ObjFanin0(pObj), vLeaves, vVolume );
450 Abc_NodeSuperChoiceCollect_rec( Abc_ObjFanin1(pObj), vLeaves, vVolume );
451 Vec_PtrPush( vVolume, pObj );
452}
453
465void Abc_NodeSuperChoiceCollect( Abc_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vVolume )
466{
467 Abc_Obj_t * pObj;
468 int i, nLeaves;
469 nLeaves = Vec_PtrSize(vLeaves);
470 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
471 pObj->fMarkB = pObj->fMarkC = 1;
472 Vec_PtrClear( vVolume );
473 Vec_PtrClear( vLeaves );
474 Abc_NodeSuperChoiceCollect_rec( pRoot, vLeaves, vVolume );
475 assert( Vec_PtrSize(vLeaves) == nLeaves );
476 Vec_PtrForEachEntry( Abc_Obj_t *, vLeaves, pObj, i )
477 pObj->fMarkC = 0;
478 Vec_PtrForEachEntry( Abc_Obj_t *, vVolume, pObj, i )
479 pObj->fMarkC = 0;
480}
481
493void Abc_NodeLeavesRemove( Vec_Ptr_t * vLeaves, unsigned uPhase, int nVars )
494{
495 int i;
496 for ( i = nVars - 1; i >= 0; i-- )
497 if ( uPhase & (1 << i) )
498 Vec_PtrRemove( vLeaves, Vec_PtrEntry(vLeaves, i) );
499}
500
513{
514 Abc_Obj_t * pFanin;
515 int i, Level;
516 Level = 0;
517 Abc_ObjForEachFanin( pObj, pFanin, i )
518 Level = Abc_MaxInt( Level, (int)pFanin->Level );
519 return Level + 1;
520}
521
533Abc_Obj_t * Abc_NodeSuperChoiceLut( Abc_ManScl_t * p, Abc_Obj_t * pObj )
534{
535 Abc_Obj_t * pFanin, * pObjNew;
536 int i, nVars, uSupport, nSuppVars;
537 // collect the cone using DFS (excluding leaves)
538 Abc_NodeSuperChoiceCollect2( pObj, p->vLeaves, p->vVolume );
539 assert( Vec_PtrEntryLast(p->vVolume) == pObj );
540 // compute the truth table
541 p->uTruth = Abc_NodeSuperChoiceTruth( p );
542 // get the support of this truth table
543 nVars = Vec_PtrSize(p->vLeaves);
544 uSupport = Extra_TruthSupport(p->uTruth, nVars);
545 nSuppVars = Extra_WordCountOnes(uSupport);
546 assert( nSuppVars <= nVars );
547 if ( nSuppVars == 0 )
548 {
549 pObj->Level = 0;
550 return NULL;
551 }
552 if ( nSuppVars == 1 )
553 {
554 // find the variable
555 for ( i = 0; i < nVars; i++ )
556 if ( uSupport & (1 << i) )
557 break;
558 assert( i < nVars );
559 pFanin = (Abc_Obj_t *)Vec_PtrEntry( p->vLeaves, i );
560 pObj->Level = pFanin->Level;
561 return NULL;
562 }
563 // support-minimize the truth table
564 if ( nSuppVars != nVars )
565 {
566 Extra_TruthShrink( p->uCofs[0], p->uTruth, nSuppVars, nVars, uSupport );
567 Extra_TruthCopy( p->uTruth, p->uCofs[0], nVars );
568 Abc_NodeLeavesRemove( p->vLeaves, ((1 << nVars) - 1) & ~uSupport, nVars );
569 }
570// return NULL;
571 // decompose the truth table recursively
572 while ( Vec_PtrSize(p->vLeaves) > p->nLutSize )
573 if ( !Abc_NodeDecomposeStep( p ) )
574 {
575 Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pFanin, i )
576 if ( Abc_ObjIsNode(pFanin) && Abc_ObjFanoutNum(pFanin) == 0 )
577 Abc_NtkDeleteObj_rec( pFanin, 1 );
578 return NULL;
579 }
580 // create the topmost node
581 pObjNew = Abc_NtkCreateNode( pObj->pNtk );
582 Vec_PtrForEachEntry( Abc_Obj_t *, p->vLeaves, pFanin, i )
583 Abc_ObjAddFanin( pObjNew, pFanin );
584 // create the function
585 pObjNew->pData = Abc_SopCreateFromTruth( (Mem_Flex_t *)pObj->pNtk->pManFunc, Vec_PtrSize(p->vLeaves), p->uTruth ); // need ISOP
586 pObjNew->Level = Abc_NodeGetLevel( pObjNew );
587 return pObjNew;
588}
589
601int Abc_NodeCompareLevelsInc( int * pp1, int * pp2 )
602{
603 Abc_Obj_t * pNode1, * pNode2;
604 pNode1 = (Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp1);
605 pNode2 = (Abc_Obj_t *)Vec_PtrEntry(s_pLeaves, *pp2);
606 if ( pNode1->Level < pNode2->Level )
607 return -1;
608 if ( pNode1->Level > pNode2->Level )
609 return 1;
610 return 0;
611}
612
624void Abc_NodeDecomposeSort( Abc_Obj_t ** pLeaves, int nVars, int * pBSet, int nLutSize )
625{
626 Abc_Obj_t * pTemp[SCL_VARS_MAX];
627 int i, k, kBest, LevelMin;
628 assert( nLutSize < nVars );
629 assert( nVars <= SCL_VARS_MAX );
630 // copy nodes into the internal storage
631// printf( "(" );
632 for ( i = 0; i < nVars; i++ )
633 {
634 pTemp[i] = pLeaves[i];
635// printf( " %d", pLeaves[i]->Level );
636 }
637// printf( " )\n" );
638 // choose one node at a time
639 for ( i = 0; i < nLutSize; i++ )
640 {
641 kBest = -1;
642 LevelMin = LARGE_LEVEL;
643 for ( k = 0; k < nVars; k++ )
644 if ( pTemp[k] && LevelMin > (int)pTemp[k]->Level )
645 {
646 LevelMin = pTemp[k]->Level;
647 kBest = k;
648 }
649 pBSet[i] = kBest;
650 pTemp[kBest] = NULL;
651 }
652}
653
665int Abc_NodeDecomposeStep( Abc_ManScl_t * p )
666{
667 static char pCofClasses[1<<SCL_LUT_MAX][1<<SCL_LUT_MAX];
668 static char nCofClasses[1<<SCL_LUT_MAX];
669 Abc_Ntk_t * pNtk;
670 Abc_Obj_t * pObjNew, * pFanin, * pNodesNew[SCL_LUT_MAX];
671 unsigned * pTruthCof, * pTruthClass, * pTruth, uPhase;
672 int i, k, c, v, w, nVars, nVarsNew, nClasses, nCofs;
673 // set the network
674 pNtk = ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, 0))->pNtk;
675 // find the earliest nodes
676 nVars = Vec_PtrSize(p->vLeaves);
677 assert( nVars > p->nLutSize );
678/*
679 for ( v = 0; v < nVars; v++ )
680 p->pBSet[v] = v;
681 qsort( (void *)p->pBSet, (size_t)nVars, sizeof(int),
682 (int (*)(const void *, const void *)) Abc_NodeCompareLevelsInc );
683*/
684 Abc_NodeDecomposeSort( (Abc_Obj_t **)Vec_PtrArray(p->vLeaves), Vec_PtrSize(p->vLeaves), p->pBSet, p->nLutSize );
685 assert( ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, p->pBSet[0]))->Level <=
686 ((Abc_Obj_t *)Vec_PtrEntry(p->vLeaves, p->pBSet[1]))->Level );
687 // cofactor w.r.t. the selected variables
688 Extra_TruthCopy( p->uCofs[1], p->uTruth, nVars );
689 c = 2;
690 for ( v = 0; v < p->nLutSize; v++ )
691 for ( k = 0; k < (1<<v); k++ )
692 {
693 Extra_TruthCopy( p->uCofs[c], p->uCofs[c/2], nVars );
694 Extra_TruthCopy( p->uCofs[c+1], p->uCofs[c/2], nVars );
695 Extra_TruthCofactor0( p->uCofs[c], nVars, p->pBSet[v] );
696 Extra_TruthCofactor1( p->uCofs[c+1], nVars, p->pBSet[v] );
697 c += 2;
698 }
699 assert( c == (2 << p->nLutSize) );
700 // count unique cofactors
701 nClasses = 0;
702 nCofs = (1 << p->nLutSize);
703 for ( i = 0; i < nCofs; i++ )
704 {
705 pTruthCof = p->uCofs[ nCofs + i ];
706 for ( k = 0; k < nClasses; k++ )
707 {
708 pTruthClass = p->uCofs[ nCofs + pCofClasses[k][0] ];
709 if ( Extra_TruthIsEqual( pTruthCof, pTruthClass, nVars ) )
710 {
711 pCofClasses[k][(int)nCofClasses[k]++ ] = i;
712 break;
713 }
714 }
715 if ( k != nClasses )
716 continue;
717 // not found
718 pCofClasses[nClasses][0] = i;
719 nCofClasses[nClasses] = 1;
720 nClasses++;
721 if ( nClasses > nCofs/2 )
722 return 0;
723 }
724 // the number of cofactors is acceptable
725 nVarsNew = Abc_Base2Log( nClasses );
726 assert( nVarsNew < p->nLutSize );
727 // create the remainder truth table
728 // for each class of cofactors, multiply cofactor truth table by its code
729 Extra_TruthClear( p->uTruth, nVars );
730 for ( k = 0; k < nClasses; k++ )
731 {
732 pTruthClass = p->uCofs[ nCofs + pCofClasses[k][0] ];
733 for ( v = 0; v < nVarsNew; v++ )
734 if ( k & (1 << v) )
735 Extra_TruthAnd( pTruthClass, pTruthClass, p->uVars[p->pBSet[v]], nVars );
736 else
737 Extra_TruthSharp( pTruthClass, pTruthClass, p->uVars[p->pBSet[v]], nVars );
738 Extra_TruthOr( p->uTruth, p->uTruth, pTruthClass, nVars );
739 }
740 // create nodes
741 pTruth = p->uCofs[0];
742 for ( v = 0; v < nVarsNew; v++ )
743 {
744 Extra_TruthClear( pTruth, p->nLutSize );
745 for ( k = 0; k < nClasses; k++ )
746 if ( k & (1 << v) )
747 for ( i = 0; i < nCofClasses[k]; i++ )
748 {
749 pTruthCof = p->uCofs[1];
750 Extra_TruthFill( pTruthCof, p->nLutSize );
751 for ( w = 0; w < p->nLutSize; w++ )
752 if ( pCofClasses[k][i] & (1 << (p->nLutSize-1-w)) )
753 Extra_TruthAnd( pTruthCof, pTruthCof, p->uVars[w], p->nLutSize );
754 else
755 Extra_TruthSharp( pTruthCof, pTruthCof, p->uVars[w], p->nLutSize );
756 Extra_TruthOr( pTruth, pTruth, pTruthCof, p->nLutSize );
757 }
758 // implement the node
759 pObjNew = Abc_NtkCreateNode( pNtk );
760 for ( i = 0; i < p->nLutSize; i++ )
761 {
762 pFanin = (Abc_Obj_t *)Vec_PtrEntry( p->vLeaves, p->pBSet[i] );
763 Abc_ObjAddFanin( pObjNew, pFanin );
764 }
765 // create the function
766 pObjNew->pData = Abc_SopCreateFromTruth( (Mem_Flex_t *)pNtk->pManFunc, p->nLutSize, pTruth ); // need ISOP
767 pObjNew->Level = Abc_NodeGetLevel( pObjNew );
768 pNodesNew[v] = pObjNew;
769 }
770 // put the new nodes back into the list
771 for ( v = 0; v < nVarsNew; v++ )
772 Vec_PtrWriteEntry( p->vLeaves, p->pBSet[v], pNodesNew[v] );
773 // compute the variables that should be removed
774 uPhase = 0;
775 for ( v = nVarsNew; v < p->nLutSize; v++ )
776 uPhase |= (1 << p->pBSet[v]);
777 // remove entries from the array
778 Abc_NodeLeavesRemove( p->vLeaves, uPhase, nVars );
779 // update truth table
780 Extra_TruthShrink( p->uCofs[0], p->uTruth, nVars - p->nLutSize + nVarsNew, nVars, ((1 << nVars) - 1) & ~uPhase );
781 Extra_TruthCopy( p->uTruth, p->uCofs[0], nVars );
782 assert( !Extra_TruthVarInSupport( p->uTruth, nVars, nVars - p->nLutSize + nVarsNew ) );
783 return 1;
784}
785
797static word s__Truths6[6] = {
798 ABC_CONST(0xAAAAAAAAAAAAAAAA),
799 ABC_CONST(0xCCCCCCCCCCCCCCCC),
800 ABC_CONST(0xF0F0F0F0F0F0F0F0),
801 ABC_CONST(0xFF00FF00FF00FF00),
802 ABC_CONST(0xFFFF0000FFFF0000),
803 ABC_CONST(0xFFFFFFFF00000000)
804};
806{
807 int Index; word t0, t1, tc;
808 assert( Vec_IntSize(vSupp) <= 6 );
809 if ( (Index = Vec_IntFind(vSupp, Abc_ObjId(pObj))) >= 0 )
810 return s__Truths6[Index];
811 assert( Abc_ObjIsNode(pObj) );
812 if ( Abc_ObjFaninNum(pObj) == 0 )
813 return Abc_NodeIsConst0(pObj) ? (word)0 : ~(word)0;
814 assert( Abc_ObjFaninNum(pObj) == 3 );
815 t0 = Abc_ObjComputeTruth( Abc_ObjFanin(pObj, 2), vSupp );
816 t1 = Abc_ObjComputeTruth( Abc_ObjFanin(pObj, 1), vSupp );
817 tc = Abc_ObjComputeTruth( Abc_ObjFanin(pObj, 0), vSupp );
818 return (tc & t1) | (~tc & t0);
819}
821{
822 if ( pObj->pCopy )
823 return pObj->pCopy;
824 if ( Abc_ObjFaninNum(pObj) == 0 )
825 return NULL;
826 assert( Abc_ObjFaninNum(pObj) == 3 );
827 if ( pObj->fMarkA || pObj->fMarkB )
828 {
829 Abc_Obj_t * pFan0 = Abc_NtkSpecialMap_rec( pNew, Abc_ObjFanin(pObj, 2), vSupps, vCover );
830 Abc_Obj_t * pFan1 = Abc_NtkSpecialMap_rec( pNew, Abc_ObjFanin(pObj, 1), vSupps, vCover );
831 Abc_Obj_t * pFanC = Abc_NtkSpecialMap_rec( pNew, Abc_ObjFanin(pObj, 0), vSupps, vCover );
832 if ( pFan0 == NULL )
833 pFan0 = Abc_NodeIsConst0(Abc_ObjFanin(pObj, 2)) ? Abc_NtkCreateNodeConst0(pNew) : Abc_NtkCreateNodeConst1(pNew);
834 if ( pFan1 == NULL )
835 pFan1 = Abc_NodeIsConst0(Abc_ObjFanin(pObj, 1)) ? Abc_NtkCreateNodeConst0(pNew) : Abc_NtkCreateNodeConst1(pNew);
836 pObj->pCopy = Abc_NtkCreateNodeMux( pNew, pFanC, pFan1, pFan0 );
837 pObj->pCopy->fMarkA = pObj->fMarkA;
838 pObj->pCopy->fMarkB = pObj->fMarkB;
839 }
840 else
841 {
842 Abc_Obj_t * pTemp; int i; word Truth;
843 Vec_Int_t * vSupp = Vec_WecEntry( vSupps, Abc_ObjId(pObj) );
844 Abc_NtkForEachObjVec( vSupp, pObj->pNtk, pTemp, i )
845 Abc_NtkSpecialMap_rec( pNew, pTemp, vSupps, vCover );
846 pObj->pCopy = Abc_NtkCreateNode( pNew );
847 Abc_NtkForEachObjVec( vSupp, pObj->pNtk, pTemp, i )
848 Abc_ObjAddFanin( pObj->pCopy, pTemp->pCopy );
849 Truth = Abc_ObjComputeTruth( pObj, vSupp );
850 pObj->pCopy->pData = Abc_SopCreateFromTruthIsop( (Mem_Flex_t *)pNew->pManFunc, Vec_IntSize(vSupp), &Truth, vCover );
851 assert( Abc_SopGetVarNum((char *)pObj->pCopy->pData) == Vec_IntSize(vSupp) );
852 }
853 return pObj->pCopy;
854}
856{
857 Abc_Ntk_t * pNtkNew;
858 Vec_Int_t * vCover = Vec_IntAlloc( 1 << 16 );
859 Vec_Wec_t * vSupps = Vec_WecStart( Abc_NtkObjNumMax(pNtk) );
860 Abc_Obj_t * pObj, * pFan0, * pFan1, * pFanC; int i, Count[2] = {0};
861 Abc_NtkForEachCi( pNtk, pObj, i )
862 Vec_IntPush( Vec_WecEntry(vSupps, i), i );
863 Abc_NtkForEachNode( pNtk, pObj, i )
864 {
865 Vec_Int_t * vSupp = Vec_WecEntry(vSupps, i);
866 if ( Abc_ObjFaninNum(pObj) == 0 )
867 continue;
868 assert( Abc_ObjFaninNum(pObj) == 3 );
869 pFan0 = Abc_ObjFanin( pObj, 2 );
870 pFan1 = Abc_ObjFanin( pObj, 1 );
871 pFanC = Abc_ObjFanin0( pObj );
872 assert( Abc_ObjIsCi(pFanC) );
873 if ( pFan0->fMarkA && pFan1->fMarkA )
874 {
875 pObj->fMarkB = 1;
876 Vec_IntPush( vSupp, Abc_ObjId(pObj) );
877 continue;
878 }
879 Vec_IntTwoMerge2( Vec_WecEntry(vSupps, Abc_ObjId(pFan0)), Vec_WecEntry(vSupps, Abc_ObjId(pFan1)), vSupp );
880 assert( Vec_IntFind(vSupp, Abc_ObjId(pFanC)) == -1 );
881 Vec_IntPushOrder( vSupp, Abc_ObjId(pFanC) );
882 if ( Vec_IntSize(vSupp) <= 6 )
883 continue;
884 Vec_IntClear( vSupp );
885 if ( !pFan0->fMarkA && !pFan1->fMarkA )
886 {
887 pObj->fMarkA = 1;
888 Vec_IntPush( vSupp, Abc_ObjId(pObj) );
889 }
890 else
891 {
892 Vec_IntPushOrder( vSupp, Abc_ObjId(pFan0) );
893 Vec_IntPushOrder( vSupp, Abc_ObjId(pFan1) );
894 Vec_IntPushOrder( vSupp, Abc_ObjId(pFanC) );
895 }
896 }
897
898 if ( fVerbose )
899 {
900 Abc_NtkForEachNode( pNtk, pObj, i )
901 {
902 printf( "Node %4d : ", i );
903 if ( pObj->fMarkA )
904 printf( " MarkA " );
905 else
906 printf( " " );
907 if ( pObj->fMarkB )
908 printf( " MarkB " );
909 else
910 printf( " " );
911 Vec_IntPrint( Vec_WecEntry(vSupps, i) );
912 }
913 }
914
915 Abc_NtkCleanCopy( pNtk );
916 pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_SOP );
917 Abc_NtkForEachCo( pNtk, pObj, i )
918 if ( Abc_ObjFaninNum(Abc_ObjFanin0(pObj)) == 0 )
919 Abc_ObjFanin0(pObj)->pCopy = Abc_NodeIsConst0(Abc_ObjFanin0(pObj)) ? Abc_NtkCreateNodeConst0(pNtkNew) : Abc_NtkCreateNodeConst1(pNtkNew);
920 else
921 Abc_NtkSpecialMap_rec( pNtkNew, Abc_ObjFanin0(pObj), vSupps, vCover );
922 Abc_NtkFinalize( pNtk, pNtkNew );
923 Abc_NtkCleanMarkAB( pNtk );
924 Vec_WecFree( vSupps );
925 Vec_IntFree( vCover );
926
927 Abc_NtkForEachNode( pNtkNew, pObj, i )
928 {
929 Count[0] += pObj->fMarkA,
930 Count[1] += pObj->fMarkB;
931 pObj->fPersist = pObj->fMarkA | pObj->fMarkB;
932 pObj->fMarkA = pObj->fMarkB = 0;
933 }
934 //printf( "Total = %3d. Nodes = %3d. MarkA = %3d. MarkB = %3d.\n", Abc_NtkNodeNum(pNtkNew),
935 // Abc_NtkNodeNum(pNtkNew) - Count[0] - Count[1], Count[0], Count[1] );
936
937 if ( !Abc_NtkCheck( pNtkNew ) )
938 {
939 printf( "Abc_NtkSpecialMapping: The network check has failed.\n" );
940 Abc_NtkDelete( pNtkNew );
941 return NULL;
942 }
943 return pNtkNew;
944}
945
949
951
952
953
void Abc_NodeLeavesRemove(Vec_Ptr_t *vLeaves, unsigned uPhase, int nVars)
Definition abcLut.c:493
#define SCL_NODE_MAX
Definition abcLut.c:34
int Abc_NodeCompareLevelsInc(int *pp1, int *pp2)
Definition abcLut.c:601
void Abc_NodeSuperChoiceCollect2(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition abcLut.c:413
int Abc_NtkSuperChoiceLut(Abc_Ntk_t *pNtk, int nLutSize, int nCutSizeMax, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition abcLut.c:81
#define LARGE_LEVEL
Definition abcLut.c:26
struct Abc_ManScl_t_ Abc_ManScl_t
Definition abcLut.c:36
#define SCL_LUT_MAX
DECLARATIONS ///.
Definition abcLut.c:32
#define SCL_VARS_MAX
Definition abcLut.c:33
void Abc_NodeSuperChoiceCollect(Abc_Obj_t *pRoot, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition abcLut.c:465
Abc_Obj_t * Abc_NtkSpecialMap_rec(Abc_Ntk_t *pNew, Abc_Obj_t *pObj, Vec_Wec_t *vSupps, Vec_Int_t *vCover)
Definition abcLut.c:820
void Abc_NodeSuperChoiceCollect2_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vVolume)
Definition abcLut.c:391
void Abc_NodeDecomposeSort(Abc_Obj_t **pLeaves, int nVars, int *pBSet, int nLutSize)
Definition abcLut.c:624
void Abc_NodeSuperChoiceCollect_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, Vec_Ptr_t *vVolume)
Definition abcLut.c:438
unsigned * Abc_NodeSuperChoiceTruth(Abc_ManScl_t *pManScl)
Definition abcLut.c:344
word Abc_ObjComputeTruth(Abc_Obj_t *pObj, Vec_Int_t *vSupp)
Definition abcLut.c:805
int Abc_NodeGetLevel(Abc_Obj_t *pObj)
Definition abcLut.c:512
Abc_Ntk_t * Abc_NtkSpecialMapping(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcLut.c:855
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
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 int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
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
struct Abc_ManCut_t_ Abc_ManCut_t
Definition abc.h:119
ABC_DLL void Abc_NtkManCutStop(Abc_ManCut_t *p)
Definition abcReconv.c:623
ABC_DLL void Abc_NtkDeleteObj_rec(Abc_Obj_t *pObj, int fOnlyNodes)
Definition abcObj.c:278
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
Definition abcCut.c:412
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition abcNtk.c:355
ABC_DLL int Abc_NodeIsConst0(Abc_Obj_t *pNode)
Definition abcObj.c:884
ABC_DLL char * Abc_SopCreateFromTruth(Mem_Flex_t *pMan, int nVars, unsigned *pTruth)
Definition abcSop.c:383
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL Vec_Int_t * Abc_NtkFanoutCounts(Abc_Ntk_t *pNtk)
Definition abcUtil.c:1741
ABC_DLL Vec_Ptr_t * Abc_NodeFindCut(Abc_ManCut_t *p, Abc_Obj_t *pRoot, int fContain)
Definition abcReconv.c:256
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeMux(Abc_Ntk_t *pNtk, Abc_Obj_t *pNodeC, Abc_Obj_t *pNode1, Abc_Obj_t *pNode0)
Definition abcObj.c:834
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadVisited(Abc_ManCut_t *p)
Definition abcReconv.c:676
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition abcSop.c:584
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL void Abc_NtkCleanMarkAB(Abc_Ntk_t *pNtk)
Definition abcUtil.c:753
ABC_DLL Vec_Ptr_t * Abc_NtkManCutReadCutSmall(Abc_ManCut_t *p)
Definition abcReconv.c:660
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition abc.h:455
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL Abc_ManCut_t * Abc_NtkManCutStart(int nNodeSizeMax, int nConeSizeMax, int nNodeFanStop, int nConeFanStop)
Definition abcReconv.c:595
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
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
struct Cut_ParamsStruct_t_ Cut_Params_t
Definition cut.h:51
void Cut_NodeSetTriv(Cut_Man_t *p, int Node)
Definition cutApi.c:145
Cut_Man_t * Cut_ManStart(Cut_Params_t *pParams)
FUNCTION DEFINITIONS ///.
Definition cutMan.c:47
struct Cut_ManStruct_t_ Cut_Man_t
BASIC TYPES ///.
Definition cut.h:48
void Cut_ManSetFanoutCounts(Cut_Man_t *p, Vec_Int_t *vFanCounts)
Definition cutMan.c:229
struct Cut_CutStruct_t_ Cut_Cut_t
Definition cut.h:50
void Cut_ManStop(Cut_Man_t *p)
Definition cutMan.c:124
Cube * p
Definition exorList.c:222
void Extra_ProgressBarStop(ProgressBar *p)
void Extra_TruthCofactor1(unsigned *pTruth, int nVars, int iVar)
int Extra_TruthVarInSupport(unsigned *pTruth, int nVars, int iVar)
void ** Extra_ArrayAlloc(int nCols, int nRows, int Size)
void Extra_TruthShrink(unsigned *pOut, unsigned *pIn, int nVars, int nVarsAll, unsigned Phase)
void Extra_TruthCofactor0(unsigned *pTruth, int nVars, int iVar)
ProgressBar * Extra_ProgressBarStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
int Extra_TruthSupport(unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
struct Mem_Flex_t_ Mem_Flex_t
Definition mem.h:34
int pBSet[SCL_VARS_MAX]
Definition abcLut.c:47
int nNodesMax
Definition abcLut.c:42
unsigned ** uSims
Definition abcLut.c:52
unsigned ** uVars
Definition abcLut.c:51
int nLutSize
Definition abcLut.c:40
int nCutSizeMax
Definition abcLut.c:41
unsigned * uTruth
Definition abcLut.c:49
Vec_Ptr_t * vLeaves
Definition abcLut.c:45
Vec_Ptr_t * vVolume
Definition abcLut.c:46
unsigned ** uCofs
Definition abcLut.c:53
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:145
unsigned fMarkC
Definition abc.h:136
Abc_Ntk_t * pNtk
Definition abc.h:130
int Id
Definition abc.h:132
unsigned fMarkB
Definition abc.h:135
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fMarkA
Definition abc.h:134
Abc_Obj_t * pNext
Definition abc.h:131
unsigned Level
Definition abc.h:142
unsigned fPersist
Definition abc.h:139
int pLeaves[0]
Definition cut.h:89
unsigned nLeaves
Definition cut.h:84
Cut_Cut_t * pNext
Definition cut.h:88
#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_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42