diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2008-01-30 20:01:00 -0800 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2008-01-30 20:01:00 -0800 |
commit | 0c6505a26a537dc911b6566f82d759521e527c08 (patch) | |
tree | f2687995efd4943fe3b1307fce7ef5942d0a57b3 /src/abc8/aig | |
parent | 4d30a1e4f1edecff86d5066ce4653a370e59e5e1 (diff) | |
download | abc-0c6505a26a537dc911b6566f82d759521e527c08.tar.gz abc-0c6505a26a537dc911b6566f82d759521e527c08.tar.bz2 abc-0c6505a26a537dc911b6566f82d759521e527c08.zip |
Version abc80130_2
Diffstat (limited to 'src/abc8/aig')
29 files changed, 0 insertions, 11525 deletions
diff --git a/src/abc8/aig/aig.h b/src/abc8/aig/aig.h deleted file mode 100644 index 31e347ca..00000000 --- a/src/abc8/aig/aig.h +++ /dev/null @@ -1,619 +0,0 @@ -/**CFile**************************************************************** - - FileName [aig.h] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [External declarations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aig.h,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#ifndef __AIG_H__ -#define __AIG_H__ - -#ifdef __cplusplus -extern "C" { -#endif - -//////////////////////////////////////////////////////////////////////// -/// INCLUDES /// -//////////////////////////////////////////////////////////////////////// - -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <assert.h> -#include <time.h> - -#include "vec2.h" - -//////////////////////////////////////////////////////////////////////// -/// PARAMETERS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// BASIC TYPES /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Aig_Man_t_ Aig_Man_t; -typedef struct Aig_Obj_t_ Aig_Obj_t; -typedef struct Aig_MmFixed_t_ Aig_MmFixed_t; -typedef struct Aig_MmFlex_t_ Aig_MmFlex_t; -typedef struct Aig_MmStep_t_ Aig_MmStep_t; - -// object types -typedef enum { - AIG_OBJ_NONE, // 0: non-existent object - AIG_OBJ_CONST1, // 1: constant 1 - AIG_OBJ_PI, // 2: primary input - AIG_OBJ_PO, // 3: primary output - AIG_OBJ_BUF, // 4: buffer node - AIG_OBJ_AND, // 5: AND node - AIG_OBJ_EXOR, // 6: EXOR node - AIG_OBJ_LATCH, // 7: latch - AIG_OBJ_VOID // 8: unused object -} Aig_Type_t; - -// the AIG node -struct Aig_Obj_t_ // 8 words -{ - Aig_Obj_t * pNext; // strashing table - Aig_Obj_t * pFanin0; // fanin - Aig_Obj_t * pFanin1; // fanin - Aig_Obj_t * pHaig; // pointer to the HAIG node - unsigned int Type : 3; // object type - unsigned int fPhase : 1; // value under 000...0 pattern - unsigned int fMarkA : 1; // multipurpose mask - unsigned int fMarkB : 1; // multipurpose mask - unsigned int nRefs : 26; // reference count - unsigned Level : 24; // the level of this node - unsigned nCuts : 8; // the number of cuts - int TravId; // unique ID of last traversal involving the node - int Id; // unique ID of the node - union { // temporary store for user's data - void * pData; - int iData; - float dData; - }; -}; - -// the AIG manager -struct Aig_Man_t_ -{ - char * pName; // the design name - // AIG nodes - Vec_Ptr_t * vPis; // the array of PIs - Vec_Ptr_t * vPos; // the array of POs - Vec_Ptr_t * vObjs; // the array of all nodes (optional) - Vec_Ptr_t * vBufs; // the array of buffers - Aig_Obj_t * pConst1; // the constant 1 node - Aig_Obj_t Ghost; // the ghost node - int nRegs; // the number of registers (registers are last POs) - int nAsserts; // the number of asserts among POs (asserts are first POs) - // AIG node counters - int nObjs[AIG_OBJ_VOID];// the number of objects by type - int nCreated; // the number of created objects - int nDeleted; // the number of deleted objects - // structural hash table - Aig_Obj_t ** pTable; // structural hash table - int nTableSize; // structural hash table size - // representation of fanouts - int * pFanData; // the database to store fanout information - int nFansAlloc; // the size of fanout representation - Vec_Vec_t * vLevels; // used to update timing information - int nBufReplaces; // the number of times replacement led to a buffer - int nBufFixes; // the number of times buffers were propagated - int nBufMax; // the maximum number of buffers during computation - // topological order - unsigned * pOrderData; - int nOrderAlloc; - int iPrev; - int iNext; - int nAndTotal; - int nAndPrev; - // representatives - Aig_Obj_t ** pEquivs; // linked list of equivalent nodes (when choices are used) - Aig_Obj_t ** pReprs; // representatives of each node - int nReprsAlloc; // the number of allocated representatives - // various data members - Aig_MmFixed_t * pMemObjs; // memory manager for objects - Vec_Int_t * vLevelR; // the reverse level of the nodes - int nLevelMax; // maximum number of levels - void * pData; // the temporary data - int nTravIds; // the current traversal ID - int fCatchExor; // enables EXOR nodes - int fAddStrash; // performs additional strashing - Aig_Obj_t ** pObjCopies; // mapping of AIG nodes into FRAIG nodes - void (*pImpFunc) (void*, void*); // implication checking precedure - void * pImpData; // implication checking data - void * pManTime; // the timing manager - void * pManCuts; - Vec_Ptr_t * vMapped; - Vec_Int_t * vFlopNums; - void * pSeqModel; - Aig_Man_t * pManHaig; - // timing statistics - int time1; - int time2; -}; - -// cut computation -typedef struct Aig_ManCut_t_ Aig_ManCut_t; -typedef struct Aig_Cut_t_ Aig_Cut_t; - -// the cut used to represent node in the AIG -struct Aig_Cut_t_ -{ - Aig_Cut_t * pNext; // the next cut in the table - int Cost; // the cost of the cut - unsigned uSign; // cut signature - int iNode; // the node, for which it is the cut - short nCutSize; // the number of bytes in the cut - char nLeafMax; // the maximum number of fanins - char nFanins; // the current number of fanins - int pFanins[0]; // the fanins (followed by the truth table) -}; - -// the CNF computation manager -struct Aig_ManCut_t_ -{ - // AIG manager - Aig_Man_t * pAig; // the input AIG manager - Aig_Cut_t ** pCuts; // the cuts for each node in the output manager - // parameters - int nCutsMax; // the max number of cuts at the node - int nLeafMax; // the max number of leaves of a cut - int fTruth; // enables truth table computation - int fVerbose; // enables verbose output - // internal variables - int nCutSize; // the number of bytes needed to store one cut - int nTruthWords; // the number of truth table words - Aig_MmFixed_t * pMemCuts; // memory manager for cuts - unsigned * puTemp[4]; // used for the truth table computation -}; - -static inline Aig_Cut_t * Aig_ObjCuts( Aig_ManCut_t * p, Aig_Obj_t * pObj ) { return p->pCuts[pObj->Id]; } -static inline void Aig_ObjSetCuts( Aig_ManCut_t * p, Aig_Obj_t * pObj, Aig_Cut_t * pCuts ) { p->pCuts[pObj->Id] = pCuts; } - -static inline int Aig_CutLeaveNum( Aig_Cut_t * pCut ) { return pCut->nFanins; } -static inline int * Aig_CutLeaves( Aig_Cut_t * pCut ) { return pCut->pFanins; } -static inline unsigned * Aig_CutTruth( Aig_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nLeafMax); } -static inline Aig_Cut_t * Aig_CutNext( Aig_Cut_t * pCut ) { return (Aig_Cut_t *)(((char *)pCut) + pCut->nCutSize); } - -// iterator over cuts of the node -#define Aig_ObjForEachCut( p, pObj, pCut, i ) \ - for ( i = 0, pCut = Aig_ObjCuts(p, pObj); i < p->nCutsMax; i++, pCut = Aig_CutNext(pCut) ) -// iterator over leaves of the cut -#define Aig_CutForEachLeaf( p, pCut, pLeaf, i ) \ - for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ ) - -//////////////////////////////////////////////////////////////////////// -/// MACRO DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -#define AIG_MIN(a,b) (((a) < (b))? (a) : (b)) -#define AIG_MAX(a,b) (((a) > (b))? (a) : (b)) -#define AIG_ABS(a) (((a) >= 0)? (a) :-(a)) -#define AIG_INFINITY (100000000) - -#ifndef PRT -#define PRT(a,t) printf("%s = ", (a)); printf("%6.2f sec\n", (float)(t)/(float)(CLOCKS_PER_SEC)) -#endif - -static inline int Aig_Float2Int( float Val ) { return *((int *)&Val); } -static inline float Aig_Int2Float( int Num ) { return *((float *)&Num); } -static inline int Aig_Base2Log( unsigned n ) { int r; assert( n >= 0 ); if ( n < 2 ) return n; for ( r = 0, n--; n; n >>= 1, r++ ); return r; } -static inline int Aig_Base10Log( unsigned n ) { int r; assert( n >= 0 ); if ( n < 2 ) return n; for ( r = 0, n--; n; n /= 10, r++ ); return r; } -static inline char * Aig_UtilStrsav( char * s ) { return s ? strcpy(ALLOC(char, strlen(s)+1), s) : NULL; } -static inline int Aig_BitWordNum( int nBits ) { return (nBits>>5) + ((nBits&31) > 0); } -static inline int Aig_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); } -static inline int Aig_InfoHasBit( unsigned * p, int i ) { return (p[(i)>>5] & (1<<((i) & 31))) > 0; } -static inline void Aig_InfoSetBit( unsigned * p, int i ) { p[(i)>>5] |= (1<<((i) & 31)); } -static inline void Aig_InfoXorBit( unsigned * p, int i ) { p[(i)>>5] ^= (1<<((i) & 31)); } -static inline unsigned Aig_InfoMask( int nVar ) { return (~(unsigned)0) >> (32-nVar); } -static inline unsigned Aig_ObjCutSign( unsigned ObjId ) { return (1 << (ObjId & 31)); } -static inline int Aig_WordCountOnes( unsigned uWord ) -{ - uWord = (uWord & 0x55555555) + ((uWord>>1) & 0x55555555); - uWord = (uWord & 0x33333333) + ((uWord>>2) & 0x33333333); - uWord = (uWord & 0x0F0F0F0F) + ((uWord>>4) & 0x0F0F0F0F); - uWord = (uWord & 0x00FF00FF) + ((uWord>>8) & 0x00FF00FF); - return (uWord & 0x0000FFFF) + (uWord>>16); -} -static inline int Aig_WordFindFirstBit( unsigned uWord ) -{ - int i; - for ( i = 0; i < 32; i++ ) - if ( uWord & (1 << i) ) - return i; - return -1; -} - -static inline Aig_Obj_t * Aig_Regular( Aig_Obj_t * p ) { return (Aig_Obj_t *)((unsigned long)(p) & ~01); } -static inline Aig_Obj_t * Aig_Not( Aig_Obj_t * p ) { return (Aig_Obj_t *)((unsigned long)(p) ^ 01); } -static inline Aig_Obj_t * Aig_NotCond( Aig_Obj_t * p, int c ) { return (Aig_Obj_t *)((unsigned long)(p) ^ (c)); } -static inline int Aig_IsComplement( Aig_Obj_t * p ) { return (int)((unsigned long)(p) & 01); } - -static inline int Aig_ManPiNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_PI]; } -static inline int Aig_ManPoNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_PO]; } -static inline int Aig_ManBufNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_BUF]; } -static inline int Aig_ManAndNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_AND]; } -static inline int Aig_ManExorNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_EXOR]; } -static inline int Aig_ManLatchNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_LATCH]; } -static inline int Aig_ManNodeNum( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_AND]+p->nObjs[AIG_OBJ_EXOR]; } -static inline int Aig_ManGetCost( Aig_Man_t * p ) { return p->nObjs[AIG_OBJ_AND]+3*p->nObjs[AIG_OBJ_EXOR]; } -static inline int Aig_ManObjNum( Aig_Man_t * p ) { return p->nCreated - p->nDeleted; } -static inline int Aig_ManObjNumMax( Aig_Man_t * p ) { return Vec_PtrSize(p->vObjs); } -static inline int Aig_ManRegNum( Aig_Man_t * p ) { return p->nRegs; } - -static inline Aig_Obj_t * Aig_ManConst0( Aig_Man_t * p ) { return Aig_Not(p->pConst1); } -static inline Aig_Obj_t * Aig_ManConst1( Aig_Man_t * p ) { return p->pConst1; } -static inline Aig_Obj_t * Aig_ManGhost( Aig_Man_t * p ) { return &p->Ghost; } -static inline Aig_Obj_t * Aig_ManPi( Aig_Man_t * p, int i ) { return (Aig_Obj_t *)Vec_PtrEntry(p->vPis, i); } -static inline Aig_Obj_t * Aig_ManPo( Aig_Man_t * p, int i ) { return (Aig_Obj_t *)Vec_PtrEntry(p->vPos, i); } -static inline Aig_Obj_t * Aig_ManLo( Aig_Man_t * p, int i ) { return (Aig_Obj_t *)Vec_PtrEntry(p->vPis, Aig_ManPiNum(p)-Aig_ManRegNum(p)+i); } -static inline Aig_Obj_t * Aig_ManLi( Aig_Man_t * p, int i ) { return (Aig_Obj_t *)Vec_PtrEntry(p->vPos, Aig_ManPoNum(p)-Aig_ManRegNum(p)+i); } -static inline Aig_Obj_t * Aig_ManObj( Aig_Man_t * p, int i ) { return p->vObjs ? (Aig_Obj_t *)Vec_PtrEntry(p->vObjs, i) : NULL; } - -static inline Aig_Type_t Aig_ObjType( Aig_Obj_t * pObj ) { return (Aig_Type_t)pObj->Type; } -static inline int Aig_ObjIsNone( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_NONE; } -static inline int Aig_ObjIsConst1( Aig_Obj_t * pObj ) { assert(!Aig_IsComplement(pObj)); return pObj->Type == AIG_OBJ_CONST1; } -static inline int Aig_ObjIsPi( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_PI; } -static inline int Aig_ObjIsPo( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_PO; } -static inline int Aig_ObjIsBuf( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_BUF; } -static inline int Aig_ObjIsAnd( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_AND; } -static inline int Aig_ObjIsExor( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_EXOR; } -static inline int Aig_ObjIsLatch( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_LATCH; } -static inline int Aig_ObjIsNode( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_AND || pObj->Type == AIG_OBJ_EXOR; } -static inline int Aig_ObjIsTerm( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_PI || pObj->Type == AIG_OBJ_PO || pObj->Type == AIG_OBJ_CONST1; } -static inline int Aig_ObjIsHash( Aig_Obj_t * pObj ) { return pObj->Type == AIG_OBJ_AND || pObj->Type == AIG_OBJ_EXOR || pObj->Type == AIG_OBJ_LATCH; } -static inline int Aig_ObjIsChoice( Aig_Man_t * p, Aig_Obj_t * pObj ) { return p->pEquivs && p->pEquivs[pObj->Id] && pObj->nRefs > 0; } - -static inline int Aig_ObjIsMarkA( Aig_Obj_t * pObj ) { return pObj->fMarkA; } -static inline void Aig_ObjSetMarkA( Aig_Obj_t * pObj ) { pObj->fMarkA = 1; } -static inline void Aig_ObjClearMarkA( Aig_Obj_t * pObj ) { pObj->fMarkA = 0; } - -static inline void Aig_ObjSetTravId( Aig_Obj_t * pObj, int TravId ) { pObj->TravId = TravId; } -static inline void Aig_ObjSetTravIdCurrent( Aig_Man_t * p, Aig_Obj_t * pObj ) { pObj->TravId = p->nTravIds; } -static inline void Aig_ObjSetTravIdPrevious( Aig_Man_t * p, Aig_Obj_t * pObj ) { pObj->TravId = p->nTravIds - 1; } -static inline int Aig_ObjIsTravIdCurrent( Aig_Man_t * p, Aig_Obj_t * pObj ) { return (int)(pObj->TravId == p->nTravIds); } -static inline int Aig_ObjIsTravIdPrevious( Aig_Man_t * p, Aig_Obj_t * pObj ) { return (int)(pObj->TravId == p->nTravIds - 1); } - -static inline int Aig_ObjPhase( Aig_Obj_t * pObj ) { return pObj->fPhase; } -static inline int Aig_ObjPhaseReal( Aig_Obj_t * pObj ) { return pObj? Aig_Regular(pObj)->fPhase ^ Aig_IsComplement(pObj) : 1; } -static inline int Aig_ObjRefs( Aig_Obj_t * pObj ) { return pObj->nRefs; } -static inline void Aig_ObjRef( Aig_Obj_t * pObj ) { pObj->nRefs++; } -static inline void Aig_ObjDeref( Aig_Obj_t * pObj ) { assert( pObj->nRefs > 0 ); pObj->nRefs--; } -static inline void Aig_ObjClearRef( Aig_Obj_t * pObj ) { pObj->nRefs = 0; } -static inline int Aig_ObjFaninId0( Aig_Obj_t * pObj ) { return pObj->pFanin0? Aig_Regular(pObj->pFanin0)->Id : -1; } -static inline int Aig_ObjFaninId1( Aig_Obj_t * pObj ) { return pObj->pFanin1? Aig_Regular(pObj->pFanin1)->Id : -1; } -static inline int Aig_ObjFaninC0( Aig_Obj_t * pObj ) { return Aig_IsComplement(pObj->pFanin0); } -static inline int Aig_ObjFaninC1( Aig_Obj_t * pObj ) { return Aig_IsComplement(pObj->pFanin1); } -static inline Aig_Obj_t * Aig_ObjFanin0( Aig_Obj_t * pObj ) { return Aig_Regular(pObj->pFanin0); } -static inline Aig_Obj_t * Aig_ObjFanin1( Aig_Obj_t * pObj ) { return Aig_Regular(pObj->pFanin1); } -static inline Aig_Obj_t * Aig_ObjChild0( Aig_Obj_t * pObj ) { return pObj->pFanin0; } -static inline Aig_Obj_t * Aig_ObjChild1( Aig_Obj_t * pObj ) { return pObj->pFanin1; } -static inline Aig_Obj_t * Aig_ObjChild0Copy( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin0(pObj)? Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin0(pObj)->pData, Aig_ObjFaninC0(pObj)) : NULL; } -static inline Aig_Obj_t * Aig_ObjChild1Copy( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? Aig_NotCond((Aig_Obj_t *)Aig_ObjFanin1(pObj)->pData, Aig_ObjFaninC1(pObj)) : NULL; } -static inline void Aig_ObjChild0Flip( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); pObj->pFanin0 = Aig_Not(pObj->pFanin0); } -static inline void Aig_ObjChild1Flip( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); pObj->pFanin1 = Aig_Not(pObj->pFanin1); } -static inline int Aig_ObjLevel( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return pObj->Level; } -static inline int Aig_ObjLevelNew( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? 1 + Aig_ObjIsExor(pObj) + AIG_MAX(Aig_ObjFanin0(pObj)->Level, Aig_ObjFanin1(pObj)->Level) : Aig_ObjFanin0(pObj)->Level; } -static inline int Aig_ObjSetLevel( Aig_Obj_t * pObj, int i ) { assert( !Aig_IsComplement(pObj) ); return pObj->Level = i; } -static inline void Aig_ObjClean( Aig_Obj_t * pObj ) { memset( pObj, 0, sizeof(Aig_Obj_t) ); } -static inline Aig_Obj_t * Aig_ObjFanout0( Aig_Man_t * p, Aig_Obj_t * pObj ) { assert(p->pFanData && pObj->Id < p->nFansAlloc); return Aig_ManObj(p, p->pFanData[5*pObj->Id] >> 1); } -static inline Aig_Obj_t * Aig_ObjEquiv( Aig_Man_t * p, Aig_Obj_t * pObj ) { return p->pEquivs? p->pEquivs[pObj->Id] : NULL; } -static inline Aig_Obj_t * Aig_ObjHaig( Aig_Obj_t * pObj ) { assert( Aig_Regular(pObj)->pHaig ); return Aig_NotCond( Aig_Regular(pObj)->pHaig, Aig_IsComplement(pObj) ); } -static inline int Aig_ObjWhatFanin( Aig_Obj_t * pObj, Aig_Obj_t * pFanin ) -{ - if ( Aig_ObjFanin0(pObj) == pFanin ) return 0; - if ( Aig_ObjFanin1(pObj) == pFanin ) return 1; - assert(0); return -1; -} -static inline int Aig_ObjFanoutC( Aig_Obj_t * pObj, Aig_Obj_t * pFanout ) -{ - if ( Aig_ObjFanin0(pFanout) == pObj ) return Aig_ObjFaninC0(pObj); - if ( Aig_ObjFanin1(pFanout) == pObj ) return Aig_ObjFaninC1(pObj); - assert(0); return -1; -} - -// create the ghost of the new node -static inline Aig_Obj_t * Aig_ObjCreateGhost( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1, Aig_Type_t Type ) -{ - Aig_Obj_t * pGhost; - assert( Type != AIG_OBJ_AND || !Aig_ObjIsConst1(Aig_Regular(p0)) ); - assert( p1 == NULL || !Aig_ObjIsConst1(Aig_Regular(p1)) ); - assert( Type == AIG_OBJ_PI || Aig_Regular(p0) != Aig_Regular(p1) ); - pGhost = Aig_ManGhost(p); - pGhost->Type = Type; - if ( p1 == NULL || Aig_Regular(p0)->Id < Aig_Regular(p1)->Id ) - { - pGhost->pFanin0 = p0; - pGhost->pFanin1 = p1; - } - else - { - pGhost->pFanin0 = p1; - pGhost->pFanin1 = p0; - } - return pGhost; -} - -// internal memory manager -static inline Aig_Obj_t * Aig_ManFetchMemory( Aig_Man_t * p ) -{ - extern char * Aig_MmFixedEntryFetch( Aig_MmFixed_t * p ); - Aig_Obj_t * pTemp; - pTemp = (Aig_Obj_t *)Aig_MmFixedEntryFetch( p->pMemObjs ); - memset( pTemp, 0, sizeof(Aig_Obj_t) ); - Vec_PtrPush( p->vObjs, pTemp ); - pTemp->Id = p->nCreated++; - return pTemp; -} -static inline void Aig_ManRecycleMemory( Aig_Man_t * p, Aig_Obj_t * pEntry ) -{ - extern void Aig_MmFixedEntryRecycle( Aig_MmFixed_t * p, char * pEntry ); - assert( pEntry->nRefs == 0 ); - pEntry->Type = AIG_OBJ_NONE; // distinquishes a dead node from a live node - Aig_MmFixedEntryRecycle( p->pMemObjs, (char *)pEntry ); - p->nDeleted++; -} - - -//////////////////////////////////////////////////////////////////////// -/// ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -// iterator over the primary inputs -#define Aig_ManForEachPi( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPis, pObj, i ) -// iterator over the primary outputs -#define Aig_ManForEachPo( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPos, pObj, i ) -// iterator over the assertions -#define Aig_ManForEachAssert( p, pObj, i ) \ - Vec_PtrForEachEntryStart( p->vPos, pObj, i, Aig_ManPoNum(p)-p->nAsserts ) -// iterator over all objects, including those currently not used -#define Aig_ManForEachObj( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vObjs, pObj, i ) if ( (pObj) == NULL ) {} else -// iterator over all nodes -#define Aig_ManForEachNode( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vObjs, pObj, i ) if ( (pObj) == NULL || !Aig_ObjIsNode(pObj) ) {} else -// iterator over the nodes whose IDs are stored in the array -#define Aig_ManForEachNodeVec( p, vIds, pObj, i ) \ - for ( i = 0; i < Vec_IntSize(vIds) && ((pObj) = Aig_ManObj(p, Vec_IntEntry(vIds,i))); i++ ) -// iterator over the nodes in the topological order -#define Aig_ManForEachNodeInOrder( p, pObj ) \ - for ( assert(p->pOrderData), p->iPrev = 0, p->iNext = p->pOrderData[1]; \ - p->iNext && (((pObj) = Aig_ManObj(p, p->iNext)), 1); \ - p->iNext = p->pOrderData[2*p->iPrev+1] ) - -// these two procedures are only here for the use inside the iterator -static inline int Aig_ObjFanout0Int( Aig_Man_t * p, int ObjId ) { assert(ObjId < p->nFansAlloc); return p->pFanData[5*ObjId]; } -static inline int Aig_ObjFanoutNext( Aig_Man_t * p, int iFan ) { assert(iFan/2 < p->nFansAlloc); return p->pFanData[5*(iFan >> 1) + 3 + (iFan & 1)]; } -// iterator over the fanouts -#define Aig_ObjForEachFanout( p, pObj, pFanout, iFan, i ) \ - for ( assert(p->pFanData), i = 0; (i < (int)(pObj)->nRefs) && \ - (((iFan) = i? Aig_ObjFanoutNext(p, iFan) : Aig_ObjFanout0Int(p, pObj->Id)), 1) && \ - (((pFanout) = Aig_ManObj(p, iFan>>1)), 1); i++ ) - - -//////////////////////////////////////////////////////////////////////// -/// SEQUENTIAL ITERATORS /// -//////////////////////////////////////////////////////////////////////// - -// iterator over the primary inputs -#define Aig_ManForEachPiSeq( p, pObj, i ) \ - Vec_PtrForEachEntryStop( p->vPis, pObj, i, Aig_ManPiNum(p)-Aig_ManRegNum(p) ) -// iterator over the latch outputs -#define Aig_ManForEachLoSeq( p, pObj, i ) \ - Vec_PtrForEachEntryStart( p->vPis, pObj, i, Aig_ManPiNum(p)-Aig_ManRegNum(p) ) -// iterator over the primary outputs -#define Aig_ManForEachPoSeq( p, pObj, i ) \ - Vec_PtrForEachEntryStop( p->vPos, pObj, i, Aig_ManPoNum(p)-Aig_ManRegNum(p) ) -// iterator over the latch inputs -#define Aig_ManForEachLiSeq( p, pObj, i ) \ - Vec_PtrForEachEntryStart( p->vPos, pObj, i, Aig_ManPoNum(p)-Aig_ManRegNum(p) ) -// iterator over the latch input and outputs -#define Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, k ) \ - for ( k = 0; (k < Aig_ManRegNum(p)) && (((pObjLi) = Aig_ManLi(p, k)), 1) \ - && (((pObjLo)=Aig_ManLo(p, k)), 1); k++ ) - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -/*=== aigCheck.c ========================================================*/ -extern int Aig_ManCheck( Aig_Man_t * p ); -extern void Aig_ManCheckMarkA( Aig_Man_t * p ); -extern void Aig_ManCheckPhase( Aig_Man_t * p ); -/*=== aigCuts.c ========================================================*/ -extern Aig_ManCut_t * Aig_ComputeCuts( Aig_Man_t * pAig, int nCutsMax, int nLeafMax, int fTruth, int fVerbose ); -extern void Aig_ManCutStop( Aig_ManCut_t * p ); -/*=== aigDfs.c ==========================================================*/ -extern Vec_Ptr_t * Aig_ManDfs( Aig_Man_t * p ); -extern Vec_Ptr_t * Aig_ManDfsPio( Aig_Man_t * p ); -extern Vec_Ptr_t * Aig_ManDfsNodes( Aig_Man_t * p, Aig_Obj_t ** ppNodes, int nNodes ); -extern Vec_Ptr_t * Aig_ManDfsChoices( Aig_Man_t * p ); -extern Vec_Ptr_t * Aig_ManDfsReverse( Aig_Man_t * p ); -extern int Aig_ManLevelNum( Aig_Man_t * p ); -extern int Aig_ManCountLevels( Aig_Man_t * p ); -extern int Aig_DagSize( Aig_Obj_t * pObj ); -extern int Aig_SupportSize( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern void Aig_ConeUnmark_rec( Aig_Obj_t * pObj ); -extern Aig_Obj_t * Aig_Transfer( Aig_Man_t * pSour, Aig_Man_t * pDest, Aig_Obj_t * pObj, int nVars ); -extern Aig_Obj_t * Aig_Compose( Aig_Man_t * p, Aig_Obj_t * pRoot, Aig_Obj_t * pFunc, int iVar ); -extern void Aig_ObjCollectCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vNodes ); -extern int Aig_ObjCollectSuper( Aig_Obj_t * pObj, Vec_Ptr_t * vSuper ); -/*=== aigFanout.c ==========================================================*/ -extern void Aig_ObjAddFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout ); -extern void Aig_ObjRemoveFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout ); -extern void Aig_ManFanoutStart( Aig_Man_t * p ); -extern void Aig_ManFanoutStop( Aig_Man_t * p ); -/*=== aigFrames.c ==========================================================*/ -extern Aig_Man_t * Aig_ManFrames( Aig_Man_t * pAig, int nFs, int fInit, int fOuts, int fRegs, int fEnlarge, Aig_Obj_t *** ppObjMap ); -/*=== aigHaig.c ==========================================================*/ -extern void Aig_ManHaigRecord( Aig_Man_t * p ); -/*=== aigMan.c ==========================================================*/ -extern Aig_Man_t * Aig_ManStart( int nNodesMax ); -extern Aig_Man_t * Aig_ManStartFrom( Aig_Man_t * p ); -extern Aig_Obj_t * Aig_ManDup_rec( Aig_Man_t * pNew, Aig_Man_t * p, Aig_Obj_t * pObj ); -extern Aig_Man_t * Aig_ManDup( Aig_Man_t * p, int fOrdered ); -extern Aig_Man_t * Aig_ManExtractMiter( Aig_Man_t * p, Aig_Obj_t * pNode1, Aig_Obj_t * pNode2 ); -extern void Aig_ManStop( Aig_Man_t * p ); -extern int Aig_ManCleanup( Aig_Man_t * p ); -extern void Aig_ManPrintStats( Aig_Man_t * p ); -/*=== aigMem.c ==========================================================*/ -extern void Aig_ManStartMemory( Aig_Man_t * p ); -extern void Aig_ManStopMemory( Aig_Man_t * p ); -/*=== aigMffc.c ==========================================================*/ -extern int Aig_NodeRef_rec( Aig_Obj_t * pNode, unsigned LevelMin ); -extern int Aig_NodeDeref_rec( Aig_Obj_t * pNode, unsigned LevelMin ); -extern int Aig_NodeMffsSupp( Aig_Man_t * p, Aig_Obj_t * pNode, int LevelMin, Vec_Ptr_t * vSupp ); -extern int Aig_NodeMffsLabel( Aig_Man_t * p, Aig_Obj_t * pNode ); -extern int Aig_NodeMffsLabelCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves ); -extern int Aig_NodeMffsExtendCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vResult ); -/*=== aigObj.c ==========================================================*/ -extern Aig_Obj_t * Aig_ObjCreatePi( Aig_Man_t * p ); -extern Aig_Obj_t * Aig_ObjCreatePo( Aig_Man_t * p, Aig_Obj_t * pDriver ); -extern Aig_Obj_t * Aig_ObjCreate( Aig_Man_t * p, Aig_Obj_t * pGhost ); -extern void Aig_ObjConnect( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFan0, Aig_Obj_t * pFan1 ); -extern void Aig_ObjDisconnect( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern void Aig_ObjDelete( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern void Aig_ObjDelete_rec( Aig_Man_t * p, Aig_Obj_t * pObj, int fFreeTop ); -extern void Aig_ObjPatchFanin0( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFaninNew ); -extern void Aig_ObjReplace( Aig_Man_t * p, Aig_Obj_t * pObjOld, Aig_Obj_t * pObjNew, int fNodesOnly, int fUpdateLevel ); -/*=== aigOper.c =========================================================*/ -extern Aig_Obj_t * Aig_IthVar( Aig_Man_t * p, int i ); -extern Aig_Obj_t * Aig_Oper( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1, Aig_Type_t Type ); -extern Aig_Obj_t * Aig_And( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ); -extern Aig_Obj_t * Aig_Latch( Aig_Man_t * p, Aig_Obj_t * pObj, int fInitOne ); -extern Aig_Obj_t * Aig_Or( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ); -extern Aig_Obj_t * Aig_Exor( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ); -extern Aig_Obj_t * Aig_Mux( Aig_Man_t * p, Aig_Obj_t * pC, Aig_Obj_t * p1, Aig_Obj_t * p0 ); -extern Aig_Obj_t * Aig_Maj( Aig_Man_t * p, Aig_Obj_t * pA, Aig_Obj_t * pB, Aig_Obj_t * pC ); -extern Aig_Obj_t * Aig_Miter( Aig_Man_t * p, Vec_Ptr_t * vPairs ); -extern Aig_Obj_t * Aig_MiterTwo( Aig_Man_t * p, Vec_Ptr_t * vNodes1, Vec_Ptr_t * vNodes2 ); -extern Aig_Obj_t * Aig_CreateAnd( Aig_Man_t * p, int nVars ); -extern Aig_Obj_t * Aig_CreateOr( Aig_Man_t * p, int nVars ); -extern Aig_Obj_t * Aig_CreateExor( Aig_Man_t * p, int nVars ); -/*=== aigOrder.c =========================================================*/ -extern void Aig_ManOrderStart( Aig_Man_t * p ); -extern void Aig_ManOrderStop( Aig_Man_t * p ); -extern void Aig_ObjOrderInsert( Aig_Man_t * p, int ObjId ); -extern void Aig_ObjOrderRemove( Aig_Man_t * p, int ObjId ); -extern void Aig_ObjOrderAdvance( Aig_Man_t * p ); -/*=== aigPart.c =========================================================*/ -extern Vec_Ptr_t * Aig_ManSupports( Aig_Man_t * pMan ); -extern Vec_Ptr_t * Aig_ManPartitionSmart( Aig_Man_t * p, int nPartSizeLimit, int fVerbose, Vec_Ptr_t ** pvPartSupps ); -extern Vec_Ptr_t * Aig_ManPartitionNaive( Aig_Man_t * p, int nPartSize ); -extern Vec_Ptr_t * Aig_ManMiterPartitioned( Aig_Man_t * p1, Aig_Man_t * p2, int nPartSize ); -extern Aig_Man_t * Aig_ManChoicePartitioned( Vec_Ptr_t * vAigs, int nPartSize, int fVerbose ); -/*=== aigRepr.c =========================================================*/ -extern void Aig_ManReprStart( Aig_Man_t * p, int nIdMax ); -extern void Aig_ManReprStop( Aig_Man_t * p ); -extern void Aig_ObjCreateRepr( Aig_Man_t * p, Aig_Obj_t * pNode1, Aig_Obj_t * pNode2 ); -extern void Aig_ManTransferRepr( Aig_Man_t * pNew, Aig_Man_t * p ); -extern Aig_Man_t * Aig_ManDupRepr( Aig_Man_t * p, int fOrdered ); -extern Aig_Man_t * Aig_ManRehash( Aig_Man_t * p ); -extern void Aig_ManMarkValidChoices( Aig_Man_t * p ); -/*=== aigRet.c ========================================================*/ -extern Aig_Man_t * Rtm_ManRetime( Aig_Man_t * p, int fForward, int nStepsMax, int fVerbose ); -/*=== aigRetF.c ========================================================*/ -extern Aig_Man_t * Aig_ManRetimeFrontier( Aig_Man_t * p, int nStepsMax ); -/*=== aigScl.c ==========================================================*/ -extern Aig_Man_t * Aig_ManRemap( Aig_Man_t * p, Vec_Ptr_t * vMap ); -extern int Aig_ManSeqCleanup( Aig_Man_t * p ); -extern int Aig_ManCountMergeRegs( Aig_Man_t * p ); -extern Aig_Man_t * Aig_ManReduceLaches( Aig_Man_t * p, int fVerbose ); -/*=== aigSeq.c ========================================================*/ -extern int Aig_ManSeqStrash( Aig_Man_t * p, int nLatches, int * pInits ); -/*=== aigShow.c ========================================================*/ -extern void Aig_ManShow( Aig_Man_t * pMan, int fHaig, Vec_Ptr_t * vBold ); -/*=== aigTable.c ========================================================*/ -extern Aig_Obj_t * Aig_TableLookup( Aig_Man_t * p, Aig_Obj_t * pGhost ); -extern Aig_Obj_t * Aig_TableLookupTwo( Aig_Man_t * p, Aig_Obj_t * pFanin0, Aig_Obj_t * pFanin1 ); -extern void Aig_TableInsert( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern void Aig_TableDelete( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern int Aig_TableCountEntries( Aig_Man_t * p ); -extern void Aig_TableProfile( Aig_Man_t * p ); -extern void Aig_TableClear( Aig_Man_t * p ); -/*=== aigTiming.c ========================================================*/ -extern void Aig_ObjClearReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern int Aig_ObjRequiredLevel( Aig_Man_t * p, Aig_Obj_t * pObj ); -extern void Aig_ManStartReverseLevels( Aig_Man_t * p, int nMaxLevelIncrease ); -extern void Aig_ManStopReverseLevels( Aig_Man_t * p ); -extern void Aig_ManUpdateLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew ); -extern void Aig_ManUpdateReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew ); -extern void Aig_ManVerifyLevel( Aig_Man_t * p ); -extern void Aig_ManVerifyReverseLevel( Aig_Man_t * p ); -/*=== aigTruth.c ========================================================*/ -extern unsigned * Aig_ManCutTruth( Aig_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vNodes, Vec_Ptr_t * vTruthElem, Vec_Ptr_t * vTruthStore ); -/*=== aigTsim.c ========================================================*/ -extern Aig_Man_t * Aig_ManConstReduce( Aig_Man_t * p, int fVerbose ); -/*=== aigUtil.c =========================================================*/ -extern unsigned Aig_PrimeCudd( unsigned p ); -extern void Aig_ManIncrementTravId( Aig_Man_t * p ); -extern int Aig_ManLevels( Aig_Man_t * p ); -extern void Aig_ManResetRefs( Aig_Man_t * p ); -extern void Aig_ManCleanMarkA( Aig_Man_t * p ); -extern void Aig_ManCleanMarkB( Aig_Man_t * p ); -extern void Aig_ManCleanData( Aig_Man_t * p ); -extern void Aig_ObjCleanData_rec( Aig_Obj_t * pObj ); -extern void Aig_ObjCollectMulti( Aig_Obj_t * pFunc, Vec_Ptr_t * vSuper ); -extern int Aig_ObjIsMuxType( Aig_Obj_t * pObj ); -extern int Aig_ObjRecognizeExor( Aig_Obj_t * pObj, Aig_Obj_t ** ppFan0, Aig_Obj_t ** ppFan1 ); -extern Aig_Obj_t * Aig_ObjRecognizeMux( Aig_Obj_t * pObj, Aig_Obj_t ** ppObjT, Aig_Obj_t ** ppObjE ); -extern Aig_Obj_t * Aig_ObjReal_rec( Aig_Obj_t * pObj ); -extern void Aig_ObjPrintEqn( FILE * pFile, Aig_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ); -extern void Aig_ObjPrintVerilog( FILE * pFile, Aig_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ); -extern void Aig_ObjPrintVerbose( Aig_Obj_t * pObj, int fHaig ); -extern void Aig_ManPrintVerbose( Aig_Man_t * p, int fHaig ); -extern void Aig_ManDump( Aig_Man_t * p ); -extern void Aig_ManDumpBlif( Aig_Man_t * p, char * pFileName ); -extern void Aig_ManDumpVerilog( Aig_Man_t * p, char * pFileName ); -/*=== aigWin.c =========================================================*/ -extern void Aig_ManFindCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit ); - -/*=== aigMem.c ===========================================================*/ -// fixed-size-block memory manager -extern Aig_MmFixed_t * Aig_MmFixedStart( int nEntrySize, int nEntriesMax ); -extern void Aig_MmFixedStop( Aig_MmFixed_t * p, int fVerbose ); -extern char * Aig_MmFixedEntryFetch( Aig_MmFixed_t * p ); -extern void Aig_MmFixedEntryRecycle( Aig_MmFixed_t * p, char * pEntry ); -extern void Aig_MmFixedRestart( Aig_MmFixed_t * p ); -extern int Aig_MmFixedReadMemUsage( Aig_MmFixed_t * p ); -extern int Aig_MmFixedReadMaxEntriesUsed( Aig_MmFixed_t * p ); -// flexible-size-block memory manager -extern Aig_MmFlex_t * Aig_MmFlexStart(); -extern void Aig_MmFlexStop( Aig_MmFlex_t * p, int fVerbose ); -extern char * Aig_MmFlexEntryFetch( Aig_MmFlex_t * p, int nBytes ); -extern void Aig_MmFlexRestart( Aig_MmFlex_t * p ); -extern int Aig_MmFlexReadMemUsage( Aig_MmFlex_t * p ); -// hierarchical memory manager -extern Aig_MmStep_t * Aig_MmStepStart( int nSteps ); -extern void Aig_MmStepStop( Aig_MmStep_t * p, int fVerbose ); -extern char * Aig_MmStepEntryFetch( Aig_MmStep_t * p, int nBytes ); -extern void Aig_MmStepEntryRecycle( Aig_MmStep_t * p, char * pEntry, int nBytes ); -extern int Aig_MmStepReadMemUsage( Aig_MmStep_t * p ); - -#ifdef __cplusplus -} -#endif - -#endif - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - diff --git a/src/abc8/aig/aigCheck.c b/src/abc8/aig/aigCheck.c deleted file mode 100644 index 8c53e635..00000000 --- a/src/abc8/aig/aigCheck.c +++ /dev/null @@ -1,163 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigCheck.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [AIG checking procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigCheck.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Checks the consistency of the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManCheck( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pObj2; - int i; - // check primary inputs - Aig_ManForEachPi( p, pObj, i ) - { - if ( Aig_ObjFanin0(pObj) || Aig_ObjFanin1(pObj) ) - { - printf( "Aig_ManCheck: The PI node \"%p\" has fanins.\n", pObj ); - return 0; - } - } - // check primary outputs - Aig_ManForEachPo( p, pObj, i ) - { - if ( !Aig_ObjFanin0(pObj) ) - { - printf( "Aig_ManCheck: The PO node \"%p\" has NULL fanin.\n", pObj ); - return 0; - } - if ( Aig_ObjFanin1(pObj) ) - { - printf( "Aig_ManCheck: The PO node \"%p\" has second fanin.\n", pObj ); - return 0; - } - } - // check internal nodes - Aig_ManForEachObj( p, pObj, i ) - { - if ( !Aig_ObjIsNode(pObj) ) - continue; - if ( !Aig_ObjFanin0(pObj) || !Aig_ObjFanin1(pObj) ) - { - printf( "Aig_ManCheck: The AIG has internal node \"%p\" with a NULL fanin.\n", pObj ); - return 0; - } - if ( Aig_ObjFanin0(pObj)->Id >= Aig_ObjFanin1(pObj)->Id ) - { - printf( "Aig_ManCheck: The AIG has node \"%p\" with a wrong ordering of fanins.\n", pObj ); - return 0; - } - pObj2 = Aig_TableLookup( p, pObj ); - if ( pObj2 != pObj ) - { - printf( "Aig_ManCheck: Node \"%p\" is not in the structural hashing table.\n", pObj ); - return 0; - } - } - // count the total number of nodes - if ( Aig_ManObjNum(p) != 1 + Aig_ManPiNum(p) + Aig_ManPoNum(p) + - Aig_ManBufNum(p) + Aig_ManAndNum(p) + Aig_ManExorNum(p) + Aig_ManLatchNum(p) ) - { - printf( "Aig_ManCheck: The number of created nodes is wrong.\n" ); - printf( "C1 = %d. Pi = %d. Po = %d. Buf = %d. And = %d. Xor = %d. Lat = %d. Total = %d.\n", - 1, Aig_ManPiNum(p), Aig_ManPoNum(p), Aig_ManBufNum(p), Aig_ManAndNum(p), Aig_ManExorNum(p), Aig_ManLatchNum(p), - 1 + Aig_ManPiNum(p) + Aig_ManPoNum(p) + Aig_ManBufNum(p) + Aig_ManAndNum(p) + Aig_ManExorNum(p) + Aig_ManLatchNum(p) ); - printf( "Created = %d. Deleted = %d. Existing = %d.\n", - p->nCreated, p->nDeleted, p->nCreated - p->nDeleted ); - return 0; - } - // count the number of nodes in the table - if ( Aig_TableCountEntries(p) != Aig_ManAndNum(p) + Aig_ManExorNum(p) + Aig_ManLatchNum(p) ) - { - printf( "Aig_ManCheck: The number of nodes in the structural hashing table is wrong.\n" ); - printf( "Entries = %d. And = %d. Xor = %d. Lat = %d. Total = %d.\n", - Aig_TableCountEntries(p), Aig_ManAndNum(p), Aig_ManExorNum(p), Aig_ManLatchNum(p), - Aig_ManAndNum(p) + Aig_ManExorNum(p) + Aig_ManLatchNum(p) ); - - return 0; - } -// if ( !Aig_ManIsAcyclic(p) ) -// return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Checks if the markA is reset.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCheckMarkA( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - assert( pObj->fMarkA == 0 ); -} - -/**Function************************************************************* - - Synopsis [Checks the consistency of phase assignment.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCheckPhase( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsPi(pObj) ) - assert( (int)pObj->fPhase == 0 ); - else - assert( (int)pObj->fPhase == (Aig_ObjPhaseReal(Aig_ObjChild0(pObj)) & Aig_ObjPhaseReal(Aig_ObjChild1(pObj))) ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigCuts.c b/src/abc8/aig/aigCuts.c deleted file mode 100644 index 494d0d5b..00000000 --- a/src/abc8/aig/aigCuts.c +++ /dev/null @@ -1,669 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigCuts.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Computation of K-feasible priority cuts.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigCuts.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" -#include "kit.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Starts the cut sweeping manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_ManCut_t * Aig_ManCutStart( Aig_Man_t * pMan, int nCutsMax, int nLeafMax, int fTruth, int fVerbose ) -{ - Aig_ManCut_t * p; - assert( nCutsMax >= 2 ); - assert( nLeafMax <= 16 ); - // allocate the fraiging manager - p = ALLOC( Aig_ManCut_t, 1 ); - memset( p, 0, sizeof(Aig_ManCut_t) ); - p->nCutsMax = nCutsMax; - p->nLeafMax = nLeafMax; - p->fTruth = fTruth; - p->fVerbose = fVerbose; - p->pAig = pMan; - // allocate room for cuts and equivalent nodes - p->pCuts = ALLOC( Aig_Cut_t *, Aig_ManObjNumMax(pMan) ); - memset( p->pCuts, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pMan) ); - // allocate memory manager - p->nTruthWords = Aig_TruthWordNum(nLeafMax); - p->nCutSize = sizeof(Aig_Cut_t) + sizeof(int) * nLeafMax + fTruth * sizeof(unsigned) * p->nTruthWords; - p->pMemCuts = Aig_MmFixedStart( p->nCutSize * p->nCutsMax, 512 ); - // room for temporary truth tables - if ( fTruth ) - { - p->puTemp[0] = ALLOC( unsigned, 4 * p->nTruthWords ); - p->puTemp[1] = p->puTemp[0] + p->nTruthWords; - p->puTemp[2] = p->puTemp[1] + p->nTruthWords; - p->puTemp[3] = p->puTemp[2] + p->nTruthWords; - } - return p; -} - -/**Function************************************************************* - - Synopsis [Stops the fraiging manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCutStop( Aig_ManCut_t * p ) -{ - Aig_MmFixedStop( p->pMemCuts, 0 ); - FREE( p->puTemp[0] ); - free( p->pCuts ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Prints one cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_CutPrint( Aig_Cut_t * pCut ) -{ - int i; - printf( "{" ); - for ( i = 0; i < pCut->nFanins; i++ ) - printf( " %d", pCut->pFanins[i] ); - printf( " }\n" ); -} - -/**Function************************************************************* - - Synopsis [Prints one cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCutPrint( Aig_ManCut_t * p, Aig_Obj_t * pObj ) -{ - Aig_Cut_t * pCut; - int i; - printf( "Cuts for node %d:\n", pObj->Id ); - Aig_ObjForEachCut( p, pObj, pCut, i ) - if ( pCut->nFanins ) - Aig_CutPrint( pCut ); -// printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Computes the total number of cuts.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManCutCount( Aig_ManCut_t * p, int * pnCutsK ) -{ - Aig_Cut_t * pCut; - Aig_Obj_t * pObj; - int i, k, nCuts = 0, nCutsK = 0; - Aig_ManForEachNode( p->pAig, pObj, i ) - Aig_ObjForEachCut( p, pObj, pCut, k ) - { - if ( pCut->nFanins == 0 ) - continue; - nCuts++; - if ( pCut->nFanins == p->nLeafMax ) - nCutsK++; - } - if ( pnCutsK ) - *pnCutsK = nCutsK; - return nCuts; -} - -/**Function************************************************************* - - Synopsis [Compute the cost of the cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Aig_CutFindCost( Aig_ManCut_t * p, Aig_Cut_t * pCut ) -{ - Aig_Obj_t * pLeaf; - int i, Cost = 0; - assert( pCut->nFanins > 0 ); - Aig_CutForEachLeaf( p->pAig, pCut, pLeaf, i ) - Cost += pLeaf->nRefs; - return Cost * 1000 / pCut->nFanins; -} - -/**Function************************************************************* - - Synopsis [Compute the cost of the cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline float Aig_CutFindCost2( Aig_ManCut_t * p, Aig_Cut_t * pCut ) -{ - Aig_Obj_t * pLeaf; - float Cost = 0.0; - int i; - assert( pCut->nFanins > 0 ); - Aig_CutForEachLeaf( p->pAig, pCut, pLeaf, i ) - Cost += (float)1.0/pLeaf->nRefs; - return 1/Cost; -} - -/**Function************************************************************* - - Synopsis [Returns the next free cut to use.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Aig_Cut_t * Aig_CutFindFree( Aig_ManCut_t * p, Aig_Obj_t * pObj ) -{ - Aig_Cut_t * pCut, * pCutMax; - int i; - pCutMax = NULL; - Aig_ObjForEachCut( p, pObj, pCut, i ) - { - if ( pCut->nFanins == 0 ) - return pCut; - if ( pCutMax == NULL || pCutMax->Cost < pCut->Cost ) - pCutMax = pCut; - } - assert( pCutMax != NULL ); - pCutMax->nFanins = 0; - return pCutMax; -} - -/**Function************************************************************* - - Synopsis [Computes the stretching phase of the cut w.r.t. the merged cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline unsigned Aig_CutTruthPhase( Aig_Cut_t * pCut, Aig_Cut_t * pCut1 ) -{ - unsigned uPhase = 0; - int i, k; - for ( i = k = 0; i < pCut->nFanins; i++ ) - { - if ( k == pCut1->nFanins ) - break; - if ( pCut->pFanins[i] < pCut1->pFanins[k] ) - continue; - assert( pCut->pFanins[i] == pCut1->pFanins[k] ); - uPhase |= (1 << i); - k++; - } - return uPhase; -} - -/**Function************************************************************* - - Synopsis [Performs truth table computation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Aig_CutComputeTruth( Aig_ManCut_t * p, Aig_Cut_t * pCut, Aig_Cut_t * pCut0, Aig_Cut_t * pCut1, int fCompl0, int fCompl1 ) -{ - // permute the first table - if ( fCompl0 ) - Kit_TruthNot( p->puTemp[0], Aig_CutTruth(pCut0), p->nLeafMax ); - else - Kit_TruthCopy( p->puTemp[0], Aig_CutTruth(pCut0), p->nLeafMax ); - Kit_TruthStretch( p->puTemp[2], p->puTemp[0], pCut0->nFanins, p->nLeafMax, Aig_CutTruthPhase(pCut, pCut0), 0 ); - // permute the second table - if ( fCompl1 ) - Kit_TruthNot( p->puTemp[1], Aig_CutTruth(pCut1), p->nLeafMax ); - else - Kit_TruthCopy( p->puTemp[1], Aig_CutTruth(pCut1), p->nLeafMax ); - Kit_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nFanins, p->nLeafMax, Aig_CutTruthPhase(pCut, pCut1), 0 ); - // produce the resulting table - Kit_TruthAnd( Aig_CutTruth(pCut), p->puTemp[2], p->puTemp[3], p->nLeafMax ); -// assert( pCut->nFanins >= Kit_TruthSupportSize( Aig_CutTruth(pCut), p->nLeafMax ) ); - return Aig_CutTruth(pCut); -} - -/**Function************************************************************* - - Synopsis [Performs support minimization for the truth table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_CutSupportMinimize( Aig_ManCut_t * p, Aig_Cut_t * pCut ) -{ - unsigned * pTruth; - int uSupp, nFansNew, i, k; - // get truth table - pTruth = Aig_CutTruth( pCut ); - // get support - uSupp = Kit_TruthSupport( pTruth, p->nLeafMax ); - // get the new support size - nFansNew = Kit_WordCountOnes( uSupp ); - // check if there are redundant variables - if ( nFansNew == pCut->nFanins ) - return nFansNew; - assert( nFansNew < pCut->nFanins ); - // minimize support - Kit_TruthShrink( p->puTemp[0], pTruth, nFansNew, p->nLeafMax, uSupp, 1 ); - for ( i = k = 0; i < pCut->nFanins; i++ ) - if ( uSupp & (1 << i) ) - pCut->pFanins[k++] = pCut->pFanins[i]; - assert( k == nFansNew ); - pCut->nFanins = nFansNew; -// assert( nFansNew == Kit_TruthSupportSize( pTruth, p->nLeafMax ) ); -//Extra_PrintBinary( stdout, pTruth, (1<<p->nLeafMax) ); printf( "\n" ); - return nFansNew; -} - -/**Function************************************************************* - - Synopsis [Returns 1 if pDom is contained in pCut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Aig_CutCheckDominance( Aig_Cut_t * pDom, Aig_Cut_t * pCut ) -{ - int i, k; - for ( i = 0; i < (int)pDom->nFanins; i++ ) - { - for ( k = 0; k < (int)pCut->nFanins; k++ ) - if ( pDom->pFanins[i] == pCut->pFanins[k] ) - break; - if ( k == (int)pCut->nFanins ) // node i in pDom is not contained in pCut - return 0; - } - // every node in pDom is contained in pCut - return 1; -} - -/**Function************************************************************* - - Synopsis [Returns 1 if the cut is contained.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_CutFilter( Aig_ManCut_t * p, Aig_Obj_t * pObj, Aig_Cut_t * pCut ) -{ - Aig_Cut_t * pTemp; - int i; - // go through the cuts of the node - Aig_ObjForEachCut( p, pObj, pTemp, i ) - { - if ( pTemp->nFanins < 2 ) - continue; - if ( pTemp == pCut ) - continue; - if ( pTemp->nFanins > pCut->nFanins ) - { - // skip the non-contained cuts - if ( (pTemp->uSign & pCut->uSign) != pCut->uSign ) - continue; - // check containment seriously - if ( Aig_CutCheckDominance( pCut, pTemp ) ) - { - // remove contained cut - pTemp->nFanins = 0; - } - } - else - { - // skip the non-contained cuts - if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign ) - continue; - // check containment seriously - if ( Aig_CutCheckDominance( pTemp, pCut ) ) - { - // remove the given - pCut->nFanins = 0; - return 1; - } - } - } - return 0; -} - -/**Function************************************************************* - - Synopsis [Merges two cuts.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Aig_CutMergeOrdered( Aig_ManCut_t * p, Aig_Cut_t * pC0, Aig_Cut_t * pC1, Aig_Cut_t * pC ) -{ - int i, k, c; - assert( pC0->nFanins >= pC1->nFanins ); - // the case of the largest cut sizes - if ( pC0->nFanins == p->nLeafMax && pC1->nFanins == p->nLeafMax ) - { - for ( i = 0; i < pC0->nFanins; i++ ) - if ( pC0->pFanins[i] != pC1->pFanins[i] ) - return 0; - for ( i = 0; i < pC0->nFanins; i++ ) - pC->pFanins[i] = pC0->pFanins[i]; - pC->nFanins = pC0->nFanins; - return 1; - } - // the case when one of the cuts is the largest - if ( pC0->nFanins == p->nLeafMax ) - { - for ( i = 0; i < pC1->nFanins; i++ ) - { - for ( k = pC0->nFanins - 1; k >= 0; k-- ) - if ( pC0->pFanins[k] == pC1->pFanins[i] ) - break; - if ( k == -1 ) // did not find - return 0; - } - for ( i = 0; i < pC0->nFanins; i++ ) - pC->pFanins[i] = pC0->pFanins[i]; - pC->nFanins = pC0->nFanins; - return 1; - } - - // compare two cuts with different numbers - i = k = 0; - for ( c = 0; c < p->nLeafMax; c++ ) - { - if ( k == pC1->nFanins ) - { - if ( i == pC0->nFanins ) - { - pC->nFanins = c; - return 1; - } - pC->pFanins[c] = pC0->pFanins[i++]; - continue; - } - if ( i == pC0->nFanins ) - { - if ( k == pC1->nFanins ) - { - pC->nFanins = c; - return 1; - } - pC->pFanins[c] = pC1->pFanins[k++]; - continue; - } - if ( pC0->pFanins[i] < pC1->pFanins[k] ) - { - pC->pFanins[c] = pC0->pFanins[i++]; - continue; - } - if ( pC0->pFanins[i] > pC1->pFanins[k] ) - { - pC->pFanins[c] = pC1->pFanins[k++]; - continue; - } - pC->pFanins[c] = pC0->pFanins[i++]; - k++; - } - if ( i < pC0->nFanins || k < pC1->nFanins ) - return 0; - pC->nFanins = c; - return 1; -} - -/**Function************************************************************* - - Synopsis [Prepares the object for FPGA mapping.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_CutMerge( Aig_ManCut_t * p, Aig_Cut_t * pCut0, Aig_Cut_t * pCut1, Aig_Cut_t * pCut ) -{ - assert( p->nLeafMax > 0 ); - // merge the nodes - if ( pCut0->nFanins < pCut1->nFanins ) - { - if ( !Aig_CutMergeOrdered( p, pCut1, pCut0, pCut ) ) - return 0; - } - else - { - if ( !Aig_CutMergeOrdered( p, pCut0, pCut1, pCut ) ) - return 0; - } - pCut->uSign = pCut0->uSign | pCut1->uSign; - return 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Cut_t * Aig_ObjPrepareCuts( Aig_ManCut_t * p, Aig_Obj_t * pObj, int fTriv ) -{ - Aig_Cut_t * pCutSet, * pCut; - int i; - // create the cutset of the node - pCutSet = (Aig_Cut_t *)Aig_MmFixedEntryFetch( p->pMemCuts ); - Aig_ObjSetCuts( p, pObj, pCutSet ); - Aig_ObjForEachCut( p, pObj, pCut, i ) - { - pCut->nFanins = 0; - pCut->iNode = pObj->Id; - pCut->nCutSize = p->nCutSize; - pCut->nLeafMax = p->nLeafMax; - } - // add unit cut if needed - if ( fTriv ) - { - pCut = pCutSet; - pCut->Cost = 0; - pCut->iNode = pObj->Id; - pCut->nFanins = 1; - pCut->pFanins[0] = pObj->Id; - pCut->uSign = Aig_ObjCutSign( pObj->Id ); - if ( p->fTruth ) - memset( Aig_CutTruth(pCut), 0xAA, sizeof(unsigned) * p->nTruthWords ); - } - return pCutSet; -} - -/**Function************************************************************* - - Synopsis [Derives cuts for one node and sweeps this node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjComputeCuts( Aig_ManCut_t * p, Aig_Obj_t * pObj, int fTriv ) -{ - Aig_Cut_t * pCut0, * pCut1, * pCut, * pCutSet; - Aig_Obj_t * pFanin0 = Aig_ObjFanin0(pObj); - Aig_Obj_t * pFanin1 = Aig_ObjFanin1(pObj); - int i, k; - // the node is not processed yet - assert( Aig_ObjIsNode(pObj) ); - assert( Aig_ObjCuts(p, pObj) == NULL ); - // set up the first cut - pCutSet = Aig_ObjPrepareCuts( p, pObj, fTriv ); - // compute pair-wise cut combinations while checking table - Aig_ObjForEachCut( p, pFanin0, pCut0, i ) - if ( pCut0->nFanins > 0 ) - Aig_ObjForEachCut( p, pFanin1, pCut1, k ) - if ( pCut1->nFanins > 0 ) - { - // make sure K-feasible cut exists - if ( Kit_WordCountOnes(pCut0->uSign | pCut1->uSign) > p->nLeafMax ) - continue; - // get the next cut of this node - pCut = Aig_CutFindFree( p, pObj ); - // assemble the new cut - if ( !Aig_CutMerge( p, pCut0, pCut1, pCut ) ) - { - assert( pCut->nFanins == 0 ); - continue; - } - // check containment - if ( Aig_CutFilter( p, pObj, pCut ) ) - { - assert( pCut->nFanins == 0 ); - continue; - } - // create its truth table - if ( p->fTruth ) - Aig_CutComputeTruth( p, pCut, pCut0, pCut1, Aig_ObjFaninC0(pObj), Aig_ObjFaninC1(pObj) ); - // assign the cost - pCut->Cost = Aig_CutFindCost( p, pCut ); - assert( pCut->nFanins > 0 ); - assert( pCut->Cost > 0 ); - } -} - -/**Function************************************************************* - - Synopsis [Computes the cuts for all nodes in the static AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_ManCut_t * Aig_ComputeCuts( Aig_Man_t * pAig, int nCutsMax, int nLeafMax, int fTruth, int fVerbose ) -{ - Aig_ManCut_t * p; - Aig_Obj_t * pObj; - int i, clk = clock(); - assert( pAig->pManCuts == NULL ); - // start the manager - p = Aig_ManCutStart( pAig, nCutsMax, nLeafMax, fTruth, fVerbose ); - // set elementary cuts at the PIs - Aig_ManForEachPi( pAig, pObj, i ) - Aig_ObjPrepareCuts( p, pObj, 1 ); - // process the nodes - Aig_ManForEachNode( pAig, pObj, i ) - Aig_ObjComputeCuts( p, pObj, 1 ); - // print stats - if ( fVerbose ) - { - int nCuts, nCutsK; - nCuts = Aig_ManCutCount( p, &nCutsK ); - printf( "Nodes = %6d. Total cuts = %6d. %d-input cuts = %6d.\n", - Aig_ManObjNum(pAig), nCuts, nLeafMax, nCutsK ); - printf( "Cut size = %2d. Truth size = %2d. Total mem = %5.2f Mb ", - p->nCutSize, 4*p->nTruthWords, 1.0*Aig_MmFixedReadMemUsage(p->pMemCuts)/(1<<20) ); - PRT( "Runtime", clock() - clk ); -/* - Aig_ManForEachNode( pAig, pObj, i ) - if ( i % 300 == 0 ) - Aig_ObjCutPrint( p, pObj ); -*/ - } - // remember the cut manager - pAig->pManCuts = p; - return p; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigDfs.c b/src/abc8/aig/aigDfs.c deleted file mode 100644 index c7488487..00000000 --- a/src/abc8/aig/aigDfs.c +++ /dev/null @@ -1,723 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigDfs.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [DFS traversal procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigDfs.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDfs_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - if ( pObj == NULL ) - return; - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return; -// assert( Aig_ObjIsNode(pObj) || Aig_ObjIsBuf(pObj) ); - Aig_ManDfs_rec( p, Aig_ObjFanin0(pObj), vNodes ); - Aig_ManDfs_rec( p, Aig_ObjFanin1(pObj), vNodes ); - assert( !Aig_ObjIsTravIdCurrent(p, pObj) ); // loop detection - Aig_ObjSetTravIdCurrent(p, pObj); - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfs( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - Aig_ManIncrementTravId( p ); - // mark constant and PIs - Aig_ObjSetTravIdCurrent( p, Aig_ManConst1(p) ); - Aig_ManForEachPi( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // if there are latches, mark them - if ( Aig_ManLatchNum(p) > 0 ) - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsLatch(pObj) ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Aig_ManNodeNum(p) ); - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsNode(pObj) || Aig_ObjIsBuf(pObj) ) - Aig_ManDfs_rec( p, pObj, vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsPio( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - Aig_ManIncrementTravId( p ); - vNodes = Vec_PtrAlloc( Aig_ManObjNumMax(p) ); - Aig_ManForEachPo( p, pObj, i ) - Aig_ManDfs_rec( p, pObj, vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsNodes( Aig_Man_t * p, Aig_Obj_t ** ppNodes, int nNodes ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - assert( Aig_ManLatchNum(p) == 0 ); - Aig_ManIncrementTravId( p ); - // mark constant and PIs - Aig_ObjSetTravIdCurrent( p, Aig_ManConst1(p) ); - Aig_ManForEachPi( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Aig_ManNodeNum(p) ); - for ( i = 0; i < nNodes; i++ ) - Aig_ManDfs_rec( p, ppNodes[i], vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDfsChoices_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - if ( pObj == NULL ) - return; - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return; - assert( Aig_ObjIsNode(pObj) ); - Aig_ManDfsChoices_rec( p, Aig_ObjFanin0(pObj), vNodes ); - Aig_ManDfsChoices_rec( p, Aig_ObjFanin1(pObj), vNodes ); - Aig_ManDfsChoices_rec( p, p->pEquivs[pObj->Id], vNodes ); - assert( !Aig_ObjIsTravIdCurrent(p, pObj) ); // loop detection - Aig_ObjSetTravIdCurrent(p, pObj); - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsChoices( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - assert( p->pEquivs != NULL ); - Aig_ManIncrementTravId( p ); - // mark constant and PIs - Aig_ObjSetTravIdCurrent( p, Aig_ManConst1(p) ); - Aig_ManForEachPi( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Aig_ManNodeNum(p) ); - Aig_ManForEachPo( p, pObj, i ) - Aig_ManDfsChoices_rec( p, Aig_ObjFanin0(pObj), vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the reverse DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDfsReverse_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - Aig_Obj_t * pFanout; - int iFanout = -1, i; - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return; - assert( Aig_ObjIsNode(pObj) || Aig_ObjIsBuf(pObj) ); - Aig_ObjForEachFanout( p, pObj, pFanout, iFanout, i ) - Aig_ManDfsReverse_rec( p, pFanout, vNodes ); - assert( !Aig_ObjIsTravIdCurrent(p, pObj) ); // loop detection - Aig_ObjSetTravIdCurrent(p, pObj); - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the reverse DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsReverse( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - Aig_ManIncrementTravId( p ); - // mark POs - Aig_ManForEachPo( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // if there are latches, mark them - if ( Aig_ManLatchNum(p) > 0 ) - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsLatch(pObj) ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Aig_ManNodeNum(p) ); - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsNode(pObj) || Aig_ObjIsBuf(pObj) ) - Aig_ManDfsReverse_rec( p, pObj, vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Computes the max number of levels in the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManLevelNum( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i, LevelsMax; - LevelsMax = 0; - Aig_ManForEachPo( p, pObj, i ) - LevelsMax = AIG_MAX( LevelsMax, (int)Aig_ObjFanin0(pObj)->Level ); - return LevelsMax; -} - -/**Function************************************************************* - - Synopsis [Computes the max number of levels in the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManCountLevels( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i, LevelsMax, Level0, Level1; - // initialize the levels - Aig_ManConst1(p)->iData = 0; - Aig_ManForEachPi( p, pObj, i ) - pObj->iData = 0; - // compute levels in a DFS order - vNodes = Aig_ManDfs( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - Level0 = Aig_ObjFanin0(pObj)->iData; - Level1 = Aig_ObjFanin1(pObj)->iData; - pObj->iData = 1 + Aig_ObjIsExor(pObj) + AIG_MAX(Level0, Level1); - } - Vec_PtrFree( vNodes ); - // get levels of the POs - LevelsMax = 0; - Aig_ManForEachPo( p, pObj, i ) - LevelsMax = AIG_MAX( LevelsMax, Aig_ObjFanin0(pObj)->iData ); - return LevelsMax; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ConeMark_rec( Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) || Aig_ObjIsMarkA(pObj) ) - return; - Aig_ConeMark_rec( Aig_ObjFanin0(pObj) ); - Aig_ConeMark_rec( Aig_ObjFanin1(pObj) ); - assert( !Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ConeCleanAndMark_rec( Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) || Aig_ObjIsMarkA(pObj) ) - return; - Aig_ConeCleanAndMark_rec( Aig_ObjFanin0(pObj) ); - Aig_ConeCleanAndMark_rec( Aig_ObjFanin1(pObj) ); - assert( !Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjSetMarkA( pObj ); - pObj->pData = NULL; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ConeCountAndMark_rec( Aig_Obj_t * pObj ) -{ - int Counter; - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) || Aig_ObjIsMarkA(pObj) ) - return 0; - Counter = 1 + Aig_ConeCountAndMark_rec( Aig_ObjFanin0(pObj) ) + - Aig_ConeCountAndMark_rec( Aig_ObjFanin1(pObj) ); - assert( !Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjSetMarkA( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ConeUnmark_rec( Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) || !Aig_ObjIsMarkA(pObj) ) - return; - Aig_ConeUnmark_rec( Aig_ObjFanin0(pObj) ); - Aig_ConeUnmark_rec( Aig_ObjFanin1(pObj) ); - assert( Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjClearMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_DagSize( Aig_Obj_t * pObj ) -{ - int Counter; - Counter = Aig_ConeCountAndMark_rec( Aig_Regular(pObj) ); - Aig_ConeUnmark_rec( Aig_Regular(pObj) ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the support size of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_SupportSize_rec( Aig_Man_t * p, Aig_Obj_t * pObj, int * pCounter ) -{ - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return; - Aig_ObjSetTravIdCurrent(p, pObj); - if ( Aig_ObjIsPi(pObj) ) - { - (*pCounter)++; - return; - } - assert( Aig_ObjIsNode(pObj) || Aig_ObjIsBuf(pObj) ); - Aig_SupportSize_rec( p, Aig_ObjFanin0(pObj), pCounter ); - if ( Aig_ObjFanin1(pObj) ) - Aig_SupportSize_rec( p, Aig_ObjFanin1(pObj), pCounter ); -} - -/**Function************************************************************* - - Synopsis [Counts the support size of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_SupportSize( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - int Counter = 0; - assert( !Aig_IsComplement(pObj) ); - assert( !Aig_ObjIsPo(pObj) ); - Aig_ManIncrementTravId( p ); - Aig_SupportSize_rec( p, pObj, &Counter ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Transfers the AIG from one manager into another.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_Transfer_rec( Aig_Man_t * pDest, Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) || Aig_ObjIsMarkA(pObj) ) - return; - Aig_Transfer_rec( pDest, Aig_ObjFanin0(pObj) ); - Aig_Transfer_rec( pDest, Aig_ObjFanin1(pObj) ); - pObj->pData = Aig_And( pDest, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - assert( !Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Transfers the AIG from one manager into another.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Transfer( Aig_Man_t * pSour, Aig_Man_t * pDest, Aig_Obj_t * pRoot, int nVars ) -{ - Aig_Obj_t * pObj; - int i; - // solve simple cases - if ( pSour == pDest ) - return pRoot; - if ( Aig_ObjIsConst1( Aig_Regular(pRoot) ) ) - return Aig_NotCond( Aig_ManConst1(pDest), Aig_IsComplement(pRoot) ); - // set the PI mapping - Aig_ManForEachPi( pSour, pObj, i ) - { - if ( i == nVars ) - break; - pObj->pData = Aig_IthVar(pDest, i); - } - // transfer and set markings - Aig_Transfer_rec( pDest, Aig_Regular(pRoot) ); - // clear the markings - Aig_ConeUnmark_rec( Aig_Regular(pRoot) ); - return Aig_NotCond( Aig_Regular(pRoot)->pData, Aig_IsComplement(pRoot) ); -} - -/**Function************************************************************* - - Synopsis [Composes the AIG (pRoot) with the function (pFunc) using PI var (iVar).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_Compose_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFunc, Aig_Obj_t * pVar ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsMarkA(pObj) ) - return; - if ( Aig_ObjIsConst1(pObj) || Aig_ObjIsPi(pObj) ) - { - pObj->pData = pObj == pVar ? pFunc : pObj; - return; - } - Aig_Compose_rec( p, Aig_ObjFanin0(pObj), pFunc, pVar ); - Aig_Compose_rec( p, Aig_ObjFanin1(pObj), pFunc, pVar ); - pObj->pData = Aig_And( p, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - assert( !Aig_ObjIsMarkA(pObj) ); // loop detection - Aig_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Composes the AIG (pRoot) with the function (pFunc) using PI var (iVar).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Compose( Aig_Man_t * p, Aig_Obj_t * pRoot, Aig_Obj_t * pFunc, int iVar ) -{ - // quit if the PI variable is not defined - if ( iVar >= Aig_ManPiNum(p) ) - { - printf( "Aig_Compose(): The PI variable %d is not defined.\n", iVar ); - return NULL; - } - // recursively perform composition - Aig_Compose_rec( p, Aig_Regular(pRoot), pFunc, Aig_ManPi(p, iVar) ); - // clear the markings - Aig_ConeUnmark_rec( Aig_Regular(pRoot) ); - return Aig_NotCond( Aig_Regular(pRoot)->pData, Aig_IsComplement(pRoot) ); -} - -/**Function************************************************************* - - Synopsis [Computes the internal nodes of the cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCollectCut_rec( Aig_Obj_t * pNode, Vec_Ptr_t * vNodes ) -{ -// Aig_Obj_t * pFan0 = Aig_ObjFanin0(pNode); -// Aig_Obj_t * pFan1 = Aig_ObjFanin1(pNode); - if ( pNode->fMarkA ) - return; - pNode->fMarkA = 1; - assert( Aig_ObjIsNode(pNode) ); - Aig_ObjCollectCut_rec( Aig_ObjFanin0(pNode), vNodes ); - Aig_ObjCollectCut_rec( Aig_ObjFanin1(pNode), vNodes ); - Vec_PtrPush( vNodes, pNode ); -//printf( "added %d ", pNode->Id ); -} - -/**Function************************************************************* - - Synopsis [Computes the internal nodes of the cut.] - - Description [Does not include the leaves of the cut.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCollectCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vNodes ) -{ - Aig_Obj_t * pObj; - int i; - // collect and mark the leaves - Vec_PtrClear( vNodes ); - Vec_PtrForEachEntry( vLeaves, pObj, i ) - { - assert( pObj->fMarkA == 0 ); - pObj->fMarkA = 1; -// printf( "%d " , pObj->Id ); - } -//printf( "\n" ); - // collect and mark the nodes - Aig_ObjCollectCut_rec( pRoot, vNodes ); - // clean the nodes - Vec_PtrForEachEntry( vNodes, pObj, i ) - pObj->fMarkA = 0; - Vec_PtrForEachEntry( vLeaves, pObj, i ) - pObj->fMarkA = 0; -} - - -/**Function************************************************************* - - Synopsis [Collects the nodes of the supergate.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjCollectSuper_rec( Aig_Obj_t * pRoot, Aig_Obj_t * pObj, Vec_Ptr_t * vSuper ) -{ - int RetValue1, RetValue2, i; - // check if the node is visited - if ( Aig_Regular(pObj)->fMarkA ) - { - // check if the node occurs in the same polarity - for ( i = 0; i < vSuper->nSize; i++ ) - if ( vSuper->pArray[i] == pObj ) - return 1; - // check if the node is present in the opposite polarity - for ( i = 0; i < vSuper->nSize; i++ ) - if ( vSuper->pArray[i] == Aig_Not(pObj) ) - return -1; - assert( 0 ); - return 0; - } - // if the new node is complemented or a PI, another gate begins - if ( pObj != pRoot && (Aig_IsComplement(pObj) || Aig_ObjType(pObj) != Aig_ObjType(pRoot) || Aig_ObjRefs(pObj) > 1) ) - { - Vec_PtrPush( vSuper, pObj ); - Aig_Regular(pObj)->fMarkA = 1; - return 0; - } - assert( !Aig_IsComplement(pObj) ); - assert( Aig_ObjIsNode(pObj) ); - // go through the branches - RetValue1 = Aig_ObjCollectSuper_rec( pRoot, Aig_ObjReal_rec( Aig_ObjChild0(pObj) ), vSuper ); - RetValue2 = Aig_ObjCollectSuper_rec( pRoot, Aig_ObjReal_rec( Aig_ObjChild1(pObj) ), vSuper ); - if ( RetValue1 == -1 || RetValue2 == -1 ) - return -1; - // return 1 if at least one branch has a duplicate - return RetValue1 || RetValue2; -} - -/**Function************************************************************* - - Synopsis [Collects the nodes of the supergate.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjCollectSuper( Aig_Obj_t * pObj, Vec_Ptr_t * vSuper ) -{ - int RetValue, i; - assert( !Aig_IsComplement(pObj) ); - assert( Aig_ObjIsNode(pObj) ); - // collect the nodes in the implication supergate - Vec_PtrClear( vSuper ); - RetValue = Aig_ObjCollectSuper_rec( pObj, pObj, vSuper ); - assert( Vec_PtrSize(vSuper) > 1 ); - // unmark the visited nodes - Vec_PtrForEachEntry( vSuper, pObj, i ) - Aig_Regular(pObj)->fMarkA = 0; - // if we found the node and its complement in the same implication supergate, - // return empty set of nodes (meaning that we should use constant-0 node) - if ( RetValue == -1 ) - vSuper->nSize = 0; - return RetValue; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigFanout.c b/src/abc8/aig/aigFanout.c deleted file mode 100644 index d0beb128..00000000 --- a/src/abc8/aig/aigFanout.c +++ /dev/null @@ -1,189 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigFanout.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Fanout manipulation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigFanout.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -// 0: first iFan -// 1: prev iFan0 -// 2: prev iFan1 -// 3: next iFan0 -// 4: next iFan1 - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -static inline int Aig_FanoutCreate( int FanId, int Num ) { assert( Num < 2 ); return (FanId << 1) | Num; } -static inline int * Aig_FanoutObj( int * pData, int ObjId ) { return pData + 5*ObjId; } -static inline int * Aig_FanoutPrev( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 1 + (iFan & 1); } -static inline int * Aig_FanoutNext( int * pData, int iFan ) { return pData + 5*(iFan >> 1) + 3 + (iFan & 1); } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Create fanout for all objects in the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManFanoutStart( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - assert( Aig_ManBufNum(p) == 0 ); - // allocate fanout datastructure - assert( p->pFanData == NULL ); - p->nFansAlloc = 2 * Aig_ManObjNumMax(p); - if ( p->nFansAlloc < (1<<12) ) - p->nFansAlloc = (1<<12); - p->pFanData = ALLOC( int, 5 * p->nFansAlloc ); - memset( p->pFanData, 0, sizeof(int) * 5 * p->nFansAlloc ); - // add fanouts for all objects - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjChild0(pObj) ) - Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj ); - if ( Aig_ObjChild1(pObj) ) - Aig_ObjAddFanout( p, Aig_ObjFanin1(pObj), pObj ); - } -} - -/**Function************************************************************* - - Synopsis [Deletes fanout for all objects in the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManFanoutStop( Aig_Man_t * p ) -{ - assert( p->pFanData != NULL ); - FREE( p->pFanData ); - p->nFansAlloc = 0; -} - -/**Function************************************************************* - - Synopsis [Adds fanout (pFanout) of node (pObj).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjAddFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout ) -{ - int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext; - assert( p->pFanData ); - assert( !Aig_IsComplement(pObj) && !Aig_IsComplement(pFanout) ); - assert( pFanout->Id > 0 ); - if ( pObj->Id >= p->nFansAlloc || pFanout->Id >= p->nFansAlloc ) - { - int nFansAlloc = 2 * AIG_MAX( pObj->Id, pFanout->Id ); - p->pFanData = REALLOC( int, p->pFanData, 5 * nFansAlloc ); - memset( p->pFanData + 5 * p->nFansAlloc, 0, sizeof(int) * 5 * (nFansAlloc - p->nFansAlloc) ); - p->nFansAlloc = nFansAlloc; - } - assert( pObj->Id < p->nFansAlloc && pFanout->Id < p->nFansAlloc ); - iFan = Aig_FanoutCreate( pFanout->Id, Aig_ObjWhatFanin(pFanout, pObj) ); - pPrevC = Aig_FanoutPrev( p->pFanData, iFan ); - pNextC = Aig_FanoutNext( p->pFanData, iFan ); - pFirst = Aig_FanoutObj( p->pFanData, pObj->Id ); - if ( *pFirst == 0 ) - { - *pFirst = iFan; - *pPrevC = iFan; - *pNextC = iFan; - } - else - { - pPrev = Aig_FanoutPrev( p->pFanData, *pFirst ); - pNext = Aig_FanoutNext( p->pFanData, *pPrev ); - assert( *pNext == *pFirst ); - *pPrevC = *pPrev; - *pNextC = *pFirst; - *pPrev = iFan; - *pNext = iFan; - } -} - -/**Function************************************************************* - - Synopsis [Removes fanout (pFanout) of node (pObj).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjRemoveFanout( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFanout ) -{ - int iFan, * pFirst, * pPrevC, * pNextC, * pPrev, * pNext; - assert( p->pFanData && pObj->Id < p->nFansAlloc && pFanout->Id < p->nFansAlloc ); - assert( !Aig_IsComplement(pObj) && !Aig_IsComplement(pFanout) ); - assert( pFanout->Id > 0 ); - iFan = Aig_FanoutCreate( pFanout->Id, Aig_ObjWhatFanin(pFanout, pObj) ); - pPrevC = Aig_FanoutPrev( p->pFanData, iFan ); - pNextC = Aig_FanoutNext( p->pFanData, iFan ); - pPrev = Aig_FanoutPrev( p->pFanData, *pNextC ); - pNext = Aig_FanoutNext( p->pFanData, *pPrevC ); - assert( *pPrev == iFan ); - assert( *pNext == iFan ); - pFirst = Aig_FanoutObj( p->pFanData, pObj->Id ); - assert( *pFirst > 0 ); - if ( *pFirst == iFan ) - { - if ( *pNextC == iFan ) - { - *pFirst = 0; - *pPrev = 0; - *pNext = 0; - *pPrevC = 0; - *pNextC = 0; - return; - } - *pFirst = *pNextC; - } - *pPrev = *pPrevC; - *pNext = *pNextC; - *pPrevC = 0; - *pNextC = 0; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigFrames.c b/src/abc8/aig/aigFrames.c deleted file mode 100644 index 4a3b0c7c..00000000 --- a/src/abc8/aig/aigFrames.c +++ /dev/null @@ -1,133 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigFrames.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Performs timeframe expansion of the AIG.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigFrames.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -static inline Aig_Obj_t * Aig_ObjFrames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return pObjMap[nFs*pObj->Id + i]; } -static inline void Aig_ObjSetFrames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i, Aig_Obj_t * pNode ) { pObjMap[nFs*pObj->Id + i] = pNode; } - -static inline Aig_Obj_t * Aig_ObjChild0Frames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return Aig_ObjFanin0(pObj)? Aig_NotCond(Aig_ObjFrames(pObjMap,nFs,Aig_ObjFanin0(pObj),i), Aig_ObjFaninC0(pObj)) : NULL; } -static inline Aig_Obj_t * Aig_ObjChild1Frames( Aig_Obj_t ** pObjMap, int nFs, Aig_Obj_t * pObj, int i ) { return Aig_ObjFanin1(pObj)? Aig_NotCond(Aig_ObjFrames(pObjMap,nFs,Aig_ObjFanin1(pObj),i), Aig_ObjFaninC1(pObj)) : NULL; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Performs timeframe expansion of the AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManFrames( Aig_Man_t * pAig, int nFs, int fInit, int fOuts, int fRegs, int fEnlarge, Aig_Obj_t *** ppObjMap ) -{ - Aig_Man_t * pFrames; - Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew; - Aig_Obj_t ** pObjMap; - int i, f; - - // create mapping for the frames nodes - pObjMap = ALLOC( Aig_Obj_t *, nFs * Aig_ManObjNumMax(pAig) ); - memset( pObjMap, 0, sizeof(Aig_Obj_t *) * nFs * Aig_ManObjNumMax(pAig) ); - - // start the fraig package - pFrames = Aig_ManStart( Aig_ManObjNumMax(pAig) * nFs ); - pFrames->pName = Aig_UtilStrsav( pAig->pName ); - // map constant nodes - for ( f = 0; f < nFs; f++ ) - Aig_ObjSetFrames( pObjMap, nFs, Aig_ManConst1(pAig), f, Aig_ManConst1(pFrames) ); - // create PI nodes for the frames - for ( f = 0; f < nFs; f++ ) - Aig_ManForEachPiSeq( pAig, pObj, i ) - Aig_ObjSetFrames( pObjMap, nFs, pObj, f, Aig_ObjCreatePi(pFrames) ); - // set initial state for the latches - if ( fInit ) - { - Aig_ManForEachLoSeq( pAig, pObj, i ) - Aig_ObjSetFrames( pObjMap, nFs, pObj, 0, Aig_ManConst0(pFrames) ); - } - else - { - Aig_ManForEachLoSeq( pAig, pObj, i ) - Aig_ObjSetFrames( pObjMap, nFs, pObj, 0, Aig_ObjCreatePi(pFrames) ); - } - - // add timeframes - for ( f = 0; f < nFs; f++ ) - { -// printf( "Frame = %d.\n", f ); - // add internal nodes of this frame - Aig_ManForEachNode( pAig, pObj, i ) - { -// Aig_Obj_t * pFanin0 = Aig_ObjChild0Frames(pObjMap,nFs,pObj,f); -// Aig_Obj_t * pFanin1 = Aig_ObjChild1Frames(pObjMap,nFs,pObj,f); -// printf( "Node = %3d. Fanin0 = %3d. Fanin1 = %3d.\n", pObj->Id, Aig_Regular(pFanin0)->Id, Aig_Regular(pFanin1)->Id ); - pObjNew = Aig_And( pFrames, Aig_ObjChild0Frames(pObjMap,nFs,pObj,f), Aig_ObjChild1Frames(pObjMap,nFs,pObj,f) ); - Aig_ObjSetFrames( pObjMap, nFs, pObj, f, pObjNew ); - } - // set the latch inputs and copy them into the latch outputs of the next frame - Aig_ManForEachLiLoSeq( pAig, pObjLi, pObjLo, i ) - { - pObjNew = Aig_ObjChild0Frames(pObjMap,nFs,pObjLi,f); - if ( f < nFs - 1 ) - Aig_ObjSetFrames( pObjMap, nFs, pObjLo, f+1, pObjNew ); - } - } - if ( fOuts ) - { - for ( f = fEnlarge?nFs-1:0; f < nFs; f++ ) - Aig_ManForEachPoSeq( pAig, pObj, i ) - { - pObjNew = Aig_ObjCreatePo( pFrames, Aig_ObjChild0Frames(pObjMap,nFs,pObj,f) ); - Aig_ObjSetFrames( pObjMap, nFs, pObj, f, pObjNew ); - } - } - if ( fRegs ) - { - pFrames->nRegs = pAig->nRegs; - Aig_ManForEachLiSeq( pAig, pObj, i ) - { - pObjNew = Aig_ObjCreatePo( pFrames, Aig_ObjChild0Frames(pObjMap,nFs,pObj,fEnlarge?0:nFs-1) ); - Aig_ObjSetFrames( pObjMap, nFs, pObj, nFs-1, pObjNew ); - } - } - Aig_ManCleanup( pFrames ); - // return the new manager - if ( ppObjMap ) - *ppObjMap = pObjMap; - else - free( pObjMap ); - return pFrames; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigHaig.c b/src/abc8/aig/aigHaig.c deleted file mode 100644 index eaf9fd05..00000000 --- a/src/abc8/aig/aigHaig.c +++ /dev/null @@ -1,270 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigHaig.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigHaig.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" -#include "satSolver.h" -#include "cnf.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -static inline Aig_Obj_t * Aig_HaigObjFrames( Aig_Obj_t ** ppMap, int nFrames, Aig_Obj_t * pObj, int f ) { return ppMap[nFrames*pObj->Id + f]; } -static inline void Aig_HaigObjSetFrames( Aig_Obj_t ** ppMap, int nFrames, Aig_Obj_t * pObj, int f, Aig_Obj_t * pNode ) { ppMap[nFrames*pObj->Id + f] = pNode; } -static inline Aig_Obj_t * Aig_HaigObjChild0Frames( Aig_Obj_t ** ppMap, int nFrames, Aig_Obj_t * pObj, int i ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin0(pObj)? Aig_NotCond(Aig_HaigObjFrames(ppMap,nFrames,Aig_ObjFanin0(pObj),i), Aig_ObjFaninC0(pObj)) : NULL; } -static inline Aig_Obj_t * Aig_HaigObjChild1Frames( Aig_Obj_t ** ppMap, int nFrames, Aig_Obj_t * pObj, int i ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? Aig_NotCond(Aig_HaigObjFrames(ppMap,nFrames,Aig_ObjFanin1(pObj),i), Aig_ObjFaninC1(pObj)) : NULL; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Performs speculative reduction for one node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Aig_ManHaigFramesNode( Aig_Obj_t ** ppMap, int nFrames, Aig_Man_t * pFrames, Aig_Obj_t * pObj, int iFrame ) -{ - Aig_Obj_t * pObjNew, * pObjNew2, * pObjRepr, * pObjReprNew, * pMiter; - // skip nodes without representative - pObjRepr = pObj->pHaig; - if ( pObjRepr == NULL ) - return; - assert( !Aig_IsComplement(pObjRepr) ); - assert( pObjRepr->Id < pObj->Id ); - // get the new node - pObjNew = Aig_HaigObjFrames( ppMap, nFrames, pObj, iFrame ); - // get the new node of the representative - pObjReprNew = Aig_HaigObjFrames( ppMap, nFrames, pObjRepr, iFrame ); - // if this is the same node, no need to add constraints - if ( Aig_Regular(pObjNew) == Aig_Regular(pObjReprNew) ) - return; - // these are different nodes - perform speculative reduction - pObjNew2 = Aig_NotCond( pObjReprNew, pObj->fPhase ^ pObjRepr->fPhase ); - // set the new node - Aig_HaigObjSetFrames( ppMap, nFrames, pObj, iFrame, pObjNew2 ); - // add the constraint - pMiter = Aig_Exor( pFrames, Aig_Regular(pObjNew), Aig_Regular(pObjReprNew) ); - pMiter = Aig_NotCond( pMiter, Aig_Regular(pMiter)->fPhase ^ Aig_IsComplement(pMiter) ); - pMiter = Aig_Not( pMiter ); - Aig_ObjCreatePo( pFrames, pMiter ); -} - -/**Function************************************************************* - - Synopsis [Prepares the inductive case with speculative reduction.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManHaigFrames( Aig_Man_t * pHaig, int nFrames ) -{ - Aig_Man_t * pFrames; - Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pObjNew; - Aig_Obj_t ** ppMap; - int i, k, f; - assert( nFrames >= 2 ); - assert( Aig_ManRegNum(pHaig) > 0 ); - assert( Aig_ManRegNum(pHaig) < Aig_ManPiNum(pHaig) ); - - // create node mapping - ppMap = ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pHaig) * nFrames ); - memset( ppMap, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pHaig) * nFrames ); - - // start the frames - pFrames = Aig_ManStart( Aig_ManObjNumMax(pHaig) * nFrames ); - pFrames->pName = Aig_UtilStrsav( pHaig->pName ); - pFrames->nRegs = pHaig->nRegs; - - // create PI nodes for the frames - for ( f = 0; f < nFrames; f++ ) - Aig_HaigObjSetFrames( ppMap, nFrames, Aig_ManConst1(pHaig), f, Aig_ManConst1(pFrames) ); - for ( f = 0; f < nFrames; f++ ) - Aig_ManForEachPiSeq( pHaig, pObj, i ) - Aig_HaigObjSetFrames( ppMap, nFrames, pObj, f, Aig_ObjCreatePi(pFrames) ); - // create latches for the first frame - Aig_ManForEachLoSeq( pHaig, pObj, i ) - Aig_HaigObjSetFrames( ppMap, nFrames, pObj, 0, Aig_ObjCreatePi(pFrames) ); - - // add timeframes - for ( f = 0; f < nFrames; f++ ) - { - // mark the asserts - if ( f == nFrames - 1 ) - pFrames->nAsserts = Aig_ManPoNum(pFrames); - // constrain latch outputs and internal nodes - Aig_ManForEachObj( pHaig, pObj, i ) - { - if ( Aig_ObjIsPi(pObj) && Aig_HaigObjFrames(ppMap, nFrames, pObj, f) == NULL ) - { - Aig_ManHaigFramesNode( ppMap, nFrames, pFrames, pObj, f ); - } - else if ( Aig_ObjIsNode(pObj) ) - { - pObjNew = Aig_And( pFrames, - Aig_HaigObjChild0Frames(ppMap,nFrames,pObj,f), - Aig_HaigObjChild1Frames(ppMap,nFrames,pObj,f) ); - Aig_HaigObjSetFrames( ppMap, nFrames, pObj, f, pObjNew ); - Aig_ManHaigFramesNode( ppMap, nFrames, pFrames, pObj, f ); - } - } - -/* - // set the constraints on the latch outputs - Aig_ManForEachLoSeq( pHaig, pObj, i ) - Aig_ManHaigFramesNode( ppMap, nFrames, pFrames, pObj, f ); - // add internal nodes of this frame - Aig_ManForEachNode( pHaig, pObj, i ) - { - pObjNew = Aig_And( pFrames, - Aig_HaigObjChild0Frames(ppMap,nFrames,pObj,f), - Aig_HaigObjChild1Frames(ppMap,nFrames,pObj,f) ); - Aig_HaigObjSetFrames( ppMap, nFrames, pObj, f, pObjNew ); - Aig_ManHaigFramesNode( ppMap, nFrames, pFrames, pObj, f ); - } -*/ - // transfer latch inputs to the latch outputs - Aig_ManForEachLiLoSeq( pHaig, pObjLi, pObjLo, k ) - { - pObjNew = Aig_HaigObjChild0Frames(ppMap,nFrames,pObjLi,f); - Aig_HaigObjSetFrames( ppMap, nFrames, pObjLo, f+1, pObjNew ); - } - } - - // remove dangling nodes - Aig_ManCleanup( pFrames ); - free( ppMap ); - return pFrames; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManHaigVerify( Aig_Man_t * pHaig ) -{ - int nBTLimit = 0; - Aig_Man_t * pFrames; - Cnf_Dat_t * pCnf; - sat_solver * pSat; - Aig_Obj_t * pObj; - int i, Lit, RetValue, Counter; - int clk = clock(); - - // create time frames with speculative reduction and convert them into CNF -clk = clock(); - pFrames = Aig_ManHaigFrames( pHaig, 2 ); - pCnf = Cnf_DeriveSimple( pFrames, Aig_ManPoNum(pFrames) - pFrames->nAsserts ); -// pCnf = Cnf_Derive( pFrames, Aig_ManPoNum(pFrames) - pFrames->nAsserts ); -//Cnf_DataWriteIntoFile( pCnf, "temp.cnf", 1 ); - // create the SAT solver to be used for this problem - pSat = Cnf_DataWriteIntoSolver( pCnf, 1, 0 ); - - printf( "HAIG regs = %d. HAIG nodes = %d. Outputs = %d.\n", - Aig_ManRegNum(pHaig), Aig_ManNodeNum(pHaig), Aig_ManPoNum(pHaig) ); - printf( "Frames regs = %d. Frames nodes = %d. Outputs = %d. Assumptions = %d. Asserts = %d.\n", - Aig_ManRegNum(pFrames), Aig_ManNodeNum(pFrames), Aig_ManPoNum(pFrames), - pFrames->nAsserts, Aig_ManPoNum(pFrames) - pFrames->nAsserts ); - -PRT( "Preparation", clock() - clk ); - if ( pSat == NULL ) - { - printf( "Aig_ManHaigVerify(): Computed CNF is not valid.\n" ); - return -1; - } - - // solve each output -clk = clock(); - Counter = 0; - Aig_ManForEachPo( pFrames, pObj, i ) - { - if ( i < pFrames->nAsserts ) - continue; - Lit = toLitCond( pCnf->pVarNums[pObj->Id], pObj->fPhase ); - RetValue = sat_solver_solve( pSat, &Lit, &Lit + 1, (sint64)nBTLimit, (sint64)0, (sint64)0, (sint64)0 ); - if ( RetValue != l_False ) - Counter++; - } -PRT( "Solving ", clock() - clk ); - if ( Counter ) - printf( "Verification failed for %d classes.\n", Counter ); - else - printf( "Verification is successful.\n" ); - - // clean up - Aig_ManStop( pFrames ); - Cnf_DataFree( pCnf ); - sat_solver_delete( pSat ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManHaigRecord( Aig_Man_t * p ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj; - int i; - // start the HAIG - p->pManHaig = Aig_ManDup( p, 1 ); - // set the pointers to the HAIG nodes - Aig_ManForEachObj( p, pObj, i ) - pObj->pHaig = pObj->pData; - // remove structural hashing table - Aig_TableClear( p->pManHaig ); - // perform a sequence of synthesis steps - pNew = Aig_ManRetimeFrontier( p, 10000 ); - // use the haig for verification - Aig_ManDumpBlif( pNew->pManHaig, "haig_temp.blif" ); - Aig_ManHaigVerify( pNew->pManHaig ); - Aig_ManStop( pNew ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigInter.c b/src/abc8/aig/aigInter.c deleted file mode 100644 index b3bc28b2..00000000 --- a/src/abc8/aig/aigInter.c +++ /dev/null @@ -1,174 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigInter.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Interpolate two AIGs.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigInter.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" -#include "cnf.h" -#include "satStore.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManInter( Aig_Man_t * pManOn, Aig_Man_t * pManOff, int fVerbose ) -{ - void * pSatCnf = NULL; - Inta_Man_t * pManInter; - Aig_Man_t * pRes; - sat_solver * pSat; - Cnf_Dat_t * pCnfOn, * pCnfOff; - Vec_Int_t * vVarsAB; - Aig_Obj_t * pObj, * pObj2; - int Lits[3], status, i; - int clk = clock(); - - assert( Aig_ManPiNum(pManOn) == Aig_ManPiNum(pManOff) ); - - // derive CNFs - pCnfOn = Cnf_Derive( pManOn, 0 ); - pCnfOff = Cnf_Derive( pManOff, 0 ); -// pCnfOn = Cnf_DeriveSimple( pManOn, 0 ); -// pCnfOff = Cnf_DeriveSimple( pManOff, 0 ); - Cnf_DataLift( pCnfOff, pCnfOn->nVars ); - - // start the solver - pSat = sat_solver_new(); - sat_solver_store_alloc( pSat ); - sat_solver_setnvars( pSat, pCnfOn->nVars + pCnfOff->nVars ); - - // add clauses of A - for ( i = 0; i < pCnfOn->nClauses; i++ ) - { - if ( !sat_solver_addclause( pSat, pCnfOn->pClauses[i], pCnfOn->pClauses[i+1] ) ) - { - Cnf_DataFree( pCnfOn ); - Cnf_DataFree( pCnfOff ); - sat_solver_delete( pSat ); - return NULL; - } - } - sat_solver_store_mark_clauses_a( pSat ); - - // add clauses of B - for ( i = 0; i < pCnfOff->nClauses; i++ ) - { - if ( !sat_solver_addclause( pSat, pCnfOff->pClauses[i], pCnfOff->pClauses[i+1] ) ) - { - Cnf_DataFree( pCnfOn ); - Cnf_DataFree( pCnfOff ); - sat_solver_delete( pSat ); - return NULL; - } - } - - // add PI clauses - // collect the common variables - vVarsAB = Vec_IntAlloc( Aig_ManPiNum(pManOn) ); - Aig_ManForEachPi( pManOn, pObj, i ) - { - Vec_IntPush( vVarsAB, pCnfOn->pVarNums[pObj->Id] ); - pObj2 = Aig_ManPi( pManOff, i ); - - Lits[0] = toLitCond( pCnfOn->pVarNums[pObj->Id], 0 ); - Lits[1] = toLitCond( pCnfOff->pVarNums[pObj2->Id], 1 ); - if ( !sat_solver_addclause( pSat, Lits, Lits+2 ) ) - assert( 0 ); - Lits[0] = toLitCond( pCnfOn->pVarNums[pObj->Id], 1 ); - Lits[1] = toLitCond( pCnfOff->pVarNums[pObj2->Id], 0 ); - if ( !sat_solver_addclause( pSat, Lits, Lits+2 ) ) - assert( 0 ); - } - Cnf_DataFree( pCnfOn ); - Cnf_DataFree( pCnfOff ); - sat_solver_store_mark_roots( pSat ); - if ( fVerbose ) - { - PRT( "Prepare", clock() - clk ); - } - -/* - status = sat_solver_simplify(pSat); - if ( status == 0 ) - { - Vec_IntFree( vVarsAB ); - Cnf_DataFree( pCnfOn ); - Cnf_DataFree( pCnfOff ); - sat_solver_delete( pSat ); - return NULL; - } -*/ - - // solve the problem - clk = clock(); - status = sat_solver_solve( pSat, NULL, NULL, (sint64)0, (sint64)0, (sint64)0, (sint64)0 ); - if ( fVerbose ) - { - PRT( "Solving", clock() - clk ); - } - if ( status == l_False ) - { - pSatCnf = sat_solver_store_release( pSat ); -// printf( "unsat\n" ); - } - else if ( status == l_True ) - { -// printf( "sat\n" ); - } - else - { -// printf( "undef\n" ); - } - sat_solver_delete( pSat ); - if ( pSatCnf == NULL ) - { - printf( "The SAT problem is not unsat.\n" ); - Vec_IntFree( vVarsAB ); - return NULL; - } - - // create the resulting manager - pManInter = Inta_ManAlloc(); - pRes = Inta_ManInterpolate( pManInter, pSatCnf, vVarsAB, fVerbose ); - Inta_ManFree( pManInter ); - - Vec_IntFree( vVarsAB ); - Sto_ManFree( pSatCnf ); - return pRes; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigMan.c b/src/abc8/aig/aigMan.c deleted file mode 100644 index da6fb9ba..00000000 --- a/src/abc8/aig/aigMan.c +++ /dev/null @@ -1,369 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigMan.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [AIG manager.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigMan.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" -//#include "tim.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Starts the AIG manager.] - - Description [The argument of this procedure is a soft limit on the - the number of nodes, or 0 if the limit is unknown.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManStart( int nNodesMax ) -{ - Aig_Man_t * p; - if ( nNodesMax <= 0 ) - nNodesMax = 10007; - // start the manager - p = ALLOC( Aig_Man_t, 1 ); - memset( p, 0, sizeof(Aig_Man_t) ); - // perform initializations - p->nTravIds = 1; - p->fCatchExor = 0; - // allocate arrays for nodes - p->vPis = Vec_PtrAlloc( 100 ); - p->vPos = Vec_PtrAlloc( 100 ); - p->vObjs = Vec_PtrAlloc( 1000 ); - p->vBufs = Vec_PtrAlloc( 100 ); - // prepare the internal memory manager - p->pMemObjs = Aig_MmFixedStart( sizeof(Aig_Obj_t), nNodesMax ); - // create the constant node - p->pConst1 = Aig_ManFetchMemory( p ); - p->pConst1->Type = AIG_OBJ_CONST1; - p->pConst1->fPhase = 1; - p->nObjs[AIG_OBJ_CONST1]++; - // start the table - p->nTableSize = Aig_PrimeCudd( nNodesMax ); - p->pTable = ALLOC( Aig_Obj_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize ); - return p; -} - -/**Function************************************************************* - - Synopsis [Duplicates the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManStartFrom( Aig_Man_t * p ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj; - int i; - // create the new manager - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - // create the PIs - Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); - Aig_ManForEachPi( p, pObj, i ) - pObj->pData = Aig_ObjCreatePi(pNew); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Duplicates the AIG manager recursively.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ManDup_rec( Aig_Man_t * pNew, Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - if ( pObj->pData ) - return pObj->pData; - Aig_ManDup_rec( pNew, p, Aig_ObjFanin0(pObj) ); - if ( Aig_ObjIsBuf(pObj) ) - return pObj->pData = Aig_ObjChild0Copy(pObj); - Aig_ManDup_rec( pNew, p, Aig_ObjFanin1(pObj) ); - if ( pNew->pManHaig == NULL ) - return pObj->pData = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - else - { - Aig_Obj_t * pObjNew = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - Aig_Regular(pObjNew->pHaig)->pHaig = Aig_Regular(pObj->pHaig); - return pObj->pData = pObjNew; - } -} - -/**Function************************************************************* - - Synopsis [Duplicates the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManDup( Aig_Man_t * p, int fOrdered ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj, * pObjNew; - int i; - // create the new manager - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - pNew->nRegs = p->nRegs; - pNew->nAsserts = p->nAsserts; - pNew->pManHaig = p->pManHaig; - if ( p->vFlopNums ) - pNew->vFlopNums = Vec_IntDup( p->vFlopNums ); - // create the PIs - Aig_ManCleanData( p ); - Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); - Aig_ManConst1(pNew)->pHaig = Aig_ManConst1(p)->pHaig; - Aig_ManForEachPi( p, pObj, i ) - { - pObjNew = Aig_ObjCreatePi( pNew ); - pObjNew->pHaig = pObj->pHaig; - pObjNew->Level = pObj->Level; - pObj->pData = pObjNew; - } - // duplicate internal nodes - if ( fOrdered ) - { - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsBuf(pObj) ) - { - if ( pNew->pManHaig == NULL ) - pObj->pData = Aig_ObjChild0Copy(pObj); - else - { - Aig_Obj_t * pObjNew = Aig_ObjChild0Copy(pObj); - Aig_Regular(pObjNew->pHaig)->pHaig = Aig_Regular(pObj->pHaig); - pObj->pData = pObjNew; - } - } - else if ( Aig_ObjIsNode(pObj) ) - { - if ( pNew->pManHaig == NULL ) - pObj->pData = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - else - { - Aig_Obj_t * pObjNew = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - Aig_Regular(pObjNew->pHaig)->pHaig = Aig_Regular(pObj->pHaig); - pObj->pData = pObjNew; - } - } - } - else - { - Aig_ManForEachObj( p, pObj, i ) - if ( !Aig_ObjIsPo(pObj) ) - { - Aig_ManDup_rec( pNew, p, pObj ); - assert( pObj->Level == ((Aig_Obj_t*)pObj->pData)->Level ); - } - } - // add the POs - Aig_ManForEachPo( p, pObj, i ) - { - pObjNew = Aig_ObjCreatePo( pNew, Aig_ObjChild0Copy(pObj) ); - pObjNew->pHaig = pObj->pHaig; - pObj->pData = pObjNew; - } - assert( Aig_ManBufNum(p) != 0 || Aig_ManNodeNum(p) == Aig_ManNodeNum(pNew) ); - // pass the HAIG to the new AIG - p->pManHaig = NULL; - Aig_ManForEachObj( p, pObj, i ) - pObj->pHaig = NULL; - // check the resulting network - if ( !Aig_ManCheck(pNew) ) - printf( "Aig_ManDup(): The check has failed.\n" ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Extracts the miter composed of XOR of the two nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManExtractMiter( Aig_Man_t * p, Aig_Obj_t * pNode1, Aig_Obj_t * pNode2 ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj; - int i; - // create the new manager - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - // create the PIs - Aig_ManCleanData( p ); - Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); - Aig_ManForEachPi( p, pObj, i ) - pObj->pData = Aig_ObjCreatePi(pNew); - // dump the nodes - Aig_ManDup_rec( pNew, p, pNode1 ); - Aig_ManDup_rec( pNew, p, pNode2 ); - // construct the EXOR - pObj = Aig_Exor( pNew, pNode1->pData, pNode2->pData ); - pObj = Aig_NotCond( pObj, Aig_Regular(pObj)->fPhase ^ Aig_IsComplement(pObj) ); - // add the PO - Aig_ObjCreatePo( pNew, pObj ); - // check the resulting network - if ( !Aig_ManCheck(pNew) ) - printf( "Aig_ManDup(): The check has failed.\n" ); - return pNew; -} - - -/**Function************************************************************* - - Synopsis [Stops the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManStop( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - if ( p->pManHaig ) - Aig_ManStop( p->pManHaig ); - if ( p->vMapped ) - Vec_PtrFree( p->vMapped ); - // print time - if ( p->time1 ) { PRT( "time1", p->time1 ); } - if ( p->time2 ) { PRT( "time2", p->time2 ); } - // delete timing -// if ( p->pManTime ) -// Tim_ManStop( p->pManTime ); - // delete fanout - if ( p->pFanData ) - Aig_ManFanoutStop( p ); - // make sure the nodes have clean marks - Aig_ManForEachObj( p, pObj, i ) - assert( !pObj->fMarkA && !pObj->fMarkB ); -// Aig_TableProfile( p ); - Aig_MmFixedStop( p->pMemObjs, 0 ); - if ( p->vPis ) Vec_PtrFree( p->vPis ); - if ( p->vPos ) Vec_PtrFree( p->vPos ); - if ( p->vObjs ) Vec_PtrFree( p->vObjs ); - if ( p->vBufs ) Vec_PtrFree( p->vBufs ); - if ( p->vLevelR ) Vec_IntFree( p->vLevelR ); - if ( p->vLevels ) Vec_VecFree( p->vLevels ); - if ( p->vFlopNums) Vec_IntFree( p->vFlopNums ); - FREE( p->pSeqModel ); - FREE( p->pName ); - FREE( p->pObjCopies ); - FREE( p->pReprs ); - FREE( p->pEquivs ); - free( p->pTable ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManCleanup( Aig_Man_t * p ) -{ - Vec_Ptr_t * vObjs; - Aig_Obj_t * pNode; - int i, nNodesOld; - nNodesOld = Aig_ManNodeNum(p); - // collect roots of dangling nodes - vObjs = Vec_PtrAlloc( 100 ); - Aig_ManForEachObj( p, pNode, i ) - if ( Aig_ObjIsNode(pNode) && Aig_ObjRefs(pNode) == 0 ) - Vec_PtrPush( vObjs, pNode ); - // recursively remove dangling nodes - Vec_PtrForEachEntry( vObjs, pNode, i ) - Aig_ObjDelete_rec( p, pNode, 1 ); - Vec_PtrFree( vObjs ); - return nNodesOld - Aig_ManNodeNum(p); -} - -/**Function************************************************************* - - Synopsis [Stops the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManPrintStats( Aig_Man_t * p ) -{ - printf( "PI/PO/Lat = %5d/%5d/%5d ", Aig_ManPiNum(p), Aig_ManPoNum(p), Aig_ManLatchNum(p) ); - printf( "A = %7d. ", Aig_ManAndNum(p) ); - if ( Aig_ManExorNum(p) ) - printf( "X = %5d. ", Aig_ManExorNum(p) ); - if ( Aig_ManBufNum(p) ) - printf( "B = %5d. ", Aig_ManBufNum(p) ); -// printf( "Cre = %6d. ", p->nCreated ); -// printf( "Del = %6d. ", p->nDeleted ); -// printf( "Lev = %3d. ", Aig_ManCountLevels(p) ); - printf( "Max = %7d. ", Aig_ManObjNumMax(p) ); - printf( "Lev = %3d. ", Aig_ManLevels(p) ); - if ( Aig_ManRegNum(p) ) - printf( "Lat = %5d. ", Aig_ManRegNum(p) ); - printf( "\n" ); - fflush( stdout ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigMem.c b/src/abc8/aig/aigMem.c deleted file mode 100644 index dab90777..00000000 --- a/src/abc8/aig/aigMem.c +++ /dev/null @@ -1,598 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigMem.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Memory managers.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigMem.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -struct Aig_MmFixed_t_ -{ - // information about individual entries - int nEntrySize; // the size of one entry - int nEntriesAlloc; // the total number of entries allocated - int nEntriesUsed; // the number of entries in use - int nEntriesMax; // the max number of entries in use - char * pEntriesFree; // the linked list of free entries - - // this is where the memory is stored - int nChunkSize; // the size of one chunk - int nChunksAlloc; // the maximum number of memory chunks - int nChunks; // the current number of memory chunks - char ** pChunks; // the allocated memory - - // statistics - int nMemoryUsed; // memory used in the allocated entries - int nMemoryAlloc; // memory allocated -}; - -struct Aig_MmFlex_t_ -{ - // information about individual entries - int nEntriesUsed; // the number of entries allocated - char * pCurrent; // the current pointer to free memory - char * pEnd; // the first entry outside the free memory - - // this is where the memory is stored - int nChunkSize; // the size of one chunk - int nChunksAlloc; // the maximum number of memory chunks - int nChunks; // the current number of memory chunks - char ** pChunks; // the allocated memory - - // statistics - int nMemoryUsed; // memory used in the allocated entries - int nMemoryAlloc; // memory allocated -}; - -struct Aig_MmStep_t_ -{ - int nMems; // the number of fixed memory managers employed - Aig_MmFixed_t ** pMems; // memory managers: 2^1 words, 2^2 words, etc - int nMapSize; // the size of the memory array - Aig_MmFixed_t ** pMap; // maps the number of bytes into its memory manager -}; - -#define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num))) -#define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0) -#define REALLOC(type, obj, num) \ - ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \ - ((type *) malloc(sizeof(type) * (num)))) - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Allocates memory pieces of fixed size.] - - Description [The size of the chunk is computed as the minimum of - 1024 entries and 64K. Can only work with entry size at least 4 byte long.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_MmFixed_t * Aig_MmFixedStart( int nEntrySize, int nEntriesMax ) -{ - Aig_MmFixed_t * p; - - p = ALLOC( Aig_MmFixed_t, 1 ); - memset( p, 0, sizeof(Aig_MmFixed_t) ); - - p->nEntrySize = nEntrySize; - p->nEntriesAlloc = 0; - p->nEntriesUsed = 0; - p->pEntriesFree = NULL; - - p->nChunkSize = nEntriesMax / 8; - if ( p->nChunkSize < 8 ) - p->nChunkSize = 8; - - p->nChunksAlloc = 64; - p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); - - p->nMemoryUsed = 0; - p->nMemoryAlloc = 0; - return p; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmFixedStop( Aig_MmFixed_t * p, int fVerbose ) -{ - int i; - if ( p == NULL ) - return; - if ( fVerbose ) - { - printf( "Fixed memory manager: Entry = %5d. Chunk = %5d. Chunks used = %5d.\n", - p->nEntrySize, p->nChunkSize, p->nChunks ); - printf( " Entries used = %8d. Entries peak = %8d. Memory used = %8d. Memory alloc = %8d.\n", - p->nEntriesUsed, p->nEntriesMax, p->nEntrySize * p->nEntriesUsed, p->nMemoryAlloc ); - } - for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Aig_MmFixedEntryFetch( Aig_MmFixed_t * p ) -{ - char * pTemp; - int i; - - // check if there are still free entries - if ( p->nEntriesUsed == p->nEntriesAlloc ) - { // need to allocate more entries - assert( p->pEntriesFree == NULL ); - if ( p->nChunks == p->nChunksAlloc ) - { - p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); - } - p->pEntriesFree = ALLOC( char, p->nEntrySize * p->nChunkSize ); - p->nMemoryAlloc += p->nEntrySize * p->nChunkSize; - // transform these entries into a linked list - pTemp = p->pEntriesFree; - for ( i = 1; i < p->nChunkSize; i++ ) - { - *((char **)pTemp) = pTemp + p->nEntrySize; - pTemp += p->nEntrySize; - } - // set the last link - *((char **)pTemp) = NULL; - // add the chunk to the chunk storage - p->pChunks[ p->nChunks++ ] = p->pEntriesFree; - // add to the number of entries allocated - p->nEntriesAlloc += p->nChunkSize; - } - // incrememt the counter of used entries - p->nEntriesUsed++; - if ( p->nEntriesMax < p->nEntriesUsed ) - p->nEntriesMax = p->nEntriesUsed; - // return the first entry in the free entry list - pTemp = p->pEntriesFree; - p->pEntriesFree = *((char **)pTemp); - return pTemp; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmFixedEntryRecycle( Aig_MmFixed_t * p, char * pEntry ) -{ - // decrement the counter of used entries - p->nEntriesUsed--; - // add the entry to the linked list of free entries - *((char **)pEntry) = p->pEntriesFree; - p->pEntriesFree = pEntry; -} - -/**Function************************************************************* - - Synopsis [] - - Description [Relocates all the memory except the first chunk.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmFixedRestart( Aig_MmFixed_t * p ) -{ - int i; - char * pTemp; - if ( p->nChunks == 0 ) - return; - // deallocate all chunks except the first one - for ( i = 1; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - p->nChunks = 1; - // transform these entries into a linked list - pTemp = p->pChunks[0]; - for ( i = 1; i < p->nChunkSize; i++ ) - { - *((char **)pTemp) = pTemp + p->nEntrySize; - pTemp += p->nEntrySize; - } - // set the last link - *((char **)pTemp) = NULL; - // set the free entry list - p->pEntriesFree = p->pChunks[0]; - // set the correct statistics - p->nMemoryAlloc = p->nEntrySize * p->nChunkSize; - p->nMemoryUsed = 0; - p->nEntriesAlloc = p->nChunkSize; - p->nEntriesUsed = 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_MmFixedReadMemUsage( Aig_MmFixed_t * p ) -{ - return p->nMemoryAlloc; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_MmFixedReadMaxEntriesUsed( Aig_MmFixed_t * p ) -{ - return p->nEntriesMax; -} - - - -/**Function************************************************************* - - Synopsis [Allocates entries of flexible size.] - - Description [Can only work with entry size at least 4 byte long.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_MmFlex_t * Aig_MmFlexStart() -{ - Aig_MmFlex_t * p; - - p = ALLOC( Aig_MmFlex_t, 1 ); - memset( p, 0, sizeof(Aig_MmFlex_t) ); - - p->nEntriesUsed = 0; - p->pCurrent = NULL; - p->pEnd = NULL; - - p->nChunkSize = (1 << 18); - p->nChunksAlloc = 64; - p->nChunks = 0; - p->pChunks = ALLOC( char *, p->nChunksAlloc ); - - p->nMemoryUsed = 0; - p->nMemoryAlloc = 0; - return p; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmFlexStop( Aig_MmFlex_t * p, int fVerbose ) -{ - int i; - if ( p == NULL ) - return; - if ( fVerbose ) - { - printf( "Flexible memory manager: Chunk size = %d. Chunks used = %d.\n", - p->nChunkSize, p->nChunks ); - printf( " Entries used = %d. Memory used = %d. Memory alloc = %d.\n", - p->nEntriesUsed, p->nMemoryUsed, p->nMemoryAlloc ); - } - for ( i = 0; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - free( p->pChunks ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Aig_MmFlexEntryFetch( Aig_MmFlex_t * p, int nBytes ) -{ - char * pTemp; - // check if there are still free entries - if ( p->pCurrent == NULL || p->pCurrent + nBytes > p->pEnd ) - { // need to allocate more entries - if ( p->nChunks == p->nChunksAlloc ) - { - p->nChunksAlloc *= 2; - p->pChunks = REALLOC( char *, p->pChunks, p->nChunksAlloc ); - } - if ( nBytes > p->nChunkSize ) - { - // resize the chunk size if more memory is requested than it can give - // (ideally, this should never happen) - p->nChunkSize = 2 * nBytes; - } - p->pCurrent = ALLOC( char, p->nChunkSize ); - p->pEnd = p->pCurrent + p->nChunkSize; - p->nMemoryAlloc += p->nChunkSize; - // add the chunk to the chunk storage - p->pChunks[ p->nChunks++ ] = p->pCurrent; - } - assert( p->pCurrent + nBytes <= p->pEnd ); - // increment the counter of used entries - p->nEntriesUsed++; - // keep track of the memory used - p->nMemoryUsed += nBytes; - // return the next entry - pTemp = p->pCurrent; - p->pCurrent += nBytes; - return pTemp; -} - -/**Function************************************************************* - - Synopsis [] - - Description [Relocates all the memory except the first chunk.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmFlexRestart( Aig_MmFlex_t * p ) -{ - int i; - if ( p->nChunks == 0 ) - return; - // deallocate all chunks except the first one - for ( i = 1; i < p->nChunks; i++ ) - free( p->pChunks[i] ); - p->nChunks = 1; - p->nMemoryAlloc = p->nChunkSize; - // transform these entries into a linked list - p->pCurrent = p->pChunks[0]; - p->pEnd = p->pCurrent + p->nChunkSize; - p->nEntriesUsed = 0; - p->nMemoryUsed = 0; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_MmFlexReadMemUsage( Aig_MmFlex_t * p ) -{ - return p->nMemoryUsed; -} - - - - - -/**Function************************************************************* - - Synopsis [Starts the hierarchical memory manager.] - - Description [This manager can allocate entries of any size. - Iternally they are mapped into the entries with the number of bytes - equal to the power of 2. The smallest entry size is 8 bytes. The - next one is 16 bytes etc. So, if the user requests 6 bytes, he gets - 8 byte entry. If we asks for 25 bytes, he gets 32 byte entry etc. - The input parameters "nSteps" says how many fixed memory managers - are employed internally. Calling this procedure with nSteps equal - to 10 results in 10 hierarchically arranged internal memory managers, - which can allocate up to 4096 (1Kb) entries. Requests for larger - entries are handed over to malloc() and then free()ed.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_MmStep_t * Aig_MmStepStart( int nSteps ) -{ - Aig_MmStep_t * p; - int i, k; - p = ALLOC( Aig_MmStep_t, 1 ); - memset( p, 0, sizeof(Aig_MmStep_t) ); - p->nMems = nSteps; - // start the fixed memory managers - p->pMems = ALLOC( Aig_MmFixed_t *, p->nMems ); - for ( i = 0; i < p->nMems; i++ ) - p->pMems[i] = Aig_MmFixedStart( (8<<i), (1<<13) ); - // set up the mapping of the required memory size into the corresponding manager - p->nMapSize = (4<<p->nMems); - p->pMap = ALLOC( Aig_MmFixed_t *, p->nMapSize+1 ); - p->pMap[0] = NULL; - for ( k = 1; k <= 4; k++ ) - p->pMap[k] = p->pMems[0]; - for ( i = 0; i < p->nMems; i++ ) - for ( k = (4<<i)+1; k <= (8<<i); k++ ) - p->pMap[k] = p->pMems[i]; -//for ( i = 1; i < 100; i ++ ) -//printf( "%10d: size = %10d\n", i, p->pMap[i]->nEntrySize ); - return p; -} - -/**Function************************************************************* - - Synopsis [Stops the memory manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmStepStop( Aig_MmStep_t * p, int fVerbose ) -{ - int i; - for ( i = 0; i < p->nMems; i++ ) - Aig_MmFixedStop( p->pMems[i], fVerbose ); -// if ( p->pLargeChunks ) -// { -// for ( i = 0; i < p->nLargeChunks; i++ ) -// free( p->pLargeChunks[i] ); -// free( p->pLargeChunks ); -// } - free( p->pMems ); - free( p->pMap ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Creates the entry.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Aig_MmStepEntryFetch( Aig_MmStep_t * p, int nBytes ) -{ - if ( nBytes == 0 ) - return NULL; - if ( nBytes > p->nMapSize ) - { -// printf( "Allocating %d bytes.\n", nBytes ); -/* - if ( p->nLargeChunks == p->nLargeChunksAlloc ) - { - if ( p->nLargeChunksAlloc == 0 ) - p->nLargeChunksAlloc = 5; - p->nLargeChunksAlloc *= 2; - p->pLargeChunks = REALLOC( char *, p->pLargeChunks, p->nLargeChunksAlloc ); - } - p->pLargeChunks[ p->nLargeChunks++ ] = ALLOC( char, nBytes ); - return p->pLargeChunks[ p->nLargeChunks - 1 ]; -*/ - return ALLOC( char, nBytes ); - } - return Aig_MmFixedEntryFetch( p->pMap[nBytes] ); -} - - -/**Function************************************************************* - - Synopsis [Recycles the entry.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_MmStepEntryRecycle( Aig_MmStep_t * p, char * pEntry, int nBytes ) -{ - if ( nBytes == 0 ) - return; - if ( nBytes > p->nMapSize ) - { - free( pEntry ); - return; - } - Aig_MmFixedEntryRecycle( p->pMap[nBytes], pEntry ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_MmStepReadMemUsage( Aig_MmStep_t * p ) -{ - int i, nMemTotal = 0; - for ( i = 0; i < p->nMems; i++ ) - nMemTotal += p->pMems[i]->nMemoryAlloc; - return nMemTotal; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// diff --git a/src/abc8/aig/aigMffc.c b/src/abc8/aig/aigMffc.c deleted file mode 100644 index 47ce896d..00000000 --- a/src/abc8/aig/aigMffc.c +++ /dev/null @@ -1,297 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigMffc.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Computation of MFFCs.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigMffc.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Dereferences the node's MFFC.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeDeref_rec( Aig_Obj_t * pNode, unsigned LevelMin ) -{ - Aig_Obj_t * pFanin; - int Counter = 0; - if ( Aig_ObjIsPi(pNode) ) - return 0; - // consider the first fanin - pFanin = Aig_ObjFanin0(pNode); - assert( pFanin->nRefs > 0 ); - if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeDeref_rec( pFanin, LevelMin ); - // skip the buffer - if ( Aig_ObjIsBuf(pNode) ) - return Counter; - assert( Aig_ObjIsNode(pNode) ); - // consider the second fanin - pFanin = Aig_ObjFanin1(pNode); - assert( pFanin->nRefs > 0 ); - if ( --pFanin->nRefs == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeDeref_rec( pFanin, LevelMin ); - return Counter + 1; -} - -/**Function************************************************************* - - Synopsis [References the node's MFFC.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeRef_rec( Aig_Obj_t * pNode, unsigned LevelMin ) -{ - Aig_Obj_t * pFanin; - int Counter = 0; - if ( Aig_ObjIsPi(pNode) ) - return 0; - // consider the first fanin - pFanin = Aig_ObjFanin0(pNode); - if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeRef_rec( pFanin, LevelMin ); - // skip the buffer - if ( Aig_ObjIsBuf(pNode) ) - return Counter; - assert( Aig_ObjIsNode(pNode) ); - // consider the second fanin - pFanin = Aig_ObjFanin1(pNode); - if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeRef_rec( pFanin, LevelMin ); - return Counter + 1; -} - -/**Function************************************************************* - - Synopsis [References the node's MFFC.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeRefLabel_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin ) -{ - Aig_Obj_t * pFanin; - int Counter = 0; - if ( Aig_ObjIsPi(pNode) ) - return 0; - Aig_ObjSetTravIdCurrent( p, pNode ); - // consider the first fanin - pFanin = Aig_ObjFanin0(pNode); - if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin ); - if ( Aig_ObjIsBuf(pNode) ) - return Counter; - assert( Aig_ObjIsNode(pNode) ); - // consider the second fanin - pFanin = Aig_ObjFanin1(pNode); - if ( pFanin->nRefs++ == 0 && (!LevelMin || pFanin->Level > LevelMin) ) - Counter += Aig_NodeRefLabel_rec( p, pFanin, LevelMin ); - return Counter + 1; -} - -/**Function************************************************************* - - Synopsis [Collects the internal and boundary nodes in the derefed MFFC.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_NodeMffsSupp_rec( Aig_Man_t * p, Aig_Obj_t * pNode, unsigned LevelMin, Vec_Ptr_t * vSupp, int fTopmost, Aig_Obj_t * pObjSkip ) -{ - // skip visited nodes - if ( Aig_ObjIsTravIdCurrent(p, pNode) ) - return; - Aig_ObjSetTravIdCurrent(p, pNode); - // add to the new support nodes - if ( !fTopmost && pNode != pObjSkip && (Aig_ObjIsPi(pNode) || pNode->nRefs > 0 || pNode->Level <= LevelMin) ) - { - if ( vSupp ) Vec_PtrPush( vSupp, pNode ); - return; - } - assert( Aig_ObjIsNode(pNode) ); - // recur on the children - Aig_NodeMffsSupp_rec( p, Aig_ObjFanin0(pNode), LevelMin, vSupp, 0, pObjSkip ); - Aig_NodeMffsSupp_rec( p, Aig_ObjFanin1(pNode), LevelMin, vSupp, 0, pObjSkip ); -} - -/**Function************************************************************* - - Synopsis [Collects the support of depth-limited MFFC.] - - Description [Returns the number of internal nodes in the MFFC.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeMffsSupp( Aig_Man_t * p, Aig_Obj_t * pNode, int LevelMin, Vec_Ptr_t * vSupp ) -{ - int ConeSize1, ConeSize2; - assert( !Aig_IsComplement(pNode) ); - assert( Aig_ObjIsNode(pNode) ); - if ( vSupp ) Vec_PtrClear( vSupp ); - Aig_ManIncrementTravId( p ); - ConeSize1 = Aig_NodeDeref_rec( pNode, LevelMin ); - Aig_NodeMffsSupp_rec( p, pNode, LevelMin, vSupp, 1, NULL ); - ConeSize2 = Aig_NodeRef_rec( pNode, LevelMin ); - assert( ConeSize1 == ConeSize2 ); - assert( ConeSize1 > 0 ); - return ConeSize1; -} - -/**Function************************************************************* - - Synopsis [Labels the nodes in the MFFC.] - - Description [Returns the number of internal nodes in the MFFC.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeMffsLabel( Aig_Man_t * p, Aig_Obj_t * pNode ) -{ - int ConeSize1, ConeSize2; - assert( !Aig_IsComplement(pNode) ); - assert( Aig_ObjIsNode(pNode) ); - Aig_ManIncrementTravId( p ); - ConeSize1 = Aig_NodeDeref_rec( pNode, 0 ); - ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 ); - assert( ConeSize1 == ConeSize2 ); - assert( ConeSize1 > 0 ); - return ConeSize1; -} - -/**Function************************************************************* - - Synopsis [Labels the nodes in the MFFC.] - - Description [Returns the number of internal nodes in the MFFC.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeMffsLabelCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves ) -{ - Aig_Obj_t * pObj; - int i, ConeSize1, ConeSize2; - assert( !Aig_IsComplement(pNode) ); - assert( Aig_ObjIsNode(pNode) ); - Aig_ManIncrementTravId( p ); - Vec_PtrForEachEntry( vLeaves, pObj, i ) - pObj->nRefs++; - ConeSize1 = Aig_NodeDeref_rec( pNode, 0 ); - ConeSize2 = Aig_NodeRefLabel_rec( p, pNode, 0 ); - Vec_PtrForEachEntry( vLeaves, pObj, i ) - pObj->nRefs--; - assert( ConeSize1 == ConeSize2 ); - assert( ConeSize1 > 0 ); - return ConeSize1; -} - -/**Function************************************************************* - - Synopsis [Expands the cut by adding the most closely related node.] - - Description [Returns 1 if the cut exists.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_NodeMffsExtendCut( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vResult ) -{ - Aig_Obj_t * pObj, * pLeafBest; - int i, LevelMax, ConeSize1, ConeSize2, ConeCur1, ConeCur2, ConeBest; - // dereference the current cut - LevelMax = 0; - Vec_PtrForEachEntry( vLeaves, pObj, i ) - LevelMax = AIG_MAX( LevelMax, (int)pObj->Level ); - if ( LevelMax == 0 ) - return 0; - // dereference the cut - ConeSize1 = Aig_NodeDeref_rec( pNode, 0 ); - // try expanding each node in the boundary - ConeBest = AIG_INFINITY; - pLeafBest = NULL; - Vec_PtrForEachEntry( vLeaves, pObj, i ) - { - if ( (int)pObj->Level != LevelMax ) - continue; - ConeCur1 = Aig_NodeDeref_rec( pObj, 0 ); - if ( ConeBest > ConeCur1 ) - { - ConeBest = ConeCur1; - pLeafBest = pObj; - } - ConeCur2 = Aig_NodeRef_rec( pObj, 0 ); - assert( ConeCur1 == ConeCur2 ); - } - assert( pLeafBest != NULL ); - assert( Aig_ObjIsNode(pLeafBest) ); - // deref the best leaf - ConeCur1 = Aig_NodeDeref_rec( pLeafBest, 0 ); - // collect the cut nodes - Vec_PtrClear( vResult ); - Aig_ManIncrementTravId( p ); - Aig_NodeMffsSupp_rec( p, pNode, 0, vResult, 1, pLeafBest ); - // ref the nodes - ConeCur2 = Aig_NodeRef_rec( pLeafBest, 0 ); - assert( ConeCur1 == ConeCur2 ); - // ref the original node - ConeSize2 = Aig_NodeRef_rec( pNode, 0 ); - assert( ConeSize1 == ConeSize2 ); - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigObj.c b/src/abc8/aig/aigObj.c deleted file mode 100644 index 80838e19..00000000 --- a/src/abc8/aig/aigObj.c +++ /dev/null @@ -1,431 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigObj.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Adding/removing objects.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigObj.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Creates primary input.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ObjCreatePi( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - pObj = Aig_ManFetchMemory( p ); - pObj->Type = AIG_OBJ_PI; - Vec_PtrPush( p->vPis, pObj ); - p->nObjs[AIG_OBJ_PI]++; - return pObj; -} - -/**Function************************************************************* - - Synopsis [Creates primary output with the given driver.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ObjCreatePo( Aig_Man_t * p, Aig_Obj_t * pDriver ) -{ - Aig_Obj_t * pObj; - pObj = Aig_ManFetchMemory( p ); - pObj->Type = AIG_OBJ_PO; - Vec_PtrPush( p->vPos, pObj ); - Aig_ObjConnect( p, pObj, pDriver, NULL ); - p->nObjs[AIG_OBJ_PO]++; - return pObj; -} - - -/**Function************************************************************* - - Synopsis [Create the new node assuming it does not exist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ObjCreate( Aig_Man_t * p, Aig_Obj_t * pGhost ) -{ - Aig_Obj_t * pObj; - assert( !Aig_IsComplement(pGhost) ); - assert( Aig_ObjIsHash(pGhost) ); -// assert( pGhost == &p->Ghost ); - // get memory for the new object - pObj = Aig_ManFetchMemory( p ); - pObj->Type = pGhost->Type; - // add connections - Aig_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 ); - // update node counters of the manager - p->nObjs[Aig_ObjType(pObj)]++; - assert( pObj->pData == NULL ); - if ( p->pManHaig ) - { - pGhost->pFanin0 = Aig_ObjHaig( pGhost->pFanin0 ); - pGhost->pFanin1 = Aig_ObjHaig( pGhost->pFanin1 ); - pObj->pHaig = Aig_ObjCreate( p->pManHaig, pGhost ); - } - return pObj; -} - -/**Function************************************************************* - - Synopsis [Connect the object to the fanin.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjConnect( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFan0, Aig_Obj_t * pFan1 ) -{ - assert( !Aig_IsComplement(pObj) ); - assert( !Aig_ObjIsPi(pObj) ); - // add the first fanin - pObj->pFanin0 = pFan0; - pObj->pFanin1 = pFan1; - // increment references of the fanins and add their fanouts - if ( pFan0 != NULL ) - { - assert( Aig_ObjFanin0(pObj)->Type > 0 ); - Aig_ObjRef( Aig_ObjFanin0(pObj) ); - if ( p->pFanData ) - Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj ); - } - if ( pFan1 != NULL ) - { - assert( Aig_ObjFanin1(pObj)->Type > 0 ); - Aig_ObjRef( Aig_ObjFanin1(pObj) ); - if ( p->pFanData ) - Aig_ObjAddFanout( p, Aig_ObjFanin1(pObj), pObj ); - } - // set level and phase - pObj->Level = Aig_ObjLevelNew( pObj ); - pObj->fPhase = Aig_ObjPhaseReal(pFan0) & Aig_ObjPhaseReal(pFan1); - // add the node to the structural hash table - if ( Aig_ObjIsHash(pObj) ) - Aig_TableInsert( p, pObj ); - // add the node to the dynamically updated topological order -// if ( p->pOrderData && Aig_ObjIsNode(pObj) ) -// Aig_ObjOrderInsert( p, pObj->Id ); -} - -/**Function************************************************************* - - Synopsis [Disconnects the object from the fanins.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjDisconnect( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - // remove connections - if ( pObj->pFanin0 != NULL ) - { - if ( p->pFanData ) - Aig_ObjRemoveFanout( p, Aig_ObjFanin0(pObj), pObj ); - Aig_ObjDeref(Aig_ObjFanin0(pObj)); - } - if ( pObj->pFanin1 != NULL ) - { - if ( p->pFanData ) - Aig_ObjRemoveFanout( p, Aig_ObjFanin1(pObj), pObj ); - Aig_ObjDeref(Aig_ObjFanin1(pObj)); - } - // remove the node from the structural hash table - if ( Aig_ObjIsHash(pObj) ) - Aig_TableDelete( p, pObj ); - // add the first fanin - pObj->pFanin0 = NULL; - pObj->pFanin1 = NULL; - // remove the node from the dynamically updated topological order -// if ( p->pOrderData && Aig_ObjIsNode(pObj) ) -// Aig_ObjOrderRemove( p, pObj->Id ); -} - -/**Function************************************************************* - - Synopsis [Deletes the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjDelete( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - assert( !Aig_ObjIsTerm(pObj) ); - assert( Aig_ObjRefs(pObj) == 0 ); - if ( p->pFanData && Aig_ObjIsBuf(pObj) ) - Vec_PtrRemove( p->vBufs, pObj ); - p->nObjs[pObj->Type]--; - Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL ); - Aig_ManRecycleMemory( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Deletes the MFFC of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjDelete_rec( Aig_Man_t * p, Aig_Obj_t * pObj, int fFreeTop ) -{ - Aig_Obj_t * pFanin0, * pFanin1; - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsConst1(pObj) || Aig_ObjIsPi(pObj) ) - return; - assert( !Aig_ObjIsPo(pObj) ); - pFanin0 = Aig_ObjFanin0(pObj); - pFanin1 = Aig_ObjFanin1(pObj); - Aig_ObjDisconnect( p, pObj ); - if ( fFreeTop ) - Aig_ObjDelete( p, pObj ); - if ( pFanin0 && !Aig_ObjIsNone(pFanin0) && Aig_ObjRefs(pFanin0) == 0 ) - Aig_ObjDelete_rec( p, pFanin0, 1 ); - if ( pFanin1 && !Aig_ObjIsNone(pFanin1) && Aig_ObjRefs(pFanin1) == 0 ) - Aig_ObjDelete_rec( p, pFanin1, 1 ); -} - -/**Function************************************************************* - - Synopsis [Replaces the first fanin of the node by the new fanin.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjPatchFanin0( Aig_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pFaninNew ) -{ - Aig_Obj_t * pFaninOld; - assert( !Aig_IsComplement(pObj) ); - assert( Aig_ObjIsPo(pObj) ); - pFaninOld = Aig_ObjFanin0(pObj); - // decrement ref and remove fanout - if ( p->pFanData ) - Aig_ObjRemoveFanout( p, pFaninOld, pObj ); - Aig_ObjDeref( pFaninOld ); - // update the fanin - pObj->pFanin0 = pFaninNew; - // increment ref and add fanout - if ( p->pFanData ) - Aig_ObjAddFanout( p, Aig_ObjFanin0(pObj), pObj ); - Aig_ObjRef( Aig_ObjFanin0(pObj) ); - // get rid of old fanin - if ( !Aig_ObjIsPi(pFaninOld) && !Aig_ObjIsConst1(pFaninOld) && Aig_ObjRefs(pFaninOld) == 0 ) - Aig_ObjDelete_rec( p, pFaninOld, 1 ); -} - -/**Function************************************************************* - - Synopsis [Replaces node with a buffer fanin by a node without them.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_NodeFixBufferFanins( Aig_Man_t * p, Aig_Obj_t * pObj, int fNodesOnly, int fUpdateLevel ) -{ - Aig_Obj_t * pFanReal0, * pFanReal1, * pResult; - p->nBufFixes++; - if ( Aig_ObjIsPo(pObj) ) - { - assert( Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) ); - pFanReal0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - assert( Aig_ObjPhaseReal(Aig_ObjChild0(pObj)) == Aig_ObjPhaseReal(pFanReal0) ); - Aig_ObjPatchFanin0( p, pObj, pFanReal0 ); - return; - } - assert( Aig_ObjIsNode(pObj) ); - assert( Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) || Aig_ObjIsBuf(Aig_ObjFanin1(pObj)) ); - // get the real fanins - pFanReal0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pFanReal1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) ); - // get the new node - if ( Aig_ObjIsNode(pObj) ) - pResult = Aig_Oper( p, pFanReal0, pFanReal1, Aig_ObjType(pObj) ); -// else if ( Aig_ObjIsLatch(pObj) ) -// pResult = Aig_Latch( p, pFanReal0, Aig_ObjInit(pObj) ); - else - assert( 0 ); - // replace the node with buffer by the node without buffer - Aig_ObjReplace( p, pObj, pResult, fNodesOnly, fUpdateLevel ); -} - -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManPropagateBuffers( Aig_Man_t * p, int fNodesOnly, int fUpdateLevel ) -{ - Aig_Obj_t * pObj; - int nSteps; - assert( p->pFanData ); - for ( nSteps = 0; Vec_PtrSize(p->vBufs) > 0; nSteps++ ) - { - // get the node with a buffer fanin - for ( pObj = Vec_PtrEntryLast(p->vBufs); Aig_ObjIsBuf(pObj); pObj = Aig_ObjFanout0(p, pObj) ); - // replace this node by a node without buffer - Aig_NodeFixBufferFanins( p, pObj, fNodesOnly, fUpdateLevel ); - // stop if a cycle occured - if ( nSteps > 1000000 ) - { - printf( "Error: A cycle is encountered while propagating buffers.\n" ); - break; - } - } - return nSteps; -} - -/**Function************************************************************* - - Synopsis [Replaces one object by another.] - - Description [The new object (pObjNew) should be used instead of the old - object (pObjOld). If the new object is complemented or used, the buffer - is added and the new object remains in the manager; otherwise, the new - object is deleted.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjReplace( Aig_Man_t * p, Aig_Obj_t * pObjOld, Aig_Obj_t * pObjNew, int fNodesOnly, int fUpdateLevel ) -{ - Aig_Obj_t * pObjNewR = Aig_Regular(pObjNew); - // the object to be replaced cannot be complemented - assert( !Aig_IsComplement(pObjOld) ); - // the object to be replaced cannot be a terminal - assert( !Aig_ObjIsPi(pObjOld) && !Aig_ObjIsPo(pObjOld) ); - // the object to be used cannot be a buffer or a PO - assert( !Aig_ObjIsBuf(pObjNewR) && !Aig_ObjIsPo(pObjNewR) ); - // the object cannot be the same - assert( pObjOld != pObjNewR ); - // make sure object is not pointing to itself - assert( pObjOld != Aig_ObjFanin0(pObjNewR) ); - assert( pObjOld != Aig_ObjFanin1(pObjNewR) ); - // map the HAIG nodes - if ( p->pManHaig != NULL ) - { - assert( pObjNewR->pHaig != NULL ); - assert( pObjNewR->pHaig->pHaig == NULL ); - pObjNewR->pHaig->pHaig = pObjOld->pHaig; - } - // recursively delete the old node - but leave the object there - pObjNewR->nRefs++; - Aig_ObjDelete_rec( p, pObjOld, 0 ); - pObjNewR->nRefs--; - // if the new object is complemented or already used, create a buffer - p->nObjs[pObjOld->Type]--; - if ( Aig_IsComplement(pObjNew) || Aig_ObjRefs(pObjNew) > 0 || (fNodesOnly && !Aig_ObjIsNode(pObjNew)) ) - { - pObjOld->Type = AIG_OBJ_BUF; - Aig_ObjConnect( p, pObjOld, pObjNew, NULL ); - p->nBufReplaces++; - } - else - { - Aig_Obj_t * pFanin0 = pObjNew->pFanin0; - Aig_Obj_t * pFanin1 = pObjNew->pFanin1; - int LevelOld = pObjOld->Level; - pObjOld->Type = pObjNew->Type; - Aig_ObjDisconnect( p, pObjNew ); - Aig_ObjConnect( p, pObjOld, pFanin0, pFanin1 ); - // update the haig node - pObjOld->pHaig = pObjNew->pHaig; - // delete the new object - Aig_ObjDelete( p, pObjNew ); - // update levels - if ( p->pFanData ) - { - pObjOld->Level = LevelOld; - Aig_ManUpdateLevel( p, pObjOld ); - } - if ( fUpdateLevel ) - { - Aig_ObjClearReverseLevel( p, pObjOld ); - Aig_ManUpdateReverseLevel( p, pObjOld ); - } - } - p->nObjs[pObjOld->Type]++; - // store buffers if fanout is allocated - if ( p->pFanData && Aig_ObjIsBuf(pObjOld) ) - { - Vec_PtrPush( p->vBufs, pObjOld ); - p->nBufMax = AIG_MAX( p->nBufMax, Vec_PtrSize(p->vBufs) ); - Aig_ManPropagateBuffers( p, fNodesOnly, fUpdateLevel ); - } -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigOper.c b/src/abc8/aig/aigOper.c deleted file mode 100644 index c19f551e..00000000 --- a/src/abc8/aig/aigOper.c +++ /dev/null @@ -1,541 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigOper.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [AIG operations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigOper.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// procedure to detect an EXOR gate -static inline int Aig_ObjIsExorType( Aig_Obj_t * p0, Aig_Obj_t * p1, Aig_Obj_t ** ppFan0, Aig_Obj_t ** ppFan1 ) -{ - if ( !Aig_IsComplement(p0) || !Aig_IsComplement(p1) ) - return 0; - p0 = Aig_Regular(p0); - p1 = Aig_Regular(p1); - if ( !Aig_ObjIsAnd(p0) || !Aig_ObjIsAnd(p1) ) - return 0; - if ( Aig_ObjFanin0(p0) != Aig_ObjFanin0(p1) || Aig_ObjFanin1(p0) != Aig_ObjFanin1(p1) ) - return 0; - if ( Aig_ObjFaninC0(p0) == Aig_ObjFaninC0(p1) || Aig_ObjFaninC1(p0) == Aig_ObjFaninC1(p1) ) - return 0; - *ppFan0 = Aig_ObjChild0(p0); - *ppFan1 = Aig_ObjChild1(p0); - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Returns i-th elementary variable.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_IthVar( Aig_Man_t * p, int i ) -{ - int v; - for ( v = Aig_ManPiNum(p); v <= i; v++ ) - Aig_ObjCreatePi( p ); - assert( i < Vec_PtrSize(p->vPis) ); - return Aig_ManPi( p, i ); -} - -/**Function************************************************************* - - Synopsis [Perform one operation.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Oper( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1, Aig_Type_t Type ) -{ - if ( Type == AIG_OBJ_AND ) - return Aig_And( p, p0, p1 ); - if ( Type == AIG_OBJ_EXOR ) - return Aig_Exor( p, p0, p1 ); - assert( 0 ); - return NULL; -} - -/**Function************************************************************* - - Synopsis [Creates the canonical form of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_CanonPair_rec( Aig_Man_t * p, Aig_Obj_t * pGhost ) -{ - Aig_Obj_t * pResult, * pLat0, * pLat1; - int fCompl0, fCompl1; - Aig_Type_t Type; - assert( Aig_ObjIsNode(pGhost) ); - // consider the case when the pair is canonical - if ( !Aig_ObjIsLatch(Aig_ObjFanin0(pGhost)) || !Aig_ObjIsLatch(Aig_ObjFanin1(pGhost)) ) - { - if ( (pResult = Aig_TableLookup( p, pGhost )) ) - return pResult; - return Aig_ObjCreate( p, pGhost ); - } - /// remember the latches - pLat0 = Aig_ObjFanin0(pGhost); - pLat1 = Aig_ObjFanin1(pGhost); - // remember type and compls - Type = Aig_ObjType(pGhost); - fCompl0 = Aig_ObjFaninC0(pGhost); - fCompl1 = Aig_ObjFaninC1(pGhost); - // call recursively - pResult = Aig_Oper( p, Aig_NotCond(Aig_ObjChild0(pLat0), fCompl0), Aig_NotCond(Aig_ObjChild0(pLat1), fCompl1), Type ); - // build latch on top of this - return Aig_Latch( p, pResult, (Type == AIG_OBJ_AND)? fCompl0 & fCompl1 : fCompl0 ^ fCompl1 ); -} - -/**Function************************************************************* - - Synopsis [Performs canonicization step.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_And( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ) -{ - Aig_Obj_t * pGhost, * pResult; -// Aig_Obj_t * pFan0, * pFan1; - if ( p->pTable == NULL ) - { -// pGhost = Aig_ObjCreateGhost( p, p0, p1, AIG_OBJ_AND ); - pGhost = Aig_ManGhost(p); - pGhost->Type = AIG_OBJ_AND; - pGhost->pFanin0 = p0; - pGhost->pFanin1 = p1; - return Aig_ObjCreate( p, pGhost ); - } - // check trivial cases - if ( p0 == p1 ) - return p0; - if ( p0 == Aig_Not(p1) ) - return Aig_Not(p->pConst1); - if ( Aig_Regular(p0) == p->pConst1 ) - return p0 == p->pConst1 ? p1 : Aig_Not(p->pConst1); - if ( Aig_Regular(p1) == p->pConst1 ) - return p1 == p->pConst1 ? p0 : Aig_Not(p->pConst1); - // check not so trivial cases - if ( p->fAddStrash && (Aig_ObjIsNode(Aig_Regular(p0)) || Aig_ObjIsNode(Aig_Regular(p1))) ) - { // http://fmv.jku.at/papers/BrummayerBiere-MEMICS06.pdf - Aig_Obj_t * pFanA, * pFanB, * pFanC, * pFanD; - pFanA = Aig_ObjChild0(Aig_Regular(p0)); - pFanB = Aig_ObjChild1(Aig_Regular(p0)); - pFanC = Aig_ObjChild0(Aig_Regular(p1)); - pFanD = Aig_ObjChild1(Aig_Regular(p1)); - if ( Aig_IsComplement(p0) ) - { - if ( pFanA == Aig_Not(p1) || pFanB == Aig_Not(p1) ) - return p1; - if ( pFanB == p1 ) - return Aig_And( p, Aig_Not(pFanA), pFanB ); - if ( pFanA == p1 ) - return Aig_And( p, Aig_Not(pFanB), pFanA ); - } - else - { - if ( pFanA == Aig_Not(p1) || pFanB == Aig_Not(p1) ) - return Aig_Not(p->pConst1); - if ( pFanA == p1 || pFanB == p1 ) - return p0; - } - if ( Aig_IsComplement(p1) ) - { - if ( pFanC == Aig_Not(p0) || pFanD == Aig_Not(p0) ) - return p0; - if ( pFanD == p0 ) - return Aig_And( p, Aig_Not(pFanC), pFanD ); - if ( pFanC == p0 ) - return Aig_And( p, Aig_Not(pFanD), pFanC ); - } - else - { - if ( pFanC == Aig_Not(p0) || pFanD == Aig_Not(p0) ) - return Aig_Not(p->pConst1); - if ( pFanC == p0 || pFanD == p0 ) - return p1; - } - if ( !Aig_IsComplement(p0) && !Aig_IsComplement(p1) ) - { - if ( pFanA == Aig_Not(pFanC) || pFanA == Aig_Not(pFanD) || pFanB == Aig_Not(pFanC) || pFanB == Aig_Not(pFanD) ) - return Aig_Not(p->pConst1); - if ( pFanA == pFanC || pFanB == pFanC ) - return Aig_And( p, p0, pFanD ); - if ( pFanB == pFanC || pFanB == pFanD ) - return Aig_And( p, pFanA, p1 ); - if ( pFanA == pFanD || pFanB == pFanD ) - return Aig_And( p, p0, pFanC ); - if ( pFanA == pFanC || pFanA == pFanD ) - return Aig_And( p, pFanB, p1 ); - } - else if ( Aig_IsComplement(p0) && !Aig_IsComplement(p1) ) - { - if ( pFanA == Aig_Not(pFanC) || pFanA == Aig_Not(pFanD) || pFanB == Aig_Not(pFanC) || pFanB == Aig_Not(pFanD) ) - return p1; - if ( pFanB == pFanC || pFanB == pFanD ) - return Aig_And( p, Aig_Not(pFanA), p1 ); - if ( pFanA == pFanC || pFanA == pFanD ) - return Aig_And( p, Aig_Not(pFanB), p1 ); - } - else if ( !Aig_IsComplement(p0) && Aig_IsComplement(p1) ) - { - if ( pFanC == Aig_Not(pFanA) || pFanC == Aig_Not(pFanB) || pFanD == Aig_Not(pFanA) || pFanD == Aig_Not(pFanB) ) - return p0; - if ( pFanD == pFanA || pFanD == pFanB ) - return Aig_And( p, Aig_Not(pFanC), p0 ); - if ( pFanC == pFanA || pFanC == pFanB ) - return Aig_And( p, Aig_Not(pFanD), p0 ); - } - else // if ( Aig_IsComplement(p0) && Aig_IsComplement(p1) ) - { - if ( pFanA == pFanD && pFanB == Aig_Not(pFanC) ) - return Aig_Not(pFanA); - if ( pFanB == pFanC && pFanA == Aig_Not(pFanD) ) - return Aig_Not(pFanB); - if ( pFanA == pFanC && pFanB == Aig_Not(pFanD) ) - return Aig_Not(pFanA); - if ( pFanB == pFanD && pFanA == Aig_Not(pFanC) ) - return Aig_Not(pFanB); - } - } - // check if it can be an EXOR gate -// if ( Aig_ObjIsExorType( p0, p1, &pFan0, &pFan1 ) ) -// return Aig_Exor( p, pFan0, pFan1 ); - pGhost = Aig_ObjCreateGhost( p, p0, p1, AIG_OBJ_AND ); - pResult = Aig_CanonPair_rec( p, pGhost ); - return pResult; -} - -/**Function************************************************************* - - Synopsis [Creates the canonical form of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Latch( Aig_Man_t * p, Aig_Obj_t * pObj, int fInitOne ) -{ - Aig_Obj_t * pGhost, * pResult; - pGhost = Aig_ObjCreateGhost( p, Aig_NotCond(pObj, fInitOne), NULL, AIG_OBJ_LATCH ); - pResult = Aig_TableLookup( p, pGhost ); - if ( pResult == NULL ) - pResult = Aig_ObjCreate( p, pGhost ); - return Aig_NotCond( pResult, fInitOne ); -} - -/**Function************************************************************* - - Synopsis [Performs canonicization step.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Exor( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ) -{ -/* - Aig_Obj_t * pGhost, * pResult; - // check trivial cases - if ( p0 == p1 ) - return Aig_Not(p->pConst1); - if ( p0 == Aig_Not(p1) ) - return p->pConst1; - if ( Aig_Regular(p0) == p->pConst1 ) - return Aig_NotCond( p1, p0 == p->pConst1 ); - if ( Aig_Regular(p1) == p->pConst1 ) - return Aig_NotCond( p0, p1 == p->pConst1 ); - // check the table - pGhost = Aig_ObjCreateGhost( p, p0, p1, AIG_OBJ_EXOR ); - if ( pResult = Aig_TableLookup( p, pGhost ) ) - return pResult; - return Aig_ObjCreate( p, pGhost ); -*/ - return Aig_Or( p, Aig_And(p, p0, Aig_Not(p1)), Aig_And(p, Aig_Not(p0), p1) ); -} - -/**Function************************************************************* - - Synopsis [Implements Boolean OR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Or( Aig_Man_t * p, Aig_Obj_t * p0, Aig_Obj_t * p1 ) -{ - return Aig_Not( Aig_And( p, Aig_Not(p0), Aig_Not(p1) ) ); -} - -/**Function************************************************************* - - Synopsis [Implements ITE operation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Mux( Aig_Man_t * p, Aig_Obj_t * pC, Aig_Obj_t * p1, Aig_Obj_t * p0 ) -{ -/* - Aig_Obj_t * pTempA1, * pTempA2, * pTempB1, * pTempB2, * pTemp; - int Count0, Count1; - // consider trivial cases - if ( p0 == Aig_Not(p1) ) - return Aig_Exor( p, pC, p0 ); - // other cases can be added - // implement the first MUX (F = C * x1 + C' * x0) - - // check for constants here!!! - - pTempA1 = Aig_TableLookup( p, Aig_ObjCreateGhost(p, pC, p1, AIG_OBJ_AND) ); - pTempA2 = Aig_TableLookup( p, Aig_ObjCreateGhost(p, Aig_Not(pC), p0, AIG_OBJ_AND) ); - if ( pTempA1 && pTempA2 ) - { - pTemp = Aig_TableLookup( p, Aig_ObjCreateGhost(p, Aig_Not(pTempA1), Aig_Not(pTempA2), AIG_OBJ_AND) ); - if ( pTemp ) return Aig_Not(pTemp); - } - Count0 = (pTempA1 != NULL) + (pTempA2 != NULL); - // implement the second MUX (F' = C * x1' + C' * x0') - pTempB1 = Aig_TableLookup( p, Aig_ObjCreateGhost(p, pC, Aig_Not(p1), AIG_OBJ_AND) ); - pTempB2 = Aig_TableLookup( p, Aig_ObjCreateGhost(p, Aig_Not(pC), Aig_Not(p0), AIG_OBJ_AND) ); - if ( pTempB1 && pTempB2 ) - { - pTemp = Aig_TableLookup( p, Aig_ObjCreateGhost(p, Aig_Not(pTempB1), Aig_Not(pTempB2), AIG_OBJ_AND) ); - if ( pTemp ) return pTemp; - } - Count1 = (pTempB1 != NULL) + (pTempB2 != NULL); - // compare and decide which one to implement - if ( Count0 >= Count1 ) - { - pTempA1 = pTempA1? pTempA1 : Aig_And(p, pC, p1); - pTempA2 = pTempA2? pTempA2 : Aig_And(p, Aig_Not(pC), p0); - return Aig_Or( p, pTempA1, pTempA2 ); - } - pTempB1 = pTempB1? pTempB1 : Aig_And(p, pC, Aig_Not(p1)); - pTempB2 = pTempB2? pTempB2 : Aig_And(p, Aig_Not(pC), Aig_Not(p0)); - return Aig_Not( Aig_Or( p, pTempB1, pTempB2 ) ); -*/ - return Aig_Or( p, Aig_And(p, pC, p1), Aig_And(p, Aig_Not(pC), p0) ); -} - -/**Function************************************************************* - - Synopsis [Implements ITE operation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Maj( Aig_Man_t * p, Aig_Obj_t * pA, Aig_Obj_t * pB, Aig_Obj_t * pC ) -{ - return Aig_Or( p, Aig_Or(p, Aig_And(p, pA, pB), Aig_And(p, pA, pC)), Aig_And(p, pB, pC) ); -} - -/**Function************************************************************* - - Synopsis [Constructs the well-balanced tree of gates.] - - Description [Disregards levels and possible logic sharing.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Multi_rec( Aig_Man_t * p, Aig_Obj_t ** ppObjs, int nObjs, Aig_Type_t Type ) -{ - Aig_Obj_t * pObj1, * pObj2; - if ( nObjs == 1 ) - return ppObjs[0]; - pObj1 = Aig_Multi_rec( p, ppObjs, nObjs/2, Type ); - pObj2 = Aig_Multi_rec( p, ppObjs + nObjs/2, nObjs - nObjs/2, Type ); - return Aig_Oper( p, pObj1, pObj2, Type ); -} - -/**Function************************************************************* - - Synopsis [Old code.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Multi( Aig_Man_t * p, Aig_Obj_t ** pArgs, int nArgs, Aig_Type_t Type ) -{ - assert( Type == AIG_OBJ_AND || Type == AIG_OBJ_EXOR ); - assert( nArgs > 0 ); - return Aig_Multi_rec( p, pArgs, nArgs, Type ); -} - -/**Function************************************************************* - - Synopsis [Implements the miter.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_Miter( Aig_Man_t * p, Vec_Ptr_t * vPairs ) -{ - int i; - assert( vPairs->nSize > 0 ); - assert( vPairs->nSize % 2 == 0 ); - for ( i = 0; i < vPairs->nSize; i += 2 ) - vPairs->pArray[i/2] = Aig_Not( Aig_Exor( p, vPairs->pArray[i], vPairs->pArray[i+1] ) ); - vPairs->nSize = vPairs->nSize/2; - return Aig_Not( Aig_Multi_rec( p, (Aig_Obj_t **)vPairs->pArray, vPairs->nSize, AIG_OBJ_AND ) ); -} - -/**Function************************************************************* - - Synopsis [Implements the miter.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_MiterTwo( Aig_Man_t * p, Vec_Ptr_t * vNodes1, Vec_Ptr_t * vNodes2 ) -{ - int i; - assert( vNodes1->nSize > 0 && vNodes1->nSize > 0 ); - assert( vNodes1->nSize == vNodes2->nSize ); - for ( i = 0; i < vNodes1->nSize; i++ ) - vNodes1->pArray[i] = Aig_Not( Aig_Exor( p, vNodes1->pArray[i], vNodes2->pArray[i] ) ); - return Aig_Not( Aig_Multi_rec( p, (Aig_Obj_t **)vNodes1->pArray, vNodes1->nSize, AIG_OBJ_AND ) ); -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_CreateAnd( Aig_Man_t * p, int nVars ) -{ - Aig_Obj_t * pFunc; - int i; - pFunc = Aig_ManConst1( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Aig_And( p, pFunc, Aig_IthVar(p, i) ); - return pFunc; -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_CreateOr( Aig_Man_t * p, int nVars ) -{ - Aig_Obj_t * pFunc; - int i; - pFunc = Aig_ManConst0( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Aig_Or( p, pFunc, Aig_IthVar(p, i) ); - return pFunc; -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_CreateExor( Aig_Man_t * p, int nVars ) -{ - Aig_Obj_t * pFunc; - int i; - pFunc = Aig_ManConst0( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Aig_Exor( p, pFunc, Aig_IthVar(p, i) ); - return pFunc; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigOrder.c b/src/abc8/aig/aigOrder.c deleted file mode 100644 index 62aeca6e..00000000 --- a/src/abc8/aig/aigOrder.c +++ /dev/null @@ -1,171 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigOrder.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Dynamically updated topological order.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigOrder.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Initializes the order datastructure.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManOrderStart( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - assert( Aig_ManBufNum(p) == 0 ); - // allocate order datastructure - assert( p->pOrderData == NULL ); - p->nOrderAlloc = 2 * Aig_ManObjNumMax(p); - if ( p->nOrderAlloc < (1<<12) ) - p->nOrderAlloc = (1<<12); - p->pOrderData = ALLOC( unsigned, 2 * p->nOrderAlloc ); - memset( p->pOrderData, 0xFF, sizeof(unsigned) * 2 * p->nOrderAlloc ); - // add the constant node - p->pOrderData[0] = p->pOrderData[1] = 0; - p->iPrev = p->iNext = 0; - // add the internal nodes - Aig_ManForEachNode( p, pObj, i ) - Aig_ObjOrderInsert( p, pObj->Id ); -} - -/**Function************************************************************* - - Synopsis [Deletes the order datastructure.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManOrderStop( Aig_Man_t * p ) -{ - assert( p->pOrderData ); - FREE( p->pOrderData ); - p->nOrderAlloc = 0; - p->iPrev = p->iNext = 0; -} - -/**Function************************************************************* - - Synopsis [Inserts an entry before iNext.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjOrderInsert( Aig_Man_t * p, int ObjId ) -{ - int iPrev; - assert( ObjId != 0 ); - assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) ); - if ( ObjId >= p->nOrderAlloc ) - { - int nOrderAlloc = 2 * ObjId; - p->pOrderData = REALLOC( unsigned, p->pOrderData, 2 * nOrderAlloc ); - memset( p->pOrderData + 2 * p->nOrderAlloc, 0xFF, sizeof(unsigned) * 2 * (nOrderAlloc - p->nOrderAlloc) ); - p->nOrderAlloc = nOrderAlloc; - } - assert( p->pOrderData[2*ObjId] == 0xFFFFFFFF ); // prev - assert( p->pOrderData[2*ObjId+1] == 0xFFFFFFFF ); // next - iPrev = p->pOrderData[2*p->iNext]; - assert( p->pOrderData[2*iPrev+1] == (unsigned)p->iNext ); - p->pOrderData[2*ObjId] = iPrev; - p->pOrderData[2*iPrev+1] = ObjId; - p->pOrderData[2*p->iNext] = ObjId; - p->pOrderData[2*ObjId+1] = p->iNext; - p->nAndTotal++; -} - -/**Function************************************************************* - - Synopsis [Removes the entry.] - - Description [If iPrev is removed, it slides backward. - If iNext is removed, it slides forward.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjOrderRemove( Aig_Man_t * p, int ObjId ) -{ - int iPrev, iNext; - assert( ObjId != 0 ); - assert( Aig_ObjIsNode( Aig_ManObj(p, ObjId) ) ); - iPrev = p->pOrderData[2*ObjId]; - iNext = p->pOrderData[2*ObjId+1]; - p->pOrderData[2*ObjId] = 0xFFFFFFFF; - p->pOrderData[2*ObjId+1] = 0xFFFFFFFF; - p->pOrderData[2*iNext] = iPrev; - p->pOrderData[2*iPrev+1] = iNext; - if ( p->iPrev == ObjId ) - { - p->nAndPrev--; - p->iPrev = iPrev; - } - if ( p->iNext == ObjId ) - p->iNext = iNext; - p->nAndTotal--; -} - -/**Function************************************************************* - - Synopsis [Advances the order forward.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjOrderAdvance( Aig_Man_t * p ) -{ - assert( p->pOrderData ); - assert( p->pOrderData[2*p->iPrev+1] == (unsigned)p->iNext ); - p->iPrev = p->iNext; - p->nAndPrev++; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigPart.c b/src/abc8/aig/aigPart.c deleted file mode 100644 index de13653c..00000000 --- a/src/abc8/aig/aigPart.c +++ /dev/null @@ -1,992 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigPart.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [AIG partitioning package.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigPart.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -typedef struct Part_Man_t_ Part_Man_t; -struct Part_Man_t_ -{ - int nChunkSize; // the size of one chunk of memory (~1 Mb) - int nStepSize; // the step size in saving memory (~64 bytes) - char * pFreeBuf; // the pointer to free memory - int nFreeSize; // the size of remaining free memory - Vec_Ptr_t * vMemory; // the memory allocated - Vec_Ptr_t * vFree; // the vector of free pieces of memory -}; - -typedef struct Part_One_t_ Part_One_t; -struct Part_One_t_ -{ - int nRefs; // the number of references - int nOuts; // the number of outputs - int nOutsAlloc; // the array size - int pOuts[0]; // the array of outputs -}; - -static inline int Part_SizeType( int nSize, int nStepSize ) { return nSize / nStepSize + ((nSize % nStepSize) > 0); } -static inline char * Part_OneNext( char * pPart ) { return *((char **)pPart); } -static inline void Part_OneSetNext( char * pPart, char * pNext ) { *((char **)pPart) = pNext; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Start the memory manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Part_Man_t * Part_ManStart( int nChunkSize, int nStepSize ) -{ - Part_Man_t * p; - p = ALLOC( Part_Man_t, 1 ); - memset( p, 0, sizeof(Part_Man_t) ); - p->nChunkSize = nChunkSize; - p->nStepSize = nStepSize; - p->vMemory = Vec_PtrAlloc( 1000 ); - p->vFree = Vec_PtrAlloc( 1000 ); - return p; -} - -/**Function************************************************************* - - Synopsis [Stops the memory manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Part_ManStop( Part_Man_t * p ) -{ - void * pMemory; - int i; - Vec_PtrForEachEntry( p->vMemory, pMemory, i ) - free( pMemory ); - Vec_PtrFree( p->vMemory ); - Vec_PtrFree( p->vFree ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Fetches the memory entry of the given size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -char * Part_ManFetch( Part_Man_t * p, int nSize ) -{ - int Type, nSizeReal; - char * pMemory; - assert( nSize > 0 ); - Type = Part_SizeType( nSize, p->nStepSize ); - Vec_PtrFillExtra( p->vFree, Type + 1, NULL ); - if ( (pMemory = Vec_PtrEntry( p->vFree, Type )) ) - { - Vec_PtrWriteEntry( p->vFree, Type, Part_OneNext(pMemory) ); - return pMemory; - } - nSizeReal = p->nStepSize * Type; - if ( p->nFreeSize < nSizeReal ) - { - p->pFreeBuf = ALLOC( char, p->nChunkSize ); - p->nFreeSize = p->nChunkSize; - Vec_PtrPush( p->vMemory, p->pFreeBuf ); - } - assert( p->nFreeSize >= nSizeReal ); - pMemory = p->pFreeBuf; - p->pFreeBuf += nSizeReal; - p->nFreeSize -= nSizeReal; - return pMemory; -} - -/**Function************************************************************* - - Synopsis [Recycles the memory entry of the given size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Part_ManRecycle( Part_Man_t * p, char * pMemory, int nSize ) -{ - int Type; - Type = Part_SizeType( nSize, p->nStepSize ); - Vec_PtrFillExtra( p->vFree, Type + 1, NULL ); - Part_OneSetNext( pMemory, Vec_PtrEntry(p->vFree, Type) ); - Vec_PtrWriteEntry( p->vFree, Type, pMemory ); -} - -/**Function************************************************************* - - Synopsis [Fetches the memory entry of the given size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Part_One_t * Part_ManFetchEntry( Part_Man_t * p, int nWords, int nRefs ) -{ - Part_One_t * pPart; - pPart = (Part_One_t *)Part_ManFetch( p, sizeof(Part_One_t) + sizeof(int) * nWords ); - pPart->nRefs = nRefs; - pPart->nOuts = 0; - pPart->nOutsAlloc = nWords; - return pPart; -} - -/**Function************************************************************* - - Synopsis [Recycles the memory entry of the given size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Part_ManRecycleEntry( Part_Man_t * p, Part_One_t * pEntry ) -{ - assert( pEntry->nOuts <= pEntry->nOutsAlloc ); - assert( pEntry->nOuts >= pEntry->nOutsAlloc/2 ); - Part_ManRecycle( p, (char *)pEntry, sizeof(Part_One_t) + sizeof(int) * pEntry->nOutsAlloc ); -} - -/**Function************************************************************* - - Synopsis [Merges two entries.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Part_One_t * Part_ManMergeEntry( Part_Man_t * pMan, Part_One_t * p1, Part_One_t * p2, int nRefs ) -{ - Part_One_t * p = Part_ManFetchEntry( pMan, p1->nOuts + p2->nOuts, nRefs ); - int * pBeg1 = p1->pOuts; - int * pBeg2 = p2->pOuts; - int * pBeg = p->pOuts; - int * pEnd1 = p1->pOuts + p1->nOuts; - int * pEnd2 = p2->pOuts + p2->nOuts; - while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 ) - { - if ( *pBeg1 == *pBeg2 ) - *pBeg++ = *pBeg1++, pBeg2++; - else if ( *pBeg1 < *pBeg2 ) - *pBeg++ = *pBeg1++; - else - *pBeg++ = *pBeg2++; - } - while ( pBeg1 < pEnd1 ) - *pBeg++ = *pBeg1++; - while ( pBeg2 < pEnd2 ) - *pBeg++ = *pBeg2++; - p->nOuts = pBeg - p->pOuts; - assert( p->nOuts <= p->nOutsAlloc ); - assert( p->nOuts >= p1->nOuts ); - assert( p->nOuts >= p2->nOuts ); - return p; -} - -/**Function************************************************************* - - Synopsis [Tranfers the entry.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Int_t * Part_ManTransferEntry( Part_One_t * p ) -{ - Vec_Int_t * vSupp; - int i; - vSupp = Vec_IntAlloc( p->nOuts ); - for ( i = 0; i < p->nOuts; i++ ) - Vec_IntPush( vSupp, p->pOuts[i] ); - return vSupp; -} - -/**Function************************************************************* - - Synopsis [Computes supports of the POs in the multi-output AIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManSupports( Aig_Man_t * pMan ) -{ - Vec_Ptr_t * vSupports; - Vec_Int_t * vSupp; - Part_Man_t * p; - Part_One_t * pPart0, * pPart1; - Aig_Obj_t * pObj; - int i; - // set the number of PIs/POs - Aig_ManForEachPi( pMan, pObj, i ) - pObj->pNext = (Aig_Obj_t *)(long)i; - Aig_ManForEachPo( pMan, pObj, i ) - pObj->pNext = (Aig_Obj_t *)(long)i; - // start the support computation manager - p = Part_ManStart( 1 << 20, 1 << 6 ); - // consider objects in the topological order - vSupports = Vec_PtrAlloc( Aig_ManPoNum(pMan) ); - Aig_ManCleanData(pMan); - Aig_ManForEachObj( pMan, pObj, i ) - { - if ( Aig_ObjIsNode(pObj) ) - { - pPart0 = Aig_ObjFanin0(pObj)->pData; - pPart1 = Aig_ObjFanin1(pObj)->pData; - pObj->pData = Part_ManMergeEntry( p, pPart0, pPart1, pObj->nRefs ); - assert( pPart0->nRefs > 0 ); - if ( --pPart0->nRefs == 0 ) - Part_ManRecycleEntry( p, pPart0 ); - assert( pPart1->nRefs > 0 ); - if ( --pPart1->nRefs == 0 ) - Part_ManRecycleEntry( p, pPart1 ); - continue; - } - if ( Aig_ObjIsPo(pObj) ) - { - pPart0 = Aig_ObjFanin0(pObj)->pData; - vSupp = Part_ManTransferEntry(pPart0); - Vec_IntPush( vSupp, (int)(long)pObj->pNext ); - Vec_PtrPush( vSupports, vSupp ); - assert( pPart0->nRefs > 0 ); - if ( --pPart0->nRefs == 0 ) - Part_ManRecycleEntry( p, pPart0 ); - continue; - } - if ( Aig_ObjIsPi(pObj) ) - { - if ( pObj->nRefs ) - { - pPart0 = Part_ManFetchEntry( p, 1, pObj->nRefs ); - pPart0->pOuts[ pPart0->nOuts++ ] = (int)(long)pObj->pNext; - pObj->pData = pPart0; - } - continue; - } - if ( Aig_ObjIsConst1(pObj) ) - { - if ( pObj->nRefs ) - pObj->pData = Part_ManFetchEntry( p, 0, pObj->nRefs ); - continue; - } - assert( 0 ); - } -//printf( "Memory usage = %d Mb.\n", Vec_PtrSize(p->vMemory) * p->nChunkSize / (1<<20) ); - Part_ManStop( p ); - // sort supports by size - Vec_VecSort( (Vec_Vec_t *)vSupports, 1 ); - // clear the number of PIs/POs - Aig_ManForEachPi( pMan, pObj, i ) - pObj->pNext = NULL; - Aig_ManForEachPo( pMan, pObj, i ) - pObj->pNext = NULL; -/* - Aig_ManForEachPo( pMan, pObj, i ) - printf( "%d ", Vec_IntSize( (Vec_Int_t *)Vec_VecEntry(vSupports, i) ) ); - printf( "\n" ); -*/ - return vSupports; -} - -/**Function************************************************************* - - Synopsis [Start char-bases support representation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Aig_ManSuppCharStart( Vec_Int_t * vOne, int nPis ) -{ - unsigned * pBuffer; - int i, Entry; - int nWords = Aig_BitWordNum(nPis); - pBuffer = ALLOC( unsigned, nWords ); - memset( pBuffer, 0, sizeof(unsigned) * nWords ); - Vec_IntForEachEntry( vOne, Entry, i ) - { - assert( Entry < nPis ); - Aig_InfoSetBit( pBuffer, Entry ); - } - return pBuffer; -} - -/**Function************************************************************* - - Synopsis [Add to char-bases support representation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManSuppCharAdd( unsigned * pBuffer, Vec_Int_t * vOne, int nPis ) -{ - int i, Entry; - Vec_IntForEachEntry( vOne, Entry, i ) - { - assert( Entry < nPis ); - Aig_InfoSetBit( pBuffer, Entry ); - } -} - -/**Function************************************************************* - - Synopsis [Find the common variables using char-bases support representation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManSuppCharCommon( unsigned * pBuffer, Vec_Int_t * vOne ) -{ - int i, Entry, nCommon = 0; - Vec_IntForEachEntry( vOne, Entry, i ) - nCommon += Aig_InfoHasBit(pBuffer, Entry); - return nCommon; -} - -/**Function************************************************************* - - Synopsis [Find the best partition.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManPartitionSmartFindPart( Vec_Ptr_t * vPartSuppsAll, Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsBit, int nSuppSizeLimit, Vec_Int_t * vOne ) -{ - Vec_Int_t * vPartSupp;//, * vPart; - int Attract, Repulse, Value, ValueBest; - int i, nCommon, iBest; - iBest = -1; - ValueBest = 0; - Vec_PtrForEachEntry( vPartSuppsAll, vPartSupp, i ) - { -// vPart = Vec_PtrEntry( vPartsAll, i ); -// if ( nSuppSizeLimit > 0 && Vec_IntSize(vPart) >= nSuppSizeLimit ) -// continue; -// nCommon = Vec_IntTwoCountCommon( vPartSupp, vOne ); - nCommon = Aig_ManSuppCharCommon( Vec_PtrEntry(vPartSuppsBit, i), vOne ); - if ( nCommon == 0 ) - continue; - if ( nCommon == Vec_IntSize(vOne) ) - return i; - // skip partitions whose size exceeds the limit - if ( nSuppSizeLimit > 0 && Vec_IntSize(vPartSupp) >= 2 * nSuppSizeLimit ) - continue; - Attract = 1000 * nCommon / Vec_IntSize(vOne); - if ( Vec_IntSize(vPartSupp) < 100 ) - Repulse = 1; - else - Repulse = 1+Aig_Base2Log(Vec_IntSize(vPartSupp)-100); - Value = Attract/Repulse; - if ( ValueBest < Value ) - { - ValueBest = Value; - iBest = i; - } - } - if ( ValueBest < 75 ) - return -1; - return iBest; -} - -/**Function************************************************************* - - Synopsis [Perform the smart partitioning.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManPartitionPrint( Aig_Man_t * p, Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll ) -{ - Vec_Int_t * vOne; - int i, nOutputs, Counter; - - Counter = 0; - Vec_PtrForEachEntry( vPartSuppsAll, vOne, i ) - { - nOutputs = Vec_IntSize(Vec_PtrEntry(vPartsAll, i)); - printf( "%d=(%d,%d) ", i, Vec_IntSize(vOne), nOutputs ); - Counter += nOutputs; - if ( i == Vec_PtrSize(vPartsAll) - 1 ) - break; - } - assert( Counter == Aig_ManPoNum(p) ); -// printf( "\nTotal = %d. Outputs = %d.\n", Counter, Aig_ManPoNum(p) ); -} - -/**Function************************************************************* - - Synopsis [Perform the smart partitioning.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManPartitionCompact( Vec_Ptr_t * vPartsAll, Vec_Ptr_t * vPartSuppsAll, int nSuppSizeLimit ) -{ - Vec_Int_t * vOne, * vPart, * vPartSupp, * vTemp; - int i, iPart; - - if ( nSuppSizeLimit == 0 ) - nSuppSizeLimit = 200; - - // pack smaller partitions into larger blocks - iPart = 0; - vPart = vPartSupp = NULL; - Vec_PtrForEachEntry( vPartSuppsAll, vOne, i ) - { - if ( Vec_IntSize(vOne) < nSuppSizeLimit ) - { - if ( vPartSupp == NULL ) - { - assert( vPart == NULL ); - vPartSupp = Vec_IntDup(vOne); - vPart = Vec_PtrEntry(vPartsAll, i); - } - else - { - vPartSupp = Vec_IntTwoMerge( vTemp = vPartSupp, vOne ); - Vec_IntFree( vTemp ); - vPart = Vec_IntTwoMerge( vTemp = vPart, Vec_PtrEntry(vPartsAll, i) ); - Vec_IntFree( vTemp ); - Vec_IntFree( Vec_PtrEntry(vPartsAll, i) ); - } - if ( Vec_IntSize(vPartSupp) < nSuppSizeLimit ) - continue; - } - else - vPart = Vec_PtrEntry(vPartsAll, i); - // add the partition - Vec_PtrWriteEntry( vPartsAll, iPart, vPart ); - vPart = NULL; - if ( vPartSupp ) - { - Vec_IntFree( Vec_PtrEntry(vPartSuppsAll, iPart) ); - Vec_PtrWriteEntry( vPartSuppsAll, iPart, vPartSupp ); - vPartSupp = NULL; - } - iPart++; - } - // add the last one - if ( vPart ) - { - Vec_PtrWriteEntry( vPartsAll, iPart, vPart ); - vPart = NULL; - - assert( vPartSupp != NULL ); - Vec_IntFree( Vec_PtrEntry(vPartSuppsAll, iPart) ); - Vec_PtrWriteEntry( vPartSuppsAll, iPart, vPartSupp ); - vPartSupp = NULL; - iPart++; - } - Vec_PtrShrink( vPartsAll, iPart ); - Vec_PtrShrink( vPartsAll, iPart ); -} - -/**Function************************************************************* - - Synopsis [Perform the smart partitioning.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManPartitionSmart( Aig_Man_t * p, int nSuppSizeLimit, int fVerbose, Vec_Ptr_t ** pvPartSupps ) -{ - Vec_Ptr_t * vPartSuppsBit; - Vec_Ptr_t * vSupports, * vPartsAll, * vPartsAll2, * vPartSuppsAll;//, * vPartPtr; - Vec_Int_t * vOne, * vPart, * vPartSupp, * vTemp; - int i, iPart, iOut, clk; - - // compute the supports for all outputs -clk = clock(); - vSupports = Aig_ManSupports( p ); -if ( fVerbose ) -{ -PRT( "Supps", clock() - clk ); -} - // start char-based support representation - vPartSuppsBit = Vec_PtrAlloc( 1000 ); - - // create partitions -clk = clock(); - vPartsAll = Vec_PtrAlloc( 256 ); - vPartSuppsAll = Vec_PtrAlloc( 256 ); - Vec_PtrForEachEntry( vSupports, vOne, i ) - { - // get the output number - iOut = Vec_IntPop(vOne); - // find closely matching part - iPart = Aig_ManPartitionSmartFindPart( vPartSuppsAll, vPartsAll, vPartSuppsBit, nSuppSizeLimit, vOne ); - if ( iPart == -1 ) - { - // create new partition - vPart = Vec_IntAlloc( 32 ); - Vec_IntPush( vPart, iOut ); - // create new partition support - vPartSupp = Vec_IntDup( vOne ); - // add this partition and its support - Vec_PtrPush( vPartsAll, vPart ); - Vec_PtrPush( vPartSuppsAll, vPartSupp ); - - Vec_PtrPush( vPartSuppsBit, Aig_ManSuppCharStart(vOne, Aig_ManPiNum(p)) ); - } - else - { - // add output to this partition - vPart = Vec_PtrEntry( vPartsAll, iPart ); - Vec_IntPush( vPart, iOut ); - // merge supports - vPartSupp = Vec_PtrEntry( vPartSuppsAll, iPart ); - vPartSupp = Vec_IntTwoMerge( vTemp = vPartSupp, vOne ); - Vec_IntFree( vTemp ); - // reinsert new support - Vec_PtrWriteEntry( vPartSuppsAll, iPart, vPartSupp ); - - Aig_ManSuppCharAdd( Vec_PtrEntry(vPartSuppsBit, iPart), vOne, Aig_ManPiNum(p) ); - } - } - - // stop char-based support representation - Vec_PtrForEachEntry( vPartSuppsBit, vTemp, i ) - free( vTemp ); - Vec_PtrFree( vPartSuppsBit ); - -//printf( "\n" ); -if ( fVerbose ) -{ -PRT( "Parts", clock() - clk ); -} - -clk = clock(); - // reorder partitions in the decreasing order of support sizes - // remember partition number in each partition support - Vec_PtrForEachEntry( vPartSuppsAll, vOne, i ) - Vec_IntPush( vOne, i ); - // sort the supports in the decreasing order - Vec_VecSort( (Vec_Vec_t *)vPartSuppsAll, 1 ); - // reproduce partitions - vPartsAll2 = Vec_PtrAlloc( 256 ); - Vec_PtrForEachEntry( vPartSuppsAll, vOne, i ) - Vec_PtrPush( vPartsAll2, Vec_PtrEntry(vPartsAll, Vec_IntPop(vOne)) ); - Vec_PtrFree( vPartsAll ); - vPartsAll = vPartsAll2; - - // compact small partitions -// Aig_ManPartitionPrint( p, vPartsAll, vPartSuppsAll ); - Aig_ManPartitionCompact( vPartsAll, vPartSuppsAll, nSuppSizeLimit ); - if ( fVerbose ) -// Aig_ManPartitionPrint( p, vPartsAll, vPartSuppsAll ); - printf( "Created %d partitions.\n", Vec_PtrSize(vPartsAll) ); - -if ( fVerbose ) -{ -//PRT( "Comps", clock() - clk ); -} - - // cleanup - Vec_VecFree( (Vec_Vec_t *)vSupports ); - if ( pvPartSupps == NULL ) - Vec_VecFree( (Vec_Vec_t *)vPartSuppsAll ); - else - *pvPartSupps = vPartSuppsAll; -/* - // converts from intergers to nodes - Vec_PtrForEachEntry( vPartsAll, vPart, iPart ) - { - vPartPtr = Vec_PtrAlloc( Vec_IntSize(vPart) ); - Vec_IntForEachEntry( vPart, iOut, i ) - Vec_PtrPush( vPartPtr, Aig_ManPo(p, iOut) ); - Vec_IntFree( vPart ); - Vec_PtrWriteEntry( vPartsAll, iPart, vPartPtr ); - } -*/ - return vPartsAll; -} - -/**Function************************************************************* - - Synopsis [Perform the naive partitioning.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManPartitionNaive( Aig_Man_t * p, int nPartSize ) -{ - Vec_Ptr_t * vParts; - Aig_Obj_t * pObj; - int nParts, i; - nParts = (Aig_ManPoNum(p) / nPartSize) + ((Aig_ManPoNum(p) % nPartSize) > 0); - vParts = (Vec_Ptr_t *)Vec_VecStart( nParts ); - Aig_ManForEachPo( p, pObj, i ) - Vec_IntPush( Vec_PtrEntry(vParts, i / nPartSize), i ); - return vParts; -} - - - -/**Function************************************************************* - - Synopsis [Adds internal nodes in the topological order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ManDupPart_rec( Aig_Man_t * pNew, Aig_Man_t * pOld, Aig_Obj_t * pObj, Vec_Int_t * vSuppMap ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( Aig_ObjIsTravIdCurrent(pOld, pObj) ) - return pObj->pData; - Aig_ObjSetTravIdCurrent(pOld, pObj); - if ( Aig_ObjIsPi(pObj) ) - { - assert( Vec_IntSize(vSuppMap) == Aig_ManPiNum(pNew) ); - Vec_IntPush( vSuppMap, (int)(long)pObj->pNext ); - return pObj->pData = Aig_ObjCreatePi(pNew); - } - assert( Aig_ObjIsNode(pObj) ); - Aig_ManDupPart_rec( pNew, pOld, Aig_ObjFanin0(pObj), vSuppMap ); - Aig_ManDupPart_rec( pNew, pOld, Aig_ObjFanin1(pObj), vSuppMap ); - return pObj->pData = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); -} - -/**Function************************************************************* - - Synopsis [Adds internal nodes in the topological order.] - - Description [Returns the array of new outputs.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDupPart( Aig_Man_t * pNew, Aig_Man_t * pOld, Vec_Int_t * vPart, Vec_Int_t * vSuppMap, int fInverse ) -{ - Vec_Ptr_t * vOutsTotal; - Aig_Obj_t * pObj; - int Entry, i; - // create the PIs - Aig_ManIncrementTravId( pOld ); - Aig_ManConst1(pOld)->pData = Aig_ManConst1(pNew); - Aig_ObjSetTravIdCurrent( pOld, Aig_ManConst1(pOld) ); - if ( !fInverse ) - { - Vec_IntForEachEntry( vSuppMap, Entry, i ) - { - pObj = Aig_ManPi( pOld, Entry ); - pObj->pData = Aig_ManPi( pNew, i ); - Aig_ObjSetTravIdCurrent( pOld, pObj ); - } - } - else - { - Vec_IntForEachEntry( vSuppMap, Entry, i ) - { - pObj = Aig_ManPi( pOld, i ); - pObj->pData = Aig_ManPi( pNew, Entry ); - Aig_ObjSetTravIdCurrent( pOld, pObj ); - } - vSuppMap = NULL; // should not be useful - } - // create the internal nodes - vOutsTotal = Vec_PtrAlloc( Vec_IntSize(vPart) ); - if ( !fInverse ) - { - Vec_IntForEachEntry( vPart, Entry, i ) - { - pObj = Aig_ManPo( pOld, Entry ); - Aig_ManDupPart_rec( pNew, pOld, Aig_ObjFanin0(pObj), vSuppMap ); - Vec_PtrPush( vOutsTotal, Aig_ObjChild0Copy(pObj) ); - } - } - else - { - Aig_ManForEachObj( pOld, pObj, i ) - { - if ( Aig_ObjIsPo(pObj) ) - { - Aig_ManDupPart_rec( pNew, pOld, Aig_ObjFanin0(pObj), vSuppMap ); - Vec_PtrPush( vOutsTotal, Aig_ObjChild0Copy(pObj) ); - } - else if ( Aig_ObjIsNode(pObj) && pObj->nRefs == 0 ) - Aig_ManDupPart_rec( pNew, pOld, pObj, vSuppMap ); - - } - } - return vOutsTotal; -} - -/**Function************************************************************* - - Synopsis [Create partitioned miter of the two AIGs.] - - Description [Assumes that each output in the second AIG cannot have - more supp vars than the same output in the first AIG.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManMiterPartitioned( Aig_Man_t * p1, Aig_Man_t * p2, int nPartSize ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pMiter; - Vec_Ptr_t * vMiters, * vNodes1, * vNodes2; - Vec_Ptr_t * vParts, * vPartSupps; - Vec_Int_t * vPart, * vPartSupp; - int i, k; - // partition the first manager - vParts = Aig_ManPartitionSmart( p1, nPartSize, 0, &vPartSupps ); - // derive miters - vMiters = Vec_PtrAlloc( Vec_PtrSize(vParts) ); - for ( i = 0; i < Vec_PtrSize(vParts); i++ ) - { - // get partition and its support - vPart = Vec_PtrEntry( vParts, i ); - vPartSupp = Vec_PtrEntry( vPartSupps, i ); - // create the new miter - pNew = Aig_ManStart( 1000 ); -// pNew->pName = Extra_UtilStrsav( p1->pName ); - // create the PIs - for ( k = 0; k < Vec_IntSize(vPartSupp); k++ ) - Aig_ObjCreatePi( pNew ); - // copy the components - vNodes1 = Aig_ManDupPart( pNew, p1, vPart, vPartSupp, 0 ); - vNodes2 = Aig_ManDupPart( pNew, p2, vPart, vPartSupp, 0 ); - // create the miter - pMiter = Aig_MiterTwo( pNew, vNodes1, vNodes2 ); - Vec_PtrFree( vNodes1 ); - Vec_PtrFree( vNodes2 ); - // create the output - Aig_ObjCreatePo( pNew, pMiter ); - // clean up - Aig_ManCleanup( pNew ); - Vec_PtrPush( vMiters, pNew ); - } - Vec_VecFree( (Vec_Vec_t *)vParts ); - Vec_VecFree( (Vec_Vec_t *)vPartSupps ); - return vMiters; -} - -/**Function************************************************************* - - Synopsis [Performs partitioned choice computation.] - - Description [Assumes that each output in the second AIG cannot have - more supp vars than the same output in the first AIG.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManChoicePartitioned( Vec_Ptr_t * vAigs, int nPartSize, int fVerbose ) -{ -// extern int Cmd_CommandExecute( void * pAbc, char * sCommand ); -// extern void * Abc_FrameGetGlobalFrame(); - extern Aig_Man_t * Fra_FraigChoice( Aig_Man_t * pManAig, int nConfMax ); - - Vec_Ptr_t * vOutsTotal, * vOuts; - Aig_Man_t * pAigTotal, * pAigPart, * pAig; - Vec_Int_t * vPart, * vPartSupp; - Vec_Ptr_t * vParts; - Aig_Obj_t * pObj; - void ** ppData; - int i, k, m; - - // partition the first AIG in the array - assert( Vec_PtrSize(vAigs) > 1 ); - pAig = Vec_PtrEntry( vAigs, 0 ); - vParts = Aig_ManPartitionSmart( pAig, nPartSize, 0, NULL ); - - // start the total fraiged AIG - pAigTotal = Aig_ManStartFrom( pAig ); - Aig_ManReprStart( pAigTotal, Vec_PtrSize(vAigs) * Aig_ManObjNumMax(pAig) + 10000 ); - vOutsTotal = Vec_PtrStart( Aig_ManPoNum(pAig) ); - - // set the PI numbers - Vec_PtrForEachEntry( vAigs, pAig, i ) - Aig_ManForEachPi( pAig, pObj, k ) - pObj->pNext = (Aig_Obj_t *)(long)k; - -// Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "unset progressbar" ); - - // create the total fraiged AIG - vPartSupp = Vec_IntAlloc( 100 ); // maps part PI num into total PI num - Vec_PtrForEachEntry( vParts, vPart, i ) - { - // derive the partition AIG - pAigPart = Aig_ManStart( 5000 ); -// pAigPart->pName = Extra_UtilStrsav( pAigPart->pName ); - Vec_IntClear( vPartSupp ); - Vec_PtrForEachEntry( vAigs, pAig, k ) - { - vOuts = Aig_ManDupPart( pAigPart, pAig, vPart, vPartSupp, 0 ); - if ( k == 0 ) - { - Vec_PtrForEachEntry( vOuts, pObj, m ) - Aig_ObjCreatePo( pAigPart, pObj ); - } - Vec_PtrFree( vOuts ); - } - // derive the total AIG from the partitioned AIG - vOuts = Aig_ManDupPart( pAigTotal, pAigPart, vPart, vPartSupp, 1 ); - // add to the outputs - Vec_PtrForEachEntry( vOuts, pObj, k ) - { - assert( Vec_PtrEntry( vOutsTotal, Vec_IntEntry(vPart,k) ) == NULL ); - Vec_PtrWriteEntry( vOutsTotal, Vec_IntEntry(vPart,k), pObj ); - } - Vec_PtrFree( vOuts ); - // store contents of pData pointers - ppData = ALLOC( void *, Aig_ManObjNumMax(pAigPart) ); - Aig_ManForEachObj( pAigPart, pObj, k ) - ppData[k] = pObj->pData; - // report the process - if ( fVerbose ) - printf( "Part %4d (out of %4d) PI = %5d. PO = %5d. And = %6d. Lev = %4d.\r", - i+1, Vec_PtrSize(vParts), Aig_ManPiNum(pAigPart), Aig_ManPoNum(pAigPart), - Aig_ManNodeNum(pAigPart), Aig_ManLevelNum(pAigPart) ); - // compute equivalence classes (to be stored in pNew->pReprs) - pAig = Fra_FraigChoice( pAigPart, 1000 ); - Aig_ManStop( pAig ); - // reset the pData pointers - Aig_ManForEachObj( pAigPart, pObj, k ) - pObj->pData = ppData[k]; - free( ppData ); - // transfer representatives to the total AIG - if ( pAigPart->pReprs ) - Aig_ManTransferRepr( pAigTotal, pAigPart ); - Aig_ManStop( pAigPart ); - } - if ( fVerbose ) - printf( " \r" ); - Vec_VecFree( (Vec_Vec_t *)vParts ); - Vec_IntFree( vPartSupp ); - -// Cmd_CommandExecute( Abc_FrameGetGlobalFrame(), "set progressbar" ); - - // clear the PI numbers - Vec_PtrForEachEntry( vAigs, pAig, i ) - Aig_ManForEachPi( pAig, pObj, k ) - pObj->pNext = NULL; -/* - // collect the missing outputs (outputs whose driver is not a node) - pAig = Vec_PtrEntry( vAigs, 0 ); - Aig_ManConst1(pAig)->pData = Aig_ManConst1(pAigTotal); - Aig_ManForEachPi( pAig, pObj, i ) - pAig->pData = Aig_ManPi( pAigTotal, i ); - Aig_ManForEachPo( pAig, pObj, i ) - if ( !Aig_ObjIsNode(Aig_ObjFanin0(pObj)) ) - { - assert( Vec_PtrEntry( vOutsTotal, i ) == NULL ); - Vec_PtrWriteEntry( vOutsTotal, i, Aig_ObjChild0Copy(pObj) ); - } -*/ - // add the outputs in the same order - Vec_PtrForEachEntry( vOutsTotal, pObj, i ) - Aig_ObjCreatePo( pAigTotal, pObj ); - Vec_PtrFree( vOutsTotal ); - - // derive the result of choicing - pAig = Aig_ManRehash( pAigTotal ); - // create the equivalent nodes lists - Aig_ManMarkValidChoices( pAig ); - return pAig; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigRepr.c b/src/abc8/aig/aigRepr.c deleted file mode 100644 index 5ee6c9af..00000000 --- a/src/abc8/aig/aigRepr.c +++ /dev/null @@ -1,457 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigRepr.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Handing node representatives.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigRepr.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Starts the array of representatives.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManReprStart( Aig_Man_t * p, int nIdMax ) -{ - assert( Aig_ManBufNum(p) == 0 ); - assert( p->pReprs == NULL ); - p->nReprsAlloc = nIdMax; - p->pReprs = ALLOC( Aig_Obj_t *, p->nReprsAlloc ); - memset( p->pReprs, 0, sizeof(Aig_Obj_t *) * p->nReprsAlloc ); -} - -/**Function************************************************************* - - Synopsis [Stop the array of representatives.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManReprStop( Aig_Man_t * p ) -{ - assert( p->pReprs != NULL ); - FREE( p->pReprs ); - p->nReprsAlloc = 0; -} - -/**Function************************************************************* - - Synopsis [Set the representative.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCreateRepr( Aig_Man_t * p, Aig_Obj_t * pNode1, Aig_Obj_t * pNode2 ) -{ - assert( p->pReprs != NULL ); - assert( !Aig_IsComplement(pNode1) ); - assert( !Aig_IsComplement(pNode2) ); - assert( pNode1->Id < p->nReprsAlloc ); - assert( pNode2->Id < p->nReprsAlloc ); - assert( pNode1->Id < pNode2->Id ); - p->pReprs[pNode2->Id] = pNode1; -} - -/**Function************************************************************* - - Synopsis [Set the representative.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Aig_ObjSetRepr( Aig_Man_t * p, Aig_Obj_t * pNode1, Aig_Obj_t * pNode2 ) -{ - assert( p->pReprs != NULL ); - assert( !Aig_IsComplement(pNode1) ); - assert( !Aig_IsComplement(pNode2) ); - assert( pNode1->Id < p->nReprsAlloc ); - assert( pNode2->Id < p->nReprsAlloc ); - if ( pNode1 == pNode2 ) - return; - if ( pNode1->Id < pNode2->Id ) - p->pReprs[pNode2->Id] = pNode1; - else - p->pReprs[pNode1->Id] = pNode2; -} - -/**Function************************************************************* - - Synopsis [Find representative.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Aig_Obj_t * Aig_ObjFindRepr( Aig_Man_t * p, Aig_Obj_t * pNode ) -{ - assert( p->pReprs != NULL ); - assert( !Aig_IsComplement(pNode) ); - assert( pNode->Id < p->nReprsAlloc ); -// assert( !p->pReprs[pNode->Id] || p->pReprs[pNode->Id]->Id < pNode->Id ); - return p->pReprs[pNode->Id]; -} - -/**Function************************************************************* - - Synopsis [Clears the representative.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Aig_ObjClearRepr( Aig_Man_t * p, Aig_Obj_t * pNode ) -{ - assert( p->pReprs != NULL ); - assert( !Aig_IsComplement(pNode) ); - assert( pNode->Id < p->nReprsAlloc ); - p->pReprs[pNode->Id] = NULL; -} - -/**Function************************************************************* - - Synopsis [Find representative transitively.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Aig_Obj_t * Aig_ObjFindReprTransitive( Aig_Man_t * p, Aig_Obj_t * pNode ) -{ - Aig_Obj_t * pNext, * pRepr; - if ( (pRepr = Aig_ObjFindRepr(p, pNode)) ) - while ( (pNext = Aig_ObjFindRepr(p, pRepr)) ) - pRepr = pNext; - return pRepr; -} - -/**Function************************************************************* - - Synopsis [Returns representatives of fanin in approapriate polarity.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline Aig_Obj_t * Aig_ObjRepr( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t * pRepr; - if ( (pRepr = Aig_ObjFindRepr(p, pObj)) ) - return Aig_NotCond( pRepr->pData, pObj->fPhase ^ pRepr->fPhase ); - return pObj->pData; -} -static inline Aig_Obj_t * Aig_ObjChild0Repr( Aig_Man_t * p, Aig_Obj_t * pObj ) { return Aig_NotCond( Aig_ObjRepr(p, Aig_ObjFanin0(pObj)), Aig_ObjFaninC0(pObj) ); } -static inline Aig_Obj_t * Aig_ObjChild1Repr( Aig_Man_t * p, Aig_Obj_t * pObj ) { return Aig_NotCond( Aig_ObjRepr(p, Aig_ObjFanin1(pObj)), Aig_ObjFaninC1(pObj) ); } - -/**Function************************************************************* - - Synopsis [Duplicates AIG while substituting representatives.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManTransferRepr( Aig_Man_t * pNew, Aig_Man_t * pOld ) -{ - Aig_Obj_t * pObj, * pRepr; - int k; - assert( pNew->pReprs != NULL ); - // extend storage to fix pNew - if ( pNew->nReprsAlloc < Aig_ManObjNumMax(pNew) ) - { - int nReprsAllocNew = 2 * Aig_ManObjNumMax(pNew); - pNew->pReprs = REALLOC( Aig_Obj_t *, pNew->pReprs, nReprsAllocNew ); - memset( pNew->pReprs + pNew->nReprsAlloc, 0, sizeof(Aig_Obj_t *) * (nReprsAllocNew-pNew->nReprsAlloc) ); - pNew->nReprsAlloc = nReprsAllocNew; - } - // go through the nodes which have representatives - Aig_ManForEachObj( pOld, pObj, k ) - if ( (pRepr = Aig_ObjFindRepr(pOld, pObj)) ) - Aig_ObjSetRepr( pNew, Aig_Regular(pRepr->pData), Aig_Regular(pObj->pData) ); -} - -/**Function************************************************************* - - Synopsis [Duplicates the AIG manager recursively.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ManDupRepr_rec( Aig_Man_t * pNew, Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t * pRepr; - if ( pObj->pData ) - return pObj->pData; - if ( (pRepr = Aig_ObjFindRepr(p, pObj)) ) - { - Aig_ManDupRepr_rec( pNew, p, pRepr ); - return pObj->pData = Aig_NotCond( pRepr->pData, pRepr->fPhase ^ pObj->fPhase ); - } - Aig_ManDupRepr_rec( pNew, p, Aig_ObjFanin0(pObj) ); - Aig_ManDupRepr_rec( pNew, p, Aig_ObjFanin1(pObj) ); - return pObj->pData = Aig_And( pNew, Aig_ObjChild0Repr(p, pObj), Aig_ObjChild1Repr(p, pObj) ); -} - -/**Function************************************************************* - - Synopsis [Duplicates AIG while substituting representatives.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManDupRepr( Aig_Man_t * p, int fOrdered ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj; - int i; - // start the HOP package - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - pNew->nRegs = p->nRegs; - if ( p->vFlopNums ) - pNew->vFlopNums = Vec_IntDup( p->vFlopNums ); - // map the const and primary inputs - Aig_ManCleanData( p ); - Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); - Aig_ManForEachPi( p, pObj, i ) - pObj->pData = Aig_ObjCreatePi(pNew); - // map the internal nodes - if ( fOrdered ) - { - Aig_ManForEachNode( p, pObj, i ) - pObj->pData = Aig_And( pNew, Aig_ObjChild0Repr(p, pObj), Aig_ObjChild1Repr(p, pObj) ); - } - else - { - Aig_ManForEachPo( p, pObj, i ) - Aig_ManDupRepr_rec( pNew, p, Aig_ObjFanin0(pObj) ); - } - // transfer the POs - Aig_ManForEachPo( p, pObj, i ) - Aig_ObjCreatePo( pNew, Aig_ObjChild0Repr(p, pObj) ); - // check the new manager - if ( !Aig_ManCheck(pNew) ) - printf( "Aig_ManDupRepr: Check has failed.\n" ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Transfer representatives and return the number of critical fanouts.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManRemapRepr( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pRepr; - int i, nFanouts = 0; - Aig_ManForEachNode( p, pObj, i ) - { - pRepr = Aig_ObjFindReprTransitive( p, pObj ); - if ( pRepr == NULL ) - continue; - assert( pRepr->Id < pObj->Id ); - Aig_ObjSetRepr( p, pObj, pRepr ); - nFanouts += (pObj->nRefs > 0); - } - return nFanouts; -} - -/**Function************************************************************* - - Synopsis [Returns 1 if pOld is in the TFI of pNew.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjCheckTfi_rec( Aig_Man_t * p, Aig_Obj_t * pNode, Aig_Obj_t * pOld ) -{ - // check the trivial cases - if ( pNode == NULL ) - return 0; -// if ( pNode->Id < pOld->Id ) // cannot use because of choices of pNode -// return 0; - if ( pNode == pOld ) - return 1; - // skip the visited node - if ( Aig_ObjIsTravIdCurrent( p, pNode ) ) - return 0; - Aig_ObjSetTravIdCurrent( p, pNode ); - // check the children - if ( Aig_ObjCheckTfi_rec( p, Aig_ObjFanin0(pNode), pOld ) ) - return 1; - if ( Aig_ObjCheckTfi_rec( p, Aig_ObjFanin1(pNode), pOld ) ) - return 1; - // check equivalent nodes - return Aig_ObjCheckTfi_rec( p, p->pEquivs[pNode->Id], pOld ); -} - -/**Function************************************************************* - - Synopsis [Returns 1 if pOld is in the TFI of pNew.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjCheckTfi( Aig_Man_t * p, Aig_Obj_t * pNew, Aig_Obj_t * pOld ) -{ - assert( !Aig_IsComplement(pNew) ); - assert( !Aig_IsComplement(pOld) ); - Aig_ManIncrementTravId( p ); - return Aig_ObjCheckTfi_rec( p, pNew, pOld ); -} - -/**Function************************************************************* - - Synopsis [Iteratively rehashes the AIG.] - - Description [The input AIG is assumed to have representatives assigned.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManRehash( Aig_Man_t * p ) -{ - Aig_Man_t * pTemp; - int i, nFanouts; - assert( p->pReprs != NULL ); - for ( i = 0; (nFanouts = Aig_ManRemapRepr( p )); i++ ) - { -// printf( "Iter = %3d. Fanouts = %6d. Nodes = %7d.\n", i+1, nFanouts, Aig_ManNodeNum(p) ); - p = Aig_ManDupRepr( pTemp = p, 1 ); - Aig_ManReprStart( p, Aig_ManObjNumMax(p) ); - Aig_ManTransferRepr( p, pTemp ); - Aig_ManStop( pTemp ); - } - return p; -} - -/**Function************************************************************* - - Synopsis [Marks the nodes that are Creates choices.] - - Description [The input AIG is assumed to have representatives assigned.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManMarkValidChoices( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pRepr; - int i; - assert( p->pReprs != NULL ); - // create equivalent nodes in the manager - assert( p->pEquivs == NULL ); - p->pEquivs = ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(p) ); - memset( p->pEquivs, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(p) ); - // make the choice nodes - Aig_ManForEachNode( p, pObj, i ) - { - pRepr = Aig_ObjFindRepr( p, pObj ); - if ( pRepr == NULL ) - continue; - assert( pObj->nRefs == 0 ); - // skip constant and PI classes - if ( !Aig_ObjIsNode(pRepr) ) - { - Aig_ObjClearRepr( p, pObj ); - continue; - } - // skip choices with combinatinal loops - if ( Aig_ObjCheckTfi( p, pObj, pRepr ) ) - { - Aig_ObjClearRepr( p, pObj ); - continue; - } -//printf( "Node %d is represented by node %d.\n", pObj->Id, pRepr->Id ); - // add choice to the choice node - p->pEquivs[pObj->Id] = p->pEquivs[pRepr->Id]; - p->pEquivs[pRepr->Id] = pObj; - } -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigRet.c b/src/abc8/aig/aigRet.c deleted file mode 100644 index d1784b1b..00000000 --- a/src/abc8/aig/aigRet.c +++ /dev/null @@ -1,969 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigRet.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Retiming of AIGs.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigRet.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// init values -typedef enum { - RTM_VAL_NONE, // 0: non-existent value - RTM_VAL_ZERO, // 1: initial value 0 - RTM_VAL_ONE, // 2: initial value 1 - RTM_VAL_VOID // 3: unused value -} Rtm_Init_t; - -typedef struct Rtm_Man_t_ Rtm_Man_t; -struct Rtm_Man_t_ -{ - // network representation - Vec_Ptr_t * vObjs; // retiming objects - Vec_Ptr_t * vPis; // PIs only - Vec_Ptr_t * vPos; // POs only - Aig_MmFlex_t * pMem; // the memory manager - // autonomous components after cutting off - // storage for overflow latches - unsigned * pExtra; - int nExtraCur; - int nExtraAlloc; -}; - -typedef struct Rtm_Edg_t_ Rtm_Edg_t; -struct Rtm_Edg_t_ -{ - unsigned long nLats : 12; // the number of latches - unsigned long LData : 20; // the latches themselves -}; - -typedef struct Rtm_Obj_t_ Rtm_Obj_t; -struct Rtm_Obj_t_ -{ - void * pCopy; // the copy of this object - unsigned long Type : 3; // object type - unsigned long fMark : 1; // multipurpose mark - unsigned long fAuto : 1; // this object belongs to an autonomous component - unsigned long fCompl0 : 1; // complemented attribute of the first edge - unsigned long fCompl1 : 1; // complemented attribute of the second edge - unsigned long nFanins : 8; // the number of fanins - unsigned Num : 17; // the retiming number of this node - int Id; // ID of this object - int Temp; // temporary usage - int nFanouts; // the number of fanouts - void * pFanio[0]; // fanins and their edges (followed by fanouts and pointers to their edges) -}; - -static inline Rtm_Obj_t * Rtm_ObjFanin( Rtm_Obj_t * pObj, int i ) { return (Rtm_Obj_t *)pObj->pFanio[2*i]; } -static inline Rtm_Obj_t * Rtm_ObjFanout( Rtm_Obj_t * pObj, int i ) { return (Rtm_Obj_t *)pObj->pFanio[2*(pObj->nFanins+i)]; } -static inline Rtm_Edg_t * Rtm_ObjEdge( Rtm_Obj_t * pObj, int i ) { return (Rtm_Edg_t *)(pObj->pFanio + 2*i + 1); } -static inline Rtm_Edg_t * Rtm_ObjFanoutEdge( Rtm_Obj_t * pObj, int i ) { return (Rtm_Edg_t *)pObj->pFanio[2*(pObj->nFanins+i) + 1]; } - -static inline Rtm_Init_t Rtm_InitNot( Rtm_Init_t Val ) { if ( Val == RTM_VAL_ZERO ) return RTM_VAL_ONE; if ( Val == RTM_VAL_ONE ) return RTM_VAL_ZERO; assert( 0 ); return -1; } -static inline Rtm_Init_t Rtm_InitNotCond( Rtm_Init_t Val, int c ) { return c ? Rtm_InitNot(Val) : Val; } -static inline Rtm_Init_t Rtm_InitAnd(Rtm_Init_t ValA, Rtm_Init_t ValB ) { if ( ValA == RTM_VAL_ONE && ValB == RTM_VAL_ONE ) return RTM_VAL_ONE; if ( ValA == RTM_VAL_ZERO || ValB == RTM_VAL_ZERO ) return RTM_VAL_ZERO; assert( 0 ); return -1; } - -static inline int Rtm_InitWordsNum( int nLats ) { return (nLats >> 4) + ((nLats & 15) > 0); } -static inline int Rtm_InitGetTwo( unsigned * p, int i ) { return (p[i>>4] >> ((i & 15)<<1)) & 3; } -static inline void Rtm_InitSetTwo( unsigned * p, int i, int val ) { p[i>>4] |= (val << ((i & 15)<<1)); } -static inline void Rtm_InitXorTwo( unsigned * p, int i, int val ) { p[i>>4] ^= (val << ((i & 15)<<1)); } - -static inline Rtm_Init_t Rtm_ObjGetFirst1( Rtm_Edg_t * pEdge ) { return pEdge->LData & 3; } -static inline Rtm_Init_t Rtm_ObjGetLast1( Rtm_Edg_t * pEdge ) { return (pEdge->LData >> ((pEdge->nLats-1)<<1)) & 3; } -static inline Rtm_Init_t Rtm_ObjGetOne1( Rtm_Edg_t * pEdge, int i ) { assert( i < (int)pEdge->nLats ); return (pEdge->LData >> (i << 1)) & 3; } -static inline Rtm_Init_t Rtm_ObjRemFirst1( Rtm_Edg_t * pEdge ) { int Val = pEdge->LData & 3; pEdge->LData >>= 2; assert(pEdge->nLats > 0); pEdge->nLats--; return Val; } -static inline Rtm_Init_t Rtm_ObjRemLast1( Rtm_Edg_t * pEdge ) { int Val = (pEdge->LData >> ((pEdge->nLats-1)<<1)) & 3; pEdge->LData ^= Val << ((pEdge->nLats-1)<<1); assert(pEdge->nLats > 0); pEdge->nLats--; return Val; } -static inline void Rtm_ObjAddFirst1( Rtm_Edg_t * pEdge, Rtm_Init_t Val ) { assert( Val > 0 && Val < 4 ); pEdge->LData = (pEdge->LData << 2) | Val; pEdge->nLats++; } -static inline void Rtm_ObjAddLast1( Rtm_Edg_t * pEdge, Rtm_Init_t Val ) { assert( Val > 0 && Val < 4 ); pEdge->LData |= Val << (pEdge->nLats<<1); pEdge->nLats++; } - -static inline Rtm_Init_t Rtm_ObjGetFirst2( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { return Rtm_InitGetTwo( p->pExtra + pEdge->LData, 0 ); } -static inline Rtm_Init_t Rtm_ObjGetLast2( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { return Rtm_InitGetTwo( p->pExtra + pEdge->LData, pEdge->nLats - 1 ); } -static inline Rtm_Init_t Rtm_ObjGetOne2( Rtm_Man_t * p, Rtm_Edg_t * pEdge, int i ) { return Rtm_InitGetTwo( p->pExtra + pEdge->LData, i ); } -static Rtm_Init_t Rtm_ObjRemFirst2( Rtm_Man_t * p, Rtm_Edg_t * pEdge ); -static inline Rtm_Init_t Rtm_ObjRemLast2( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { Rtm_Init_t Val = Rtm_ObjGetLast2( p, pEdge ); Rtm_InitXorTwo( p->pExtra + pEdge->LData, pEdge->nLats - 1, Val ); pEdge->nLats--; return Val; } -static void Rtm_ObjAddFirst2( Rtm_Man_t * p, Rtm_Edg_t * pEdge, Rtm_Init_t Val ); -static inline void Rtm_ObjAddLast2( Rtm_Man_t * p, Rtm_Edg_t * pEdge, Rtm_Init_t Val ) { Rtm_InitSetTwo( p->pExtra + pEdge->LData, pEdge->nLats, Val ); pEdge->nLats++; } - -static void Rtm_ObjTransferToSmall( Rtm_Man_t * p, Rtm_Edg_t * pEdge ); -static void Rtm_ObjTransferToBig( Rtm_Man_t * p, Rtm_Edg_t * pEdge ); -static void Rtm_ObjTransferToBigger( Rtm_Man_t * p, Rtm_Edg_t * pEdge ); - -static inline Rtm_Init_t Rtm_ObjGetFirst( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { return pEdge->nLats > 10? Rtm_ObjGetFirst2(p, pEdge) : Rtm_ObjGetFirst1(pEdge); } -static inline Rtm_Init_t Rtm_ObjGetLast( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { return pEdge->nLats > 10? Rtm_ObjGetLast2(p, pEdge) : Rtm_ObjGetLast1(pEdge); } -static inline Rtm_Init_t Rtm_ObjGetOne( Rtm_Man_t * p, Rtm_Edg_t * pEdge, int i ) { return pEdge->nLats > 10? Rtm_ObjGetOne2(p, pEdge, i) : Rtm_ObjGetOne1(pEdge, i); } -static Rtm_Init_t Rtm_ObjRemFirst( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { Rtm_Init_t Res = pEdge->nLats > 10 ? Rtm_ObjRemFirst2(p, pEdge) : Rtm_ObjRemFirst1(pEdge); if ( pEdge->nLats == 10 ) Rtm_ObjTransferToSmall(p, pEdge); return Res; } -static Rtm_Init_t Rtm_ObjRemLast( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) { Rtm_Init_t Res = pEdge->nLats > 10 ? Rtm_ObjRemLast2(p, pEdge) : Rtm_ObjRemLast1(pEdge); if ( pEdge->nLats == 10 ) Rtm_ObjTransferToSmall(p, pEdge); return Res; } -static void Rtm_ObjAddFirst( Rtm_Man_t * p, Rtm_Edg_t * pEdge, Rtm_Init_t Val ) { if ( pEdge->nLats == 10 ) Rtm_ObjTransferToBig(p, pEdge); else if ( (pEdge->nLats & 15) == 15 ) Rtm_ObjTransferToBigger(p, pEdge); if ( pEdge->nLats >= 10 ) Rtm_ObjAddFirst2(p, pEdge, Val); else Rtm_ObjAddFirst1(pEdge, Val); } -static void Rtm_ObjAddLast( Rtm_Man_t * p, Rtm_Edg_t * pEdge, Rtm_Init_t Val ) { if ( pEdge->nLats == 10 ) Rtm_ObjTransferToBig(p, pEdge); else if ( (pEdge->nLats & 15) == 15 ) Rtm_ObjTransferToBigger(p, pEdge); if ( pEdge->nLats >= 10 ) Rtm_ObjAddLast2(p, pEdge, Val); else Rtm_ObjAddLast1(pEdge, Val); } - - -// iterator over the primary inputs -#define Rtm_ManForEachPi( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPis, pObj, i ) -// iterator over the primary outputs -#define Rtm_ManForEachPo( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPos, pObj, i ) -// iterator over all objects, including those currently not used -#define Rtm_ManForEachObj( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vObjs, pObj, i ) -// iterate through the fanins -#define Rtm_ObjForEachFanin( pObj, pFanin, i ) \ - for ( i = 0; i < (int)(pObj)->nFanins && ((pFanin = Rtm_ObjFanin(pObj, i)), 1); i++ ) -// iterate through the fanouts -#define Rtm_ObjForEachFanout( pObj, pFanout, i ) \ - for ( i = 0; i < (int)(pObj)->nFanouts && ((pFanout = Rtm_ObjFanout(pObj, i)), 1); i++ ) -// iterate through the fanin edges -#define Rtm_ObjForEachFaninEdge( pObj, pEdge, i ) \ - for ( i = 0; i < (int)(pObj)->nFanins && ((pEdge = Rtm_ObjEdge(pObj, i)), 1); i++ ) -// iterate through the fanout edges -#define Rtm_ObjForEachFanoutEdge( pObj, pEdge, i ) \ - for ( i = 0; i < (int)(pObj)->nFanouts && ((pEdge = Rtm_ObjFanoutEdge(pObj, i)), 1); i++ ) - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Transfers from big to small storage.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjTransferToSmall( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) -{ - assert( pEdge->nLats == 10 ); - pEdge->LData = p->pExtra[pEdge->LData]; -} - -/**Function************************************************************* - - Synopsis [Transfers from small to big storage.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjTransferToBig( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) -{ - assert( pEdge->nLats == 10 ); - if ( p->nExtraCur + 1 > p->nExtraAlloc ) - { - int nExtraAllocNew = AIG_MAX( 2 * p->nExtraAlloc, 1024 ); - p->pExtra = REALLOC( unsigned, p->pExtra, nExtraAllocNew ); - p->nExtraAlloc = nExtraAllocNew; - } - p->pExtra[p->nExtraCur] = pEdge->LData; - pEdge->LData = p->nExtraCur++; -} - -/**Function************************************************************* - - Synopsis [Transfers to bigger storage.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjTransferToBigger( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) -{ - int nWords; - assert( (pEdge->nLats & 15) == 15 ); - nWords = (pEdge->nLats + 1) >> 4; - if ( p->nExtraCur + nWords + 1 > p->nExtraAlloc ) - { - int nExtraAllocNew = AIG_MAX( 2 * p->nExtraAlloc, 1024 ); - p->pExtra = REALLOC( unsigned, p->pExtra, nExtraAllocNew ); - p->nExtraAlloc = nExtraAllocNew; - } - memcpy( p->pExtra + p->nExtraCur, p->pExtra + pEdge->LData, sizeof(unsigned) * nWords ); - p->pExtra[p->nExtraCur + nWords] = 0; - pEdge->LData = p->nExtraCur; - p->nExtraCur += nWords + 1; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Rtm_Init_t Rtm_ObjRemFirst2( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) -{ - Rtm_Init_t Val = 0, Temp; - unsigned * pB = p->pExtra + pEdge->LData, * pE = pB + Rtm_InitWordsNum( pEdge->nLats-- ) - 1; - while ( pE >= pB ) - { - Temp = *pE & 3; - *pE = (*pE >> 2) | (Val << 30); - Val = Temp; - pE--; - } - assert( Val != 0 ); - return Val; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjAddFirst2( Rtm_Man_t * p, Rtm_Edg_t * pEdge, Rtm_Init_t Val ) -{ - unsigned * pB = p->pExtra + pEdge->LData, * pE = pB + Rtm_InitWordsNum( ++pEdge->nLats ); - Rtm_Init_t Temp; - assert( Val != 0 ); - while ( pB < pE ) - { - Temp = *pB >> 30; - *pB = (*pB << 2) | Val; - Val = Temp; - pB++; - } -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_PrintEdge( Rtm_Man_t * p, Rtm_Edg_t * pEdge ) -{ -// unsigned LData = pEdge->LData; - printf( "%d : ", pEdge->nLats ); -/* - if ( pEdge->nLats > 10 ) - Extra_PrintBinary( stdout, p->pExtra + pEdge->LData, 2*(pEdge->nLats+1) ); - else - Extra_PrintBinary( stdout, &LData, 2*(pEdge->nLats+1) ); -*/ - printf( "\n" ); -} - - -/**Function************************************************************* - - Synopsis [Allocates the retiming manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Rtm_Man_t * Rtm_ManAlloc( Aig_Man_t * p ) -{ - Rtm_Man_t * pRtm; - // start the manager - pRtm = ALLOC( Rtm_Man_t, 1 ); - memset( pRtm, 0, sizeof(Rtm_Man_t) ); - // perform initializations - pRtm->vObjs = Vec_PtrAlloc( Aig_ManObjNum(p) ); - pRtm->vPis = Vec_PtrAlloc( Aig_ManPiNum(p) ); - pRtm->vPos = Vec_PtrAlloc( Aig_ManPoNum(p) ); - pRtm->pMem = Aig_MmFlexStart(); - return pRtm; -} - -/**Function************************************************************* - - Synopsis [Allocates the retiming manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ManFree( Rtm_Man_t * p ) -{ - Vec_PtrFree( p->vObjs ); - Vec_PtrFree( p->vPis ); - Vec_PtrFree( p->vPos ); - Aig_MmFlexStop( p->pMem, 0 ); - FREE( p->pExtra ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Counts the maximum number of latches on an edge.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ManLatchMax( Rtm_Man_t * p ) -{ - Rtm_Obj_t * pObj; - Rtm_Edg_t * pEdge; - int nLatchMax = 0, i, k;//, c, Val; - Rtm_ManForEachObj( p, pObj, i ) - Rtm_ObjForEachFaninEdge( pObj, pEdge, k ) - { -/* - for ( c = 0; c < (int)pEdge->nLats; c++ ) - { - Val = Rtm_ObjGetOne( p, pEdge, c ); - assert( Val == 1 || Val == 2 ); - } -*/ - nLatchMax = AIG_MAX( nLatchMax, (int)pEdge->nLats ); - } - return nLatchMax; -} - -/**Function************************************************************* - - Synopsis [Allocates the retiming object.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Rtm_Obj_t * Rtm_ObjAlloc( Rtm_Man_t * pRtm, int nFanins, int nFanouts ) -{ - Rtm_Obj_t * pObj; - int Size = sizeof(Rtm_Obj_t) + sizeof(Rtm_Obj_t *) * (nFanins + nFanouts) * 2; - pObj = (Rtm_Obj_t *)Aig_MmFlexEntryFetch( pRtm->pMem, Size ); - memset( pObj, 0, sizeof(Rtm_Obj_t) ); - pObj->Type = (int)(nFanins == 1 && nFanouts == 0); // mark PO - pObj->Num = nFanins; // temporary - pObj->Temp = nFanouts; - pObj->Id = Vec_PtrSize(pRtm->vObjs); - Vec_PtrPush( pRtm->vObjs, pObj ); - return pObj; -} - -/**Function************************************************************* - - Synopsis [Allocates the retiming object.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjAddFanin( Rtm_Obj_t * pObj, Rtm_Obj_t * pFanin, int fCompl ) -{ - pObj->pFanio[ 2*pObj->nFanins ] = pFanin; - pObj->pFanio[ 2*pObj->nFanins + 1 ] = NULL; - pFanin->pFanio[ 2*(pFanin->Num + pFanin->nFanouts) ] = pObj; - pFanin->pFanio[ 2*(pFanin->Num + pFanin->nFanouts) + 1 ] = pObj->pFanio + 2*pObj->nFanins + 1; - if ( pObj->nFanins == 0 ) - pObj->fCompl0 = fCompl; - else if ( pObj->nFanins == 1 ) - pObj->fCompl1 = fCompl; - else - assert( 0 ); - pObj->nFanins++; - pFanin->nFanouts++; - assert( pObj->nFanins <= pObj->Num ); - assert( pFanin->nFanouts <= pFanin->Temp ); -} - -/**Function************************************************************* - - Synopsis [Check the possibility of forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ObjCheckRetimeFwd( Rtm_Obj_t * pObj ) -{ - Rtm_Edg_t * pEdge; - int i; - Rtm_ObjForEachFaninEdge( pObj, pEdge, i ) - if ( pEdge->nLats == 0 ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Check the possibility of forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ObjCheckRetimeBwd( Rtm_Obj_t * pObj ) -{ - Rtm_Edg_t * pEdge; - int i; - Rtm_ObjForEachFanoutEdge( pObj, pEdge, i ) - if ( pEdge->nLats == 0 ) - return 0; - return 1; -} - -/**Function************************************************************* - - Synopsis [Check the possibility of forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ObjGetDegreeFwd( Rtm_Obj_t * pObj ) -{ - Rtm_Obj_t * pFanin; - int i, Degree = 0; - Rtm_ObjForEachFanin( pObj, pFanin, i ) - Degree = AIG_MAX( Degree, (int)pFanin->Num ); - return Degree + 1; -} - -/**Function************************************************************* - - Synopsis [Check the possibility of forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ObjGetDegreeBwd( Rtm_Obj_t * pObj ) -{ - Rtm_Obj_t * pFanout; - int i, Degree = 0; - Rtm_ObjForEachFanout( pObj, pFanout, i ) - Degree = AIG_MAX( Degree, (int)pFanout->Num ); - return Degree + 1; -} - -/**Function************************************************************* - - Synopsis [Performs forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjRetimeFwd( Rtm_Man_t * pRtm, Rtm_Obj_t * pObj ) -{ - Rtm_Init_t ValTotal, ValCur; - Rtm_Edg_t * pEdge; - int i; - assert( Rtm_ObjCheckRetimeFwd(pObj) ); - // extract values and compute the result - ValTotal = RTM_VAL_ONE; - Rtm_ObjForEachFaninEdge( pObj, pEdge, i ) - { - ValCur = Rtm_ObjRemFirst( pRtm, pEdge ); - ValCur = Rtm_InitNotCond( ValCur, i? pObj->fCompl1 : pObj->fCompl0 ); - ValTotal = Rtm_InitAnd( ValTotal, ValCur ); - } - // insert the result in the fanout values - Rtm_ObjForEachFanoutEdge( pObj, pEdge, i ) - Rtm_ObjAddLast( pRtm, pEdge, ValTotal ); -} - -/**Function************************************************************* - - Synopsis [Performs forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjRetimeBwd( Rtm_Man_t * pRtm, Rtm_Obj_t * pObj ) -{ - Rtm_Edg_t * pEdge; - int i; - assert( Rtm_ObjCheckRetimeBwd(pObj) ); - // extract values and compute the result - Rtm_ObjForEachFanoutEdge( pObj, pEdge, i ) - Rtm_ObjRemLast( pRtm, pEdge ); - // insert the result in the fanout values - Rtm_ObjForEachFaninEdge( pObj, pEdge, i ) - Rtm_ObjAddFirst( pRtm, pEdge, RTM_VAL_VOID ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjMarkAutoFwd_rec( Rtm_Obj_t * pObj ) -{ - Rtm_Obj_t * pFanout; - int i; - if ( pObj->fAuto ) - return; - pObj->fAuto = 1; - Rtm_ObjForEachFanout( pObj, pFanout, i ) - Rtm_ObjMarkAutoFwd_rec( pFanout ); -} - -/**Function************************************************************* - - Synopsis [Marks the nodes unreachable from the PIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ManMarkAutoFwd( Rtm_Man_t * pRtm ) -{ - Rtm_Obj_t * pObjRtm; - int i, Counter = 0; - // mark nodes reachable from the PIs - pObjRtm = Vec_PtrEntry( pRtm->vObjs, 0 ); - Rtm_ObjMarkAutoFwd_rec( pObjRtm ); - Rtm_ManForEachPi( pRtm, pObjRtm, i ) - Rtm_ObjMarkAutoFwd_rec( pObjRtm ); - // count the number of autonomous nodes - Rtm_ManForEachObj( pRtm, pObjRtm, i ) - { - pObjRtm->fAuto = !pObjRtm->fAuto; - Counter += pObjRtm->fAuto; - } - // mark the fanins of the autonomous nodes - return Counter; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Rtm_ObjMarkAutoBwd_rec( Rtm_Obj_t * pObj ) -{ - Rtm_Obj_t * pFanin; - int i; - if ( pObj->fAuto ) - return; - pObj->fAuto = 1; - Rtm_ObjForEachFanin( pObj, pFanin, i ) - Rtm_ObjMarkAutoBwd_rec( pFanin ); -} - -/**Function************************************************************* - - Synopsis [Marks the nodes unreachable from the POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Rtm_ManMarkAutoBwd( Rtm_Man_t * pRtm ) -{ - Rtm_Obj_t * pObjRtm; - int i, Counter = 0; - // mark nodes reachable from the PIs - pObjRtm = Vec_PtrEntry( pRtm->vObjs, 0 ); - pObjRtm->fAuto = 1; - Rtm_ManForEachPi( pRtm, pObjRtm, i ) - pObjRtm->fAuto = 1; - Rtm_ManForEachPo( pRtm, pObjRtm, i ) - Rtm_ObjMarkAutoBwd_rec( pObjRtm ); - // count the number of autonomous nodes - Rtm_ManForEachObj( pRtm, pObjRtm, i ) - { - pObjRtm->fAuto = !pObjRtm->fAuto; - Counter += pObjRtm->fAuto; - } - // mark the fanins of the autonomous nodes - return Counter; -} - -/**Function************************************************************* - - Synopsis [Derive retiming manager from the given AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Rtm_Man_t * Rtm_ManFromAig( Aig_Man_t * p ) -{ - Rtm_Man_t * pRtm; - Aig_Obj_t * pObj, * pObjLi, * pObjLo; - int i; - assert( Aig_ManRegNum(p) > 0 ); - assert( Aig_ManBufNum(p) == 0 ); - // allocate the manager - pRtm = Rtm_ManAlloc( p ); - // allocate objects - pObj = Aig_ManConst1(p); - pObj->pData = Rtm_ObjAlloc( pRtm, 0, pObj->nRefs ); - Aig_ManForEachPiSeq( p, pObj, i ) - { - pObj->pData = Rtm_ObjAlloc( pRtm, 0, pObj->nRefs ); - Vec_PtrPush( pRtm->vPis, pObj->pData ); - } - Aig_ManForEachPoSeq( p, pObj, i ) - { - pObj->pData = Rtm_ObjAlloc( pRtm, 1, 0 ); - Vec_PtrPush( pRtm->vPos, pObj->pData ); - } - Aig_ManForEachLoSeq( p, pObj, i ) - pObj->pData = Rtm_ObjAlloc( pRtm, 1, pObj->nRefs ); - Aig_ManForEachLiSeq( p, pObj, i ) - pObj->pData = Rtm_ObjAlloc( pRtm, 1, 1 ); - Aig_ManForEachNode( p, pObj, i ) - pObj->pData = Rtm_ObjAlloc( pRtm, 2, pObj->nRefs ); - // connect objects - Aig_ManForEachPoSeq( p, pObj, i ) - Rtm_ObjAddFanin( pObj->pData, Aig_ObjFanin0(pObj)->pData, Aig_ObjFaninC0(pObj) ); - Aig_ManForEachLiSeq( p, pObj, i ) - Rtm_ObjAddFanin( pObj->pData, Aig_ObjFanin0(pObj)->pData, Aig_ObjFaninC0(pObj) ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - Rtm_ObjAddFanin( pObjLo->pData, pObjLi->pData, 0 ); - Aig_ManForEachNode( p, pObj, i ) - { - Rtm_ObjAddFanin( pObj->pData, Aig_ObjFanin0(pObj)->pData, Aig_ObjFaninC0(pObj) ); - Rtm_ObjAddFanin( pObj->pData, Aig_ObjFanin1(pObj)->pData, Aig_ObjFaninC1(pObj) ); - } - return pRtm; -} - -/**Function************************************************************* - - Synopsis [Derive AIG manager after retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Rtm_ManToAig_rec( Aig_Man_t * pNew, Rtm_Man_t * pRtm, Rtm_Obj_t * pObjRtm, int * pLatches ) -{ - Rtm_Edg_t * pEdge; - Aig_Obj_t * pRes, * pFanin; - int k, Val; - if ( pObjRtm->pCopy ) - return pObjRtm->pCopy; - // get the inputs - pRes = Aig_ManConst1( pNew ); - Rtm_ObjForEachFaninEdge( pObjRtm, pEdge, k ) - { - if ( pEdge->nLats == 0 ) - pFanin = Rtm_ManToAig_rec( pNew, pRtm, Rtm_ObjFanin(pObjRtm, k), pLatches ); - else - { - Val = Rtm_ObjGetFirst( pRtm, pEdge ); - pFanin = Aig_ManPi( pNew, pLatches[2*pObjRtm->Id + k] + pEdge->nLats - 1 ); - pFanin = Aig_NotCond( pFanin, Val == RTM_VAL_ONE ); - } - pFanin = Aig_NotCond( pFanin, k ? pObjRtm->fCompl1 : pObjRtm->fCompl0 ); - pRes = Aig_And( pNew, pRes, pFanin ); - } - return pObjRtm->pCopy = pRes; -} - -/**Function************************************************************* - - Synopsis [Derive AIG manager after retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Rtm_ManToAig( Rtm_Man_t * pRtm ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObjNew; - Rtm_Obj_t * pObjRtm; - Rtm_Edg_t * pEdge; - int i, k, m, Val, nLatches, * pLatches; - // count latches and mark the first latch on each edge - pLatches = ALLOC( int, 2 * Vec_PtrSize(pRtm->vObjs) ); - nLatches = 0; - Rtm_ManForEachObj( pRtm, pObjRtm, i ) - Rtm_ObjForEachFaninEdge( pObjRtm, pEdge, k ) - { - pLatches[2*pObjRtm->Id + k] = Vec_PtrSize(pRtm->vPis) + nLatches; - nLatches += pEdge->nLats; - } - // create the new manager - pNew = Aig_ManStart( Vec_PtrSize(pRtm->vObjs) + nLatches ); - // create PIs/POs and latches - pObjRtm = Vec_PtrEntry( pRtm->vObjs, 0 ); - pObjRtm->pCopy = Aig_ManConst1(pNew); - Rtm_ManForEachPi( pRtm, pObjRtm, i ) - pObjRtm->pCopy = Aig_ObjCreatePi(pNew); - for ( i = 0; i < nLatches; i++ ) - Aig_ObjCreatePi(pNew); - // create internal nodes - Rtm_ManForEachObj( pRtm, pObjRtm, i ) - Rtm_ManToAig_rec( pNew, pRtm, pObjRtm, pLatches ); - // create POs - Rtm_ManForEachPo( pRtm, pObjRtm, i ) - Aig_ObjCreatePo( pNew, pObjRtm->pCopy ); - // connect latches - Rtm_ManForEachObj( pRtm, pObjRtm, i ) - Rtm_ObjForEachFaninEdge( pObjRtm, pEdge, k ) - { - if ( pEdge->nLats == 0 ) - continue; - pObjNew = Rtm_ObjFanin( pObjRtm, k )->pCopy; - for ( m = 0; m < (int)pEdge->nLats; m++ ) - { - Val = Rtm_ObjGetOne( pRtm, pEdge, pEdge->nLats - 1 - m ); - assert( Val == RTM_VAL_ZERO || Val == RTM_VAL_ONE || Val == RTM_VAL_VOID ); - pObjNew = Aig_NotCond( pObjNew, Val == RTM_VAL_ONE ); - Aig_ObjCreatePo( pNew, pObjNew ); - pObjNew = Aig_ManPi( pNew, pLatches[2*pObjRtm->Id + k] + m ); - pObjNew = Aig_NotCond( pObjNew, Val == RTM_VAL_ONE ); - } -// assert( Aig_Regular(pObjNew)->nRefs > 0 ); - } - free( pLatches ); - pNew->nRegs = nLatches; - // remove useless nodes - Aig_ManCleanup( pNew ); - if ( !Aig_ManCheck( pNew ) ) - printf( "Rtm_ManToAig: The network check has failed.\n" ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Performs forward retiming with the given limit on depth.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Rtm_ManRetime( Aig_Man_t * p, int fForward, int nStepsMax, int fVerbose ) -{ - Vec_Ptr_t * vQueue; - Aig_Man_t * pNew; - Rtm_Man_t * pRtm; - Rtm_Obj_t * pObj, * pNext; - Aig_Obj_t * pObjAig; - int i, k, nAutos, Degree, DegreeMax = 0; - int clk; - - // create the retiming manager -clk = clock(); - pRtm = Rtm_ManFromAig( p ); - // set registers - Aig_ManForEachLoSeq( p, pObjAig, i ) - Rtm_ObjAddFirst( pRtm, Rtm_ObjEdge(pObjAig->pData, 0), fForward? RTM_VAL_ZERO : RTM_VAL_VOID ); - // detect and mark the autonomous components - if ( fForward ) - nAutos = Rtm_ManMarkAutoFwd( pRtm ); - else - nAutos = Rtm_ManMarkAutoBwd( pRtm ); - if ( fVerbose ) - { - printf( "Detected %d autonomous objects. ", nAutos ); - PRT( "Time", clock() - clk ); - } - - // set the current retiming number - Rtm_ManForEachObj( pRtm, pObj, i ) - { - assert( pObj->nFanins == pObj->Num ); - assert( pObj->nFanouts == pObj->Temp ); - pObj->Num = 0; - } - -clk = clock(); - // put the LOs on the queue - vQueue = Vec_PtrAlloc( 1000 ); - if ( fForward ) - { - Aig_ManForEachLoSeq( p, pObjAig, i ) - { - pObj = pObjAig->pData; - if ( pObj->fAuto ) - continue; - pObj->fMark = 1; - Vec_PtrPush( vQueue, pObj ); - } - } - else - { - Aig_ManForEachLiSeq( p, pObjAig, i ) - { - pObj = pObjAig->pData; - if ( pObj->fAuto ) - continue; - pObj->fMark = 1; - Vec_PtrPush( vQueue, pObj ); - } - } - // perform retiming - DegreeMax = 0; - Vec_PtrForEachEntry( vQueue, pObj, i ) - { - pObj->fMark = 0; - // retime the node - if ( fForward ) - { - Rtm_ObjRetimeFwd( pRtm, pObj ); - // check if its fanouts should be retimed - Rtm_ObjForEachFanout( pObj, pNext, k ) - { - if ( pNext->fMark ) // skip aleady scheduled - continue; - if ( pNext->Type ) // skip POs - continue; - if ( !Rtm_ObjCheckRetimeFwd( pNext ) ) // skip non-retimable - continue; - Degree = Rtm_ObjGetDegreeFwd( pNext ); - DegreeMax = AIG_MAX( DegreeMax, Degree ); - if ( Degree > nStepsMax ) // skip nodes with high degree - continue; - pNext->fMark = 1; - pNext->Num = Degree; - Vec_PtrPush( vQueue, pNext ); - } - } - else - { - Rtm_ObjRetimeBwd( pRtm, pObj ); - // check if its fanouts should be retimed - Rtm_ObjForEachFanin( pObj, pNext, k ) - { - if ( pNext->fMark ) // skip aleady scheduled - continue; - if ( pNext->nFanins == 0 ) // skip PIs - continue; - if ( !Rtm_ObjCheckRetimeBwd( pNext ) ) // skip non-retimable - continue; - Degree = Rtm_ObjGetDegreeBwd( pNext ); - DegreeMax = AIG_MAX( DegreeMax, Degree ); - if ( Degree > nStepsMax ) // skip nodes with high degree - continue; - pNext->fMark = 1; - pNext->Num = Degree; - Vec_PtrPush( vQueue, pNext ); - } - } - } - - if ( fVerbose ) - { - printf( "Performed %d %s latch moves of max depth %d and max latch count %d.\n", - Vec_PtrSize(vQueue), fForward? "fwd":"bwd", DegreeMax, Rtm_ManLatchMax(pRtm) ); - printf( "Memory usage = %d. ", pRtm->nExtraCur ); - PRT( "Time", clock() - clk ); - } - Vec_PtrFree( vQueue ); - - // get the new manager - pNew = Rtm_ManToAig( pRtm ); - pNew->pName = Aig_UtilStrsav( p->pName ); - Rtm_ManFree( pRtm ); - // group the registers -clk = clock(); - pNew = Aig_ManReduceLaches( pNew, fVerbose ); - if ( fVerbose ) - { - PRT( "Register sharing time", clock() - clk ); - } - return pNew; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigRetF.c b/src/abc8/aig/aigRetF.c deleted file mode 100644 index 8ca4fba1..00000000 --- a/src/abc8/aig/aigRetF.c +++ /dev/null @@ -1,219 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigRetF.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Retiming frontier.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigRetF.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Mark the nodes reachable from the PIs in the reverse order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManRetimeMark_rec( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - if ( pObj->fMarkB ) - return 1; - if ( Aig_ObjIsPi(pObj) || Aig_ObjIsConst1(pObj) ) - return 0; - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return pObj->fMarkB; - Aig_ObjSetTravIdCurrent(p, pObj); - if ( Aig_ManRetimeMark_rec( p, Aig_ObjFanin0(pObj) ) ) - return pObj->fMarkB = 1; - if ( Aig_ObjIsNode(pObj) && Aig_ManRetimeMark_rec( p, Aig_ObjFanin1(pObj) ) ) - return pObj->fMarkB = 1; - assert( pObj->fMarkB == 0 ); - return 0; -} - -/**Function************************************************************* - - Synopsis [Mark the nodes reachable from the true PIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManRetimeMark( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pObjLi, * pObjLo; - int fChange, i; - // mark the PIs - Aig_ManForEachObj( p, pObj, i ) - assert( pObj->fMarkB == 0 ); - Aig_ManForEachPiSeq( p, pObj, i ) - pObj->fMarkB = 1; - // map registers into each other - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - assert( pObjLo->pNext == NULL ); - assert( pObjLi->pNext == NULL ); - pObjLo->pNext = pObjLi; - pObjLi->pNext = pObjLo; - } - // iterativively mark the logic reachable from PIs - fChange = 1; - while ( fChange ) - { - fChange = 0; - Aig_ManIncrementTravId( p ); - Aig_ManForEachPo( p, pObj, i ) - { - if ( pObj->fMarkB ) - continue; - if ( Aig_ManRetimeMark_rec( p, pObj ) ) - { - if ( pObj->pNext ) - pObj->pNext->fMarkB = 1; - fChange = 1; - } - } - } - // clean register mapping - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - pObjLo->pNext = pObjLi->pNext = NULL; -} - - -/**Function************************************************************* - - Synopsis [Performs forward retiming.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManRetimeFrontier( Aig_Man_t * p, int nStepsMax ) -{ - Aig_Obj_t * pObj, * pObjNew, * pObjLo, * pObjLo0, * pObjLo1, * pObjLi, * pObjLi0, * pObjLi1;//, * pObjLi0_, * pObjLi1_, * pObjLi0__, * pObjLi1__; - int i, Counter, fCompl, fChange; - assert( Aig_ManRegNum(p) > 0 ); - // remove structural hashing table - Aig_TableClear( p ); - // mark the retimable nodes - Aig_ManRetimeMark( p ); - // mark the register outputs - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - pObjLo->fMarkA = 1; - pObjLo->pNext = pObjLi; - pObjLi->pNext = pObjLo; - } - // go through the nodes and find retimable ones - Counter = 0; - fChange = 1; - while ( fChange ) - { - fChange = 0; - Aig_ManForEachNode( p, pObj, i ) - { - if ( !pObj->fMarkB ) - continue; - if ( Aig_ObjIsBuf(pObj) ) - continue; - // get the real inputs of the node (skipping the buffers) - pObjLo0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pObjLo1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) ); - if ( !Aig_Regular(pObjLo0)->fMarkA || !Aig_Regular(pObjLo1)->fMarkA ) - continue; - // remember complemented attribute - fCompl = Aig_IsComplement(pObjLo0) & Aig_IsComplement(pObjLo1); - // get the register inputs -// pObjLi0_ = Aig_Regular(pObjLo0)->pNext; -// pObjLi1_ = Aig_Regular(pObjLo1)->pNext; -// pObjLi0__ = Aig_ObjChild0(Aig_Regular(pObjLo0)->pNext); -// pObjLi1__ = Aig_ObjChild0(Aig_Regular(pObjLo1)->pNext); - pObjLi0 = Aig_NotCond( Aig_ObjChild0(Aig_Regular(pObjLo0)->pNext), Aig_IsComplement(pObjLo0) ); - pObjLi1 = Aig_NotCond( Aig_ObjChild0(Aig_Regular(pObjLo1)->pNext), Aig_IsComplement(pObjLo1) ); - // create new node - pObjNew = Aig_And( p, pObjLi0, pObjLi1 ); - pObjNew->fMarkB = 1; - // create new register - pObjLo = Aig_ObjCreatePi(p); - pObjLo->fMarkA = 1; - pObjLi = Aig_ObjCreatePo( p, Aig_NotCond(pObjNew, fCompl) ); - p->nRegs++; - pObjLo->pNext = pObjLi; - pObjLi->pNext = pObjLo; - // add the buffer - Aig_ObjDisconnect( p, pObj ); - pObj->Type = AIG_OBJ_BUF; - p->nObjs[AIG_OBJ_AND]--; - p->nObjs[AIG_OBJ_BUF]++; - Aig_ObjConnect( p, pObj, Aig_NotCond(pObjLo, fCompl), NULL ); - // create HAIG if defined - if ( p->pManHaig ) - { - // create HAIG latch - pObjLo->pHaig = Aig_ObjCreatePi( p->pManHaig ); - pObjLi->pHaig = Aig_ObjCreatePo( p->pManHaig, Aig_ObjHaig( Aig_ObjChild0(pObjLi) ) ); - // create equivalence class - assert( pObjLo->pHaig != NULL ); - assert( pObjLo->pHaig->pHaig == NULL ); - pObjLo->pHaig->pHaig = Aig_Regular(pObj->pHaig); - } - // mark the change - fChange = 1; - // check the limit - if ( ++Counter >= nStepsMax ) - { - fChange = 0; - break; - } - } - } - // clean the markings - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - pObjLo->fMarkA = 0; - pObjLo->pNext = pObjLi->pNext = NULL; - } - Aig_ManForEachObj( p, pObj, i ) - pObj->fMarkB = 0; - // remove useless registers - Aig_ManSeqCleanup( p ); - // rehash the nodes - return Aig_ManDup( p, 1 ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigScl.c b/src/abc8/aig/aigScl.c deleted file mode 100644 index 9721dd17..00000000 --- a/src/abc8/aig/aigScl.c +++ /dev/null @@ -1,399 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigScl.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Sequential cleanup.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigScl.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Remaps the manager.] - - Description [Map in the array specifies for each CI node the node that - should be used after remapping.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManRemap( Aig_Man_t * p, Vec_Ptr_t * vMap ) -{ - Aig_Man_t * pNew; - Aig_Obj_t * pObj, * pObjMapped; - int i; - // create the new manager - pNew = Aig_ManStart( Aig_ManObjNumMax(p) ); - pNew->pName = Aig_UtilStrsav( p->pName ); - pNew->nRegs = p->nRegs; - pNew->nAsserts = p->nAsserts; - if ( p->vFlopNums ) - pNew->vFlopNums = Vec_IntDup( p->vFlopNums ); - // create the PIs - Aig_ManCleanData( p ); - Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); - Aig_ManForEachPi( p, pObj, i ) - pObj->pData = Aig_ObjCreatePi(pNew); - // implement the mapping - Aig_ManForEachPi( p, pObj, i ) - { - pObjMapped = Vec_PtrEntry( vMap, i ); - pObj->pData = Aig_NotCond( Aig_Regular(pObjMapped)->pData, Aig_IsComplement(pObjMapped) ); - } - // duplicate internal nodes - Aig_ManForEachObj( p, pObj, i ) - if ( Aig_ObjIsBuf(pObj) ) - pObj->pData = Aig_ObjChild0Copy(pObj); - else if ( Aig_ObjIsNode(pObj) ) - pObj->pData = Aig_And( pNew, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) ); - // add the POs - Aig_ManForEachPo( p, pObj, i ) - Aig_ObjCreatePo( pNew, Aig_ObjChild0Copy(pObj) ); - assert( Aig_ManNodeNum(p) >= Aig_ManNodeNum(pNew) ); - // check the resulting network - if ( !Aig_ManCheck(pNew) ) - printf( "Aig_ManDup(): The check has failed.\n" ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManSeqCleanup_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - return; - Aig_ObjSetTravIdCurrent(p, pObj); - // collect latch input corresponding to unmarked PI (latch output) - if ( Aig_ObjIsPi(pObj) ) - { - Vec_PtrPush( vNodes, pObj->pNext ); - return; - } - if ( Aig_ObjIsPo(pObj) || Aig_ObjIsBuf(pObj) ) - { - Aig_ManSeqCleanup_rec( p, Aig_ObjFanin0(pObj), vNodes ); - return; - } - assert( Aig_ObjIsNode(pObj) ); - Aig_ManSeqCleanup_rec( p, Aig_ObjFanin0(pObj), vNodes ); - Aig_ManSeqCleanup_rec( p, Aig_ObjFanin1(pObj), vNodes ); -} - -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManSeqCleanup( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes, * vCis, * vCos; - Aig_Obj_t * pObj, * pObjLi, * pObjLo; - int i, nTruePis, nTruePos; -// assert( Aig_ManBufNum(p) == 0 ); - - // mark the PIs - Aig_ManIncrementTravId( p ); - Aig_ObjSetTravIdCurrent( p, Aig_ManConst1(p) ); - Aig_ManForEachPiSeq( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - - // prepare to collect nodes reachable from POs - vNodes = Vec_PtrAlloc( 100 ); - Aig_ManForEachPoSeq( p, pObj, i ) - Vec_PtrPush( vNodes, pObj ); - - // remember latch inputs in latch outputs - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - pObjLo->pNext = pObjLi; - // mark the nodes reachable from these nodes - Vec_PtrForEachEntry( vNodes, pObj, i ) - Aig_ManSeqCleanup_rec( p, pObj, vNodes ); - assert( Vec_PtrSize(vNodes) <= Aig_ManPoNum(p) ); - // clean latch output pointers - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - pObjLo->pNext = NULL; - - // if some latches are removed, update PIs/POs - if ( Vec_PtrSize(vNodes) < Aig_ManPoNum(p) ) - { - if ( p->vFlopNums ) - { - int nTruePos = Aig_ManPoNum(p)-Aig_ManRegNum(p); - // remember numbers of flops in the flops - Aig_ManForEachLiSeq( p, pObj, i ) - pObj->pNext = (Aig_Obj_t *)(long)Vec_IntEntry( p->vFlopNums, i - nTruePos ); - // reset the flop numbers - Vec_PtrForEachEntryStart( vNodes, pObj, i, nTruePos ) - Vec_IntWriteEntry( p->vFlopNums, i - nTruePos, (int)(long)pObj->pNext ); - Vec_IntShrink( p->vFlopNums, Vec_PtrSize(vNodes) - nTruePos ); - // clean the next pointer - Aig_ManForEachLiSeq( p, pObj, i ) - pObj->pNext = NULL; - } - // collect new CIs/COs - vCis = Vec_PtrAlloc( Aig_ManPiNum(p) ); - Aig_ManForEachPi( p, pObj, i ) - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - Vec_PtrPush( vCis, pObj ); - else - { - Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL ); -// Aig_ManRecycleMemory( p, pObj ); - } - vCos = Vec_PtrAlloc( Aig_ManPoNum(p) ); - Aig_ManForEachPo( p, pObj, i ) - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - Vec_PtrPush( vCos, pObj ); - else - { - Aig_ObjDisconnect( p, pObj ); - Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL ); -// Aig_ManRecycleMemory( p, pObj ); - } - // remember the number of true PIs/POs - nTruePis = Aig_ManPiNum(p) - Aig_ManRegNum(p); - nTruePos = Aig_ManPoNum(p) - Aig_ManRegNum(p); - // set the new number of registers - p->nRegs -= Aig_ManPoNum(p) - Vec_PtrSize(vNodes); - // create new PIs/POs - assert( Vec_PtrSize(vCis) == nTruePis + p->nRegs ); - assert( Vec_PtrSize(vCos) == nTruePos + p->nRegs ); - Vec_PtrFree( p->vPis ); p->vPis = vCis; - Vec_PtrFree( p->vPos ); p->vPos = vCos; - p->nObjs[AIG_OBJ_PI] = Vec_PtrSize( p->vPis ); - p->nObjs[AIG_OBJ_PO] = Vec_PtrSize( p->vPos ); - - } - Vec_PtrFree( vNodes ); - // remove dangling nodes - return Aig_ManCleanup( p ); -} - -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManCountMergeRegs( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pFanin; - int i, Counter = 0, Const0 = 0, Const1 = 0; - Aig_ManIncrementTravId( p ); - Aig_ManForEachLiSeq( p, pObj, i ) - { - pFanin = Aig_ObjFanin0(pObj); - if ( Aig_ObjIsConst1(pFanin) ) - { - if ( Aig_ObjFaninC0(pObj) ) - Const0++; - else - Const1++; - } - if ( Aig_ObjIsTravIdCurrent(p, pFanin) ) - continue; - Aig_ObjSetTravIdCurrent(p, pFanin); - Counter++; - } - printf( "Regs = %d. Fanins = %d. Const0 = %d. Const1 = %d.\n", - Aig_ManRegNum(p), Counter, Const0, Const1 ); - return 0; -} - - -/**Function************************************************************* - - Synopsis [Checks how many latches can be reduced.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManReduceLachesCount( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pFanin; - int i, Counter = 0, Diffs = 0; - assert( Aig_ManRegNum(p) > 0 ); - Aig_ManForEachObj( p, pObj, i ) - assert( !pObj->fMarkA && !pObj->fMarkB ); - Aig_ManForEachLiSeq( p, pObj, i ) - { - pFanin = Aig_ObjFanin0(pObj); - if ( Aig_ObjFaninC0(pObj) ) - { - if ( pFanin->fMarkB ) - Counter++; - else - pFanin->fMarkB = 1; - } - else - { - if ( pFanin->fMarkA ) - Counter++; - else - pFanin->fMarkA = 1; - } - } - // count fanins that have both attributes - Aig_ManForEachLiSeq( p, pObj, i ) - { - pFanin = Aig_ObjFanin0(pObj); - Diffs += pFanin->fMarkA && pFanin->fMarkB; - pFanin->fMarkA = pFanin->fMarkB = 0; - } -// printf( "Diffs = %d.\n", Diffs ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Reduces the latches.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManReduceLachesOnce( Aig_Man_t * p ) -{ - Vec_Ptr_t * vMap; - Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pFanin; - int * pMapping, i; - // start mapping by adding the true PIs - vMap = Vec_PtrAlloc( Aig_ManPiNum(p) ); - Aig_ManForEachPiSeq( p, pObj, i ) - Vec_PtrPush( vMap, pObj ); - // create mapping of fanin nodes into the corresponding latch outputs - pMapping = ALLOC( int, 2 * Aig_ManObjNumMax(p) ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - pFanin = Aig_ObjFanin0(pObjLi); - if ( Aig_ObjFaninC0(pObjLi) ) - { - if ( pFanin->fMarkB ) - { - Vec_PtrPush( vMap, Aig_ManLo(p, pMapping[2*pFanin->Id + 1]) ); - } - else - { - pFanin->fMarkB = 1; - pMapping[2*pFanin->Id + 1] = i; - Vec_PtrPush( vMap, pObjLo ); - } - } - else - { - if ( pFanin->fMarkA ) - { - Vec_PtrPush( vMap, Aig_ManLo(p, pMapping[2*pFanin->Id]) ); - } - else - { - pFanin->fMarkA = 1; - pMapping[2*pFanin->Id] = i; - Vec_PtrPush( vMap, pObjLo ); - } - } - } - free( pMapping ); - Aig_ManForEachLiSeq( p, pObj, i ) - { - pFanin = Aig_ObjFanin0(pObj); - pFanin->fMarkA = pFanin->fMarkB = 0; - } - return vMap; -} - -/**Function************************************************************* - - Synopsis [Reduces the latches.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManReduceLaches( Aig_Man_t * p, int fVerbose ) -{ - Aig_Man_t * pTemp; - Vec_Ptr_t * vMap; - int nSaved, nCur; - for ( nSaved = 0; (nCur = Aig_ManReduceLachesCount(p)); nSaved += nCur ) - { - if ( fVerbose ) - { - printf( "Saved = %5d. ", nCur ); - printf( "RBeg = %5d. NBeg = %6d. ", Aig_ManRegNum(p), Aig_ManNodeNum(p) ); - } - vMap = Aig_ManReduceLachesOnce( p ); - p = Aig_ManRemap( pTemp = p, vMap ); - Aig_ManStop( pTemp ); - Vec_PtrFree( vMap ); - Aig_ManSeqCleanup( p ); - if ( fVerbose ) - { - printf( "REnd = %5d. NEnd = %6d. ", Aig_ManRegNum(p), Aig_ManNodeNum(p) ); - printf( "\n" ); - } - if ( p->nRegs == 0 ) - break; - } - return p; -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigSeq.c b/src/abc8/aig/aigSeq.c deleted file mode 100644 index daafeab1..00000000 --- a/src/abc8/aig/aigSeq.c +++ /dev/null @@ -1,502 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigSeq.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Sequential strashing.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigSeq.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Converts combinational AIG manager into a sequential one.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManSeqStrashConvert( Aig_Man_t * p, int nLatches, int * pInits ) -{ - Aig_Obj_t * pObjLi, * pObjLo, * pLatch; - int i; - assert( Vec_PtrSize( p->vBufs ) == 0 ); - // collect the POs to be converted into latches - for ( i = 0; i < nLatches; i++ ) - { - // get the corresponding PI/PO pair - pObjLi = Aig_ManPo( p, Aig_ManPoNum(p) - nLatches + i ); - pObjLo = Aig_ManPi( p, Aig_ManPiNum(p) - nLatches + i ); - // create latch - pLatch = Aig_Latch( p, Aig_ObjChild0(pObjLi), pInits? pInits[i] : 0 ); - // recycle the old PO object - Aig_ObjDisconnect( p, pObjLi ); - Vec_PtrWriteEntry( p->vObjs, pObjLi->Id, NULL ); - Aig_ManRecycleMemory( p, pObjLi ); - // convert the corresponding PI to be a buffer and connect it to the latch - pObjLo->Type = AIG_OBJ_BUF; - Aig_ObjConnect( p, pObjLo, pLatch, NULL ); - // save the buffer -// Vec_PtrPush( p->vBufs, pObjLo ); - } - // shrink the arrays - Vec_PtrShrink( p->vPis, Aig_ManPiNum(p) - nLatches ); - Vec_PtrShrink( p->vPos, Aig_ManPoNum(p) - nLatches ); - // update the counters of different objects - p->nObjs[AIG_OBJ_PI] -= nLatches; - p->nObjs[AIG_OBJ_PO] -= nLatches; - p->nObjs[AIG_OBJ_BUF] += nLatches; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDfsSeq_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( pObj == NULL ) - return; - if ( Aig_ObjIsTravIdCurrent( p, pObj ) ) - return; - Aig_ObjSetTravIdCurrent( p, pObj ); - if ( Aig_ObjIsPi(pObj) || Aig_ObjIsConst1(pObj) ) - return; - Aig_ManDfsSeq_rec( p, Aig_ObjFanin0(pObj), vNodes ); - Aig_ManDfsSeq_rec( p, Aig_ObjFanin1(pObj), vNodes ); -// if ( (Aig_ObjFanin0(pObj) == NULL || Aig_ObjIsBuf(Aig_ObjFanin0(pObj))) && -// (Aig_ObjFanin1(pObj) == NULL || Aig_ObjIsBuf(Aig_ObjFanin1(pObj))) ) - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsSeq( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - Aig_ManIncrementTravId( p ); - vNodes = Vec_PtrAlloc( Aig_ManNodeNum(p) ); - Aig_ManForEachPo( p, pObj, i ) - Aig_ManDfsSeq_rec( p, Aig_ObjFanin0(pObj), vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDfsUnreach_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - assert( !Aig_IsComplement(pObj) ); - if ( pObj == NULL ) - return; - if ( Aig_ObjIsTravIdPrevious(p, pObj) || Aig_ObjIsTravIdCurrent(p, pObj) ) - return; - Aig_ObjSetTravIdPrevious( p, pObj ); // assume unknown - Aig_ManDfsUnreach_rec( p, Aig_ObjFanin0(pObj), vNodes ); - Aig_ManDfsUnreach_rec( p, Aig_ObjFanin1(pObj), vNodes ); - if ( Aig_ObjIsTravIdPrevious(p, Aig_ObjFanin0(pObj)) && - (Aig_ObjFanin1(pObj) == NULL || Aig_ObjIsTravIdPrevious(p, Aig_ObjFanin1(pObj))) ) - Vec_PtrPush( vNodes, pObj ); - else - Aig_ObjSetTravIdCurrent( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes unreachable from PIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManDfsUnreach( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj, * pFanin; - int i, k;//, RetValue; - // collect unreachable nodes - Aig_ManIncrementTravId( p ); - Aig_ManIncrementTravId( p ); - // mark the constant and PIs - Aig_ObjSetTravIdPrevious( p, Aig_ManConst1(p) ); - Aig_ManForEachPi( p, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - // curr marks visited nodes reachable from PIs - // prev marks visited nodes unreachable or unknown - - // collect the unreachable nodes - vNodes = Vec_PtrAlloc( 32 ); - Aig_ManForEachPo( p, pObj, i ) - Aig_ManDfsUnreach_rec( p, Aig_ObjFanin0(pObj), vNodes ); - - // refine resulting nodes - do - { - k = 0; - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - assert( Aig_ObjIsTravIdPrevious(p, pObj) ); - if ( Aig_ObjIsLatch(pObj) || Aig_ObjIsBuf(pObj) ) - { - pFanin = Aig_ObjFanin0(pObj); - assert( Aig_ObjIsTravIdPrevious(p, pFanin) || Aig_ObjIsTravIdCurrent(p, pFanin) ); - if ( Aig_ObjIsTravIdCurrent(p, pFanin) ) - { - Aig_ObjSetTravIdCurrent( p, pObj ); - continue; - } - } - else // AND gate - { - assert( Aig_ObjIsNode(pObj) ); - pFanin = Aig_ObjFanin0(pObj); - assert( Aig_ObjIsTravIdPrevious(p, pFanin) || Aig_ObjIsTravIdCurrent(p, pFanin) ); - if ( Aig_ObjIsTravIdCurrent(p, pFanin) ) - { - Aig_ObjSetTravIdCurrent( p, pObj ); - continue; - } - pFanin = Aig_ObjFanin1(pObj); - assert( Aig_ObjIsTravIdPrevious(p, pFanin) || Aig_ObjIsTravIdCurrent(p, pFanin) ); - if ( Aig_ObjIsTravIdCurrent(p, pFanin) ) - { - Aig_ObjSetTravIdCurrent( p, pObj ); - continue; - } - } - // write it back - Vec_PtrWriteEntry( vNodes, k++, pObj ); - } - Vec_PtrShrink( vNodes, k ); - } - while ( k < i ); - -// if ( Vec_PtrSize(vNodes) > 0 ) -// printf( "Found %d unreachable.\n", Vec_PtrSize(vNodes) ); - return vNodes; - -/* - // the resulting array contains all unreachable nodes except const 1 - if ( Vec_PtrSize(vNodes) == 0 ) - { - Vec_PtrFree( vNodes ); - return 0; - } - RetValue = Vec_PtrSize(vNodes); - - // mark these nodes - Aig_ManIncrementTravId( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - Aig_ObjSetTravIdCurrent( p, pObj ); - Vec_PtrFree( vNodes ); - return RetValue; -*/ -} - - -/**Function************************************************************* - - Synopsis [Removes nodes that do not fanout into POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManRemoveUnmarked( Aig_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i, RetValue; - // collect unmarked nodes - vNodes = Vec_PtrAlloc( 100 ); - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjIsTerm(pObj) ) - continue; - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - continue; -//Aig_ObjPrintVerbose( pObj, 0 ); - Aig_ObjDisconnect( p, pObj ); - Vec_PtrPush( vNodes, pObj ); - } - if ( Vec_PtrSize(vNodes) == 0 ) - { - Vec_PtrFree( vNodes ); - return 0; - } - // remove the dangling objects - RetValue = Vec_PtrSize(vNodes); - Vec_PtrForEachEntry( vNodes, pObj, i ) - Aig_ObjDelete( p, pObj ); -// printf( "Removed %d dangling.\n", Vec_PtrSize(vNodes) ); - Vec_PtrFree( vNodes ); - return RetValue; -} - -/**Function************************************************************* - - Synopsis [Rehashes the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManSeqRehashOne( Aig_Man_t * p, Vec_Ptr_t * vNodes, Vec_Ptr_t * vUnreach ) -{ - Aig_Obj_t * pObj, * pObjNew, * pFanin0, * pFanin1; - int i, RetValue = 0, Counter = 0;//, Counter2 = 0; - - // mark the unreachable nodes - Aig_ManIncrementTravId( p ); - Vec_PtrForEachEntry( vUnreach, pObj, i ) - Aig_ObjSetTravIdCurrent(p, pObj); -/* - // count the number of unreachable object connections - // that is the number of unreachable objects connected to main objects - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - continue; - - pFanin0 = Aig_ObjFanin0(pObj); - if ( pFanin0 == NULL ) - continue; - if ( Aig_ObjIsTravIdCurrent(p, pFanin0) ) - pFanin0->fMarkA = 1; - - pFanin1 = Aig_ObjFanin1(pObj); - if ( pFanin1 == NULL ) - continue; - if ( Aig_ObjIsTravIdCurrent(p, pFanin1) ) - pFanin1->fMarkA = 1; - } - - // count the objects - Aig_ManForEachObj( p, pObj, i ) - Counter2 += pObj->fMarkA, pObj->fMarkA = 0; - printf( "Connections = %d.\n", Counter2 ); -*/ - - // go through the nodes while skipping unreachable - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - // skip nodes unreachable from the PIs - if ( Aig_ObjIsTravIdCurrent(p, pObj) ) - continue; - // process the node - if ( Aig_ObjIsPo(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) ) - continue; - pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - Aig_ObjPatchFanin0( p, pObj, pFanin0 ); - continue; - } - if ( Aig_ObjIsLatch(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) ) - continue; - pObjNew = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pObjNew = Aig_Latch( p, pObjNew, 0 ); - Aig_ObjReplace( p, pObj, pObjNew, 1, 0 ); - RetValue = 1; - Counter++; - continue; - } - if ( Aig_ObjIsNode(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) && !Aig_ObjIsBuf(Aig_ObjFanin1(pObj)) ) - continue; - pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pFanin1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) ); - pObjNew = Aig_And( p, pFanin0, pFanin1 ); - Aig_ObjReplace( p, pObj, pObjNew, 1, 0 ); - RetValue = 1; - Counter++; - continue; - } - } -// printf( "Rehashings = %d.\n", Counter++ ); - return RetValue; -} - -/**Function************************************************************* - - Synopsis [If AIG contains buffers, this procedure removes them.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManRemoveBuffers( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj, * pObjNew, * pFanin0, * pFanin1; - int i; - if ( Aig_ManBufNum(p) == 0 ) - return; - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjIsPo(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) ) - continue; - pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - Aig_ObjPatchFanin0( p, pObj, pFanin0 ); - } - else if ( Aig_ObjIsLatch(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) ) - continue; - pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pObjNew = Aig_Latch( p, pFanin0, 0 ); - Aig_ObjReplace( p, pObj, pObjNew, 0, 0 ); - } - else if ( Aig_ObjIsAnd(pObj) ) - { - if ( !Aig_ObjIsBuf(Aig_ObjFanin0(pObj)) && !Aig_ObjIsBuf(Aig_ObjFanin1(pObj)) ) - continue; - pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); - pFanin1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) ); - pObjNew = Aig_And( p, pFanin0, pFanin1 ); - Aig_ObjReplace( p, pObj, pObjNew, 0, 0 ); - } - } - assert( Aig_ManBufNum(p) == 0 ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManSeqStrash( Aig_Man_t * p, int nLatches, int * pInits ) -{ - Vec_Ptr_t * vNodes, * vUnreach; -// Aig_Obj_t * pObj, * pFanin; -// int i; - int Iter, RetValue = 1; - - // create latches out of the additional PI/PO pairs - Aig_ManSeqStrashConvert( p, nLatches, pInits ); - - // iteratively rehash the network - for ( Iter = 0; RetValue; Iter++ ) - { -// Aig_ManPrintStats( p ); -/* - Aig_ManForEachObj( p, pObj, i ) - { - assert( pObj->Type > 0 ); - pFanin = Aig_ObjFanin0(pObj); - assert( pFanin == NULL || pFanin->Type > 0 ); - pFanin = Aig_ObjFanin1(pObj); - assert( pFanin == NULL || pFanin->Type > 0 ); - } -*/ - // mark nodes unreachable from the PIs - vUnreach = Aig_ManDfsUnreach( p ); - if ( Iter == 0 && Vec_PtrSize(vUnreach) > 0 ) - printf( "Unreachable objects = %d.\n", Vec_PtrSize(vUnreach) ); - // collect nodes reachable from the POs - vNodes = Aig_ManDfsSeq( p ); - // remove nodes unreachable from the POs - if ( Iter == 0 ) - Aig_ManRemoveUnmarked( p ); - // continue rehashing as long as there are changes - RetValue = Aig_ManSeqRehashOne( p, vNodes, vUnreach ); - Vec_PtrFree( vNodes ); - Vec_PtrFree( vUnreach ); - } - - // perform the final cleanup - Aig_ManIncrementTravId( p ); - vNodes = Aig_ManDfsSeq( p ); - Aig_ManRemoveUnmarked( p ); - Vec_PtrFree( vNodes ); - // remove buffers if they are left -// Aig_ManRemoveBuffers( p ); - - // clean up - if ( !Aig_ManCheck( p ) ) - { - printf( "Aig_ManSeqStrash: The network check has failed.\n" ); - return 0; - } - return 1; - -} - - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigShow.c b/src/abc8/aig/aigShow.c deleted file mode 100644 index 96b0e37f..00000000 --- a/src/abc8/aig/aigShow.c +++ /dev/null @@ -1,356 +0,0 @@ -/**CFile**************************************************************** - - FileName [ivyShow.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [And-Inverter Graph package.] - - Synopsis [Visualization of HAIG.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - May 11, 2006.] - - Revision [$Id: ivyShow.c,v 1.00 2006/05/11 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Writes the graph structure of AIG for DOT.] - - Description [Useful for graph visualization using tools such as GraphViz: - http://www.graphviz.org/] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_WriteDotAig( Aig_Man_t * pMan, char * pFileName, int fHaig, Vec_Ptr_t * vBold ) -{ - FILE * pFile; - Aig_Obj_t * pNode;//, * pTemp, * pPrev; - int LevelMax, Level, i; - - if ( Aig_ManNodeNum(pMan) > 200 ) - { - fprintf( stdout, "Cannot visualize AIG with more than 200 nodes.\n" ); - return; - } - if ( (pFile = fopen( pFileName, "w" )) == NULL ) - { - fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", pFileName ); - return; - } - - // mark the nodes - if ( vBold ) - Vec_PtrForEachEntry( vBold, pNode, i ) - pNode->fMarkB = 1; - - // compute levels -// LevelMax = 1 + Aig_ManSetLevels( pMan, fHaig ); - LevelMax = 1 + Aig_ManLevels( pMan ); - Aig_ManForEachPo( pMan, pNode, i ) - pNode->Level = LevelMax; - - // write the DOT header - fprintf( pFile, "# %s\n", "AIG structure generated by IVY package" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "digraph AIG {\n" ); - fprintf( pFile, "size = \"7.5,10\";\n" ); -// fprintf( pFile, "ranksep = 0.5;\n" ); -// fprintf( pFile, "nodesep = 0.5;\n" ); - fprintf( pFile, "center = true;\n" ); -// fprintf( pFile, "orientation = landscape;\n" ); -// fprintf( pFile, "edge [fontsize = 10];\n" ); -// fprintf( pFile, "edge [dir = none];\n" ); - fprintf( pFile, "edge [dir = back];\n" ); - fprintf( pFile, "\n" ); - - // labels on the left of the picture - fprintf( pFile, "{\n" ); - fprintf( pFile, " node [shape = plaintext];\n" ); - fprintf( pFile, " edge [style = invis];\n" ); - fprintf( pFile, " LevelTitle1 [label=\"\"];\n" ); - fprintf( pFile, " LevelTitle2 [label=\"\"];\n" ); - // generate node names with labels - for ( Level = LevelMax; Level >= 0; Level-- ) - { - // the visible node name - fprintf( pFile, " Level%d", Level ); - fprintf( pFile, " [label = " ); - // label name - fprintf( pFile, "\"" ); - fprintf( pFile, "\"" ); - fprintf( pFile, "];\n" ); - } - - // genetate the sequence of visible/invisible nodes to mark levels - fprintf( pFile, " LevelTitle1 -> LevelTitle2 ->" ); - for ( Level = LevelMax; Level >= 0; Level-- ) - { - // the visible node name - fprintf( pFile, " Level%d", Level ); - // the connector - if ( Level != 0 ) - fprintf( pFile, " ->" ); - else - fprintf( pFile, ";" ); - } - fprintf( pFile, "\n" ); - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - - // generate title box on top - fprintf( pFile, "{\n" ); - fprintf( pFile, " rank = same;\n" ); - fprintf( pFile, " LevelTitle1;\n" ); - fprintf( pFile, " title1 [shape=plaintext,\n" ); - fprintf( pFile, " fontsize=20,\n" ); - fprintf( pFile, " fontname = \"Times-Roman\",\n" ); - fprintf( pFile, " label=\"" ); - fprintf( pFile, "%s", "AIG structure visualized by ABC" ); - fprintf( pFile, "\\n" ); - fprintf( pFile, "Benchmark \\\"%s\\\". ", "aig" ); -// fprintf( pFile, "Time was %s. ", Extra_TimeStamp() ); - fprintf( pFile, "\"\n" ); - fprintf( pFile, " ];\n" ); - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - - // generate statistics box - fprintf( pFile, "{\n" ); - fprintf( pFile, " rank = same;\n" ); - fprintf( pFile, " LevelTitle2;\n" ); - fprintf( pFile, " title2 [shape=plaintext,\n" ); - fprintf( pFile, " fontsize=18,\n" ); - fprintf( pFile, " fontname = \"Times-Roman\",\n" ); - fprintf( pFile, " label=\"" ); - fprintf( pFile, "The set contains %d logic nodes and spans %d levels.", Aig_ManNodeNum(pMan), LevelMax ); - fprintf( pFile, "\\n" ); - fprintf( pFile, "\"\n" ); - fprintf( pFile, " ];\n" ); - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - - // generate the COs - fprintf( pFile, "{\n" ); - fprintf( pFile, " rank = same;\n" ); - // the labeling node of this level - fprintf( pFile, " Level%d;\n", LevelMax ); - // generate the CO nodes - Aig_ManForEachPo( pMan, pNode, i ) - { -/* - if ( fHaig || pNode->pEquiv == NULL ) - fprintf( pFile, " Node%d%s [label = \"%d%s\"", pNode->Id, - (Aig_ObjIsLatch(pNode)? "_in":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") ); - else - fprintf( pFile, " Node%d%s [label = \"%d%s(%d%s)\"", pNode->Id, - (Aig_ObjIsLatch(pNode)? "_in":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":""), - Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); -*/ - fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); - - fprintf( pFile, ", shape = %s", (Aig_ObjIsLatch(pNode)? "box":"invtriangle") ); - fprintf( pFile, ", color = coral, fillcolor = coral" ); - fprintf( pFile, "];\n" ); - } - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - - // generate nodes of each rank - for ( Level = LevelMax - 1; Level > 0; Level-- ) - { - fprintf( pFile, "{\n" ); - fprintf( pFile, " rank = same;\n" ); - // the labeling node of this level - fprintf( pFile, " Level%d;\n", Level ); - Aig_ManForEachObj( pMan, pNode, i ) - { - if ( (int)pNode->Level != Level ) - continue; -/* - if ( fHaig || pNode->pEquiv == NULL ) - fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); - else - fprintf( pFile, " Node%d [label = \"%d(%d%s)\"", pNode->Id, pNode->Id, - Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); -*/ - fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); - - fprintf( pFile, ", shape = ellipse" ); - if ( vBold && pNode->fMarkB ) - fprintf( pFile, ", style = filled" ); - fprintf( pFile, "];\n" ); - } - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - } - - // generate the CI nodes - fprintf( pFile, "{\n" ); - fprintf( pFile, " rank = same;\n" ); - // the labeling node of this level - fprintf( pFile, " Level%d;\n", 0 ); - // generate constant node - if ( Aig_ObjRefs(Aig_ManConst1(pMan)) > 0 ) - { - pNode = Aig_ManConst1(pMan); - // check if the costant node is present - fprintf( pFile, " Node%d [label = \"Const1\"", pNode->Id ); - fprintf( pFile, ", shape = ellipse" ); - fprintf( pFile, ", color = coral, fillcolor = coral" ); - fprintf( pFile, "];\n" ); - } - // generate the CI nodes - Aig_ManForEachPi( pMan, pNode, i ) - { -/* - if ( fHaig || pNode->pEquiv == NULL ) - fprintf( pFile, " Node%d%s [label = \"%d%s\"", pNode->Id, - (Aig_ObjIsLatch(pNode)? "_out":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":"") ); - else - fprintf( pFile, " Node%d%s [label = \"%d%s(%d%s)\"", pNode->Id, - (Aig_ObjIsLatch(pNode)? "_out":""), pNode->Id, (Aig_ObjIsLatch(pNode)? "_out":""), - Aig_Regular(pNode->pEquiv)->Id, Aig_IsComplement(pNode->pEquiv)? "\'":"" ); -*/ - fprintf( pFile, " Node%d [label = \"%d\"", pNode->Id, pNode->Id ); - - fprintf( pFile, ", shape = %s", (Aig_ObjIsLatch(pNode)? "box":"triangle") ); - fprintf( pFile, ", color = coral, fillcolor = coral" ); - fprintf( pFile, "];\n" ); - } - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - - // generate invisible edges from the square down - fprintf( pFile, "title1 -> title2 [style = invis];\n" ); - Aig_ManForEachPo( pMan, pNode, i ) - fprintf( pFile, "title2 -> Node%d%s [style = invis];\n", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") ); - - // generate edges - Aig_ManForEachObj( pMan, pNode, i ) - { - if ( !Aig_ObjIsNode(pNode) && !Aig_ObjIsPo(pNode) && !Aig_ObjIsBuf(pNode) ) - continue; - // generate the edge from this node to the next - fprintf( pFile, "Node%d%s", pNode->Id, (Aig_ObjIsLatch(pNode)? "_in":"") ); - fprintf( pFile, " -> " ); - fprintf( pFile, "Node%d%s", Aig_ObjFaninId0(pNode), (Aig_ObjIsLatch(Aig_ObjFanin0(pNode))? "_out":"") ); - fprintf( pFile, " [" ); - fprintf( pFile, "style = %s", Aig_ObjFaninC0(pNode)? "dotted" : "bold" ); -// if ( Aig_NtkIsSeq(pNode->pMan) && Seq_ObjFaninL0(pNode) > 0 ) -// fprintf( pFile, ", label = \"%s\"", Seq_ObjFaninGetInitPrintable(pNode,0) ); - fprintf( pFile, "]" ); - fprintf( pFile, ";\n" ); - if ( !Aig_ObjIsNode(pNode) ) - continue; - // generate the edge from this node to the next - fprintf( pFile, "Node%d", pNode->Id ); - fprintf( pFile, " -> " ); - fprintf( pFile, "Node%d%s", Aig_ObjFaninId1(pNode), (Aig_ObjIsLatch(Aig_ObjFanin1(pNode))? "_out":"") ); - fprintf( pFile, " [" ); - fprintf( pFile, "style = %s", Aig_ObjFaninC1(pNode)? "dotted" : "bold" ); -// if ( Aig_NtkIsSeq(pNode->pMan) && Seq_ObjFaninL1(pNode) > 0 ) -// fprintf( pFile, ", label = \"%s\"", Seq_ObjFaninGetInitPrintable(pNode,1) ); - fprintf( pFile, "]" ); - fprintf( pFile, ";\n" ); -/* - // generate the edges between the equivalent nodes - if ( fHaig && pNode->pEquiv && Aig_ObjRefs(pNode) > 0 ) - { - pPrev = pNode; - for ( pTemp = pNode->pEquiv; pTemp != pNode; pTemp = Aig_Regular(pTemp->pEquiv) ) - { - fprintf( pFile, "Node%d", pPrev->Id ); - fprintf( pFile, " -> " ); - fprintf( pFile, "Node%d", pTemp->Id ); - fprintf( pFile, " [style = %s]", Aig_IsComplement(pTemp->pEquiv)? "dotted" : "bold" ); - fprintf( pFile, ";\n" ); - pPrev = pTemp; - } - // connect the last node with the first - fprintf( pFile, "Node%d", pPrev->Id ); - fprintf( pFile, " -> " ); - fprintf( pFile, "Node%d", pNode->Id ); - fprintf( pFile, " [style = %s]", Aig_IsComplement(pPrev->pEquiv)? "dotted" : "bold" ); - fprintf( pFile, ";\n" ); - } -*/ - } - - fprintf( pFile, "}" ); - fprintf( pFile, "\n" ); - fprintf( pFile, "\n" ); - fclose( pFile ); - - // unmark nodes - if ( vBold ) - Vec_PtrForEachEntry( vBold, pNode, i ) - pNode->fMarkB = 0; - - Aig_ManForEachPo( pMan, pNode, i ) - pNode->Level = Aig_ObjFanin0(pNode)->Level; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManShow( Aig_Man_t * pMan, int fHaig, Vec_Ptr_t * vBold ) -{ - extern void Abc_ShowFile( char * FileNameDot ); - static Counter = 0; - char FileNameDot[200]; - FILE * pFile; - // create the file name -// Aig_ShowGetFileName( pMan->pName, FileNameDot ); - sprintf( FileNameDot, "temp%02d.dot", Counter++ ); - // check that the file can be opened - if ( (pFile = fopen( FileNameDot, "w" )) == NULL ) - { - fprintf( stdout, "Cannot open the intermediate file \"%s\".\n", FileNameDot ); - return; - } - fclose( pFile ); - // generate the file - Aig_WriteDotAig( pMan, FileNameDot, fHaig, vBold ); - // visualize the file - Abc_ShowFile( FileNameDot ); -} - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigTable.c b/src/abc8/aig/aigTable.c deleted file mode 100644 index 357b63c3..00000000 --- a/src/abc8/aig/aigTable.c +++ /dev/null @@ -1,289 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigTable.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Structural hashing table.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigTable.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// hashing the node -static unsigned long Aig_Hash( Aig_Obj_t * pObj, int TableSize ) -{ - unsigned long Key = Aig_ObjIsExor(pObj) * 1699; - Key ^= Aig_ObjFanin0(pObj)->Id * 7937; - Key ^= Aig_ObjFanin1(pObj)->Id * 2971; - Key ^= Aig_ObjFaninC0(pObj) * 911; - Key ^= Aig_ObjFaninC1(pObj) * 353; - return Key % TableSize; -} - -// returns the place where this node is stored (or should be stored) -static Aig_Obj_t ** Aig_TableFind( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t ** ppEntry; - if ( Aig_ObjIsLatch(pObj) ) - { - assert( Aig_ObjChild0(pObj) && Aig_ObjChild1(pObj) == NULL ); - } - else - { - assert( Aig_ObjChild0(pObj) && Aig_ObjChild1(pObj) ); - assert( Aig_ObjFanin0(pObj)->Id < Aig_ObjFanin1(pObj)->Id ); - } - for ( ppEntry = p->pTable + Aig_Hash(pObj, p->nTableSize); *ppEntry; ppEntry = &(*ppEntry)->pNext ) - if ( *ppEntry == pObj ) - return ppEntry; - assert( *ppEntry == NULL ); - return ppEntry; -} - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Resizes the table.] - - Description [Typically this procedure should not be called.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TableResize( Aig_Man_t * p ) -{ - Aig_Obj_t * pEntry, * pNext; - Aig_Obj_t ** pTableOld, ** ppPlace; - int nTableSizeOld, Counter, i, clk; -clk = clock(); - // save the old table - pTableOld = p->pTable; - nTableSizeOld = p->nTableSize; - // get the new table - p->nTableSize = Aig_PrimeCudd( 2 * Aig_ManNodeNum(p) ); - p->pTable = ALLOC( Aig_Obj_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize ); - // rehash the entries from the old table - Counter = 0; - for ( i = 0; i < nTableSizeOld; i++ ) - for ( pEntry = pTableOld[i], pNext = pEntry? pEntry->pNext : NULL; - pEntry; pEntry = pNext, pNext = pEntry? pEntry->pNext : NULL ) - { - // get the place where this entry goes in the table - ppPlace = Aig_TableFind( p, pEntry ); - assert( *ppPlace == NULL ); // should not be there - // add the entry to the list - *ppPlace = pEntry; - pEntry->pNext = NULL; - Counter++; - } - assert( Counter == Aig_ManNodeNum(p) ); -// printf( "Increasing the structural table size from %6d to %6d. ", nTableSizeOld, p->nTableSize ); -// PRT( "Time", clock() - clk ); - // replace the table and the parameters - free( pTableOld ); -} - -/**Function************************************************************* - - Synopsis [Checks if node with the given attributes is in the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_TableLookup( Aig_Man_t * p, Aig_Obj_t * pGhost ) -{ - Aig_Obj_t * pEntry; - assert( !Aig_IsComplement(pGhost) ); - if ( pGhost->Type == AIG_OBJ_LATCH ) - { - assert( Aig_ObjChild0(pGhost) && Aig_ObjChild1(pGhost) == NULL ); - if ( !Aig_ObjRefs(Aig_ObjFanin0(pGhost)) ) - return NULL; - } - else - { - assert( pGhost->Type == AIG_OBJ_AND ); - assert( Aig_ObjChild0(pGhost) && Aig_ObjChild1(pGhost) ); - assert( Aig_ObjFanin0(pGhost)->Id < Aig_ObjFanin1(pGhost)->Id ); - if ( !Aig_ObjRefs(Aig_ObjFanin0(pGhost)) || !Aig_ObjRefs(Aig_ObjFanin1(pGhost)) ) - return NULL; - } - for ( pEntry = p->pTable[Aig_Hash(pGhost, p->nTableSize)]; pEntry; pEntry = pEntry->pNext ) - { - if ( Aig_ObjChild0(pEntry) == Aig_ObjChild0(pGhost) && - Aig_ObjChild1(pEntry) == Aig_ObjChild1(pGhost) && - Aig_ObjType(pEntry) == Aig_ObjType(pGhost) ) - return pEntry; - } - return NULL; -} - -/**Function************************************************************* - - Synopsis [Checks if node with the given attributes is in the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_TableLookupTwo( Aig_Man_t * p, Aig_Obj_t * pFanin0, Aig_Obj_t * pFanin1 ) -{ - Aig_Obj_t * pGhost; - // consider simple cases - if ( pFanin0 == pFanin1 ) - return pFanin0; - if ( pFanin0 == Aig_Not(pFanin1) ) - return Aig_ManConst0(p); - if ( Aig_Regular(pFanin0) == Aig_ManConst1(p) ) - return pFanin0 == Aig_ManConst1(p) ? pFanin1 : Aig_ManConst0(p); - if ( Aig_Regular(pFanin1) == Aig_ManConst1(p) ) - return pFanin1 == Aig_ManConst1(p) ? pFanin0 : Aig_ManConst0(p); - pGhost = Aig_ObjCreateGhost( p, pFanin0, pFanin1, AIG_OBJ_AND ); - return Aig_TableLookup( p, pGhost ); -} - -/**Function************************************************************* - - Synopsis [Adds the new node to the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TableInsert( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t ** ppPlace; - if ( p->pTable == NULL ) - return; - assert( !Aig_IsComplement(pObj) ); - assert( Aig_TableLookup(p, pObj) == NULL ); - if ( (pObj->Id & 0xFF) == 0 && 2 * p->nTableSize < Aig_ManNodeNum(p) ) - Aig_TableResize( p ); - ppPlace = Aig_TableFind( p, pObj ); - assert( *ppPlace == NULL ); - *ppPlace = pObj; -} - -/**Function************************************************************* - - Synopsis [Deletes the node from the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TableDelete( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t ** ppPlace; - if ( p->pTable == NULL ) - return; - assert( !Aig_IsComplement(pObj) ); - ppPlace = Aig_TableFind( p, pObj ); - assert( *ppPlace == pObj ); // node should be in the table - // remove the node - *ppPlace = pObj->pNext; - pObj->pNext = NULL; -} - -/**Function************************************************************* - - Synopsis [Count the number of nodes in the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_TableCountEntries( Aig_Man_t * p ) -{ - Aig_Obj_t * pEntry; - int i, Counter = 0; - for ( i = 0; i < p->nTableSize; i++ ) - for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext ) - Counter++; - return Counter; -} - -/**Function******************************************************************** - - Synopsis [Profiles the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Aig_TableProfile( Aig_Man_t * p ) -{ - Aig_Obj_t * pEntry; - int i, Counter; - for ( i = 0; i < p->nTableSize; i++ ) - { - Counter = 0; - for ( pEntry = p->pTable[i]; pEntry; pEntry = pEntry->pNext ) - Counter++; - if ( Counter ) - printf( "%d ", Counter ); - } -} - -/**Function******************************************************************** - - Synopsis [Profiles the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Aig_TableClear( Aig_Man_t * p ) -{ - FREE( p->pTable ); - p->nTableSize = 0; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigTiming.c b/src/abc8/aig/aigTiming.c deleted file mode 100644 index de8fdc7c..00000000 --- a/src/abc8/aig/aigTiming.c +++ /dev/null @@ -1,351 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigTiming.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Incremental updating of direct/reverse AIG levels.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigTiming.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Returns the reverse level of the node.] - - Description [The reverse level is the level of the node in reverse - topological order, starting from the COs.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Aig_ObjReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - assert( p->vLevelR ); - Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 ); - return Vec_IntEntry(p->vLevelR, pObj->Id); -} - -/**Function************************************************************* - - Synopsis [Sets the reverse level of the node.] - - Description [The reverse level is the level of the node in reverse - topological order, starting from the COs.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline void Aig_ObjSetReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj, int LevelR ) -{ - assert( p->vLevelR ); - Vec_IntFillExtra( p->vLevelR, pObj->Id + 1, 0 ); - Vec_IntWriteEntry( p->vLevelR, pObj->Id, LevelR ); -} - -/**Function************************************************************* - - Synopsis [Resets reverse level of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjClearReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_ObjSetReverseLevel( p, pObj, 0 ); -} - -/**Function************************************************************* - - Synopsis [Returns required level of the node.] - - Description [Converts the reverse levels of the node into its required - level as follows: ReqLevel(Node) = MaxLevels(Ntk) + 1 - LevelR(Node).] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjRequiredLevel( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - assert( p->vLevelR ); - return p->nLevelMax + 1 - Aig_ObjReverseLevel(p, pObj); -} - -/**Function************************************************************* - - Synopsis [Computes the reverse level of the node using its fanout levels.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjReverseLevelNew( Aig_Man_t * p, Aig_Obj_t * pObj ) -{ - Aig_Obj_t * pFanout; - int i, iFanout = -1, LevelCur, Level = 0; - Aig_ObjForEachFanout( p, pObj, pFanout, iFanout, i ) - { - LevelCur = Aig_ObjReverseLevel( p, pFanout ); - Level = AIG_MAX( Level, LevelCur ); - } - return Level + 1; -} - -/**Function************************************************************* - - Synopsis [Prepares for the computation of required levels.] - - Description [This procedure should be called before the required times - are used. It starts internal data structures, which records the level - from the COs of the network nodes in reverse topologogical order.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManStartReverseLevels( Aig_Man_t * p, int nMaxLevelIncrease ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - assert( p->pFanData != NULL ); - assert( p->vLevelR == NULL ); - // remember the maximum number of direct levels - p->nLevelMax = Aig_ManLevels(p) + nMaxLevelIncrease; - // start the reverse levels - p->vLevelR = Vec_IntAlloc( 0 ); - Vec_IntFill( p->vLevelR, Aig_ManObjNumMax(p), 0 ); - // compute levels in reverse topological order - vNodes = Aig_ManDfsReverse( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - assert( pObj->fMarkA == 0 ); - Aig_ObjSetReverseLevel( p, pObj, Aig_ObjReverseLevelNew(p, pObj) ); - } - Vec_PtrFree( vNodes ); -} - -/**Function************************************************************* - - Synopsis [Cleans the data structures used to compute required levels.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManStopReverseLevels( Aig_Man_t * p ) -{ - assert( p->vLevelR != NULL ); - Vec_IntFree( p->vLevelR ); - p->vLevelR = NULL; - p->nLevelMax = 0; - -} - -/**Function************************************************************* - - Synopsis [Incrementally updates level of the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManUpdateLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew ) -{ - Aig_Obj_t * pFanout, * pTemp; - int iFanout = -1, LevelOld, Lev, k, m; - assert( p->pFanData != NULL ); - assert( Aig_ObjIsNode(pObjNew) ); - // allocate level if needed - if ( p->vLevels == NULL ) - p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 ); - // check if level has changed - LevelOld = Aig_ObjLevel(pObjNew); - if ( LevelOld == Aig_ObjLevelNew(pObjNew) ) - return; - // start the data structure for level update - // we cannot fail to visit a node when using this structure because the - // nodes are stored by their _old_ levels, which are assumed to be correct - Vec_VecClear( p->vLevels ); - Vec_VecPush( p->vLevels, LevelOld, pObjNew ); - pObjNew->fMarkA = 1; - // recursively update level - Vec_VecForEachEntryStart( p->vLevels, pTemp, Lev, k, LevelOld ) - { - pTemp->fMarkA = 0; - assert( Aig_ObjLevel(pTemp) == Lev ); - pTemp->Level = Aig_ObjLevelNew(pTemp); - // if the level did not change, no need to check the fanout levels - if ( Aig_ObjLevel(pTemp) == Lev ) - continue; - // schedule fanout for level update - Aig_ObjForEachFanout( p, pTemp, pFanout, iFanout, m ) - { - if ( Aig_ObjIsNode(pFanout) && !pFanout->fMarkA ) - { - assert( Aig_ObjLevel(pFanout) >= Lev ); - Vec_VecPush( p->vLevels, Aig_ObjLevel(pFanout), pFanout ); - pFanout->fMarkA = 1; - } - } - } -} - -/**Function************************************************************* - - Synopsis [Incrementally updates level of the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManUpdateReverseLevel( Aig_Man_t * p, Aig_Obj_t * pObjNew ) -{ - Aig_Obj_t * pFanin, * pTemp; - int LevelOld, LevFanin, Lev, k; - assert( p->vLevelR != NULL ); - assert( Aig_ObjIsNode(pObjNew) ); - // allocate level if needed - if ( p->vLevels == NULL ) - p->vLevels = Vec_VecAlloc( Aig_ManLevels(p) + 8 ); - // check if level has changed - LevelOld = Aig_ObjReverseLevel(p, pObjNew); - if ( LevelOld == Aig_ObjReverseLevelNew(p, pObjNew) ) - return; - // start the data structure for level update - // we cannot fail to visit a node when using this structure because the - // nodes are stored by their _old_ levels, which are assumed to be correct - Vec_VecClear( p->vLevels ); - Vec_VecPush( p->vLevels, LevelOld, pObjNew ); - pObjNew->fMarkA = 1; - // recursively update level - Vec_VecForEachEntryStart( p->vLevels, pTemp, Lev, k, LevelOld ) - { - pTemp->fMarkA = 0; - LevelOld = Aig_ObjReverseLevel(p, pTemp); - assert( LevelOld == Lev ); - Aig_ObjSetReverseLevel( p, pTemp, Aig_ObjReverseLevelNew(p, pTemp) ); - // if the level did not change, to need to check the fanout levels - if ( Aig_ObjReverseLevel(p, pTemp) == Lev ) - continue; - // schedule fanins for level update - pFanin = Aig_ObjFanin0(pTemp); - if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA ) - { - LevFanin = Aig_ObjReverseLevel( p, pFanin ); - assert( LevFanin >= Lev ); - Vec_VecPush( p->vLevels, LevFanin, pFanin ); - pFanin->fMarkA = 1; - } - pFanin = Aig_ObjFanin1(pTemp); - if ( Aig_ObjIsNode(pFanin) && !pFanin->fMarkA ) - { - LevFanin = Aig_ObjReverseLevel( p, pFanin ); - assert( LevFanin >= Lev ); - Vec_VecPush( p->vLevels, LevFanin, pFanin ); - pFanin->fMarkA = 1; - } - } -} - -/**Function************************************************************* - - Synopsis [Verifies direct level of the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManVerifyLevel( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i, Counter = 0; - assert( p->pFanData ); - Aig_ManForEachNode( p, pObj, i ) - if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) ) - { - printf( "Level of node %6d should be %4d instead of %4d.\n", - pObj->Id, Aig_ObjLevelNew(pObj), Aig_ObjLevel(pObj) ); - Counter++; - } - if ( Counter ) - printf( "Levels of %d nodes are incorrect.\n", Counter ); -} - -/**Function************************************************************* - - Synopsis [Verifies reverse level of the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManVerifyReverseLevel( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i, Counter = 0; - assert( p->vLevelR ); - Aig_ManForEachNode( p, pObj, i ) - if ( Aig_ObjLevel(pObj) != Aig_ObjLevelNew(pObj) ) - { - printf( "Reverse level of node %6d should be %4d instead of %4d.\n", - pObj->Id, Aig_ObjReverseLevelNew(p, pObj), Aig_ObjReverseLevel(p, pObj) ); - Counter++; - } - if ( Counter ) - printf( "Reverse levels of %d nodes are incorrect.\n", Counter ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigTruth.c b/src/abc8/aig/aigTruth.c deleted file mode 100644 index a92f9e1d..00000000 --- a/src/abc8/aig/aigTruth.c +++ /dev/null @@ -1,98 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigTruth.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Computes truth table for the cut.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigTruth.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Computes truth table of the cut.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Aig_ManCutTruthOne( Aig_Obj_t * pNode, unsigned * pTruth, int nWords ) -{ - unsigned * pTruth0, * pTruth1; - int i; - pTruth0 = Aig_ObjFanin0(pNode)->pData; - pTruth1 = Aig_ObjFanin1(pNode)->pData; - if ( Aig_ObjIsExor(pNode) ) - for ( i = 0; i < nWords; i++ ) - pTruth[i] = pTruth0[i] ^ pTruth1[i]; - else if ( !Aig_ObjFaninC0(pNode) && !Aig_ObjFaninC1(pNode) ) - for ( i = 0; i < nWords; i++ ) - pTruth[i] = pTruth0[i] & pTruth1[i]; - else if ( !Aig_ObjFaninC0(pNode) && Aig_ObjFaninC1(pNode) ) - for ( i = 0; i < nWords; i++ ) - pTruth[i] = pTruth0[i] & ~pTruth1[i]; - else if ( Aig_ObjFaninC0(pNode) && !Aig_ObjFaninC1(pNode) ) - for ( i = 0; i < nWords; i++ ) - pTruth[i] = ~pTruth0[i] & pTruth1[i]; - else // if ( Aig_ObjFaninC0(pNode) && Aig_ObjFaninC1(pNode) ) - for ( i = 0; i < nWords; i++ ) - pTruth[i] = ~pTruth0[i] & ~pTruth1[i]; - return pTruth; -} - -/**Function************************************************************* - - Synopsis [Computes truth table of the cut.] - - Description [The returned pointer should be used immediately.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Aig_ManCutTruth( Aig_Obj_t * pRoot, Vec_Ptr_t * vLeaves, Vec_Ptr_t * vNodes, Vec_Ptr_t * vTruthElem, Vec_Ptr_t * vTruthStore ) -{ - Aig_Obj_t * pObj; - int i, nWords; - assert( Vec_PtrSize(vLeaves) <= Vec_PtrSize(vTruthElem) ); - assert( Vec_PtrSize(vNodes) <= Vec_PtrSize(vTruthStore) ); - assert( Vec_PtrSize(vNodes) == 0 || pRoot == Vec_PtrEntryLast(vNodes) ); - // assign elementary truth tables - Vec_PtrForEachEntry( vLeaves, pObj, i ) - pObj->pData = Vec_PtrEntry( vTruthElem, i ); - // compute truths for other nodes - nWords = Aig_TruthWordNum( Vec_PtrSize(vLeaves) ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - pObj->pData = Aig_ManCutTruthOne( pObj, Vec_PtrEntry(vTruthStore, i), nWords ); - return pRoot->pData; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigTsim.c b/src/abc8/aig/aigTsim.c deleted file mode 100644 index a8a3dda8..00000000 --- a/src/abc8/aig/aigTsim.c +++ /dev/null @@ -1,436 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigTsim.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Ternary simulation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigTsim.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -#define TSI_MAX_ROUNDS 1000 - -#define AIG_XVS0 1 -#define AIG_XVS1 2 -#define AIG_XVSX 3 - -static inline void Aig_ObjSetXsim( Aig_Obj_t * pObj, int Value ) { pObj->nCuts = Value; } -static inline int Aig_ObjGetXsim( Aig_Obj_t * pObj ) { return pObj->nCuts; } -static inline int Aig_XsimInv( int Value ) -{ - if ( Value == AIG_XVS0 ) - return AIG_XVS1; - if ( Value == AIG_XVS1 ) - return AIG_XVS0; - assert( Value == AIG_XVSX ); - return AIG_XVSX; -} -static inline int Aig_XsimAnd( int Value0, int Value1 ) -{ - if ( Value0 == AIG_XVS0 || Value1 == AIG_XVS0 ) - return AIG_XVS0; - if ( Value0 == AIG_XVSX || Value1 == AIG_XVSX ) - return AIG_XVSX; - assert( Value0 == AIG_XVS1 && Value1 == AIG_XVS1 ); - return AIG_XVS1; -} -static inline int Aig_XsimRand2() -{ - return (rand() & 1) ? AIG_XVS1 : AIG_XVS0; -} -static inline int Aig_XsimRand3() -{ - int RetValue; - do { - RetValue = rand() & 3; - } while ( RetValue == 0 ); - return RetValue; -} -static inline int Aig_ObjGetXsimFanin0( Aig_Obj_t * pObj ) -{ - int RetValue; - RetValue = Aig_ObjGetXsim(Aig_ObjFanin0(pObj)); - return Aig_ObjFaninC0(pObj)? Aig_XsimInv(RetValue) : RetValue; -} -static inline int Aig_ObjGetXsimFanin1( Aig_Obj_t * pObj ) -{ - int RetValue; - RetValue = Aig_ObjGetXsim(Aig_ObjFanin1(pObj)); - return Aig_ObjFaninC1(pObj)? Aig_XsimInv(RetValue) : RetValue; -} -static inline void Aig_XsimPrint( FILE * pFile, int Value ) -{ - if ( Value == AIG_XVS0 ) - { - fprintf( pFile, "0" ); - return; - } - if ( Value == AIG_XVS1 ) - { - fprintf( pFile, "1" ); - return; - } - assert( Value == AIG_XVSX ); - fprintf( pFile, "x" ); -} - -// simulation manager -typedef struct Aig_Tsi_t_ Aig_Tsi_t; -struct Aig_Tsi_t_ -{ - Aig_Man_t * pAig; // the original AIG manager - // ternary state representation - int nWords; // the number of words in the states - Vec_Ptr_t * vStates; // the collection of ternary states - Aig_MmFixed_t * pMem; // memory for ternary states - // hash table for terminary states - unsigned ** pBins; - int nBins; -}; - -static inline unsigned * Aig_TsiNext( unsigned * pState, int nWords ) { return *((unsigned **)(pState + nWords)); } -static inline void Aig_TsiSetNext( unsigned * pState, int nWords, unsigned * pNext ) { *((unsigned **)(pState + nWords)) = pNext; } - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Allocates simulation manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Tsi_t * Aig_TsiStart( Aig_Man_t * pAig ) -{ - Aig_Tsi_t * p; - p = (Aig_Tsi_t *)malloc( sizeof(Aig_Tsi_t) ); - memset( p, 0, sizeof(Aig_Tsi_t) ); - p->pAig = pAig; - p->nWords = Aig_BitWordNum( 2*Aig_ManRegNum(pAig) ); - p->vStates = Vec_PtrAlloc( 1000 ); - p->pMem = Aig_MmFixedStart( sizeof(unsigned) * p->nWords + sizeof(unsigned *), 10000 ); - p->nBins = Aig_PrimeCudd(TSI_MAX_ROUNDS/2); - p->pBins = ALLOC( unsigned *, p->nBins ); - memset( p->pBins, 0, sizeof(unsigned *) * p->nBins ); - return p; -} - -/**Function************************************************************* - - Synopsis [Deallocates simulation manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TsiStop( Aig_Tsi_t * p ) -{ - Aig_MmFixedStop( p->pMem, 0 ); - Vec_PtrFree( p->vStates ); - free( p->pBins ); - free( p ); -} - -/**Function************************************************************* - - Synopsis [Computes hash value of the node using its simulation info.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_TsiStateHash( unsigned * pState, int nWords, 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 < nWords; i++ ) - uHash ^= pState[i] * s_FPrimes[i & 0x7F]; - return uHash % nTableSize; -} - -/**Function************************************************************* - - Synopsis [Inserts value into the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_TsiStateLookup( Aig_Tsi_t * p, unsigned * pState, int nWords ) -{ - unsigned * pEntry; - int Hash; - Hash = Aig_TsiStateHash( pState, nWords, p->nBins ); - for ( pEntry = p->pBins[Hash]; pEntry; pEntry = Aig_TsiNext(pEntry, nWords) ) - if ( !memcmp( pEntry, pState, sizeof(unsigned) * nWords ) ) - return 1; - return 0; -} - -/**Function************************************************************* - - Synopsis [Inserts value into the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TsiStateInsert( Aig_Tsi_t * p, unsigned * pState, int nWords ) -{ - int Hash = Aig_TsiStateHash( pState, nWords, p->nBins ); - assert( !Aig_TsiStateLookup( p, pState, nWords ) ); - Aig_TsiSetNext( pState, nWords, p->pBins[Hash] ); - p->pBins[Hash] = pState; -} - -/**Function************************************************************* - - Synopsis [Inserts value into the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -unsigned * Aig_TsiStateNew( Aig_Tsi_t * p ) -{ - unsigned * pState; - pState = (unsigned *)Aig_MmFixedEntryFetch( p->pMem ); - memset( pState, 0, sizeof(unsigned) * p->nWords ); - Vec_PtrPush( p->vStates, pState ); - return pState; -} - -/**Function************************************************************* - - Synopsis [Inserts value into the table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_TsiStatePrint( Aig_Tsi_t * p, unsigned * pState ) -{ - int i, Value, nZeros = 0, nOnes = 0, nDcs = 0; - for ( i = 0; i < Aig_ManRegNum(p->pAig); i++ ) - { - Value = (Aig_InfoHasBit( pState, 2 * i + 1 ) << 1) | Aig_InfoHasBit( pState, 2 * i ); - if ( Value == 1 ) - printf( "0" ), nZeros++; - else if ( Value == 2 ) - printf( "1" ), nOnes++; - else if ( Value == 3 ) - printf( "x" ), nDcs++; - else - assert( 0 ); - } - printf( " (0=%5d, 1=%5d, x=%5d)\n", nZeros, nOnes, nDcs ); -} - - -/**Function************************************************************* - - Synopsis [Cycles the circuit to create a new initial state.] - - Description [Simulates the circuit with random input for the given - number of timeframes to get a better initial state.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Aig_ManTernarySimulate( Aig_Man_t * p, int fVerbose ) -{ - Aig_Tsi_t * pTsi; - Vec_Ptr_t * vMap; - Aig_Obj_t * pObj, * pObjLi, * pObjLo; - unsigned * pState, * pPrev; - int i, k, f, fConstants, Value, nCounter; - // allocate the simulation manager - pTsi = Aig_TsiStart( p ); - // initialize the values - Aig_ObjSetXsim( Aig_ManConst1(p), AIG_XVS1 ); - Aig_ManForEachPiSeq( p, pObj, i ) - Aig_ObjSetXsim( pObj, AIG_XVSX ); - Aig_ManForEachLoSeq( p, pObj, i ) - Aig_ObjSetXsim( pObj, AIG_XVS0 ); - // simulate for the given number of timeframes - for ( f = 0; f < TSI_MAX_ROUNDS; f++ ) - { - // collect this state - pState = Aig_TsiStateNew( pTsi ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - Value = Aig_ObjGetXsim(pObjLo); - if ( Value & 1 ) - Aig_InfoSetBit( pState, 2 * i ); - if ( Value & 2 ) - Aig_InfoSetBit( pState, 2 * i + 1 ); - } -// Aig_TsiStatePrint( pTsi, pState ); - // check if this state exists - if ( Aig_TsiStateLookup( pTsi, pState, pTsi->nWords ) ) - break; - // insert this state - Aig_TsiStateInsert( pTsi, pState, pTsi->nWords ); - // simulate internal nodes - Aig_ManForEachNode( p, pObj, i ) - Aig_ObjSetXsim( pObj, Aig_XsimAnd(Aig_ObjGetXsimFanin0(pObj), Aig_ObjGetXsimFanin1(pObj)) ); - // transfer the latch values - Aig_ManForEachLiSeq( p, pObj, i ) - Aig_ObjSetXsim( pObj, Aig_ObjGetXsimFanin0(pObj) ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - Aig_ObjSetXsim( pObjLo, Aig_ObjGetXsim(pObjLi) ); - } - if ( f == TSI_MAX_ROUNDS ) - { - printf( "Aig_ManTernarySimulate(): Did not reach a fixed point after %d iterations (not a bug).\n", TSI_MAX_ROUNDS ); - Aig_TsiStop( pTsi ); - return NULL; - } - // OR all the states - pState = Vec_PtrEntry( pTsi->vStates, 0 ); - Vec_PtrForEachEntry( pTsi->vStates, pPrev, i ) - { - for ( k = 0; k < pTsi->nWords; k++ ) - pState[k] |= pPrev[k]; - } - // check if there are constants - fConstants = 0; - if ( 2*Aig_ManRegNum(p) == 32*pTsi->nWords ) - { - for ( i = 0; i < pTsi->nWords; i++ ) - if ( pState[i] != ~0 ) - fConstants = 1; - } - else - { - for ( i = 0; i < pTsi->nWords - 1; i++ ) - if ( pState[i] != ~0 ) - fConstants = 1; - if ( pState[i] != Aig_InfoMask( 2*Aig_ManRegNum(p) - 32*(pTsi->nWords-1) ) ) - fConstants = 1; - } - if ( fConstants == 0 ) - { - Aig_TsiStop( pTsi ); - return NULL; - } - - // start mapping by adding the true PIs - vMap = Vec_PtrAlloc( Aig_ManPiNum(p) ); - Aig_ManForEachPiSeq( p, pObj, i ) - Vec_PtrPush( vMap, pObj ); - // find constant registers - nCounter = 0; - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - Value = (Aig_InfoHasBit( pState, 2 * i + 1 ) << 1) | Aig_InfoHasBit( pState, 2 * i ); - nCounter += (Value == 1 || Value == 2); - if ( Value == 1 ) - Vec_PtrPush( vMap, Aig_ManConst0(p) ); - else if ( Value == 2 ) - Vec_PtrPush( vMap, Aig_ManConst1(p) ); - else if ( Value == 3 ) - Vec_PtrPush( vMap, pObjLo ); - else - assert( 0 ); -// Aig_XsimPrint( stdout, Value ); - } -// printf( "\n" ); - Aig_TsiStop( pTsi ); - if ( fVerbose ) - printf( "Detected %d constants after %d iterations of ternary simulation.\n", nCounter, f ); - return vMap; -} - -/**Function************************************************************* - - Synopsis [Reduces the circuit using ternary simulation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Man_t * Aig_ManConstReduce( Aig_Man_t * p, int fVerbose ) -{ - Aig_Man_t * pTemp; - Vec_Ptr_t * vMap; - while ( (vMap = Aig_ManTernarySimulate( p, fVerbose )) ) - { - if ( fVerbose ) - printf( "RBeg = %5d. NBeg = %6d. ", Aig_ManRegNum(p), Aig_ManNodeNum(p) ); - p = Aig_ManRemap( pTemp = p, vMap ); - Aig_ManStop( pTemp ); - Vec_PtrFree( vMap ); - Aig_ManSeqCleanup( p ); - if ( fVerbose ) - printf( "REnd = %5d. NEnd = %6d. \n", Aig_ManRegNum(p), Aig_ManNodeNum(p) ); - } - return p; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigUtil.c b/src/abc8/aig/aigUtil.c deleted file mode 100644 index f6f34de9..00000000 --- a/src/abc8/aig/aigUtil.c +++ /dev/null @@ -1,855 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigUtil.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Various procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigUtil.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function******************************************************************** - - Synopsis [Returns the next prime >= p.] - - Description [Copied from CUDD, for stand-aloneness.] - - SideEffects [None] - - SeeAlso [] - -******************************************************************************/ -unsigned int Aig_PrimeCudd( unsigned int p ) -{ - int i,pn; - - p--; - do { - p++; - if (p&1) { - pn = 1; - i = 3; - while ((unsigned) (i * i) <= p) { - if (p % i == 0) { - pn = 0; - break; - } - i += 2; - } - } else { - pn = 0; - } - } while (!pn); - return(p); - -} /* end of Cudd_Prime */ - -/**Function************************************************************* - - Synopsis [Increments the current traversal ID of the network.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManIncrementTravId( Aig_Man_t * p ) -{ - if ( p->nTravIds >= (1<<30)-1 ) - Aig_ManCleanData( p ); - p->nTravIds++; -} - -/**Function************************************************************* - - Synopsis [Collect the latches.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManLevels( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i, LevelMax = 0; - Aig_ManForEachPo( p, pObj, i ) - LevelMax = AIG_MAX( LevelMax, (int)Aig_ObjFanin0(pObj)->Level ); - return LevelMax; -} - -/**Function************************************************************* - - Synopsis [Reset reference counters.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManResetRefs( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - pObj->nRefs = 0; - Aig_ManForEachObj( p, pObj, i ) - { - if ( Aig_ObjFanin0(pObj) ) - Aig_ObjFanin0(pObj)->nRefs++; - if ( Aig_ObjFanin1(pObj) ) - Aig_ObjFanin1(pObj)->nRefs++; - } -} - -/**Function************************************************************* - - Synopsis [Cleans MarkB.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCleanMarkA( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - pObj->fMarkA = 0; -} - -/**Function************************************************************* - - Synopsis [Cleans MarkB.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCleanMarkB( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - pObj->fMarkB = 0; -} - -/**Function************************************************************* - - Synopsis [Cleans the data pointers for the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManCleanData( Aig_Man_t * p ) -{ - Aig_Obj_t * pObj; - int i; - Aig_ManForEachObj( p, pObj, i ) - pObj->pData = NULL; -} - -/**Function************************************************************* - - Synopsis [Recursively cleans the data pointers in the cone of the node.] - - Description [Applicable to small AIGs only because no caching is performed.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCleanData_rec( Aig_Obj_t * pObj ) -{ - assert( !Aig_IsComplement(pObj) ); - assert( !Aig_ObjIsPo(pObj) ); - if ( Aig_ObjIsAnd(pObj) ) - { - Aig_ObjCleanData_rec( Aig_ObjFanin0(pObj) ); - Aig_ObjCleanData_rec( Aig_ObjFanin1(pObj) ); - } - pObj->pData = NULL; -} - - -/**Function************************************************************* - - Synopsis [Detects multi-input gate rooted at this node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCollectMulti_rec( Aig_Obj_t * pRoot, Aig_Obj_t * pObj, Vec_Ptr_t * vSuper ) -{ - if ( pRoot != pObj && (Aig_IsComplement(pObj) || Aig_ObjIsPi(pObj) || Aig_ObjType(pRoot) != Aig_ObjType(pObj)) ) - { - Vec_PtrPushUnique(vSuper, pObj); - return; - } - Aig_ObjCollectMulti_rec( pRoot, Aig_ObjChild0(pObj), vSuper ); - Aig_ObjCollectMulti_rec( pRoot, Aig_ObjChild1(pObj), vSuper ); -} - -/**Function************************************************************* - - Synopsis [Detects multi-input gate rooted at this node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjCollectMulti( Aig_Obj_t * pRoot, Vec_Ptr_t * vSuper ) -{ - assert( !Aig_IsComplement(pRoot) ); - Vec_PtrClear( vSuper ); - Aig_ObjCollectMulti_rec( pRoot, pRoot, vSuper ); -} - -/**Function************************************************************* - - Synopsis [Returns 1 if the node is the root of MUX or EXOR/NEXOR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjIsMuxType( Aig_Obj_t * pNode ) -{ - Aig_Obj_t * pNode0, * pNode1; - // check that the node is regular - assert( !Aig_IsComplement(pNode) ); - // if the node is not AND, this is not MUX - if ( !Aig_ObjIsAnd(pNode) ) - return 0; - // if the children are not complemented, this is not MUX - if ( !Aig_ObjFaninC0(pNode) || !Aig_ObjFaninC1(pNode) ) - return 0; - // get children - pNode0 = Aig_ObjFanin0(pNode); - pNode1 = Aig_ObjFanin1(pNode); - // if the children are not ANDs, this is not MUX - if ( !Aig_ObjIsAnd(pNode0) || !Aig_ObjIsAnd(pNode1) ) - return 0; - // otherwise the node is MUX iff it has a pair of equal grandchildren - return (Aig_ObjFanin0(pNode0) == Aig_ObjFanin0(pNode1) && (Aig_ObjFaninC0(pNode0) ^ Aig_ObjFaninC0(pNode1))) || - (Aig_ObjFanin0(pNode0) == Aig_ObjFanin1(pNode1) && (Aig_ObjFaninC0(pNode0) ^ Aig_ObjFaninC1(pNode1))) || - (Aig_ObjFanin1(pNode0) == Aig_ObjFanin0(pNode1) && (Aig_ObjFaninC1(pNode0) ^ Aig_ObjFaninC0(pNode1))) || - (Aig_ObjFanin1(pNode0) == Aig_ObjFanin1(pNode1) && (Aig_ObjFaninC1(pNode0) ^ Aig_ObjFaninC1(pNode1))); -} - - -/**Function************************************************************* - - Synopsis [Recognizes what nodes are inputs of the EXOR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ObjRecognizeExor( Aig_Obj_t * pObj, Aig_Obj_t ** ppFan0, Aig_Obj_t ** ppFan1 ) -{ - Aig_Obj_t * p0, * p1; - assert( !Aig_IsComplement(pObj) ); - if ( !Aig_ObjIsNode(pObj) ) - return 0; - if ( Aig_ObjIsExor(pObj) ) - { - *ppFan0 = Aig_ObjChild0(pObj); - *ppFan1 = Aig_ObjChild1(pObj); - return 1; - } - assert( Aig_ObjIsAnd(pObj) ); - p0 = Aig_ObjChild0(pObj); - p1 = Aig_ObjChild1(pObj); - if ( !Aig_IsComplement(p0) || !Aig_IsComplement(p1) ) - return 0; - p0 = Aig_Regular(p0); - p1 = Aig_Regular(p1); - if ( !Aig_ObjIsAnd(p0) || !Aig_ObjIsAnd(p1) ) - return 0; - if ( Aig_ObjFanin0(p0) != Aig_ObjFanin0(p1) || Aig_ObjFanin1(p0) != Aig_ObjFanin1(p1) ) - return 0; - if ( Aig_ObjFaninC0(p0) == Aig_ObjFaninC0(p1) || Aig_ObjFaninC1(p0) == Aig_ObjFaninC1(p1) ) - return 0; - *ppFan0 = Aig_ObjChild0(p0); - *ppFan1 = Aig_ObjChild1(p0); - return 1; -} - -/**Function************************************************************* - - Synopsis [Recognizes what nodes are control and data inputs of a MUX.] - - Description [If the node is a MUX, returns the control variable C. - Assigns nodes T and E to be the then and else variables of the MUX. - Node C is never complemented. Nodes T and E can be complemented. - This function also recognizes EXOR/NEXOR gates as MUXes.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ObjRecognizeMux( Aig_Obj_t * pNode, Aig_Obj_t ** ppNodeT, Aig_Obj_t ** ppNodeE ) -{ - Aig_Obj_t * pNode0, * pNode1; - assert( !Aig_IsComplement(pNode) ); - assert( Aig_ObjIsMuxType(pNode) ); - // get children - pNode0 = Aig_ObjFanin0(pNode); - pNode1 = Aig_ObjFanin1(pNode); - - // find the control variable - if ( Aig_ObjFanin1(pNode0) == Aig_ObjFanin1(pNode1) && (Aig_ObjFaninC1(pNode0) ^ Aig_ObjFaninC1(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p2) ) - if ( Aig_ObjFaninC1(pNode0) ) - { // pNode2->p2 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild0(pNode1));//pNode2->p1); - *ppNodeE = Aig_Not(Aig_ObjChild0(pNode0));//pNode1->p1); - return Aig_ObjChild1(pNode1);//pNode2->p2; - } - else - { // pNode1->p2 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild0(pNode0));//pNode1->p1); - *ppNodeE = Aig_Not(Aig_ObjChild0(pNode1));//pNode2->p1); - return Aig_ObjChild1(pNode0);//pNode1->p2; - } - } - else if ( Aig_ObjFanin0(pNode0) == Aig_ObjFanin0(pNode1) && (Aig_ObjFaninC0(pNode0) ^ Aig_ObjFaninC0(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p1) ) - if ( Aig_ObjFaninC0(pNode0) ) - { // pNode2->p1 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild1(pNode1));//pNode2->p2); - *ppNodeE = Aig_Not(Aig_ObjChild1(pNode0));//pNode1->p2); - return Aig_ObjChild0(pNode1);//pNode2->p1; - } - else - { // pNode1->p1 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild1(pNode0));//pNode1->p2); - *ppNodeE = Aig_Not(Aig_ObjChild1(pNode1));//pNode2->p2); - return Aig_ObjChild0(pNode0);//pNode1->p1; - } - } - else if ( Aig_ObjFanin0(pNode0) == Aig_ObjFanin1(pNode1) && (Aig_ObjFaninC0(pNode0) ^ Aig_ObjFaninC1(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p1) ) - if ( Aig_ObjFaninC0(pNode0) ) - { // pNode2->p2 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild0(pNode1));//pNode2->p1); - *ppNodeE = Aig_Not(Aig_ObjChild1(pNode0));//pNode1->p2); - return Aig_ObjChild1(pNode1);//pNode2->p2; - } - else - { // pNode1->p1 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild1(pNode0));//pNode1->p2); - *ppNodeE = Aig_Not(Aig_ObjChild0(pNode1));//pNode2->p1); - return Aig_ObjChild0(pNode0);//pNode1->p1; - } - } - else if ( Aig_ObjFanin1(pNode0) == Aig_ObjFanin0(pNode1) && (Aig_ObjFaninC1(pNode0) ^ Aig_ObjFaninC0(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p2) ) - if ( Aig_ObjFaninC1(pNode0) ) - { // pNode2->p1 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild1(pNode1));//pNode2->p2); - *ppNodeE = Aig_Not(Aig_ObjChild0(pNode0));//pNode1->p1); - return Aig_ObjChild0(pNode1);//pNode2->p1; - } - else - { // pNode1->p2 is positive phase of C - *ppNodeT = Aig_Not(Aig_ObjChild0(pNode0));//pNode1->p1); - *ppNodeE = Aig_Not(Aig_ObjChild1(pNode1));//pNode2->p2); - return Aig_ObjChild1(pNode0);//pNode1->p2; - } - } - assert( 0 ); // this is not MUX - return NULL; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Aig_Obj_t * Aig_ObjReal_rec( Aig_Obj_t * pObj ) -{ - Aig_Obj_t * pObjNew, * pObjR = Aig_Regular(pObj); - if ( !Aig_ObjIsBuf(pObjR) ) - return pObj; - pObjNew = Aig_ObjReal_rec( Aig_ObjChild0(pObjR) ); - return Aig_NotCond( pObjNew, Aig_IsComplement(pObj) ); -} - - -/**Function************************************************************* - - Synopsis [Prints Eqn formula for the AIG rooted at this node.] - - Description [The formula is in terms of PIs, which should have - their names assigned in pObj->pData fields.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjPrintEqn( FILE * pFile, Aig_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ) -{ - Vec_Ptr_t * vSuper; - Aig_Obj_t * pFanin; - int fCompl, i; - // store the complemented attribute - fCompl = Aig_IsComplement(pObj); - pObj = Aig_Regular(pObj); - // constant case - if ( Aig_ObjIsConst1(pObj) ) - { - fprintf( pFile, "%d", !fCompl ); - return; - } - // PI case - if ( Aig_ObjIsPi(pObj) ) - { - fprintf( pFile, "%s%s", fCompl? "!" : "", (char*)pObj->pData ); - return; - } - // AND case - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry(vLevels, Level); - Aig_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Aig_ObjPrintEqn( pFile, Aig_NotCond(pFanin, fCompl), vLevels, Level+1 ); - if ( i < Vec_PtrSize(vSuper) - 1 ) - fprintf( pFile, " %s ", fCompl? "+" : "*" ); - } - fprintf( pFile, "%s", (Level==0? "" : ")") ); - return; -} - -/**Function************************************************************* - - Synopsis [Prints Verilog formula for the AIG rooted at this node.] - - Description [The formula is in terms of PIs, which should have - their names assigned in pObj->pData fields.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjPrintVerilog( FILE * pFile, Aig_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ) -{ - Vec_Ptr_t * vSuper; - Aig_Obj_t * pFanin, * pFanin0, * pFanin1, * pFaninC; - int fCompl, i; - // store the complemented attribute - fCompl = Aig_IsComplement(pObj); - pObj = Aig_Regular(pObj); - // constant case - if ( Aig_ObjIsConst1(pObj) ) - { - fprintf( pFile, "1\'b%d", !fCompl ); - return; - } - // PI case - if ( Aig_ObjIsPi(pObj) ) - { - fprintf( pFile, "%s%s", fCompl? "~" : "", (char*)pObj->pData ); - return; - } - // EXOR case - if ( Aig_ObjIsExor(pObj) ) - { - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry( vLevels, Level ); - Aig_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Aig_ObjPrintVerilog( pFile, Aig_NotCond(pFanin, (fCompl && i==0)), vLevels, Level+1 ); - if ( i < Vec_PtrSize(vSuper) - 1 ) - fprintf( pFile, " ^ " ); - } - fprintf( pFile, "%s", (Level==0? "" : ")") ); - return; - } - // MUX case - if ( Aig_ObjIsMuxType(pObj) ) - { - if ( Aig_ObjRecognizeExor( pObj, &pFanin0, &pFanin1 ) ) - { - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Aig_ObjPrintVerilog( pFile, Aig_NotCond(pFanin0, fCompl), vLevels, Level+1 ); - fprintf( pFile, " ^ " ); - Aig_ObjPrintVerilog( pFile, pFanin1, vLevels, Level+1 ); - fprintf( pFile, "%s", (Level==0? "" : ")") ); - } - else - { - pFaninC = Aig_ObjRecognizeMux( pObj, &pFanin1, &pFanin0 ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Aig_ObjPrintVerilog( pFile, pFaninC, vLevels, Level+1 ); - fprintf( pFile, " ? " ); - Aig_ObjPrintVerilog( pFile, Aig_NotCond(pFanin1, fCompl), vLevels, Level+1 ); - fprintf( pFile, " : " ); - Aig_ObjPrintVerilog( pFile, Aig_NotCond(pFanin0, fCompl), vLevels, Level+1 ); - fprintf( pFile, "%s", (Level==0? "" : ")") ); - } - return; - } - // AND case - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry(vLevels, Level); - Aig_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Aig_ObjPrintVerilog( pFile, Aig_NotCond(pFanin, fCompl), vLevels, Level+1 ); - if ( i < Vec_PtrSize(vSuper) - 1 ) - fprintf( pFile, " %s ", fCompl? "|" : "&" ); - } - fprintf( pFile, "%s", (Level==0? "" : ")") ); - return; -} - - -/**Function************************************************************* - - Synopsis [Prints node in HAIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ObjPrintVerbose( Aig_Obj_t * pObj, int fHaig ) -{ - assert( !Aig_IsComplement(pObj) ); - printf( "Node %p : ", pObj ); - if ( Aig_ObjIsConst1(pObj) ) - printf( "constant 1" ); - else if ( Aig_ObjIsPi(pObj) ) - printf( "PI" ); - else - printf( "AND( %p%s, %p%s )", - Aig_ObjFanin0(pObj), (Aig_ObjFaninC0(pObj)? "\'" : " "), - Aig_ObjFanin1(pObj), (Aig_ObjFaninC1(pObj)? "\'" : " ") ); - printf( " (refs = %3d)", Aig_ObjRefs(pObj) ); -} - -/**Function************************************************************* - - Synopsis [Prints node in HAIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManPrintVerbose( Aig_Man_t * p, int fHaig ) -{ - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj; - int i; - printf( "PIs: " ); - Aig_ManForEachPi( p, pObj, i ) - printf( " %p", pObj ); - printf( "\n" ); - vNodes = Aig_ManDfs( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - Aig_ObjPrintVerbose( pObj, fHaig ), printf( "\n" ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Write speculative miter for one node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDump( Aig_Man_t * p ) -{ - static int Counter = 0; - char FileName[20]; - // dump the logic into a file - sprintf( FileName, "aigbug\\%03d.blif", ++Counter ); - Aig_ManDumpBlif( p, FileName ); - printf( "Intermediate AIG with %d nodes was written into file \"%s\".\n", Aig_ManNodeNum(p), FileName ); -} - -/**Function************************************************************* - - Synopsis [Writes the AIG into a BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDumpBlif( Aig_Man_t * p, char * pFileName ) -{ - FILE * pFile; - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pConst1 = NULL; - int i, nDigits, Counter = 0; - if ( Aig_ManPoNum(p) == 0 ) - { - printf( "Aig_ManDumpBlif(): AIG manager does not have POs.\n" ); - return; - } - // check if constant is used - Aig_ManForEachPo( p, pObj, i ) - if ( Aig_ObjIsConst1(Aig_ObjFanin0(pObj)) ) - pConst1 = Aig_ManConst1(p); - // collect nodes in the DFS order - vNodes = Aig_ManDfs( p ); - // assign IDs to objects - Aig_ManConst1(p)->iData = Counter++; - Aig_ManForEachPi( p, pObj, i ) - pObj->iData = Counter++; - Aig_ManForEachPo( p, pObj, i ) - pObj->iData = Counter++; - Vec_PtrForEachEntry( vNodes, pObj, i ) - pObj->iData = Counter++; - nDigits = Aig_Base10Log( Counter ); - // write the file - pFile = fopen( pFileName, "w" ); - fprintf( pFile, "# BLIF file written by procedure Aig_ManDumpBlif()\n" ); -// fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" ); - fprintf( pFile, ".model test\n" ); - // write PIs - fprintf( pFile, ".inputs" ); - Aig_ManForEachPiSeq( p, pObj, i ) - fprintf( pFile, " n%0*d", nDigits, pObj->iData ); - fprintf( pFile, "\n" ); - // write POs - fprintf( pFile, ".outputs" ); - Aig_ManForEachPoSeq( p, pObj, i ) - fprintf( pFile, " n%0*d", nDigits, pObj->iData ); - fprintf( pFile, "\n" ); - // write latches - if ( Aig_ManRegNum(p) ) - { - fprintf( pFile, "\n" ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - fprintf( pFile, ".latch n%0*d n%0*d 0\n", nDigits, pObjLi->iData, nDigits, pObjLo->iData ); - fprintf( pFile, "\n" ); - } - // write nodes - if ( pConst1 ) - fprintf( pFile, ".names n%0*d\n 1\n", nDigits, pConst1->iData ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - fprintf( pFile, ".names n%0*d n%0*d n%0*d\n", - nDigits, Aig_ObjFanin0(pObj)->iData, - nDigits, Aig_ObjFanin1(pObj)->iData, - nDigits, pObj->iData ); - fprintf( pFile, "%d%d 1\n", !Aig_ObjFaninC0(pObj), !Aig_ObjFaninC1(pObj) ); - } - // write POs - Aig_ManForEachPo( p, pObj, i ) - { - fprintf( pFile, ".names n%0*d n%0*d\n", - nDigits, Aig_ObjFanin0(pObj)->iData, - nDigits, pObj->iData ); - fprintf( pFile, "%d 1\n", !Aig_ObjFaninC0(pObj) ); - } - fprintf( pFile, ".end\n\n" ); - fclose( pFile ); - Vec_PtrFree( vNodes ); -} - -/**Function************************************************************* - - Synopsis [Writes the AIG into a Verilog file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManDumpVerilog( Aig_Man_t * p, char * pFileName ) -{ - FILE * pFile; - Vec_Ptr_t * vNodes; - Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pConst1 = NULL; - int i, nDigits, Counter = 0; - if ( Aig_ManPoNum(p) == 0 ) - { - printf( "Aig_ManDumpBlif(): AIG manager does not have POs.\n" ); - return; - } - // check if constant is used - Aig_ManForEachPo( p, pObj, i ) - if ( Aig_ObjIsConst1(Aig_ObjFanin0(pObj)) ) - pConst1 = Aig_ManConst1(p); - // collect nodes in the DFS order - vNodes = Aig_ManDfs( p ); - // assign IDs to objects - Aig_ManConst1(p)->iData = Counter++; - Aig_ManForEachPi( p, pObj, i ) - pObj->iData = Counter++; - Aig_ManForEachPo( p, pObj, i ) - pObj->iData = Counter++; - Vec_PtrForEachEntry( vNodes, pObj, i ) - pObj->iData = Counter++; - nDigits = Aig_Base10Log( Counter ); - // write the file - pFile = fopen( pFileName, "w" ); - fprintf( pFile, "// Verilog file written by procedure Aig_ManDumpVerilog()\n" ); -// fprintf( pFile, "// http://www.eecs.berkeley.edu/~alanmi/abc/\n" ); - if ( Aig_ManRegNum(p) ) - fprintf( pFile, "module %s ( clock", p->pName? p->pName: "test" ); - else - fprintf( pFile, "module %s (", p->pName? p->pName: "test" ); - Aig_ManForEachPiSeq( p, pObj, i ) - fprintf( pFile, "%s n%0*d", ((Aig_ManRegNum(p) || i)? ",":""), nDigits, pObj->iData ); - Aig_ManForEachPoSeq( p, pObj, i ) - fprintf( pFile, ", n%0*d", nDigits, pObj->iData ); - fprintf( pFile, " );\n" ); - - // write PIs - if ( Aig_ManRegNum(p) ) - fprintf( pFile, "input clock;\n" ); - Aig_ManForEachPiSeq( p, pObj, i ) - fprintf( pFile, "input n%0*d;\n", nDigits, pObj->iData ); - // write POs - Aig_ManForEachPoSeq( p, pObj, i ) - fprintf( pFile, "output n%0*d;\n", nDigits, pObj->iData ); - // write latches - if ( Aig_ManRegNum(p) ) - { - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - fprintf( pFile, "reg n%0*d;\n", nDigits, pObjLo->iData ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - fprintf( pFile, "wire n%0*d;\n", nDigits, pObjLi->iData ); - } - // write nodes - Vec_PtrForEachEntry( vNodes, pObj, i ) - fprintf( pFile, "wire n%0*d;\n", nDigits, pObj->iData ); - if ( pConst1 ) - fprintf( pFile, "wire n%0*d;\n", nDigits, pConst1->iData ); - // write nodes - if ( pConst1 ) - fprintf( pFile, "assign n%0*d = 1\'b1;\n", nDigits, pConst1->iData ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - fprintf( pFile, "assign n%0*d = %sn%0*d & %sn%0*d;\n", - nDigits, pObj->iData, - !Aig_ObjFaninC0(pObj) ? " " : "~", nDigits, Aig_ObjFanin0(pObj)->iData, - !Aig_ObjFaninC1(pObj) ? " " : "~", nDigits, Aig_ObjFanin1(pObj)->iData - ); - } - // write POs - Aig_ManForEachPoSeq( p, pObj, i ) - { - fprintf( pFile, "assign n%0*d = %sn%0*d;\n", - nDigits, pObj->iData, - !Aig_ObjFaninC0(pObj) ? " " : "~", nDigits, Aig_ObjFanin0(pObj)->iData ); - } - if ( Aig_ManRegNum(p) ) - { - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - { - fprintf( pFile, "assign n%0*d = %sn%0*d;\n", - nDigits, pObjLi->iData, - !Aig_ObjFaninC0(pObjLi) ? " " : "~", nDigits, Aig_ObjFanin0(pObjLi)->iData ); - } - } - - // write initial state - if ( Aig_ManRegNum(p) ) - { - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - fprintf( pFile, "always @ (posedge clock) begin n%0*d <= n%0*d; end\n", - nDigits, pObjLo->iData, - nDigits, pObjLi->iData ); - Aig_ManForEachLiLoSeq( p, pObjLi, pObjLo, i ) - fprintf( pFile, "initial begin n%0*d <= 1\'b0; end\n", - nDigits, pObjLo->iData ); - } - - fprintf( pFile, "endmodule\n\n" ); - fclose( pFile ); - Vec_PtrFree( vNodes ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aigWin.c b/src/abc8/aig/aigWin.c deleted file mode 100644 index 0485b243..00000000 --- a/src/abc8/aig/aigWin.c +++ /dev/null @@ -1,184 +0,0 @@ -/**CFile**************************************************************** - - FileName [aigWin.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [Window computation.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aigWin.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Evaluate the cost of removing the node from the set of leaves.] - - Description [Returns the number of new leaves that will be brought in. - Returns large number if the node cannot be removed from the set of leaves.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -static inline int Aig_NodeGetLeafCostOne( Aig_Obj_t * pNode, int nFanoutLimit ) -{ - int Cost; - // make sure the node is in the construction zone - assert( pNode->fMarkA ); - // cannot expand over the PI node - if ( Aig_ObjIsPi(pNode) ) - return 999; - // get the cost of the cone - Cost = (!Aig_ObjFanin0(pNode)->fMarkA) + (!Aig_ObjFanin1(pNode)->fMarkA); - // always accept if the number of leaves does not increase - if ( Cost < 2 ) - return Cost; - // skip nodes with many fanouts - if ( (int)pNode->nRefs > nFanoutLimit ) - return 999; - // return the number of nodes that will be on the leaves if this node is removed - return Cost; -} - -/**Function************************************************************* - - Synopsis [Builds reconvergence-driven cut by changing one leaf at a time.] - - Description [This procedure looks at the current leaves and tries to change - one leaf at a time in such a way that the cut grows as little as possible. - In evaluating the fanins, this procedure looks only at their immediate - predecessors (this is why it is called a one-level construction procedure).] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Aig_ManFindCut_int( Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit ) -{ - Aig_Obj_t * pNode, * pFaninBest, * pNext; - int CostBest, CostCur, i; - // find the best fanin - CostBest = 100; - pFaninBest = NULL; -//printf( "Evaluating fanins of the cut:\n" ); - Vec_PtrForEachEntry( vFront, pNode, i ) - { - CostCur = Aig_NodeGetLeafCostOne( pNode, nFanoutLimit ); -//printf( " Fanin %s has cost %d.\n", Aig_ObjName(pNode), CostCur ); - if ( CostBest > CostCur || - (CostBest == CostCur && pNode->Level > pFaninBest->Level) ) - { - CostBest = CostCur; - pFaninBest = pNode; - } - if ( CostBest == 0 ) - break; - } - if ( pFaninBest == NULL ) - return 0; - assert( CostBest < 3 ); - if ( Vec_PtrSize(vFront) - 1 + CostBest > nSizeLimit ) - return 0; - assert( Aig_ObjIsNode(pFaninBest) ); - // remove the node from the array - Vec_PtrRemove( vFront, pFaninBest ); -//printf( "Removing fanin %s.\n", Aig_ObjName(pFaninBest) ); - - // add the left child to the fanins - pNext = Aig_ObjFanin0(pFaninBest); - if ( !pNext->fMarkA ) - { -//printf( "Adding fanin %s.\n", Aig_ObjName(pNext) ); - pNext->fMarkA = 1; - Vec_PtrPush( vFront, pNext ); - Vec_PtrPush( vVisited, pNext ); - } - // add the right child to the fanins - pNext = Aig_ObjFanin1(pFaninBest); - if ( !pNext->fMarkA ) - { -//printf( "Adding fanin %s.\n", Aig_ObjName(pNext) ); - pNext->fMarkA = 1; - Vec_PtrPush( vFront, pNext ); - Vec_PtrPush( vVisited, pNext ); - } - assert( Vec_PtrSize(vFront) <= nSizeLimit ); - // keep doing this - return 1; -} - -/**Function************************************************************* - - Synopsis [Computes one sequential cut of the given size.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Aig_ManFindCut( Aig_Obj_t * pRoot, Vec_Ptr_t * vFront, Vec_Ptr_t * vVisited, int nSizeLimit, int nFanoutLimit ) -{ - Aig_Obj_t * pNode; - int i; - - assert( !Aig_IsComplement(pRoot) ); - assert( Aig_ObjIsNode(pRoot) ); - assert( Aig_ObjChild0(pRoot) ); - assert( Aig_ObjChild1(pRoot) ); - - // start the cut - Vec_PtrClear( vFront ); - Vec_PtrPush( vFront, Aig_ObjFanin0(pRoot) ); - Vec_PtrPush( vFront, Aig_ObjFanin1(pRoot) ); - - // start the visited nodes - Vec_PtrClear( vVisited ); - Vec_PtrPush( vVisited, pRoot ); - Vec_PtrPush( vVisited, Aig_ObjFanin0(pRoot) ); - Vec_PtrPush( vVisited, Aig_ObjFanin1(pRoot) ); - - // mark these nodes - assert( !pRoot->fMarkA ); - assert( !Aig_ObjFanin0(pRoot)->fMarkA ); - assert( !Aig_ObjFanin1(pRoot)->fMarkA ); - pRoot->fMarkA = 1; - Aig_ObjFanin0(pRoot)->fMarkA = 1; - Aig_ObjFanin1(pRoot)->fMarkA = 1; - - // compute the cut - while ( Aig_ManFindCut_int( vFront, vVisited, nSizeLimit, nFanoutLimit ) ); - assert( Vec_PtrSize(vFront) <= nSizeLimit ); - - // clean the visit markings - Vec_PtrForEachEntry( vVisited, pNode, i ) - pNode->fMarkA = 0; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/aig_.c b/src/abc8/aig/aig_.c deleted file mode 100644 index b2313d35..00000000 --- a/src/abc8/aig/aig_.c +++ /dev/null @@ -1,48 +0,0 @@ -/**CFile**************************************************************** - - FileName [aig_.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [AIG package.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: aig_.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "aig.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ - - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/abc8/aig/module.make b/src/abc8/aig/module.make deleted file mode 100644 index 4b81834f..00000000 --- a/src/abc8/aig/module.make +++ /dev/null @@ -1,23 +0,0 @@ -SRC += src/aig/aig/aigCheck.c \ - src/aig/aig/aigDfs.c \ - src/aig/aig/aigFanout.c \ - src/aig/aig/aigFrames.c \ - src/aig/aig/aigHaig.c \ - src/aig/aig/aigMan.c \ - src/aig/aig/aigMem.c \ - src/aig/aig/aigMffc.c \ - src/aig/aig/aigObj.c \ - src/aig/aig/aigOper.c \ - src/aig/aig/aigOrder.c \ - src/aig/aig/aigPart.c \ - src/aig/aig/aigRepr.c \ - src/aig/aig/aigRet.c \ - src/aig/aig/aigRetF.c \ - src/aig/aig/aigScl.c \ - src/aig/aig/aigSeq.c \ - src/aig/aig/aigTable.c \ - src/aig/aig/aigTiming.c \ - src/aig/aig/aigTruth.c \ - src/aig/aig/aigTsim.c \ - src/aig/aig/aigUtil.c \ - src/aig/aig/aigWin.c
\ No newline at end of file |