45static inline word Abc_NtkSharePack(
int Lev,
int Id ) {
return (((
word)Lev) << 32) | Id; }
46static inline int Abc_NtkShareUnpackLev(
word Num ) {
return (Num >> 32); }
47static inline int Abc_NtkShareUnpackId(
word Num ) {
return Num & 0xFFFFFFFF; }
70 p->vObj2Lit = Vec_IntAlloc( 1000 );
79 Vec_PtrFreeP( &
p->vBuckets );
80 Vec_IntFreeP( &
p->vObj2Lit );
99 Abc_Obj_t * pObjC, * pObj0, * pObj1, * pRoot = NULL;
102 int i, k, fCompl = 0;
103 assert( !Abc_ObjIsComplement(pObj) );
106 vSuper = Vec_WrdAlloc( 10 );
107 Vec_WrdPush( vSuper, Abc_NtkSharePack(Abc_ObjLevel(pObj), Abc_ObjId(pObj)) );
108 while ( Vec_WrdSize(vSuper) > 0 )
111 Num = Vec_WrdEntry( vSuper, 0 );
120 pRoot = Abc_NtkObj( pNtk, Abc_NtkShareUnpackId(Num) );
123 Vec_WrdRemove( vSuper, Num );
131 assert( pObj1 == Abc_ObjNot(pObj0) );
132 fCompl ^= Abc_ObjIsComplement(pObjC); pObjC = Abc_ObjRegular(pObjC);
133 fCompl ^= Abc_ObjIsComplement(pObj0); pObj0 = Abc_ObjRegular(pObj0);
134 Vec_WrdPushOrder( vSuper, Abc_NtkSharePack(Abc_ObjLevel(pObjC), Abc_ObjId(pObjC)) );
135 Vec_WrdPushOrder( vSuper, Abc_NtkSharePack(Abc_ObjLevel(pObj0), Abc_ObjId(pObj0)) );
141 if ( i + 1 == Vec_WrdSize(vSuper) )
143 Vec_WrdWriteEntry( vSuper, k++, Num );
146 NumNext = Vec_WrdEntry( vSuper, i+1 );
148 if ( Num == NumNext )
151 Vec_WrdWriteEntry( vSuper, k++, Num );
153 Vec_WrdShrink( vSuper, k );
157 Vec_WrdWriteEntry( vSuper, i, Abc_NtkShareUnpackId(Num) );
163 Abc_Obj_t * pObj0, * pObj1, * pRoot = NULL;
167 assert( !Abc_ObjIsComplement(pObj) );
169 vSuper = Vec_WrdAlloc( 10 );
170 Vec_WrdPush( vSuper, Abc_NtkSharePack(Abc_ObjLevel(pObj), Abc_ObjToLit(pObj)) );
171 while ( Vec_WrdSize(vSuper) > 0 )
174 Num = Vec_WrdEntry( vSuper, 0 );
183 pRoot = Abc_ObjFromLit( pNtk, Abc_NtkShareUnpackId(Num) );
184 if ( !Abc_ObjIsComplement(pRoot) && Abc_ObjIsNode(pRoot) )
186 Vec_WrdRemove( vSuper, Num );
192 assert( Abc_ObjIsNode(pRoot) );
194 pObj0 = Abc_ObjChild0(pRoot);
195 pObj1 = Abc_ObjChild1(pRoot);
196 assert( Abc_ObjIsNode(Abc_ObjRegular(pObj0)) || Abc_ObjIsCi(Abc_ObjRegular(pObj0)) );
197 assert( Abc_ObjIsNode(Abc_ObjRegular(pObj1)) || Abc_ObjIsCi(Abc_ObjRegular(pObj1)) );
198 Vec_WrdPushOrder( vSuper, Abc_NtkSharePack(Abc_ObjLevel(Abc_ObjRegular(pObj0)), Abc_ObjToLit(pObj0)) );
199 Vec_WrdPushOrder( vSuper, Abc_NtkSharePack(Abc_ObjLevel(Abc_ObjRegular(pObj1)), Abc_ObjToLit(pObj1)) );
205 if ( i + 1 == Vec_WrdSize(vSuper) )
207 Vec_WrdWriteEntry( vSuper, k++, Num );
210 NumNext = Vec_WrdEntry( vSuper, i+1 );
212 if ( Num + 1 == NumNext && (NumNext & 1) )
214 Vec_WrdClear( vSuper );
218 Vec_WrdWriteEntry( vSuper, k++, Num );
220 Vec_WrdShrink( vSuper, k );
223 Vec_WrdWriteEntry( vSuper, i, Abc_NtkShareUnpackId(Num) );
240 if ( Abc_NodeIsTravIdCurrent( pObj ) )
242 Abc_NodeSetTravIdCurrent( pObj );
243 if ( Abc_ObjIsCi(pObj) )
245 assert( Abc_ObjIsNode(pObj) );
252 if ( Vec_WrdSize(vSuper) <= 1 || Vec_WrdSize(vSuper) >=
p->nMultiSize )
257 if ( vInput == NULL )
259 vInput = Vec_IntAlloc( 10 );
260 Vec_IntPush( vInput, Abc_Var2Lit((
int)Num, 0) );
261 Vec_IntPush( vInput, Abc_ObjLevel(Abc_NtkObj(
p->pNtk, (
int)Num)) );
263 Vec_PtrWriteEntry( vInputs, (
int)Num, vInput );
265 Vec_IntPush( vInput, Vec_IntSize(
p->vObj2Lit) );
267 Vec_IntPush(
p->vObj2Lit, Abc_Var2Lit(Abc_ObjId(pObj), fCompl) );
272 Vec_WrdFree( vSuper );
285 if ( Abc_NodeIsTravIdCurrent( pObj ) )
287 Abc_NodeSetTravIdCurrent( pObj );
288 if ( Abc_ObjIsCi(pObj) )
290 assert( Abc_ObjIsNode(pObj) );
292 if ( Vec_WrdSize(vSuper) <= 1 || Vec_WrdSize(vSuper) >=
p->nMultiSize )
297 if ( vInput == NULL )
299 vInput = Vec_IntAlloc( 10 );
300 Vec_IntPush( vInput, (
int)Num );
301 Vec_IntPush( vInput, Abc_ObjLevel(Abc_NtkObj(
p->pNtk, Abc_Lit2Var((
int)Num))) );
303 Vec_PtrWriteEntry( vInputs, (
int)Num, vInput );
305 Vec_IntPush( vInput, Vec_IntSize(
p->vObj2Lit) );
307 Vec_IntPush(
p->vObj2Lit, Abc_ObjToLit(pObj) );
312 Vec_WrdFree( vSuper );
322 vInputs = Vec_PtrStart( Abc_NtkObjNumMax(
p->pNtk) * (1 + fAnd) );
323 Abc_NtkIncrementTravId(
p->pNtk );
327 if ( Abc_ObjIsNode(Abc_ObjFanin0(pObj)) )
333 if ( Abc_ObjIsNode(Abc_ObjFanin0(pObj)) )
336 p->nStartCols = Vec_IntSize(
p->vObj2Lit);
342 nOnesMax = Abc_MaxInt( nOnesMax, Vec_IntSize(vInput)-
SHARE_NUM );
346 p->vBuckets = Vec_PtrAlloc( nOnesMax + 1 );
347 for ( i = 0; i <= nOnesMax; i++ )
348 Vec_PtrPush(
p->vBuckets, Vec_PtrAlloc(10) );
353 Vec_PtrPush( (
Vec_Ptr_t *)Vec_PtrEntry(
p->vBuckets, Vec_IntSize(vInput)-
SHARE_NUM), vInput );
354 Vec_PtrFree( vInputs );
373 char * pBuffer =
ABC_ALLOC(
char, Vec_IntSize(
p->vObj2Lit) + 1 );
374 int * pCounters =
ABC_CALLOC(
int, Vec_IntSize(
p->vObj2Lit) + 1 );
379 for ( k = 0; k < Vec_IntSize(
p->vObj2Lit); k++ )
385 assert( ObjId < Vec_IntSize(
p->vObj2Lit) );
386 pBuffer[ObjId] =
'1';
389 printf(
"%4d%3d: %s\n", Vec_IntEntry(vInput, 0), Vec_IntEntry(vInput, 1), pBuffer );
392 for ( i = 0; i < Vec_IntSize(
p->vObj2Lit); i++ )
393 if ( pCounters[i] > 0 )
394 printf(
"%d=%d ", i, pCounters[i] );
398 for ( i = 0; i <
p->nStartCols; i++ )
399 nTotal += pCounters[i] - 1;
400 printf(
"Total = %d. ",
nTotal );
401 printf(
"Gates = %d.\n", Vec_IntSize(
p->vObj2Lit) -
p->nStartCols +
nTotal );
406 printf(
"Bucket contents: " );
408 printf(
"%d ", Vec_PtrSize(vBucket) );
429 pFile = fopen(
"multi_and.blif",
"wb" );
432 printf(
"Cannot open output file.\n" );
435 fprintf( pFile,
".model %s\n",
"multi_and" );
436 fprintf( pFile,
".inputs" );
437 for ( i = 0; i < Abc_NtkCiNum(
p); i++ )
438 fprintf( pFile,
" i%d", i );
439 fprintf( pFile,
"\n" );
440 fprintf( pFile,
".outputs" );
441 for ( i = 0; i < Abc_NtkCoNum(
p); i++ )
442 fprintf( pFile,
" o%d", i );
443 fprintf( pFile,
"\n" );
446 for ( i = 0; i < Abc_NtkCoNum(
p); i++ )
448 pObj = Abc_NtkCo(
p, i );
450 fprintf( pFile,
".names" );
452 fprintf( pFile,
" i%d", pObj->
iTemp );
453 fprintf( pFile,
" o%d\n", i );
455 fprintf( pFile,
"1" );
456 fprintf( pFile,
" 1\n" );
457 Vec_PtrFree( vSupp );
459 fprintf( pFile,
".end\n\n" );
478 Vec_Ptr_t * vPool = Vec_PtrAlloc( nPoolSize );
480 Vec_Int_t * vInput, * vInput2, * vInputBest = NULL, * vInputBest2 = NULL;
481 int i, k, Cost, CostBest = 0, Delay, DelayBest = 0;
486 Vec_PtrPush( vPool, vInput );
487 if ( Vec_PtrSize(vPool) == nPoolSize )
503 Cost = Vec_IntTwoCountCommon(vInput, vInput2);
513 Delay = Abc_MaxInt( Vec_IntEntry(vInput, 1), Vec_IntEntry(vInput2, 1) );
515 if ( CostBest < Cost || (CostBest == Cost && (DelayBest > Delay)) )
520 vInputBest2 = vInput2;
523 Vec_PtrFree( vPool );
525 *pvInput = vInputBest;
526 *pvInput2 = vInputBest2;
528 if ( vInputBest == NULL )
543 if ( vInput == NULL )
547 pObj0 = Abc_ObjFromLit(
p->pNtk, Vec_IntEntry(vInput, 0) );
548 pObj1 = Abc_ObjFromLit(
p->pNtk, Vec_IntEntry(vInput2, 0) );
556 vOld1 = Vec_IntAlloc( 16 ); Vec_IntPush( vOld1, Vec_IntEntry(vInput, 0) ); Vec_IntPush( vOld1, Vec_IntEntry(vInput, 1) );
557 vOld2 = Vec_IntAlloc( 16 ); Vec_IntPush( vOld2, Vec_IntEntry(vInput2, 0) ); Vec_IntPush( vOld2, Vec_IntEntry(vInput2, 1) );
558 vNew = Vec_IntAlloc( 16 ); Vec_IntPush( vNew, Abc_ObjToLit(pObj) ); Vec_IntPush( vNew, Abc_ObjLevel(Abc_ObjRegular(pObj)) );
566 Vec_IntTwoSplit( vInput, vInput2, vNew, vOld1, vOld2 );
574 Vec_IntPush( vOld1, Vec_IntSize(
p->vObj2Lit) );
575 Vec_IntPush( vOld2, Vec_IntSize(
p->vObj2Lit) );
576 Vec_IntPush(
p->vObj2Lit, Abc_ObjToLit(pObj) );
578 Vec_PtrPush( (
Vec_Ptr_t *)Vec_PtrEntry(
p->vBuckets, Vec_IntSize(vOld1)-
SHARE_NUM), vOld1 );
579 Vec_PtrPush( (
Vec_Ptr_t *)Vec_PtrEntry(
p->vBuckets, Vec_IntSize(vOld2)-
SHARE_NUM), vOld2 );
582 Vec_IntFree( vInput );
583 Vec_IntFree( vInput2 );
604 int i, j, k, ObjId, iLit;
607 vOrig = Vec_PtrAlloc(
p->nStartCols );
608 vRepl = Vec_PtrAlloc(
p->nStartCols );
609 for ( i = 0; i <
p->nStartCols; i++ )
611 iLit = Vec_IntEntry(
p->vObj2Lit, i );
612 assert( !fAnd || !Abc_LitIsCompl(iLit) );
614 pObj = Abc_NtkObj(
p->pNtk, Abc_Lit2Var(iLit) );
619 pNew = Abc_ObjNotCond(
Abc_AigConst1(
p->pNtk), !Abc_LitIsCompl(iLit) );
621 Vec_PtrPush( vOrig, pObj );
622 Vec_PtrPush( vRepl, pNew );
633 assert( ObjId < Vec_IntSize(
p->vObj2Lit) );
634 if ( ObjId >=
p->nStartCols )
636 assert( ObjId < p->nStartCols );
637 iLit = Vec_IntEntry( vInput, 0 );
639 pNew = (
Abc_Obj_t *)Vec_PtrEntry( vRepl, ObjId );
644 Vec_PtrWriteEntry( vRepl, ObjId, pNew );
650 printf(
"Total gates collected = %d. Total gates constructed = %d.\n",
p->nFoundGates,
p->nCountGates );
653 vMap2Repl = Vec_IntStartFull( Abc_NtkObjNumMax(
p->pNtk) );
657 Vec_IntWriteEntry( vMap2Repl, Abc_ObjId(pObj), Abc_ObjToLit((
Abc_Obj_t *)Vec_PtrEntry(vRepl, i)) );
659 Vec_PtrFree( vOrig );
660 Vec_PtrFree( vRepl );
665 if ( Abc_ObjIsCo(pObj) || Abc_ObjIsNode(pObj) )
667 iLit = Vec_IntEntry( vMap2Repl, Abc_ObjFaninId0(pObj) );
670 if ( iLit == iLitConst1 && fAnd )
673 Vec_IntWriteEntry( &pObj->
vFanins, 0, Abc_Lit2Var(iLitConst1) );
677 pObj->
fCompl0 ^= Abc_LitIsCompl(iLit);
678 Vec_IntWriteEntry( &pObj->
vFanins, 0, Abc_Lit2Var(iLit) );
682 if ( Abc_ObjIsNode(pObj) )
684 iLit = Vec_IntEntry( vMap2Repl, Abc_ObjFaninId1(pObj) );
687 if ( iLit == iLitConst1 && fAnd )
690 Vec_IntWriteEntry( &pObj->
vFanins, 1, Abc_Lit2Var(iLitConst1) );
694 pObj->
fCompl1 ^= Abc_LitIsCompl(iLit);
695 Vec_IntWriteEntry( &pObj->
vFanins, 1, Abc_Lit2Var(iLit) );
700 Vec_IntFree( vMap2Repl );
725 assert( Abc_NtkIsStrash(pNtk) );
728 p->nMultiSize = nMultiSize;
729 p->fVerbose = fVerbose;
731 if (
p->nStartCols < 2 )
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL Abc_Obj_t * Abc_AigXor(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
struct Abc_Aig_t_ Abc_Aig_t
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL Vec_Ptr_t * Abc_NtkNodeSupport(Abc_Ntk_t *pNtk, Abc_Obj_t **ppNodes, int nNodes)
ABC_DLL Abc_Ntk_t * Abc_NtkBalanceExor(Abc_Ntk_t *pNtk, int fUpdateLevel, int fVerbose)
ABC_DLL Abc_Obj_t * Abc_AigAnd(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
#define Abc_NtkForEachCi(pNtk, pCi, i)
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Ntk_t * Abc_NtkBalance(Abc_Ntk_t *pNtk, int fDuplicate, int fSelective, int fUpdateLevel)
FUNCTION DEFINITIONS ///.
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
ABC_DLL Abc_Obj_t * Abc_AigConst1(Abc_Ntk_t *pNtk)
ABC_DLL int Abc_NodeIsExorType(Abc_Obj_t *pNode)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Aig_ManStop(Aig_Man_t *p)
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
int nTotal
DECLARATIONS ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Gia_Man_t * Gia_ManFromAig(Aig_Man_t *p)
INCLUDES ///.
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkFromAigPhase(Aig_Man_t *pMan)
DECLARATIONS ///.
Aig_Man_t * Abc_NtkToDar(Abc_Ntk_t *pNtk, int fExors, int fRegisters)
struct Gia_Man_t_ Gia_Man_t
unsigned __int64 word
DECLARATIONS ///.
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
#define Vec_PtrForEachEntryReverse(Type, vVec, pEntry, i)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_WrdForEachEntryStart(vVec, Entry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
#define Vec_WrdForEachEntryReverse(vVec, pEntry, i)