diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-01-21 04:30:10 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-01-21 04:30:10 -0800 |
commit | 8014f25f6db719fa62336f997963532a14c568f6 (patch) | |
tree | c691ee91a3a2d452a2bd24ac89a8c717beaa7af7 /src/aig/ntl | |
parent | c44cc5de9429e6b4f1c05045fcf43c9cb96437b5 (diff) | |
download | abc-8014f25f6db719fa62336f997963532a14c568f6.tar.gz abc-8014f25f6db719fa62336f997963532a14c568f6.tar.bz2 abc-8014f25f6db719fa62336f997963532a14c568f6.zip |
Major restructuring of the code.
Diffstat (limited to 'src/aig/ntl')
-rw-r--r-- | src/aig/ntl/module.make | 17 | ||||
-rw-r--r-- | src/aig/ntl/ntl.h | 426 | ||||
-rw-r--r-- | src/aig/ntl/ntlCheck.c | 379 | ||||
-rw-r--r-- | src/aig/ntl/ntlCore.c | 152 | ||||
-rw-r--r-- | src/aig/ntl/ntlEc.c | 370 | ||||
-rw-r--r-- | src/aig/ntl/ntlExtract.c | 877 | ||||
-rw-r--r-- | src/aig/ntl/ntlFraig.c | 1004 | ||||
-rw-r--r-- | src/aig/ntl/ntlInsert.c | 614 | ||||
-rw-r--r-- | src/aig/ntl/ntlMan.c | 1068 | ||||
-rw-r--r-- | src/aig/ntl/ntlMap.c | 346 | ||||
-rw-r--r-- | src/aig/ntl/ntlNames.c | 471 | ||||
-rw-r--r-- | src/aig/ntl/ntlObj.c | 319 | ||||
-rw-r--r-- | src/aig/ntl/ntlReadBlif.c | 1446 | ||||
-rw-r--r-- | src/aig/ntl/ntlSweep.c | 214 | ||||
-rw-r--r-- | src/aig/ntl/ntlTable.c | 554 | ||||
-rw-r--r-- | src/aig/ntl/ntlTime.c | 245 | ||||
-rw-r--r-- | src/aig/ntl/ntlUtil.c | 737 | ||||
-rw-r--r-- | src/aig/ntl/ntlWriteBlif.c | 697 | ||||
-rw-r--r-- | src/aig/ntl/ntl_.c | 52 | ||||
-rw-r--r-- | src/aig/ntl/ntlnwk.h | 113 |
20 files changed, 0 insertions, 10101 deletions
diff --git a/src/aig/ntl/module.make b/src/aig/ntl/module.make deleted file mode 100644 index 2af0f4e0..00000000 --- a/src/aig/ntl/module.make +++ /dev/null @@ -1,17 +0,0 @@ -SRC += src/aig/ntl/ntlCheck.c \ - src/aig/ntl/ntlCore.c \ - src/aig/ntl/ntlEc.c \ - src/aig/ntl/ntlExtract.c \ - src/aig/ntl/ntlFraig.c \ - src/aig/ntl/ntlInsert.c \ - src/aig/ntl/ntlMan.c \ - src/aig/ntl/ntlMap.c \ - src/aig/ntl/ntlNames.c \ - src/aig/ntl/ntlObj.c \ - src/aig/ntl/ntlReadBlif.c \ - src/aig/ntl/ntlSweep.c \ - src/aig/ntl/ntlTable.c \ - src/aig/ntl/ntlTime.c \ - src/aig/ntl/ntlUtil.c \ - src/aig/ntl/ntlWriteBlif.c - diff --git a/src/aig/ntl/ntl.h b/src/aig/ntl/ntl.h deleted file mode 100644 index c0d701e0..00000000 --- a/src/aig/ntl/ntl.h +++ /dev/null @@ -1,426 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntl.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntl.h,v 1.3 2008/10/24 14:18:44 mjarvin Exp $] - -***********************************************************************/ - -#ifndef __NTL_H__ -#define __NTL_H__ - - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include "aig.h" -#include "tim.h" -#include "nwk.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Ntl_Mod_t_ Ntl_Mod_t; -typedef struct Ntl_Reg_t_ Ntl_Reg_t; -typedef struct Ntl_Obj_t_ Ntl_Obj_t; -typedef struct Ntl_Net_t_ Ntl_Net_t; -typedef struct Ntl_Lut_t_ Ntl_Lut_t; - -// object types -typedef enum { - NTL_OBJ_NONE, // 0: non-existent object - NTL_OBJ_PI, // 1: primary input - NTL_OBJ_PO, // 2: primary output - NTL_OBJ_LATCH, // 3: latch - NTL_OBJ_NODE, // 4: logic node - NTL_OBJ_LUT1, // 5: inverter/buffer - NTL_OBJ_BOX, // 6: white box or black box - NTL_OBJ_VOID // 7: unused object -} Ntl_Type_t; - -struct Ntl_Man_t_ -{ - // models of this design - char * pName; // the name of this design - char * pSpec; // the name of input file - Vec_Ptr_t * vModels; // the array of all models used to represent boxes - int BoxTypes[32]; // the array of box types among the models - // memory managers - Aig_MmFlex_t * pMemObjs; // memory for objects - Aig_MmFlex_t * pMemSops; // memory for SOPs - // extracted representation - Vec_Ptr_t * vCis; // the primary inputs of the extracted part - Vec_Ptr_t * vCos; // the primary outputs of the extracted part - Vec_Ptr_t * vVisNodes; // the nodes of the abstracted part - Vec_Int_t * vBox1Cios; // the first COs of the boxes - Vec_Int_t * vRegClasses; // the classes of registers in the AIG - Vec_Int_t * vRstClasses; // the classes of reset registers in the AIG - Aig_Man_t * pAig; // the extracted AIG - Tim_Man_t * pManTime; // the timing manager - int iLastCi; // the last true CI - void * pNal; // additional data - void (*pNalF)(void *); // additional data - void (*pNalD)(void *,void *); // additional data - void (*pNalW)(void *,void *); // additional data - void (*pNalR)(void *); // additional data - // hashing names into models - Ntl_Mod_t ** pModTable; // the hash table of names into models - int nModTableSize; // the allocated table size - int nModEntries; // the number of entries in the hash table -}; - -struct Ntl_Mod_t_ -{ - // model description - Ntl_Man_t * pMan; // the model manager - char * pName; // the model name - Vec_Ptr_t * vObjs; // the array of all objects - Vec_Ptr_t * vPis; // the array of PI objects - Vec_Ptr_t * vPos; // the array of PO objects - Vec_Ptr_t * vNets; // the array of nets - int nObjs[NTL_OBJ_VOID]; // counter of objects of each type - // box attributes - unsigned int attrWhite :1; // box has known logic - unsigned int attrBox :1; // box is to remain unmapped - unsigned int attrComb :1; // box is combinational - unsigned int attrKeep :1; // box cannot be removed by structural sweep - unsigned int attrNoMerge :1; // box outputs cannot be merged - // hashing names into nets - Ntl_Net_t ** pTable; // the hash table of names into nets - int nTableSize; // the allocated table size - int nEntries; // the number of entries in the hash table - // clocks of the model - Vec_Ptr_t * vClocks; // the clock signals - Vec_Vec_t * vClockFlops; // the flops of each clock - // resets of the model - Vec_Ptr_t * vResets; // the reset signals - Vec_Vec_t * vResetFlops; // the ASYNC flops of each reset - // delay information - Vec_Int_t * vDelays; - Vec_Int_t * vTimeInputs; - Vec_Int_t * vTimeOutputs; - float * pDelayTable; - // other data members - Ntl_Mod_t * pNext; - void * pCopy; - int nUsed, nRems; -}; - -struct Ntl_Reg_t_ -{ - unsigned int regInit : 2; // register initial value - unsigned int regType : 3; // register type - unsigned int regClass : 28; // register class -}; - -struct Ntl_Obj_t_ -{ -// Ntl_Mod_t * pModel; // the model - void * pCopy; // the copy of this object - unsigned Type : 3; // object type - unsigned fMark : 1; // temporary mark - unsigned Id : 28; // object ID - int nFanins; // the number of fanins - int nFanouts; // the number of fanouts - int Reset; // reset of the flop - union { // functionality - Ntl_Mod_t * pImplem; // model (for boxes) - char * pSop; // SOP (for logic nodes) - Ntl_Reg_t LatchId; // init state + register class (for latches) - }; - union { // clock / other data - Ntl_Net_t * pClock; // clock (for registers) - void * pTemp; // other data - int iTemp; // other data - }; - Ntl_Net_t * pFanio[0]; // fanins/fanouts -}; - -struct Ntl_Net_t_ -{ - Ntl_Net_t * pNext; // next net in the hash table - void * pCopy; // the copy of this object - union { - void * pCopy2; // the copy of this object - float dTemp; // other data - int iTemp; // other data - }; - Ntl_Obj_t * pDriver; // driver of the net - unsigned NetId : 27; // unique ID of the net - unsigned nVisits : 2; // the number of times the net is visted - unsigned fMark : 1; // temporary mark - unsigned fMark2 : 1; // temporary mark - unsigned fFixed : 1; // the fixed net - char pName[0]; // the name of this net -}; - -struct Ntl_Lut_t_ -{ - int Id; // the ID of the root AIG node - int nFanins; // the number of fanins - int * pFanins; // the array of fanins - unsigned * pTruth; // the truth table -}; - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - - -//////////////////////////////////////////////////////////////////////// -/// INLINED FUNCTIONS /// -//////////////////////////////////////////////////////////////////////// - -static inline Ntl_Mod_t * Ntl_ManRootModel( Ntl_Man_t * p ) { return (Ntl_Mod_t *)Vec_PtrEntry( p->vModels, 0 ); } - -static inline int Ntl_ModelPiNum( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_PI]; } -static inline int Ntl_ModelPoNum( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_PO]; } -static inline int Ntl_ModelNodeNum( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_NODE]; } -static inline int Ntl_ModelLut1Num( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_LUT1]; } -static inline int Ntl_ModelLatchNum( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_LATCH]; } -static inline int Ntl_ModelBoxNum( Ntl_Mod_t * p ) { return p->nObjs[NTL_OBJ_BOX]; } - -static inline Ntl_Obj_t * Ntl_ModelPi( Ntl_Mod_t * p, int i ) { return (Ntl_Obj_t *)Vec_PtrEntry(p->vPis, i); } -static inline Ntl_Obj_t * Ntl_ModelPo( Ntl_Mod_t * p, int i ) { return (Ntl_Obj_t *)Vec_PtrEntry(p->vPos, i); } -static inline Ntl_Obj_t * Ntl_ModelObj( Ntl_Mod_t * p, int i ) { return (Ntl_Obj_t *)Vec_PtrEntry(p->vObjs, i); } -static inline Ntl_Net_t * Ntl_ModelNet( Ntl_Mod_t * p, int i ) { return (Ntl_Net_t *)Vec_PtrEntry(p->vNets, i); } - -static inline char * Ntl_ModelPiName( Ntl_Mod_t * p, int i ) { return Ntl_ModelPi(p, i)->pFanio[0]->pName; } -static inline char * Ntl_ModelPoName( Ntl_Mod_t * p, int i ) { return Ntl_ModelPo(p, i)->pFanio[0]->pName; } - -static inline int Ntl_ObjFaninNum( Ntl_Obj_t * p ) { return p->nFanins; } -static inline int Ntl_ObjFanoutNum( Ntl_Obj_t * p ) { return p->nFanouts; } - -static inline int Ntl_ObjIsPi( Ntl_Obj_t * p ) { return p->Type == NTL_OBJ_PI; } -static inline int Ntl_ObjIsPo( Ntl_Obj_t * p ) { return p->Type == NTL_OBJ_PO; } -static inline int Ntl_ObjIsNode( Ntl_Obj_t * p ) { return p->Type == NTL_OBJ_NODE; } -static inline int Ntl_ObjIsLatch( Ntl_Obj_t * p ) { return p->Type == NTL_OBJ_LATCH; } -static inline int Ntl_ObjIsBox( Ntl_Obj_t * p ) { return p->Type == NTL_OBJ_BOX; } -static inline int Ntl_ObjIsLutBox( Ntl_Obj_t * p ) { return Ntl_ObjIsBox(p) && strncmp("LUT", p->pImplem->pName, 3) == 0; } - -static inline Ntl_Net_t * Ntl_ObjFanin0( Ntl_Obj_t * p ) { return p->pFanio[0]; } -static inline Ntl_Net_t * Ntl_ObjFanout0( Ntl_Obj_t * p ) { return p->pFanio[p->nFanins]; } - -static inline Ntl_Net_t * Ntl_ObjFanin( Ntl_Obj_t * p, int i ) { return p->pFanio[i]; } -static inline Ntl_Net_t * Ntl_ObjFanout( Ntl_Obj_t * p, int i ) { return p->pFanio[p->nFanins+i]; } - -static inline void Ntl_ObjSetFanin( Ntl_Obj_t * p, Ntl_Net_t * pNet, int i ) { p->pFanio[i] = pNet; } -static inline void Ntl_ObjSetFanout( Ntl_Obj_t * p, Ntl_Net_t * pNet, int i ) { p->pFanio[p->nFanins+i] = pNet; pNet->pDriver = p; } - -static inline int Ntl_ObjIsInit1( Ntl_Obj_t * p ) { assert( Ntl_ObjIsLatch(p) ); return p->LatchId.regInit == 1; } -static inline void Ntl_ObjSetInit0( Ntl_Obj_t * p ) { assert( Ntl_ObjIsLatch(p) ); p->LatchId.regInit = 0; } - -static inline int Ntl_BoxIsWhite( Ntl_Obj_t * p ) { assert( Ntl_ObjIsBox(p) ); return p->pImplem->attrWhite; } -static inline int Ntl_BoxIsBlack( Ntl_Obj_t * p ) { assert( Ntl_ObjIsBox(p) ); return !p->pImplem->attrWhite; } -static inline int Ntl_BoxIsComb( Ntl_Obj_t * p ) { assert( Ntl_ObjIsBox(p) ); return p->pImplem->attrComb; } -static inline int Ntl_BoxIsSeq( Ntl_Obj_t * p ) { assert( Ntl_ObjIsBox(p) ); return !p->pImplem->attrComb; } -static inline int Ntl_BoxIsNoMerge( Ntl_Obj_t * p ) { assert( Ntl_ObjIsBox(p) ); return !p->pImplem->attrNoMerge; } - -static inline int Ntl_ObjIsMapLeaf( Ntl_Obj_t * p ) { return Ntl_ObjIsPi(p) || (Ntl_ObjIsBox(p) && Ntl_BoxIsSeq(p)); } -static inline int Ntl_ObjIsMapRoot( Ntl_Obj_t * p ) { return Ntl_ObjIsPo(p) || (Ntl_ObjIsBox(p) && Ntl_BoxIsSeq(p)); } - -static inline int Ntl_ObjIsCombLeaf( Ntl_Obj_t * p ) { return Ntl_ObjIsPi(p) || (Ntl_ObjIsBox(p) && (Ntl_BoxIsSeq(p) || Ntl_BoxIsBlack(p))); } -static inline int Ntl_ObjIsCombRoot( Ntl_Obj_t * p ) { return Ntl_ObjIsPo(p) || (Ntl_ObjIsBox(p) && (Ntl_BoxIsSeq(p) || Ntl_BoxIsBlack(p))); } - -static inline int Ntl_ObjIsSeqLeaf( Ntl_Obj_t * p ) { return Ntl_ObjIsPi(p) || (Ntl_ObjIsBox(p) && Ntl_BoxIsBlack(p)); } -static inline int Ntl_ObjIsSeqRoot( Ntl_Obj_t * p ) { return Ntl_ObjIsPo(p) || (Ntl_ObjIsBox(p) && Ntl_BoxIsBlack(p)); } - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -#define Ntl_ManForEachModel( p, pMod, i ) \ - for ( i = 0; (i < Vec_PtrSize(p->vModels)) && (((pMod) = (Ntl_Mod_t*)Vec_PtrEntry(p->vModels, i)), 1); i++ ) -#define Ntl_ManForEachCiNet( p, pNet, i ) \ - Vec_PtrForEachEntry( Ntl_Net_t *, p->vCis, pNet, i ) -#define Ntl_ManForEachCoNet( p, pNet, i ) \ - Vec_PtrForEachEntry( Ntl_Net_t *, p->vCos, pNet, i ) - -#define Ntl_ModelForEachPi( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vPis)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vPis, i)), 1); i++ ) -#define Ntl_ModelForEachPo( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vPos)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vPos, i)), 1); i++ ) -#define Ntl_ModelForEachNet( pNwk, pNet, i ) \ - Vec_PtrForEachEntry( Ntl_Net_t *, pNwk->vNets, pNet, i ) \ - if ( pNet == NULL ) {} else -#define Ntl_ModelForEachObj( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( pObj == NULL ) {} else -#define Ntl_ModelForEachLatch( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsLatch((Ntl_Obj_t*)pObj) ) {} else -#define Ntl_ModelForEachNode( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsNode(pObj) ) {} else -#define Ntl_ModelForEachBox( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsBox(pObj) ) {} else - -#define Ntl_ObjForEachFanin( pObj, pFanin, i ) \ - for ( i = 0; (i < (pObj)->nFanins) && (((pFanin) = (pObj)->pFanio[i]), 1); i++ ) -#define Ntl_ObjForEachFanout( pObj, pFanout, i ) \ - for ( i = 0; (i < (pObj)->nFanouts) && (((pFanout) = (pObj)->pFanio[(pObj)->nFanins+i]), 1); i++ ) - -#define Ntl_ModelForEachMapLeaf( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsMapLeaf(pObj) ) {} else -#define Ntl_ModelForEachMapRoot( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsMapRoot(pObj) ) {} else -#define Ntl_ModelForEachCombLeaf( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsCombLeaf(pObj) ) {} else -#define Ntl_ModelForEachCombRoot( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsCombRoot(pObj) ) {} else -#define Ntl_ModelForEachSeqLeaf( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsSeqLeaf(pObj) ) {} else -#define Ntl_ModelForEachSeqRoot( pNwk, pObj, i ) \ - for ( i = 0; (i < Vec_PtrSize(pNwk->vObjs)) && (((pObj) = (Ntl_Obj_t*)Vec_PtrEntry(pNwk->vObjs, i)), 1); i++ ) \ - if ( (pObj) == NULL || !Ntl_ObjIsSeqRoot(pObj) ) {} else - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/*=== ntlCore.c ==========================================================*/ -extern ABC_DLL int Ntl_ManInsertTest( Ntl_Man_t * p, Aig_Man_t * pAig ); -extern ABC_DLL int Ntl_ManInsertTestIf( Ntl_Man_t * p, Aig_Man_t * pAig ); -/*=== ntlEc.c ==========================================================*/ -extern ABC_DLL void Ntl_ManPrepareCecMans( Ntl_Man_t * pMan1, Ntl_Man_t * pMan2, Aig_Man_t ** ppAig1, Aig_Man_t ** ppAig2 ); -extern ABC_DLL void Ntl_ManPrepareCec( char * pFileName1, char * pFileName2, Aig_Man_t ** ppAig1, Aig_Man_t ** ppAig2 ); -extern ABC_DLL Aig_Man_t * Ntl_ManPrepareSec( char * pFileName1, char * pFileName2 ); -/*=== ntlExtract.c ==========================================================*/ -extern ABC_DLL Aig_Man_t * Ntl_ManExtract( Ntl_Man_t * p ); -extern ABC_DLL Aig_Man_t * Ntl_ManCollapse( Ntl_Man_t * p, int fSeq ); -extern ABC_DLL Aig_Man_t * Ntl_ManCollapseComb( Ntl_Man_t * p ); -extern ABC_DLL Aig_Man_t * Ntl_ManCollapseSeq( Ntl_Man_t * p, int nMinDomSize, int fVerbose ); -extern ABC_DLL Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig, Tim_Man_t * pManTime ); -/*=== ntlInsert.c ==========================================================*/ -extern ABC_DLL Ntl_Man_t * Ntl_ManInsertMapping( Ntl_Man_t * p, Vec_Ptr_t * vMapping, Aig_Man_t * pAig ); -extern ABC_DLL Ntl_Man_t * Ntl_ManInsertAig( Ntl_Man_t * p, Aig_Man_t * pAig ); -extern ABC_DLL Ntl_Man_t * Ntl_ManInsertNtk( Ntl_Man_t * p, Nwk_Man_t * pNtk ); -/*=== ntlCheck.c ==========================================================*/ -extern ABC_DLL int Ntl_ManCheck( Ntl_Man_t * pMan ); -extern ABC_DLL int Ntl_ModelCheck( Ntl_Mod_t * pModel, int fMain ); -extern ABC_DLL void Ntl_ModelFixNonDrivenNets( Ntl_Mod_t * pModel ); -extern ABC_DLL void Ntl_ModelTransformLatches( Ntl_Mod_t * pModel ); -/*=== ntlMan.c ============================================================*/ -extern ABC_DLL Ntl_Man_t * Ntl_ManAlloc(); -extern ABC_DLL void Ntl_ManCleanup( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManStartFrom( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManDup( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManDupCollapseLuts( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManFree( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManPrintStats( Ntl_Man_t * p ); -extern ABC_DLL Tim_Man_t * Ntl_ManReadTimeMan( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManPrintTypes( Ntl_Man_t * p ); -extern ABC_DLL int Ntl_ManCompareClockClasses( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ); -extern ABC_DLL void Ntl_ManPrintClocks( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManPrintResets( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Mod_t * Ntl_ModelAlloc( Ntl_Man_t * pMan, char * pName ); -extern ABC_DLL Ntl_Mod_t * Ntl_ModelStartFrom( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ); -extern ABC_DLL Ntl_Mod_t * Ntl_ModelDup( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ); -extern ABC_DLL Ntl_Mod_t * Ntl_ModelDupCollapseLuts( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ); -extern ABC_DLL void Ntl_ModelFree( Ntl_Mod_t * p ); -extern ABC_DLL Ntl_Mod_t * Ntl_ManCreateLatchModel( Ntl_Man_t * pMan, int Init ); -extern ABC_DLL int Ntl_ModelCountLut0( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelCountLut1( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelCountBuf( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelCountInv( Ntl_Mod_t * p ); -/*=== ntlMap.c ============================================================*/ -extern ABC_DLL Vec_Ptr_t * Ntl_MappingAlloc( int nLuts, int nVars ); -extern ABC_DLL Vec_Ptr_t * Ntl_MappingFromAig( Aig_Man_t * p ); -extern ABC_DLL Vec_Ptr_t * Ntl_MappingFpga( Aig_Man_t * p ); -extern ABC_DLL Vec_Ptr_t * Ntl_MappingIf( Ntl_Man_t * pMan, Aig_Man_t * p ); -/*=== ntlObj.c ============================================================*/ -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreatePi( Ntl_Mod_t * pModel ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreatePo( Ntl_Mod_t * pModel, Ntl_Net_t * pNet ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreateLatch( Ntl_Mod_t * pModel ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreateNode( Ntl_Mod_t * pModel, int nFanins ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreateBox( Ntl_Mod_t * pModel, int nFanins, int nFanouts ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelDupObj( Ntl_Mod_t * pModel, Ntl_Obj_t * pOld ); -extern ABC_DLL Ntl_Obj_t * Ntl_ModelCreatePiWithName( Ntl_Mod_t * pModel, char * pName ); -extern ABC_DLL char * Ntl_ManStoreName( Ntl_Man_t * p, char * pName ); -extern ABC_DLL char * Ntl_ManStoreSop( Aig_MmFlex_t * pMan, const char * pSop ); -extern ABC_DLL char * Ntl_ManStoreFileName( Ntl_Man_t * p, char * pFileName ); -extern ABC_DLL int Ntl_ManObjWhichFanout( Ntl_Obj_t * pNode, Ntl_Net_t * pFanout ); -/*=== ntlSweep.c ==========================================================*/ -extern ABC_DLL int Ntl_ManSweep( Ntl_Man_t * p, int fVerbose ); -/*=== ntlTable.c ==========================================================*/ -extern ABC_DLL Ntl_Net_t * Ntl_ModelFindNet( Ntl_Mod_t * p, const char * pName ); -extern ABC_DLL char * Ntl_ModelCreateNetName( Ntl_Mod_t * p, const char * pName, int Num ); -extern ABC_DLL Ntl_Net_t * Ntl_ModelFindOrCreateNet( Ntl_Mod_t * p, const char * pName ); -extern ABC_DLL Ntl_Net_t * Ntl_ModelDontFindCreateNet( Ntl_Mod_t * p, const char * pName ); -extern ABC_DLL void Ntl_ModelSetPioNumbers( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelFindPioNumber( Ntl_Mod_t * p, int fPiOnly, int fPoOnly, const char * pName, int * pNumber ); -extern ABC_DLL int Ntl_ModelSetNetDriver( Ntl_Obj_t * pObj, Ntl_Net_t * pNet ); -extern ABC_DLL int Ntl_ModelClearNetDriver( Ntl_Obj_t * pObj, Ntl_Net_t * pNet ); -extern ABC_DLL void Ntl_ModelDeleteNet( Ntl_Mod_t * p, Ntl_Net_t * pNet ); -extern ABC_DLL void Ntl_ModelInsertNet( Ntl_Mod_t * p, Ntl_Net_t * pNet ); -extern ABC_DLL int Ntl_ModelCountNets( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ManAddModel( Ntl_Man_t * p, Ntl_Mod_t * pModel ); -extern ABC_DLL Ntl_Mod_t * Ntl_ManFindModel( Ntl_Man_t * p, const char * pName ); -/*=== ntlTime.c ==========================================================*/ -extern ABC_DLL Tim_Man_t * Ntl_ManCreateTiming( Ntl_Man_t * p ); -/*=== ntlReadBlif.c ==========================================================*/ -extern ABC_DLL Ntl_Man_t * Ntl_ManReadBlif( char * pFileName, int fCheck ); -/*=== ntlWriteBlif.c ==========================================================*/ -extern ABC_DLL void Ntl_ManWriteBlif( Ntl_Man_t * p, char * pFileName ); -extern ABC_DLL void Ntl_WriteBlifLogic( Nwk_Man_t * pNtk, Ntl_Man_t * p, char * pFileName ); -/*=== ntlUtil.c ==========================================================*/ -extern ABC_DLL int Ntl_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 ); -extern ABC_DLL int Ntl_ModelGetFaninMax( Ntl_Mod_t * pRoot ); -extern ABC_DLL Ntl_Net_t * Ntl_ModelFindSimpleNet( Ntl_Net_t * pNetCo ); -extern ABC_DLL int Ntl_ManCountSimpleCoDrivers( Ntl_Man_t * p ); -extern ABC_DLL Vec_Ptr_t * Ntl_ManCollectCiNames( Ntl_Man_t * p ); -extern ABC_DLL Vec_Ptr_t * Ntl_ManCollectCoNames( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManMarkCiCoNets( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManUnmarkCiCoNets( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManSetZeroInitValues( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManTransformInitValues( Ntl_Man_t * p ); -extern ABC_DLL Vec_Vec_t * Ntl_ManTransformRegClasses( Ntl_Man_t * pMan, int nSizeMax, int fVerbose ); -extern ABC_DLL void Ntl_ManFilterRegisterClasses( Aig_Man_t * pAig, Vec_Int_t * vRegClasses, int fVerbose ); -extern ABC_DLL int Ntl_ManLatchNum( Ntl_Man_t * p ); -extern ABC_DLL int Ntl_ManIsComb( Ntl_Man_t * p ); -extern ABC_DLL int Ntl_ModelCombLeafNum( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelCombRootNum( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelSeqLeafNum( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelSeqRootNum( Ntl_Mod_t * p ); -extern ABC_DLL int Ntl_ModelCheckNetsAreNotMarked( Ntl_Mod_t * pModel ); -extern ABC_DLL void Ntl_ModelClearNets( Ntl_Mod_t * pModel ); -extern ABC_DLL void Ntl_ManRemoveUselessNets( Ntl_Man_t * p ); - - - -ABC_NAMESPACE_HEADER_END - - - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/aig/ntl/ntlCheck.c b/src/aig/ntl/ntlCheck.c deleted file mode 100644 index 7aecf878..00000000 --- a/src/aig/ntl/ntlCheck.c +++ /dev/null @@ -1,379 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlCheck.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Checks consistency of the netlist.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlCheck.c,v 1.1 2008/10/10 14:09:29 mjarvin Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "aig.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCheckCombPoPaths_rec( Ntl_Mod_t * pModel, Ntl_Net_t * pNet ) -{ - Ntl_Net_t * pFanin; - int i; - // skip visited nets - if ( pNet->nVisits == 2 ) - return 1; - pNet->nVisits = 2; - // process PIs - if ( Ntl_ObjIsPi(pNet->pDriver) ) - return 0; - // process registers - if ( Ntl_ObjIsLatch(pNet->pDriver) ) - return 1; - assert( Ntl_ObjIsNode(pNet->pDriver) ); - // call recursively - Ntl_ObjForEachFanin( pNet->pDriver, pFanin, i ) - if ( !Ntl_ModelCheckCombPoPaths_rec( pModel, pFanin ) ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Checks the existence of combinational paths from POs to PIs.] - - Description [Returns 0 if the path is found.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCheckCombPoPaths( Ntl_Mod_t * pModel ) -{ - Ntl_Obj_t * pObj; - int i; - Ntl_ModelClearNets( pModel ); - Ntl_ModelForEachPo( pModel, pObj, i ) - if ( !Ntl_ModelCheckCombPoPaths_rec( pModel, Ntl_ObjFanin0(pObj) ) ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Checks one model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCheck( Ntl_Mod_t * pModel, int fMain ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - int i, k, fStatus = 1; - - // check root level model - if ( fMain ) - { - if ( Ntl_ModelLatchNum(pModel) > 0 ) - { - printf( "Root level model %s has %d registers.\n", pModel->pName, Ntl_ModelLatchNum(pModel) ); - fStatus = 0; - } - goto checkobjs; - } - - // check delay information - if ( pModel->attrBox && pModel->attrComb ) - { - if ( pModel->vDelays == NULL ) - { - printf( "Warning: Comb model %s does not have delay info. Default 1.0 delays are assumed.\n", pModel->pName ); - pModel->vDelays = Vec_IntAlloc( 3 ); - Vec_IntPush( pModel->vDelays, -1 ); - Vec_IntPush( pModel->vDelays, -1 ); - Vec_IntPush( pModel->vDelays, Aig_Float2Int(1.0) ); - } - if ( pModel->vTimeInputs != NULL ) - { - printf( "Combinational model %s has input arrival/required time information.\n", pModel->pName ); - fStatus = 0; - } - if ( pModel->vTimeOutputs != NULL ) - { - printf( "Combinational model %s has output arrival/required time information.\n", pModel->pName ); - fStatus = 0; - } - } - if ( pModel->attrBox && !pModel->attrComb ) - { - if ( pModel->vDelays != NULL ) - { - printf( "Sequential model %s has delay info.\n", pModel->pName ); - fStatus = 0; - } - if ( pModel->vTimeInputs == NULL ) - { - printf( "Warning: Seq model %s does not have input arrival/required time info. Default 0.0 is assumed.\n", pModel->pName ); - pModel->vTimeInputs = Vec_IntAlloc( 2 ); - Vec_IntPush( pModel->vTimeInputs, -1 ); - Vec_IntPush( pModel->vTimeInputs, Aig_Float2Int(0.0) ); - } - if ( pModel->vTimeOutputs == NULL ) - { -// printf( "Warning: Seq model %s does not have output arrival/required time info. Default 0.0 is assumed.\n", pModel->pName ); - pModel->vTimeOutputs = Vec_IntAlloc( 2 ); - Vec_IntPush( pModel->vTimeOutputs, -1 ); - Vec_IntPush( pModel->vTimeOutputs, Aig_Float2Int(0.0) ); - } - } - - // check box attributes - if ( pModel->attrBox ) - { - if ( !pModel->attrWhite ) - { - if ( Ntl_ModelNodeNum(pModel) + Ntl_ModelLut1Num(pModel) > 0 ) - { - printf( "Model %s is a blackbox, yet it has %d nodes.\n", pModel->pName, Ntl_ModelNodeNum(pModel) + Ntl_ModelLut1Num(pModel) ); - fStatus = 0; - } - if ( Ntl_ModelLatchNum(pModel) > 0 ) - { - printf( "Model %s is a blackbox, yet it has %d registers.\n", pModel->pName, Ntl_ModelLatchNum(pModel) ); - fStatus = 0; - } - return fStatus; - } - // this is a white box - if ( pModel->attrComb && Ntl_ModelNodeNum(pModel) + Ntl_ModelLut1Num(pModel) == 0 ) - { - printf( "Model %s is a comb white box, yet it has no nodes.\n", pModel->pName ); - fStatus = 0; - } - if ( pModel->attrComb && Ntl_ModelLatchNum(pModel) > 0 ) - { - printf( "Model %s is a comb white box, yet it has registers.\n", pModel->pName ); - fStatus = 0; - } - if ( !pModel->attrComb && Ntl_ModelLatchNum(pModel) == 0 ) - { - printf( "Model %s is a seq white box, yet it has no registers.\n", pModel->pName ); - fStatus = 0; - } - if ( !pModel->attrComb && !Ntl_ModelCheckCombPoPaths(pModel) ) - { - printf( "Model %s is a seq white box with comb paths from PIs to POs.\n", pModel->pName ); - fStatus = 0; - } - } - -checkobjs: - // check nets - Ntl_ModelForEachNet( pModel, pNet, i ) - { - if ( pNet->pName == NULL ) - { - printf( "Net in bin %d does not have a name\n", i ); - fStatus = 0; - } -/* - if ( pNet->pDriver == NULL ) - { - printf( "Net %s does not have a driver\n", pNet->pName ); - fStatus = 0; - } -*/ - } - - // check objects - Ntl_ModelForEachObj( pModel, pObj, i ) - { - Ntl_ObjForEachFanin( pObj, pNet, k ) - if ( pNet == NULL ) - { - printf( "Object %d does not have fanin net %d\n", i, k ); - fStatus = 0; - } - Ntl_ObjForEachFanout( pObj, pNet, k ) - if ( pNet == NULL ) - { - printf( "Object %d does not have fanout net %d\n", i, k ); - fStatus = 0; - } - } - return fStatus; -} - -/**Function************************************************************* - - Synopsis [Checks the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCheck( Ntl_Man_t * pMan ) -{ - Ntl_Mod_t * pMod1; - int i, fStatus = 1; - // check that the models have unique names - Ntl_ManForEachModel( pMan, pMod1, i ) - { - if ( pMod1->pName == NULL ) - { - printf( "Model %d does not have a name\n", i ); - fStatus = 0; - } - } - // check that the models (except the first one) do not have boxes - Ntl_ManForEachModel( pMan, pMod1, i ) - { - if ( i == 0 ) - continue; - if ( Ntl_ModelBoxNum(pMod1) > 0 ) - { - printf( "Non-root model %d (%s) has %d boxes.\n", i, pMod1->pName, Ntl_ModelBoxNum(pMod1) ); - fStatus = 0; - } - } - // check models - Ntl_ManForEachModel( pMan, pMod1, i ) - { - if ( !Ntl_ModelCheck( pMod1, i==0 ) ) - fStatus = 0; - } - return fStatus; -} - - -/**Function************************************************************* - - Synopsis [Fixed problems with non-driven nets in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelFixNonDrivenNets( Ntl_Mod_t * pModel ) -{ - Vec_Ptr_t * vNets; - Ntl_Net_t * pNet; - Ntl_Obj_t * pNode; - int i; - - if ( !pModel->attrWhite ) - return; - - // check for non-driven nets - vNets = Vec_PtrAlloc( 100 ); - Ntl_ModelForEachNet( pModel, pNet, i ) - { - if ( pNet->pDriver != NULL ) - continue; - // add the constant 0 driver - pNode = Ntl_ModelCreateNode( pModel, 0 ); - pNode->pSop = Ntl_ManStoreSop( pModel->pMan->pMemSops, " 0\n" ); - Ntl_ModelSetNetDriver( pNode, pNet ); - // add the net to those for which the warning will be printed - Vec_PtrPush( vNets, pNet ); - } - -#if 0 // sjang - // print the warning - if ( Vec_PtrSize(vNets) > 0 ) - { - printf( "Warning: Constant-0 drivers added to %d non-driven nets in network \"%s\": ", Vec_PtrSize(vNets), pModel->pName ); - Vec_PtrForEachEntry( Ntl_Net_t *, vNets, pNet, i ) - { - printf( "%s%s", (i? ", ": ""), pNet->pName ); - if ( i == 3 ) - { - if ( Vec_PtrSize(vNets) > 3 ) - printf( " ..." ); - break; - } - } - printf( "\n" ); - } -#endif - Vec_PtrFree( vNets ); -} - -/**Function************************************************************* - - Synopsis [Fixed problems with non-driven nets in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelTransformLatches( Ntl_Mod_t * pModel ) -{ - Ntl_Mod_t * pMod[3] = { NULL }; - Ntl_Obj_t * pLatch; - int i, Init; - if ( Ntl_ModelLatchNum(pModel) == 0 ) - return; - Ntl_ModelForEachLatch( pModel, pLatch, i ) - { - Init = pLatch->LatchId.regInit; - if ( pMod[Init] == NULL ) - pMod[Init] = Ntl_ManCreateLatchModel( pModel->pMan, Init ); - pLatch->pImplem = pMod[Init]; - pLatch->Type = NTL_OBJ_BOX; - } - printf( "In the main model \"%s\", %d latches are transformed into white seq boxes.\n", pModel->pName, Ntl_ModelLatchNum(pModel) ); - pModel->nObjs[NTL_OBJ_BOX] += Ntl_ModelLatchNum(pModel); - pModel->nObjs[NTL_OBJ_LATCH] = 0; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlCore.c b/src/aig/ntl/ntlCore.c deleted file mode 100644 index c09bac0f..00000000 --- a/src/aig/ntl/ntlCore.c +++ /dev/null @@ -1,152 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlCore.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [DFS traversal.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlCore.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "dch.h" -#include "dar.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Extracts AIG from the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManPerformChoicing( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fConstruct, int nConfMax, int nLevelMax, int fVerbose ) -{ -// extern Aig_Man_t * Dar_ManBalance( Aig_Man_t * pAig, int fUpdateLevel ); -// extern Aig_Man_t * Dar_ManCompress( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fPower, int fVerbose ); -// extern Aig_Man_t * Dar_ManChoice( Aig_Man_t * pAig, int fBalance, int fUpdateLevel, int fConstruct, int nConfMax, int nLevelMax, int fVerbose ); - Aig_Man_t * pTemp; - - // perform synthesis -//printf( "Pre-synthesis AIG: " ); -//Aig_ManPrintStats( pAig ); -// pTemp = Dar_ManBalance( pAig, 1 ); -// pTemp = Dar_ManCompress( pAig, 1, 1, 0, 0 ); - pTemp = Dar_ManChoice( pAig, fBalance, fUpdateLevel, fConstruct, nConfMax, nLevelMax, fVerbose ); -//printf( "Post-synthesis AIG: " ); -//Aig_ManPrintStats( pTemp ); - - return pTemp; -} - -/**Function************************************************************* - - Synopsis [Extracts AIG from the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManPerformChoicingNew( Aig_Man_t * pAig, Dch_Pars_t * pPars ) -{ -// extern Aig_Man_t * Dar_ManChoiceNew( Aig_Man_t * pAig, Dch_Pars_t * pPars ); - Aig_Man_t * pTemp; -/* - Aig_Obj_t * pObj; - int i; - Aig_ManForEachPi( pAig, pObj, i ) - printf( "%d ", pObj->Level ); - printf( "\n" ); -*/ - pTemp = Dar_ManChoiceNew( pAig, pPars ); -/* - Aig_ManForEachPi( pTemp, pObj, i ) - printf( "%d ", pObj->Level ); - printf( "\n" ); -*/ - return pTemp; -} - -/**Function************************************************************* - - Synopsis [Testing procedure for insertion of mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManInsertTest( Ntl_Man_t * p, Aig_Man_t * pAig ) -{ - Ntl_Man_t * pNew; - Vec_Ptr_t * vMapping; - int RetValue; - vMapping = Ntl_MappingFromAig( pAig ); - pNew = Ntl_ManInsertMapping( p, vMapping, pAig ); - RetValue = (pNew != NULL); - Ntl_ManFree( pNew ); - Vec_PtrFree( vMapping ); - return RetValue; -} - -/**Function************************************************************* - - Synopsis [Testing procedure for insertion of mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManInsertTestIf( Ntl_Man_t * p, Aig_Man_t * pAig ) -{ - Ntl_Man_t * pNew; - Vec_Ptr_t * vMapping; - int RetValue; - vMapping = Ntl_MappingIf( p, pAig ); - pNew = Ntl_ManInsertMapping( p, vMapping, pAig ); - RetValue = (pNew != NULL); - Ntl_ManFree( pNew ); - Vec_PtrFree( vMapping ); - return RetValue; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlEc.c b/src/aig/ntl/ntlEc.c deleted file mode 100644 index 331cd906..00000000 --- a/src/aig/ntl/ntlEc.c +++ /dev/null @@ -1,370 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlEc.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Equivalence checking procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlEc.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "saig.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Adds PIs to both models, so that they have the same PIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManCreateMissingInputs( Ntl_Mod_t * p1, Ntl_Mod_t * p2, int fSeq ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNext; - int i, k; - if ( fSeq ) - { - Ntl_ModelForEachSeqLeaf( p1, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - Ntl_ModelCreatePiWithName( p2, pNext->pName ); - } - } - Ntl_ModelForEachSeqLeaf( p2, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p1, pNext->pName ); - if ( pNet == NULL ) - Ntl_ModelCreatePiWithName( p1, pNext->pName ); - } - } - } - else - { - Ntl_ModelForEachCombLeaf( p1, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - Ntl_ModelCreatePiWithName( p2, pNext->pName ); - } - } - Ntl_ModelForEachCombLeaf( p2, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p1, pNext->pName ); - if ( pNet == NULL ) - Ntl_ModelCreatePiWithName( p1, pNext->pName ); - } - } - } -} - -/**Function************************************************************* - - Synopsis [Creates arrays of combinational inputs in the same order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManDeriveCommonCis( Ntl_Man_t * pMan1, Ntl_Man_t * pMan2, int fSeq ) -{ - Ntl_Mod_t * p1 = Ntl_ManRootModel(pMan1); - Ntl_Mod_t * p2 = Ntl_ManRootModel(pMan2); - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNext; - int i, k; - // order the CIs - Vec_PtrClear( pMan1->vCis ); - Vec_PtrClear( pMan2->vCis ); - if ( fSeq ) - { - assert( Ntl_ModelSeqLeafNum(p1) == Ntl_ModelSeqLeafNum(p2) ); - Ntl_ModelForEachSeqLeaf( p1, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - { - printf( "Ntl_ManDeriveCommonCis(): Internal error!\n" ); - return; - } - Vec_PtrPush( pMan1->vCis, pNext ); - Vec_PtrPush( pMan2->vCis, pNet ); - } - } - } - else - { - assert( Ntl_ModelCombLeafNum(p1) == Ntl_ModelCombLeafNum(p2) ); - Ntl_ModelForEachCombLeaf( p1, pObj, i ) - { - Ntl_ObjForEachFanout( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - { - printf( "Ntl_ManDeriveCommonCis(): Internal error!\n" ); - return; - } - Vec_PtrPush( pMan1->vCis, pNext ); - Vec_PtrPush( pMan2->vCis, pNet ); - } - } - } -} - -/**Function************************************************************* - - Synopsis [Creates arrays of combinational outputs in the same order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManDeriveCommonCos( Ntl_Man_t * pMan1, Ntl_Man_t * pMan2, int fSeq ) -{ - Ntl_Mod_t * p1 = Ntl_ManRootModel(pMan1); - Ntl_Mod_t * p2 = Ntl_ManRootModel(pMan2); - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNext; - int i, k; - // order the COs - Vec_PtrClear( pMan1->vCos ); - Vec_PtrClear( pMan2->vCos ); - if ( fSeq ) - { - Ntl_ModelForEachSeqRoot( p1, pObj, i ) - { - Ntl_ObjForEachFanin( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - { - printf( "Ntl_ManDeriveCommonCos(): Cannot find output %s in the second design. Skipping it!\n", - pNext->pName ); - continue; - } - Vec_PtrPush( pMan1->vCos, pNext ); - Vec_PtrPush( pMan2->vCos, pNet ); - } - } - } - else - { - Ntl_ModelForEachCombRoot( p1, pObj, i ) - { - Ntl_ObjForEachFanin( pObj, pNext, k ) - { - pNet = Ntl_ModelFindNet( p2, pNext->pName ); - if ( pNet == NULL ) - { - printf( "Ntl_ManDeriveCommonCos(): Cannot find output %s in the second design. Skipping it!\n", - pNext->pName ); - continue; - } - Vec_PtrPush( pMan1->vCos, pNext ); - Vec_PtrPush( pMan2->vCos, pNet ); - } - } - } -} - -/**Function************************************************************* - - Synopsis [Prepares AIGs for combinational equivalence checking.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrepareCecMans( Ntl_Man_t * pMan1, Ntl_Man_t * pMan2, Aig_Man_t ** ppAig1, Aig_Man_t ** ppAig2 ) -{ - Ntl_Mod_t * pModel1, * pModel2; - *ppAig1 = NULL; - *ppAig2 = NULL; - // make sure they are compatible - pModel1 = Ntl_ManRootModel( pMan1 ); - pModel2 = Ntl_ManRootModel( pMan2 ); - if ( Ntl_ModelCombLeafNum(pModel1) != Ntl_ModelCombLeafNum(pModel2) ) - { - printf( "Warning: The number of inputs in the designs is different (%d and %d).\n", - Ntl_ModelCombLeafNum(pModel1), Ntl_ModelCombLeafNum(pModel2) ); - } - if ( Ntl_ModelCombRootNum(pModel1) != Ntl_ModelCombRootNum(pModel2) ) - { - printf( "Warning: The number of outputs in the designs is different (%d and %d).\n", - Ntl_ModelCombRootNum(pModel1), Ntl_ModelCombRootNum(pModel2) ); - } - // normalize inputs/outputs - Ntl_ManCreateMissingInputs( pModel1, pModel2, 0 ); - if ( Ntl_ModelCombLeafNum(pModel1) != Ntl_ModelCombLeafNum(pModel2) ) - { - printf( "Ntl_ManPrepareCec(): Cannot verify designs with too many different CIs.\n" ); - return; - } - Ntl_ManDeriveCommonCis( pMan1, pMan2, 0 ); - Ntl_ManDeriveCommonCos( pMan1, pMan2, 0 ); - if ( Vec_PtrSize(pMan1->vCos) == 0 ) - { - printf( "Ntl_ManPrepareCec(): There is no identically-named primary outputs to compare.\n" ); - return; - } - // derive AIGs - *ppAig1 = Ntl_ManCollapse( pMan1, 0 ); - *ppAig2 = Ntl_ManCollapse( pMan2, 0 ); -} - -/**Function************************************************************* - - Synopsis [Prepares AIGs for combinational equivalence checking.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrepareCec( char * pFileName1, char * pFileName2, Aig_Man_t ** ppAig1, Aig_Man_t ** ppAig2 ) -{ - Ntl_Man_t * pMan1, * pMan2; - // read the netlists - pMan1 = Ntl_ManReadBlif( pFileName1, 1 ); - pMan2 = Ntl_ManReadBlif( pFileName2, 1 ); - if ( !pMan1 || !pMan2 ) - { - if ( pMan1 ) Ntl_ManFree( pMan1 ); - if ( pMan2 ) Ntl_ManFree( pMan2 ); - printf( "Ntl_ManPrepareCec(): Reading designs from file has failed.\n" ); - return; - } - Ntl_ManPrepareCecMans( pMan1, pMan2, ppAig1, ppAig2 ); - // cleanup - Ntl_ManFree( pMan1 ); - Ntl_ManFree( pMan2 ); -} - -/**Function************************************************************* - - Synopsis [Prepares AIGs for sequential equivalence checking.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManPrepareSec( char * pFileName1, char * pFileName2 ) -{ -// extern Aig_Man_t * Saig_ManCreateMiter( Aig_Man_t * p1, Aig_Man_t * p2, int Oper ); - - Aig_Man_t * pAig1, * pAig2, * pAig; - Ntl_Man_t * pMan1, * pMan2; - Ntl_Mod_t * pModel1, * pModel2; - // read the netlists - pMan1 = Ntl_ManReadBlif( pFileName1, 1 ); - pMan2 = Ntl_ManReadBlif( pFileName2, 1 ); - if ( !pMan1 || !pMan2 ) - { - if ( pMan1 ) Ntl_ManFree( pMan1 ); - if ( pMan2 ) Ntl_ManFree( pMan2 ); - printf( "Ntl_ManPrepareSec(): Reading designs from file has failed.\n" ); - return NULL; - } - // make sure they are compatible - if ( Ntl_ManLatchNum(pMan1) == 0 || Ntl_ManLatchNum(pMan2) == 0 ) - { - if ( pMan1 ) Ntl_ManFree( pMan1 ); - if ( pMan2 ) Ntl_ManFree( pMan2 ); - printf( "Ntl_ManPrepareSec(): The designs have no latches. Use combinational command \"*cec\".\n" ); - return NULL; - } - pModel1 = Ntl_ManRootModel( pMan1 ); - pModel2 = Ntl_ManRootModel( pMan2 ); - if ( Ntl_ModelSeqLeafNum(pModel1) != Ntl_ModelSeqLeafNum(pModel2) ) - { - printf( "Warning: The number of inputs in the designs is different (%d and %d).\n", - Ntl_ModelPiNum(pModel1), Ntl_ModelPiNum(pModel2) ); - } - if ( Ntl_ModelSeqRootNum(pModel1) != Ntl_ModelSeqRootNum(pModel2) ) - { - printf( "Warning: The number of outputs in the designs is different (%d and %d).\n", - Ntl_ModelPoNum(pModel1), Ntl_ModelPoNum(pModel2) ); - } - // normalize inputs/outputs - Ntl_ManCreateMissingInputs( pModel1, pModel2, 1 ); - Ntl_ManDeriveCommonCis( pMan1, pMan2, 1 ); - Ntl_ManDeriveCommonCos( pMan1, pMan2, 1 ); - if ( Vec_PtrSize(pMan1->vCos) == 0 ) - { - printf( "Ntl_ManPrepareSec(): There is no identically-named primary outputs to compare.\n" ); - if ( pMan1 ) Ntl_ManFree( pMan1 ); - if ( pMan2 ) Ntl_ManFree( pMan2 ); - return NULL; - } - // derive AIGs - pAig1 = Ntl_ManCollapse( pMan1, 1 ); - pAig2 = Ntl_ManCollapse( pMan2, 1 ); - pAig = Saig_ManCreateMiter( pAig1, pAig2, 0 ); - Aig_ManCleanup( pAig ); - Aig_ManStop( pAig1 ); - Aig_ManStop( pAig2 ); - // cleanup - Ntl_ManFree( pMan1 ); - Ntl_ManFree( pMan2 ); - return pAig; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlExtract.c b/src/aig/ntl/ntlExtract.c deleted file mode 100644 index a6268b2c..00000000 --- a/src/aig/ntl/ntlExtract.c +++ /dev/null @@ -1,877 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlExtract.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Netlist SOP to AIG conversion.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlExtract.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "dec.h" -#include "kit.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Strashes one logic node using its SOP.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Ntl_ConvertSopToAigInternal( Aig_Man_t * pMan, Ntl_Obj_t * pNode, char * pSop ) -{ - Ntl_Net_t * pNet; - Aig_Obj_t * pAnd, * pSum; - int i, Value, nFanins; - char * pCube; - // get the number of variables - nFanins = Kit_PlaGetVarNum(pSop); - // go through the cubes of the node's SOP - pSum = Aig_ManConst0(pMan); - Kit_PlaForEachCube( pSop, nFanins, pCube ) - { - // create the AND of literals - pAnd = Aig_ManConst1(pMan); - Kit_PlaCubeForEachVar( pCube, Value, i ) - { - pNet = Ntl_ObjFanin( pNode, i ); - if ( Value == '1' ) - pAnd = Aig_And( pMan, pAnd, (Aig_Obj_t *)pNet->pCopy ); - else if ( Value == '0' ) - pAnd = Aig_And( pMan, pAnd, Aig_Not((Aig_Obj_t *)pNet->pCopy) ); - } - // add to the sum of cubes - pSum = Aig_Or( pMan, pSum, pAnd ); - } - // decide whether to complement the result - if ( Kit_PlaIsComplement(pSop) ) - pSum = Aig_Not(pSum); - return pSum; -} - -/**Function************************************************************* - - Synopsis [Transforms the decomposition graph into the AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Ntl_GraphToNetworkAig( Aig_Man_t * pMan, Dec_Graph_t * pGraph ) -{ - Dec_Node_t * pNode = NULL; // Suppress "might be used uninitialized" - Aig_Obj_t * pAnd0, * pAnd1; - int i; - // check for constant function - if ( Dec_GraphIsConst(pGraph) ) - return Aig_NotCond( Aig_ManConst1(pMan), Dec_GraphIsComplement(pGraph) ); - // check for a literal - if ( Dec_GraphIsVar(pGraph) ) - return Aig_NotCond( (Aig_Obj_t *)Dec_GraphVar(pGraph)->pFunc, Dec_GraphIsComplement(pGraph) ); - // build the AIG nodes corresponding to the AND gates of the graph - Dec_GraphForEachNode( pGraph, pNode, i ) - { - pAnd0 = Aig_NotCond( (Aig_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl ); - pAnd1 = Aig_NotCond( (Aig_Obj_t *)Dec_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl ); - pNode->pFunc = Aig_And( pMan, pAnd0, pAnd1 ); - } - // complement the result if necessary - return Aig_NotCond( (Aig_Obj_t *)pNode->pFunc, Dec_GraphIsComplement(pGraph) ); -} - -/**Function************************************************************* - - Synopsis [Converts the network from AIG to BDD representation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Ntl_ManBuildNodeAig( Ntl_Man_t * p, Ntl_Obj_t * pNode ) -{ - int fUseFactor = 1; - // consider the constant node - if ( Kit_PlaGetVarNum(pNode->pSop) == 0 ) - return Aig_NotCond( Aig_ManConst1(p->pAig), Kit_PlaIsConst0(pNode->pSop) ); - // decide when to use factoring - if ( fUseFactor && Kit_PlaGetVarNum(pNode->pSop) > 2 && Kit_PlaGetCubeNum(pNode->pSop) > 1 ) - { - Dec_Graph_t * pFForm; - Dec_Node_t * pFFNode; - Aig_Obj_t * pFunc; - int i; - // perform factoring - pFForm = Dec_Factor( pNode->pSop ); - // collect the fanins - Dec_GraphForEachLeaf( pFForm, pFFNode, i ) - pFFNode->pFunc = Ntl_ObjFanin(pNode, i)->pCopy; - // perform strashing - pFunc = Ntl_GraphToNetworkAig( p->pAig, pFForm ); - Dec_GraphFree( pFForm ); - return pFunc; - } - return Ntl_ConvertSopToAigInternal( p->pAig, pNode, pNode->pSop ); -} - -/**Function************************************************************* - - Synopsis [Collects the nodes in a topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManExtract_rec( Ntl_Man_t * p, Ntl_Net_t * pNet ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNetFanin; - int i; - // skip visited - if ( pNet->nVisits == 2 ) - return 1; - // if the node is on the path, this is a combinational loop - if ( pNet->nVisits == 1 ) - return 0; - // mark the node as the one on the path - pNet->nVisits = 1; - // derive the box - pObj = pNet->pDriver; - assert( Ntl_ObjIsNode(pObj) || Ntl_ObjIsBox(pObj) ); - // visit the input nets of the box - Ntl_ObjForEachFanin( pObj, pNetFanin, i ) - if ( !Ntl_ManExtract_rec( p, pNetFanin ) ) - return 0; - // add box inputs/outputs to COs/CIs - if ( Ntl_ObjIsBox(pObj) ) - { - int LevelCur, LevelMax = -TIM_ETERNITY; - assert( Ntl_BoxIsComb(pObj) ); - assert( Ntl_ModelLatchNum(pObj->pImplem) == 0 ); - assert( pObj->pImplem->vDelays != NULL ); - Vec_IntPush( p->vBox1Cios, Aig_ManPoNum(p->pAig) ); - Ntl_ObjForEachFanin( pObj, pNetFanin, i ) - { - LevelCur = Aig_ObjLevel( Aig_Regular((Aig_Obj_t *)pNetFanin->pCopy) ); - LevelMax = ABC_MAX( LevelMax, LevelCur ); - Vec_PtrPush( p->vCos, pNetFanin ); - Aig_ObjCreatePo( p->pAig, (Aig_Obj_t *)pNetFanin->pCopy ); - } - Ntl_ObjForEachFanout( pObj, pNetFanin, i ) - { - Vec_PtrPush( p->vCis, pNetFanin ); - pNetFanin->pCopy = Aig_ObjCreatePi( p->pAig ); - Aig_ObjSetLevel( (Aig_Obj_t *)pNetFanin->pCopy, LevelMax + 1 ); - } - } - Vec_PtrPush( p->vVisNodes, pObj ); - if ( Ntl_ObjIsNode(pObj) ) - pNet->pCopy = Ntl_ManBuildNodeAig( p, pObj ); - pNet->nVisits = 2; - return 1; -} - -/**Function************************************************************* - - Synopsis [Performs DFS.] - - Description [Checks for combinational loops. Collects PI/PO nets. - Collects nodes in the topological order.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManExtract( Ntl_Man_t * p ) -{ - Aig_Man_t * pAig; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - int i, k, nUselessObjects; - Ntl_ManCleanup( p ); - Vec_PtrClear( p->vCis ); - Vec_PtrClear( p->vCos ); - Vec_PtrClear( p->vVisNodes ); - Vec_IntClear( p->vBox1Cios ); - // start the AIG manager - assert( p->pAig == NULL ); - p->pAig = Aig_ManStart( 10000 ); - p->pAig->pName = Aig_UtilStrsav( p->pName ); - p->pAig->pSpec = Aig_UtilStrsav( p->pSpec ); - // get the root model - pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelLatchNum(pRoot) == 0 ); - // clear net visited flags - Ntl_ModelClearNets( pRoot ); - // collect mapping leafs - Ntl_ModelForEachMapLeaf( pRoot, pObj, i ) - { - assert( !Ntl_ObjIsBox(pObj) || Ntl_BoxIsBlack(pObj) || Ntl_ModelLatchNum(pObj->pImplem) > 0 ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - { - Vec_PtrPush( p->vCis, pNet ); - pNet->pCopy = Aig_ObjCreatePi( p->pAig ); - if ( pNet->nVisits ) - { - printf( "Ntl_ManExtract(): Seq leaf is duplicated or defined as a primary input.\n" ); - return 0; - } - pNet->nVisits = 2; - } - } - p->iLastCi = Aig_ManPiNum(p->pAig); - // collect mapping roots - Ntl_ModelForEachMapRoot( pRoot, pObj, i ) - { - Ntl_ObjForEachFanin( pObj, pNet, k ) - { - if ( !Ntl_ManExtract_rec( p, pNet ) ) - { - printf( "Ntl_ManExtract(): Error: Combinational loop is detected.\n" ); - return 0; - } - Vec_PtrPush( p->vCos, pNet ); - Aig_ObjCreatePo( p->pAig, (Aig_Obj_t *)pNet->pCopy ); - } - } - // visit dangling boxes - Ntl_ModelForEachBox( pRoot, pObj, i ) - { - pNet = Ntl_ObjFanout0(pObj); - if ( !Ntl_ManExtract_rec( p, pNet ) ) - { - printf( "Ntl_ManExtract(): Error: Combinational loop is detected.\n" ); - return 0; - } - } - // report the number of dangling objects - nUselessObjects = Ntl_ModelNodeNum(pRoot) + Ntl_ModelLut1Num(pRoot) + Ntl_ModelBoxNum(pRoot) - Vec_PtrSize(p->vVisNodes); -// if ( nUselessObjects ) -// printf( "The number of dangling objects = %d.\n", nUselessObjects ); - // cleanup the AIG - Aig_ManCleanup( p->pAig ); - // extract the timing manager - assert( p->pManTime == NULL ); - p->pManTime = Ntl_ManCreateTiming( p ); - // discretize timing info - p->pAig->pManTime = Tim_ManDup( p->pManTime, 1 ); - pAig = p->pAig; p->pAig = NULL; - return pAig; -} - - - - -/**Function************************************************************* - - Synopsis [Collects the nodes in a topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCollapseBoxComb_rec( Ntl_Man_t * p, Ntl_Obj_t * pBox ) -{ - extern int Ntl_ManCollapse_rec( Ntl_Man_t * p, Ntl_Net_t * pNet ); - Ntl_Mod_t * pModel = pBox->pImplem; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNetBox; - int i; - assert( Ntl_ObjFaninNum(pBox) == Ntl_ModelPiNum(pModel) ); - assert( Ntl_ObjFanoutNum(pBox) == Ntl_ModelPoNum(pModel) ); - // clear net visited flags - Ntl_ModelClearNets( pModel ); - // transfer from the box to the PIs of the model - Ntl_ModelForEachPi( pModel, pObj, i ) - { - pNet = Ntl_ObjFanout0(pObj); - pNetBox = Ntl_ObjFanin( pBox, i ); - pNet->pCopy = pNetBox->pCopy; - pNet->nVisits = 2; - } - // compute AIG for the internal nodes - Ntl_ModelForEachPo( pModel, pObj, i ) - { - pNet = Ntl_ObjFanin0(pObj); - if ( !Ntl_ManCollapse_rec( p, pNet ) ) - return 0; - pNetBox = Ntl_ObjFanout( pBox, i ); - pNetBox->pCopy = pNet->pCopy; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Collects the nodes in a topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCollapseBoxSeq1_rec( Ntl_Man_t * p, Ntl_Obj_t * pBox ) -{ - extern int Ntl_ManCollapse_rec( Ntl_Man_t * p, Ntl_Net_t * pNet ); - Ntl_Mod_t * pModel = pBox->pImplem; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNetBox; - int i; - assert( Ntl_ModelLatchNum(pModel) > 0 ); - assert( Ntl_ObjFaninNum(pBox) == Ntl_ModelPiNum(pModel) ); - assert( Ntl_ObjFanoutNum(pBox) == Ntl_ModelPoNum(pModel) ); - // clear net visited flags - Ntl_ModelClearNets( pModel ); - // initialize the registers - Ntl_ModelForEachLatch( pModel, pObj, i ) - { - pNet = Ntl_ObjFanout0(pObj); - pNet->pCopy = Aig_ObjCreatePi( p->pAig ); - if ( Ntl_ObjIsInit1( pObj ) ) - pNet->pCopy = Aig_Not((Aig_Obj_t *)pNet->pCopy); - pNet->nVisits = 2; - // remember the class of this register - Vec_IntPush( p->vRegClasses, p->pNal ? pBox->iTemp : pObj->LatchId.regClass ); - Vec_IntPush( p->vRstClasses, p->pNal ? pBox->Reset : -1 ); - } - // compute AIG for the internal nodes - Ntl_ModelForEachPo( pModel, pObj, i ) - { - pNet = Ntl_ObjFanin0(pObj); - if ( !Ntl_ManCollapse_rec( p, pNet ) ) - return 0; - pNetBox = Ntl_ObjFanout( pBox, i ); - pNetBox->pCopy = pNet->pCopy; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Collects the nodes in a topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCollapseBoxSeq2_rec( Ntl_Man_t * p, Ntl_Obj_t * pBox, int iFirstPi ) -{ - extern int Ntl_ManCollapse_rec( Ntl_Man_t * p, Ntl_Net_t * pNet ); - Ntl_Mod_t * pModel = pBox->pImplem; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet, * pNetBox; - int i; - assert( Ntl_ModelLatchNum(pModel) > 0 ); - assert( Ntl_ObjFaninNum(pBox) == Ntl_ModelPiNum(pModel) ); - assert( Ntl_ObjFanoutNum(pBox) == Ntl_ModelPoNum(pModel) ); - // clear net visited flags - Ntl_ModelClearNets( pModel ); - // transfer from the box to the PIs of the model - Ntl_ModelForEachPi( pModel, pObj, i ) - { - pNet = Ntl_ObjFanout0(pObj); - pNetBox = Ntl_ObjFanin( pBox, i ); - pNet->pCopy = pNetBox->pCopy; - pNet->nVisits = 2; - } - // initialize the registers - Ntl_ModelForEachLatch( pModel, pObj, i ) - { - pNet = Ntl_ObjFanout0(pObj); - pNet->pCopy = Aig_ManPi( p->pAig, iFirstPi++ ); - if ( Ntl_ObjIsInit1( pObj ) ) - pNet->pCopy = Aig_Not((Aig_Obj_t *)pNet->pCopy); - pNet->nVisits = 2; - } - // compute AIGs for the registers - Ntl_ModelForEachLatch( pModel, pObj, i ) - { - pNet = Ntl_ObjFanin0(pObj); - if ( !Ntl_ManCollapse_rec( p, pNet ) ) - return 0; - if ( Ntl_ObjIsInit1( pObj ) ) - Aig_ObjCreatePo( p->pAig, Aig_Not((Aig_Obj_t *)pNet->pCopy) ); - else - Aig_ObjCreatePo( p->pAig, (Aig_Obj_t *)pNet->pCopy ); - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Collects the nodes in a topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCollapse_rec( Ntl_Man_t * p, Ntl_Net_t * pNet ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNetFanin; - int i; - // skip visited - if ( pNet->nVisits == 2 ) - return 1; - // if the node is on the path, this is a combinational loop - if ( pNet->nVisits == 1 ) - return 0; - // mark the node as the one on the path - pNet->nVisits = 1; - // derive the box - pObj = pNet->pDriver; - assert( Ntl_ObjIsNode(pObj) || Ntl_ObjIsBox(pObj) ); - // visit the input nets of the box - Ntl_ObjForEachFanin( pObj, pNetFanin, i ) - if ( !Ntl_ManCollapse_rec( p, pNetFanin ) ) - return 0; - // add box inputs/outputs to COs/CIs - if ( Ntl_ObjIsBox(pObj) ) - { - assert( Ntl_BoxIsWhite(pObj) && Ntl_BoxIsComb(pObj) ); - if ( !Ntl_ManCollapseBoxComb_rec( p, pObj ) ) - return 0; - } - if ( Ntl_ObjIsNode(pObj) ) - pNet->pCopy = Ntl_ManBuildNodeAig( p, pObj ); - pNet->nVisits = 2; - return 1; -} - -/**Function************************************************************* - - Synopsis [Performs DFS.] - - Description [Checks for combinational loops. Collects PI/PO nets. - Collects nodes in the topological order.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManCollapse( Ntl_Man_t * p, int fSeq ) -{ - Aig_Man_t * pAig; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pBox; - Ntl_Net_t * pNet; - int i, k, nTruePis, nTruePos, iBox = 0; - assert( Vec_PtrSize(p->vCis) != 0 ); - assert( Vec_PtrSize(p->vCos) != 0 ); - Vec_IntClear( p->vBox1Cios ); - Vec_IntClear( p->vRegClasses ); - Vec_IntClear( p->vRstClasses ); - // clear net visited flags - pRoot = Ntl_ManRootModel(p); - assert( Ntl_ModelLatchNum(pRoot) == 0 ); - Ntl_ModelClearNets( pRoot ); - // create the manager - p->pAig = Aig_ManStart( 10000 ); - p->pAig->pName = Aig_UtilStrsav( p->pName ); - p->pAig->pSpec = Aig_UtilStrsav( p->pSpec ); - // set the inputs - Ntl_ManForEachCiNet( p, pNet, i ) - { - pNet->pCopy = Aig_ObjCreatePi( p->pAig ); - if ( pNet->nVisits ) - { - printf( "Ntl_ManCollapse(): Primary input appears twice in the list.\n" ); - return 0; - } - pNet->nVisits = 2; - } - nTruePis = Aig_ManPiNum(p->pAig); - // create inputs of seq boxes - if ( fSeq ) { - Ntl_ModelForEachBox( pRoot, pBox, i ) - { - if ( !(Ntl_BoxIsSeq(pBox) && Ntl_BoxIsWhite(pBox)) ) - continue; - Vec_IntPush( p->vBox1Cios, Aig_ManPiNum(p->pAig) ); - Ntl_ManCollapseBoxSeq1_rec( p, pBox ); - Ntl_ObjForEachFanout( pBox, pNet, k ) - pNet->nVisits = 2; - } - } - // derive the outputs - Ntl_ManForEachCoNet( p, pNet, i ) - { - if ( !Ntl_ManCollapse_rec( p, pNet ) ) - { - printf( "Ntl_ManCollapse(): Error: Combinational loop is detected.\n" ); - return 0; - } - Aig_ObjCreatePo( p->pAig, (Aig_Obj_t *)pNet->pCopy ); - } - nTruePos = Aig_ManPoNum(p->pAig); - // create outputs of seq boxes - if ( fSeq ) { - Ntl_ModelForEachBox( pRoot, pBox, i ) - { - if ( !(Ntl_BoxIsSeq(pBox) && Ntl_BoxIsWhite(pBox)) ) - continue; - Ntl_ObjForEachFanin( pBox, pNet, k ) - if ( !Ntl_ManCollapse_rec( p, pNet ) ) - { - printf( "Ntl_ManCollapse(): Error: Combinational loop is detected.\n" ); - return 0; - } - Ntl_ManCollapseBoxSeq2_rec( p, pBox, Vec_IntEntry(p->vBox1Cios, iBox++) ); - } - } - // make sure registers are added correctly - if ( Aig_ManPiNum(p->pAig) - nTruePis != Aig_ManPoNum(p->pAig) - nTruePos ) - { - printf( "Ntl_ManCollapse(): Error: Registers are created incorrectly.\n" ); - return 0; - } - // cleanup the AIG - Aig_ManSetRegNum( p->pAig, Aig_ManPiNum(p->pAig) - nTruePis ); - Aig_ManCleanup( p->pAig ); - pAig = p->pAig; p->pAig = NULL; - return pAig; -} - - -/**Function************************************************************* - - Synopsis [Collapses the netlist combinationally.] - - Description [Checks for combinational loops. Collects PI/PO nets. - Collects nodes in the topological order.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManCollapseComb( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - int i, k; - Vec_PtrClear( p->vCis ); - Vec_PtrClear( p->vCos ); - // prepare the model - pRoot = Ntl_ManRootModel(p); - // collect the leaves for this traversal - Ntl_ModelForEachCombLeaf( pRoot, pObj, i ) - Ntl_ObjForEachFanout( pObj, pNet, k ) - Vec_PtrPush( p->vCis, pNet ); - // collect the roots for this traversal - Ntl_ModelForEachCombRoot( pRoot, pObj, i ) - Ntl_ObjForEachFanin( pObj, pNet, k ) - Vec_PtrPush( p->vCos, pNet ); - // perform the traversal - return Ntl_ManCollapse( p, 0 ); -} - -/**Function************************************************************* - - Synopsis [Collapses the netlist combinationally.] - - Description [Checks for combinational loops. Collects PI/PO nets. - Collects nodes in the topological order.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManCollapseSeq( Ntl_Man_t * p, int nMinDomSize, int fVerbose ) -{ - Aig_Man_t * pAig; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - int i, k; - Vec_PtrClear( p->vCis ); - Vec_PtrClear( p->vCos ); - // prepare the model - pRoot = Ntl_ManRootModel(p); - // collect the leaves for this traversal - Ntl_ModelForEachSeqLeaf( pRoot, pObj, i ) - Ntl_ObjForEachFanout( pObj, pNet, k ) - Vec_PtrPush( p->vCis, pNet ); - // collect the roots for this traversal - Ntl_ModelForEachSeqRoot( pRoot, pObj, i ) - Ntl_ObjForEachFanin( pObj, pNet, k ) - Vec_PtrPush( p->vCos, pNet ); - // perform the traversal - pAig = Ntl_ManCollapse( p, 1 ); - // check if there are register classes - pAig->vClockDoms = Ntl_ManTransformRegClasses( p, nMinDomSize, fVerbose ); - if ( pAig->vClockDoms ) - { - if ( Vec_VecSize(pAig->vClockDoms) == 0 ) - { - printf( "Register classes are below the limit (%d). Seq synthesis is not performed.\n", nMinDomSize ); - Aig_ManStop( pAig ); - pAig = NULL; - } - else if ( fVerbose ) - printf( "Performing seq synthesis for %d register classes.\n", Vec_VecSize(pAig->vClockDoms) ); - if ( fVerbose ) - printf( "\n" ); - } - return pAig; -} - - - -/**Function************************************************************* - - Synopsis [Increments reference counter of the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Ntl_NetIncrementRefs( Ntl_Net_t * pNet ) -{ - int nRefs = (int)(long)pNet->pCopy; - pNet->pCopy = (void *)(long)(nRefs + 1); -} - -/**Function************************************************************* - - Synopsis [Extracts logic newtork out of the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Nwk_Obj_t * Ntl_ManExtractNwk_rec( Ntl_Man_t * p, Ntl_Net_t * pNet, Nwk_Man_t * pNtk, Vec_Int_t * vCover, Vec_Int_t * vMemory ) -{ - extern Hop_Obj_t * Kit_CoverToHop( Hop_Man_t * pMan, Vec_Int_t * vCover, int nVars, Vec_Int_t * vMemory ); - Ntl_Net_t * pFaninNet; - Nwk_Obj_t * pNode; - int i; - if ( pNet->fMark ) - return (Nwk_Obj_t *)pNet->pCopy2; - pNet->fMark = 1; - pNode = Nwk_ManCreateNode( pNtk, Ntl_ObjFaninNum(pNet->pDriver), (int)(long)pNet->pCopy ); - Ntl_ObjForEachFanin( pNet->pDriver, pFaninNet, i ) - { - Ntl_ManExtractNwk_rec( p, pFaninNet, pNtk, vCover, vMemory ); - Nwk_ObjAddFanin( pNode, (Nwk_Obj_t *)pFaninNet->pCopy2 ); - } - if ( Ntl_ObjFaninNum(pNet->pDriver) == 0 || Kit_PlaGetVarNum(pNet->pDriver->pSop) == 0 ) - pNode->pFunc = Hop_NotCond( Hop_ManConst1(pNtk->pManHop), Kit_PlaIsConst0(pNet->pDriver->pSop) ); - else - { - Kit_PlaToIsop( pNet->pDriver->pSop, vCover ); - pNode->pFunc = Kit_CoverToHop( pNtk->pManHop, vCover, Ntl_ObjFaninNum(pNet->pDriver), vMemory ); - if ( Kit_PlaIsComplement(pNet->pDriver->pSop) ) - pNode->pFunc = Hop_Not(pNode->pFunc); - } - return (Nwk_Obj_t *)(pNet->pCopy2 = pNode); -} - -/**Function************************************************************* - - Synopsis [Extracts logic network out of the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -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, * pNetSimple; - Ntl_Obj_t * pObj; - Aig_Obj_t * pAnd; - Vec_Int_t * vCover, * vMemory; - int i, k; - pRoot = Ntl_ManRootModel( p ); - 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 - Ntl_ModelClearNets( pRoot ); - 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_ManForEachObj( pAig, pAnd, i ) - { - if ( Aig_ObjIsPi(pAnd) ) - { - pNet = (Ntl_Net_t *)pAnd->pData; - pNet->fMark = 1; - pNet->pCopy2 = Nwk_ManCreateCi( pNtk, (int)(long)pNet->pCopy ); - } - else if ( Aig_ObjIsPo(pAnd) ) - { - pNet = (Ntl_Net_t *)pAnd->pData; - pNode = Nwk_ManCreateCo( pNtk ); - if ( (pNetSimple = Ntl_ModelFindSimpleNet( pNet )) ) - { - pNetSimple->pCopy2 = Ntl_ManExtractNwk_rec( p, pNetSimple, pNtk, vCover, vMemory ); - Nwk_ObjAddFanin( pNode, (Nwk_Obj_t *)pNetSimple->pCopy2 ); - pNode->fInvert = Kit_PlaIsInv( pNet->pDriver->pSop ); - } - else - { - pNet->pCopy2 = Ntl_ManExtractNwk_rec( p, pNet, pNtk, vCover, vMemory ); - Nwk_ObjAddFanin( pNode, (Nwk_Obj_t *)pNet->pCopy2 ); - pNode->fInvert = (Nwk_ObjFanin0(pNode)->pFunc == Hop_ManConst0(pNtk->pManHop)); // fixed on June 7, 2009 - } - } - } - Ntl_ModelClearNets( pRoot ); - 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 ); - Nwk_ManRemoveDupFanins( pNtk, 0 ); - assert( Nwk_ManCheck( pNtk ) ); - return pNtk; -} - -/**Function************************************************************* - - Synopsis [Extracts logic newtork out of the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Nwk_Man_t * Ntl_ManReadNwk( char * pFileName, Aig_Man_t * pAig, Tim_Man_t * pManTime ) -{ - Nwk_Man_t * pNtk; - Ntl_Man_t * pNtl; - Ntl_Mod_t * pRoot; - pNtl = Ntl_ManReadBlif( pFileName, 1 ); - if ( pNtl == NULL ) - { - printf( "Ntl_ManReadNwk(): Reading BLIF has failed.\n" ); - 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", - Ntl_ModelPiNum(pRoot), Aig_ManPiNum(pAig) ); - return NULL; - } - if ( Ntl_ModelPoNum(pRoot) != Aig_ManPoNum(pAig) ) - { - printf( "Ntl_ManReadNwk(): The number of primary outputs does not match (%d and %d).\n", - Ntl_ModelPoNum(pRoot), Aig_ManPoNum(pAig) ); - return NULL; - } - pNtk = Ntl_ManExtractNwk( pNtl, pAig, pManTime ); - Ntl_ManFree( pNtl ); - return pNtk; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlFraig.c b/src/aig/ntl/ntlFraig.c deleted file mode 100644 index 9470df3e..00000000 --- a/src/aig/ntl/ntlFraig.c +++ /dev/null @@ -1,1004 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlFraig.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Performing fraiging with white-boxes.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlFraig.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "fra.h" -#include "ssw.h" -#include "dch.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Remaps representatives of the equivalence classes.] - - Description [For each equivalence class, if the current representative - of the class cannot be used because its corresponding net has no-merge - attribute, find the topologically-shallowest node, which can be used - as a representative.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManUpdateNoMergeReprs( Aig_Man_t * pAig, Aig_Obj_t ** pReprs ) -{ - Aig_Obj_t ** pReprsNew = NULL; - Aig_Obj_t * pObj, * pRepres, * pRepresNew; - Ntl_Net_t * pNet, * pNetObj; - int i; - - // allocate room for the new representative - pReprsNew = ABC_ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pAig) ); - memset( pReprsNew, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pAig) ); - Aig_ManForEachObj( pAig, pObj, i ) - { - // get the old representative node - pRepres = pReprs[pObj->Id]; - if ( pRepres == NULL ) - continue; - // if this representative node is already remapped, skip it - pRepresNew = pReprsNew[ pRepres->Id ]; - if ( pRepresNew != NULL ) - continue; - // get the net of the representative node - pNet = (Ntl_Net_t *)pRepres->pData; - assert( pRepres->pData != NULL ); - if ( Ntl_ObjIsBox(pNet->pDriver) && pNet->pDriver->pImplem->attrNoMerge ) - { - // the net belongs to the no-merge box - pNetObj = (Ntl_Net_t *)pObj->pData; - if ( Ntl_ObjIsBox(pNetObj->pDriver) && pNetObj->pDriver->pImplem->attrNoMerge ) - continue; - // the object's net does not belong to the no-merge box - // pObj can be used instead of pRepres - pReprsNew[ pRepres->Id ] = pObj; - } - else - { - // otherwise, it is fine to use pRepres - pReprsNew[ pRepres->Id ] = pRepres; - } - } - // update the representatives - Aig_ManForEachObj( pAig, pObj, i ) - { - // get the representative node - pRepres = pReprs[ pObj->Id ]; - if ( pRepres == NULL ) - continue; - // if the representative has no mapping, undo the mapping of the node - pRepresNew = pReprsNew[ pRepres->Id ]; - if ( pRepresNew == NULL || pRepresNew == pObj ) - { - pReprs[ pObj->Id ] = NULL; - continue; - } - // remap the representative -// assert( pObj->Id > pRepresNew->Id ); -// pReprs[ pObj->Id ] = pRepresNew; - if ( pObj->Id > pRepresNew->Id ) - pReprs[ pObj->Id ] = pRepresNew; - else - pReprs[ pObj->Id ] = NULL; - } - ABC_FREE( pReprsNew ); -} - -/**Function************************************************************* - - Synopsis [Transfers equivalence class info from pAigCol to pAig.] - - Description [pAig points to the nodes of netlist (pNew) derived using it. - pNew points to the nodes of the collapsed AIG (pAigCol) derived using it.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t ** Ntl_ManFraigDeriveClasses( Aig_Man_t * pAig, Ntl_Man_t * pNew, Aig_Man_t * pAigCol ) -{ - Ntl_Net_t * pNet; - Aig_Obj_t ** pReprs = NULL, ** pMapBack = NULL; - Aig_Obj_t * pObj, * pObjCol, * pObjColRepr, * pCorresp; - int i; - - // remember pointers to the nets of pNew - Aig_ManForEachObj( pAig, pObj, i ) - pObj->pNext = (Aig_Obj_t *)pObj->pData; - - // map the AIG managers - Aig_ManForEachObj( pAig, pObj, i ) - { - if ( Aig_ObjIsConst1(pObj) ) - pObj->pData = Aig_ManConst1(pAigCol); - else if ( !Aig_ObjIsPo(pObj) ) - { - pNet = (Ntl_Net_t *)pObj->pData; - pObjCol = Aig_Regular((Aig_Obj_t *)pNet->pCopy); - pObj->pData = pObjCol; - } - } - - // create mapping from the collapsed manager into the original manager - // (each node in the collapsed manager may have more than one equivalent node - // in the original manager; this procedure finds the first node in the original - // manager that is equivalent to the given node in the collapsed manager) - pMapBack = ABC_ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pAigCol) ); - memset( pMapBack, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pAigCol) ); - Aig_ManForEachObj( pAig, pObj, i ) - { - if ( Aig_ObjIsPo(pObj) ) - continue; - pObjCol = (Aig_Obj_t *)pObj->pData; - if ( pObjCol == NULL ) - continue; - if ( pMapBack[pObjCol->Id] == NULL ) - pMapBack[pObjCol->Id] = pObj; - } - - // create the equivalence classes for the original manager - pReprs = ABC_ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pAig) ); - memset( pReprs, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pAig) ); - Aig_ManForEachObj( pAig, pObj, i ) - { - if ( Aig_ObjIsPo(pObj) ) - continue; - // get the collapsed node - pObjCol = (Aig_Obj_t *)pObj->pData; - if ( pObjCol == NULL ) - continue; - // get the representative of the collapsed node - pObjColRepr = pAigCol->pReprs[pObjCol->Id]; - if ( pObjColRepr == NULL ) - pObjColRepr = pObjCol; - // get the corresponding original node - pCorresp = pMapBack[pObjColRepr->Id]; - if ( pCorresp == NULL || pCorresp == pObj ) - continue; - // set the representative - if ( pCorresp->Id < pObj->Id ) - pReprs[pObj->Id] = pCorresp; - else - pReprs[pCorresp->Id] = pObj; - } - ABC_FREE( pMapBack ); - - // recall pointers to the nets of pNew - Aig_ManForEachObj( pAig, pObj, i ) - pObj->pData = pObj->pNext, pObj->pNext = NULL; - - // remap no-merge representatives to point to - // the shallowest nodes in the class without no-merge - Ntl_ManUpdateNoMergeReprs( pAig, pReprs ); - return pReprs; -} - -/**Function************************************************************* - - Synopsis [Uses equivalences in the AIG to reduce the design.] - - Description [The AIG (pAig) was extracted from the netlist and still - points to it (pObj->pData is the pointer to the nets in the netlist). - Equivalences have been computed for the collapsed AIG and transfered - to this AIG (pAig). This procedure reduces the corresponding nets.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManReduce( Ntl_Man_t * p, Aig_Man_t * pAig ) -{ - Aig_Obj_t * pObj, * pObjRepr; - Ntl_Net_t * pNet, * pNetRepr, * pNetNew; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode, * pNodeOld; - int i, fCompl, Counter = 0; - char * pNameNew; -// int Lenght; - assert( pAig->pReprs ); - pRoot = Ntl_ManRootModel( p ); - Aig_ManForEachObj( pAig, pObj, i ) - { - pObjRepr = Aig_ObjRepr( pAig, pObj ); - if ( pObjRepr == NULL ) - continue; - assert( pObj != pObjRepr ); - pNet = (Ntl_Net_t *)pObj->pData; - pNetRepr = (Ntl_Net_t *)pObjRepr->pData; - // consider special cases, when the net should not be reduced - if ( Ntl_ObjIsBox(pNet->pDriver) ) - { - // do not reduce the net if it is driven by a multi-output box - if ( Ntl_ObjFanoutNum(pNet->pDriver) > 1 ) - continue; - // do not reduce the net if it has no-merge attribute - if ( pNet->pDriver->pImplem->attrNoMerge ) - continue; - // do not reduce the net if the replacement net has no-merge attribute - if ( pNetRepr != NULL && Ntl_ObjIsBox(pNetRepr->pDriver) && - pNetRepr->pDriver->pImplem->attrNoMerge ) - continue; - } - if ( pNetRepr == NULL ) - { - // this is the constant node - assert( Aig_ObjIsConst1(pObjRepr) ); - pNode = Ntl_ModelCreateNode( pRoot, 0 ); - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, " 1\n" ); - if ( (pNetRepr = Ntl_ModelFindNet( pRoot, "Const1" )) ) - { - printf( "Ntl_ManReduce(): Internal error: Intermediate net name is not unique.\n" ); - return; - } - pNetRepr = Ntl_ModelFindOrCreateNet( pRoot, "Const1" ); - if ( !Ntl_ModelSetNetDriver( pNode, pNetRepr ) ) - { - printf( "Ntl_ManReduce(): Internal error: Net has more than one fanin.\n" ); - return; - } - pObjRepr->pData = pNetRepr; - pNetRepr->pCopy = Aig_ManConst1(pAig); - } - // get the complemented attributes of the nets - fCompl = Aig_IsComplement((Aig_Obj_t *)pNet->pCopy) ^ Aig_Regular((Aig_Obj_t *)pNet->pCopy)->fPhase ^ - Aig_IsComplement((Aig_Obj_t *)pNetRepr->pCopy) ^ Aig_Regular((Aig_Obj_t *)pNetRepr->pCopy)->fPhase; - // create interter/buffer driven by the representative net - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = fCompl? Ntl_ManStoreSop( p->pMemSops, "0 1\n" ) : Ntl_ManStoreSop( p->pMemSops, "1 1\n" ); - Ntl_ObjSetFanin( pNode, pNetRepr, 0 ); - // make the new node drive the equivalent net (pNet) - pNodeOld = pNet->pDriver; - if ( !Ntl_ModelClearNetDriver( pNet->pDriver, pNet ) ) - printf( "Ntl_ManReduce(): Internal error! Net already has no driver.\n" ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - printf( "Ntl_ManReduce(): Internal error! Net already has a driver.\n" ); -/* - // remove this net from the hash table (but do not remove from the array) - Ntl_ModelDeleteNet( pRoot, pNet ); - // create new net with the same name - pNetNew = Ntl_ModelFindOrCreateNet( pRoot, pNet->pName ); - // clean the name - pNet->pName[0] = 0; -*/ - // create new net with a new name - pNameNew = Ntl_ModelCreateNetName( pRoot, "noname", (int)(ABC_PTRINT_T)pNet ); - pNetNew = Ntl_ModelFindOrCreateNet( pRoot, pNameNew ); - - // make the old node drive the new net without fanouts - if ( !Ntl_ModelSetNetDriver( pNodeOld, pNetNew ) ) - printf( "Ntl_ManReduce(): Internal error! Net already has a driver.\n" ); - - Counter++; - } -// printf( "Nets without names = %d.\n", Counter ); -} - -/**Function************************************************************* - - Synopsis [Resets complemented attributes of the collapsed AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManResetComplemented( Ntl_Man_t * p, Aig_Man_t * pAigCol ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Aig_Obj_t * pObjCol; - int i; - pRoot = Ntl_ManRootModel(p); - Ntl_ModelForEachLatch( pRoot, pObj, i ) - { - if ( Ntl_ObjIsInit1( pObj ) ) - { - pObjCol = (Aig_Obj_t *)Ntl_ObjFanout0(pObj)->pCopy; - assert( pObjCol->fPhase == 0 ); - pObjCol->fPhase = 1; - } - } -} - -/**Function************************************************************* - - Synopsis [Finalizes the transformation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManFinalize( Ntl_Man_t * pNew, Aig_Man_t * pAig, Aig_Man_t * pAigCol, int fVerbose ) -{ - int fUseExtraSweep = 1; - Ntl_Man_t * pSwept; - Aig_Man_t * pTemp; - assert( pAig->pReprs == NULL ); - assert( pAigCol->pReprs != NULL ); - - // transfer equivalence classes to the original AIG - pAig->pReprs = Ntl_ManFraigDeriveClasses( pAig, pNew, pAigCol ); - pAig->nReprsAlloc = Aig_ManObjNumMax(pAig); -if ( fVerbose ) - printf( "Equivalences: Collapsed = %5d. Extracted = %5d.\n", Aig_ManCountReprs(pAigCol), Aig_ManCountReprs(pAig) ); -/* -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( pAig, pObj, i ) - if ( pAig->pReprs[i] != NULL ) - printf( "%s%d->%s%d ", - (Aig_ObjIsPi(pObj)? "pi": ""), - pObj->Id, - (Aig_ObjIsPi(pAig->pReprs[i])? "pi": ""), - pAig->pReprs[i]->Id ); - printf( "\n" ); -} -*/ - // implement equivalence classes and remove dangling nodes - Ntl_ManReduce( pNew, pAig ); - Ntl_ManSweep( pNew, fVerbose ); - - // perform one more sweep - if ( fUseExtraSweep ) - { - pTemp = Ntl_ManExtract( pNew ); - pSwept = Ntl_ManInsertAig( pNew, pTemp ); - Aig_ManStop( pTemp ); - Ntl_ManSweep( pSwept, fVerbose ); - return pSwept; - } - return Ntl_ManDup(pNew); -} - -/**Function************************************************************* - - Synopsis [Returns AIG with WB after fraiging.] - - Description [Consumes the input NTL to save memory.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManFraig( Ntl_Man_t * p, int nPartSize, int nConfLimit, int nLevelMax, int fUseCSat, int fVerbose ) -{ - Ntl_Man_t * pNew, * pAux; - Aig_Man_t * pAig, * pAigCol, * pTemp; - - if ( Ntl_ModelNodeNum(Ntl_ManRootModel(p)) == 0 ) - return p; - - // collapse the AIG - pAig = Ntl_ManExtract( p ); - pNew = Ntl_ManInsertAig( p, pAig ); - Ntl_ManFree( p ); - pAigCol = Ntl_ManCollapseComb( pNew ); - if ( pAigCol == NULL ) - { - Aig_ManStop( pAig ); - return pNew; - } - - // perform fraiging for the given design - if ( fUseCSat ) - { -// extern Aig_Man_t * Cec_FraigCombinational( Aig_Man_t * pAig, int nConfs, int fVerbose ); -// pTemp = Cec_FraigCombinational( pAigCol, nConfLimit, fVerbose ); -// Aig_ManStop( pTemp ); - extern void Dch_ComputeEquivalences( Aig_Man_t * pAig, Dch_Pars_t * pPars ); - Dch_Pars_t Pars, * pPars = &Pars; - Dch_ManSetDefaultParams( pPars ); - pPars->nBTLimit = nConfLimit; - pPars->fVerbose = fVerbose; - Dch_ComputeEquivalences( pAigCol, pPars ); - } - else - { - nPartSize = nPartSize? nPartSize : Aig_ManPoNum(pAigCol); - pTemp = Aig_ManFraigPartitioned( pAigCol, nPartSize, nConfLimit, nLevelMax, fVerbose ); - Aig_ManStop( pTemp ); - } - - // finalize the transformation - pNew = Ntl_ManFinalize( pAux = pNew, pAig, pAigCol, fVerbose ); - Ntl_ManFree( pAux ); - Aig_ManStop( pAig ); - Aig_ManStop( pAigCol ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Counts the number of resets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManAigCountResets( Ntl_Man_t * pNtl ) -{ -/* - Ntl_Mod_t * pModel = Ntl_ManRootModel(pNtl); - Ntl_Obj_t * pBox; - int i, Counter = -1; - Ntl_ModelForEachObj( pModel, pBox, i ) - Counter = ABC_MAX( Counter, pBox->Reset ); - return Counter + 1; -*/ - return -1; -} - -/**Function************************************************************* - - Synopsis [Transforms sequential AIG to allow for async reset.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Ntl_ManAigToRst( Ntl_Man_t * pNtl, Aig_Man_t * p ) -{ - Ntl_Mod_t * pModel = Ntl_ManRootModel(pNtl); - Aig_Man_t * pNew; - Aig_Obj_t * pObj; - int i, iRegNum, iRstNum, Counter = 0; - int nResets = Ntl_ManAigCountResets( pNtl ); - assert( pNtl->pNal != NULL ); - assert( Aig_ManRegNum(p) > 0 ); - assert( Vec_IntSize(pNtl->vRstClasses) == Aig_ManRegNum(p) ); -//printf( "Number of resets before synthesis = %d.\n", nResets ); - // create the PIs - Aig_ManCleanData( p ); - Aig_ManSetPioNumbers( p ); - // create the new manager - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - pNew->pSpec = Aig_UtilStrsav( p->pSpec ); - // create special PIs - for ( i = 0; i < nResets; i++ ) - Aig_ObjCreatePi( pNew ); - // duplicate internal nodes - Aig_ManForEachPi( p, pObj, i ) - pObj->pData = Aig_ObjCreatePi( pNew ); - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjIsNode(pObj) ) - pObj->pData = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - else if ( Aig_ObjIsPo(pObj) ) - pObj->pData = Aig_ObjCreatePo( pNew, Aig_ObjChild0Copy(pObj) ); - else if ( Aig_ObjIsPi(pObj) ) - { -// pObj->pData = Aig_ObjCreatePi( pNew ); - iRegNum = Aig_ObjPioNum(pObj) - (Aig_ManPiNum(p) - Aig_ManRegNum(p)); - if ( iRegNum < 0 ) - continue; - iRstNum = Vec_IntEntry(pNtl->vRstClasses, iRegNum); - if ( iRstNum < 0 ) - continue; - assert( iRstNum < nResets ); - pObj->pData = Aig_And( pNew, (Aig_Obj_t *)pObj->pData, Aig_ManPi(pNew, iRstNum) ); // could be NOT(pi) - Counter++; - } - else if ( Aig_ObjIsConst1(pObj) ) - pObj->pData = Aig_ManConst1(pNew); - else - assert( 0 ); - } - assert( Aig_ManNodeNum(p) + Counter == Aig_ManNodeNum(pNew) ); - if ( (Counter = Aig_ManCleanup( pNew )) ) - printf( "Aig_ManDupOrdered(): Cleanup after AIG duplication removed %d nodes.\n", Counter ); - Aig_ManSetRegNum( pNew, Aig_ManRegNum(p) ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Remaps equivalence classes from the new nodes to the old ones.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManRemapClassesLcorr( Ntl_Man_t * pNtl, Aig_Man_t * p, Aig_Man_t * pNew ) -{ - Ntl_Mod_t * pModel = Ntl_ManRootModel(pNtl); - Aig_Obj_t * pObj, * pObjRepr, * pObjNew, * pObjNewRepr; - int i, nResets = Ntl_ManAigCountResets( pNtl ); - int nTruePis = Aig_ManPiNum(p) - Aig_ManRegNum(p); - assert( pNew->pReprs != NULL ); - assert( nResets == Aig_ManPiNum(pNew) - Aig_ManPiNum(p) ); - Aig_ManReprStart( p, Aig_ManObjNumMax(p) ); - Aig_ManForEachLoSeq( pNew, pObjNew, i ) - { - pObj = Aig_ManPi( p, i - nResets ); - pObjNewRepr = pNew->pReprs[pObjNew->Id]; - if ( pObjNewRepr == NULL ) - continue; - if ( pObjNewRepr == Aig_ManConst1(pNew) ) - { - Aig_ObjCreateRepr( p, Aig_ManConst1(p), pObj ); - continue; - } - assert( Aig_ObjIsPi(pObjNewRepr) ); - // find the corresponding representative node - pObjRepr = Aig_ManPi( p, Aig_ObjPioNum(pObjNewRepr) - nResets ); - // if they belong to different domains, quit - if ( Vec_IntEntry( pNtl->vRstClasses, Aig_ObjPioNum(pObj) - nTruePis ) != - Vec_IntEntry( pNtl->vRstClasses, Aig_ObjPioNum(pObjRepr) - nTruePis ) ) - continue; - Aig_ObjCreateRepr( p, pObjRepr, pObj ); - } -} - -/**Function************************************************************* - - Synopsis [Remaps equivalence classes from the new nodes to the old ones.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManRemapClassesScorr( Ntl_Man_t * pNtl, Aig_Man_t * p, Aig_Man_t * pNew ) -{ - Aig_Obj_t * pObj, * pObjRepr, * pObjNew, * pObjNewRepr; - int i; - // map things back - Aig_ManForEachObj( p, pObj, i ) - { - pObjNew = (Aig_Obj_t *)pObj->pData; - assert( pObjNew != NULL && !Aig_IsComplement(pObjNew) ); - pObjNew->pData = pObj; - } - // remap the classes - Aig_ManForEachObj( pNew, pObjNew, i ) - { - pObjNewRepr = pNew->pReprs[pObjNew->Id]; - if ( pObjNewRepr == NULL ) - continue; - pObj = (Aig_Obj_t *)pObjNew->pData; - pObjRepr = (Aig_Obj_t *)pObjNewRepr->pData; - assert( Aig_ObjId(pObjRepr) < Aig_ObjId(pObj) ); - Aig_ObjCreateRepr( p, pObjRepr, pObj ); - } -} - - -/**Function************************************************************* - - Synopsis [Performs sequential cleanup.] - - Description [Consumes the input NTL to save memory.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManScl( Ntl_Man_t * p, int fLatchConst, int fLatchEqual, int fVerbose ) -{ - Ntl_Man_t * pNew, * pAux; - Aig_Man_t * pAig, * pAigCol, * pTemp; - - // collapse the AIG - pAig = Ntl_ManExtract( p ); -//Ntl_ManPrintStats( p ); -//Aig_ManPrintStats( pAig ); - pNew = Ntl_ManInsertAig( p, pAig ); - Ntl_ManFree( p ); - pAigCol = Ntl_ManCollapseSeq( pNew, 0, fVerbose ); - if ( pAigCol == NULL ) - { - Aig_ManStop( pAig ); - return pNew; - } -//Ntl_ManPrintStats( pNew ); -//Aig_ManPrintStats( pAigCol ); - - // perform SCL - if ( pNew->pNal ) - { - Aig_Man_t * pAigRst; - pAigRst = Ntl_ManAigToRst( pNew, pAigCol ); - pTemp = Aig_ManScl( pAigRst, fLatchConst, fLatchEqual, 0, -1, -1, fVerbose, 0 ); - Aig_ManStop( pTemp ); - Ntl_ManRemapClassesLcorr( pNew, pAigCol, pAigRst ); - Aig_ManStop( pAigRst ); - } - else - { - pTemp = Aig_ManScl( pAigCol, fLatchConst, fLatchEqual, 0, -1, -1, fVerbose, 0 ); - Aig_ManStop( pTemp ); - } - - // finalize the transformation - pNew = Ntl_ManFinalize( pAux = pNew, pAig, pAigCol, fVerbose ); - Ntl_ManFree( pAux ); - Aig_ManStop( pAig ); - Aig_ManStop( pAigCol ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Returns AIG with WB after fraiging.] - - Description [Consumes the input NTL to save memory.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManLcorr( Ntl_Man_t * p, int nConfMax, int fScorrGia, int fUseCSat, int fVerbose ) -{ - Ntl_Man_t * pNew, * pAux; - Aig_Man_t * pAig, * pAigCol, * pTemp; - Ssw_Pars_t Pars, * pPars = &Pars; - Ssw_ManSetDefaultParamsLcorr( pPars ); - pPars->nBTLimit = nConfMax; - pPars->fVerbose = fVerbose; - - // collapse the AIG - pAig = Ntl_ManExtract( p ); - pNew = Ntl_ManInsertAig( p, pAig ); - Ntl_ManFree( p ); - pAigCol = Ntl_ManCollapseSeq( pNew, pPars->nMinDomSize, pPars->fVerbose ); - if ( pAigCol == NULL ) - { - Aig_ManStop( pAig ); - return pNew; - } - - // perform LCORR - pPars->fScorrGia = fScorrGia; - pPars->fUseCSat = fUseCSat; - if ( pNew->pNal ) - { - Aig_Man_t * pAigRst; - pAigRst = Ntl_ManAigToRst( pNew, pAigCol ); - pTemp = Ssw_LatchCorrespondence( pAigRst, pPars ); - Aig_ManStop( pTemp ); - Ntl_ManRemapClassesLcorr( pNew, pAigCol, pAigRst ); - Aig_ManStop( pAigRst ); - } - else - { - pTemp = Ssw_LatchCorrespondence( pAigCol, pPars ); - Aig_ManStop( pTemp ); - } - - // finalize the transformation - pNew = Ntl_ManFinalize( pAux = pNew, pAig, pAigCol, fVerbose ); - Ntl_ManFree( pAux ); - Aig_ManStop( pAig ); - Aig_ManStop( pAigCol ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Returns AIG with WB after fraiging.] - - Description [Consumes the input NTL to save memory.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManSsw( Ntl_Man_t * p, Fra_Ssw_t * pPars ) -{ - Ntl_Man_t * pNew, * pAux; - Aig_Man_t * pAig, * pAigCol, * pTemp; - assert( 0 ); // not updated for nal - - // collapse the AIG - pAig = Ntl_ManExtract( p ); - pNew = Ntl_ManInsertAig( p, pAig ); - Ntl_ManFree( p ); - pAigCol = Ntl_ManCollapseSeq( pNew, pPars->nMinDomSize, pPars->fVerbose ); - if ( pAigCol == NULL ) - { - Aig_ManStop( pAig ); - return pNew; - } - - // perform SCL for the given design - pTemp = Fra_FraigInduction( pAigCol, pPars ); - Aig_ManStop( pTemp ); - - // finalize the transformation - pNew = Ntl_ManFinalize( pAux = pNew, pAig, pAigCol, pPars->fVerbose ); - Ntl_ManFree( pAux ); - Aig_ManStop( pAig ); - Aig_ManStop( pAigCol ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Returns AIG with WB after fraiging.] - - Description [Consumes the input NTL to save memory.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManScorr( Ntl_Man_t * p, Ssw_Pars_t * pPars ) -{ - Ntl_Man_t * pNew, * pAux; - Aig_Man_t * pAig, * pAigCol, * pTemp; - - // collapse the AIG - pAig = Ntl_ManExtract( p ); - pNew = Ntl_ManInsertAig( p, pAig ); - Ntl_ManFree( p ); - pAigCol = Ntl_ManCollapseSeq( pNew, pPars->nMinDomSize, pPars->fVerbose ); - if ( pAigCol == NULL ) - { - Aig_ManStop( pAig ); - return pNew; - } - - // perform SCL - if ( pNew->pNal ) - { - Aig_Man_t * pAigRst; - pAigRst = Ntl_ManAigToRst( pNew, pAigCol ); - pTemp = Ssw_SignalCorrespondence( pAigRst, pPars ); - Aig_ManStop( pTemp ); - Ntl_ManRemapClassesLcorr( pNew, pAigCol, pAigRst ); - Aig_ManStop( pAigRst ); - } - else - { - pPars->fVerbose = 1; - - pTemp = Ssw_SignalCorrespondence( pAigCol, pPars ); - Aig_ManStop( pTemp ); - } - - // finalize the transformation - pNew = Ntl_ManFinalize( pAux = pNew, pAig, pAigCol, pPars->fVerbose ); - Ntl_ManFree( pAux ); - Aig_ManStop( pAig ); - Aig_ManStop( pAigCol ); - return pNew; -} - - -/**Function************************************************************* - - Synopsis [Transfers the copy field into the second copy field.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManTransferCopy( Ntl_Man_t * p ) -{ - Ntl_Net_t * pNet; - Ntl_Mod_t * pRoot; - int i; - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachNet( pRoot, pNet, i ) - { - pNet->pCopy2 = pNet->pCopy; - pNet->pCopy = NULL; - } -} - -/**Function************************************************************* - - Synopsis [Reattaches one white-box.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManAttachWhiteBox( Ntl_Man_t * p, Aig_Man_t * pAigCol, Aig_Man_t * pAigRed, Ntl_Man_t * pNew, Ntl_Obj_t * pBox ) -{ -} - -/**Function************************************************************* - - Synopsis [Reattaches white-boxes after reducing the netlist.] - - Description [The following parameters are given: - Original netlist (p) whose nets point to the nodes of collapsed AIG. - Collapsed AIG (pAigCol) whose objects point to those of reduced AIG. - Reduced AIG (pAigRed) whose objects point to the nets of the new netlist. - The new netlist is changed by this procedure to have those white-boxes - from the original AIG (p) those outputs are preserved after reduction. - Note that if outputs are preserved, the inputs are also preserved.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManAttachWhiteBoxes( Ntl_Man_t * p, Aig_Man_t * pAigCol, Aig_Man_t * pAigRed, Ntl_Man_t * pNew, int fVerbose ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pBox; - Ntl_Net_t * pNet; - int i, k, Counter = 0; - // go through the white-boxes and check if they are preserved - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachBox( pRoot, pBox, i ) - { - Ntl_ObjForEachFanout( pBox, pNet, k ) - { - // skip dangling outputs of the box - if ( pNet->pCopy == NULL ) - continue; - // skip the outputs that are not preserved after merging equivalence - if ( Aig_Regular((Aig_Obj_t *)pNet->pCopy2)->pData == NULL ) - continue; - break; - } - if ( k == Ntl_ObjFanoutNum(pBox) ) - continue; - // the box is preserved - Ntl_ManAttachWhiteBox( p, pAigCol, pAigRed, pNew, pBox ); - Counter++; - } - if ( fVerbose ) - printf( "Attached %d boxed (out of %d).\n", Counter, Ntl_ModelBoxNum(pRoot) ); -} - -/**Function************************************************************* - - Synopsis [Flip complemented edges.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManFlipEdges( Ntl_Man_t * p, Aig_Man_t * pAigCol ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Aig_Obj_t * pObjCol, * pFanin; - int i, iLatch; - pRoot = Ntl_ManRootModel(p); - iLatch = 0; - Ntl_ModelForEachLatch( pRoot, pObj, i ) - { - if ( Ntl_ObjIsInit1( pObj ) ) - { - pObjCol = Aig_ManPi( pAigCol, Ntl_ModelPiNum(pRoot) + iLatch ); - assert( pObjCol->fMarkA == 0 ); - pObjCol->fMarkA = 1; - } - iLatch++; - } - // flip pointers to the complemented edges - Aig_ManForEachObj( pAigCol, pObjCol, i ) - { - pFanin = Aig_ObjFanin0(pObjCol); - if ( pFanin && pFanin->fMarkA ) - pObjCol->pFanin0 = Aig_Not(pObjCol->pFanin0); - pFanin = Aig_ObjFanin1(pObjCol); - if ( pFanin && pFanin->fMarkA ) - pObjCol->pFanin1 = Aig_Not(pObjCol->pFanin1); - } - // flip complemented latch derivers and undo the marks - iLatch = 0; - Ntl_ModelForEachLatch( pRoot, pObj, i ) - { - if ( Ntl_ObjIsInit1( pObj ) ) - { - // flip the latch input - pObjCol = Aig_ManPo( pAigCol, Ntl_ModelPoNum(pRoot) + iLatch ); - pObjCol->pFanin0 = Aig_Not(pObjCol->pFanin0); - // unmark the latch output - pObjCol = Aig_ManPi( pAigCol, Ntl_ModelPiNum(pRoot) + iLatch ); - assert( pObjCol->fMarkA == 1 ); - pObjCol->fMarkA = 0; - } - iLatch++; - } -} - -/**Function************************************************************* - - Synopsis [Returns AIG with WB after sequential SAT sweeping.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManSsw2( Ntl_Man_t * p, Fra_Ssw_t * pPars ) -{ - Ntl_Man_t * pNew; - Aig_Man_t * pAigRed, * pAigCol; - // collapse the AIG - pAigCol = Ntl_ManCollapseSeq( p, pPars->nMinDomSize, pPars->fVerbose ); - // transform the collapsed AIG - pAigRed = Fra_FraigInduction( pAigCol, pPars ); - Aig_ManStop( pAigRed ); - pAigRed = Aig_ManDupReprBasic( pAigCol ); - // insert the result back - Ntl_ManFlipEdges( p, pAigRed ); - Ntl_ManTransferCopy( p ); - pNew = Ntl_ManInsertAig( p, pAigRed ); - // attach the white-boxes - Ntl_ManAttachWhiteBoxes( p, pAigCol, pAigRed, pNew, pPars->fVerbose ); - Ntl_ManSweep( pNew, pPars->fVerbose ); - // cleanup - Aig_ManStop( pAigRed ); - Aig_ManStop( pAigCol ); - return pNew; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlInsert.c b/src/aig/ntl/ntlInsert.c deleted file mode 100644 index 8b0e3493..00000000 --- a/src/aig/ntl/ntlInsert.c +++ /dev/null @@ -1,614 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlInsert.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Procedures to insert mapping into a design.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlInsert.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "kit.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Inserts the given mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManInsertMapping( Ntl_Man_t * p, Vec_Ptr_t * vMapping, Aig_Man_t * pAig ) -{ - char Buffer[1000]; - Vec_Ptr_t * vCopies; - Vec_Int_t * vCover; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet, * pNetCo; - Ntl_Lut_t * pLut; - int i, k, nDigits; - assert( Vec_PtrSize(p->vCis) == Aig_ManPiNum(pAig) ); - assert( Vec_PtrSize(p->vCos) == Aig_ManPoNum(pAig) ); - p = Ntl_ManStartFrom( p ); - pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelNodeNum(pRoot) == 0 ); - // map the AIG back onto the design - Ntl_ManForEachCiNet( p, pNet, i ) - pNet->pCopy = Aig_ManPi( pAig, i ); - // start mapping of AIG nodes into their copies - vCopies = Vec_PtrStart( Aig_ManObjNumMax(pAig) ); - Ntl_ManForEachCiNet( p, pNet, i ) - Vec_PtrWriteEntry( vCopies, ((Aig_Obj_t *)pNet->pCopy)->Id, pNet ); - // create a new node for each LUT - vCover = Vec_IntAlloc( 1 << 16 ); - nDigits = Aig_Base10Log( Vec_PtrSize(vMapping) ); - Vec_PtrForEachEntry( Ntl_Lut_t *, vMapping, pLut, i ) - { - pNode = Ntl_ModelCreateNode( pRoot, pLut->nFanins ); - pNode->pSop = Kit_PlaFromTruth( p->pMemSops, pLut->pTruth, pLut->nFanins, vCover ); - if ( !Kit_TruthIsConst0(pLut->pTruth, pLut->nFanins) && !Kit_TruthIsConst1(pLut->pTruth, pLut->nFanins) ) - { - for ( k = 0; k < pLut->nFanins; k++ ) - { - pNet = (Ntl_Net_t *)Vec_PtrEntry( vCopies, pLut->pFanins[k] ); - if ( pNet == NULL ) - { - printf( "Ntl_ManInsert(): Internal error: Net not found.\n" ); - return 0; - } - Ntl_ObjSetFanin( pNode, pNet, k ); - } - } - else - pNode->nFanins = 0; - sprintf( Buffer, "lut%0*d", nDigits, i ); - if ( (pNet = Ntl_ModelFindNet( pRoot, Buffer )) ) - { - printf( "Ntl_ManInsert(): Internal error: Intermediate net name is not unique.\n" ); - return 0; - } - pNet = Ntl_ModelFindOrCreateNet( pRoot, Buffer ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsert(): Internal error: Net has more than one fanin.\n" ); - return 0; - } - Vec_PtrWriteEntry( vCopies, pLut->Id, pNet ); - } - Vec_IntFree( vCover ); - // mark CIs and outputs of the registers - Ntl_ManForEachCiNet( p, pNetCo, i ) - pNetCo->fMark = 1; - // update the CO pointers - Ntl_ManForEachCoNet( p, pNetCo, i ) - { - if ( pNetCo->fMark ) - continue; - pNetCo->fMark = 1; - pNet = (Ntl_Net_t *)Vec_PtrEntry( vCopies, Aig_Regular((Aig_Obj_t *)pNetCo->pCopy)->Id ); - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = Aig_IsComplement((Aig_Obj_t *)pNetCo->pCopy)? Ntl_ManStoreSop( p->pMemSops, "0 1\n" ) : Ntl_ManStoreSop( p->pMemSops, "1 1\n" ); - Ntl_ObjSetFanin( pNode, pNet, 0 ); - // update the CO driver net - assert( pNetCo->pDriver == NULL ); - if ( !Ntl_ModelSetNetDriver( pNode, pNetCo ) ) - { - printf( "Ntl_ManInsert(): Internal error: PO net has more than one fanin.\n" ); - return 0; - } - } - Vec_PtrFree( vCopies ); - // clean CI/CO marks - Ntl_ManUnmarkCiCoNets( p ); - if ( !Ntl_ManCheck( p ) ) - printf( "Ntl_ManInsertNtk: The check has failed for design %s.\n", p->pName ); - return p; -} - -/**Function************************************************************* - - Synopsis [Inserts the given mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManInsertAig( Ntl_Man_t * p, Aig_Man_t * pAig ) -{ - char Buffer[1000]; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet, * pNetCo; - Aig_Obj_t * pObj, * pFanin; - int i, nDigits, Counter; - assert( Vec_PtrSize(p->vCis) == Aig_ManPiNum(pAig) ); - assert( Vec_PtrSize(p->vCos) == Aig_ManPoNum(pAig) ); - p = Ntl_ManStartFrom( p ); - pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelNodeNum(pRoot) == 0 ); - // set the correspondence between the PI/PO nodes - Aig_ManCleanData( pAig ); - Ntl_ManForEachCiNet( p, pNet, i ) - Aig_ManPi( pAig, i )->pData = pNet; - // create constant node if needed - if ( Aig_ManConst1(pAig)->nRefs > 0 ) - { - pNode = Ntl_ModelCreateNode( pRoot, 0 ); - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, " 1\n" ); - if ( (pNet = Ntl_ModelFindNet( pRoot, "Const1" )) ) - { - printf( "Ntl_ManInsertAig(): Internal error: Intermediate net name is not unique.\n" ); - return 0; - } - pNet = Ntl_ModelFindOrCreateNet( pRoot, "Const1" ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertAig(): Internal error: Net has more than one fanin.\n" ); - return 0; - } - Aig_ManConst1(pAig)->pData = pNet; - } - // create a new node for each LUT - Counter = 0; - nDigits = Aig_Base10Log( Aig_ManNodeNum(pAig) ); - Aig_ManForEachObj( pAig, pObj, i ) - { - if ( !Aig_ObjIsNode(pObj) ) - continue; - if ( Aig_ObjFanin0(pObj)->pData == NULL || Aig_ObjFanin1(pObj)->pData == NULL ) - { - printf( "Ntl_ManInsertAig(): Internal error: Net not found.\n" ); - return 0; - } - pNode = Ntl_ModelCreateNode( pRoot, 2 ); - Ntl_ObjSetFanin( pNode, (Ntl_Net_t *)Aig_ObjFanin0(pObj)->pData, 0 ); - Ntl_ObjSetFanin( pNode, (Ntl_Net_t *)Aig_ObjFanin1(pObj)->pData, 1 ); - if ( Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) ) - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, "00 1\n" ); - else if ( Aig_ObjFaninC0(pObj) && !Aig_ObjFaninC1(pObj) ) - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, "01 1\n" ); - else if ( !Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) ) - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, "10 1\n" ); - else // if ( Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) ) - pNode->pSop = Ntl_ManStoreSop( p->pMemSops, "11 1\n" ); - sprintf( Buffer, "and%0*d", nDigits, Counter++ ); - if ( (pNet = Ntl_ModelFindNet( pRoot, Buffer )) ) - { - printf( "Ntl_ManInsertAig(): Internal error: Intermediate net name is not unique.\n" ); - return 0; - } - pNet = Ntl_ModelFindOrCreateNet( pRoot, Buffer ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertAig(): Internal error: Net has more than one fanin.\n" ); - return 0; - } - pObj->pData = pNet; - } - // mark CIs and outputs of the registers - Ntl_ManForEachCiNet( p, pNetCo, i ) - pNetCo->fMark = 1; - // update the CO pointers - Ntl_ManForEachCoNet( p, pNetCo, i ) - { - if ( pNetCo->fMark ) - continue; - pNetCo->fMark = 1; - // get the corresponding PO and its driver - pObj = Aig_ManPo( pAig, i ); - pFanin = Aig_ObjFanin0( pObj ); - // get the net driving the driver - pNet = (Ntl_Net_t *)pFanin->pData; - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = Aig_ObjFaninC0(pObj)? Ntl_ManStoreSop( p->pMemSops, "0 1\n" ) : Ntl_ManStoreSop( p->pMemSops, "1 1\n" ); - Ntl_ObjSetFanin( pNode, pNet, 0 ); - // update the CO driver net - assert( pNetCo->pDriver == NULL ); - if ( !Ntl_ModelSetNetDriver( pNode, pNetCo ) ) - { - printf( "Ntl_ManInsertAig(): Internal error: PO net has more than one fanin.\n" ); - return 0; - } - } - // clean CI/CO marks - Ntl_ManUnmarkCiCoNets( p ); - if ( !Ntl_ManCheck( p ) ) - printf( "Ntl_ManInsertAig: The check has failed for design %s.\n", p->pName ); - return p; -} - -/**Function************************************************************* - - Synopsis [Find drivers of the given net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManFindDriver( Ntl_Man_t * p, char * pName ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet, * pNetThis; - int i, k; - pRoot = Ntl_ManRootModel( p ); - pNetThis = Ntl_ModelFindNet( pRoot, pName ); - printf( "\n*** Net %d \"%s\":\n", pNetThis->NetId, pName ); - // mark from the nodes - Ntl_ModelForEachPo( pRoot, pNode, i ) - if ( pNetThis == Ntl_ObjFanin0(pNode) ) - printf( "driven by PO %d\n", i ); - Ntl_ModelForEachNode( pRoot, pNode, i ) - Ntl_ObjForEachFanin( pNode, pNet, k ) - if ( pNetThis == pNet ) - printf( "driven by node %d with %d fanins and %d fanouts\n (%s)\n", - pNode->Id, Ntl_ObjFaninNum(pNode), Ntl_ObjFanoutNum(pNode), Ntl_ObjFanout(pNode,0)->pName ); - Ntl_ModelForEachBox( pRoot, pNode, i ) - Ntl_ObjForEachFanin( pNode, pNet, k ) - if ( pNetThis == pNet ) - printf( "driven by box %d with %d fanins and %d fanouts\n (%s)\n", - pNode->Id, Ntl_ObjFaninNum(pNode), Ntl_ObjFanoutNum(pNode), Ntl_ObjFanout(pNode,0)->pName ); -} - -/**Function************************************************************* - - Synopsis [Inserts the given mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManInsertNtk2( Ntl_Man_t * p, Nwk_Man_t * pNtk ) -{ - int fWriteConstants = 1; - char Buffer[1000]; - Vec_Ptr_t * vObjs; - Vec_Int_t * vTruth; - Vec_Int_t * vCover; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet, * pNetCo; - Nwk_Obj_t * pObj, * pFanin; - int i, k, nDigits; - unsigned * pTruth; - assert( Vec_PtrSize(p->vCis) == Nwk_ManCiNum(pNtk) ); - assert( Vec_PtrSize(p->vCos) == Nwk_ManCoNum(pNtk) ); - p = Ntl_ManStartFrom( p ); - pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelNodeNum(pRoot) == 0 ); - // set the correspondence between the PI/PO nodes - Ntl_ManForEachCiNet( p, pNet, i ) - Nwk_ManCi( pNtk, i )->pCopy = pNet; - // create a new node for each LUT - vTruth = Vec_IntAlloc( 1 << 16 ); - vCover = Vec_IntAlloc( 1 << 16 ); - nDigits = Aig_Base10Log( Nwk_ManNodeNum(pNtk) ); - // go through the nodes in the topological order - vObjs = Nwk_ManDfs( pNtk ); - Vec_PtrForEachEntry( Nwk_Obj_t *, vObjs, pObj, i ) - { - if ( !Nwk_ObjIsNode(pObj) ) - continue; -/* - if ( fWriteConstants && Nwk_ObjFaninNum(pObj) == 0 ) - { - pObj->pCopy = NULL; - continue; - } -*/ - // skip constant drivers if they only drive COs - if ( fWriteConstants && Nwk_ObjFaninNum(pObj) == 0 ) - { - Nwk_Obj_t * pFanout; - int i; - Nwk_ObjForEachFanout( pObj, pFanout, i ) - if ( Nwk_ObjIsNode(pFanout) ) - break; - if ( i == Nwk_ObjFanoutNum(pObj) ) - { - pObj->pCopy = NULL; - continue; - } - } - - pNode = Ntl_ModelCreateNode( pRoot, Nwk_ObjFaninNum(pObj) ); - pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 ); - if ( Hop_IsComplement(pObj->pFunc) ) - Kit_TruthNot( pTruth, pTruth, Nwk_ObjFaninNum(pObj) ); - if ( !Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) && !Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - Nwk_ObjForEachFanin( pObj, pFanin, k ) - { - pNet = (Ntl_Net_t *)pFanin->pCopy; - if ( pNet == NULL ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Net not found.\n" ); - return 0; - } - Ntl_ObjSetFanin( pNode, pNet, k ); - } - } - else if ( Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - pObj->pFunc = Hop_ManConst0(pNtk->pManHop); - pNode->nFanins = 0; - } - else if ( Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - pObj->pFunc = Hop_ManConst1(pNtk->pManHop); - pNode->nFanins = 0; - } - pNode->pSop = Kit_PlaFromTruth( p->pMemSops, pTruth, Nwk_ObjFaninNum(pObj), vCover ); - sprintf( Buffer, "lut%0*d", nDigits, i ); - if ( (pNet = Ntl_ModelFindNet( pRoot, Buffer )) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Intermediate net name is not unique.\n" ); - return 0; - } - pNet = Ntl_ModelFindOrCreateNet( pRoot, Buffer ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Net has more than one fanin.\n" ); - return 0; - } - pObj->pCopy = pNet; - } - Vec_PtrFree( vObjs ); - Vec_IntFree( vCover ); - Vec_IntFree( vTruth ); - // mark the nets driving special boxes - if ( p->pNalR ) - p->pNalR( p ); - // mark CIs and outputs of the registers - Ntl_ManForEachCiNet( p, pNetCo, i ) - pNetCo->fMark = 1; - // update the CO pointers - Ntl_ManForEachCoNet( p, pNetCo, i ) - { - if ( pNetCo->fMark ) - continue; - pNetCo->fMark = 1; - // get the corresponding PO and its driver - pObj = Nwk_ManCo( pNtk, i ); - pFanin = Nwk_ObjFanin0( pObj ); - // get the net driving this PO - pNet = (Ntl_Net_t *)pFanin->pCopy; - if ( pNet == NULL ) // constant net - { - assert( fWriteConstants ); - pNode = Ntl_ModelCreateNode( pRoot, 0 ); - pNode->pSop = pObj->fInvert? Ntl_ManStoreSop( p->pMemSops, " 0\n" ) : Ntl_ManStoreSop( p->pMemSops, " 1\n" ); - } - else - if ( Nwk_ObjFanoutNum(pFanin) == 1 && Ntl_ObjIsNode(pNet->pDriver) && !pNet->fMark2 ) - { - pNode = pNet->pDriver; - if ( !Ntl_ModelClearNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error! Net already has no driver.\n" ); - return NULL; - } - // remove this net - Ntl_ModelDeleteNet( pRoot, pNet ); - Vec_PtrWriteEntry( pRoot->vNets, pNet->NetId, NULL ); - // update node's function - if ( pObj->fInvert ) - Kit_PlaComplement( pNode->pSop ); - } - else - { -/* - if ( fWriteConstants && Ntl_ObjFaninNum(pNet->pDriver) == 0 ) - { - pNode = Ntl_ModelCreateNode( pRoot, 0 ); - pNode->pSop = pObj->fInvert? Ntl_ManStoreSop( p->pMemSops, " 0\n" ) : Ntl_ManStoreSop( p->pMemSops, " 1\n" ); - } - else -*/ - { -// assert( Ntl_ObjFaninNum(pNet->pDriver) != 0 ); - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = pObj->fInvert? Ntl_ManStoreSop( p->pMemSops, "0 1\n" ) : Ntl_ManStoreSop( p->pMemSops, "1 1\n" ); - Ntl_ObjSetFanin( pNode, pNet, 0 ); - } - } - // update the CO driver net - assert( pNetCo->pDriver == NULL ); - if ( !Ntl_ModelSetNetDriver( pNode, pNetCo ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: PO net has more than one fanin.\n" ); - return NULL; - } - } - // clean CI/CO marks - Ntl_ManUnmarkCiCoNets( p ); - if ( !Ntl_ManCheck( p ) ) - { - printf( "Ntl_ManInsertNtk: The check has failed for design %s.\n", p->pName ); - return NULL; - } - return p; -} - - -/**Function************************************************************* - - Synopsis [Inserts the given mapping into the netlist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManInsertNtk( Ntl_Man_t * p, Nwk_Man_t * pNtk ) -{ - char Buffer[1000]; - Vec_Ptr_t * vObjs; - Vec_Int_t * vTruth; - Vec_Int_t * vCover; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet, * pNetCo; - Nwk_Obj_t * pObj, * pFanin; - int i, k, nDigits; - unsigned * pTruth; - assert( Vec_PtrSize(p->vCis) == Nwk_ManCiNum(pNtk) ); - assert( Vec_PtrSize(p->vCos) == Nwk_ManCoNum(pNtk) ); - p = Ntl_ManStartFrom( p ); - pRoot = Ntl_ManRootModel( p ); - assert( Ntl_ModelNodeNum(pRoot) == 0 ); - // set the correspondence between the PI/PO nodes - Ntl_ManForEachCiNet( p, pNet, i ) - Nwk_ManCi( pNtk, i )->pCopy = pNet; - // create a new node for each LUT - vTruth = Vec_IntAlloc( 1 << 16 ); - vCover = Vec_IntAlloc( 1 << 16 ); - nDigits = Aig_Base10Log( Nwk_ManNodeNum(pNtk) ); - // go through the nodes in the topological order - vObjs = Nwk_ManDfs( pNtk ); - Vec_PtrForEachEntry( Nwk_Obj_t *, vObjs, pObj, i ) - { - if ( !Nwk_ObjIsNode(pObj) ) - continue; - pNode = Ntl_ModelCreateNode( pRoot, Nwk_ObjFaninNum(pObj) ); - pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 ); - if ( Hop_IsComplement(pObj->pFunc) ) - Kit_TruthNot( pTruth, pTruth, Nwk_ObjFaninNum(pObj) ); - if ( !Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) && !Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - Nwk_ObjForEachFanin( pObj, pFanin, k ) - { - pNet = (Ntl_Net_t *)pFanin->pCopy; - if ( pNet == NULL ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Net not found.\n" ); - return 0; - } - Ntl_ObjSetFanin( pNode, pNet, k ); - } - } - else if ( Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - pObj->pFunc = Hop_ManConst0(pNtk->pManHop); - pNode->nFanins = 0; - } - else if ( Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) ) - { - pObj->pFunc = Hop_ManConst1(pNtk->pManHop); - pNode->nFanins = 0; - } - pNode->pSop = Kit_PlaFromTruth( p->pMemSops, pTruth, Nwk_ObjFaninNum(pObj), vCover ); - sprintf( Buffer, "lut%0*d", nDigits, i ); - if ( (pNet = Ntl_ModelFindNet( pRoot, Buffer )) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Intermediate net name is not unique.\n" ); - return 0; - } - pNet = Ntl_ModelFindOrCreateNet( pRoot, Buffer ); - if ( !Ntl_ModelSetNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: Net has more than one fanin.\n" ); - return 0; - } - pObj->pCopy = pNet; - } - Vec_PtrFree( vObjs ); - Vec_IntFree( vCover ); - Vec_IntFree( vTruth ); - // mark CIs and outputs of the registers - Ntl_ManForEachCiNet( p, pNetCo, i ) - pNetCo->fMark = 1; - // update the CO pointers - Ntl_ManForEachCoNet( p, pNetCo, i ) - { - if ( pNetCo->fMark ) - continue; - pNetCo->fMark = 1; - // get the corresponding PO and its driver - pObj = Nwk_ManCo( pNtk, i ); - pFanin = Nwk_ObjFanin0( pObj ); - // get the net driving this PO - pNet = (Ntl_Net_t *)pFanin->pCopy; - if ( Nwk_ObjFanoutNum(pFanin) == 1 && Ntl_ObjIsNode(pNet->pDriver) ) - { - pNode = pNet->pDriver; - if ( !Ntl_ModelClearNetDriver( pNode, pNet ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error! Net already has no driver.\n" ); - return NULL; - } - // remove this net - Ntl_ModelDeleteNet( pRoot, pNet ); - Vec_PtrWriteEntry( pRoot->vNets, pNet->NetId, NULL ); - // update node's function - if ( pObj->fInvert ) - Kit_PlaComplement( pNode->pSop ); - } - else - { - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = pObj->fInvert? Ntl_ManStoreSop( p->pMemSops, "0 1\n" ) : Ntl_ManStoreSop( p->pMemSops, "1 1\n" ); - Ntl_ObjSetFanin( pNode, pNet, 0 ); - } - // update the CO driver net - assert( pNetCo->pDriver == NULL ); - if ( !Ntl_ModelSetNetDriver( pNode, pNetCo ) ) - { - printf( "Ntl_ManInsertNtk(): Internal error: PO net has more than one fanin.\n" ); - return NULL; - } - } - // clean CI/CO marks - Ntl_ManUnmarkCiCoNets( p ); - if ( !Ntl_ManCheck( p ) ) - { - printf( "Ntl_ManInsertNtk: The check has failed for design %s.\n", p->pName ); - return NULL; - } - return p; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlMan.c b/src/aig/ntl/ntlMan.c deleted file mode 100644 index 45fb7226..00000000 --- a/src/aig/ntl/ntlMan.c +++ /dev/null @@ -1,1068 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlMan.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Netlist manager.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Allocates the netlist manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManAlloc() -{ - Ntl_Man_t * p; - // start the manager - p = ABC_ALLOC( Ntl_Man_t, 1 ); - memset( p, 0, sizeof(Ntl_Man_t) ); - p->vModels = Vec_PtrAlloc( 1000 ); - p->vCis = Vec_PtrAlloc( 1000 ); - p->vCos = Vec_PtrAlloc( 1000 ); - p->vVisNodes = Vec_PtrAlloc( 1000 ); - p->vBox1Cios = Vec_IntAlloc( 1000 ); - p->vRegClasses = Vec_IntAlloc( 1000 ); - p->vRstClasses = Vec_IntAlloc( 1000 ); - // start the manager - p->pMemObjs = Aig_MmFlexStart(); - p->pMemSops = Aig_MmFlexStart(); - // allocate model table - p->nModTableSize = Aig_PrimeCudd( 100 ); - p->pModTable = ABC_ALLOC( Ntl_Mod_t *, p->nModTableSize ); - memset( p->pModTable, 0, sizeof(Ntl_Mod_t *) * p->nModTableSize ); - return p; -} - -/**Function************************************************************* - - Synopsis [Cleanups extended representation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManCleanup( Ntl_Man_t * p ) -{ - if ( p->pAig ) - { - Aig_ManStop( p->pAig ); - p->pAig = NULL; - } - if ( p->pManTime ) - { - Tim_ManStop( p->pManTime ); - p->pManTime = NULL; - } -} - -/**Function************************************************************* - - Synopsis [Duplicates the design without the nodes of the root model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManStartFrom( Ntl_Man_t * pOld ) -{ - Ntl_Man_t * pNew; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pBox; - Ntl_Net_t * pNet; - int i, k; - pNew = Ntl_ManAlloc(); - pNew->pName = Ntl_ManStoreFileName( pNew, pOld->pName ); - pNew->pSpec = Ntl_ManStoreName( pNew, pOld->pName ); - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - { - if ( i == 0 ) - { - Ntl_ManMarkCiCoNets( pOld ); - pModel->pCopy = Ntl_ModelStartFrom( pNew, pModel ); - Ntl_ManUnmarkCiCoNets( pOld ); - } - else - pModel->pCopy = Ntl_ModelDup( pNew, pModel ); - } - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - Ntl_ModelForEachBox( pModel, pBox, k ) - { - ((Ntl_Obj_t *)pBox->pCopy)->pImplem = (Ntl_Mod_t *)pBox->pImplem->pCopy; - ((Ntl_Obj_t *)pBox->pCopy)->iTemp = pBox->iTemp; -// ((Ntl_Obj_t *)pBox->pCopy)->Reset = pBox->Reset; - } - Ntl_ManForEachCiNet( pOld, pNet, i ) - Vec_PtrPush( pNew->vCis, pNet->pCopy ); - Ntl_ManForEachCoNet( pOld, pNet, i ) - Vec_PtrPush( pNew->vCos, pNet->pCopy ); - if ( pOld->pManTime ) - pNew->pManTime = Tim_ManDup( pOld->pManTime, 0 ); - if ( pOld->pNal ) - pOld->pNalD( pOld, pNew ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Duplicates the design.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManDup( Ntl_Man_t * pOld ) -{ - Ntl_Man_t * pNew; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pBox; - Ntl_Net_t * pNet; - int i, k; - pNew = Ntl_ManAlloc(); - pNew->pName = Ntl_ManStoreFileName( pNew, pOld->pName ); - pNew->pSpec = Ntl_ManStoreName( pNew, pOld->pName ); - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - pModel->pCopy = Ntl_ModelDup( pNew, pModel ); - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - Ntl_ModelForEachBox( pModel, pBox, k ) - ((Ntl_Obj_t *)pBox->pCopy)->pImplem = (Ntl_Mod_t *)pBox->pImplem->pCopy; - Ntl_ManForEachCiNet( pOld, pNet, i ) - Vec_PtrPush( pNew->vCis, pNet->pCopy ); - Ntl_ManForEachCoNet( pOld, pNet, i ) - Vec_PtrPush( pNew->vCos, pNet->pCopy ); - if ( pOld->pManTime ) - pNew->pManTime = Tim_ManDup( pOld->pManTime, 0 ); - if ( !Ntl_ManCheck( pNew ) ) - printf( "Ntl_ManDup: The check has failed for design %s.\n", pNew->pName ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Duplicates the design.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManDupCollapseLuts( Ntl_Man_t * pOld ) -{ - Ntl_Man_t * pNew; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pBox; -// Ntl_Net_t * pNet; - int i, k; - pNew = Ntl_ManAlloc(); - pNew->pName = Ntl_ManStoreFileName( pNew, pOld->pName ); - pNew->pSpec = Ntl_ManStoreName( pNew, pOld->pName ); - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - pModel->pCopy = Ntl_ModelDupCollapseLuts( pNew, pModel ); - Vec_PtrForEachEntry( Ntl_Mod_t *, pOld->vModels, pModel, i ) - Ntl_ModelForEachBox( pModel, pBox, k ) - if ( pBox->pCopy ) - ((Ntl_Obj_t *)pBox->pCopy)->pImplem = (Ntl_Mod_t *)pBox->pImplem->pCopy; -// Ntl_ManForEachCiNet( pOld, pNet, i ) -// Vec_PtrPush( pNew->vCis, pNet->pCopy ); -// Ntl_ManForEachCoNet( pOld, pNet, i ) -// Vec_PtrPush( pNew->vCos, pNet->pCopy ); -// if ( pOld->pManTime ) -// pNew->pManTime = Tim_ManDup( pOld->pManTime, 0 ); - if ( !Ntl_ManCheck( pNew ) ) - printf( "Ntl_ManDup: The check has failed for design %s.\n", pNew->pName ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Deallocates the netlist manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManFree( Ntl_Man_t * p ) -{ - if ( p->vModels ) - { - Ntl_Mod_t * pModel; - int i; - Ntl_ManForEachModel( p, pModel, i ) - Ntl_ModelFree( pModel ); - Vec_PtrFree( p->vModels ); - } - if ( p->vCis ) Vec_PtrFree( p->vCis ); - if ( p->vCos ) Vec_PtrFree( p->vCos ); - if ( p->vVisNodes ) Vec_PtrFree( p->vVisNodes ); - if ( p->vRegClasses) Vec_IntFree( p->vRegClasses ); - if ( p->vRstClasses) Vec_IntFree( p->vRstClasses ); - if ( p->vBox1Cios ) Vec_IntFree( p->vBox1Cios ); - if ( p->pMemObjs ) Aig_MmFlexStop( p->pMemObjs, 0 ); - if ( p->pMemSops ) Aig_MmFlexStop( p->pMemSops, 0 ); - if ( p->pAig ) Aig_ManStop( p->pAig ); - if ( p->pManTime ) Tim_ManStop( p->pManTime ); - if ( p->pNal ) p->pNalF( p->pNal ); - ABC_FREE( p->pModTable ); - ABC_FREE( p ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrintStats( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - pRoot = Ntl_ManRootModel( p ); - printf( "%-15s : ", p->pName ); - printf( "pi = %5d ", Ntl_ModelPiNum(pRoot) ); - printf( "po = %5d ", Ntl_ModelPoNum(pRoot) ); - printf( "lat = %5d ", Ntl_ModelLatchNum(pRoot) ); - printf( "node = %5d ", Ntl_ModelNodeNum(pRoot) ); - printf( "\n " ); - printf( "inv/buf = %5d ", Ntl_ModelLut1Num(pRoot) ); - printf( "box = %4d ", Ntl_ModelBoxNum(pRoot) ); - printf( "mod = %3d ", Vec_PtrSize(p->vModels) ); - printf( "net = %d", Ntl_ModelCountNets(pRoot) ); - printf( "\n" ); - fflush( stdout ); - assert( Ntl_ModelLut1Num(pRoot) == Ntl_ModelCountLut1(pRoot) ); - Ntl_ManPrintTypes( p ); - fflush( stdout ); -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Nwk_ManPrintStatsShort( Ntl_Man_t * p, Aig_Man_t * pAig, Nwk_Man_t * pNtk ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i, Counter = 0; - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachBox( pRoot, pObj, i ) - if ( strcmp(pObj->pImplem->pName, "dff") == 0 ) - Counter++; - if ( Counter == 0 ) - { - Ntl_ModelForEachBox( pRoot, pObj, i ) - Counter += (pObj->pImplem->attrWhite && !pObj->pImplem->attrComb); - } - printf( "%-15s : ", p->pName ); - printf( "pi =%5d ", Ntl_ModelPiNum(pRoot) ); - printf( "po =%5d ", Ntl_ModelPoNum(pRoot) ); - printf( "ff =%5d ", Counter ); - printf( "box =%6d ", Ntl_ModelBoxNum(pRoot) ); - if ( pAig != NULL ) - { - Counter = Aig_ManChoiceNum( pAig ); - if ( Counter ) - printf( "cho =%7d ", Counter ); - else - printf( "aig =%7d ", Aig_ManNodeNum(pAig) ); - } - if ( pNtk == NULL ) - printf( "No mapping.\n" ); - else - { - printf( "lut =%5d ", Nwk_ManNodeNum(pNtk) ); - printf( "lev =%3d ", Nwk_ManLevel(pNtk) ); -// printf( "del =%5.2f ", Nwk_ManDelayTraceLut(pNtk) ); - printf( "\n" ); - } -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManStatsRegs( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i, Counter = 0; - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachBox( pRoot, pObj, i ) - if ( strcmp(pObj->pImplem->pName, "m_dff") == 0 ) - Counter++; - return Counter; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManStatsLuts( Ntl_Man_t * p ) -{ - return Ntl_ModelLut1Num( Ntl_ManRootModel(p) ) + Ntl_ModelNodeNum( Ntl_ManRootModel(p) ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Nwk_ManStatsLuts( Nwk_Man_t * pNtk ) -{ - return pNtk ? Nwk_ManNodeNum(pNtk) : -1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Nwk_ManStatsLevs( Nwk_Man_t * pNtk ) -{ - return pNtk ? Nwk_ManLevel(pNtk) : -1; -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Nwk_ManPrintStatsUpdate( Ntl_Man_t * p, Aig_Man_t * pAig, Nwk_Man_t * pNtk, - int nRegInit, int nLutInit, int nLevInit, int Time ) -{ - printf( "FF =%7d (%5.1f%%) ", Ntl_ManStatsRegs(p), nRegInit ? (100.0*(nRegInit-Ntl_ManStatsRegs(p))/nRegInit) : 0.0 ); - if ( pNtk == NULL ) - printf( "Mapping is not available. " ); - else - { - printf( "Lut =%7d (%5.1f%%) ", Ntl_ManStatsLuts(p), nLutInit ? (100.0*(nLutInit-Ntl_ManStatsLuts(p))/nLutInit) : 0.0 ); - printf( "Lev =%4d (%5.1f%%) ", Nwk_ManStatsLevs(pNtk), nLevInit ? (100.0*(nLevInit-Nwk_ManStatsLevs(pNtk))/nLevInit) : 0.0 ); - } - ABC_PRT( "Time", clock() - Time ); -} - - -/**Function************************************************************* - - Synopsis [Deallocates the netlist manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Tim_Man_t * Ntl_ManReadTimeMan( Ntl_Man_t * p ) -{ - return p->pManTime; -} - -/**Function************************************************************* - - Synopsis [Saves the model type.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManSaveBoxType( Ntl_Obj_t * pObj ) -{ - Ntl_Mod_t * pModel = pObj->pImplem; - int Number = 0; - assert( Ntl_ObjIsBox(pObj) ); - Number |= (pModel->attrWhite << 0); - Number |= (pModel->attrBox << 1); - Number |= (pModel->attrComb << 2); - Number |= (pModel->attrKeep << 3); - Number |= (pModel->attrNoMerge << 4); - pModel->pMan->BoxTypes[Number]++; -} - -/**Function************************************************************* - - Synopsis [Saves the model type.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrintTypes( Ntl_Man_t * p ) -{ - Vec_Ptr_t * vFlops; - Ntl_Net_t * pNet; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pObj; - int i; - pModel = Ntl_ManRootModel( p ); - if ( Ntl_ModelBoxNum(pModel) == 0 ) - return; - printf( "BOX STATISTICS:\n" ); - Ntl_ModelForEachBox( pModel, pObj, i ) - Ntl_ManSaveBoxType( pObj ); - for ( i = 0; i < 32; i++ ) - { - if ( !p->BoxTypes[i] ) - continue; - printf( "Type %2d Num = %7d :", i, p->BoxTypes[i] ); - printf( " %s", ((i & 1) > 0)? "white ": "black " ); - printf( " %s", ((i & 2) > 0)? "box ": "logic " ); - printf( " %s", ((i & 4) > 0)? "comb ": "seq " ); - printf( " %s", ((i & 8) > 0)? "keep ": "sweep " ); - printf( " %s", ((i & 16) > 0)? "no_merge": "merge " ); - printf( "\n" ); - } - printf( "MODEL STATISTICS:\n" ); - Ntl_ManForEachModel( p, pModel, i ) - if ( i ) printf( "Model %2d : Name = %10s Used = %6d.\n", i, pModel->pName, pModel->nUsed ); - for ( i = 0; i < 32; i++ ) - p->BoxTypes[i] = 0; - pModel = Ntl_ManRootModel( p ); - if ( pModel->vClockFlops ) - { - printf( "CLOCK STATISTICS:\n" ); - Vec_VecForEachLevel( pModel->vClockFlops, vFlops, i ) - { - pNet = (Ntl_Net_t *)Vec_PtrEntry( pModel->vClocks, i ); - printf( "Clock %2d : Name = %30s Flops = %6d.\n", i+1, pNet->pName, Vec_PtrSize(vFlops) ); - } - } - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Procedure used for sorting the nodes in decreasing order of levels.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCompareClockClasses( Vec_Ptr_t ** pp1, Vec_Ptr_t ** pp2 ) -{ - int Diff = Vec_PtrSize(*pp1) - Vec_PtrSize(*pp2); - if ( Diff > 0 ) - return -1; - if ( Diff < 0 ) - return 1; - return 0; -} - -/**Function************************************************************* - - Synopsis [Saves the model type.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrintClocks( Ntl_Man_t * p ) -{ - Vec_Ptr_t * vFlops; - Ntl_Net_t * pNet; - Ntl_Mod_t * pModel; - int i; - pModel = Ntl_ManRootModel( p ); - if ( Ntl_ModelBoxNum(pModel) == 0 ) - return; - if ( pModel->vClockFlops ) - { - printf( "CLOCK STATISTICS:\n" ); - Vec_VecForEachLevel( pModel->vClockFlops, vFlops, i ) - { - pNet = (Ntl_Net_t *)Vec_PtrEntry( pModel->vClocks, i ); - printf( "Clock %2d : Name = %30s Flops = %6d.\n", i+1, pNet->pName, Vec_PtrSize(vFlops) ); - if ( i == 10 ) - { - printf( "Skipping... (the total is %d)\n", Vec_VecSize(pModel->vClockFlops) ); - break; - } - } - } -// printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Saves the model type.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManPrintResets( Ntl_Man_t * p ) -{ - Vec_Ptr_t * vFlops; - Ntl_Net_t * pNet; - Ntl_Mod_t * pModel; - int i; - pModel = Ntl_ManRootModel( p ); - if ( Ntl_ModelBoxNum(pModel) == 0 ) - return; - if ( pModel->vResetFlops ) - { - printf( "RESET STATISTICS:\n" ); - Vec_VecForEachLevel( pModel->vResetFlops, vFlops, i ) - { - pNet = (Ntl_Net_t *)Vec_PtrEntry( pModel->vResets, i ); - printf( "Reset %2d : Name = %30s Flops = %6d.\n", i+1, pNet->pName, Vec_PtrSize(vFlops) ); - if ( i == 10 ) - { - printf( "Skipping... (the total is %d)\n", Vec_VecSize(pModel->vResetFlops) ); - break; - } - } - } -// printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Allocates the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ModelAlloc( Ntl_Man_t * pMan, char * pName ) -{ - Ntl_Mod_t * p; - // start the manager - p = ABC_ALLOC( Ntl_Mod_t, 1 ); - memset( p, 0, sizeof(Ntl_Mod_t) ); - p->attrBox = 1; - p->attrComb = 1; - p->attrWhite = 1; - p->attrKeep = 0; - p->attrNoMerge = 0; - p->pMan = pMan; - p->pName = Ntl_ManStoreName( p->pMan, pName ); - p->vObjs = Vec_PtrAlloc( 100 ); - p->vPis = Vec_PtrAlloc( 10 ); - p->vPos = Vec_PtrAlloc( 10 ); - p->vNets = Vec_PtrAlloc( 100 ); - // start the table - p->nTableSize = Aig_PrimeCudd( 100 ); - p->pTable = ABC_ALLOC( Ntl_Net_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Ntl_Net_t *) * p->nTableSize ); - // add model to the table - if ( !Ntl_ManAddModel( pMan, p ) ) - { - Ntl_ModelFree( p ); - return NULL; - } - return p; -} - -/**Function************************************************************* - - Synopsis [Duplicates the model without nodes but with CI/CO nets.] - - Description [The CI/CO nets of the old model should be marked before - calling this procedure.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ModelStartFrom( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ) -{ - Ntl_Mod_t * pModelNew; - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - int i, k; - pModelNew = Ntl_ModelAlloc( pManNew, pModelOld->pName ); - pModelNew->attrWhite = pModelOld->attrWhite; - pModelNew->attrBox = pModelOld->attrBox; - pModelNew->attrComb = pModelOld->attrComb; - pModelNew->attrKeep = pModelOld->attrKeep; - pModelNew->attrNoMerge = pModelOld->attrNoMerge; - Ntl_ModelForEachObj( pModelOld, pObj, i ) - { - if ( Ntl_ObjIsNode(pObj) ) - pObj->pCopy = NULL; - else - pObj->pCopy = Ntl_ModelDupObj( pModelNew, pObj ); - } - Ntl_ModelForEachNet( pModelOld, pNet, i ) - { - if ( pNet->pDriver == NULL ) - pNet->pCopy = Ntl_ModelFindOrCreateNet( pModelNew, pNet->pName ); - else if ( pNet->fMark ) - { - pNet->pCopy = Ntl_ModelFindOrCreateNet( pModelNew, pNet->pName ); - ((Ntl_Net_t *)pNet->pCopy)->pDriver = (Ntl_Obj_t *)pNet->pDriver->pCopy; - } - else - pNet->pCopy = NULL; - if ( pNet->pCopy ) - ((Ntl_Net_t *)pNet->pCopy)->fFixed = pNet->fFixed; - } - Ntl_ModelForEachObj( pModelOld, pObj, i ) - { - if ( Ntl_ObjIsNode(pObj) ) - continue; - Ntl_ObjForEachFanin( pObj, pNet, k ) - if ( pNet->pCopy != NULL ) - Ntl_ObjSetFanin( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - if ( pNet->pCopy != NULL ) - Ntl_ObjSetFanout( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - if ( Ntl_ObjIsLatch(pObj) ) - { - ((Ntl_Obj_t *)pObj->pCopy)->LatchId = pObj->LatchId; - ((Ntl_Obj_t *)pObj->pCopy)->pClock = (Ntl_Net_t *)pObj->pClock->pCopy; - } - } - pModelNew->vDelays = pModelOld->vDelays? Vec_IntDup( pModelOld->vDelays ) : NULL; - pModelNew->vTimeInputs = pModelOld->vTimeInputs? Vec_IntDup( pModelOld->vTimeInputs ) : NULL; - pModelNew->vTimeOutputs = pModelOld->vTimeOutputs? Vec_IntDup( pModelOld->vTimeOutputs ) : NULL; - return pModelNew; -} - -/**Function************************************************************* - - Synopsis [Duplicates the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ModelDup( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ) -{ - Ntl_Mod_t * pModelNew; - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - int i, k; - pModelNew = Ntl_ModelAlloc( pManNew, pModelOld->pName ); - pModelNew->attrWhite = pModelOld->attrWhite; - pModelNew->attrBox = pModelOld->attrBox; - pModelNew->attrComb = pModelOld->attrComb; - pModelNew->attrKeep = pModelOld->attrKeep; - pModelNew->attrNoMerge = pModelOld->attrNoMerge; - Ntl_ModelForEachObj( pModelOld, pObj, i ) - pObj->pCopy = Ntl_ModelDupObj( pModelNew, pObj ); - Ntl_ModelForEachNet( pModelOld, pNet, i ) - { - pNet->pCopy = Ntl_ModelFindOrCreateNet( pModelNew, pNet->pName ); - ((Ntl_Net_t *)pNet->pCopy)->fFixed = pNet->fFixed; - if ( pNet->pDriver == NULL ) - { - assert( !pModelOld->attrWhite ); - continue; - } - ((Ntl_Net_t *)pNet->pCopy)->pDriver = (Ntl_Obj_t *)pNet->pDriver->pCopy; - assert( pNet->pDriver->pCopy != NULL ); - } - Ntl_ModelForEachObj( pModelOld, pObj, i ) - { - Ntl_ObjForEachFanin( pObj, pNet, k ) - Ntl_ObjSetFanin( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - Ntl_ObjSetFanout( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - if ( Ntl_ObjIsLatch(pObj) ) - { - ((Ntl_Obj_t *)pObj->pCopy)->LatchId = pObj->LatchId; - ((Ntl_Obj_t *)pObj->pCopy)->pClock = pObj->pClock? (Ntl_Net_t *)pObj->pClock->pCopy : NULL; - } - if ( Ntl_ObjIsNode(pObj) ) - ((Ntl_Obj_t *)pObj->pCopy)->pSop = Ntl_ManStoreSop( pManNew->pMemSops, pObj->pSop ); - } - pModelNew->vDelays = pModelOld->vDelays? Vec_IntDup( pModelOld->vDelays ) : NULL; - pModelNew->vTimeInputs = pModelOld->vTimeInputs? Vec_IntDup( pModelOld->vTimeInputs ) : NULL; - pModelNew->vTimeOutputs = pModelOld->vTimeOutputs? Vec_IntDup( pModelOld->vTimeOutputs ) : NULL; - return pModelNew; -} - - -// *r x\large\club_u2.blif.bz2; *ps; *clplut; *ps -// *r x\large\amazon_core.blif.bz2; *ps; *clplut; *ps - - -/**Function************************************************************* - - Synopsis [Duplicates the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ModelDupCollapseLuts( Ntl_Man_t * pManNew, Ntl_Mod_t * pModelOld ) -{ - Ntl_Mod_t * pModelNew, * pModelBox; - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj, * pObjBox; - char * pNameBuf = ABC_ALLOC( char, 10000 ); - int i, k, m, Counter = 0; - pModelNew = Ntl_ModelAlloc( pManNew, pModelOld->pName ); - pModelNew->attrWhite = pModelOld->attrWhite; - pModelNew->attrBox = pModelOld->attrBox; - pModelNew->attrComb = pModelOld->attrComb; - pModelNew->attrKeep = pModelOld->attrKeep; - pModelNew->attrNoMerge = pModelOld->attrNoMerge; - Ntl_ModelForEachObj( pModelOld, pObj, i ) - if ( Ntl_ObjIsLutBox(pObj) ) // skip collapsible LUT boxes - pObj->pCopy = NULL; - else - pObj->pCopy = Ntl_ModelDupObj( pModelNew, pObj ); - Ntl_ModelForEachNet( pModelOld, pNet, i ) - { - pNet->pCopy = Ntl_ModelFindOrCreateNet( pModelNew, pNet->pName ); - ((Ntl_Net_t *)pNet->pCopy)->fFixed = pNet->fFixed; - if ( pNet->pDriver == NULL ) - { - assert( !pModelOld->attrWhite ); - continue; - } - if ( Ntl_ObjIsLutBox(pNet->pDriver) ) - continue; - ((Ntl_Net_t *)pNet->pCopy)->pDriver = (Ntl_Obj_t *)pNet->pDriver->pCopy; - assert( pNet->pDriver->pCopy != NULL ); - } - Ntl_ModelForEachObj( pModelOld, pObj, i ) - { - if ( Ntl_ObjIsLutBox(pObj) ) // collapse LUT boxes - { - pModelBox = pObj->pImplem; - assert( pModelBox->attrComb ); - assert( Ntl_ObjFaninNum(pObj) == Ntl_ModelPiNum(pModelBox) ); - assert( Ntl_ObjFanoutNum(pObj) == Ntl_ModelPoNum(pModelBox) ); - Ntl_ModelClearNets( pModelBox ); - // attach PI/PO nets - Ntl_ModelForEachPi( pModelBox, pObjBox, k ) - Ntl_ObjFanout0(pObjBox)->pCopy = Ntl_ObjFanin(pObj, k)->pCopy; - Ntl_ModelForEachPo( pModelBox, pObjBox, k ) - Ntl_ObjFanin0(pObjBox)->pCopy = Ntl_ObjFanout(pObj, k)->pCopy; - // duplicate internal nodes - Ntl_ModelForEachNode( pModelBox, pObjBox, k ) - pObjBox->pCopy = Ntl_ModelDupObj( pModelNew, pObjBox ); - // duplicate and connect nets - Ntl_ModelForEachNet( pModelBox, pNet, k ) - { - if ( pNet->pCopy != NULL ) - continue; - sprintf( pNameBuf, "box%d_%s", i, pNet->pName ); - pNet->pCopy = Ntl_ModelFindOrCreateNet( pModelNew, pNameBuf ); // change name!!! - ((Ntl_Net_t *)pNet->pCopy)->pDriver = (Ntl_Obj_t *)pNet->pDriver->pCopy; - } - // connect nodes - Ntl_ModelForEachNode( pModelBox, pObjBox, k ) - { - Ntl_ObjForEachFanin( pObjBox, pNet, m ) - Ntl_ObjSetFanin( (Ntl_Obj_t *)pObjBox->pCopy, (Ntl_Net_t *)pNet->pCopy, m ); - Ntl_ObjForEachFanout( pObjBox, pNet, m ) - Ntl_ObjSetFanout( (Ntl_Obj_t *)pObjBox->pCopy, (Ntl_Net_t *)pNet->pCopy, m ); - ((Ntl_Obj_t *)pObjBox->pCopy)->pSop = Ntl_ManStoreSop( pManNew->pMemSops, pObjBox->pSop ); - } - // connect the PO nets - Ntl_ModelForEachPo( pModelBox, pObjBox, k ) - ((Ntl_Net_t *)Ntl_ObjFanin0(pObjBox)->pCopy)->pDriver = (Ntl_Obj_t *)Ntl_ObjFanin0(pObjBox)->pDriver->pCopy; - assert( pObj->pCopy == NULL ); - Counter++; - } - else - { - Ntl_ObjForEachFanin( pObj, pNet, k ) - Ntl_ObjSetFanin( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - Ntl_ObjSetFanout( (Ntl_Obj_t *)pObj->pCopy, (Ntl_Net_t *)pNet->pCopy, k ); - if ( Ntl_ObjIsLatch(pObj) ) - { - ((Ntl_Obj_t *)pObj->pCopy)->LatchId = pObj->LatchId; - ((Ntl_Obj_t *)pObj->pCopy)->pClock = pObj->pClock? (Ntl_Net_t *)pObj->pClock->pCopy : NULL; - } - if ( Ntl_ObjIsNode(pObj) ) - ((Ntl_Obj_t *)pObj->pCopy)->pSop = Ntl_ManStoreSop( pManNew->pMemSops, pObj->pSop ); - } - } - pModelNew->vDelays = pModelOld->vDelays? Vec_IntDup( pModelOld->vDelays ) : NULL; - pModelNew->vTimeInputs = pModelOld->vTimeInputs? Vec_IntDup( pModelOld->vTimeInputs ) : NULL; - pModelNew->vTimeOutputs = pModelOld->vTimeOutputs? Vec_IntDup( pModelOld->vTimeOutputs ) : NULL; - ABC_FREE( pNameBuf ); - if ( Counter ) - printf( "Collapsed %d LUT boxes.\n", Counter ); - return pModelNew; -} - -/**Function************************************************************* - - Synopsis [Deallocates the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelFree( Ntl_Mod_t * p ) -{ - assert( Ntl_ModelCheckNetsAreNotMarked(p) ); - if ( p->vTimeOutputs ) Vec_IntFree( p->vTimeOutputs ); - if ( p->vTimeInputs ) Vec_IntFree( p->vTimeInputs ); - if ( p->vDelays ) Vec_IntFree( p->vDelays ); - if ( p->vClocks ) Vec_PtrFree( p->vClocks ); - if ( p->vClockFlops ) Vec_VecFree( p->vClockFlops ); - if ( p->vResets ) Vec_PtrFree( p->vResets ); - if ( p->vResetFlops ) Vec_VecFree( p->vResetFlops ); - Vec_PtrFree( p->vNets ); - Vec_PtrFree( p->vObjs ); - Vec_PtrFree( p->vPis ); - Vec_PtrFree( p->vPos ); - ABC_FREE( p->pTable ); - ABC_FREE( p ); -} - -/**Function************************************************************* - - Synopsis [Create model equal to the latch with the given init value.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ManCreateLatchModel( Ntl_Man_t * pMan, int Init ) -{ - char Name[100]; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNetLi, * pNetLo; - // create model - sprintf( Name, "%s%d", "latch", Init ); - pModel = Ntl_ModelAlloc( pMan, Name ); - pModel->attrWhite = 1; - pModel->attrBox = 1; - pModel->attrComb = 0; - pModel->attrKeep = 0; - pModel->attrNoMerge = 0; - // create primary input - pObj = Ntl_ModelCreatePi( pModel ); - pNetLi = Ntl_ModelFindOrCreateNet( pModel, "li" ); - Ntl_ModelSetNetDriver( pObj, pNetLi ); - // create latch - pObj = Ntl_ModelCreateLatch( pModel ); - pObj->LatchId.regInit = Init; - pObj->pFanio[0] = pNetLi; - // create primary output - pNetLo = Ntl_ModelFindOrCreateNet( pModel, "lo" ); - Ntl_ModelSetNetDriver( pObj, pNetLo ); - pObj = Ntl_ModelCreatePo( pModel, pNetLo ); - // set timing information - pModel->vTimeInputs = Vec_IntAlloc( 2 ); - Vec_IntPush( pModel->vTimeInputs, -1 ); - Vec_IntPush( pModel->vTimeInputs, Aig_Float2Int(0.0) ); - pModel->vTimeOutputs = Vec_IntAlloc( 2 ); - Vec_IntPush( pModel->vTimeOutputs, -1 ); - Vec_IntPush( pModel->vTimeOutputs, Aig_Float2Int(0.0) ); - return pModel; -} - - -/**Function************************************************************* - - Synopsis [Count constant nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCountLut0( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pNode; - int i, Counter = 0; - Ntl_ModelForEachNode( p, pNode, i ) - if ( Ntl_ObjFaninNum(pNode) == 0 ) - Counter++; - return Counter; -} - -/**Function************************************************************* - - Synopsis [Count single-output nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCountLut1( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pNode; - int i, Counter = 0; - Ntl_ModelForEachNode( p, pNode, i ) - if ( Ntl_ObjFaninNum(pNode) == 1 ) - Counter++; - return Counter; -} - -/**Function************************************************************* - - Synopsis [Count buffers] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCountBuf( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pNode; - int i, Counter = 0; - Ntl_ModelForEachNode( p, pNode, i ) - if ( Ntl_ObjFaninNum(pNode) == 1 && pNode->pSop[0] == '1' ) - Counter++; - return Counter; -} - -/**Function************************************************************* - - Synopsis [Count inverters.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCountInv( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pNode; - int i, Counter = 0; - Ntl_ModelForEachNode( p, pNode, i ) - if ( Ntl_ObjFaninNum(pNode) == 1 && pNode->pSop[0] == '0' ) - Counter++; - return Counter; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlMap.c b/src/aig/ntl/ntlMap.c deleted file mode 100644 index 0ce8549d..00000000 --- a/src/aig/ntl/ntlMap.c +++ /dev/null @@ -1,346 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlMap.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Derives mapped network from AIG.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlMap.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" -#include "kit.h" -#include "if.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Allocates mapping for the given AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_MappingAlloc( int nLuts, int nVars ) -{ - char * pMemory; - Ntl_Lut_t ** pArray; - int nEntrySize, i; - nEntrySize = sizeof(Ntl_Lut_t) + sizeof(int) * nVars + sizeof(unsigned) * Aig_TruthWordNum(nVars); - pArray = (Ntl_Lut_t **)ABC_ALLOC( char, (sizeof(Ntl_Lut_t *) + nEntrySize) * nLuts ); - pMemory = (char *)(pArray + nLuts); - memset( pMemory, 0, nEntrySize * nLuts ); - for ( i = 0; i < nLuts; i++ ) - { - pArray[i] = (Ntl_Lut_t *)pMemory; - pArray[i]->pFanins = (int *)(pMemory + sizeof(Ntl_Lut_t)); - pArray[i]->pTruth = (unsigned *)(pMemory + sizeof(Ntl_Lut_t) + sizeof(int) * nVars); - pMemory += nEntrySize; - } - return Vec_PtrAllocArray( (void **)pArray, nLuts ); -} - -/**Function************************************************************* - - Synopsis [Derives trivial mapping from the AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_MappingFromAig( Aig_Man_t * p ) -{ - Vec_Ptr_t * vMapping; - Ntl_Lut_t * pLut; - Aig_Obj_t * pObj; - int i, k = 0, nBytes = 4; - vMapping = Ntl_MappingAlloc( Aig_ManAndNum(p) + (int)(Aig_ManConst1(p)->nRefs > 0), 2 ); - if ( Aig_ManConst1(p)->nRefs > 0 ) - { - pLut = (Ntl_Lut_t *)Vec_PtrEntry( vMapping, k++ ); - pLut->Id = 0; - pLut->nFanins = 0; - memset( pLut->pTruth, 0xFF, nBytes ); - } - Aig_ManForEachNode( p, pObj, i ) - { - pLut = (Ntl_Lut_t *)Vec_PtrEntry( vMapping, k++ ); - pLut->Id = pObj->Id; - pLut->nFanins = 2; - pLut->pFanins[0] = Aig_ObjFaninId0(pObj); - pLut->pFanins[1] = Aig_ObjFaninId1(pObj); - if ( Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) ) - memset( pLut->pTruth, 0x11, nBytes ); - else if ( !Aig_ObjFaninC0(pObj) && Aig_ObjFaninC1(pObj) ) - memset( pLut->pTruth, 0x22, nBytes ); - else if ( Aig_ObjFaninC0(pObj) && !Aig_ObjFaninC1(pObj) ) - memset( pLut->pTruth, 0x44, nBytes ); - else if ( !Aig_ObjFaninC0(pObj) && !Aig_ObjFaninC1(pObj) ) - memset( pLut->pTruth, 0x88, nBytes ); - } - assert( k == Vec_PtrSize(vMapping) ); - return vMapping; -} - - -/**Function************************************************************* - - Synopsis [Load the network into FPGA manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManSetIfParsDefault( If_Par_t * pPars ) -{ -// extern void * Abc_FrameReadLibLut(); - // set defaults - memset( pPars, 0, sizeof(If_Par_t) ); - // user-controlable paramters -// pPars->nLutSize = -1; - pPars->nLutSize = 6; - pPars->nCutsMax = 8; - pPars->nFlowIters = 1; - pPars->nAreaIters = 2; - pPars->DelayTarget = -1; - pPars->Epsilon = (float)0.005; - pPars->fPreprocess = 1; - pPars->fArea = 0; - pPars->fFancy = 0; - pPars->fExpRed = 0; - pPars->fLatchPaths = 0; - pPars->fEdge = 1; - pPars->fCutMin = 0; - pPars->fSeqMap = 0; - pPars->fVerbose = 1; - // internal parameters - pPars->fTruth = 1; - pPars->nLatches = 0; - pPars->fLiftLeaves = 0; -// pPars->pLutLib = Abc_FrameReadLibLut(); - pPars->pLutLib = NULL; - pPars->pTimesArr = NULL; - pPars->pTimesArr = NULL; - pPars->pFuncCost = NULL; -/* - if ( pPars->nLutSize == -1 ) - { - if ( pPars->pLutLib == NULL ) - { - printf( "The LUT library is not given.\n" ); - return; - } - // get LUT size from the library - pPars->nLutSize = pPars->pLutLib->LutMax; - } -*/ -} - - -/**Function************************************************************* - - Synopsis [Load the network into FPGA manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -If_Man_t * Ntl_ManToIf( Aig_Man_t * p, If_Par_t * pPars ) -{ - If_Man_t * pIfMan; - Aig_Obj_t * pNode;//, * pFanin, * pPrev; - int i; - // start the mapping manager and set its parameters - pIfMan = If_ManStart( pPars ); - // print warning about excessive memory usage - if ( 1.0 * Aig_ManObjNum(p) * pIfMan->nObjBytes / (1<<30) > 1.0 ) - printf( "Warning: The mapper will allocate %.1f Gb for to represent the subject graph with %d AIG nodes.\n", - 1.0 * Aig_ManObjNum(p) * pIfMan->nObjBytes / (1<<30), Aig_ManObjNum(p) ); - // load the AIG into the mapper - Aig_ManForEachObj( p, pNode, i ) - { - if ( Aig_ObjIsAnd(pNode) ) - pNode->pData = (Aig_Obj_t *)If_ManCreateAnd( pIfMan, - If_NotCond( (If_Obj_t *)Aig_ObjFanin0(pNode)->pData, Aig_ObjFaninC0(pNode) ), - If_NotCond( (If_Obj_t *)Aig_ObjFanin1(pNode)->pData, Aig_ObjFaninC1(pNode) ) ); - else if ( Aig_ObjIsPi(pNode) ) - { - pNode->pData = If_ManCreateCi( pIfMan ); - ((If_Obj_t *)pNode->pData)->Level = pNode->Level; - if ( pIfMan->nLevelMax < (int)pNode->Level ) - pIfMan->nLevelMax = (int)pNode->Level; - } - else if ( Aig_ObjIsPo(pNode) ) - pNode->pData = If_ManCreateCo( pIfMan, If_NotCond( (If_Obj_t *)Aig_ObjFanin0(pNode)->pData, Aig_ObjFaninC0(pNode) ) ); - else if ( Aig_ObjIsConst1(pNode) ) - Aig_ManConst1(p)->pData = If_ManConst1( pIfMan ); - else // add the node to the mapper - assert( 0 ); - // set up the choice node -// if ( Aig_AigNodeIsChoice( pNode ) ) -// { -// pIfMan->nChoices++; -// for ( pPrev = pNode, pFanin = pNode->pData; pFanin; pPrev = pFanin, pFanin = pFanin->pData ) -// If_ObjSetChoice( (If_Obj_t *)pPrev->pData, (If_Obj_t *)pFanin->pData ); -// If_ManCreateChoice( pIfMan, (If_Obj_t *)pNode->pData ); -// } - { - If_Obj_t * pIfObj = (If_Obj_t *)pNode->pData; - assert( !If_IsComplement(pIfObj) ); - assert( pIfObj->Id == pNode->Id ); - } - } - return pIfMan; -} - -/**Function************************************************************* - - Synopsis [Creates the mapped network.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_ManFromIf( Aig_Man_t * p, If_Man_t * pMan ) -{ - Vec_Ptr_t * vIfMap; - If_Obj_t * pNode, * pLeaf; - If_Cut_t * pCutBest; - Vec_Ptr_t * vMapping; - Vec_Int_t * vIfToAig; - Aig_Obj_t * pObj; - Ntl_Lut_t * pLut; - int * ppLeaves; - int i, k, nLuts, nLeaves, nWords, nVarsMax; - // create mapping of If nodes into AIG nodes - vIfToAig = Vec_IntStart( Aig_ManObjNumMax(p) ); - Vec_IntFill( vIfToAig, Aig_ManObjNumMax(p), -1 ); - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjIsPo(pObj) ) - continue; - if ( Aig_ObjIsConst1(pObj) && pObj->pData == NULL ) - continue; - if ( Aig_ObjIsPi(pObj) && pObj->pData == NULL ) - continue; - pNode = (If_Obj_t *)pObj->pData; - assert( pNode != NULL ); - Vec_IntWriteEntry( vIfToAig, pNode->Id, pObj->Id ); - } - // create the mapping - vIfMap = If_ManCollectMappingDirect( pMan ); - nVarsMax = pMan->pPars->nLutSize; - nWords = Aig_TruthWordNum( nVarsMax ); - vMapping = Ntl_MappingAlloc( Vec_PtrSize(vIfMap) + (int)(Aig_ManConst1(p)->nRefs > 0), nVarsMax ); - nLuts = 0; - if ( Aig_ManConst1(p)->nRefs > 0 ) - { - pLut = (Ntl_Lut_t *)Vec_PtrEntry( vMapping, nLuts++ ); - pLut->Id = 0; - pLut->nFanins = 0; - memset( pLut->pTruth, 0xFF, 4 * nWords ); - } - Vec_PtrForEachEntry( If_Obj_t *, vIfMap, pNode, i ) - { - // get the best cut - pCutBest = If_ObjCutBest(pNode); - nLeaves = If_CutLeaveNum( pCutBest ); - ppLeaves = If_CutLeaves( pCutBest ); - // fill the LUT - pLut = (Ntl_Lut_t *)Vec_PtrEntry( vMapping, nLuts++ ); - pLut->Id = Vec_IntEntry( vIfToAig, pNode->Id ); - pLut->nFanins = nLeaves; - If_CutForEachLeaf( pMan, pCutBest, pLeaf, k ) - pLut->pFanins[k] = Vec_IntEntry( vIfToAig, pLeaf->Id ); - // compute the truth table - memcpy( pLut->pTruth, If_CutTruth(pCutBest), 4 * nWords ); - } - assert( nLuts == Vec_PtrSize(vMapping) ); - Vec_IntFree( vIfToAig ); - Vec_PtrFree( vIfMap ); - return vMapping; -} - -/**Function************************************************************* - - Synopsis [Interface with the FPGA mapping package.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_MappingIf( Ntl_Man_t * pMan, Aig_Man_t * p ) -{ - Vec_Ptr_t * vMapping; - If_Par_t Pars, * pPars = &Pars; - If_Man_t * pIfMan; - // perform FPGA mapping - Ntl_ManSetIfParsDefault( pPars ); - // set the arrival times - pPars->pTimesArr = ABC_ALLOC( float, Aig_ManPiNum(p) ); - memset( pPars->pTimesArr, 0, sizeof(float) * Aig_ManPiNum(p) ); - // translate into the mapper - pIfMan = Ntl_ManToIf( p, pPars ); - if ( pIfMan == NULL ) - return NULL; - pIfMan->pManTim = Tim_ManDup( pMan->pManTime, 0 ); - if ( !If_ManPerformMapping( pIfMan ) ) - { - If_ManStop( pIfMan ); - return NULL; - } - // transform the result of mapping into the new network - vMapping = Ntl_ManFromIf( p, pIfMan ); - If_ManStop( pIfMan ); - if ( vMapping == NULL ) - return NULL; - return vMapping; -} - - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlNames.c b/src/aig/ntl/ntlNames.c deleted file mode 100644 index fa91711d..00000000 --- a/src/aig/ntl/ntlNames.c +++ /dev/null @@ -1,471 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlNames.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Data-structure for storing hiNamrchical object names.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlNames.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// name object -typedef struct Ntl_ObjNam_t_ Ntl_ObjNam_t; -struct Ntl_ObjNam_t_ -{ - int iPrev; // prefix of this name - int iNext; // the next name in the hash table - char pName[0]; // name characters -}; - -// name manager -typedef struct Ntl_ManNam_t_ Ntl_ManNam_t; -struct Ntl_ManNam_t_ -{ - // info storage for names - char * pStore; // storage for name objects - int nStore; // the size of allocated storage - int iHandle; // the current free handle - int nHandles; // the number of handles - int nRefs; // reference counter for the manager - // hash table for names - int nBins; - unsigned * pBins; - // temporaries - Vec_Str_t * vName; // storage for returned name -}; - -static inline Ntl_ObjNam_t * Ntl_ManNamObj( Ntl_ManNam_t * p, int h ) { assert( !(h & 3) ); return (Ntl_ObjNam_t *)(p->pStore + h); } -static inline int Ntl_ManNamObjHandle( Ntl_ManNam_t * p, Ntl_ObjNam_t * pObj ) { return ((char *)pObj) - p->pStore; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Creates manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_ManNam_t * Ntl_ManNamStart() -{ - Ntl_ManNam_t * p; - p = ABC_CALLOC( Ntl_ManNam_t, 1 ); - p->nStore = (1 << 20); - p->pStore = ABC_ALLOC( char, p->nStore ); - p->iHandle = 4; - p->nBins = Aig_PrimeCudd( 500000 ); - p->pBins = ABC_CALLOC( unsigned, p->nBins ); - p->vName = Vec_StrAlloc( 1000 ); - return p; -} - -/**Function************************************************************* - - Synopsis [Deletes manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManNamStop( Ntl_ManNam_t * p ) -{ - Vec_StrFree( p->vName ); - ABC_FREE( p->pStore ); - ABC_FREE( p->pBins ); - ABC_FREE( p ); -} - -/**Function************************************************************* - - Synopsis [Deletes manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManNamReportMemUsage( Ntl_ManNam_t * p ) -{ - return sizeof(Ntl_ManNam_t) + p->nStore + sizeof(int) * p->nBins + sizeof(int) * Vec_StrSize(p->vName); -} - -/**Function************************************************************* - - Synopsis [References the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManNamRef( Ntl_ManNam_t * p ) -{ - p->nRefs++; -} - -/**Function************************************************************* - - Synopsis [Dereferences the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManNamDeref( Ntl_ManNam_t * p ) -{ - if ( --p->nRefs == 0 ) - Ntl_ManNamStop( p ); -} - -/**Function************************************************************* - - Synopsis [Returns object with the given handle.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -/**Function************************************************************* - - Synopsis [Computes hash value of the node using its simulation info.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManNamStrHash( char * pStr, int Length, int nTableSize ) -{ - static int s_FPrimes[128] = { - 1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459, - 1499, 1559, 1607, 1657, 1709, 1759, 1823, 1877, 1933, 1997, - 2039, 2089, 2141, 2213, 2269, 2311, 2371, 2411, 2467, 2543, - 2609, 2663, 2699, 2741, 2797, 2851, 2909, 2969, 3037, 3089, - 3169, 3221, 3299, 3331, 3389, 3461, 3517, 3557, 3613, 3671, - 3719, 3779, 3847, 3907, 3943, 4013, 4073, 4129, 4201, 4243, - 4289, 4363, 4441, 4493, 4549, 4621, 4663, 4729, 4793, 4871, - 4933, 4973, 5021, 5087, 5153, 5227, 5281, 5351, 5417, 5471, - 5519, 5573, 5651, 5693, 5749, 5821, 5861, 5923, 6011, 6073, - 6131, 6199, 6257, 6301, 6353, 6397, 6481, 6563, 6619, 6689, - 6737, 6803, 6863, 6917, 6977, 7027, 7109, 7187, 7237, 7309, - 7393, 7477, 7523, 7561, 7607, 7681, 7727, 7817, 7877, 7933, - 8011, 8039, 8059, 8081, 8093, 8111, 8123, 8147 - }; - unsigned uHash; - int i; - uHash = 0; - for ( i = 0; i < Length; i++ ) - if ( i & 1 ) - uHash *= pStr[i] * s_FPrimes[i & 0x7F]; - else - uHash ^= pStr[i] * s_FPrimes[i & 0x7F]; - return uHash % nTableSize; -} - - -/**Function************************************************************* - - Synopsis [Compares two strings to be equal.] - - Description [Returns 1 if the strings match.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManNamStrCompare_rec( Ntl_ManNam_t * p, char * pStr, int Length, Ntl_ObjNam_t * pThis ) -{ - Ntl_ObjNam_t * pNext = (pThis->iPrev)? Ntl_ManNamObj(p, pThis->iPrev) : NULL; - int LengthNew = strlen(pThis->pName); - if ( !strncmp( pThis->pName, pStr + Length - LengthNew, LengthNew ) ) - return 0; - if ( pNext == NULL ) - return 1; - return Ntl_ManNamStrCompare_rec( p, pStr, Length - LengthNew, pNext ); -} - - -/**Function************************************************************* - - Synopsis [Returns the place of this state in the table or NULL if it exists.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline unsigned * Ntl_ManNamStrHashFind( Ntl_ManNam_t * p, char * pStr, int Length, int * pHandle ) -{ - Ntl_ObjNam_t * pThis; - unsigned * pPlace = p->pBins + Ntl_ManNamStrHash( pStr, Length, p->nBins ); - for ( pThis = (*pPlace)? Ntl_ManNamObj(p, *pPlace) : NULL; pThis; - pPlace = (unsigned *)&pThis->iNext, pThis = (*pPlace)? Ntl_ManNamObj(p, *pPlace) : NULL ) - if ( !Ntl_ManNamStrCompare_rec( p, pStr, Length, pThis ) ) - { - *pHandle = Ntl_ManNamObjHandle( p, pThis ); - return NULL; - } - *pHandle = -1; - return pPlace; -} - -/**Function************************************************************* - - Synopsis [Resizes the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManNamStrHashResize( Ntl_ManNam_t * p ) -{ - Ntl_ObjNam_t * pThis; - unsigned * pBinsOld, * piPlace; - int nBinsOld, iNext, iHandle, Counter, i; - assert( p->pBins != NULL ); - // replace the table - pBinsOld = p->pBins; - nBinsOld = p->nBins; - p->nBins = Aig_PrimeCudd( 3 * p->nBins ); - p->pBins = ABC_CALLOC( unsigned, p->nBins ); - // rehash the entries from the old table - Counter = 0; - for ( i = 0; i < nBinsOld; i++ ) - for ( pThis = (pBinsOld[i]? Ntl_ManNamObj(p, pBinsOld[i]) : NULL), - iNext = (pThis? pThis->iNext : 0); - pThis; pThis = (iNext? Ntl_ManNamObj(p, iNext) : NULL), - iNext = (pThis? pThis->iNext : 0) ) - { - pThis->iNext = 0; - piPlace = Ntl_ManNamStrHashFind( p, pThis->pName, strlen(pThis->pName), &iHandle ); - assert( *piPlace == 0 ); // should not be there - *piPlace = Ntl_ManNamObjHandle( p, pThis ); - Counter++; - } - assert( Counter == p->nHandles ); - ABC_FREE( pBinsOld ); -} - -/**Function************************************************************* - - Synopsis [Returns the handle of a new object to represent the name.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManNamStrGrow_rec( Ntl_ManNam_t * p, char * pStr, int Length, unsigned * piPlace ) -{ - Ntl_ObjNam_t * pThis; - char * pStrNew; - int Separ, LengthNew; - int iHandle; - assert( Length > 0 ); - // find the separator symbol - for ( Separ = Length - 2; Separ >= 0 && pStr[Separ] != '/'; Separ-- ); - pStrNew = (Separ == -1) ? pStr : pStr + Separ + 1; - LengthNew = Length - (pStrNew - pStr); - // realloc memory if needed - if ( p->iHandle + (int)sizeof(Ntl_ObjNam_t) + LengthNew+5 > p->nStore ) - { - int OffSet; - if ( (char *)piPlace > p->pStore && (char *)piPlace < p->pStore + p->nStore ) - OffSet = (char *)piPlace - p->pStore; - else - OffSet = -1; - p->nStore *= 2; - p->pStore = ABC_REALLOC( char, p->pStore, p->nStore ); - if ( OffSet >= 0 ) - piPlace = (unsigned *)(p->pStore + OffSet); - } - // new entry is created - p->nHandles++; - *piPlace = p->iHandle; - pThis = Ntl_ManNamObj( p, p->iHandle ); - p->iHandle += sizeof(Ntl_ObjNam_t) + 4 * Aig_BitWordNum( 8*(LengthNew+1) ); - pThis->iNext = 0; - pThis->iPrev = 0; - strncpy( pThis->pName, pStrNew, LengthNew ); - pThis->pName[LengthNew] = 0; - // expand hash table if needed -// if ( p->nHandles > 2 * p->nBins ) -// Ntl_ManNamStrHashResize( p ); - // create previous object if needed - if ( Separ >= 0 ) - { - assert( pStr[Separ] == '/' ); - Separ++; - piPlace = Ntl_ManNamStrHashFind( p, pStr, Separ, &iHandle ); - if ( piPlace != NULL ) - iHandle = Ntl_ManNamStrGrow_rec( p, pStr, Separ, piPlace ); - pThis->iPrev = iHandle; - } - return Ntl_ManNamObjHandle( p, pThis ); -} - -/**Function************************************************************* - - Synopsis [Finds or adds the given name to storage.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManNamStrFind( Ntl_ManNam_t * p, char * pStr ) -{ - int iHandle; - Ntl_ManNamStrHashFind( p, pStr, strlen(pStr), &iHandle ); - return iHandle; -} - -/**Function************************************************************* - - Synopsis [Finds or adds the given name to storage.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned Ntl_ManNamStrFindOrAdd( Ntl_ManNam_t * p, char * pStr ) -{ - unsigned * piPlace; - int iHandle, Length = strlen(pStr); - assert( Length > 0 ); - piPlace = Ntl_ManNamStrHashFind( p, pStr, Length, &iHandle ); - if ( piPlace == NULL ) - return iHandle; - assert( *piPlace == 0 ); - return Ntl_ManNamStrGrow_rec( p, pStr, Length, piPlace ); -} - -/**Function************************************************************* - - Synopsis [Returns name from handle.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ntl_ManNamStr( Ntl_ManNam_t * p, int h ) -{ - Ntl_ObjNam_t * pObj; - int k; - assert( h && h < p->iHandle ); - Vec_StrClear( p->vName ); - for ( pObj = Ntl_ManNamObj( p, h ); pObj; pObj = pObj->iPrev ? Ntl_ManNamObj(p, pObj->iPrev) : NULL ) - for ( k = strlen(pObj->pName) - 1; k >= 0; k-- ) - Vec_StrPush( p->vName, pObj->pName[k] ); - Vec_StrReverseOrder( p->vName ); - Vec_StrPush( p->vName, 0 ); - return Vec_StrArray( p->vName ); -} - -/**Function************************************************************* - - Synopsis [Testing procedure for the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManNamTest( Ntl_Man_t * pNtl ) -{ - Ntl_ManNam_t * p; - Ntl_Mod_t * pRoot; - Ntl_Net_t * pNet; - int Memory; - int i, iHandle; - int clk = clock(); - - p = Ntl_ManNamStart(); -printf( "a" ); - Memory = 0; - pRoot = Ntl_ManRootModel( pNtl ); - Ntl_ModelForEachNet( pRoot, pNet, i ) - { - Memory += strlen(pNet->pName) + 1; - iHandle = Ntl_ManNamStrFindOrAdd( p, pNet->pName ); - -// printf( "Before = %s\n", pNet->pName ); -// printf( "After = %s\n", Ntl_ManNamStr(p, iHandle) ); - } - printf( "Net =%7d. Handle =%8d. ", Vec_PtrSize(pRoot->vNets), p->nHandles ); - printf( "Mem old = %7.2f Mb. Mem new = %7.2f Mb.\n", - 1.0 * Memory / (1 << 20), 1.0 * Ntl_ManNamReportMemUsage(p) / (1 << 20) ); - ABC_PRT( "Time", clock() - clk ); -printf( "b" ); - - Ntl_ManNamStop( p ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlObj.c b/src/aig/ntl/ntlObj.c deleted file mode 100644 index 209974aa..00000000 --- a/src/aig/ntl/ntlObj.c +++ /dev/null @@ -1,319 +0,0 @@ -/**CFile**************************************************************** - - FileName [.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: .c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Creates the primary input.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreatePi( Ntl_Mod_t * pModel ) -{ - Ntl_Obj_t * p; - p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) ); - memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) ); - p->Id = Vec_PtrSize( pModel->vObjs ); - Vec_PtrPush( pModel->vObjs, p ); - Vec_PtrPush( pModel->vPis, p ); -// p->pModel = pModel; - p->Type = NTL_OBJ_PI; - p->nFanins = 0; - p->nFanouts = 1; - pModel->nObjs[NTL_OBJ_PI]++; - return p; -} - -/**Function************************************************************* - - Synopsis [Creates the primary output.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreatePo( Ntl_Mod_t * pModel, Ntl_Net_t * pNet ) -{ - Ntl_Obj_t * p; - p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) ); - memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) ); - p->Id = Vec_PtrSize( pModel->vObjs ); - Vec_PtrPush( pModel->vObjs, p ); - Vec_PtrPush( pModel->vPos, p ); -// p->pModel = pModel; - p->Type = NTL_OBJ_PO; - p->nFanins = 1; - p->nFanouts = 0; - p->pFanio[0] = pNet; - pModel->nObjs[NTL_OBJ_PO]++; - return p; -} - -/**Function************************************************************* - - Synopsis [Creates the primary output.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreateLatch( Ntl_Mod_t * pModel ) -{ - Ntl_Obj_t * p; - p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * 3 ); - memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * 3 ); - p->Id = Vec_PtrSize( pModel->vObjs ); - Vec_PtrPush( pModel->vObjs, p ); -// p->pModel = pModel; - p->Type = NTL_OBJ_LATCH; - p->nFanins = 1; - p->nFanouts = 1; - pModel->nObjs[NTL_OBJ_LATCH]++; - return p; -} - -/**Function************************************************************* - - Synopsis [Creates the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreateNode( Ntl_Mod_t * pModel, int nFanins ) -{ - Ntl_Obj_t * p; - p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + 1) ); - memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + 1) ); - p->Id = Vec_PtrSize( pModel->vObjs ); - Vec_PtrPush( pModel->vObjs, p ); -// p->pModel = pModel; - p->Type = NTL_OBJ_NODE; - p->nFanins = nFanins; - p->nFanouts = 1; - if ( nFanins == 1 ) - pModel->nObjs[NTL_OBJ_LUT1]++; - else - pModel->nObjs[NTL_OBJ_NODE]++; - return p; -} - -/**Function************************************************************* - - Synopsis [Create the latch.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreateBox( Ntl_Mod_t * pModel, int nFanins, int nFanouts ) -{ - Ntl_Obj_t * p; - p = (Ntl_Obj_t *)Aig_MmFlexEntryFetch( pModel->pMan->pMemObjs, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + nFanouts) ); - memset( p, 0, sizeof(Ntl_Obj_t) + sizeof(Ntl_Net_t *) * (nFanins + nFanouts) ); - p->Id = Vec_PtrSize( pModel->vObjs ); - Vec_PtrPush( pModel->vObjs, p ); -// p->pModel = pModel; - p->Type = NTL_OBJ_BOX; - p->nFanins = nFanins; - p->nFanouts = nFanouts; - p->Reset = -1; - pModel->nObjs[NTL_OBJ_BOX]++; - return p; -} - -/**Function************************************************************* - - Synopsis [Create the latch.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelDupObj( Ntl_Mod_t * pModel, Ntl_Obj_t * pOld ) -{ - Ntl_Obj_t * pNew = NULL; // Supprses "might be used uninitialized" - if ( Ntl_ObjIsPi( pOld ) ) - pNew = Ntl_ModelCreatePi( pModel ); - else if ( Ntl_ObjIsPo( pOld ) ) - pNew = Ntl_ModelCreatePo( pModel, NULL ); - else if ( Ntl_ObjIsLatch( pOld ) ) - pNew = Ntl_ModelCreateLatch( pModel ); - else if ( Ntl_ObjIsNode( pOld ) ) - pNew = Ntl_ModelCreateNode( pModel, Ntl_ObjFaninNum(pOld) ); - else if ( Ntl_ObjIsBox( pOld ) ) - pNew = Ntl_ModelCreateBox( pModel, Ntl_ObjFaninNum(pOld), Ntl_ObjFanoutNum(pOld) ); - return pNew; -} - - -/**Function************************************************************* - - Synopsis [Creates the primary input with the given name.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Obj_t * Ntl_ModelCreatePiWithName( Ntl_Mod_t * pModel, char * pName ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - pNet = Ntl_ModelFindOrCreateNet( pModel, pName ); - if ( pNet->pDriver ) - return NULL; - pObj = Ntl_ModelCreatePi( pModel ); - Ntl_ModelSetNetDriver( pObj, pNet ); - return pObj; -} - -/**Function************************************************************* - - Synopsis [Allocates memory and copies the name into it.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ntl_ManStoreName( Ntl_Man_t * p, char * pName ) -{ - char * pStore; - pStore = Aig_MmFlexEntryFetch( p->pMemObjs, strlen(pName) + 1 ); - strcpy( pStore, pName ); - return pStore; -} - -/**Function************************************************************* - - Synopsis [Allocates memory and copies the SOP into it.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ntl_ManStoreSop( Aig_MmFlex_t * pMan, const char * pSop ) -{ - char * pStore; - pStore = Aig_MmFlexEntryFetch( pMan, strlen(pSop) + 1 ); - strcpy( pStore, pSop ); - return pStore; -} - -/**Function************************************************************* - - Synopsis [Allocates memory and copies the root of file name there.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ntl_ManStoreFileName( Ntl_Man_t * p, char * pFileName ) -{ - char * pBeg, * pEnd, * pStore, * pCur; - // find the first dot - for ( pEnd = pFileName; *pEnd; pEnd++ ) - if ( *pEnd == '.' ) - break; - // find the first char - for ( pBeg = pEnd - 1; pBeg >= pFileName; pBeg-- ) - if ( !((*pBeg >= 'a' && *pBeg <= 'z') || (*pBeg >= 'A' && *pBeg <= 'Z') || (*pBeg >= '0' && *pBeg <= '9') || *pBeg == '_') ) - break; - pBeg++; - // fill up storage - pStore = Aig_MmFlexEntryFetch( p->pMemSops, pEnd - pBeg + 1 ); - for ( pCur = pStore; pBeg < pEnd; pBeg++, pCur++ ) - *pCur = *pBeg; - *pCur = 0; - return pStore; -} - - -/**Function************************************************************* - - Synopsis [Returns the index of the fanin in the fanin list of the fanout.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManObjWhichFanout( Ntl_Obj_t * pNode, Ntl_Net_t * pFanout ) -{ - Ntl_Net_t * pObj; - int i; - Ntl_ObjForEachFanout( pNode, pObj, i ) - if ( pObj == pFanout ) - return i; - return -1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlReadBlif.c b/src/aig/ntl/ntlReadBlif.c deleted file mode 100644 index 88962efa..00000000 --- a/src/aig/ntl/ntlReadBlif.c +++ /dev/null @@ -1,1446 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlReadBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Command processing package.] - - Synopsis [Procedures to read BLIF file.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - January 8, 2007.] - - Revision [$Id: ntlReadBlif.c,v 1.1 2008/10/10 14:09:30 mjarvin Exp $] - -***********************************************************************/ - -// The code in this file is developed in collaboration with Mark Jarvin of Toronto. - -#include "ntl.h" -#include "bzlib.h" -#include "zlib.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Ntl_ReadMod_t_ Ntl_ReadMod_t; // parsing model -typedef struct Ntl_ReadMan_t_ Ntl_ReadMan_t; // parsing manager - -struct Ntl_ReadMod_t_ -{ - // file lines - char * pFirst; // .model line - char * pAttrib; // .attrib line - Vec_Ptr_t * vInputs; // .inputs lines - Vec_Ptr_t * vOutputs; // .outputs lines - Vec_Ptr_t * vLatches; // .latch lines - Vec_Ptr_t * vNames; // .names lines - Vec_Ptr_t * vSubckts; // .subckt lines - Vec_Ptr_t * vDelays; // .delay lines - Vec_Ptr_t * vTimeInputs; // .input_arrival/required lines - Vec_Ptr_t * vTimeOutputs; // .output_required/arrival lines - int fBlackBox; // indicates blackbox model - int fNoMerge; // indicates no-merge model - char fInArr; - char fInReq; - char fOutArr; - char fOutReq; - // the resulting network - Ntl_Mod_t * pNtk; - // the parent manager - Ntl_ReadMan_t * pMan; -}; - -struct Ntl_ReadMan_t_ -{ - // general info about file - char * pFileName; // the name of the file - char * pBuffer; // the contents of the file - Vec_Ptr_t * vLines; // the line beginnings - // the results of reading - Ntl_Man_t * pDesign; // the design under construction - // intermediate storage for models - Vec_Ptr_t * vModels; // vector of models - Ntl_ReadMod_t * pLatest; // the current model - // current processing info - Vec_Ptr_t * vTokens; // the current tokens - Vec_Ptr_t * vTokens2; // the current tokens - Vec_Str_t * vFunc; // the local function - // error reporting - char sError[512]; // the error string generated during parsing - // statistics - int nTablesRead; // the number of processed tables - int nTablesLeft; // the number of dangling tables -}; - -// static functions -static Ntl_ReadMan_t * Ntl_ReadAlloc(); -static void Ntl_ReadFree( Ntl_ReadMan_t * p ); -static Ntl_ReadMod_t * Ntl_ReadModAlloc(); -static void Ntl_ReadModFree( Ntl_ReadMod_t * p ); -static char * Ntl_ReadLoadFile( char * pFileName ); -static char * Ntl_ReadLoadFileBz2( char * pFileName ); -static char * Ntl_ReadLoadFileGz( char * pFileName ); -static void Ntl_ReadReadPreparse( Ntl_ReadMan_t * p ); -static int Ntl_ReadReadInterfaces( Ntl_ReadMan_t * p ); -static Ntl_Man_t * Ntl_ReadParse( Ntl_ReadMan_t * p ); -static int Ntl_ReadParseLineModel( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineAttrib( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineInputs( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineOutputs( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineLatch( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineSubckt( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineDelay( Ntl_ReadMod_t * p, char * pLine ); -static int Ntl_ReadParseLineTimes( Ntl_ReadMod_t * p, char * pLine, int fOutput ); -static int Ntl_ReadParseLineNamesBlif( Ntl_ReadMod_t * p, char * pLine ); - -static int Ntl_ReadCharIsSpace( char s ) { return s == ' ' || s == '\t' || s == '\r' || s == '\n'; } -static int Ntl_ReadCharIsSopSymb( char s ) { return s == '0' || s == '1' || s == '-' || s == '\r' || s == '\n'; } - - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Reads the network from the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Man_t * Ntl_ManReadBlif( char * pFileName, int fCheck ) -{ - FILE * pFile; - Ntl_ReadMan_t * p; - Ntl_Man_t * pDesign; - if ( !Ntl_FileIsType(pFileName, ".blif", ".blif.gz", ".blif.bz2") ) - { - printf( "Wrong file format\n" ); - return NULL; - } - // check that the file is available - pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - printf( "Ntl_ManReadBlif(): The file is unavailable (absent or open).\n" ); - return 0; - } - fclose( pFile ); - - // start the file reader - p = Ntl_ReadAlloc(); - p->pFileName = pFileName; - if ( !strncmp(pFileName+strlen(pFileName)-4,".bz2",4) ) - p->pBuffer = Ntl_ReadLoadFileBz2( pFileName ); - else if ( !strncmp(pFileName+strlen(pFileName)-3,".gz",3) ) - p->pBuffer = Ntl_ReadLoadFileGz( pFileName ); - else - p->pBuffer = Ntl_ReadLoadFile( pFileName ); - if ( p->pBuffer == NULL ) - { - Ntl_ReadFree( p ); - return NULL; - } - // set the design name - p->pDesign = Ntl_ManAlloc(); - p->pDesign->pName = Ntl_ManStoreFileName( p->pDesign, pFileName ); - p->pDesign->pSpec = Ntl_ManStoreName( p->pDesign, pFileName ); - // prepare the file for parsing - Ntl_ReadReadPreparse( p ); - // parse interfaces of each network - if ( !Ntl_ReadReadInterfaces( p ) ) - { - if ( p->sError[0] ) - fprintf( stdout, "%s\n", p->sError ); - Ntl_ReadFree( p ); - return NULL; - } - // construct the network - pDesign = Ntl_ReadParse( p ); - if ( p->sError[0] ) - fprintf( stdout, "%s\n", p->sError ); - if ( pDesign == NULL ) - { - Ntl_ReadFree( p ); - return NULL; - } - p->pDesign = NULL; - Ntl_ReadFree( p ); -// pDesign should be linked to all models of the design - - // make sure that everything is okay with the network structure - if ( fCheck ) - { - if ( !Ntl_ManCheck( pDesign ) ) - { - printf( "Ntl_ReadBlif: The check has failed for design %s.\n", pDesign->pName ); - Ntl_ManFree( pDesign ); - return NULL; - } - - } - // transform the design by removing the CO drivers -// if ( (nNodes = Ntl_ManReconnectCoDrivers(pDesign)) ) -// printf( "The design was transformed by removing %d buf/inv CO drivers.\n", nNodes ); -//Ntl_ManWriteBlif( pDesign, "_temp_.blif" ); -/* - { - Aig_Man_t * p = Ntl_ManCollapseSeq( pDesign ); - Aig_ManStop( p ); - } -*/ - return pDesign; -} - -/**Function************************************************************* - - Synopsis [Allocates the BLIF parsing structure.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static Ntl_ReadMan_t * Ntl_ReadAlloc() -{ - Ntl_ReadMan_t * p; - p = ABC_ALLOC( Ntl_ReadMan_t, 1 ); - memset( p, 0, sizeof(Ntl_ReadMan_t) ); - p->vLines = Vec_PtrAlloc( 512 ); - p->vModels = Vec_PtrAlloc( 512 ); - p->vTokens = Vec_PtrAlloc( 512 ); - p->vTokens2 = Vec_PtrAlloc( 512 ); - p->vFunc = Vec_StrAlloc( 512 ); - return p; -} - -/**Function************************************************************* - - Synopsis [Frees the BLIF parsing structure.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadFree( Ntl_ReadMan_t * p ) -{ - Ntl_ReadMod_t * pMod; - int i; - if ( p->pDesign ) - Ntl_ManFree( p->pDesign ); - if ( p->pBuffer ) - ABC_FREE( p->pBuffer ); - if ( p->vLines ) - Vec_PtrFree( p->vLines ); - if ( p->vModels ) - { - Vec_PtrForEachEntry( Ntl_ReadMod_t *, p->vModels, pMod, i ) - Ntl_ReadModFree( pMod ); - Vec_PtrFree( p->vModels ); - } - Vec_PtrFree( p->vTokens ); - Vec_PtrFree( p->vTokens2 ); - Vec_StrFree( p->vFunc ); - ABC_FREE( p ); -} - -/**Function************************************************************* - - Synopsis [Allocates the BLIF parsing structure for one model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static Ntl_ReadMod_t * Ntl_ReadModAlloc() -{ - Ntl_ReadMod_t * p; - p = ABC_ALLOC( Ntl_ReadMod_t, 1 ); - memset( p, 0, sizeof(Ntl_ReadMod_t) ); - p->vInputs = Vec_PtrAlloc( 8 ); - p->vOutputs = Vec_PtrAlloc( 8 ); - p->vLatches = Vec_PtrAlloc( 8 ); - p->vNames = Vec_PtrAlloc( 8 ); - p->vSubckts = Vec_PtrAlloc( 8 ); - p->vDelays = Vec_PtrAlloc( 8 ); - p->vTimeInputs = Vec_PtrAlloc( 8 ); - p->vTimeOutputs = Vec_PtrAlloc( 8 ); - return p; -} - -/**Function************************************************************* - - Synopsis [Deallocates the BLIF parsing structure for one model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadModFree( Ntl_ReadMod_t * p ) -{ - Vec_PtrFree( p->vInputs ); - Vec_PtrFree( p->vOutputs ); - Vec_PtrFree( p->vLatches ); - Vec_PtrFree( p->vNames ); - Vec_PtrFree( p->vSubckts ); - Vec_PtrFree( p->vDelays ); - Vec_PtrFree( p->vTimeInputs ); - Vec_PtrFree( p->vTimeOutputs ); - ABC_FREE( p ); -} - - - -/**Function************************************************************* - - Synopsis [Counts the number of given chars.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadCountChars( char * pLine, char Char ) -{ - char * pCur; - int Counter = 0; - for ( pCur = pLine; *pCur; pCur++ ) - if ( *pCur == Char ) - Counter++; - return Counter; -} - -/**Function************************************************************* - - Synopsis [Collects the already split tokens.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadCollectTokens( Vec_Ptr_t * vTokens, char * pInput, char * pOutput ) -{ - char * pCur; - Vec_PtrClear( vTokens ); - for ( pCur = pInput; pCur < pOutput; pCur++ ) - { - if ( *pCur == 0 ) - continue; - Vec_PtrPush( vTokens, pCur ); - while ( *++pCur ); - } -} - -/**Function************************************************************* - - Synopsis [Splits the line into tokens.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadSplitIntoTokens( Vec_Ptr_t * vTokens, char * pLine, char Stop ) -{ - char * pCur; - // clear spaces - for ( pCur = pLine; *pCur != Stop; pCur++ ) - if ( Ntl_ReadCharIsSpace(*pCur) ) - *pCur = 0; - // collect tokens - Ntl_ReadCollectTokens( vTokens, pLine, pCur ); -} - -/**Function************************************************************* - - Synopsis [Splits the line into tokens.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadSplitIntoTokensAndClear( Vec_Ptr_t * vTokens, char * pLine, char Stop, char Char ) -{ - char * pCur; - // clear spaces - for ( pCur = pLine; *pCur != Stop; pCur++ ) - if ( Ntl_ReadCharIsSpace(*pCur) || *pCur == Char ) - *pCur = 0; - // collect tokens - Ntl_ReadCollectTokens( vTokens, pLine, pCur ); -} - -/**Function************************************************************* - - Synopsis [Returns the 1-based number of the line in which the token occurs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadGetLine( Ntl_ReadMan_t * p, char * pToken ) -{ - char * pLine; - int i; - Vec_PtrForEachEntry( char *, p->vLines, pLine, i ) - if ( pToken < pLine ) - return i; - return -1; -} - -/**Function************************************************************* - - Synopsis [Reads the file into a character buffer.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static char * Ntl_ReadLoadFile( char * pFileName ) -{ - FILE * pFile; - int nFileSize; - char * pContents; - pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - fclose( pFile ); - printf( "Ntl_ReadLoadFile(): The file is unavailable (absent or open).\n" ); - return NULL; - } - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - if ( nFileSize == 0 ) - { - fclose( pFile ); - printf( "Ntl_ReadLoadFile(): The file is empty.\n" ); - return NULL; - } - pContents = ABC_ALLOC( char, nFileSize + 10 ); - rewind( pFile ); - fread( pContents, nFileSize, 1, pFile ); - fclose( pFile ); - // finish off the file with the spare .end line - // some benchmarks suddenly break off without this line - strcpy( pContents + nFileSize, "\n.end\n" ); - return pContents; -} - -/**Function************************************************************* - - Synopsis [Reads the file into a character buffer.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -typedef struct buflist { - char buf[1<<20]; - int nBuf; - struct buflist * next; -} buflist; - -static char * Ntl_ReadLoadFileBz2( char * pFileName ) -{ - FILE * pFile; - int nFileSize = 0; - char * pContents; - BZFILE * b; - int bzError; - struct buflist * pNext; - buflist * bufHead = NULL, * buf = NULL; - - pFile = fopen( pFileName, "rb" ); - if ( pFile == NULL ) - { - printf( "Ntl_ReadLoadFileBz2(): The file is unavailable (absent or open).\n" ); - return NULL; - } - b = BZ2_bzReadOpen(&bzError,pFile,0,0,NULL,0); - if (bzError != BZ_OK) { - printf( "Ntl_ReadLoadFileBz2(): BZ2_bzReadOpen() failed with error %d.\n",bzError ); - return NULL; - } - do { - if (!bufHead) - buf = bufHead = ABC_ALLOC( buflist, 1 ); - else - buf = buf->next = ABC_ALLOC( buflist, 1 ); - nFileSize += buf->nBuf = BZ2_bzRead(&bzError,b,buf->buf,1<<20); - buf->next = NULL; - } while (bzError == BZ_OK); - if (bzError == BZ_STREAM_END) { - // we're okay - char * p; - int nBytes = 0; - BZ2_bzReadClose(&bzError,b); - p = pContents = ABC_ALLOC( char, nFileSize + 10 ); - buf = bufHead; - do { - memcpy(p+nBytes,buf->buf,buf->nBuf); - nBytes += buf->nBuf; -// } while((buf = buf->next)); - pNext = buf->next; - ABC_FREE( buf ); - } while((buf = pNext)); - } else if (bzError == BZ_DATA_ERROR_MAGIC) { - // not a BZIP2 file - BZ2_bzReadClose(&bzError,b); - fseek( pFile, 0, SEEK_END ); - nFileSize = ftell( pFile ); - if ( nFileSize == 0 ) - { - printf( "Ntl_ReadLoadFileBz2(): The file is empty.\n" ); - return NULL; - } - pContents = ABC_ALLOC( char, nFileSize + 10 ); - rewind( pFile ); - fread( pContents, nFileSize, 1, pFile ); - } else { - // Some other error. - printf( "Ntl_ReadLoadFileBz2(): Unable to read the compressed BLIF.\n" ); - return NULL; - } - fclose( pFile ); - // finish off the file with the spare .end line - // some benchmarks suddenly break off without this line - strcpy( pContents + nFileSize, "\n.end\n" ); - return pContents; -} - -/**Function************************************************************* - - Synopsis [Reads the file into a character buffer.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static char * Ntl_ReadLoadFileGz( char * pFileName ) -{ - const int READ_BLOCK_SIZE = 100000; - FILE * pFile; - char * pContents; - int amtRead, readBlock, nFileSize = READ_BLOCK_SIZE; - pFile = (FILE *)gzopen( pFileName, "rb" ); // if pFileName doesn't end in ".gz" then this acts as a passthrough to fopen - pContents = ABC_ALLOC( char, nFileSize ); - readBlock = 0; - while ((amtRead = gzread(pFile, pContents + readBlock * READ_BLOCK_SIZE, READ_BLOCK_SIZE)) == READ_BLOCK_SIZE) { - //printf("%d: read %d bytes\n", readBlock, amtRead); - nFileSize += READ_BLOCK_SIZE; - pContents = ABC_REALLOC(char, pContents, nFileSize); - ++readBlock; - } - //printf("%d: read %d bytes\n", readBlock, amtRead); - assert( amtRead != -1 ); // indicates a zlib error - nFileSize -= (READ_BLOCK_SIZE - amtRead); - gzclose(pFile); - return pContents; -} - -/**Function************************************************************* - - Synopsis [Prepares the parsing.] - - Description [Performs several preliminary operations: - - Cuts the file buffer into separate lines. - - Removes comments and line extenders. - - Sorts lines by directives. - - Estimates the number of objects. - - Allocates room for the objects. - - Allocates room for the hash table.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static void Ntl_ReadReadPreparse( Ntl_ReadMan_t * p ) -{ - char * pCur, * pPrev; - int i, fComment = 0; - // parse the buffer into lines and remove comments - Vec_PtrPush( p->vLines, p->pBuffer ); - for ( pCur = p->pBuffer; *pCur; pCur++ ) - { - if ( *pCur == '\n' ) - { - *pCur = 0; -// if ( *(pCur-1) == '\r' ) -// *(pCur-1) = 0; - fComment = 0; - Vec_PtrPush( p->vLines, pCur + 1 ); - } - else if ( *pCur == '#' ) - fComment = 1; - // remove comments - if ( fComment ) - *pCur = 0; - } - - // unfold the line extensions and sort lines by directive - Vec_PtrForEachEntry( char *, p->vLines, pCur, i ) - { - if ( *pCur == 0 ) - continue; - // find previous non-space character - for ( pPrev = pCur - 2; pPrev >= p->pBuffer; pPrev-- ) - if ( !Ntl_ReadCharIsSpace(*pPrev) ) - break; - // if it is the line extender, overwrite it with spaces - if ( pPrev >= p->pBuffer && *pPrev == '\\' ) - { - for ( ; *pPrev; pPrev++ ) - *pPrev = ' '; - *pPrev = ' '; - continue; - } - // skip spaces at the beginning of the line - while ( Ntl_ReadCharIsSpace(*pCur++) ); - // parse directives - if ( *(pCur-1) != '.' ) - continue; - if ( !strncmp(pCur, "names", 5) ) - Vec_PtrPush( p->pLatest->vNames, pCur ); - else if ( !strncmp(pCur, "latch", 5) ) - Vec_PtrPush( p->pLatest->vLatches, pCur ); - else if ( !strncmp(pCur, "inputs", 6) ) - Vec_PtrPush( p->pLatest->vInputs, pCur ); - else if ( !strncmp(pCur, "outputs", 7) ) - Vec_PtrPush( p->pLatest->vOutputs, pCur ); - else if ( !strncmp(pCur, "subckt", 6) ) - Vec_PtrPush( p->pLatest->vSubckts, pCur ); - else if ( !strncmp(pCur, "delay", 5) ) - Vec_PtrPush( p->pLatest->vDelays, pCur ); - else if ( !strncmp(pCur, "input_arrival", 13) || - !strncmp(pCur, "input_required", 14) ) - { - if ( !strncmp(pCur, "input_arrival", 13) ) - p->pLatest->fInArr = 1; - if ( !strncmp(pCur, "input_required", 14) ) - p->pLatest->fInReq = 1; - Vec_PtrPush( p->pLatest->vTimeInputs, pCur ); - } - else if ( !strncmp(pCur, "output_required", 15) || - !strncmp(pCur, "output_arrival", 14) ) - { - if ( !strncmp(pCur, "output_required", 15) ) - p->pLatest->fOutReq = 1; - if ( !strncmp(pCur, "output_arrival", 14) ) - p->pLatest->fOutArr = 1; - Vec_PtrPush( p->pLatest->vTimeOutputs, pCur ); - } - else if ( !strncmp(pCur, "blackbox", 8) ) - p->pLatest->fBlackBox = 1; - else if ( !strncmp(pCur, "model", 5) ) - { - p->pLatest = Ntl_ReadModAlloc(); - p->pLatest->pFirst = pCur; - p->pLatest->pMan = p; - } - else if ( !strncmp(pCur, "attrib", 6) ) - { - if ( p->pLatest->pAttrib != NULL ) - fprintf( stdout, "Line %d: Skipping second .attrib line for this model.\n", Ntl_ReadGetLine(p, pCur) ); - else - p->pLatest->pAttrib = pCur; - } - else if ( !strncmp(pCur, "end", 3) ) - { - if ( p->pLatest ) - Vec_PtrPush( p->vModels, p->pLatest ); - p->pLatest = NULL; - } - else if ( !strncmp(pCur, "exdc", 4) ) - { - fprintf( stdout, "Line %d: Skipping EXDC network.\n", Ntl_ReadGetLine(p, pCur) ); - break; - } - else if ( !strncmp(pCur, "no_merge", 8) ) - { - p->pLatest->fNoMerge = 1; - } - else - { - pCur--; - if ( pCur[strlen(pCur)-1] == '\r' ) - pCur[strlen(pCur)-1] = 0; - fprintf( stdout, "Line %d: Skipping line \"%s\".\n", Ntl_ReadGetLine(p, pCur), pCur ); - } - } -} - -/**Function************************************************************* - - Synopsis [Parses interfaces of the models.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadReadInterfaces( Ntl_ReadMan_t * p ) -{ - Ntl_ReadMod_t * pMod; - char * pLine; - int i, k; - // iterate through the models - Vec_PtrForEachEntry( Ntl_ReadMod_t *, p->vModels, pMod, i ) - { - // parse the model - if ( !Ntl_ReadParseLineModel( pMod, pMod->pFirst ) ) - return 0; - // parse the model attributes - if ( pMod->pAttrib && !Ntl_ReadParseLineAttrib( pMod, pMod->pAttrib ) ) - return 0; - // parse no-merge - if ( pMod->fNoMerge ) - pMod->pNtk->attrNoMerge = 1; - // parse the inputs - Vec_PtrForEachEntry( char *, pMod->vInputs, pLine, k ) - if ( !Ntl_ReadParseLineInputs( pMod, pLine ) ) - return 0; - // parse the outputs - Vec_PtrForEachEntry( char *, pMod->vOutputs, pLine, k ) - if ( !Ntl_ReadParseLineOutputs( pMod, pLine ) ) - return 0; - // parse the delay info - Ntl_ModelSetPioNumbers( pMod->pNtk ); - Vec_PtrForEachEntry( char *, pMod->vDelays, pLine, k ) - if ( !Ntl_ReadParseLineDelay( pMod, pLine ) ) - return 0; - Vec_PtrForEachEntry( char *, pMod->vTimeInputs, pLine, k ) - if ( !Ntl_ReadParseLineTimes( pMod, pLine, 0 ) ) - return 0; - Vec_PtrForEachEntry( char *, pMod->vTimeOutputs, pLine, k ) - if ( !Ntl_ReadParseLineTimes( pMod, pLine, 1 ) ) - return 0; - // report timing line stats - if ( pMod->fInArr && pMod->fInReq ) - printf( "Model %s has both .input_arrival and .input_required.\n", pMod->pNtk->pName ); - if ( pMod->fOutArr && pMod->fOutReq ) - printf( "Model %s has both .output_arrival and .output_required.\n", pMod->pNtk->pName ); - if ( !pMod->vDelays && !pMod->fInArr && !pMod->fInReq ) - printf( "Model %s has neither .input_arrival nor .input_required.\n", pMod->pNtk->pName ); - if ( !pMod->vDelays && !pMod->fOutArr && !pMod->fOutReq ) - printf( "Model %s has neither .output_arrival nor .output_required.\n", pMod->pNtk->pName ); - } - return 1; -} - - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static Ntl_Man_t * Ntl_ReadParse( Ntl_ReadMan_t * p ) -{ - Ntl_Man_t * pDesign; - Ntl_ReadMod_t * pMod; - char * pLine; - int i, k; - // iterate through the models - Vec_PtrForEachEntry( Ntl_ReadMod_t *, p->vModels, pMod, i ) - { - // parse the latches - Vec_PtrForEachEntry( char *, pMod->vLatches, pLine, k ) - if ( !Ntl_ReadParseLineLatch( pMod, pLine ) ) - return NULL; - // parse the nodes - Vec_PtrForEachEntry( char *, pMod->vNames, pLine, k ) - if ( !Ntl_ReadParseLineNamesBlif( pMod, pLine ) ) - return NULL; - // parse the subcircuits - Vec_PtrForEachEntry( char *, pMod->vSubckts, pLine, k ) - if ( !Ntl_ReadParseLineSubckt( pMod, pLine ) ) - return NULL; - // finalize the network - Ntl_ModelFixNonDrivenNets( pMod->pNtk ); - } - if ( i == 0 ) - return NULL; - // update the design name - pMod = (Ntl_ReadMod_t *)Vec_PtrEntry( p->vModels, 0 ); - if ( Ntl_ModelLatchNum(pMod->pNtk) > 0 ) - Ntl_ModelTransformLatches( pMod->pNtk ); - p->pDesign->pName = Ntl_ManStoreName( p->pDesign, pMod->pNtk->pName ); - // return the network - pDesign = p->pDesign; - p->pDesign = NULL; - return pDesign; -} - -/**Function************************************************************* - - Synopsis [Parses the model line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineModel( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - char * pToken; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry( vTokens, 0 ); - assert( !strcmp(pToken, "model") ); - if ( Vec_PtrSize(vTokens) != 2 ) - { - sprintf( p->pMan->sError, "Line %d: The number of entries (%d) in .model line is different from two.", Ntl_ReadGetLine(p->pMan, pToken), Vec_PtrSize(vTokens) ); - return 0; - } - p->pNtk = Ntl_ModelAlloc( p->pMan->pDesign, (char *)Vec_PtrEntry(vTokens, 1) ); - if ( p->pNtk == NULL ) - { - sprintf( p->pMan->sError, "Line %d: Model %s already exists.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 1) ); - return 0; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the model line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineAttrib( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - char * pToken; - int i; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry( vTokens, 0 ); - assert( !strncmp(pToken, "attrib", 6) ); - Vec_PtrForEachEntryStart( char *, vTokens, pToken, i, 1 ) - { - pToken = (char *)Vec_PtrEntry( vTokens, i ); - if ( strcmp( pToken, "white" ) == 0 ) - p->pNtk->attrWhite = 1; - else if ( strcmp( pToken, "black" ) == 0 ) - p->pNtk->attrWhite = 0; - else if ( strcmp( pToken, "box" ) == 0 ) - p->pNtk->attrBox = 1; - else if ( strcmp( pToken, "logic" ) == 0 ) - p->pNtk->attrBox = 0; - else if ( strcmp( pToken, "comb" ) == 0 ) - p->pNtk->attrComb = 1; - else if ( strcmp( pToken, "seq" ) == 0 ) - p->pNtk->attrComb = 0; - else if ( strcmp( pToken, "keep" ) == 0 ) - p->pNtk->attrKeep = 1; - else if ( strcmp( pToken, "sweep" ) == 0 ) - p->pNtk->attrKeep = 0; - else - { - sprintf( p->pMan->sError, "Line %d: Unknown attribute (%s) in the .attrib line of model %s.", Ntl_ReadGetLine(p->pMan, pToken), pToken, p->pNtk->pName ); - return 0; - } - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the inputs line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineInputs( Ntl_ReadMod_t * p, char * pLine ) -{ - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - Vec_Ptr_t * vTokens = p->pMan->vTokens; - char * pToken; - int i; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry(vTokens, 0); - assert( !strcmp(pToken, "inputs") ); - Vec_PtrForEachEntryStart( char *, vTokens, pToken, i, 1 ) - { - pObj = Ntl_ModelCreatePi( p->pNtk ); - pNet = Ntl_ModelFindOrCreateNet( p->pNtk, pToken ); - if ( !Ntl_ModelSetNetDriver( pObj, pNet ) ) - { - sprintf( p->pMan->sError, "Line %d: Net %s already has a driver.", Ntl_ReadGetLine(p->pMan, pToken), pNet->pName ); - return 0; - } - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the outputs line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineOutputs( Ntl_ReadMod_t * p, char * pLine ) -{ - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - Vec_Ptr_t * vTokens = p->pMan->vTokens; - char * pToken; - int i; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry(vTokens, 0); - assert( !strcmp(pToken, "outputs") ); - Vec_PtrForEachEntryStart( char *, vTokens, pToken, i, 1 ) - { - pNet = Ntl_ModelFindOrCreateNet( p->pNtk, pToken ); - pObj = Ntl_ModelCreatePo( p->pNtk, pNet ); - pNet->pCopy = pObj; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the latches line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineLatch( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - Ntl_Net_t * pNetLi, * pNetLo; - Ntl_Obj_t * pObj; - char * pToken, * pNameLi, * pNameLo; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry(vTokens,0); - assert( !strcmp(pToken, "latch") ); - if ( Vec_PtrSize(vTokens) < 3 ) - { - sprintf( p->pMan->sError, "Line %d: Latch does not have input name and output name.", Ntl_ReadGetLine(p->pMan, pToken) ); - return 0; - } - // create latch - pNameLi = (char *)Vec_PtrEntry( vTokens, 1 ); - pNameLo = (char *)Vec_PtrEntry( vTokens, 2 ); - pNetLi = Ntl_ModelFindOrCreateNet( p->pNtk, pNameLi ); - pNetLo = Ntl_ModelFindOrCreateNet( p->pNtk, pNameLo ); - pObj = Ntl_ModelCreateLatch( p->pNtk ); - pObj->pFanio[0] = pNetLi; - if ( !Ntl_ModelSetNetDriver( pObj, pNetLo ) ) - { - sprintf( p->pMan->sError, "Line %d: Net %s already has a driver.", Ntl_ReadGetLine(p->pMan, pToken), pNetLo->pName ); - return 0; - } - // get initial value - if ( Vec_PtrSize(vTokens) > 3 ) - pObj->LatchId.regInit = atoi( (char *)Vec_PtrEntry(vTokens,Vec_PtrSize(vTokens)-1) ); - else - pObj->LatchId.regInit = 2; - if ( pObj->LatchId.regInit < 0 || pObj->LatchId.regInit > 2 ) - { - sprintf( p->pMan->sError, "Line %d: Initial state of the latch is incorrect \"%s\".", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens,3) ); - return 0; - } - // get the register class -// if ( Vec_PtrSize(vTokens) == 6 ) - if ( Vec_PtrSize(vTokens) == 5 || Vec_PtrSize(vTokens) == 6 ) - { - pToken = (char *)Vec_PtrEntry(vTokens,3); - if ( strcmp( pToken, "fe" ) == 0 ) - pObj->LatchId.regType = 1; - else if ( strcmp( pToken, "re" ) == 0 ) - pObj->LatchId.regType = 2; - else if ( strcmp( pToken, "ah" ) == 0 ) - pObj->LatchId.regType = 3; - else if ( strcmp( pToken, "al" ) == 0 ) - pObj->LatchId.regType = 4; - else if ( strcmp( pToken, "as" ) == 0 ) - pObj->LatchId.regType = 5; - else if ( pToken[0] >= '0' && pToken[0] <= '9' ) - pObj->LatchId.regClass = atoi(pToken); - else - { - sprintf( p->pMan->sError, "Line %d: Type/class of the latch is incorrect \"%s\".", Ntl_ReadGetLine(p->pMan, pToken), pToken ); - return 0; - } - } - if ( pObj->LatchId.regClass < 0 || pObj->LatchId.regClass > (1<<24) ) - { - sprintf( p->pMan->sError, "Line %d: Class of the latch is incorrect \"%s\".", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens,3) ); - return 0; - } - // get the clock -// if ( Vec_PtrSize(vTokens) == 5 || Vec_PtrSize(vTokens) == 6 ) - if ( Vec_PtrSize(vTokens) == 6 ) - { - pToken = (char *)Vec_PtrEntry(vTokens,Vec_PtrSize(vTokens)-2); - pNetLi = Ntl_ModelFindOrCreateNet( p->pNtk, pToken ); - pObj->pClock = pNetLi; - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the subckt line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineSubckt( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - Ntl_Mod_t * pModel; - Ntl_Obj_t * pBox, * pTerm; - Ntl_Net_t * pNet; - char * pToken, * pName, ** ppNames; - int nEquals, i, k; - - // split the line into tokens - nEquals = Ntl_ReadCountChars( pLine, '=' ); - Ntl_ReadSplitIntoTokensAndClear( vTokens, pLine, '\0', '=' ); - pToken = (char *)Vec_PtrEntry(vTokens,0); - assert( !strcmp(pToken, "subckt") ); - - // get the model for this box - pName = (char *)Vec_PtrEntry(vTokens,1); - pModel = Ntl_ManFindModel( p->pMan->pDesign, pName ); - if ( pModel == NULL ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find the model for subcircuit %s.", Ntl_ReadGetLine(p->pMan, pToken), pName ); - return 0; - } -/* - // temporary fix for splitting the .subckt line - if ( nEquals < Ntl_ModelPiNum(pModel) + Ntl_ModelPoNum(pModel) ) - { - Vec_Ptr_t * vTokens2 = Vec_PtrAlloc( 10 ); - // get one additional token - pToken = Vec_PtrEntry( vTokens, Vec_PtrSize(vTokens) - 1 ); - for ( ; *pToken; pToken++ ); - for ( ; *pToken == 0; pToken++ ); - Ntl_ReadSplitIntoTokensAndClear( vTokens2, pToken, '\0', '=' ); -// assert( Vec_PtrSize( vTokens2 ) == 2 ); - Vec_PtrForEachEntry( char *, vTokens2, pToken, i ) - Vec_PtrPush( vTokens, pToken ); - nEquals += Vec_PtrSize(vTokens2)/2; - Vec_PtrFree( vTokens2 ); - } -*/ - // check if the number of tokens is correct - if ( nEquals != Ntl_ModelPiNum(pModel) + Ntl_ModelPoNum(pModel) ) - { - sprintf( p->pMan->sError, "Line %d: The number of ports (%d) in .subckt %s differs from the sum of PIs and POs of the model (%d).", - Ntl_ReadGetLine(p->pMan, pToken), nEquals, pName, Ntl_ModelPiNum(pModel) + Ntl_ModelPoNum(pModel) ); - return 0; - } - - // get the names - ppNames = (char **)Vec_PtrArray(vTokens) + 2; - - // create the box with these terminals - pBox = Ntl_ModelCreateBox( p->pNtk, Ntl_ModelPiNum(pModel), Ntl_ModelPoNum(pModel) ); - pBox->pImplem = pModel; - Ntl_ModelForEachPi( pModel, pTerm, i ) - { - // find this terminal among the formal inputs of the subcircuit - pName = Ntl_ObjFanout0(pTerm)->pName; - for ( k = 0; k < nEquals; k++ ) - if ( !strcmp( ppNames[2*k], pName ) ) - break; - if ( k == nEquals ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find PI \"%s\" of the model \"%s\" as a formal input of the subcircuit.", - Ntl_ReadGetLine(p->pMan, pToken), pName, pModel->pName ); - return 0; - } - // create the BI with the actual name - pNet = Ntl_ModelFindOrCreateNet( p->pNtk, ppNames[2*k+1] ); - Ntl_ObjSetFanin( pBox, pNet, i ); - } - Ntl_ModelForEachPo( pModel, pTerm, i ) - { - // find this terminal among the formal outputs of the subcircuit - pName = Ntl_ObjFanin0(pTerm)->pName; - for ( k = 0; k < nEquals; k++ ) - if ( !strcmp( ppNames[2*k], pName ) ) - break; - if ( k == nEquals ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find PO \"%s\" of the model \"%s\" as a formal output of the subcircuit.", - Ntl_ReadGetLine(p->pMan, pToken), pName, pModel->pName ); - return 0; - } - // create the BI with the actual name - pNet = Ntl_ModelFindOrCreateNet( p->pNtk, ppNames[2*k+1] ); - Ntl_ObjSetFanout( pBox, pNet, i ); - } - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the subckt line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineDelay( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - int RetValue1, RetValue2, Number1, Number2, Temp; - char * pToken, * pTokenNum; - float Delay; - assert( sizeof(float) == sizeof(int) ); - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry(vTokens,0); - assert( !strcmp(pToken, "delay") ); - if ( Vec_PtrSize(vTokens) < 2 && Vec_PtrSize(vTokens) > 4 ) - { - sprintf( p->pMan->sError, "Line %d: Delay line does not have a valid number of parameters (1, 2, or 3).", Ntl_ReadGetLine(p->pMan, pToken) ); - return 0; - } - // find the delay number - pTokenNum = (char *)Vec_PtrEntryLast(vTokens); - Delay = atof( pTokenNum ); - if ( Delay == 0.0 && pTokenNum[0] != '0' ) - { - sprintf( p->pMan->sError, "Line %d: Delay value (%s) appears to be invalid.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntryLast(vTokens) ); - return 0; - } - // find the PI/PO numbers - RetValue1 = 0; Number1 = -1; - if ( Vec_PtrSize(vTokens) > 2 ) - { - RetValue1 = Ntl_ModelFindPioNumber( p->pNtk, 0, 0, (char *)Vec_PtrEntry(vTokens, 1), &Number1 ); - if ( RetValue1 == 0 ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find signal \"%s\" among PIs/POs.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 1) ); - return 0; - } - } - RetValue2 = 0; Number2 = -1; - if ( Vec_PtrSize(vTokens) > 3 ) - { - RetValue2 = Ntl_ModelFindPioNumber( p->pNtk, 0, 0, (char *)Vec_PtrEntry(vTokens, 2), &Number2 ); - if ( RetValue2 == 0 ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find signal \"%s\" among PIs/POs.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 2) ); - return 0; - } - } - if ( RetValue1 == RetValue2 && RetValue1 ) - { - sprintf( p->pMan->sError, "Line %d: Both signals \"%s\" and \"%s\" listed appear to be PIs or POs.", - Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 1), (char*)Vec_PtrEntry(vTokens, 2) ); - return 0; - } - if ( RetValue2 < RetValue1 ) - { - Temp = RetValue2; RetValue2 = RetValue1; RetValue1 = Temp; - Temp = Number2; Number2 = Number1; Number1 = Temp; - } - assert( RetValue1 == 0 || RetValue1 == -1 ); - assert( RetValue2 == 0 || RetValue2 == 1 ); - // store the values - if ( p->pNtk->vDelays == NULL ) - p->pNtk->vDelays = Vec_IntAlloc( 100 ); - Vec_IntPush( p->pNtk->vDelays, Number1 ); - Vec_IntPush( p->pNtk->vDelays, Number2 ); - Vec_IntPush( p->pNtk->vDelays, Aig_Float2Int(Delay) ); - return 1; -} - -/**Function************************************************************* - - Synopsis [Parses the subckt line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineTimes( Ntl_ReadMod_t * p, char * pLine, int fOutput ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - int RetValue, Number = -1; - char * pToken, * pTokenNum; - float Delay; - assert( sizeof(float) == sizeof(int) ); - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - pToken = (char *)Vec_PtrEntry(vTokens,0); - if ( fOutput ) - assert( !strncmp(pToken, "output_", 7) ); - else - assert( !strncmp(pToken, "input_", 6) ); - if ( Vec_PtrSize(vTokens) != 2 && Vec_PtrSize(vTokens) != 3 ) - { - sprintf( p->pMan->sError, "Line %d: Delay line does not have a valid number of parameters (2 or 3).", Ntl_ReadGetLine(p->pMan, pToken) ); - return 0; - } - // find the delay number - pTokenNum = (char *)Vec_PtrEntryLast(vTokens); - if ( !strcmp( pTokenNum, "-inf" ) ) - Delay = -TIM_ETERNITY; - else if ( !strcmp( pTokenNum, "inf" ) ) - Delay = TIM_ETERNITY; - else - Delay = atof( pTokenNum ); - if ( Delay == 0.0 && pTokenNum[0] != '0' ) - { - sprintf( p->pMan->sError, "Line %d: Delay value (%s) appears to be invalid.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntryLast(vTokens) ); - return 0; - } - // find the PI/PO numbers - if ( fOutput ) - { - if ( Vec_PtrSize(vTokens) == 3 ) - { - RetValue = Ntl_ModelFindPioNumber( p->pNtk, 0, 1, (char *)Vec_PtrEntry(vTokens, 1), &Number ); - if ( RetValue == 0 ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find signal \"%s\" among POs.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 1) ); - return 0; - } - } - // store the values - if ( p->pNtk->vTimeOutputs == NULL ) - p->pNtk->vTimeOutputs = Vec_IntAlloc( 100 ); - Vec_IntPush( p->pNtk->vTimeOutputs, Number ); - Vec_IntPush( p->pNtk->vTimeOutputs, Aig_Float2Int(Delay) ); - } - else - { - if ( Vec_PtrSize(vTokens) == 3 ) - { - RetValue = Ntl_ModelFindPioNumber( p->pNtk, 1, 0, (char *)Vec_PtrEntry(vTokens, 1), &Number ); - if ( RetValue == 0 ) - { - sprintf( p->pMan->sError, "Line %d: Cannot find signal \"%s\" among PIs.", Ntl_ReadGetLine(p->pMan, pToken), (char*)Vec_PtrEntry(vTokens, 1) ); - return 0; - } - } - // store the values - if ( p->pNtk->vTimeInputs == NULL ) - p->pNtk->vTimeInputs = Vec_IntAlloc( 100 ); - Vec_IntPush( p->pNtk->vTimeInputs, Number ); - Vec_IntPush( p->pNtk->vTimeInputs, Aig_Float2Int(Delay) ); - } - return 1; -} - - -/**Function************************************************************* - - Synopsis [Constructs the SOP cover from the file parsing info.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static char * Ntl_ReadParseTableBlif( Ntl_ReadMod_t * p, char * pTable, int nFanins ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - Vec_Str_t * vFunc = p->pMan->vFunc; - char * pProduct, * pOutput; - int i, Polarity = -1; - - - p->pMan->nTablesRead++; - // get the tokens - Ntl_ReadSplitIntoTokens( vTokens, pTable, '.' ); - if ( Vec_PtrSize(vTokens) == 0 ) - return Ntl_ManStoreSop( p->pMan->pDesign->pMemSops, " 0\n" ); - if ( Vec_PtrSize(vTokens) == 1 ) - { - pOutput = (char *)Vec_PtrEntry( vTokens, 0 ); - if ( *pOutput == '\"' ) - return Ntl_ManStoreSop( p->pMan->pDesign->pMemSops, pOutput ); - if ( ((pOutput[0] - '0') & 0x8E) || pOutput[1] ) - { - sprintf( p->pMan->sError, "Line %d: Constant table has wrong output value \"%s\".", Ntl_ReadGetLine(p->pMan, pOutput), pOutput ); - return NULL; - } - return Ntl_ManStoreSop( p->pMan->pDesign->pMemSops, (pOutput[0] == '0') ? " 0\n" : " 1\n" ); - } - pProduct = (char *)Vec_PtrEntry( vTokens, 0 ); - if ( Vec_PtrSize(vTokens) % 2 == 1 ) - { - sprintf( p->pMan->sError, "Line %d: Table has odd number of tokens (%d).", Ntl_ReadGetLine(p->pMan, pProduct), Vec_PtrSize(vTokens) ); - return NULL; - } - // parse the table - Vec_StrClear( vFunc ); - for ( i = 0; i < Vec_PtrSize(vTokens)/2; i++ ) - { - pProduct = (char *)Vec_PtrEntry( vTokens, 2*i + 0 ); - pOutput = (char *)Vec_PtrEntry( vTokens, 2*i + 1 ); - if ( strlen(pProduct) != (unsigned)nFanins ) - { - sprintf( p->pMan->sError, "Line %d: Cube \"%s\" has size different from the fanin count (%d).", Ntl_ReadGetLine(p->pMan, pProduct), pProduct, nFanins ); - return NULL; - } - if ( ((pOutput[0] - '0') & 0x8E) || pOutput[1] ) - { - sprintf( p->pMan->sError, "Line %d: Output value \"%s\" is incorrect.", Ntl_ReadGetLine(p->pMan, pProduct), pOutput ); - return NULL; - } - if ( Polarity == -1 ) - Polarity = pOutput[0] - '0'; - else if ( Polarity != pOutput[0] - '0' ) - { - sprintf( p->pMan->sError, "Line %d: Output value \"%s\" differs from the value in the first line of the table (%d).", Ntl_ReadGetLine(p->pMan, pProduct), pOutput, Polarity ); - return NULL; - } - // parse one product - Vec_StrPrintStr( vFunc, pProduct ); - Vec_StrPush( vFunc, ' ' ); - Vec_StrPush( vFunc, pOutput[0] ); - Vec_StrPush( vFunc, '\n' ); - } - Vec_StrPush( vFunc, '\0' ); - return Vec_StrArray( vFunc ); -} - -/**Function************************************************************* - - Synopsis [Parses the nodes line.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static int Ntl_ReadParseLineNamesBlif( Ntl_ReadMod_t * p, char * pLine ) -{ - Vec_Ptr_t * vTokens = p->pMan->vTokens; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNetOut, * pNetIn; - char * pNameOut, * pNameIn; - int i; - Ntl_ReadSplitIntoTokens( vTokens, pLine, '\0' ); - // parse the mapped node -// if ( !strcmp(Vec_PtrEntry(vTokens,0), "gate") ) -// return Ntl_ReadParseLineGateBlif( p, vTokens ); - // parse the regular name line - assert( !strcmp((char *)Vec_PtrEntry(vTokens,0), "names") ); - pNameOut = (char *)Vec_PtrEntryLast( vTokens ); - pNetOut = Ntl_ModelFindOrCreateNet( p->pNtk, pNameOut ); - // create fanins - pNode = Ntl_ModelCreateNode( p->pNtk, Vec_PtrSize(vTokens) - 2 ); - for ( i = 0; i < Vec_PtrSize(vTokens) - 2; i++ ) - { - pNameIn = (char *)Vec_PtrEntry(vTokens, i+1); - pNetIn = Ntl_ModelFindOrCreateNet( p->pNtk, pNameIn ); - Ntl_ObjSetFanin( pNode, pNetIn, i ); - } - if ( !Ntl_ModelSetNetDriver( pNode, pNetOut ) ) - { - sprintf( p->pMan->sError, "Line %d: Signal \"%s\" is defined more than once.", Ntl_ReadGetLine(p->pMan, pNameOut), pNameOut ); - return 0; - } - // parse the table of this node - pNode->pSop = Ntl_ReadParseTableBlif( p, pNameOut + strlen(pNameOut), pNode->nFanins ); - if ( pNode->pSop == NULL ) - return 0; - pNode->pSop = Ntl_ManStoreSop( p->pNtk->pMan->pMemSops, pNode->pSop ); - return 1; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlSweep.c b/src/aig/ntl/ntlSweep.c deleted file mode 100644 index 29e40f30..00000000 --- a/src/aig/ntl/ntlSweep.c +++ /dev/null @@ -1,214 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlSweep.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Performs structural sweep of the netlist.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlSweep.c,v 1.1 2008/10/10 14:09:30 mjarvin Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Detects logic that does not fanout into POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManSweepMark_rec( Ntl_Man_t * p, Ntl_Obj_t * pObj ) -{ - Ntl_Net_t * pNet; - int i; - if ( pObj->fMark ) - return; - pObj->fMark = 1; - Ntl_ObjForEachFanin( pObj, pNet, i ) - Ntl_ManSweepMark_rec( p, pNet->pDriver ); -} - -/**Function************************************************************* - - Synopsis [Detects logic that does not fanout into POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManSweepMark( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i; - // get the root model - pRoot = Ntl_ManRootModel( p ); - // clear net visited flags - Ntl_ModelForEachObj( pRoot, pObj, i ) - assert( pObj->fMark == 0 ); - // label the primary inputs - Ntl_ModelForEachPi( pRoot, pObj, i ) - pObj->fMark = 1; - // start from the primary outputs - Ntl_ModelForEachPo( pRoot, pObj, i ) - Ntl_ManSweepMark_rec( p, pObj ); - // start from the persistant boxes - Ntl_ModelForEachBox( pRoot, pObj, i ) - if ( pObj->pImplem->attrKeep ) - Ntl_ManSweepMark_rec( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Removes logic that does not fanout into POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManSweep( Ntl_Man_t * p, int fVerbose ) -{ - int nObjsOld[NTL_OBJ_VOID]; - Ntl_Mod_t * pRoot, * pMod; - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - int i, k, nNetsOld; - int ModelCounter = 0, Counter = 0; - - // remember the number of objects - pRoot = Ntl_ManRootModel( p ); - for ( i = 0; i < NTL_OBJ_VOID; i++ ) - nObjsOld[i] = pRoot->nObjs[i]; - nNetsOld = Ntl_ModelCountNets(pRoot); - - // mark the nets that do not fanout into POs - Ntl_ManSweepMark( p ); - - // count how many boxes of each type are swept away - if ( fVerbose ) - { - Ntl_ManForEachModel( p, pMod, i ) - pMod->nUsed = pMod->nRems = 0; - Ntl_ModelForEachObj( pRoot, pObj, i ) - if ( Ntl_ObjIsBox(pObj) && pObj->pImplem ) - { - pObj->pImplem->nUsed++; - if ( !pObj->fMark ) - { - if ( pObj->pImplem->nRems++ == 0 ) - ModelCounter++; - } - } - } - - // remove the useless objects and their nets - Ntl_ModelForEachObj( pRoot, pObj, i ) - { - if ( pObj->fMark ) - { - pObj->fMark = 0; - continue; - } - // remove the fanout nets - Ntl_ObjForEachFanout( pObj, pNet, k ) - if ( pNet != NULL && pNet->pName[0] != 0 ) - { - Ntl_ModelDeleteNet( pRoot, pNet ); - Vec_PtrWriteEntry( pRoot->vNets, pNet->NetId, NULL ); - } - // remove the object - if ( Ntl_ObjIsNode(pObj) && Ntl_ObjFaninNum(pObj) == 1 ) - pRoot->nObjs[NTL_OBJ_LUT1]--; - else - pRoot->nObjs[pObj->Type]--; - Vec_PtrWriteEntry( pRoot->vObjs, pObj->Id, NULL ); - pObj->Type = NTL_OBJ_NONE; - Counter++; - } - - - - // print detailed statistics of sweeping - if ( fVerbose && Counter > 0) - { - int numLutBox = 0; - - printf( "Swept away:" ); - printf( " Node = %d (%4.1f %%)", - nObjsOld[NTL_OBJ_NODE] - pRoot->nObjs[NTL_OBJ_NODE], - !nObjsOld[NTL_OBJ_NODE]? 0.0: 100.0 * (nObjsOld[NTL_OBJ_NODE] - pRoot->nObjs[NTL_OBJ_NODE]) / nObjsOld[NTL_OBJ_NODE] ); - printf( " Buf/Inv = %d (%4.1f %%)", - nObjsOld[NTL_OBJ_LUT1] - pRoot->nObjs[NTL_OBJ_LUT1], - !nObjsOld[NTL_OBJ_LUT1]? 0.0: 100.0 * (nObjsOld[NTL_OBJ_LUT1] - pRoot->nObjs[NTL_OBJ_LUT1]) / nObjsOld[NTL_OBJ_LUT1] ); - printf( " Lat = %d (%4.1f %%)", - nObjsOld[NTL_OBJ_LATCH] - pRoot->nObjs[NTL_OBJ_LATCH], - !nObjsOld[NTL_OBJ_LATCH]? 0.0: 100.0 * (nObjsOld[NTL_OBJ_LATCH] - pRoot->nObjs[NTL_OBJ_LATCH]) / nObjsOld[NTL_OBJ_LATCH] ); - printf( " Box = %d (%4.1f %%)", - nObjsOld[NTL_OBJ_BOX] - pRoot->nObjs[NTL_OBJ_BOX], - !nObjsOld[NTL_OBJ_BOX]? 0.0: 100.0 * (nObjsOld[NTL_OBJ_BOX] - pRoot->nObjs[NTL_OBJ_BOX]) / nObjsOld[NTL_OBJ_BOX] ); - printf( "\n" ); - if ( ModelCounter ) - { - printf( "Sweep removed %d boxed of %d types (out of %d types):\n", - nObjsOld[NTL_OBJ_BOX] - pRoot->nObjs[NTL_OBJ_BOX], ModelCounter, Vec_PtrSize(p->vModels)-1 ); - Ntl_ManForEachModel( p, pMod, i ) - { - if ( i && (pMod->nRems + pMod->nUsed-pMod->nRems) > 0) - { - - if (strncmp(pMod->pName, "LUT", 3) != 0) - { - //printf( "( M%d: %s, S=%d, L=%d ) ", i, pMod->pName, pMod->nRems, pMod->nUsed-pMod->nRems ); - //printf( "Model %3d : %-40s Swept = %5d. Left = %5d.\n", i, pMod->pName, pMod->nRems, pMod->nUsed-pMod->nRems ); - } else - { - numLutBox++; - } - } - } -// printf("\nLUTboxType =%d\n", numLutBox); - } - } - if ( !Ntl_ManCheck( p ) ) - printf( "Ntl_ManSweep: The check has failed for design %s.\n", p->pName ); - return Counter; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlTable.c b/src/aig/ntl/ntlTable.c deleted file mode 100644 index 23207081..00000000 --- a/src/aig/ntl/ntlTable.c +++ /dev/null @@ -1,554 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlTable.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Name table manipulation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlTable.c,v 1.3 2008/10/24 14:18:44 mjarvin Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// hashing for strings -static unsigned Ntl_HashString( const char * pName, int TableSize ) -{ - static int s_Primes[10] = { - 1291, 1699, 2357, 4177, 5147, - 5647, 6343, 7103, 7873, 8147 - }; - unsigned i, Key = 0; - for ( i = 0; pName[i] != '\0'; i++ ) - Key ^= s_Primes[i%10]*pName[i]*pName[i]; - return Key % TableSize; -} - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Allocates memory for the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Net_t * Ntl_ModelCreateNet( Ntl_Mod_t * p, const char * pName ) -{ - Ntl_Net_t * pNet; - int nSize = sizeof(Ntl_Net_t) + strlen(pName) + 1; - nSize = (nSize / sizeof(char*) + ((nSize % sizeof(char*)) > 0)) * sizeof(char*); // added by Saurabh on Sep 3, 2009 - pNet = (Ntl_Net_t *)Aig_MmFlexEntryFetch( p->pMan->pMemObjs, nSize ); - memset( pNet, 0, sizeof(Ntl_Net_t) ); - strcpy( pNet->pName, pName ); - pNet->NetId = Vec_PtrSize( p->vNets ); - Vec_PtrPush( p->vNets, pNet ); - return pNet; -} - -/**Function************************************************************* - - Synopsis [Allocates memory for the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Ntl_ModelCreateNetName( Ntl_Mod_t * p, const char * pName, int Num ) -{ - char * pResult; - char Buffer[1000]; - assert( strlen(pName) < 900 ); - do { - sprintf( Buffer, "%s%d", pName, Num++ ); - } while ( Ntl_ModelFindNet( p, Buffer ) != NULL ); - pResult = (char *)Aig_MmFlexEntryFetch( p->pMan->pMemObjs, strlen(Buffer) + 1 ); - strcpy( pResult, Buffer ); - return pResult; -} - -/**Function************************************************************* - - Synopsis [Resizes the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelTableResize( Ntl_Mod_t * p ) -{ - Ntl_Net_t ** pTableNew, ** ppSpot, * pEntry, * pEntry2; - int nTableSizeNew, Counter, e, clk; -clk = clock(); - // get the new table size - nTableSizeNew = Aig_PrimeCudd( 3 * p->nTableSize ); - // allocate a new array - pTableNew = ABC_ALLOC( Ntl_Net_t *, nTableSizeNew ); - memset( pTableNew, 0, sizeof(Ntl_Net_t *) * nTableSizeNew ); - // rehash entries - Counter = 0; - for ( e = 0; e < p->nTableSize; e++ ) - for ( pEntry = p->pTable[e], pEntry2 = pEntry? pEntry->pNext : NULL; - pEntry; pEntry = pEntry2, pEntry2 = pEntry? pEntry->pNext : NULL ) - { - ppSpot = pTableNew + Ntl_HashString( pEntry->pName, nTableSizeNew ); - pEntry->pNext = *ppSpot; - *ppSpot = pEntry; - Counter++; - } - assert( Counter == p->nEntries ); -// printf( "Increasing the structural table size from %6d to %6d. ", p->nTableSize, nTableSizeNew ); -// ABC_PRT( "Time", clock() - clk ); - // replace the table and the parameters - ABC_FREE( p->pTable ); - p->pTable = pTableNew; - p->nTableSize = nTableSizeNew; -} - -/**Function************************************************************* - - Synopsis [Finds net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Net_t * Ntl_ModelFindNet( Ntl_Mod_t * p, const char * pName ) -{ - Ntl_Net_t * pEnt; - unsigned Key = Ntl_HashString( pName, p->nTableSize ); - for ( pEnt = p->pTable[Key]; pEnt; pEnt = pEnt->pNext ) - if ( !strcmp( pEnt->pName, pName ) ) - return pEnt; - return NULL; -} - -/**Function************************************************************* - - Synopsis [Deletes net from the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelDeleteNet( Ntl_Mod_t * p, Ntl_Net_t * pNet ) -{ - Ntl_Net_t * pEnt, * pPrev; - unsigned Key = Ntl_HashString( pNet->pName, p->nTableSize ); - for ( pPrev = NULL, pEnt = p->pTable[Key]; pEnt; pPrev = pEnt, pEnt = pEnt->pNext ) - if ( pEnt == pNet ) - break; - if ( pEnt == NULL ) - { - printf( "Ntl_ModelDeleteNet(): Net to be deleted is not found in the hash table.\n" ); - return; - } - if ( pPrev == NULL ) - p->pTable[Key] = pEnt->pNext; - else - pPrev->pNext = pEnt->pNext; - p->nEntries--; -} - -/**Function************************************************************* - - Synopsis [Inserts net into the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelInsertNet( Ntl_Mod_t * p, Ntl_Net_t * pNet ) -{ - unsigned Key = Ntl_HashString( pNet->pName, p->nTableSize ); - assert( Ntl_ModelFindNet( p, pNet->pName ) == NULL ); - pNet->pNext = p->pTable[Key]; - p->pTable[Key] = pNet; -} - -/**Function************************************************************* - - Synopsis [Finds or creates the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Net_t * Ntl_ModelFindOrCreateNet( Ntl_Mod_t * p, const char * pName ) -{ - Ntl_Net_t * pEnt; - unsigned Key = Ntl_HashString( pName, p->nTableSize ); - for ( pEnt = p->pTable[Key]; pEnt; pEnt = pEnt->pNext ) - if ( !strcmp( pEnt->pName, pName ) ) - return pEnt; - pEnt = Ntl_ModelCreateNet( p, pName ); - pEnt->pNext = p->pTable[Key]; - p->pTable[Key] = pEnt; - if ( ++p->nEntries > 2 * p->nTableSize ) - Ntl_ModelTableResize( p ); - return pEnt; -} - -/**Function************************************************************* - - Synopsis [Creates new net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Net_t * Ntl_ModelDontFindCreateNet( Ntl_Mod_t * p, const char * pName ) -{ - Ntl_Net_t * pEnt; - unsigned Key = Ntl_HashString( pName, p->nTableSize ); - pEnt = Ntl_ModelCreateNet( p, pName ); - pEnt->pNext = p->pTable[Key]; - p->pTable[Key] = pEnt; - if ( ++p->nEntries > 2 * p->nTableSize ) - Ntl_ModelTableResize( p ); - return pEnt; -} - -/**Function************************************************************* - - Synopsis [Assigns numbers to PIs and POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelSetPioNumbers( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pObj; - int i; - Ntl_ModelForEachPi( p, pObj, i ) - pObj->iTemp = i; - Ntl_ModelForEachPo( p, pObj, i ) - pObj->iTemp = i; -} - -/**Function************************************************************* - - Synopsis [Returns -1, 0, +1 (when it is PI, not found, or PO).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelFindPioNumber_old( Ntl_Mod_t * p, int fPiOnly, int fPoOnly, const char * pName, int * pNumber ) -{ - Ntl_Net_t * pNet; - Ntl_Obj_t * pObj; - int i; - *pNumber = -1; - pNet = Ntl_ModelFindNet( p, pName ); - if ( pNet == NULL ) - return 0; - if ( fPiOnly ) - { - Ntl_ModelForEachPi( p, pObj, i ) - { - if ( Ntl_ObjFanout0(pObj) == pNet ) - { - *pNumber = i; - return -1; - } - } - return 0; - } - if ( fPoOnly ) - { - Ntl_ModelForEachPo( p, pObj, i ) - { - if ( Ntl_ObjFanin0(pObj) == pNet ) - { - *pNumber = i; - return 1; - } - } - return 0; - } - Ntl_ModelForEachPo( p, pObj, i ) - { - if ( Ntl_ObjFanin0(pObj) == pNet ) - { - *pNumber = i; - return 1; - } - } - Ntl_ModelForEachPi( p, pObj, i ) - { - if ( Ntl_ObjFanout0(pObj) == pNet ) - { - *pNumber = i; - return -1; - } - } - return 0; -} - -/**Function************************************************************* - - Synopsis [Returns -1, 0, +1 (when it is PI, not found, or PO).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelFindPioNumber( Ntl_Mod_t * p, int fPiOnly, int fPoOnly, const char * pName, int * pNumber ) -{ - Ntl_Net_t * pNet; - Ntl_Obj_t * pTerm; - *pNumber = -1; - pNet = Ntl_ModelFindNet( p, pName ); - if ( pNet == NULL ) - return 0; - if ( fPiOnly ) - { - pTerm = pNet->pDriver; - if ( pTerm && Ntl_ObjIsPi(pTerm) ) - { - *pNumber = pTerm->iTemp; - return -1; - } - return 0; - } - if ( fPoOnly ) - { - pTerm = (Ntl_Obj_t *)pNet->pCopy; - if ( pTerm && Ntl_ObjIsPo(pTerm) ) - { - *pNumber = pTerm->iTemp; - return 1; - } - return 0; - } - pTerm = (Ntl_Obj_t *)pNet->pCopy; - if ( pTerm && Ntl_ObjIsPo(pTerm) ) - { - *pNumber = pTerm->iTemp; - return 1; - } - pTerm = pNet->pDriver; - if ( pTerm && Ntl_ObjIsPi(pTerm) ) - { - *pNumber = pTerm->iTemp; - return -1; - } - return 0; -} - -/**Function************************************************************* - - Synopsis [Sets the driver of the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelSetNetDriver( Ntl_Obj_t * pObj, Ntl_Net_t * pNet ) -{ - if ( pObj->pFanio[pObj->nFanins] != NULL ) - return 0; - if ( pNet->pDriver != NULL ) - return 0; - pObj->pFanio[pObj->nFanins] = pNet; - pNet->pDriver = pObj; - return 1; -} - -/**Function************************************************************* - - Synopsis [Clears the driver of the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelClearNetDriver( Ntl_Obj_t * pObj, Ntl_Net_t * pNet ) -{ - if ( pObj->pFanio[pObj->nFanins] == NULL ) - return 0; - if ( pNet->pDriver == NULL ) - return 0; - pObj->pFanio[pObj->nFanins] = NULL; - pNet->pDriver = NULL; - return 1; -} - -/**Function************************************************************* - - Synopsis [Counts the number of nets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCountNets( Ntl_Mod_t * p ) -{ - Ntl_Net_t * pNet; - int i, Counter = 0; - Ntl_ModelForEachNet( p, pNet, i ) - Counter++; - return Counter; -} - - - - -/**Function************************************************************* - - Synopsis [Resizes the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManModelTableResize( Ntl_Man_t * p ) -{ - Ntl_Mod_t ** pModTableNew, ** ppSpot, * pEntry, * pEntry2; - int nModTableSizeNew, Counter, e, clk; -clk = clock(); - // get the new table size - nModTableSizeNew = Aig_PrimeCudd( 3 * p->nModTableSize ); - // allocate a new array - pModTableNew = ABC_ALLOC( Ntl_Mod_t *, nModTableSizeNew ); - memset( pModTableNew, 0, sizeof(Ntl_Mod_t *) * nModTableSizeNew ); - // rehash entries - Counter = 0; - for ( e = 0; e < p->nModTableSize; e++ ) - for ( pEntry = p->pModTable[e], pEntry2 = pEntry? pEntry->pNext : NULL; - pEntry; pEntry = pEntry2, pEntry2 = pEntry? pEntry->pNext : NULL ) - { - ppSpot = pModTableNew + Ntl_HashString( pEntry->pName, nModTableSizeNew ); - pEntry->pNext = *ppSpot; - *ppSpot = pEntry; - Counter++; - } - assert( Counter == p->nModEntries ); -// printf( "Increasing the structural table size from %6d to %6d. ", p->nTableSize, nTableSizeNew ); -// ABC_PRT( "Time", clock() - clk ); - // replace the table and the parameters - ABC_FREE( p->pModTable ); - p->pModTable = pModTableNew; - p->nModTableSize = nModTableSizeNew; -} - -/**Function************************************************************* - - Synopsis [Finds or creates the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManAddModel( Ntl_Man_t * p, Ntl_Mod_t * pModel ) -{ - Ntl_Mod_t * pEnt; - unsigned Key = Ntl_HashString( pModel->pName, p->nModTableSize ); - for ( pEnt = p->pModTable[Key]; pEnt; pEnt = pEnt->pNext ) - if ( !strcmp( pEnt->pName, pModel->pName ) ) - return 0; - pModel->pNext = p->pModTable[Key]; - p->pModTable[Key] = pModel; - if ( ++p->nModEntries > 2 * p->nModTableSize ) - Ntl_ManModelTableResize( p ); - Vec_PtrPush( p->vModels, pModel ); - return 1; -} - -/**Function************************************************************* - - Synopsis [Finds or creates the net.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Ntl_Mod_t * Ntl_ManFindModel( Ntl_Man_t * p, const char * pName ) -{ - Ntl_Mod_t * pEnt; - unsigned Key = Ntl_HashString( pName, p->nModTableSize ); - for ( pEnt = p->pModTable[Key]; pEnt; pEnt = pEnt->pNext ) - if ( !strcmp( pEnt->pName, pName ) ) - return pEnt; - return NULL; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlTime.c b/src/aig/ntl/ntlTime.c deleted file mode 100644 index 7a531482..00000000 --- a/src/aig/ntl/ntlTime.c +++ /dev/null @@ -1,245 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlTime.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Creates timing manager.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlTime.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -float * Ntl_ManCreateDelayTable( Vec_Int_t * vDelays, int nIns, int nOuts ) -{ - float * pDelayTable, Delay; - int iIn, iOut, i, k; - assert( Vec_IntSize(vDelays) % 3 == 0 ); - pDelayTable = ABC_ALLOC( float, nIns * nOuts ); - memset( pDelayTable, 0, sizeof(float) * nIns * nOuts ); - Vec_IntForEachEntry( vDelays, iIn, i ) - { - iOut = Vec_IntEntry(vDelays, ++i); - Delay = Aig_Int2Float( Vec_IntEntry(vDelays, ++i) ); - if ( iIn == -1 && iOut == -1 ) - for ( k = 0; k < nIns * nOuts; k++ ) - pDelayTable[k] = Delay; - else if ( iIn == -1 ) - for ( k = 0; k < nIns; k++ ) - pDelayTable[iOut * nIns + k] = Delay; - else if ( iOut == -1 ) - for ( k = 0; k < nOuts; k++ ) - pDelayTable[k * nIns + iIn] = Delay; - else - pDelayTable[iOut * nIns + iIn] = Delay; - } - return pDelayTable; -} - -/**Function************************************************************* - - Synopsis [Records the arrival times for the map leaves.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManUnpackLeafTiming( Ntl_Man_t * p, Tim_Man_t * pMan ) -{ - Vec_Int_t * vTimes; - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - float dTime; - int i, k, v, Entry, Counter; - // clean the place - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachMapLeaf( pRoot, pObj, i ) - Ntl_ObjForEachFanout( pObj, pNet, k ) - pNet->dTemp = 0; - // store the PI timing - vTimes = pRoot->vTimeInputs; - if ( vTimes ) { - Vec_IntForEachEntry( vTimes, Entry, i ) - { - dTime = Aig_Int2Float( Vec_IntEntry(vTimes,++i) ); - if ( Entry == -1 ) - { - Ntl_ModelForEachPi( pRoot, pObj, v ) - Ntl_ObjFanout0(pObj)->dTemp = dTime; - } - else - { - pObj = Ntl_ModelPi( pRoot, Entry ); - Ntl_ObjFanout0(pObj)->dTemp = dTime; - } - } - } - // store box timing - Ntl_ModelForEachMapLeaf( pRoot, pObj, k ) - { - if ( !(Ntl_ObjIsBox(pObj) && Ntl_BoxIsSeq(pObj)) ) - continue; - vTimes = pObj->pImplem->vTimeOutputs; - if ( vTimes == NULL ) - continue; - Vec_IntForEachEntry( vTimes, Entry, i ) - { - dTime = Aig_Int2Float( Vec_IntEntry(vTimes,++i) ); - if ( Entry == -1 ) - { - Ntl_ObjForEachFanout( pObj, pNet, v ) - pNet->dTemp = dTime; - } - else - { - pNet = Ntl_ObjFanout( pObj, Entry ); - pNet->dTemp = dTime; - } - } - } - // load them into the timing manager - Counter = 0; - Ntl_ModelForEachMapLeaf( pRoot, pObj, i ) - Ntl_ObjForEachFanout( pObj, pNet, k ) - { - if ( pNet->dTemp == TIM_ETERNITY ) - pNet->dTemp = -TIM_ETERNITY; - Tim_ManInitCiArrival( pMan, Counter++, pNet->dTemp ); - } - assert( Counter == p->iLastCi ); -} - -/**Function************************************************************* - - Synopsis [Records the required times for the map leaves.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManUnpackRootTiming( Ntl_Man_t * p, Tim_Man_t * pMan ) -{ -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Tim_Man_t * Ntl_ManCreateTiming( Ntl_Man_t * p ) -{ - Tim_Man_t * pMan; - Vec_Ptr_t * vDelayTables; - Ntl_Mod_t * pRoot, * pModel; - Ntl_Obj_t * pObj; - int i, curPi, iBox;//, Entry; - assert( p->pAig != NULL ); - pRoot = Ntl_ManRootModel( p ); - // start the timing manager - pMan = Tim_ManStart( Aig_ManPiNum(p->pAig), Aig_ManPoNum(p->pAig) ); - // unpack the timing data - Ntl_ManUnpackLeafTiming( p, pMan ); -// Ntl_ManUnpackRootTiming( p, pMan ); -/* - if ( pRoot->vTimeInputs ) - { - Vec_IntForEachEntry( pRoot->vTimeInputs, Entry, i ) - { - if ( Entry == -1 ) - Tim_ManSetCiArrivalAll( pMan, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeInputs,++i)) ); - else - Tim_ManInitCiArrival( pMan, Entry, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeInputs,++i)) ); - } - } - // unpack the data in the required times - if ( pRoot->vTimeOutputs ) - { - Vec_IntForEachEntry( pRoot->vTimeOutputs, Entry, i ) - { - if ( Entry == -1 ) - Tim_ManSetCoRequiredAll( pMan, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeOutputs,++i)) ); - else - Tim_ManInitCoRequired( pMan, Entry, Aig_Int2Float(Vec_IntEntry(pRoot->vTimeOutputs,++i)) ); - } - } -*/ - // derive timing tables for the whilte comb boxes - vDelayTables = Vec_PtrAlloc( Vec_PtrSize(p->vModels) ); - Ntl_ManForEachModel( p, pModel, i ) - { - if ( pModel->vDelays ) - pModel->pDelayTable = Ntl_ManCreateDelayTable( pModel->vDelays, Ntl_ModelPiNum(pModel), Ntl_ModelPoNum(pModel) ); - Vec_PtrPush( vDelayTables, pModel->pDelayTable ); - } - Tim_ManSetDelayTables( pMan, vDelayTables ); - // set up the boxes - iBox = 0; - curPi = p->iLastCi; - Vec_PtrForEachEntry( Ntl_Obj_t *, p->vVisNodes, pObj, i ) - { - if ( !Ntl_ObjIsBox(pObj) ) - continue; - Tim_ManCreateBoxFirst( pMan, Vec_IntEntry(p->vBox1Cios, iBox), Ntl_ObjFaninNum(pObj), curPi, Ntl_ObjFanoutNum(pObj), pObj->pImplem->pDelayTable ); - curPi += Ntl_ObjFanoutNum(pObj); - iBox++; - } - // forget refs to the delay tables in the network - Ntl_ManForEachModel( p, pModel, i ) - pModel->pDelayTable = NULL; -// Tim_ManPrint( pMan ); - return pMan; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlUtil.c b/src/aig/ntl/ntlUtil.c deleted file mode 100644 index c3c6fd49..00000000 --- a/src/aig/ntl/ntlUtil.c +++ /dev/null @@ -1,737 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlUtil.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [Various utilities.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Returns one if the file has a given extension.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_FileIsType( char * pFileName, char * pS1, char * pS2, char * pS3 ) -{ - int lenS, lenF = strlen(pFileName); - lenS = pS1 ? strlen(pS1) : 0; - if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS1, lenS ) ) - return 1; - lenS = pS2 ? strlen(pS2) : 0; - if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS2, lenS ) ) - return 1; - lenS = pS3 ? strlen(pS3) : 0; - if ( lenS && lenF > lenS && !strncmp( pFileName+lenF-lenS, pS3, lenS ) ) - return 1; - return 0; -} - -/**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.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCountSimpleCoDriversOne( Ntl_Net_t * pNetCo ) -{ - Ntl_Net_t * pNetFanin; - // skip the case when the net is not driven by a node - if ( !Ntl_ObjIsNode(pNetCo->pDriver) ) - return 0; - // skip the case when the node is not an inv/buf - if ( Ntl_ObjFaninNum(pNetCo->pDriver) != 1 ) - return 0; - // skip the case when the second-generation driver is not a node - pNetFanin = Ntl_ObjFanin0(pNetCo->pDriver); - if ( !Ntl_ObjIsNode(pNetFanin->pDriver) ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Counts COs that are connected to the internal nodes through invs/bufs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManCountSimpleCoDrivers( Ntl_Man_t * p ) -{ - Ntl_Net_t * pNetCo; - Ntl_Obj_t * pObj; - Ntl_Mod_t * pRoot; - int i, k, Counter; - Counter = 0; - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachPo( pRoot, pObj, i ) - Counter += Ntl_ManCountSimpleCoDriversOne( Ntl_ObjFanin0(pObj) ); - Ntl_ModelForEachLatch( pRoot, pObj, i ) - Counter += Ntl_ManCountSimpleCoDriversOne( Ntl_ObjFanin0(pObj) ); - Ntl_ModelForEachBox( pRoot, pObj, i ) - Ntl_ObjForEachFanin( pObj, pNetCo, k ) - Counter += Ntl_ManCountSimpleCoDriversOne( pNetCo ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Derives the array of CI names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_ManCollectCiNames( Ntl_Man_t * p ) -{ - Vec_Ptr_t * vNames; - Ntl_Net_t * pNet; - int i; - vNames = Vec_PtrAlloc( 1000 ); - Ntl_ManForEachCiNet( p, pNet, i ) - Vec_PtrPush( vNames, pNet->pName ); - return vNames; -} - -/**Function************************************************************* - - Synopsis [Derives the array of CI names.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Ntl_ManCollectCoNames( Ntl_Man_t * p ) -{ - Vec_Ptr_t * vNames; - Ntl_Net_t * pNet; - int i; - vNames = Vec_PtrAlloc( 1000 ); - Ntl_ManForEachCoNet( p, pNet, i ) - Vec_PtrPush( vNames, pNet->pName ); - return vNames; -} - -/**Function************************************************************* - - Synopsis [Marks the CI/CO nets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManMarkCiCoNets( Ntl_Man_t * p ) -{ - Ntl_Net_t * pNet; - int i; - Ntl_ManForEachCiNet( p, pNet, i ) - pNet->fMark = 1; - Ntl_ManForEachCoNet( p, pNet, i ) - pNet->fMark = 1; -} - -/**Function************************************************************* - - Synopsis [Unmarks the CI/CO nets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManUnmarkCiCoNets( Ntl_Man_t * p ) -{ - Ntl_Net_t * pNet; - int i; - Ntl_ManForEachCiNet( p, pNet, i ) - pNet->fMark = 0; - Ntl_ManForEachCoNet( p, pNet, i ) - pNet->fMark = 0; -} - -/**Function************************************************************* - - Synopsis [Convert initial values of registers to be zero.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManSetZeroInitValues( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i; - pRoot = Ntl_ManRootModel(p); - Ntl_ModelForEachLatch( pRoot, pObj, i ) - pObj->LatchId.regInit = 0; -} - -/**Function************************************************************* - - Synopsis [Transforms the netlist to have latches with const-0 init-values.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManAddInverters( Ntl_Mod_t * pRoot, Ntl_Obj_t * pObj ) -{ - char * pStore; -// Ntl_Mod_t * pRoot = pObj->pModel; - Ntl_Man_t * pMan = pRoot->pMan; - Ntl_Net_t * pNetLo, * pNetLi, * pNetLoInv, * pNetLiInv; - Ntl_Obj_t * pNode; - int nLength, RetValue; - assert( Ntl_ObjIsInit1( pObj ) ); - // get the nets - pNetLi = Ntl_ObjFanin0(pObj); - pNetLo = Ntl_ObjFanout0(pObj); - // get storage for net names - nLength = strlen(pNetLi->pName) + strlen(pNetLo->pName) + 10; - pStore = Aig_MmFlexEntryFetch( pMan->pMemSops, nLength ); - // create input interter - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = Ntl_ManStoreSop( pMan->pMemSops, "0 1\n" ); - Ntl_ObjSetFanin( pNode, pNetLi, 0 ); - // create input net - strcpy( pStore, pNetLi->pName ); - strcat( pStore, "_inv" ); - if ( Ntl_ModelFindNet( pRoot, pStore ) ) - { - printf( "Ntl_ManTransformInitValues(): Internal error! Cannot create net with LI-name + _inv\n" ); - return; - } - pNetLiInv = Ntl_ModelFindOrCreateNet( pRoot, pStore ); - RetValue = Ntl_ModelSetNetDriver( pNode, pNetLiInv ); - assert( RetValue ); - // connect latch to the input net - Ntl_ObjSetFanin( pObj, pNetLiInv, 0 ); - // disconnect latch from the output net - RetValue = Ntl_ModelClearNetDriver( pObj, pNetLo ); - assert( RetValue ); - // create the output net - strcpy( pStore, pNetLo->pName ); - strcat( pStore, "_inv" ); - if ( Ntl_ModelFindNet( pRoot, pStore ) ) - { - printf( "Ntl_ManTransformInitValues(): Internal error! Cannot create net with LO-name + _inv\n" ); - return; - } - pNetLoInv = Ntl_ModelFindOrCreateNet( pRoot, pStore ); - RetValue = Ntl_ModelSetNetDriver( pObj, pNetLoInv ); - assert( RetValue ); - // create output interter - pNode = Ntl_ModelCreateNode( pRoot, 1 ); - pNode->pSop = Ntl_ManStoreSop( pMan->pMemSops, "0 1\n" ); - Ntl_ObjSetFanin( pNode, pNetLoInv, 0 ); - // redirect the old output net - RetValue = Ntl_ModelSetNetDriver( pNode, pNetLo ); - assert( RetValue ); -} - -/**Function************************************************************* - - Synopsis [Transforms the netlist to have latches with const-0 init-values.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManTransformInitValues( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i; - pRoot = Ntl_ManRootModel(p); - Ntl_ModelForEachLatch( pRoot, pObj, i ) - { - if ( Ntl_ObjIsInit1( pObj ) ) - Ntl_ManAddInverters( pRoot, pObj ); - pObj->LatchId.regInit = 0; - } -} - -/**Function************************************************************* - - Synopsis [Transforms register classes.] - - Description [Returns the vector of vectors containing the numbers - of registers belonging to the same class. Skips classes containing - less than the given number of registers.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Vec_t * Ntl_ManTransformRegClasses( Ntl_Man_t * pMan, int nSizeMax, int fVerbose ) -{ - Vec_Ptr_t * vParts; - Vec_Int_t * vPart; - int * pClassNums, nClasses; - int Class, ClassMax, i, k; - if ( Vec_IntSize(pMan->vRegClasses) == 0 ) - { - printf( "Ntl_ManReportRegClasses(): Register classes are not defined.\n" ); -// return (Vec_Vec_t *)Vec_PtrAlloc(0); - return NULL; - } - // find the largest class - ClassMax = -1; - Vec_IntForEachEntry( pMan->vRegClasses, Class, k ) - { - if ( Class < 0 ) - { - printf( "Ntl_ManReportRegClasses(): Register class (%d) is negative.\n", Class ); - return NULL; - } - if ( ClassMax < Class ) - ClassMax = Class; - } - if ( ClassMax > 1000000 ) - { - printf( "Ntl_ManReportRegClasses(): The largest number of a register class (%d) is too large (> 1000000).\n", ClassMax ); - return NULL; - } - // count the number of classes - pClassNums = ABC_CALLOC( int, ClassMax + 1 ); - Vec_IntForEachEntry( pMan->vRegClasses, Class, k ) - pClassNums[Class]++; - // count the number of classes - nClasses = 0; - for ( i = 0; i <= ClassMax; i++ ) - nClasses += (int)(pClassNums[i] > 0); - // report the classes - if ( fVerbose && nClasses > 1 ) - { - printf( "The number of register clases = %d.\n", nClasses ); - for ( i = 0; i <= ClassMax; i++ ) - if ( pClassNums[i] ) - printf( "(%d, %d) ", i, pClassNums[i] ); - printf( "\n" ); - } - // skip if there is only one class - if ( nClasses == 1 ) - { - vParts = NULL; - if ( Vec_IntSize(pMan->vRegClasses) >= nSizeMax ) - { - vParts = Vec_PtrAlloc( 100 ); - vPart = Vec_IntStartNatural( Vec_IntSize(pMan->vRegClasses) ); - Vec_PtrPush( vParts, vPart ); - } - printf( "There is only one class with %d registers.\n", Vec_IntSize(pMan->vRegClasses) ); - ABC_FREE( pClassNums ); - return (Vec_Vec_t *)vParts; - } - // create classes - vParts = Vec_PtrAlloc( 100 ); - for ( i = 0; i <= ClassMax; i++ ) - { - if ( pClassNums[i] == 0 || pClassNums[i] < nSizeMax ) - continue; - vPart = Vec_IntAlloc( pClassNums[i] ); - Vec_IntForEachEntry( pMan->vRegClasses, Class, k ) - if ( Class == i ) - Vec_IntPush( vPart, k ); - assert( Vec_IntSize(vPart) == pClassNums[i] ); - Vec_PtrPush( vParts, vPart ); - } - ABC_FREE( pClassNums ); - Vec_VecSort( (Vec_Vec_t *)vParts, 1 ); - // report the selected classes - if ( fVerbose ) - { - printf( "The number of selected register clases = %d.\n", Vec_PtrSize(vParts) ); - Vec_PtrForEachEntry( Vec_Int_t *, vParts, vPart, i ) - printf( "(%d, %d) ", i, Vec_IntSize(vPart) ); - printf( "\n" ); - } - return (Vec_Vec_t *)vParts; -} - -/**Function************************************************************* - - Synopsis [Filter register clases using clock-domain information.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManFilterRegisterClasses( Aig_Man_t * pAig, Vec_Int_t * vRegClasses, int fVerbose ) -{ - Aig_Obj_t * pObj, * pRepr; - int i, k, nOmitted, nTotal; - if ( pAig->pReprs == NULL ) - return; - assert( pAig->nRegs > 0 ); - Aig_ManForEachPi( pAig, pObj, i ) - pObj->PioNum = -1; - k = 0; - Aig_ManForEachLoSeq( pAig, pObj, i ) - pObj->PioNum = k++; - // consider equivalences - nOmitted = nTotal = 0; - Aig_ManForEachObj( pAig, pObj, i ) - { - pRepr = pAig->pReprs[pObj->Id]; - if ( pRepr == NULL ) - continue; - nTotal++; - assert( Aig_ObjIsPi(pObj) ); - assert( Aig_ObjIsPi(pRepr) || Aig_ObjIsConst1(pRepr) ); - if ( Aig_ObjIsConst1(pRepr) ) - continue; - assert( pObj->PioNum >= 0 && pRepr->PioNum >= 0 ); - // remove equivalence if they belong to different classes - if ( Vec_IntEntry( vRegClasses, pObj->PioNum ) == - Vec_IntEntry( vRegClasses, pRepr->PioNum ) ) - continue; - pAig->pReprs[pObj->Id] = NULL; - nOmitted++; - } - Aig_ManForEachPi( pAig, pObj, i ) - pObj->PioNum = -1; - if ( fVerbose ) - printf( "Omitted %d (out of %d) equivs due to register class mismatch.\n", - nOmitted, nTotal ); -} - - -/**Function************************************************************* - - Synopsis [Counts the number of CIs in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManLatchNum( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pObj; - int i, Counter = 0; - pRoot = Ntl_ManRootModel(p); - Ntl_ModelForEachBox( pRoot, pObj, i ) - Counter += Ntl_ModelLatchNum( pObj->pImplem ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Returns 1 if the design is combinational.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ManIsComb( Ntl_Man_t * p ) -{ - return Ntl_ManLatchNum(p) == 0; -} - -/**Function************************************************************* - - Synopsis [Counts the number of CIs in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCombLeafNum( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pObj; - int i, Counter = 0; - Ntl_ModelForEachCombLeaf( p, pObj, i ) - Counter += Ntl_ObjFanoutNum( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the number of COs in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCombRootNum( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pObj; - int i, Counter = 0; - Ntl_ModelForEachCombRoot( p, pObj, i ) - Counter += Ntl_ObjFaninNum( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the number of CIs in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelSeqLeafNum( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pObj; - int i, Counter = 0; - Ntl_ModelForEachSeqLeaf( p, pObj, i ) - Counter += Ntl_ObjFanoutNum( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the number of COs in the model.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelSeqRootNum( Ntl_Mod_t * p ) -{ - Ntl_Obj_t * pObj; - int i, Counter = 0; - Ntl_ModelForEachSeqRoot( p, pObj, i ) - Counter += Ntl_ObjFaninNum( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Unmarks the CI/CO nets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Ntl_ModelCheckNetsAreNotMarked( Ntl_Mod_t * pModel ) -{ - Ntl_Net_t * pNet; - int i; - Ntl_ModelForEachNet( pModel, pNet, i ) - assert( pNet->fMark == 0 ); - return 1; -} - -/**Function************************************************************* - - Synopsis [Unmarks the CI/CO nets.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ModelClearNets( Ntl_Mod_t * pModel ) -{ - Ntl_Net_t * pNet; - int i; - Ntl_ModelForEachNet( pModel, pNet, i ) - { - pNet->nVisits = pNet->fMark = 0; - pNet->pCopy = pNet->pCopy2 = NULL; - } -} - -/**Function************************************************************* - - Synopsis [Removes nets without fanins and fanouts.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManRemoveUselessNets( Ntl_Man_t * p ) -{ - Ntl_Mod_t * pRoot; - Ntl_Obj_t * pNode; - Ntl_Net_t * pNet; - int i, k, Counter; - pRoot = Ntl_ManRootModel( p ); - Ntl_ModelForEachNet( pRoot, pNet, i ) - pNet->fMark = 0; - Ntl_ModelForEachPi( pRoot, pNode, i ) - { - pNet = Ntl_ObjFanout0(pNode); - pNet->fMark = 1; - } - Ntl_ModelForEachPo( pRoot, pNode, i ) - { - pNet = Ntl_ObjFanin0(pNode); - pNet->fMark = 1; - } - Ntl_ModelForEachNode( pRoot, pNode, i ) - { - Ntl_ObjForEachFanin( pNode, pNet, k ) - pNet->fMark = 1; - Ntl_ObjForEachFanout( pNode, pNet, k ) - pNet->fMark = 1; - } - Ntl_ModelForEachBox( pRoot, pNode, i ) - { - Ntl_ObjForEachFanin( pNode, pNet, k ) - pNet->fMark = 1; - Ntl_ObjForEachFanout( pNode, pNet, k ) - pNet->fMark = 1; - } - Counter = 0; - Ntl_ModelForEachNet( pRoot, pNet, i ) - { - if ( pNet->fMark ) - { - pNet->fMark = 0; - continue; - } - if ( pNet->fFixed ) - continue; - Ntl_ModelDeleteNet( pRoot, pNet ); - Vec_PtrWriteEntry( pRoot->vNets, pNet->NetId, NULL ); - Counter++; - } - if ( Counter ) - printf( "Deleted %d nets without fanins/fanouts.\n", Counter ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlWriteBlif.c b/src/aig/ntl/ntlWriteBlif.c deleted file mode 100644 index f9b2781f..00000000 --- a/src/aig/ntl/ntlWriteBlif.c +++ /dev/null @@ -1,697 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlWriteBlif.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Command processing package.] - - Synopsis [Procedures to write BLIF files.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlWriteBlif.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -// The code in this file is developed in collaboration with Mark Jarvin of Toronto. - -#include "ntl.h" -#include "ioa.h" - -#include <stdarg.h> -#include "bzlib.h" -#include "zlib.h" - -ABC_NAMESPACE_IMPL_START - - -#ifdef _WIN32 -#define vsnprintf _vsnprintf -#endif - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Writes one model into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlifModel( FILE * pFile, Ntl_Mod_t * pModel, int fMain ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - float Delay; - int i, k; - fprintf( pFile, ".model %s\n", pModel->pName ); - if ( pModel->attrWhite || pModel->attrBox || pModel->attrComb || pModel->attrKeep ) - { - fprintf( pFile, ".attrib" ); - fprintf( pFile, " %s", pModel->attrWhite? "white": "black" ); - fprintf( pFile, " %s", pModel->attrBox? "box" : "logic" ); - fprintf( pFile, " %s", pModel->attrComb? "comb" : "seq" ); -// fprintf( pFile, " %s", pModel->attrKeep? "keep" : "sweep" ); - fprintf( pFile, "\n" ); - } - if ( pModel->attrNoMerge ) - fprintf( pFile, ".no_merge\n" ); - fprintf( pFile, ".inputs" ); - Ntl_ModelForEachPi( pModel, pObj, i ) - fprintf( pFile, " %s", Ntl_ObjFanout0(pObj)->pName ); - fprintf( pFile, "\n" ); - fprintf( pFile, ".outputs" ); - Ntl_ModelForEachPo( pModel, pObj, i ) - fprintf( pFile, " %s", Ntl_ObjFanin0(pObj)->pName ); - fprintf( pFile, "\n" ); - // write delays - if ( pModel->vDelays ) - { - for ( i = 0; i < Vec_IntSize(pModel->vDelays); i += 3 ) - { - fprintf( pFile, ".delay" ); - if ( Vec_IntEntry(pModel->vDelays,i) != -1 ) - fprintf( pFile, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vDelays,i)))->pName ); - if ( Vec_IntEntry(pModel->vDelays,i+1) != -1 ) - fprintf( pFile, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vDelays,i+1)))->pName ); - fprintf( pFile, " %.3f", Aig_Int2Float(Vec_IntEntry(pModel->vDelays,i+2)) ); - fprintf( pFile, "\n" ); - } - } - if ( pModel->vTimeInputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeInputs); i += 2 ) - { - if ( fMain ) - fprintf( pFile, ".input_arrival" ); - else - fprintf( pFile, ".input_required" ); - if ( Vec_IntEntry(pModel->vTimeInputs,i) != -1 ) - fprintf( pFile, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vTimeInputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeInputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - fprintf( pFile, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - fprintf( pFile, " inf" ); - else - fprintf( pFile, " %.3f", Delay ); - fprintf( pFile, "\n" ); - } - } - if ( pModel->vTimeOutputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeOutputs); i += 2 ) - { - if ( fMain ) - fprintf( pFile, ".output_required" ); - else - fprintf( pFile, ".output_arrival" ); - if ( Vec_IntEntry(pModel->vTimeOutputs,i) != -1 ) - fprintf( pFile, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vTimeOutputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeOutputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - fprintf( pFile, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - fprintf( pFile, " inf" ); - else - fprintf( pFile, " %.3f", Delay ); - fprintf( pFile, "\n" ); - } - } - // write objects - Ntl_ModelForEachObj( pModel, pObj, i ) - { - if ( Ntl_ObjIsNode(pObj) ) - { - fprintf( pFile, ".names" ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - fprintf( pFile, " %s", pNet->pName ); - fprintf( pFile, " %s\n", Ntl_ObjFanout0(pObj)->pName ); - fprintf( pFile, "%s", pObj->pSop ); - if ( *pObj->pSop == '\"' ) - fprintf( pFile, "\n" ); - } - else if ( Ntl_ObjIsLatch(pObj) ) - { - fprintf( pFile, ".latch" ); - fprintf( pFile, " %s", Ntl_ObjFanin0(pObj)->pName ); - fprintf( pFile, " %s", Ntl_ObjFanout0(pObj)->pName ); - assert( pObj->LatchId.regType == 0 || pObj->LatchId.regClass == 0 ); - if ( pObj->LatchId.regType ) - { - if ( pObj->LatchId.regType == 1 ) - fprintf( pFile, " fe" ); - else if ( pObj->LatchId.regType == 2 ) - fprintf( pFile, " re" ); - else if ( pObj->LatchId.regType == 3 ) - fprintf( pFile, " ah" ); - else if ( pObj->LatchId.regType == 4 ) - fprintf( pFile, " al" ); - else if ( pObj->LatchId.regType == 5 ) - fprintf( pFile, " as" ); - else - assert( 0 ); - } - else if ( pObj->LatchId.regClass ) - fprintf( pFile, " %d", pObj->LatchId.regClass ); - if ( pObj->pClock ) - fprintf( pFile, " %s", pObj->pClock->pName ); - fprintf( pFile, " %d", pObj->LatchId.regInit ); - fprintf( pFile, "\n" ); - } - else if ( Ntl_ObjIsBox(pObj) ) - { - fprintf( pFile, ".subckt %s", pObj->pImplem->pName ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - fprintf( pFile, " %s=%s", Ntl_ModelPiName(pObj->pImplem, k), pNet->pName ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - fprintf( pFile, " %s=%s", Ntl_ModelPoName(pObj->pImplem, k), pNet->pName ); - fprintf( pFile, "\n" ); - } - } - fprintf( pFile, ".end\n\n" ); -} - -/**Function************************************************************* - - Synopsis [Writes the netlist into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlif_old( Ntl_Man_t * p, char * pFileName ) -{ - FILE * pFile; - Ntl_Mod_t * pModel; - int i; - // start the output stream - pFile = fopen( pFileName, "w" ); - if ( pFile == NULL ) - { - fprintf( stdout, "Ntl_ManWriteBlif(): Cannot open the output file \"%s\".\n", pFileName ); - return; - } - fprintf( pFile, "# Benchmark \"%s\" written by ABC-8 on %s\n", p->pName, Aig_TimeStamp() ); - // write the models - Ntl_ManForEachModel( p, pModel, i ) - Ntl_ManWriteBlifModel( pFile, pModel, i==0 ); - // close the file - fclose( pFile ); -} - -/**Function************************************************************* - - Synopsis [Writes the logic network into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlifLogic( Nwk_Man_t * pNtk, Ntl_Man_t * p, char * pFileName ) -{ - Ntl_Man_t * pNew; - pNew = Ntl_ManInsertNtk( p, pNtk ); - Ntl_ManWriteBlif( pNew, pFileName ); - Ntl_ManFree( pNew ); -} - - - -/**Function************************************************************* - - Synopsis [Procedure to write data into BZ2 file.] - - Description [Based on the vsnprintf() man page.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -typedef struct bz2file { - FILE * f; - BZFILE * b; - char * buf; - int nBytes; - int nBytesMax; -} bz2file; - -int fprintfBz2(bz2file * b, char * fmt, ...) { - if (b->b) { - char * newBuf; - int bzError; - va_list ap; - while (1) { - va_start(ap,fmt); - b->nBytes = vsnprintf(b->buf,b->nBytesMax,fmt,ap); - va_end(ap); - if (b->nBytes > -1 && b->nBytes < b->nBytesMax) - break; - if (b->nBytes > -1) - b->nBytesMax = b->nBytes + 1; - else - b->nBytesMax *= 2; - if ((newBuf = ABC_REALLOC( char,b->buf,b->nBytesMax )) == NULL) - return -1; - else - b->buf = newBuf; - } - BZ2_bzWrite( &bzError, b->b, b->buf, b->nBytes ); - if (bzError == BZ_IO_ERROR) { - fprintf( stdout, "Ntl_ManWriteBlif(): I/O error writing to compressed stream.\n" ); - return -1; - } - return b->nBytes; - } else { - int n; - va_list ap; - va_start(ap,fmt); - n = vfprintf( b->f, fmt, ap); - va_end(ap); - return n; - } -} - -/**Function************************************************************* - - Synopsis [Writes one model into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlifModelGz( gzFile pFile, Ntl_Mod_t * pModel, int fMain ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - float Delay; - int i, k; - gzprintf( pFile, ".model %s\n", pModel->pName ); - if ( pModel->attrWhite || pModel->attrBox || pModel->attrComb || pModel->attrKeep ) - { - gzprintf( pFile, ".attrib" ); - gzprintf( pFile, " %s", pModel->attrWhite? "white": "black" ); - gzprintf( pFile, " %s", pModel->attrBox? "box" : "logic" ); - gzprintf( pFile, " %s", pModel->attrComb? "comb" : "seq" ); -// gzprintf( pFile, " %s", pModel->attrKeep? "keep" : "sweep" ); - gzprintf( pFile, "\n" ); - } - if ( pModel->attrNoMerge ) - gzprintf( pFile, ".no_merge\n" ); - gzprintf( pFile, ".inputs" ); - Ntl_ModelForEachPi( pModel, pObj, i ) - gzprintf( pFile, " %s", Ntl_ObjFanout0(pObj)->pName ); - gzprintf( pFile, "\n" ); - gzprintf( pFile, ".outputs" ); - Ntl_ModelForEachPo( pModel, pObj, i ) - gzprintf( pFile, " %s", Ntl_ObjFanin0(pObj)->pName ); - gzprintf( pFile, "\n" ); - // write delays - if ( pModel->vDelays ) - { - for ( i = 0; i < Vec_IntSize(pModel->vDelays); i += 3 ) - { - gzprintf( pFile, ".delay" ); - if ( Vec_IntEntry(pModel->vDelays,i) != -1 ) - gzprintf( pFile, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vDelays,i)))->pName ); - if ( Vec_IntEntry(pModel->vDelays,i+1) != -1 ) - gzprintf( pFile, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vDelays,i+1)))->pName ); - gzprintf( pFile, " %.3f", Aig_Int2Float(Vec_IntEntry(pModel->vDelays,i+2)) ); - gzprintf( pFile, "\n" ); - } - } - if ( pModel->vTimeInputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeInputs); i += 2 ) - { - if ( fMain ) - gzprintf( pFile, ".input_arrival" ); - else - gzprintf( pFile, ".input_required" ); - if ( Vec_IntEntry(pModel->vTimeInputs,i) != -1 ) - gzprintf( pFile, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vTimeInputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeInputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - gzprintf( pFile, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - gzprintf( pFile, " inf" ); - else - gzprintf( pFile, " %.3f", Delay ); - gzprintf( pFile, "\n" ); - } - } - if ( pModel->vTimeOutputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeOutputs); i += 2 ) - { - if ( fMain ) - gzprintf( pFile, ".output_required" ); - else - gzprintf( pFile, ".output_arrival" ); - if ( Vec_IntEntry(pModel->vTimeOutputs,i) != -1 ) - gzprintf( pFile, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vTimeOutputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeOutputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - gzprintf( pFile, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - gzprintf( pFile, " inf" ); - else - gzprintf( pFile, " %.3f", Delay ); - gzprintf( pFile, "\n" ); - } - } - // write objects - Ntl_ModelForEachObj( pModel, pObj, i ) - { - if ( Ntl_ObjIsNode(pObj) ) - { - gzprintf( pFile, ".names" ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - gzprintf( pFile, " %s", pNet->pName ); - gzprintf( pFile, " %s\n", Ntl_ObjFanout0(pObj)->pName ); - gzprintf( pFile, "%s", pObj->pSop ); - if ( *pObj->pSop == '\"' ) - gzprintf( pFile, "\n" ); - } - else if ( Ntl_ObjIsLatch(pObj) ) - { - gzprintf( pFile, ".latch" ); - gzprintf( pFile, " %s", Ntl_ObjFanin0(pObj)->pName ); - gzprintf( pFile, " %s", Ntl_ObjFanout0(pObj)->pName ); - assert( pObj->LatchId.regType == 0 || pObj->LatchId.regClass == 0 ); - if ( pObj->LatchId.regType ) - { - if ( pObj->LatchId.regType == 1 ) - gzprintf( pFile, " fe" ); - else if ( pObj->LatchId.regType == 2 ) - gzprintf( pFile, " re" ); - else if ( pObj->LatchId.regType == 3 ) - gzprintf( pFile, " ah" ); - else if ( pObj->LatchId.regType == 4 ) - gzprintf( pFile, " al" ); - else if ( pObj->LatchId.regType == 5 ) - gzprintf( pFile, " as" ); - else - assert( 0 ); - } - else if ( pObj->LatchId.regClass ) - gzprintf( pFile, " %d", pObj->LatchId.regClass ); - if ( pObj->pClock ) - gzprintf( pFile, " %s", pObj->pClock->pName ); - gzprintf( pFile, " %d", pObj->LatchId.regInit ); - gzprintf( pFile, "\n" ); - } - else if ( Ntl_ObjIsBox(pObj) ) - { - gzprintf( pFile, ".subckt %s", pObj->pImplem->pName ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - gzprintf( pFile, " %s=%s", Ntl_ModelPiName(pObj->pImplem, k), pNet->pName ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - gzprintf( pFile, " %s=%s", Ntl_ModelPoName(pObj->pImplem, k), pNet->pName ); - gzprintf( pFile, "\n" ); - } - } - gzprintf( pFile, ".end\n\n" ); -} - -/**Function************************************************************* - - Synopsis [Writes the logic network into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlifGz( Ntl_Man_t * p, char * pFileName ) -{ - Ntl_Mod_t * pModel; - int i; - gzFile pFile; - - // start the output stream - pFile = gzopen( pFileName, "wb" ); // if pFileName doesn't end in ".gz" then this acts as a passthrough to fopen - if ( pFile == NULL ) - { - fprintf( stdout, "Ntl_ManWriteBlif(): Cannot open the output file \"%s\".\n", pFileName ); - return; - } - - gzprintf( pFile, "# Benchmark \"%s\" written by ABC-8 on %s\n", p->pName, Aig_TimeStamp() ); - // write the models - Ntl_ManForEachModel( p, pModel, i ) - Ntl_ManWriteBlifModelGz( pFile, pModel, i==0 ); - // close the file - gzclose( pFile ); -} - - -/**Function************************************************************* - - Synopsis [Writes one model into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlifModelBz2( bz2file * b, Ntl_Mod_t * pModel, int fMain ) -{ - Ntl_Obj_t * pObj; - Ntl_Net_t * pNet; - float Delay; - int i, k; - fprintfBz2( b, ".model %s\n", pModel->pName ); - if ( pModel->attrWhite || pModel->attrBox || pModel->attrComb || pModel->attrKeep ) - { - fprintfBz2( b, ".attrib" ); - fprintfBz2( b, " %s", pModel->attrWhite? "white": "black" ); - fprintfBz2( b, " %s", pModel->attrBox? "box" : "logic" ); - fprintfBz2( b, " %s", pModel->attrComb? "comb" : "seq" ); -// fprintfBz2( b, " %s", pModel->attrKeep? "keep" : "sweep" ); - fprintfBz2( b, "\n" ); - } - if ( pModel->attrNoMerge ) - fprintfBz2( b, ".no_merge\n" ); - fprintfBz2( b, ".inputs" ); - Ntl_ModelForEachPi( pModel, pObj, i ) - fprintfBz2( b, " %s", Ntl_ObjFanout0(pObj)->pName ); - fprintfBz2( b, "\n" ); - fprintfBz2( b, ".outputs" ); - Ntl_ModelForEachPo( pModel, pObj, i ) - fprintfBz2( b, " %s", Ntl_ObjFanin0(pObj)->pName ); - fprintfBz2( b, "\n" ); - // write delays - if ( pModel->vDelays ) - { - for ( i = 0; i < Vec_IntSize(pModel->vDelays); i += 3 ) - { - fprintfBz2( b, ".delay" ); - if ( Vec_IntEntry(pModel->vDelays,i) != -1 ) - fprintfBz2( b, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vDelays,i)))->pName ); - if ( Vec_IntEntry(pModel->vDelays,i+1) != -1 ) - fprintfBz2( b, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vDelays,i+1)))->pName ); - fprintfBz2( b, " %.3f", Aig_Int2Float(Vec_IntEntry(pModel->vDelays,i+2)) ); - fprintfBz2( b, "\n" ); - } - } - if ( pModel->vTimeInputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeInputs); i += 2 ) - { - if ( fMain ) - fprintfBz2( b, ".input_arrival" ); - else - fprintfBz2( b, ".input_required" ); - if ( Vec_IntEntry(pModel->vTimeInputs,i) != -1 ) - fprintfBz2( b, " %s", Ntl_ObjFanout0(Ntl_ModelPi(pModel, Vec_IntEntry(pModel->vTimeInputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeInputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - fprintfBz2( b, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - fprintfBz2( b, " inf" ); - else - fprintfBz2( b, " %.3f", Delay ); - fprintfBz2( b, "\n" ); - } - } - if ( pModel->vTimeOutputs ) - { - for ( i = 0; i < Vec_IntSize(pModel->vTimeOutputs); i += 2 ) - { - if ( fMain ) - fprintfBz2( b, ".output_required" ); - else - fprintfBz2( b, ".output_arrival" ); - if ( Vec_IntEntry(pModel->vTimeOutputs,i) != -1 ) - fprintfBz2( b, " %s", Ntl_ObjFanin0(Ntl_ModelPo(pModel, Vec_IntEntry(pModel->vTimeOutputs,i)))->pName ); - Delay = Aig_Int2Float(Vec_IntEntry(pModel->vTimeOutputs,i+1)); - if ( Delay == -TIM_ETERNITY ) - fprintfBz2( b, " -inf" ); - else if ( Delay == TIM_ETERNITY ) - fprintfBz2( b, " inf" ); - else - fprintfBz2( b, " %.3f", Delay ); - fprintfBz2( b, "\n" ); - } - } - // write objects - Ntl_ModelForEachObj( pModel, pObj, i ) - { - if ( Ntl_ObjIsNode(pObj) ) - { - fprintfBz2( b, ".names" ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - fprintfBz2( b, " %s", pNet->pName ); - fprintfBz2( b, " %s\n", Ntl_ObjFanout0(pObj)->pName ); - fprintfBz2( b, "%s", pObj->pSop ); - if ( *pObj->pSop == '\"' ) - fprintfBz2( b, "\n" ); - } - else if ( Ntl_ObjIsLatch(pObj) ) - { - fprintfBz2( b, ".latch" ); - fprintfBz2( b, " %s", Ntl_ObjFanin0(pObj)->pName ); - fprintfBz2( b, " %s", Ntl_ObjFanout0(pObj)->pName ); - assert( pObj->LatchId.regType == 0 || pObj->LatchId.regClass == 0 ); - if ( pObj->LatchId.regType ) - { - if ( pObj->LatchId.regType == 1 ) - fprintfBz2( b, " fe" ); - else if ( pObj->LatchId.regType == 2 ) - fprintfBz2( b, " re" ); - else if ( pObj->LatchId.regType == 3 ) - fprintfBz2( b, " ah" ); - else if ( pObj->LatchId.regType == 4 ) - fprintfBz2( b, " al" ); - else if ( pObj->LatchId.regType == 5 ) - fprintfBz2( b, " as" ); - else - assert( 0 ); - } - else if ( pObj->LatchId.regClass ) - fprintfBz2( b, " %d", pObj->LatchId.regClass ); - if ( pObj->pClock ) - fprintfBz2( b, " %s", pObj->pClock->pName ); - fprintfBz2( b, " %d", pObj->LatchId.regInit ); - fprintfBz2( b, "\n" ); - } - else if ( Ntl_ObjIsBox(pObj) ) - { - fprintfBz2( b, ".subckt %s", pObj->pImplem->pName ); - Ntl_ObjForEachFanin( pObj, pNet, k ) - fprintfBz2( b, " %s=%s", Ntl_ModelPiName(pObj->pImplem, k), pNet->pName ); - Ntl_ObjForEachFanout( pObj, pNet, k ) - fprintfBz2( b, " %s=%s", Ntl_ModelPoName(pObj->pImplem, k), pNet->pName ); - fprintfBz2( b, "\n" ); - } - } - fprintfBz2( b, ".end\n\n" ); -} - -/**Function************************************************************* - - Synopsis [Writes the logic network into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Ntl_ManWriteBlif( Ntl_Man_t * p, char * pFileName ) -{ - Ntl_Mod_t * pModel; - int i, bzError; - bz2file b; - if ( p->pNal && !Ntl_FileIsType(pFileName, ".blif", ".blif.gz", ".blif.bz2") ) - { - p->pNalW( p, pFileName ); - return; - } - // write the GZ file - if (!strncmp(pFileName+strlen(pFileName)-3,".gz",3)) - { - Ntl_ManWriteBlifGz( p, pFileName ); - return; - } - - memset(&b,0,sizeof(b)); - b.nBytesMax = (1<<12); - b.buf = ABC_ALLOC( char,b.nBytesMax ); - - // start the output stream - b.f = fopen( pFileName, "wb" ); - if ( b.f == NULL ) - { - fprintf( stdout, "Ntl_ManWriteBlif(): Cannot open the output file \"%s\".\n", pFileName ); - ABC_FREE(b.buf); - return; - } - if (!strncmp(pFileName+strlen(pFileName)-4,".bz2",4)) { - b.b = BZ2_bzWriteOpen( &bzError, b.f, 9, 0, 0 ); - if ( bzError != BZ_OK ) { - BZ2_bzWriteClose( &bzError, b.b, 0, NULL, NULL ); - fprintf( stdout, "Ntl_ManWriteBlif(): Cannot start compressed stream.\n" ); - fclose( b.f ); - ABC_FREE(b.buf); - return; - } - } - - fprintfBz2( &b, "# Benchmark \"%s\" written by ABC-8 on %s\n", p->pName, Aig_TimeStamp() ); - // write the models - Ntl_ManForEachModel( p, pModel, i ) - Ntl_ManWriteBlifModelBz2( &b, pModel, i==0 ); - // close the file - if (b.b) { - BZ2_bzWriteClose( &bzError, b.b, 0, NULL, NULL ); - if (bzError == BZ_IO_ERROR) { - fprintf( stdout, "Ntl_ManWriteBlif(): I/O error closing compressed stream.\n" ); - fclose( b.f ); - ABC_FREE(b.buf); - return; - } - } - fclose( b.f ); - ABC_FREE(b.buf); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntl_.c b/src/aig/ntl/ntl_.c deleted file mode 100644 index 9b0b1d0a..00000000 --- a/src/aig/ntl/ntl_.c +++ /dev/null @@ -1,52 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntl_.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist representation.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntl_.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "ntl.h" - -ABC_NAMESPACE_IMPL_START - - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - -ABC_NAMESPACE_IMPL_END - diff --git a/src/aig/ntl/ntlnwk.h b/src/aig/ntl/ntlnwk.h deleted file mode 100644 index 0b07f243..00000000 --- a/src/aig/ntl/ntlnwk.h +++ /dev/null @@ -1,113 +0,0 @@ -/**CFile**************************************************************** - - FileName [ntlnwk.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [Netlist and network representation.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - June 20, 2005.] - - Revision [$Id: ntlnwk.h,v 1.3 2008/10/24 14:18:44 mjarvin Exp $] - -***********************************************************************/ - -#ifndef __NTLNWK_H__ -#define __NTLNWK_H__ - - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -ABC_NAMESPACE_HEADER_START - - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Ntl_Man_t_ Ntl_Man_t; -typedef struct Nwk_Man_t_ Nwk_Man_t; - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// INLINED FUNCTIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -extern ABC_DLL Ntl_Man_t * Ntl_ManReadBlif( char * pFileName, int fCheck ); -extern ABC_DLL void Ntl_ManWriteBlif( Ntl_Man_t * p, char * pFileName ); - -extern ABC_DLL Tim_Man_t * Ntl_ManReadTimeMan( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManDup( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManFree( Ntl_Man_t * p ); -extern ABC_DLL int Ntl_ManIsComb( Ntl_Man_t * p ); -extern ABC_DLL void Ntl_ManPrintStats( Ntl_Man_t * p ); -extern ABC_DLL int Ntl_ManSweep( Ntl_Man_t * p, int fVerbose ); -extern ABC_DLL Ntl_Man_t * Ntl_ManInsertNtk( Ntl_Man_t * p, Nwk_Man_t * pNtk ); -extern ABC_DLL Ntl_Man_t * Ntl_ManInsertAig( Ntl_Man_t * p, Aig_Man_t * pAig ); -extern ABC_DLL Aig_Man_t * Ntl_ManExtract( Ntl_Man_t * p ); -extern ABC_DLL Aig_Man_t * Ntl_ManCollapse( Ntl_Man_t * p, int fSeq ); -extern ABC_DLL Aig_Man_t * Ntl_ManCollapseSeq( Ntl_Man_t * p, int nMinDomSize, int fVerbose ); -extern ABC_DLL Ntl_Man_t * Ntl_ManDupCollapseLuts( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManFraig( Ntl_Man_t * p, int nPartSize, int nConfLimit, int nLevelMax, int fUseCSat, int fVerbose ); -extern ABC_DLL void Ntl_ManPrepareCecMans( Ntl_Man_t * pMan1, Ntl_Man_t * pMan2, Aig_Man_t ** ppAig1, Aig_Man_t ** ppAig2 ); -extern ABC_DLL Vec_Ptr_t * Ntl_ManCollectCiNames( Ntl_Man_t * p ); -extern ABC_DLL Vec_Ptr_t * Ntl_ManCollectCoNames( Ntl_Man_t * p ); -extern ABC_DLL Ntl_Man_t * Ntl_ManScl( Ntl_Man_t * p, int fLatchConst, int fLatchEqual, int fVerbose ); -extern ABC_DLL Ntl_Man_t * Ntl_ManLcorr( Ntl_Man_t * p, int nConfMax, int fScorrGia, int fUseCSat, int fVerbose ); -extern ABC_DLL Ntl_Man_t * Ntl_ManSsw( Ntl_Man_t * p, Fra_Ssw_t * pPars ); -extern ABC_DLL Ntl_Man_t * Ntl_ManScorr( Ntl_Man_t * p, Ssw_Pars_t * pPars ); -extern ABC_DLL void Ntl_ManTransformInitValues( Ntl_Man_t * p ); - -extern ABC_DLL void Ntl_ManPrepareCec( char * pFileName1, char * pFileName2, Aig_Man_t ** ppMan1, Aig_Man_t ** ppMan2 ); -extern ABC_DLL Aig_Man_t * Ntl_ManPrepareSec( char * pFileName1, char * pFileName2 ); - -extern ABC_DLL Nwk_Man_t * Ntl_ManExtractNwk( Ntl_Man_t * p, Aig_Man_t * pAig, Tim_Man_t * pManTime ); -extern ABC_DLL Nwk_Man_t * Ntl_ManReadNwk( char * pFileName, Aig_Man_t * pAig, Tim_Man_t * pManTime ); -extern ABC_DLL void Nwk_ManPrintStats( Nwk_Man_t * p, If_Lib_t * pLutLib, int fSaveBest, int fDumpResult, int fPower, Ntl_Man_t * pNtl ); -extern ABC_DLL void Nwk_ManPrintStatsShort( Ntl_Man_t * p, Aig_Man_t * pAig, Nwk_Man_t * pNtk ); -extern ABC_DLL void Nwk_ManPrintFanioNew( Nwk_Man_t * p ); -extern ABC_DLL Nwk_Man_t * Nwk_MappingIf( Aig_Man_t * p, Tim_Man_t * pManTime, If_Par_t * pPars ); -extern ABC_DLL void Nwk_ManSetIfParsDefault( If_Par_t * pPars ); -extern ABC_DLL void Nwk_ManBidecResyn( Nwk_Man_t * p, int fVerbose ); -extern ABC_DLL Aig_Man_t * Nwk_ManSpeedup( Nwk_Man_t * p, int fUseLutLib, int Percentage, int Degree, int fVerbose, int fVeryVerbose ); -extern ABC_DLL Aig_Man_t * Nwk_ManStrash( Nwk_Man_t * p ); -extern ABC_DLL Vec_Int_t * Nwk_ManLutMerge( Nwk_Man_t * p, void * pPars ); -extern ABC_DLL int Nwk_ManCheck( Nwk_Man_t * p ); -extern ABC_DLL void Nwk_ManDumpBlif( Nwk_Man_t * p, char * pFileName, Vec_Ptr_t * vCiNames, Vec_Ptr_t * vCoNames ); -extern ABC_DLL void Nwk_ManFree( Nwk_Man_t * p ); - - - -ABC_NAMESPACE_HEADER_END - - - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - |