diff options
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/cba/cba.h | 115 | ||||
-rw-r--r-- | src/base/cba/cbaBlast.c | 305 | ||||
-rw-r--r-- | src/base/cba/cbaBuild.c | 207 | ||||
-rw-r--r-- | src/base/cba/cbaNtk.c | 127 | ||||
-rw-r--r-- | src/base/cba/cbaSimple.c | 113 | ||||
-rw-r--r-- | src/base/cba/cbaWriteBlif.c | 2 | ||||
-rw-r--r-- | src/base/cba/cbaWriteVer.c | 40 |
7 files changed, 467 insertions, 442 deletions
diff --git a/src/base/cba/cba.h b/src/base/cba/cba.h index 56db6f29..15e94461 100644 --- a/src/base/cba/cba.h +++ b/src/base/cba/cba.h @@ -61,19 +61,22 @@ typedef enum { // Verilog predefined models typedef enum { CBA_NODE_NONE = 0, // 0: unused - CBA_NODE_CONST, // 1: constant - CBA_NODE_BUF, // 2: buffer - CBA_NODE_INV, // 3: inverter - CBA_NODE_AND, // 4: AND - CBA_NODE_NAND, // 5: NAND - CBA_NODE_OR, // 6: OR - CBA_NODE_NOR, // 7: NOR - CBA_NODE_XOR, // 8: XOR - CBA_NODE_XNOR, // 9 .XNOR - CBA_NODE_MUX, // 10: MUX - CBA_NODE_MAJ, // 11: MAJ - CBA_NODE_KNOWN, // 12: unknown - CBA_NODE_UNKNOWN // 13: unknown + CBA_NODE_C0, // 1: logic node + CBA_NODE_C1, // 2: logic node + CBA_NODE_BUF, // 3: buffer + CBA_NODE_INV, // 4: inverter + CBA_NODE_AND, // 5: AND + CBA_NODE_NAND, // 6: NAND + CBA_NODE_OR, // 7: OR + CBA_NODE_NOR, // 8: NOR + CBA_NODE_XOR, // 9: XOR + CBA_NODE_XNOR, // 10 XNOR + CBA_NODE_MUX, // 11: MUX + CBA_NODE_MAJ, // 12: MAJ + CBA_NODE_AND00, // 13: AND00 + CBA_NODE_AND01, // 14: AND01 + CBA_NODE_AND10, // 15: AND10 + CBA_NODE_UNKNOWN // 16: unknown } Cba_NodeType_t; @@ -150,7 +153,8 @@ static inline char * Cba_NtkFuncStr( Cba_Ntk_t * p, int i ) { r static inline Vec_Set_t * Cba_NtkMem( Cba_Ntk_t * p ) { return Cba_ManMem(p->pDesign); } static inline int Cba_NtkMemSave( Cba_Ntk_t * p, int * d, int s ) { return Cba_ManMemSave(p->pDesign, d, s); } static inline int * Cba_NtkMemRead( Cba_Ntk_t * p, int h ) { return Cba_ManMemRead(p->pDesign, h); } -static inline Cba_Ntk_t * Cba_NtkHost( Cba_Ntk_t * p ) { return Cba_ManNtk(p->pDesign, p->iBoxNtk); } +static inline Cba_Ntk_t * Cba_NtkHostNtk( Cba_Ntk_t * p ) { return Cba_ManNtk(p->pDesign, p->iBoxNtk); } +static inline int Cba_NtkHostObj( Cba_Ntk_t * p ) { return p->iBoxObj; } static inline void Cba_NtkSetHost( Cba_Ntk_t * p, int n, int i ) { p->iBoxNtk = n; p->iBoxObj = i; } static inline Vec_Int_t * Cba_NtkCopies( Cba_Ntk_t * p ) { return &p->pDesign->vCopies; } static inline int Cba_NtkCopy( Cba_Ntk_t * p, int i ) { return Vec_IntEntry( Cba_NtkCopies(p), p->iObjStart + i ); } @@ -175,15 +179,17 @@ static inline int Cba_ObjIsCo( Cba_Ntk_t * p, int i ) { r static inline int Cba_ObjIsCio( Cba_Ntk_t * p, int i ) { return Cba_ObjIsCi(p, i) || Cba_ObjIsCo(p, i); } static inline int Cba_ObjIsBio( Cba_Ntk_t * p, int i ) { return Cba_ObjIsBi(p, i) || Cba_ObjIsBo(p, i); } -static inline int Cba_ObjFanin0( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsPo(p, i) || Cba_ObjIsBio(p, i)); return Cba_ObjFuncId(p, i); } +static inline int Cba_ObjFanin0( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsPo(p, i) || Cba_ObjIsBio(p, i)); return Cba_ObjFaninId(p, i); } static inline int * Cba_ObjFaninArray( Cba_Ntk_t * p, int i ) { assert(Cba_ObjType(p, i) >= CBA_OBJ_NODE); return Cba_NtkMemRead(p, Cba_ObjFaninId(p, i)); } static inline int Cba_ObjFaninNum( Cba_Ntk_t * p, int i ) { return *Cba_ObjFaninArray(p, i); } static inline int * Cba_ObjFanins( Cba_Ntk_t * p, int i ) { return Cba_ObjFaninArray(p, i) + 1; } static inline Vec_Int_t * Cba_ObjFaninVec( Cba_Ntk_t * p, int i ) { static Vec_Int_t V; V.pArray = Cba_ObjFaninArray(p, i); V.nSize = V.nCap = V.pArray ? *V.pArray++ : 0; return &V; } static inline Vec_Int_t * Cba_ObjFaninVec2( Cba_Ntk_t * p, int i ) { static Vec_Int_t W; W.pArray = Cba_ObjFaninArray(p, i); W.nSize = W.nCap = W.pArray ? *W.pArray++ : 0; return &W; } -static inline Cba_NodeType_t Cba_ObjNodeType( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsNode(p, i)); return Cba_ObjFaninId(p, i); } +static inline Cba_NodeType_t Cba_ObjNodeType( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsNode(p, i)); return Cba_ObjFuncId(p, i); } static inline int Cba_ObjBoxModelId( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_ObjFuncId(p, i); } static inline Cba_Ntk_t * Cba_ObjBoxModel( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_ManNtk(p->pDesign, Cba_ObjBoxModelId(p, i)); } +static inline int Cba_ObjBoxSize( Cba_Ntk_t * p, int i ) { return 1 + Cba_NtkPiNum(Cba_ObjBoxModel(p, i)) + Cba_NtkPoNum(Cba_ObjBoxModel(p, i)); } + static inline int Cba_ObjBoxBiNum( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_NtkPiNum(Cba_ObjBoxModel(p, i)); } static inline int Cba_ObjBoxBoNum( Cba_Ntk_t * p, int i ) { assert(Cba_ObjIsBox(p, i)); return Cba_NtkPoNum(Cba_ObjBoxModel(p, i)); } static inline int Cba_ObjBoxBi( Cba_Ntk_t * p, int b, int i ) { assert(Cba_ObjIsBox(p, b)); return b - Cba_ObjBoxBiNum(p, b) + i; } @@ -253,7 +259,7 @@ static inline int Cba_ManHandleBuffer( Cba_Man_t * p, int iFanin ) { int h = Vec_SetFetchH( Cba_ManMem(p), sizeof(int) * 2 ); int * pArray = (int *)Vec_SetEntry( Cba_ManMem(p), h ); - pArray[0] = 1; + pArray[0] = (iFanin >= 0) ? 1 : 0; pArray[1] = iFanin; return h; } @@ -289,6 +295,14 @@ static inline Cba_Ntk_t * Cba_NtkAlloc( Cba_Man_t * p, char * pName ) printf( "Model with name %s already exists.\n", pName ); return pNtk; } +static inline void Cba_NtkResize( Cba_Ntk_t * p, int nObjs ) +{ + assert( Vec_IntSize(&p->vTypes) == 0 ); + Cba_ManFetchArray( p->pDesign, &p->vTypes, nObjs ); + Cba_ManFetchArray( p->pDesign, &p->vFuncs, nObjs ); + Cba_ManFetchArray( p->pDesign, &p->vFanins, nObjs ); + Cba_ManFetchArray( p->pDesign, &p->vNameIds, nObjs ); +} static inline Cba_Man_t * Cba_ManAlloc( char * pFileName ) { Cba_Man_t * p = ABC_CALLOC( Cba_Man_t, 1 ); @@ -304,15 +318,25 @@ static inline Cba_Man_t * Cba_ManAlloc( char * pFileName ) } static inline Cba_Man_t * Cba_ManClone( Cba_Man_t * pOld ) { + Cba_Ntk_t * pNtk, * pNtkNew; int i; Cba_Man_t * p = ABC_CALLOC( Cba_Man_t, 1 ); p->pName = Extra_FileDesignName( pOld->pName ); p->pSpec = Abc_UtilStrsav( pOld->pSpec ); p->pNames = Abc_NamRef( pOld->pNames ); p->pModels = Abc_NamRef( pOld->pModels ); p->pFuncs = Abc_NamRef( pOld->pFuncs ); + p->iRoot = 1; Vec_SetAlloc_( &p->Mem, 20 ); Vec_PtrPush( &p->vNtks, NULL ); - p->iRoot = 1; + Cba_ManForEachNtk( pOld, pNtk, i ) + { + pNtkNew = Cba_NtkAlloc( p, Cba_NtkName(pNtk) ); + Cba_ManFetchArray( p, &pNtkNew->vInputs, Cba_NtkPiNum(pNtk) ); + Cba_ManFetchArray( p, &pNtkNew->vOutputs, Cba_NtkPoNum(pNtk) ); + Cba_ManFetchArray( p, &pNtkNew->vBoxes, Cba_NtkBoxNum(pNtk) ); + Vec_IntShrink( &pNtkNew->vBoxes, 0 ); + } + assert( Cba_ManNtkNum(p) == Cba_ManNtkNum(pOld) ); return p; } @@ -343,6 +367,58 @@ static inline int Cba_ManMemory( Cba_Man_t * p ) return nMem; } +static inline Cba_NodeType_t Ptr_SopToType( char * pSop ) +{ + if ( !strcmp(pSop, " 1\n") ) return CBA_NODE_C0; + if ( !strcmp(pSop, " 0\n") ) return CBA_NODE_C1; + if ( !strcmp(pSop, "1 1\n") ) return CBA_NODE_BUF; + if ( !strcmp(pSop, "0 1\n") ) return CBA_NODE_INV; + if ( !strcmp(pSop, "11 1\n") ) return CBA_NODE_AND; + if ( !strcmp(pSop, "00 1\n") ) return CBA_NODE_AND00; + if ( !strcmp(pSop, "01 1\n") ) return CBA_NODE_AND01; + if ( !strcmp(pSop, "10 1\n") ) return CBA_NODE_AND10; + if ( !strcmp(pSop, "00 0\n") ) return CBA_NODE_OR; + if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return CBA_NODE_OR; + if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return CBA_NODE_OR; + if ( !strcmp(pSop, "01 1\n10 1\n") ) return CBA_NODE_XOR; + if ( !strcmp(pSop, "10 1\n01 1\n") ) return CBA_NODE_XOR; + if ( !strcmp(pSop, "11 1\n00 1\n") ) return CBA_NODE_XNOR; + if ( !strcmp(pSop, "00 1\n11 1\n") ) return CBA_NODE_XNOR; + assert( 0 ); + return CBA_NODE_NONE; +} +static inline char * Ptr_TypeToName( Cba_NodeType_t Type ) +{ + if ( Type == CBA_NODE_C0 ) return "const0"; + if ( Type == CBA_NODE_C1 ) return "const1"; + if ( Type == CBA_NODE_BUF ) return "buf"; + if ( Type == CBA_NODE_INV ) return "not"; + if ( Type == CBA_NODE_AND ) return "and"; + if ( Type == CBA_NODE_AND00 ) return "and00"; + if ( Type == CBA_NODE_AND01 ) return "and01"; + if ( Type == CBA_NODE_AND10 ) return "and10"; + if ( Type == CBA_NODE_OR ) return "or"; + if ( Type == CBA_NODE_XOR ) return "xor"; + if ( Type == CBA_NODE_XNOR ) return "xnor"; + assert( 0 ); + return "???"; +} +static inline char * Ptr_TypeToSop( Cba_NodeType_t Type ) +{ + if ( Type == CBA_NODE_C0 ) return " 0\n"; + if ( Type == CBA_NODE_C1 ) return " 1\n"; + if ( Type == CBA_NODE_BUF ) return "1 1\n"; + if ( Type == CBA_NODE_INV ) return "0 1\n"; + if ( Type == CBA_NODE_AND ) return "11 1\n"; + if ( Type == CBA_NODE_AND00 ) return "00 1\n"; + if ( Type == CBA_NODE_AND01 ) return "01 1\n"; + if ( Type == CBA_NODE_AND10 ) return "10 1\n"; + if ( Type == CBA_NODE_OR ) return "00 0\n"; + if ( Type == CBA_NODE_XOR ) return "01 1\n10 1\n"; + if ( Type == CBA_NODE_XNOR ) return "00 1\n11 1\n"; + assert( 0 ); + return "???"; +} /*=== cbaBuild.c =========================================================*/ extern Cba_Man_t * Cba_ManBuild( Cba_Man_t * p ); @@ -359,8 +435,7 @@ extern void Cba_PrsWriteVerilog( char * pFileName, Cba_Man_t * p ); extern void Cba_ManAssignInternNames( Cba_Man_t * p ); extern int Cba_NtkNodeNum( Cba_Ntk_t * p ); extern int Cba_ManObjNum( Cba_Man_t * p ); -extern void Cba_ManSetNtkBoxes( Cba_Man_t * p ); -extern Cba_Man_t * Cba_ManDupStart( Cba_Man_t * p, Vec_Int_t * vObjCounts ); +extern Cba_Man_t * Cba_ManDupStart( Cba_Man_t * p, Vec_Int_t * vNtkSizes ); extern Cba_Man_t * Cba_ManDup( Cba_Man_t * p ); diff --git a/src/base/cba/cbaBlast.c b/src/base/cba/cbaBlast.c index 8d2d53cd..26931e38 100644 --- a/src/base/cba/cbaBlast.c +++ b/src/base/cba/cbaBlast.c @@ -42,12 +42,15 @@ ABC_NAMESPACE_IMPL_START SeeAlso [] ***********************************************************************/ -void Cba_ManExtractSave( Cba_Man_t * p, int iLNtk, int iLObj, int iRNtk, int iRObj ) +int Cba_ManAddBarbuf( Gia_Man_t * pNew, int iRes, Cba_Man_t * p, int iLNtk, int iLObj, int iRNtk, int iRObj ) { +// if ( iRes == 0 || iRes == 1 ) +// return iRes; Vec_IntPush( p->vBuf2LeafNtk, iLNtk ); Vec_IntPush( p->vBuf2LeafObj, iLObj ); Vec_IntPush( p->vBuf2RootNtk, iRNtk ); Vec_IntPush( p->vBuf2RootObj, iRObj ); + return Gia_ManAppendBuf( pNew, iRes ); } int Cba_ManExtract_rec( Gia_Man_t * pNew, Cba_Ntk_t * p, int i ) { @@ -61,44 +64,64 @@ int Cba_ManExtract_rec( Gia_Man_t * pNew, Cba_Ntk_t * p, int i ) Cba_Ntk_t * pBox = Cba_ObjBoModel( p, i ); int iObj = Cba_NtkPo( pBox, Cba_ObjCioIndex(p, i) ); iRes = Cba_ManExtract_rec( pNew, pBox, iObj ); - iRes = Gia_ManAppendBuf( pNew, iRes ); - Cba_ManExtractSave( p->pDesign, Cba_NtkId(p), i, Cba_NtkId(pBox), iObj ); + iRes = Cba_ManAddBarbuf( pNew, iRes, p->pDesign, Cba_NtkId(p), i, Cba_NtkId(pBox), iObj ); } else if ( Cba_ObjIsPi(p, i) ) { - Cba_Ntk_t * pHost = Cba_NtkHost( p ); - int iObj = Cba_ObjBoxBi( pHost, p->iBoxObj, Cba_ObjCioIndex(p, i) ); + Cba_Ntk_t * pHost = Cba_NtkHostNtk( p ); + int iObj = Cba_ObjBoxBi( pHost, Cba_NtkHostObj(p), Cba_ObjCioIndex(p, i) ); iRes = Cba_ManExtract_rec( pNew, pHost, iObj ); - iRes = Gia_ManAppendBuf( pNew, iRes ); - Cba_ManExtractSave( p->pDesign, Cba_NtkId(p), i, Cba_NtkId(pHost), iObj ); + iRes = Cba_ManAddBarbuf( pNew, iRes, p->pDesign, Cba_NtkId(p), i, Cba_NtkId(pHost), iObj ); } else if ( Cba_ObjIsNode(p, i) ) { int * pFanins = Cba_ObjFaninArray(p, i); int k, pLits[3], Type = Cba_ObjNodeType(p, i); assert( pFanins[0] <= 3 ); - for ( k = 0; k < pFanins[0]; k++ ) - pLits[k] = Cba_ManExtract_rec( pNew, p, pFanins[k+1] ); - if ( Type == CBA_NODE_AND ) - iRes = Gia_ManHashAnd( pNew, pLits[0], pLits[1] ); - else if ( Type == CBA_NODE_OR ) - iRes = Gia_ManHashAnd( pNew, pLits[0], pLits[1] ); - else if ( Type == CBA_NODE_XOR ) - iRes = Gia_ManHashXor( pNew, pLits[0], pLits[1] ); - else if ( Type == CBA_NODE_XNOR ) - iRes = Abc_LitNot( Gia_ManHashXor( pNew, pLits[0], pLits[1] ) ); - else assert( 0 ), iRes = -1; + if ( pFanins[0] == 0 ) + { + if ( Type == CBA_NODE_C0 ) + iRes = 0; + else if ( Type == CBA_NODE_C1 ) + iRes = 1; + else assert( 0 ); + } + else if ( pFanins[0] == 1 ) + { + if ( Type == CBA_NODE_BUF ) + iRes = Cba_ManExtract_rec( pNew, p, pFanins[1] ); + else if ( Type == CBA_NODE_INV ) + iRes = Abc_LitNot( Cba_ManExtract_rec( pNew, p, pFanins[1] ) ); + else assert( 0 ); + } + else + { + for ( k = 0; k < pFanins[0]; k++ ) + pLits[k] = Cba_ManExtract_rec( pNew, p, pFanins[k+1] ); + if ( Type == CBA_NODE_AND ) + iRes = Gia_ManHashAnd( pNew, pLits[0], pLits[1] ); + else if ( Type == CBA_NODE_OR ) + iRes = Gia_ManHashOr( pNew, pLits[0], pLits[1] ); + else if ( Type == CBA_NODE_XOR ) + iRes = Gia_ManHashXor( pNew, pLits[0], pLits[1] ); + else if ( Type == CBA_NODE_XNOR ) + iRes = Abc_LitNot( Gia_ManHashXor( pNew, pLits[0], pLits[1] ) ); + else assert( 0 ); + } } else assert( 0 ); Cba_NtkSetCopy( p, i, iRes ); return iRes; } - Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fVerbose ) { Cba_Ntk_t * pRoot = Cba_ManRoot(p); Gia_Man_t * pNew, * pTemp; int i, iObj; + Vec_IntFreeP( &p->vBuf2LeafNtk ); + Vec_IntFreeP( &p->vBuf2LeafObj ); + Vec_IntFreeP( &p->vBuf2RootNtk ); + Vec_IntFreeP( &p->vBuf2RootObj ); p->vBuf2LeafNtk = Vec_IntAlloc( 1000 ); p->vBuf2LeafObj = Vec_IntAlloc( 1000 ); p->vBuf2RootNtk = Vec_IntAlloc( 1000 ); @@ -108,12 +131,13 @@ Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fVerbose ) pNew = Gia_ManStart( Cba_ManObjNum(p) ); pNew->pName = Abc_UtilStrsav(p->pName); pNew->pSpec = Abc_UtilStrsav(p->pSpec); - Vec_IntFill( &p->vCopies, Cba_ManObjNum(p), -1 ); Cba_NtkForEachPi( pRoot, iObj, i ) Cba_NtkSetCopy( pRoot, iObj, Gia_ManAppendCi(pNew) ); + Gia_ManHashAlloc( pNew ); Cba_NtkForEachPo( pRoot, iObj, i ) Cba_ManExtract_rec( pNew, pRoot, iObj ); + Gia_ManHashStop( pNew ); Cba_NtkForEachPo( pRoot, iObj, i ) Gia_ManAppendCo( pNew, Cba_NtkCopy(pRoot, iObj) ); assert( Vec_IntSize(p->vBuf2LeafNtk) == pNew->nBufs ); @@ -121,7 +145,7 @@ Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fVerbose ) // cleanup pNew = Gia_ManCleanup( pTemp = pNew ); Gia_ManStop( pTemp ); -// Gia_ManPrintStats( pNew, NULL ); + Gia_ManPrintStats( pNew, NULL ); // pNew = Gia_ManSweepHierarchy( pTemp = pNew ); // Gia_ManStop( pTemp ); // Gia_ManPrintStats( pNew, NULL ); @@ -130,7 +154,7 @@ Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fVerbose ) /**Function************************************************************* - Synopsis [] + Synopsis [Returns the number of objects in each network.] Description [] @@ -139,122 +163,179 @@ Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fVerbose ) SeeAlso [] ***********************************************************************/ -// return the array of object counters for each network -void Cba_ManCountNodes_rec( Cba_Man_t * p, Abc_Obj_t * pObj, int iNtk, Vec_Int_t * vObjCounts, Vec_Int_t * vBufDrivers, Vec_Int_t * vObj2Ntk, Vec_Int_t * vObj2Obj ) +Vec_Int_t * Cba_ManCountGia( Cba_Man_t * p, Gia_Man_t * pGia, int fAlwaysAdd ) { - if ( Abc_ObjIsBarBuf(pObj) ) + Cba_Ntk_t * pNtk; + Gia_Obj_t * pObj; + int i, k, iBox, Count = 0; + Vec_Int_t * vNtkSizes = Vec_IntStart( Cba_ManNtkNum(p) + 1 ); + Vec_Int_t * vDrivenCos = Vec_IntStart( Cba_ManNtkNum(p) + 1 ); + assert( Vec_IntSize(p->vBuf2LeafNtk) == Gia_ManBufNum(pGia) ); + // assing for each GIA node, the network it belongs to and count nodes for all networks + Gia_ManConst0(pGia)->Value = 1; + Gia_ManForEachPi( pGia, pObj, i ) + pObj->Value = 1; + Gia_ManForEachAnd( pGia, pObj, i ) { - Abc_Obj_t * pFanin = Abc_ObjFanin0(pObj); - if ( Abc_ObjIsPi(pFanin) || (Abc_ObjIsNode(pFanin) && Abc_ObjFaninNum(pFanin) > 0) ) - Vec_IntAddToEntry( vBufDrivers, iNtk, 1 ); - Cba_ManCountNodes_rec( p, Abc_ObjFanin0(pObj), pObj->iTemp, vObjCounts, vBufDrivers, vObj2Ntk, vObj2Obj ); + if ( Gia_ObjIsBuf(pObj) ) + { + if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) ) + Vec_IntAddToEntry( vDrivenCos, Gia_ObjFanin0(pObj)->Value, 1 ); + pObj->Value = Vec_IntEntry( p->vBuf2LeafNtk, Count++ ); + } + else + { + pObj->Value = Gia_ObjFanin0(pObj)->Value; + assert( pObj->Value == Gia_ObjFanin1(pObj)->Value ); + Vec_IntAddToEntry( vNtkSizes, pObj->Value, 1 ); + } } - else if ( Abc_ObjFaninNum(pObj) > 0 ) + assert( Count == Gia_ManBufNum(pGia) ); + Gia_ManForEachPo( pGia, pObj, i ) { - Abc_Obj_t * pFanin; int i; - Abc_ObjForEachFanin( pObj, pFanin, i ) - Cba_ManCountNodes_rec( p, pFanin, iNtk, vObjCounts, vBufDrivers, vObj2Ntk, vObj2Obj ); - Vec_IntWriteEntry( vObj2Ntk, Abc_ObjId(pObj), iNtk ); - Vec_IntWriteEntry( vObj2Obj, Abc_ObjId(pObj), Vec_IntEntry(vObjCounts, iNtk) ); - Vec_IntAddToEntry( vObjCounts, iNtk, 1 ); + assert( Gia_ObjFanin0(pObj)->Value == 1 ); + pObj->Value = Gia_ObjFanin0(pObj)->Value; + if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) ) + Vec_IntAddToEntry( vDrivenCos, pObj->Value, 1 ); } -} -Vec_Int_t * Cba_ManCountNodes( Cba_Man_t * p, Abc_Ntk_t * pAbcNtk, Vec_Int_t * vBuf2RootNtk, Vec_Int_t ** pvObj2Ntk, Vec_Int_t ** pvObj2Obj ) -{ - Cba_Ntk_t * pNtk; - Abc_Obj_t * pObj; - Vec_Int_t * vObjCounts = Vec_IntStart( Cba_ManNtkNum(p) + 1 ); - Vec_Int_t * vBufDrivers = Vec_IntStart( Cba_ManNtkNum(p) + 1 ); - // set networks to which barbufs belong - int i, k, iBox, iBarBuf = Vec_IntSize( vBuf2RootNtk ); - assert( Vec_IntSize(vBuf2RootNtk) == pAbcNtk->nBarBufs2 ); - Abc_NtkForEachNodeReverse( pAbcNtk, pObj, i ) - pObj->iTemp = Vec_IntEntry( vBuf2RootNtk, --iBarBuf ); - assert( iBarBuf == 0 ); - // start with primary inputs + // for each network, count the total number of COs Cba_ManForEachNtk( p, pNtk, i ) { - Vec_IntAddToEntry( vObjCounts, i, Cba_NtkPiNum(pNtk) ); + Count = Cba_NtkPiNum(pNtk) + 2 * Cba_NtkPoNum(pNtk) - (fAlwaysAdd ? 0 : Vec_IntEntry(vDrivenCos, i)); Cba_NtkForEachBox( pNtk, iBox, k ) - Vec_IntAddToEntry( vObjCounts, i, Cba_NtkPiNum(Cba_ObjBoxModel(pNtk, iBox)) + Cba_NtkPoNum(Cba_ObjBoxModel(pNtk, iBox)) + 1 ); + Count += Cba_ObjBoxSize(pNtk, iBox) + Cba_ObjBoxBiNum(pNtk, iBox); + Vec_IntAddToEntry( vNtkSizes, i, Count ); } - // count internal nodes (network is in topo order) - *pvObj2Ntk = Vec_IntStartFull( Abc_NtkObjNumMax(pAbcNtk) ); - *pvObj2Obj = Vec_IntStartFull( Abc_NtkObjNumMax(pAbcNtk) ); - Abc_NtkForEachPo( pAbcNtk, pObj, i ) - Cba_ManCountNodes_rec( p, Abc_ObjFanin0(pObj), p->iRoot, vObjCounts, vBufDrivers, *pvObj2Ntk, *pvObj2Obj ); - // count PIs, POs, and PO drivers - Cba_ManForEachNtk( p, pNtk, i ) - Vec_IntAddToEntry( vObjCounts, i, 2 * Cba_NtkPoNum(pNtk) - Vec_IntEntry(vBufDrivers, i) ); - Vec_IntFree( vBufDrivers ); - return vObjCounts; + Vec_IntFree( vDrivenCos ); + return vNtkSizes; } -Cba_Man_t * Cba_ManInsert( Cba_Man_t * p, Abc_Ntk_t * pAbcNtk, int fVerbose ) +void Cba_ManRemapBarbufs( Cba_Man_t * pNew, Cba_Man_t * p ) { - Cba_Man_t * pNew; - Cba_Ntk_t * pNtk; - Abc_Obj_t * pObj, * pFanin; - Vec_Int_t * vObj2Ntk, * vObj2Obj; - Vec_Int_t * vObjCounts = Cba_ManCountNodes( p, pAbcNtk, p->vBuf2RootNtk, &vObj2Ntk, &vObj2Obj ); - Vec_Int_t * vFanins; - int i, k, iNtk, iBuf = 0; - // create initial mapping - pNew = Cba_ManDupStart( p, vObjCounts ); - // set PIs point to the leaves - Abc_NtkForEachPi( pAbcNtk, pObj, i ) + Cba_Ntk_t * pNtk; int Entry, i; + assert( p->vBuf2RootNtk != NULL ); + assert( pNew->vBuf2RootNtk == NULL ); + pNew->vBuf2RootNtk = Vec_IntDup( p->vBuf2RootNtk ); + pNew->vBuf2RootObj = Vec_IntDup( p->vBuf2RootObj ); + pNew->vBuf2LeafNtk = Vec_IntDup( p->vBuf2LeafNtk ); + pNew->vBuf2LeafObj = Vec_IntDup( p->vBuf2LeafObj ); + Vec_IntForEachEntry( p->vBuf2LeafObj, Entry, i ) { - Vec_IntWriteEntry( vObj2Ntk, Abc_ObjId(pObj), p->iRoot ); - Vec_IntWriteEntry( vObj2Obj, Abc_ObjId(pObj), i ); + pNtk = Cba_ManNtk( p, Vec_IntEntry(p->vBuf2LeafNtk, i) ); + Vec_IntWriteEntry( pNew->vBuf2LeafObj, i, Cba_NtkCopy(pNtk, Entry) ); } - // set buffers to point to the leaves - assert( Vec_IntSize(p->vBuf2LeafNtk) == pAbcNtk->nBarBufs2 ); - assert( Vec_IntSize(p->vBuf2LeafObj) == pAbcNtk->nBarBufs2 ); - Abc_NtkForEachBarBuf( pAbcNtk, pObj, i ) + Vec_IntForEachEntry( p->vBuf2RootObj, Entry, i ) { - Vec_IntWriteEntry( vObj2Ntk, Abc_ObjId(pObj), Vec_IntEntry(p->vBuf2LeafNtk, iBuf) ); - Vec_IntWriteEntry( vObj2Obj, Abc_ObjId(pObj), Vec_IntEntry(p->vBuf2LeafObj, iBuf) ); - iBuf++; + pNtk = Cba_ManNtk( p, Vec_IntEntry(p->vBuf2RootNtk, i) ); + Vec_IntWriteEntry( pNew->vBuf2RootObj, i, Cba_NtkCopy(pNtk, Entry) ); } - assert( iBuf == pAbcNtk->nBarBufs2 ); - // copy internal nodes - vFanins = Vec_IntAlloc( 100 ); - Abc_NtkForEachNode( pAbcNtk, pObj, i ) +} +void Cba_NtkCreateAndConnectBuffer( Gia_Man_t * pGia, Gia_Obj_t * pObj, Cba_Ntk_t * pNtk, int iTerm ) +{ + Vec_IntWriteEntry( &pNtk->vTypes, pNtk->nObjs, CBA_OBJ_NODE ); + if ( !pGia || !Gia_ObjFaninId0p(pGia, pObj) ) + { + Vec_IntWriteEntry( &pNtk->vFuncs, pNtk->nObjs, pGia && Gia_ObjFaninC0(pObj) ? CBA_NODE_C1 : CBA_NODE_C0 ); + Vec_IntWriteEntry( &pNtk->vFanins, pNtk->nObjs, Cba_ManHandleBuffer(pNtk->pDesign, -1) ); + } + else { - if ( Abc_ObjIsBarBuf(pObj) ) - continue; - if ( Abc_ObjFaninNum(pObj) == 0 ) - continue; - Vec_IntClear( vFanins ); - iNtk = Vec_IntEntry(vObj2Ntk, Abc_ObjId(pObj)); - Abc_ObjForEachFanin( pObj, pFanin, k ) + Vec_IntWriteEntry( &pNtk->vFuncs, pNtk->nObjs, Gia_ObjFaninC0(pObj) ? CBA_NODE_INV : CBA_NODE_BUF ); + Vec_IntWriteEntry( &pNtk->vFanins, pNtk->nObjs, Cba_ManHandleBuffer(pNtk->pDesign, Gia_ObjFanin0(pObj)->Value) ); + } + Vec_IntWriteEntry( &pNtk->vNameIds, pNtk->nObjs, Cba_ObjNameId(pNtk, iTerm) ); + Vec_IntWriteEntry( &pNtk->vFanins, iTerm, pNtk->nObjs++ ); +} +void Cba_NtkInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ) +{ + Cba_Ntk_t * pNtk, * pRoot = Cba_ManRoot( p ); + Vec_Int_t * vTemp = Vec_IntAlloc( 100 ); + int i, j, k, iBox, iTerm, Count = 0; + Gia_Obj_t * pObj; + + Gia_ManConst0(pGia)->Value = ~0; + Gia_ManForEachPi( pGia, pObj, i ) + pObj->Value = Cba_NtkPi( pRoot, i ); + Gia_ManForEachAnd( pGia, pObj, i ) + { + if ( Gia_ObjIsBuf(pObj) ) + { + pNtk = Cba_ManNtk( p, Vec_IntEntry(p->vBuf2RootNtk, Count) ); + iTerm = Vec_IntEntry( p->vBuf2RootObj, Count ); + assert( Cba_ObjIsCo(pNtk, iTerm) ); + Cba_NtkCreateAndConnectBuffer( pGia, pObj, pNtk, iTerm ); + // prepare leaf + pObj->Value = Vec_IntEntry( p->vBuf2LeafObj, Count++ ); + } + else { - assert( Vec_IntEntry(vObj2Ntk, Abc_ObjId(pFanin)) == iNtk ); - Vec_IntPush( vFanins, Vec_IntEntry(vObj2Obj, Abc_ObjId(pFanin)) ); + Cba_NodeType_t Type; + pNtk = Cba_ManNtk( p, pObj->Value ); + if ( Gia_ObjFaninC0(pObj) && Gia_ObjFaninC1(pObj) ) + Type = CBA_NODE_AND00; + else if ( Gia_ObjFaninC0(pObj) ) + Type = CBA_NODE_AND01; + else if ( Gia_ObjFaninC1(pObj) ) + Type = CBA_NODE_AND10; + else + Type = CBA_NODE_AND; + Vec_IntFillTwo( vTemp, 2, Gia_ObjFanin0(pObj)->Value, Gia_ObjFanin1(pObj)->Value ); + Vec_IntWriteEntry( &pNtk->vTypes, pNtk->nObjs, CBA_OBJ_NODE ); + Vec_IntWriteEntry( &pNtk->vFuncs, pNtk->nObjs, Type ); + Vec_IntWriteEntry( &pNtk->vFanins, pNtk->nObjs, Cba_ManHandleArray(p, vTemp) ); + pObj->Value = pNtk->nObjs++; } - pNtk = Cba_ManNtk( pNew, iNtk ); - Vec_IntPush( &pNtk->vTypes, CBA_OBJ_NODE ); - Vec_IntPush( &pNtk->vFuncs, -1 ); - Vec_IntPush( &pNtk->vFanins, Cba_ManHandleArray(pNew, vFanins) ); } - // set buffers to point to the roots - assert( Vec_IntSize(p->vBuf2RootNtk) == pAbcNtk->nBarBufs2 ); - assert( Vec_IntSize(p->vBuf2RootObj) == pAbcNtk->nBarBufs2 ); - iBuf = 0; - Abc_NtkForEachBarBuf( pAbcNtk, pObj, i ) + assert( Count == Gia_ManBufNum(pGia) ); + Vec_IntFree( vTemp ); + + // create constant 0 drivers for COs without barbufs + Cba_ManForEachNtk( p, pNtk, i ) { - Vec_IntWriteEntry( vObj2Ntk, Abc_ObjId(pObj), Vec_IntEntry(p->vBuf2RootNtk, iBuf) ); - Vec_IntWriteEntry( vObj2Obj, Abc_ObjId(pObj), Vec_IntEntry(p->vBuf2RootObj, iBuf) ); - iBuf++; + Cba_NtkForEachBox( pNtk, iBox, k ) + Cba_BoxForEachBi( pNtk, iBox, iTerm, j ) + if ( Cba_ObjFanin0(pNtk, iTerm) == -1 ) + Cba_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm ); + Cba_NtkForEachPo( pNtk, iTerm, k ) + if ( pNtk != pRoot && Cba_ObjFanin0(pNtk, iTerm) == -1 ) + Cba_NtkCreateAndConnectBuffer( NULL, NULL, pNtk, iTerm ); } - assert( iBuf == pAbcNtk->nBarBufs2 ); - // connect driven root nodes + // create node and connect POs + Gia_ManForEachPo( pGia, pObj, i ) + Cba_NtkCreateAndConnectBuffer( pGia, pObj, pRoot, Cba_NtkPo(pRoot, i) ); + assert( Cba_NtkObjNum(pRoot) == pRoot->nObjs ); +} +Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ) +{ + Vec_Int_t * vNtkSizes = Cba_ManCountGia( p, pGia, 1 ); + Cba_Man_t * pNew = Cba_ManDupStart( p, vNtkSizes ); + Cba_ManRemapBarbufs( pNew, p ); + Cba_NtkInsertGia( pNew, pGia ); + Vec_IntFree( vNtkSizes ); + return pNew; + +} +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] - Vec_IntFree( vObj2Ntk ); - Vec_IntFree( vObj2Obj ); +***********************************************************************/ +Cba_Man_t * Cba_ManBlastTest( Cba_Man_t * p ) +{ + Gia_Man_t * pGia = Cba_ManExtract( p, 0 ); + Cba_Man_t * pNew = Cba_ManInsertGia( p, pGia ); + Gia_ManStop( pGia ); + Cba_ManAssignInternNames( pNew ); return pNew; } + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaBuild.c b/src/base/cba/cbaBuild.c index d47563d1..b4f95f23 100644 --- a/src/base/cba/cbaBuild.c +++ b/src/base/cba/cbaBuild.c @@ -26,15 +26,6 @@ ABC_NAMESPACE_IMPL_START /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -/* - Elaboration input data: - Vec_Int_t vInputs; // inputs (used by parser to store signals as NameId) - Vec_Int_t vOutputs; // outputs (used by parser to store signals as NameId) - Vec_Int_t vTypes; // types (used by parser to store Cba_PrsType_t) - Vec_Int_t vFuncs; // functions (used by parser to store function) - Vec_Int_t vFanins; // fanins (used by parser to store fanin/fanout signals as NameId) -*/ - //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -90,12 +81,45 @@ void Cba_NtkRemapBoxes( Cba_Ntk_t * pNtk, Vec_Int_t * vMap ) Cba_BoxRemap( pNtk, iBox, vMap ); } // create maps of NameId and boxes -int Cba_NtkCreateMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes ) +void Cba_NtkFindNonDriven( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, int nObjCount, Vec_Int_t * vNonDriven ) +{ + int i, iObj, Type, NameId, Index; + // consider input node names + Vec_IntClear( vNonDriven ); + Cba_NtkForEachObjType( pNtk, Type, iObj ) + { + if ( Type == CBA_OBJ_NODE ) + { + Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj ); + Vec_IntForEachEntryStart( vFanins, NameId, i, 1 ) + if ( Vec_IntEntry(vMap, NameId) == -1 ) + Vec_IntWriteEntry( vMap, NameId, nObjCount++ ), Vec_IntPush(vNonDriven, NameId); + } + else if ( Type == CBA_OBJ_BOX ) + { + Cba_Ntk_t * pNtkBox = Cba_ObjBoxModel( pNtk, iObj ); + Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj ); + Vec_IntForEachEntry( vFanins, Index, i ) + { + i++; + if ( Index >= Cba_NtkPiNum(pNtkBox) ) + continue; + NameId = Vec_IntEntry( vFanins, i ); + if ( Vec_IntEntry(vMap, NameId) == -1 ) + Vec_IntWriteEntry( vMap, NameId, nObjCount++ ), Vec_IntPush(vNonDriven, NameId); + } + } + } + Cba_NtkForEachPo( pNtk, NameId, i ) + if ( Vec_IntEntry(vMap, NameId) == -1 ) + Vec_IntWriteEntry( vMap, NameId, nObjCount++ ), Vec_IntPush(vNonDriven, NameId); + if ( Vec_IntSize(vNonDriven) > 0 ) + printf( "Module %s has %d non-driven nets (for example, %s).\n", Cba_NtkName(pNtk), Vec_IntSize(vNonDriven), Cba_NtkStr(pNtk, Vec_IntEntry(vNonDriven, 0)) ); +} +int Cba_NtkCreateMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes, Vec_Int_t * vNonDriven ) { - Vec_Int_t * vFanins; int i, iObj, Type, Index, NameId; int nObjCount = 0; - // map old name IDs into new object IDs Vec_IntClear( vBoxes ); Cba_NtkForEachPi( pNtk, NameId, i ) @@ -109,7 +133,7 @@ int Cba_NtkCreateMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes ) if ( Type == CBA_OBJ_NODE ) { // consider node output name - vFanins = Cba_ObjFaninVec( pNtk, iObj ); + Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj ); NameId = Vec_IntEntry( vFanins, 0 ); if ( Vec_IntEntry(vMap, NameId) != -1 ) printf( "Node output name %d is already driven.\n", NameId ); @@ -117,10 +141,10 @@ int Cba_NtkCreateMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes ) } else if ( Type == CBA_OBJ_BOX ) { + Vec_Int_t * vFanins = Cba_ObjFaninVec( pNtk, iObj ); Cba_Ntk_t * pNtkBox = Cba_ObjBoxModel( pNtk, iObj ); nObjCount += Cba_NtkPiNum(pNtkBox); Vec_IntPush( vBoxes, nObjCount++ ); - vFanins = Cba_ObjFaninVec( pNtk, iObj ); Vec_IntForEachEntry( vFanins, Index, i ) { i++; @@ -136,83 +160,11 @@ int Cba_NtkCreateMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes ) nObjCount += Cba_NtkPoNum(pNtkBox); } } - // add outputs - nObjCount += Cba_NtkPoNum(pNtk); + Cba_NtkFindNonDriven( pNtk, vMap, nObjCount, vNonDriven ); + nObjCount += Vec_IntSize(vNonDriven) + Cba_NtkPoNum(pNtk); return nObjCount; } -void Cba_NtkCleanMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap ) -{ - Vec_Int_t * vFanins; - int i, iObj, Type, NameId; - Cba_NtkForEachPi( pNtk, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); - Cba_NtkForEachObjType( pNtk, Type, iObj ) - { - vFanins = Cba_ObjFaninVec( pNtk, iObj ); - if ( Type == CBA_OBJ_NODE ) - { - Vec_IntForEachEntry( vFanins, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); - } - else if ( Type == CBA_OBJ_BOX ) - { - Vec_IntForEachEntry( vFanins, NameId, i ) - Vec_IntWriteEntry( vMap, Vec_IntEntry(vFanins, ++i), -1 ); - } - } - Cba_NtkForEachPo( pNtk, NameId, i ) - Vec_IntWriteEntry( vMap, NameId, -1 ); -} -int Cba_NtkCheckNonDriven( Cba_Ntk_t * pNtk, Vec_Int_t * vMap, int nObjCount ) -{ - Vec_Int_t * vFanins; - int i, iObj, Type, NameId, Index; - int NonDriven = 0; - // check non-driven nets - Cba_NtkForEachObjType( pNtk, Type, iObj ) - { - if ( Type == CBA_OBJ_NODE ) - { - // consider node input names - vFanins = Cba_ObjFaninVec( pNtk, iObj ); - Vec_IntForEachEntryStart( vFanins, NameId, i, 1 ) - { - if ( Vec_IntEntry(vMap, NameId) != -1 ) - continue; - if ( NonDriven++ == 0 ) nObjCount++; - Vec_IntWriteEntry( vMap, NameId, nObjCount-1 ); - } - } - else if ( Type == CBA_OBJ_BOX ) - { - Cba_Ntk_t * pNtkBox = Cba_ObjBoxModel( pNtk, iObj ); - vFanins = Cba_ObjFaninVec( pNtk, iObj ); - Vec_IntForEachEntry( vFanins, Index, i ) - { - i++; - if ( Index >= Cba_NtkPiNum(pNtkBox) ) - continue; - // consider box input name - NameId = Vec_IntEntry( vFanins, i ); - if ( Vec_IntEntry(vMap, NameId) != -1 ) - continue; - if ( NonDriven++ == 0 ) nObjCount++; - Vec_IntWriteEntry( vMap, NameId, nObjCount-1 ); - } - } - } - Cba_NtkForEachPo( pNtk, NameId, i ) - { - if ( Vec_IntEntry(vMap, NameId) != -1 ) - continue; - if ( NonDriven++ == 0 ) nObjCount++; - Vec_IntWriteEntry( vMap, NameId, nObjCount-1 ); - } - if ( NonDriven > 0 ) - printf( "Detected %d non-driven nets.\n", NonDriven ); - return NonDriven; -} -Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vBoxes, Vec_Int_t * vTemp, int nObjCount ) +Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_Int_t * vNonDriven, Vec_Int_t * vTemp, int nObjCount ) { Vec_Int_t * vFanins; Cba_Ntk_t * pNtkNew, * pNtkBox; @@ -220,11 +172,7 @@ Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, // start network pNtkNew = Cba_ManNtk( pNew, Cba_NtkId(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vTypes, nObjCount ); - Cba_ManFetchArray( pNew, &pNtkNew->vFuncs, nObjCount ); - Cba_ManFetchArray( pNew, &pNtkNew->vFanins, nObjCount ); - Cba_ManFetchArray( pNew, &pNtkNew->vNameIds, nObjCount ); - Cba_ManSetupArray( pNew, &pNtkNew->vBoxes, vBoxes ); + Cba_NtkResize( pNtkNew, nObjCount ); // fill object information Cba_NtkForEachPi( pNtk, NameId, i ) @@ -235,7 +183,6 @@ Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, i ); Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, NameId ); } - Cba_NtkForEachObjType( pNtk, Type, iObj ) { vFanins = Cba_ObjFaninVec( pNtk, iObj ); @@ -285,18 +232,29 @@ Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, { Vec_IntWriteEntry( &pNtkNew->vTypes, FaninId, CBA_OBJ_BI ); Vec_IntWriteEntry( &pNtkNew->vFuncs, FaninId, i ); - Vec_IntWriteEntry( &pNtkNew->vFanins, FaninId, Cba_ManHandleBuffer(pNew, Vec_IntEntry(vTemp, i)) ); + Vec_IntWriteEntry( &pNtkNew->vFanins, FaninId, Vec_IntEntry(vTemp, i) ); } // create box outputs Cba_BoxForEachBo( pNtkNew, ObjId, FaninId, i ) { Vec_IntWriteEntry( &pNtkNew->vTypes, FaninId, CBA_OBJ_BO ); Vec_IntWriteEntry( &pNtkNew->vFuncs, FaninId, i ); - Vec_IntWriteEntry( &pNtkNew->vFanins, FaninId, Cba_ManHandleBuffer(pNew, ObjId) ); + Vec_IntWriteEntry( &pNtkNew->vFanins, FaninId, ObjId ); } } } assert( nBoxes == Vec_IntSize(&pNtkNew->vBoxes) ); + // add constants for nondriven nodes + Vec_IntForEachEntry( vNonDriven, NameId, i ) + { + ObjId = Vec_IntEntry( vMap, NameId ); + Vec_IntWriteEntry( &pNtkNew->vOutputs, i, ObjId ); + Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId, CBA_OBJ_NODE ); + Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, CBA_NODE_C0 ); + Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, Cba_ManHandleBuffer(pNew, -1) ); + Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, NameId ); + } + // add PO nodes Cba_NtkForEachPo( pNtk, NameId, i ) { ObjId = nObjCount - Cba_NtkPoNum(pNtk) + i; @@ -305,45 +263,66 @@ Cba_Ntk_t * Cba_NtkBuild( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, Vec_Int_t * vMap, Vec_IntWriteEntry( &pNtkNew->vOutputs, i, ObjId ); Vec_IntWriteEntry( &pNtkNew->vTypes, ObjId, CBA_OBJ_PO ); Vec_IntWriteEntry( &pNtkNew->vFuncs, ObjId, i ); - Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, Cba_ManHandleBuffer(pNew, FaninId) ); + Vec_IntWriteEntry( &pNtkNew->vFanins, ObjId, FaninId ); // remove NameId from the driver and assign it to the output //Vec_IntWriteEntry( &pNtkNew->vNameIds, FaninId, -1 ); Vec_IntWriteEntry( &pNtkNew->vNameIds, ObjId, NameId ); } return pNtkNew; } -Cba_Man_t * Cba_ManPreBuild( Cba_Man_t * p ) +void Cba_NtkCleanMap( Cba_Ntk_t * pNtk, Vec_Int_t * vMap ) { - Cba_Man_t * pNew = Cba_ManClone( p ); - Cba_Ntk_t * pNtk, * pNtkNew; int i; - Cba_ManForEachNtk( p, pNtk, i ) + Vec_Int_t * vFanins; + int i, iObj, Type, NameId; + Cba_NtkForEachPi( pNtk, NameId, i ) + Vec_IntWriteEntry( vMap, NameId, -1 ); + Cba_NtkForEachObjType( pNtk, Type, iObj ) { - pNtkNew = Cba_NtkAlloc( pNew, Cba_NtkName(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vInputs, Cba_NtkPiNum(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vOutputs, Cba_NtkPoNum(pNtk) ); + vFanins = Cba_ObjFaninVec( pNtk, iObj ); + if ( Type == CBA_OBJ_NODE ) + { + Vec_IntForEachEntry( vFanins, NameId, i ) + Vec_IntWriteEntry( vMap, NameId, -1 ); + } + else if ( Type == CBA_OBJ_BOX ) + { + Vec_IntForEachEntry( vFanins, NameId, i ) + Vec_IntWriteEntry( vMap, Vec_IntEntry(vFanins, ++i), -1 ); + } } - assert( Cba_ManNtkNum(pNew) == Cba_ManNtkNum(p) ); - return pNew; + Cba_NtkForEachPo( pNtk, NameId, i ) + Vec_IntWriteEntry( vMap, NameId, -1 ); } + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ Cba_Man_t * Cba_ManBuild( Cba_Man_t * p ) { - Cba_Man_t * pNew = Cba_ManPreBuild( p ); + Cba_Man_t * pNew = Cba_ManClone( p ); Vec_Int_t * vMap = Vec_IntStartFull( Abc_NamObjNumMax(p->pNames) + 1 ); - Vec_Int_t * vBoxes = Vec_IntAlloc( 1000 ); + Vec_Int_t * vNonDr = Vec_IntAlloc( 1000 ); Vec_Int_t * vTemp = Vec_IntAlloc( 1000 ); Cba_Ntk_t * pNtk; int i, nObjs; assert( Abc_NamObjNumMax(p->pModels) == Cba_ManNtkNum(p) + 1 ); Cba_ManForEachNtk( p, pNtk, i ) { Cba_NtkRemapBoxes( pNtk, vMap ); - nObjs = Cba_NtkCreateMap( pNtk, vMap, vBoxes ); - Cba_NtkCheckNonDriven( pNtk, vMap, nObjs ); - Cba_NtkBuild( pNew, pNtk, vMap, vBoxes, vTemp, nObjs ); + nObjs = Cba_NtkCreateMap( pNtk, vMap, &Cba_ManNtk(pNew, i)->vBoxes, vNonDr ); + Cba_NtkBuild( pNew, pNtk, vMap, vNonDr, vTemp, nObjs ); Cba_NtkCleanMap( pNtk, vMap ); } - Vec_IntFree( vTemp ); - Vec_IntFree( vBoxes ); Vec_IntFree( vMap ); + Vec_IntFree( vNonDr ); + Vec_IntFree( vTemp ); return pNew; } diff --git a/src/base/cba/cbaNtk.c b/src/base/cba/cbaNtk.c index 30e721a6..9d2fe6d1 100644 --- a/src/base/cba/cbaNtk.c +++ b/src/base/cba/cbaNtk.c @@ -47,7 +47,7 @@ void Cba_ManAssignInternNamesNtk( Cba_Ntk_t * p ) int nDigits = Abc_Base10Log( Cba_NtkObjNum(p) ); Cba_NtkForEachObjType( p, Type, i ) { - if ( Type == CBA_OBJ_NODE ) + if ( Type == CBA_OBJ_NODE && Cba_ObjNameId(p, i) == -1 ) { char Buffer[100]; sprintf( Buffer, "%s%0*d", "_n_", nDigits, i ); @@ -92,20 +92,6 @@ int Cba_ManObjNum( Cba_Man_t * p ) } return Count; } -void Cba_ManSetNtkBoxes( Cba_Man_t * p ) -{ - Cba_Ntk_t * pNtk, * pBox; - int i, k, Type; - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkForEachObjType( pNtk, Type, k ) - if ( Type == CBA_OBJ_BOX ) - { - pBox = Cba_ObjBoxModel(pNtk, k); - assert( pBox->iBoxNtk == 0 ); - pBox->iBoxNtk = i; - pBox->iBoxObj = k; - } -} /**Function************************************************************* @@ -118,61 +104,74 @@ void Cba_ManSetNtkBoxes( Cba_Man_t * p ) SeeAlso [] ***********************************************************************/ -void Cba_ObjDup( Cba_Ntk_t * pNew, Cba_Ntk_t * p, int iObj ) +// duplicate PI/PO/boxes +void Cba_ObjDupStart( Cba_Ntk_t * pNew, Cba_Ntk_t * p, int iObj ) { if ( Cba_ObjIsPi(p, iObj) ) - Vec_IntWriteEntry( &pNew->vInputs, Cba_ObjFuncId(pNew, iObj), pNew->nObjs ); + Vec_IntWriteEntry( &pNew->vInputs, Cba_ObjFuncId(p, iObj), pNew->nObjs ); if ( Cba_ObjIsPo(p, iObj) ) - Vec_IntWriteEntry( &pNew->vOutputs, Cba_ObjFuncId(pNew, iObj), pNew->nObjs ); - if ( Cba_ObjIsBox(p, iObj) ) - Vec_IntPush( &pNew->vBoxes, pNew->nObjs ); + Vec_IntWriteEntry( &pNew->vOutputs, Cba_ObjFuncId(p, iObj), pNew->nObjs ); Vec_IntWriteEntry( &pNew->vTypes, pNew->nObjs, Cba_ObjType(p, iObj) ); - Vec_IntWriteEntry( &pNew->vFuncs, pNew->nObjs, Cba_ObjFuncId(pNew, iObj) ); + Vec_IntWriteEntry( &pNew->vFuncs, pNew->nObjs, Cba_ObjFuncId(p, iObj) ); Vec_IntWriteEntry( &pNew->vNameIds, pNew->nObjs, Cba_ObjNameId(p, iObj) ); + if ( Cba_ObjIsBox(p, iObj) ) + Cba_NtkSetHost( Cba_ObjBoxModel(pNew, pNew->nObjs), Cba_NtkId(pNew), pNew->nObjs ); + if ( Cba_ObjIsBox(p, iObj) ) + Vec_IntPush( &pNew->vBoxes, pNew->nObjs ); Cba_NtkSetCopy( p, iObj, pNew->nObjs++ ); } - -// allocates memory -Cba_Ntk_t * Cba_NtkDupAlloc( Cba_Man_t * pNew, Cba_Ntk_t * pNtk, int nObjs ) -{ - Cba_Ntk_t * pNtkNew = Cba_NtkAlloc( pNew, Cba_NtkName(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vInputs, Cba_NtkPiNum(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vOutputs, Cba_NtkPoNum(pNtk) ); - Cba_ManFetchArray( pNew, &pNtkNew->vTypes, nObjs ); - Cba_ManFetchArray( pNew, &pNtkNew->vFuncs, nObjs ); - Cba_ManFetchArray( pNew, &pNtkNew->vFanins, nObjs ); - Cba_ManFetchArray( pNew, &pNtkNew->vNameIds, nObjs ); - Cba_ManFetchArray( pNew, &pNtkNew->vBoxes, Cba_NtkBoxNum(pNtk) ); - Vec_IntShrink( &pNtkNew->vBoxes, 0 ); - return pNtkNew; -} -// duplicate PI/PO/boxes -int Cba_NtkDupStart( Cba_Ntk_t * pNew, Cba_Ntk_t * p ) +void Cba_NtkDupStart( Cba_Ntk_t * pNew, Cba_Ntk_t * p ) { - int i, k, iObj; + int i, k, iObj, iTerm; + assert( Vec_IntSize(&pNew->vBoxes) == 0 ); pNew->nObjs = 0; Cba_NtkForEachPi( p, iObj, i ) - Cba_ObjDup( pNew, p, iObj ); + Cba_ObjDupStart( pNew, p, iObj ); Cba_NtkForEachPo( p, iObj, i ) - Cba_ObjDup( pNew, p, iObj ); + Cba_ObjDupStart( pNew, p, iObj ); Cba_NtkForEachBox( p, iObj, i ) { Cba_Ntk_t * pBox = Cba_ObjBoxModel( p, iObj ); - for ( k = 0; k < Cba_NtkPiNum(pBox); k++ ) - Cba_ObjDup( pNew, p, Cba_ObjBoxBi(p, iObj, k) ); - Cba_ObjDup( pNew, p, iObj ); - for ( k = 0; k < Cba_NtkPoNum(pBox); k++ ) - Cba_ObjDup( pNew, p, Cba_ObjBoxBo(p, iObj, k) ); + Cba_BoxForEachBi( p, iObj, iTerm, k ) + Cba_ObjDupStart( pNew, p, iTerm ); + Cba_ObjDupStart( pNew, p, iObj ); + Cba_BoxForEachBo( p, iObj, iTerm, k ) + Cba_ObjDupStart( pNew, p, iTerm ); } - return pNew->nObjs; + assert( Cba_NtkBoxNum(p) == Cba_NtkBoxNum(pNew) ); +} +Cba_Man_t * Cba_ManDupStart( Cba_Man_t * p, Vec_Int_t * vNtkSizes ) +{ + Cba_Ntk_t * pNtk; int i; + Cba_Man_t * pNew = Cba_ManClone( p ); + Cba_ManForEachNtk( p, pNtk, i ) + Cba_NtkResize( Cba_ManNtk(pNew, i), vNtkSizes ? Vec_IntEntry(vNtkSizes, i) : Cba_NtkObjNum(pNtk) ); + Vec_IntFill( &p->vCopies, Cba_ManObjNum(p), -1 ); + Cba_ManForEachNtk( p, pNtk, i ) + Cba_NtkDupStart( Cba_ManNtk(pNew, i), pNtk ); + return pNew; } + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ // duplicate internal nodes void Cba_NtkDupNodes( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vTemp ) { Vec_Int_t * vFanins; int i, k, Type, iTerm, iObj; + // dup nodes Cba_NtkForEachNode( p, iObj ) - Cba_ObjDup( pNew, p, iObj ); + Cba_ObjDupStart( pNew, p, iObj ); + assert( pNew->nObjs == Cba_NtkObjNum(pNew) ); // connect Cba_NtkForEachObjType( p, Type, i ) { @@ -190,33 +189,6 @@ void Cba_NtkDupNodes( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vTemp ) Vec_IntPush( vTemp, Cba_NtkCopy(p, iTerm) ); Vec_IntWriteEntry( &pNew->vFanins, Cba_NtkCopy(p, i), Cba_ManHandleArray(pNew->pDesign, vTemp) ); } - -} -// finalize network -void Cba_NtkDupFinish( Cba_Ntk_t * pNew ) -{ - int iObj; - // add constant drivers - Cba_NtkForEachCo( pNew, iObj ) - { - } - // restrict - Vec_IntShrink( &pNew->vTypes, pNew->nObjs ); - Vec_IntShrink( &pNew->vFuncs, pNew->nObjs ); - Vec_IntShrink( &pNew->vFanins, pNew->nObjs ); - Vec_IntShrink( &pNew->vNameIds, pNew->nObjs ); -} - -Cba_Man_t * Cba_ManDupStart( Cba_Man_t * p, Vec_Int_t * vObjCounts ) -{ - Cba_Ntk_t * pNtk; int i; - Cba_Man_t * pNew = Cba_ManAlloc( Cba_ManName(p) ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkDupAlloc( pNew, pNtk, vObjCounts ? Cba_NtkObjNum(pNtk) : Vec_IntEntry(vObjCounts, i) ); - Vec_IntFill( &p->vCopies, Cba_ManObjNum(pNew), -1 ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkDupStart( Cba_ManNtk(pNew, i), pNtk ); - return pNew; } Cba_Man_t * Cba_ManDup( Cba_Man_t * p ) { @@ -225,13 +197,12 @@ Cba_Man_t * Cba_ManDup( Cba_Man_t * p ) Cba_Man_t * pNew = Cba_ManDupStart( p, NULL ); Cba_ManForEachNtk( p, pNtk, i ) Cba_NtkDupNodes( Cba_ManNtk(pNew, i), pNtk, vTemp ); - Cba_ManForEachNtk( p, pNtk, i ) - Cba_NtkDupFinish( Cba_ManNtk(pNew, i) ); - Vec_IntClear( vTemp ); + Vec_IntFree( vTemp ); return pNew; } + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaSimple.c b/src/base/cba/cbaSimple.c index fb04b657..8b4c336f 100644 --- a/src/base/cba/cbaSimple.c +++ b/src/base/cba/cbaSimple.c @@ -36,33 +36,6 @@ node = array containing output name, followed by node type, followed by input box = array containing model name, instance name, followed by pairs of formal/actual names for each port */ -typedef enum { - PTR_OBJ_NONE, // 0: non-existent object - PTR_OBJ_CONST0, // 1: constant node - PTR_OBJ_PI, // 2: primary input - PTR_OBJ_PO, // 3: primary output - PTR_OBJ_FAN, // 4: box output - PTR_OBJ_FLOP, // 5: flip-flop - PTR_OBJ_BOX, // 6: box - PTR_OBJ_NODE, // 7: logic node - - PTR_OBJ_C0, // 8: logic node - PTR_OBJ_C1, // 9: logic node - PTR_OBJ_BUF, // 0: logic node - PTR_OBJ_INV, // 1: logic node - PTR_OBJ_AND, // 2: logic node - PTR_OBJ_OR, // 3: logic node - PTR_OBJ_XOR, // 4: logic node - PTR_OBJ_NAND, // 5: logic node - PTR_OBJ_NOR, // 6: logic node - PTR_OBJ_XNOR, // 7: logic node - PTR_OBJ_MUX, // 8: logic node - PTR_OBJ_MAJ, // 9: logic node - - PTR_VOID // 0: placeholder -} Ptr_ObjType_t; - - //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// @@ -78,44 +51,7 @@ typedef enum { SeeAlso [] ***********************************************************************/ -char * Ptr_TypeToName( Ptr_ObjType_t Type ) -{ - if ( Type == PTR_OBJ_BUF ) return "buf"; - if ( Type == PTR_OBJ_INV ) return "not"; - if ( Type == PTR_OBJ_AND ) return "and"; - if ( Type == PTR_OBJ_OR ) return "or"; - if ( Type == PTR_OBJ_XOR ) return "xor"; - if ( Type == PTR_OBJ_XNOR ) return "xnor"; - assert( 0 ); - return "???"; -} -char * Ptr_TypeToSop( int Type ) -{ - if ( Type == PTR_OBJ_BUF ) return "1 1\n"; - if ( Type == PTR_OBJ_INV ) return "0 1\n"; - if ( Type == PTR_OBJ_AND ) return "11 1\n"; - if ( Type == PTR_OBJ_OR ) return "00 0\n"; - if ( Type == PTR_OBJ_XOR ) return "01 1\n10 1\n"; - if ( Type == PTR_OBJ_XNOR ) return "00 1\n11 1\n"; - assert( 0 ); - return "???"; -} -Ptr_ObjType_t Ptr_SopToType( char * pSop ) -{ - if ( !strcmp(pSop, "1 1\n") ) return PTR_OBJ_BUF; - if ( !strcmp(pSop, "0 1\n") ) return PTR_OBJ_INV; - if ( !strcmp(pSop, "11 1\n") ) return PTR_OBJ_AND; - if ( !strcmp(pSop, "00 0\n") ) return PTR_OBJ_OR; - if ( !strcmp(pSop, "-1 1\n1- 1\n") ) return PTR_OBJ_OR; - if ( !strcmp(pSop, "1- 1\n-1 1\n") ) return PTR_OBJ_OR; - if ( !strcmp(pSop, "01 1\n10 1\n") ) return PTR_OBJ_XOR; - if ( !strcmp(pSop, "10 1\n01 1\n") ) return PTR_OBJ_XOR; - if ( !strcmp(pSop, "11 1\n00 1\n") ) return PTR_OBJ_XNOR; - if ( !strcmp(pSop, "00 1\n11 1\n") ) return PTR_OBJ_XNOR; - assert( 0 ); - return PTR_OBJ_NONE; -} -Ptr_ObjType_t Ptr_HopToType( Abc_Obj_t * pObj ) +Cba_NodeType_t Ptr_HopToType( Abc_Obj_t * pObj ) { static word uTruth, uTruths6[3] = { ABC_CONST(0xAAAAAAAAAAAAAAAA), @@ -124,14 +60,14 @@ Ptr_ObjType_t Ptr_HopToType( Abc_Obj_t * pObj ) }; assert( Abc_ObjIsNode(pObj) ); uTruth = Hop_ManComputeTruth6( (Hop_Man_t *)Abc_ObjNtk(pObj)->pManFunc, (Hop_Obj_t *)pObj->pData, Abc_ObjFaninNum(pObj) ); - if ( uTruth == uTruths6[0] ) return PTR_OBJ_BUF; - if ( uTruth == ~uTruths6[0] ) return PTR_OBJ_INV; - if ( uTruth == (uTruths6[0] & uTruths6[1]) ) return PTR_OBJ_AND; - if ( uTruth == (uTruths6[0] | uTruths6[1]) ) return PTR_OBJ_OR; - if ( uTruth == (uTruths6[0] ^ uTruths6[1]) ) return PTR_OBJ_XOR; - if ( uTruth == (uTruths6[0] ^~uTruths6[1]) ) return PTR_OBJ_XNOR; + if ( uTruth == uTruths6[0] ) return CBA_NODE_BUF; + if ( uTruth == ~uTruths6[0] ) return CBA_NODE_INV; + if ( uTruth == (uTruths6[0] & uTruths6[1]) ) return CBA_NODE_AND; + if ( uTruth == (uTruths6[0] | uTruths6[1]) ) return CBA_NODE_OR; + if ( uTruth == (uTruths6[0] ^ uTruths6[1]) ) return CBA_NODE_XOR; + if ( uTruth == (uTruths6[0] ^~uTruths6[1]) ) return CBA_NODE_XNOR; assert( 0 ); - return PTR_OBJ_NONE; + return CBA_NODE_NONE; } /**Function************************************************************* @@ -315,11 +251,9 @@ void Ptr_ManDumpModuleBlif( FILE * pFile, Vec_Ptr_t * vNtk ) fprintf( pFile, "\n" ); fprintf( pFile, ".outputs" ); Ptr_ManDumpSignalsBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 2), 1 ); - fprintf( pFile, "\n\n" ); - Ptr_ManDumpNodesBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3) ); fprintf( pFile, "\n" ); + Ptr_ManDumpNodesBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 3) ); Ptr_ManDumpBoxesBlif( pFile, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4) ); - fprintf( pFile, "\n" ); fprintf( pFile, ".end\n\n" ); } void Ptr_ManDumpBlif( char * pFileName, Vec_Ptr_t * vDes ) @@ -352,7 +286,7 @@ void Ptr_ManDumpBlif( char * pFileName, Vec_Ptr_t * vDes ) void Ptr_ManDumpNodeVerilog( FILE * pFile, Vec_Ptr_t * vNode ) { char * pName; int i; - fprintf( pFile, "%s", Ptr_TypeToName( (Ptr_ObjType_t)Abc_Ptr2Int(Vec_PtrEntry(vNode, 1)) ) ); + fprintf( pFile, "%s", Ptr_TypeToName( (Cba_NodeType_t)Abc_Ptr2Int(Vec_PtrEntry(vNode, 1)) ) ); fprintf( pFile, "( %s", (char *)Vec_PtrEntry(vNode, 0) ); Vec_PtrForEachEntryStart( char *, vNode, pName, i, 2 ) fprintf( pFile, ", %s", pName ); @@ -651,7 +585,7 @@ void Cba_PrsReadNodes( Cba_Man_t * p, Vec_Ptr_t * vNodes, Vec_Int_t * vTypesCur, Vec_PtrForEachEntry( Vec_Ptr_t *, vNodes, vNode, i ) { Vec_IntPush( vTypesCur, CBA_OBJ_NODE ); - Vec_IntPush( vFuncsCur, (Ptr_ObjType_t)Abc_Ptr2Int(Vec_PtrEntry(vNode, 1)) ); + Vec_IntPush( vFuncsCur, (Cba_NodeType_t)Abc_Ptr2Int(Vec_PtrEntry(vNode, 1)) ); Vec_IntPush( vInstIdsCur, 0 ); Vec_IntPush( vFaninsCur, Cba_ManHandleArray(p, Cba_PrsReadList(p, vNode, vList, 1, -1)) ); } @@ -676,6 +610,7 @@ void Cba_PrsReadModule( Cba_Man_t * p, Vec_Ptr_t * vNtk ) Vec_Int_t * vInstIdsCur = Vec_IntAlloc( 1000 ); Vec_Int_t * vFaninsCur = Vec_IntAlloc( 1000 ); Vec_Int_t * vList = Vec_IntAlloc( 1000 ); + Vec_Int_t * vBoxes = Vec_IntStart( Vec_PtrSize((Vec_Ptr_t *)Vec_PtrEntry(vNtk, 4)) ); Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, (char *)Vec_PtrEntry(vNtk, 0) ); Cba_PrsReadList( p, (Vec_Ptr_t *)Vec_PtrEntry(vNtk, 1), vInputsCur, -1, -1 ); @@ -689,6 +624,7 @@ void Cba_PrsReadModule( Cba_Man_t * p, Vec_Ptr_t * vNtk ) Cba_ManSetupArray( p, &pNtk->vFuncs, vFuncsCur ); Cba_ManSetupArray( p, &pNtk->vInstIds, vInstIdsCur ); Cba_ManSetupArray( p, &pNtk->vFanins, vFaninsCur ); + Cba_ManSetupArray( p, &pNtk->vBoxes, vBoxes ); Vec_IntFree( vInputsCur ); Vec_IntFree( vOutputsCur ); @@ -697,6 +633,7 @@ void Cba_PrsReadModule( Cba_Man_t * p, Vec_Ptr_t * vNtk ) Vec_IntFree( vInstIdsCur ); Vec_IntFree( vFaninsCur ); Vec_IntFree( vList ); + Vec_IntFree( vBoxes ); } Cba_Man_t * Cba_PrsReadPtr( Vec_Ptr_t * vDes ) { @@ -721,6 +658,7 @@ Cba_Man_t * Cba_PrsReadPtr( Vec_Ptr_t * vDes ) ***********************************************************************/ void Cba_ManReadDesExperiment( Abc_Ntk_t * pNtk ) { + extern Cba_Man_t * Cba_ManBlastTest( Cba_Man_t * p ); abctime clk = Abc_Clock(); Cba_Man_t * p, * pTemp; char * pFileName; @@ -751,9 +689,28 @@ void Cba_ManReadDesExperiment( Abc_Ntk_t * pNtk ) // dump pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out3.blif"); Cba_ManWriteBlif( pFileName, p ); - Cba_ManFree( p ); printf( "Finished writing output file \"%s\". ", pFileName ); Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + + // duplicate CBA + p = Cba_ManDup( pTemp = p ); + Cba_ManFree( pTemp ); + // dump + pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out4.blif"); + Cba_ManWriteBlif( pFileName, p ); + printf( "Finished writing output file \"%s\". ", pFileName ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + + // CBA->GIA->CBA + p = Cba_ManBlastTest( pTemp = p ); + Cba_ManFree( pTemp ); + // dump + pFileName = Extra_FileNameGenericAppend(pNtk->pDesign->pName, "_out5.blif"); + Cba_ManWriteBlif( pFileName, p ); + printf( "Finished writing output file \"%s\". ", pFileName ); + Abc_PrintTime( 1, "Time", Abc_Clock() - clk ); + + Cba_ManFree( p ); } //////////////////////////////////////////////////////////////////////// diff --git a/src/base/cba/cbaWriteBlif.c b/src/base/cba/cbaWriteBlif.c index 001a291c..ea141005 100644 --- a/src/base/cba/cbaWriteBlif.c +++ b/src/base/cba/cbaWriteBlif.c @@ -75,7 +75,7 @@ void Cba_PrsWriteBlifLines( FILE * pFile, Cba_Ntk_t * p ) else if ( Type == CBA_OBJ_BOX ) // .names/assign/box2 (no formal/actual binding) { fprintf( pFile, ".subckt" ); - fprintf( pFile, " %s", Cba_ObjFuncStr(p, i) ); + fprintf( pFile, " %s", Cba_NtkName(Cba_ObjBoxModel(p, i)) ); Cba_PrsWriteBlifArray2( pFile, p, Cba_ObjFaninVec(p, i) ); } else if ( Type == CBA_OBJ_LATCH ) // .names/assign/box2 (no formal/actual binding) diff --git a/src/base/cba/cbaWriteVer.c b/src/base/cba/cbaWriteVer.c index 39ab1faf..8e72ee9a 100644 --- a/src/base/cba/cbaWriteVer.c +++ b/src/base/cba/cbaWriteVer.c @@ -26,44 +26,6 @@ ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -/* - -// node types during parsing -typedef enum { - CBA_NODE_NONE = 0, // 0: unused - CBA_NODE_CONST, // 1: constant - CBA_NODE_BUF, // 2: buffer - CBA_NODE_INV, // 3: inverter - CBA_NODE_AND, // 4: AND - CBA_NODE_OR, // 5: OR - CBA_NODE_XOR, // 6: XOR - CBA_NODE_NAND, // 7: NAND - CBA_NODE_NOR, // 8: NOR - CBA_NODE_XNOR, // 9 .XNOR - CBA_NODE_MUX, // 10: MUX - CBA_NODE_MAJ, // 11: MAJ - CBA_NODE_KNOWN // 12: unknown - CBA_NODE_UNKNOWN // 13: unknown -} Cba_NodeType_t; - -*/ - -const char * s_NodeTypes[CBA_NODE_UNKNOWN+1] = { - NULL, // 0: unused - "const", // 1: constant - "buf", // 2: buffer - "not", // 3: inverter - "and", // 4: AND - "nand", // 5: OR - "or", // 6: XOR - "nor", // 7: NAND - "xor", // 8: NOR - "xnor", // 9: .XNOR - "mux", // 10: MUX - "maj", // 11: MAJ - "???" // 12: known - "???" // 13: unknown -}; //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -139,7 +101,7 @@ void Cba_PrsWriteVerilogNodes( FILE * pFile, Cba_Ntk_t * p ) Func = Cba_ObjFuncId(p, i); if ( Func >= CBA_NODE_BUF && Func <= CBA_NODE_XNOR ) { - fprintf( pFile, " %s (", s_NodeTypes[Func] ); + fprintf( pFile, " %s (", Ptr_TypeToName(Func) ); Cba_PrsWriteVerilogArray2( pFile, p, Cba_ObjFaninVec(p, i) ); fprintf( pFile, ");\n" ); } |