diff options
Diffstat (limited to 'src/aig/ntl')
-rw-r--r-- | src/aig/ntl/ntl.h | 32 | ||||
-rw-r--r-- | src/aig/ntl/ntlExtract.c | 78 | ||||
-rw-r--r-- | src/aig/ntl/ntlUtil.c | 45 |
3 files changed, 122 insertions, 33 deletions
diff --git a/src/aig/ntl/ntl.h b/src/aig/ntl/ntl.h index 0ba62bea..1028bd97 100644 --- a/src/aig/ntl/ntl.h +++ b/src/aig/ntl/ntl.h @@ -198,25 +198,25 @@ static inline void Ntl_ObjSetFanout( Ntl_Obj_t * p, Ntl_Net_t * pNet, int for ( i = 0; (i < Vec_PtrSize(p->vNodes)) && (((pObj) = Vec_PtrEntry(p->vNodes, i)), 1); i++ ) \ if ( (pObj) == NULL || !Ntl_ObjIsBox(pObj) ) {} else -#define Ntl_ModelForEachPi( pNtl, pObj, i ) \ - Vec_PtrForEachEntry( pNtl->vPis, pObj, i ) -#define Ntl_ModelForEachPo( pNtl, pObj, i ) \ - Vec_PtrForEachEntry( pNtl->vPos, pObj, i ) -#define Ntl_ModelForEachObj( pNtl, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNtl->vObjs)) && (((pObj) = Vec_PtrEntry(pNtl->vObjs, i)), 1); i++ ) \ +#define Ntl_ModelForEachPi( pNwk, pObj, i ) \ + Vec_PtrForEachEntry( pNwk->vPis, pObj, i ) +#define Ntl_ModelForEachPo( pNwk, pObj, i ) \ + Vec_PtrForEachEntry( pNwk->vPos, pObj, i ) +#define Ntl_ModelForEachObj( pNwk, pObj, i ) \ + for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ if ( pObj == NULL ) {} else -#define Ntl_ModelForEachLatch( pNtl, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNtl->vObjs)) && (((pObj) = Vec_PtrEntry(pNtl->vObjs, i)), 1); i++ ) \ +#define Ntl_ModelForEachLatch( pNwk, pObj, i ) \ + for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ if ( (pObj) == NULL || !Ntl_ObjIsLatch(pObj) ) {} else -#define Ntl_ModelForEachNode( pNtl, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNtl->vObjs)) && (((pObj) = Vec_PtrEntry(pNtl->vObjs, i)), 1); i++ ) \ +#define Ntl_ModelForEachNode( pNwk, pObj, i ) \ + for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ if ( (pObj) == NULL || !Ntl_ObjIsNode(pObj) ) {} else -#define Ntl_ModelForEachBox( pNtl, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNtl->vObjs)) && (((pObj) = Vec_PtrEntry(pNtl->vObjs, i)), 1); i++ ) \ +#define Ntl_ModelForEachBox( pNwk, pObj, i ) \ + for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ if ( (pObj) == NULL || !Ntl_ObjIsBox(pObj) ) {} else -#define Ntl_ModelForEachNet( pNtl, pNet, i ) \ - for ( i = 0; i < pNtl->nTableSize; i++ ) \ - for ( pNet = pNtl->pTable[i]; pNet; pNet = pNet->pNext ) +#define Ntl_ModelForEachNet( pNwk, pNet, i ) \ + for ( i = 0; i < pNwk->nTableSize; i++ ) \ + for ( pNet = pNwk->pTable[i]; pNet; pNet = pNet->pNext ) #define Ntl_ObjForEachFanin( pObj, pFanin, i ) \ for ( i = 0; (i < (pObj)->nFanins) && ((pFanin) = (pObj)->pFanio[i]); i++ ) @@ -296,6 +296,8 @@ extern void Ioa_WriteBlif( Ntl_Man_t * p, char * pFileName ); extern void Ioa_WriteBlifLogic( Nwk_Man_t * pNtk, Ntl_Man_t * p, char * pFileName ); /*=== ntlUtil.c ==========================================================*/ extern int Ntl_ModelCountLut1( Ntl_Mod_t * pRoot ); +extern int Ntl_ModelGetFaninMax( Ntl_Mod_t * pRoot ); +extern Ntl_Net_t * Ntl_ModelFindSimpleNet( Ntl_Net_t * pNetCo ); extern int Ntl_ManCountSimpleCoDrivers( Ntl_Man_t * p ); extern Vec_Ptr_t * Ntl_ManCollectCiNames( Ntl_Man_t * p ); extern Vec_Ptr_t * Ntl_ManCollectCoNames( Ntl_Man_t * p ); diff --git a/src/aig/ntl/ntlExtract.c b/src/aig/ntl/ntlExtract.c index f278cba8..69219282 100644 --- a/src/aig/ntl/ntlExtract.c +++ b/src/aig/ntl/ntlExtract.c @@ -277,7 +277,7 @@ Aig_Man_t * Ntl_ManExtract( Ntl_Man_t * p ) Vec_PtrPush( p->vCos, pNet ); Aig_ObjCreatePo( p->pAig, pNet->pCopy ); } - // visit the nodes starting from latch inputs outputs + // visit the nodes starting from latch inputs Ntl_ModelForEachLatch( pRoot, pObj, i ) { pNet = Ntl_ObjFanin0(pObj); @@ -777,21 +777,22 @@ Nwk_Obj_t * Ntl_ManExtractNwk_rec( Ntl_Man_t * p, Ntl_Net_t * pNet, Nwk_Man_t * SeeAlso [] ***********************************************************************/ -Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig ) +Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig, Tim_Man_t * pManTime ) { Nwk_Man_t * pNtk; Nwk_Obj_t * pNode; Ntl_Mod_t * pRoot; - Ntl_Net_t * pNet; + Ntl_Net_t * pNet, * pNetSimple; Ntl_Obj_t * pObj; Aig_Obj_t * pAnd; Vec_Int_t * vCover, * vMemory; int i, k; pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelBoxNum(pRoot) == 0 ); - assert( Ntl_ModelLatchNum(pRoot) == 0 ); - assert( Ntl_ModelPiNum(pRoot) == Aig_ManPiNum(pAig) ); - assert( Ntl_ModelPoNum(pRoot) == Aig_ManPoNum(pAig) ); + if ( Ntl_ModelGetFaninMax(pRoot) > 6 ) + { + printf( "The network contains logic nodes with more than 6 inputs.\n" ); + return NULL; + } vCover = Vec_IntAlloc( 100 ); vMemory = Vec_IntAlloc( 1 << 16 ); // count the number of fanouts of each net @@ -803,30 +804,59 @@ Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig ) Ntl_ModelForEachObj( pRoot, pObj, i ) Ntl_ObjForEachFanin( pObj, pNet, k ) Ntl_NetIncrementRefs( pNet ); + // remember netlist objects int the AIG nodes + if ( pManTime != NULL ) // logic netlist + { + assert( Ntl_ModelPiNum(pRoot) == Aig_ManPiNum(pAig) ); + assert( Ntl_ModelPoNum(pRoot) == Aig_ManPoNum(pAig) ); + Aig_ManForEachPi( pAig, pAnd, i ) + pAnd->pData = Ntl_ObjFanout0( Ntl_ModelPi(pRoot, i) ); + Aig_ManForEachPo( pAig, pAnd, i ) + pAnd->pData = Ntl_ObjFanin0(Ntl_ModelPo(pRoot, i) ); + } + else // real netlist + { + assert( p->vCis && p->vCos ); + Aig_ManForEachPi( pAig, pAnd, i ) + pAnd->pData = Vec_PtrEntry( p->vCis, i ); + Aig_ManForEachPo( pAig, pAnd, i ) + pAnd->pData = Vec_PtrEntry( p->vCos, i ); + } // construct the network pNtk = Nwk_ManAlloc(); pNtk->pName = Aig_UtilStrsav( pAig->pName ); pNtk->pSpec = Aig_UtilStrsav( pAig->pSpec ); - Aig_ManSetPioNumbers( pAig ); +// Aig_ManSetPioNumbers( pAig ); Aig_ManForEachObj( pAig, pAnd, i ) { if ( Aig_ObjIsPi(pAnd) ) { - pObj = Ntl_ModelPi( pRoot, Aig_ObjPioNum(pAnd) ); - pNet = Ntl_ObjFanout0(pObj); +// pObj = Ntl_ModelPi( pRoot, Aig_ObjPioNum(pAnd) ); +// pNet = Ntl_ObjFanout0(pObj); + pNet = pAnd->pData; pNet->fMark = 1; pNet->pCopy = Nwk_ManCreateCi( pNtk, (int)(long)pNet->pCopy ); } else if ( Aig_ObjIsPo(pAnd) ) { - pObj = Ntl_ModelPo( pRoot, Aig_ObjPioNum(pAnd) ); - pNet = Ntl_ObjFanin0(pObj); - pNet->pCopy = Ntl_ManExtractNwk_rec( p, pNet, pNtk, vCover, vMemory ); +// pObj = Ntl_ModelPo( pRoot, Aig_ObjPioNum(pAnd) ); +// pNet = Ntl_ObjFanin0(pObj); + pNet = pAnd->pData; pNode = Nwk_ManCreateCo( pNtk ); - Nwk_ObjAddFanin( pNode, pNet->pCopy ); + if ( (pNetSimple = Ntl_ModelFindSimpleNet( pNet )) ) + { + pNetSimple->pCopy = Ntl_ManExtractNwk_rec( p, pNetSimple, pNtk, vCover, vMemory ); + Nwk_ObjAddFanin( pNode, pNetSimple->pCopy ); + pNode->fInvert = Kit_PlaIsInv( pNet->pDriver->pSop ); + } + else + { + pNet->pCopy = Ntl_ManExtractNwk_rec( p, pNet, pNtk, vCover, vMemory ); + Nwk_ObjAddFanin( pNode, pNet->pCopy ); + } } } - Aig_ManCleanPioNumbers( pAig ); +// Aig_ManCleanPioNumbers( pAig ); Ntl_ModelForEachNet( pRoot, pNet, i ) { pNet->pCopy = NULL; @@ -835,6 +865,10 @@ Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig ) Vec_IntFree( vCover ); Vec_IntFree( vMemory ); // create timing manager from the current design + if ( pManTime ) + pNtk->pManTime = Tim_ManDup( pManTime, 0 ); + else + pNtk->pManTime = Tim_ManDup( p->pManTime, 0 ); return pNtk; } @@ -861,6 +895,16 @@ Nwk_Man_t * Ntl_ManReadNwk( char * pFileName, Aig_Man_t * pAig, Tim_Man_t * pMan return NULL; } pRoot = Ntl_ManRootModel( pNtl ); + if ( Ntl_ModelLatchNum(pRoot) != 0 ) + { + printf( "Ntl_ManReadNwk(): The input network has %d registers.\n", Ntl_ModelLatchNum(pRoot) ); + return NULL; + } + if ( Ntl_ModelBoxNum(pRoot) != 0 ) + { + printf( "Ntl_ManReadNwk(): The input network has %d boxes.\n", Ntl_ModelBoxNum(pRoot) ); + return NULL; + } if ( Ntl_ModelPiNum(pRoot) != Aig_ManPiNum(pAig) ) { printf( "Ntl_ManReadNwk(): The number of primary inputs does not match (%d and %d).\n", @@ -873,10 +917,8 @@ Nwk_Man_t * Ntl_ManReadNwk( char * pFileName, Aig_Man_t * pAig, Tim_Man_t * pMan Ntl_ModelPoNum(pRoot), Aig_ManPoNum(pAig) ); return NULL; } - pNtk = Ntl_ManExtractNwk( pNtl, pAig ); + pNtk = Ntl_ManExtractNwk( pNtl, pAig, pManTime ); Ntl_ManFree( pNtl ); - if ( pManTime ) - pNtk->pManTime = Tim_ManDup( pManTime, 0 ); return pNtk; } diff --git a/src/aig/ntl/ntlUtil.c b/src/aig/ntl/ntlUtil.c index 83586e42..6849889d 100644 --- a/src/aig/ntl/ntlUtil.c +++ b/src/aig/ntl/ntlUtil.c @@ -51,6 +51,51 @@ int Ntl_ModelCountLut1( Ntl_Mod_t * pRoot ) /**Function************************************************************* + Synopsis [Reads the maximum number of fanins.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Ntl_ModelGetFaninMax( Ntl_Mod_t * pRoot ) +{ + Ntl_Obj_t * pNode; + int i, nFaninsMax = 0; + Ntl_ModelForEachNode( pRoot, pNode, i ) + { + if ( nFaninsMax < Ntl_ObjFaninNum(pNode) ) + nFaninsMax = Ntl_ObjFaninNum(pNode); + } + return nFaninsMax; +} + +/**Function************************************************************* + + Synopsis [If the net is driven by an inv/buf, returns its fanin.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Ntl_Net_t * Ntl_ModelFindSimpleNet( Ntl_Net_t * pNetCo ) +{ + // skip the case when the net is not driven by a node + if ( !Ntl_ObjIsNode(pNetCo->pDriver) ) + return NULL; + // skip the case when the node is not an inv/buf + if ( Ntl_ObjFaninNum(pNetCo->pDriver) != 1 ) + return NULL; + return Ntl_ObjFanin0(pNetCo->pDriver); +} + +/**Function************************************************************* + Synopsis [Connects COs to the internal nodes other than inv/bufs.] Description [Should be called immediately after reading from file.] |