36#define AU_MAX_FANINS 0x1FFFFFFF
112static inline int Au_Var2Lit(
int Var,
int fCompl ) {
return Var +
Var + fCompl; }
113static inline int Au_Lit2Var(
int Lit ) {
return Lit >> 1; }
114static inline int Au_LitIsCompl(
int Lit ) {
return Lit & 1; }
115static inline int Au_LitNot(
int Lit ) {
return Lit ^ 1; }
116static inline int Au_LitNotCond(
int Lit,
int c ) {
return Lit ^ (int)(c > 0); }
117static inline int Au_LitRegular(
int Lit ) {
return Lit & ~01; }
122static inline int Au_IsComplement(
Au_Obj_t *
p ) {
return (
int)((ABC_PTRUINT_T)(
p) & 01); }
124static inline char * Au_UtilStrsav(
char * s ) {
return s ?
strcpy(
ABC_ALLOC(
char,
strlen(s)+1), s) : NULL; }
126static inline char * Au_ManName(
Au_Man_t *
p ) {
return p->pName; }
127static inline int Au_ManNtkNum(
Au_Man_t *
p ) {
return Vec_PtrSize(&
p->vNtks) - 1; }
131static inline char * Au_NtkName(
Au_Ntk_t *
p ) {
return p->pName; }
139static inline int Au_NtkObjNumMax(
Au_Ntk_t *
p ) {
return (Vec_PtrSize(&
p->vPages) - 1) * (1 << 12) +
p->iHandle; }
140static inline int Au_NtkObjNum(
Au_Ntk_t *
p ) {
return Vec_IntSize(&
p->vObjs); }
143static inline Au_Obj_t * Au_NtkPi(
Au_Ntk_t *
p,
int i ) {
return Au_NtkObj(
p, Vec_IntEntry(&
p->vPis, i)); }
144static inline Au_Obj_t * Au_NtkPo(
Au_Ntk_t *
p,
int i ) {
return Au_NtkObj(
p, Vec_IntEntry(&
p->vPos, i)); }
145static inline Au_Obj_t * Au_NtkObjI(
Au_Ntk_t *
p,
int i ) {
return Au_NtkObj(
p, Vec_IntEntry(&
p->vObjs, i)); }
157static inline char * Au_ObjBase(
Au_Obj_t *
p ) {
return (
char *)
p - ((ABC_PTRINT_T)
p & 0x3FF); }
159static inline int Au_ObjId(
Au_Obj_t *
p ) {
return ((
int *)Au_ObjBase(
p))[2] | (((ABC_PTRINT_T)
p & 0x3FF) >> 4); }
160static inline int Au_ObjPioNum(
Au_Obj_t *
p ) {
assert(Au_ObjIsTerm(
p));
return p->Fanins[
p->nFanins]; }
161static inline int Au_ObjFunc(
Au_Obj_t *
p ) {
return p->Func; }
162static inline Au_Ntk_t * Au_ObjModel(
Au_Obj_t *
p ) {
assert(Au_ObjIsFan(
p)||Au_ObjIsBox(
p));
return Au_ManNtk(Au_NtkMan(Au_ObjNtk(
p)),
p->Func); }
164static inline int Au_ObjFaninNum(
Au_Obj_t *
p ) {
return p->nFanins; }
165static inline int Au_ObjFaninId(
Au_Obj_t *
p,
int i ) {
assert(i >= 0 && i < (
int)
p->nFanins &&
p->Fanins[i]);
return Au_Lit2Var(
p->Fanins[i]); }
166static inline int Au_ObjFaninId0(
Au_Obj_t *
p ) {
return Au_ObjFaninId(
p, 0); }
167static inline int Au_ObjFaninId1(
Au_Obj_t *
p ) {
return Au_ObjFaninId(
p, 1); }
168static inline int Au_ObjFaninId2(
Au_Obj_t *
p ) {
return Au_ObjFaninId(
p, 2); }
169static inline Au_Obj_t * Au_ObjFanin(
Au_Obj_t *
p,
int i ) {
return Au_NtkObj(Au_ObjNtk(
p), Au_ObjFaninId(
p, i)); }
173static inline int Au_ObjFaninC(
Au_Obj_t *
p,
int i ) {
assert(i >= 0 && i < (
int)
p->nFanins &&
p->Fanins[i]);
return Au_LitIsCompl(
p->Fanins[i]); }
174static inline int Au_ObjFaninC0(
Au_Obj_t *
p ) {
return Au_ObjFaninC(
p, 0); }
175static inline int Au_ObjFaninC1(
Au_Obj_t *
p ) {
return Au_ObjFaninC(
p, 1); }
176static inline int Au_ObjFaninC2(
Au_Obj_t *
p ) {
return Au_ObjFaninC(
p, 2); }
177static inline int Au_ObjFaninLit(
Au_Obj_t *
p,
int i ) {
assert(i >= 0 && i < (
int)
p->nFanins &&
p->Fanins[i]);
return p->Fanins[i]; }
178static inline void Au_ObjSetFanin(
Au_Obj_t *
p,
int i,
int f ) {
assert(f > 0 &&
p->Fanins[i] == 0);
p->Fanins[i] = Au_Var2Lit(f,0); }
179static inline void Au_ObjSetFaninLit(
Au_Obj_t *
p,
int i,
int f){
assert(f >= 0 &&
p->Fanins[i] == 0);
p->Fanins[i] = f; }
181static inline int Au_BoxFanoutNum(
Au_Obj_t *
p ) {
assert(Au_ObjIsBox(
p));
return p->Fanins[
p->nFanins]; }
182static inline int Au_BoxFanoutId(
Au_Obj_t *
p,
int i ) {
assert(i >= 0 && i < Au_BoxFanoutNum(
p));
return p->Fanins[
p->nFanins+1+i]; }
183static inline Au_Obj_t * Au_BoxFanout(
Au_Obj_t *
p,
int i ) {
return Au_NtkObj(Au_ObjNtk(
p), Au_BoxFanoutId(
p, i)); }
185static inline int Au_ObjCopy(
Au_Obj_t *
p ) {
return Vec_IntEntry( &Au_ObjNtk(
p)->vCopies, Au_ObjId(
p) ); }
186static inline void Au_ObjSetCopy(
Au_Obj_t *
p,
int c ) { Vec_IntWriteEntry( &Au_ObjNtk(
p)->vCopies, Au_ObjId(
p), c ); }
188static inline int Au_ObjFanout(
Au_Obj_t *
p,
int i ) {
assert(
p->Type ==
AU_OBJ_BOX && i >= 0 && i < p->Fanins[
p->nFanins] &&
p->Fanins[i]);
return p->Fanins[
p->nFanins + 1 + i]; }
189static inline void Au_ObjSetFanout(
Au_Obj_t *
p,
int i,
int f ) {
assert(
p->Type ==
AU_OBJ_BOX && i >= 0 && i < p->Fanins[
p->nFanins] &&
p->Fanins[i] == 0 && f > 0);
p->Fanins[
p->nFanins + 1 + i] = f; }
191static inline void Au_NtkIncrementTravId(
Au_Ntk_t *
p ) {
if (
p->vTravIds.pArray == NULL) Vec_IntFill(&
p->vTravIds, Au_NtkObjNumMax(
p)+500, 0);
p->nTravIds++;
assert(
p->nTravIds < (1<<30)); }
192static inline void Au_ObjSetTravIdCurrent(
Au_Obj_t *
p ) { Vec_IntSetEntry(&Au_ObjNtk(
p)->vTravIds, Au_ObjId(
p), Au_ObjNtk(
p)->nTravIds ); }
193static inline void Au_ObjSetTravIdPrevious(
Au_Obj_t *
p ) { Vec_IntSetEntry(&Au_ObjNtk(
p)->vTravIds, Au_ObjId(
p), Au_ObjNtk(
p)->nTravIds-1 ); }
194static inline int Au_ObjIsTravIdCurrent(
Au_Obj_t *
p ) {
return (Vec_IntGetEntry(&Au_ObjNtk(
p)->vTravIds, Au_ObjId(
p)) == Au_ObjNtk(
p)->nTravIds); }
195static inline int Au_ObjIsTravIdPrevious(
Au_Obj_t *
p ) {
return (Vec_IntGetEntry(&Au_ObjNtk(
p)->vTravIds, Au_ObjId(
p)) == Au_ObjNtk(
p)->nTravIds-1); }
196static inline void Au_ObjSetTravIdCurrentId(
Au_Ntk_t *
p,
int Id ) { Vec_IntSetEntry(&
p->vTravIds, Id,
p->nTravIds ); }
197static inline int Au_ObjIsTravIdCurrentId(
Au_Ntk_t *
p,
int Id ) {
return (Vec_IntGetEntry(&
p->vTravIds, Id) ==
p->nTravIds); }
199#define Au_ManForEachNtk( p, pNtk, i ) \
200 for ( i = 1; (i < Vec_PtrSize(&p->vNtks)) && (((pNtk) = Au_ManNtk(p, i)), 1); i++ )
201#define Au_ManForEachNtkReverse( p, pNtk, i ) \
202 for ( i = Vec_PtrSize(&p->vNtks) - 1;(i>=1) && (((pNtk) = Au_ManNtk(p, i)), 1); i-- )
204#define Au_ObjForEachFaninId( pObj, hFanin, i ) \
205 for ( i = 0; (i < Au_ObjFaninNum(pObj)) && (((hFanin) = Au_ObjFaninId(pObj, i)), 1); i++ )
206#define Au_BoxForEachFanoutId( pObj, hFanout, i) \
207 for ( i = 0; (i < Au_BoxFanoutNum(pObj)) && (((hFanout) = Au_BoxFanoutId(pObj, i)), 1); i++ )
209#define Au_ObjForEachFanin( pObj, pFanin, i ) \
210 for ( i = 0; (i < Au_ObjFaninNum(pObj)) && (((pFanin) = Au_ObjFanin(pObj, i)), 1); i++ )
211#define Au_BoxForEachFanout( pObj, pFanout, i) \
212 for ( i = 0; (i < Au_BoxFanoutNum(pObj)) && (((pFanout) = Au_BoxFanout(pObj, i)), 1); i++ )
214#define Au_NtkForEachPi( p, pObj, i ) \
215 for ( i = 0; (i < Vec_IntSize(&p->vPis)) && (((pObj) = Au_NtkPi(p, i)), 1); i++ )
216#define Au_NtkForEachPo( p, pObj, i ) \
217 for ( i = 0; (i < Vec_IntSize(&p->vPos)) && (((pObj) = Au_NtkPo(p, i)), 1); i++ )
218#define Au_NtkForEachObj( p, pObj, i ) \
219 for ( i = 0; (i < Vec_IntSize(&p->vObjs)) && (((pObj) = Au_NtkObjI(p, i)), 1); i++ )
220#define Au_NtkForEachNode( p, pObj, i ) \
221 for ( i = 0; (i < Vec_IntSize(&p->vObjs)) && (((pObj) = Au_NtkObjI(p, i)), 1); i++ ) if ( !Au_ObjIsNode(pObj) ) {} else
222#define Au_NtkForEachBox( p, pObj, i ) \
223 for ( i = 0; (i < Vec_IntSize(&p->vObjs)) && (((pObj) = Au_NtkObjI(p, i)), 1); i++ ) if ( !Au_ObjIsBox(pObj) ) {} else
249 p->pName = Au_UtilStrsav( pName );
250 p->vChunks = Vec_PtrAlloc( 111 );
251 Vec_IntGrow( &
p->vPis, 111 );
252 Vec_IntGrow( &
p->vPos, 111 );
253 Vec_IntGrow( &
p->vObjs, 1111 );
254 Vec_PtrGrow( &
p->vPages, 11 );
261 Vec_PtrFreeFree(
p->vChunks );
274 Mem += 4 *
p->vPis.nCap;
275 Mem += 4 *
p->vPos.nCap;
276 Mem += 4 *
p->vObjs.nCap;
277 Mem += 16 *
p->nObjsAlloc;
282 printf(
"%-30s:", Au_NtkName(
p) );
283 printf(
" i/o =%6d/%6d", Au_NtkPiNum(
p), Au_NtkPoNum(
p) );
284 if ( Au_NtkFlopNum(
p) )
285 printf(
" lat =%5d", Au_NtkFlopNum(
p) );
286 printf(
" nd =%6d", Au_NtkNodeNum(
p) );
288 printf(
" box =%5d", Au_NtkBoxNum(
p) );
289 printf(
" obj =%7d", Au_NtkObjNum(
p) );
292 printf(
" %5.1f %%", 100.0 * (Au_NtkObjNumMax(
p) - Au_NtkObjNum(
p)) / Au_NtkObjNumMax(
p) );
294 printf(
" %5.1f %%", 100.0 * (
p->nObjsAlloc -
p->nObjsUsed) /
p->nObjsAlloc );
299 Vec_IntFill( &
p->vCopies, Au_NtkObjNumMax(
p), -1 );
305 if (
p->pMan &&
p->pMan->pFuncs )
309 Counter += (pObj->
Func == (unsigned)Func);
331 p->pName = Au_UtilStrsav( pName );
332 Vec_PtrGrow( &
p->vNtks, 111 );
333 Vec_PtrPush( &
p->vNtks, NULL );
339 if ( --
p->nRefs > 0 )
359 if ( !
strcmp(Au_NtkName(pNtk), pName) )
368 return Au_ManNtk(
p, iNtk );
373 p->pMan = pMan; pMan->
nRefs++;
374 p->Id = Vec_PtrSize( &pMan->
vNtks );
375 Vec_PtrPush( &pMan->
vNtks,
p );
397 if ( Vec_PtrSize(&
p->vNtks) > 2 )
398 printf(
"Design %-13s\n", Au_ManName(
p) );
419 pBoxModel = Au_ObjModel(pObj);
420 if ( pBoxModel == NULL || pBoxModel == pNtk )
424 Vec_IntPush( vOrder, pNtk->
Id );
436 vOrder = Vec_IntAlloc( Au_ManNtkNum(
p)+1 );
437 Vec_IntPush( vOrder, 0 );
439 assert( Vec_IntEntryLast(vOrder) == pRoot->
Id );
441 Vec_IntPop( vOrder );
443 if ( pNtk->
fMark == 0 )
444 Vec_IntPush( vOrder, pNtk->
Id );
445 Vec_IntPush( vOrder, pRoot->
Id );
446 assert( Vec_IntSize(vOrder) == Au_ManNtkNum(
p)+1 );
450 Vec_IntReverseOrder( vOrder );
454 vNtksNew = Vec_PtrAlloc( Au_ManNtkNum(
p)+1 );
456 Vec_PtrPush( vNtksNew, Au_ManNtk(
p, Entry) );
458 assert( Vec_IntEntry(vOrder, 1) == pRoot->
Id );
459 vOrder = Vec_IntInvert( vTemp = vOrder, 0 );
460 Vec_IntFree( vTemp );
461 assert( Vec_IntEntry(vOrder, 1) == pRoot->
Id );
465 pNtk->
Id = Vec_IntEntry( vOrder, pNtk->
Id );
468 pBox->
Func = Vec_IntEntry( vOrder, pBox->
Func );
476 p->vNtks.pArray = vNtksNew->pArray;
477 vNtksNew->pArray = NULL;
478 Vec_PtrFree( vNtksNew );
483 pBoxModel = Au_ObjModel(pBox);
484 if ( pBoxModel == NULL || pBoxModel == pNtk )
487 assert( Au_ObjFaninNum(pBox) == Au_NtkPiNum(pBoxModel) );
488 assert( Au_BoxFanoutNum(pBox) == Au_NtkPoNum(pBoxModel) );
490 Vec_IntFree( vOrder );
499 pNtk->
nBoxes = Au_NtkBoxNum(pNtk);
500 pNtk->
nNodes = Au_NtkNodeNum(pNtk);
501 pNtk->
nPorts = Au_NtkPiNum(pNtk) + Au_NtkPoNum(pNtk);
509 pBoxModel = Au_ObjModel(pBox);
510 if ( pBoxModel == NULL || pBoxModel == pNtk )
512 assert( Au_ObjFaninNum(pBox) == Au_NtkPiNum(pBoxModel) );
513 assert( Au_BoxFanoutNum(pBox) == Au_NtkPoNum(pBoxModel) );
526 pNtk = Au_ManNtkRoot(
p);
527 printf(
"Total nodes = %15.0f. Total instances = %15.0f. Total ports = %15.0f.\n",
533 printf(
"Total ANDs = %15.0f.\n", pNtk->
nNodeAnds );
534 printf(
"Total XORs = %15.0f.\n", pNtk->
nNodeXors );
535 printf(
"Total MUXes = %15.0f.\n", pNtk->
nNodeMuxs );
541 return strcmp( Au_NtkName(*p1), Au_NtkName(*p2) );
550 if ( pNtk->
pMan == NULL )
552 printf(
"There is no hierarchy information.\n" );
576 vCounts = Vec_IntStart( Vec_PtrSize(vMods) );
579 if ( Au_NtkBoxNum(pModel) == 0 )
581 Vec_IntFill( vCounts, Vec_IntSize(vCounts), 0 );
584 pBoxModel = Au_ObjModel(pObj);
585 if ( pBoxModel == NULL || pBoxModel == pModel )
587 Num = Vec_PtrFind( vMods, pBoxModel );
588 assert( Num >= 0 && Num < Vec_PtrSize(vMods) );
589 Vec_IntAddToEntry( vCounts, Num, 1 );
594 printf(
"%-30s : ", Au_NtkName(pModel) );
595 printf(
"PI=%6d ", Au_NtkPiNum(pModel) );
596 printf(
"PO=%6d ", Au_NtkPoNum(pModel) );
597 printf(
"BB=%6d ", Au_NtkBoxNum(pModel) );
598 printf(
"ND=%6d ", Au_NtkNodeNum(pModel) );
604 printf(
"%15d : %s\n", Num, Au_NtkName((
Au_Ntk_t *)Vec_PtrEntry(vMods, k)) );
606 Vec_IntFree( vCounts );
609 if ( Au_NtkBoxNum(pModel) != 0 )
612 printf(
"%-30s : ", Au_NtkName(pModel) );
613 printf(
"PI=%6d ", Au_NtkPiNum(pModel) );
614 printf(
"PO=%6d ", Au_NtkPoNum(pModel) );
615 printf(
"BB=%6d ", Au_NtkBoxNum(pModel) );
616 printf(
"ND=%6d ", Au_NtkNodeNum(pModel) );
623 if ( Au_NtkPiNum(*p1) - Au_NtkPiNum(*p2) != 0 )
624 return Au_NtkPiNum(*p1) - Au_NtkPiNum(*p2);
626 return Au_NtkPoNum(*p1) - Au_NtkPoNum(*p2);
633 if ( pNtk->
pMan == NULL )
635 printf(
"There is no hierarchy information.\n" );
642 vModsNew = Vec_PtrDup( vMods );
650 printf(
"%-30s : ", Au_NtkName(pModel) );
651 printf(
"PI=%6d ", Au_NtkPiNum(pModel) );
652 printf(
"PO=%6d ", Au_NtkPoNum(pModel) );
653 printf(
"BB=%6d ", Au_NtkBoxNum(pModel) );
654 printf(
"ND=%6d ", Au_NtkNodeNum(pModel) );
657 Vec_PtrFree( vModsNew );
665 int i, k, RetValue = 0;
667 if ( pNtk->
pMan == NULL )
669 printf(
"There is no hierarchy information.\n" );
677 if ( Au_ObjIsBox(pObj) && Au_ObjModel(pObj) == pModel )
679 printf(
"WARNING: Model \"%s\" contains a recursive definition.\n", Au_NtkName(pModel) );
691 int i, iFanin, Counter = 0;
692 if ( Au_ObjIsTravIdCurrentId(
p, Id) )
694 Au_ObjSetTravIdCurrentId(
p, Id);
695 pObj = Au_NtkObj(
p, Id );
696 if ( Au_ObjIsPi(pObj) )
698 assert( Au_ObjIsNode(pObj) || Au_ObjIsBox(pObj) || Au_ObjIsFan(pObj) );
706 Au_NtkIncrementTravId(
p );
736 if ( Au_ObjIsNode(pObj) )
738 printf(
"Nodes with small support %d (out of %d)\n", Counter, Au_NtkNodeNum(
p) );
753static inline void Au_NtkInsertHeader(
Au_Ntk_t *
p )
756 assert( (((ABC_PTRINT_T)(pMem +
p->iHandle) & 0x3FF) >> 4) == 0 );
758 ((
int *)(pMem +
p->iHandle))[2] = ((Vec_PtrSize(&
p->vPages) - 1) << 12) | (
p->iHandle & 0xFC0);
764 int nObjInt = ((2+nFanins) >> 2) + (((2+nFanins) & 3) > 0);
765 int Id, nObjIntReal = nObjInt;
767 nObjInt = 63 + 64 * (((nObjInt-63) >> 6) + (((nObjInt-63) & 63) > 0));
768 if ( Vec_PtrSize(&
p->vPages) == 0 ||
p->iHandle + nObjInt > (1 << 12) )
770 if ( nObjInt + 64 > (1 << 12) )
774 Vec_PtrPush(
p->vChunks, pMem );
775 if ( ((ABC_PTRINT_T)pMem & 0xF) )
776 pMem = (
Au_Obj_t *)((
char *)pMem + 16 - ((ABC_PTRINT_T)pMem & 0xF));
777 assert( ((ABC_PTRINT_T)pMem & 0xF) == 0 );
778 p->iHandle = (((ABC_PTRINT_T)pMem & 0x3FF) >> 4);
781 pMem += 64 - (
p->iHandle & 63);
784 Vec_PtrPush( &
p->vPages, pMem );
785 Au_NtkInsertHeader(
p );
789 pMem = (
Au_Obj_t *)Vec_PtrEntryLast( &
p->vPages );
790 if ( (
p->iHandle & 63) == 0 || nObjInt > (64 - (
p->iHandle & 63)) )
792 if (
p->iHandle & 63 )
793 p->iHandle += 64 - (
p->iHandle & 63);
794 Au_NtkInsertHeader(
p );
796 if (
p->iHandle + nObjInt > (1 << 12) )
799 pObj = pMem +
p->iHandle;
800 assert( *((
int *)pObj) == 0 );
802 p->nObjs[pObj->
Type = Type]++;
805 Au_ObjSetFaninLit( pObj, 0, Vec_IntSize(&
p->vPis) );
806 Vec_IntPush( &
p->vPis, Au_ObjId(pObj) );
810 Au_ObjSetFaninLit( pObj, 1, Vec_IntSize(&
p->vPos) );
811 Vec_IntPush( &
p->vPos, Au_ObjId(pObj) );
813 p->iHandle += nObjInt;
814 p->nObjsUsed += nObjIntReal;
817 Vec_IntPush( &
p->vObjs, Id );
818 pTemp = Au_NtkObj(
p, Id );
834 Au_ObjSetFaninLit( Au_NtkObj(pNtk, Id), 0, iFanin );
842 Au_ObjSetFaninLit(
p, 0, iFanin );
843 Au_ObjSetFaninLit(
p, 1, iFanout );
853 Au_ObjSetFaninLit(
p, i, iFanin );
859 int i, iFanin, nFanins = Vec_IntSize(vFanins);
863 Au_ObjSetFaninLit(
p, i, iFanin );
864 Au_ObjSetFaninLit(
p, nFanins, nFanouts );
865 for ( i = 0; i < nFanouts; i++ )
866 Au_ObjSetFaninLit(
p, nFanins + 1 + i,
Au_NtkCreateFan(pNtk, Au_Var2Lit(Id,0), i, iModel) );
867 p->nFanins = nFanins;
908static inline int Au_NtkRemapNum(
Vec_Int_t * vNum2Obj,
int Num )
910 return Au_Var2Lit(Vec_IntEntry(vNum2Obj, Au_Lit2Var(Num)), Au_LitIsCompl(Num));
923static inline void Au_NtkParseCBlifNum(
Vec_Int_t * vFanins,
char * pToken,
Vec_Int_t * vNum2Obj )
927 assert( pToken[0] >=
'0' && pToken[0] <=
'9' );
928 Num1 = atoi( pToken );
929 for ( pCur = pToken; *pCur; pCur++ )
932 Num2 = atoi( pCur+1 );
933 for ( i = 0; i < Num2; i++ )
934 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num1 + i + i) );
937 else if ( *pCur ==
'*' )
939 Num2 = atoi( pCur+1 );
940 for ( i = 0; i < Num2; i++ )
941 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num1) );
945 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num1) );
965 char * pBuffer, * pCur;
966 Vec_Int_t * vLines, * vNum2Obj, * vFanins;
967 int i, k, j, Id, nInputs, nOutputs;
970 pFile = fopen( pFileName,
"rb" );
973 printf(
"Cannot open file \"%s\".\n", pFileName );
979 vLines = Vec_IntAlloc( 1000 );
980 Vec_IntPush( vLines, 0 );
981 for ( pCur = pBuffer; *pCur; pCur++ )
985 Vec_IntPush( vLines, pCur - pBuffer + 1 );
990 vNum2Obj = Vec_IntAlloc( 1000 );
991 vFanins = Vec_IntAlloc( 1000 );
994 pCur =
strtok( pBuffer + Line,
" \t\r" );
995 if ( pCur == NULL || *pCur ==
'#' )
999 printf(
"Cannot read directive in line %d: \"%s\".\n", i, pBuffer + Line );
1002 Vec_IntClear( vFanins );
1003 if ( !
strcmp(pCur,
".and") )
1005 for ( k = 0; k < 2; k++ )
1007 pCur =
strtok( NULL,
" \t\r" );
1009 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num) );
1012 Vec_IntPush( vNum2Obj, Id );
1014 else if ( !
strcmp(pCur,
".xor") )
1016 for ( k = 0; k < 2; k++ )
1018 pCur =
strtok( NULL,
" \t\r" );
1020 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num) );
1023 Vec_IntPush( vNum2Obj, Id );
1025 else if ( !
strcmp(pCur,
".mux") )
1027 for ( k = 0; k < 3; k++ )
1029 pCur =
strtok( NULL,
" \t\r" );
1031 Vec_IntPush( vFanins, Au_NtkRemapNum(vNum2Obj, Num) );
1034 Vec_IntPush( vNum2Obj, Id );
1036 else if ( !
strcmp(pCur,
".subckt") )
1038 pCur =
strtok( NULL,
" \t\r" );
1039 Func = pCur - pBuffer;
1040 pCur =
strtok( NULL,
" \t\r" );
1041 nInputs = atoi( pCur );
1042 pCur =
strtok( NULL,
" \t\r" );
1043 nOutputs = atoi( pCur );
1046 pCur =
strtok( NULL,
" \t\r" );
1047 if ( pCur == NULL || *pCur ==
'#' )
1049 Au_NtkParseCBlifNum( vFanins, pCur, vNum2Obj );
1051 assert( Vec_IntSize(vFanins) == nInputs );
1053 pBox = Au_NtkObj( pRoot, Id );
1055 Vec_IntPush( vNum2Obj, Num );
1057 else if ( !
strcmp(pCur,
".model") )
1059 pCur =
strtok( NULL,
" \t\r" );
1062 Vec_IntClear( vNum2Obj );
1063 Vec_IntPush( vNum2Obj, Id );
1065 else if ( !
strcmp(pCur,
".inputs") )
1067 pCur =
strtok( NULL,
" \t\r" );
1069 for ( k = 0; k < Num; k++ )
1072 else if ( !
strcmp(pCur,
".outputs") )
1074 pCur =
strtok( NULL,
" \t\r" );
1075 nOutputs = atoi( pCur );
1078 pCur =
strtok( NULL,
" \t\r" );
1079 if ( pCur == NULL || *pCur ==
'#' )
1081 Au_NtkParseCBlifNum( vFanins, pCur, vNum2Obj );
1083 assert( Vec_IntSize(vFanins) == nOutputs );
1087 else if (
strcmp(pCur,
".end") )
1088 printf(
"Unknown directive in line %d: \"%s\".\n", i, pBuffer + Line );
1090 Vec_IntFree( vFanins );
1091 Vec_IntFree( vNum2Obj );
1092 Vec_IntFree( vLines );
1104 pRoot = Au_ManNtkRoot( pMan );
1136 assert( Au_ObjCopy(pTerm) >= 0 );
1137 if (
strcmp(Au_NtkName(
p),
"ref_egcd") == 0 )
1139 printf(
"Replacing one instance of recursive model \"%s\" by a black box.\n",
"ref_egcd" );
1141 Au_ObjSetCopy( pTerm, Gia_ManAppendCi(pGia) );
1146 if ( Au_ObjIsNode(pObj) )
1148 if (
p->pMan->pFuncs )
1152 assert( Au_ObjFaninNum(pObj) <= 16 );
1156 gFanins[k] = Au_ObjCopy(pTerm);
1157 assert( gFanins[k] >= 0 );
1163 int Lit0, Lit1, Lit2;
1165 Lit0 = Abc_LitNotCond( Au_ObjCopy(Au_ObjFanin0(pObj)), Au_ObjFaninC0(pObj) );
1166 Lit1 = Abc_LitNotCond( Au_ObjCopy(Au_ObjFanin1(pObj)), Au_ObjFaninC1(pObj) );
1167 if ( pObj->
Func == 1 )
1169 else if ( pObj->
Func == 2 )
1171 else if ( pObj->
Func == 3 )
1173 Lit2 = Abc_LitNotCond( Au_ObjCopy(Au_ObjFanin2(pObj)), Au_ObjFaninC2(pObj) );
1179 Au_ObjSetCopy( pObj, Lit );
1181 else if ( Au_ObjIsBox(pObj) )
1183 Au_Ntk_t * pModel = Au_ObjModel(pObj);
1186 assert( Au_ObjFaninNum(pObj) == Au_NtkPiNum(pModel) );
1187 assert( Au_BoxFanoutNum(pObj) == Au_NtkPoNum(pModel) );
1190 Au_ObjSetCopy( Au_NtkPi(pModel, k), Au_ObjCopy(pTerm) );
1195 Au_ObjSetCopy( pTerm, Au_ObjCopy(Au_NtkPo(pModel, k)) );
1197 else if ( Au_ObjIsConst0(pObj) )
1198 Au_ObjSetCopy( pObj, 0 );
1203 Lit = Abc_LitNotCond( Au_ObjCopy(Au_ObjFanin0(pTerm)), Au_ObjFaninC0(pTerm) );
1204 Au_ObjSetCopy( pTerm, Lit );
1207 assert( Au_ObjCopy(pTerm) >= 0 );
1227 printf(
"Collapsing model \"%s\"...\n", Au_NtkName(
p) );
1231 pGia->
pName = Abc_UtilStrsav( Au_NtkName(
p) );
1234 Gia_ManFlipVerbose( pGia );
1237 Au_ObjSetCopy( pTerm, Gia_ManAppendCi(pGia) );
1242 Gia_ManAppendCo( pGia, Au_ObjCopy(pTerm) );
1258static inline void Au_ObjSetXsim(
Au_Obj_t * pObj,
int Value ) { pObj->
Value = Value; }
1259static inline int Au_ObjGetXsim(
Au_Obj_t * pObj ) {
return pObj->
Value; }
1260static inline int Au_XsimInv(
int Value )
1269static inline int Au_XsimAnd(
int Value0,
int Value1 )
1278static inline int Au_XsimXor(
int Value0,
int Value1 )
1286static inline int Au_XsimMux(
int ValueC,
int Value1,
int Value0 )
1298static inline int Au_ObjGetXsimFan0(
Au_Obj_t * pObj )
1300 int Value = Au_ObjGetXsim( Au_ObjFanin0(pObj) );
1301 return Au_ObjFaninC0(pObj) ? Au_XsimInv(Value) : Value;
1303static inline int Au_ObjGetXsimFan1(
Au_Obj_t * pObj )
1305 int Value = Au_ObjGetXsim( Au_ObjFanin1(pObj) );
1306 return Au_ObjFaninC1(pObj) ? Au_XsimInv(Value) : Value;
1308static inline int Au_ObjGetXsimFan2(
Au_Obj_t * pObj )
1310 int Value = Au_ObjGetXsim( Au_ObjFanin2(pObj) );
1311 return Au_ObjFaninC2(pObj) ? Au_XsimInv(Value) : Value;
1331 assert( Au_ObjGetXsim(pTerm) > 0 );
1332 if ( Au_ObjGetXsim(pTerm) ==
AU_VALX )
1333 p->pMan->nPortsNC++;
1334 else if ( Au_ObjGetXsim(pTerm) ==
AU_VAL0 )
1335 p->pMan->nPortsC0++;
1337 p->pMan->nPortsC1++;
1339 if (
strcmp(Au_NtkName(
p),
"ref_egcd") == 0 )
1341 printf(
"Replacing one instance of recursive model \"%s\" by a black box.\n",
"ref_egcd" );
1343 Au_ObjSetXsim( pTerm,
AU_VALX );
1348 if ( Au_ObjIsNode(pObj) )
1350 if ( pObj->
Func == 1 )
1351 Au_ObjSetXsim( pObj, Au_XsimAnd(Au_ObjGetXsimFan0(pObj), Au_ObjGetXsimFan1(pObj)) );
1352 else if ( pObj->
Func == 2 )
1353 Au_ObjSetXsim( pObj, Au_XsimXor(Au_ObjGetXsimFan0(pObj), Au_ObjGetXsimFan1(pObj)) );
1354 else if ( pObj->
Func == 3 )
1355 Au_ObjSetXsim( pObj, Au_XsimMux(Au_ObjGetXsimFan0(pObj), Au_ObjGetXsimFan1(pObj), Au_ObjGetXsimFan2(pObj)) );
1358 else if ( Au_ObjIsBox(pObj) )
1360 Au_Ntk_t * pModel = Au_ObjModel(pObj);
1362 assert( Au_ObjFaninNum(pObj) == Au_NtkPiNum(pModel) );
1363 assert( Au_BoxFanoutNum(pObj) == Au_NtkPoNum(pModel) );
1366 Au_ObjSetXsim( Au_NtkPi(pModel, k), Au_ObjGetXsim(pTerm) );
1371 Au_ObjSetXsim( pTerm, Au_ObjGetXsim(Au_NtkPo(pModel, k)) );
1373 else if ( Au_ObjIsConst0(pObj) )
1374 Au_ObjSetXsim( pObj,
AU_VAL0 );
1378 Au_ObjSetXsim( pTerm, Au_ObjGetXsimFan0(pObj) );
1381 assert( Au_ObjGetXsim(pTerm) > 0 );
1382 if ( Au_ObjGetXsim(pTerm) ==
AU_VALX )
1383 p->pMan->nPortsNC++;
1384 else if ( Au_ObjGetXsim(pTerm) ==
AU_VAL0 )
1385 p->pMan->nPortsC0++;
1387 p->pMan->nPortsC1++;
1405 int i, Counter[2] = {0};
1406 assert(
p->pMan->pFuncs == NULL );
1407 printf(
"Collapsing model \"%s\"...\n", Au_NtkName(
p) );
1410 Au_ObjSetXsim( pTerm,
AU_VALX );
1412 p->pMan->nPortsC0 = 0;
1413 p->pMan->nPortsC1 = 0;
1414 p->pMan->nPortsNC = 0;
1418 if ( Au_ObjGetXsim(pTerm) ==
AU_VAL0 )
1420 else if ( Au_ObjGetXsim(pTerm) ==
AU_VAL1 )
1423 printf(
"Const0 outputs =%15d. Const1 outputs =%15d. Total outputs =%15d.\n",
1424 Counter[0], Counter[1], Au_NtkPoNum(
p) );
1425 printf(
"Const0 ports = %.0f. Const1 ports = %.0f. Non-const ports= %.0f. Total ports = %.0f.\n",
1426 p->pMan->nPortsC0,
p->pMan->nPortsC1,
p->pMan->nPortsNC,
p->pMan->nPortsC0 +
p->pMan->nPortsC1 +
p->pMan->nPortsNC );
1449 assert( Abc_NtkIsNetlist(pNtk) );
1456 vFanins = Vec_IntAlloc( 100 );
1460 Vec_IntClear( vFanins );
1461 if ( Abc_ObjIsNode(pObj) )
1464 Vec_IntPush( vFanins, Au_Var2Lit(pTerm->
iTemp, 0) );
1469 assert( Abc_ObjIsBox(pObj) );
1471 Vec_IntPush( vFanins, Au_Var2Lit(Abc_ObjFanin0(pTerm)->iTemp, 0) );
1473 pAuObj = Au_NtkObj(
p, pObj->
iTemp);
1475 Abc_ObjFanout0(pTerm)->iTemp = Au_ObjFanout(pAuObj, k);
1478 Vec_IntFree( vFanins );
1491 char * pModelName =
"path_0_r_x_lhs";
1497 abctime clk1, clk2 = 0, clk3 = 0, clk = Abc_Clock();
1503 clk2 += Abc_Clock() - clk1;
1514 clk2 += Abc_Clock() - clk1;
1516 Vec_PtrFree( vOrder );
1518 Vec_PtrFree( vModels );
1531 printf(
"Could not find module \"%s\".\n", pModelName );
1541 clk3 = Abc_Clock() - clk1;
1551 clk2 += Abc_Clock() - clk1;
1553 Abc_PrintTime( 1,
"Time all ", Abc_Clock() - clk );
1554 Abc_PrintTime( 1,
"Time new ", clk2 );
1555 Abc_PrintTime( 1,
"Time GIA ", clk3 );
1573 int fSimulation = 0;
1576 abctime clk1 = 0, clk = Abc_Clock();
1582 printf(
"Reading CBLIF file has failed.\n" );
1585 if ( pNtk->
pMan == NULL || pNtk->
pMan->
vNtks.pArray == NULL )
1587 printf(
"There is no hierarchy information.\n" );
1591 Abc_PrintTime( 1,
"Reading file", Abc_Clock() - clk );
1604 if ( pNtkClp == NULL )
1615 Abc_PrintTime( 1,
"Time sim ", Abc_Clock() - clk1 );
1620 Abc_PrintTime( 1,
"Time GIA ", Abc_Clock() - clk1 );
1625 Abc_PrintTime( 1,
"Time all ", Abc_Clock() - clk );
Vec_Ptr_t * Abc_NtkCollectHie(Abc_Ntk_t *pNtk)
int Au_NtkCheckRecursive(Au_Ntk_t *pNtk)
ABC_NAMESPACE_IMPL_END ABC_NAMESPACE_IMPL_START Vec_Ptr_t * Abc_NtkDfsBoxes(Abc_Ntk_t *pNtk)
void Au_ManPrintStats(Au_Man_t *p)
void Au_ManCountThings(Au_Man_t *p)
int Au_NtkAllocObj(Au_Ntk_t *p, int nFanins, int Type)
#define Au_ManForEachNtkReverse(p, pNtk, i)
int Au_NtkCreateFan(Au_Ntk_t *pNtk, int iFanin, int iFanout, int iModel)
#define Au_ObjForEachFaninId(pObj, hFanin, i)
Gia_Man_t * Au_NtkDeriveFlatGia(Au_Ntk_t *p)
int Au_ObjSuppSize_rec(Au_Ntk_t *p, int Id)
int Abc_NtkDeriveFlatGiaSop(Gia_Man_t *pGia, int *gFanins, char *pSop)
int Au_NtkCreateConst0(Au_Ntk_t *pNtk)
int Au_NtkCreatePi(Au_Ntk_t *pNtk)
#define Au_NtkForEachBox(p, pObj, i)
int Au_NtkCreatePo(Au_Ntk_t *pNtk, int iFanin)
void Au_ManDelete(Au_Man_t *p)
int Au_NtkCompareNames(Au_Ntk_t **p1, Au_Ntk_t **p2)
void Au_NtkTerSimulate_rec(Au_Ntk_t *p)
#define Au_BoxForEachFanoutId(pObj, hFanout, i)
#define Au_BoxForEachFanout(pObj, pFanout, i)
int Abc_NtkCheckRecursive(Abc_Ntk_t *pNtk)
int Au_NtkMemUsage(Au_Ntk_t *p)
#define Au_NtkForEachNode(p, pObj, i)
int Au_ManFindNtk(Au_Man_t *p, char *pName)
void Au_ManPrintBoxInfoSorted(Au_Ntk_t *pNtk)
#define Au_NtkForEachObj(p, pObj, i)
void Au_ManReorderModels_rec(Au_Ntk_t *pNtk, Vec_Int_t *vOrder)
int Au_ManMemUsage(Au_Man_t *p)
Gia_Man_t * Abc_NtkHieCecTest2(char *pFileName, char *pModelName, int fVerbose)
#define Au_NtkForEachPo(p, pObj, i)
#define Au_ObjForEachFanin(pObj, pFanin, i)
Au_Ntk_t * Au_NtkParseCBlif(char *pFileName)
int Au_NtkSuppSizeTest(Au_Ntk_t *p)
Au_Ntk_t * Au_NtkDerive(Au_Man_t *pMan, Abc_Ntk_t *pNtk, Vec_Ptr_t *vOrder)
void Au_ManAddNtk(Au_Man_t *pMan, Au_Ntk_t *p)
void Au_NtkCleanCopy(Au_Ntk_t *p)
int Au_NtkCreateBox(Au_Ntk_t *pNtk, Vec_Int_t *vFanins, int nFanouts, int iModel)
struct Au_Man_t_ Au_Man_t
void Au_ManFree(Au_Man_t *p)
int Au_ObjSuppSize(Au_Obj_t *pObj)
#define Au_ManForEachNtk(p, pNtk, i)
Au_Man_t * Au_ManAlloc(char *pName)
void Au_NtkPrintStats(Au_Ntk_t *p)
struct Au_Ntk_t_ Au_Ntk_t
#define Au_NtkForEachPi(p, pObj, i)
void Au_NtkDeriveFlatGia_rec(Gia_Man_t *pGia, Au_Ntk_t *p)
Au_Ntk_t * Au_NtkAlloc(Au_Man_t *pMan, char *pName)
FUNCTION DEFINITIONS ///.
void Au_ManReorderModels(Au_Man_t *p, Au_Ntk_t *pRoot)
struct Au_Obj_t_ Au_Obj_t
int Au_NtkCompareSign(Au_Ntk_t **p1, Au_Ntk_t **p2)
Gia_Man_t * Au_ManDeriveTest(Abc_Ntk_t *pRoot)
void Au_NtkTerSimulate(Au_Ntk_t *p)
int Au_NtkNodeNumFunc(Au_Ntk_t *p, int Func)
int Au_NtkCreateNode(Au_Ntk_t *pNtk, Vec_Int_t *vFanins, int iFunc)
Au_Ntk_t * Au_ManFindNtkP(Au_Man_t *p, char *pName)
void Au_ManPrintBoxInfo(Au_Ntk_t *pNtk)
void Au_NtkFree(Au_Ntk_t *p)
int Au_ManMemUsageUseful(Au_Man_t *p)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachPo(pNtk, pPo, i)
#define Abc_ObjForEachFanin(pObj, pFanin, i)
#define Abc_ObjForEachFanout(pObj, pFanout, i)
struct Abc_Ntk_t_ Abc_Ntk_t
#define Abc_NtkForEachPi(pNtk, pPi, i)
ABC_DLL int Abc_SopGetVarNum(char *pSop)
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
#define ABC_ALLOC(type, num)
#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 ///.
void Gia_ManStop(Gia_Man_t *p)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
void Gia_ManHashAlloc(Gia_Man_t *p)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
struct Gia_Man_t_ Gia_Man_t
int Gia_ManHashMux(Gia_Man_t *p, int iCtrl, int iData1, int iData0)
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
void Gia_ManHashStop(Gia_Man_t *p)
void Abc_NamStop(Abc_Nam_t *p)
int Abc_NamStrFindOrAdd(Abc_Nam_t *p, char *pStr, int *pfFound)
int Abc_NamObjNumMax(Abc_Nam_t *p)
Abc_Nam_t * Abc_NamStart(int nObjs, int nAveSize)
FUNCTION DEFINITIONS ///.
char * Abc_NamStr(Abc_Nam_t *p, int NameId)
typedefABC_NAMESPACE_HEADER_START struct Abc_Nam_t_ Abc_Nam_t
INCLUDES ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.