diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2015-07-23 21:33:52 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2015-07-23 21:33:52 -0700 |
commit | e9be6ecaf8a5d87c0e92ccd82b94f5439dbc82f3 (patch) | |
tree | 268d19cb67203f759372da09006517580ae7fae8 /src/base/cba | |
parent | 9bd16029f154903b0ece7206d9ab84e393a5ef18 (diff) | |
download | abc-e9be6ecaf8a5d87c0e92ccd82b94f5439dbc82f3.tar.gz abc-e9be6ecaf8a5d87c0e92ccd82b94f5439dbc82f3.tar.bz2 abc-e9be6ecaf8a5d87c0e92ccd82b94f5439dbc82f3.zip |
Updates to Cba data-structure.
Diffstat (limited to 'src/base/cba')
-rw-r--r-- | src/base/cba/cba.h | 300 | ||||
-rw-r--r-- | src/base/cba/cbaCom.c | 2 | ||||
-rw-r--r-- | src/base/cba/cbaNtk.c | 572 |
3 files changed, 697 insertions, 177 deletions
diff --git a/src/base/cba/cba.h b/src/base/cba/cba.h index d36c75af..546c54bd 100644 --- a/src/base/cba/cba.h +++ b/src/base/cba/cba.h @@ -215,6 +215,7 @@ static inline int Cba_NtkPi( Cba_Ntk_t * p, int i ) { r static inline int Cba_NtkPo( Cba_Ntk_t * p, int i ) { return Vec_IntEntry(&p->vOutputs, i); } static inline char * Cba_NtkStr( Cba_Ntk_t * p, int i ) { return Cba_ManStr(p->pDesign, i); } static inline char * Cba_NtkName( Cba_Ntk_t * p ) { return Cba_NtkStr(p, p->NameId); } +static inline int Cba_NtkNameId( Cba_Ntk_t * p ) { return p->NameId; } static inline int Cba_NtkCopy( Cba_Ntk_t * p ) { return p->iCopy; } static inline Cba_Ntk_t * Cba_NtkCopyNtk(Cba_Man_t * pNew, Cba_Ntk_t * p) { return Cba_ManNtk(pNew, Cba_NtkCopy(p)); } static inline void Cba_NtkSetCopy( Cba_Ntk_t * p, int i ) { assert(p->iCopy == 0); p->iCopy = i; } @@ -235,33 +236,19 @@ static inline int Cba_NtkBoxNum( Cba_Ntk_t * p ) { r static inline int Cba_NtkBoxUserNum( Cba_Ntk_t * p ) { return Cba_NtkTypeNum(p, CBA_OBJ_BOX); } static inline int Cba_NtkBoxPrimNum( Cba_Ntk_t * p ) { return Vec_StrCountLarger(&p->vObjType, (char)CBA_OBJ_BOX); } -static inline void Cba_NtkStartObjCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjCopy, Vec_StrCap(&p->vObjType), -1); } -static inline void Cba_NtkStartObjFuncs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjFunc, Vec_StrCap(&p->vObjType), 0); } -static inline void Cba_NtkStartObjNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjName, Vec_StrCap(&p->vObjType), 0); } -static inline void Cba_NtkStartObjAttrs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjAttr, Vec_StrCap(&p->vObjType), 0); } -static inline void Cba_NtkStartFonCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonCopy, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonName, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonRanges( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonRange,Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonLefts( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonLeft, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonRights( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonRight,Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonPrevs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonPrev, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFonNexts( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonNext, Vec_IntCap(&p->vFonObj), 0); } -static inline void Cba_NtkStartFinFon0( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinFon0, Vec_IntCap(&p->vFinFon), 0); } -static inline void Cba_NtkStartFinObjs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinObj, Vec_IntCap(&p->vFinFon), 0); } - -static inline void Cba_NtkFreeObjCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjCopy); } -static inline void Cba_NtkFreeObjFuncs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjFunc); } -static inline void Cba_NtkFreeObjNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjName); } -static inline void Cba_NtkFreeObjAttrs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjAttr); } -static inline void Cba_NtkFreeFonCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonCopy); } -static inline void Cba_NtkFreeFonNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonName); } -static inline void Cba_NtkFreeFonRanges( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonRange); } -static inline void Cba_NtkFreeFonLefts( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonLeft); } -static inline void Cba_NtkFreeFonRights( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonRight); } -static inline void Cba_NtkFreeFonPrevs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonPrev); } -static inline void Cba_NtkFreeFonNexts( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonNext); } -static inline void Cba_NtkFreeFinFon0( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinFon0); } -static inline void Cba_NtkFreeFinObjs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinObj); } +static inline void Cba_NtkCleanObjCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjCopy, Vec_StrCap(&p->vObjType), -1); } +static inline void Cba_NtkCleanObjFuncs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjFunc, Vec_StrCap(&p->vObjType), 0); } +static inline void Cba_NtkCleanObjNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjName, Vec_StrCap(&p->vObjType), 0); } +static inline void Cba_NtkCleanObjAttrs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjAttr, Vec_StrCap(&p->vObjType), 0); Vec_IntFill(&p->vAttrSto, 1, -1); } +static inline void Cba_NtkCleanFonCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonCopy, Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonName, Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonRanges( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonRange,Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonLefts( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonLeft, Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonRights( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonRight,Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonPrevs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonPrev, Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFonNexts( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonNext, Vec_IntCap(&p->vFonObj), 0); } +static inline void Cba_NtkCleanFinFon0( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinFon0, Vec_IntCap(&p->vFinFon), 0); } +static inline void Cba_NtkCleanFinObjs( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFinObj, Vec_IntCap(&p->vFinFon), 0); } static inline int Cba_NtkHasObjCopies( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjCopy) > 0; } static inline int Cba_NtkHasObjFuncs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vObjFunc) > 0; } @@ -277,9 +264,19 @@ static inline int Cba_NtkHasFonNexts( Cba_Ntk_t * p ) { r static inline int Cba_NtkHasFinFon0( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFinFon0) > 0; } static inline int Cba_NtkHasFinObjs( Cba_Ntk_t * p ) { return Vec_IntSize(&p->vFinObj) > 0; } -static inline void Cba_NtkCleanObjCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vObjCopy, Vec_StrSize(&p->vObjType), -1); } -static inline void Cba_NtkCleanFonCopies( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonCopy, Vec_IntSize(&p->vFonObj), -1); } -static inline void Cba_NtkCleanFonNames( Cba_Ntk_t * p ) { Vec_IntFill(&p->vFonName, Vec_IntSize(&p->vFonObj), 0); } +static inline void Cba_NtkFreeObjCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjCopy); } +static inline void Cba_NtkFreeObjFuncs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjFunc); } +static inline void Cba_NtkFreeObjNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjName); } +static inline void Cba_NtkFreeObjAttrs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vObjAttr); } +static inline void Cba_NtkFreeFonCopies( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonCopy); } +static inline void Cba_NtkFreeFonNames( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonName); } +static inline void Cba_NtkFreeFonRanges( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonRange); } +static inline void Cba_NtkFreeFonLefts( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonLeft); } +static inline void Cba_NtkFreeFonRights( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonRight); } +static inline void Cba_NtkFreeFonPrevs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonPrev); } +static inline void Cba_NtkFreeFonNexts( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFonNext); } +static inline void Cba_NtkFreeFinFon0( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinFon0); } +static inline void Cba_NtkFreeFinObjs( Cba_Ntk_t * p ) { Vec_IntErase(&p->vFinObj); } static inline Cba_ObjType_t Cba_ObjType( Cba_Ntk_t * p, int i ) { assert(i>0); return (Cba_ObjType_t)(int)(unsigned char)Vec_StrEntry(&p->vObjType, i); } static inline void Cba_ObjCleanType( Cba_Ntk_t * p, int i ) { assert(i>0); Vec_StrWriteEntry( &p->vObjType, i, (char)CBA_OBJ_NONE ); } @@ -300,22 +297,21 @@ static inline int Cba_ObjFon( Cba_Ntk_t * p, int i, int k ) { a static inline int Cba_ObjFinNum( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_ObjFin0(p, i+1) - Cba_ObjFin0(p, i); } static inline int Cba_ObjFonNum( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_ObjFon0(p, i+1) - Cba_ObjFon0(p, i); } -static inline int Cba_ObjCopy( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntGetEntryFull(&p->vObjCopy, i); } -static inline int Cba_ObjFunc( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntGetEntry(&p->vObjFunc, i); } -static inline int Cba_ObjName( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntGetEntry(&p->vObjName, i); } +static inline int Cba_ObjCopy( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjCopies(p) ); return Vec_IntGetEntryFull(&p->vObjCopy, i); } +static inline int Cba_ObjFunc( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjFuncs(p) ); return Vec_IntGetEntry(&p->vObjFunc, i); } +static inline int Cba_ObjName( Cba_Ntk_t * p, int i ) { assert(i>0); assert( Cba_NtkHasObjNames(p) ); return Vec_IntGetEntry(&p->vObjName, i); } static inline char * Cba_ObjNameStr( Cba_Ntk_t * p, int i ) { assert(i>0); return Cba_NtkStr(p, Cba_ObjName(p, i)); } -static inline int Cba_ObjAttr( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntGetEntry(&p->vObjAttr, i); } - -static inline int * Cba_ObjAttrs( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntGetEntryP(&p->vObjAttr, i); } -static inline int Cba_ObjAttrSize( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntry(&p->vAttrSto, Vec_IntGetEntry(&p->vObjAttr, i)); } -static inline int * Cba_ObjAttrArray( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntryP(&p->vAttrSto, Vec_IntGetEntry(&p->vObjAttr, i)+1); } +static inline int Cba_ObjAttr( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_NtkHasObjAttrs(p) ? Vec_IntGetEntry(&p->vObjAttr, i) : 0; } +static inline int Cba_ObjAttrSize( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_ObjAttr(p, i) ? Vec_IntEntry(&p->vAttrSto, Cba_ObjAttr(p, i)) : 0; } +static inline int * Cba_ObjAttrArray( Cba_Ntk_t * p, int i ) { assert(i>=0); return Cba_ObjAttr(p, i) ? Vec_IntEntryP(&p->vAttrSto, Cba_ObjAttr(p, i)+1) : NULL; } static inline void Cba_ObjSetCopy( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjCopy(p, i) == -1); Vec_IntSetEntry( &p->vObjCopy, i, x ); } static inline void Cba_ObjSetFunc( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjFunc(p, i) == 0); Vec_IntSetEntry( &p->vObjFunc, i, x ); } static inline void Cba_ObjSetName( Cba_Ntk_t * p, int i, int x ) { assert(Cba_ObjName(p, i) == 0); Vec_IntSetEntry( &p->vObjName, i, x ); } -static inline void Cba_ObjSetAttrs( Cba_Ntk_t * p, int i, int * a, int s ) { assert(Cba_ObjAttr(p, i) == 0); Vec_IntSetEntry(&p->vObjAttr, i, Vec_IntSize(&p->vAttrSto)); if (a) Vec_IntPushArray(&p->vAttrSto, a, s); } +static inline void Cba_ObjSetAttrs( Cba_Ntk_t * p, int i, int * a, int s ) { assert(Cba_ObjAttr(p, i) == 0); if ( !a ) return; Vec_IntSetEntry(&p->vObjAttr, i, Vec_IntSize(&p->vAttrSto)); Vec_IntPush(&p->vAttrSto, s); Vec_IntPushArray(&p->vAttrSto, a, s); } static inline int Cba_FinFon( Cba_Ntk_t * p, int f ) { assert(f>0); return Vec_IntEntry(&p->vFinFon, f); } +static inline void Cba_PatchFinFon( Cba_Ntk_t * p, int f, int x ) { assert(f>0); Vec_IntWriteEntry(&p->vFinFon, f, x); } static inline int Cba_ObjFinFon( Cba_Ntk_t * p, int i, int k ) { assert(i>0); return Cba_FinFon(p, Cba_ObjFin(p, i, k)); } static inline int * Cba_ObjFinFons( Cba_Ntk_t * p, int i ) { assert(i>0); return Vec_IntEntryP(&p->vFinFon, Cba_ObjFin0(p, i)); } @@ -333,13 +329,13 @@ static inline int Cba_FonConst( int f ) { a static inline int Cba_FonFromConst( int c ) { assert(c >= 0); return -c-1; } static inline int Cba_FonObj( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry(&p->vFonObj, f) : 0; } -static inline int Cba_FonCopy( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry( &p->vFonCopy, f ) : f; } +static inline int Cba_FonCopy( Cba_Ntk_t * p, int f ) { return Cba_FonIsReal(f) ? Vec_IntEntry(&p->vFonCopy, f) : f; } static inline void Cba_FonSetCopy( Cba_Ntk_t * p, int f, int x ) { assert(Cba_FonIsReal(f)); assert(Cba_FonCopy(p, f) == 0); Vec_IntWriteEntry(&p->vFonCopy, f, x); } -static inline int Cba_FonName( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Vec_IntGetEntry( &p->vFonName, f ); } -static inline char * Cba_FonNameStr( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_NtkStr(p, Cba_FonName(p, f)); } -static inline void Cba_FonSetName( Cba_Ntk_t * p, int f, int x ) { assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) == 0); Vec_IntSetEntry(&p->vFonName, f, x); } -static inline void Cba_FonCleanName( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) != 0); Vec_IntSetEntry(&p->vFonName, f, 0); } -static inline void Cba_FonPatchName( Cba_Ntk_t * p, int f, int x) { assert(Cba_FonIsReal(f)); Cba_FonCleanName(p, f); Cba_FonSetName(p, f, x); } +static inline int Cba_FonName( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); return Vec_IntGetEntry( &p->vFonName, f ); } +static inline char * Cba_FonNameStr( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); return Cba_NtkStr(p, Cba_FonName(p, f)); } +static inline void Cba_FonSetName( Cba_Ntk_t * p, int f, int x ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) == 0); Vec_IntSetEntry(&p->vFonName, f, x); } +static inline void Cba_FonCleanName( Cba_Ntk_t * p, int f ) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); assert(Cba_FonName(p, f) != 0); Vec_IntSetEntry(&p->vFonName, f, 0); } +static inline void Cba_FonPatchName( Cba_Ntk_t * p, int f, int x) { assert(Cba_NtkHasFonNames(p)); assert(Cba_FonIsReal(f)); Cba_FonCleanName(p, f); Cba_FonSetName(p, f, x); } static inline int Cba_FonIndex( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return f - Cba_ObjFon0( p, Cba_FonObj(p, f) ); } static inline int Cba_FonNtkId( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_ObjNtkId( p, Cba_FonObj(p, f) ); } static inline Cba_Ntk_t * Cba_FonNtk( Cba_Ntk_t * p, int f ) { assert(Cba_FonIsReal(f)); return Cba_ObjNtk( p, Cba_FonObj(p, f) ); } @@ -376,10 +372,10 @@ static inline int Cba_ObjFanin( Cba_Ntk_t * p, int i, int k ) { a #define Cba_NtkForEachBoxPrim( p, i ) \ for ( i = 1; i < Vec_StrSize(&p->vObjType); i++ ) if ( !Cba_ObjIsBoxPrim(p, i) ) {} else -#define Cba_NtkForEachFinFon( p, iFon, i ) \ - for ( i = 0; i < Vec_IntSize(&p->vFinFon) && (((iFon) = Vec_IntEntry(&p->vFinFon, i)), 1); i++ ) if ( !iFon ) {} else -#define Cba_NtkForEachFonName( p, Name, i ) \ - for ( i = 0; i < Vec_IntSize(&p->vFonName) && (((Name) = Vec_IntEntry(&p->vFonName, i)), 1); i++ ) if ( !Name ) {} else +#define Cba_NtkForEachFinFon( p, iFon, iFin ) \ + for ( iFin = 0; iFin < Vec_IntSize(&p->vFinFon) && (((iFon) = Vec_IntEntry(&p->vFinFon, iFin)), 1); i++ ) if ( !iFon ) {} else +#define Cba_NtkForEachFonName( p, NameId, iFon ) \ + for ( iFon = 0; iFon < Vec_IntSize(&p->vFonName) && (((NameId) = Vec_IntEntry(&p->vFonName, iFon)), 1); i++ ) if ( !NameId ) {} else #define Cba_ObjForEachFin( p, iObj, iFin, k ) \ for ( k = 0, iFin = Cba_ObjFin0(p, iObj); iFin < Cba_ObjFin0(p, iObj+1); iFin++, k++ ) @@ -471,14 +467,59 @@ static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, int NameId, int nIns, in Vec_IntGrow( &pNew->vFonObj, nFons+1 ); Vec_IntPush( &pNew->vFonObj, 0 ); return pNew; } +static inline void Cba_NtkFree( Cba_Ntk_t * p ) +{ + // interface + Vec_IntErase( &p->vInputs ); + Vec_IntErase( &p->vOutputs ); + Vec_IntErase( &p->vOrder ); + // stucture + Vec_StrErase( &p->vObjType ); + Vec_IntErase( &p->vObjFin0 ); + Vec_IntErase( &p->vObjFon0 ); + Vec_IntErase( &p->vFinFon ); + Vec_IntErase( &p->vFonObj ); + // optional + Vec_IntErase( &p->vObjCopy ); + Vec_IntErase( &p->vObjFunc ); + Vec_IntErase( &p->vObjName ); + Vec_IntErase( &p->vObjAttr ); + Vec_IntErase( &p->vAttrSto ); + Vec_IntErase( &p->vFonCopy ); + Vec_IntErase( &p->vFonName ); + Vec_IntErase( &p->vFonRange ); + Vec_IntErase( &p->vFonLeft ); + Vec_IntErase( &p->vFonRight ); + Vec_IntErase( &p->vFonPrev ); + Vec_IntErase( &p->vFonNext ); + Vec_IntErase( &p->vFinFon0 ); + Vec_IntErase( &p->vFinObj ); + Vec_IntErase( &p->vNtkObjs ); + // other + Vec_IntErase( &p->vArray0 ); + Vec_IntErase( &p->vArray1 ); + if ( p->vOther ) Vec_VecFree( (Vec_Vec_t *)p->vOther ); + ABC_FREE( p ); +} static inline void Cba_NtkAdd( Cba_Man_t * p, Cba_Ntk_t * pNtk ) { - int fFound, NtkId = Abc_NamStrFindOrAdd( p->pMods, Cba_NtkStr(pNtk, pNtk->NameId), &fFound ); + int fFound, NtkId = Abc_NamStrFindOrAdd( p->pMods, Cba_NtkName(pNtk), &fFound ); if ( fFound ) - printf( "Network with name \"%s\" already exists.\n", Cba_NtkStr(pNtk, pNtk->NameId) ); + printf( "Network with name \"%s\" already exists.\n", Cba_NtkName(pNtk) ); else assert( NtkId == pNtk->Id ); } +static inline void Cba_NtkUpdate( Cba_Man_t * p, Cba_Ntk_t * pNtk ) +{ + int fFound, NtkId = Abc_NamStrFindOrAdd( p->pMods, Cba_NtkName(pNtk), &fFound ); + if ( !fFound ) + printf( "Network with name \"%s\" does not exist.\n", Cba_NtkName(pNtk) ); + else + { + Cba_NtkFree( Cba_ManNtk(p, NtkId) ); + Vec_PtrWriteEntry( &p->vNtks, NtkId, pNtk ); + } +} static inline Vec_Int_t * Cba_NtkCollect( Cba_Ntk_t * p ) { int iObj; @@ -487,73 +528,31 @@ static inline Vec_Int_t * Cba_NtkCollect( Cba_Ntk_t * p ) Vec_IntPush( vObjs, iObj ); return vObjs; } -static inline void Cba_NtkCollectDfs_rec( Cba_Ntk_t * p, int iObj, Vec_Int_t * vObjs ) -{ - int iFin, iFanin, k; - if ( !Cba_ObjCopy(p, iObj) ) - return; - Cba_ObjSetCopy( p, iObj, 0 ); - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - Vec_IntPush( vObjs, iObj ); -} -static inline Vec_Int_t * Cba_NtkCollectDfs( Cba_Ntk_t * p ) -{ - int i, k, iObj, iFin, iFanin; - Vec_Int_t * vObjs = Vec_IntAlloc( Cba_NtkObjNum(p) ); - // collect PIs - Cba_NtkForEachPi( p, iObj, i ) - Vec_IntPush( vObjs, iObj ); - // prepare leaves - Cba_NtkCleanObjCopies( p ); - Vec_IntForEachEntry( vObjs, iObj, i ) - Cba_ObjSetCopy( p, iObj, 0 ); - // collect internal - Cba_NtkForEachPo( p, iObj, i ) - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - // additionally collect user modules without outputs - Cba_NtkForEachBoxUser( p, iObj ) - if ( Cba_ObjFonNum(p, iObj) == 0 ) - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) - Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); - // collect POs - Cba_NtkForEachPo( p, iObj, i ) - Vec_IntPush( vObjs, iObj ); - // collect user boxes without fanouts - Cba_NtkForEachBoxUser( p, iObj ) - if ( Cba_ObjFonNum(p, iObj) == 0 ) - Vec_IntPush( vObjs, iObj ); - assert( Vec_IntSize(vObjs) <= Cba_NtkObjNum(p) ); - if ( Vec_IntSize(vObjs) != Cba_NtkObjNum(p) ) - printf( "Warning: DSF ordering collected %d out of %d objects.\n", Vec_IntSize(vObjs), Cba_NtkObjNum(p) ); - return vObjs; -} static inline void Cba_NtkCreateFonNames( Cba_Ntk_t * p, char * pPref ) { - int i, iObj, NameId; + int i, iObj, iFon, NameId; Cba_NtkCleanFonNames( p ); - Cba_NtkForEachPi( p, iObj, i ) - Cba_FonSetName( p, Cba_ObjFon0(p, iObj), Cba_ObjName(p, iObj) ); - Cba_NtkForEachPo( p, iObj, i ) - Cba_FonSetName( p, Cba_ObjFinFon(p, iObj, 0), Cba_ObjName(p, iObj) ); - Vec_IntForEachEntryStart( &p->vFonName, NameId, i, 1 ) + Cba_NtkForEachPiFon( p, iObj, iFon, i ) + Cba_FonSetName( p, iFon, Cba_ObjName(p, iFon) ); + Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) + if ( Cba_FonIsReal(iFon) && !Cba_FonName(p, iFon) ) + Cba_FonSetName( p, iFon, Cba_ObjName(p, iFon) ); + Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) if ( NameId == 0 ) - Vec_IntWriteEntry( &p->vFonName, i, Cba_ManNewStrId(p->pDesign, pPref, i, NULL) ); + Vec_IntWriteEntry( &p->vFonName, iFon, Cba_ManNewStrId(p->pDesign, pPref, iFon, NULL) ); } static inline void Cba_NtkMissingFonNames( Cba_Ntk_t * p, char * pPref ) { - int i, iObj, iFon; - Cba_NtkForEachPi( p, iObj, i ) - if ( !Cba_FonName(p, Cba_ObjFon0(p, iObj)) ) - Cba_FonSetName( p, Cba_ObjFon0(p, iObj), Cba_ObjName(p, iObj) ); - Cba_NtkForEachPo( p, iObj, i ) - if ( Cba_ObjFinFon(p, iObj, 0) > 0 && !Cba_FonName(p, Cba_ObjFinFon(p, iObj, 0)) ) - Cba_FonSetName( p, Cba_ObjFinFon(p, iObj, 0), Cba_ObjName(p, iObj) ); - Cba_NtkForEachObj( p, iObj ) - Cba_ObjForEachFon( p, iObj, iFon, i ) - if ( !Cba_FonName(p, iFon) ) - Cba_FonSetName( p, iFon, Cba_ManNewStrId(p->pDesign, pPref, iFon, NULL) ); + int i, iObj, iFon, NameId; + Cba_NtkForEachPiFon( p, iObj, iFon, i ) + if ( !Cba_FonName(p, iFon) ) + Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); + Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) + if ( Cba_FonIsReal(iFon) && !Cba_FonName(p, iFon) ) + Cba_FonSetName( p, iFon, Cba_ObjName(p, iObj) ); + Vec_IntForEachEntryStart( &p->vFonName, NameId, iFon, 1 ) + if ( NameId == 0 ) + Cba_FonSetName( p, iFon, Cba_ManNewStrId(p->pDesign, pPref, iFon, NULL) ); } static inline void Cba_NtkCountParams( Cba_Ntk_t * p, Vec_Int_t * vObjs, int * nPis, int * nPos, int * nFins, int * nFons ) @@ -574,8 +573,7 @@ static inline Cba_Ntk_t * Cba_NtkDup( Cba_Man_t * pMan, Cba_Ntk_t * p, Vec_Int_t int i, k, iObj, iObjNew, iFin, iFon; int nPis, nPos, nFins, nFons; Cba_NtkCountParams( p, vObjs, &nPis, &nPos, &nFins, &nFons ); - pNew = Cba_NtkAlloc( pMan, 0, nPis, nPos, Vec_IntSize(vObjs), nFins, nFons ); - Cba_NtkAdd( pMan, pNew ); + pNew = Cba_NtkAlloc( pMan, Cba_NtkNameId(p), nPis, nPos, Vec_IntSize(vObjs), nFins, nFons ); Cba_NtkCleanObjCopies( p ); Cba_NtkCleanFonCopies( p ); Vec_IntForEachEntry( vObjs, iObj, i ) @@ -621,41 +619,6 @@ static inline void Cba_NtkDupAttrs( Cba_Ntk_t * pNew, Cba_Ntk_t * p ) Vec_IntAppend( &pNew->vAttrSto, &p->vAttrSto ); pNew->vOther = p->vOther ? (Vec_Ptr_t *)Vec_VecDup( (Vec_Vec_t *)p->vOther ) : NULL; } - -static inline void Cba_NtkFree( Cba_Ntk_t * p ) -{ - // interface - Vec_IntErase( &p->vInputs ); - Vec_IntErase( &p->vOutputs ); - Vec_IntErase( &p->vOrder ); - // stucture - Vec_StrErase( &p->vObjType ); - Vec_IntErase( &p->vObjFin0 ); - Vec_IntErase( &p->vObjFon0 ); - Vec_IntErase( &p->vFinFon ); - Vec_IntErase( &p->vFonObj ); - // optional - Vec_IntErase( &p->vObjCopy ); - Vec_IntErase( &p->vObjFunc ); - Vec_IntErase( &p->vObjName ); - Vec_IntErase( &p->vObjAttr ); - Vec_IntErase( &p->vAttrSto ); - Vec_IntErase( &p->vFonCopy ); - Vec_IntErase( &p->vFonName ); - Vec_IntErase( &p->vFonRange ); - Vec_IntErase( &p->vFonLeft ); - Vec_IntErase( &p->vFonRight ); - Vec_IntErase( &p->vFonPrev ); - Vec_IntErase( &p->vFonNext ); - Vec_IntErase( &p->vFinFon0 ); - Vec_IntErase( &p->vFinObj ); - Vec_IntErase( &p->vNtkObjs ); - // other - Vec_IntErase( &p->vArray0 ); - Vec_IntErase( &p->vArray1 ); - if ( p->vOther ) Vec_VecFree( (Vec_Vec_t *)p->vOther ); - ABC_FREE( p ); -} static inline int Cba_NtkMemory( Cba_Ntk_t * p ) { int nMem = sizeof(Cba_Ntk_t); @@ -690,29 +653,14 @@ static inline int Cba_NtkMemory( Cba_Ntk_t * p ) nMem += (int)Vec_IntMemory(&p->vArray1 ); return nMem; } -static inline int Cba_NtkIsTopoOrder( Cba_Ntk_t * p ) -{ - int i, iObj, iFin, iFanin, fTopo = 1; - Vec_Bit_t * vVisited = Vec_BitStart( Cba_NtkObjNum(p) + 1 ); - Cba_NtkForEachObj( p, iObj ) - { - Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, i ) - if ( !Vec_BitEntry(vVisited, iFanin) ) - fTopo = 0; - if ( !fTopo ) - break; - Vec_BitWriteEntry( vVisited, iObj, 1 ); - } - Vec_BitFree( vVisited ); - return fTopo; -} static inline void Cba_NtkPrintStats( Cba_Ntk_t * p ) { printf( "pi =%5d ", Cba_NtkPiNum(p) ); printf( "po =%5d ", Cba_NtkPoNum(p) ); - printf( "user =%6d ", Cba_NtkBoxUserNum(p) ); - printf( "prim =%6d ", Cba_NtkBoxPrimNum(p) ); - printf( "topo =%4s ", Cba_NtkIsTopoOrder(p) ? "yes" : "no" ); + printf( "box =%5d ", Cba_NtkBoxNum(p) ); + printf( "prim =%5d ", Cba_NtkBoxPrimNum(p) ); + printf( "user =%5d ", Cba_NtkBoxUserNum(p) ); + //printf( "topo =%4s ", Cba_NtkIsTopoOrder(p) ? "yes" : "no" ); printf( " %s ", Cba_NtkName(p) ); if ( Vec_IntSize(&p->vNtkObjs) ) printf( "-> %s", Cba_NtkName(Cba_NtkNtk(p, Vec_IntEntry(&p->vNtkObjs, 0))) ); @@ -761,10 +709,11 @@ static inline Cba_Man_t * Cba_ManAlloc( char * pFileName, int nNtks, Abc_Nam_t * static inline Cba_Man_t * Cba_ManDup( Cba_Man_t * p, Vec_Int_t*(* pFuncOrder)(Cba_Ntk_t*) ) { Cba_Ntk_t * pNtk, * pNtkNew; int i; - Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, Cba_ManNtkNum(p), Abc_NamRef(p->pStrs), Abc_NamRef(p->pMods) ); + Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, Cba_ManNtkNum(p), Abc_NamRef(p->pStrs), Abc_NamStart(100, 24) ); Cba_ManForEachNtk( p, pNtk, i ) { pNtkNew = Cba_NtkDupOrder( pNew, pNtk, pFuncOrder ); + Cba_NtkAdd( pNew, pNtkNew ); Cba_NtkDupAttrs( pNtkNew, pNtk ); } // Cba_ManForEachNtk( p, pNtk, i ) @@ -787,14 +736,6 @@ static inline void Cba_ManFree( Cba_Man_t * p ) ABC_FREE( p->pSpec ); ABC_FREE( p ); } -static inline int Cba_ManIsTopOrder( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk; int i; - Cba_ManForEachNtk( p, pNtk, i ) - if ( !Cba_NtkIsTopoOrder(pNtk) ) - return 0; - return 1; -} static inline int Cba_ManMemory( Cba_Man_t * p ) { Cba_Ntk_t * pNtk; int i; @@ -880,6 +821,13 @@ static inline void Cba_ManPrintStats( Cba_Man_t * p, int nModules, int fVerbose /*=== cbaCba.c ===============================================================*/ /*=== cbaCom.c ===============================================================*/ /*=== cbaNtk.c ===============================================================*/ +extern int Cba_ManIsTopOrder( Cba_Man_t * p, int(* pFuncIsSeq)(Cba_Ntk_t*, int) ); +extern Vec_Int_t * Cba_NtkCollectDfs( Cba_Ntk_t * p ); +extern Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p, int TypeBuf ); +extern Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs ); +extern Cba_Man_t * Cba_ManDeriveFromGia( Gia_Man_t * pGia ); +extern Cba_Man_t * Cba_ManInsertGroup( Cba_Man_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ); + /*=== cbaReadBlif.c ==========================================================*/ extern Vec_Ptr_t * Prs_ManReadBlif( char * pFileName ); /*=== cbaReadVer.c ===========================================================*/ diff --git a/src/base/cba/cbaCom.c b/src/base/cba/cbaCom.c index d1ad95c5..21db2e90 100644 --- a/src/base/cba/cbaCom.c +++ b/src/base/cba/cbaCom.c @@ -522,7 +522,7 @@ int Cba_CommandClp( Abc_Frame_t * pAbc, int argc, char ** argv ) } #if 0 - pNew = Cba_ManCollapse( p ); + pNew = Cba_ManCollapse( p, CBA_BOX_BUF ); Cba_AbcUpdateMan( pAbc, pNew ); #endif diff --git a/src/base/cba/cbaNtk.c b/src/base/cba/cbaNtk.c index 821e9cfd..5ed4542a 100644 --- a/src/base/cba/cbaNtk.c +++ b/src/base/cba/cbaNtk.c @@ -32,6 +32,161 @@ ABC_NAMESPACE_IMPL_START /**Function************************************************************* + Synopsis [Returns 1 if the manager is in the topo order.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Cba_NtkIsTopoOrder( Cba_Ntk_t * p, int(* pFuncIsSeq)(Cba_Ntk_t*, int) ) +{ + int i, iObj, iFin, iFanin, fTopo = 1; + Vec_Bit_t * vVisited = Vec_BitStart( Cba_NtkObjNum(p) + 1 ); + // mark PIs and seq objects + Cba_NtkForEachObj( p, iObj ) + if ( Cba_ObjIsPi(p, iObj) || pFuncIsSeq(p, iObj) ) + Vec_BitWriteEntry( vVisited, iObj, 1 ); + // visit combinational nodes + Cba_NtkForEachBox( p, iObj ) + if ( !pFuncIsSeq(p, iObj) ) + { + Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, i ) + if ( !Vec_BitEntry(vVisited, iFanin) ) + fTopo = 0; + if ( !fTopo ) + break; + Vec_BitWriteEntry( vVisited, iObj, 1 ); + } + // visit POs and seq objects + Cba_NtkForEachObj( p, iObj ) + if ( Cba_ObjIsPo(p, iObj) || pFuncIsSeq(p, iObj) ) + { + Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, i ) + if ( !Vec_BitEntry(vVisited, iFanin) ) + fTopo = 0; + if ( !fTopo ) + break; + } + Vec_BitFree( vVisited ); + return fTopo; +} +int Cba_ManIsTopOrder( Cba_Man_t * p, int(* pFuncIsSeq)(Cba_Ntk_t*, int) ) +{ + Cba_Ntk_t * pNtk; int i; + Cba_ManForEachNtk( p, pNtk, i ) + if ( !Cba_NtkIsTopoOrder(pNtk, pFuncIsSeq) ) + return 0; + return 1; +} + +/**Function************************************************************* + + Synopsis [Collect nodes in the DFS order.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Cba_NtkCollectDfs_rec( Cba_Ntk_t * p, int iObj, Vec_Int_t * vObjs ) +{ + int iFin, iFanin, k; + if ( !Cba_ObjCopy(p, iObj) ) + return; + Cba_ObjSetCopy( p, iObj, 0 ); + Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) + Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); + Vec_IntPush( vObjs, iObj ); +} +Vec_Int_t * Cba_NtkCollectDfs( Cba_Ntk_t * p ) +{ + int i, k, iObj, iFin, iFanin; + Vec_Int_t * vObjs = Vec_IntAlloc( Cba_NtkObjNum(p) ); + // collect PIs + Cba_NtkForEachPi( p, iObj, i ) + Vec_IntPush( vObjs, iObj ); + // prepare leaves + Cba_NtkCleanObjCopies( p ); + Vec_IntForEachEntry( vObjs, iObj, i ) + Cba_ObjSetCopy( p, iObj, 0 ); + // collect internal + Cba_NtkForEachPo( p, iObj, i ) + Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) + Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); + // additionally collect user modules without outputs + Cba_NtkForEachBoxUser( p, iObj ) + if ( Cba_ObjFonNum(p, iObj) == 0 ) + Cba_ObjForEachFinFaninReal( p, iObj, iFin, iFanin, k ) + Cba_NtkCollectDfs_rec( p, iFanin, vObjs ); + // collect POs + Cba_NtkForEachPo( p, iObj, i ) + Vec_IntPush( vObjs, iObj ); + // collect user boxes without fanouts + Cba_NtkForEachBoxUser( p, iObj ) + if ( Cba_ObjFonNum(p, iObj) == 0 ) + Vec_IntPush( vObjs, iObj ); + assert( Vec_IntSize(vObjs) <= Cba_NtkObjNum(p) ); + if ( Vec_IntSize(vObjs) != Cba_NtkObjNum(p) ) + printf( "Warning: DSF ordering collected %d out of %d objects.\n", Vec_IntSize(vObjs), Cba_NtkObjNum(p) ); + return vObjs; +} + + +/**Function************************************************************* + + Synopsis [Count number of objects after collapsing.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Cba_ManGetClpStats_rec( Cba_Ntk_t * p, int * pCountN, int * pCountI, int * pCountO ) +{ + int iObj, Id = Cba_NtkId(p); + if ( pCountN[Id] >= 0 ) + return; + pCountN[Id] = pCountI[Id] = pCountO[Id] = 0; + Cba_NtkForEachObj( p, iObj ) + if ( Cba_ObjIsBoxPrim(p, iObj) ) + { + pCountN[Id] += 1; + pCountI[Id] += Cba_ObjFinNum(p, iObj); + pCountO[Id] += Cba_ObjFonNum(p, iObj); + } + else if ( Cba_ObjIsBoxUser(p, iObj) ) + { + int NtkId = Cba_ObjNtkId(p, iObj); + Cba_ManGetClpStats_rec( Cba_ObjNtk(p, iObj), pCountN, pCountI, pCountO ); + pCountN[Id] += pCountN[NtkId] + Cba_ObjFonNum(p, iObj); + pCountI[Id] += pCountI[NtkId] + Cba_ObjFonNum(p, iObj); + pCountO[Id] += pCountO[NtkId] + Cba_ObjFonNum(p, iObj); + } +} +void Cba_ManGetClpStats( Cba_Man_t * p, int * nObjs, int * nFins, int * nFons ) +{ + int * pCountN = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); + int * pCountI = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); + int * pCountO = ABC_FALLOC( int, Cba_ManNtkNum(p) + 1 ); + Cba_Ntk_t * pRoot = Cba_ManRoot(p); + Cba_ManGetClpStats_rec( pRoot, pCountN, pCountI, pCountO ); + *nObjs = Cba_NtkPioNum(pRoot) + pCountN[Cba_NtkId(pRoot)]; + *nFins = Cba_NtkPoNum(pRoot) + pCountI[Cba_NtkId(pRoot)]; + *nFons = Cba_NtkPiNum(pRoot) + pCountO[Cba_NtkId(pRoot)]; + ABC_FREE( pCountN ); + ABC_FREE( pCountI ); + ABC_FREE( pCountO ); +} + +/**Function************************************************************* + Synopsis [] Description [] @@ -41,6 +196,423 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ +void Cba_NtkCollapse_rec( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vSigs, int TypeBuf ) +{ + int i, iObj, iObjNew, iFin, iFon; + Cba_NtkCleanObjCopies( p ); + Cba_NtkCleanFonCopies( p ); + // set PI copies + assert( Vec_IntSize(vSigs) == Cba_NtkPiNum(p) ); + Cba_NtkForEachPiFon( p, iObj, iFon, i ) + Cba_FonSetCopy( p, iFon, Vec_IntEntry(vSigs, i) ); + // duplicate primitives and create buffers for user instances + Cba_NtkForEachObj( p, iObj ) + if ( Cba_ObjIsBoxPrim( p, iObj ) ) + { + iObjNew = Cba_ObjDup( pNew, p, iObj ); + Cba_ObjForEachFon( p, iObj, iFon, i ) + Cba_FonSetCopy( p, iFon, Cba_ObjFon(pNew, iObjNew, i) ); + if ( Cba_ObjAttr(p, iObj) ) + Cba_ObjSetAttrs( pNew, iObjNew, Cba_ObjAttrArray(p, iObj), Cba_ObjAttrSize(p, iObj) ); + } + else if ( Cba_ObjIsBoxUser( p, iObj ) ) + { + Cba_ObjForEachFon( p, iObj, iFon, i ) + { + iObjNew = Cba_ObjAlloc( pNew, TypeBuf, 1, 1 ); + Cba_FonSetCopy( p, iFon, Cba_ObjFon0(pNew, iObjNew) ); + } + } + // connect primitives and collapse user instances + Cba_NtkForEachObj( p, iObj ) + if ( Cba_ObjIsBoxPrim( p, iObj ) ) + { + iObjNew = Cba_ObjCopy( p, iObj ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + Cba_ObjSetFinFon( pNew, iObjNew, i, Cba_FonCopy(p, iFon) ); + } + else if ( Cba_ObjIsBoxUser( p, iObj ) ) + { + Vec_IntClear( vSigs ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i ) + Vec_IntPush( vSigs, Cba_FonCopy(p, iFon) ); + assert( Vec_IntSize(vSigs) == Cba_ObjFinNum(p, iObj) ); + Cba_NtkCollapse_rec( pNew, Cba_ObjNtk(p, iObj), vSigs, TypeBuf ); + assert( Vec_IntSize(vSigs) == Cba_ObjFonNum(p, iObj) ); + Cba_ObjForEachFon( p, iObj, iFon, i ) + { + iObjNew = Cba_FonObj( pNew, Cba_FonCopy(p, iFon) ); // buffer + Cba_ObjSetFinFon( pNew, iObjNew, 0, Vec_IntEntry(vSigs, i) ); + } + } + // collect POs + Vec_IntClear( vSigs ); + Cba_NtkForEachPoDriverFon( p, iObj, iFon, i ) + Vec_IntPush( vSigs, Cba_FonCopy(p, iFon) ); +} +Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p, int TypeBuf ) +{ + Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamStart(100, 24) ); + Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew; + Vec_Int_t * vSigs = Vec_IntAlloc( 1000 ); + int i, iObj, iObjNew, iFon, nObjs = 0, nFins = 0, nFons = 0; + Cba_ManGetClpStats( p, &nObjs, &nFins, &nFons ); + pRootNew = Cba_NtkAlloc( pNew, Cba_NtkNameId(pRoot), Cba_NtkPiNum(pRoot), Cba_NtkPoNum(pRoot), nObjs, nFins, nFons ); + Cba_NtkAdd( pNew, pRootNew ); + if ( Cba_NtkHasObjNames(pRoot) ) + Cba_NtkCleanObjNames( pRootNew ); + if ( Cba_NtkHasFonNames(pRoot) ) + Cba_NtkCleanFonNames( pRootNew ); + if ( Cba_NtkHasObjAttrs(pRoot) ) + Cba_NtkCleanObjAttrs( pRootNew ); + if ( Cba_ObjAttr(pRoot, 0) ) + Cba_ObjSetAttrs( pRootNew, 0, Cba_ObjAttrArray(pRoot, 0), Cba_ObjAttrSize(pRoot, 0) ); + Cba_NtkCleanObjCopies( pRoot ); + Cba_NtkForEachPiFon( pRoot, iObj, iFon, i ) + { + iObjNew = Cba_ObjDup( pRootNew, pRoot, iObj ); + Vec_IntPush( vSigs, Cba_ObjFon0(pRootNew, iObjNew) ); + if ( Cba_NtkHasObjNames(pRoot) ) + Cba_ObjSetName( pRootNew, iObjNew, Cba_ObjName(pRoot, iObj) ); + if ( Cba_NtkHasFonNames(pRoot) ) + Cba_FonSetName( pRootNew, Cba_ObjFon0(pRootNew, iObjNew), Cba_FonName(pRoot, iFon) ); + if ( Cba_ObjAttr(pRoot, iObj) ) + Cba_ObjSetAttrs( pRootNew, iObjNew, Cba_ObjAttrArray(pRoot, iObj), Cba_ObjAttrSize(pRoot, iObj) ); + } + assert( Vec_IntSize(vSigs) == Cba_NtkPiNum(pRoot) ); + Cba_NtkCollapse_rec( pRootNew, pRoot, vSigs, TypeBuf ); + assert( Vec_IntSize(vSigs) == Cba_NtkPoNum(pRoot) ); + Cba_NtkForEachPoDriverFon( pRoot, iObj, iFon, i ) + { + iObjNew = Cba_ObjDup( pRootNew, pRoot, iObj ); + Cba_ObjSetFinFon( pRootNew, iObjNew, 0, Vec_IntEntry(vSigs, i) ); + if ( Cba_NtkHasObjNames(pRoot) ) + Cba_ObjSetName( pRootNew, iObjNew, Cba_ObjName(pRoot, iObj) ); + if ( Cba_NtkHasFonNames(pRoot) ) + Cba_FonSetName( pRootNew, Vec_IntEntry(vSigs, i), Cba_FonName(pRoot, iFon) ); + if ( Cba_ObjAttr(pRoot, iObj) ) + Cba_ObjSetAttrs( pRootNew, iObjNew, Cba_ObjAttrArray(pRoot, iObj), Cba_ObjAttrSize(pRoot, iObj) ); + } + Vec_IntFree( vSigs ); + assert( Cba_NtkObjNum(pRootNew) == Cba_NtkObjNumAlloc(pRootNew) ); + assert( Cba_NtkFinNum(pRootNew) == Cba_NtkFinNumAlloc(pRootNew) ); + assert( Cba_NtkFonNum(pRootNew) == Cba_NtkFonNumAlloc(pRootNew) ); + // create internal node names + Cba_NtkMissingFonNames( pRootNew, "m" ); + return pNew; +} + + + +/**Function************************************************************* + + Synopsis [Performs the reverse of collapsing.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Cba_NtkCollectInFons( Cba_Ntk_t * p, Vec_Int_t * vObjs ) +{ + Vec_Int_t * vFons = Vec_IntAlloc( 100 ); + Vec_Bit_t * vVisFons = Vec_BitStart( Cba_NtkFonNum(p) + 1 ); + int i, k, iObj, iFin, iFon, Entry; + // mark fanin fons + Vec_IntForEachEntry( vObjs, iObj, i ) + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + if ( iFon > 0 ) + Vec_BitWriteEntry( vVisFons, iFon, 1 ); + // unmark internal fons + Vec_IntForEachEntry( vObjs, iObj, i ) + Cba_ObjForEachFon( p, iObj, iFon, k ) + Vec_BitWriteEntry( vVisFons, iFon, 0 ); + // collect fons + Vec_BitForEachEntry( vVisFons, Entry, iFon ) + if ( Entry ) + Vec_IntPush( vFons, iFon ); + Vec_BitFree( vVisFons ); + return vFons; +} +Vec_Int_t * Cba_NtkCollectOutFons( Cba_Ntk_t * p, Vec_Int_t * vObjs ) +{ + Vec_Int_t * vFons = Vec_IntAlloc( 100 ); + Vec_Bit_t * vMapObjs = Vec_BitStart( Cba_NtkObjNum(p) + 1 ); + Vec_Bit_t * vVisFons = Vec_BitStart( Cba_NtkFonNum(p) + 1 ); + int i, k, iObj, iFin, iFon; + // map objects + Vec_IntForEachEntry( vObjs, iObj, i ) + Vec_BitWriteEntry( vMapObjs, iObj, 1 ); + // mark those used by non-objects + Cba_NtkForEachObj( p, iObj ) + if ( !Vec_BitEntry(vMapObjs, iObj) ) + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + if ( iFon > 0 ) + Vec_BitWriteEntry( vVisFons, iFon, 1 ); + // collect pointed fons among those in objects + Vec_IntForEachEntry( vObjs, iObj, i ) + Cba_ObjForEachFon( p, iObj, iFon, k ) + if ( Vec_BitEntry(vVisFons, iFon) ) + Vec_IntPush( vFons, iFon ); + Vec_BitFree( vMapObjs ); + Vec_BitFree( vVisFons ); + return vFons; +} +void Cba_NtkCollectGroupStats( Cba_Ntk_t * p, Vec_Int_t * vObjs, int * pnFins, int * pnFons ) +{ + int i, iObj, nFins = 0, nFons = 0; + Vec_IntForEachEntry( vObjs, iObj, i ) + { + nFins += Cba_ObjFinNum(p, iObj); + nFons += Cba_ObjFonNum(p, iObj); + } + *pnFins = nFins; + *pnFons = nFons; +} +void Cba_ManExtractGroupInt( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vObjs, Vec_Int_t * vFonIns, Vec_Int_t * vFonOuts ) +{ + int i, k, iObj, iObjNew, iFin, iFon; + Cba_NtkCleanObjCopies( p ); + Cba_NtkCleanFonCopies( p ); + // create inputs and map fons + Vec_IntForEachEntry( vFonIns, iFon, i ) + { + iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_PI, 0, 1 ); + Cba_FonSetCopy( p, iFon, Cba_ObjFon0(pNew, iObjNew) ); + if ( Cba_NtkHasObjNames(p) ) + Cba_ObjSetName( pNew, iObjNew, Cba_ObjName(p, Cba_FonObj(p, iFon)) ); + if ( Cba_NtkHasFonNames(p) ) + Cba_FonSetName( pNew, Cba_ObjFon0(pNew, iObjNew), Cba_FonName(p, iFon) ); + + } + // create internal + Vec_IntForEachEntry( vObjs, iObj, i ) + { + iObjNew = Cba_ObjDup( pNew, p, iObj ); + if ( Cba_NtkHasObjNames(p) ) + Cba_ObjSetName( pNew, iObjNew, Cba_ObjName(p, iObj) ); + Cba_ObjForEachFon( p, iObj, iFon, k ) + { + Cba_FonSetCopy( p, iFon, Cba_ObjFon(pNew, iObjNew, k) ); + if ( Cba_NtkHasFonNames(p) ) + Cba_FonSetName( pNew, Cba_ObjFon(pNew, iObjNew, k), Cba_FonName(p, iFon) ); + } + } + // connect internal + Vec_IntForEachEntry( vObjs, iObj, i ) + { + iObjNew = Cba_ObjCopy( p, iObj ); + Cba_ObjForEachFinFon( p, iObj, iFin, iFon, k ) + Cba_ObjSetFinFon( pNew, iObjNew, k, Cba_FonCopy(p, iFon) ); + } + // create POs + Vec_IntForEachEntry( vFonOuts, iFon, i ) + { + iObjNew = Cba_ObjAlloc( pNew, CBA_OBJ_PO, 1, 0 ); + if ( Cba_NtkHasObjNames(p) ) + Cba_ObjSetName( pNew, iObjNew, Cba_FonName(p, iFon) ); + Cba_ObjSetFinFon( pNew, iObjNew, 0, Cba_FonCopy(p, iFon) ); + } + assert( Cba_NtkObjNum(pNew) == Cba_NtkObjNumAlloc(pNew) ); + assert( Cba_NtkFinNum(pNew) == Cba_NtkFinNumAlloc(pNew) ); + assert( Cba_NtkFonNum(pNew) == Cba_NtkFonNumAlloc(pNew) ); +} +Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs ) +{ + Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamStart(100, 24) ); + Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew; + Vec_Int_t * vFonIns = Cba_NtkCollectInFons( pRoot, vObjs ); + Vec_Int_t * vFonOuts = Cba_NtkCollectOutFons( pRoot, vObjs ); + int nObjs, nFins, nFons; + // collect stats + Cba_NtkCollectGroupStats( pRoot, vObjs, &nFins, &nFons ); + nObjs = Vec_IntSize(vObjs) + Vec_IntSize(vFonIns) + Vec_IntSize(vFonOuts); + nFins += Vec_IntSize(vFonOuts); + nFons += Vec_IntSize(vFonIns); + // create network + pRootNew = Cba_NtkAlloc( pNew, Cba_NtkNameId(pRoot), Vec_IntSize(vFonIns), Vec_IntSize(vFonOuts), nObjs, nFins, nFons ); + Cba_NtkAdd( pNew, pRootNew ); + if ( Cba_NtkHasObjNames(pRoot) ) + Cba_NtkCleanObjNames( pRootNew ); + if ( Cba_NtkHasFonNames(pRoot) ) + Cba_NtkCleanFonNames( pRootNew ); + // add group nodes + Cba_ManExtractGroupInt( pRootNew, pRoot, vObjs, vFonIns, vFonOuts ); + Cba_NtkMissingFonNames( pRootNew, "b" ); + // cleanup + Vec_IntFree( vFonIns ); + Vec_IntFree( vFonOuts ); + return pNew; +} + + +/**Function************************************************************* + + Synopsis [Derives the design from the GIA manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Cba_NtkInsertGiaLit( Cba_Ntk_t * p, int iLit, Vec_Int_t * vLit2Fon ) +{ + int iObjNew; + if ( iLit == 0 || iLit == 1 ) + return Cba_FonFromConst(iLit); + if ( Vec_IntEntry(vLit2Fon, iLit) >= 0 ) + return Vec_IntEntry(vLit2Fon, iLit); + assert( Abc_LitIsCompl(iLit) ); + assert( Vec_IntEntry(vLit2Fon, Abc_LitNot(iLit)) >= 0 ); + iObjNew = Cba_ObjAlloc( p, CBA_BOX_INV, 1, 1 ); + Cba_ObjSetFinFon( p, iObjNew, 0, Vec_IntEntry(vLit2Fon, Abc_LitNot(iLit)) ); + Vec_IntWriteEntry( vLit2Fon, iLit, Cba_ObjFon0(p, iObjNew) ); + return Cba_ObjFon0(p, iObjNew); +} +static inline int Cba_NtkInsertGiaObj( Cba_Ntk_t * p, Gia_Man_t * pGia, int iObj, Vec_Int_t * vLit2Fon ) +{ + Gia_Obj_t * pObj = Gia_ManObj( pGia, iObj ); + int iLit0 = Gia_ObjFaninLit0( pObj, iObj ); + int iLit1 = Gia_ObjFaninLit1( pObj, iObj ); + int iFon0 = Cba_NtkInsertGiaLit( p, iLit0, vLit2Fon ); + int iFon1 = Cba_NtkInsertGiaLit( p, iLit1, vLit2Fon ); + int iObjNew; + if ( Gia_ObjIsMux(pGia, pObj) ) + { + int iLit2 = Gia_ObjFaninLit2( pGia, iObj ); + int iFon2 = Cba_NtkInsertGiaLit( p, iLit2, vLit2Fon ); + iObjNew = Cba_ObjAlloc( p, CBA_BOX_MUX, 3, 1 ); + Cba_ObjSetFinFon( p, iObjNew, 0, iFon2 ); + Cba_ObjSetFinFon( p, iObjNew, 1, iFon1 ); + Cba_ObjSetFinFon( p, iObjNew, 2, iFon0 ); + } + else + { + assert( Gia_ObjIsAnd(pObj) ); + iObjNew = Cba_ObjAlloc( p, Gia_ObjIsXor(pObj) ? CBA_BOX_XOR : CBA_BOX_AND, 2, 1 ); + Cba_ObjSetFinFon( p, iObjNew, 0, iFon0 ); + Cba_ObjSetFinFon( p, iObjNew, 1, iFon1 ); + } + Vec_IntWriteEntry( vLit2Fon, Abc_Var2Lit(iObj, 0), Cba_ObjFon0(p, iObjNew) ); + return iObjNew; +} +Cba_Man_t * Cba_ManDeriveFromGia( Gia_Man_t * pGia ) +{ + Cba_Man_t * p = Cba_ManAlloc( pGia->pSpec, 1, NULL, NULL ); + Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, Abc_NamStrFindOrAdd(p->pStrs, pGia->pName, NULL), Gia_ManCiNum(pGia), Gia_ManCoNum(pGia), 1000, 2000, 1000 ); + Vec_Int_t * vLit2Fon = Vec_IntStartFull( 2*Gia_ManObjNum(pGia) ); + int i, iObj, iObjNew, NameId, iLit0, iFon0; + Gia_Obj_t * pObj; + Cba_NtkAdd( p, pNtk ); + Cba_NtkCleanObjNames( pNtk ); + Gia_ManForEachCiId( pGia, iObj, i ) + { + NameId = pGia->vNamesIn? Abc_NamStrFindOrAdd(p->pStrs, Vec_PtrEntry(pGia->vNamesIn, i), NULL) : Cba_ManNewStrId(p, "i", i, NULL); + iObjNew = Cba_ObjAlloc( pNtk, CBA_OBJ_PI, 0, 1 ); + Cba_ObjSetName( pNtk, iObjNew, NameId ); + Vec_IntWriteEntry( vLit2Fon, Abc_Var2Lit(iObj, 0), Cba_ObjFon0(pNtk, iObjNew) ); + } + Gia_ManForEachAndId( pGia, iObj ) + Cba_NtkInsertGiaObj( pNtk, pGia, iObj, vLit2Fon ); + // create inverters if needed + Gia_ManForEachCoId( pGia, iObj, i ) + { + pObj = Gia_ManObj( pGia, iObj ); + iLit0 = Gia_ObjFaninLit0( pObj, iObj ); + iFon0 = Cba_NtkInsertGiaLit( pNtk, iLit0, vLit2Fon ); // can be const! + } + Gia_ManForEachCoId( pGia, iObj, i ) + { + pObj = Gia_ManObj( pGia, iObj ); + iLit0 = Gia_ObjFaninLit0( pObj, iObj ); + iFon0 = Cba_NtkInsertGiaLit( pNtk, iLit0, vLit2Fon ); // can be const! + NameId = pGia->vNamesOut? Abc_NamStrFindOrAdd(p->pStrs, Vec_PtrEntry(pGia->vNamesOut, i), NULL) : Cba_ManNewStrId(p, "o", i, NULL); + iObjNew = Cba_ObjAlloc( pNtk, CBA_OBJ_PO, 1, 0 ); + Cba_ObjSetName( pNtk, iObjNew, NameId ); + Cba_ObjSetFinFon( pNtk, iObjNew, 0, iFon0 ); + } + Cba_NtkCleanFonNames( pNtk ); + Cba_NtkCreateFonNames( pNtk, "a" ); + Vec_IntFree( vLit2Fon ); + return p; +} + + +/**Function************************************************************* + + Synopsis [Inserts the network into the root module instead of objects.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Cba_NtkInsertGroup( Cba_Ntk_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ) +{ + Vec_Int_t * vFonIns = Cba_NtkCollectInFons( p, vObjs ); + Vec_Int_t * vFonOuts = Cba_NtkCollectOutFons( p, vObjs ); + int i, iObj, iObjNew, iFin, iFon; + assert( Cba_NtkPiNum(pSyn) == Vec_IntSize(vFonIns) ); + assert( Cba_NtkPoNum(pSyn) == Vec_IntSize(vFonOuts) ); + // mark AIG with the input fons + Cba_NtkCleanFonCopies( pSyn ); + Cba_NtkForEachPiFon( pSyn, iObj, iFon, i ) + Cba_FonSetCopy( pSyn, iFon, Vec_IntEntry(vFonIns, i) ); + Vec_IntFree( vFonIns ); + // build up internal nodes + Cba_NtkCleanObjCopies( pSyn ); + Cba_NtkForEachBox( pSyn, iObj ) + { + iObjNew = Cba_ObjDup( p, pSyn, iObj ); + Cba_ObjForEachFon( pSyn, iObj, iFon, i ) + Cba_FonSetCopy( pSyn, iFon, Cba_ObjFon(p, iObjNew, i) ); + } + // connect internal nodes + Cba_NtkForEachBox( pSyn, iObj ) + { + iObjNew = Cba_ObjCopy( pSyn, iObj ); + Cba_ObjForEachFinFon( pSyn, iObj, iFin, iFon, i ) + Cba_ObjSetFinFon( p, iObjNew, i, Cba_FonCopy(pSyn, iFon) ); + } + // connect output fons + Cba_NtkCleanFonCopies( p ); + Cba_NtkForEachPoDriverFon( pSyn, iObj, iFon, i ) + Cba_FonSetCopy( p, Vec_IntEntry(vFonOuts, i), Cba_FonCopy(pSyn, iFon) ); + Vec_IntFree( vFonOuts ); + // update fins pointing to output fons to point to the new fons + if ( Cba_NtkHasFonNames(p) ) + Vec_IntFillExtra( &p->vFonName, Cba_NtkFonNum(p) + 1, 0 ); + Cba_NtkForEachFinFon( p, iFon, iFin ) + if ( Cba_FonIsReal(iFon) && Cba_FonCopy(p, iFon) ) + { + Cba_PatchFinFon( p, iFin, Cba_FonCopy(p, iFon) ); + if ( Cba_NtkHasFonNames(p) && Cba_FonIsReal(Cba_FonCopy(p, iFon)) ) + { + Cba_FonSetName( p, Cba_FonCopy(p, iFon), Cba_FonName(p, iFon) ); + Cba_FonCleanName( p, iFon ); + } + } + Cba_NtkMissingFonNames( p, "j" ); +/* + // duplicate in DFS order + pNew = Cba_NtkDupOrder( p->pDesign, p, Cba_NtkCollectDfs ); + Cba_NtkDupAttrs( pNew, p ); + // replace "p" with "pNew" + Cba_NtkUpdate( Cba_NtkMan(p), pNew ); // removes "p" + return pNew; +*/ +} +Cba_Man_t * Cba_ManInsertGroup( Cba_Man_t * p, Vec_Int_t * vObjs, Cba_Ntk_t * pSyn ) +{ + Cba_NtkInsertGroup( Cba_ManRoot(p), vObjs, pSyn ); + return Cba_ManDup( p, Cba_NtkCollectDfs ); +} //////////////////////////////////////////////////////////////////////// /// END OF FILE /// |