120static inline int Fx_ManGetFirstVarCube(
Fx_Man_t *
p,
Vec_Int_t * vCube ) {
return Vec_IntEntry(
p->vVarCube, Vec_IntEntry(vCube, 0) ); }
122#define Fx_ManForEachCubeVec( vVec, vCubes, vCube, i ) \
123 for ( i = 0; (i < Vec_IntSize(vVec)) && ((vCube) = Vec_WecEntry(vCubes, Vec_IntEntry(vVec, i))); i++ )
145 char * pCube, * pSop;
146 int nVars, i, v, Lit;
147 assert( Abc_NtkIsSopLogic(pNtk) );
148 vCubes = Vec_WecAlloc( 1000 );
151 pSop = (
char *)pNode->
pData;
153 assert( nVars == Abc_ObjFaninNum(pNode) );
157 vCube = Vec_WecPushLevel( vCubes );
158 Vec_IntPush( vCube, Abc_ObjId(pNode) );
162 Vec_IntPush( vCube, Abc_Var2Lit(Abc_ObjFaninId(pNode, v), 1) );
163 else if ( Lit ==
'1' )
164 Vec_IntPush( vCube, Abc_Var2Lit(Abc_ObjFaninId(pNode, v), 0) );
166 Vec_IntSelectSort( Vec_IntArray(vCube) + 1, Vec_IntSize(vCube) - 1 );
185 Vec_Int_t * vCube, * vPres, * vFirst, * vCount;
187 char * pCube, * pSop;
188 int i, k, v, Lit, iFanin, iNodeMax = 0;
189 assert( Abc_NtkIsSopLogic(pNtk) );
194 assert( Vec_IntSize(vCube) > 0 );
195 assert( Lit <= Vec_IntEntry(vCube, 0) );
196 Lit = Vec_IntEntry(vCube, 0);
200 iNodeMax = Abc_MaxInt( iNodeMax, Vec_IntEntry(vCube, 0) );
202 if ( iNodeMax < Abc_NtkObjNumMax(pNtk) )
208 for ( i = Abc_NtkObjNumMax(pNtk); i <= iNodeMax; i++ )
210 pNode = Abc_NtkCreateNode( pNtk );
211 assert( i == (
int)Abc_ObjId(pNode) );
214 vFirst = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
215 vCount = Vec_IntStart( Abc_NtkObjNumMax(pNtk) );
218 iFanin = Vec_IntEntry( vCube, 0 );
219 if ( Vec_IntEntry(vCount, iFanin) == 0 )
220 Vec_IntWriteEntry( vFirst, iFanin, i );
221 Vec_IntAddToEntry( vCount, iFanin, 1 );
224 vPres = Vec_IntStartFull( Abc_NtkObjNumMax(pNtk) );
230 assert( Vec_IntEntry(vCount, i) > 0 );
231 for ( k = 0; k < Vec_IntEntry(vCount, i); k++ )
233 vCube = Vec_WecEntry( vCubes, Vec_IntEntry(vFirst, i) + k );
234 assert( Vec_IntEntry( vCube, 0 ) == i );
237 pFanin = Abc_NtkObj(pNtk, Abc_Lit2Var(Lit));
238 if ( Vec_IntEntry(vPres, Abc_ObjId(pFanin)) >= 0 )
240 Vec_IntWriteEntry(vPres, Abc_ObjId(pFanin), Abc_ObjFaninNum(pNode));
246 for ( k = 0; k < Vec_IntEntry(vCount, i); k++ )
248 vCube = Vec_WecEntry( vCubes, Vec_IntEntry(vFirst, i) + k );
249 assert( Vec_IntEntry( vCube, 0 ) == i );
252 pFanin = Abc_NtkObj(pNtk, Abc_Lit2Var(Lit));
253 iFanin = Vec_IntEntry(vPres, Abc_ObjId(pFanin));
254 assert( iFanin >= 0 && iFanin < Abc_ObjFaninNum(pNode) );
255 pCube[iFanin] = Abc_LitIsCompl(Lit) ?
'0' :
'1';
257 pCube += Abc_ObjFaninNum(pNode) + 3;
265 Vec_IntWriteEntry( vPres, Abc_ObjId(pFanin), -1 );
267 Vec_IntFree( vFirst );
268 Vec_IntFree( vCount );
269 Vec_IntFree( vPres );
290 if ( !Vec_IntCheckUniqueSmall( &pNode->
vFanins ) ) {
291 printf(
"Fanins of node %d: ", i );
292 Vec_IntPrint( &pNode->
vFanins );
311 extern int Fx_FastExtract(
Vec_Wec_t * vCubes,
int ObjIdMax,
int nNewNodesMax,
int LitCountMax,
int fCanonDivs,
int fVerbose,
int fVeryVerbose );
313 assert( Abc_NtkIsSopLogic(pNtk) );
317 printf(
"Abc_NtkFastExtract: Nodes have duplicated fanins. FX is not performed.\n" );
323 if (
Fx_FastExtract( vCubes, Abc_NtkObjNumMax(pNtk), nNewNodesMax, LitCountMax, fCanonDivs, fVerbose, fVeryVerbose ) > 0 )
327 Vec_WecFree( vCubes );
329 printf(
"Abc_NtkFxPerform: The network check has failed.\n" );
333 printf(
"Warning: The network has not been changed by \"fx\".\n" );
334 Vec_WecFree( vCubes );
357 p->vCubesS = Vec_IntAlloc( 100 );
358 p->vCubesD = Vec_IntAlloc( 100 );
359 p->vCompls = Vec_IntAlloc( 100 );
360 p->vCubeFree = Vec_IntAlloc( 100 );
361 p->vDiv = Vec_IntAlloc( 100 );
362 p->vSCC = Vec_IntAlloc( 100 );
368 Vec_WecFree(
p->vLits );
369 Vec_IntFree(
p->vCounts );
370 Hsh_VecManStop(
p->pHash );
371 Vec_FltFree(
p->vWeights );
372 Vec_QueFree(
p->vPrio );
373 Vec_IntFree(
p->vVarCube );
374 Vec_IntFree(
p->vLevels );
376 Vec_IntFree(
p->vCubesS );
377 Vec_IntFree(
p->vCubesD );
378 Vec_IntFree(
p->vCompls );
379 Vec_IntFree(
p->vCubeFree );
380 Vec_IntFree(
p->vDiv );
381 Vec_IntFree(
p->vSCC );
398 int i, Lit, Level = 0;
400 Level = Abc_MaxInt( Level, Vec_IntEntry(
p->vLevels, Abc_Lit2Var(Abc_Lit2Var(Lit))) );
401 return Abc_MinInt( Level, 800 );
405 int k, Lit, Level = 0;
407 Level = Abc_MaxInt( Level, Vec_IntEntry(
p->vLevels, Abc_Lit2Var(Lit)) );
413 int i, iVar, iFirst = 0;
414 iVar = Vec_IntEntry( Vec_WecEntry(
p->vCubes,0), 0 );
415 p->vLevels = Vec_IntStart(
p->nVars );
418 if ( iVar != Vec_IntEntry(vCube, 0) )
421 Vec_IntAddToEntry(
p->vLevels, iVar, i - iFirst );
422 iVar = Vec_IntEntry(vCube, 0);
425 Vec_IntUpdateEntry(
p->vLevels, iVar, Fx_ManComputeLevelCube(
p, vCube) );
440static inline void Fx_PrintDivArray(
Vec_Int_t * vDiv )
444 if ( !Abc_LitIsCompl(Lit) )
445 printf(
"%d(1)", Abc_Lit2Var(Lit) );
448 if ( Abc_LitIsCompl(Lit) )
449 printf(
"%d(2)", Abc_Lit2Var(Lit) );
451static inline void Fx_PrintDiv(
Fx_Man_t *
p,
int iDiv )
454 printf(
"%4d : ",
p->nDivs );
455 printf(
"Div %7d : ", iDiv );
456 printf(
"Weight %12.5f ", Vec_FltEntry(
p->vWeights, iDiv) );
457 Fx_PrintDivArray( Hsh_VecReadEntry(
p->pHash, iDiv) );
458 for ( i = Vec_IntSize(Hsh_VecReadEntry(
p->pHash, iDiv)) + 3; i < 16; i++ )
460 printf(
"Lits =%7d ",
p->nLits );
461 printf(
"Divs =%8d ", Hsh_VecSize(
p->pHash) );
462 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->timeStart );
464static void Fx_PrintDivisors(
Fx_Man_t *
p )
467 for ( iDiv = 0; iDiv < Vec_FltSize(
p->vWeights); iDiv++ )
468 Fx_PrintDiv(
p, iDiv );
472 printf(
"Cubes =%8d ", Vec_WecSizeUsed(
p->vCubes) );
473 printf(
"Lits =%8d ", Vec_WecSizeUsed(
p->vLits) );
474 printf(
"Divs =%8d ", Hsh_VecSize(
p->pHash) );
475 printf(
"Divs+ =%8d ", Vec_QueSize(
p->vPrio) );
476 printf(
"Compl =%8d ",
p->nDivMux[1] );
477 printf(
"Extr =%7d ",
p->nDivs );
478 Abc_PrintTime( 1,
"Time", clk );
494static int Fx_ManDivNormalize(
Vec_Int_t * vCubeFree )
496 int * L = Vec_IntArray(vCubeFree);
497 int RetValue = 0, LitA0 = -1, LitB0 = -1, LitA1 = -1, LitB1 = -1;
498 assert( Vec_IntSize(vCubeFree) == 4 );
499 if ( Abc_LitIsCompl(L[0]) != Abc_LitIsCompl(L[1]) && (L[0] >> 2) == (L[1] >> 2) )
501 if ( Abc_LitIsCompl(L[2]) == Abc_LitIsCompl(L[3]) )
503 LitA0 = Abc_Lit2Var(L[0]), LitB0 = Abc_Lit2Var(L[1]);
504 if ( Abc_LitIsCompl(L[0]) == Abc_LitIsCompl(L[2]) )
506 assert( Abc_LitIsCompl(L[1]) == Abc_LitIsCompl(L[3]) );
507 LitA1 = Abc_Lit2Var(L[2]), LitB1 = Abc_Lit2Var(L[3]);
511 assert( Abc_LitIsCompl(L[0]) == Abc_LitIsCompl(L[3]) );
512 assert( Abc_LitIsCompl(L[1]) == Abc_LitIsCompl(L[2]) );
513 LitA1 = Abc_Lit2Var(L[3]), LitB1 = Abc_Lit2Var(L[2]);
516 else if ( Abc_LitIsCompl(L[1]) != Abc_LitIsCompl(L[2]) && (L[1] >> 2) == (L[2] >> 2) )
518 if ( Abc_LitIsCompl(L[0]) == Abc_LitIsCompl(L[3]) )
520 LitA0 = Abc_Lit2Var(L[1]), LitB0 = Abc_Lit2Var(L[2]);
521 if ( Abc_LitIsCompl(L[1]) == Abc_LitIsCompl(L[0]) )
522 LitA1 = Abc_Lit2Var(L[0]), LitB1 = Abc_Lit2Var(L[3]);
524 LitA1 = Abc_Lit2Var(L[3]), LitB1 = Abc_Lit2Var(L[0]);
526 else if ( Abc_LitIsCompl(L[2]) != Abc_LitIsCompl(L[3]) && (L[2] >> 2) == (L[3] >> 2) )
528 if ( Abc_LitIsCompl(L[0]) == Abc_LitIsCompl(L[1]) )
530 LitA0 = Abc_Lit2Var(L[2]), LitB0 = Abc_Lit2Var(L[3]);
531 if ( Abc_LitIsCompl(L[2]) == Abc_LitIsCompl(L[0]) )
532 LitA1 = Abc_Lit2Var(L[0]), LitB1 = Abc_Lit2Var(L[1]);
534 LitA1 = Abc_Lit2Var(L[1]), LitB1 = Abc_Lit2Var(L[0]);
538 assert( LitA0 == Abc_LitNot(LitB0) );
539 if ( Abc_LitIsCompl(LitA0) )
544 assert( !Abc_LitIsCompl(LitA0) );
545 if ( Abc_LitIsCompl(LitA1) )
547 LitA1 = Abc_LitNot(LitA1);
548 LitB1 = Abc_LitNot(LitB1);
551 assert( !Abc_LitIsCompl(LitA1) );
556 L[0] = Abc_Var2Lit( LitA0, 0 );
557 L[1] = Abc_Var2Lit( LitB0, 1 );
558 L[2] = Abc_Var2Lit( LitA1, 0 );
559 L[3] = Abc_Var2Lit( LitB1, 1 );
576 int * pBeg1 = Vec_IntArray( vArr1 ) + 1;
577 int * pBeg2 = Vec_IntArray( vArr2 ) + 1;
578 int * pEnd1 = Vec_IntLimit( vArr1 );
579 int * pEnd2 = Vec_IntLimit( vArr2 );
580 int Counter = 0, fAttr0 = 0, fAttr1 = 1;
581 Vec_IntClear( vCubeFree );
582 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
584 if ( *pBeg1 == *pBeg2 )
585 pBeg1++, pBeg2++, Counter++;
586 else if ( *pBeg1 < *pBeg2 )
587 Vec_IntPush( vCubeFree, Abc_Var2Lit(*pBeg1++, fAttr0) );
590 if ( Vec_IntSize(vCubeFree) == 0 )
591 fAttr0 = 1, fAttr1 = 0;
592 Vec_IntPush( vCubeFree, Abc_Var2Lit(*pBeg2++, fAttr1) );
595 while ( pBeg1 < pEnd1 )
596 Vec_IntPush( vCubeFree, Abc_Var2Lit(*pBeg1++, fAttr0) );
597 while ( pBeg2 < pEnd2 )
598 Vec_IntPush( vCubeFree, Abc_Var2Lit(*pBeg2++, fAttr1) );
599 if ( Vec_IntSize(vCubeFree) == 0 )
600 printf(
"The SOP has duplicated cubes.\n" );
601 else if ( Vec_IntSize(vCubeFree) == 1 )
603 else if ( Vec_IntSize( vCubeFree ) == 3 )
605 int * pArray = Vec_IntArray( vCubeFree );
607 if ( Abc_Lit2Var( pArray[0] ) == Abc_LitNot( Abc_Lit2Var( pArray[1] ) ) )
609 if ( Abc_LitIsCompl( pArray[0] ) == Abc_LitIsCompl( pArray[2] ) )
610 Vec_IntDrop( vCubeFree, 0 );
612 Vec_IntDrop( vCubeFree, 1 );
614 else if ( Abc_Lit2Var( pArray[1] ) == Abc_LitNot( Abc_Lit2Var( pArray[2] ) ) )
616 if ( Abc_LitIsCompl( pArray[1] ) == Abc_LitIsCompl( pArray[0] ) )
617 Vec_IntDrop( vCubeFree, 1 );
619 Vec_IntDrop( vCubeFree, 2 );
622 if ( Vec_IntSize( vCubeFree ) == 2 )
624 int Lit0 = Abc_Lit2Var( pArray[0] ),
625 Lit1 = Abc_Lit2Var( pArray[1] );
630 Vec_IntWriteEntry( vCubeFree, 0, Abc_Var2Lit( Lit0, 0 ) );
631 Vec_IntWriteEntry( vCubeFree, 1, Abc_Var2Lit( Lit1, 1 ) );
634 assert( !Abc_LitIsCompl(Vec_IntEntry(vCubeFree, 0)) );
649static inline void Fx_ManDivFindPivots(
Vec_Int_t * vDiv,
int * pLit0,
int * pLit1 )
656 if ( Abc_LitIsCompl(Lit) )
659 *pLit1 = Abc_Lit2Var(Lit);
664 *pLit0 = Abc_Lit2Var(Lit);
666 if ( *pLit0 >= 0 && *pLit1 >= 0 )
670static inline int Fx_ManDivRemoveLits(
Vec_Int_t * vCube,
Vec_Int_t * vDiv,
int fCompl )
672 int i, Lit, Count = 0;
673 assert( !fCompl || Vec_IntSize(vDiv) == 4 );
676 Count += Vec_IntRemove1( vCube, Abc_Lit2Var(Lit) ^ (fCompl && i > 1) );
677 if ( Vec_IntSize( vDiv ) == 2 )
678 Count += Vec_IntRemove1( vCube, Abc_LitNot( Abc_Lit2Var(Lit) ) );
684 int i, Lit, * pArray;
688 if ( Abc_LitIsCompl(Lit) )
689 Vec_IntPush( vCube2, Abc_Lit2Var(Lit) );
691 Vec_IntPush( vCube, Abc_Lit2Var(Lit) );
692 if ( Vec_IntSize(vDiv) == 4 && Vec_IntSize(vCube) == 3 )
694 assert( Vec_IntSize(vCube2) == 3 );
695 pArray = Vec_IntArray(vCube);
696 if ( pArray[1] > pArray[2] )
697 ABC_SWAP(
int, pArray[1], pArray[2] );
698 pArray = Vec_IntArray(vCube2);
699 if ( pArray[1] > pArray[2] )
700 ABC_SWAP(
int, pArray[1], pArray[2] );
718 int i, k, Lit, Count;
720 p->nVars =
p->nLits = 0;
723 assert( Vec_IntSize(vCube) > 0 );
724 p->nVars = Abc_MaxInt(
p->nVars, Vec_IntEntry(vCube, 0) );
725 p->nLits += Vec_IntSize(vCube) - 1;
727 p->nVars = Abc_MaxInt(
p->nVars, Abc_Lit2Var(Lit) );
733 p->vCounts = Vec_IntStart( 2*
p->nVars );
736 Vec_IntAddToEntry(
p->vCounts, Lit, 1 );
738 p->vLits = Vec_WecStart( 2*
p->nVars );
740 Vec_IntGrow( Vec_WecEntry(
p->vLits, Lit), Count );
744 Vec_WecPush(
p->vLits, Lit, i );
746 p->vVarCube = Vec_IntStartFull(
p->nVars );
748 if ( Vec_IntEntry(
p->vVarCube, Vec_IntEntry(vCube, 0)) == -1 )
749 Vec_IntWriteEntry(
p->vVarCube, Vec_IntEntry(vCube, 0), i );
753 int k, n, Lit, Lit2, iDiv;
754 if ( Vec_IntSize(vPivot) < 2 )
760 Vec_IntClear(
p->vCubeFree );
761 Vec_IntPush(
p->vCubeFree, Abc_Var2Lit(Abc_LitNot(Lit), 0) );
762 Vec_IntPush(
p->vCubeFree, Abc_Var2Lit(Abc_LitNot(Lit2), 1) );
763 iDiv = Hsh_VecManAdd(
p->pHash,
p->vCubeFree );
766 if ( Vec_FltSize(
p->vWeights) == iDiv )
768 Vec_FltPush(
p->vWeights, -2 + 0.9 - 0.001 * Fx_ManComputeLevelDiv(
p,
p->vCubeFree));
771 assert( iDiv < Vec_FltSize(
p->vWeights) );
772 Vec_FltAddToEntry(
p->vWeights, iDiv, 1 );
777 assert( iDiv < Vec_FltSize(
p->vWeights) );
778 Vec_FltAddToEntry(
p->vWeights, iDiv, -1 );
783 if ( Vec_QueIsMember(
p->vPrio, iDiv) )
784 Vec_QueUpdate(
p->vPrio, iDiv );
786 Vec_QuePush(
p->vPrio, iDiv );
789 return Vec_IntSize(vPivot) * (Vec_IntSize(vPivot) - 1) / 2;
797 if ( Vec_IntSize(vCube) == 0 || vCube == vPivot )
799 if ( Vec_WecIntHasMark(vCube) && Vec_WecIntHasMark(vPivot) && vCube > vPivot )
801 if ( Vec_IntEntry(vCube, 0) != Vec_IntEntry(vPivot, 0) )
808 if ( Vec_IntSize( vCube ) > Vec_IntSize( vPivot ) )
809 Vec_IntPush(
p->vSCC, Vec_WecLevelId(
p->vCubes, vCube ) );
811 Vec_IntPush(
p->vSCC, Vec_WecLevelId(
p->vCubes, vPivot ) );
815 if ( Vec_IntSize(
p->vCubeFree) == 4 )
817 int Value = Fx_ManDivNormalize(
p->vCubeFree );
820 else if ( Value == 1 )
824 if (
p->fCanonDivs && Value < 0 )
827 if (
p->LitCountMax &&
p->LitCountMax < Vec_IntSize(
p->vCubeFree) )
829 if (
p->fCanonDivs && Vec_IntSize(
p->vCubeFree) == 3 )
831 iDiv = Hsh_VecManAdd(
p->pHash,
p->vCubeFree );
834 if ( iDiv == Vec_FltSize(
p->vWeights) )
835 Vec_FltPush(
p->vWeights, -Vec_IntSize(
p->vCubeFree) + 0.9 - 0.0009 * Fx_ManComputeLevelDiv(
p,
p->vCubeFree));
836 assert( iDiv < Vec_FltSize(
p->vWeights) );
837 Vec_FltAddToEntry(
p->vWeights, iDiv, Base + Vec_IntSize(
p->vCubeFree) - 1 );
842 assert( iDiv < Vec_FltSize(
p->vWeights) );
843 Vec_FltAddToEntry(
p->vWeights, iDiv, -(Base + Vec_IntSize(
p->vCubeFree) - 1) );
848 if ( Vec_QueIsMember(
p->vPrio, iDiv) )
849 Vec_QueUpdate(
p->vPrio, iDiv );
851 Vec_QuePush(
p->vPrio, iDiv );
862 p->pHash = Hsh_VecManStart( 1000 );
863 p->vWeights = Vec_FltAlloc( 1000 );
867 assert(
p->nDivsS == Vec_FltSize(
p->vWeights) );
872 p->vPrio = Vec_QueAlloc( Vec_FltSize(
p->vWeights) );
873 Vec_QueSetPriority(
p->vPrio, Vec_FltArrayP(
p->vWeights) );
876 Vec_QuePush(
p->vPrio, i );
893 int i, CubeId, k = 0;
895 if ( Vec_IntSize(Vec_WecEntry(vCubes, CubeId)) > 0 )
896 Vec_IntWriteEntry( vLit2Cube, k++, CubeId );
897 Vec_IntShrink( vLit2Cube, k );
912static inline int Fx_ManGetCubeVar(
Vec_Wec_t * vCubes,
int iCube ) {
return Vec_IntEntry( Vec_WecEntry(vCubes, iCube), 0 ); }
915 int * pBeg1 = vPart0->pArray;
916 int * pBeg2 = vPart1->pArray;
917 int * pEnd1 = vPart0->pArray + vPart0->nSize;
918 int * pEnd2 = vPart1->pArray + vPart1->nSize;
919 int i, k, i_, k_, fCompl, CubeId1, CubeId2;
920 Vec_IntClear( vPairs );
921 Vec_IntClear( vCompls );
922 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
924 CubeId1 = Fx_ManGetCubeVar(vCubes, *pBeg1);
925 CubeId2 = Fx_ManGetCubeVar(vCubes, *pBeg2);
926 if ( CubeId1 == CubeId2 )
928 for ( i = 1; pBeg1+i < pEnd1; i++ )
929 if ( CubeId1 != Fx_ManGetCubeVar(vCubes, pBeg1[i]) )
931 for ( k = 1; pBeg2+k < pEnd2; k++ )
932 if ( CubeId1 != Fx_ManGetCubeVar(vCubes, pBeg2[k]) )
934 for ( i_ = 0; i_ < i; i_++ )
935 for ( k_ = 0; k_ < k; k_++ )
937 if ( pBeg1[i_] == pBeg2[k_] )
939 Fx_ManDivFindCubeFree( Vec_WecEntry(vCubes, pBeg1[i_]), Vec_WecEntry(vCubes, pBeg2[k_]), vCubeFree, fWarning );
940 fCompl = (Vec_IntSize(vCubeFree) == 4 && Fx_ManDivNormalize(vCubeFree) == 1);
941 if ( !Vec_IntEqual( vDiv, vCubeFree ) )
943 Vec_IntPush( vPairs, pBeg1[i_] );
944 Vec_IntPush( vPairs, pBeg2[k_] );
945 Vec_IntPush( vCompls, fCompl );
950 else if ( CubeId1 < CubeId2 )
970 Vec_Int_t * vCube, * vCube2, * vLitP = NULL, * vLitN = NULL;
972 int i, k, Lit0, Lit1, iVarNew = 0, RetValue, Level;
973 float Diff = Vec_FltEntry(
p->vWeights, iDiv) - (float)((
int)Vec_FltEntry(
p->vWeights, iDiv));
974 assert( Diff > 0.0 && Diff < 1.0 );
978 Vec_IntClear( vDiv );
979 Vec_IntAppend( vDiv, Hsh_VecReadEntry(
p->pHash, iDiv) );
980 Fx_ManDivFindPivots( vDiv, &Lit0, &Lit1 );
981 assert( Lit0 >= 0 && Lit1 >= 0 );
985 Vec_IntClear(
p->vCubesS );
986 if ( Vec_IntSize(vDiv) == 2 )
988 Fx_ManCompressCubes(
p->vCubes, Vec_WecEntry(
p->vLits, Abc_LitNot(Lit0)) );
989 Fx_ManCompressCubes(
p->vCubes, Vec_WecEntry(
p->vLits, Abc_LitNot(Lit1)) );
990 Vec_IntTwoRemoveCommon( Vec_WecEntry(
p->vLits, Abc_LitNot(Lit0)), Vec_WecEntry(
p->vLits, Abc_LitNot(Lit1)),
p->vCubesS );
994 Fx_ManCompressCubes(
p->vCubes, Vec_WecEntry(
p->vLits, Lit0) );
995 Fx_ManCompressCubes(
p->vCubes, Vec_WecEntry(
p->vLits, Lit1) );
996 Fx_ManFindCommonPairs(
p->vCubes, Vec_WecEntry(
p->vLits, Lit0), Vec_WecEntry(
p->vLits, Lit1),
p->vCubesD,
p->vCompls, vDiv,
p->vCubeFree, fWarning );
1005 Vec_WecMarkLevels(
p->vCubes,
p->vCubesS );
1006 Vec_WecMarkLevels(
p->vCubes,
p->vCubesD );
1015 Vec_WecUnmarkLevels(
p->vCubes,
p->vCubesS );
1016 Vec_WecUnmarkLevels(
p->vCubes,
p->vCubesD );
1018 if ( Abc_Lit2Var(Lit0) == Abc_Lit2Var(Lit1) && Vec_IntSize(Hsh_VecReadEntry(
p->pHash, iDiv)) == 2 )
1019 goto ExtractFromPairs;
1022 iVarNew = Vec_WecSize(
p->vLits ) / 2;
1023 assert( Vec_IntSize(
p->vVarCube) == iVarNew );
1024 Vec_IntPush(
p->vVarCube, Vec_WecSize(
p->vCubes) );
1025 vCube = Vec_WecPushLevel(
p->vCubes );
1026 Vec_IntPush( vCube, iVarNew );
1027 if ( Vec_IntSize(vDiv) == 2 )
1029 Vec_IntPush( vCube, Abc_LitNot(Lit0) );
1030 Vec_IntPush( vCube, Abc_LitNot(Lit1) );
1031 Level = 1 + Fx_ManComputeLevelCube(
p, vCube );
1035 vCube2 = Vec_WecPushLevel(
p->vCubes );
1036 vCube = Vec_WecEntry(
p->vCubes, Vec_WecSize(
p->vCubes) - 2 );
1037 Vec_IntPush( vCube2, iVarNew );
1038 Fx_ManDivAddLits( vCube, vCube2, vDiv );
1039 Level = 2 + Abc_MaxInt( Fx_ManComputeLevelCube(
p, vCube), Fx_ManComputeLevelCube(
p, vCube2) );
1041 assert( Vec_IntSize(
p->vLevels) == iVarNew );
1042 Vec_IntPush(
p->vLevels, Level );
1044 p->nLits += Vec_IntSize( vDiv );
1046 vLitP = Vec_WecPushLevel(
p->vLits );
1047 vLitN = Vec_WecPushLevel(
p->vLits );
1048 vLitP = Vec_WecEntry(
p->vLits, Vec_WecSize(
p->vLits) - 2 );
1052 RetValue = Vec_IntRemove1( vCube, Abc_LitNot(Lit0) );
1053 RetValue += Vec_IntRemove1( vCube, Abc_LitNot(Lit1) );
1055 Vec_IntPush( vCube, Abc_Var2Lit(iVarNew, 0) );
1056 Vec_IntPush( vLitP, Vec_WecLevelId(
p->vCubes, vCube) );
1063 assert( Vec_IntSize(
p->vCubesD) % 2 == 0 );
1064 assert( Vec_IntSize(
p->vCubesD) == 2 * Vec_IntSize(
p->vCompls) );
1065 for ( i = 0; i < Vec_IntSize(
p->vCubesD); i += 2 )
1067 int fCompl = Vec_IntEntry(
p->vCompls, i/2);
1068 p->nCompls += fCompl;
1069 vCube = Vec_WecEntry(
p->vCubes, Vec_IntEntry(
p->vCubesD, i) );
1070 vCube2 = Vec_WecEntry(
p->vCubes, Vec_IntEntry(
p->vCubesD, i+1) );
1071 RetValue = Fx_ManDivRemoveLits( vCube, vDiv, fCompl );
1072 RetValue += Fx_ManDivRemoveLits( vCube2, vDiv, fCompl );
1073 assert( RetValue == Vec_IntSize(vDiv) || RetValue == Vec_IntSize( vDiv ) + 1);
1076 if ( Vec_IntSize(vDiv) == 2 || fCompl )
1078 Vec_IntPush( vCube, Abc_Var2Lit(iVarNew, 1) );
1079 Vec_IntPush( vLitN, Vec_WecLevelId(
p->vCubes, vCube) );
1083 Vec_IntPush( vCube, Abc_Var2Lit(iVarNew, 0) );
1084 Vec_IntPush( vLitP, Vec_WecLevelId(
p->vCubes, vCube) );
1087 p->nLits -= Vec_IntSize(vDiv) + Vec_IntSize(vCube2) - 2;
1090 Vec_IntWriteEntry(
p->vCubesD, k++, Vec_WecLevelId(
p->vCubes, vCube) );
1091 Vec_IntClear( vCube2 );
1093 assert( k == Vec_IntSize(
p->vCubesD) / 2 );
1094 Vec_IntShrink(
p->vCubesD, k );
1095 Vec_IntSort(
p->vCubesD, 0 );
1106 Vec_WecMarkLevels(
p->vCubes,
p->vCubesS );
1107 Vec_WecMarkLevels(
p->vCubes,
p->vCubesD );
1116 Vec_WecUnmarkLevels(
p->vCubes,
p->vCubesS );
1117 Vec_WecUnmarkLevels(
p->vCubes,
p->vCubesD );
1120 if ( Vec_IntSize(
p->vSCC ) )
1122 Vec_IntUniqify(
p->vSCC );
1126 Vec_IntClear( vCube );
1128 Vec_IntClear(
p->vSCC );
1131 if ( Vec_IntSize(vDiv) > 2 )
1133 vCube = Vec_WecEntry(
p->vCubes, Vec_WecSize(
p->vCubes) - 2 );
1134 vCube2 = Vec_WecEntry(
p->vCubes, Vec_WecSize(
p->vCubes) - 1 );
1138 Vec_WecPush(
p->vLits, Lit0, Vec_WecLevelId(
p->vCubes, vCube) );
1140 Vec_WecPush(
p->vLits, Lit0, Vec_WecLevelId(
p->vCubes, vCube2) );
1146 Vec_IntTwoRemove( Vec_WecEntry(
p->vLits, Abc_Lit2Var(Lit0)),
p->vCubesD );
1147 if ( (
p->nCompls && i > 1) || Vec_IntSize( vDiv ) == 2 )
1148 Vec_IntTwoRemove( Vec_WecEntry(
p->vLits, Abc_LitNot(Abc_Lit2Var(Lit0))),
p->vCubesD );
1166int Fx_FastExtract(
Vec_Wec_t * vCubes,
int ObjIdMax,
int nNewNodesMax,
int LitCountMax,
int fCanonDivs,
int fVerbose,
int fVeryVerbose )
1168 int fVeryVeryVerbose = 0;
1169 int i, iDiv, fWarning = 0;
1174 p->LitCountMax = LitCountMax;
1175 p->fCanonDivs = fCanonDivs;
1180 Fx_PrintDivisors(
p );
1182 Fx_PrintStats(
p, Abc_Clock() - clk );
1184 p->timeStart = Abc_Clock();
1185 for ( i = 0; i < nNewNodesMax && Vec_QueTopPriority(
p->vPrio) > 0.0; i++ )
1187 iDiv = Vec_QuePop(
p->vPrio);
1189 Fx_PrintDiv(
p, iDiv );
1191 if ( fVeryVeryVerbose )
1192 Fx_PrintDivisors(
p );
1195 Fx_PrintStats(
p, Abc_Clock() - clk );
1198 Vec_WecRemoveEmpty( vCubes );
void Fx_ManCreateDivisors(Fx_Man_t *p)
typedefABC_NAMESPACE_IMPL_START struct Fx_Man_t_ Fx_Man_t
DECLARATIONS ///.
void Fx_ManStop(Fx_Man_t *p)
Vec_Wec_t * Abc_NtkFxRetrieve(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
void Fx_ManCubeDoubleCubeDivisors(Fx_Man_t *p, int iFirst, Vec_Int_t *vPivot, int fRemove, int fUpdate, int *fWarning)
int Fx_ManDivFindCubeFree(Vec_Int_t *vArr1, Vec_Int_t *vArr2, Vec_Int_t *vCubeFree, int *fWarning)
Fx_Man_t * Fx_ManStart(Vec_Wec_t *vCubes)
void Abc_NtkFxInsert(Abc_Ntk_t *pNtk, Vec_Wec_t *vCubes)
void Fx_ManFindCommonPairs(Vec_Wec_t *vCubes, Vec_Int_t *vPart0, Vec_Int_t *vPart1, Vec_Int_t *vPairs, Vec_Int_t *vCompls, Vec_Int_t *vDiv, Vec_Int_t *vCubeFree, int *fWarning)
#define Fx_ManForEachCubeVec(vVec, vCubes, vCube, i)
void Fx_ManUpdate(Fx_Man_t *p, int iDiv, int *fWarning)
void Fx_ManCreateLiterals(Fx_Man_t *p, int nVars)
int Fx_FastExtract(Vec_Wec_t *vCubes, int ObjIdMax, int nNewNodesMax, int LitCountMax, int fCanonDivs, int fVerbose, int fVeryVerbose)
int Fx_ManCubeSingleCubeDivisors(Fx_Man_t *p, Vec_Int_t *vPivot, int fRemove, int fUpdate)
void Fx_ManComputeLevel(Fx_Man_t *p)
int Abc_NtkFxPerform(Abc_Ntk_t *pNtk, int nNewNodesMax, int LitCountMax, int fCanonDivs, int fVerbose, int fVeryVerbose)
int Abc_NtkFxCheck(Abc_Ntk_t *pNtk)
struct Abc_Obj_t_ Abc_Obj_t
ABC_DLL char * Abc_SopStart(Mem_Flex_t *pMan, int nCubes, int nVars)
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
#define Abc_ObjForEachFanin(pObj, pFanin, i)
ABC_DLL void Abc_SopComplement(char *pSop)
#define Abc_CubeForEachVar(pCube, Value, i)
struct Abc_Ntk_t_ Abc_Ntk_t
#define Abc_SopForEachCube(pSop, nFanins, pCube)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
ABC_DLL void Abc_ObjRemoveFanins(Abc_Obj_t *pObj)
ABC_DLL int Abc_SopIsComplement(char *pSop)
#define Abc_NtkForEachNode(pNtk, pNode, i)
#define ABC_SWAP(Type, a, b)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Mem_Flex_t_ Mem_Flex_t
#define Vec_FltForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Flt_t_ Vec_Flt_t
INCLUDES ///.
struct Hsh_VecMan_t_ Hsh_VecMan_t
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Que_t_ Vec_Que_t
INCLUDES ///.
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
#define Vec_WecForEachLevelStart(vGlob, vVec, i, LevelStart)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.