From c5277d3334e3dbca556fbf82bbe1c0cacdc85cb1 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Thu, 12 Jul 2007 08:01:00 -0700 Subject: Version abc70712 --- src/aig/aig/aig.h | 373 ++++++++ src/aig/aig/aigCheck.c | 121 +++ src/aig/aig/aigDfs.c | 381 ++++++++ src/aig/aig/aigMan.c | 224 +++++ src/aig/aig/aigMem.c | 597 +++++++++++++ src/aig/aig/aigObj.c | 308 +++++++ src/aig/aig/aigOper.c | 429 +++++++++ src/aig/aig/aigSeq.c | 497 +++++++++++ src/aig/aig/aigTable.c | 279 ++++++ src/aig/aig/aigUtil.c | 642 ++++++++++++++ src/aig/aig/aig_.c | 48 + src/aig/aig/module.make | 9 + src/aig/bdc/bdc.h | 73 ++ src/aig/bdc/bdcCore.c | 189 ++++ src/aig/bdc/bdcDec.c | 461 ++++++++++ src/aig/bdc/bdcInt.h | 151 ++++ src/aig/bdc/bdcTable.c | 140 +++ src/aig/bdc/bdc_.c | 49 ++ src/aig/bdc/module.make | 4 + src/aig/cnf/cnf.h | 21 +- src/aig/cnf/cnfCore.c | 9 +- src/aig/cnf/cnfCut.c | 17 +- src/aig/cnf/cnfData.c | 4 +- src/aig/cnf/cnfMan.c | 8 +- src/aig/cnf/cnfMap.c | 54 +- src/aig/cnf/cnfPost.c | 48 +- src/aig/cnf/cnfUtil.c | 41 +- src/aig/cnf/cnfWrite.c | 30 +- src/aig/csw/csw.h | 2 +- src/aig/csw/cswCore.c | 40 +- src/aig/csw/cswCut.c | 269 +++++- src/aig/csw/cswInt.h | 62 +- src/aig/csw/cswMan.c | 47 +- src/aig/csw/cswTable.c | 55 +- src/aig/dar/dar.h | 428 +-------- src/aig/dar/darBalance.c | 129 +-- src/aig/dar/darCheck.c | 121 --- src/aig/dar/darCore.c | 151 ++-- src/aig/dar/darCut.c | 303 ++++--- src/aig/dar/darData.c | 1684 ++++++++++++++++++++++++++++++++++- src/aig/dar/darDfs.c | 381 -------- src/aig/dar/darInt.h | 158 ++++ src/aig/dar/darLib.c | 312 +++++-- src/aig/dar/darMan.c | 189 +--- src/aig/dar/darMem.c | 601 ------------- src/aig/dar/darObj.c | 308 ------- src/aig/dar/darOper.c | 429 --------- src/aig/dar/darSeq.c | 497 ----------- src/aig/dar/darTable.c | 279 ------ src/aig/dar/darTruth.c | 111 +-- src/aig/dar/darUtil.c | 625 ------------- src/aig/dar/module.make | 10 +- src/aig/fra/fra.h | 49 +- src/aig/fra/fraAnd.c | 52 +- src/aig/fra/fraClass.c | 56 +- src/aig/fra/fraCnf.c | 72 +- src/aig/fra/fraCore.c | 10 +- src/aig/fra/fraMan.c | 38 +- src/aig/fra/fraSat.c | 36 +- src/aig/fra/fraSim.c | 96 +- src/aig/kit/kit.h | 543 ++++++++++++ src/aig/kit/kitBdd.c | 231 +++++ src/aig/kit/kitDsd.c | 2185 ++++++++++++++++++++++++++++++++++++++++++++++ src/aig/kit/kitFactor.c | 338 +++++++ src/aig/kit/kitGraph.c | 397 +++++++++ src/aig/kit/kitHop.c | 115 +++ src/aig/kit/kitIsop.c | 325 +++++++ src/aig/kit/kitSop.c | 570 ++++++++++++ src/aig/kit/kitTruth.c | 1640 ++++++++++++++++++++++++++++++++++ src/aig/kit/kit_.c | 48 + src/aig/kit/module.make | 8 + 71 files changed, 14587 insertions(+), 4620 deletions(-) create mode 100644 src/aig/aig/aig.h create mode 100644 src/aig/aig/aigCheck.c create mode 100644 src/aig/aig/aigDfs.c create mode 100644 src/aig/aig/aigMan.c create mode 100644 src/aig/aig/aigMem.c create mode 100644 src/aig/aig/aigObj.c create mode 100644 src/aig/aig/aigOper.c create mode 100644 src/aig/aig/aigSeq.c create mode 100644 src/aig/aig/aigTable.c create mode 100644 src/aig/aig/aigUtil.c create mode 100644 src/aig/aig/aig_.c create mode 100644 src/aig/aig/module.make create mode 100644 src/aig/bdc/bdc.h create mode 100644 src/aig/bdc/bdcCore.c create mode 100644 src/aig/bdc/bdcDec.c create mode 100644 src/aig/bdc/bdcInt.h create mode 100644 src/aig/bdc/bdcTable.c create mode 100644 src/aig/bdc/bdc_.c create mode 100644 src/aig/bdc/module.make delete mode 100644 src/aig/dar/darCheck.c delete mode 100644 src/aig/dar/darDfs.c create mode 100644 src/aig/dar/darInt.h delete mode 100644 src/aig/dar/darMem.c delete mode 100644 src/aig/dar/darObj.c delete mode 100644 src/aig/dar/darOper.c delete mode 100644 src/aig/dar/darSeq.c delete mode 100644 src/aig/dar/darTable.c delete mode 100644 src/aig/dar/darUtil.c create mode 100644 src/aig/kit/kit.h create mode 100644 src/aig/kit/kitBdd.c create mode 100644 src/aig/kit/kitDsd.c create mode 100644 src/aig/kit/kitFactor.c create mode 100644 src/aig/kit/kitGraph.c create mode 100644 src/aig/kit/kitHop.c create mode 100644 src/aig/kit/kitIsop.c create mode 100644 src/aig/kit/kitSop.c create mode 100644 src/aig/kit/kitTruth.c create mode 100644 src/aig/kit/kit_.c create mode 100644 src/aig/kit/module.make (limited to 'src/aig') diff --git a/src/aig/aig/aig.h b/src/aig/aig/aig.h new file mode 100644 index 00000000..4d9f9819 --- /dev/null +++ b/src/aig/aig/aig.h @@ -0,0 +1,373 @@ +/**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 +#include +#include +#include +#include + +#include "vec.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 +{ + void * pData; // misc (cuts, copy, etc) + Aig_Obj_t * pNext; // strashing table + Aig_Obj_t * pFanin0; // fanin + Aig_Obj_t * pFanin1; // fanin + unsigned long Type : 3; // object type + unsigned long fPhase : 1; // value under 000...0 pattern + unsigned long fMarkA : 1; // multipurpose mask + unsigned long fMarkB : 1; // multipurpose mask + unsigned long 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 +}; + +// the AIG manager +struct Aig_Man_t_ +{ + // 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) + Aig_Obj_t * pConst1; // the constant 1 node + Aig_Obj_t Ghost; // the ghost node + // 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 + // various data members + Aig_MmFixed_t * pMemObjs; // memory manager for objects + Vec_Int_t * vRequired; // the required times + int nLevelMax; // maximum number of levels + void * pData; // the temporary data + int nTravIds; // the current traversal ID + int fCatchExor; // enables EXOR nodes + // timing statistics + int time1; + int time2; +}; + +//////////////////////////////////////////////////////////////////////// +/// MACRO DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +#define AIG_MIN(a,b) (((a) < (b))? (a) : (b)) +#define AIG_MAX(a,b) (((a) > (b))? (a) : (b)) +#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_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_ObjCutSign( unsigned ObjId ) { return (1 << (ObjId & 31)); } + +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 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_ManObj( Aig_Man_t * p, int i ) { return p->vObjs ? (Aig_Obj_t *)Vec_PtrEntry(p->vObjs, i) : NULL; } + +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_ManObjIdMax( Aig_Man_t * p ) { return Vec_PtrSize(p->vObjs); } + +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_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_ObjTravId( Aig_Obj_t * pObj ) { return (int)pObj->pData; } +static inline int Aig_ObjPhase( Aig_Obj_t * pObj ) { return pObj->fPhase; } +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_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 int Aig_ObjLevel( Aig_Obj_t * pObj ) { return pObj->nRefs; } +static inline int Aig_ObjLevelNew( Aig_Obj_t * pObj ) { return 1 + Aig_ObjIsExor(pObj) + AIG_MAX(Aig_ObjFanin0(pObj)->Level, Aig_ObjFanin1(pObj)->Level); } +static inline int Aig_ObjFaninPhase( Aig_Obj_t * pObj ) { return Aig_Regular(pObj)->fPhase ^ Aig_IsComplement(pObj); } +static inline void Aig_ObjClean( Aig_Obj_t * pObj ) { memset( pObj, 0, sizeof(Aig_Obj_t) ); } +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 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 + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/*=== aigCheck.c ========================================================*/ +extern int Aig_ManCheck( Aig_Man_t * p ); +/*=== aigDfs.c ==========================================================*/ +extern Vec_Ptr_t * Aig_ManDfs( Aig_Man_t * p ); +extern Vec_Ptr_t * Aig_ManDfsNodes( Aig_Man_t * p, Aig_Obj_t ** ppNodes, int nNodes ); +extern int Aig_ManCountLevels( Aig_Man_t * p ); +extern void Aig_ManCreateRefs( Aig_Man_t * p ); +extern int Aig_DagSize( 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 ); +/*=== aigMan.c ==========================================================*/ +extern Aig_Man_t * Aig_ManStart(); +extern Aig_Man_t * Aig_ManStartFrom( Aig_Man_t * p ); +extern Aig_Man_t * Aig_ManDup( Aig_Man_t * p ); +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 ); +/*=== 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 ); +/*=== 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_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 ); +/*=== aigSeq.c ========================================================*/ +extern int Aig_ManSeqStrash( Aig_Man_t * p, int nLatches, int * pInits ); +/*=== aigTable.c ========================================================*/ +extern Aig_Obj_t * Aig_TableLookup( Aig_Man_t * p, Aig_Obj_t * pGhost ); +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 ); +/*=== 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_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_ManDumpBlif( Aig_Man_t * p, char * pFileName ); + +/*=== 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/aig/aig/aigCheck.c b/src/aig/aig/aigCheck.c new file mode 100644 index 00000000..1a8f108e --- /dev/null +++ b/src/aig/aig/aigCheck.c @@ -0,0 +1,121 @@ +/**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; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aigDfs.c b/src/aig/aig/aigDfs.c new file mode 100644 index 00000000..0f2d9401 --- /dev/null +++ b/src/aig/aig/aigDfs.c @@ -0,0 +1,381 @@ +/**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 ) +{ + assert( !Aig_IsComplement(pObj) ); + if ( pObj == NULL ) + return; + 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_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 [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)->pData = NULL; + Aig_ManForEachPi( p, pObj, i ) + pObj->pData = NULL; + // compute levels in a DFS order + vNodes = Aig_ManDfs( p ); + Vec_PtrForEachEntry( vNodes, pObj, i ) + { + Level0 = (int)Aig_ObjFanin0(pObj)->pData; + Level1 = (int)Aig_ObjFanin1(pObj)->pData; + pObj->pData = (void *)(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, (int)Aig_ObjFanin0(pObj)->pData ); + 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 [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) ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aigMan.c b/src/aig/aig/aigMan.c new file mode 100644 index 00000000..1b0ea548 --- /dev/null +++ b/src/aig/aig/aigMan.c @@ -0,0 +1,224 @@ +/**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" + +//////////////////////////////////////////////////////////////////////// +/// 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 ); + // 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_ManObjIdMax(p) + 1 ); + // 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.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Aig_Man_t * Aig_ManDup( Aig_Man_t * p ) +{ + Aig_Man_t * pNew; + Aig_Obj_t * pObj; + int i; + // create the new manager + pNew = Aig_ManStart( Aig_ManObjIdMax(p) + 1 ); + // create the PIs + Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); + Aig_ManForEachPi( p, pObj, i ) + pObj->pData = Aig_ObjCreatePi(pNew); + // 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) ); + // 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; + // print time + if ( p->time1 ) { PRT( "time1", p->time1 ); } + if ( p->time2 ) { PRT( "time2", p->time2 ); } + // 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->vRequired ) Vec_IntFree( p->vRequired ); + 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 = %6d. ", Aig_ManAndNum(p) ); + if ( Aig_ManExorNum(p) ) + printf( "X = %5d. ", Aig_ManExorNum(p) ); +// if ( Aig_ManBufNum(p) ) + printf( "B = %3d. ", Aig_ManBufNum(p) ); + printf( "Cre = %6d. ", p->nCreated ); + printf( "Del = %6d. ", p->nDeleted ); +// printf( "Lev = %3d. ", Aig_ManCountLevels(p) ); + printf( "\n" ); +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aigMem.c b/src/aig/aig/aigMem.c new file mode 100644 index 00000000..20663e6f --- /dev/null +++ b/src/aig/aig/aigMem.c @@ -0,0 +1,597 @@ +/**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; + + // 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<nMapSize = (4<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<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/aig/aig/aigObj.c b/src/aig/aig/aigObj.c new file mode 100644 index 00000000..a261ab40 --- /dev/null +++ b/src/aig/aig/aigObj.c @@ -0,0 +1,308 @@ +/**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 ); + // add connections + Aig_ObjConnect( p, pObj, pDriver, NULL ); + // update node counters of the manager + 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 ); + 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 ( pFan1 != NULL ) + { + assert( Aig_ObjFanin1(pObj)->Type > 0 ); + Aig_ObjRef( Aig_ObjFanin1(pObj) ); + } + // set level and phase + if ( pFan1 != NULL ) + { + pObj->Level = Aig_ObjLevelNew( pObj ); + pObj->fPhase = Aig_ObjFaninPhase(pFan0) & Aig_ObjFaninPhase(pFan1); + } + else + { + pObj->Level = pFan0->Level; + pObj->fPhase = Aig_ObjFaninPhase(pFan0); + } + // add the node to the structural hash table + if ( Aig_ObjIsHash(pObj) ) + Aig_TableInsert( p, pObj ); +} + +/**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 ) + Aig_ObjDeref(Aig_ObjFanin0(pObj)); + if ( pObj->pFanin1 != NULL ) + 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; +} + +/**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 ); + 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) ); + pFaninOld = Aig_ObjFanin0(pObj); + // decrement ref and remove fanout + Aig_ObjDeref( pFaninOld ); + // update the fanin + pObj->pFanin0 = pFaninNew; + // increment ref and add fanout + Aig_ObjRef( Aig_Regular(pFaninNew) ); + // 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 one object by another.] + + Description [Both objects are currently in the manager. 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.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Aig_ObjReplace( Aig_Man_t * p, Aig_Obj_t * pObjOld, Aig_Obj_t * pObjNew, int fNodesOnly ) +{ + 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) ); + // 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 ); + } + else + { + Aig_Obj_t * pFanin0 = pObjNew->pFanin0; + Aig_Obj_t * pFanin1 = pObjNew->pFanin1; + pObjOld->Type = pObjNew->Type; + Aig_ObjDisconnect( p, pObjNew ); + Aig_ObjConnect( p, pObjOld, pFanin0, pFanin1 ); + Aig_ObjDelete( p, pObjNew ); + } + p->nObjs[pObjOld->Type]++; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aigOper.c b/src/aig/aig/aigOper.c new file mode 100644 index 00000000..55ab5862 --- /dev/null +++ b/src/aig/aig/aigOper.c @@ -0,0 +1,429 @@ +/**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; + // 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 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 ); + // go through the cubes of the node's SOP + 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 [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/aig/aig/aigSeq.c b/src/aig/aig/aigSeq.c new file mode 100644 index 00000000..98b7d195 --- /dev/null +++ b/src/aig/aig/aigSeq.c @@ -0,0 +1,497 @@ +/**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; + // 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 ); + } + // 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 ); + 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 ); + 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 ); + } + 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 ); + } + } + 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/aig/aig/aigTable.c b/src/aig/aig/aigTable.c new file mode 100644 index 00000000..e8cfb480 --- /dev/null +++ b/src/aig/aig/aigTable.c @@ -0,0 +1,279 @@ +/**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 ^= (long)Aig_ObjFanin0(pObj) * 7937; + Key ^= (long)Aig_ObjFanin1(pObj) * 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; +} + +static void Aig_TableResize( Aig_Man_t * p ); +static unsigned int Cudd_PrimeAig( unsigned int p ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**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 [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; + 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; + 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 [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, nEntries, i, clk; +clk = clock(); + // save the old table + pTableOld = p->pTable; + nTableSizeOld = p->nTableSize; + // get the new table + p->nTableSize = Cudd_PrimeAig( 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++; + } + nEntries = Aig_ManNodeNum(p); + assert( Counter == nEntries ); + 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 [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 [Returns the next prime >= p.] + + Description [Copied from CUDD, for stand-aloneness.] + + SideEffects [None] + + SeeAlso [] + +******************************************************************************/ +unsigned int Cudd_PrimeAig( 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 */ + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aigUtil.c b/src/aig/aig/aigUtil.c new file mode 100644 index 00000000..1e45bca1 --- /dev/null +++ b/src/aig/aig/aigUtil.c @@ -0,0 +1,642 @@ +/**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 [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? "!" : "", 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? "~" : "", 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 [Writes the AIG into the BLIF file.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Aig_ManDumpBlif( Aig_Man_t * p, char * pFileName ) +{ + FILE * pFile; + Vec_Ptr_t * vNodes; + Aig_Obj_t * pObj, * pConst1 = NULL; + int i, nDigits, Counter = 0; + if ( Aig_ManPoNum(p) == 0 ) + { + printf( "Aig_ManDumpBlif(): AIG manager does not have POs.\n" ); + return; + } + // collect nodes in the DFS order + vNodes = Aig_ManDfs( p ); + // assign IDs to objects + Aig_ManConst1(p)->pData = (void *)Counter++; + Aig_ManForEachPi( p, pObj, i ) + pObj->pData = (void *)Counter++; + Aig_ManForEachPo( p, pObj, i ) + pObj->pData = (void *)Counter++; + Vec_PtrForEachEntry( vNodes, pObj, i ) + pObj->pData = (void *)Counter++; + nDigits = Extra_Base10Log( Counter ); + // write the file + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# BLIF file written by procedure Aig_ManDumpBlif() in ABC\n" ); + fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" ); + fprintf( pFile, ".model test\n" ); + // write PIs + fprintf( pFile, ".inputs" ); + Aig_ManForEachPi( p, pObj, i ) + fprintf( pFile, " n%0*d", nDigits, (int)pObj->pData ); + fprintf( pFile, "\n" ); + // write POs + fprintf( pFile, ".outputs" ); + Aig_ManForEachPo( p, pObj, i ) + fprintf( pFile, " n%0*d", nDigits, (int)pObj->pData ); + fprintf( pFile, "\n" ); + // write nodes + Vec_PtrForEachEntry( vNodes, pObj, i ) + { + fprintf( pFile, ".names n%0*d n%0*d n%0*d\n", + nDigits, (int)Aig_ObjFanin0(pObj)->pData, + nDigits, (int)Aig_ObjFanin1(pObj)->pData, + nDigits, (int)pObj->pData ); + 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, (int)Aig_ObjFanin0(pObj)->pData, + nDigits, (int)pObj->pData ); + fprintf( pFile, "%d 1\n", !Aig_ObjFaninC0(pObj) ); + if ( Aig_ObjIsConst1(Aig_ObjFanin0(pObj)) ) + pConst1 = Aig_ManConst1(p); + } + if ( pConst1 ) + fprintf( pFile, ".names n%0*d\n 1\n", nDigits, (int)pConst1->pData ); + fprintf( pFile, ".end\n\n" ); + fclose( pFile ); + Vec_PtrFree( vNodes ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/aig/aig_.c b/src/aig/aig/aig_.c new file mode 100644 index 00000000..b2313d35 --- /dev/null +++ b/src/aig/aig/aig_.c @@ -0,0 +1,48 @@ +/**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/aig/aig/module.make b/src/aig/aig/module.make new file mode 100644 index 00000000..f1e83fe6 --- /dev/null +++ b/src/aig/aig/module.make @@ -0,0 +1,9 @@ +SRC += src/aig/aig/aigCheck.c \ + src/aig/aig/aigDfs.c \ + src/aig/aig/aigMan.c \ + src/aig/aig/aigMem.c \ + src/aig/aig/aigObj.c \ + src/aig/aig/aigOper.c \ + src/aig/aig/aigSeq.c \ + src/aig/aig/aigTable.c \ + src/aig/aig/aigUtil.c diff --git a/src/aig/bdc/bdc.h b/src/aig/bdc/bdc.h new file mode 100644 index 00000000..71875edb --- /dev/null +++ b/src/aig/bdc/bdc.h @@ -0,0 +1,73 @@ +/**CFile**************************************************************** + + FileName [bdc.h] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [External declarations.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 30, 2007.] + + Revision [$Id: bdc.h,v 1.00 2007/01/30 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#ifndef __BDC_H__ +#define __BDC_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//////////////////////////////////////////////////////////////////////// +/// INCLUDES /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// PARAMETERS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// BASIC TYPES /// +//////////////////////////////////////////////////////////////////////// + +typedef struct Bdc_Man_t_ Bdc_Man_t; +typedef struct Bdc_Par_t_ Bdc_Par_t; +struct Bdc_Par_t_ +{ + // general parameters + int nVarsMax; // the maximum support + int fVerbose; // enable basic stats + int fVeryVerbose; // enable detailed stats +}; + +//////////////////////////////////////////////////////////////////////// +/// MACRO DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/*=== bdcCore.c ==========================================================*/ +extern Bdc_Man_t * Bdc_ManAlloc( Bdc_Par_t * pPars ); +extern void Bdc_ManFree( Bdc_Man_t * p ); +extern int Bdc_ManDecompose( Bdc_Man_t * p, unsigned * puFunc, unsigned * puCare, int nVars, Vec_Ptr_t * vDivs, int nNodesLimit ); + + +#ifdef __cplusplus +} +#endif + +#endif + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + diff --git a/src/aig/bdc/bdcCore.c b/src/aig/bdc/bdcCore.c new file mode 100644 index 00000000..157927b1 --- /dev/null +++ b/src/aig/bdc/bdcCore.c @@ -0,0 +1,189 @@ +/**CFile**************************************************************** + + FileName [bdcCore.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [The gateway to bi-decomposition.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 30, 2007.] + + Revision [$Id: bdcCore.c,v 1.00 2007/01/30 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "bdcInt.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Allocate resynthesis manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Bdc_Man_t * Bdc_ManAlloc( Bdc_Par_t * pPars ) +{ + Bdc_Man_t * p; + unsigned * pData; + int i, k, nBits; + p = ALLOC( Bdc_Man_t, 1 ); + memset( p, 0, sizeof(Bdc_Man_t) ); + assert( pPars->nVarsMax > 3 && pPars->nVarsMax < 16 ); + p->pPars = pPars; + p->nWords = Kit_TruthWordNum( pPars->nVarsMax ); + p->nDivsLimit = 200; + p->nNodesLimit = 0; // will be set later + // memory + p->vMemory = Vec_IntStart( 1 << 16 ); + // internal nodes + p->nNodesAlloc = 512; + p->pNodes = ALLOC( Bdc_Fun_t, p->nNodesAlloc ); + // set up hash table + p->nTableSize = (1 << p->pPars->nVarsMax); + p->pTable = ALLOC( Bdc_Fun_t *, p->nTableSize ); + memset( p->pTable, 0, sizeof(Bdc_Fun_t *) * p->nTableSize ); + p->vSpots = Vec_IntAlloc( 256 ); + // truth tables + p->vTruths = Vec_PtrAllocSimInfo( pPars->nVarsMax + 5, p->nWords ); + // set elementary truth tables + nBits = (1 << pPars->nVarsMax); + Kit_TruthFill( Vec_PtrEntry(p->vTruths, 0), p->nVars ); + for ( k = 0; k < pPars->nVarsMax; k++ ) + { + pData = Vec_PtrEntry( p->vTruths, k+1 ); + Kit_TruthClear( pData, p->nVars ); + for ( i = 0; i < nBits; i++ ) + if ( i & (1 << k) ) + pData[i>>5] |= (1 << (i&31)); + } + p->puTemp1 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 1 ); + p->puTemp2 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 2 ); + p->puTemp3 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 3 ); + p->puTemp4 = Vec_PtrEntry( p->vTruths, pPars->nVarsMax + 4 ); + // start the internal ISFs + p->pIsfOL = &p->IsfOL; Bdc_IsfStart( p, p->pIsfOL ); + p->pIsfOR = &p->IsfOR; Bdc_IsfStart( p, p->pIsfOR ); + p->pIsfAL = &p->IsfAL; Bdc_IsfStart( p, p->pIsfAL ); + p->pIsfAR = &p->IsfAR; Bdc_IsfStart( p, p->pIsfAR ); + return p; +} + +/**Function************************************************************* + + Synopsis [Deallocate resynthesis manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Bdc_ManFree( Bdc_Man_t * p ) +{ + Vec_IntFree( p->vMemory ); + Vec_IntFree( p->vSpots ); + Vec_PtrFree( p->vTruths ); + free( p->pNodes ); + free( p->pTable ); + free( p ); +} + +/**Function************************************************************* + + Synopsis [Clears the manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Bdc_ManPrepare( Bdc_Man_t * p, Vec_Ptr_t * vDivs ) +{ + unsigned * puTruth; + Bdc_Fun_t * pNode; + int i; + Bdc_TableClear( p ); + Vec_IntClear( p->vMemory ); + // add constant 1 and elementary vars + p->nNodes = p->nNodesNew = 0; + for ( i = 0; i <= p->pPars->nVarsMax; i++ ) + { + pNode = Bdc_FunNew( p ); + pNode->Type = BDC_TYPE_PI; + pNode->puFunc = Vec_PtrEntry( p->vTruths, i ); + pNode->uSupp = i? (1 << (i-1)) : 0; + Bdc_TableAdd( p, pNode ); + } + // add the divisors + Vec_PtrForEachEntry( vDivs, puTruth, i ) + { + pNode = Bdc_FunNew( p ); + pNode->Type = BDC_TYPE_PI; + pNode->puFunc = puTruth; + pNode->uSupp = Kit_TruthSupport( puTruth, p->nVars ); + Bdc_TableAdd( p, pNode ); + if ( i == p->nDivsLimit ) + break; + } +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of one function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_ManDecompose( Bdc_Man_t * p, unsigned * puFunc, unsigned * puCare, int nVars, Vec_Ptr_t * vDivs, int nNodesMax ) +{ + Bdc_Isf_t Isf, * pIsf = &Isf; + // set current manager parameters + p->nVars = nVars; + p->nWords = Kit_TruthWordNum( nVars ); + Bdc_ManPrepare( p, vDivs ); + p->nNodesLimit = (p->nNodes + nNodesMax < p->nNodesAlloc)? p->nNodes + nNodesMax : p->nNodesAlloc; + // copy the function + Bdc_IsfStart( p, pIsf ); + Bdc_IsfClean( pIsf ); + pIsf->uSupp = Kit_TruthSupport( puFunc, p->nVars ) | Kit_TruthSupport( puCare, p->nVars ); + Kit_TruthAnd( pIsf->puOn, puCare, puFunc, p->nVars ); + Kit_TruthSharp( pIsf->puOff, puCare, puFunc, p->nVars ); + // call decomposition + Bdc_SuppMinimize( p, pIsf ); + p->pRoot = Bdc_ManDecompose_rec( p, pIsf ); + if ( p->pRoot == NULL ) + return -1; + return p->nNodesNew; +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/bdc/bdcDec.c b/src/aig/bdc/bdcDec.c new file mode 100644 index 00000000..747fcb14 --- /dev/null +++ b/src/aig/bdc/bdcDec.c @@ -0,0 +1,461 @@ +/**CFile**************************************************************** + + FileName [bdcDec.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [Decomposition procedures.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 30, 2007.] + + Revision [$Id: bdcDec.c,v 1.00 2007/01/30 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "bdcInt.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static Bdc_Type_t Bdc_DecomposeStep( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR ); +static int Bdc_DecomposeUpdateRight( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR, unsigned * puTruth, Bdc_Type_t Type ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Performs one step of bi-decomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Bdc_Fun_t * Bdc_ManDecompose_rec( Bdc_Man_t * p, Bdc_Isf_t * pIsf ) +{ + Bdc_Fun_t * pFunc; + Bdc_Isf_t IsfL, * pIsfL = &IsfL; + Bdc_Isf_t IsfB, * pIsfR = &IsfB; + // check computed results + if ( pFunc = Bdc_TableLookup( p, pIsf ) ) + return pFunc; + // decide on the decomposition type + pFunc = Bdc_FunNew( p ); + if ( pFunc == NULL ) + return NULL; + pFunc->Type = Bdc_DecomposeStep( p, pIsf, pIsfL, pIsfR ); + // decompose the left branch + pFunc->pFan0 = Bdc_ManDecompose_rec( p, pIsfL ); + if ( pFunc->pFan0 == NULL ) + return NULL; + // decompose the right branch + if ( Bdc_DecomposeUpdateRight( p, pIsf, pIsfL, pIsfR, pFunc->pFan0->puFunc, pFunc->Type ) ) + { + p->nNodes--; + return pFunc->pFan0; + } + pFunc->pFan1 = Bdc_ManDecompose_rec( p, pIsfL ); + if ( pFunc->pFan1 == NULL ) + return NULL; + // compute the function of node + pFunc->puFunc = (unsigned *)Vec_IntFetch(p->vMemory, p->nWords); + if ( pFunc->Type == BDC_TYPE_AND ) + Kit_TruthAnd( pFunc->puFunc, pFunc->pFan0->puFunc, pFunc->pFan1->puFunc, p->nVars ); + else if ( pFunc->Type == BDC_TYPE_OR ) + Kit_TruthOr( pFunc->puFunc, pFunc->pFan0->puFunc, pFunc->pFan1->puFunc, p->nVars ); + else + assert( 0 ); + // verify correctness + assert( Bdc_TableCheckContainment(p, pIsf, pFunc->puFunc) ); + // convert from OR to AND + if ( pFunc->Type == BDC_TYPE_OR ) + { + pFunc->Type = BDC_TYPE_AND; + pFunc->pFan0 = Bdc_Not(pFunc->pFan0); + pFunc->pFan1 = Bdc_Not(pFunc->pFan1); + Kit_TruthNot( pFunc->puFunc, pFunc->puFunc, p->nVars ); + pFunc = Bdc_Not(pFunc); + } + Bdc_TableAdd( p, Bdc_Regular(pFunc) ); + return pFunc; +} + +/**Function************************************************************* + + Synopsis [Updates the ISF of the right after the left was decompoosed.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_DecomposeUpdateRight( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR, unsigned * puTruth, Bdc_Type_t Type ) +{ + if ( Type == BDC_TYPE_OR ) + { +// Right.Q = bdd_appex( Q, CompSpecLeftF, bddop_diff, setRightRes ); +// Right.R = bdd_exist( R, setRightRes ); + +// if ( pR->Q ) Cudd_RecursiveDeref( dd, pR->Q ); +// if ( pR->R ) Cudd_RecursiveDeref( dd, pR->R ); +// pR->Q = Cudd_bddAndAbstract( dd, pF->Q, Cudd_Not(CompSpecF), pL->V ); Cudd_Ref( pR->Q ); +// pR->R = Cudd_bddExistAbstract( dd, pF->R, pL->V ); Cudd_Ref( pR->R ); + +// assert( pR->R != b0 ); +// return (int)( pR->Q == b0 ); + + Kit_TruthSharp( pIsfR->puOn, pIsf->puOn, puTruth, p->nVars ); + Kit_TruthExistSet( pIsfR->puOn, pIsfR->puOn, p->nVars, pIsfL->uSupp ); + Kit_TruthExistSet( pIsfR->puOff, pIsf->puOff, p->nVars, pIsfL->uSupp ); + assert( !Kit_TruthIsConst0(pIsfR->puOff, p->nVars) ); + return Kit_TruthIsConst0(pIsfR->puOn, p->nVars); + } + else if ( Type == BDC_TYPE_AND ) + { +// Right.R = bdd_appex( R, CompSpecLeftF, bddop_and, setRightRes ); +// Right.Q = bdd_exist( Q, setRightRes ); + +// if ( pR->Q ) Cudd_RecursiveDeref( dd, pR->Q ); +// if ( pR->R ) Cudd_RecursiveDeref( dd, pR->R ); +// pR->R = Cudd_bddAndAbstract( dd, pF->R, CompSpecF, pL->V ); Cudd_Ref( pR->R ); +// pR->Q = Cudd_bddExistAbstract( dd, pF->Q, pL->V ); Cudd_Ref( pR->Q ); + +// assert( pR->Q != b0 ); +// return (int)( pR->R == b0 ); + + Kit_TruthSharp( pIsfR->puOn, pIsf->puOn, puTruth, p->nVars ); + Kit_TruthExistSet( pIsfR->puOn, pIsfR->puOn, p->nVars, pIsfL->uSupp ); + Kit_TruthExistSet( pIsfR->puOff, pIsf->puOff, p->nVars, pIsfL->uSupp ); + assert( !Kit_TruthIsConst0(pIsfR->puOff, p->nVars) ); + return Kit_TruthIsConst0(pIsfR->puOn, p->nVars); + } + return 0; +} + +/**Function************************************************************* + + Synopsis [Checks existence of OR-bidecomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Bdc_DecomposeGetCost( Bdc_Man_t * p, int nLeftVars, int nRightVars ) +{ + assert( nLeftVars > 0 ); + assert( nRightVars > 0 ); + // compute the decomposition coefficient + if ( nLeftVars >= nRightVars ) + return BDC_SCALE * (p->nVars * nRightVars + nLeftVars); + else // if ( nLeftVars < nRightVars ) + return BDC_SCALE * (p->nVars * nLeftVars + nRightVars); +} + +/**Function************************************************************* + + Synopsis [Checks existence of weak OR-bidecomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_DecomposeFindInitialVarSet( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR ) +{ + char pVars[16]; + int v, nVars, Beg, End; + + assert( pIsfL->uSupp == 0 ); + assert( pIsfR->uSupp == 0 ); + + // fill in the variables + nVars = 0; + for ( v = 0; v < p->nVars; v++ ) + if ( pIsf->uSupp & (1 << v) ) + pVars[nVars++] = v; + + // try variable pairs + for ( Beg = 0; Beg < nVars; Beg++ ) + { + Kit_TruthExistNew( p->puTemp1, pIsf->puOff, p->nVars, pVars[Beg] ); + for ( End = nVars - 1; End > Beg; End-- ) + { + Kit_TruthExistNew( p->puTemp2, pIsf->puOff, p->nVars, pVars[End] ); + if ( Kit_TruthIsDisjoint3(pIsf->puOn, p->puTemp1, p->puTemp2, p->nVars) ) + { + pIsfL->uSupp = (1 << Beg); + pIsfR->uSupp = (1 << End); + pIsfL->Var = Beg; + pIsfR->Var = End; + return 1; + } + } + } + return 0; +} + +/**Function************************************************************* + + Synopsis [Checks existence of weak OR-bidecomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_DecomposeWeakOr( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR ) +{ + int v, VarCost, VarBest, Cost, VarCostBest = 0; + + for ( v = 0; v < p->nVars; v++ ) + { + Kit_TruthExistNew( p->puTemp1, pIsf->puOff, p->nVars, v ); +// if ( (Q & !bdd_exist( R, VarSetXa )) != bddfalse ) +// Exist = Cudd_bddExistAbstract( dd, pF->R, Var ); Cudd_Ref( Exist ); +// if ( Cudd_bddIteConstant( dd, pF->Q, Cudd_Not(Exist), b0 ) != b0 ) + if ( !Kit_TruthIsImply( pIsf->puOn, p->puTemp1, p->nVars ) ) + { + // measure the cost of this variable +// VarCost = bdd_satcountset( bdd_forall( Q, VarSetXa ), VarCube ); + +// Univ = Cudd_bddUnivAbstract( dd, pF->Q, Var ); Cudd_Ref( Univ ); +// VarCost = Kit_TruthCountOnes( Univ, p->nVars ); +// Cudd_RecursiveDeref( dd, Univ ); + + Kit_TruthForallNew( p->puTemp2, pIsf->puOn, p->nVars, v ); + VarCost = Kit_TruthCountOnes( p->puTemp2, p->nVars ); + if ( VarCost == 0 ) + VarCost = 1; + if ( VarCostBest < VarCost ) + { + VarCostBest = VarCost; + VarBest = v; + } + } + } + + // derive the components for weak-bi-decomposition if the variable is found + if ( VarCostBest ) + { +// funQLeftRes = Q & bdd_exist( R, setRightORweak ); + +// Temp = Cudd_bddExistAbstract( dd, pF->R, VarBest ); Cudd_Ref( Temp ); +// pL->Q = Cudd_bddAnd( dd, pF->Q, Temp ); Cudd_Ref( pL->Q ); +// Cudd_RecursiveDeref( dd, Temp ); + + Kit_TruthExistNew( p->puTemp1, pIsf->puOff, p->nVars, VarBest ); + Kit_TruthAnd( pIsfL->puOn, pIsf->puOn, p->puTemp1, p->nVars ); + +// pL->R = pF->R; Cudd_Ref( pL->R ); +// pL->V = VarBest; Cudd_Ref( pL->V ); + Kit_TruthCopy( pIsfL->puOff, pIsf->puOff, p->nVars ); + pIsfL->Var = VarBest; + +// assert( pL->Q != b0 ); +// assert( pL->R != b0 ); +// assert( Cudd_bddIteConstant( dd, pL->Q, pL->R, b0 ) == b0 ); + + // express cost in percents of the covered boolean space + Cost = VarCostBest * BDC_SCALE / (1<nVars); + if ( Cost == 0 ) + Cost = 1; + return Cost; + } + return 0; +} + +/**Function************************************************************* + + Synopsis [Checks existence of OR-bidecomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_DecomposeOr( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR ) +{ + unsigned uSuppRem; + int v, nLeftVars = 1, nRightVars = 1; + // clean the var sets + Bdc_IsfClean( pIsfL ); + Bdc_IsfClean( pIsfR ); + // find initial variable sets + if ( !Bdc_DecomposeFindInitialVarSet( p, pIsf, pIsfL, pIsfR ) ) + return Bdc_DecomposeWeakOr( p, pIsf, pIsfL, pIsfR ); + // prequantify the variables in the offset + Kit_TruthExistNew( p->puTemp1, pIsf->puOff, p->nVars, pIsfL->Var ); + Kit_TruthExistNew( p->puTemp2, pIsf->puOff, p->nVars, pIsfR->Var ); + // go through the remaining variables + uSuppRem = pIsf->uSupp & ~pIsfL->uSupp & ~pIsfR->uSupp; + assert( Kit_WordCountOnes(uSuppRem) > 0 ); + for ( v = 0; v < p->nVars; v++ ) + { + if ( (uSuppRem & (1 << v)) == 0 ) + continue; + // prequantify this variable + Kit_TruthExistNew( p->puTemp3, p->puTemp1, p->nVars, v ); + Kit_TruthExistNew( p->puTemp4, p->puTemp2, p->nVars, v ); + if ( nLeftVars < nRightVars ) + { +// if ( (Q & bdd_exist( pF->R, pL->V & VarNew ) & bdd_exist( pF->R, pR->V )) == bddfalse ) +// if ( VerifyORCondition( dd, pF->Q, pF->R, pL->V, pR->V, VarNew ) ) + if ( Kit_TruthIsDisjoint3(pIsf->puOn, p->puTemp3, p->puTemp2, p->nVars) ) + { +// pL->V &= VarNew; + pIsfL->uSupp |= (1 << v); + nLeftVars++; + } +// else if ( (Q & bdd_exist( pF->R, pR->V & VarNew ) & bdd_exist( pF->R, pL->V )) == bddfalse ) + else if ( Kit_TruthIsDisjoint3(pIsf->puOn, p->puTemp4, p->puTemp1, p->nVars) ) + { +// pR->V &= VarNew; + pIsfR->uSupp |= (1 << v); + nRightVars++; + } + } + else + { +// if ( (Q & bdd_exist( pF->R, pR->V & VarNew ) & bdd_exist( pF->R, pL->V )) == bddfalse ) + if ( Kit_TruthIsDisjoint3(pIsf->puOn, p->puTemp4, p->puTemp1, p->nVars) ) + { +// pR->V &= VarNew; + pIsfR->uSupp |= (1 << v); + nRightVars++; + } +// else if ( (Q & bdd_exist( pF->R, pL->V & VarNew ) & bdd_exist( pF->R, pR->V )) == bddfalse ) + else if ( Kit_TruthIsDisjoint3(pIsf->puOn, p->puTemp3, p->puTemp2, p->nVars) ) + { +// pL->V &= VarNew; + pIsfL->uSupp |= (1 << v); + nLeftVars++; + } + } + } + + // derive the functions Q and R for the left branch +// pL->Q = bdd_appex( pF->Q, bdd_exist( pF->R, pL->V ), bddop_and, pR->V ); +// pL->R = bdd_exist( pF->R, pR->V ); + +// Temp = Cudd_bddExistAbstract( dd, pF->R, pL->V ); Cudd_Ref( Temp ); +// pL->Q = Cudd_bddAndAbstract( dd, pF->Q, Temp, pR->V ); Cudd_Ref( pL->Q ); +// Cudd_RecursiveDeref( dd, Temp ); +// pL->R = Cudd_bddExistAbstract( dd, pF->R, pR->V ); Cudd_Ref( pL->R ); + + Kit_TruthAnd( pIsfL->puOn, pIsf->puOn, p->puTemp1, p->nVars ); + Kit_TruthExistSet( pIsfL->puOn, pIsfL->puOn, p->nVars, pIsfR->uSupp ); + Kit_TruthCopy( pIsfL->puOff, p->puTemp2, p->nVars ); + + // derive the functions Q and R for the right branch +// Temp = Cudd_bddExistAbstract( dd, pF->R, pR->V ); Cudd_Ref( Temp ); +// pR->Q = Cudd_bddAndAbstract( dd, pF->Q, Temp, pL->V ); Cudd_Ref( pR->Q ); +// Cudd_RecursiveDeref( dd, Temp ); +// pR->R = Cudd_bddExistAbstract( dd, pF->R, pL->V ); Cudd_Ref( pR->R ); + +/* + Kit_TruthAnd( pIsfR->puOn, pIsf->puOn, p->puTemp2, p->nVars ); + Kit_TruthExistSet( pIsfR->puOn, pIsfR->puOn, p->nVars, pIsfL->uSupp ); + Kit_TruthCopy( pIsfR->puOff, p->puTemp1, p->nVars ); +*/ + +// assert( pL->Q != b0 ); +// assert( pL->R != b0 ); +// assert( Cudd_bddIteConstant( dd, pL->Q, pL->R, b0 ) == b0 ); + assert( !Kit_TruthIsConst0(pIsfL->puOn, p->nVars) ); + assert( !Kit_TruthIsConst0(pIsfL->puOff, p->nVars) ); + assert( Kit_TruthIsDisjoint(pIsfL->puOn, pIsfL->puOff, p->nVars) ); + + return Bdc_DecomposeGetCost( p, nLeftVars, nRightVars ); +} + +/**Function************************************************************* + + Synopsis [Performs one step of bi-decomposition.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Bdc_Type_t Bdc_DecomposeStep( Bdc_Man_t * p, Bdc_Isf_t * pIsf, Bdc_Isf_t * pIsfL, Bdc_Isf_t * pIsfR ) +{ + int CostOr, CostAnd, CostOrL, CostOrR, CostAndL, CostAndR; + + Bdc_IsfClean( p->pIsfOL ); + Bdc_IsfClean( p->pIsfOR ); + Bdc_IsfClean( p->pIsfAL ); + Bdc_IsfClean( p->pIsfAR ); + + // perform OR decomposition + CostOr = Bdc_DecomposeOr( p, pIsf, p->pIsfOL, p->pIsfOR ); + + // perform AND decomposition + Bdc_IsfNot( pIsf ); + CostAnd = Bdc_DecomposeOr( p, pIsf, p->pIsfAL, p->pIsfAR ); + Bdc_IsfNot( pIsf ); + Bdc_IsfNot( p->pIsfAL ); + Bdc_IsfNot( p->pIsfAR ); + + // check the hash table + Bdc_SuppMinimize( p, p->pIsfOL ); + CostOrL = (Bdc_TableLookup(p, p->pIsfOL) != NULL); + Bdc_SuppMinimize( p, p->pIsfOR ); + CostOrR = (Bdc_TableLookup(p, p->pIsfOR) != NULL); + Bdc_SuppMinimize( p, p->pIsfAL ); + CostAndL = (Bdc_TableLookup(p, p->pIsfAL) != NULL); + Bdc_SuppMinimize( p, p->pIsfAR ); + CostAndR = (Bdc_TableLookup(p, p->pIsfAR) != NULL); + + // check if there is any reuse for the components + if ( CostOrL + CostOrR < CostAndL + CostAndR ) + { + Bdc_IsfCopy( pIsfL, p->pIsfOL ); + Bdc_IsfCopy( pIsfR, p->pIsfOR ); + return BDC_TYPE_OR; + } + if ( CostOrL + CostOrR > CostAndL + CostAndR ) + { + Bdc_IsfCopy( pIsfL, p->pIsfAL ); + Bdc_IsfCopy( pIsfR, p->pIsfAR ); + return BDC_TYPE_AND; + } + + // compare the two-component costs + if ( CostOr < CostAnd ) + { + Bdc_IsfCopy( pIsfL, p->pIsfOL ); + Bdc_IsfCopy( pIsfR, p->pIsfOR ); + return BDC_TYPE_OR; + } + return BDC_TYPE_AND; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/bdc/bdcInt.h b/src/aig/bdc/bdcInt.h new file mode 100644 index 00000000..65ab9d27 --- /dev/null +++ b/src/aig/bdc/bdcInt.h @@ -0,0 +1,151 @@ +/**CFile**************************************************************** + + FileName [bdcInt.h] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [Internal declarations.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 15, 2007.] + + Revision [$Id: resInt.h,v 1.00 2007/01/15 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#ifndef __BDC_INT_H__ +#define __BDC_INT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//////////////////////////////////////////////////////////////////////// +/// INCLUDES /// +//////////////////////////////////////////////////////////////////////// + +#include "kit.h" +#include "bdc.h" + +//////////////////////////////////////////////////////////////////////// +/// PARAMETERS /// +//////////////////////////////////////////////////////////////////////// + +#define BDC_SCALE 100 // value used to compute the cost + +//////////////////////////////////////////////////////////////////////// +/// BASIC TYPES /// +//////////////////////////////////////////////////////////////////////// + +// network types +typedef enum { + BDC_TYPE_NONE = 0, // 0: unknown + BDC_TYPE_CONST1, // 1: constant 1 + BDC_TYPE_PI, // 2: primary input + BDC_TYPE_AND, // 4: AND-gate + BDC_TYPE_OR, // 5: OR-gate (temporary) + BDC_TYPE_XOR, // 6: XOR-gate + BDC_TYPE_MUX, // 7: MUX-gate + BDC_TYPE_OTHER // 8: unused +} Bdc_Type_t; + +typedef struct Bdc_Fun_t_ Bdc_Fun_t; +struct Bdc_Fun_t_ +{ + int Type; // Const1, PI, AND, XOR, MUX + Bdc_Fun_t * pFan0; // fanin of the given node + Bdc_Fun_t * pFan1; // fanin of the given node + Bdc_Fun_t * pFan2; // fanin of the given node + unsigned uSupp; // bit mask of current support + unsigned * puFunc; // the function of the node + Bdc_Fun_t * pNext; // next function with same support + void * pCopy; // the copy field +}; + +typedef struct Bdc_Isf_t_ Bdc_Isf_t; +struct Bdc_Isf_t_ +{ + int Var; // the first variable assigned + unsigned uSupp; // the current support + unsigned * puOn; // on-set + unsigned * puOff; // off-set +}; + +typedef struct Bdc_Man_t_ Bdc_Man_t; +struct Bdc_Man_t_ +{ + // external parameters + Bdc_Par_t * pPars; // parameter set + int nVars; // the number of variables + int nWords; // the number of words + int nNodesLimit; // the limit on the number of new nodes + int nDivsLimit; // the limit on the number of divisors + // internal nodes + Bdc_Fun_t * pNodes; // storage for decomposition nodes + int nNodes; // the number of nodes used + int nNodesNew; // the number of nodes used + int nNodesAlloc; // the number of nodes allocated + Bdc_Fun_t * pRoot; // the root node + // resub candidates + Bdc_Fun_t ** pTable; // hash table of candidates + int nTableSize; // hash table size (1 << nVarsMax) + Vec_Int_t * vSpots; // the occupied spots in the table + // elementary truth tables + Vec_Ptr_t * vTruths; // for const 1 and elementary variables + unsigned * puTemp1; // temporary truth table + unsigned * puTemp2; // temporary truth table + unsigned * puTemp3; // temporary truth table + unsigned * puTemp4; // temporary truth table + // temporary ISFs + Bdc_Isf_t * pIsfOL, IsfOL; + Bdc_Isf_t * pIsfOR, IsfOR; + Bdc_Isf_t * pIsfAL, IsfAL; + Bdc_Isf_t * pIsfAR, IsfAR; + // internal memory manager + Vec_Int_t * vMemory; // memory for internal truth tables +}; + +// working with complemented attributes of objects +static inline int Bdc_IsComplement( Bdc_Fun_t * p ) { return (int)((unsigned long)p & (unsigned long)01); } +static inline Bdc_Fun_t * Bdc_Regular( Bdc_Fun_t * p ) { return (Bdc_Fun_t *)((unsigned long)p & ~(unsigned long)01); } +static inline Bdc_Fun_t * Bdc_Not( Bdc_Fun_t * p ) { return (Bdc_Fun_t *)((unsigned long)p ^ (unsigned long)01); } +static inline Bdc_Fun_t * Bdc_NotCond( Bdc_Fun_t * p, int c ) { return (Bdc_Fun_t *)((unsigned long)p ^ (unsigned long)(c!=0)); } + +static inline Bdc_Fun_t * Bdc_FunNew( Bdc_Man_t * p ) { Bdc_Fun_t * pRes; if ( p->nNodes == p->nNodesLimit ) return NULL; pRes = p->pNodes + p->nNodes++; memset( pRes, 0, sizeof(Bdc_Fun_t) ); p->nNodesNew++; return pRes; } +static inline void Bdc_IsfStart( Bdc_Man_t * p, Bdc_Isf_t * pF ) { pF->puOn = Vec_IntFetch( p->vMemory, p->nWords ); pF->puOff = Vec_IntFetch( p->vMemory, p->nWords ); } +static inline void Bdc_IsfClean( Bdc_Isf_t * p ) { p->uSupp = 0; p->Var = 0; } +static inline void Bdc_IsfCopy( Bdc_Isf_t * p, Bdc_Isf_t * q ) { Bdc_Isf_t T = *p; *p = *q; *q = T; } +static inline void Bdc_IsfNot( Bdc_Isf_t * p ) { unsigned * puT = p->puOn; p->puOn = p->puOff; p->puOff = puT; } + +//////////////////////////////////////////////////////////////////////// +/// MACRO DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/*=== bdcDec.c ==========================================================*/ +extern Bdc_Fun_t * Bdc_ManDecompose_rec( Bdc_Man_t * p, Bdc_Isf_t * pIsf ); +/*=== bdcTable.c ==========================================================*/ +extern Bdc_Fun_t * Bdc_TableLookup( Bdc_Man_t * p, Bdc_Isf_t * pIsf ); +extern void Bdc_TableAdd( Bdc_Man_t * p, Bdc_Fun_t * pFunc ); +extern void Bdc_TableClear( Bdc_Man_t * p ); +extern void Bdc_SuppMinimize( Bdc_Man_t * p, Bdc_Isf_t * pIsf ); +extern int Bdc_TableCheckContainment( Bdc_Man_t * p, Bdc_Isf_t * pIsf, unsigned * puTruth ); + +#ifdef __cplusplus +} +#endif + +#endif + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + diff --git a/src/aig/bdc/bdcTable.c b/src/aig/bdc/bdcTable.c new file mode 100644 index 00000000..d86a938d --- /dev/null +++ b/src/aig/bdc/bdcTable.c @@ -0,0 +1,140 @@ +/**CFile**************************************************************** + + FileName [bdcTable.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [Hash table for intermediate nodes.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 30, 2007.] + + Revision [$Id: bdcTable.c,v 1.00 2007/01/30 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "bdcInt.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Minimizes the support of the ISF.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Bdc_SuppMinimize( Bdc_Man_t * p, Bdc_Isf_t * pIsf ) +{ + int v; + // go through the support variables + for ( v = 0; v < p->nVars; v++ ) + { + if ( (pIsf->uSupp & (1 << v)) == 0 ) + continue; + Kit_TruthExistNew( p->puTemp1, pIsf->puOn, p->nVars, v ); + Kit_TruthExistNew( p->puTemp2, pIsf->puOff, p->nVars, v ); + if ( !Kit_TruthIsDisjoint( p->puTemp1, p->puTemp2, p->nVars ) ) + continue; + // remove the variable + Kit_TruthCopy( pIsf->puOn, p->puTemp1, p->nVars ); + Kit_TruthCopy( pIsf->puOff, p->puTemp2, p->nVars ); + pIsf->uSupp &= ~(1 << v); + } +} + +/**Function************************************************************* + + Synopsis [Checks containment of the function in the ISF.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Bdc_TableCheckContainment( Bdc_Man_t * p, Bdc_Isf_t * pIsf, unsigned * puTruth ) +{ + return Kit_TruthIsImply( pIsf->puOn, puTruth, p->nVars ) && + Kit_TruthIsDisjoint( pIsf->puOff, puTruth, p->nVars ); +} + +/**Function************************************************************* + + Synopsis [Adds the new entry to the hash table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Bdc_Fun_t * Bdc_TableLookup( Bdc_Man_t * p, Bdc_Isf_t * pIsf ) +{ + Bdc_Fun_t * pFunc; + for ( pFunc = p->pTable[pIsf->uSupp]; pFunc; pFunc = pFunc->pNext ) + if ( Bdc_TableCheckContainment( p, pIsf, pFunc->puFunc ) ) + return pFunc; + return NULL; +} + +/**Function************************************************************* + + Synopsis [Adds the new entry to the hash table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Bdc_TableAdd( Bdc_Man_t * p, Bdc_Fun_t * pFunc ) +{ + if ( p->pTable[pFunc->uSupp] == NULL ) + Vec_IntPush( p->vSpots, pFunc->uSupp ); + pFunc->pNext = p->pTable[pFunc->uSupp]; + p->pTable[pFunc->uSupp] = pFunc; +} + +/**Function************************************************************* + + Synopsis [Adds the new entry to the hash table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Bdc_TableClear( Bdc_Man_t * p ) +{ + int Spot, i; + Vec_IntForEachEntry( p->vSpots, Spot, i ) + p->pTable[Spot] = NULL; + Vec_IntClear( p->vSpots ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/bdc/bdc_.c b/src/aig/bdc/bdc_.c new file mode 100644 index 00000000..9d0a9462 --- /dev/null +++ b/src/aig/bdc/bdc_.c @@ -0,0 +1,49 @@ +/**CFile**************************************************************** + + FileName [bdc_.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Truth-table-based bi-decomposition engine.] + + Synopsis [] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - January 30, 2007.] + + Revision [$Id: bdc_.c,v 1.00 2007/01/30 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "bdcInt.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ + + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/bdc/module.make b/src/aig/bdc/module.make new file mode 100644 index 00000000..8697c998 --- /dev/null +++ b/src/aig/bdc/module.make @@ -0,0 +1,4 @@ +SRC += src/aig/bdc/bdcCore.c \ + src/aig/bdc/bdcDec.c \ + src/aig/bdc/bdcTable.c + diff --git a/src/aig/cnf/cnf.h b/src/aig/cnf/cnf.h index 8c27b62d..c758867c 100644 --- a/src/aig/cnf/cnf.h +++ b/src/aig/cnf/cnf.h @@ -36,7 +36,8 @@ extern "C" { #include #include "vec.h" -#include "dar.h" +#include "aig.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// PARAMETERS /// @@ -53,7 +54,7 @@ typedef struct Cnf_Cut_t_ Cnf_Cut_t; // the CNF asserting outputs of AIG to be 1 struct Cnf_Dat_t_ { - Dar_Man_t * pMan; // the AIG manager, for which CNF is computed + Aig_Man_t * pMan; // the AIG manager, for which CNF is computed int nVars; // the number of variables int nLiterals; // the number of CNF literals int nClauses; // the number of CNF clauses @@ -74,11 +75,11 @@ struct Cnf_Cut_t_ // the CNF computation manager struct Cnf_Man_t_ { - Dar_Man_t * pManAig; // the underlying AIG manager + Aig_Man_t * pManAig; // the underlying AIG manager char * pSopSizes; // sizes of SOPs for 4-variable functions char ** pSops; // the SOPs for 4-variable functions int aArea; // the area of the mapping - Dar_MmFlex_t * pMemCuts; // memory manager for cuts + Aig_MmFlex_t * pMemCuts; // memory manager for cuts int nMergeLimit; // the limit on the size of merged cut unsigned * pTruths[4]; // temporary truth tables Vec_Int_t * vMemory; // memory for intermediate ISOP representation @@ -88,8 +89,8 @@ static inline int Cnf_CutLeaveNum( Cnf_Cut_t * pCut ) { return pCut- static inline int * Cnf_CutLeaves( Cnf_Cut_t * pCut ) { return pCut->pFanins; } static inline unsigned * Cnf_CutTruth( Cnf_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nFanins); } -static inline Cnf_Cut_t * Cnf_ObjBestCut( Dar_Obj_t * pObj ) { return pObj->pData; } -static inline void Cnf_ObjSetBestCut( Dar_Obj_t * pObj, Cnf_Cut_t * pCut ) { pObj->pData = pCut; } +static inline Cnf_Cut_t * Cnf_ObjBestCut( Aig_Obj_t * pObj ) { return pObj->pData; } +static inline void Cnf_ObjSetBestCut( Aig_Obj_t * pObj, Cnf_Cut_t * pCut ) { pObj->pData = pCut; } //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// @@ -101,16 +102,16 @@ static inline void Cnf_ObjSetBestCut( Dar_Obj_t * pObj, Cnf_Cut_t * pCut // iterator over leaves of the cut #define Cnf_CutForEachLeaf( p, pCut, pLeaf, i ) \ - for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Dar_ManObj(p, (pCut)->pFanins[i])); i++ ) + for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ ) //////////////////////////////////////////////////////////////////////// /// FUNCTION DECLARATIONS /// //////////////////////////////////////////////////////////////////////// /*=== cnfCore.c ========================================================*/ -extern Cnf_Dat_t * Cnf_Derive( Cnf_Man_t * p, Dar_Man_t * pAig ); +extern Cnf_Dat_t * Cnf_Derive( Cnf_Man_t * p, Aig_Man_t * pAig ); /*=== cnfCut.c ========================================================*/ -extern Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Dar_Obj_t * pObj ); +extern Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Aig_Obj_t * pObj ); extern void Cnf_CutPrint( Cnf_Cut_t * pCut ); extern void Cnf_CutFree( Cnf_Cut_t * pCut ); extern void Cnf_CutUpdateRefs( Cnf_Man_t * p, Cnf_Cut_t * pCut, Cnf_Cut_t * pCutFan, Cnf_Cut_t * pCutRes ); @@ -130,7 +131,7 @@ extern void Cnf_ManTransferCuts( Cnf_Man_t * p ); extern void Cnf_ManFreeCuts( Cnf_Man_t * p ); extern void Cnf_ManPostprocess( Cnf_Man_t * p ); /*=== cnfUtil.c ========================================================*/ -extern Vec_Ptr_t * Dar_ManScanMapping( Cnf_Man_t * p, int fCollect ); +extern Vec_Ptr_t * Aig_ManScanMapping( Cnf_Man_t * p, int fCollect ); extern Vec_Ptr_t * Cnf_ManScanMapping( Cnf_Man_t * p, int fCollect ); /*=== cnfWrite.c ========================================================*/ extern void Cnf_SopConvertToVector( char * pSop, int nCubes, Vec_Int_t * vCover ); diff --git a/src/aig/cnf/cnfCore.c b/src/aig/cnf/cnfCore.c index b09f0bdc..a3a7efaa 100644 --- a/src/aig/cnf/cnfCore.c +++ b/src/aig/cnf/cnfCore.c @@ -39,20 +39,20 @@ SeeAlso [] ***********************************************************************/ -Cnf_Dat_t * Cnf_Derive( Cnf_Man_t * p, Dar_Man_t * pAig ) +Cnf_Dat_t * Cnf_Derive( Cnf_Man_t * p, Aig_Man_t * pAig ) { + Aig_MmFixed_t * pMemCuts; Cnf_Dat_t * pCnf = NULL; Vec_Ptr_t * vMapped; int nIters = 2; int clk; // connect the managers - pAig->pManCnf = p; p->pManAig = pAig; // generate cuts for all nodes, assign cost, and find best cuts clk = clock(); - Dar_ManComputeCuts( pAig ); + pMemCuts = Dar_ManComputeCuts( pAig ); PRT( "Cuts", clock() - clk ); /* // iteratively improve area flow @@ -65,7 +65,7 @@ PRT( "iter ", clock() - clk ); } */ // write the file - vMapped = Dar_ManScanMapping( p, 1 ); + vMapped = Aig_ManScanMapping( p, 1 ); Vec_PtrFree( vMapped ); clk = clock(); @@ -91,6 +91,7 @@ PRT( "Ext ", clock() - clk ); Dar_ManCutsFree( pAig ); return pCnf; */ + Aig_MmFixedStop( pMemCuts, 0 ); return NULL; } diff --git a/src/aig/cnf/cnfCut.c b/src/aig/cnf/cnfCut.c index feeef1f2..afe5920a 100644 --- a/src/aig/cnf/cnfCut.c +++ b/src/aig/cnf/cnfCut.c @@ -43,10 +43,10 @@ Cnf_Cut_t * Cnf_CutAlloc( Cnf_Man_t * p, int nLeaves ) { Cnf_Cut_t * pCut; - int nSize = sizeof(Cnf_Cut_t) + sizeof(int) * nLeaves + sizeof(unsigned) * Dar_TruthWordNum(nLeaves); - pCut = (Cnf_Cut_t *)Dar_MmFlexEntryFetch( p->pMemCuts, nSize ); + int nSize = sizeof(Cnf_Cut_t) + sizeof(int) * nLeaves + sizeof(unsigned) * Aig_TruthWordNum(nLeaves); + pCut = (Cnf_Cut_t *)Aig_MmFlexEntryFetch( p->pMemCuts, nSize ); pCut->nFanins = nLeaves; - pCut->nWords = Dar_TruthWordNum(nLeaves); + pCut->nWords = Aig_TruthWordNum(nLeaves); pCut->vIsop[0] = pCut->vIsop[1] = NULL; return pCut; } @@ -81,13 +81,14 @@ void Cnf_CutFree( Cnf_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Dar_Obj_t * pObj ) +Cnf_Cut_t * Cnf_CutCreate( Cnf_Man_t * p, Aig_Obj_t * pObj ) { Dar_Cut_t * pCutBest; Cnf_Cut_t * pCut; unsigned * pTruth; - assert( Dar_ObjIsNode(pObj) ); - pCutBest = Dar_ObjBestCut( pObj ); + assert( Aig_ObjIsNode(pObj) ); +// pCutBest = Aig_ObjBestCut( pObj ); + pCutBest = NULL; assert( pCutBest != NULL ); assert( pCutBest->nLeaves <= 4 ); pCut = Cnf_CutAlloc( p, pCutBest->nLeaves ); @@ -131,7 +132,7 @@ void Cnf_CutPrint( Cnf_Cut_t * pCut ) ***********************************************************************/ void Cnf_CutDeref( Cnf_Man_t * p, Cnf_Cut_t * pCut ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; Cnf_CutForEachLeaf( p->pManAig, pCut, pObj, i ) { @@ -153,7 +154,7 @@ void Cnf_CutDeref( Cnf_Man_t * p, Cnf_Cut_t * pCut ) ***********************************************************************/ void Cnf_CutRef( Cnf_Man_t * p, Cnf_Cut_t * pCut ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; Cnf_CutForEachLeaf( p->pManAig, pCut, pObj, i ) { diff --git a/src/aig/cnf/cnfData.c b/src/aig/cnf/cnfData.c index 57ce9392..7b8be51e 100644 --- a/src/aig/cnf/cnfData.c +++ b/src/aig/cnf/cnfData.c @@ -4614,7 +4614,7 @@ void Cnf_ReadMsops( char ** ppSopSizes, char *** ppSops ) SeeAlso [] ***********************************************************************/ -int Dar_ManDeriveCnfTest() +int Aig_ManDeriveCnfTest() { int i, k, Lit; printf( "\n" ); @@ -4644,7 +4644,7 @@ int Dar_ManDeriveCnfTest() SeeAlso [] ***********************************************************************/ -int Dar_ManDeriveCnfTest2() +int Aig_ManDeriveCnfTest2() { char s_Data3[81] = "!#&()*+,-.0123456789:;<=>?ABCDEFGHIJKLMNOPQRSTUVWXYZ[]abcdefghijklmnopqrstuvwxyz|"; diff --git a/src/aig/cnf/cnfMan.c b/src/aig/cnf/cnfMan.c index d1d1fc21..e978e322 100644 --- a/src/aig/cnf/cnfMan.c +++ b/src/aig/cnf/cnfMan.c @@ -52,12 +52,12 @@ Cnf_Man_t * Cnf_ManStart() // derive internal data structures Cnf_ReadMsops( &p->pSopSizes, &p->pSops ); // allocate memory manager for cuts - p->pMemCuts = Dar_MmFlexStart(); + p->pMemCuts = Aig_MmFlexStart(); p->nMergeLimit = 10; // allocate temporary truth tables - p->pTruths[0] = ALLOC( unsigned, 4 * Dar_TruthWordNum(p->nMergeLimit) ); + p->pTruths[0] = ALLOC( unsigned, 4 * Aig_TruthWordNum(p->nMergeLimit) ); for ( i = 1; i < 4; i++ ) - p->pTruths[i] = p->pTruths[i-1] + Dar_TruthWordNum(p->nMergeLimit); + p->pTruths[i] = p->pTruths[i-1] + Aig_TruthWordNum(p->nMergeLimit); p->vMemory = Vec_IntAlloc( 1 << 18 ); return p; } @@ -77,7 +77,7 @@ void Cnf_ManStop( Cnf_Man_t * p ) { Vec_IntFree( p->vMemory ); free( p->pTruths[0] ); - Dar_MmFlexStop( p->pMemCuts, 0 ); + Aig_MmFlexStop( p->pMemCuts, 0 ); free( p->pSopSizes ); free( p->pSops[1] ); free( p->pSops ); diff --git a/src/aig/cnf/cnfMap.c b/src/aig/cnf/cnfMap.c index 09be7701..a9ba41a0 100644 --- a/src/aig/cnf/cnfMap.c +++ b/src/aig/cnf/cnfMap.c @@ -28,6 +28,8 @@ /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// +#if 0 + /**Function************************************************************* Synopsis [Computes area of the first level.] @@ -39,16 +41,16 @@ SeeAlso [] ***********************************************************************/ -void Dar_CutDeref( Dar_Man_t * p, Dar_Cut_t * pCut ) +void Aig_CutDeref( Aig_Man_t * p, Dar_Cut_t * pCut ) { - Dar_Obj_t * pLeaf; + Aig_Obj_t * pLeaf; int i; Dar_CutForEachLeaf( p, pCut, pLeaf, i ) { assert( pLeaf->nRefs > 0 ); - if ( --pLeaf->nRefs > 0 || !Dar_ObjIsAnd(pLeaf) ) + if ( --pLeaf->nRefs > 0 || !Aig_ObjIsAnd(pLeaf) ) continue; - Dar_CutDeref( p, Dar_ObjBestCut(pLeaf) ); + Aig_CutDeref( p, Aig_ObjBestCut(pLeaf) ); } } @@ -63,16 +65,16 @@ void Dar_CutDeref( Dar_Man_t * p, Dar_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -int Dar_CutRef( Dar_Man_t * p, Dar_Cut_t * pCut ) +int Aig_CutRef( Aig_Man_t * p, Dar_Cut_t * pCut ) { - Dar_Obj_t * pLeaf; - int i, Area = pCut->Cost; + Aig_Obj_t * pLeaf; + int i, Area = pCut->Value; Dar_CutForEachLeaf( p, pCut, pLeaf, i ) { assert( pLeaf->nRefs >= 0 ); - if ( pLeaf->nRefs++ > 0 || !Dar_ObjIsAnd(pLeaf) ) + if ( pLeaf->nRefs++ > 0 || !Aig_ObjIsAnd(pLeaf) ) continue; - Area += Dar_CutRef( p, Dar_ObjBestCut(pLeaf) ); + Area += Aig_CutRef( p, Aig_ObjBestCut(pLeaf) ); } return Area; } @@ -88,11 +90,11 @@ int Dar_CutRef( Dar_Man_t * p, Dar_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -int Cnf_CutArea( Dar_Man_t * p, Dar_Cut_t * pCut ) +int Cnf_CutArea( Aig_Man_t * p, Dar_Cut_t * pCut ) { int Area; - Area = Dar_CutRef( p, pCut ); - Dar_CutDeref( p, pCut ); + Area = Aig_CutRef( p, pCut ); + Aig_CutDeref( p, pCut ); return Area; } @@ -136,7 +138,7 @@ static inline int Cnf_CutCompare( Dar_Cut_t * pC0, Dar_Cut_t * pC1 ) SeeAlso [] ***********************************************************************/ -Dar_Cut_t * Cnf_ObjFindBestCut( Dar_Obj_t * pObj ) +Dar_Cut_t * Cnf_ObjFindBestCut( Aig_Obj_t * pObj ) { Dar_Cut_t * pCut, * pCutBest; int i; @@ -160,7 +162,7 @@ Dar_Cut_t * Cnf_ObjFindBestCut( Dar_Obj_t * pObj ) ***********************************************************************/ void Cnf_CutAssignAreaFlow( Cnf_Man_t * p, Dar_Cut_t * pCut ) { - Dar_Obj_t * pLeaf; + Aig_Obj_t * pLeaf; int i; pCut->Cost = p->pSopSizes[pCut->uTruth] + p->pSopSizes[0xFFFF & ~pCut->uTruth]; pCut->Area = (float)pCut->Cost; @@ -168,16 +170,16 @@ void Cnf_CutAssignAreaFlow( Cnf_Man_t * p, Dar_Cut_t * pCut ) pCut->FanRefs = 0; Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i ) { - if ( !Dar_ObjIsNode(pLeaf) ) + if ( !Aig_ObjIsNode(pLeaf) ) continue; if ( pLeaf->nRefs == 0 ) { - pCut->Area += Dar_ObjBestCut(pLeaf)->Area; + pCut->Area += Aig_ObjBestCut(pLeaf)->Area; pCut->NoRefs++; } else { - pCut->Area += Dar_ObjBestCut(pLeaf)->Area / pLeaf->nRefs; + pCut->Area += Aig_ObjBestCut(pLeaf)->Area / pLeaf->nRefs; if ( pCut->FanRefs + pLeaf->nRefs > 15 ) pCut->FanRefs = 15; else @@ -199,18 +201,18 @@ void Cnf_CutAssignAreaFlow( Cnf_Man_t * p, Dar_Cut_t * pCut ) ***********************************************************************/ void Cnf_CutAssignArea( Cnf_Man_t * p, Dar_Cut_t * pCut ) { - Dar_Obj_t * pLeaf; + Aig_Obj_t * pLeaf; int i; pCut->Area = (float)pCut->Cost; pCut->NoRefs = 0; pCut->FanRefs = 0; Dar_CutForEachLeaf( p->pManAig, pCut, pLeaf, i ) { - if ( !Dar_ObjIsNode(pLeaf) ) + if ( !Aig_ObjIsNode(pLeaf) ) continue; if ( pLeaf->nRefs == 0 ) { - pCut->Area += Dar_ObjBestCut(pLeaf)->Cost; + pCut->Area += Aig_ObjBestCut(pLeaf)->Cost; pCut->NoRefs++; } else @@ -236,18 +238,18 @@ void Cnf_CutAssignArea( Cnf_Man_t * p, Dar_Cut_t * pCut ) ***********************************************************************/ int Cnf_ManMapForCnf( Cnf_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; Dar_Cut_t * pCut, * pCutBest; int i, k; // visit the nodes in the topological order and update their best cuts - Dar_ManForEachNode( p->pManAig, pObj, i ) + Aig_ManForEachNode( p->pManAig, pObj, i ) { // find the old best cut - pCutBest = Dar_ObjBestCut(pObj); + pCutBest = Aig_ObjBestCut(pObj); Dar_ObjClearBestCut(pCutBest); // if the node is used, dereference its cut if ( pObj->nRefs ) - Dar_CutDeref( p->pManAig, pCutBest ); + Aig_CutDeref( p->pManAig, pCutBest ); // evaluate the cuts of this node Dar_ObjForEachCut( pObj, pCut, k ) @@ -259,11 +261,13 @@ int Cnf_ManMapForCnf( Cnf_Man_t * p ) Dar_ObjSetBestCut( pCutBest ); // if the node is used, reference its cut if ( pObj->nRefs ) - Dar_CutRef( p->pManAig, pCutBest ); + Aig_CutRef( p->pManAig, pCutBest ); } return 1; } +#endif + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/aig/cnf/cnfPost.c b/src/aig/cnf/cnfPost.c index 2f6a6424..988275b2 100644 --- a/src/aig/cnf/cnfPost.c +++ b/src/aig/cnf/cnfPost.c @@ -41,27 +41,30 @@ ***********************************************************************/ void Cnf_ManPostprocess_old( Cnf_Man_t * p ) { - extern int Dar_ManLargeCutEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Dar_Cut_t * pCutL, int Leaf ); +// extern int Aig_ManLargeCutEval( Aig_Man_t * p, Aig_Obj_t * pRoot, Dar_Cut_t * pCutR, Dar_Cut_t * pCutL, int Leaf ); int nNew, Gain, nGain = 0, nVars = 0; - Dar_Obj_t * pObj, * pFan; + Aig_Obj_t * pObj, * pFan; Dar_Cut_t * pCutBest, * pCut; int i, k;//, a, b, Counter; - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) { - if ( !Dar_ObjIsNode(pObj) ) + if ( !Aig_ObjIsNode(pObj) ) continue; if ( pObj->nRefs == 0 ) continue; - pCutBest = Dar_ObjBestCut(pObj); +// pCutBest = Aig_ObjBestCut(pObj); + pCutBest = NULL; + Dar_CutForEachLeaf( p->pManAig, pCutBest, pFan, k ) { - if ( !Dar_ObjIsNode(pFan) ) + if ( !Aig_ObjIsNode(pFan) ) continue; assert( pFan->nRefs != 0 ); if ( pFan->nRefs != 1 ) continue; - pCut = Dar_ObjBestCut(pFan); +// pCut = Aig_ObjBestCut(pFan); + pCut = NULL; /* // find how many common variable they have Counter = 0; @@ -77,11 +80,16 @@ void Cnf_ManPostprocess_old( Cnf_Man_t * p ) printf( "%d ", Counter ); */ // find the new truth table after collapsing these two cuts - nNew = Dar_ManLargeCutEval( p->pManAig, pObj, pCutBest, pCut, pFan->Id ); + + +// nNew = Aig_ManLargeCutEval( p->pManAig, pObj, pCutBest, pCut, pFan->Id ); + nNew = 0; + + // printf( "%d+%d=%d:%d(%d) ", pCutBest->Cost, pCut->Cost, // pCutBest->Cost+pCut->Cost, nNew, pCutBest->Cost+pCut->Cost-nNew ); - Gain = pCutBest->Cost+pCut->Cost-nNew; + Gain = pCutBest->Value + pCut->Value - nNew; if ( Gain > 0 ) { nGain += Gain; @@ -105,12 +113,12 @@ void Cnf_ManPostprocess_old( Cnf_Man_t * p ) ***********************************************************************/ void Cnf_ManTransferCuts( Cnf_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; - Dar_MmFlexRestart( p->pMemCuts ); - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_MmFlexRestart( p->pMemCuts ); + Aig_ManForEachObj( p->pManAig, pObj, i ) { - if ( Dar_ObjIsNode(pObj) && pObj->nRefs > 0 ) + if ( Aig_ObjIsNode(pObj) && pObj->nRefs > 0 ) pObj->pData = Cnf_CutCreate( p, pObj ); else pObj->pData = NULL; @@ -130,9 +138,9 @@ void Cnf_ManTransferCuts( Cnf_Man_t * p ) ***********************************************************************/ void Cnf_ManFreeCuts( Cnf_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) if ( pObj->pData ) { Cnf_CutFree( pObj->pData ); @@ -154,10 +162,10 @@ void Cnf_ManFreeCuts( Cnf_Man_t * p ) void Cnf_ManPostprocess( Cnf_Man_t * p ) { Cnf_Cut_t * pCut, * pCutFan, * pCutRes; - Dar_Obj_t * pObj, * pFan; + Aig_Obj_t * pObj, * pFan; int Order[16], Costs[16]; int i, k, fChanges; - Dar_ManForEachNode( p->pManAig, pObj, i ) + Aig_ManForEachNode( p->pManAig, pObj, i ) { if ( pObj->nRefs == 0 ) continue; @@ -167,7 +175,7 @@ void Cnf_ManPostprocess( Cnf_Man_t * p ) Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k ) { Order[k] = k; - Costs[k] = Dar_ObjIsNode(pFan)? Cnf_ObjBestCut(pFan)->Cost : 0; + Costs[k] = Aig_ObjIsNode(pFan)? Cnf_ObjBestCut(pFan)->Cost : 0; } // sort the cuts by Weight do { @@ -186,9 +194,9 @@ void Cnf_ManPostprocess( Cnf_Man_t * p ) // Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k ) - for ( k = 0; (k < (int)(pCut)->nFanins) && ((pFan) = Dar_ManObj(p->pManAig, (pCut)->pFanins[Order[k]])); k++ ) + for ( k = 0; (k < (int)(pCut)->nFanins) && ((pFan) = Aig_ManObj(p->pManAig, (pCut)->pFanins[Order[k]])); k++ ) { - if ( !Dar_ObjIsNode(pFan) ) + if ( !Aig_ObjIsNode(pFan) ) continue; assert( pFan->nRefs != 0 ); if ( pFan->nRefs != 1 ) diff --git a/src/aig/cnf/cnfUtil.c b/src/aig/cnf/cnfUtil.c index 249f43fb..da5edef2 100644 --- a/src/aig/cnf/cnfUtil.c +++ b/src/aig/cnf/cnfUtil.c @@ -39,22 +39,23 @@ SeeAlso [] ***********************************************************************/ -int Dar_ManScanMapping_rec( Cnf_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vMapped ) +int Aig_ManScanMapping_rec( Cnf_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vMapped ) { - Dar_Obj_t * pLeaf; + Aig_Obj_t * pLeaf; Dar_Cut_t * pCutBest; int aArea, i; - if ( pObj->nRefs++ || Dar_ObjIsPi(pObj) || Dar_ObjIsConst1(pObj) ) + if ( pObj->nRefs++ || Aig_ObjIsPi(pObj) || Aig_ObjIsConst1(pObj) ) return 0; - assert( Dar_ObjIsAnd(pObj) ); + assert( Aig_ObjIsAnd(pObj) ); // collect the node first to derive pre-order if ( vMapped ) Vec_PtrPush( vMapped, pObj ); // visit the transitive fanin of the selected cut - pCutBest = Dar_ObjBestCut(pObj); - aArea = pCutBest->Cost; +// pCutBest = Aig_ObjBestCut(pObj); + pCutBest = NULL; + aArea = pCutBest->Value; Dar_CutForEachLeaf( p->pManAig, pCutBest, pLeaf, i ) - aArea += Dar_ManScanMapping_rec( p, pLeaf, vMapped ); + aArea += Aig_ManScanMapping_rec( p, pLeaf, vMapped ); return aArea; } @@ -69,21 +70,21 @@ int Dar_ManScanMapping_rec( Cnf_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vMapped SeeAlso [] ***********************************************************************/ -Vec_Ptr_t * Dar_ManScanMapping( Cnf_Man_t * p, int fCollect ) +Vec_Ptr_t * Aig_ManScanMapping( Cnf_Man_t * p, int fCollect ) { Vec_Ptr_t * vMapped = NULL; - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; // clean all references - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) pObj->nRefs = 0; // allocate the array if ( fCollect ) vMapped = Vec_PtrAlloc( 1000 ); // collect nodes reachable from POs in the DFS order through the best cuts p->aArea = 0; - Dar_ManForEachPo( p->pManAig, pObj, i ) - p->aArea += Dar_ManScanMapping_rec( p, Dar_ObjFanin0(pObj), vMapped ); + Aig_ManForEachPo( p->pManAig, pObj, i ) + p->aArea += Aig_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped ); printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) : 0, p->aArea ); return vMapped; } @@ -99,14 +100,14 @@ Vec_Ptr_t * Dar_ManScanMapping( Cnf_Man_t * p, int fCollect ) SeeAlso [] ***********************************************************************/ -int Cnf_ManScanMapping_rec( Cnf_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vMapped ) +int Cnf_ManScanMapping_rec( Cnf_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vMapped ) { - Dar_Obj_t * pLeaf; + Aig_Obj_t * pLeaf; Cnf_Cut_t * pCutBest; int aArea, i; - if ( pObj->nRefs++ || Dar_ObjIsPi(pObj) || Dar_ObjIsConst1(pObj) ) + if ( pObj->nRefs++ || Aig_ObjIsPi(pObj) || Aig_ObjIsConst1(pObj) ) return 0; - assert( Dar_ObjIsAnd(pObj) ); + assert( Aig_ObjIsAnd(pObj) ); assert( pObj->pData != NULL ); // visit the transitive fanin of the selected cut pCutBest = pObj->pData; @@ -134,18 +135,18 @@ int Cnf_ManScanMapping_rec( Cnf_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vMapped Vec_Ptr_t * Cnf_ManScanMapping( Cnf_Man_t * p, int fCollect ) { Vec_Ptr_t * vMapped = NULL; - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; // clean all references - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) pObj->nRefs = 0; // allocate the array if ( fCollect ) vMapped = Vec_PtrAlloc( 1000 ); // collect nodes reachable from POs in the DFS order through the best cuts p->aArea = 0; - Dar_ManForEachPo( p->pManAig, pObj, i ) - p->aArea += Cnf_ManScanMapping_rec( p, Dar_ObjFanin0(pObj), vMapped ); + Aig_ManForEachPo( p->pManAig, pObj, i ) + p->aArea += Cnf_ManScanMapping_rec( p, Aig_ObjFanin0(pObj), vMapped ); printf( "Variables = %6d. Clauses = %8d.\n", vMapped? Vec_PtrSize(vMapped) : 0, p->aArea ); return vMapped; } diff --git a/src/aig/cnf/cnfWrite.c b/src/aig/cnf/cnfWrite.c index 2637d115..22c4240a 100644 --- a/src/aig/cnf/cnfWrite.c +++ b/src/aig/cnf/cnfWrite.c @@ -183,7 +183,7 @@ int Cnf_IsopWriteCube( int Cube, int nVars, int * pVars, int fCompl, int * pLite ***********************************************************************/ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; Cnf_Dat_t * pCnf; Cnf_Cut_t * pCut; int OutVar, pVars[32], * pLits, ** pClas; @@ -191,11 +191,11 @@ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) int i, k, nLiterals, nClauses, nCubes, Cube, Number; // count the number of literals and clauses - nLiterals = 1 + Dar_ManPoNum( p->pManAig ); - nClauses = 1 + Dar_ManPoNum( p->pManAig ); + nLiterals = 1 + Aig_ManPoNum( p->pManAig ); + nClauses = 1 + Aig_ManPoNum( p->pManAig ); Vec_PtrForEachEntry( vMapped, pObj, i ) { - assert( Dar_ObjIsNode(pObj) ); + assert( Aig_ObjIsNode(pObj) ); pCut = Cnf_ObjBestCut( pObj ); // positive polarity of the cut @@ -224,7 +224,7 @@ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) nLiterals += Cnf_IsopCountLiterals( pCut->vIsop[0], pCut->nFanins ) + Vec_IntSize(pCut->vIsop[0]); nClauses += Vec_IntSize(pCut->vIsop[0]); } -//printf( "%d ", nClauses-(1 + Dar_ManPoNum( p->pManAig )) ); +//printf( "%d ", nClauses-(1 + Aig_ManPoNum( p->pManAig )) ); } //printf( "\n" ); @@ -239,13 +239,13 @@ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) // set variable numbers Number = 0; - pCnf->pVarNums = ALLOC( int, 1+Dar_ManObjIdMax(p->pManAig) ); - memset( pCnf->pVarNums, 0xff, sizeof(int) * (1+Dar_ManObjIdMax(p->pManAig)) ); + pCnf->pVarNums = ALLOC( int, 1+Aig_ManObjIdMax(p->pManAig) ); + memset( pCnf->pVarNums, 0xff, sizeof(int) * (1+Aig_ManObjIdMax(p->pManAig)) ); Vec_PtrForEachEntry( vMapped, pObj, i ) pCnf->pVarNums[pObj->Id] = Number++; - Dar_ManForEachPi( p->pManAig, pObj, i ) + Aig_ManForEachPi( p->pManAig, pObj, i ) pCnf->pVarNums[pObj->Id] = Number++; - pCnf->pVarNums[Dar_ManConst1(p->pManAig)->Id] = Number++; + pCnf->pVarNums[Aig_ManConst1(p->pManAig)->Id] = Number++; pCnf->nVars = Number; // assign the clauses @@ -260,7 +260,7 @@ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) for ( k = 0; k < (int)pCut->nFanins; k++ ) { pVars[k] = pCnf->pVarNums[ pCut->pFanins[k] ]; - assert( pVars[k] <= Dar_ManObjIdMax(p->pManAig) ); + assert( pVars[k] <= Aig_ManObjIdMax(p->pManAig) ); } // positive polarity of the cut @@ -310,17 +310,17 @@ Cnf_Dat_t * Cnf_ManWriteCnf( Cnf_Man_t * p, Vec_Ptr_t * vMapped ) } // write the constant literal - OutVar = pCnf->pVarNums[ Dar_ManConst1(p->pManAig)->Id ]; - assert( OutVar <= Dar_ManObjIdMax(p->pManAig) ); + OutVar = pCnf->pVarNums[ Aig_ManConst1(p->pManAig)->Id ]; + assert( OutVar <= Aig_ManObjIdMax(p->pManAig) ); *pClas++ = pLits; *pLits++ = 2 * OutVar; // write the output literals - Dar_ManForEachPo( p->pManAig, pObj, i ) + Aig_ManForEachPo( p->pManAig, pObj, i ) { - OutVar = pCnf->pVarNums[ Dar_ObjFanin0(pObj)->Id ]; + OutVar = pCnf->pVarNums[ Aig_ObjFanin0(pObj)->Id ]; *pClas++ = pLits; - *pLits++ = 2 * OutVar + Dar_ObjFaninC0(pObj); + *pLits++ = 2 * OutVar + Aig_ObjFaninC0(pObj); } // verify that the correct number of literals and clauses was written diff --git a/src/aig/csw/csw.h b/src/aig/csw/csw.h index 4a326414..1443f4d9 100644 --- a/src/aig/csw/csw.h +++ b/src/aig/csw/csw.h @@ -51,7 +51,7 @@ extern "C" { //////////////////////////////////////////////////////////////////////// /*=== cnfCore.c ========================================================*/ -extern Dar_Man_t * Csw_Sweep( Dar_Man_t * pAig, int nCutsMax, int nLeafMax, int fVerbose ); +extern Aig_Man_t * Csw_Sweep( Aig_Man_t * pAig, int nCutsMax, int nLeafMax, int fVerbose ); #ifdef __cplusplus } diff --git a/src/aig/csw/cswCore.c b/src/aig/csw/cswCore.c index ddf37035..20893058 100644 --- a/src/aig/csw/cswCore.c +++ b/src/aig/csw/cswCore.c @@ -39,34 +39,48 @@ SeeAlso [] ***********************************************************************/ -Dar_Man_t * Csw_Sweep( Dar_Man_t * pAig, int nCutsMax, int nLeafMax, int fVerbose ) +Aig_Man_t * Csw_Sweep( Aig_Man_t * pAig, int nCutsMax, int nLeafMax, int fVerbose ) { Csw_Man_t * p; - Dar_Man_t * pRes; - Dar_Obj_t * pObj, * pObjNew, * pObjRes; - int i; + Aig_Man_t * pRes; + Aig_Obj_t * pObj, * pObjNew, * pObjRes; + int i, clk; +clk = clock(); // start the manager p = Csw_ManStart( pAig, nCutsMax, nLeafMax, fVerbose ); // set elementary cuts at the PIs - Dar_ManForEachPi( p->pManRes, pObj, i ) + Aig_ManForEachPi( p->pManRes, pObj, i ) + { Csw_ObjPrepareCuts( p, pObj, 1 ); + Csw_ObjAddRefs( p, pObj, Aig_ManPi(p->pManAig,i)->nRefs ); + } // process the nodes - Dar_ManForEachNode( pAig, pObj, i ) + Aig_ManForEachNode( pAig, pObj, i ) { // create the new node - pObjNew = Dar_And( p->pManRes, Csw_ObjChild0Equiv(p, pObj), Csw_ObjChild1Equiv(p, pObj) ); + pObjNew = Aig_And( p->pManRes, Csw_ObjChild0Equiv(p, pObj), Csw_ObjChild1Equiv(p, pObj) ); // check if this node can be represented using another node - pObjRes = Csw_ObjSweep( p, Dar_Regular(pObjNew), pObj->nRefs > 1 ); - pObjRes = Dar_NotCond( pObjRes, Dar_IsComplement(pObjNew) ); - // set the resulting node +// pObjRes = Csw_ObjSweep( p, Aig_Regular(pObjNew), pObj->nRefs > 1 ); +// pObjRes = Aig_NotCond( pObjRes, Aig_IsComplement(pObjNew) ); + // try recursively if resubsitution is used + do { + pObjRes = Csw_ObjSweep( p, Aig_Regular(pObjNew), pObj->nRefs > 1 ); + pObjRes = Aig_NotCond( pObjRes, Aig_IsComplement(pObjNew) ); + pObjNew = pObjRes; + } while ( Csw_ObjCuts(p, Aig_Regular(pObjNew)) == NULL && !Aig_ObjIsConst1(Aig_Regular(pObjNew)) ); + // save the resulting node Csw_ObjSetEquiv( p, pObj, pObjRes ); + // add to the reference counter + Csw_ObjAddRefs( p, Aig_Regular(pObjRes), pObj->nRefs ); } // add the POs - Dar_ManForEachPo( pAig, pObj, i ) - Dar_ObjCreatePo( p->pManRes, Csw_ObjChild0Equiv(p, pObj) ); + Aig_ManForEachPo( pAig, pObj, i ) + Aig_ObjCreatePo( p->pManRes, Csw_ObjChild0Equiv(p, pObj) ); // remove dangling nodes - Dar_ManCleanup( p->pManRes ); + Aig_ManCleanup( p->pManRes ); // return the resulting manager +p->timeTotal = clock() - clk; +p->timeOther = p->timeTotal - p->timeCuts - p->timeHash; pRes = p->pManRes; Csw_ManStop( p ); return pRes; diff --git a/src/aig/csw/cswCut.c b/src/aig/csw/cswCut.c index f1cb1fde..b3b7152b 100644 --- a/src/aig/csw/cswCut.c +++ b/src/aig/csw/cswCut.c @@ -41,13 +41,41 @@ ***********************************************************************/ static inline int Csw_CutFindCost( Csw_Man_t * p, Csw_Cut_t * pCut ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pLeaf; int i, Cost = 0; - Csw_CutForEachLeaf( p->pManRes, pCut, pObj, i ) - Cost += pObj->nRefs; + assert( pCut->nFanins > 0 ); + Csw_CutForEachLeaf( p->pManRes, pCut, pLeaf, i ) + { +// Cost += pLeaf->nRefs; + Cost += Csw_ObjRefs( p, pLeaf ); +// printf( "%d ", pLeaf->nRefs ); + } +//printf( "\n" ); return Cost * 100 / pCut->nFanins; } +/**Function************************************************************* + + Synopsis [Compute the cost of the cut.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline float Csw_CutFindCost2( Csw_Man_t * p, Csw_Cut_t * pCut ) +{ + Aig_Obj_t * pLeaf; + float Cost = 0.0; + int i; + assert( pCut->nFanins > 0 ); + Csw_CutForEachLeaf( p->pManRes, pCut, pLeaf, i ) + Cost += (float)1.0/pLeaf->nRefs; + return 1/Cost; +} + /**Function************************************************************* Synopsis [Returns the next free cut to use.] @@ -59,7 +87,7 @@ static inline int Csw_CutFindCost( Csw_Man_t * p, Csw_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -static inline Csw_Cut_t * Csw_CutFindFree( Csw_Man_t * p, Dar_Obj_t * pObj ) +static inline Csw_Cut_t * Csw_CutFindFree( Csw_Man_t * p, Aig_Obj_t * pObj ) { Csw_Cut_t * pCut, * pCutMax; int i; @@ -131,9 +159,124 @@ unsigned * Csw_CutComputeTruth( Csw_Man_t * p, Csw_Cut_t * pCut, Csw_Cut_t * pCu Kit_TruthStretch( p->puTemp[3], p->puTemp[1], pCut1->nFanins, p->nLeafMax, Cut_TruthPhase(pCut, pCut1), 0 ); // produce the resulting table Kit_TruthAnd( Csw_CutTruth(pCut), p->puTemp[2], p->puTemp[3], p->nLeafMax ); +// assert( pCut->nFanins >= Kit_TruthSupportSize( Csw_CutTruth(pCut), p->nLeafMax ) ); return Csw_CutTruth(pCut); } +/**Function************************************************************* + + Synopsis [Performs support minimization for the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Csw_CutSupportMinimize( Csw_Man_t * p, Csw_Cut_t * pCut ) +{ + unsigned * pTruth; + int uSupp, nFansNew, i, k; + // get truth table + pTruth = Csw_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<nLeafMax) ); printf( "\n" ); + return nFansNew; +} + +/**Function************************************************************* + + Synopsis [Returns 1 if pDom is contained in pCut.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Csw_CutCheckDominance( Csw_Cut_t * pDom, Csw_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 Csw_CutFilter( Csw_Man_t * p, Aig_Obj_t * pObj, Csw_Cut_t * pCut ) +{ + Csw_Cut_t * pTemp; + int i; + // go through the cuts of the node + Csw_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 ( Csw_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 ( Csw_CutCheckDominance( pTemp, pCut ) ) + { + // remove the given + pCut->nFanins = 0; + return 1; + } + } + } + return 0; +} + /**Function************************************************************* Synopsis [Merges two cuts.] @@ -249,6 +392,50 @@ int Csw_CutMerge( Csw_Man_t * p, Csw_Cut_t * pCut0, Csw_Cut_t * pCut1, Csw_Cut_t return 1; } +/**Function************************************************************* + + Synopsis [Consider cut with more than 2 fanins having 2 true variables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Aig_Obj_t * Csw_ObjTwoVarCut( Csw_Man_t * p, Csw_Cut_t * pCut ) +{ + Aig_Obj_t * pRes, * pIn0, * pIn1; + int nVars, uTruth, fCompl = 0; + assert( pCut->nFanins > 2 ); + // minimize support of this cut + nVars = Csw_CutSupportMinimize( p, pCut ); + assert( nVars == 2 ); + // get the fanins + pIn0 = Aig_ManObj( p->pManRes, pCut->pFanins[0] ); + pIn1 = Aig_ManObj( p->pManRes, pCut->pFanins[1] ); + // derive the truth table + uTruth = 0xF & *Csw_CutTruth(pCut); + if ( uTruth == 14 || uTruth == 13 || uTruth == 11 || uTruth == 7 ) + { + uTruth = 0xF & ~uTruth; + fCompl = 1; + } + // compute the result + pRes = NULL; + if ( uTruth == 1 ) // 0001 // 1110 14 + pRes = Aig_And( p->pManRes, Aig_Not(pIn0), Aig_Not(pIn1) ); + if ( uTruth == 2 ) // 0010 // 1101 13 + pRes = Aig_And( p->pManRes, pIn0 , Aig_Not(pIn1) ); + if ( uTruth == 4 ) // 0100 // 1011 11 + pRes = Aig_And( p->pManRes, Aig_Not(pIn0), pIn1 ); + if ( uTruth == 8 ) // 1000 // 0111 7 + pRes = Aig_And( p->pManRes, pIn0 , pIn1 ); + if ( pRes ) + pRes = Aig_NotCond( pRes, fCompl ); + return pRes; +} + /**Function************************************************************* Synopsis [] @@ -260,17 +447,19 @@ int Csw_CutMerge( Csw_Man_t * p, Csw_Cut_t * pCut0, Csw_Cut_t * pCut1, Csw_Cut_t SeeAlso [] ***********************************************************************/ -Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) +Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Aig_Obj_t * pObj, int fTriv ) { Csw_Cut_t * pCutSet, * pCut; int i; // create the cutset of the node - pCutSet = (Csw_Cut_t *)Dar_MmFixedEntryFetch( p->pMemCuts ); + pCutSet = (Csw_Cut_t *)Aig_MmFixedEntryFetch( p->pMemCuts ); Csw_ObjSetCuts( p, pObj, pCutSet ); Csw_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 ) @@ -280,7 +469,7 @@ Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) pCut->iNode = pObj->Id; pCut->nFanins = 1; pCut->pFanins[0] = pObj->Id; - pCut->uSign = Csw_ObjCutSign( pObj->Id ); + pCut->uSign = Aig_ObjCutSign( pObj->Id ); memset( Csw_CutTruth(pCut), 0xAA, sizeof(unsigned) * p->nTruthWords ); } return pCutSet; @@ -288,7 +477,7 @@ Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) /**Function************************************************************* - Synopsis [] + Synopsis [Derives cuts for one node and sweeps this node.] Description [] @@ -297,23 +486,24 @@ Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Csw_ObjSweep( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) +Aig_Obj_t * Csw_ObjSweep( Csw_Man_t * p, Aig_Obj_t * pObj, int fTriv ) { + int fUseResub = 1; Csw_Cut_t * pCut0, * pCut1, * pCut, * pCutSet; - Dar_Obj_t * pFanin0 = Dar_ObjFanin0(pObj); - Dar_Obj_t * pFanin1 = Dar_ObjFanin1(pObj); - Dar_Obj_t * pObjNew; + Aig_Obj_t * pFanin0 = Aig_ObjFanin0(pObj); + Aig_Obj_t * pFanin1 = Aig_ObjFanin1(pObj); + Aig_Obj_t * pObjNew; unsigned * pTruth; - int i, k, nVars, iVar; + int i, k, nVars, nFanins, iVar, clk; - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) ) + assert( !Aig_IsComplement(pObj) ); + if ( !Aig_ObjIsNode(pObj) ) return pObj; if ( Csw_ObjCuts(p, pObj) ) return pObj; // the node is not processed yet assert( Csw_ObjCuts(p, pObj) == NULL ); - assert( Dar_ObjIsNode(pObj) ); + assert( Aig_ObjIsNode(pObj) ); // set up the first cut pCutSet = Csw_ObjPrepareCuts( p, pObj, fTriv ); @@ -329,48 +519,77 @@ Dar_Obj_t * Csw_ObjSweep( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ) continue; // get the next cut of this node pCut = Csw_CutFindFree( p, pObj ); +clk = clock(); // assemble the new cut if ( !Csw_CutMerge( p, pCut0, pCut1, pCut ) ) { assert( pCut->nFanins == 0 ); continue; } -/* // check containment - if ( Csw_CutFilter( p, pCutSet, pCut ) ) + if ( Csw_CutFilter( p, pObj, pCut ) ) { - pCut->nFanins = 0; + assert( pCut->nFanins == 0 ); continue; } -*/ // create its truth table - pTruth = Csw_CutComputeTruth( p, pCut, pCut0, pCut1, Dar_ObjFaninC0(pObj), Dar_ObjFaninC1(pObj) ); - // check for trivial truth table + pTruth = Csw_CutComputeTruth( p, pCut, pCut0, pCut1, Aig_ObjFaninC0(pObj), Aig_ObjFaninC1(pObj) ); + // support minimize the truth table + nFanins = pCut->nFanins; +// nVars = Csw_CutSupportMinimize( p, pCut ); // leads to quality degradation nVars = Kit_TruthSupportSize( pTruth, p->nLeafMax ); +p->timeCuts += clock() - clk; + + // check for trivial truth tables if ( nVars == 0 ) - return Dar_NotCond( Dar_ManConst1(p->pManRes), !(pTruth[0] & 1) ); + { + p->nNodesTriv0++; + return Aig_NotCond( Aig_ManConst1(p->pManRes), !(pTruth[0] & 1) ); + } if ( nVars == 1 ) { + p->nNodesTriv1++; iVar = Kit_WordFindFirstBit( Kit_TruthSupport(pTruth, p->nLeafMax) ); assert( iVar < pCut->nFanins ); - return Dar_NotCond( Dar_ManObj(p->pManRes, pCut->pFanins[iVar]), (pTruth[0] & 1) ); + return Aig_NotCond( Aig_ManObj(p->pManRes, pCut->pFanins[iVar]), (pTruth[0] & 1) ); + } + if ( nVars == 2 && nFanins > 2 && fUseResub ) + { + if ( pObjNew = Csw_ObjTwoVarCut( p, pCut ) ) + { + p->nNodesTriv2++; + return pObjNew; + } } + // check if an equivalent node with the same cut exists - if ( pObjNew = Csw_TableCutLookup( p, pCut ) ) +clk = clock(); + pObjNew = pCut->nFanins > 2 ? Csw_TableCutLookup( p, pCut ) : NULL; +p->timeHash += clock() - clk; + if ( pObjNew ) + { + p->nNodesCuts++; return pObjNew; + } + // assign the cost pCut->Cost = Csw_CutFindCost( p, pCut ); assert( pCut->nFanins > 0 ); assert( pCut->Cost > 0 ); } + p->nNodesTried++; // load the resulting cuts into the table +clk = clock(); Csw_ObjForEachCut( p, pObj, pCut, i ) + { if ( pCut->nFanins > 2 ) { assert( pCut->Cost > 0 ); Csw_TableCutInsert( p, pCut ); } + } +p->timeHash += clock() - clk; // return the node if could not replace it return pObj; diff --git a/src/aig/csw/cswInt.h b/src/aig/csw/cswInt.h index 74fa417b..37efe9b4 100644 --- a/src/aig/csw/cswInt.h +++ b/src/aig/csw/cswInt.h @@ -35,6 +35,7 @@ extern "C" { #include #include +#include "aig.h" #include "dar.h" #include "kit.h" #include "csw.h" @@ -55,9 +56,12 @@ struct Csw_Cut_t_ { Csw_Cut_t * pNext; // the next cut in the table int Cost; // the cost of the cut +// float Cost; // the cost of the cut unsigned uSign; // cut signature int iNode; // the node, for which it is the cut - int nFanins; // the number of words in truth table + 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) }; @@ -65,10 +69,11 @@ struct Csw_Cut_t_ struct Csw_Man_t_ { // AIG manager - Dar_Man_t * pManAig; // the input AIG manager - Dar_Man_t * pManRes; // the output AIG manager - Dar_Obj_t ** pEquiv; // the equivalent nodes in the resulting manager + Aig_Man_t * pManAig; // the input AIG manager + Aig_Man_t * pManRes; // the output AIG manager + Aig_Obj_t ** pEquiv; // the equivalent nodes in the resulting manager Csw_Cut_t ** pCuts; // the cuts for each node in the output manager + int * pnRefs; // the number of references of each new node // hash table for cuts Csw_Cut_t ** pTable; // the table composed of cuts int nTableSize; // the size of hash table @@ -79,25 +84,36 @@ struct Csw_Man_t_ // internal variables int nCutSize; // the number of bytes needed to store one cut int nTruthWords; // the number of truth table words - Dar_MmFixed_t * pMemCuts; // memory manager for cuts + Aig_MmFixed_t * pMemCuts; // memory manager for cuts unsigned * puTemp[4]; // used for the truth table computation + // statistics + int nNodesTriv0; // the number of trivial nodes + int nNodesTriv1; // the number of trivial nodes + int nNodesTriv2; // the number of trivial nodes + int nNodesCuts; // the number of rewritten nodes + int nNodesTried; // the number of nodes tried + int timeCuts; // time to compute the cut and its truth table + int timeHash; // time for hashing cuts + int timeOther; // other time + int timeTotal; // total time }; -static inline unsigned Csw_ObjCutSign( unsigned ObjId ) { return (1 << (ObjId % 31)); } +static inline int Csw_CutLeaveNum( Csw_Cut_t * pCut ) { return pCut->nFanins; } +static inline int * Csw_CutLeaves( Csw_Cut_t * pCut ) { return pCut->pFanins; } +static inline unsigned * Csw_CutTruth( Csw_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nLeafMax); } +static inline Csw_Cut_t * Csw_CutNext( Csw_Cut_t * pCut ) { return (Csw_Cut_t *)(((char *)pCut) + pCut->nCutSize); } -static inline int Csw_CutLeaveNum( Csw_Cut_t * pCut ) { return pCut->nFanins; } -static inline int * Csw_CutLeaves( Csw_Cut_t * pCut ) { return pCut->pFanins; } -static inline unsigned * Csw_CutTruth( Csw_Cut_t * pCut ) { return (unsigned *)(pCut->pFanins + pCut->nFanins); } -static inline Csw_Cut_t * Csw_CutNext( Csw_Man_t * p, Csw_Cut_t * pCut ) { return (Csw_Cut_t *)(((char *)pCut) + p->nCutSize); } +static inline int Csw_ObjRefs( Csw_Man_t * p, Aig_Obj_t * pObj ) { return p->pnRefs[pObj->Id]; } +static inline void Csw_ObjAddRefs( Csw_Man_t * p, Aig_Obj_t * pObj, int nRefs ) { p->pnRefs[pObj->Id] += nRefs; } -static inline Csw_Cut_t * Csw_ObjCuts( Csw_Man_t * p, Dar_Obj_t * pObj ) { return p->pCuts[pObj->Id]; } -static inline void Csw_ObjSetCuts( Csw_Man_t * p, Dar_Obj_t * pObj, Csw_Cut_t * pCuts ) { p->pCuts[pObj->Id] = pCuts; } +static inline Csw_Cut_t * Csw_ObjCuts( Csw_Man_t * p, Aig_Obj_t * pObj ) { return p->pCuts[pObj->Id]; } +static inline void Csw_ObjSetCuts( Csw_Man_t * p, Aig_Obj_t * pObj, Csw_Cut_t * pCuts ) { p->pCuts[pObj->Id] = pCuts; } -static inline Dar_Obj_t * Csw_ObjEquiv( Csw_Man_t * p, Dar_Obj_t * pObj ) { return p->pEquiv[pObj->Id]; } -static inline void Csw_ObjSetEquiv( Csw_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pEquiv ) { p->pEquiv[pObj->Id] = pEquiv; } +static inline Aig_Obj_t * Csw_ObjEquiv( Csw_Man_t * p, Aig_Obj_t * pObj ) { return p->pEquiv[pObj->Id]; } +static inline void Csw_ObjSetEquiv( Csw_Man_t * p, Aig_Obj_t * pObj, Aig_Obj_t * pEquiv ) { p->pEquiv[pObj->Id] = pEquiv; } -static inline Dar_Obj_t * Csw_ObjChild0Equiv( Csw_Man_t * p, Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin0(pObj)? Dar_NotCond(Csw_ObjEquiv(p, Dar_ObjFanin0(pObj)), Dar_ObjFaninC0(pObj)) : NULL; } -static inline Dar_Obj_t * Csw_ObjChild1Equiv( Csw_Man_t * p, Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin1(pObj)? Dar_NotCond(Csw_ObjEquiv(p, Dar_ObjFanin1(pObj)), Dar_ObjFaninC1(pObj)) : NULL; } +static inline Aig_Obj_t * Csw_ObjChild0Equiv( Csw_Man_t * p, Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin0(pObj)? Aig_NotCond(Csw_ObjEquiv(p, Aig_ObjFanin0(pObj)), Aig_ObjFaninC0(pObj)) : NULL; } +static inline Aig_Obj_t * Csw_ObjChild1Equiv( Csw_Man_t * p, Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? Aig_NotCond(Csw_ObjEquiv(p, Aig_ObjFanin1(pObj)), Aig_ObjFaninC1(pObj)) : NULL; } //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// @@ -109,25 +125,25 @@ static inline Dar_Obj_t * Csw_ObjChild1Equiv( Csw_Man_t * p, Dar_Obj_t * pObj ) // iterator over cuts of the node #define Csw_ObjForEachCut( p, pObj, pCut, i ) \ - for ( i = 0, pCut = Csw_ObjCuts(p, pObj); i < p->nCutsMax; i++, pCut = Csw_CutNext(p, pCut) ) + for ( i = 0, pCut = Csw_ObjCuts(p, pObj); i < p->nCutsMax; i++, pCut = Csw_CutNext(pCut) ) // iterator over leaves of the cut #define Csw_CutForEachLeaf( p, pCut, pLeaf, i ) \ - for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Dar_ManObj(p, (pCut)->pFanins[i])); i++ ) + for ( i = 0; (i < (int)(pCut)->nFanins) && ((pLeaf) = Aig_ManObj(p, (pCut)->pFanins[i])); i++ ) //////////////////////////////////////////////////////////////////////// /// FUNCTION DECLARATIONS /// //////////////////////////////////////////////////////////////////////// /*=== cnfCut.c ========================================================*/ -extern Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ); -extern Dar_Obj_t * Csw_ObjSweep( Csw_Man_t * p, Dar_Obj_t * pObj, int fTriv ); +extern Csw_Cut_t * Csw_ObjPrepareCuts( Csw_Man_t * p, Aig_Obj_t * pObj, int fTriv ); +extern Aig_Obj_t * Csw_ObjSweep( Csw_Man_t * p, Aig_Obj_t * pObj, int fTriv ); /*=== cnfMan.c ========================================================*/ -extern Csw_Man_t * Csw_ManStart( Dar_Man_t * pMan, int nCutsMax, int nLeafMax, int fVerbose ); +extern Csw_Man_t * Csw_ManStart( Aig_Man_t * pMan, int nCutsMax, int nLeafMax, int fVerbose ); extern void Csw_ManStop( Csw_Man_t * p ); /*=== cnfTable.c ========================================================*/ +extern int Csw_TableCountCuts( Csw_Man_t * p ); extern void Csw_TableCutInsert( Csw_Man_t * p, Csw_Cut_t * pCut ); -extern Dar_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ); -extern unsigned int Cudd_PrimeCws( unsigned int p ); +extern Aig_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ); #ifdef __cplusplus } diff --git a/src/aig/csw/cswMan.c b/src/aig/csw/cswMan.c index 180fecef..2af1a844 100644 --- a/src/aig/csw/cswMan.c +++ b/src/aig/csw/cswMan.c @@ -39,10 +39,10 @@ SeeAlso [] ***********************************************************************/ -Csw_Man_t * Csw_ManStart( Dar_Man_t * pMan, int nCutsMax, int nLeafMax, int fVerbose ) +Csw_Man_t * Csw_ManStart( Aig_Man_t * pMan, int nCutsMax, int nLeafMax, int fVerbose ) { Csw_Man_t * p; - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; assert( nCutsMax >= 2 ); assert( nLeafMax <= 16 ); @@ -54,24 +54,26 @@ Csw_Man_t * Csw_ManStart( Dar_Man_t * pMan, int nCutsMax, int nLeafMax, int fVer p->fVerbose = fVerbose; p->pManAig = pMan; // create the new manager - p->pManRes = Dar_ManStartFrom( pMan ); - assert( Dar_ManPiNum(p->pManAig) == Dar_ManPiNum(p->pManRes) ); + p->pManRes = Aig_ManStartFrom( pMan ); + assert( Aig_ManPiNum(p->pManAig) == Aig_ManPiNum(p->pManRes) ); // allocate room for cuts and equivalent nodes - p->pEquiv = ALLOC( Dar_Obj_t *, Dar_ManObjIdMax(pMan) + 1 ); - p->pCuts = ALLOC( Csw_Cut_t *, Dar_ManObjIdMax(pMan) + 1 ); - memset( p->pCuts, 0, sizeof(Dar_Obj_t *) * (Dar_ManObjIdMax(pMan) + 1) ); + p->pnRefs = ALLOC( int, Aig_ManObjIdMax(pMan) + 1 ); + p->pEquiv = ALLOC( Aig_Obj_t *, Aig_ManObjIdMax(pMan) + 1 ); + p->pCuts = ALLOC( Csw_Cut_t *, Aig_ManObjIdMax(pMan) + 1 ); + memset( p->pCuts, 0, sizeof(Aig_Obj_t *) * (Aig_ManObjIdMax(pMan) + 1) ); + memset( p->pnRefs, 0, sizeof(int) * (Aig_ManObjIdMax(pMan) + 1) ); // allocate memory manager - p->nTruthWords = Dar_TruthWordNum(nLeafMax); + p->nTruthWords = Aig_TruthWordNum(nLeafMax); p->nCutSize = sizeof(Csw_Cut_t) + sizeof(int) * nLeafMax + sizeof(unsigned) * p->nTruthWords; - p->pMemCuts = Dar_MmFixedStart( p->nCutSize * p->nCutsMax, 512 ); + p->pMemCuts = Aig_MmFixedStart( p->nCutSize * p->nCutsMax, 512 ); // allocate hash table for cuts - p->nTableSize = Cudd_PrimeCws( Dar_ManNodeNum(pMan) * p->nCutsMax / 2 ); + p->nTableSize = Aig_PrimeCudd( Aig_ManNodeNum(pMan) * p->nCutsMax / 2 ); p->pTable = ALLOC( Csw_Cut_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Dar_Obj_t *) * p->nTableSize ); + memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize ); // set the pointers to the available fraig nodes - Csw_ObjSetEquiv( p, Dar_ManConst1(p->pManAig), Dar_ManConst1(p->pManRes) ); - Dar_ManForEachPi( p->pManAig, pObj, i ) - Csw_ObjSetEquiv( p, pObj, Dar_ManPi(p->pManRes, i) ); + Csw_ObjSetEquiv( p, Aig_ManConst1(p->pManAig), Aig_ManConst1(p->pManRes) ); + Aig_ManForEachPi( p->pManAig, pObj, i ) + Csw_ObjSetEquiv( p, pObj, Aig_ManPi(p->pManRes, i) ); // room for temporary truth tables p->puTemp[0] = ALLOC( unsigned, 4 * p->nTruthWords ); p->puTemp[1] = p->puTemp[0] + p->nTruthWords; @@ -93,8 +95,23 @@ Csw_Man_t * Csw_ManStart( Dar_Man_t * pMan, int nCutsMax, int nLeafMax, int fVer ***********************************************************************/ void Csw_ManStop( Csw_Man_t * p ) { + if ( p->fVerbose ) + { + int nNodesBeg = Aig_ManNodeNum(p->pManAig); + int nNodesEnd = Aig_ManNodeNum(p->pManRes); + printf( "Beg = %7d. End = %7d. (%6.2f %%) Try = %7d. Cuts = %8d.\n", + nNodesBeg, nNodesEnd, 100.0*(nNodesBeg-nNodesEnd)/nNodesBeg, + p->nNodesTried, Csw_TableCountCuts( p ) ); + printf( "Triv0 = %6d. Triv1 = %6d. Triv2 = %6d. Cut-replace = %6d.\n", + p->nNodesTriv0, p->nNodesTriv1, p->nNodesTriv2, p->nNodesCuts ); + PRTP( "Cuts ", p->timeCuts, p->timeTotal ); + PRTP( "Hashing ", p->timeHash, p->timeTotal ); + PRTP( "Other ", p->timeOther, p->timeTotal ); + PRTP( "TOTAL ", p->timeTotal, p->timeTotal ); + } free( p->puTemp[0] ); - Dar_MmFixedStop( p->pMemCuts, 0 ); + Aig_MmFixedStop( p->pMemCuts, 0 ); + free( p->pnRefs ); free( p->pEquiv ); free( p->pCuts ); free( p->pTable ); diff --git a/src/aig/csw/cswTable.c b/src/aig/csw/cswTable.c index 82f09d01..87e36ae1 100644 --- a/src/aig/csw/cswTable.c +++ b/src/aig/csw/cswTable.c @@ -65,41 +65,26 @@ unsigned Csw_CutHash( Csw_Cut_t * pCut ) return uHash; } -/**Function******************************************************************** - - Synopsis [Returns the next prime >= p.] +/**Function************************************************************* - Description [Copied from CUDD, for stand-aloneness.] + Synopsis [Returns the total number of cuts in the table.] - SideEffects [None] + Description [] + + SideEffects [] SeeAlso [] -******************************************************************************/ -unsigned int Cudd_PrimeCws( unsigned int p ) +***********************************************************************/ +int Csw_TableCountCuts( Csw_Man_t * 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 */ + Csw_Cut_t * pEnt; + int i, Counter = 0; + for ( i = 0; i < p->nTableSize; i++ ) + for ( pEnt = p->pTable[i]; pEnt; pEnt = pEnt->pNext ) + Counter++; + return Counter; +} /**Function************************************************************* @@ -130,9 +115,9 @@ void Csw_TableCutInsert( Csw_Man_t * p, Csw_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ) +Aig_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ) { - Dar_Obj_t * pRes = NULL; + Aig_Obj_t * pRes = NULL; Csw_Cut_t * pEnt; unsigned * pTruthNew, * pTruthOld; int iEntry = Csw_CutHash(pCut) % p->nTableSize; @@ -150,8 +135,8 @@ Dar_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ) { if ( Kit_TruthIsEqual( pTruthOld, pTruthNew, pCut->nFanins ) ) { - pRes = Dar_ManObj( p->pManRes, pEnt->iNode ); - assert( pRes->fPhase == Dar_ManObj( p->pManRes, pCut->iNode )->fPhase ); + pRes = Aig_ManObj( p->pManRes, pEnt->iNode ); + assert( pRes->fPhase == Aig_ManObj( p->pManRes, pCut->iNode )->fPhase ); break; } } @@ -159,8 +144,8 @@ Dar_Obj_t * Csw_TableCutLookup( Csw_Man_t * p, Csw_Cut_t * pCut ) { if ( Kit_TruthIsOpposite( pTruthOld, pTruthNew, pCut->nFanins ) ) { - pRes = Dar_Not( Dar_ManObj( p->pManRes, pEnt->iNode ) ); - assert( Dar_Regular(pRes)->fPhase != Dar_ManObj( p->pManRes, pCut->iNode )->fPhase ); + pRes = Aig_Not( Aig_ManObj( p->pManRes, pEnt->iNode ) ); + assert( Aig_Regular(pRes)->fPhase != Aig_ManObj( p->pManRes, pCut->iNode )->fPhase ); break; } } diff --git a/src/aig/dar/dar.h b/src/aig/dar/dar.h index 8e82cdf4..cff2785b 100644 --- a/src/aig/dar/dar.h +++ b/src/aig/dar/dar.h @@ -29,14 +29,6 @@ extern "C" { /// INCLUDES /// //////////////////////////////////////////////////////////////////////// -#include -#include -#include -#include -#include - -#include "vec.h" - //////////////////////////////////////////////////////////////////////// /// PARAMETERS /// //////////////////////////////////////////////////////////////////////// @@ -46,434 +38,34 @@ extern "C" { //////////////////////////////////////////////////////////////////////// typedef struct Dar_Par_t_ Dar_Par_t; -typedef struct Dar_Man_t_ Dar_Man_t; -typedef struct Dar_Obj_t_ Dar_Obj_t; -typedef struct Dar_Cut_t_ Dar_Cut_t; -typedef struct Dar_Cnf_t_ Dar_Cnf_t; -typedef struct Dar_MmFixed_t_ Dar_MmFixed_t; -typedef struct Dar_MmFlex_t_ Dar_MmFlex_t; -typedef struct Dar_MmStep_t_ Dar_MmStep_t; - -// the maximum number of cuts stored at a node -#define DAR_CUT_BASE 64 -// object types -typedef enum { - DAR_AIG_NONE, // 0: non-existent object - DAR_AIG_CONST1, // 1: constant 1 - DAR_AIG_PI, // 2: primary input - DAR_AIG_PO, // 3: primary output - DAR_AIG_BUF, // 4: buffer node - DAR_AIG_AND, // 5: AND node - DAR_AIG_EXOR, // 6: EXOR node - DAR_AIG_LATCH, // 7: latch - DAR_AIG_VOID // 8: unused object -} Dar_Type_t; - -// the parameters +// the rewriting parameters struct Dar_Par_t_ { - int fUpdateLevel; - int fUseZeros; - int fVerbose; - int fVeryVerbose; -}; - -// the AIG 4-cut -struct Dar_Cut_t_ // 8 words -{ - unsigned uSign; - unsigned uTruth : 16; // the truth table of the cut function - unsigned Cost : 5; // the cost of the cut in terms of CNF clauses - unsigned FanRefs : 4; // the average number of fanin references - unsigned NoRefs : 3; // the average number of fanin references - unsigned nLeaves : 3; // the number of leaves - unsigned fBest : 1; // marks the best cut - int pLeaves[4]; // the array of leaves -// unsigned char pIndices[4]; - float Area; // the area flow or exact area of the cut -}; - -// the AIG node -struct Dar_Obj_t_ // 8 words -{ - void * pData; // misc (cuts, copy, etc) - Dar_Obj_t * pNext; // strashing table - Dar_Obj_t * pFanin0; // fanin - Dar_Obj_t * pFanin1; // fanin - unsigned long Type : 3; // object type - unsigned long fPhase : 1; // value under 000...0 pattern - unsigned long fMarkA : 1; // multipurpose mask - unsigned long fMarkB : 1; // multipurpose mask - unsigned long 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 -}; - -// the AIG manager -struct Dar_Man_t_ -{ - // parameters governing rewriting - Dar_Par_t * pPars; - // 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) - Dar_Obj_t * pConst1; // the constant 1 node - Dar_Obj_t Ghost; // the ghost node - // AIG node counters - int nObjs[DAR_AIG_VOID];// the number of objects by type - int nCreated; // the number of created objects - int nDeleted; // the number of deleted objects - // structural hash table - Dar_Obj_t ** pTable; // structural hash table - int nTableSize; // structural hash table size - // 4-input cuts of the nodes - Dar_Cut_t * pBaseCuts[DAR_CUT_BASE]; - Dar_Cut_t BaseCuts[DAR_CUT_BASE]; - int nBaseCuts; - int nCutsUsed; - int nCutsFiltered; - // current rewriting step - int nNodesInit; // the original number of nodes - Vec_Ptr_t * vLeavesBest; // the best set of leaves - int OutBest; // the best output (in the library) - int OutNumBest; // the best number of the output - int GainBest; // the best gain - int LevelBest; // the level of node with the best gain - int ClassBest; // the equivalence class of the best replacement - int nTotalSubgs; // the total number of subgraphs tried - int ClassTimes[222];// the runtimes for each class - int ClassGains[222];// the gains for each class - int ClassSubgs[222];// the graphs for each class - int nCutMemUsed; // memory used for cuts - // various data members - Dar_MmFixed_t * pMemObjs; // memory manager for objects - Dar_MmFlex_t * pMemCuts; // memory manager for cuts - Vec_Int_t * vRequired; // the required times - int nLevelMax; // maximum number of levels - void * pData; // the temporary data - int nTravIds; // the current traversal ID - int fCatchExor; // enables EXOR nodes - // CNF mapping - void * pManCnf; // CNF conversion manager - // rewriting statistics - int nCutsBad; - int nCutsGood; - // timing statistics - int timeCuts; - int timeEval; - int timeOther; - int timeTotal; - int time1; - int time2; -}; - -// the CNF asserting outputs of AIG to be 1 -struct Dar_Cnf_t_ -{ - Dar_Man_t * pMan; // the AIG manager, for which CNF is computed - int nLiterals; // the number of CNF literals - int nClauses; // the number of CNF clauses - int ** pClauses; // the CNF clauses - int * pVarNums; // the number of CNF variable for each node ID (-1 if unused) + int nCutsMax; // the maximum number of cuts to try + int nSubgMax; // the maximum number of subgraphs to try + int fUpdateLevel; // update level + int fUseZeros; // performs zero-cost replacement + int fVerbose; // enables verbose output + int fVeryVerbose; // enables very verbose output }; //////////////////////////////////////////////////////////////////////// /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// -#define DAR_MIN(a,b) (((a) < (b))? (a) : (b)) -#define DAR_MAX(a,b) (((a) > (b))? (a) : (b)) -#define DAR_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 Dar_BitWordNum( int nBits ) { return (nBits>>5) + ((nBits&31) > 0); } -static inline int Dar_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); } -static inline int Dar_InfoHasBit( unsigned * p, int i ) { return (p[(i)>>5] & (1<<((i) & 31))) > 0; } -static inline void Dar_InfoSetBit( unsigned * p, int i ) { p[(i)>>5] |= (1<<((i) & 31)); } -static inline void Dar_InfoXorBit( unsigned * p, int i ) { p[(i)>>5] ^= (1<<((i) & 31)); } - -static inline Dar_Obj_t * Dar_Regular( Dar_Obj_t * p ) { return (Dar_Obj_t *)((unsigned long)(p) & ~01); } -static inline Dar_Obj_t * Dar_Not( Dar_Obj_t * p ) { return (Dar_Obj_t *)((unsigned long)(p) ^ 01); } -static inline Dar_Obj_t * Dar_NotCond( Dar_Obj_t * p, int c ) { return (Dar_Obj_t *)((unsigned long)(p) ^ (c)); } -static inline int Dar_IsComplement( Dar_Obj_t * p ) { return (int )(((unsigned long)p) & 01); } - -static inline Dar_Obj_t * Dar_ManConst0( Dar_Man_t * p ) { return Dar_Not(p->pConst1); } -static inline Dar_Obj_t * Dar_ManConst1( Dar_Man_t * p ) { return p->pConst1; } -static inline Dar_Obj_t * Dar_ManGhost( Dar_Man_t * p ) { return &p->Ghost; } -static inline Dar_Obj_t * Dar_ManPi( Dar_Man_t * p, int i ) { return (Dar_Obj_t *)Vec_PtrEntry(p->vPis, i); } -static inline Dar_Obj_t * Dar_ManPo( Dar_Man_t * p, int i ) { return (Dar_Obj_t *)Vec_PtrEntry(p->vPos, i); } -static inline Dar_Obj_t * Dar_ManObj( Dar_Man_t * p, int i ) { return p->vObjs ? (Dar_Obj_t *)Vec_PtrEntry(p->vObjs, i) : NULL; } - -static inline int Dar_ManPiNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_PI]; } -static inline int Dar_ManPoNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_PO]; } -static inline int Dar_ManBufNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_BUF]; } -static inline int Dar_ManAndNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_AND]; } -static inline int Dar_ManExorNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_EXOR]; } -static inline int Dar_ManLatchNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_LATCH]; } -static inline int Dar_ManNodeNum( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_AND]+p->nObjs[DAR_AIG_EXOR]; } -static inline int Dar_ManGetCost( Dar_Man_t * p ) { return p->nObjs[DAR_AIG_AND]+3*p->nObjs[DAR_AIG_EXOR]; } -static inline int Dar_ManObjNum( Dar_Man_t * p ) { return p->nCreated - p->nDeleted; } -static inline int Dar_ManObjIdMax( Dar_Man_t * p ) { return Vec_PtrSize(p->vObjs); } - -static inline Dar_Type_t Dar_ObjType( Dar_Obj_t * pObj ) { return (Dar_Type_t)pObj->Type; } -static inline int Dar_ObjIsNone( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_NONE; } -static inline int Dar_ObjIsConst1( Dar_Obj_t * pObj ) { assert(!Dar_IsComplement(pObj)); return pObj->Type == DAR_AIG_CONST1; } -static inline int Dar_ObjIsPi( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_PI; } -static inline int Dar_ObjIsPo( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_PO; } -static inline int Dar_ObjIsBuf( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_BUF; } -static inline int Dar_ObjIsAnd( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_AND; } -static inline int Dar_ObjIsExor( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_EXOR; } -static inline int Dar_ObjIsLatch( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_LATCH; } -static inline int Dar_ObjIsNode( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_AND || pObj->Type == DAR_AIG_EXOR; } -static inline int Dar_ObjIsTerm( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_PI || pObj->Type == DAR_AIG_PO || pObj->Type == DAR_AIG_CONST1; } -static inline int Dar_ObjIsHash( Dar_Obj_t * pObj ) { return pObj->Type == DAR_AIG_AND || pObj->Type == DAR_AIG_EXOR || pObj->Type == DAR_AIG_LATCH; } - -static inline int Dar_ObjIsMarkA( Dar_Obj_t * pObj ) { return pObj->fMarkA; } -static inline void Dar_ObjSetMarkA( Dar_Obj_t * pObj ) { pObj->fMarkA = 1; } -static inline void Dar_ObjClearMarkA( Dar_Obj_t * pObj ) { pObj->fMarkA = 0; } - -static inline void Dar_ObjSetTravId( Dar_Obj_t * pObj, int TravId ) { pObj->TravId = TravId; } -static inline void Dar_ObjSetTravIdCurrent( Dar_Man_t * p, Dar_Obj_t * pObj ) { pObj->TravId = p->nTravIds; } -static inline void Dar_ObjSetTravIdPrevious( Dar_Man_t * p, Dar_Obj_t * pObj ) { pObj->TravId = p->nTravIds - 1; } -static inline int Dar_ObjIsTravIdCurrent( Dar_Man_t * p, Dar_Obj_t * pObj ) { return (int)(pObj->TravId == p->nTravIds); } -static inline int Dar_ObjIsTravIdPrevious( Dar_Man_t * p, Dar_Obj_t * pObj ) { return (int)(pObj->TravId == p->nTravIds - 1); } - -static inline int Dar_ObjTravId( Dar_Obj_t * pObj ) { return (int)pObj->pData; } -static inline int Dar_ObjPhase( Dar_Obj_t * pObj ) { return pObj->fPhase; } -static inline int Dar_ObjRefs( Dar_Obj_t * pObj ) { return pObj->nRefs; } -static inline void Dar_ObjRef( Dar_Obj_t * pObj ) { pObj->nRefs++; } -static inline void Dar_ObjDeref( Dar_Obj_t * pObj ) { assert( pObj->nRefs > 0 ); pObj->nRefs--; } -static inline void Dar_ObjClearRef( Dar_Obj_t * pObj ) { pObj->nRefs = 0; } -static inline int Dar_ObjFaninC0( Dar_Obj_t * pObj ) { return Dar_IsComplement(pObj->pFanin0); } -static inline int Dar_ObjFaninC1( Dar_Obj_t * pObj ) { return Dar_IsComplement(pObj->pFanin1); } -static inline Dar_Obj_t * Dar_ObjFanin0( Dar_Obj_t * pObj ) { return Dar_Regular(pObj->pFanin0); } -static inline Dar_Obj_t * Dar_ObjFanin1( Dar_Obj_t * pObj ) { return Dar_Regular(pObj->pFanin1); } -static inline Dar_Obj_t * Dar_ObjChild0( Dar_Obj_t * pObj ) { return pObj->pFanin0; } -static inline Dar_Obj_t * Dar_ObjChild1( Dar_Obj_t * pObj ) { return pObj->pFanin1; } -static inline Dar_Obj_t * Dar_ObjChild0Copy( Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin0(pObj)? Dar_NotCond((Dar_Obj_t *)Dar_ObjFanin0(pObj)->pData, Dar_ObjFaninC0(pObj)) : NULL; } -static inline Dar_Obj_t * Dar_ObjChild1Copy( Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin1(pObj)? Dar_NotCond((Dar_Obj_t *)Dar_ObjFanin1(pObj)->pData, Dar_ObjFaninC1(pObj)) : NULL; } -static inline int Dar_ObjLevel( Dar_Obj_t * pObj ) { return pObj->nRefs; } -static inline int Dar_ObjLevelNew( Dar_Obj_t * pObj ) { return 1 + Dar_ObjIsExor(pObj) + DAR_MAX(Dar_ObjFanin0(pObj)->Level, Dar_ObjFanin1(pObj)->Level); } -static inline int Dar_ObjFaninPhase( Dar_Obj_t * pObj ) { return Dar_Regular(pObj)->fPhase ^ Dar_IsComplement(pObj); } -static inline void Dar_ObjClean( Dar_Obj_t * pObj ) { memset( pObj, 0, sizeof(Dar_Obj_t) ); } -static inline int Dar_ObjWhatFanin( Dar_Obj_t * pObj, Dar_Obj_t * pFanin ) -{ - if ( Dar_ObjFanin0(pObj) == pFanin ) return 0; - if ( Dar_ObjFanin1(pObj) == pFanin ) return 1; - assert(0); return -1; -} -static inline int Dar_ObjFanoutC( Dar_Obj_t * pObj, Dar_Obj_t * pFanout ) -{ - if ( Dar_ObjFanin0(pFanout) == pObj ) return Dar_ObjFaninC0(pObj); - if ( Dar_ObjFanin1(pFanout) == pObj ) return Dar_ObjFaninC1(pObj); - assert(0); return -1; -} -static inline Dar_Cut_t * Dar_ObjBestCut( Dar_Obj_t * pObj ) -{ - Dar_Cut_t * pCut; int i; - for ( pCut = pObj->pData, i = 0; i < (int)pObj->nCuts; i++, pCut++ ) - if ( pCut->fBest ) - return pCut; - return NULL; -} -static inline void Dar_ObjSetBestCut( Dar_Cut_t * pCut ) { assert( !pCut->fBest ); pCut->fBest = 1; } -static inline void Dar_ObjClearBestCut( Dar_Cut_t * pCut ) { assert( pCut->fBest ); pCut->fBest = 0; } - -// create the ghost of the new node -static inline Dar_Obj_t * Dar_ObjCreateGhost( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1, Dar_Type_t Type ) -{ - Dar_Obj_t * pGhost; - assert( Type != DAR_AIG_AND || !Dar_ObjIsConst1(Dar_Regular(p0)) ); - assert( p1 == NULL || !Dar_ObjIsConst1(Dar_Regular(p1)) ); - assert( Type == DAR_AIG_PI || Dar_Regular(p0) != Dar_Regular(p1) ); - pGhost = Dar_ManGhost(p); - pGhost->Type = Type; - if ( p1 == NULL || Dar_Regular(p0)->Id < Dar_Regular(p1)->Id ) - { - pGhost->pFanin0 = p0; - pGhost->pFanin1 = p1; - } - else - { - pGhost->pFanin0 = p1; - pGhost->pFanin1 = p0; - } - return pGhost; -} - -// internal memory manager -static inline Dar_Obj_t * Dar_ManFetchMemory( Dar_Man_t * p ) -{ - extern char * Dar_MmFixedEntryFetch( Dar_MmFixed_t * p ); - Dar_Obj_t * pTemp; - pTemp = (Dar_Obj_t *)Dar_MmFixedEntryFetch( p->pMemObjs ); - memset( pTemp, 0, sizeof(Dar_Obj_t) ); - Vec_PtrPush( p->vObjs, pTemp ); - pTemp->Id = p->nCreated++; - return pTemp; -} -static inline void Dar_ManRecycleMemory( Dar_Man_t * p, Dar_Obj_t * pEntry ) -{ - extern void Dar_MmFixedEntryRecycle( Dar_MmFixed_t * p, char * pEntry ); - assert( pEntry->nRefs == 0 ); - pEntry->Type = DAR_AIG_NONE; // distinquishes a dead node from a live node - Dar_MmFixedEntryRecycle( p->pMemObjs, (char *)pEntry ); - p->nDeleted++; -} - - //////////////////////////////////////////////////////////////////////// /// ITERATORS /// //////////////////////////////////////////////////////////////////////// -// iterator over the primary inputs -#define Dar_ManForEachPi( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPis, pObj, i ) -// iterator over the primary outputs -#define Dar_ManForEachPo( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vPos, pObj, i ) -// iterator over all objects, including those currently not used -#define Dar_ManForEachObj( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vObjs, pObj, i ) if ( (pObj) == NULL ) {} else -// iterator over all nodes -#define Dar_ManForEachNode( p, pObj, i ) \ - Vec_PtrForEachEntry( p->vObjs, pObj, i ) if ( (pObj) == NULL || !Dar_ObjIsNode(pObj) ) {} else -// iterator over all cuts of the node -#define Dar_ObjForEachCut( pObj, pCut, i ) \ - for ( pCut = pObj->pData, i = 0; i < (int)pObj->nCuts; i++, pCut++ ) if ( i==0 ) {} else -// iterator over leaves of the cut -#define Dar_CutForEachLeaf( p, pCut, pLeaf, i ) \ - for ( i = 0; (i < (int)(pCut)->nLeaves) && ((pLeaf) = Dar_ManObj(p, (pCut)->pLeaves[i])); i++ ) - //////////////////////////////////////////////////////////////////////// /// FUNCTION DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -/*=== darBalance.c ========================================================*/ -extern Dar_Man_t * Dar_ManBalance( Dar_Man_t * p, int fUpdateLevel ); -extern Dar_Obj_t * Dar_NodeBalanceBuildSuper( Dar_Man_t * p, Vec_Ptr_t * vSuper, Dar_Type_t Type, int fUpdateLevel ); -/*=== darCheck.c ========================================================*/ -extern int Dar_ManCheck( Dar_Man_t * p ); -/*=== darCnf.c ========================================================*/ -extern Dar_Cnf_t * Dar_ManDeriveCnf( Dar_Man_t * p ); -extern Dar_Cut_t * Dar_ObjFindBestCut( Dar_Obj_t * pObj ); -extern void Dar_CutAssignAreaFlow( Dar_Man_t * p, Dar_Cut_t * pCut ); -extern void Dar_CutAssignArea( Dar_Man_t * p, Dar_Cut_t * pCut ); -extern void Dar_CnfFree( Dar_Cnf_t * pCnf ); /*=== darCore.c ========================================================*/ -extern int Dar_ManRewrite( Dar_Man_t * p ); -extern int Dar_ManComputeCuts( Dar_Man_t * p ); -/*=== darCut.c ========================================================*/ -extern void Dar_ManSetupPis( Dar_Man_t * p ); -extern Dar_Cut_t * Dar_ObjComputeCuts_rec( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern Dar_Cut_t * Dar_ObjComputeCuts( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern void Dar_ManCutsFree( Dar_Man_t * p ); -/*=== darData.c ========================================================*/ -extern Vec_Int_t * Dar_LibReadNodes(); -extern Vec_Int_t * Dar_LibReadOuts(); -/*=== darData2.c ========================================================*/ -extern void Dar_LibReadMsops( char ** ppSopSizes, char *** ppSops ); -/*=== darDfs.c ==========================================================*/ -extern Vec_Ptr_t * Dar_ManDfs( Dar_Man_t * p ); -extern Vec_Ptr_t * Dar_ManDfsNodes( Dar_Man_t * p, Dar_Obj_t ** ppNodes, int nNodes ); -extern int Dar_ManCountLevels( Dar_Man_t * p ); -extern void Dar_ManCreateRefs( Dar_Man_t * p ); -extern int Dar_DagSize( Dar_Obj_t * pObj ); -extern void Dar_ConeUnmark_rec( Dar_Obj_t * pObj ); -extern Dar_Obj_t * Dar_Transfer( Dar_Man_t * pSour, Dar_Man_t * pDest, Dar_Obj_t * pObj, int nVars ); -extern Dar_Obj_t * Dar_Compose( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Obj_t * pFunc, int iVar ); -/*=== darLib.c ==========================================================*/ -extern void Dar_LibStart(); -extern void Dar_LibStop(); -extern void Dar_LibEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCut, int Required ); -extern Dar_Obj_t * Dar_LibBuildBest( Dar_Man_t * p ); -/*=== darMan.c ==========================================================*/ -extern Dar_Man_t * Dar_ManStart(); -extern Dar_Man_t * Dar_ManStartFrom( Dar_Man_t * p ); -extern Dar_Man_t * Dar_ManDup( Dar_Man_t * p ); -extern void Dar_ManStop( Dar_Man_t * p ); -extern int Dar_ManCleanup( Dar_Man_t * p ); -extern void Dar_ManPrintStats( Dar_Man_t * p ); -extern void Dar_ManPrintRuntime( Dar_Man_t * p ); -/*=== darMem.c ==========================================================*/ -extern void Dar_ManStartMemory( Dar_Man_t * p ); -extern void Dar_ManStopMemory( Dar_Man_t * p ); -/*=== darObj.c ==========================================================*/ -extern Dar_Obj_t * Dar_ObjCreatePi( Dar_Man_t * p ); -extern Dar_Obj_t * Dar_ObjCreatePo( Dar_Man_t * p, Dar_Obj_t * pDriver ); -extern Dar_Obj_t * Dar_ObjCreate( Dar_Man_t * p, Dar_Obj_t * pGhost ); -extern void Dar_ObjConnect( Dar_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pFan0, Dar_Obj_t * pFan1 ); -extern void Dar_ObjDisconnect( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern void Dar_ObjDelete( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern void Dar_ObjDelete_rec( Dar_Man_t * p, Dar_Obj_t * pObj, int fFreeTop ); -extern void Dar_ObjPatchFanin0( Dar_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pFaninNew ); -extern void Dar_ObjReplace( Dar_Man_t * p, Dar_Obj_t * pObjOld, Dar_Obj_t * pObjNew, int fNodesOnly ); -/*=== darOper.c =========================================================*/ -extern Dar_Obj_t * Dar_IthVar( Dar_Man_t * p, int i ); -extern Dar_Obj_t * Dar_Oper( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1, Dar_Type_t Type ); -extern Dar_Obj_t * Dar_And( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ); -extern Dar_Obj_t * Dar_Latch( Dar_Man_t * p, Dar_Obj_t * pObj, int fInitOne ); -extern Dar_Obj_t * Dar_Or( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ); -extern Dar_Obj_t * Dar_Exor( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ); -extern Dar_Obj_t * Dar_Mux( Dar_Man_t * p, Dar_Obj_t * pC, Dar_Obj_t * p1, Dar_Obj_t * p0 ); -extern Dar_Obj_t * Dar_Maj( Dar_Man_t * p, Dar_Obj_t * pA, Dar_Obj_t * pB, Dar_Obj_t * pC ); -extern Dar_Obj_t * Dar_Miter( Dar_Man_t * p, Vec_Ptr_t * vPairs ); -extern Dar_Obj_t * Dar_CreateAnd( Dar_Man_t * p, int nVars ); -extern Dar_Obj_t * Dar_CreateOr( Dar_Man_t * p, int nVars ); -extern Dar_Obj_t * Dar_CreateExor( Dar_Man_t * p, int nVars ); -/*=== darSeq.c ========================================================*/ -extern int Dar_ManSeqStrash( Dar_Man_t * p, int nLatches, int * pInits ); -/*=== darTable.c ========================================================*/ -extern Dar_Obj_t * Dar_TableLookup( Dar_Man_t * p, Dar_Obj_t * pGhost ); -extern void Dar_TableInsert( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern void Dar_TableDelete( Dar_Man_t * p, Dar_Obj_t * pObj ); -extern int Dar_TableCountEntries( Dar_Man_t * p ); -extern void Dar_TableProfile( Dar_Man_t * p ); -/*=== darUtil.c =========================================================*/ -extern Dar_Par_t * Dar_ManDefaultParams(); -extern void Dar_ManIncrementTravId( Dar_Man_t * p ); -extern int Dar_ManLevels( Dar_Man_t * p ); -extern void Dar_ManCleanData( Dar_Man_t * p ); -extern void Dar_ObjCleanData_rec( Dar_Obj_t * pObj ); -extern void Dar_ObjCollectMulti( Dar_Obj_t * pFunc, Vec_Ptr_t * vSuper ); -extern int Dar_ObjIsMuxType( Dar_Obj_t * pObj ); -extern int Dar_ObjRecognizeExor( Dar_Obj_t * pObj, Dar_Obj_t ** ppFan0, Dar_Obj_t ** ppFan1 ); -extern Dar_Obj_t * Dar_ObjRecognizeMux( Dar_Obj_t * pObj, Dar_Obj_t ** ppObjT, Dar_Obj_t ** ppObjE ); -extern Dar_Obj_t * Dar_ObjReal_rec( Dar_Obj_t * pObj ); -extern void Dar_ObjPrintEqn( FILE * pFile, Dar_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ); -extern void Dar_ObjPrintVerilog( FILE * pFile, Dar_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ); -extern void Dar_ObjPrintVerbose( Dar_Obj_t * pObj, int fHaig ); -extern void Dar_ManPrintVerbose( Dar_Man_t * p, int fHaig ); -extern void Dar_ManDumpBlif( Dar_Man_t * p, char * pFileName ); - -/*=== darMem.c ===========================================================*/ -// fixed-size-block memory manager -extern Dar_MmFixed_t * Dar_MmFixedStart( int nEntrySize, int nEntriesMax ); -extern void Dar_MmFixedStop( Dar_MmFixed_t * p, int fVerbose ); -extern char * Dar_MmFixedEntryFetch( Dar_MmFixed_t * p ); -extern void Dar_MmFixedEntryRecycle( Dar_MmFixed_t * p, char * pEntry ); -extern void Dar_MmFixedRestart( Dar_MmFixed_t * p ); -extern int Dar_MmFixedReadMemUsage( Dar_MmFixed_t * p ); -extern int Dar_MmFixedReadMaxEntriesUsed( Dar_MmFixed_t * p ); -// flexible-size-block memory manager -extern Dar_MmFlex_t * Dar_MmFlexStart(); -extern void Dar_MmFlexStop( Dar_MmFlex_t * p, int fVerbose ); -extern char * Dar_MmFlexEntryFetch( Dar_MmFlex_t * p, int nBytes ); -extern void Dar_MmFlexRestart( Dar_MmFlex_t * p ); -extern int Dar_MmFlexReadMemUsage( Dar_MmFlex_t * p ); -// hierarchical memory manager -extern Dar_MmStep_t * Dar_MmStepStart( int nSteps ); -extern void Dar_MmStepStop( Dar_MmStep_t * p, int fVerbose ); -extern char * Dar_MmStepEntryFetch( Dar_MmStep_t * p, int nBytes ); -extern void Dar_MmStepEntryRecycle( Dar_MmStep_t * p, char * pEntry, int nBytes ); -extern int Dar_MmStepReadMemUsage( Dar_MmStep_t * p ); +extern void Dar_ManDefaultParams( Dar_Par_t * pPars ); +extern int Dar_ManRewrite( Aig_Man_t * pAig, Dar_Par_t * pPars ); +extern Aig_MmFixed_t * Dar_ManComputeCuts( Aig_Man_t * pAig ); #ifdef __cplusplus } diff --git a/src/aig/dar/darBalance.c b/src/aig/dar/darBalance.c index 2d9a48d4..a1502382 100644 --- a/src/aig/dar/darBalance.c +++ b/src/aig/dar/darBalance.c @@ -18,17 +18,18 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -static Dar_Obj_t * Dar_NodeBalance_rec( Dar_Man_t * pNew, Dar_Obj_t * pObj, Vec_Vec_t * vStore, int Level, int fUpdateLevel ); -static Vec_Ptr_t * Dar_NodeBalanceCone( Dar_Obj_t * pObj, Vec_Vec_t * vStore, int Level ); -static int Dar_NodeBalanceFindLeft( Vec_Ptr_t * vSuper ); -static void Dar_NodeBalancePermute( Dar_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, int fExor ); -static void Dar_NodeBalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Dar_Obj_t * pObj ); +static Aig_Obj_t * Dar_Balance_rec( Aig_Man_t * pNew, Aig_Obj_t * pObj, Vec_Vec_t * vStore, int Level, int fUpdateLevel ); +static Vec_Ptr_t * Dar_BalanceCone( Aig_Obj_t * pObj, Vec_Vec_t * vStore, int Level ); +static int Dar_BalanceFindLeft( Vec_Ptr_t * vSuper ); +static void Dar_BalancePermute( Aig_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, int fExor ); +static void Dar_BalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Aig_Obj_t * pObj ); +static Aig_Obj_t * Dar_BalanceBuildSuper( Aig_Man_t * p, Vec_Ptr_t * vSuper, Aig_Type_t Type, int fUpdateLevel ); //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -45,33 +46,33 @@ static void Dar_NodeBalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Da SeeAlso [] ***********************************************************************/ -Dar_Man_t * Dar_ManBalance( Dar_Man_t * p, int fUpdateLevel ) +Aig_Man_t * Dar_ManBalance( Aig_Man_t * p, int fUpdateLevel ) { - Dar_Man_t * pNew; - Dar_Obj_t * pObj, * pObjNew; + Aig_Man_t * pNew; + Aig_Obj_t * pObj, * pObjNew; Vec_Vec_t * vStore; int i; // create the new manager - pNew = Dar_ManStart(); + pNew = Aig_ManStart(); // map the PI nodes - Dar_ManCleanData( p ); - Dar_ManConst1(p)->pData = Dar_ManConst1(pNew); - Dar_ManForEachPi( p, pObj, i ) - pObj->pData = Dar_ObjCreatePi(pNew); + Aig_ManCleanData( p ); + Aig_ManConst1(p)->pData = Aig_ManConst1(pNew); + Aig_ManForEachPi( p, pObj, i ) + pObj->pData = Aig_ObjCreatePi(pNew); // balance the AIG vStore = Vec_VecAlloc( 50 ); - Dar_ManForEachPo( p, pObj, i ) + Aig_ManForEachPo( p, pObj, i ) { - pObjNew = Dar_NodeBalance_rec( pNew, Dar_ObjFanin0(pObj), vStore, 0, fUpdateLevel ); - Dar_ObjCreatePo( pNew, Dar_NotCond( pObjNew, Dar_ObjFaninC0(pObj) ) ); + pObjNew = Dar_Balance_rec( pNew, Aig_ObjFanin0(pObj), vStore, 0, fUpdateLevel ); + Aig_ObjCreatePo( pNew, Aig_NotCond( pObjNew, Aig_ObjFaninC0(pObj) ) ); } Vec_VecFree( vStore ); // remove dangling nodes -// Dar_ManCreateRefs( pNew ); -// if ( i = Dar_ManCleanup( pNew ) ) +// Aig_ManCreateRefs( pNew ); +// if ( i = Aig_ManCleanup( pNew ) ) // printf( "Cleanup after balancing removed %d dangling nodes.\n", i ); // check the resulting AIG - if ( !Dar_ManCheck(pNew) ) + if ( !Aig_ManCheck(pNew) ) printf( "Dar_ManBalance(): The check has failed.\n" ); return pNew; } @@ -87,33 +88,33 @@ Dar_Man_t * Dar_ManBalance( Dar_Man_t * p, int fUpdateLevel ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Dar_NodeBalance_rec( Dar_Man_t * pNew, Dar_Obj_t * pObjOld, Vec_Vec_t * vStore, int Level, int fUpdateLevel ) +Aig_Obj_t * Dar_Balance_rec( Aig_Man_t * pNew, Aig_Obj_t * pObjOld, Vec_Vec_t * vStore, int Level, int fUpdateLevel ) { - Dar_Obj_t * pObjNew; + Aig_Obj_t * pObjNew; Vec_Ptr_t * vSuper; int i; - assert( !Dar_IsComplement(pObjOld) ); + assert( !Aig_IsComplement(pObjOld) ); // return if the result is known if ( pObjOld->pData ) return pObjOld->pData; - assert( Dar_ObjIsNode(pObjOld) ); + assert( Aig_ObjIsNode(pObjOld) ); // get the implication supergate - vSuper = Dar_NodeBalanceCone( pObjOld, vStore, Level ); + vSuper = Dar_BalanceCone( pObjOld, vStore, Level ); // check if supergate contains two nodes in the opposite polarity if ( vSuper->nSize == 0 ) - return pObjOld->pData = Dar_ManConst0(pNew); + return pObjOld->pData = Aig_ManConst0(pNew); if ( Vec_PtrSize(vSuper) < 2 ) printf( "BUG!\n" ); // for each old node, derive the new well-balanced node for ( i = 0; i < Vec_PtrSize(vSuper); i++ ) { - pObjNew = Dar_NodeBalance_rec( pNew, Dar_Regular(vSuper->pArray[i]), vStore, Level + 1, fUpdateLevel ); - vSuper->pArray[i] = Dar_NotCond( pObjNew, Dar_IsComplement(vSuper->pArray[i]) ); + pObjNew = Dar_Balance_rec( pNew, Aig_Regular(vSuper->pArray[i]), vStore, Level + 1, fUpdateLevel ); + vSuper->pArray[i] = Aig_NotCond( pObjNew, Aig_IsComplement(vSuper->pArray[i]) ); } // build the supergate - pObjNew = Dar_NodeBalanceBuildSuper( pNew, vSuper, Dar_ObjType(pObjOld), fUpdateLevel ); + pObjNew = Dar_BalanceBuildSuper( pNew, vSuper, Aig_ObjType(pObjOld), fUpdateLevel ); // make sure the balanced node is not assigned -// assert( pObjOld->Level >= Dar_Regular(pObjNew)->Level ); +// assert( pObjOld->Level >= Aig_Regular(pObjNew)->Level ); assert( pObjOld->pData == NULL ); return pObjOld->pData = pObjNew; } @@ -129,11 +130,11 @@ Dar_Obj_t * Dar_NodeBalance_rec( Dar_Man_t * pNew, Dar_Obj_t * pObjOld, Vec_Vec_ SeeAlso [] ***********************************************************************/ -int Dar_NodeBalanceCone_rec( Dar_Obj_t * pRoot, Dar_Obj_t * pObj, Vec_Ptr_t * vSuper ) +int Dar_BalanceCone_rec( Aig_Obj_t * pRoot, Aig_Obj_t * pObj, Vec_Ptr_t * vSuper ) { int RetValue1, RetValue2, i; // check if the node is visited - if ( Dar_Regular(pObj)->fMarkB ) + if ( Aig_Regular(pObj)->fMarkB ) { // check if the node occurs in the same polarity for ( i = 0; i < vSuper->nSize; i++ ) @@ -141,23 +142,23 @@ int Dar_NodeBalanceCone_rec( Dar_Obj_t * pRoot, Dar_Obj_t * pObj, Vec_Ptr_t * vS return 1; // check if the node is present in the opposite polarity for ( i = 0; i < vSuper->nSize; i++ ) - if ( vSuper->pArray[i] == Dar_Not(pObj) ) + 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 && (Dar_IsComplement(pObj) || Dar_ObjType(pObj) != Dar_ObjType(pRoot) || Dar_ObjRefs(pObj) > 1) ) + if ( pObj != pRoot && (Aig_IsComplement(pObj) || Aig_ObjType(pObj) != Aig_ObjType(pRoot) || Aig_ObjRefs(pObj) > 1) ) { Vec_PtrPush( vSuper, pObj ); - Dar_Regular(pObj)->fMarkB = 1; + Aig_Regular(pObj)->fMarkB = 1; return 0; } - assert( !Dar_IsComplement(pObj) ); - assert( Dar_ObjIsNode(pObj) ); + assert( !Aig_IsComplement(pObj) ); + assert( Aig_ObjIsNode(pObj) ); // go through the branches - RetValue1 = Dar_NodeBalanceCone_rec( pRoot, Dar_ObjChild0(pObj), vSuper ); - RetValue2 = Dar_NodeBalanceCone_rec( pRoot, Dar_ObjChild1(pObj), vSuper ); + RetValue1 = Dar_BalanceCone_rec( pRoot, Aig_ObjChild0(pObj), vSuper ); + RetValue2 = Dar_BalanceCone_rec( pRoot, Aig_ObjChild1(pObj), vSuper ); if ( RetValue1 == -1 || RetValue2 == -1 ) return -1; // return 1 if at least one branch has a duplicate @@ -175,11 +176,11 @@ int Dar_NodeBalanceCone_rec( Dar_Obj_t * pRoot, Dar_Obj_t * pObj, Vec_Ptr_t * vS SeeAlso [] ***********************************************************************/ -Vec_Ptr_t * Dar_NodeBalanceCone( Dar_Obj_t * pObj, Vec_Vec_t * vStore, int Level ) +Vec_Ptr_t * Dar_BalanceCone( Aig_Obj_t * pObj, Vec_Vec_t * vStore, int Level ) { Vec_Ptr_t * vNodes; int RetValue, i; - assert( !Dar_IsComplement(pObj) ); + assert( !Aig_IsComplement(pObj) ); // extend the storage if ( Vec_VecSize( vStore ) <= Level ) Vec_VecPush( vStore, Level, 0 ); @@ -187,11 +188,11 @@ Vec_Ptr_t * Dar_NodeBalanceCone( Dar_Obj_t * pObj, Vec_Vec_t * vStore, int Level vNodes = Vec_VecEntry( vStore, Level ); Vec_PtrClear( vNodes ); // collect the nodes in the implication supergate - RetValue = Dar_NodeBalanceCone_rec( pObj, pObj, vNodes ); + RetValue = Dar_BalanceCone_rec( pObj, pObj, vNodes ); assert( vNodes->nSize > 1 ); // unmark the visited nodes Vec_PtrForEachEntry( vNodes, pObj, i ) - Dar_Regular(pObj)->fMarkB = 0; + Aig_Regular(pObj)->fMarkB = 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 ) @@ -210,9 +211,9 @@ Vec_Ptr_t * Dar_NodeBalanceCone( Dar_Obj_t * pObj, Vec_Vec_t * vStore, int Level SeeAlso [] ***********************************************************************/ -int Dar_NodeCompareLevelsDecrease( Dar_Obj_t ** pp1, Dar_Obj_t ** pp2 ) +int Aig_NodeCompareLevelsDecrease( Aig_Obj_t ** pp1, Aig_Obj_t ** pp2 ) { - int Diff = Dar_ObjLevel(Dar_Regular(*pp1)) - Dar_ObjLevel(Dar_Regular(*pp2)); + int Diff = Aig_ObjLevel(Aig_Regular(*pp1)) - Aig_ObjLevel(Aig_Regular(*pp2)); if ( Diff > 0 ) return -1; if ( Diff < 0 ) @@ -231,24 +232,24 @@ int Dar_NodeCompareLevelsDecrease( Dar_Obj_t ** pp1, Dar_Obj_t ** pp2 ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Dar_NodeBalanceBuildSuper( Dar_Man_t * p, Vec_Ptr_t * vSuper, Dar_Type_t Type, int fUpdateLevel ) +Aig_Obj_t * Dar_BalanceBuildSuper( Aig_Man_t * p, Vec_Ptr_t * vSuper, Aig_Type_t Type, int fUpdateLevel ) { - Dar_Obj_t * pObj1, * pObj2; + Aig_Obj_t * pObj1, * pObj2; int LeftBound; assert( vSuper->nSize > 1 ); // sort the new nodes by level in the decreasing order - Vec_PtrSort( vSuper, Dar_NodeCompareLevelsDecrease ); + Vec_PtrSort( vSuper, Aig_NodeCompareLevelsDecrease ); // balance the nodes while ( vSuper->nSize > 1 ) { // find the left bound on the node to be paired - LeftBound = (!fUpdateLevel)? 0 : Dar_NodeBalanceFindLeft( vSuper ); + LeftBound = (!fUpdateLevel)? 0 : Dar_BalanceFindLeft( vSuper ); // find the node that can be shared (if no such node, randomize choice) - Dar_NodeBalancePermute( p, vSuper, LeftBound, Type == DAR_AIG_EXOR ); + Dar_BalancePermute( p, vSuper, LeftBound, Type == AIG_OBJ_EXOR ); // pull out the last two nodes pObj1 = Vec_PtrPop(vSuper); pObj2 = Vec_PtrPop(vSuper); - Dar_NodeBalancePushUniqueOrderByLevel( vSuper, Dar_Oper(p, pObj1, pObj2, Type) ); + Dar_BalancePushUniqueOrderByLevel( vSuper, Aig_Oper(p, pObj1, pObj2, Type) ); } return Vec_PtrEntry(vSuper, 0); } @@ -268,9 +269,9 @@ Dar_Obj_t * Dar_NodeBalanceBuildSuper( Dar_Man_t * p, Vec_Ptr_t * vSuper, Dar_Ty SeeAlso [] ***********************************************************************/ -int Dar_NodeBalanceFindLeft( Vec_Ptr_t * vSuper ) +int Dar_BalanceFindLeft( Vec_Ptr_t * vSuper ) { - Dar_Obj_t * pObjRight, * pObjLeft; + Aig_Obj_t * pObjRight, * pObjLeft; int Current; // if two or less nodes, pair with the first if ( Vec_PtrSize(vSuper) < 3 ) @@ -284,13 +285,13 @@ int Dar_NodeBalanceFindLeft( Vec_Ptr_t * vSuper ) // get the next node on the left pObjLeft = Vec_PtrEntry( vSuper, Current ); // if the level of this node is different, quit the loop - if ( Dar_ObjLevel(Dar_Regular(pObjLeft)) != Dar_ObjLevel(Dar_Regular(pObjRight)) ) + if ( Aig_ObjLevel(Aig_Regular(pObjLeft)) != Aig_ObjLevel(Aig_Regular(pObjRight)) ) break; } Current++; // get the node, for which the equality holds pObjLeft = Vec_PtrEntry( vSuper, Current ); - assert( Dar_ObjLevel(Dar_Regular(pObjLeft)) == Dar_ObjLevel(Dar_Regular(pObjRight)) ); + assert( Aig_ObjLevel(Aig_Regular(pObjLeft)) == Aig_ObjLevel(Aig_Regular(pObjRight)) ); return Current; } @@ -306,9 +307,9 @@ int Dar_NodeBalanceFindLeft( Vec_Ptr_t * vSuper ) SeeAlso [] ***********************************************************************/ -void Dar_NodeBalancePermute( Dar_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, int fExor ) +void Dar_BalancePermute( Aig_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, int fExor ) { - Dar_Obj_t * pObj1, * pObj2, * pObj3, * pGhost; + Aig_Obj_t * pObj1, * pObj2, * pObj3, * pGhost; int RightBound, i; // get the right bound RightBound = Vec_PtrSize(vSuper) - 2; @@ -318,20 +319,20 @@ void Dar_NodeBalancePermute( Dar_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, i // get the two last nodes pObj1 = Vec_PtrEntry( vSuper, RightBound + 1 ); pObj2 = Vec_PtrEntry( vSuper, RightBound ); - if ( Dar_Regular(pObj1) == p->pConst1 || Dar_Regular(pObj2) == p->pConst1 ) + if ( Aig_Regular(pObj1) == p->pConst1 || Aig_Regular(pObj2) == p->pConst1 ) return; // find the first node that can be shared for ( i = RightBound; i >= LeftBound; i-- ) { pObj3 = Vec_PtrEntry( vSuper, i ); - if ( Dar_Regular(pObj3) == p->pConst1 ) + if ( Aig_Regular(pObj3) == p->pConst1 ) { Vec_PtrWriteEntry( vSuper, i, pObj2 ); Vec_PtrWriteEntry( vSuper, RightBound, pObj3 ); return; } - pGhost = Dar_ObjCreateGhost( p, pObj1, pObj3, fExor? DAR_AIG_EXOR : DAR_AIG_AND ); - if ( Dar_TableLookup( p, pGhost ) ) + pGhost = Aig_ObjCreateGhost( p, pObj1, pObj3, fExor? AIG_OBJ_EXOR : AIG_OBJ_AND ); + if ( Aig_TableLookup( p, pGhost ) ) { if ( pObj3 == pObj2 ) return; @@ -364,9 +365,9 @@ void Dar_NodeBalancePermute( Dar_Man_t * p, Vec_Ptr_t * vSuper, int LeftBound, i SeeAlso [] ***********************************************************************/ -void Dar_NodeBalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Dar_Obj_t * pObj ) +void Dar_BalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Aig_Obj_t * pObj ) { - Dar_Obj_t * pObj1, * pObj2; + Aig_Obj_t * pObj1, * pObj2; int i; if ( Vec_PtrPushUnique(vStore, pObj) ) return; @@ -375,7 +376,7 @@ void Dar_NodeBalancePushUniqueOrderByLevel( Vec_Ptr_t * vStore, Dar_Obj_t * pObj { pObj1 = vStore->pArray[i ]; pObj2 = vStore->pArray[i-1]; - if ( Dar_ObjLevel(Dar_Regular(pObj1)) <= Dar_ObjLevel(Dar_Regular(pObj2)) ) + if ( Aig_ObjLevel(Aig_Regular(pObj1)) <= Aig_ObjLevel(Aig_Regular(pObj2)) ) break; vStore->pArray[i ] = pObj2; vStore->pArray[i-1] = pObj1; diff --git a/src/aig/dar/darCheck.c b/src/aig/dar/darCheck.c deleted file mode 100644 index 5c7a2390..00000000 --- a/src/aig/dar/darCheck.c +++ /dev/null @@ -1,121 +0,0 @@ -/**CFile**************************************************************** - - FileName [darCheck.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [AIG checking procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darCheck.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Checks the consistency of the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManCheck( Dar_Man_t * p ) -{ - Dar_Obj_t * pObj, * pObj2; - int i; - // check primary inputs - Dar_ManForEachPi( p, pObj, i ) - { - if ( Dar_ObjFanin0(pObj) || Dar_ObjFanin1(pObj) ) - { - printf( "Dar_ManCheck: The PI node \"%p\" has fanins.\n", pObj ); - return 0; - } - } - // check primary outputs - Dar_ManForEachPo( p, pObj, i ) - { - if ( !Dar_ObjFanin0(pObj) ) - { - printf( "Dar_ManCheck: The PO node \"%p\" has NULL fanin.\n", pObj ); - return 0; - } - if ( Dar_ObjFanin1(pObj) ) - { - printf( "Dar_ManCheck: The PO node \"%p\" has second fanin.\n", pObj ); - return 0; - } - } - // check internal nodes - Dar_ManForEachObj( p, pObj, i ) - { - if ( !Dar_ObjIsNode(pObj) ) - continue; - if ( !Dar_ObjFanin0(pObj) || !Dar_ObjFanin1(pObj) ) - { - printf( "Dar_ManCheck: The AIG has internal node \"%p\" with a NULL fanin.\n", pObj ); - return 0; - } - if ( Dar_ObjFanin0(pObj)->Id >= Dar_ObjFanin1(pObj)->Id ) - { - printf( "Dar_ManCheck: The AIG has node \"%p\" with a wrong ordering of fanins.\n", pObj ); - return 0; - } - pObj2 = Dar_TableLookup( p, pObj ); - if ( pObj2 != pObj ) - { - printf( "Dar_ManCheck: Node \"%p\" is not in the structural hashing table.\n", pObj ); - return 0; - } - } - // count the total number of nodes - if ( Dar_ManObjNum(p) != 1 + Dar_ManPiNum(p) + Dar_ManPoNum(p) + Dar_ManBufNum(p) + Dar_ManAndNum(p) + Dar_ManExorNum(p) + Dar_ManLatchNum(p) ) - { - printf( "Dar_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, Dar_ManPiNum(p), Dar_ManPoNum(p), Dar_ManBufNum(p), Dar_ManAndNum(p), Dar_ManExorNum(p), Dar_ManLatchNum(p), - 1 + Dar_ManPiNum(p) + Dar_ManPoNum(p) + Dar_ManBufNum(p) + Dar_ManAndNum(p) + Dar_ManExorNum(p) + Dar_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 ( Dar_TableCountEntries(p) != Dar_ManAndNum(p) + Dar_ManExorNum(p) + Dar_ManLatchNum(p) ) - { - printf( "Dar_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", - Dar_TableCountEntries(p), Dar_ManAndNum(p), Dar_ManExorNum(p), Dar_ManLatchNum(p), - Dar_ManAndNum(p) + Dar_ManExorNum(p) + Dar_ManLatchNum(p) ); - - return 0; - } -// if ( !Dar_ManIsAcyclic(p) ) -// return 0; - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darCore.c b/src/aig/dar/darCore.c index 23563766..a617f5d6 100644 --- a/src/aig/dar/darCore.c +++ b/src/aig/dar/darCore.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -28,6 +28,28 @@ /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// +/**Function************************************************************* + + Synopsis [Returns the structure with default assignment of parameters.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Dar_ManDefaultParams( Dar_Par_t * pPars ) +{ + memset( pPars, 0, sizeof(Dar_Par_t) ); + pPars->nCutsMax = 8; + pPars->nSubgMax = 4; + pPars->fUpdateLevel = 0; + pPars->fUseZeros = 0; + pPars->fVerbose = 0; + pPars->fVeryVerbose = 0; +} + /**Function************************************************************* Synopsis [] @@ -39,89 +61,107 @@ SeeAlso [] ***********************************************************************/ -int Dar_ManRewrite( Dar_Man_t * p ) +int Dar_ManRewrite( Aig_Man_t * pAig, Dar_Par_t * pPars ) { + Dar_Man_t * p; ProgressBar * pProgress; - Dar_Cut_t * pCutSet; - Dar_Obj_t * pObj, * pObjNew; + Dar_Cut_t * pCut; + Aig_Obj_t * pObj, * pObjNew; int i, k, nNodesOld, nNodeBefore, nNodeAfter, Required; int clk = 0, clkStart; + // create rewriting manager + p = Dar_ManStart( pAig, pPars ); // remove dangling nodes - Dar_ManCleanup( p ); + Aig_ManCleanup( pAig ); // set elementary cuts for the PIs - Dar_ManSetupPis( p ); +// Dar_ManSetupPis( p ); + Aig_ManCleanData( pAig ); + Dar_ObjPrepareCuts( p, Aig_ManConst1(pAig) ); + Aig_ManForEachPi( pAig, pObj, i ) + Dar_ObjPrepareCuts( p, pObj ); // if ( p->pPars->fUpdateLevel ) -// Dar_NtkStartReverseLevels( p ); +// Aig_NtkStartReverseLevels( p ); // resynthesize each node once clkStart = clock(); - p->nNodesInit = Dar_ManNodeNum(p); - nNodesOld = Vec_PtrSize( p->vObjs ); + p->nNodesInit = Aig_ManNodeNum(pAig); + nNodesOld = Vec_PtrSize( pAig->vObjs ); pProgress = Extra_ProgressBarStart( stdout, nNodesOld ); - Dar_ManForEachObj( p, pObj, i ) + Aig_ManForEachObj( pAig, pObj, i ) { Extra_ProgressBarUpdate( pProgress, i, NULL ); - if ( !Dar_ObjIsNode(pObj) ) + if ( !Aig_ObjIsNode(pObj) ) continue; if ( i > nNodesOld ) break; // compute cuts for the node clk = clock(); - pCutSet = Dar_ObjComputeCuts_rec( p, pObj ); + Dar_ObjComputeCuts_rec( p, pObj ); p->timeCuts += clock() - clk; - // go through the cuts of this node - Required = 1000000; - p->GainBest = -1; - for ( k = 1; k < (int)pObj->nCuts; k++ ) + + // check if there is a trivial cut + Dar_ObjForEachCut( pObj, pCut, k ) + if ( pCut->nLeaves == 0 || (pCut->nLeaves == 1 && pCut->pLeaves[0] != pObj->Id) ) + break; + if ( k < (int)pObj->nCuts ) { -/* - if ( pObj->Id == 654 ) + assert( pCut->nLeaves < 2 ); + if ( pCut->nLeaves == 0 ) // replace by constant { - int m; - for ( m = 0; m < 4; m++ ) - printf( "%d ", pCutSet[k].pLeaves[m] ); - printf( "\n" ); + assert( pCut->uTruth == 0 || pCut->uTruth == 0xFFFF ); + pObjNew = Aig_NotCond( Aig_ManConst1(p->pAig), pCut->uTruth==0 ); } -*/ - Dar_LibEval( p, pObj, pCutSet + k, Required ); + else + { + assert( pCut->uTruth == 0xAAAA || pCut->uTruth == 0x5555 ); + pObjNew = Aig_NotCond( Aig_ManObj(p->pAig, pCut->pLeaves[0]), pCut->uTruth==0x5555 ); + } + // replace the node + Aig_ObjReplace( pAig, pObj, pObjNew, 1 ); + // remove the old cuts + Dar_ObjSetCuts( pObj, NULL ); + continue; } + + // evaluate the cuts + p->GainBest = -1; + Required = 1000000; + Dar_ObjForEachCut( pObj, pCut, k ) + Dar_LibEval( p, pObj, pCut, Required ); // check the best gain if ( !(p->GainBest > 0 || p->GainBest == 0 && p->pPars->fUseZeros) ) continue; // if we end up here, a rewriting step is accepted - nNodeBefore = Dar_ManNodeNum( p ); + nNodeBefore = Aig_ManNodeNum( pAig ); pObjNew = Dar_LibBuildBest( p ); - pObjNew = Dar_NotCond( pObjNew, pObjNew->fPhase ^ pObj->fPhase ); - assert( (int)Dar_Regular(pObjNew)->Level <= Required ); + pObjNew = Aig_NotCond( pObjNew, pObjNew->fPhase ^ pObj->fPhase ); + assert( (int)Aig_Regular(pObjNew)->Level <= Required ); // replace the node - Dar_ObjReplace( p, pObj, pObjNew, 1 ); + Aig_ObjReplace( pAig, pObj, pObjNew, 1 ); // remove the old cuts - pObj->pData = NULL; + Dar_ObjSetCuts( pObj, NULL ); // compare the gains - nNodeAfter = Dar_ManNodeNum( p ); + nNodeAfter = Aig_ManNodeNum( pAig ); assert( p->GainBest <= nNodeBefore - nNodeAfter ); // count gains of this class p->ClassGains[p->ClassBest] += nNodeBefore - nNodeAfter; - -// if ( p->ClassBest == 29 ) -// printf( "%d ", p->OutNumBest ); - } p->timeTotal = clock() - clkStart; p->timeOther = p->timeTotal - p->timeCuts - p->timeEval; Extra_ProgressBarStop( pProgress ); - p->nCutMemUsed = Dar_MmFlexReadMemUsage(p->pMemCuts)/(1<<20); + p->nCutMemUsed = Aig_MmFixedReadMemUsage(p->pMemCuts)/(1<<20); Dar_ManCutsFree( p ); + // stop the rewriting manager + Dar_ManStop( p ); // put the nodes into the DFS order and reassign their IDs -// Dar_NtkReassignIds( p ); - +// Aig_NtkReassignIds( p ); // fix the levels // if ( p->pPars->fUpdateLevel ) -// Dar_NtkStopReverseLevels( p ); +// Aig_NtkStopReverseLevels( p ); // check - if ( !Dar_ManCheck( p ) ) + if ( !Aig_ManCheck( pAig ) ) { - printf( "Dar_ManRewrite: The network check has failed.\n" ); + printf( "Aig_ManRewrite: The network check has failed.\n" ); return 0; } return 1; @@ -138,32 +178,37 @@ p->timeOther = p->timeTotal - p->timeCuts - p->timeEval; SeeAlso [] ***********************************************************************/ -int Dar_ManComputeCuts( Dar_Man_t * p ) +Aig_MmFixed_t * Dar_ManComputeCuts( Aig_Man_t * pAig ) { - Dar_Obj_t * pObj; + Dar_Man_t * p; + Aig_Obj_t * pObj; + Aig_MmFixed_t * pMemCuts; int i, clk = 0, clkStart = clock(); int nCutsMax = 0, nCutsTotal = 0; + // create rewriting manager + p = Dar_ManStart( pAig, NULL ); // remove dangling nodes - Dar_ManCleanup( p ); + Aig_ManCleanup( pAig ); // set elementary cuts for the PIs - Dar_ManSetupPis( p ); +// Dar_ManSetupPis( p ); + Aig_ManForEachPi( pAig, pObj, i ) + Dar_ObjPrepareCuts( p, pObj ); // compute cuts for each nodes in the topological order - Dar_ManForEachObj( p, pObj, i ) + Aig_ManForEachObj( pAig, pObj, i ) { - if ( !Dar_ObjIsNode(pObj) ) + if ( !Aig_ObjIsNode(pObj) ) continue; Dar_ObjComputeCuts( p, pObj ); nCutsTotal += pObj->nCuts - 1; - nCutsMax = DAR_MAX( nCutsMax, (int)pObj->nCuts - 1 ); + nCutsMax = AIG_MAX( nCutsMax, (int)pObj->nCuts - 1 ); } - // print statistics on the number of non-trivial cuts - printf( "Node = %6d. Cut = %8d. Max = %3d. Ave = %.2f. Filter = %8d. Created = %8d.\n", - Dar_ManNodeNum(p), nCutsTotal, nCutsMax, (float)nCutsTotal/Dar_ManNodeNum(p), - p->nCutsFiltered, p->nCutsFiltered+nCutsTotal+Dar_ManNodeNum(p)+Dar_ManPiNum(p) ); - PRT( "Time", clock() - clkStart ); // free the cuts + pMemCuts = p->pMemCuts; + p->pMemCuts = NULL; // Dar_ManCutsFree( p ); - return 1; + // stop the rewriting manager + Dar_ManStop( p ); + return pMemCuts; } diff --git a/src/aig/dar/darCut.c b/src/aig/dar/darCut.c index 48f4dc6c..af9d1227 100644 --- a/src/aig/dar/darCut.c +++ b/src/aig/dar/darCut.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -28,6 +28,97 @@ /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// +/**Function************************************************************* + + Synopsis [Returns the number of 1s in the machine word.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Dar_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); +} + +/**Function************************************************************* + + Synopsis [Compute the cost of the cut.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline int Dar_CutFindValue( Dar_Man_t * p, Dar_Cut_t * pCut ) +{ + Aig_Obj_t * pLeaf; + int i, Value; + assert( pCut->fUsed ); + if ( pCut->nLeaves < 2 ) + return 1001; + Value = 0; + Dar_CutForEachLeaf( p->pAig, pCut, pLeaf, i ) + { + if ( pLeaf == NULL ) + return 0; + assert( pLeaf != NULL ); + Value += pLeaf->nRefs; + } + if ( Value > 1000 ) + Value = 1000; + return Value; +} + +/**Function************************************************************* + + Synopsis [Returns the next free cut to use.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline Dar_Cut_t * Dar_CutFindFree( Dar_Man_t * p, Aig_Obj_t * pObj ) +{ + Dar_Cut_t * pCut, * pCutMax; + int i; + pCutMax = NULL; + Dar_ObjForEachCutAll( pObj, pCut, i ) + { + if ( pCut->fUsed == 0 ) + return pCut; + if ( pCut->nLeaves < 3 ) + continue; + if ( pCutMax == NULL || pCutMax->Value > pCut->Value ) + pCutMax = pCut; + } + if ( pCutMax == NULL ) + { + Dar_ObjForEachCutAll( pObj, pCut, i ) + { + if ( pCut->nLeaves < 2 ) + continue; + if ( pCutMax == NULL || pCutMax->Value > pCut->Value ) + pCutMax = pCut; + } + } + assert( pCutMax != NULL ); + pCutMax->fUsed = 0; + return pCutMax; +} + /**Function************************************************************* Synopsis [Returns 1 if pDom is contained in pCut.] @@ -42,6 +133,7 @@ static inline int Dar_CutCheckDominance( Dar_Cut_t * pDom, Dar_Cut_t * pCut ) { int i, k; + assert( pDom->fUsed && pCut->fUsed ); for ( i = 0; i < (int)pDom->nLeaves; i++ ) { for ( k = 0; k < (int)pCut->nLeaves; k++ ) @@ -65,14 +157,16 @@ static inline int Dar_CutCheckDominance( Dar_Cut_t * pDom, Dar_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -static inline int Dar_CutFilter( Dar_Man_t * p, Dar_Cut_t * pCut ) +static inline int Dar_CutFilter( Aig_Obj_t * pObj, Dar_Cut_t * pCut ) { Dar_Cut_t * pTemp; - int i, k; - assert( p->pBaseCuts[p->nCutsUsed] == pCut ); - for ( i = 0; i < p->nCutsUsed; i++ ) + int i; + assert( pCut->fUsed ); + // go through the cuts of the node + Dar_ObjForEachCut( pObj, pTemp, i ) { - pTemp = p->pBaseCuts[i]; + if ( pTemp == pCut ) + continue; if ( pTemp->nLeaves > pCut->nLeaves ) { // skip the non-contained cuts @@ -81,17 +175,8 @@ static inline int Dar_CutFilter( Dar_Man_t * p, Dar_Cut_t * pCut ) // check containment seriously if ( Dar_CutCheckDominance( pCut, pTemp ) ) { -// p->ppCuts[i] = p->ppCuts[p->nCuts-1]; -// p->ppCuts[p->nCuts-1] = pTemp; -// p->nCuts--; -// i--; // remove contained cut - for ( k = i; k < p->nCutsUsed; k++ ) - p->pBaseCuts[k] = p->pBaseCuts[k+1]; - p->pBaseCuts[p->nCutsUsed] = pTemp; - p->nCutsUsed--; - i--; - p->nCutsFiltered++; + pTemp->fUsed = 0; } } else @@ -102,7 +187,8 @@ static inline int Dar_CutFilter( Dar_Man_t * p, Dar_Cut_t * pCut ) // check containment seriously if ( Dar_CutCheckDominance( pTemp, pCut ) ) { - p->nCutsFiltered++; + // remove the given cut + pCut->fUsed = 0; return 1; } } @@ -215,6 +301,7 @@ static inline int Dar_CutMergeOrdered( Dar_Cut_t * pC, Dar_Cut_t * pC0, Dar_Cut_ ***********************************************************************/ static inline int Dar_CutMerge( Dar_Cut_t * pCut, Dar_Cut_t * pCut0, Dar_Cut_t * pCut1 ) { + assert( !pCut->fUsed ); // merge the nodes if ( pCut0->nLeaves <= pCut1->nLeaves ) { @@ -227,6 +314,7 @@ static inline int Dar_CutMerge( Dar_Cut_t * pCut, Dar_Cut_t * pCut0, Dar_Cut_t * return 0; } pCut->uSign = pCut0->uSign | pCut1->uSign; + pCut->fUsed = 1; return 1; } @@ -377,6 +465,8 @@ static inline int Dar_CutSuppMinimize( Dar_Cut_t * pCut ) }; unsigned uPhase = 0, uTruth = 0xFFFF & pCut->uTruth; int i, k, nLeaves; + assert( pCut->fUsed ); + assert( pCut->nLeaves > 0 ); // compute the truth support of the cut's function nLeaves = pCut->nLeaves; for ( i = 0; i < (int)pCut->nLeaves; i++ ) @@ -395,10 +485,8 @@ static inline int Dar_CutSuppMinimize( Dar_Cut_t * pCut ) { if ( !(uPhase & (1 << i)) ) continue; - pCut->pLeaves[k] = pCut->pLeaves[i]; -// pCut->pIndices[k] = pCut->pIndices[i]; - pCut->uSign |= (1 << (pCut->pLeaves[i] & 31)); - k++; + pCut->pLeaves[k++] = pCut->pLeaves[i]; + pCut->uSign |= Aig_ObjCutSign( pCut->pLeaves[i] ); } assert( k == nLeaves ); pCut->nLeaves = nLeaves; @@ -416,16 +504,13 @@ static inline int Dar_CutSuppMinimize( Dar_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -void Dar_ObjSetupTrivial( Dar_Obj_t * pObj ) +void Dar_ManCutsFree( Dar_Man_t * p ) { - Dar_Cut_t * pCut; - pCut = pObj->pData; - memset( pCut, 0, sizeof(Dar_Cut_t) ); - pCut->nLeaves = 1; - pCut->pLeaves[0] = pObj->Id; -// pCut->pIndices[0] = 0; - pCut->uSign = (1 << (pObj->Id & 31)); - pCut->uTruth = 0xAAAA; + if ( p->pMemCuts == NULL ) + return; + Aig_MmFixedStop( p->pMemCuts, 0 ); + p->pMemCuts = NULL; +// Aig_ManCleanData( p ); } /**Function************************************************************* @@ -439,16 +524,35 @@ void Dar_ObjSetupTrivial( Dar_Obj_t * pObj ) SeeAlso [] ***********************************************************************/ -void Dar_ManSetupPis( Dar_Man_t * p ) +Dar_Cut_t * Dar_ObjPrepareCuts( Dar_Man_t * p, Aig_Obj_t * pObj ) { - Dar_Obj_t * pObj; + Dar_Cut_t * pCutSet, * pCut; int i; - Dar_ManForEachPi( p, pObj, i ) + assert( Dar_ObjCuts(pObj) == NULL ); + pObj->nCuts = p->pPars->nCutsMax; + // create the cutset of the node + pCutSet = (Dar_Cut_t *)Aig_MmFixedEntryFetch( p->pMemCuts ); + Dar_ObjSetCuts( pObj, pCutSet ); + Dar_ObjForEachCut( pObj, pCut, i ) + pCut->fUsed = 0; + // add unit cut if needed + pCut = pCutSet; + pCut->fUsed = 1; + if ( Aig_ObjIsConst1(pObj) ) { - pObj->nCuts = 1; - pObj->pData = (Dar_Cut_t *)Dar_MmFlexEntryFetch( p->pMemCuts, pObj->nCuts * sizeof(Dar_Cut_t) ); - Dar_ObjSetupTrivial( pObj ); + pCut->nLeaves = 0; + pCut->uSign = 0; + pCut->uTruth = 0xFFFF; } + else + { + pCut->nLeaves = 1; + pCut->pLeaves[0] = pObj->Id; + pCut->uSign = Aig_ObjCutSign( pObj->Id ); + pCut->uTruth = 0xAAAA; + } + pCut->Value = Dar_CutFindValue( p, pCut ); + return pCutSet; } /**Function************************************************************* @@ -462,86 +566,75 @@ void Dar_ManSetupPis( Dar_Man_t * p ) SeeAlso [] ***********************************************************************/ -void Dar_ManCutsFree( Dar_Man_t * p ) -{ -// Dar_ManCleanData( p ); - Dar_MmFlexStop( p->pMemCuts, 0 ); - p->pMemCuts = NULL; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Cut_t * Dar_ObjComputeCuts( Dar_Man_t * p, Dar_Obj_t * pObj ) +Dar_Cut_t * Dar_ObjComputeCuts( Dar_Man_t * p, Aig_Obj_t * pObj ) { - Dar_Obj_t * pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - Dar_Obj_t * pFanin1 = Dar_ObjReal_rec( Dar_ObjChild1(pObj) ); - Dar_Cut_t * pStart0 = Dar_Regular(pFanin0)->pData; - Dar_Cut_t * pStart1 = Dar_Regular(pFanin1)->pData; - Dar_Cut_t * pStop0 = pStart0 + Dar_Regular(pFanin0)->nCuts; - Dar_Cut_t * pStop1 = pStart1 + Dar_Regular(pFanin1)->nCuts; - Dar_Cut_t * pCut0, * pCut1, * pCut; - int i; - assert( pObj->pData == NULL ); + Aig_Obj_t * pFanin0 = Aig_ObjReal_rec( Aig_ObjChild0(pObj) ); + Aig_Obj_t * pFanin1 = Aig_ObjReal_rec( Aig_ObjChild1(pObj) ); + Aig_Obj_t * pFaninR0 = Aig_Regular(pFanin0); + Aig_Obj_t * pFaninR1 = Aig_Regular(pFanin1); + Dar_Cut_t * pCutSet, * pCut0, * pCut1, * pCut; + int i, k, RetValue; + + assert( !Aig_IsComplement(pObj) ); + assert( Aig_ObjIsNode(pObj) ); + assert( Dar_ObjCuts(pObj) == NULL ); + assert( Dar_ObjCuts(pFaninR0) != NULL ); + assert( Dar_ObjCuts(pFaninR1) != NULL ); + + // set up the first cut + pCutSet = Dar_ObjPrepareCuts( p, pObj ); // make sure fanins cuts are computed - p->nCutsUsed = 0; - for ( pCut0 = pStart0; pCut0 < pStop0; pCut0++ ) - for ( pCut1 = pStart1; pCut1 < pStop1; pCut1++ ) + Dar_ObjForEachCut( pFaninR0, pCut0, i ) + Dar_ObjForEachCut( pFaninR1, pCut1, k ) { - // get storage for the next cut - if ( p->nCutsUsed == p->nBaseCuts ) - break; - pCut = p->pBaseCuts[p->nCutsUsed]; + p->nCutsAll++; + // make sure K-feasible cut exists + if ( Dar_WordCountOnes(pCut0->uSign | pCut1->uSign) > 4 ) + continue; + // get the next cut of this node + pCut = Dar_CutFindFree( p, pObj ); // create the new cut if ( !Dar_CutMerge( pCut, pCut0, pCut1 ) ) + { + assert( !pCut->fUsed ); continue; + } + p->nCutsTried++; // check dominance - if ( Dar_CutFilter( p, pCut ) ) + if ( Dar_CutFilter( pObj, pCut ) ) + { + assert( !pCut->fUsed ); continue; + } // compute truth table - pCut->uTruth = 0xFFFF & Dar_CutTruth( pCut, pCut0, pCut1, Dar_IsComplement(pFanin0), Dar_IsComplement(pFanin1) ); + pCut->uTruth = 0xFFFF & Dar_CutTruth( pCut, pCut0, pCut1, Aig_IsComplement(pFanin0), Aig_IsComplement(pFanin1) ); // minimize support of the cut if ( Dar_CutSuppMinimize( pCut ) ) { - if ( Dar_CutFilter( p, pCut ) ) - continue; + // if a simple cut is found return immediately + if ( pCut->nLeaves < 2 ) + return pCutSet; + // otherwise, filter the cuts again + RetValue = Dar_CutFilter( pObj, pCut ); + assert( !RetValue ); } - // CNF mapping: assign the cut cost - if ( p->pManCnf ) + // assign the value of the cut + pCut->Value = Dar_CutFindValue( p, pCut ); + // if the cut contains removed node, do not use it + if ( pCut->Value == 0 ) { - extern void Cnf_CutAssignAreaFlow( void * pManCnf, Dar_Cut_t * pCut ); - Cnf_CutAssignAreaFlow( p->pManCnf, pCut ); + p->nCutsSkipped++; + pCut->fUsed = 0; } - - // increment the number of cuts - p->nCutsUsed++; - } - // get memory for the cuts of this node - pObj->nCuts = p->nCutsUsed + 1; - pObj->pData = pCut = (Dar_Cut_t *)Dar_MmFlexEntryFetch( p->pMemCuts, pObj->nCuts * sizeof(Dar_Cut_t) ); - // create elementary cut - Dar_ObjSetupTrivial( pObj ); - // copy non-elementary cuts - for ( i = 0; i < p->nCutsUsed; i++ ) - *++pCut = *(p->pBaseCuts[i]); - - // CNF mapping: assign the best cut - if ( p->pManCnf ) - { - extern Dar_Cut_t * Cnf_ObjFindBestCut( Dar_Obj_t * pObj ); - Dar_ObjSetBestCut( Cnf_ObjFindBestCut(pObj) ); } - return pObj->pData; + // count the number of nontrivial cuts cuts + Dar_ObjForEachCut( pObj, pCut, i ) + p->nCutsUsed += pCut->fUsed; + // discount trivial cut + p->nCutsUsed--; + return pCutSet; } /**Function************************************************************* @@ -555,14 +648,14 @@ Dar_Cut_t * Dar_ObjComputeCuts( Dar_Man_t * p, Dar_Obj_t * pObj ) SeeAlso [] ***********************************************************************/ -Dar_Cut_t * Dar_ObjComputeCuts_rec( Dar_Man_t * p, Dar_Obj_t * pObj ) +Dar_Cut_t * Dar_ObjComputeCuts_rec( Dar_Man_t * p, Aig_Obj_t * pObj ) { - if ( pObj->pData ) - return pObj->pData; - if ( Dar_ObjIsBuf(pObj) ) - return Dar_ObjComputeCuts_rec( p, Dar_ObjFanin0(pObj) ); - Dar_ObjComputeCuts_rec( p, Dar_ObjFanin0(pObj) ); - Dar_ObjComputeCuts_rec( p, Dar_ObjFanin1(pObj) ); + if ( Dar_ObjCuts(pObj) ) + return Dar_ObjCuts(pObj); + if ( Aig_ObjIsBuf(pObj) ) + return Dar_ObjComputeCuts_rec( p, Aig_ObjFanin0(pObj) ); + Dar_ObjComputeCuts_rec( p, Aig_ObjFanin0(pObj) ); + Dar_ObjComputeCuts_rec( p, Aig_ObjFanin1(pObj) ); return Dar_ObjComputeCuts( p, pObj ); } diff --git a/src/aig/dar/darData.c b/src/aig/dar/darData.c index 60fab63e..abf1d378 100644 --- a/src/aig/dar/darData.c +++ b/src/aig/dar/darData.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -9419,6 +9419,1665 @@ unsigned int s_Data2[24772] = { 15235,15234,27897,27488 }; + +const int s_nDataSize3 = 24772; +unsigned int s_Data3[24772] = { +//Output priorities (total = 24772): +10, 9, 12, 6, 11, 14, 4, 1, 7, 5, 2, 3, 13, 8, 0, +0, 1, 2, 219, 218, 76, 217, 216, 77, 1, 0, 74, 78, 79, 75, +70, 71, 72, 68, 73, 69, 310, 299, 296, 331, 297, 332, 114, 26, 298, +340, 330, 336, 338, 339, 62, 112, 328, 334, 329, 335, 113, 337, 327, 333, +115, 60, 27, 61, 63, 273, 215, 36, 213, 31, 35, 39, 319, 312, 320, +323, 324, 343, 157, 345, 28, 178, 32, 59, 269, 58, 309, 305, 275, 271, +308, 304, 34, 117, 181, 129, 154, 211, 30, 38, 177, 193, 55, 130, 268, +33, 303, 174, 29, 37, 119, 212, 143, 188, 66, 270, 141, 183, 194, 179, +126, 261, 190, 267, 344, 346, 272, 189, 173, 274, 51, 322, 321, 342, 315, +214, 311, 14, 57, 223, 348, 125, 176, 192, 317, 280, 314, 165, 160, 175, +326, 127, 17, 247, 172, 262, 5, 231, 99, 138, 124, 54, 301, 325, 167, +15, 43, 205, 47, 122, 147, 292, 295, 83, 106, 86, 87, 220, 131, 347, +293, 150, 209, 233, 67, 116, 148, 156, 171, 180, 191, 256, 195, 341, 128, +277, 291, 281, 289, 294, 313, 102, 46, 103, 207, 229, 236, 240, 224, 227, +249, 170, 49, 251, 258, 318, 133, 197, 278, 2, 56, 252, 265, 254, 20, +142, 151, 316, 164, 121, 162, 41, 107, 139, 203, 288, 302, 48, 52, 110, +53, 64, 4, 16, 284, 135, 307, 3, 40, 155, 202, 23, 93, 22, 92, +290, 65, 210, 50, 98, 208, 94, 123, 137, 187, 225, 7, 10, 120, 109, +263, 287, 186, 108, 152, 264, 90, 253, 96, 97, 136, 200, 118, 140, 300, +306, 185, 6, 11, 89, 259, 85, 101, 132, 196, 24, 45, 260, 244, 91, +18, 104, 232, 19, 44, 105, 184, 21, 84, 226, 250, 283, 279, 286, 158, +248, 257, 255, 80, 169, 13, 100, 81, 168, 199, 238, 9, 12, 82, 182, +201, 266, 146, 204, 230, 239, 241, 159, 221, 285, 134, 88, 242, 246, 8, +144, 222, 149, 161, 228, 237, 276, 95, 206, 282, 163, 198, 243, 235, 245, +42, 166, 25, 111, 145, 153, 234, 13, 0, 1, 8, 3, 11, 7, 9, +2, 12, 4, 6, 5, 10, 0, 61, 62, 0, 2, 3, 5, 6, 8, +15, 17, 1, 4, 7, 9, 10, 11, 12, 13, 14, 16, 18, 19, 20, +21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, +36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, +51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 63, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 4, 5, +2, 0, 1, 3, 7, 10, 8, 11, 6, 9, 97, 100, 22, 123, 124, +125, 98, 101, 40, 39, 66, 72, 75, 69, 68, 74, 21, 41, 67, 73, +77, 30, 71, 23, 106, 36, 54, 55, 63, 96, 32, 99, 58, 59, 65, +38, 107, 27, 17, 56, 57, 64, 70, 76, 29, 15, 31, 122, 102, 25, +48, 49, 50, 51, 52, 53, 26, 28, 103, 37, 127, 104, 120, 121, 24, +33, 46, 47, 62, 112, 113, 116, 105, 20, 13, 126, 128, 35, 34, 19, +42, 43, 44, 45, 60, 61, 18, 79, 84, 91, 16, 14, 82, 89, 94, +85, 119, 83, 88, 95, 118, 78, 90, 81, 86, 93, 12, 80, 87, 92, +108, 109, 110, 111, 114, 115, 117, 148, 542, 149, 147, 303, 531, 555, 573, +574, 532, 556, 150, 153, 155, 578, 304, 560, 536, 151, 154, 157, 534, 558, +576, 533, 538, 557, 575, 547, 551, 570, 305, 568, 306, 540, 541, 544, 546, +550, 553, 562, 564, 565, 571, 552, 554, 572, 535, 559, 577, 537, 561, 569, +539, 543, 545, 548, 549, 563, 566, 567, 308, 307, 152, 156, 158, 382, 144, +128, 145, 438, 446, 450, 458, 462, 470, 474, 482, 492, 500, 504, 510, 516, +522, 530, 204, 394, 528, 381, 397, 480, 498, 396, 400, 436, 444, 448, 456, +460, 468, 472, 490, 502, 508, 514, 520, 286, 388, 393, 294, 403, 273, 384, +385, 387, 391, 399, 408, 313, 317, 347, 354, 414, 419, 426, 25, 88, 127, +130, 198, 275, 336, 483, 126, 281, 283, 341, 432, 299, 325, 390, 402, 415, +416, 417, 418, 427, 428, 116, 124, 134, 142, 221, 229, 298, 479, 486, 497, +527, 24, 87, 227, 311, 315, 329, 353, 506, 512, 518, 30, 34, 41, 196, +300, 484, 48, 104, 186, 191, 264, 335, 343, 363, 234, 276, 441, 443, 453, +455, 465, 467, 477, 495, 525, 222, 269, 476, 494, 524, 395, 89, 140, 413, +420, 425, 481, 499, 505, 511, 517, 529, 200, 257, 327, 398, 401, 440, 445, +452, 457, 464, 469, 32, 36, 42, 47, 345, 365, 435, 442, 447, 454, 459, +466, 471, 478, 489, 496, 501, 507, 513, 519, 526, 202, 323, 146, 170, 177, +179, 248, 255, 368, 380, 206, 122, 132, 258, 279, 288, 296, 349, 375, 434, +46, 114, 165, 180, 201, 219, 243, 250, 297, 405, 429, 33, 38, 43, 172, +203, 208, 346, 392, 404, 410, 485, 488, 183, 216, 261, 348, 386, 430, 20, +26, 65, 100, 131, 162, 167, 174, 182, 188, 189, 194, 210, 218, 240, 252, +260, 266, 272, 284, 360, 372, 383, 423, 12, 17, 57, 92, 99, 129, 213, +215, 230, 231, 278, 291, 293, 339, 389, 406, 411, 422, 15, 60, 62, 97, +117, 119, 135, 199, 224, 225, 236, 245, 267, 302, 321, 326, 377, 407, 102, +137, 175, 274, 431, 412, 421, 424, 173, 238, 246, 251, 253, 262, 270, 282, +366, 370, 378, 437, 439, 449, 451, 461, 463, 473, 475, 491, 493, 503, 509, +515, 521, 523, 0, 1, 81, 82, 106, 160, 168, 184, 185, 192, 193, 263, +271, 277, 322, 358, 22, 28, 31, 40, 67, 98, 103, 105, 138, 254, 316, +319, 355, 328, 10, 14, 49, 52, 59, 70, 73, 90, 112, 133, 220, 228, +232, 233, 301, 309, 314, 331, 333, 337, 344, 351, 35, 37, 44, 163, 342, +409, 433, 487, 259, 27, 29, 39, 50, 161, 164, 176, 178, 181, 187, 190, +197, 205, 239, 241, 242, 324, 332, 359, 361, 362, 371, 373, 374, 6, 7, +45, 55, 56, 75, 77, 79, 80, 108, 109, 159, 166, 169, 171, 195, 217, +237, 247, 249, 256, 265, 268, 280, 334, 340, 350, 357, 367, 369, 379, 2, +3, 9, 18, 19, 21, 23, 53, 63, 64, 66, 68, 72, 76, 83, 84, +93, 95, 96, 101, 107, 111, 120, 121, 123, 125, 139, 141, 143, 212, 244, +290, 295, 310, 312, 318, 320, 330, 338, 352, 356, 4, 5, 8, 11, 13, +51, 54, 58, 61, 69, 71, 74, 78, 85, 86, 94, 110, 113, 115, 136, +207, 209, 211, 214, 223, 226, 235, 285, 287, 289, 292, 364, 376, 16, 91, +118, 0, 3, 19, 149, 96, 20, 150, 5, 1, 6, 4, 2, 147, 93, +91, 145, 148, 95, 146, 85, 55, 66, 76, 59, 73, 81, 51, 61, 64, +54, 58, 92, 94, 63, 173, 62, 86, 65, 75, 60, 74, 82, 56, 52, +53, 57, 171, 167, 160, 159, 170, 72, 141, 162, 172, 28, 68, 29, 140, +168, 27, 70, 126, 139, 69, 163, 89, 137, 166, 71, 169, 129, 142, 164, +116, 135, 143, 90, 67, 113, 121, 165, 161, 131, 123, 125, 133, 30, 7, +138, 10, 117, 119, 11, 120, 127, 134, 130, 132, 115, 124, 114, 136, 9, +118, 33, 77, 157, 158, 8, 12, 88, 155, 156, 34, 78, 99, 97, 128, +36, 44, 87, 35, 43, 15, 13, 17, 122, 21, 23, 25, 144, 37, 45, +47, 103, 32, 42, 80, 39, 49, 83, 108, 40, 50, 84, 38, 46, 48, +31, 41, 79, 18, 98, 22, 24, 26, 14, 16, 105, 107, 100, 152, 111, +109, 104, 101, 110, 112, 106, 153, 102, 151, 154, 0, 1, 3, 4, 2, +12, 13, 10, 11, 14, 9, 6, 5, 7, 8, 21, 24, 23, 22, 20, +19, 15, 16, 17, 18, 0, 1, 3, 2, 108, 109, 139, 153, 122, 96, +178, 97, 126, 95, 101, 100, 94, 174, 140, 172, 175, 173, 5, 36, 154, +88, 83, 80, 35, 161, 151, 19, 11, 6, 147, 143, 34, 176, 123, 37, +169, 170, 171, 163, 164, 165, 166, 167, 168, 155, 156, 157, 158, 159, 160, +82, 162, 177, 152, 81, 111, 7, 12, 20, 128, 4, 93, 21, 64, 13, +148, 60, 62, 118, 10, 18, 33, 144, 30, 48, 135, 149, 86, 114, 99, +124, 129, 130, 131, 61, 63, 65, 8, 14, 16, 22, 24, 26, 28, 73, +75, 77, 90, 56, 72, 74, 76, 78, 51, 53, 55, 57, 59, 67, 69, +71, 79, 89, 91, 50, 52, 54, 58, 66, 68, 70, 92, 107, 39, 41, +43, 45, 47, 110, 103, 105, 120, 145, 127, 38, 40, 42, 44, 46, 137, +102, 104, 106, 31, 32, 49, 9, 15, 17, 23, 29, 87, 25, 27, 150, +141, 142, 84, 85, 146, 98, 116, 119, 133, 115, 121, 136, 132, 125, 117, +112, 113, 138, 134, 2, 0, 1, 3, 8, 6, 7, 4, 5, 9, 10, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 2, 1, 4, 8, 7, 9, 6, 0, 5, 3, 10, 109, 107, +108, 97, 105, 28, 30, 21, 81, 26, 32, 106, 20, 24, 35, 22, 34, +96, 104, 62, 27, 111, 11, 18, 23, 36, 83, 37, 12, 95, 17, 46, +56, 25, 40, 42, 87, 89, 14, 16, 13, 29, 103, 82, 110, 15, 19, +31, 33, 102, 38, 66, 67, 68, 69, 70, 71, 72, 85, 41, 115, 117, +91, 93, 94, 99, 101, 43, 73, 86, 88, 114, 116, 50, 52, 74, 76, +77, 78, 79, 39, 113, 44, 45, 47, 48, 49, 51, 53, 54, 55, 57, +58, 59, 60, 61, 63, 64, 65, 75, 80, 84, 90, 92, 98, 100, 112, +0, 1, 20, 17, 18, 12, 19, 16, 21, 15, 23, 14, 22, 13, 0, +6, 5, 11, 3, 9, 2, 8, 1, 7, 4, 10, 3, 4, 11, 14, +17, 32, 0, 1, 2, 5, 6, 7, 8, 9, 10, 12, 13, 15, 16, +18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, +34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 2, 3, 0, 1, +15, 13, 17, 21, 77, 76, 33, 30, 34, 110, 105, 114, 118, 31, 32, +35, 101, 100, 16, 131, 12, 14, 130, 135, 132, 112, 120, 116, 111, 115, +119, 79, 117, 113, 121, 20, 133, 80, 134, 78, 81, 44, 109, 49, 47, +124, 46, 28, 48, 126, 26, 87, 89, 90, 88, 6, 5, 7, 9, 11, +19, 36, 38, 40, 42, 86, 91, 18, 4, 10, 39, 8, 37, 41, 43, +45, 60, 127, 27, 61, 106, 129, 59, 108, 128, 53, 54, 57, 58, 62, +50, 29, 56, 63, 52, 55, 107, 122, 123, 125, 51, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 75, 82, 83, 84, 85, 92, 93, 94, +95, 96, 97, 98, 99, 102, 103, 104, 23, 25, 24, 22, 175, 174, 176, +162, 158, 165, 124, 166, 15, 155, 126, 160, 120, 121, 122, 123, 125, 127, +128, 129, 153, 157, 171, 152, 163, 170, 96, 97, 108, 0, 3, 6, 9, +12, 66, 69, 72, 75, 78, 81, 130, 131, 150, 151, 156, 159, 161, 168, +169, 173, 177, 154, 164, 167, 172, 1, 2, 4, 5, 7, 8, 10, 11, +13, 14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, +29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, +44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, +59, 60, 61, 62, 63, 64, 65, 67, 68, 70, 71, 73, 74, 76, 77, +79, 80, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, +95, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 109, 110, 111, 112, +113, 114, 115, 116, 117, 118, 119, 132, 133, 134, 135, 136, 137, 138, 139, +140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 178, 179, 0, 1, 2, +8, 6, 7, 3, 5, 4, 0, 1305, 1308, 540, 545, 558, 563, 564, 569, +570, 575, 576, 581, 582, 587, 588, 593, 594, 599, 600, 605, 606, 611, 612, +617, 618, 623, 624, 629, 630, 635, 636, 641, 642, 647, 648, 653, 654, 657, +662, 663, 668, 669, 672, 677, 678, 681, 684, 687, 690, 0, 1, 2, 3, +4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, +34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, +49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, +64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, +79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, +94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, +109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, +124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, +139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, +154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, +169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, +184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, +199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, +214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, +229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, +244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, +259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, +274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, +289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, +304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, +319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, +334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, +349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, +364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, +379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, +394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, +409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, +424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, +439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, +454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, +469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, +484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, +499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, +514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, +529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 541, 542, 543, 544, +546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 559, 560, 561, +562, 565, 566, 567, 568, 571, 572, 573, 574, 577, 578, 579, 580, 583, 584, +585, 586, 589, 590, 591, 592, 595, 596, 597, 598, 601, 602, 603, 604, 607, +608, 609, 610, 613, 614, 615, 616, 619, 620, 621, 622, 625, 626, 627, 628, +631, 632, 633, 634, 637, 638, 639, 640, 643, 644, 645, 646, 649, 650, 651, +652, 655, 656, 658, 659, 660, 661, 664, 665, 666, 667, 670, 671, 673, 674, +675, 676, 679, 680, 682, 683, 685, 686, 688, 689, 691, 692, 693, 694, 695, +696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, +711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, +726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, +741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, +756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, +771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, +786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, +801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, +816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, +831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, +846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, +861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, +876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, +891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, +906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, +921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, +936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, +951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, +966, 967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, +981, 982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, +996, 997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, +1011, 1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, +1026, 1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, +1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, +1056, 1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, +1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, +1086, 1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, +1101, 1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, +1116, 1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, +1131, 1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, +1146, 1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, +1161, 1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, +1176, 1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, +1191, 1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, +1206, 1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, +1221, 1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, +1236, 1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, +1251, 1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, +1266, 1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, +1281, 1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, +1296, 1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1306, 1307, 1309, 1310, 158, 161, +164, 167, 170, 173, 74, 77, 86, 89, 0, 3, 12, 15, 24, 27, 36, +39, 48, 51, 60, 63, 110, 113, 122, 125, 134, 137, 146, 149, 76, 88, +156, 160, 162, 165, 169, 171, 2, 132, 175, 26, 38, 50, 62, 72, 83, +84, 95, 108, 120, 78, 90, 96, 104, 174, 14, 144, 176, 9, 21, 33, +45, 57, 69, 79, 81, 91, 93, 98, 106, 119, 131, 143, 155, 59, 71, +157, 159, 163, 166, 168, 172, 99, 101, 103, 105, 11, 35, 47, 73, 75, +80, 82, 85, 87, 92, 94, 97, 100, 102, 107, 117, 129, 141, 8, 20, +23, 32, 44, 56, 68, 114, 126, 138, 150, 153, 179, 186, 191, 198, 180, +192, 1, 4, 5, 6, 7, 10, 13, 16, 17, 18, 19, 22, 25, 28, +29, 30, 31, 34, 37, 40, 41, 42, 43, 46, 49, 52, 53, 54, 55, +58, 61, 64, 65, 66, 67, 70, 109, 111, 112, 115, 116, 118, 121, 123, +124, 127, 128, 130, 133, 135, 136, 139, 140, 142, 145, 147, 148, 151, 152, +154, 213, 214, 215, 216, 177, 189, 184, 196, 221, 222, 223, 224, 178, 181, +182, 183, 185, 187, 188, 190, 193, 194, 195, 197, 199, 200, 201, 202, 203, +204, 205, 206, 207, 208, 209, 210, 211, 212, 217, 218, 219, 220, 2, 4, +6, 8, 10, 12, 32, 34, 36, 46, 48, 52, 54, 56, 58, 60, 62, +64, 86, 87, 88, 105, 106, 107, 108, 109, 112, 113, 115, 117, 121, 1, +3, 5, 7, 9, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21, 23, +25, 26, 27, 28, 29, 30, 31, 33, 35, 37, 38, 39, 40, 41, 42, +43, 44, 45, 47, 49, 51, 53, 55, 57, 59, 61, 63, 65, 66, 67, +68, 71, 73, 75, 76, 78, 79, 80, 82, 83, 84, 92, 93, 94, 96, +97, 98, 99, 100, 101, 102, 103, 104, 110, 111, 114, 116, 118, 119, 120, +122, 124, 126, 127, 129, 131, 141, 143, 145, 146, 148, 150, 152, 153, 156, +166, 167, 170, 173, 174, 176, 180, 182, 184, 186, 0, 22, 24, 50, 69, +70, 72, 74, 77, 81, 85, 89, 90, 91, 95, 123, 125, 128, 130, 132, +133, 134, 135, 136, 137, 138, 139, 140, 142, 144, 147, 149, 151, 154, 155, +157, 158, 159, 160, 161, 162, 163, 164, 165, 168, 169, 171, 172, 175, 177, +178, 179, 181, 183, 185, 122, 85, 89, 92, 106, 118, 136, 148, 156, 164, +27, 35, 37, 38, 52, 57, 62, 67, 71, 83, 55, 65, 68, 121, 26, +53, 63, 66, 80, 82, 105, 114, 119, 123, 137, 143, 14, 25, 30, 31, +100, 28, 117, 108, 134, 3, 12, 34, 36, 39, 40, 45, 46, 51, 59, +60, 61, 73, 74, 75, 76, 77, 78, 84, 86, 87, 88, 90, 91, 93, +94, 95, 110, 112, 115, 116, 120, 127, 128, 130, 132, 141, 142, 152, 175, +58, 0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 13, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 29, 32, 33, 41, 42, 43, 44, +47, 48, 49, 50, 54, 56, 64, 69, 70, 72, 79, 81, 96, 97, 98, +99, 101, 102, 103, 104, 107, 109, 111, 113, 124, 125, 126, 129, 131, 133, +135, 138, 139, 140, 144, 145, 146, 147, 149, 150, 151, 153, 154, 155, 157, +158, 159, 160, 161, 162, 163, 165, 166, 167, 168, 169, 170, 171, 172, 173, +174, 176, 177, 23, 29, 5, 24, 25, 26, 27, 28, 30, 31, 0, 1, +2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, +18, 19, 20, 21, 22, 32, 83, 84, 96, 99, 100, 16, 85, 98, 18, +26, 27, 37, 40, 49, 52, 17, 51, 55, 57, 97, 8, 3, 19, 9, +50, 56, 58, 10, 53, 72, 82, 87, 89, 91, 14, 118, 129, 12, 81, +86, 88, 90, 130, 11, 20, 21, 22, 23, 24, 25, 28, 29, 30, 31, +32, 33, 34, 35, 36, 43, 67, 68, 69, 93, 95, 41, 45, 47, 4, +5, 6, 13, 38, 117, 128, 71, 0, 1, 2, 15, 39, 92, 94, 65, +70, 122, 123, 127, 7, 42, 44, 46, 48, 54, 59, 60, 61, 62, 63, +64, 66, 105, 106, 109, 110, 111, 112, 113, 114, 121, 124, 126, 73, 74, +75, 76, 77, 78, 79, 80, 101, 102, 103, 104, 107, 108, 115, 116, 119, +120, 125, 18, 24, 5, 7, 9, 13, 0, 1, 2, 3, 4, 6, 8, +10, 11, 12, 14, 15, 16, 17, 19, 20, 21, 22, 23, 25, 26, 27, +28, 29, 30, 38, 37, 3, 2, 39, 4, 40, 5, 109, 110, 111, 99, +107, 97, 105, 140, 141, 142, 0, 98, 106, 1, 100, 108, 34, 35, 36, +10, 11, 42, 46, 50, 54, 58, 62, 66, 70, 13, 17, 21, 30, 6, +88, 90, 96, 102, 113, 115, 121, 123, 125, 135, 137, 139, 9, 14, 18, +22, 33, 44, 48, 52, 56, 60, 64, 68, 72, 116, 126, 130, 43, 47, +51, 55, 59, 63, 67, 71, 85, 91, 93, 103, 80, 82, 83, 73, 75, +76, 119, 129, 133, 12, 16, 20, 31, 7, 41, 45, 49, 53, 57, 61, +65, 69, 117, 127, 131, 87, 89, 95, 101, 112, 114, 120, 122, 124, 134, +136, 138, 86, 92, 94, 104, 118, 128, 132, 79, 81, 84, 74, 77, 78, +8, 15, 19, 23, 32, 24, 25, 28, 26, 27, 29, 0, 1, 2, 3, +4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, +34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, +49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, +64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, +79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, +94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, +109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, +124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, +139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, +154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 34, 5, 6, 7, +8, 9, 10, 11, 12, 33, 47, 2, 4, 19, 20, 21, 36, 37, 38, +40, 41, 0, 1, 3, 13, 14, 15, 16, 17, 18, 22, 23, 24, 25, +26, 27, 28, 29, 30, 31, 32, 35, 39, 42, 43, 44, 45, 46, 48, +49, 50, 144, 145, 0, 141, 142, 143, 155, 154, 139, 140, 146, 147, 150, +151, 76, 82, 83, 84, 85, 86, 87, 158, 131, 77, 132, 159, 23, 24, +25, 26, 27, 28, 32, 33, 73, 79, 91, 95, 1, 3, 5, 12, 13, +14, 15, 16, 17, 18, 19, 20, 21, 22, 29, 30, 31, 34, 102, 104, +106, 108, 112, 113, 114, 115, 116, 117, 118, 119, 138, 37, 39, 41, 43, +48, 50, 52, 54, 2, 4, 6, 7, 8, 9, 10, 11, 36, 38, 40, +42, 44, 45, 46, 47, 56, 57, 58, 59, 60, 62, 64, 66, 68, 70, +72, 74, 75, 78, 80, 81, 88, 89, 90, 92, 93, 94, 96, 97, 98, +100, 103, 105, 107, 109, 137, 160, 161, 162, 35, 49, 51, 53, 55, 61, +63, 65, 67, 69, 71, 99, 101, 110, 111, 120, 121, 122, 123, 124, 125, +126, 127, 128, 129, 130, 133, 134, 135, 136, 148, 149, 152, 153, 156, 157, +4, 11, 5, 6, 7, 8, 10, 9, 12, 17, 18, 19, 21, 2, 3, +0, 1, 13, 14, 15, 16, 20, 28, 32, 34, 38, 40, 22, 23, 24, +25, 26, 27, 29, 30, 31, 33, 35, 36, 37, 39, 41, 73, 69, 95, +11, 72, 14, 12, 13, 93, 71, 74, 94, 87, 81, 86, 79, 60, 96, +98, 88, 59, 82, 97, 44, 46, 54, 68, 92, 100, 45, 53, 67, 43, +91, 99, 80, 89, 77, 1, 3, 9, 5, 6, 7, 8, 70, 28, 83, +22, 34, 42, 49, 51, 57, 17, 23, 29, 37, 63, 19, 25, 31, 39, +48, 50, 52, 56, 58, 62, 64, 66, 84, 76, 90, 78, 75, 85, 4, +0, 2, 10, 20, 26, 32, 36, 40, 15, 61, 16, 18, 24, 30, 35, +38, 47, 55, 65, 21, 27, 33, 41, 0, 1, 2, 3, 4, 5, 6, +7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, +22, 23, 24, 25, 26, 40, 42, 3, 1, 51, 5, 49, 48, 22, 24, +4, 2, 52, 50, 76, 78, 80, 94, 96, 98, 23, 47, 26, 27, 63, +64, 65, 70, 71, 21, 77, 79, 81, 17, 20, 33, 37, 41, 43, 57, +55, 56, 58, 59, 60, 61, 62, 18, 19, 25, 32, 36, 95, 97, 99, +0, 38, 39, 54, 67, 69, 73, 75, 85, 87, 91, 93, 53, 66, 84, +86, 90, 89, 6, 7, 11, 12, 13, 82, 83, 68, 72, 74, 92, 8, +9, 10, 14, 15, 16, 28, 29, 30, 31, 34, 35, 44, 45, 46, 88, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, +30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, +45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, +60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, +75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, +90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, +105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, +120, 121, 122, 123, 124, 125, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, +84, 85, 86, 87, 88, 89, 90, 91, 92, 0, 1, 2, 3, 4, 5, +6, 7, 8, 1, 3, 43, 0, 2, 4, 5, 6, 7, 8, 9, 10, +11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, +26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, +41, 42, 44, 45, 46, 89, 90, 0, 1, 2, 3, 4, 5, 6, 7, +8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, +23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, +38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, +53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, +83, 84, 85, 86, 87, 88, 91, 92, 93, 94, 95, 96, 97, 98, 99, +100, 101, 102, 103, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, +11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, +26, 27, 28, 29, 30, 31, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 186, 189, 174, +185, 179, 180, 177, 181, 188, 191, 60, 63, 175, 183, 176, 184, 64, 61, +62, 65, 178, 182, 187, 190, 130, 142, 154, 166, 104, 110, 116, 13, 24, +36, 78, 122, 136, 148, 160, 172, 7, 18, 30, 84, 102, 108, 114, 105, +111, 117, 120, 123, 74, 86, 98, 107, 113, 119, 125, 1, 9, 20, 32, +44, 45, 55, 75, 99, 103, 109, 115, 0, 6, 19, 31, 42, 43, 54, +72, 73, 85, 96, 97, 137, 149, 161, 173, 2, 46, 47, 56, 76, 77, +100, 101, 127, 133, 139, 145, 151, 157, 163, 169, 8, 21, 33, 87, 106, +112, 118, 121, 124, 128, 129, 140, 141, 152, 153, 3, 4, 15, 26, 38, +48, 49, 50, 51, 57, 58, 66, 67, 68, 69, 80, 90, 91, 92, 93, +126, 131, 134, 138, 143, 146, 150, 155, 158, 162, 167, 170, 10, 11, 22, +23, 34, 35, 88, 89, 135, 147, 159, 171, 5, 12, 14, 16, 17, 25, +27, 28, 29, 37, 39, 40, 41, 52, 53, 59, 70, 71, 79, 81, 82, +83, 94, 95, 132, 144, 156, 164, 165, 168, 756, 759, 761, 104, 105, 640, +647, 700, 107, 757, 760, 102, 222, 224, 310, 420, 431, 441, 460, 468, 491, +494, 501, 558, 571, 654, 666, 683, 722, 7, 10, 31, 34, 60, 65, 162, +165, 178, 434, 467, 477, 480, 550, 569, 657, 671, 682, 718, 751, 13, 37, +54, 175, 181, 262, 265, 313, 385, 465, 551, 563, 641, 645, 701, 719, 253, +316, 333, 339, 364, 365, 369, 371, 436, 439, 461, 496, 499, 505, 514, 520, +522, 577, 585, 588, 598, 601, 608, 617, 622, 685, 727, 733, 223, 240, 191, +709, 92, 115, 144, 199, 248, 252, 290, 307, 338, 372, 382, 410, 475, 508, +513, 515, 527, 547, 566, 567, 572, 580, 587, 590, 595, 604, 606, 615, 619, +688, 716, 725, 730, 735, 739, 747, 11, 16, 22, 23, 35, 40, 46, 47, +52, 53, 59, 64, 88, 89, 94, 103, 118, 121, 124, 138, 143, 149, 163, +164, 179, 184, 190, 202, 205, 208, 225, 244, 245, 250, 259, 268, 280, 281, +284, 285, 291, 322, 328, 332, 340, 373, 379, 388, 400, 401, 404, 405, 411, +421, 426, 428, 429, 437, 442, 450, 455, 457, 469, 478, 481, 488, 497, 502, +529, 530, 536, 537, 540, 553, 564, 570, 625, 626, 630, 635, 637, 643, 655, +656, 668, 670, 678, 681, 691, 692, 699, 703, 704, 724, 738, 749, 750, 753, +560, 574, 723, 85, 331, 470, 101, 217, 633, 642, 697, 742, 745, 754, 19, +43, 48, 187, 324, 97, 218, 296, 416, 130, 137, 166, 226, 241, 271, 279, +319, 327, 391, 399, 440, 482, 142, 283, 325, 403, 443, 453, 485, 758, 0, +24, 67, 298, 336, 346, 464, 489, 504, 507, 510, 516, 518, 521, 523, 524, +535, 552, 559, 573, 576, 579, 582, 583, 591, 592, 594, 599, 602, 603, 607, +611, 614, 616, 620, 623, 632, 644, 649, 651, 661, 663, 667, 669, 684, 687, +696, 708, 720, 726, 729, 732, 736, 1, 2, 3, 4, 5, 6, 8, 9, +12, 14, 15, 17, 18, 20, 21, 25, 26, 27, 28, 29, 30, 32, 33, +36, 38, 39, 41, 42, 44, 45, 49, 50, 51, 55, 56, 57, 58, 61, +62, 63, 66, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, +80, 81, 82, 83, 84, 86, 87, 90, 91, 93, 95, 96, 98, 99, 100, +106, 108, 109, 110, 111, 112, 113, 114, 116, 117, 119, 120, 122, 123, 125, +126, 127, 128, 129, 131, 132, 133, 134, 135, 136, 139, 140, 141, 145, 146, +147, 148, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 167, +168, 169, 170, 171, 172, 173, 174, 176, 177, 180, 182, 183, 185, 186, 188, +189, 192, 193, 194, 195, 196, 197, 198, 200, 201, 203, 204, 206, 207, 209, +210, 211, 212, 213, 214, 215, 216, 219, 220, 221, 227, 228, 229, 230, 231, +232, 233, 234, 235, 236, 237, 238, 239, 242, 243, 246, 247, 249, 251, 254, +255, 256, 257, 258, 260, 261, 263, 264, 266, 267, 269, 270, 272, 273, 274, +275, 276, 277, 278, 282, 286, 287, 288, 289, 292, 293, 294, 295, 297, 299, +300, 301, 302, 303, 304, 305, 306, 308, 309, 311, 312, 314, 315, 317, 318, +320, 321, 323, 326, 329, 330, 334, 335, 337, 341, 342, 343, 344, 345, 347, +348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, +363, 366, 367, 368, 370, 374, 375, 376, 377, 378, 380, 381, 383, 384, 386, +387, 389, 390, 392, 393, 394, 395, 396, 397, 398, 402, 406, 407, 408, 409, +412, 413, 414, 415, 417, 418, 419, 422, 423, 424, 425, 427, 430, 432, 433, +435, 438, 444, 445, 446, 447, 448, 449, 451, 452, 454, 456, 458, 459, 462, +463, 466, 471, 472, 473, 474, 476, 479, 483, 484, 486, 487, 490, 492, 493, +495, 498, 500, 503, 506, 509, 511, 512, 517, 519, 525, 526, 528, 531, 532, +533, 534, 538, 539, 541, 542, 543, 544, 545, 546, 548, 549, 554, 555, 556, +557, 561, 562, 565, 568, 575, 578, 581, 584, 586, 589, 593, 596, 597, 600, +605, 609, 610, 612, 613, 618, 621, 624, 627, 628, 629, 631, 634, 636, 638, +639, 646, 648, 650, 652, 653, 658, 659, 660, 662, 664, 665, 672, 673, 674, +675, 676, 677, 679, 680, 686, 689, 690, 693, 694, 695, 698, 702, 705, 706, +707, 710, 711, 712, 713, 714, 715, 717, 721, 728, 731, 734, 737, 740, 741, +743, 744, 746, 748, 752, 755, 325, 326, 324, 15, 258, 103, 123, 3, 9, +124, 331, 14, 259, 16, 2, 8, 337, 102, 335, 340, 4, 10, 17, 120, +246, 247, 276, 333, 334, 33, 72, 128, 338, 5, 11, 76, 105, 127, 0, +13, 74, 73, 122, 1, 75, 7, 300, 336, 364, 6, 12, 228, 235, 263, +265, 270, 280, 291, 106, 297, 77, 135, 162, 169, 192, 199, 201, 214, 216, +225, 260, 262, 104, 306, 316, 339, 170, 200, 223, 341, 137, 160, 190, 203, +215, 218, 141, 150, 157, 171, 180, 187, 312, 313, 317, 39, 125, 143, 148, +158, 173, 178, 188, 308, 318, 107, 322, 362, 35, 91, 97, 109, 299, 230, +272, 293, 244, 256, 289, 323, 367, 38, 121, 302, 303, 311, 327, 245, 257, +261, 290, 305, 234, 264, 279, 34, 36, 79, 85, 115, 126, 298, 307, 309, +319, 328, 57, 63, 69, 198, 229, 271, 292, 82, 88, 90, 96, 108, 118, +304, 320, 329, 37, 41, 80, 86, 116, 301, 332, 139, 159, 164, 168, 189, +194, 205, 213, 217, 220, 222, 40, 136, 145, 167, 177, 197, 202, 212, 227, +18, 27, 48, 363, 237, 267, 282, 196, 240, 241, 252, 253, 285, 286, 142, +147, 152, 155, 156, 172, 175, 182, 185, 186, 310, 321, 330, 346, 347, 348, +355, 138, 163, 165, 193, 195, 204, 210, 219, 226, 131, 132, 208, 250, 251, +278, 314, 315, 357, 365, 140, 146, 179, 206, 211, 20, 29, 50, 161, 166, +191, 221, 224, 269, 368, 26, 44, 47, 58, 64, 70, 81, 87, 117, 144, +151, 153, 174, 181, 183, 93, 99, 111, 232, 274, 295, 59, 65, 71, 133, +134, 149, 154, 176, 184, 209, 350, 361, 239, 242, 254, 284, 287, 268, 56, +62, 68, 78, 84, 94, 100, 112, 114, 92, 98, 110, 238, 283, 55, 61, +67, 349, 236, 243, 255, 266, 281, 288, 19, 24, 28, 42, 45, 49, 129, +130, 207, 248, 249, 277, 354, 359, 360, 233, 275, 296, 352, 353, 22, 31, +52, 54, 60, 66, 83, 89, 95, 101, 113, 119, 342, 345, 366, 231, 273, +294, 25, 43, 46, 23, 32, 53, 343, 351, 358, 21, 30, 51, 344, 356, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, +30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, +45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, +60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, +75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, +90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, +105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, +120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, +135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, +150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, +165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, +180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, +195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, +210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, +225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, +240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, +255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, +270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, +285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, +300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, +315, 316, 317, 318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, +330, 331, 332, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, +345, 346, 347, 348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, +360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, +375, 376, 377, 19, 29, 33, 45, 86, 88, 90, 92, 18, 27, 31, 47, +82, 103, 37, 41, 55, 87, 11, 35, 39, 43, 49, 51, 53, 57, 61, +63, 89, 91, 105, 109, 114, 20, 9, 13, 107, 28, 30, 32, 34, 46, +48, 78, 84, 133, 135, 93, 112, 134, 136, 36, 40, 62, 66, 80, 38, +42, 44, 50, 52, 54, 56, 58, 64, 127, 131, 137, 1, 15, 16, 21, +22, 102, 111, 113, 128, 132, 138, 23, 25, 59, 68, 70, 94, 69, 3, +4, 6, 7, 10, 104, 106, 108, 110, 121, 123, 67, 24, 26, 60, 122, +124, 72, 76, 81, 96, 85, 74, 98, 129, 83, 125, 0, 2, 5, 8, +12, 14, 17, 71, 73, 75, 77, 79, 95, 97, 99, 100, 126, 65, 130, +101, 118, 116, 120, 115, 117, 119, 219, 220, 221, 127, 131, 135, 139, 228, +229, 230, 231, 232, 233, 234, 235, 222, 223, 224, 225, 226, 227, 236, 237, +238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, +253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, 265, 266, 275, +276, 277, 278, 9, 13, 17, 21, 25, 29, 36, 40, 44, 48, 49, 56, +60, 64, 68, 72, 76, 80, 84, 171, 176, 180, 184, 0, 1, 2, 3, +4, 5, 6, 7, 8, 10, 11, 12, 14, 15, 16, 18, 19, 20, 22, +23, 24, 26, 27, 28, 30, 31, 32, 33, 34, 35, 37, 38, 39, 41, +42, 43, 45, 46, 47, 50, 51, 52, 53, 54, 55, 57, 58, 59, 61, +62, 63, 65, 66, 67, 69, 70, 71, 73, 74, 75, 77, 78, 79, 81, +82, 83, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, +98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, +113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 128, +129, 130, 132, 133, 134, 136, 137, 138, 140, 141, 142, 143, 144, 145, 146, +147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, +162, 163, 164, 165, 166, 167, 168, 169, 170, 172, 173, 174, 175, 177, 178, +179, 181, 182, 183, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, +196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, +211, 212, 213, 214, 215, 216, 217, 218, 267, 268, 269, 270, 271, 272, 273, +274, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 1, 2, +3, 4, 0, 8, 12, 11, 102, 127, 6, 5, 101, 7, 128, 4, 3, +10, 1, 2, 0, 9, 92, 90, 97, 114, 94, 95, 99, 112, 111, 123, +116, 118, 120, 121, 125, 98, 89, 91, 96, 93, 100, 113, 24, 34, 16, +36, 14, 22, 13, 21, 33, 18, 26, 30, 115, 117, 124, 119, 122, 126, +17, 25, 29, 104, 19, 27, 31, 106, 28, 20, 32, 15, 23, 35, 54, +56, 110, 51, 72, 88, 38, 40, 49, 58, 60, 64, 66, 74, 81, 105, +107, 37, 39, 50, 52, 57, 59, 63, 65, 71, 73, 82, 87, 42, 43, +45, 48, 61, 67, 70, 76, 77, 79, 83, 86, 53, 55, 41, 44, 46, +47, 62, 68, 69, 75, 78, 80, 84, 85, 109, 103, 108, 7, 8, 6, +9, 17, 10, 28, 26, 24, 50, 68, 4, 34, 5, 0, 23, 46, 2, +18, 33, 1, 85, 19, 58, 62, 70, 29, 31, 35, 3, 25, 27, 47, +48, 49, 51, 11, 90, 30, 32, 36, 40, 41, 42, 43, 44, 45, 12, +13, 14, 15, 16, 20, 21, 22, 37, 38, 39, 52, 53, 54, 55, 56, +57, 59, 60, 61, 63, 64, 65, 66, 67, 69, 71, 72, 73, 74, 75, +76, 77, 78, 79, 80, 81, 82, 83, 84, 86, 87, 88, 89, 88, 125, +101, 103, 124, 127, 134, 135, 25, 29, 37, 45, 165, 177, 163, 180, 138, +142, 113, 24, 28, 36, 40, 41, 44, 48, 49, 58, 59, 60, 61, 66, +67, 68, 69, 70, 71, 72, 73, 89, 92, 93, 145, 148, 149, 94, 105, +109, 151, 154, 161, 173, 96, 99, 100, 102, 104, 107, 108, 111, 114, 115, +116, 118, 119, 120, 122, 123, 126, 132, 133, 136, 137, 140, 141, 155, 156, +159, 160, 164, 169, 171, 172, 175, 176, 179, 181, 182, 183, 0, 1, 2, +3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, +18, 19, 20, 21, 22, 23, 26, 27, 30, 31, 32, 33, 34, 35, 38, +39, 42, 43, 46, 47, 50, 51, 52, 53, 54, 55, 56, 57, 62, 63, +64, 65, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, +87, 90, 91, 95, 97, 98, 106, 110, 112, 117, 121, 128, 129, 130, 131, +139, 143, 144, 146, 147, 150, 152, 153, 157, 158, 162, 166, 167, 168, 170, +174, 178, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 0, 1, 2, 3, +4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, +34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, +49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, +64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, +79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, +94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, +109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, +124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, +139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, +154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, +169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, +184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, +199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, +214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, +229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, +244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, +259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, +274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, +289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, +304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, +319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, +334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, +349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, +364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, +379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, +394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, +409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, +424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, +439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, +454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, +469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, +484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, +499, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, +514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, +529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, +544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, +559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, +574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, +589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, +604, 605, 606, 607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, +619, 620, 621, 622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, +634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, +649, 650, 651, 652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, +664, 665, 666, 667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, +679, 680, 681, 682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, +694, 695, 696, 697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, +709, 710, 711, 712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, +724, 725, 726, 727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, +739, 740, 741, 742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, +754, 755, 756, 757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, +769, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, +784, 785, 786, 787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, +799, 800, 801, 802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, +814, 815, 816, 817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, +829, 830, 831, 832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, +844, 845, 846, 847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, +859, 860, 861, 862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, +874, 875, 876, 877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, +889, 890, 891, 892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, +904, 905, 906, 907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, +919, 920, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, +934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, +949, 950, 951, 952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, +964, 965, 966, 967, 968, 969, 970, 971, 306, 146, 158, 174, 216, 233, 27, +29, 121, 123, 125, 127, 144, 150, 152, 173, 188, 218, 295, 299, 307, 0, +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 28, 30, 31, 32, +33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, +78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, +93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, +108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 122, 124, +126, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, +142, 143, 145, 147, 148, 149, 151, 153, 154, 155, 156, 157, 159, 160, 161, +162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 175, 176, 177, 178, +179, 180, 181, 182, 183, 184, 185, 186, 187, 189, 190, 191, 192, 193, 194, +195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, +210, 211, 212, 213, 214, 215, 217, 219, 220, 221, 222, 223, 224, 225, 226, +227, 228, 229, 230, 231, 232, 234, 235, 236, 237, 238, 239, 240, 241, 242, +243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, +258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, +273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, +288, 289, 290, 291, 292, 293, 294, 296, 297, 298, 300, 301, 302, 303, 304, +305, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, +322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, +337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, +352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, +367, 368, 369, 370, 371, 372, 373, 374, 76, 106, 77, 107, 125, 115, 126, +60, 61, 71, 59, 96, 99, 110, 89, 70, 58, 25, 27, 33, 35, 86, +87, 72, 75, 79, 94, 112, 95, 100, 73, 74, 78, 101, 102, 105, 109, +88, 26, 32, 34, 103, 104, 108, 24, 97, 98, 113, 114, 44, 64, 69, +36, 38, 41, 43, 47, 54, 57, 63, 66, 111, 37, 39, 40, 42, 45, +46, 55, 56, 62, 65, 67, 68, 90, 92, 5, 11, 9, 84, 8, 4, +10, 2, 48, 50, 52, 81, 82, 0, 6, 12, 14, 85, 80, 83, 49, +51, 53, 91, 93, 118, 121, 124, 3, 17, 18, 21, 22, 29, 30, 1, +7, 13, 15, 116, 119, 122, 129, 16, 19, 20, 23, 28, 31, 117, 120, +123, 127, 128, 130, 3, 4, 5, 6, 25, 26, 27, 28, 29, 33, 41, +54, 61, 62, 99, 101, 105, 106, 107, 108, 133, 134, 0, 7, 30, 83, +86, 87, 88, 90, 91, 92, 93, 135, 136, 137, 1, 2, 31, 32, 34, +100, 102, 103, 104, 119, 132, 138, 139, 140, 16, 21, 22, 23, 24, 44, +51, 64, 65, 66, 67, 69, 71, 72, 73, 74, 75, 76, 8, 9, 10, +11, 12, 13, 14, 15, 35, 36, 42, 43, 46, 48, 49, 50, 52, 60, +63, 77, 78, 79, 80, 81, 82, 85, 89, 94, 95, 96, 97, 98, 109, +110, 111, 112, 113, 114, 115, 120, 121, 17, 18, 19, 20, 37, 38, 39, +40, 45, 47, 53, 55, 56, 57, 58, 59, 68, 70, 84, 116, 117, 118, +122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 141, 142, 143, 144, 145, +146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, +161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, +176, 177, 178, 179, 180, 181, 182, 49, 18, 16, 17, 42, 45, 15, 8, +46, 39, 6, 48, 7, 9, 10, 41, 44, 5, 40, 43, 30, 47, 51, +52, 25, 19, 20, 21, 22, 23, 24, 3, 4, 29, 31, 32, 33, 34, +35, 36, 37, 38, 71, 73, 11, 12, 13, 14, 50, 70, 0, 1, 2, +26, 27, 28, 60, 62, 69, 61, 63, 64, 65, 72, 75, 76, 54, 55, +56, 57, 58, 59, 66, 68, 81, 82, 83, 84, 86, 74, 53, 67, 77, +78, 79, 80, 85, 87, 88, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, +84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, +99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, +114, 115, 116, 117, 118, 119, 120, 121, 122, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +21, 100, 31, 35, 41, 33, 30, 34, 40, 82, 81, 103, 47, 32, 15, +99, 46, 9, 21, 8, 69, 65, 67, 14, 62, 57, 58, 60, 80, 56, +20, 11, 97, 10, 85, 86, 1, 22, 26, 36, 16, 17, 78, 79, 105, +108, 5, 24, 28, 38, 44, 45, 59, 61, 63, 70, 109, 111, 0, 4, +25, 29, 39, 50, 51, 54, 55, 71, 72, 73, 74, 75, 76, 77, 95, +96, 101, 102, 104, 110, 98, 18, 19, 83, 84, 89, 23, 27, 37, 42, +43, 48, 113, 2, 3, 6, 7, 12, 13, 49, 52, 53, 87, 88, 90, +91, 92, 93, 94, 106, 107, 112, 64, 66, 68, 5, 4, 0, 39, 48, +17, 8, 6, 7, 77, 78, 75, 76, 79, 80, 16, 15, 73, 56, 55, +74, 40, 41, 42, 60, 9, 10, 11, 12, 13, 14, 59, 43, 62, 1, +2, 3, 44, 61, 58, 68, 22, 23, 28, 35, 36, 45, 46, 47, 57, +67, 69, 70, 71, 19, 18, 20, 21, 24, 25, 26, 27, 29, 30, 31, +32, 33, 34, 37, 38, 49, 50, 51, 52, 53, 54, 63, 64, 65, 66, +72, 81, 82, 83, 84, 34, 44, 71, 32, 43, 30, 35, 72, 33, 11, +10, 39, 37, 13, 38, 42, 36, 12, 41, 31, 8, 9, 40, 50, 69, +55, 20, 24, 28, 135, 1, 5, 15, 136, 70, 46, 51, 114, 115, 45, +3, 7, 17, 113, 116, 54, 128, 129, 134, 138, 0, 4, 14, 26, 19, +23, 27, 48, 62, 63, 68, 123, 124, 125, 126, 131, 132, 29, 49, 59, +60, 66, 127, 130, 133, 86, 110, 119, 57, 58, 65, 83, 87, 103, 111, +122, 18, 22, 82, 102, 61, 64, 67, 21, 25, 52, 2, 6, 16, 75, +76, 85, 90, 95, 99, 100, 109, 120, 56, 73, 74, 77, 78, 79, 80, +81, 84, 88, 89, 91, 92, 93, 94, 96, 97, 98, 101, 104, 105, 106, +107, 108, 112, 117, 118, 121, 137, 47, 53, 4, 5, 0, 1, 2, 3, +7, 8, 6, 9, 10, 20, 25, 27, 18, 19, 21, 23, 24, 26, 28, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 22, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 76, 96, 112, 109, 110, 94, 95, 49, 73, 56, 61, 65, 68, +102, 30, 37, 38, 40, 41, 44, 45, 47, 48, 55, 57, 59, 60, 79, +82, 88, 89, 90, 91, 92, 98, 100, 105, 108, 111, 0, 1, 2, 3, +4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, +35, 36, 39, 42, 43, 46, 50, 51, 52, 53, 54, 58, 62, 63, 64, +66, 67, 69, 70, 71, 72, 74, 75, 77, 78, 80, 81, 83, 84, 85, +86, 87, 93, 97, 99, 101, 103, 104, 106, 107, 113, 91, 42, 46, 77, +26, 8, 78, 41, 43, 44, 47, 68, 5, 30, 45, 89, 90, 48, 49, +50, 51, 25, 76, 93, 14, 70, 88, 4, 23, 24, 29, 59, 63, 75, +79, 92, 97, 0, 1, 2, 6, 7, 15, 16, 17, 20, 21, 27, 31, +32, 33, 34, 35, 36, 62, 64, 67, 72, 61, 66, 71, 86, 94, 12, +74, 55, 58, 60, 81, 83, 3, 9, 10, 11, 13, 18, 19, 22, 28, +37, 38, 39, 40, 53, 56, 65, 69, 73, 82, 84, 85, 52, 54, 57, +80, 87, 95, 96, 1, 8, 10, 13, 12, 6, 2, 0, 11, 9, 5, +25, 7, 19, 43, 44, 45, 32, 33, 34, 50, 51, 52, 26, 22, 23, +3, 4, 28, 15, 36, 37, 49, 30, 31, 29, 14, 20, 21, 24, 27, +17, 39, 46, 16, 35, 53, 38, 40, 41, 42, 18, 47, 48, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, +77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, +92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, +107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, +122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 49, 310, 312, +314, 269, 271, 273, 275, 277, 279, 281, 297, 299, 0, 1, 2, 3, 4, +5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, +20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 50, +51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, +66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, +81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, +96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, +111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, +126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, +141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, +156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, +171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, +186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, +201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, +216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, +231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, +246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, +261, 262, 263, 264, 265, 266, 267, 268, 270, 272, 274, 276, 278, 280, 282, +283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, 295, 296, 298, +300, 301, 302, 303, 304, 305, 306, 307, 308, 309, 311, 313, 315, 316, 317, +318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, +333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, +348, 349, 350, 351, 352, 353, 354, 355, 179, 200, 161, 175, 243, 100, 104, +196, 198, 223, 227, 176, 203, 212, 215, 162, 163, 247, 160, 174, 216, 218, +158, 172, 96, 157, 166, 170, 197, 199, 217, 219, 159, 173, 178, 201, 99, +101, 103, 105, 177, 202, 213, 214, 98, 102, 92, 108, 112, 116, 120, 124, +128, 132, 184, 192, 208, 180, 188, 204, 239, 249, 221, 225, 154, 165, 169, +51, 53, 55, 57, 59, 63, 67, 71, 75, 79, 83, 87, 95, 119, 123, +127, 131, 138, 142, 146, 150, 183, 191, 207, 236, 241, 245, 250, 61, 65, +69, 73, 77, 81, 85, 89, 93, 109, 113, 117, 140, 144, 148, 152, 8, +9, 14, 15, 20, 21, 50, 52, 54, 56, 91, 107, 111, 115, 121, 125, +129, 133, 134, 135, 136, 137, 141, 145, 149, 153, 155, 164, 168, 181, 187, +189, 195, 205, 211, 58, 62, 66, 70, 74, 78, 82, 86, 118, 122, 126, +130, 0, 1, 2, 3, 4, 5, 6, 7, 10, 11, 12, 13, 16, 17, +18, 19, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, +60, 64, 68, 72, 76, 80, 84, 88, 139, 143, 147, 151, 186, 194, 210, +222, 226, 238, 242, 246, 248, 94, 97, 156, 167, 171, 228, 230, 90, 106, +110, 114, 220, 224, 237, 240, 244, 251, 182, 185, 190, 193, 206, 209, 229, +231, 232, 233, 234, 235, 24, 51, 54, 111, 25, 52, 55, 112, 13, 31, +34, 37, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 26, 27, 28, 29, 30, +32, 33, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, +49, 50, 53, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, +83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, +98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 113, 114, +115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, +130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 0, +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 8, 16, 18, 7, 26, 30, 34, 104, 14, 15, 17, 19, 22, +48, 68, 73, 75, 79, 11, 1, 6, 20, 28, 32, 36, 38, 40, 44, +98, 102, 103, 105, 106, 115, 2, 13, 21, 23, 49, 53, 54, 55, 56, +57, 58, 60, 61, 64, 66, 67, 69, 76, 83, 85, 95, 100, 10, 0, +3, 4, 5, 9, 12, 24, 25, 27, 29, 31, 33, 35, 37, 39, 41, +42, 43, 45, 46, 47, 50, 51, 52, 59, 62, 63, 65, 70, 71, 72, +74, 77, 78, 80, 81, 82, 84, 86, 87, 88, 89, 90, 91, 92, 93, +94, 96, 97, 99, 101, 107, 108, 109, 110, 111, 112, 113, 114, 116, 117, +118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 121, 120, 103, 101, 102, +86, 111, 124, 27, 44, 100, 10, 13, 82, 92, 98, 78, 88, 94, 42, +40, 9, 11, 12, 14, 80, 84, 90, 96, 45, 119, 122, 46, 48, 50, +52, 104, 106, 109, 110, 1, 4, 18, 25, 29, 32, 19, 34, 22, 5, +8, 38, 107, 39, 16, 17, 21, 26, 30, 33, 43, 87, 125, 41, 83, +93, 99, 2, 24, 28, 31, 35, 53, 55, 81, 91, 97, 105, 0, 3, +7, 6, 15, 20, 23, 36, 37, 47, 49, 51, 54, 56, 57, 58, 59, +60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, +75, 76, 77, 79, 85, 89, 95, 108, 112, 113, 114, 115, 116, 117, 118, +123, 161, 57, 60, 95, 169, 165, 171, 0, 160, 40, 168, 164, 39, 58, +59, 96, 1, 2, 50, 55, 64, 75, 85, 92, 97, 71, 77, 81, 87, +6, 16, 30, 44, 181, 170, 49, 56, 63, 76, 86, 91, 98, 174, 180, +5, 15, 29, 43, 72, 78, 82, 88, 113, 126, 194, 195, 198, 158, 159, +162, 163, 114, 125, 144, 145, 166, 167, 192, 193, 156, 47, 48, 51, 52, +53, 54, 61, 62, 65, 66, 83, 84, 89, 90, 93, 94, 99, 100, 101, +102, 103, 104, 130, 131, 132, 133, 134, 135, 152, 175, 176, 177, 67, 69, +73, 79, 105, 3, 4, 7, 8, 13, 14, 17, 18, 19, 20, 25, 26, +27, 28, 31, 32, 33, 34, 37, 38, 41, 42, 45, 46, 68, 70, 74, +80, 106, 117, 118, 142, 143, 178, 179, 138, 9, 140, 147, 148, 107, 109, +111, 139, 141, 146, 149, 182, 183, 184, 185, 190, 191, 115, 119, 121, 123, +137, 155, 157, 187, 189, 197, 10, 11, 12, 21, 22, 23, 24, 35, 36, +108, 110, 112, 116, 120, 122, 124, 127, 128, 129, 136, 150, 151, 153, 154, +173, 186, 188, 196, 172, 37, 36, 33, 32, 35, 34, 4, 2, 6, 0, +44, 45, 47, 46, 42, 43, 39, 41, 40, 38, 5, 7, 3, 1, 51, +17, 11, 15, 19, 9, 13, 10, 14, 18, 16, 23, 24, 27, 28, 31, +8, 12, 20, 22, 21, 25, 26, 29, 30, 49, 48, 50, 179, 176, 165, +178, 171, 175, 174, 177, 162, 168, 190, 188, 202, 200, 33, 75, 93, 51, +81, 87, 173, 164, 157, 114, 3, 6, 156, 15, 21, 27, 170, 167, 123, +63, 69, 39, 45, 57, 199, 211, 172, 208, 205, 214, 181, 184, 203, 196, +169, 198, 201, 160, 161, 137, 163, 125, 209, 119, 183, 215, 166, 207, 204, +213, 197, 191, 206, 210, 182, 212, 187, 185, 53, 83, 89, 192, 186, 193, +136, 180, 194, 130, 142, 154, 155, 148, 149, 131, 143, 116, 32, 74, 92, +122, 101, 107, 110, 113, 98, 104, 71, 65, 41, 47, 59, 2, 11, 14, +20, 26, 195, 189, 147, 150, 151, 145, 133, 127, 139, 126, 138, 132, 144, +117, 159, 52, 82, 88, 158, 120, 96, 102, 108, 99, 105, 111, 30, 72, +90, 8, 5, 9, 0, 124, 97, 103, 109, 12, 18, 24, 48, 78, 84, +66, 60, 70, 62, 35, 77, 95, 68, 42, 50, 80, 86, 17, 23, 29, +36, 54, 38, 44, 56, 152, 153, 64, 40, 58, 46, 128, 140, 129, 134, +135, 141, 146, 106, 100, 112, 121, 7, 4, 115, 118, 34, 61, 76, 94, +16, 22, 28, 37, 43, 55, 49, 79, 85, 67, 1, 13, 19, 25, 31, +73, 91, 10, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, +27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, +42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, +57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, +87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, +102, 103, 104, 105, 106, 107, 108, 109, 110, 2, 5, 8, 11, 14, 17, +20, 23, 26, 29, 32, 35, 38, 41, 44, 47, 50, 53, 56, 59, 62, +65, 68, 0, 1, 3, 4, 6, 7, 9, 10, 12, 13, 15, 16, 18, +19, 21, 22, 24, 25, 27, 28, 30, 31, 33, 34, 36, 37, 39, 40, +42, 43, 45, 46, 48, 49, 51, 52, 54, 55, 57, 58, 60, 61, 63, +64, 66, 67, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +53, 52, 72, 71, 73, 70, 97, 98, 96, 99, 68, 80, 82, 74, 77, +78, 5, 22, 25, 41, 49, 1, 9, 17, 95, 103, 102, 104, 75, 76, +79, 66, 69, 93, 67, 94, 81, 83, 84, 85, 86, 87, 88, 89, 90, +91, 106, 107, 92, 100, 101, 105, 32, 34, 38, 12, 15, 54, 58, 62, +39, 14, 36, 57, 61, 65, 31, 35, 47, 29, 45, 42, 28, 44, 30, +46, 18, 16, 55, 59, 63, 40, 21, 26, 50, 3, 7, 11, 19, 0, +4, 8, 33, 37, 20, 23, 24, 27, 43, 48, 51, 2, 6, 10, 13, +56, 60, 64, 0, 2, 1, 11, 5, 6, 12, 3, 4, 9, 10, 14, +7, 8, 13, 21, 36, 18, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 37, 15, 16, 22, 17, 19, 20, 0, 1, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 48, 5, 34, 63, +4, 62, 50, 47, 49, 33, 35, 36, 29, 3, 6, 61, 64, 54, 58, +45, 32, 51, 56, 60, 70, 57, 40, 46, 11, 55, 59, 44, 53, 65, +72, 14, 15, 17, 20, 22, 27, 66, 68, 69, 71, 26, 19, 67, 1, +9, 12, 7, 25, 24, 28, 30, 31, 10, 8, 16, 18, 21, 23, 52, +0, 2, 41, 42, 43, 13, 37, 38, 39, 107, 15, 97, 100, 101, 105, +99, 33, 81, 79, 80, 34, 92, 95, 86, 48, 118, 41, 43, 119, 35, +36, 37, 75, 102, 103, 104, 23, 24, 25, 26, 31, 4, 17, 19, 21, +22, 27, 38, 39, 52, 56, 58, 64, 70, 72, 82, 47, 87, 51, 55, +57, 77, 78, 98, 116, 117, 28, 29, 30, 32, 40, 42, 5, 7, 9, +93, 96, 1, 2, 3, 6, 8, 10, 12, 54, 59, 65, 66, 68, 69, +71, 73, 74, 76, 83, 84, 89, 90, 106, 109, 111, 112, 114, 44, 45, +46, 49, 50, 11, 53, 16, 18, 20, 0, 13, 14, 60, 61, 62, 63, +67, 85, 88, 91, 94, 108, 110, 113, 115, 13, 4, 46, 47, 2, 6, +37, 38, 43, 51, 54, 55, 58, 67, 69, 0, 1, 3, 5, 7, 8, +9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 39, 40, 41, +42, 44, 45, 48, 49, 50, 52, 53, 56, 57, 59, 60, 61, 62, 63, +64, 65, 66, 68, 70, 71, 72, 73, 74, 75, 7, 4, 6, 5, 2, +3, 9, 8, 0, 1, 23, 22, 24, 25, 14, 26, 30, 34, 10, 11, +12, 13, 15, 16, 17, 18, 19, 20, 21, 27, 28, 29, 31, 32, 33, +35, 36, 37, 0, 1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, +55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, +70, 71, 72, 73, 0, 1, 2, 3, 4, 4, 0, 1, 2, 3, 5, +6, 7, 8, 0, 1, 2, 3, 4, 5, 323, 139, 149, 165, 207, 234, +320, 296, 300, 20, 44, 45, 52, 138, 147, 189, 191, 192, 193, 210, 213, +215, 217, 226, 232, 236, 238, 293, 322, 325, 74, 122, 306, 150, 264, 4, +5, 197, 201, 117, 172, 188, 195, 203, 222, 244, 245, 265, 271, 291, 292, +332, 2, 18, 19, 22, 34, 46, 57, 82, 84, 85, 88, 89, 120, 130, +133, 134, 136, 137, 140, 142, 143, 145, 146, 148, 153, 159, 160, 161, 162, +166, 169, 173, 184, 185, 209, 211, 219, 228, 229, 231, 237, 240, 242, 243, +246, 247, 248, 251, 253, 254, 257, 286, 294, 298, 324, 335, 33, 98, 118, +200, 204, 303, 305, 327, 100, 196, 205, 275, 123, 126, 282, 0, 1, 3, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 21, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 35, 36, 37, 38, 39, 40, 41, +42, 43, 47, 48, 49, 50, 51, 53, 54, 55, 56, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 75, 76, 77, +78, 79, 80, 81, 83, 86, 87, 90, 91, 92, 93, 94, 95, 96, 97, +99, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, +115, 116, 119, 121, 124, 125, 127, 128, 129, 131, 132, 135, 141, 144, 151, +152, 154, 155, 156, 157, 158, 163, 164, 167, 168, 170, 171, 174, 175, 176, +177, 178, 179, 180, 181, 182, 183, 186, 187, 190, 194, 198, 199, 202, 206, +208, 212, 214, 216, 218, 220, 221, 223, 224, 225, 227, 230, 233, 235, 239, +241, 249, 250, 252, 255, 256, 258, 259, 260, 261, 262, 263, 266, 267, 268, +269, 270, 272, 273, 274, 276, 277, 278, 279, 280, 281, 283, 284, 285, 287, +288, 289, 290, 295, 297, 299, 301, 302, 304, 307, 308, 309, 310, 311, 312, +313, 314, 315, 316, 317, 318, 319, 321, 326, 328, 329, 330, 331, 333, 334, +336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, +351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, +77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, +92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, +107, 108, 109, 4, 5, 18, 20, 0, 1, 2, 3, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 19, 21, 22, 23, 24, 25, 26, +0, 1, 2, 3, 4, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, +55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, +70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, +85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, +100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, +115, 116, 117, 118, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, +11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, +26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, +41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, +56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, +71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, +86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, +101, 102, 103, 104, 105, 106, 107, 38, 40, 39, 65, 63, 66, 26, 28, +11, 20, 24, 32, 108, 8, 47, 45, 48, 49, 105, 109, 139, 75, 124, +18, 22, 30, 34, 111, 102, 114, 118, 77, 123, 133, 1, 5, 17, 46, +69, 73, 81, 29, 78, 101, 37, 50, 64, 9, 51, 55, 61, 76, 68, +72, 84, 2, 6, 14, 19, 23, 35, 67, 71, 79, 83, 107, 113, 115, +117, 137, 147, 36, 10, 27, 53, 57, 59, 135, 13, 103, 104, 126, 3, +7, 15, 41, 44, 54, 58, 60, 70, 74, 80, 82, 0, 4, 12, 16, +21, 25, 31, 33, 42, 43, 52, 56, 62, 85, 88, 91, 94, 106, 110, +112, 116, 119, 120, 121, 122, 125, 127, 128, 129, 130, 131, 132, 134, 136, +138, 140, 141, 142, 143, 144, 145, 146, 148, 89, 86, 87, 90, 92, 93, +95, 96, 97, 98, 99, 100, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 1, 2, 4, 32, 36, 38, 3, 34, 28, 31, 35, +37, 6, 12, 14, 19, 20, 22, 33, 39, 43, 53, 54, 55, 56, 57, +61, 67, 69, 70, 71, 30, 0, 5, 7, 8, 9, 10, 11, 13, 15, +16, 17, 18, 21, 23, 24, 25, 26, 27, 29, 40, 41, 42, 44, 45, +46, 47, 48, 49, 50, 51, 52, 58, 59, 60, 62, 63, 64, 65, 66, +68, 72, 16, 28, 34, 38, 42, 2, 14, 15, 18, 19, 26, 29, 30, +31, 32, 33, 40, 43, 0, 1, 3, 4, 5, 6, 7, 8, 9, 10, +11, 12, 13, 17, 20, 21, 22, 23, 24, 25, 27, 35, 36, 37, 39, +41, 2, 0, 7, 1, 86, 5, 74, 21, 89, 85, 88, 3, 4, 6, +51, 23, 111, 70, 56, 90, 98, 27, 78, 53, 68, 80, 87, 116, 12, +25, 109, 114, 103, 108, 110, 9, 57, 62, 65, 91, 96, 99, 69, 71, +72, 73, 81, 49, 50, 52, 93, 101, 36, 55, 64, 125, 19, 20, 22, +106, 41, 8, 11, 13, 29, 34, 37, 54, 102, 107, 118, 123, 126, 14, +15, 16, 18, 82, 83, 84, 92, 97, 100, 104, 112, 17, 32, 121, 94, +24, 113, 76, 77, 79, 10, 61, 95, 26, 28, 30, 31, 35, 38, 39, +40, 46, 58, 59, 60, 63, 66, 67, 75, 105, 115, 117, 119, 120, 124, +127, 128, 33, 42, 43, 44, 45, 47, 48, 122, 0, 1, 2, 3, 4, +5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, +20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 2, 0, 1, 3, 4, +5, 6, 7, 8, 82, 11, 26, 19, 75, 6, 9, 47, 54, 66, 73, +80, 87, 0, 3, 4, 5, 18, 23, 24, 25, 44, 53, 62, 63, 65, +67, 68, 69, 70, 72, 76, 77, 86, 88, 89, 90, 91, 92, 93, 22, +10, 15, 21, 49, 58, 50, 59, 83, 1, 2, 7, 8, 12, 13, 14, +16, 17, 20, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 45, 46, 48, 51, 52, 55, 56, 57, 60, 61, +64, 71, 74, 78, 79, 81, 84, 85, 0, 1, 0, 1, 34, 2, 12, +13, 32, 37, 76, 3, 10, 11, 19, 20, 21, 22, 23, 27, 28, 29, +30, 35, 53, 55, 78, 4, 16, 17, 5, 6, 7, 8, 9, 14, 15, +18, 24, 25, 26, 31, 33, 36, 38, 39, 40, 41, 42, 43, 44, 45, +46, 47, 48, 49, 50, 51, 52, 54, 56, 57, 58, 59, 60, 61, 62, +63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 77, 79, +80, 81, 82, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +12, 13, 14, 15, 5, 30, 31, 0, 1, 2, 3, 4, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 32, 33, 34, 35, 36, 37, 59, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 60, 61, 62, 63, +64, 65, 36, 61, 20, 1, 19, 126, 127, 60, 56, 33, 34, 35, 21, +22, 52, 59, 67, 71, 72, 63, 65, 66, 32, 45, 57, 84, 91, 114, +125, 64, 0, 2, 3, 68, 70, 73, 26, 46, 53, 54, 55, 58, 115, +131, 74, 12, 96, 97, 99, 41, 42, 44, 49, 50, 75, 80, 83, 85, +103, 106, 107, 108, 109, 110, 111, 112, 113, 116, 117, 118, 119, 120, 124, +13, 62, 76, 77, 78, 86, 128, 129, 94, 23, 24, 25, 27, 28, 29, +30, 31, 37, 38, 39, 40, 43, 47, 48, 51, 4, 5, 6, 7, 8, +9, 10, 11, 14, 15, 16, 17, 18, 69, 79, 81, 82, 87, 88, 89, +90, 92, 93, 95, 98, 100, 101, 102, 104, 105, 121, 122, 123, 130, 132, +3, 2, 10, 11, 1, 4, 6, 8, 5, 7, 9, 0, 31, 30, 15, +43, 49, 53, 57, 45, 12, 13, 16, 18, 32, 34, 36, 14, 33, 35, +37, 21, 23, 17, 19, 20, 22, 24, 25, 26, 27, 28, 29, 42, 48, +52, 56, 38, 41, 44, 46, 50, 54, 39, 40, 47, 51, 55, 35, 36, +3, 5, 7, 9, 11, 2, 17, 30, 34, 14, 20, 23, 4, 6, 13, +16, 18, 19, 22, 24, 25, 31, 32, 33, 8, 10, 12, 15, 21, 0, +1, 26, 27, 28, 29, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 42, 43, 44, 45, 46, 47, 5, 4, 6, 21, 0, 3, 18, +16, 15, 17, 9, 12, 20, 7, 14, 19, 8, 10, 11, 13, 1, 2, +167, 168, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, +43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, +58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, +73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, +88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, +103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, +118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, +133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, +148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, +163, 164, 165, 166, 0, 1, 2, 3, 4, 5, 6, 7, 8, 0, 1, +2, 3, 7, 6, 8, 9, 16, 2, 18, 19, 28, 27, 24, 25, 26, +17, 3, 20, 22, 21, 23, 13, 0, 4, 14, 1, 5, 12, 10, 11, +15, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 12, 13, +14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 18, 22, 28, 35, 53, 54, 57, 59, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 19, 20, 21, 23, 24, 25, 26, 27, 29, 30, 31, 32, 33, 34, +36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, +51, 52, 55, 56, 58, 9, 13, 4, 6, 11, 15, 8, 12, 5, 7, +10, 14, 2, 3, 0, 1, 0, 3, 4, 7, 1, 2, 5, 6, 8, +9, 10, 0, 1, 2, 65, 64, 66, 52, 46, 49, 53, 59, 44, 48, +45, 57, 34, 25, 26, 27, 36, 56, 24, 43, 47, 0, 1, 2, 3, +4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 28, 29, 30, 31, 32, 33, 35, 37, 38, 39, +40, 41, 42, 50, 51, 54, 55, 58, 60, 61, 62, 63, 0, 1, 2, +3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, +18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, +33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, +78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, +93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, +108, 109, 110, 111, 112, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 42, 43, 44, 45, 46, 47, 48, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +21, 22, 23, 24, 25, 26, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, +84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, +99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, +114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, +129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, +144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, +159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, +174, 175, 84, 86, 5, 16, 18, 21, 81, 82, 3, 6, 10, 12, 14, +22, 24, 26, 29, 39, 41, 42, 54, 56, 58, 60, 62, 75, 0, 1, +2, 4, 7, 8, 9, 11, 13, 15, 17, 19, 20, 23, 25, 27, 28, +30, 31, 32, 33, 34, 35, 36, 37, 38, 40, 43, 44, 45, 46, 47, +48, 49, 50, 51, 52, 53, 55, 57, 59, 61, 63, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 76, 77, 78, 79, 80, 83, 85, 0, +2, 4, 6, 14, 16, 18, 20, 8, 31, 10, 11, 24, 25, 28, 29, +32, 33, 36, 38, 40, 41, 44, 45, 9, 30, 1, 3, 5, 7, 12, +13, 15, 17, 19, 21, 22, 23, 26, 27, 34, 35, 37, 39, 42, 43, +46, 47, 27, 28, 35, 36, 45, 46, 13, 14, 59, 60, 0, 1, 2, +3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 15, 16, 17, 18, 19, +20, 21, 22, 23, 24, 25, 26, 29, 30, 31, 32, 33, 34, 37, 38, +39, 40, 41, 42, 43, 44, 47, 48, 49, 50, 51, 52, 53, 54, 55, +56, 57, 58, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, +73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, +88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, +103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, +118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, +133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, +148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, +163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, +178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, +193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, +208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, +223, 224, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 0, 4, 1, 2, 3, 7, 5, 9, 6, 8, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, +30, 31, 32, 33, 34, 35, 36, 37, 8, 11, 9, 10, 0, 1, 4, +5, 2, 3, 6, 7, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, +27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, +42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, +57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, +72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, +87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, +102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, +117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, +132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, +147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, +162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, +177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, +192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, 205, 206, +207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, 220, 221, +222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, 235, 236, +237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, 250, 251, +252, 253, 254, 255, 256, 257, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +35, 1, 2, 20, 29, 32, 33, 34, 0, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23, 24, +25, 26, 27, 28, 30, 31, 36, 37, 38, 39, 40, 41, 42, 43, 44, +45, 46, 47, 48, 49, 50, 51, 52, 53, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, +36, 37, 38, 39, 40, 0, 1, 0, 1, 2, 3, 4, 5, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, +77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, +92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, +107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, +122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, +137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, +152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, +167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, +182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, +197, 198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, +212, 213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, +227, 228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, +242, 243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, +257, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, +14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, +29, 0, 1, 4, 27, 19, 21, 5, 18, 6, 8, 10, 11, 12, 14, +15, 16, 17, 20, 0, 1, 2, 3, 7, 9, 13, 22, 23, 24, 25, +26, 28, 29, 30, 31, 32, 33, 34, 35, 0, 1, 2, 3, 4, 0, +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 18, 19, 112, 110, 113, 111, 29, 37, 18, 93, 96, 97, 99, +98, 92, 100, 104, 105, 108, 101, 61, 62, 69, 77, 86, 70, 78, 85, +68, 76, 87, 60, 54, 55, 59, 30, 38, 73, 81, 90, 94, 19, 14, +16, 71, 79, 84, 50, 51, 57, 0, 2, 4, 6, 8, 10, 12, 20, +26, 34, 44, 64, 72, 80, 91, 40, 63, 13, 5, 7, 9, 11, 15, +1, 3, 39, 21, 48, 49, 56, 95, 74, 82, 89, 31, 25, 33, 45, +65, 43, 103, 106, 107, 109, 17, 52, 53, 58, 28, 36, 41, 23, 27, +35, 47, 42, 66, 22, 24, 32, 46, 67, 75, 83, 88, 102, 6, 7, +0, 1, 3, 5, 2, 4, 50, 48, 52, 54, 56, 2, 6, 14, 18, +22, 26, 30, 34, 49, 53, 55, 57, 58, 59, 60, 0, 1, 3, 4, +5, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 19, 20, 21, 23, +24, 25, 27, 28, 29, 31, 32, 33, 35, 36, 37, 38, 39, 40, 41, +42, 43, 44, 45, 46, 47, 51, 23, 24, 25, 26, 16, 18, 20, 22, +15, 17, 19, 21, 6, 8, 10, 12, 14, 0, 2, 1, 3, 4, 5, +11, 7, 9, 13, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, +11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, +26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, +41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, +56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, +71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, +86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, +101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, +116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, +131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 1, 0, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 0, 1, 2, 112, 114, 19, 61, 70, +18, 111, 3, 5, 6, 66, 82, 109, 110, 113, 58, 102, 104, 31, 35, +36, 37, 38, 71, 77, 86, 93, 95, 96, 108, 47, 25, 45, 46, 53, +55, 75, 40, 41, 42, 52, 60, 83, 84, 24, 26, 11, 12, 22, 23, +28, 30, 57, 63, 65, 69, 81, 90, 106, 32, 33, 34, 49, 50, 51, +72, 73, 78, 79, 87, 88, 94, 4, 7, 8, 9, 10, 20, 21, 29, +39, 43, 44, 48, 54, 56, 59, 62, 64, 67, 68, 74, 76, 80, 89, +91, 92, 100, 101, 115, 116, 16, 99, 13, 14, 15, 17, 27, 85, 97, +98, 103, 105, 107, 117, 7, 10, 19, 0, 1, 2, 3, 4, 5, 6, +8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 0, 1, 2, 3, 4, +5, 7, 17, 0, 1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, +13, 14, 15, 16, 18, 19, 20, 21, 22, 23, 0, 1, 0, 7, 11, +5, 6, 10, 3, 4, 1, 2, 8, 9, 12, 0, 1, 2, 3, 4, +0, 1, 2, 3, 4, 1, 3, 0, 2, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 0, 1, 2, 3, 4, +5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, +20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 0, 1, 75, 78, 76, 15, 79, 77, 8, 85, 14, 0, 4, +10, 81, 83, 84, 87, 12, 80, 82, 11, 9, 2, 6, 86, 36, 38, +37, 13, 1, 5, 3, 7, 49, 22, 24, 28, 32, 50, 58, 63, 66, +71, 23, 25, 29, 33, 47, 48, 51, 52, 53, 54, 46, 17, 19, 16, +20, 21, 26, 27, 30, 31, 34, 35, 39, 40, 41, 42, 43, 44, 45, +55, 56, 57, 59, 60, 61, 62, 64, 65, 67, 68, 69, 70, 72, 73, +74, 18, 11, 22, 1, 3, 5, 7, 9, 10, 13, 15, 16, 18, 20, +26, 28, 0, 2, 4, 6, 8, 12, 14, 17, 19, 21, 23, 24, 25, +27, 29, 47, 45, 43, 48, 42, 44, 49, 46, 33, 11, 27, 31, 37, +38, 63, 17, 18, 21, 23, 25, 29, 32, 35, 77, 83, 97, 0, 5, +9, 15, 16, 19, 39, 41, 53, 69, 20, 22, 24, 26, 28, 30, 34, +36, 76, 82, 96, 102, 103, 1, 3, 7, 13, 40, 51, 57, 61, 67, +71, 73, 75, 81, 87, 95, 101, 106, 107, 70, 2, 4, 6, 8, 10, +12, 14, 50, 52, 54, 55, 56, 58, 59, 60, 62, 64, 65, 66, 68, +72, 74, 78, 79, 80, 84, 85, 86, 88, 89, 90, 91, 92, 93, 94, +98, 99, 100, 104, 105, 108, 109, 0, 1, 46, 43, 47, 42, 3, 44, +5, 20, 4, 18, 24, 26, 30, 38, 34, 36, 7, 9, 22, 2, 45, +21, 40, 19, 35, 37, 39, 32, 12, 14, 28, 10, 16, 41, 25, 27, +31, 6, 8, 23, 33, 11, 17, 13, 15, 29, 52, 50, 53, 48, 49, +51, 0, 1, 0, 1, 2, 3, 4, 5, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, +36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, +51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, +66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, +81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, +96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, +111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, +126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, +141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, +156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, +171, 172, 173, 174, 175, 176, 177, 178, 179, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, +21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, +36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, +51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, +66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, +81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, +96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, +111, 112, 113, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, +27, 28, 29, 30, 31, 32, 33, 34, 35, 5, 15, 19, 27, 31, 35, +39, 43, 96, 104, 120, 121, 131, 0, 1, 2, 10, 12, 24, 25, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 76, 77, 78, 79, 80, +81, 82, 83, 84, 85, 86, 87, 88, 90, 91, 93, 95, 97, 99, 101, +103, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, +119, 122, 123, 124, 125, 126, 127, 128, 129, 130, 132, 133, 134, 135, 136, +137, 138, 140, 144, 148, 152, 156, 160, 164, 3, 4, 6, 7, 8, 9, +11, 13, 14, 16, 17, 18, 20, 21, 22, 23, 26, 28, 29, 30, 32, +33, 34, 36, 37, 38, 40, 41, 42, 44, 45, 57, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 89, +92, 94, 98, 100, 102, 139, 141, 142, 143, 145, 146, 147, 149, 150, 151, +153, 154, 155, 157, 158, 159, 161, 162, 163, 165, 166, 36, 57, 60, 65, +68, 114, 135, 156, 161, 162, 165, 170, 176, 179, 182, 183, 188, 191, 194, +197, 198, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 34, 35, 37, 38, 39, 40, 41, 42, 43, +44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 58, 59, +61, 62, 63, 64, 66, 67, 69, 70, 71, 72, 73, 74, 75, 76, 77, +78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, +93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, +108, 109, 110, 111, 112, 113, 115, 116, 117, 118, 119, 120, 121, 122, 123, +124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 136, 137, 138, 139, +140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, +155, 157, 158, 159, 160, 163, 164, 166, 167, 168, 169, 171, 172, 173, 174, +175, 177, 178, 180, 181, 184, 185, 186, 187, 189, 190, 192, 193, 195, 196, +199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, +214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, +229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, +244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, +259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, +274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, +289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, +304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, +319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, +334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, +349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, +364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, +379, 380, 381, 382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, +394, 395, 396, 397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, +409, 410, 411, 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, +424, 425, 426, 427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, +439, 440, 441, 442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, +454, 455, 456, 457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, +469, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, +484, 485, 486, 487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, +499, 500, 501, 502, 503, 504, 505, 506, 0, 1, 2, 3, 4, 5, 6, +7, 8, 9, 10, 11, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, +40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, +55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, +70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, +85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, +100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, +115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, 129, +130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, +145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, 159, +160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, 174, +175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, 189, +190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, 202, 203, 204, +205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, 217, 218, 219, +220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, 232, 233, 234, +235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, 247, 248, 249, +250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 262, 263, 264, +265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, +280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, 292, 293, 294, +295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, 309, +310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, 322, 323, 324, +325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, 337, 338, 339, +340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, 352, 353, 354, +355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, +370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, 382, 383, 384, +385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, 397, 398, 399, +400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, 412, 413, 414, +415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 427, 428, 429, +430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, 442, 443, 444, +445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, 457, 458, 459, +460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, 472, 473, 474, +475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, 487, 488, 489, +490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, 502, 503, 504, +505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, +520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, +535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, +550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, +565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, +580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, +595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, +610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, 622, 623, 624, +625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, 637, 638, 639, +640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, 652, 653, 654, +655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, 667, 668, 669, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 0, 1, 2, 3, 4, 5, 6, 7, +8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, +23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, +38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, +53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, +68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, +83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, +98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, +113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, +128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, +143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, +158, 159, 160, 161, 162, 163, 164, 165, 166, 0, 1, 2, 3, 4, 5, +6, 7, 8, 9, 10, 11, 12, 13, 14, 0, 1, 2, 3, 4, 5, +0, 3, 5, 10, 16, 18, 94, 4, 6, 7, 8, 17, 37, 44, 48, +51, 56, 66, 69, 75, 79, 82, 84, 88, 98, 99, 102, 1, 2, 9, +11, 12, 13, 14, 15, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, +29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40, 41, 42, 43, 45, +46, 47, 49, 50, 52, 53, 54, 55, 57, 58, 59, 60, 61, 62, 63, +64, 65, 67, 68, 70, 71, 72, 73, 74, 76, 77, 78, 80, 81, 83, +85, 86, 87, 89, 90, 91, 92, 93, 95, 96, 97, 100, 101, 103, 104, +105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, +120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, +135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, +150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, +165, 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, +180, 181, 182, 183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, +81, 18, 24, 33, 69, 83, 19, 25, 35, 71, 0, 1, 2, 3, 4, +5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 20, 21, +22, 23, 26, 27, 28, 29, 30, 31, 32, 34, 36, 37, 38, 39, 40, +41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, +56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 70, 72, +73, 74, 75, 76, 77, 78, 79, 80, 82, 84, 85, 86, 87, 88, 89, +90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, +105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, +120, 121, 122, 123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, +135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, +150, 151, 152, 153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, +165, 166, 167, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, +12, 13, 14, 15, 16, 17, 4, 5, 6, 31, 32, 39, 40, 41, 0, +1, 2, 3, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, +19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 33, 34, 35, +36, 37, 38, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, +84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, +99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, +114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, +129, 130, 131, 132, 133, 134, 135, 136, 0, 1, 3, 22, 23, 26, 34, +0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 18, 19, 20, 21, 24, 25, 27, 28, 29, 30, 31, 32, 33, +35, 36, 37, 38, 39, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 0, +1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, +16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, +31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, +46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, +61, 62, 63, 64, 65, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, +10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, +25, 26, 27, 28, 29, 30, 31, 32, 33, 51, 0, 1, 2, 3, 4, +5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, +20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, +35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, +50, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, +66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 0, 1, 2, +3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, +18, 19, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, +47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, +62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, +77, 74, 75, 92, 93, 116, 143, 144, 149, 14, 15, 34, 35, 36, 37, +68, 69, 98, 99, 104, 105, 110, 111, 154, 155, 156, 157, 166, 167, 168, +169, 178, 179, 180, 181, 4, 5, 6, 7, 22, 23, 24, 25, 46, 47, +50, 51, 56, 57, 60, 61, 80, 82, 85, 87, 121, 122, 123, 124, 133, +134, 135, 136, 190, 191, 194, 197, 202, 203, 206, 207, 212, 213, 216, 217, +0, 1, 2, 3, 8, 9, 10, 11, 12, 13, 16, 17, 18, 19, 20, +21, 26, 27, 28, 29, 30, 31, 32, 33, 38, 39, 40, 41, 42, 43, +44, 45, 48, 49, 52, 53, 54, 55, 58, 59, 62, 63, 64, 65, 66, +67, 70, 71, 72, 73, 76, 77, 78, 79, 81, 83, 84, 86, 88, 89, +90, 91, 94, 95, 96, 97, 100, 101, 102, 103, 106, 107, 108, 109, 112, +113, 114, 115, 117, 118, 119, 120, 125, 126, 127, 128, 129, 130, 131, 132, +137, 138, 139, 140, 141, 142, 145, 146, 147, 148, 150, 151, 152, 153, 158, +159, 160, 161, 162, 163, 164, 165, 170, 171, 172, 173, 174, 175, 176, 177, +182, 183, 184, 185, 186, 187, 188, 189, 192, 193, 195, 196, 198, 199, 200, +201, 204, 205, 208, 209, 210, 211, 214, 215, 218, 219, 220, 221, 0, 1, +2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, +17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, +32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 0, 1, 2, +3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, +18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, +33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, +48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, +63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, +78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, +93, 94, 95, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, +108, 109, 110, 111, 112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, +123, 124, 125, 126, 127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, +138, 139, 140, 141, 142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, +153, 154, 155, 156, 157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, +168, 169, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, +183, 184, 185, 186, 187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, +198, 199, 200, 201, 202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, +213, 214, 215, 216, 217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, +228, 229, 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, +243, 244, 245, 246, 247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, +258, 259, 260, 261, 262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, +273, 274, 275, 276, 277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, +288, 289, 290, 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, +303, 304, 305, 306, 307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, +318, 319, 320, 321, 322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, +333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, +348, 349, 350, 351, 352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, +363, 364, 365, 366, 367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, +0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, +15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, +30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, +45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 0, 1, 2, 3, +4, 5, 6, 7, 0, 1, 14, 15, 16, 17, 2, 3, 4, 5, 8, +9, 10, 11, 12, 13, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 11, 2, 5, 10, 8, 4, 9, 1, 7, +3, 0, 6, 42, 45, 36, 39, 12, 16, 18, 22, 38, 41, 44, 47, +37, 40, 43, 46, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, +11, 13, 14, 15, 17, 19, 20, 21, 23, 24, 25, 26, 27, 28, 29, +30, 31, 32, 33, 34, 35, 0, 1, 2, 3, 4, 5, 6, 7, 8, +9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, +24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, +39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, +54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, +69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, +84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, +99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, +114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, 127, 128, +129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, +144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, 157, 158, +159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, 172, 173, +174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, 187, 188, +189, 190, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, +13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, +28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, +43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, +58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, +73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, +88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, 102, +103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 4, 5, +6, 8, 1, 3, 0, 2, 7, 9, 0, 1, 2, 3, 4, 5, 6, +7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, +22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, +37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, +52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, +67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, +82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, +97, 98, 99, 100, 101, 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, +112, 113, 114, 115, 116, 117, 118, 119, 120, 121, 122, 123, 124, 125, 126, +127, 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, +142, 143, 144, 145, 146, 147, 148, 149, 150, 151, 152, 153, 154, 155, 156, +157, 158, 159, 160, 161, 162, 163, 164, 165, 166, 167, 168, 169, 170, 171, +172, 173, 174, 175, 176, 177, 178, 179, 180, 181, 182, 183, 184, 185, 186, +187, 188, 189, 190, 191, 192, 193, 194, 195, 196, 197, 198, 199, 200, 201, +202, 203, 204, 205, 206, 207, 208, 209, 210, 211, 212, 213, 214, 215, 216, +217, 218, 219, 220, 221, 222, 223, 224, 225, 226, 227, 228, 229, 230, 231, +232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 243, 244, 245, 246, +247, 248, 249, 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, +262, 263, 264, 265, 266, 267, 268, 269, 270, 271, 272, 273, 274, 275, 276, +277, 278, 279, 280, 281, 282, 283, 284, 285, 286, 287, 288, 289, 290, 291, +292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, +307, 308, 309, 310, 311, 312, 313, 314, 315, 316, 317, 318, 319, 320, 321, +322, 323, 324, 325, 326, 327, 328, 329, 330, 331, 332, 333, 334, 335, 336, +337, 338, 339, 340, 341, 342, 343, 344, 345, 346, 347, 348, 349, 350, 351, +352, 353, 354, 355, 356, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, +367, 368, 369, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 380, 381, +382, 383, 384, 385, 386, 387, 388, 389, 390, 391, 392, 393, 394, 395, 396, +397, 398, 399, 400, 401, 402, 403, 404, 405, 406, 407, 408, 409, 410, 411, +412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, +427, 428, 429, 430, 431, 432, 433, 434, 435, 436, 437, 438, 439, 440, 441, +442, 443, 444, 445, 446, 447, 448, 449, 450, 451, 452, 453, 454, 455, 456, +457, 458, 459, 460, 461, 462, 463, 464, 465, 466, 467, 468, 469, 470, 471, +472, 473, 474, 475, 476, 477, 478, 479, 480, 481, 482, 483, 484, 485, 486, +487, 488, 489, 490, 491, 492, 493, 494, 495, 496, 497, 498, 499, 500, 501, +502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, +517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, +532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, +547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, +562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, +577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, +592, 593, 594, 595, 596, 597, 598, 599, 600, 601, 602, 603, 604, 605, 606, +607, 608, 609, 610, 611, 612, 613, 614, 615, 616, 617, 618, 619, 620, 621, +622, 623, 624, 625, 626, 627, 628, 629, 630, 631, 632, 633, 634, 635, 636, +637, 638, 639, 640, 641, 642, 643, 644, 645, 646, 647, 648, 649, 650, 651, +652, 653, 654, 655, 656, 657, 658, 659, 660, 661, 662, 663, 664, 665, 666, +667, 668, 669, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 680, 681, +682, 683, 684, 685, 686, 687, 688, 689, 690, 691, 692, 693, 694, 695, 696, +697, 698, 699, 700, 701, 702, 703, 704, 705, 706, 707, 708, 709, 710, 711, +712, 713, 714, 715, 716, 717, 718, 719, 720, 721, 722, 723, 724, 725, 726, +727, 728, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, +742, 743, 744, 745, 746, 747, 748, 749, 750, 751, 752, 753, 754, 755, 756, +757, 758, 759, 760, 761, 762, 763, 764, 765, 766, 767, 768, 769, 770, 771, +772, 773, 774, 775, 776, 777, 778, 779, 780, 781, 782, 783, 784, 785, 786, +787, 788, 789, 790, 791, 792, 793, 794, 795, 796, 797, 798, 799, 800, 801, +802, 803, 804, 805, 806, 807, 808, 809, 810, 811, 812, 813, 814, 815, 816, +817, 818, 819, 820, 821, 822, 823, 824, 825, 826, 827, 828, 829, 830, 831, +832, 833, 834, 835, 836, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, +847, 848, 849, 850, 851, 852, 853, 854, 855, 856, 857, 858, 859, 860, 861, +862, 863, 864, 865, 866, 867, 868, 869, 870, 871, 872, 873, 874, 875, 876, +877, 878, 879, 880, 881, 882, 883, 884, 885, 886, 887, 888, 889, 890, 891, +892, 893, 894, 895, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, +907, 908, 909, 910, 911, 912, 913, 914, 915, 916, 917, 918, 919, 920, 921, +922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, 934, 935, 936, +937, 938, 939, 940, 941, 942, 943, 944, 945, 946, 947, 948, 949, 950, 951, +952, 953, 954, 955, 956, 957, 958, 959, 960, 961, 962, 963, 964, 965, 966, +967, 968, 969, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 980, 981, +982, 983, 984, 985, 986, 987, 988, 989, 990, 991, 992, 993, 994, 995, 996, +997, 998, 999, 1000, 1001, 1002, 1003, 1004, 1005, 1006, 1007, 1008, 1009, 1010, 1011, +1012, 1013, 1014, 1015, 1016, 1017, 1018, 1019, 1020, 1021, 1022, 1023, 1024, 1025, 1026, +1027, 1028, 1029, 1030, 1031, 1032, 1033, 1034, 1035, 1036, 1037, 1038, 1039, 1040, 1041, +1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1050, 1051, 1052, 1053, 1054, 1055, 1056, +1057, 1058, 1059, 1060, 1061, 1062, 1063, 1064, 1065, 1066, 1067, 1068, 1069, 1070, 1071, +1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1080, 1081, 1082, 1083, 1084, 1085, 1086, +1087, 1088, 1089, 1090, 1091, 1092, 1093, 1094, 1095, 1096, 1097, 1098, 1099, 1100, 1101, +1102, 1103, 1104, 1105, 1106, 1107, 1108, 1109, 1110, 1111, 1112, 1113, 1114, 1115, 1116, +1117, 1118, 1119, 1120, 1121, 1122, 1123, 1124, 1125, 1126, 1127, 1128, 1129, 1130, 1131, +1132, 1133, 1134, 1135, 1136, 1137, 1138, 1139, 1140, 1141, 1142, 1143, 1144, 1145, 1146, +1147, 1148, 1149, 1150, 1151, 1152, 1153, 1154, 1155, 1156, 1157, 1158, 1159, 1160, 1161, +1162, 1163, 1164, 1165, 1166, 1167, 1168, 1169, 1170, 1171, 1172, 1173, 1174, 1175, 1176, +1177, 1178, 1179, 1180, 1181, 1182, 1183, 1184, 1185, 1186, 1187, 1188, 1189, 1190, 1191, +1192, 1193, 1194, 1195, 1196, 1197, 1198, 1199, 1200, 1201, 1202, 1203, 1204, 1205, 1206, +1207, 1208, 1209, 1210, 1211, 1212, 1213, 1214, 1215, 1216, 1217, 1218, 1219, 1220, 1221, +1222, 1223, 1224, 1225, 1226, 1227, 1228, 1229, 1230, 1231, 1232, 1233, 1234, 1235, 1236, +1237, 1238, 1239, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1250, 1251, +1252, 1253, 1254, 1255, 1256, 1257, 1258, 1259, 1260, 1261, 1262, 1263, 1264, 1265, 1266, +1267, 1268, 1269, 1270, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1280, 1281, +1282, 1283, 1284, 1285, 1286, 1287, 1288, 1289, 1290, 1291, 1292, 1293, 1294, 1295, 1296, +1297, 1298, 1299, 1300, 1301, 1302, 1303, 1304, 1305, 1306, 1307, 1308, 1309, 1310, 1311, +1312, 1313, 1314, 1315, 1316, 1317, 1318, 1319, 1320, 1321, 1322, 1323, 1324, 1325, 1326, +1327, 1328, 1329, 1330, 1331, 1332, 1333, 1334, 1335, 1336, 1337, 1338, 1339, 1340, 1341, +1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1350, 1351, 1352, 1353, 1354, 1355, 1356, +1357, 1358, 1359, 1360, 1361, 1362, 1363, 1364, 1365, 1366, 1367, 1368, 1369, 1370, 1371, +1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1380, 1381, 1382, 1383, 1384, 1385, 1386, +1387, 1388, 1389, 1390, 1391, 1392, 1393, 1394, 1395, 1396, 1397, 1398, 1399, 1400, 1401, +1402, 1403, 1404, 1405, 1406, 1407, 1408, 1409, 1410, 1411, 1412, 1413, 1414, 1415, 1416, +1417, 1418, 1419, 1420, 1421, 1422, 1423, 1424, 1425, 1426, 1427, 1428, 1429, 1430, 1431, +1432, 1433, 1434, 1435, 1436, 1437, 1438, 1439, 1440, 1441, 1442, 1443, 1444, 1445, 1446, +1447, 1448, 1449, 1450, 1451, 1452, 1453, 1454, 1455, 1456, 1457, 1458, 1459, 1460, 1461, +1462, 1463, 1464, 1465, 1466, 1467, 1468, 1469, 1470, 1471, 1472, 1473, 1474, 1475, 1476, +1477, 1478, 1479, 1480, 1481, 1482, 1483, 1484, 1485, 1486, 1487, 1488, 1489, 1490, 1491, +1492, 1493, 1494, 1495, 1496, 1497, 1498, 1499, 1500, 1501, 1502, 1503, 1504, 1505, 1506, +1507, 1508, 1509, 1510, 1511, 1512, 1513, 1514, 1515, 1516, 1517, 1518, 1519, 1520, 1521, +1522, 1523, 1524, 1525, 1526, 1527, 1528, 1529, 1530, 1531, 1532, 1533, 1534, 1535, 1536, +1537, 1538, 1539, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1550, 1551, +1552, 1553, 1554, 1555, 1556, 1557, 1558, 1559, 1560, 1561, 1562, 1563, 1564, 1565, 1566, +1567, 1568, 1569, 1570, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1580, 1581, +1582, 1583, 1584, 1585, 1586, 1587, 1588, 1589, 1590, 1591, 1592, 1593, 1594, 1595, 1596, +1597, 1598, 1599, 1600, 1601, 1602, 1603, 1604, 1605, 1606, 1607, 1608, 1609, 1610, 1611, +1612, 1613, 1614, 1615, 1616, 1617, 1618, 1619, 1620, 1621, 1622, 1623, 1624, 1625, 1626, +1627, 1628, 1629, 1630, 1631, 1632, 1633, 1634, 1635, 1636, 1637, 1638, 1639, 1640, 1641, +1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1650, 1651, 1652, 1653, 1654, 1655, 1656, +1657, 1658, 1659, 1660, 1661, 1662, 1663, 1664, 1665, 1666, 1667, 1668, 1669, 1670, 1671, +1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1680, 1681, 1682, 1683, 1684, 1685, 1686, +1687, 1688, 1689, 1690, 1691, 1692, 1693, 1694, 1695, 1696, 1697, 1698, 1699, 1700, 1701, +1702, 1703, 1704, 1705, 1706, 1707, 1708, 1709, 1710, 1711, 1712, 1713, 1714, 1715, 1716, +1717, 1718, 1719, 1720, 1721, 1722, 1723, 1724, 1725, 1726, 1727, 1728, 1729, 1730, 1731, +1732, 1733, 1734, 1735, 1736, 1737, 1738, 1739, 1740, 1741, 1742, 1743, 1744, 1745, 1746, +1747, 1748, 1749, 1750, 1751, 1752, 1753, 1754, 1755, 1756, 1757, 1758, 1759, 1760, 1761, +1762, 1763, 1764, 1765, 1766, 1767, 1768, 1769, 1770, 1771, 1772, 1773, 1774, 1775, 1776, +1777, 1778, 1779, 1780, 1781, 1782, 1783, 1784, 1785, 1786, 1787, 1788, 1789, 1790, 1791, +1792, 1793, 1794, 1795, 1796, 1797, 1798, 1799, 1800, 1801, 1802, 1803, 1804, 1805, 1806, +1807, 1808, 1809, 1810, 1811, 1812, 1813, 1814, 1815, 1816, 1817, 1818, 1819, 1820, 1821, +1822, 1823, 1824, 1825, 1826, 1827, 1828, 1829, 1830, 1831, 1832, 1833, 1834, 1835, 1836, +1837, 1838, 1839, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1850, 1851, +1852, 1853, 1854, 1855, 1856, 1857, 1858, 1859, 1860, 1861, 1862, 1863, 1864, 1865, 1866, +1867, 1868, 1869, 1870, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1880, 1881, +1882, 1883, 1884, 1885, 1886, 1887, 1888, 1889, 1890, 1891, 1892, 1893, 1894, 1895, 1896, +1897, 1898, 1899, 1900, 1901, 1902, 1903, 1904, 1905, 1906, 1907, 1908, 1909, 1910, 1911, +1912, 1913, 1914, 1915, 1916, 1917, 1918, 1919, 1920, 1921, 1922, 1923, 1924, 1925, 1926, +1927, 1928, 1929, 1930, 1931, 1932, 1933, 1934, 1935, 1936, 1937, 1938, 1939, 1940, 1941, +1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949, 1950, 1951, 1952, 1953, 1954, 1955, 1956, +1957, 1958, 1959, 1960, 1961, 1962, 1963, 1964, 1965, 1966, 1967, 1968, 1969, 1970, 1971, +1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979, 1980, 1981, 1982, 1983, 1984, 1985, 1986, +1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, +2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015, 2016, +2017, 2018, 2019, 2020, 2021, 2022, 2023, 2024, 2025, 2026, 2027, 2028, 2029, 2030, 2031, +2032, 2033, 2034, 2035, 2036, 2037, 2038, 2039, 2040, 2041, 2042, 2043, 2044, 2045, 2046, +2047, 2048, 2049, 2050, 2051, 2052, 2053, 2054, 2055, 2056, 2057, 2058, 2059, 2060, 2061, +2062, 2063, 2064, 2065, 2066, 2067, 2068, 2069, 2070, 2071, 2072, 2073, 2074, 2075, 2076, +2077, 2078, 2079, 2080, 2081, 2082, 2083, 2084, 2085, 2086, 2087, 2088, 2089, 2090, 2091, +2092, 2093, 2094, 2095, 2096, 2097, 2098, 2099, 2100, 2101, 2102, 2103, 2104, 2105, 2106, +2107, 2108, 2109, 2110, 2111, 2112, 2113, 2114, 2115, 2116, 2117, 2118, 2119, 2120, 2121, +2122, 2123, 2124, 2125, 2126, 2127, 2128, 2129, 2130, 2131, 2132, 2133, 2134, 2135, 2136, +2137, 2138, 2139, 2140, 2141, 2142, 2143, 2144, 2145, 2146, 2147, 2148, 2149, 2150, 2151, +2152, 2153, 2154, 2155, 2156, 2157, 2158, 2159, 2160, 2161, 2162, 2163, 2164, 2165, 2166, +2167, 2168, 2169, 2170, 2171, 2172, 2173, 2174, 2175, 2176, 2177, 2178, 2179, 2180, 2181, +2182, 2183, 2184, 2185, 2186, 2187, 2188, 2189, 2190, 2191, 2192, 2193, 2194, 2195, 2196, +2197, 2198, 2199, 2200, 2201, 2202, 2203, 2204, 2205, 2206, 2207, 2208, 2209, 2210, 2211, +2212, 2213, 2214, 2215, 2216, 2217, 2218, 2219, 2220, 2221, 2222, 2223, 2224, 2225, 2226, +2227, 2228, 2229, 2230, 2231, 2232, 2233, 2234, 2235, 2236, 2237, 2238, 2239, 2240, 2241, +2242, 2243, 2244, 2245, 2246, 2247, 2248, 2249, 2250, 2251, 2252, 2253, 2254, 2255, 2256, +2257, 2258, 2259, 2260, 2261, 2262, 2263, 2264, 2265, 2266, 2267, 2268, 2269, 2270, 2271, +2272, 2273, 2274, 2275, 2276, 2277, 2278, 2279, 2280, 2281, 2282, 2283, 2284, 2285, 2286, +2287, 2288, 2289, 2290, 2291, 2292, 2293, 2294, 2295, 2296, 2297, 2298, 2299, 2300, 2301, +2302, 2303, 2304, 2305, 2306, 2307, 2308, 2309, 2310, 2311, 2312, 2313, 2314, 2315, 2316, +2317, 2318, 2319, 2320, 2321, 2322, 2323, 2324, 2325, 2326, 2327, 2328, 2329, 2330, 2331, +2332, 2333, 2334, 2335, 2336, 2337, 2338, 2339, 2340, 2341, 2342, 2343, 2344, 2345, 2346, +2347, 2348, 2349, 2350, 2351, 2352, 2353, 2354, 2355, 2356, 2357, 2358, 2359, 2360, 2361, +2362, 2363, 2364, 2365, 2366, 2367, 2368, 2369, 2370, 2371, 2372, 2373, 2374, 2375, 2376, +2377, 2378, 2379, 2380, 2381, 2382, 2383, 2384, 2385, 2386, 2387, 2388, 2389, 2390, 2391, +2392, 2393, 2394, 2395, 2396, 2397, 2398, 2399, 2400, 2401, 2402, 2403, 2404, 2405, 2406, +2407, 2408, 2409, 2410, 2411, 2412, 2413, 2414, 2415, 2416, 2417, 2418, 2419, 2420, 2421, +2422, 2423, 2424, 2425, 2426, 2427, 2428, 2429, 2430, 2431, 2432, 2433, 2434, 2435, 2436, +2437, 2438, 2439, 2440, 2441, 2442, 2443, 2444, 2445, 2446, 2447, 2448, 2449, 2450, 2451, +2452, 2453, 2454, 2455, 2456, 2457, 2458, 2459, 2460, 2461, 2462, 2463, 2464, 2465, 2466, +2467, 2468, 2469, 2470, 2471, 2472, 2473, 2474, 2475, 2476, 2477, 2478, 2479, 2480, 2481, +2482, 2483, 2484, 2485, 2486, 2487, 2488, 2489, 2490, 2491, 2492, 2493, 2494, 2495, 2496, +2497, 2498, 2499, 2500, 2501, 2502, 2503, 2504, 2505, 2506, 2507, 2508, 2509, 2510, 2511, +2512, 2513, 2514, 2515, 2516, 2517, 2518, 2519, 2520, 2521, 2522, 2523, 2524, 2525, 2526, +2527, 2528, 2529, 2530, 2531, 2532, 2533, 2534, 2535, 2536, 2537, 2538, 2539, 2540, 2541, +2542, 2543, 2544, 2545, 2546, 2547, 2548, 2549, 2550, 2551, 2552, 2553, 2554, 2555, 2556, +2557, 2558, 2559, 2560, 2561, 2562, 2563, 2564, 2565, 2566, 2567, 2568, 2569, 2570, 2571, +2572, 2573, 2574, 2575, 2576, 2577, 2578, 2579, 2580, 2581, 2582, 2583, 2584, 2585, 2586, +2587, 2588, 2589, 2590, 2591, 2592, 2593, 2594, 2595, 2596, 2597, 2598, 2599, 2600, 2601, +2602, 2603, 2604, 2605, 2606, 2607, 2608, 2609, 2610, 2611, 2612, 2613, 2614, 2615, 2616, +2617, 2618, 2619, 2620, 2621, 2622, 2623, 2624, 2625, 2626, 2627, 2628, 2629, 2630, 2631, +2632, 2633, 2634, 2635, 2636, 2637, 2638, 2639, 2640, 2641, 2642, 2643, 2644, 2645, 2646, +2647, 2648, 2649, 2650, 2651, 2652, 2653, 2654, 2655, 2656, 2657, 2658, 2659, 2660, 2661, +2662, 2663, 2664, 2665, 2666, 2667, 2668, 2669, 2670, 2671, 2672, 2673, 2674, 2675, 2676, +2677, 2678, 2679, 2680, 2681, 2682, 2683, 2684, 2685, 2686, 2687, 2688, 2689, 2690, 2691, +2692, 2693, 2694, 2695, 2696, 2697, 2698, 2699, 2700, 2701, 2702, 2703, 2704, 2705, 2706, +2707, 2708, 2709, 2710, 2711, 2712, 2713, 2714, 2715, 2716, 2717, 2718, 2719, 2720, 2721, +2722, 2723, 2724, 2725, 2726, 2727, 2728, 2729, 2730, 2731, 2732, 2733, 2734, 2735, 2736, +2737, 2738, 2739, 2740, 2741, 2742, 2743, 2744, 2745, 2746, 2747, 2748, 2749, 2750, 2751, +2752, 2753, 2754, 2755, 2756, 2757, 2758, 2759, 2760, 2761, 2762, 2763, 2764, 2765, 2766, +2767, 2768, 2769, 2770, 2771, 2772, 2773, 2774, 2775, 2776, 2777, 2778, 2779, 2780, 2781, +2782, 2783, 2784, 2785, 2786, 2787, 2788, 2789, 2790, 2791, 2792, 2793, 2794, 2795, 2796, +2797, 2798, 2799, 2800, 2801, 2802, 2803, 2804, 2805, 2806, 2807, 2808, 2809, 2810, 2811, +2812, 2813, 2814, 2815, 2816, 2817, 2818, 2819, 2820, 2821, 2822, 2823, 2824, 2825, 2826, +2827, 2828, 2829, 2830, 2831, 2832, 2833, 2834, 2835, 2836, 2837, 2838, 2839, 2840, 2841, +2842, 2843, 2844, 2845, 2846, 2847, 2848, 2849, 2850, 2851, 2852, 2853, 2854, 2855, 2856, +2857, 2858, 2859, 2860, 2861, 2862, 2863, 9, 11, 6, 7, 8, 10, 4, 5, +0, 1, 2, 3, 0, 2, 10, 3, 6, 1, 9, 11, 4, 8, 7, +5, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, +14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, +29, 30, 31, 32, 33, 34, 35, 68, 116, 22, 10, 97, 117, 52, 110, +7, 19, 111, 115, 6, 18, 0, 74, 88, 12, 48, 108, 99, 109, 38, +104, 4, 16, 24, 96, 15, 3, 50, 84, 71, 85, 36, 102, 103, 119, +54, 86, 100, 30, 25, 105, 113, 69, 53, 63, 98, 87, 93, 89, 95, +9, 21, 62, 114, 5, 17, 26, 55, 2, 14, 65, 8, 20, 64, 92, +42, 106, 11, 23, 46, 66, 34, 101, 107, 56, 35, 47, 57, 67, 76, +118, 75, 83, 82, 94, 37, 77, 29, 51, 1, 13, 27, 49, 58, 112, +39, 59, 28, 70, 44, 73, 80, 81, 32, 72, 31, 43, 33, 40, 41, +45, 60, 61, 78, 79, 90, 91 +}; + + /**Function************************************************************* Synopsis [Reads library from array.] @@ -9461,6 +11120,27 @@ Vec_Int_t * Dar_LibReadOuts() return vResult; } +/**Function************************************************************* + + Synopsis [Reads library from array.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Dar_LibReadPrios() +{ + Vec_Int_t * vResult; + int i; + vResult = Vec_IntAlloc( s_nDataSize3 ); + for ( i = 0; i < s_nDataSize3; i++ ) + Vec_IntPush( vResult, s_Data3[i] ); + return vResult; +} + //#if 0 #include "abc.h" @@ -9476,7 +11156,7 @@ Vec_Int_t * Dar_LibReadOuts() SeeAlso [] ***********************************************************************/ -void Dar_NtkGenerateArrays( Abc_Ntk_t * pNtk ) +void Aig_NtkGenerateArrays( Abc_Ntk_t * pNtk ) { extern int Io_WriteAigerEncode( char * pBuffer, int Pos, unsigned x ); diff --git a/src/aig/dar/darDfs.c b/src/aig/dar/darDfs.c deleted file mode 100644 index 116f428c..00000000 --- a/src/aig/dar/darDfs.c +++ /dev/null @@ -1,381 +0,0 @@ -/**CFile**************************************************************** - - FileName [darDfs.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [DFS traversal procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darDfs.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManDfs_rec( Dar_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( pObj == NULL ) - return; - if ( Dar_ObjIsTravIdCurrent(p, pObj) ) - return; - assert( Dar_ObjIsNode(pObj) || Dar_ObjIsBuf(pObj) ); - Dar_ManDfs_rec( p, Dar_ObjFanin0(pObj), vNodes ); - Dar_ManDfs_rec( p, Dar_ObjFanin1(pObj), vNodes ); - assert( !Dar_ObjIsTravIdCurrent(p, pObj) ); // loop detection - Dar_ObjSetTravIdCurrent(p, pObj); - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Dar_ManDfs( Dar_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i; - Dar_ManIncrementTravId( p ); - // mark constant and PIs - Dar_ObjSetTravIdCurrent( p, Dar_ManConst1(p) ); - Dar_ManForEachPi( p, pObj, i ) - Dar_ObjSetTravIdCurrent( p, pObj ); - // if there are latches, mark them - if ( Dar_ManLatchNum(p) > 0 ) - Dar_ManForEachObj( p, pObj, i ) - if ( Dar_ObjIsLatch(pObj) ) - Dar_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Dar_ManNodeNum(p) ); - Dar_ManForEachObj( p, pObj, i ) - if ( Dar_ObjIsNode(pObj) || Dar_ObjIsBuf(pObj) ) - Dar_ManDfs_rec( p, pObj, vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Dar_ManDfsNodes( Dar_Man_t * p, Dar_Obj_t ** ppNodes, int nNodes ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i; - assert( Dar_ManLatchNum(p) == 0 ); - Dar_ManIncrementTravId( p ); - // mark constant and PIs - Dar_ObjSetTravIdCurrent( p, Dar_ManConst1(p) ); - Dar_ManForEachPi( p, pObj, i ) - Dar_ObjSetTravIdCurrent( p, pObj ); - // go through the nodes - vNodes = Vec_PtrAlloc( Dar_ManNodeNum(p) ); - for ( i = 0; i < nNodes; i++ ) - Dar_ManDfs_rec( p, ppNodes[i], vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Computes the max number of levels in the manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManCountLevels( Dar_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i, LevelsMax, Level0, Level1; - // initialize the levels - Dar_ManConst1(p)->pData = NULL; - Dar_ManForEachPi( p, pObj, i ) - pObj->pData = NULL; - // compute levels in a DFS order - vNodes = Dar_ManDfs( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - Level0 = (int)Dar_ObjFanin0(pObj)->pData; - Level1 = (int)Dar_ObjFanin1(pObj)->pData; - pObj->pData = (void *)(1 + Dar_ObjIsExor(pObj) + DAR_MAX(Level0, Level1)); - } - Vec_PtrFree( vNodes ); - // get levels of the POs - LevelsMax = 0; - Dar_ManForEachPo( p, pObj, i ) - LevelsMax = DAR_MAX( LevelsMax, (int)Dar_ObjFanin0(pObj)->pData ); - return LevelsMax; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ConeMark_rec( Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) || Dar_ObjIsMarkA(pObj) ) - return; - Dar_ConeMark_rec( Dar_ObjFanin0(pObj) ); - Dar_ConeMark_rec( Dar_ObjFanin1(pObj) ); - assert( !Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ConeCleanAndMark_rec( Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) || Dar_ObjIsMarkA(pObj) ) - return; - Dar_ConeCleanAndMark_rec( Dar_ObjFanin0(pObj) ); - Dar_ConeCleanAndMark_rec( Dar_ObjFanin1(pObj) ); - assert( !Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjSetMarkA( pObj ); - pObj->pData = NULL; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ConeCountAndMark_rec( Dar_Obj_t * pObj ) -{ - int Counter; - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) || Dar_ObjIsMarkA(pObj) ) - return 0; - Counter = 1 + Dar_ConeCountAndMark_rec( Dar_ObjFanin0(pObj) ) + - Dar_ConeCountAndMark_rec( Dar_ObjFanin1(pObj) ); - assert( !Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjSetMarkA( pObj ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ConeUnmark_rec( Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) || !Dar_ObjIsMarkA(pObj) ) - return; - Dar_ConeUnmark_rec( Dar_ObjFanin0(pObj) ); - Dar_ConeUnmark_rec( Dar_ObjFanin1(pObj) ); - assert( Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjClearMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Counts the number of AIG nodes rooted at this cone.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_DagSize( Dar_Obj_t * pObj ) -{ - int Counter; - Counter = Dar_ConeCountAndMark_rec( Dar_Regular(pObj) ); - Dar_ConeUnmark_rec( Dar_Regular(pObj) ); - return Counter; -} - -/**Function************************************************************* - - Synopsis [Transfers the AIG from one manager into another.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_Transfer_rec( Dar_Man_t * pDest, Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) || Dar_ObjIsMarkA(pObj) ) - return; - Dar_Transfer_rec( pDest, Dar_ObjFanin0(pObj) ); - Dar_Transfer_rec( pDest, Dar_ObjFanin1(pObj) ); - pObj->pData = Dar_And( pDest, Dar_ObjChild0Copy(pObj), Dar_ObjChild1Copy(pObj) ); - assert( !Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Transfers the AIG from one manager into another.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Transfer( Dar_Man_t * pSour, Dar_Man_t * pDest, Dar_Obj_t * pRoot, int nVars ) -{ - Dar_Obj_t * pObj; - int i; - // solve simple cases - if ( pSour == pDest ) - return pRoot; - if ( Dar_ObjIsConst1( Dar_Regular(pRoot) ) ) - return Dar_NotCond( Dar_ManConst1(pDest), Dar_IsComplement(pRoot) ); - // set the PI mapping - Dar_ManForEachPi( pSour, pObj, i ) - { - if ( i == nVars ) - break; - pObj->pData = Dar_IthVar(pDest, i); - } - // transfer and set markings - Dar_Transfer_rec( pDest, Dar_Regular(pRoot) ); - // clear the markings - Dar_ConeUnmark_rec( Dar_Regular(pRoot) ); - return Dar_NotCond( Dar_Regular(pRoot)->pData, Dar_IsComplement(pRoot) ); -} - -/**Function************************************************************* - - Synopsis [Composes the AIG (pRoot) with the function (pFunc) using PI var (iVar).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_Compose_rec( Dar_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pFunc, Dar_Obj_t * pVar ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( Dar_ObjIsMarkA(pObj) ) - return; - if ( Dar_ObjIsConst1(pObj) || Dar_ObjIsPi(pObj) ) - { - pObj->pData = pObj == pVar ? pFunc : pObj; - return; - } - Dar_Compose_rec( p, Dar_ObjFanin0(pObj), pFunc, pVar ); - Dar_Compose_rec( p, Dar_ObjFanin1(pObj), pFunc, pVar ); - pObj->pData = Dar_And( p, Dar_ObjChild0Copy(pObj), Dar_ObjChild1Copy(pObj) ); - assert( !Dar_ObjIsMarkA(pObj) ); // loop detection - Dar_ObjSetMarkA( pObj ); -} - -/**Function************************************************************* - - Synopsis [Composes the AIG (pRoot) with the function (pFunc) using PI var (iVar).] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Compose( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Obj_t * pFunc, int iVar ) -{ - // quit if the PI variable is not defined - if ( iVar >= Dar_ManPiNum(p) ) - { - printf( "Dar_Compose(): The PI variable %d is not defined.\n", iVar ); - return NULL; - } - // recursively perform composition - Dar_Compose_rec( p, Dar_Regular(pRoot), pFunc, Dar_ManPi(p, iVar) ); - // clear the markings - Dar_ConeUnmark_rec( Dar_Regular(pRoot) ); - return Dar_NotCond( Dar_Regular(pRoot)->pData, Dar_IsComplement(pRoot) ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darInt.h b/src/aig/dar/darInt.h new file mode 100644 index 00000000..0eb8f9fe --- /dev/null +++ b/src/aig/dar/darInt.h @@ -0,0 +1,158 @@ +/**CFile**************************************************************** + + FileName [darInt.h] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [DAG-aware AIG rewriting.] + + Synopsis [Internal declarations.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - April 28, 2007.] + + Revision [$Id: darInt.h,v 1.00 2007/04/28 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#ifndef __DAR_INT_H__ +#define __DAR_INT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//////////////////////////////////////////////////////////////////////// +/// INCLUDES /// +//////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include + +#include "vec.h" +#include "aig.h" +#include "dar.h" + +//////////////////////////////////////////////////////////////////////// +/// PARAMETERS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// BASIC TYPES /// +//////////////////////////////////////////////////////////////////////// + +typedef struct Dar_Man_t_ Dar_Man_t; +typedef struct Dar_Cut_t_ Dar_Cut_t; + +// the AIG 4-cut +struct Dar_Cut_t_ // 6 words +{ + unsigned uSign; // cut signature + unsigned uTruth : 16; // the truth table of the cut function + unsigned Value : 12; // the value of the cut + unsigned fUsed : 1; // marks the cut currently in use + unsigned nLeaves : 3; // the number of leaves + int pLeaves[4]; // the array of leaves +}; + +// the AIG manager +struct Dar_Man_t_ +{ + // input data; + Dar_Par_t * pPars; // rewriting parameters + Aig_Man_t * pAig; // AIG manager + // various data members + Aig_MmFixed_t * pMemCuts; // memory manager for cuts + void * pManCnf; // CNF managers + // current rewriting step + Vec_Ptr_t * vLeavesBest; // the best set of leaves + int OutBest; // the best output (in the library) + int OutNumBest; // the best number of the output + int GainBest; // the best gain + int LevelBest; // the level of node with the best gain + int ClassBest; // the equivalence class of the best replacement + // function statistics + int nTotalSubgs; // the total number of subgraphs tried + int ClassTimes[222];// the runtimes for each class + int ClassGains[222];// the gains for each class + int ClassSubgs[222];// the graphs for each class + int nCutMemUsed; // memory used for cuts + // rewriting statistics + int nNodesInit; // the original number of nodes + int nCutsAll; // all cut pairs + int nCutsTried; // computed cuts + int nCutsUsed; // used cuts + int nCutsBad; // bad cuts due to absent fanin + int nCutsGood; // good cuts + int nCutsSkipped; // skipped bad cuts + // timing statistics + int timeCuts; + int timeEval; + int timeOther; + int timeTotal; + int time1; + int time2; +}; + +static inline Dar_Cut_t * Dar_ObjCuts( Aig_Obj_t * pObj ) { return pObj->pData; } +static inline void Dar_ObjSetCuts( Aig_Obj_t * pObj, Dar_Cut_t * pCuts ) { pObj->pData = pCuts; } + +//////////////////////////////////////////////////////////////////////// +/// MACRO DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// ITERATORS /// +//////////////////////////////////////////////////////////////////////// + +// iterator over all cuts of the node +#define Dar_ObjForEachCutAll( pObj, pCut, i ) \ + for ( (pCut) = Dar_ObjCuts(pObj), i = 0; i < (int)(pObj)->nCuts; i++, pCut++ ) +#define Dar_ObjForEachCut( pObj, pCut, i ) \ + for ( (pCut) = Dar_ObjCuts(pObj), i = 0; i < (int)(pObj)->nCuts; i++, pCut++ ) if ( (pCut)->fUsed==0 ) {} else +// iterator over leaves of the cut +#define Dar_CutForEachLeaf( p, pCut, pLeaf, i ) \ + for ( i = 0; (i < (int)(pCut)->nLeaves) && (((pLeaf) = Aig_ManObj(p, (pCut)->pLeaves[i])), 1); i++ ) + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/*=== darBalance.c ========================================================*/ +extern Aig_Man_t * Dar_ManBalance( Aig_Man_t * p, int fUpdateLevel ); +/*=== darCore.c ========================================================*/ +/*=== darCut.c ========================================================*/ +extern Dar_Cut_t * Dar_ObjPrepareCuts( Dar_Man_t * p, Aig_Obj_t * pObj ); +extern void Dar_ManCutsFree( Dar_Man_t * p ); +extern Dar_Cut_t * Dar_ObjComputeCuts_rec( Dar_Man_t * p, Aig_Obj_t * pObj ); +extern Dar_Cut_t * Dar_ObjComputeCuts( Dar_Man_t * p, Aig_Obj_t * pObj ); +/*=== darData.c ========================================================*/ +extern Vec_Int_t * Dar_LibReadNodes(); +extern Vec_Int_t * Dar_LibReadOuts(); +extern Vec_Int_t * Dar_LibReadPrios(); +/*=== darLib.c ==========================================================*/ +extern void Dar_LibStart(); +extern void Dar_LibStop(); +extern void Dar_LibEval( Dar_Man_t * p, Aig_Obj_t * pRoot, Dar_Cut_t * pCut, int Required ); +extern Aig_Obj_t * Dar_LibBuildBest( Dar_Man_t * p ); +/*=== darMan.c ==========================================================*/ +extern Dar_Man_t * Dar_ManStart( Aig_Man_t * pAig, Dar_Par_t * pPars ); +extern void Dar_ManStop( Dar_Man_t * p ); +extern void Dar_ManPrintStats( Dar_Man_t * p ); + +#ifdef __cplusplus +} +#endif + +#endif + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + diff --git a/src/aig/dar/darLib.c b/src/aig/dar/darLib.c index 89ce2f0b..fce6155b 100644 --- a/src/aig/dar/darLib.c +++ b/src/aig/dar/darLib.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -41,7 +41,7 @@ struct Dar_LibObj_t_ // library object (2 words) struct Dar_LibDat_t_ // library object data { - Dar_Obj_t * pFunc; // the corresponding AIG node if it exists + Aig_Obj_t * pFunc; // the corresponding AIG node if it exists int Level; // level of this node after it is constructured int TravId; // traversal ID of the library object data unsigned char Area; // area of the node @@ -61,7 +61,16 @@ struct Dar_Lib_t_ // library int nSubgr[222]; // the number of subgraphs by class int * pSubgr[222]; // the subgraphs for each class int * pSubgrMem; // memory for subgraph pointers - int pSubgrTotal; // the total number of subgraph + int nSubgrTotal; // the total number of subgraph + // structure priorities + int * pPriosMem; // memory for priority of structures + int * pPrios[222]; // pointers to the priority numbers + // structure places in the priorities + int * pPlaceMem; // memory for places of structures in the priority lists + int * pPlace[222]; // pointers to the places numbers + // structure scores + int * pScoreMem; // memory for scores of structures + int * pScore[222]; // pointers to the scores numbers // nodes by class int nNodes[222]; // the number of nodes by class int * pNodes[222]; // the nodes for each class @@ -141,6 +150,9 @@ void Dar_LibFree( Dar_Lib_t * p ) free( p->pDatas ); free( p->pNodesMem ); free( p->pSubgrMem ); + free( p->pPriosMem ); + FREE( p->pPlaceMem ); + FREE( p->pScoreMem ); free( p->pPerms4 ); free( p->puCanons ); free( p->pPhases ); @@ -208,8 +220,9 @@ void Dar_LibSetup_rec( Dar_Lib_t * p, Dar_LibObj_t * pObj, int Class ) SeeAlso [] ***********************************************************************/ -void Dar_LibSetup( Dar_Lib_t * p, Vec_Int_t * vOuts ) +void Dar_LibSetup( Dar_Lib_t * p, Vec_Int_t * vOuts, Vec_Int_t * vPrios ) { + int fTraining = 0; Dar_LibObj_t * pObj; int nNodesTotal, uTruth, Class, Out, i, k; assert( p->iObj == p->nObjs ); @@ -226,14 +239,14 @@ void Dar_LibSetup( Dar_Lib_t * p, Vec_Int_t * vOuts ) } // allocate memory for the roots of each class p->pSubgrMem = ALLOC( int, Vec_IntSize(vOuts) ); - p->pSubgrTotal = 0; + p->nSubgrTotal = 0; for ( i = 0; i < 222; i++ ) { - p->pSubgr[i] = p->pSubgrMem + p->pSubgrTotal; - p->pSubgrTotal += p->nSubgr[i]; + p->pSubgr[i] = p->pSubgrMem + p->nSubgrTotal; + p->nSubgrTotal += p->nSubgr[i]; p->nSubgr[i] = 0; } - assert( p->pSubgrTotal == Vec_IntSize(vOuts) ); + assert( p->nSubgrTotal == Vec_IntSize(vOuts) ); // add the outputs to storage Vec_IntForEachEntry( vOuts, Out, i ) { @@ -243,6 +256,65 @@ void Dar_LibSetup( Dar_Lib_t * p, Vec_Int_t * vOuts ) p->pSubgr[Class][ p->nSubgr[Class]++ ] = Out; } + if ( fTraining ) + { + // allocate memory for the priority of roots of each class + p->pPriosMem = ALLOC( int, Vec_IntSize(vOuts) ); + p->nSubgrTotal = 0; + for ( i = 0; i < 222; i++ ) + { + p->pPrios[i] = p->pPriosMem + p->nSubgrTotal; + p->nSubgrTotal += p->nSubgr[i]; + for ( k = 0; k < p->nSubgr[i]; k++ ) + p->pPrios[i][k] = k; + + } + assert( p->nSubgrTotal == Vec_IntSize(vOuts) ); + + // allocate memory for the priority of roots of each class + p->pPlaceMem = ALLOC( int, Vec_IntSize(vOuts) ); + p->nSubgrTotal = 0; + for ( i = 0; i < 222; i++ ) + { + p->pPlace[i] = p->pPlaceMem + p->nSubgrTotal; + p->nSubgrTotal += p->nSubgr[i]; + for ( k = 0; k < p->nSubgr[i]; k++ ) + p->pPlace[i][k] = k; + + } + assert( p->nSubgrTotal == Vec_IntSize(vOuts) ); + + // allocate memory for the priority of roots of each class + p->pScoreMem = ALLOC( int, Vec_IntSize(vOuts) ); + p->nSubgrTotal = 0; + for ( i = 0; i < 222; i++ ) + { + p->pScore[i] = p->pScoreMem + p->nSubgrTotal; + p->nSubgrTotal += p->nSubgr[i]; + for ( k = 0; k < p->nSubgr[i]; k++ ) + p->pScore[i][k] = 0; + + } + assert( p->nSubgrTotal == Vec_IntSize(vOuts) ); + } + else + { + int Counter = 0; + // allocate memory for the priority of roots of each class + p->pPriosMem = ALLOC( int, Vec_IntSize(vOuts) ); + p->nSubgrTotal = 0; + for ( i = 0; i < 222; i++ ) + { + p->pPrios[i] = p->pPriosMem + p->nSubgrTotal; + p->nSubgrTotal += p->nSubgr[i]; + for ( k = 0; k < p->nSubgr[i]; k++ ) + p->pPrios[i][k] = Vec_IntEntry(vPrios, Counter++); + + } + assert( p->nSubgrTotal == Vec_IntSize(vOuts) ); + assert( Counter == Vec_IntSize(vPrios) ); + } + // create traversal IDs for ( i = 0; i < p->iObj; i++ ) Dar_LibObj(p, i)->Num = 0xff; @@ -294,12 +366,13 @@ void Dar_LibSetup( Dar_Lib_t * p, Vec_Int_t * vOuts ) ***********************************************************************/ Dar_Lib_t * Dar_LibRead() { - Vec_Int_t * vObjs, * vOuts; + Vec_Int_t * vObjs, * vOuts, * vPrios; Dar_Lib_t * p; int i; // read nodes and outputs - vObjs = Dar_LibReadNodes(); - vOuts = Dar_LibReadOuts(); + vObjs = Dar_LibReadNodes(); + vOuts = Dar_LibReadOuts(); + vPrios = Dar_LibReadPrios(); // create library p = Dar_LibAlloc( Vec_IntSize(vObjs)/2 + 4, 6000 ); // create nodes @@ -307,7 +380,7 @@ Dar_Lib_t * Dar_LibRead() Dar_LibAddNode( p, vObjs->pArray[i] >> 1, vObjs->pArray[i+1] >> 1, vObjs->pArray[i] & 1, vObjs->pArray[i+1] & 1 ); // create outputs - Dar_LibSetup( p, vOuts ); + Dar_LibSetup( p, vOuts, vPrios ); Vec_IntFree( vObjs ); Vec_IntFree( vOuts ); return p; @@ -329,7 +402,7 @@ void Dar_LibStart() int clk = clock(); assert( s_DarLib == NULL ); s_DarLib = Dar_LibRead(); - printf( "The 4-input library started with %d nodes and %d subgraphs. ", s_DarLib->nObjs - 4, s_DarLib->pSubgrTotal ); + printf( "The 4-input library started with %d nodes and %d subgraphs. ", s_DarLib->nObjs - 4, s_DarLib->nSubgrTotal ); PRT( "Time", clock() - clk ); } @@ -351,6 +424,77 @@ void Dar_LibStop() s_DarLib = NULL; } +/**Function************************************************************* + + Synopsis [Updates the score of the class and adjusts the priority of this class.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Dar_LibIncrementScore( int Class, int Out, int Gain ) +{ + int * pPrios = s_DarLib->pPrios[Class]; // pPrios[i] = Out + int * pPlace = s_DarLib->pPlace[Class]; // pPlace[Out] = i + int * pScore = s_DarLib->pScore[Class]; // score of Out + int Out2; + assert( Class >= 0 && Class < 222 ); + assert( Out >= 0 && Out < s_DarLib->nSubgr[Class] ); + assert( pPlace[pPrios[Out]] == Out ); + // increment the score + pScore[Out] += Gain; + // move the out in the order + while ( pPlace[Out] > 0 && pScore[Out] > pScore[ pPrios[pPlace[Out]-1] ] ) + { + // get the previous output in the priority list + Out2 = pPrios[pPlace[Out]-1]; + // swap Out and Out2 + pPlace[Out]--; + pPlace[Out2]++; + pPrios[pPlace[Out]] = Out; + pPrios[pPlace[Out2]] = Out2; + } +} + +/**Function************************************************************* + + Synopsis [Prints out the priorities into the file.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Dar_LibDumpPriorities() +{ + int i, k, Out, Out2, Counter = 0, Printed = 0; + printf( "\nOutput priorities (total = %d):\n", s_DarLib->nSubgrTotal ); + for ( i = 0; i < 222; i++ ) + { +// printf( "Class%d: ", i ); + for ( k = 0; k < s_DarLib->nSubgr[i]; k++ ) + { + Out = s_DarLib->pPrios[i][k]; + Out2 = k == 0 ? Out : s_DarLib->pPrios[i][k-1]; + assert( s_DarLib->pScore[i][Out2] >= s_DarLib->pScore[i][Out] ); +// printf( "%d(%d), ", Out, s_DarLib->pScore[i][Out] ); + printf( "%d, ", Out ); + Printed++; + if ( ++Counter == 15 ) + { + printf( "\n" ); + Counter = 0; + } + } + } + printf( "\n" ); + assert( Printed == s_DarLib->nSubgrTotal ); +} /**Function************************************************************* @@ -366,7 +510,7 @@ void Dar_LibStop() ***********************************************************************/ int Dar_LibCutMatch( Dar_Man_t * p, Dar_Cut_t * pCut ) { - Dar_Obj_t * pFanin; + Aig_Obj_t * pFanin; unsigned uPhase; char * pPerm; int i; @@ -377,16 +521,15 @@ int Dar_LibCutMatch( Dar_Man_t * p, Dar_Cut_t * pCut ) // collect fanins with the corresponding permutation/phase for ( i = 0; i < (int)pCut->nLeaves; i++ ) { - pFanin = Dar_ManObj( p, pCut->pLeaves[pPerm[i]] ); + pFanin = Aig_ManObj( p->pAig, pCut->pLeaves[pPerm[i]] ); if ( pFanin == NULL ) { p->nCutsBad++; return 0; } - pFanin = Dar_NotCond(pFanin, ((uPhase >> i) & 1) ); -// Vec_PtrWriteEntry( p->vFaninsCur, i, pFanin ); + pFanin = Aig_NotCond(pFanin, ((uPhase >> i) & 1) ); s_DarLib->pDatas[i].pFunc = pFanin; - s_DarLib->pDatas[i].Level = Dar_Regular(pFanin)->Level; + s_DarLib->pDatas[i].Level = Aig_Regular(pFanin)->Level; } p->nCutsGood++; return 1; @@ -405,22 +548,22 @@ int Dar_LibCutMatch( Dar_Man_t * p, Dar_Cut_t * pCut ) SeeAlso [] ***********************************************************************/ -int Dar_NodeDeref_rec( Dar_Man_t * p, Dar_Obj_t * pNode ) +int Aig_NodeDeref_rec( Aig_Man_t * p, Aig_Obj_t * pNode ) { - Dar_Obj_t * pFanin; + Aig_Obj_t * pFanin; int Counter = 0; - if ( Dar_ObjIsPi(pNode) ) + if ( Aig_ObjIsPi(pNode) ) return Counter; - pFanin = Dar_ObjFanin0( pNode ); + pFanin = Aig_ObjFanin0( pNode ); assert( pFanin->nRefs > 0 ); if ( --pFanin->nRefs == 0 ) - Counter += Dar_NodeDeref_rec( p, pFanin ); - if ( Dar_ObjIsBuf(pNode) ) + Counter += Aig_NodeDeref_rec( p, pFanin ); + if ( Aig_ObjIsBuf(pNode) ) return Counter; - pFanin = Dar_ObjFanin1( pNode ); + pFanin = Aig_ObjFanin1( pNode ); assert( pFanin->nRefs > 0 ); if ( --pFanin->nRefs == 0 ) - Counter += Dar_NodeDeref_rec( p, pFanin ); + Counter += Aig_NodeDeref_rec( p, pFanin ); return 1 + Counter; } @@ -435,21 +578,21 @@ int Dar_NodeDeref_rec( Dar_Man_t * p, Dar_Obj_t * pNode ) SeeAlso [] ***********************************************************************/ -int Dar_NodeRef_rec( Dar_Man_t * p, Dar_Obj_t * pNode ) +int Aig_NodeRef_rec( Aig_Man_t * p, Aig_Obj_t * pNode ) { - Dar_Obj_t * pFanin; + Aig_Obj_t * pFanin; int Counter = 0; - if ( Dar_ObjIsPi(pNode) ) + if ( Aig_ObjIsPi(pNode) ) return Counter; - Dar_ObjSetTravIdCurrent( p, pNode ); - pFanin = Dar_ObjFanin0( pNode ); + Aig_ObjSetTravIdCurrent( p, pNode ); + pFanin = Aig_ObjFanin0( pNode ); if ( pFanin->nRefs++ == 0 ) - Counter += Dar_NodeRef_rec( p, pFanin ); - if ( Dar_ObjIsBuf(pNode) ) + Counter += Aig_NodeRef_rec( p, pFanin ); + if ( Aig_ObjIsBuf(pNode) ) return Counter; - pFanin = Dar_ObjFanin1( pNode ); + pFanin = Aig_ObjFanin1( pNode ); if ( pFanin->nRefs++ == 0 ) - Counter += Dar_NodeRef_rec( p, pFanin ); + Counter += Aig_NodeRef_rec( p, pFanin ); return 1 + Counter; } @@ -464,20 +607,20 @@ int Dar_NodeRef_rec( Dar_Man_t * p, Dar_Obj_t * pNode ) SeeAlso [] ***********************************************************************/ -int Dar_LibCutMarkMffc( Dar_Man_t * p, Dar_Obj_t * pRoot ) +int Dar_LibCutMarkMffc( Aig_Man_t * p, Aig_Obj_t * pRoot, int nLeaves ) { int i, nNodes1, nNodes2; // mark the cut leaves - for ( i = 0; i < 4; i++ ) - Dar_Regular(s_DarLib->pDatas[i].pFunc)->nRefs++; + for ( i = 0; i < nLeaves; i++ ) + Aig_Regular(s_DarLib->pDatas[i].pFunc)->nRefs++; // label MFFC with current ID - Dar_ManIncrementTravId( p ); - nNodes1 = Dar_NodeDeref_rec( p, pRoot ); - nNodes2 = Dar_NodeRef_rec( p, pRoot ); + Aig_ManIncrementTravId( p ); + nNodes1 = Aig_NodeDeref_rec( p, pRoot ); + nNodes2 = Aig_NodeRef_rec( p, pRoot ); assert( nNodes1 == nNodes2 ); // unmark the cut leaves - for ( i = 0; i < 4; i++ ) - Dar_Regular(s_DarLib->pDatas[i].pFunc)->nRefs--; + for ( i = 0; i < nLeaves; i++ ) + Aig_Regular(s_DarLib->pDatas[i].pFunc)->nRefs--; return nNodes1; } @@ -525,7 +668,7 @@ void Dar_LibEvalAssignNums( Dar_Man_t * p, int Class ) { Dar_LibObj_t * pObj; Dar_LibDat_t * pData, * pData0, * pData1; - Dar_Obj_t * pGhost, * pFanin0, * pFanin1; + Aig_Obj_t * pGhost, * pFanin0, * pFanin1; int i; for ( i = 0; i < s_DarLib->nNodes[Class]; i++ ) { @@ -538,15 +681,29 @@ void Dar_LibEvalAssignNums( Dar_Man_t * p, int Class ) // explore the fanins pData0 = s_DarLib->pDatas + Dar_LibObj(s_DarLib, pObj->Fan0)->Num; pData1 = s_DarLib->pDatas + Dar_LibObj(s_DarLib, pObj->Fan1)->Num; - pData->Level = 1 + DAR_MAX(pData0->Level, pData1->Level); + pData->Level = 1 + AIG_MAX(pData0->Level, pData1->Level); if ( pData0->pFunc == NULL || pData1->pFunc == NULL ) continue; - pFanin0 = Dar_NotCond( pData0->pFunc, pObj->fCompl0 ); - pFanin1 = Dar_NotCond( pData1->pFunc, pObj->fCompl1 ); - pGhost = Dar_ObjCreateGhost( p, pFanin0, pFanin1, DAR_AIG_AND ); - pData->pFunc = Dar_TableLookup( p, pGhost ); + pFanin0 = Aig_NotCond( pData0->pFunc, pObj->fCompl0 ); + pFanin1 = Aig_NotCond( pData1->pFunc, pObj->fCompl1 ); + + // consider simple cases + if ( pFanin0 == pFanin1 ) + pData->pFunc = pFanin0; + else if ( pFanin0 == Aig_Not(pFanin1) ) + pData->pFunc = Aig_ManConst0(p->pAig); + else if ( Aig_Regular(pFanin0) == Aig_ManConst1(p->pAig) ) + pData->pFunc = pFanin0 == Aig_ManConst1(p->pAig) ? pFanin1 : Aig_ManConst0(p->pAig); + else if ( Aig_Regular(pFanin1) == Aig_ManConst1(p->pAig) ) + pData->pFunc = pFanin1 == Aig_ManConst1(p->pAig) ? pFanin0 : Aig_ManConst0(p->pAig); + else + { + pGhost = Aig_ObjCreateGhost( p->pAig, pFanin0, pFanin1, AIG_OBJ_AND ); + pData->pFunc = Aig_TableLookup( p->pAig, pGhost ); + } + // clear the node if it is part of MFFC - if ( pData->pFunc != NULL && Dar_ObjIsTravIdCurrent(p, pData->pFunc) ) + if ( pData->pFunc != NULL && Aig_ObjIsTravIdCurrent(p->pAig, pData->pFunc) ) pData->pFunc = NULL; //if ( Class == 7 ) //printf( "Evaling node %d at data %d\n", pData->pFunc? pData->pFunc->Id : -1, pObj->Num ); @@ -599,44 +756,32 @@ int Dar_LibEval_rec( Dar_LibObj_t * pObj, int Out, int nNodesSaved, int Required SeeAlso [] ***********************************************************************/ -void Dar_LibEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCut, int Required ) +void Dar_LibEval( Dar_Man_t * p, Aig_Obj_t * pRoot, Dar_Cut_t * pCut, int Required ) { + int fTraining = 0; Dar_LibObj_t * pObj; - int i, k, Class, nNodesSaved, nNodesAdded, nNodesGained, clk; + int Out, k, Class, nNodesSaved, nNodesAdded, nNodesGained, clk; + clk = clock(); if ( pCut->nLeaves != 4 ) return; -// if ( s_DarLib->nSubgr[ s_DarLib->pMap[pCut->uTruth] ] > 100 ) -// return; - clk = clock(); -/* - for ( k = 0; k < 4; k++ ) - if ( pCut->pLeaves[k] > 4 ) - return; -*/ - // check if the cut exits + // check if the cut exits and assigns leaves and their levels if ( !Dar_LibCutMatch(p, pCut) ) return; // mark MFFC of the node - nNodesSaved = Dar_LibCutMarkMffc( p, pRoot ); + nNodesSaved = Dar_LibCutMarkMffc( p->pAig, pRoot, pCut->nLeaves ); // evaluate the cut Class = s_DarLib->pMap[pCut->uTruth]; Dar_LibEvalAssignNums( p, Class ); - -//if ( pRoot->Id == 654 ) -//printf( "\n" ); // profile outputs by their savings p->nTotalSubgs += s_DarLib->nSubgr[Class]; p->ClassSubgs[Class] += s_DarLib->nSubgr[Class]; - for ( i = 0; i < s_DarLib->nSubgr[Class]; i++ ) + for ( Out = 0; Out < s_DarLib->nSubgr[Class]; Out++ ) { - pObj = Dar_LibObj(s_DarLib, s_DarLib->pSubgr[Class][i]); - if ( pRoot->Id == 654 ) - { -// Dar_LibObjPrint_rec( pObj ); -// printf( "\n" ); - } - nNodesAdded = Dar_LibEval_rec( pObj, i, nNodesSaved, Required ); + pObj = Dar_LibObj(s_DarLib, s_DarLib->pSubgr[Class][Out]); + nNodesAdded = Dar_LibEval_rec( pObj, Out, nNodesSaved, Required ); nNodesGained = nNodesSaved - nNodesAdded; + if ( fTraining && nNodesGained >= 0 ) + Dar_LibIncrementScore( Class, Out, nNodesGained + 1 ); if ( nNodesGained <= 0 ) continue; if ( nNodesGained < p->GainBest || @@ -644,10 +789,10 @@ void Dar_LibEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCut, int Requir continue; // remember this possibility Vec_PtrClear( p->vLeavesBest ); - for ( k = 0; k < 4; k++ ) + for ( k = 0; k < (int)pCut->nLeaves; k++ ) Vec_PtrPush( p->vLeavesBest, s_DarLib->pDatas[k].pFunc ); - p->OutBest = s_DarLib->pSubgr[Class][i]; - p->OutNumBest = i; + p->OutBest = s_DarLib->pSubgr[Class][Out]; + p->OutNumBest = Out; p->LevelBest = s_DarLib->pDatas[pObj->Num].Level; p->GainBest = nNodesGained; p->ClassBest = Class; @@ -689,17 +834,17 @@ void Dar_LibBuildClear_rec( Dar_LibObj_t * pObj, int * pCounter ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Dar_LibBuildBest_rec( Dar_Man_t * p, Dar_LibObj_t * pObj ) +Aig_Obj_t * Dar_LibBuildBest_rec( Dar_Man_t * p, Dar_LibObj_t * pObj ) { - Dar_Obj_t * pFanin0, * pFanin1; + Aig_Obj_t * pFanin0, * pFanin1; Dar_LibDat_t * pData = s_DarLib->pDatas + pObj->Num; if ( pData->pFunc ) return pData->pFunc; pFanin0 = Dar_LibBuildBest_rec( p, Dar_LibObj(s_DarLib, pObj->Fan0) ); pFanin1 = Dar_LibBuildBest_rec( p, Dar_LibObj(s_DarLib, pObj->Fan1) ); - pFanin0 = Dar_NotCond( pFanin0, pObj->fCompl0 ); - pFanin1 = Dar_NotCond( pFanin1, pObj->fCompl1 ); - pData->pFunc = Dar_And( p, pFanin0, pFanin1 ); + pFanin0 = Aig_NotCond( pFanin0, pObj->fCompl0 ); + pFanin1 = Aig_NotCond( pFanin1, pObj->fCompl1 ); + pData->pFunc = Aig_And( p->pAig, pFanin0, pFanin1 ); //printf( "Adding node %d for data %d\n", pData->pFunc->Id, pObj->Num ); return pData->pFunc; } @@ -715,15 +860,16 @@ Dar_Obj_t * Dar_LibBuildBest_rec( Dar_Man_t * p, Dar_LibObj_t * pObj ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Dar_LibBuildBest( Dar_Man_t * p ) +Aig_Obj_t * Dar_LibBuildBest( Dar_Man_t * p ) { int i, Counter = 4; - for ( i = 0; i < 4; i++ ) + for ( i = 0; i < Vec_PtrSize(p->vLeavesBest); i++ ) s_DarLib->pDatas[i].pFunc = Vec_PtrEntry( p->vLeavesBest, i ); Dar_LibBuildClear_rec( Dar_LibObj(s_DarLib, p->OutBest), &Counter ); return Dar_LibBuildBest_rec( p, Dar_LibObj(s_DarLib, p->OutBest) ); } + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/aig/dar/darMan.c b/src/aig/dar/darMan.c index 52df8890..a209503a 100644 --- a/src/aig/dar/darMan.c +++ b/src/aig/dar/darMan.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -30,48 +30,25 @@ /**Function************************************************************* - Synopsis [Starts the AIG manager.] + Synopsis [Starts the rewriting manager.] - Description [The argument of this procedure is a soft limit on the - the number of nodes, or 0 if the limit is unknown.] + Description [] SideEffects [] SeeAlso [] ***********************************************************************/ -Dar_Man_t * Dar_ManStart( int nNodesMax ) +Dar_Man_t * Dar_ManStart( Aig_Man_t * pAig, Dar_Par_t * pPars ) { Dar_Man_t * p; - int i; - if ( nNodesMax <= 0 ) - nNodesMax = 10007; // start the manager p = ALLOC( Dar_Man_t, 1 ); memset( p, 0, sizeof(Dar_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->pPars = pPars; + p->pAig = pAig; // prepare the internal memory manager - p->pMemObjs = Dar_MmFixedStart( sizeof(Dar_Obj_t), nNodesMax ); - p->pMemCuts = Dar_MmFlexStart(); - // prepare storage for cuts - p->nBaseCuts = DAR_CUT_BASE; - for ( i = 0; i < p->nBaseCuts; i++ ) - p->pBaseCuts[i] = p->BaseCuts + i; - // create the constant node - p->pConst1 = Dar_ManFetchMemory( p ); - p->pConst1->Type = DAR_AIG_CONST1; - p->pConst1->fPhase = 1; - p->nObjs[DAR_AIG_CONST1]++; - // start the table - p->nTableSize = nNodesMax; - p->pTable = ALLOC( Dar_Obj_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Dar_Obj_t *) * p->nTableSize ); + p->pMemCuts = Aig_MmFixedStart( p->pPars->nCutsMax * sizeof(Dar_Cut_t), 512 ); // other data p->vLeavesBest = Vec_PtrAlloc( 4 ); return p; @@ -79,69 +56,7 @@ Dar_Man_t * Dar_ManStart( int nNodesMax ) /**Function************************************************************* - Synopsis [Duplicates the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Man_t * Dar_ManStartFrom( Dar_Man_t * p ) -{ - Dar_Man_t * pNew; - Dar_Obj_t * pObj; - int i; - // create the new manager - pNew = Dar_ManStart( Dar_ManObjIdMax(p) + 1 ); - // create the PIs - Dar_ManConst1(p)->pData = Dar_ManConst1(pNew); - Dar_ManForEachPi( p, pObj, i ) - pObj->pData = Dar_ObjCreatePi(pNew); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Duplicates the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Man_t * Dar_ManDup( Dar_Man_t * p ) -{ - Dar_Man_t * pNew; - Dar_Obj_t * pObj; - int i; - // create the new manager - pNew = Dar_ManStart( Dar_ManObjIdMax(p) + 1 ); - // create the PIs - Dar_ManConst1(p)->pData = Dar_ManConst1(pNew); - Dar_ManForEachPi( p, pObj, i ) - pObj->pData = Dar_ObjCreatePi(pNew); - // duplicate internal nodes - Dar_ManForEachObj( p, pObj, i ) - if ( Dar_ObjIsBuf(pObj) ) - pObj->pData = Dar_ObjChild0Copy(pObj); - else if ( Dar_ObjIsNode(pObj) ) - pObj->pData = Dar_And( pNew, Dar_ObjChild0Copy(pObj), Dar_ObjChild1Copy(pObj) ); - // add the POs - Dar_ManForEachPo( p, pObj, i ) - Dar_ObjCreatePo( pNew, Dar_ObjChild0Copy(pObj) ); - // check the resulting network - if ( !Dar_ManCheck(pNew) ) - printf( "Dar_ManDup(): The check has failed.\n" ); - return pNew; -} - -/**Function************************************************************* - - Synopsis [Stops the AIG manager.] + Synopsis [Stops the rewriting manager.] Description [] @@ -152,55 +67,15 @@ Dar_Man_t * Dar_ManDup( Dar_Man_t * p ) ***********************************************************************/ void Dar_ManStop( Dar_Man_t * p ) { - Dar_Obj_t * pObj; - int i; - // make sure the nodes have clean marks - Dar_ManForEachObj( p, pObj, i ) - assert( !pObj->fMarkA && !pObj->fMarkB ); - // print time - if ( p->time1 ) { PRT( "time1", p->time1 ); } - if ( p->time2 ) { PRT( "time2", p->time2 ); } -// Dar_TableProfile( p ); - Dar_MmFixedStop( p->pMemObjs, 0 ); - Dar_MmFlexStop( p->pMemCuts, 0 ); - if ( p->vPis ) Vec_PtrFree( p->vPis ); - if ( p->vPos ) Vec_PtrFree( p->vPos ); - if ( p->vObjs ) Vec_PtrFree( p->vObjs ); - if ( p->vRequired ) Vec_IntFree( p->vRequired ); - if ( p->vLeavesBest ) Vec_PtrFree( p->vLeavesBest ); - free( p->pTable ); + if ( p->pPars->fVerbose ) + Dar_ManPrintStats( p ); + if ( p->pMemCuts ) + Aig_MmFixedStop( p->pMemCuts, 0 ); + if ( p->vLeavesBest ) + Vec_PtrFree( p->vLeavesBest ); free( p ); } -/**Function************************************************************* - - Synopsis [Returns the number of dangling nodes removed.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManCleanup( Dar_Man_t * p ) -{ - Vec_Ptr_t * vObjs; - Dar_Obj_t * pNode; - int i, nNodesOld; - nNodesOld = Dar_ManNodeNum(p); - // collect roots of dangling nodes - vObjs = Vec_PtrAlloc( 100 ); - Dar_ManForEachObj( p, pNode, i ) - if ( Dar_ObjIsNode(pNode) && Dar_ObjRefs(pNode) == 0 ) - Vec_PtrPush( vObjs, pNode ); - // recursively remove dangling nodes - Vec_PtrForEachEntry( vObjs, pNode, i ) - Dar_ObjDelete_rec( p, pNode, 1 ); - Vec_PtrFree( vObjs ); - return nNodesOld - Dar_ManNodeNum(p); -} - /**Function************************************************************* Synopsis [Stops the AIG manager.] @@ -213,40 +88,19 @@ int Dar_ManCleanup( Dar_Man_t * p ) ***********************************************************************/ void Dar_ManPrintStats( Dar_Man_t * p ) -{ - printf( "PI/PO/Lat = %5d/%5d/%5d ", Dar_ManPiNum(p), Dar_ManPoNum(p), Dar_ManLatchNum(p) ); - printf( "A = %6d. ", Dar_ManAndNum(p) ); - if ( Dar_ManExorNum(p) ) - printf( "X = %5d. ", Dar_ManExorNum(p) ); - if ( Dar_ManBufNum(p) ) - printf( "B = %3d. ", Dar_ManBufNum(p) ); - printf( "Cre = %6d. ", p->nCreated ); - printf( "Del = %6d. ", p->nDeleted ); -// printf( "Lev = %3d. ", Dar_ManCountLevels(p) ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Stops the AIG manager.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManPrintRuntime( Dar_Man_t * p ) { int i, Gain; - printf( "Good cuts = %d. Bad cuts = %d. Cut mem = %d Mb\n", - p->nCutsGood, p->nCutsBad, p->nCutMemUsed ); + Gain = p->nNodesInit - Aig_ManNodeNum(p->pAig); + printf( "NodesBeg = %8d. NodesEnd = %8d. Gain = %6d. (%6.2f %%). Cut mem = %d Mb\n", + p->nNodesInit, Aig_ManNodeNum(p->pAig), Gain, 100.0*Gain/p->nNodesInit, p->nCutMemUsed ); + printf( "Cuts = %8d. Tried = %8d. Used = %8d. Bad = %5d. Skipped = %5d. Ave = %.2f.\n", + p->nCutsAll, p->nCutsTried, p->nCutsUsed, p->nCutsBad, p->nCutsSkipped, + (float)p->nCutsUsed/Aig_ManNodeNum(p->pAig) ); PRT( "Cuts ", p->timeCuts ); PRT( "Eval ", p->timeEval ); PRT( "Other ", p->timeOther ); PRT( "TOTAL ", p->timeTotal ); - Gain = p->nNodesInit - Dar_ManNodeNum(p); +/* for ( i = 0; i < 222; i++ ) { if ( p->ClassGains[i] == 0 && p->ClassTimes[i] == 0 ) @@ -257,6 +111,7 @@ void Dar_ManPrintRuntime( Dar_Man_t * p ) printf( "R = %7d ", p->ClassGains[i]? p->ClassSubgs[i]/p->ClassGains[i] : 9999999 ); PRTP( "T", p->ClassTimes[i], p->timeEval ); } +*/ } diff --git a/src/aig/dar/darMem.c b/src/aig/dar/darMem.c deleted file mode 100644 index c2626bb1..00000000 --- a/src/aig/dar/darMem.c +++ /dev/null @@ -1,601 +0,0 @@ -/**CFile**************************************************************** - - FileName [darMem.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [Memory managers.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darMem.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include -#include -#include -#include -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -struct Dar_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 Dar_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 Dar_MmStep_t_ -{ - int nMems; // the number of fixed memory managers employed - Dar_MmFixed_t ** pMems; // memory managers: 2^1 words, 2^2 words, etc - int nMapSize; // the size of the memory array - Dar_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 [] - -***********************************************************************/ -Dar_MmFixed_t * Dar_MmFixedStart( int nEntrySize, int nEntriesMax ) -{ - Dar_MmFixed_t * p; - - p = ALLOC( Dar_MmFixed_t, 1 ); - memset( p, 0, sizeof(Dar_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 Dar_MmFixedStop( Dar_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 * Dar_MmFixedEntryFetch( Dar_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 Dar_MmFixedEntryRecycle( Dar_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 Dar_MmFixedRestart( Dar_MmFixed_t * p ) -{ - int i; - char * pTemp; - - // 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 Dar_MmFixedReadMemUsage( Dar_MmFixed_t * p ) -{ - return p->nMemoryAlloc; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_MmFixedReadMaxEntriesUsed( Dar_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 [] - -***********************************************************************/ -Dar_MmFlex_t * Dar_MmFlexStart() -{ - Dar_MmFlex_t * p; - - p = ALLOC( Dar_MmFlex_t, 1 ); - memset( p, 0, sizeof(Dar_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 Dar_MmFlexStop( Dar_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 * Dar_MmFlexEntryFetch( Dar_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 Dar_MmFlexRestart( Dar_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 Dar_MmFlexReadMemUsage( Dar_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 [] - -***********************************************************************/ -Dar_MmStep_t * Dar_MmStepStart( int nSteps ) -{ - Dar_MmStep_t * p; - int i, k; - p = ALLOC( Dar_MmStep_t, 1 ); - memset( p, 0, sizeof(Dar_MmStep_t) ); - p->nMems = nSteps; - // start the fixed memory managers - p->pMems = ALLOC( Dar_MmFixed_t *, p->nMems ); - for ( i = 0; i < p->nMems; i++ ) - p->pMems[i] = Dar_MmFixedStart( (8<nMapSize = (4<nMems); - p->pMap = ALLOC( Dar_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<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 Dar_MmStepStop( Dar_MmStep_t * p, int fVerbose ) -{ - int i; - for ( i = 0; i < p->nMems; i++ ) - Dar_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 * Dar_MmStepEntryFetch( Dar_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 Dar_MmFixedEntryFetch( p->pMap[nBytes] ); -} - - -/**Function************************************************************* - - Synopsis [Recycles the entry.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_MmStepEntryRecycle( Dar_MmStep_t * p, char * pEntry, int nBytes ) -{ - if ( nBytes == 0 ) - return; - if ( nBytes > p->nMapSize ) - { - free( pEntry ); - return; - } - Dar_MmFixedEntryRecycle( p->pMap[nBytes], pEntry ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_MmStepReadMemUsage( Dar_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/aig/dar/darObj.c b/src/aig/dar/darObj.c deleted file mode 100644 index 85b142e6..00000000 --- a/src/aig/dar/darObj.c +++ /dev/null @@ -1,308 +0,0 @@ -/**CFile**************************************************************** - - FileName [darObj.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [Adding/removing objects.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darObj.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Creates primary input.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_ObjCreatePi( Dar_Man_t * p ) -{ - Dar_Obj_t * pObj; - pObj = Dar_ManFetchMemory( p ); - pObj->Type = DAR_AIG_PI; - Vec_PtrPush( p->vPis, pObj ); - p->nObjs[DAR_AIG_PI]++; - return pObj; -} - -/**Function************************************************************* - - Synopsis [Creates primary output with the given driver.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_ObjCreatePo( Dar_Man_t * p, Dar_Obj_t * pDriver ) -{ - Dar_Obj_t * pObj; - pObj = Dar_ManFetchMemory( p ); - pObj->Type = DAR_AIG_PO; - Vec_PtrPush( p->vPos, pObj ); - // add connections - Dar_ObjConnect( p, pObj, pDriver, NULL ); - // update node counters of the manager - p->nObjs[DAR_AIG_PO]++; - return pObj; -} - - -/**Function************************************************************* - - Synopsis [Create the new node assuming it does not exist.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_ObjCreate( Dar_Man_t * p, Dar_Obj_t * pGhost ) -{ - Dar_Obj_t * pObj; - assert( !Dar_IsComplement(pGhost) ); - assert( Dar_ObjIsHash(pGhost) ); - assert( pGhost == &p->Ghost ); - // get memory for the new object - pObj = Dar_ManFetchMemory( p ); - pObj->Type = pGhost->Type; - // add connections - Dar_ObjConnect( p, pObj, pGhost->pFanin0, pGhost->pFanin1 ); - // update node counters of the manager - p->nObjs[Dar_ObjType(pObj)]++; - assert( pObj->pData == NULL ); - return pObj; -} - -/**Function************************************************************* - - Synopsis [Connect the object to the fanin.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjConnect( Dar_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pFan0, Dar_Obj_t * pFan1 ) -{ - assert( !Dar_IsComplement(pObj) ); - assert( !Dar_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( Dar_ObjFanin0(pObj)->Type > 0 ); - Dar_ObjRef( Dar_ObjFanin0(pObj) ); - } - if ( pFan1 != NULL ) - { - assert( Dar_ObjFanin1(pObj)->Type > 0 ); - Dar_ObjRef( Dar_ObjFanin1(pObj) ); - } - // set level and phase - if ( pFan1 != NULL ) - { - pObj->Level = Dar_ObjLevelNew( pObj ); - pObj->fPhase = Dar_ObjFaninPhase(pFan0) & Dar_ObjFaninPhase(pFan1); - } - else - { - pObj->Level = pFan0->Level; - pObj->fPhase = Dar_ObjFaninPhase(pFan0); - } - // add the node to the structural hash table - if ( Dar_ObjIsHash(pObj) ) - Dar_TableInsert( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Disconnects the object from the fanins.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjDisconnect( Dar_Man_t * p, Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - // remove connections - if ( pObj->pFanin0 != NULL ) - Dar_ObjDeref(Dar_ObjFanin0(pObj)); - if ( pObj->pFanin1 != NULL ) - Dar_ObjDeref(Dar_ObjFanin1(pObj)); - // remove the node from the structural hash table - if ( Dar_ObjIsHash(pObj) ) - Dar_TableDelete( p, pObj ); - // add the first fanin - pObj->pFanin0 = NULL; - pObj->pFanin1 = NULL; -} - -/**Function************************************************************* - - Synopsis [Deletes the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjDelete( Dar_Man_t * p, Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - assert( !Dar_ObjIsTerm(pObj) ); - assert( Dar_ObjRefs(pObj) == 0 ); - p->nObjs[pObj->Type]--; - Vec_PtrWriteEntry( p->vObjs, pObj->Id, NULL ); - Dar_ManRecycleMemory( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Deletes the MFFC of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjDelete_rec( Dar_Man_t * p, Dar_Obj_t * pObj, int fFreeTop ) -{ - Dar_Obj_t * pFanin0, * pFanin1; - assert( !Dar_IsComplement(pObj) ); - if ( Dar_ObjIsConst1(pObj) || Dar_ObjIsPi(pObj) ) - return; - assert( !Dar_ObjIsPo(pObj) ); - pFanin0 = Dar_ObjFanin0(pObj); - pFanin1 = Dar_ObjFanin1(pObj); - Dar_ObjDisconnect( p, pObj ); - if ( fFreeTop ) - Dar_ObjDelete( p, pObj ); - if ( pFanin0 && !Dar_ObjIsNone(pFanin0) && Dar_ObjRefs(pFanin0) == 0 ) - Dar_ObjDelete_rec( p, pFanin0, 1 ); - if ( pFanin1 && !Dar_ObjIsNone(pFanin1) && Dar_ObjRefs(pFanin1) == 0 ) - Dar_ObjDelete_rec( p, pFanin1, 1 ); -} - -/**Function************************************************************* - - Synopsis [Replaces the first fanin of the node by the new fanin.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjPatchFanin0( Dar_Man_t * p, Dar_Obj_t * pObj, Dar_Obj_t * pFaninNew ) -{ - Dar_Obj_t * pFaninOld; - assert( !Dar_IsComplement(pObj) ); - pFaninOld = Dar_ObjFanin0(pObj); - // decrement ref and remove fanout - Dar_ObjDeref( pFaninOld ); - // update the fanin - pObj->pFanin0 = pFaninNew; - // increment ref and add fanout - Dar_ObjRef( Dar_Regular(pFaninNew) ); - // get rid of old fanin - if ( !Dar_ObjIsPi(pFaninOld) && !Dar_ObjIsConst1(pFaninOld) && Dar_ObjRefs(pFaninOld) == 0 ) - Dar_ObjDelete_rec( p, pFaninOld, 1 ); -} - -/**Function************************************************************* - - Synopsis [Replaces one object by another.] - - Description [Both objects are currently in the manager. 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.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjReplace( Dar_Man_t * p, Dar_Obj_t * pObjOld, Dar_Obj_t * pObjNew, int fNodesOnly ) -{ - Dar_Obj_t * pObjNewR = Dar_Regular(pObjNew); - // the object to be replaced cannot be complemented - assert( !Dar_IsComplement(pObjOld) ); - // the object to be replaced cannot be a terminal - assert( !Dar_ObjIsPi(pObjOld) && !Dar_ObjIsPo(pObjOld) ); - // the object to be used cannot be a buffer or a PO - assert( !Dar_ObjIsBuf(pObjNewR) && !Dar_ObjIsPo(pObjNewR) ); - // the object cannot be the same - assert( pObjOld != pObjNewR ); - // make sure object is not pointing to itself - assert( pObjOld != Dar_ObjFanin0(pObjNewR) ); - assert( pObjOld != Dar_ObjFanin1(pObjNewR) ); - // recursively delete the old node - but leave the object there - pObjNewR->nRefs++; - Dar_ObjDelete_rec( p, pObjOld, 0 ); - pObjNewR->nRefs--; - // if the new object is complemented or already used, create a buffer - p->nObjs[pObjOld->Type]--; - if ( Dar_IsComplement(pObjNew) || Dar_ObjRefs(pObjNew) > 0 || (fNodesOnly && !Dar_ObjIsNode(pObjNew)) ) - { - pObjOld->Type = DAR_AIG_BUF; - Dar_ObjConnect( p, pObjOld, pObjNew, NULL ); - } - else - { - Dar_Obj_t * pFanin0 = pObjNew->pFanin0; - Dar_Obj_t * pFanin1 = pObjNew->pFanin1; - pObjOld->Type = pObjNew->Type; - Dar_ObjDisconnect( p, pObjNew ); - Dar_ObjConnect( p, pObjOld, pFanin0, pFanin1 ); - Dar_ObjDelete( p, pObjNew ); - } - p->nObjs[pObjOld->Type]++; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darOper.c b/src/aig/dar/darOper.c deleted file mode 100644 index cfb89e31..00000000 --- a/src/aig/dar/darOper.c +++ /dev/null @@ -1,429 +0,0 @@ -/**CFile**************************************************************** - - FileName [darOper.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [AIG operations.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darOper.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// procedure to detect an EXOR gate -static inline int Dar_ObjIsExorType( Dar_Obj_t * p0, Dar_Obj_t * p1, Dar_Obj_t ** ppFan0, Dar_Obj_t ** ppFan1 ) -{ - if ( !Dar_IsComplement(p0) || !Dar_IsComplement(p1) ) - return 0; - p0 = Dar_Regular(p0); - p1 = Dar_Regular(p1); - if ( !Dar_ObjIsAnd(p0) || !Dar_ObjIsAnd(p1) ) - return 0; - if ( Dar_ObjFanin0(p0) != Dar_ObjFanin0(p1) || Dar_ObjFanin1(p0) != Dar_ObjFanin1(p1) ) - return 0; - if ( Dar_ObjFaninC0(p0) == Dar_ObjFaninC0(p1) || Dar_ObjFaninC1(p0) == Dar_ObjFaninC1(p1) ) - return 0; - *ppFan0 = Dar_ObjChild0(p0); - *ppFan1 = Dar_ObjChild1(p0); - return 1; -} - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Returns i-th elementary variable.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_IthVar( Dar_Man_t * p, int i ) -{ - int v; - for ( v = Dar_ManPiNum(p); v <= i; v++ ) - Dar_ObjCreatePi( p ); - assert( i < Vec_PtrSize(p->vPis) ); - return Dar_ManPi( p, i ); -} - -/**Function************************************************************* - - Synopsis [Perform one operation.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Oper( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1, Dar_Type_t Type ) -{ - if ( Type == DAR_AIG_AND ) - return Dar_And( p, p0, p1 ); - if ( Type == DAR_AIG_EXOR ) - return Dar_Exor( p, p0, p1 ); - assert( 0 ); - return NULL; -} - -/**Function************************************************************* - - Synopsis [Creates the canonical form of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_CanonPair_rec( Dar_Man_t * p, Dar_Obj_t * pGhost ) -{ - Dar_Obj_t * pResult, * pLat0, * pLat1; - int fCompl0, fCompl1; - Dar_Type_t Type; - assert( Dar_ObjIsNode(pGhost) ); - // consider the case when the pair is canonical - if ( !Dar_ObjIsLatch(Dar_ObjFanin0(pGhost)) || !Dar_ObjIsLatch(Dar_ObjFanin1(pGhost)) ) - { - if ( pResult = Dar_TableLookup( p, pGhost ) ) - return pResult; - return Dar_ObjCreate( p, pGhost ); - } - /// remember the latches - pLat0 = Dar_ObjFanin0(pGhost); - pLat1 = Dar_ObjFanin1(pGhost); - // remember type and compls - Type = Dar_ObjType(pGhost); - fCompl0 = Dar_ObjFaninC0(pGhost); - fCompl1 = Dar_ObjFaninC1(pGhost); - // call recursively - pResult = Dar_Oper( p, Dar_NotCond(Dar_ObjChild0(pLat0), fCompl0), Dar_NotCond(Dar_ObjChild0(pLat1), fCompl1), Type ); - // build latch on top of this - return Dar_Latch( p, pResult, (Type == DAR_AIG_AND)? fCompl0 & fCompl1 : fCompl0 ^ fCompl1 ); -} - -/**Function************************************************************* - - Synopsis [Performs canonicization step.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_And( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ) -{ - Dar_Obj_t * pGhost, * pResult; -// Dar_Obj_t * pFan0, * pFan1; - // check trivial cases - if ( p0 == p1 ) - return p0; - if ( p0 == Dar_Not(p1) ) - return Dar_Not(p->pConst1); - if ( Dar_Regular(p0) == p->pConst1 ) - return p0 == p->pConst1 ? p1 : Dar_Not(p->pConst1); - if ( Dar_Regular(p1) == p->pConst1 ) - return p1 == p->pConst1 ? p0 : Dar_Not(p->pConst1); - // check if it can be an EXOR gate -// if ( Dar_ObjIsExorType( p0, p1, &pFan0, &pFan1 ) ) -// return Dar_Exor( p, pFan0, pFan1 ); - pGhost = Dar_ObjCreateGhost( p, p0, p1, DAR_AIG_AND ); - pResult = Dar_CanonPair_rec( p, pGhost ); - return pResult; -} - -/**Function************************************************************* - - Synopsis [Creates the canonical form of the node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Latch( Dar_Man_t * p, Dar_Obj_t * pObj, int fInitOne ) -{ - Dar_Obj_t * pGhost, * pResult; - pGhost = Dar_ObjCreateGhost( p, Dar_NotCond(pObj, fInitOne), NULL, DAR_AIG_LATCH ); - pResult = Dar_TableLookup( p, pGhost ); - if ( pResult == NULL ) - pResult = Dar_ObjCreate( p, pGhost ); - return Dar_NotCond( pResult, fInitOne ); -} - -/**Function************************************************************* - - Synopsis [Performs canonicization step.] - - Description [The argument nodes can be complemented.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Exor( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ) -{ -/* - Dar_Obj_t * pGhost, * pResult; - // check trivial cases - if ( p0 == p1 ) - return Dar_Not(p->pConst1); - if ( p0 == Dar_Not(p1) ) - return p->pConst1; - if ( Dar_Regular(p0) == p->pConst1 ) - return Dar_NotCond( p1, p0 == p->pConst1 ); - if ( Dar_Regular(p1) == p->pConst1 ) - return Dar_NotCond( p0, p1 == p->pConst1 ); - // check the table - pGhost = Dar_ObjCreateGhost( p, p0, p1, DAR_AIG_EXOR ); - if ( pResult = Dar_TableLookup( p, pGhost ) ) - return pResult; - return Dar_ObjCreate( p, pGhost ); -*/ - return Dar_Or( p, Dar_And(p, p0, Dar_Not(p1)), Dar_And(p, Dar_Not(p0), p1) ); -} - -/**Function************************************************************* - - Synopsis [Implements Boolean OR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Or( Dar_Man_t * p, Dar_Obj_t * p0, Dar_Obj_t * p1 ) -{ - return Dar_Not( Dar_And( p, Dar_Not(p0), Dar_Not(p1) ) ); -} - -/**Function************************************************************* - - Synopsis [Implements ITE operation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Mux( Dar_Man_t * p, Dar_Obj_t * pC, Dar_Obj_t * p1, Dar_Obj_t * p0 ) -{ -/* - Dar_Obj_t * pTempA1, * pTempA2, * pTempB1, * pTempB2, * pTemp; - int Count0, Count1; - // consider trivial cases - if ( p0 == Dar_Not(p1) ) - return Dar_Exor( p, pC, p0 ); - // other cases can be added - // implement the first MUX (F = C * x1 + C' * x0) - - // check for constants here!!! - - pTempA1 = Dar_TableLookup( p, Dar_ObjCreateGhost(p, pC, p1, DAR_AIG_AND) ); - pTempA2 = Dar_TableLookup( p, Dar_ObjCreateGhost(p, Dar_Not(pC), p0, DAR_AIG_AND) ); - if ( pTempA1 && pTempA2 ) - { - pTemp = Dar_TableLookup( p, Dar_ObjCreateGhost(p, Dar_Not(pTempA1), Dar_Not(pTempA2), DAR_AIG_AND) ); - if ( pTemp ) return Dar_Not(pTemp); - } - Count0 = (pTempA1 != NULL) + (pTempA2 != NULL); - // implement the second MUX (F' = C * x1' + C' * x0') - pTempB1 = Dar_TableLookup( p, Dar_ObjCreateGhost(p, pC, Dar_Not(p1), DAR_AIG_AND) ); - pTempB2 = Dar_TableLookup( p, Dar_ObjCreateGhost(p, Dar_Not(pC), Dar_Not(p0), DAR_AIG_AND) ); - if ( pTempB1 && pTempB2 ) - { - pTemp = Dar_TableLookup( p, Dar_ObjCreateGhost(p, Dar_Not(pTempB1), Dar_Not(pTempB2), DAR_AIG_AND) ); - if ( pTemp ) return pTemp; - } - Count1 = (pTempB1 != NULL) + (pTempB2 != NULL); - // compare and decide which one to implement - if ( Count0 >= Count1 ) - { - pTempA1 = pTempA1? pTempA1 : Dar_And(p, pC, p1); - pTempA2 = pTempA2? pTempA2 : Dar_And(p, Dar_Not(pC), p0); - return Dar_Or( p, pTempA1, pTempA2 ); - } - pTempB1 = pTempB1? pTempB1 : Dar_And(p, pC, Dar_Not(p1)); - pTempB2 = pTempB2? pTempB2 : Dar_And(p, Dar_Not(pC), Dar_Not(p0)); - return Dar_Not( Dar_Or( p, pTempB1, pTempB2 ) ); -*/ - return Dar_Or( p, Dar_And(p, pC, p1), Dar_And(p, Dar_Not(pC), p0) ); -} - -/**Function************************************************************* - - Synopsis [Implements ITE operation.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Maj( Dar_Man_t * p, Dar_Obj_t * pA, Dar_Obj_t * pB, Dar_Obj_t * pC ) -{ - return Dar_Or( p, Dar_Or(p, Dar_And(p, pA, pB), Dar_And(p, pA, pC)), Dar_And(p, pB, pC) ); -} - -/**Function************************************************************* - - Synopsis [Constructs the well-balanced tree of gates.] - - Description [Disregards levels and possible logic sharing.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Multi_rec( Dar_Man_t * p, Dar_Obj_t ** ppObjs, int nObjs, Dar_Type_t Type ) -{ - Dar_Obj_t * pObj1, * pObj2; - if ( nObjs == 1 ) - return ppObjs[0]; - pObj1 = Dar_Multi_rec( p, ppObjs, nObjs/2, Type ); - pObj2 = Dar_Multi_rec( p, ppObjs + nObjs/2, nObjs - nObjs/2, Type ); - return Dar_Oper( p, pObj1, pObj2, Type ); -} - -/**Function************************************************************* - - Synopsis [Old code.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Multi( Dar_Man_t * p, Dar_Obj_t ** pArgs, int nArgs, Dar_Type_t Type ) -{ - assert( Type == DAR_AIG_AND || Type == DAR_AIG_EXOR ); - assert( nArgs > 0 ); - return Dar_Multi_rec( p, pArgs, nArgs, Type ); -} - -/**Function************************************************************* - - Synopsis [Implements the miter.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_Miter( Dar_Man_t * p, Vec_Ptr_t * vPairs ) -{ - int i; - assert( vPairs->nSize > 0 ); - assert( vPairs->nSize % 2 == 0 ); - // go through the cubes of the node's SOP - for ( i = 0; i < vPairs->nSize; i += 2 ) - vPairs->pArray[i/2] = Dar_Not( Dar_Exor( p, vPairs->pArray[i], vPairs->pArray[i+1] ) ); - vPairs->nSize = vPairs->nSize/2; - return Dar_Not( Dar_Multi_rec( p, (Dar_Obj_t **)vPairs->pArray, vPairs->nSize, DAR_AIG_AND ) ); -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_CreateAnd( Dar_Man_t * p, int nVars ) -{ - Dar_Obj_t * pFunc; - int i; - pFunc = Dar_ManConst1( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Dar_And( p, pFunc, Dar_IthVar(p, i) ); - return pFunc; -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_CreateOr( Dar_Man_t * p, int nVars ) -{ - Dar_Obj_t * pFunc; - int i; - pFunc = Dar_ManConst0( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Dar_Or( p, pFunc, Dar_IthVar(p, i) ); - return pFunc; -} - -/**Function************************************************************* - - Synopsis [Creates AND function with nVars inputs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_CreateExor( Dar_Man_t * p, int nVars ) -{ - Dar_Obj_t * pFunc; - int i; - pFunc = Dar_ManConst0( p ); - for ( i = 0; i < nVars; i++ ) - pFunc = Dar_Exor( p, pFunc, Dar_IthVar(p, i) ); - return pFunc; -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darSeq.c b/src/aig/dar/darSeq.c deleted file mode 100644 index 33f11f31..00000000 --- a/src/aig/dar/darSeq.c +++ /dev/null @@ -1,497 +0,0 @@ -/**CFile**************************************************************** - - FileName [darSeq.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darSeq.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Converts combinational AIG manager into a sequential one.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManSeqStrashConvert( Dar_Man_t * p, int nLatches, int * pInits ) -{ - Dar_Obj_t * pObjLi, * pObjLo, * pLatch; - int i; - // collect the POs to be converted into latches - for ( i = 0; i < nLatches; i++ ) - { - // get the corresponding PI/PO pair - pObjLi = Dar_ManPo( p, Dar_ManPoNum(p) - nLatches + i ); - pObjLo = Dar_ManPi( p, Dar_ManPiNum(p) - nLatches + i ); - // create latch - pLatch = Dar_Latch( p, Dar_ObjChild0(pObjLi), pInits? pInits[i] : 0 ); - // recycle the old PO object - Dar_ObjDisconnect( p, pObjLi ); - Vec_PtrWriteEntry( p->vObjs, pObjLi->Id, NULL ); - Dar_ManRecycleMemory( p, pObjLi ); - // convert the corresponding PI to be a buffer and connect it to the latch - pObjLo->Type = DAR_AIG_BUF; - Dar_ObjConnect( p, pObjLo, pLatch, NULL ); - } - // shrink the arrays - Vec_PtrShrink( p->vPis, Dar_ManPiNum(p) - nLatches ); - Vec_PtrShrink( p->vPos, Dar_ManPoNum(p) - nLatches ); - // update the counters of different objects - p->nObjs[DAR_AIG_PI] -= nLatches; - p->nObjs[DAR_AIG_PO] -= nLatches; - p->nObjs[DAR_AIG_BUF] += nLatches; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManDfsSeq_rec( Dar_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( pObj == NULL ) - return; - if ( Dar_ObjIsTravIdCurrent( p, pObj ) ) - return; - Dar_ObjSetTravIdCurrent( p, pObj ); - if ( Dar_ObjIsPi(pObj) || Dar_ObjIsConst1(pObj) ) - return; - Dar_ManDfsSeq_rec( p, Dar_ObjFanin0(pObj), vNodes ); - Dar_ManDfsSeq_rec( p, Dar_ObjFanin1(pObj), vNodes ); -// if ( (Dar_ObjFanin0(pObj) == NULL || Dar_ObjIsBuf(Dar_ObjFanin0(pObj))) && -// (Dar_ObjFanin1(pObj) == NULL || Dar_ObjIsBuf(Dar_ObjFanin1(pObj))) ) - Vec_PtrPush( vNodes, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Dar_ManDfsSeq( Dar_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i; - Dar_ManIncrementTravId( p ); - vNodes = Vec_PtrAlloc( Dar_ManNodeNum(p) ); - Dar_ManForEachPo( p, pObj, i ) - Dar_ManDfsSeq_rec( p, Dar_ObjFanin0(pObj), vNodes ); - return vNodes; -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes in the DFS order.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManDfsUnreach_rec( Dar_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vNodes ) -{ - assert( !Dar_IsComplement(pObj) ); - if ( pObj == NULL ) - return; - if ( Dar_ObjIsTravIdPrevious(p, pObj) || Dar_ObjIsTravIdCurrent(p, pObj) ) - return; - Dar_ObjSetTravIdPrevious( p, pObj ); // assume unknown - Dar_ManDfsUnreach_rec( p, Dar_ObjFanin0(pObj), vNodes ); - Dar_ManDfsUnreach_rec( p, Dar_ObjFanin1(pObj), vNodes ); - if ( Dar_ObjIsTravIdPrevious(p, Dar_ObjFanin0(pObj)) && - (Dar_ObjFanin1(pObj) == NULL || Dar_ObjIsTravIdPrevious(p, Dar_ObjFanin1(pObj))) ) - Vec_PtrPush( vNodes, pObj ); - else - Dar_ObjSetTravIdCurrent( p, pObj ); -} - -/**Function************************************************************* - - Synopsis [Collects internal nodes unreachable from PIs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Vec_Ptr_t * Dar_ManDfsUnreach( Dar_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj, * pFanin; - int i, k;//, RetValue; - // collect unreachable nodes - Dar_ManIncrementTravId( p ); - Dar_ManIncrementTravId( p ); - // mark the constant and PIs - Dar_ObjSetTravIdPrevious( p, Dar_ManConst1(p) ); - Dar_ManForEachPi( p, pObj, i ) - Dar_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 ); - Dar_ManForEachPo( p, pObj, i ) - Dar_ManDfsUnreach_rec( p, Dar_ObjFanin0(pObj), vNodes ); - - // refine resulting nodes - do - { - k = 0; - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - assert( Dar_ObjIsTravIdPrevious(p, pObj) ); - if ( Dar_ObjIsLatch(pObj) || Dar_ObjIsBuf(pObj) ) - { - pFanin = Dar_ObjFanin0(pObj); - assert( Dar_ObjIsTravIdPrevious(p, pFanin) || Dar_ObjIsTravIdCurrent(p, pFanin) ); - if ( Dar_ObjIsTravIdCurrent(p, pFanin) ) - { - Dar_ObjSetTravIdCurrent( p, pObj ); - continue; - } - } - else // AND gate - { - assert( Dar_ObjIsNode(pObj) ); - pFanin = Dar_ObjFanin0(pObj); - assert( Dar_ObjIsTravIdPrevious(p, pFanin) || Dar_ObjIsTravIdCurrent(p, pFanin) ); - if ( Dar_ObjIsTravIdCurrent(p, pFanin) ) - { - Dar_ObjSetTravIdCurrent( p, pObj ); - continue; - } - pFanin = Dar_ObjFanin1(pObj); - assert( Dar_ObjIsTravIdPrevious(p, pFanin) || Dar_ObjIsTravIdCurrent(p, pFanin) ); - if ( Dar_ObjIsTravIdCurrent(p, pFanin) ) - { - Dar_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 - Dar_ManIncrementTravId( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - Dar_ObjSetTravIdCurrent( p, pObj ); - Vec_PtrFree( vNodes ); - return RetValue; -*/ -} - - -/**Function************************************************************* - - Synopsis [Removes nodes that do not fanout into POs.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManRemoveUnmarked( Dar_Man_t * p ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i, RetValue; - // collect unmarked nodes - vNodes = Vec_PtrAlloc( 100 ); - Dar_ManForEachObj( p, pObj, i ) - { - if ( Dar_ObjIsTerm(pObj) ) - continue; - if ( Dar_ObjIsTravIdCurrent(p, pObj) ) - continue; -//Dar_ObjPrintVerbose( pObj, 0 ); - Dar_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 ) - Dar_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 Dar_ManSeqRehashOne( Dar_Man_t * p, Vec_Ptr_t * vNodes, Vec_Ptr_t * vUnreach ) -{ - Dar_Obj_t * pObj, * pObjNew, * pFanin0, * pFanin1; - int i, RetValue = 0, Counter = 0, Counter2 = 0; - - // mark the unreachable nodes - Dar_ManIncrementTravId( p ); - Vec_PtrForEachEntry( vUnreach, pObj, i ) - Dar_ObjSetTravIdCurrent(p, pObj); -/* - // count the number of unreachable object connections - // that is the number of unreachable objects connected to main objects - Dar_ManForEachObj( p, pObj, i ) - { - if ( Dar_ObjIsTravIdCurrent(p, pObj) ) - continue; - - pFanin0 = Dar_ObjFanin0(pObj); - if ( pFanin0 == NULL ) - continue; - if ( Dar_ObjIsTravIdCurrent(p, pFanin0) ) - pFanin0->fMarkA = 1; - - pFanin1 = Dar_ObjFanin1(pObj); - if ( pFanin1 == NULL ) - continue; - if ( Dar_ObjIsTravIdCurrent(p, pFanin1) ) - pFanin1->fMarkA = 1; - } - - // count the objects - Dar_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 ( Dar_ObjIsTravIdCurrent(p, pObj) ) - continue; - // process the node - if ( Dar_ObjIsPo(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) ) - continue; - pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - Dar_ObjPatchFanin0( p, pObj, pFanin0 ); - continue; - } - if ( Dar_ObjIsLatch(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) ) - continue; - pObjNew = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - pObjNew = Dar_Latch( p, pObjNew, 0 ); - Dar_ObjReplace( p, pObj, pObjNew, 1 ); - RetValue = 1; - Counter++; - continue; - } - if ( Dar_ObjIsNode(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) && !Dar_ObjIsBuf(Dar_ObjFanin1(pObj)) ) - continue; - pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - pFanin1 = Dar_ObjReal_rec( Dar_ObjChild1(pObj) ); - pObjNew = Dar_And( p, pFanin0, pFanin1 ); - Dar_ObjReplace( p, pObj, pObjNew, 1 ); - 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 Dar_ManRemoveBuffers( Dar_Man_t * p ) -{ - Dar_Obj_t * pObj, * pObjNew, * pFanin0, * pFanin1; - int i; - if ( Dar_ManBufNum(p) == 0 ) - return; - Dar_ManForEachObj( p, pObj, i ) - { - if ( Dar_ObjIsPo(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) ) - continue; - pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - Dar_ObjPatchFanin0( p, pObj, pFanin0 ); - } - else if ( Dar_ObjIsLatch(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) ) - continue; - pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - pObjNew = Dar_Latch( p, pFanin0, 0 ); - Dar_ObjReplace( p, pObj, pObjNew, 0 ); - } - else if ( Dar_ObjIsAnd(pObj) ) - { - if ( !Dar_ObjIsBuf(Dar_ObjFanin0(pObj)) && !Dar_ObjIsBuf(Dar_ObjFanin1(pObj)) ) - continue; - pFanin0 = Dar_ObjReal_rec( Dar_ObjChild0(pObj) ); - pFanin1 = Dar_ObjReal_rec( Dar_ObjChild1(pObj) ); - pObjNew = Dar_And( p, pFanin0, pFanin1 ); - Dar_ObjReplace( p, pObj, pObjNew, 0 ); - } - } - assert( Dar_ManBufNum(p) == 0 ); -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManSeqStrash( Dar_Man_t * p, int nLatches, int * pInits ) -{ - Vec_Ptr_t * vNodes, * vUnreach; -// Dar_Obj_t * pObj, * pFanin; -// int i; - int Iter, RetValue = 1; - - // create latches out of the additional PI/PO pairs - Dar_ManSeqStrashConvert( p, nLatches, pInits ); - - // iteratively rehash the network - for ( Iter = 0; RetValue; Iter++ ) - { -// Dar_ManPrintStats( p ); -/* - Dar_ManForEachObj( p, pObj, i ) - { - assert( pObj->Type > 0 ); - pFanin = Dar_ObjFanin0(pObj); - assert( pFanin == NULL || pFanin->Type > 0 ); - pFanin = Dar_ObjFanin1(pObj); - assert( pFanin == NULL || pFanin->Type > 0 ); - } -*/ - // mark nodes unreachable from the PIs - vUnreach = Dar_ManDfsUnreach( p ); - if ( Iter == 0 && Vec_PtrSize(vUnreach) > 0 ) - printf( "Unreachable objects = %d.\n", Vec_PtrSize(vUnreach) ); - // collect nodes reachable from the POs - vNodes = Dar_ManDfsSeq( p ); - // remove nodes unreachable from the POs - if ( Iter == 0 ) - Dar_ManRemoveUnmarked( p ); - // continue rehashing as long as there are changes - RetValue = Dar_ManSeqRehashOne( p, vNodes, vUnreach ); - Vec_PtrFree( vNodes ); - Vec_PtrFree( vUnreach ); - } - - // perform the final cleanup - Dar_ManIncrementTravId( p ); - vNodes = Dar_ManDfsSeq( p ); - Dar_ManRemoveUnmarked( p ); - Vec_PtrFree( vNodes ); - // remove buffers if they are left -// Dar_ManRemoveBuffers( p ); - - // clean up - if ( !Dar_ManCheck( p ) ) - { - printf( "Dar_ManSeqStrash: The network check has failed.\n" ); - return 0; - } - return 1; - -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darTable.c b/src/aig/dar/darTable.c deleted file mode 100644 index af9956ec..00000000 --- a/src/aig/dar/darTable.c +++ /dev/null @@ -1,279 +0,0 @@ -/**CFile**************************************************************** - - FileName [darTable.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [Structural hashing table.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darTable.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -// hashing the node -static unsigned long Dar_Hash( Dar_Obj_t * pObj, int TableSize ) -{ - unsigned long Key = Dar_ObjIsExor(pObj) * 1699; - Key ^= (long)Dar_ObjFanin0(pObj) * 7937; - Key ^= (long)Dar_ObjFanin1(pObj) * 2971; - Key ^= Dar_ObjFaninC0(pObj) * 911; - Key ^= Dar_ObjFaninC1(pObj) * 353; - return Key % TableSize; -} - -// returns the place where this node is stored (or should be stored) -static Dar_Obj_t ** Dar_TableFind( Dar_Man_t * p, Dar_Obj_t * pObj ) -{ - Dar_Obj_t ** ppEntry; - if ( Dar_ObjIsLatch(pObj) ) - { - assert( Dar_ObjChild0(pObj) && Dar_ObjChild1(pObj) == NULL ); - } - else - { - assert( Dar_ObjChild0(pObj) && Dar_ObjChild1(pObj) ); - assert( Dar_ObjFanin0(pObj)->Id < Dar_ObjFanin1(pObj)->Id ); - } - for ( ppEntry = p->pTable + Dar_Hash(pObj, p->nTableSize); *ppEntry; ppEntry = &(*ppEntry)->pNext ) - if ( *ppEntry == pObj ) - return ppEntry; - assert( *ppEntry == NULL ); - return ppEntry; -} - -static void Dar_TableResize( Dar_Man_t * p ); -static unsigned int Cudd_PrimeAig( unsigned int p ); - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Checks if node with the given attributes is in the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_TableLookup( Dar_Man_t * p, Dar_Obj_t * pGhost ) -{ - Dar_Obj_t * pEntry; - assert( !Dar_IsComplement(pGhost) ); - if ( pGhost->Type == DAR_AIG_LATCH ) - { - assert( Dar_ObjChild0(pGhost) && Dar_ObjChild1(pGhost) == NULL ); - if ( !Dar_ObjRefs(Dar_ObjFanin0(pGhost)) ) - return NULL; - } - else - { - assert( pGhost->Type == DAR_AIG_AND ); - assert( Dar_ObjChild0(pGhost) && Dar_ObjChild1(pGhost) ); - assert( Dar_ObjFanin0(pGhost)->Id < Dar_ObjFanin1(pGhost)->Id ); - if ( !Dar_ObjRefs(Dar_ObjFanin0(pGhost)) || !Dar_ObjRefs(Dar_ObjFanin1(pGhost)) ) - return NULL; - } - for ( pEntry = p->pTable[Dar_Hash(pGhost, p->nTableSize)]; pEntry; pEntry = pEntry->pNext ) - { - if ( Dar_ObjChild0(pEntry) == Dar_ObjChild0(pGhost) && - Dar_ObjChild1(pEntry) == Dar_ObjChild1(pGhost) && - Dar_ObjType(pEntry) == Dar_ObjType(pGhost) ) - return pEntry; - } - return NULL; -} - -/**Function************************************************************* - - Synopsis [Adds the new node to the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_TableInsert( Dar_Man_t * p, Dar_Obj_t * pObj ) -{ - Dar_Obj_t ** ppPlace; - assert( !Dar_IsComplement(pObj) ); - assert( Dar_TableLookup(p, pObj) == NULL ); - if ( (pObj->Id & 0xFF) == 0 && 2 * p->nTableSize < Dar_ManNodeNum(p) ) - Dar_TableResize( p ); - ppPlace = Dar_TableFind( p, pObj ); - assert( *ppPlace == NULL ); - *ppPlace = pObj; -} - -/**Function************************************************************* - - Synopsis [Deletes the node from the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_TableDelete( Dar_Man_t * p, Dar_Obj_t * pObj ) -{ - Dar_Obj_t ** ppPlace; - assert( !Dar_IsComplement(pObj) ); - ppPlace = Dar_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 Dar_TableCountEntries( Dar_Man_t * p ) -{ - Dar_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 [Resizes the table.] - - Description [Typically this procedure should not be called.] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_TableResize( Dar_Man_t * p ) -{ - Dar_Obj_t * pEntry, * pNext; - Dar_Obj_t ** pTableOld, ** ppPlace; - int nTableSizeOld, Counter, nEntries, i, clk; -clk = clock(); - // save the old table - pTableOld = p->pTable; - nTableSizeOld = p->nTableSize; - // get the new table - p->nTableSize = Cudd_PrimeAig( 2 * Dar_ManNodeNum(p) ); - p->pTable = ALLOC( Dar_Obj_t *, p->nTableSize ); - memset( p->pTable, 0, sizeof(Dar_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 = Dar_TableFind( p, pEntry ); - assert( *ppPlace == NULL ); // should not be there - // add the entry to the list - *ppPlace = pEntry; - pEntry->pNext = NULL; - Counter++; - } - nEntries = Dar_ManNodeNum(p); - assert( Counter == nEntries ); - 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 [Profiles the hash table.] - - Description [] - - SideEffects [] - - SeeAlso [] - -******************************************************************************/ -void Dar_TableProfile( Dar_Man_t * p ) -{ - Dar_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 [Returns the next prime >= p.] - - Description [Copied from CUDD, for stand-aloneness.] - - SideEffects [None] - - SeeAlso [] - -******************************************************************************/ -unsigned int Cudd_PrimeAig( 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 */ - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/darTruth.c b/src/aig/dar/darTruth.c index 16b9f62a..7fd47787 100644 --- a/src/aig/dar/darTruth.c +++ b/src/aig/dar/darTruth.c @@ -18,7 +18,7 @@ ***********************************************************************/ -#include "dar.h" +#include "darInt.h" //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// @@ -28,6 +28,8 @@ /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// +#if 0 + /**Function************************************************************* Synopsis [Computes truth table of the cut.] @@ -39,14 +41,14 @@ SeeAlso [] ***********************************************************************/ -void Dar_ManCollectCut_rec( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * vNodes ) +void Aig_ManCollectCut_rec( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Int_t * vNodes ) { if ( pNode->fMarkA ) return; pNode->fMarkA = 1; - assert( Dar_ObjIsAnd(pNode) || Dar_ObjIsExor(pNode) ); - Dar_ManCollectCut_rec( p, Dar_ObjFanin0(pNode), vNodes ); - Dar_ManCollectCut_rec( p, Dar_ObjFanin1(pNode), vNodes ); + assert( Aig_ObjIsAnd(pNode) || Aig_ObjIsExor(pNode) ); + Aig_ManCollectCut_rec( p, Aig_ObjFanin0(pNode), vNodes ); + Aig_ManCollectCut_rec( p, Aig_ObjFanin1(pNode), vNodes ); Vec_IntPush( vNodes, pNode->Id ); } @@ -62,7 +64,7 @@ void Dar_ManCollectCut_rec( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * vNodes SeeAlso [] ***********************************************************************/ -void Dar_ManCollectCut( Dar_Man_t * p, Dar_Obj_t * pRoot, Vec_Int_t * vLeaves, Vec_Int_t * vNodes ) +void Aig_ManCollectCut( Aig_Man_t * p, Aig_Obj_t * pRoot, Vec_Int_t * vLeaves, Vec_Int_t * vNodes ) { int i, Leaf; // collect and mark the leaves @@ -70,13 +72,13 @@ void Dar_ManCollectCut( Dar_Man_t * p, Dar_Obj_t * pRoot, Vec_Int_t * vLeaves, V Vec_IntForEachEntry( vLeaves, Leaf, i ) { Vec_IntPush( vNodes, Leaf ); - Dar_ManObj(p, Leaf)->fMarkA = 1; + Aig_ManObj(p, Leaf)->fMarkA = 1; } // collect and mark the nodes - Dar_ManCollectCut_rec( p, pRoot, vNodes ); + Aig_ManCollectCut_rec( p, pRoot, vNodes ); // clean the nodes Vec_IntForEachEntry( vNodes, Leaf, i ) - Dar_ManObj(p, Leaf)->fMarkA = 0; + Aig_ManObj(p, Leaf)->fMarkA = 0; } /**Function************************************************************* @@ -90,7 +92,7 @@ void Dar_ManCollectCut( Dar_Man_t * p, Dar_Obj_t * pRoot, Vec_Int_t * vLeaves, V SeeAlso [] ***********************************************************************/ -unsigned * Dar_ObjGetTruthStore( int ObjNum, Vec_Int_t * vTruth ) +unsigned * Aig_ObjGetTruthStore( int ObjNum, Vec_Int_t * vTruth ) { return ((unsigned *)Vec_IntArray(vTruth)) + 8 * ObjNum; } @@ -106,26 +108,26 @@ unsigned * Dar_ObjGetTruthStore( int ObjNum, Vec_Int_t * vTruth ) SeeAlso [] ***********************************************************************/ -void Dar_ManCutTruthOne( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * vTruth, int nWords ) +void Aig_ManCutTruthOne( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Int_t * vTruth, int nWords ) { unsigned * pTruth, * pTruth0, * pTruth1; int i; - pTruth = Dar_ObjGetTruthStore( pNode->Level, vTruth ); - pTruth0 = Dar_ObjGetTruthStore( Dar_ObjFanin0(pNode)->Level, vTruth ); - pTruth1 = Dar_ObjGetTruthStore( Dar_ObjFanin1(pNode)->Level, vTruth ); - if ( Dar_ObjIsExor(pNode) ) + pTruth = Aig_ObjGetTruthStore( pNode->Level, vTruth ); + pTruth0 = Aig_ObjGetTruthStore( Aig_ObjFanin0(pNode)->Level, vTruth ); + pTruth1 = Aig_ObjGetTruthStore( Aig_ObjFanin1(pNode)->Level, vTruth ); + if ( Aig_ObjIsExor(pNode) ) for ( i = 0; i < nWords; i++ ) pTruth[i] = pTruth0[i] ^ pTruth1[i]; - else if ( !Dar_ObjFaninC0(pNode) && !Dar_ObjFaninC1(pNode) ) + else if ( !Aig_ObjFaninC0(pNode) && !Aig_ObjFaninC1(pNode) ) for ( i = 0; i < nWords; i++ ) pTruth[i] = pTruth0[i] & pTruth1[i]; - else if ( !Dar_ObjFaninC0(pNode) && Dar_ObjFaninC1(pNode) ) + else if ( !Aig_ObjFaninC0(pNode) && Aig_ObjFaninC1(pNode) ) for ( i = 0; i < nWords; i++ ) pTruth[i] = pTruth0[i] & ~pTruth1[i]; - else if ( Dar_ObjFaninC0(pNode) && !Dar_ObjFaninC1(pNode) ) + else if ( Aig_ObjFaninC0(pNode) && !Aig_ObjFaninC1(pNode) ) for ( i = 0; i < nWords; i++ ) pTruth[i] = ~pTruth0[i] & pTruth1[i]; - else // if ( Dar_ObjFaninC0(pNode) && Dar_ObjFaninC1(pNode) ) + else // if ( Aig_ObjFaninC0(pNode) && Aig_ObjFaninC1(pNode) ) for ( i = 0; i < nWords; i++ ) pTruth[i] = ~pTruth0[i] & ~pTruth1[i]; } @@ -142,7 +144,7 @@ void Dar_ManCutTruthOne( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * vTruth, i SeeAlso [] ***********************************************************************/ -unsigned * Dar_ManCutTruth( Dar_Man_t * p, Dar_Obj_t * pRoot, Vec_Int_t * vLeaves, Vec_Int_t * vNodes, Vec_Int_t * vTruth ) +unsigned * Aig_ManCutTruth( Aig_Man_t * p, Aig_Obj_t * pRoot, Vec_Int_t * vLeaves, Vec_Int_t * vNodes, Vec_Int_t * vTruth ) { static unsigned uTruths[8][8] = { // elementary truth tables { 0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA,0xAAAAAAAA }, @@ -156,20 +158,20 @@ unsigned * Dar_ManCutTruth( Dar_Man_t * p, Dar_Obj_t * pRoot, Vec_Int_t * vLeave }; int i, Leaf; // collect the cut -// Dar_ManCollectCut( p, pRoot, vLeaves, vNodes ); +// Aig_ManCollectCut( p, pRoot, vLeaves, vNodes ); // set the node numbers Vec_IntForEachEntry( vNodes, Leaf, i ) - Dar_ManObj(p, Leaf)->Level = i; + Aig_ManObj(p, Leaf)->Level = i; // alloc enough memory Vec_IntClear( vTruth ); Vec_IntGrow( vTruth, 8 * Vec_IntSize(vNodes) ); // set the elementary truth tables Vec_IntForEachEntry( vLeaves, Leaf, i ) - memcpy( Dar_ObjGetTruthStore(i, vTruth), uTruths[i], 8 * sizeof(unsigned) ); + memcpy( Aig_ObjGetTruthStore(i, vTruth), uTruths[i], 8 * sizeof(unsigned) ); // compute truths for other nodes Vec_IntForEachEntryStart( vNodes, Leaf, i, Vec_IntSize(vLeaves) ) - Dar_ManCutTruthOne( p, Dar_ManObj(p, Leaf), vTruth, 8 ); - return Dar_ObjGetTruthStore( pRoot->Level, vTruth ); + Aig_ManCutTruthOne( p, Aig_ManObj(p, Leaf), vTruth, 8 ); + return Aig_ObjGetTruthStore( pRoot->Level, vTruth ); } static inline int Kit_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); } @@ -191,21 +193,21 @@ static inline void Kit_TruthNot( unsigned * pOut, unsigned * pIn, int nVars ) SeeAlso [] ***********************************************************************/ -int Dar_ManLargeCutEvalIsop( unsigned * pTruth, int nVars, Vec_Int_t * vMemory ) +int Aig_ManLargeCutEvalIsop( unsigned * pTruth, int nVars, Vec_Int_t * vMemory ) { extern int Kit_TruthIsop( unsigned * puTruth, int nVars, Vec_Int_t * vMemory, int fTryBoth ); int RetValue, nClauses; // compute ISOP for the positive phase RetValue = Kit_TruthIsop( pTruth, nVars, vMemory, 0 ); if ( RetValue == -1 ) - return DAR_INFINITY; + return AIG_INFINITY; assert( RetValue == 0 || RetValue == 1 ); nClauses = Vec_IntSize( vMemory ); // compute ISOP for the negative phase Kit_TruthNot( pTruth, pTruth, nVars ); RetValue = Kit_TruthIsop( pTruth, nVars, vMemory, 0 ); if ( RetValue == -1 ) - return DAR_INFINITY; + return AIG_INFINITY; Kit_TruthNot( pTruth, pTruth, nVars ); assert( RetValue == 0 || RetValue == 1 ); nClauses += Vec_IntSize( vMemory ); @@ -223,21 +225,21 @@ int Dar_ManLargeCutEvalIsop( unsigned * pTruth, int nVars, Vec_Int_t * vMemory ) SeeAlso [] ***********************************************************************/ -void Dar_ManLargeCutCollect_rec( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * vLeaves, Vec_Int_t * vNodes ) +void Aig_ManLargeCutCollect_rec( Aig_Man_t * p, Aig_Obj_t * pNode, Vec_Int_t * vLeaves, Vec_Int_t * vNodes ) { - if ( Dar_ObjIsTravIdCurrent(p, pNode) ) + if ( Aig_ObjIsTravIdCurrent(p, pNode) ) return; - if ( Dar_ObjIsTravIdPrevious(p, pNode) ) + if ( Aig_ObjIsTravIdPrevious(p, pNode) ) { Vec_IntPush( vLeaves, pNode->Id ); // Vec_IntPush( vNodes, pNode->Id ); - Dar_ObjSetTravIdCurrent( p, pNode ); + Aig_ObjSetTravIdCurrent( p, pNode ); return; } - assert( Dar_ObjIsAnd(pNode) || Dar_ObjIsExor(pNode) ); - Dar_ObjSetTravIdCurrent( p, pNode ); - Dar_ManLargeCutCollect_rec( p, Dar_ObjFanin0(pNode), vLeaves, vNodes ); - Dar_ManLargeCutCollect_rec( p, Dar_ObjFanin1(pNode), vLeaves, vNodes ); + assert( Aig_ObjIsAnd(pNode) || Aig_ObjIsExor(pNode) ); + Aig_ObjSetTravIdCurrent( p, pNode ); + Aig_ManLargeCutCollect_rec( p, Aig_ObjFanin0(pNode), vLeaves, vNodes ); + Aig_ManLargeCutCollect_rec( p, Aig_ObjFanin1(pNode), vLeaves, vNodes ); Vec_IntPush( vNodes, pNode->Id ); } @@ -252,24 +254,24 @@ void Dar_ManLargeCutCollect_rec( Dar_Man_t * p, Dar_Obj_t * pNode, Vec_Int_t * v SeeAlso [] ***********************************************************************/ -void Dar_ManLargeCutCollect( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Dar_Cut_t * pCutL, int Leaf, +void Aig_ManLargeCutCollect( Aig_Man_t * p, Aig_Obj_t * pRoot, Aig_Cut_t * pCutR, Aig_Cut_t * pCutL, int Leaf, Vec_Int_t * vLeaves, Vec_Int_t * vNodes ) { Vec_Int_t * vTemp; - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int Node, i; - Dar_ManIncrementTravId( p ); - Dar_CutForEachLeaf( p, pCutR, pObj, i ) + Aig_ManIncrementTravId( p ); + Aig_CutForEachLeaf( p, pCutR, pObj, i ) if ( pObj->Id != Leaf ) - Dar_ObjSetTravIdCurrent( p, pObj ); - Dar_CutForEachLeaf( p, pCutL, pObj, i ) - Dar_ObjSetTravIdCurrent( p, pObj ); + Aig_ObjSetTravIdCurrent( p, pObj ); + Aig_CutForEachLeaf( p, pCutL, pObj, i ) + Aig_ObjSetTravIdCurrent( p, pObj ); // collect the internal nodes and leaves - Dar_ManIncrementTravId( p ); + Aig_ManIncrementTravId( p ); vTemp = Vec_IntAlloc( 100 ); - Dar_ManLargeCutCollect_rec( p, pRoot, vLeaves, vTemp ); + Aig_ManLargeCutCollect_rec( p, pRoot, vLeaves, vTemp ); Vec_IntForEachEntry( vLeaves, Node, i ) Vec_IntPush( vNodes, Node ); @@ -291,22 +293,22 @@ void Dar_ManLargeCutCollect( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR SeeAlso [] ***********************************************************************/ -int Dar_ManLargeCutEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Dar_Cut_t * pCutL, int Leaf ) +int Aig_ManLargeCutEval( Aig_Man_t * p, Aig_Obj_t * pRoot, Aig_Cut_t * pCutR, Aig_Cut_t * pCutL, int Leaf ) { Vec_Int_t * vLeaves, * vNodes, * vTruth, * vMemory; unsigned * pTruth; int RetValue; -// Dar_Obj_t * pObj; +// Aig_Obj_t * pObj; vMemory = Vec_IntAlloc( 1 << 16 ); vTruth = Vec_IntAlloc( 1 << 16 ); vLeaves = Vec_IntAlloc( 100 ); vNodes = Vec_IntAlloc( 100 ); - Dar_ManLargeCutCollect( p, pRoot, pCutR, pCutL, Leaf, vLeaves, vNodes ); + Aig_ManLargeCutCollect( p, pRoot, pCutR, pCutL, Leaf, vLeaves, vNodes ); /* // collect the nodes - Dar_CutForEachLeaf( p, pCutR, pObj, i ) + Aig_CutForEachLeaf( p, pCutR, pObj, i ) { if ( pObj->Id == Leaf ) continue; @@ -316,7 +318,7 @@ int Dar_ManLargeCutEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Da Vec_IntPush( vLeaves, pObj->Id ); Vec_IntPush( vNodes, pObj->Id ); } - Dar_CutForEachLeaf( p, pCutL, pObj, i ) + Aig_CutForEachLeaf( p, pCutL, pObj, i ) { if ( pObj->fMarkA ) continue; @@ -325,14 +327,14 @@ int Dar_ManLargeCutEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Da Vec_IntPush( vNodes, pObj->Id ); } // collect and mark the nodes - Dar_ManCollectCut_rec( p, pRoot, vNodes ); + Aig_ManCollectCut_rec( p, pRoot, vNodes ); // clean the nodes Vec_IntForEachEntry( vNodes, Leaf, i ) - Dar_ManObj(p, Leaf)->fMarkA = 0; + Aig_ManObj(p, Leaf)->fMarkA = 0; */ - pTruth = Dar_ManCutTruth( p, pRoot, vLeaves, vNodes, vTruth ); - RetValue = Dar_ManLargeCutEvalIsop( pTruth, Vec_IntSize(vLeaves), vMemory ); + pTruth = Aig_ManCutTruth( p, pRoot, vLeaves, vNodes, vTruth ); + RetValue = Aig_ManLargeCutEvalIsop( pTruth, Vec_IntSize(vLeaves), vMemory ); Vec_IntFree( vLeaves ); Vec_IntFree( vNodes ); @@ -342,6 +344,7 @@ int Dar_ManLargeCutEval( Dar_Man_t * p, Dar_Obj_t * pRoot, Dar_Cut_t * pCutR, Da return RetValue; } +#endif //////////////////////////////////////////////////////////////////////// /// END OF FILE /// diff --git a/src/aig/dar/darUtil.c b/src/aig/dar/darUtil.c deleted file mode 100644 index 052fad60..00000000 --- a/src/aig/dar/darUtil.c +++ /dev/null @@ -1,625 +0,0 @@ -/**CFile**************************************************************** - - FileName [darUtil.c] - - SystemName [ABC: Logic synthesis and verification system.] - - PackageName [DAG-aware AIG rewriting.] - - Synopsis [Various procedures.] - - Author [Alan Mishchenko] - - Affiliation [UC Berkeley] - - Date [Ver. 1.0. Started - April 28, 2007.] - - Revision [$Id: darUtil.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $] - -***********************************************************************/ - -#include "dar.h" - -//////////////////////////////////////////////////////////////////////// -/// DECLARATIONS /// -//////////////////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////////////////// -/// FUNCTION DEFINITIONS /// -//////////////////////////////////////////////////////////////////////// - -/**Function************************************************************* - - Synopsis [Returns the structure with default assignment of parameters.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Par_t * Dar_ManDefaultParams() -{ - Dar_Par_t * p; - p = ALLOC( Dar_Par_t, 1 ); - memset( p, 0, sizeof(Dar_Par_t) ); - return p; -} - -/**Function************************************************************* - - Synopsis [Increments the current traversal ID of the network.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManIncrementTravId( Dar_Man_t * p ) -{ - if ( p->nTravIds >= (1<<30)-1 ) - Dar_ManCleanData( p ); - p->nTravIds++; -} - -/**Function************************************************************* - - Synopsis [Collect the latches.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ManLevels( Dar_Man_t * p ) -{ - Dar_Obj_t * pObj; - int i, LevelMax = 0; - Dar_ManForEachPo( p, pObj, i ) - LevelMax = DAR_MAX( LevelMax, (int)Dar_ObjFanin0(pObj)->Level ); - return LevelMax; -} - -/**Function************************************************************* - - Synopsis [Cleans the data pointers for the nodes.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManCleanData( Dar_Man_t * p ) -{ - Dar_Obj_t * pObj; - int i; - Dar_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 Dar_ObjCleanData_rec( Dar_Obj_t * pObj ) -{ - assert( !Dar_IsComplement(pObj) ); - assert( !Dar_ObjIsPo(pObj) ); - if ( Dar_ObjIsAnd(pObj) ) - { - Dar_ObjCleanData_rec( Dar_ObjFanin0(pObj) ); - Dar_ObjCleanData_rec( Dar_ObjFanin1(pObj) ); - } - pObj->pData = NULL; -} - -/**Function************************************************************* - - Synopsis [Detects multi-input gate rooted at this node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjCollectMulti_rec( Dar_Obj_t * pRoot, Dar_Obj_t * pObj, Vec_Ptr_t * vSuper ) -{ - if ( pRoot != pObj && (Dar_IsComplement(pObj) || Dar_ObjIsPi(pObj) || Dar_ObjType(pRoot) != Dar_ObjType(pObj)) ) - { - Vec_PtrPushUnique(vSuper, pObj); - return; - } - Dar_ObjCollectMulti_rec( pRoot, Dar_ObjChild0(pObj), vSuper ); - Dar_ObjCollectMulti_rec( pRoot, Dar_ObjChild1(pObj), vSuper ); -} - -/**Function************************************************************* - - Synopsis [Detects multi-input gate rooted at this node.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ObjCollectMulti( Dar_Obj_t * pRoot, Vec_Ptr_t * vSuper ) -{ - assert( !Dar_IsComplement(pRoot) ); - Vec_PtrClear( vSuper ); - Dar_ObjCollectMulti_rec( pRoot, pRoot, vSuper ); -} - -/**Function************************************************************* - - Synopsis [Returns 1 if the node is the root of MUX or EXOR/NEXOR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ObjIsMuxType( Dar_Obj_t * pNode ) -{ - Dar_Obj_t * pNode0, * pNode1; - // check that the node is regular - assert( !Dar_IsComplement(pNode) ); - // if the node is not AND, this is not MUX - if ( !Dar_ObjIsAnd(pNode) ) - return 0; - // if the children are not complemented, this is not MUX - if ( !Dar_ObjFaninC0(pNode) || !Dar_ObjFaninC1(pNode) ) - return 0; - // get children - pNode0 = Dar_ObjFanin0(pNode); - pNode1 = Dar_ObjFanin1(pNode); - // if the children are not ANDs, this is not MUX - if ( !Dar_ObjIsAnd(pNode0) || !Dar_ObjIsAnd(pNode1) ) - return 0; - // otherwise the node is MUX iff it has a pair of equal grandchildren - return (Dar_ObjFanin0(pNode0) == Dar_ObjFanin0(pNode1) && (Dar_ObjFaninC0(pNode0) ^ Dar_ObjFaninC0(pNode1))) || - (Dar_ObjFanin0(pNode0) == Dar_ObjFanin1(pNode1) && (Dar_ObjFaninC0(pNode0) ^ Dar_ObjFaninC1(pNode1))) || - (Dar_ObjFanin1(pNode0) == Dar_ObjFanin0(pNode1) && (Dar_ObjFaninC1(pNode0) ^ Dar_ObjFaninC0(pNode1))) || - (Dar_ObjFanin1(pNode0) == Dar_ObjFanin1(pNode1) && (Dar_ObjFaninC1(pNode0) ^ Dar_ObjFaninC1(pNode1))); -} - - -/**Function************************************************************* - - Synopsis [Recognizes what nodes are inputs of the EXOR.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -int Dar_ObjRecognizeExor( Dar_Obj_t * pObj, Dar_Obj_t ** ppFan0, Dar_Obj_t ** ppFan1 ) -{ - Dar_Obj_t * p0, * p1; - assert( !Dar_IsComplement(pObj) ); - if ( !Dar_ObjIsNode(pObj) ) - return 0; - if ( Dar_ObjIsExor(pObj) ) - { - *ppFan0 = Dar_ObjChild0(pObj); - *ppFan1 = Dar_ObjChild1(pObj); - return 1; - } - assert( Dar_ObjIsAnd(pObj) ); - p0 = Dar_ObjChild0(pObj); - p1 = Dar_ObjChild1(pObj); - if ( !Dar_IsComplement(p0) || !Dar_IsComplement(p1) ) - return 0; - p0 = Dar_Regular(p0); - p1 = Dar_Regular(p1); - if ( !Dar_ObjIsAnd(p0) || !Dar_ObjIsAnd(p1) ) - return 0; - if ( Dar_ObjFanin0(p0) != Dar_ObjFanin0(p1) || Dar_ObjFanin1(p0) != Dar_ObjFanin1(p1) ) - return 0; - if ( Dar_ObjFaninC0(p0) == Dar_ObjFaninC0(p1) || Dar_ObjFaninC1(p0) == Dar_ObjFaninC1(p1) ) - return 0; - *ppFan0 = Dar_ObjChild0(p0); - *ppFan1 = Dar_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 [] - -***********************************************************************/ -Dar_Obj_t * Dar_ObjRecognizeMux( Dar_Obj_t * pNode, Dar_Obj_t ** ppNodeT, Dar_Obj_t ** ppNodeE ) -{ - Dar_Obj_t * pNode0, * pNode1; - assert( !Dar_IsComplement(pNode) ); - assert( Dar_ObjIsMuxType(pNode) ); - // get children - pNode0 = Dar_ObjFanin0(pNode); - pNode1 = Dar_ObjFanin1(pNode); - - // find the control variable - if ( Dar_ObjFanin1(pNode0) == Dar_ObjFanin1(pNode1) && (Dar_ObjFaninC1(pNode0) ^ Dar_ObjFaninC1(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p2) ) - if ( Dar_ObjFaninC1(pNode0) ) - { // pNode2->p2 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild0(pNode1));//pNode2->p1); - *ppNodeE = Dar_Not(Dar_ObjChild0(pNode0));//pNode1->p1); - return Dar_ObjChild1(pNode1);//pNode2->p2; - } - else - { // pNode1->p2 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild0(pNode0));//pNode1->p1); - *ppNodeE = Dar_Not(Dar_ObjChild0(pNode1));//pNode2->p1); - return Dar_ObjChild1(pNode0);//pNode1->p2; - } - } - else if ( Dar_ObjFanin0(pNode0) == Dar_ObjFanin0(pNode1) && (Dar_ObjFaninC0(pNode0) ^ Dar_ObjFaninC0(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p1) ) - if ( Dar_ObjFaninC0(pNode0) ) - { // pNode2->p1 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild1(pNode1));//pNode2->p2); - *ppNodeE = Dar_Not(Dar_ObjChild1(pNode0));//pNode1->p2); - return Dar_ObjChild0(pNode1);//pNode2->p1; - } - else - { // pNode1->p1 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild1(pNode0));//pNode1->p2); - *ppNodeE = Dar_Not(Dar_ObjChild1(pNode1));//pNode2->p2); - return Dar_ObjChild0(pNode0);//pNode1->p1; - } - } - else if ( Dar_ObjFanin0(pNode0) == Dar_ObjFanin1(pNode1) && (Dar_ObjFaninC0(pNode0) ^ Dar_ObjFaninC1(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p1) ) - if ( Dar_ObjFaninC0(pNode0) ) - { // pNode2->p2 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild0(pNode1));//pNode2->p1); - *ppNodeE = Dar_Not(Dar_ObjChild1(pNode0));//pNode1->p2); - return Dar_ObjChild1(pNode1);//pNode2->p2; - } - else - { // pNode1->p1 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild1(pNode0));//pNode1->p2); - *ppNodeE = Dar_Not(Dar_ObjChild0(pNode1));//pNode2->p1); - return Dar_ObjChild0(pNode0);//pNode1->p1; - } - } - else if ( Dar_ObjFanin1(pNode0) == Dar_ObjFanin0(pNode1) && (Dar_ObjFaninC1(pNode0) ^ Dar_ObjFaninC0(pNode1)) ) - { -// if ( Fraig_IsComplement(pNode1->p2) ) - if ( Dar_ObjFaninC1(pNode0) ) - { // pNode2->p1 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild1(pNode1));//pNode2->p2); - *ppNodeE = Dar_Not(Dar_ObjChild0(pNode0));//pNode1->p1); - return Dar_ObjChild0(pNode1);//pNode2->p1; - } - else - { // pNode1->p2 is positive phase of C - *ppNodeT = Dar_Not(Dar_ObjChild0(pNode0));//pNode1->p1); - *ppNodeE = Dar_Not(Dar_ObjChild1(pNode1));//pNode2->p2); - return Dar_ObjChild1(pNode0);//pNode1->p2; - } - } - assert( 0 ); // this is not MUX - return NULL; -} - -/**Function************************************************************* - - Synopsis [] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -Dar_Obj_t * Dar_ObjReal_rec( Dar_Obj_t * pObj ) -{ - Dar_Obj_t * pObjNew, * pObjR = Dar_Regular(pObj); - if ( !Dar_ObjIsBuf(pObjR) ) - return pObj; - pObjNew = Dar_ObjReal_rec( Dar_ObjChild0(pObjR) ); - return Dar_NotCond( pObjNew, Dar_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 Dar_ObjPrintEqn( FILE * pFile, Dar_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ) -{ - Vec_Ptr_t * vSuper; - Dar_Obj_t * pFanin; - int fCompl, i; - // store the complemented attribute - fCompl = Dar_IsComplement(pObj); - pObj = Dar_Regular(pObj); - // constant case - if ( Dar_ObjIsConst1(pObj) ) - { - fprintf( pFile, "%d", !fCompl ); - return; - } - // PI case - if ( Dar_ObjIsPi(pObj) ) - { - fprintf( pFile, "%s%s", fCompl? "!" : "", pObj->pData ); - return; - } - // AND case - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry(vLevels, Level); - Dar_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Dar_ObjPrintEqn( pFile, Dar_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 Dar_ObjPrintVerilog( FILE * pFile, Dar_Obj_t * pObj, Vec_Vec_t * vLevels, int Level ) -{ - Vec_Ptr_t * vSuper; - Dar_Obj_t * pFanin, * pFanin0, * pFanin1, * pFaninC; - int fCompl, i; - // store the complemented attribute - fCompl = Dar_IsComplement(pObj); - pObj = Dar_Regular(pObj); - // constant case - if ( Dar_ObjIsConst1(pObj) ) - { - fprintf( pFile, "1\'b%d", !fCompl ); - return; - } - // PI case - if ( Dar_ObjIsPi(pObj) ) - { - fprintf( pFile, "%s%s", fCompl? "~" : "", pObj->pData ); - return; - } - // EXOR case - if ( Dar_ObjIsExor(pObj) ) - { - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry( vLevels, Level ); - Dar_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Dar_ObjPrintVerilog( pFile, Dar_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 ( Dar_ObjIsMuxType(pObj) ) - { - if ( Dar_ObjRecognizeExor( pObj, &pFanin0, &pFanin1 ) ) - { - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Dar_ObjPrintVerilog( pFile, Dar_NotCond(pFanin0, fCompl), vLevels, Level+1 ); - fprintf( pFile, " ^ " ); - Dar_ObjPrintVerilog( pFile, pFanin1, vLevels, Level+1 ); - fprintf( pFile, "%s", (Level==0? "" : ")") ); - } - else - { - pFaninC = Dar_ObjRecognizeMux( pObj, &pFanin1, &pFanin0 ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Dar_ObjPrintVerilog( pFile, pFaninC, vLevels, Level+1 ); - fprintf( pFile, " ? " ); - Dar_ObjPrintVerilog( pFile, Dar_NotCond(pFanin1, fCompl), vLevels, Level+1 ); - fprintf( pFile, " : " ); - Dar_ObjPrintVerilog( pFile, Dar_NotCond(pFanin0, fCompl), vLevels, Level+1 ); - fprintf( pFile, "%s", (Level==0? "" : ")") ); - } - return; - } - // AND case - Vec_VecExpand( vLevels, Level ); - vSuper = Vec_VecEntry(vLevels, Level); - Dar_ObjCollectMulti( pObj, vSuper ); - fprintf( pFile, "%s", (Level==0? "" : "(") ); - Vec_PtrForEachEntry( vSuper, pFanin, i ) - { - Dar_ObjPrintVerilog( pFile, Dar_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 Dar_ObjPrintVerbose( Dar_Obj_t * pObj, int fHaig ) -{ - assert( !Dar_IsComplement(pObj) ); - printf( "Node %p : ", pObj ); - if ( Dar_ObjIsConst1(pObj) ) - printf( "constant 1" ); - else if ( Dar_ObjIsPi(pObj) ) - printf( "PI" ); - else - printf( "AND( %p%s, %p%s )", - Dar_ObjFanin0(pObj), (Dar_ObjFaninC0(pObj)? "\'" : " "), - Dar_ObjFanin1(pObj), (Dar_ObjFaninC1(pObj)? "\'" : " ") ); - printf( " (refs = %3d)", Dar_ObjRefs(pObj) ); -} - -/**Function************************************************************* - - Synopsis [Prints node in HAIG.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManPrintVerbose( Dar_Man_t * p, int fHaig ) -{ - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj; - int i; - printf( "PIs: " ); - Dar_ManForEachPi( p, pObj, i ) - printf( " %p", pObj ); - printf( "\n" ); - vNodes = Dar_ManDfs( p ); - Vec_PtrForEachEntry( vNodes, pObj, i ) - Dar_ObjPrintVerbose( pObj, fHaig ), printf( "\n" ); - printf( "\n" ); -} - -/**Function************************************************************* - - Synopsis [Writes the AIG into the BLIF file.] - - Description [] - - SideEffects [] - - SeeAlso [] - -***********************************************************************/ -void Dar_ManDumpBlif( Dar_Man_t * p, char * pFileName ) -{ - FILE * pFile; - Vec_Ptr_t * vNodes; - Dar_Obj_t * pObj, * pConst1 = NULL; - int i, nDigits, Counter = 0; - if ( Dar_ManPoNum(p) == 0 ) - { - printf( "Dar_ManDumpBlif(): AIG manager does not have POs.\n" ); - return; - } - // collect nodes in the DFS order - vNodes = Dar_ManDfs( p ); - // assign IDs to objects - Dar_ManConst1(p)->pData = (void *)Counter++; - Dar_ManForEachPi( p, pObj, i ) - pObj->pData = (void *)Counter++; - Dar_ManForEachPo( p, pObj, i ) - pObj->pData = (void *)Counter++; - Vec_PtrForEachEntry( vNodes, pObj, i ) - pObj->pData = (void *)Counter++; - nDigits = Extra_Base10Log( Counter ); - // write the file - pFile = fopen( pFileName, "w" ); - fprintf( pFile, "# BLIF file written by procedure Dar_ManDumpBlif() in ABC\n" ); - fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" ); - fprintf( pFile, ".model test\n" ); - // write PIs - fprintf( pFile, ".inputs" ); - Dar_ManForEachPi( p, pObj, i ) - fprintf( pFile, " n%0*d", nDigits, (int)pObj->pData ); - fprintf( pFile, "\n" ); - // write POs - fprintf( pFile, ".outputs" ); - Dar_ManForEachPo( p, pObj, i ) - fprintf( pFile, " n%0*d", nDigits, (int)pObj->pData ); - fprintf( pFile, "\n" ); - // write nodes - Vec_PtrForEachEntry( vNodes, pObj, i ) - { - fprintf( pFile, ".names n%0*d n%0*d n%0*d\n", - nDigits, (int)Dar_ObjFanin0(pObj)->pData, - nDigits, (int)Dar_ObjFanin1(pObj)->pData, - nDigits, (int)pObj->pData ); - fprintf( pFile, "%d%d 1\n", !Dar_ObjFaninC0(pObj), !Dar_ObjFaninC1(pObj) ); - } - // write POs - Dar_ManForEachPo( p, pObj, i ) - { - fprintf( pFile, ".names n%0*d n%0*d\n", - nDigits, (int)Dar_ObjFanin0(pObj)->pData, - nDigits, (int)pObj->pData ); - fprintf( pFile, "%d 1\n", !Dar_ObjFaninC0(pObj) ); - if ( Dar_ObjIsConst1(Dar_ObjFanin0(pObj)) ) - pConst1 = Dar_ManConst1(p); - } - if ( pConst1 ) - fprintf( pFile, ".names n%0*d\n 1\n", nDigits, (int)pConst1->pData ); - fprintf( pFile, ".end\n\n" ); - fclose( pFile ); - Vec_PtrFree( vNodes ); -} - -//////////////////////////////////////////////////////////////////////// -/// END OF FILE /// -//////////////////////////////////////////////////////////////////////// - - diff --git a/src/aig/dar/module.make b/src/aig/dar/module.make index 4bf473d4..bcf9a2e6 100644 --- a/src/aig/dar/module.make +++ b/src/aig/dar/module.make @@ -1,15 +1,7 @@ SRC += src/aig/dar/darBalance.c \ - src/aig/dar/darCheck.c \ src/aig/dar/darCore.c \ src/aig/dar/darCut.c \ src/aig/dar/darData.c \ - src/aig/dar/darDfs.c \ src/aig/dar/darLib.c \ src/aig/dar/darMan.c \ - src/aig/dar/darMem.c \ - src/aig/dar/darObj.c \ - src/aig/dar/darOper.c \ - src/aig/dar/darSeq.c \ - src/aig/dar/darTable.c \ - src/aig/dar/darTruth.c \ - src/aig/dar/darUtil.c + src/aig/dar/darTruth.c diff --git a/src/aig/fra/fra.h b/src/aig/fra/fra.h index 29195d19..7f2df105 100644 --- a/src/aig/fra/fra.h +++ b/src/aig/fra/fra.h @@ -36,6 +36,7 @@ extern "C" { #include #include "vec.h" +#include "aig.h" #include "dar.h" #include "satSolver.h" @@ -73,8 +74,8 @@ struct Fra_Man_t_ // high-level data Fra_Par_t * pPars; // parameters governing fraiging // AIG managers - Dar_Man_t * pManAig; // the starting AIG manager - Dar_Man_t * pManFraig; // the final AIG manager + Aig_Man_t * pManAig; // the starting AIG manager + Aig_Man_t * pManFraig; // the final AIG manager // simulation info unsigned * pSimWords; // memory for simulation information int nSimWords; // the number of simulation words @@ -86,8 +87,8 @@ struct Fra_Man_t_ Vec_Ptr_t * vClasses; // equivalence classes Vec_Ptr_t * vClasses1; // equivalence class of Const1 node Vec_Ptr_t * vClassesTemp; // temporary storage for new classes - Dar_Obj_t ** pMemClasses; // memory allocated for equivalence classes - Dar_Obj_t ** pMemClassesFree; // memory allocated for equivalence classes to be used + Aig_Obj_t ** pMemClasses; // memory allocated for equivalence classes + Aig_Obj_t ** pMemClassesFree; // memory allocated for equivalence classes to be used Vec_Ptr_t * vClassOld; // old equivalence class after splitting Vec_Ptr_t * vClassNew; // new equivalence class(es) after splitting int nPairs; // the number of pairs of nodes @@ -98,8 +99,8 @@ struct Fra_Man_t_ sint64 nBTLimitGlobal; // resource limit sint64 nInsLimitGlobal; // resource limit // various data members - Dar_Obj_t ** pMemFraig; // memory allocated for points to the fraig nodes - Dar_Obj_t ** pMemRepr; // memory allocated for points to the node representatives + Aig_Obj_t ** pMemFraig; // memory allocated for points to the fraig nodes + Aig_Obj_t ** pMemRepr; // memory allocated for points to the node representatives Vec_Ptr_t ** pMemFanins; // the arrays of fanins int * pMemSatNums; // the array of SAT numbers int nSizeAlloc; // allocated size of the arrays @@ -135,21 +136,21 @@ struct Fra_Man_t_ /// MACRO DEFINITIONS /// //////////////////////////////////////////////////////////////////////// -static inline unsigned * Fra_ObjSim( Dar_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pSimWords + ((Fra_Man_t *)pObj->pData)->nSimWords * pObj->Id; } +static inline unsigned * Fra_ObjSim( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pSimWords + ((Fra_Man_t *)pObj->pData)->nSimWords * pObj->Id; } static inline unsigned Fra_ObjRandomSim() { return (rand() << 24) ^ (rand() << 12) ^ rand(); } -static inline Dar_Obj_t * Fra_ObjFraig( Dar_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemFraig[pObj->Id]; } -static inline Dar_Obj_t * Fra_ObjRepr( Dar_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemRepr[pObj->Id]; } -static inline Vec_Ptr_t * Fra_ObjFaninVec( Dar_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemFanins[pObj->Id]; } -static inline int Fra_ObjSatNum( Dar_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemSatNums[pObj->Id]; } +static inline Aig_Obj_t * Fra_ObjFraig( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemFraig[pObj->Id]; } +static inline Aig_Obj_t * Fra_ObjRepr( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemRepr[pObj->Id]; } +static inline Vec_Ptr_t * Fra_ObjFaninVec( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemFanins[pObj->Id]; } +static inline int Fra_ObjSatNum( Aig_Obj_t * pObj ) { return ((Fra_Man_t *)pObj->pData)->pMemSatNums[pObj->Id]; } -static inline void Fra_ObjSetFraig( Dar_Obj_t * pObj, Dar_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pMemFraig[pObj->Id] = pNode; } -static inline void Fra_ObjSetRepr( Dar_Obj_t * pObj, Dar_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pMemRepr[pObj->Id] = pNode; } -static inline void Fra_ObjSetFaninVec( Dar_Obj_t * pObj, Vec_Ptr_t * vFanins ) { ((Fra_Man_t *)pObj->pData)->pMemFanins[pObj->Id] = vFanins; } -static inline void Fra_ObjSetSatNum( Dar_Obj_t * pObj, int Num ) { ((Fra_Man_t *)pObj->pData)->pMemSatNums[pObj->Id] = Num; } +static inline void Fra_ObjSetFraig( Aig_Obj_t * pObj, Aig_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pMemFraig[pObj->Id] = pNode; } +static inline void Fra_ObjSetRepr( Aig_Obj_t * pObj, Aig_Obj_t * pNode ) { ((Fra_Man_t *)pObj->pData)->pMemRepr[pObj->Id] = pNode; } +static inline void Fra_ObjSetFaninVec( Aig_Obj_t * pObj, Vec_Ptr_t * vFanins ) { ((Fra_Man_t *)pObj->pData)->pMemFanins[pObj->Id] = vFanins; } +static inline void Fra_ObjSetSatNum( Aig_Obj_t * pObj, int Num ) { ((Fra_Man_t *)pObj->pData)->pMemSatNums[pObj->Id] = Num; } -static inline Dar_Obj_t * Fra_ObjChild0Fra( Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin0(pObj)? Dar_NotCond(Fra_ObjFraig(Dar_ObjFanin0(pObj)), Dar_ObjFaninC0(pObj)) : NULL; } -static inline Dar_Obj_t * Fra_ObjChild1Fra( Dar_Obj_t * pObj ) { assert( !Dar_IsComplement(pObj) ); return Dar_ObjFanin1(pObj)? Dar_NotCond(Fra_ObjFraig(Dar_ObjFanin1(pObj)), Dar_ObjFaninC1(pObj)) : NULL; } +static inline Aig_Obj_t * Fra_ObjChild0Fra( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin0(pObj)? Aig_NotCond(Fra_ObjFraig(Aig_ObjFanin0(pObj)), Aig_ObjFaninC0(pObj)) : NULL; } +static inline Aig_Obj_t * Fra_ObjChild1Fra( Aig_Obj_t * pObj ) { assert( !Aig_IsComplement(pObj) ); return Aig_ObjFanin1(pObj)? Aig_NotCond(Fra_ObjFraig(Aig_ObjFanin1(pObj)), Aig_ObjFaninC1(pObj)) : NULL; } //////////////////////////////////////////////////////////////////////// /// ITERATORS /// @@ -167,21 +168,21 @@ extern void Fra_CreateClasses( Fra_Man_t * p ); extern int Fra_RefineClasses( Fra_Man_t * p ); extern int Fra_RefineClasses1( Fra_Man_t * p ); /*=== fraCnf.c ========================================================*/ -extern void Fra_NodeAddToSolver( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ); +extern void Fra_NodeAddToSolver( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ); /*=== fraCore.c ========================================================*/ -extern Dar_Man_t * Fra_Perform( Dar_Man_t * pManAig, Fra_Par_t * pParams ); +extern Aig_Man_t * Fra_Perform( Aig_Man_t * pManAig, Fra_Par_t * pParams ); /*=== fraMan.c ========================================================*/ extern void Fra_ParamsDefault( Fra_Par_t * pParams ); -extern Fra_Man_t * Fra_ManStart( Dar_Man_t * pManAig, Fra_Par_t * pParams ); +extern Fra_Man_t * Fra_ManStart( Aig_Man_t * pManAig, Fra_Par_t * pParams ); extern void Fra_ManPrepare( Fra_Man_t * p ); extern void Fra_ManStop( Fra_Man_t * p ); extern void Fra_ManPrint( Fra_Man_t * p ); /*=== fraSat.c ========================================================*/ -extern int Fra_NodesAreEquiv( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ); -extern int Fra_NodeIsConst( Fra_Man_t * p, Dar_Obj_t * pNew ); +extern int Fra_NodesAreEquiv( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ); +extern int Fra_NodeIsConst( Fra_Man_t * p, Aig_Obj_t * pNew ); /*=== fraSim.c ========================================================*/ -extern int Fra_NodeHasZeroSim( Fra_Man_t * p, Dar_Obj_t * pObj ); -extern int Fra_NodeCompareSims( Fra_Man_t * p, Dar_Obj_t * pObj0, Dar_Obj_t * pObj1 ); +extern int Fra_NodeHasZeroSim( Fra_Man_t * p, Aig_Obj_t * pObj ); +extern int Fra_NodeCompareSims( Fra_Man_t * p, Aig_Obj_t * pObj0, Aig_Obj_t * pObj1 ); extern void Fra_SavePattern( Fra_Man_t * p ); extern void Fra_Simulate( Fra_Man_t * p ); extern void Fra_Resimulate( Fra_Man_t * p ); diff --git a/src/aig/fra/fraAnd.c b/src/aig/fra/fraAnd.c index a360ce9b..36b4ccc3 100644 --- a/src/aig/fra/fraAnd.c +++ b/src/aig/fra/fraAnd.c @@ -40,48 +40,48 @@ SeeAlso [] ***********************************************************************/ -Dar_Obj_t * Fra_And( Fra_Man_t * p, Dar_Obj_t * pObjOld ) +Aig_Obj_t * Fra_And( Fra_Man_t * p, Aig_Obj_t * pObjOld ) { - Dar_Obj_t * pObjOldRepr, * pObjFraig, * pFanin0Fraig, * pFanin1Fraig, * pObjOldReprFraig; + Aig_Obj_t * pObjOldRepr, * pObjFraig, * pFanin0Fraig, * pFanin1Fraig, * pObjOldReprFraig; int RetValue; - assert( !Dar_IsComplement(pObjOld) ); - assert( Dar_ObjIsNode(pObjOld) ); + assert( !Aig_IsComplement(pObjOld) ); + assert( Aig_ObjIsNode(pObjOld) ); // get the fraiged fanins pFanin0Fraig = Fra_ObjChild0Fra(pObjOld); pFanin1Fraig = Fra_ObjChild1Fra(pObjOld); // get the fraiged node - pObjFraig = Dar_And( p->pManFraig, pFanin0Fraig, pFanin1Fraig ); - if ( Dar_ObjIsConst1(Dar_Regular(pObjFraig)) ) + pObjFraig = Aig_And( p->pManFraig, pFanin0Fraig, pFanin1Fraig ); + if ( Aig_ObjIsConst1(Aig_Regular(pObjFraig)) ) return pObjFraig; - Dar_Regular(pObjFraig)->pData = p; + Aig_Regular(pObjFraig)->pData = p; // get representative of this class pObjOldRepr = Fra_ObjRepr(pObjOld); if ( pObjOldRepr == NULL || // this is a unique node - (!p->pPars->fDoSparse && pObjOldRepr == Dar_ManConst1(p->pManAig)) ) // this is a sparse node + (!p->pPars->fDoSparse && pObjOldRepr == Aig_ManConst1(p->pManAig)) ) // this is a sparse node { - assert( Dar_Regular(pFanin0Fraig) != Dar_Regular(pFanin1Fraig) ); - assert( Dar_Regular(pObjFraig) != Dar_Regular(pFanin0Fraig) ); - assert( Dar_Regular(pObjFraig) != Dar_Regular(pFanin1Fraig) ); + assert( Aig_Regular(pFanin0Fraig) != Aig_Regular(pFanin1Fraig) ); + assert( Aig_Regular(pObjFraig) != Aig_Regular(pFanin0Fraig) ); + assert( Aig_Regular(pObjFraig) != Aig_Regular(pFanin1Fraig) ); return pObjFraig; } // get the fraiged representative pObjOldReprFraig = Fra_ObjFraig(pObjOldRepr); // if the fraiged nodes are the same, return - if ( Dar_Regular(pObjFraig) == Dar_Regular(pObjOldReprFraig) ) + if ( Aig_Regular(pObjFraig) == Aig_Regular(pObjOldReprFraig) ) return pObjFraig; - assert( Dar_Regular(pObjFraig) != Dar_ManConst1(p->pManFraig) ); + assert( Aig_Regular(pObjFraig) != Aig_ManConst1(p->pManFraig) ); // printf( "Node = %d. Repr = %d.\n", pObjOld->Id, pObjOldRepr->Id ); // if they are proved different, the c-ex will be in p->pPatWords - RetValue = Fra_NodesAreEquiv( p, Dar_Regular(pObjOldReprFraig), Dar_Regular(pObjFraig) ); + RetValue = Fra_NodesAreEquiv( p, Aig_Regular(pObjOldReprFraig), Aig_Regular(pObjFraig) ); if ( RetValue == 1 ) // proved equivalent { // pObjOld->fMarkA = 1; - return Dar_NotCond( pObjOldReprFraig, pObjOld->fPhase ^ pObjOldRepr->fPhase ); + return Aig_NotCond( pObjOldReprFraig, pObjOld->fPhase ^ pObjOldRepr->fPhase ); } if ( RetValue == -1 ) // failed { - Dar_Obj_t * ppNodes[2] = { Dar_Regular(pObjOldReprFraig), Dar_Regular(pObjFraig) }; + Aig_Obj_t * ppNodes[2] = { Aig_Regular(pObjOldReprFraig), Aig_Regular(pObjFraig) }; Vec_Ptr_t * vNodes; if ( !p->pPars->fSpeculate ) @@ -90,11 +90,11 @@ Dar_Obj_t * Fra_And( Fra_Man_t * p, Dar_Obj_t * pObjOld ) // pObjOld->fMarkB = 1; p->nSpeculs++; - vNodes = Dar_ManDfsNodes( p->pManFraig, ppNodes, 2 ); + vNodes = Aig_ManDfsNodes( p->pManFraig, ppNodes, 2 ); printf( "%d ", Vec_PtrSize(vNodes) ); Vec_PtrFree( vNodes ); - return Dar_NotCond( pObjOldReprFraig, pObjOld->fPhase ^ pObjOldRepr->fPhase ); + return Aig_NotCond( pObjOldReprFraig, pObjOld->fPhase ^ pObjOldRepr->fPhase ); } // printf( "Disproved %d and %d.\n", pObjOldRepr->Id, pObjOld->Id ); // simulate the counter-example and return the Fraig node @@ -118,18 +118,18 @@ Dar_Obj_t * Fra_And( Fra_Man_t * p, Dar_Obj_t * pObjOld ) ***********************************************************************/ void Fra_Sweep( Fra_Man_t * p ) { - Dar_Obj_t * pObj, * pObjNew; + Aig_Obj_t * pObj, * pObjNew; int i, k = 0; p->nClassesZero = Vec_PtrSize(p->vClasses1); p->nClassesBeg = Vec_PtrSize(p->vClasses) + (int)(Vec_PtrSize(p->vClasses1) > 0); // duplicate internal nodes -// p->pProgress = Extra_ProgressBarStart( stdout, Dar_ManNodeNum(p->pManAig) ); - Dar_ManForEachNode( p->pManAig, pObj, i ) +// p->pProgress = Extra_ProgressBarStart( stdout, Aig_ManNodeNum(p->pManAig) ); + Aig_ManForEachNode( p->pManAig, pObj, i ) { // Extra_ProgressBarUpdate( p->pProgress, k++, NULL ); // default to simple strashing if simulation detected a counter-example for a PO if ( p->pManFraig->pData ) - pObjNew = Dar_And( p->pManFraig, Fra_ObjChild0Fra(pObj), Fra_ObjChild1Fra(pObj) ); + pObjNew = Aig_And( p->pManFraig, Fra_ObjChild0Fra(pObj), Fra_ObjChild1Fra(pObj) ); else pObjNew = Fra_And( p, pObj ); // pObjNew can be complemented Fra_ObjSetFraig( pObj, pObjNew ); @@ -138,15 +138,15 @@ p->nClassesBeg = Vec_PtrSize(p->vClasses) + (int)(Vec_PtrSize(p->vClasses1) > 0 // Extra_ProgressBarStop( p->pProgress ); p->nClassesEnd = Vec_PtrSize(p->vClasses) + (int)(Vec_PtrSize(p->vClasses1) > 0); // try to prove the outputs of the miter - p->nNodesMiter = Dar_ManNodeNum(p->pManFraig); + p->nNodesMiter = Aig_ManNodeNum(p->pManFraig); // Fra_MiterStatus( p->pManFraig ); // if ( p->pPars->fProve && p->pManFraig->pData == NULL ) // Fra_MiterProve( p ); // add the POs - Dar_ManForEachPo( p->pManAig, pObj, i ) - Dar_ObjCreatePo( p->pManFraig, Fra_ObjChild0Fra(pObj) ); + Aig_ManForEachPo( p->pManAig, pObj, i ) + Aig_ObjCreatePo( p->pManFraig, Fra_ObjChild0Fra(pObj) ); // remove dangling nodes - Dar_ManCleanup( p->pManFraig ); + Aig_ManCleanup( p->pManFraig ); } //////////////////////////////////////////////////////////////////////// diff --git a/src/aig/fra/fraClass.c b/src/aig/fra/fraClass.c index 33421423..3de54453 100644 --- a/src/aig/fra/fraClass.c +++ b/src/aig/fra/fraClass.c @@ -36,8 +36,8 @@ /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -static inline Dar_Obj_t * Fra_ObjNext( Dar_Obj_t ** ppNexts, Dar_Obj_t * pObj ) { return ppNexts[pObj->Id]; } -static inline void Fra_ObjSetNext( Dar_Obj_t ** ppNexts, Dar_Obj_t * pObj, Dar_Obj_t * pNext ) { ppNexts[pObj->Id] = pNext; } +static inline Aig_Obj_t * Fra_ObjNext( Aig_Obj_t ** ppNexts, Aig_Obj_t * pObj ) { return ppNexts[pObj->Id]; } +static inline void Fra_ObjSetNext( Aig_Obj_t ** ppNexts, Aig_Obj_t * pObj, Aig_Obj_t * pNext ) { ppNexts[pObj->Id] = pNext; } //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -54,9 +54,9 @@ static inline void Fra_ObjSetNext( Dar_Obj_t ** ppNexts, Dar_Obj_t * pOb SeeAlso [] ***********************************************************************/ -void Fra_PrintClass( Dar_Obj_t ** pClass ) +void Fra_PrintClass( Aig_Obj_t ** pClass ) { - Dar_Obj_t * pTemp; + Aig_Obj_t * pTemp; int i; printf( "{ " ); for ( i = 0; pTemp = pClass[i]; i++ ) @@ -75,9 +75,9 @@ void Fra_PrintClass( Dar_Obj_t ** pClass ) SeeAlso [] ***********************************************************************/ -int Fra_CountClass( Dar_Obj_t ** pClass ) +int Fra_CountClass( Aig_Obj_t ** pClass ) { - Dar_Obj_t * pTemp; + Aig_Obj_t * pTemp; int i; for ( i = 0; pTemp = pClass[i]; i++ ); return i; @@ -96,7 +96,7 @@ int Fra_CountClass( Dar_Obj_t ** pClass ) ***********************************************************************/ int Fra_CountPairsClasses( Fra_Man_t * p ) { - Dar_Obj_t ** pClass; + Aig_Obj_t ** pClass; int i, nNodes, nPairs = 0; Vec_PtrForEachEntry( p->vClasses, pClass, i ) { @@ -120,7 +120,7 @@ int Fra_CountPairsClasses( Fra_Man_t * p ) ***********************************************************************/ void Fra_PrintClasses( Fra_Man_t * p ) { - Dar_Obj_t ** pClass; + Aig_Obj_t ** pClass; int i; printf( "Total classes = %d. Total pairs = %d.\n", Vec_PtrSize(p->vClasses), Fra_CountPairsClasses(p) ); Vec_PtrForEachEntry( p->vClasses, pClass, i ) @@ -142,7 +142,7 @@ void Fra_PrintClasses( Fra_Man_t * p ) SeeAlso [] ***********************************************************************/ -unsigned Fra_NodeHash( Fra_Man_t * p, Dar_Obj_t * pObj ) +unsigned Fra_NodeHash( Fra_Man_t * p, Aig_Obj_t * pObj ) { static int s_FPrimes[128] = { 1009, 1049, 1093, 1151, 1201, 1249, 1297, 1361, 1427, 1459, @@ -220,21 +220,21 @@ unsigned int Cudd_PrimeFra( unsigned int p ) ***********************************************************************/ void Fra_CreateClasses( Fra_Man_t * p ) { - Dar_Obj_t ** ppTable, ** ppNexts; - Dar_Obj_t * pObj, * pTemp; + Aig_Obj_t ** ppTable, ** ppNexts; + Aig_Obj_t * pObj, * pTemp; int i, k, nTableSize, nEntries, nNodes, iEntry; // allocate the hash table hashing simulation info into nodes - nTableSize = Cudd_PrimeFra( Dar_ManObjIdMax(p->pManAig) + 1 ); - ppTable = ALLOC( Dar_Obj_t *, nTableSize ); - ppNexts = ALLOC( Dar_Obj_t *, nTableSize ); - memset( ppTable, 0, sizeof(Dar_Obj_t *) * nTableSize ); + nTableSize = Cudd_PrimeFra( Aig_ManObjIdMax(p->pManAig) + 1 ); + ppTable = ALLOC( Aig_Obj_t *, nTableSize ); + ppNexts = ALLOC( Aig_Obj_t *, nTableSize ); + memset( ppTable, 0, sizeof(Aig_Obj_t *) * nTableSize ); // add all the nodes to the hash table Vec_PtrClear( p->vClasses1 ); - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) { - if ( !Dar_ObjIsNode(pObj) && !Dar_ObjIsPi(pObj) ) + if ( !Aig_ObjIsNode(pObj) && !Aig_ObjIsPi(pObj) ) continue; // hash the node by its simulation info iEntry = Fra_NodeHash( p, pObj ) % nTableSize; @@ -242,7 +242,7 @@ void Fra_CreateClasses( Fra_Man_t * p ) if ( iEntry == 0 && Fra_NodeHasZeroSim( p, pObj ) ) { Vec_PtrPush( p->vClasses1, pObj ); - Fra_ObjSetRepr( pObj, Dar_ManConst1(p->pManAig) ); + Fra_ObjSetRepr( pObj, Aig_ManConst1(p->pManAig) ); continue; } // add the node to the class @@ -275,15 +275,15 @@ void Fra_CreateClasses( Fra_Man_t * p ) } // allocate room for classes - p->pMemClasses = ALLOC( Dar_Obj_t *, 2*(nEntries + Vec_PtrSize(p->vClasses1)) ); + p->pMemClasses = ALLOC( Aig_Obj_t *, 2*(nEntries + Vec_PtrSize(p->vClasses1)) ); p->pMemClassesFree = p->pMemClasses + 2*nEntries; // copy the entries into storage in the topological order Vec_PtrClear( p->vClasses ); nEntries = 0; - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) { - if ( !Dar_ObjIsNode(pObj) && !Dar_ObjIsPi(pObj) ) + if ( !Aig_ObjIsNode(pObj) && !Aig_ObjIsPi(pObj) ) continue; // skip the nodes that are not representatives of non-trivial classes if ( pObj->fMarkA == 0 ) @@ -307,7 +307,7 @@ void Fra_CreateClasses( Fra_Man_t * p ) Fra_ObjSetRepr( pTemp, pObj ); } // add as many empty entries -// memset( p->pMemClasses + 2*nEntries + nNodes, 0, sizeof(Dar_Obj_t *) * nNodes ); +// memset( p->pMemClasses + 2*nEntries + nNodes, 0, sizeof(Aig_Obj_t *) * nNodes ); p->pMemClasses[2*nEntries + nNodes] = NULL; // increment the number of entries nEntries += k; @@ -329,9 +329,9 @@ void Fra_CreateClasses( Fra_Man_t * p ) SeeAlso [] ***********************************************************************/ -Dar_Obj_t ** Fra_RefineClassOne( Fra_Man_t * p, Dar_Obj_t ** ppClass ) +Aig_Obj_t ** Fra_RefineClassOne( Fra_Man_t * p, Aig_Obj_t ** ppClass ) { - Dar_Obj_t * pObj, ** ppThis; + Aig_Obj_t * pObj, ** ppThis; int i; assert( ppClass[0] != NULL && ppClass[1] != NULL ); @@ -390,7 +390,7 @@ Dar_Obj_t ** Fra_RefineClassOne( Fra_Man_t * p, Dar_Obj_t ** ppClass ) ***********************************************************************/ int Fra_RefineClassLastIter( Fra_Man_t * p, Vec_Ptr_t * vClasses ) { - Dar_Obj_t ** pClass, ** pClass2; + Aig_Obj_t ** pClass, ** pClass2; int nRefis; pClass = Vec_PtrEntryLast( vClasses ); for ( nRefis = 0; pClass2 = Fra_RefineClassOne( p, pClass ); nRefis++ ) @@ -426,7 +426,7 @@ int Fra_RefineClassLastIter( Fra_Man_t * p, Vec_Ptr_t * vClasses ) int Fra_RefineClasses( Fra_Man_t * p ) { Vec_Ptr_t * vTemp; - Dar_Obj_t ** pClass; + Aig_Obj_t ** pClass; int clk, i, nRefis; // check if some outputs already became non-constant // this is a special case when computation can be stopped!!! @@ -466,14 +466,14 @@ p->timeRef += clock() - clk; ***********************************************************************/ int Fra_RefineClasses1( Fra_Man_t * p ) { - Dar_Obj_t * pObj, ** ppClass; + Aig_Obj_t * pObj, ** ppClass; int i, k, nRefis, clk; // check if there is anything to refine if ( Vec_PtrSize(p->vClasses1) == 0 ) return 0; clk = clock(); // make sure constant 1 class contains only non-constant nodes - assert( Vec_PtrEntry(p->vClasses1,0) != Dar_ManConst1(p->pManAig) ); + assert( Vec_PtrEntry(p->vClasses1,0) != Aig_ManConst1(p->pManAig) ); // collect all the nodes to be refined k = 0; Vec_PtrClear( p->vClassNew ); diff --git a/src/aig/fra/fraCnf.c b/src/aig/fra/fraCnf.c index a662ade2..7df55d93 100644 --- a/src/aig/fra/fraCnf.c +++ b/src/aig/fra/fraCnf.c @@ -40,23 +40,23 @@ SeeAlso [] ***********************************************************************/ -void Fra_AddClausesMux( Fra_Man_t * p, Dar_Obj_t * pNode ) +void Fra_AddClausesMux( Fra_Man_t * p, Aig_Obj_t * pNode ) { - Dar_Obj_t * pNodeI, * pNodeT, * pNodeE; + Aig_Obj_t * pNodeI, * pNodeT, * pNodeE; int pLits[4], RetValue, VarF, VarI, VarT, VarE, fCompT, fCompE; - assert( !Dar_IsComplement( pNode ) ); - assert( Dar_ObjIsMuxType( pNode ) ); + assert( !Aig_IsComplement( pNode ) ); + assert( Aig_ObjIsMuxType( pNode ) ); // get nodes (I = if, T = then, E = else) - pNodeI = Dar_ObjRecognizeMux( pNode, &pNodeT, &pNodeE ); + pNodeI = Aig_ObjRecognizeMux( pNode, &pNodeT, &pNodeE ); // get the variable numbers VarF = Fra_ObjSatNum(pNode); VarI = Fra_ObjSatNum(pNodeI); - VarT = Fra_ObjSatNum(Dar_Regular(pNodeT)); - VarE = Fra_ObjSatNum(Dar_Regular(pNodeE)); + VarT = Fra_ObjSatNum(Aig_Regular(pNodeT)); + VarE = Fra_ObjSatNum(Aig_Regular(pNodeE)); // get the complementation flags - fCompT = Dar_IsComplement(pNodeT); - fCompE = Dar_IsComplement(pNodeE); + fCompT = Aig_IsComplement(pNodeT); + fCompE = Aig_IsComplement(pNodeE); // f = ITE(i, t, e) @@ -123,12 +123,12 @@ void Fra_AddClausesMux( Fra_Man_t * p, Dar_Obj_t * pNode ) SeeAlso [] ***********************************************************************/ -void Fra_AddClausesSuper( Fra_Man_t * p, Dar_Obj_t * pNode, Vec_Ptr_t * vSuper ) +void Fra_AddClausesSuper( Fra_Man_t * p, Aig_Obj_t * pNode, Vec_Ptr_t * vSuper ) { - Dar_Obj_t * pFanin; + Aig_Obj_t * pFanin; int * pLits, nLits, RetValue, i; - assert( !Dar_IsComplement(pNode) ); - assert( Dar_ObjIsNode( pNode ) ); + assert( !Aig_IsComplement(pNode) ); + assert( Aig_ObjIsNode( pNode ) ); // create storage for literals nLits = Vec_PtrSize(vSuper) + 1; pLits = ALLOC( int, nLits ); @@ -136,14 +136,14 @@ void Fra_AddClausesSuper( Fra_Man_t * p, Dar_Obj_t * pNode, Vec_Ptr_t * vSuper ) // add !A => !C or A + !C Vec_PtrForEachEntry( vSuper, pFanin, i ) { - pLits[0] = toLitCond(Fra_ObjSatNum(Dar_Regular(pFanin)), Dar_IsComplement(pFanin)); + pLits[0] = toLitCond(Fra_ObjSatNum(Aig_Regular(pFanin)), Aig_IsComplement(pFanin)); pLits[1] = toLitCond(Fra_ObjSatNum(pNode), 1); RetValue = sat_solver_addclause( p->pSat, pLits, pLits + 2 ); assert( RetValue ); } // add A & B => C or !A + !B + C Vec_PtrForEachEntry( vSuper, pFanin, i ) - pLits[i] = toLitCond(Fra_ObjSatNum(Dar_Regular(pFanin)), !Dar_IsComplement(pFanin)); + pLits[i] = toLitCond(Fra_ObjSatNum(Aig_Regular(pFanin)), !Aig_IsComplement(pFanin)); pLits[nLits-1] = toLitCond(Fra_ObjSatNum(pNode), 0); RetValue = sat_solver_addclause( p->pSat, pLits, pLits + nLits ); assert( RetValue ); @@ -161,18 +161,18 @@ void Fra_AddClausesSuper( Fra_Man_t * p, Dar_Obj_t * pNode, Vec_Ptr_t * vSuper ) SeeAlso [] ***********************************************************************/ -void Fra_CollectSuper_rec( Dar_Obj_t * pObj, Vec_Ptr_t * vSuper, int fFirst, int fUseMuxes ) +void Fra_CollectSuper_rec( Aig_Obj_t * pObj, Vec_Ptr_t * vSuper, int fFirst, int fUseMuxes ) { // if the new node is complemented or a PI, another gate begins - if ( Dar_IsComplement(pObj) || Dar_ObjIsPi(pObj) || (!fFirst && Dar_ObjRefs(pObj) > 1) || - (fUseMuxes && Dar_ObjIsMuxType(pObj)) ) + if ( Aig_IsComplement(pObj) || Aig_ObjIsPi(pObj) || (!fFirst && Aig_ObjRefs(pObj) > 1) || + (fUseMuxes && Aig_ObjIsMuxType(pObj)) ) { Vec_PtrPushUnique( vSuper, pObj ); return; } // go through the branches - Fra_CollectSuper_rec( Dar_ObjChild0(pObj), vSuper, 0, fUseMuxes ); - Fra_CollectSuper_rec( Dar_ObjChild1(pObj), vSuper, 0, fUseMuxes ); + Fra_CollectSuper_rec( Aig_ObjChild0(pObj), vSuper, 0, fUseMuxes ); + Fra_CollectSuper_rec( Aig_ObjChild1(pObj), vSuper, 0, fUseMuxes ); } /**Function************************************************************* @@ -186,11 +186,11 @@ void Fra_CollectSuper_rec( Dar_Obj_t * pObj, Vec_Ptr_t * vSuper, int fFirst, int SeeAlso [] ***********************************************************************/ -Vec_Ptr_t * Fra_CollectSuper( Dar_Obj_t * pObj, int fUseMuxes ) +Vec_Ptr_t * Fra_CollectSuper( Aig_Obj_t * pObj, int fUseMuxes ) { Vec_Ptr_t * vSuper; - assert( !Dar_IsComplement(pObj) ); - assert( !Dar_ObjIsPi(pObj) ); + assert( !Aig_IsComplement(pObj) ); + assert( !Aig_ObjIsPi(pObj) ); vSuper = Vec_PtrAlloc( 4 ); Fra_CollectSuper_rec( pObj, vSuper, 1, fUseMuxes ); return vSuper; @@ -207,19 +207,19 @@ Vec_Ptr_t * Fra_CollectSuper( Dar_Obj_t * pObj, int fUseMuxes ) SeeAlso [] ***********************************************************************/ -void Fra_ObjAddToFrontier( Fra_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vFrontier ) +void Fra_ObjAddToFrontier( Fra_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vFrontier ) { Fra_Man_t * pTemp = pObj->pData; - assert( !Dar_IsComplement(pObj) ); + assert( !Aig_IsComplement(pObj) ); if ( Fra_ObjSatNum(pObj) ) return; assert( Fra_ObjSatNum(pObj) == 0 ); assert( Fra_ObjFaninVec(pObj) == NULL ); - if ( Dar_ObjIsConst1(pObj) ) + if ( Aig_ObjIsConst1(pObj) ) return; //printf( "Assigning node %d number %d\n", pObj->Id, p->nSatVars ); Fra_ObjSetSatNum( pObj, p->nSatVars++ ); - if ( Dar_ObjIsNode(pObj) ) + if ( Aig_ObjIsNode(pObj) ) Vec_PtrPush( vFrontier, pObj ); } @@ -234,10 +234,10 @@ void Fra_ObjAddToFrontier( Fra_Man_t * p, Dar_Obj_t * pObj, Vec_Ptr_t * vFrontie SeeAlso [] ***********************************************************************/ -void Fra_NodeAddToSolver( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ) +void Fra_NodeAddToSolver( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ) { Vec_Ptr_t * vFrontier, * vFanins; - Dar_Obj_t * pNode, * pFanin; + Aig_Obj_t * pNode, * pFanin; int i, k, fUseMuxes = 1; assert( pOld || pNew ); // quit if CNF is ready @@ -253,22 +253,22 @@ void Fra_NodeAddToSolver( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ) // create the supergate assert( Fra_ObjSatNum(pNode) ); assert( Fra_ObjFaninVec(pNode) == NULL ); - if ( fUseMuxes && Dar_ObjIsMuxType(pNode) ) + if ( fUseMuxes && Aig_ObjIsMuxType(pNode) ) { vFanins = Vec_PtrAlloc( 4 ); - Vec_PtrPushUnique( vFanins, Dar_ObjFanin0( Dar_ObjFanin0(pNode) ) ); - Vec_PtrPushUnique( vFanins, Dar_ObjFanin0( Dar_ObjFanin1(pNode) ) ); - Vec_PtrPushUnique( vFanins, Dar_ObjFanin1( Dar_ObjFanin0(pNode) ) ); - Vec_PtrPushUnique( vFanins, Dar_ObjFanin1( Dar_ObjFanin1(pNode) ) ); + Vec_PtrPushUnique( vFanins, Aig_ObjFanin0( Aig_ObjFanin0(pNode) ) ); + Vec_PtrPushUnique( vFanins, Aig_ObjFanin0( Aig_ObjFanin1(pNode) ) ); + Vec_PtrPushUnique( vFanins, Aig_ObjFanin1( Aig_ObjFanin0(pNode) ) ); + Vec_PtrPushUnique( vFanins, Aig_ObjFanin1( Aig_ObjFanin1(pNode) ) ); Vec_PtrForEachEntry( vFanins, pFanin, k ) - Fra_ObjAddToFrontier( p, Dar_Regular(pFanin), vFrontier ); + Fra_ObjAddToFrontier( p, Aig_Regular(pFanin), vFrontier ); Fra_AddClausesMux( p, pNode ); } else { vFanins = Fra_CollectSuper( pNode, fUseMuxes ); Vec_PtrForEachEntry( vFanins, pFanin, k ) - Fra_ObjAddToFrontier( p, Dar_Regular(pFanin), vFrontier ); + Fra_ObjAddToFrontier( p, Aig_Regular(pFanin), vFrontier ); Fra_AddClausesSuper( p, pNode, vFanins ); } assert( Vec_PtrSize(vFanins) > 1 ); diff --git a/src/aig/fra/fraCore.c b/src/aig/fra/fraCore.c index 7fdd1b83..5338d662 100644 --- a/src/aig/fra/fraCore.c +++ b/src/aig/fra/fraCore.c @@ -39,15 +39,15 @@ SeeAlso [] ***********************************************************************/ -Dar_Man_t * Fra_Perform( Dar_Man_t * pManAig, Fra_Par_t * pPars ) +Aig_Man_t * Fra_Perform( Aig_Man_t * pManAig, Fra_Par_t * pPars ) { Fra_Man_t * p; - Dar_Man_t * pManAigNew; + Aig_Man_t * pManAigNew; int clk; - if ( Dar_ManNodeNum(pManAig) == 0 ) - return Dar_ManDup(pManAig); + if ( Aig_ManNodeNum(pManAig) == 0 ) + return Aig_ManDup(pManAig); clk = clock(); - assert( Dar_ManLatchNum(pManAig) == 0 ); + assert( Aig_ManLatchNum(pManAig) == 0 ); p = Fra_ManStart( pManAig, pPars ); Fra_Simulate( p ); Fra_Sweep( p ); diff --git a/src/aig/fra/fraMan.c b/src/aig/fra/fraMan.c index 19ed6c03..78246a8c 100644 --- a/src/aig/fra/fraMan.c +++ b/src/aig/fra/fraMan.c @@ -66,7 +66,7 @@ void Fra_ParamsDefault( Fra_Par_t * pPars ) SeeAlso [] ***********************************************************************/ -Fra_Man_t * Fra_ManStart( Dar_Man_t * pManAig, Fra_Par_t * pPars ) +Fra_Man_t * Fra_ManStart( Aig_Man_t * pManAig, Fra_Par_t * pPars ) { Fra_Man_t * p; // allocate the fraiging manager @@ -74,15 +74,15 @@ Fra_Man_t * Fra_ManStart( Dar_Man_t * pManAig, Fra_Par_t * pPars ) memset( p, 0, sizeof(Fra_Man_t) ); p->pPars = pPars; p->pManAig = pManAig; - p->pManFraig = Dar_ManStartFrom( pManAig ); - assert( Dar_ManPiNum(p->pManAig) == Dar_ManPiNum(p->pManFraig) ); + p->pManFraig = Aig_ManStartFrom( pManAig ); + assert( Aig_ManPiNum(p->pManAig) == Aig_ManPiNum(p->pManFraig) ); // allocate simulation info p->nSimWords = pPars->nSimWords; - p->pSimWords = ALLOC( unsigned, (Dar_ManObjIdMax(pManAig) + 1) * p->nSimWords ); + p->pSimWords = ALLOC( unsigned, (Aig_ManObjIdMax(pManAig) + 1) * p->nSimWords ); // clean simulation info of the constant node - memset( p->pSimWords, 0, sizeof(unsigned) * ((Dar_ManPiNum(pManAig) + 1) * p->nSimWords) ); + memset( p->pSimWords, 0, sizeof(unsigned) * ((Aig_ManPiNum(pManAig) + 1) * p->nSimWords) ); // allocate storage for sim pattern - p->nPatWords = Dar_BitWordNum( Dar_ManPiNum(pManAig) ); + p->nPatWords = Aig_BitWordNum( Aig_ManPiNum(pManAig) ); p->pPatWords = ALLOC( unsigned, p->nPatWords ); p->pPatScores = ALLOC( int, 32 * p->nSimWords ); p->vPiVars = Vec_PtrAlloc( 100 ); @@ -92,11 +92,11 @@ Fra_Man_t * Fra_ManStart( Dar_Man_t * pManAig, Fra_Par_t * pPars ) p->vClassNew = Vec_PtrAlloc( 100 ); p->vClassesTemp = Vec_PtrAlloc( 100 ); // allocate other members - p->nSizeAlloc = Dar_ManObjIdMax(pManAig) + 1; - p->pMemFraig = ALLOC( Dar_Obj_t *, p->nSizeAlloc ); - memset( p->pMemFraig, 0, p->nSizeAlloc * sizeof(Dar_Obj_t *) ); - p->pMemRepr = ALLOC( Dar_Obj_t *, p->nSizeAlloc ); - memset( p->pMemRepr, 0, p->nSizeAlloc * sizeof(Dar_Obj_t *) ); + p->nSizeAlloc = Aig_ManObjIdMax(pManAig) + 1; + p->pMemFraig = ALLOC( Aig_Obj_t *, p->nSizeAlloc ); + memset( p->pMemFraig, 0, p->nSizeAlloc * sizeof(Aig_Obj_t *) ); + p->pMemRepr = ALLOC( Aig_Obj_t *, p->nSizeAlloc ); + memset( p->pMemRepr, 0, p->nSizeAlloc * sizeof(Aig_Obj_t *) ); p->pMemFanins = ALLOC( Vec_Ptr_t *, p->nSizeAlloc ); memset( p->pMemFanins, 0, p->nSizeAlloc * sizeof(Vec_Ptr_t *) ); p->pMemSatNums = ALLOC( int, p->nSizeAlloc ); @@ -123,18 +123,18 @@ Fra_Man_t * Fra_ManStart( Dar_Man_t * pManAig, Fra_Par_t * pPars ) ***********************************************************************/ void Fra_ManPrepare( Fra_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; // set the pointers to the manager - Dar_ManForEachObj( p->pManFraig, pObj, i ) + Aig_ManForEachObj( p->pManFraig, pObj, i ) pObj->pData = p; // set the pointer to the manager - Dar_ManForEachObj( p->pManAig, pObj, i ) + Aig_ManForEachObj( p->pManAig, pObj, i ) pObj->pData = p; // set the pointers to the available fraig nodes - Fra_ObjSetFraig( Dar_ManConst1(p->pManAig), Dar_ManConst1(p->pManFraig) ); - Dar_ManForEachPi( p->pManAig, pObj, i ) - Fra_ObjSetFraig( pObj, Dar_ManPi(p->pManFraig, i) ); + Fra_ObjSetFraig( Aig_ManConst1(p->pManAig), Aig_ManConst1(p->pManFraig) ); + Aig_ManForEachPi( p->pManAig, pObj, i ) + Fra_ObjSetFraig( pObj, Aig_ManPi(p->pManFraig, i) ); } /**Function************************************************************* @@ -187,14 +187,14 @@ void Fra_ManStop( Fra_Man_t * p ) ***********************************************************************/ void Fra_ManPrint( Fra_Man_t * p ) { - double nMemory = 1.0*Dar_ManObjIdMax(p->pManAig)*((p->nSimWords+2)*sizeof(unsigned)+6*sizeof(void*))/(1<<20); + double nMemory = 1.0*Aig_ManObjIdMax(p->pManAig)*((p->nSimWords+2)*sizeof(unsigned)+6*sizeof(void*))/(1<<20); printf( "SimWords = %d. Rounds = %d. Mem = %0.2f Mb. ", p->nSimWords, p->nSimRounds, nMemory ); printf( "Classes: Beg = %d. End = %d.\n", p->nClassesBeg, p->nClassesEnd ); printf( "Limits: BTNode = %d. BTMiter = %d.\n", p->pPars->nBTLimitNode, p->pPars->nBTLimitMiter ); printf( "Proof = %d. Counter-example = %d. Fail = %d. FailReal = %d. Zero = %d.\n", p->nSatProof, p->nSatCallsSat, p->nSatFails, p->nSatFailsReal, p->nClassesZero ); printf( "Final = %d. Miter = %d. Total = %d. Mux = %d. (Exor = %d.) SatVars = %d.\n", - Dar_ManNodeNum(p->pManFraig), p->nNodesMiter, Dar_ManNodeNum(p->pManAig), 0, 0, p->nSatVars ); + Aig_ManNodeNum(p->pManFraig), p->nNodesMiter, Aig_ManNodeNum(p->pManAig), 0, 0, p->nSatVars ); if ( p->pSat ) Sat_SolverPrintStats( stdout, p->pSat ); PRT( "AIG simulation ", p->timeSim ); PRT( "AIG traversal ", p->timeTrav ); diff --git a/src/aig/fra/fraSat.c b/src/aig/fra/fraSat.c index 1c72c807..66b1ba5a 100644 --- a/src/aig/fra/fraSat.c +++ b/src/aig/fra/fraSat.c @@ -24,7 +24,7 @@ /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// -static int Fra_SetActivityFactors( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ); +static int Fra_SetActivityFactors( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ); //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// @@ -41,13 +41,13 @@ static int Fra_SetActivityFactors( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * SeeAlso [] ***********************************************************************/ -int Fra_NodesAreEquiv( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ) +int Fra_NodesAreEquiv( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ) { int pLits[4], RetValue, RetValue1, nBTLimit, clk, clk2 = clock(); // make sure the nodes are not complemented - assert( !Dar_IsComplement(pNew) ); - assert( !Dar_IsComplement(pOld) ); + assert( !Aig_IsComplement(pNew) ); + assert( !Aig_IsComplement(pOld) ); assert( pNew != pOld ); // if at least one of the nodes is a failed node, perform adjustments: @@ -189,12 +189,12 @@ p->timeSatFail += clock() - clk; SeeAlso [] ***********************************************************************/ -int Fra_NodeIsConst( Fra_Man_t * p, Dar_Obj_t * pNew ) +int Fra_NodeIsConst( Fra_Man_t * p, Aig_Obj_t * pNew ) { int pLits[2], RetValue1, RetValue, clk; // make sure the nodes are not complemented - assert( !Dar_IsComplement(pNew) ); + assert( !Aig_IsComplement(pNew) ); assert( pNew != p->pManFraig->pConst1 ); p->nSatCalls++; @@ -261,19 +261,19 @@ p->timeSatFail += clock() - clk; SeeAlso [] ***********************************************************************/ -int Fra_SetActivityFactors_rec( Fra_Man_t * p, Dar_Obj_t * pObj, int LevelMin, int LevelMax ) +int Fra_SetActivityFactors_rec( Fra_Man_t * p, Aig_Obj_t * pObj, int LevelMin, int LevelMax ) { Vec_Ptr_t * vFanins; - Dar_Obj_t * pFanin; + Aig_Obj_t * pFanin; int i, Counter = 0; - assert( !Dar_IsComplement(pObj) ); + assert( !Aig_IsComplement(pObj) ); assert( Fra_ObjSatNum(pObj) ); // skip visited variables - if ( Dar_ObjIsTravIdCurrent(p->pManFraig, pObj) ) + if ( Aig_ObjIsTravIdCurrent(p->pManFraig, pObj) ) return 0; - Dar_ObjSetTravIdCurrent(p->pManFraig, pObj); + Aig_ObjSetTravIdCurrent(p->pManFraig, pObj); // add the PI to the list - if ( pObj->Level <= (unsigned)LevelMin || Dar_ObjIsPi(pObj) ) + if ( pObj->Level <= (unsigned)LevelMin || Aig_ObjIsPi(pObj) ) return 0; // set the factor of this variable // (LevelMax-LevelMin) / (pObj->Level-LevelMin) = p->pPars->dActConeBumpMax / ThisBump @@ -282,7 +282,7 @@ int Fra_SetActivityFactors_rec( Fra_Man_t * p, Dar_Obj_t * pObj, int LevelMin, i // explore the fanins vFanins = Fra_ObjFaninVec( pObj ); Vec_PtrForEachEntry( vFanins, pFanin, i ) - Counter += Fra_SetActivityFactors_rec( p, Dar_Regular(pFanin), LevelMin, LevelMax ); + Counter += Fra_SetActivityFactors_rec( p, Aig_Regular(pFanin), LevelMin, LevelMax ); return 1 + Counter; } @@ -297,7 +297,7 @@ int Fra_SetActivityFactors_rec( Fra_Man_t * p, Dar_Obj_t * pObj, int LevelMin, i SeeAlso [] ***********************************************************************/ -int Fra_SetActivityFactors( Fra_Man_t * p, Dar_Obj_t * pOld, Dar_Obj_t * pNew ) +int Fra_SetActivityFactors( Fra_Man_t * p, Aig_Obj_t * pOld, Aig_Obj_t * pNew ) { int clk, LevelMin, LevelMax; assert( pOld || pNew ); @@ -305,15 +305,15 @@ clk = clock(); // reset the active variables veci_resize(&p->pSat->act_vars, 0); // prepare for traversal - Dar_ManIncrementTravId( p->pManFraig ); + Aig_ManIncrementTravId( p->pManFraig ); // determine the min and max level to visit assert( p->pPars->dActConeRatio > 0 && p->pPars->dActConeRatio < 1 ); - LevelMax = DAR_MAX( (pNew ? pNew->Level : 0), (pOld ? pOld->Level : 0) ); + LevelMax = AIG_MAX( (pNew ? pNew->Level : 0), (pOld ? pOld->Level : 0) ); LevelMin = (int)(LevelMax * (1.0 - p->pPars->dActConeRatio)); // traverse - if ( pOld && !Dar_ObjIsConst1(pOld) ) + if ( pOld && !Aig_ObjIsConst1(pOld) ) Fra_SetActivityFactors_rec( p, pOld, LevelMin, LevelMax ); - if ( pNew && !Dar_ObjIsConst1(pNew) ) + if ( pNew && !Aig_ObjIsConst1(pNew) ) Fra_SetActivityFactors_rec( p, pNew, LevelMin, LevelMax ); //Fra_PrintActivity( p ); p->timeTrav += clock() - clk; diff --git a/src/aig/fra/fraSim.c b/src/aig/fra/fraSim.c index 7207cfa2..beaa79fd 100644 --- a/src/aig/fra/fraSim.c +++ b/src/aig/fra/fraSim.c @@ -39,11 +39,11 @@ SeeAlso [] ***********************************************************************/ -void Fra_NodeAssignRandom( Fra_Man_t * p, Dar_Obj_t * pObj ) +void Fra_NodeAssignRandom( Fra_Man_t * p, Aig_Obj_t * pObj ) { unsigned * pSims; int i; - assert( Dar_ObjIsPi(pObj) ); + assert( Aig_ObjIsPi(pObj) ); pSims = Fra_ObjSim(pObj); for ( i = 0; i < p->nSimWords; i++ ) pSims[i] = Fra_ObjRandomSim(); @@ -60,11 +60,11 @@ void Fra_NodeAssignRandom( Fra_Man_t * p, Dar_Obj_t * pObj ) SeeAlso [] ***********************************************************************/ -void Fra_NodeAssignConst( Fra_Man_t * p, Dar_Obj_t * pObj, int fConst1 ) +void Fra_NodeAssignConst( Fra_Man_t * p, Aig_Obj_t * pObj, int fConst1 ) { unsigned * pSims; int i; - assert( Dar_ObjIsPi(pObj) ); + assert( Aig_ObjIsPi(pObj) ); pSims = Fra_ObjSim(pObj); for ( i = 0; i < p->nSimWords; i++ ) pSims[i] = fConst1? ~(unsigned)0 : 0; @@ -83,9 +83,9 @@ void Fra_NodeAssignConst( Fra_Man_t * p, Dar_Obj_t * pObj, int fConst1 ) ***********************************************************************/ void Fra_AssignRandom( Fra_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; - Dar_ManForEachPi( p->pManAig, pObj, i ) + Aig_ManForEachPi( p->pManAig, pObj, i ) Fra_NodeAssignRandom( p, pObj ); } @@ -102,17 +102,17 @@ void Fra_AssignRandom( Fra_Man_t * p ) ***********************************************************************/ void Fra_AssignDist1( Fra_Man_t * p, unsigned * pPat ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i, Limit; - Dar_ManForEachPi( p->pManAig, pObj, i ) + Aig_ManForEachPi( p->pManAig, pObj, i ) { - Fra_NodeAssignConst( p, pObj, Dar_InfoHasBit(pPat, i) ); -// printf( "%d", Dar_InfoHasBit(pPat, i) ); + Fra_NodeAssignConst( p, pObj, Aig_InfoHasBit(pPat, i) ); +// printf( "%d", Aig_InfoHasBit(pPat, i) ); } // printf( "\n" ); - Limit = DAR_MIN( Dar_ManPiNum(p->pManAig), p->nSimWords * 32 - 1 ); + Limit = AIG_MIN( Aig_ManPiNum(p->pManAig), p->nSimWords * 32 - 1 ); for ( i = 0; i < Limit; i++ ) - Dar_InfoXorBit( Fra_ObjSim( Dar_ManPi(p->pManAig,i) ), i+1 ); + Aig_InfoXorBit( Fra_ObjSim( Aig_ManPi(p->pManAig,i) ), i+1 ); } /**Function************************************************************* @@ -126,7 +126,7 @@ void Fra_AssignDist1( Fra_Man_t * p, unsigned * pPat ) SeeAlso [] ***********************************************************************/ -int Fra_NodeHasZeroSim( Fra_Man_t * p, Dar_Obj_t * pObj ) +int Fra_NodeHasZeroSim( Fra_Man_t * p, Aig_Obj_t * pObj ) { unsigned * pSims; int i; @@ -148,7 +148,7 @@ int Fra_NodeHasZeroSim( Fra_Man_t * p, Dar_Obj_t * pObj ) SeeAlso [] ***********************************************************************/ -void Fra_NodeComplementSim( Fra_Man_t * p, Dar_Obj_t * pObj ) +void Fra_NodeComplementSim( Fra_Man_t * p, Aig_Obj_t * pObj ) { unsigned * pSims; int i; @@ -168,7 +168,7 @@ void Fra_NodeComplementSim( Fra_Man_t * p, Dar_Obj_t * pObj ) SeeAlso [] ***********************************************************************/ -int Fra_NodeCompareSims( Fra_Man_t * p, Dar_Obj_t * pObj0, Dar_Obj_t * pObj1 ) +int Fra_NodeCompareSims( Fra_Man_t * p, Aig_Obj_t * pObj0, Aig_Obj_t * pObj1 ) { unsigned * pSims0, * pSims1; int i; @@ -192,20 +192,20 @@ int Fra_NodeCompareSims( Fra_Man_t * p, Dar_Obj_t * pObj0, Dar_Obj_t * pObj1 ) SeeAlso [] ***********************************************************************/ -void Fra_NodeSimulate( Fra_Man_t * p, Dar_Obj_t * pObj ) +void Fra_NodeSimulate( Fra_Man_t * p, Aig_Obj_t * pObj ) { unsigned * pSims, * pSims0, * pSims1; int fCompl, fCompl0, fCompl1, i; - assert( !Dar_IsComplement(pObj) ); - assert( Dar_ObjIsNode(pObj) ); + assert( !Aig_IsComplement(pObj) ); + assert( Aig_ObjIsNode(pObj) ); // get hold of the simulation information pSims = Fra_ObjSim(pObj); - pSims0 = Fra_ObjSim(Dar_ObjFanin0(pObj)); - pSims1 = Fra_ObjSim(Dar_ObjFanin1(pObj)); + pSims0 = Fra_ObjSim(Aig_ObjFanin0(pObj)); + pSims1 = Fra_ObjSim(Aig_ObjFanin1(pObj)); // get complemented attributes of the children using their random info fCompl = pObj->fPhase; - fCompl0 = Dar_ObjFaninPhase(Dar_ObjChild0(pObj)); - fCompl1 = Dar_ObjFaninPhase(Dar_ObjChild1(pObj)); + fCompl0 = Aig_ObjFaninPhase(Aig_ObjChild0(pObj)); + fCompl1 = Aig_ObjFaninPhase(Aig_ObjChild1(pObj)); // simulate if ( fCompl0 && fCompl1 ) { @@ -290,13 +290,13 @@ void Fra_SavePattern1( Fra_Man_t * p ) ***********************************************************************/ void Fra_SavePattern( Fra_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; memset( p->pPatWords, 0, sizeof(unsigned) * p->nPatWords ); - Dar_ManForEachPi( p->pManFraig, pObj, i ) + Aig_ManForEachPi( p->pManFraig, pObj, i ) // Vec_PtrForEachEntry( p->vPiVars, pObj, i ) if ( p->pSat->model.ptr[Fra_ObjSatNum(pObj)] == l_True ) - Dar_InfoSetBit( p->pPatWords, i ); + Aig_InfoSetBit( p->pPatWords, i ); // Ivy_InfoSetBit( p->pPatWords, pObj->Id - 1 ); } @@ -329,7 +329,7 @@ void Fra_CleanPatScores( Fra_Man_t * p ) SeeAlso [] ***********************************************************************/ -void Fra_AddToPatScores( Fra_Man_t * p, Dar_Obj_t * pClass, Dar_Obj_t * pClassNew ) +void Fra_AddToPatScores( Fra_Man_t * p, Aig_Obj_t * pClass, Aig_Obj_t * pClassNew ) { unsigned * pSims0, * pSims1; unsigned uDiff; @@ -363,7 +363,7 @@ void Fra_AddToPatScores( Fra_Man_t * p, Dar_Obj_t * pClass, Dar_Obj_t * pClassNe int Fra_SelectBestPat( Fra_Man_t * p ) { unsigned * pSims; - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i, nLimit = p->nSimWords * 32, MaxScore = 0, BestPat = -1; for ( i = 1; i < nLimit; i++ ) { @@ -379,11 +379,11 @@ int Fra_SelectBestPat( Fra_Man_t * p ) // printf( "Max score is %3d. ", MaxScore ); // copy the best pattern into the selected pattern memset( p->pPatWords, 0, sizeof(unsigned) * p->nPatWords ); - Dar_ManForEachPi( p->pManAig, pObj, i ) + Aig_ManForEachPi( p->pManAig, pObj, i ) { pSims = Fra_ObjSim(pObj); - if ( Dar_InfoHasBit(pSims, BestPat) ) - Dar_InfoSetBit(p->pPatWords, i); + if ( Aig_InfoHasBit(pSims, BestPat) ) + Aig_InfoSetBit(p->pPatWords, i); } return MaxScore; } @@ -401,17 +401,17 @@ int Fra_SelectBestPat( Fra_Man_t * p ) ***********************************************************************/ void Fra_SimulateOne( Fra_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i, clk; clk = clock(); - Dar_ManForEachNode( p->pManAig, pObj, i ) + Aig_ManForEachNode( p->pManAig, pObj, i ) { Fra_NodeSimulate( p, pObj ); /* - if ( Dar_ObjFraig(pObj) == NULL ) + if ( Aig_ObjFraig(pObj) == NULL ) printf( "%3d --- -- %d : ", pObj->Id, pObj->fPhase ); else - printf( "%3d %3d %2d %d : ", pObj->Id, Dar_Regular(Dar_ObjFraig(pObj))->Id, Dar_ObjSatNum(Dar_Regular(Dar_ObjFraig(pObj))), pObj->fPhase ); + printf( "%3d %3d %2d %d : ", pObj->Id, Aig_Regular(Aig_ObjFraig(pObj))->Id, Aig_ObjSatNum(Aig_Regular(Aig_ObjFraig(pObj))), pObj->fPhase ); Extra_PrintBinary( stdout, Fra_ObjSim(pObj), 30 ); printf( "\n" ); */ @@ -527,7 +527,7 @@ void Fra_Simulate( Fra_Man_t * p ) SeeAlso [] ***********************************************************************/ -void Fra_CheckOutputSimsSavePattern( Fra_Man_t * p, Dar_Obj_t * pObj ) +void Fra_CheckOutputSimsSavePattern( Fra_Man_t * p, Aig_Obj_t * pObj ) { unsigned * pSims; int i, k, BestPat, * pModel; @@ -545,10 +545,10 @@ void Fra_CheckOutputSimsSavePattern( Fra_Man_t * p, Dar_Obj_t * pObj ) // determine the best pattern BestPat = i * 32 + k; // fill in the counter-example data - pModel = ALLOC( int, Dar_ManPiNum(p->pManFraig) ); - Dar_ManForEachPi( p->pManAig, pObj, i ) + pModel = ALLOC( int, Aig_ManPiNum(p->pManFraig) ); + Aig_ManForEachPi( p->pManAig, pObj, i ) { - pModel[i] = Dar_InfoHasBit(Fra_ObjSim(pObj), BestPat); + pModel[i] = Aig_InfoHasBit(Fra_ObjSim(pObj), BestPat); // printf( "%d", pModel[i] ); } // printf( "\n" ); @@ -571,26 +571,26 @@ void Fra_CheckOutputSimsSavePattern( Fra_Man_t * p, Dar_Obj_t * pObj ) ***********************************************************************/ int Fra_CheckOutputSims( Fra_Man_t * p ) { - Dar_Obj_t * pObj; + Aig_Obj_t * pObj; int i; // make sure the reference simulation pattern does not detect the bug - pObj = Dar_ManPo( p->pManAig, 0 ); - assert( Dar_ObjFanin0(pObj)->fPhase == (unsigned)Dar_ObjFaninC0(pObj) ); // Dar_ObjFaninPhase(Dar_ObjChild0(pObj)) == 0 - Dar_ManForEachPo( p->pManAig, pObj, i ) + pObj = Aig_ManPo( p->pManAig, 0 ); + assert( Aig_ObjFanin0(pObj)->fPhase == (unsigned)Aig_ObjFaninC0(pObj) ); // Aig_ObjFaninPhase(Aig_ObjChild0(pObj)) == 0 + Aig_ManForEachPo( p->pManAig, pObj, i ) { // complement simulation info -// if ( Dar_ObjFanin0(pObj)->fPhase ^ Dar_ObjFaninC0(pObj) ) // Dar_ObjFaninPhase(Dar_ObjChild0(pObj)) -// Fra_NodeComplementSim( p, Dar_ObjFanin0(pObj) ); +// if ( Aig_ObjFanin0(pObj)->fPhase ^ Aig_ObjFaninC0(pObj) ) // Aig_ObjFaninPhase(Aig_ObjChild0(pObj)) +// Fra_NodeComplementSim( p, Aig_ObjFanin0(pObj) ); // check - if ( !Fra_NodeHasZeroSim( p, Dar_ObjFanin0(pObj) ) ) + if ( !Fra_NodeHasZeroSim( p, Aig_ObjFanin0(pObj) ) ) { // create the counter-example from this pattern - Fra_CheckOutputSimsSavePattern( p, Dar_ObjFanin0(pObj) ); + Fra_CheckOutputSimsSavePattern( p, Aig_ObjFanin0(pObj) ); return 1; } // complement simulation info -// if ( Dar_ObjFanin0(pObj)->fPhase ^ Dar_ObjFaninC0(pObj) ) -// Fra_NodeComplementSim( p, Dar_ObjFanin0(pObj) ); +// if ( Aig_ObjFanin0(pObj)->fPhase ^ Aig_ObjFaninC0(pObj) ) +// Fra_NodeComplementSim( p, Aig_ObjFanin0(pObj) ); } return 0; } diff --git a/src/aig/kit/kit.h b/src/aig/kit/kit.h new file mode 100644 index 00000000..e9a389e0 --- /dev/null +++ b/src/aig/kit/kit.h @@ -0,0 +1,543 @@ +/**CFile**************************************************************** + + FileName [kit.h] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [External declarations.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kit.h,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#ifndef __KIT_H__ +#define __KIT_H__ + +#ifdef __cplusplus +extern "C" { +#endif + +//////////////////////////////////////////////////////////////////////// +/// INCLUDES /// +//////////////////////////////////////////////////////////////////////// + +#include +#include +#include +#include +#include +#include "vec.h" + +//////////////////////////////////////////////////////////////////////// +/// PARAMETERS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// BASIC TYPES /// +//////////////////////////////////////////////////////////////////////// + +typedef struct Kit_Sop_t_ Kit_Sop_t; +struct Kit_Sop_t_ +{ + int nCubes; // the number of cubes + unsigned * pCubes; // the storage for cubes +}; + +typedef struct Kit_Edge_t_ Kit_Edge_t; +struct Kit_Edge_t_ +{ + unsigned fCompl : 1; // the complemented bit + unsigned Node : 30; // the decomposition node pointed by the edge +}; + +typedef struct Kit_Node_t_ Kit_Node_t; +struct Kit_Node_t_ +{ + Kit_Edge_t eEdge0; // the left child of the node + Kit_Edge_t eEdge1; // the right child of the node + // other info + void * pFunc; // the function of the node (BDD or AIG) + unsigned Level : 14; // the level of this node in the global AIG + // printing info + unsigned fNodeOr : 1; // marks the original OR node + unsigned fCompl0 : 1; // marks the original complemented edge + unsigned fCompl1 : 1; // marks the original complemented edge + // latch info + unsigned nLat0 : 5; // the number of latches on the first edge + unsigned nLat1 : 5; // the number of latches on the second edge + unsigned nLat2 : 5; // the number of latches on the output edge +}; + +typedef struct Kit_Graph_t_ Kit_Graph_t; +struct Kit_Graph_t_ +{ + int fConst; // marks the constant 1 graph + int nLeaves; // the number of leaves + int nSize; // the number of nodes (including the leaves) + int nCap; // the number of allocated nodes + Kit_Node_t * pNodes; // the array of leaves and internal nodes + Kit_Edge_t eRoot; // the pointer to the topmost node +}; + + +// DSD node types +typedef enum { + KIT_DSD_NONE = 0, // 0: unknown + KIT_DSD_CONST1, // 1: constant 1 + KIT_DSD_VAR, // 2: elementary variable + KIT_DSD_AND, // 3: multi-input AND + KIT_DSD_XOR, // 4: multi-input XOR + KIT_DSD_PRIME // 5: arbitrary function of 3+ variables +} Kit_Dsd_t; + +// DSD node +typedef struct Kit_DsdObj_t_ Kit_DsdObj_t; +struct Kit_DsdObj_t_ +{ + unsigned Id : 6; // the number of this node + unsigned Type : 3; // none, const, var, AND, XOR, MUX, PRIME + unsigned fMark : 1; // finished checking output + unsigned Offset : 8; // offset to the truth table + unsigned nRefs : 8; // offset to the truth table + unsigned nFans : 6; // the number of fanins of this node + unsigned char pFans[0]; // the fanin literals +}; + +// DSD network +typedef struct Kit_DsdNtk_t_ Kit_DsdNtk_t; +struct Kit_DsdNtk_t_ +{ + unsigned char nVars; // at most 16 (perhaps 18?) + unsigned char nNodesAlloc; // the number of allocated nodes (at most nVars) + unsigned char nNodes; // the number of nodes + unsigned char Root; // the root of the tree + unsigned * pMem; // memory for the truth tables (memory manager?) + unsigned * pSupps; // supports of the nodes + Kit_DsdObj_t** pNodes; // the nodes +}; + +// DSD manager +typedef struct Kit_DsdMan_t_ Kit_DsdMan_t; +struct Kit_DsdMan_t_ +{ + int nVars; // the maximum number of variables + int nWords; // the number of words in TTs + Vec_Ptr_t * vTtElems; // elementary truth tables + Vec_Ptr_t * vTtNodes; // the node truth tables +}; + +static inline int Kit_DsdVar2Lit( int Var, int fCompl ) { return Var + Var + fCompl; } +static inline int Kit_DsdLit2Var( int Lit ) { return Lit >> 1; } +static inline int Kit_DsdLitIsCompl( int Lit ) { return Lit & 1; } +static inline int Kit_DsdLitNot( int Lit ) { return Lit ^ 1; } +static inline int Kit_DsdLitNotCond( int Lit, int c ) { return Lit ^ (int)(c > 0); } +static inline int Kit_DsdLitRegular( int Lit ) { return Lit & 0xfe; } + +static inline unsigned Kit_DsdObjOffset( int nFans ) { return (nFans >> 2) + ((nFans & 3) > 0); } +static inline unsigned * Kit_DsdObjTruth( Kit_DsdObj_t * pObj ) { return pObj->Type == KIT_DSD_PRIME ? (unsigned *)pObj->pFans + pObj->Offset: NULL; } +static inline Kit_DsdObj_t * Kit_DsdNtkObj( Kit_DsdNtk_t * pNtk, int Id ) { assert( Id >= 0 && Id < pNtk->nVars + pNtk->nNodes ); return Id < pNtk->nVars ? NULL : pNtk->pNodes[Id - pNtk->nVars]; } +static inline Kit_DsdObj_t * Kit_DsdNtkRoot( Kit_DsdNtk_t * pNtk ) { return Kit_DsdNtkObj( pNtk, Kit_DsdLit2Var(pNtk->Root) ); } +static inline int Kit_DsdLitIsLeaf( Kit_DsdNtk_t * pNtk, int Lit ) { int Id = Kit_DsdLit2Var(Lit); assert( Id >= 0 && Id < pNtk->nVars + pNtk->nNodes ); return Id < pNtk->nVars; } +static inline unsigned Kit_DsdLitSupport( Kit_DsdNtk_t * pNtk, int Lit ) { int Id = Kit_DsdLit2Var(Lit); assert( Id >= 0 && Id < pNtk->nVars + pNtk->nNodes ); return pNtk->pSupps? (Id < pNtk->nVars? (1 << Id) : pNtk->pSupps[Id - pNtk->nVars]) : 0; } + +#define Kit_DsdNtkForEachObj( pNtk, pObj, i ) \ + for ( i = 0; (i < (pNtk)->nNodes) && ((pObj) = (pNtk)->pNodes[i]); i++ ) +#define Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) \ + for ( i = 0; (i < (pObj)->nFans) && ((iLit) = (pObj)->pFans[i], 1); i++ ) + +//////////////////////////////////////////////////////////////////////// +/// MACRO DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +#define KIT_MIN(a,b) (((a) < (b))? (a) : (b)) +#define KIT_MAX(a,b) (((a) > (b))? (a) : (b)) +#define KIT_INFINITY (100000000) + +#ifndef ALLOC +#define ALLOC(type, num) ((type *) malloc(sizeof(type) * (num))) +#endif + +#ifndef FREE +#define FREE(obj) ((obj) ? (free((char *) (obj)), (obj) = 0) : 0) +#endif + +#ifndef REALLOC +#define REALLOC(type, obj, num) \ + ((obj) ? ((type *) realloc((char *)(obj), sizeof(type) * (num))) : \ + ((type *) malloc(sizeof(type) * (num)))) +#endif + +static inline int Kit_CubeHasLit( unsigned uCube, int i ) { return(uCube & (unsigned)(1< 0; } +static inline unsigned Kit_CubeSetLit( unsigned uCube, int i ) { return uCube | (unsigned)(1<> (32-nVar); } + +static inline int Kit_CubeIsMarked( unsigned uCube ) { return Kit_CubeHasLit( uCube, 31 ); } +static inline unsigned Kit_CubeMark( unsigned uCube ) { return Kit_CubeSetLit( uCube, 31 ); } +static inline unsigned Kit_CubeUnmark( unsigned uCube ) { return Kit_CubeRemLit( uCube, 31 ); } + +static inline int Kit_SopCubeNum( Kit_Sop_t * cSop ) { return cSop->nCubes; } +static inline unsigned Kit_SopCube( Kit_Sop_t * cSop, int i ) { return cSop->pCubes[i]; } +static inline void Kit_SopShrink( Kit_Sop_t * cSop, int nCubesNew ) { cSop->nCubes = nCubesNew; } +static inline void Kit_SopPushCube( Kit_Sop_t * cSop, unsigned uCube ) { cSop->pCubes[cSop->nCubes++] = uCube; } +static inline void Kit_SopWriteCube( Kit_Sop_t * cSop, unsigned uCube, int i ) { cSop->pCubes[i] = uCube; } + +static inline Kit_Edge_t Kit_EdgeCreate( int Node, int fCompl ) { Kit_Edge_t eEdge = { fCompl, Node }; return eEdge; } +static inline unsigned Kit_EdgeToInt( Kit_Edge_t eEdge ) { return (eEdge.Node << 1) | eEdge.fCompl; } +static inline Kit_Edge_t Kit_IntToEdge( unsigned Edge ) { return Kit_EdgeCreate( Edge >> 1, Edge & 1 ); } +static inline unsigned Kit_EdgeToInt_( Kit_Edge_t eEdge ) { return *(unsigned *)&eEdge; } +static inline Kit_Edge_t Kit_IntToEdge_( unsigned Edge ) { return *(Kit_Edge_t *)&Edge; } + +static inline int Kit_GraphIsConst( Kit_Graph_t * pGraph ) { return pGraph->fConst; } +static inline int Kit_GraphIsConst0( Kit_Graph_t * pGraph ) { return pGraph->fConst && pGraph->eRoot.fCompl; } +static inline int Kit_GraphIsConst1( Kit_Graph_t * pGraph ) { return pGraph->fConst && !pGraph->eRoot.fCompl; } +static inline int Kit_GraphIsComplement( Kit_Graph_t * pGraph ) { return pGraph->eRoot.fCompl; } +static inline int Kit_GraphIsVar( Kit_Graph_t * pGraph ) { return pGraph->eRoot.Node < (unsigned)pGraph->nLeaves; } +static inline void Kit_GraphComplement( Kit_Graph_t * pGraph ) { pGraph->eRoot.fCompl ^= 1; } +static inline void Kit_GraphSetRoot( Kit_Graph_t * pGraph, Kit_Edge_t eRoot ) { pGraph->eRoot = eRoot; } +static inline int Kit_GraphLeaveNum( Kit_Graph_t * pGraph ) { return pGraph->nLeaves; } +static inline int Kit_GraphNodeNum( Kit_Graph_t * pGraph ) { return pGraph->nSize - pGraph->nLeaves; } +static inline Kit_Node_t * Kit_GraphNode( Kit_Graph_t * pGraph, int i ) { return pGraph->pNodes + i; } +static inline Kit_Node_t * Kit_GraphNodeLast( Kit_Graph_t * pGraph ) { return pGraph->pNodes + pGraph->nSize - 1; } +static inline int Kit_GraphNodeInt( Kit_Graph_t * pGraph, Kit_Node_t * pNode ) { return pNode - pGraph->pNodes; } +static inline int Kit_GraphNodeIsVar( Kit_Graph_t * pGraph, Kit_Node_t * pNode ) { return Kit_GraphNodeInt(pGraph,pNode) < pGraph->nLeaves; } +static inline Kit_Node_t * Kit_GraphVar( Kit_Graph_t * pGraph ) { assert( Kit_GraphIsVar( pGraph ) ); return Kit_GraphNode( pGraph, pGraph->eRoot.Node ); } +static inline int Kit_GraphVarInt( Kit_Graph_t * pGraph ) { assert( Kit_GraphIsVar( pGraph ) ); return Kit_GraphNodeInt( pGraph, Kit_GraphVar(pGraph) ); } +static inline Kit_Node_t * Kit_GraphNodeFanin0( Kit_Graph_t * pGraph, Kit_Node_t * pNode ){ return Kit_GraphNodeIsVar(pGraph, pNode)? NULL : Kit_GraphNode(pGraph, pNode->eEdge0.Node); } +static inline Kit_Node_t * Kit_GraphNodeFanin1( Kit_Graph_t * pGraph, Kit_Node_t * pNode ){ return Kit_GraphNodeIsVar(pGraph, pNode)? NULL : Kit_GraphNode(pGraph, pNode->eEdge1.Node); } + +static inline int Kit_Float2Int( float Val ) { return *((int *)&Val); } +static inline float Kit_Int2Float( int Num ) { return *((float *)&Num); } +static inline int Kit_BitWordNum( int nBits ) { return nBits/(8*sizeof(unsigned)) + ((nBits%(8*sizeof(unsigned))) > 0); } +static inline int Kit_TruthWordNum( int nVars ) { return nVars <= 5 ? 1 : (1 << (nVars - 5)); } +static inline unsigned Kit_BitMask( int nBits ) { assert( nBits <= 32 ); return ~((~(unsigned)0) << nBits); } + +static inline void Kit_TruthSetBit( unsigned * p, int Bit ) { p[Bit>>5] |= (1<<(Bit & 31)); } +static inline void Kit_TruthXorBit( unsigned * p, int Bit ) { p[Bit>>5] ^= (1<<(Bit & 31)); } +static inline int Kit_TruthHasBit( unsigned * p, int Bit ) { return (p[Bit>>5] & (1<<(Bit & 31))) > 0; } + +static inline int Kit_WordFindFirstBit( unsigned uWord ) +{ + int i; + for ( i = 0; i < 32; i++ ) + if ( uWord & (1 << i) ) + return i; + return -1; +} +static inline int Kit_WordHasOneBit( unsigned uWord ) +{ + return (uWord & (uWord - 1)) == 0; +} +static inline int Kit_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 Kit_TruthCountOnes( unsigned * pIn, int nVars ) +{ + int w, Counter = 0; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + Counter += Kit_WordCountOnes(pIn[w]); + return Counter; +} +static inline int Kit_TruthFindFirstBit( unsigned * pIn, int nVars ) +{ + int w; + for ( w = 0; w < Kit_TruthWordNum(nVars); w++ ) + if ( pIn[w] ) + return 32*w + Kit_WordFindFirstBit(pIn[w]); + return -1; +} +static inline int Kit_TruthFindFirstZero( unsigned * pIn, int nVars ) +{ + int w; + for ( w = 0; w < Kit_TruthWordNum(nVars); w++ ) + if ( ~pIn[w] ) + return 32*w + Kit_WordFindFirstBit(~pIn[w]); + return -1; +} +static inline int Kit_TruthIsEqual( unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn0[w] != pIn1[w] ) + return 0; + return 1; +} +static inline int Kit_TruthIsOpposite( unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn0[w] != ~pIn1[w] ) + return 0; + return 1; +} +static inline int Kit_TruthIsEqualWithPhase( unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + if ( (pIn0[0] & 1) == (pIn1[0] & 1) ) + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn0[w] != pIn1[w] ) + return 0; + } + else + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn0[w] != ~pIn1[w] ) + return 0; + } + return 1; +} +static inline int Kit_TruthIsConst0( unsigned * pIn, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn[w] ) + return 0; + return 1; +} +static inline int Kit_TruthIsConst1( unsigned * pIn, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn[w] != ~(unsigned)0 ) + return 0; + return 1; +} +static inline int Kit_TruthIsImply( unsigned * pIn1, unsigned * pIn2, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn1[w] & ~pIn2[w] ) + return 0; + return 1; +} +static inline int Kit_TruthIsDisjoint( unsigned * pIn1, unsigned * pIn2, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn1[w] & pIn2[w] ) + return 0; + return 1; +} +static inline int Kit_TruthIsDisjoint3( unsigned * pIn1, unsigned * pIn2, unsigned * pIn3, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + if ( pIn1[w] & pIn2[w] & pIn3[w] ) + return 0; + return 1; +} +static inline void Kit_TruthCopy( unsigned * pOut, unsigned * pIn, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn[w]; +} +static inline void Kit_TruthClear( unsigned * pOut, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = 0; +} +static inline void Kit_TruthFill( unsigned * pOut, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = ~(unsigned)0; +} +static inline void Kit_TruthNot( unsigned * pOut, unsigned * pIn, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = ~pIn[w]; +} +static inline void Kit_TruthAnd( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] & pIn1[w]; +} +static inline void Kit_TruthOr( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] | pIn1[w]; +} +static inline void Kit_TruthXor( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] ^ pIn1[w]; +} +static inline void Kit_TruthSharp( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] & ~pIn1[w]; +} +static inline void Kit_TruthNand( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = ~(pIn0[w] & pIn1[w]); +} +static inline void Kit_TruthAndPhase( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, int nVars, int fCompl0, int fCompl1 ) +{ + int w; + if ( fCompl0 && fCompl1 ) + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = ~(pIn0[w] | pIn1[w]); + } + else if ( fCompl0 && !fCompl1 ) + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = ~pIn0[w] & pIn1[w]; + } + else if ( !fCompl0 && fCompl1 ) + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] & ~pIn1[w]; + } + else // if ( !fCompl0 && !fCompl1 ) + { + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = pIn0[w] & pIn1[w]; + } +} +static inline void Kit_TruthMux( unsigned * pOut, unsigned * pIn0, unsigned * pIn1, unsigned * pCtrl, int nVars ) +{ + int w; + for ( w = Kit_TruthWordNum(nVars)-1; w >= 0; w-- ) + pOut[w] = (pIn0[w] & ~pCtrl[w]) | (pIn1[w] & pCtrl[w]); +} + +//////////////////////////////////////////////////////////////////////// +/// ITERATORS /// +//////////////////////////////////////////////////////////////////////// + +#define Kit_SopForEachCube( cSop, uCube, i ) \ + for ( i = 0; (i < Kit_SopCubeNum(cSop)) && ((uCube) = Kit_SopCube(cSop, i)); i++ ) +#define Kit_CubeForEachLiteral( uCube, Lit, nLits, i ) \ + for ( i = 0; (i < (nLits)) && ((Lit) = Kit_CubeHasLit(uCube, i)); i++ ) + +#define Kit_GraphForEachLeaf( pGraph, pLeaf, i ) \ + for ( i = 0; (i < (pGraph)->nLeaves) && (((pLeaf) = Kit_GraphNode(pGraph, i)), 1); i++ ) +#define Kit_GraphForEachNode( pGraph, pAnd, i ) \ + for ( i = (pGraph)->nLeaves; (i < (pGraph)->nSize) && (((pAnd) = Kit_GraphNode(pGraph, i)), 1); i++ ) + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +/*=== kitBdd.c ==========================================================*/ +extern DdNode * Kit_SopToBdd( DdManager * dd, Kit_Sop_t * cSop, int nVars ); +extern DdNode * Kit_GraphToBdd( DdManager * dd, Kit_Graph_t * pGraph ); +extern DdNode * Kit_TruthToBdd( DdManager * dd, unsigned * pTruth, int nVars, int fMSBonTop ); +/*=== kitDsd.c ==========================================================*/ +extern Kit_DsdMan_t * Kit_DsdManAlloc( int nVars ); +extern void Kit_DsdManFree( Kit_DsdMan_t * p ); +extern Kit_DsdNtk_t * Kit_DsdDeriveNtk( unsigned * pTruth, int nVars, int nLutSize ); +extern unsigned * Kit_DsdTruthCompute( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned uSupp ); +extern void Kit_DsdTruth( Kit_DsdNtk_t * pNtk, unsigned * pTruthRes ); +extern void Kit_DsdTruthPartial( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned * pTruthRes, unsigned uSupp ); +extern void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk ); +extern void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk ); +extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars ); +extern Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars ); +extern Kit_DsdNtk_t * Kit_DsdDecomposeMux( unsigned * pTruth, int nVars, int nDecMux ); +extern void Kit_DsdVerify( Kit_DsdNtk_t * pNtk, unsigned * pTruth, int nVars ); +extern void Kit_DsdNtkFree( Kit_DsdNtk_t * pNtk ); +extern int Kit_DsdNonDsdSizeMax( Kit_DsdNtk_t * pNtk ); +extern void Kit_DsdGetSupports( Kit_DsdNtk_t * p ); +extern Kit_DsdNtk_t * Kit_DsdExpand( Kit_DsdNtk_t * p ); +extern Kit_DsdNtk_t * Kit_DsdShrink( Kit_DsdNtk_t * p, int pPrios[] ); +extern void Kit_DsdRotate( Kit_DsdNtk_t * p, int pFreqs[] ); +extern int Kit_DsdCofactoring( unsigned * pTruth, int nVars, int * pCofVars, int nLimit, int fVerbose ); +/*=== kitFactor.c ==========================================================*/ +extern Kit_Graph_t * Kit_SopFactor( Vec_Int_t * vCover, int fCompl, int nVars, Vec_Int_t * vMemory ); +/*=== kitGraph.c ==========================================================*/ +extern Kit_Graph_t * Kit_GraphCreate( int nLeaves ); +extern Kit_Graph_t * Kit_GraphCreateConst0(); +extern Kit_Graph_t * Kit_GraphCreateConst1(); +extern Kit_Graph_t * Kit_GraphCreateLeaf( int iLeaf, int nLeaves, int fCompl ); +extern void Kit_GraphFree( Kit_Graph_t * pGraph ); +extern Kit_Node_t * Kit_GraphAppendNode( Kit_Graph_t * pGraph ); +extern Kit_Edge_t Kit_GraphAddNodeAnd( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1 ); +extern Kit_Edge_t Kit_GraphAddNodeOr( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1 ); +extern Kit_Edge_t Kit_GraphAddNodeXor( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1, int Type ); +extern Kit_Edge_t Kit_GraphAddNodeMux( Kit_Graph_t * pGraph, Kit_Edge_t eEdgeC, Kit_Edge_t eEdgeT, Kit_Edge_t eEdgeE, int Type ); +extern unsigned Kit_GraphToTruth( Kit_Graph_t * pGraph ); +extern Kit_Graph_t * Kit_TruthToGraph( unsigned * pTruth, int nVars, Vec_Int_t * vMemory ); +extern int Kit_GraphLeafDepth_rec( Kit_Graph_t * pGraph, Kit_Node_t * pNode, Kit_Node_t * pLeaf ); +/*=== kitHop.c ==========================================================*/ +/*=== kitIsop.c ==========================================================*/ +extern int Kit_TruthIsop( unsigned * puTruth, int nVars, Vec_Int_t * vMemory, int fTryBoth ); +/*=== kitSop.c ==========================================================*/ +extern void Kit_SopCreate( Kit_Sop_t * cResult, Vec_Int_t * vInput, int nVars, Vec_Int_t * vMemory ); +extern void Kit_SopCreateInverse( Kit_Sop_t * cResult, Vec_Int_t * vInput, int nVars, Vec_Int_t * vMemory ); +extern void Kit_SopDup( Kit_Sop_t * cResult, Kit_Sop_t * cSop, Vec_Int_t * vMemory ); +extern void Kit_SopDivideByLiteralQuo( Kit_Sop_t * cSop, int iLit ); +extern void Kit_SopDivideByCube( Kit_Sop_t * cSop, Kit_Sop_t * cDiv, Kit_Sop_t * vQuo, Kit_Sop_t * vRem, Vec_Int_t * vMemory ); +extern void Kit_SopDivideInternal( Kit_Sop_t * cSop, Kit_Sop_t * cDiv, Kit_Sop_t * vQuo, Kit_Sop_t * vRem, Vec_Int_t * vMemory ); +extern void Kit_SopMakeCubeFree( Kit_Sop_t * cSop ); +extern int Kit_SopIsCubeFree( Kit_Sop_t * cSop ); +extern void Kit_SopCommonCubeCover( Kit_Sop_t * cResult, Kit_Sop_t * cSop, Vec_Int_t * vMemory ); +extern int Kit_SopAnyLiteral( Kit_Sop_t * cSop, int nLits ); +extern int Kit_SopDivisor( Kit_Sop_t * cResult, Kit_Sop_t * cSop, int nLits, Vec_Int_t * vMemory ); +extern void Kit_SopBestLiteralCover( Kit_Sop_t * cResult, Kit_Sop_t * cSop, unsigned uCube, int nLits, Vec_Int_t * vMemory ); +/*=== kitTruth.c ==========================================================*/ +extern void Kit_TruthSwapAdjacentVars( unsigned * pOut, unsigned * pIn, int nVars, int Start ); +extern void Kit_TruthStretch( unsigned * pOut, unsigned * pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn ); +extern void Kit_TruthShrink( unsigned * pOut, unsigned * pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn ); +extern int Kit_TruthVarInSupport( unsigned * pTruth, int nVars, int iVar ); +extern int Kit_TruthSupportSize( unsigned * pTruth, int nVars ); +extern unsigned Kit_TruthSupport( unsigned * pTruth, int nVars ); +extern void Kit_TruthCofactor0( unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthCofactor1( unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthCofactor0New( unsigned * pOut, unsigned * pIn, int nVars, int iVar ); +extern void Kit_TruthCofactor1New( unsigned * pOut, unsigned * pIn, int nVars, int iVar ); +extern void Kit_TruthExist( unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthExistNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthExistSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask ); +extern void Kit_TruthForall( unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthForallNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthForallSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask ); +extern void Kit_TruthUniqueNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ); +extern void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar ); +extern void Kit_TruthChangePhase( unsigned * pTruth, int nVars, int iVar ); +extern int Kit_TruthMinCofSuppOverlap( unsigned * pTruth, int nVars, int * pVarMin ); +extern int Kit_TruthBestCofVar( unsigned * pTruth, int nVars, unsigned * pCof0, unsigned * pCof1 ); +extern void Kit_TruthCountOnesInCofs( unsigned * pTruth, int nVars, short * pStore ); +extern void Kit_TruthCountOnesInCofsSlow( unsigned * pTruth, int nVars, short * pStore, unsigned * pAux ); +extern unsigned Kit_TruthHash( unsigned * pIn, int nWords ); +extern unsigned Kit_TruthSemiCanonicize( unsigned * pInOut, unsigned * pAux, int nVars, char * pCanonPerm, short * pStore ); +extern char * Kit_TruthDumpToFile( unsigned * pTruth, int nVars, int nFile ); + +#ifdef __cplusplus +} +#endif + +#endif + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + diff --git a/src/aig/kit/kitBdd.c b/src/aig/kit/kitBdd.c new file mode 100644 index 00000000..9c8d4f7a --- /dev/null +++ b/src/aig/kit/kitBdd.c @@ -0,0 +1,231 @@ +/**CFile**************************************************************** + + FileName [kitBdd.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Procedures involving BDDs.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitBdd.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" +#include "extra.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Derives the BDD for the given SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +DdNode * Kit_SopToBdd( DdManager * dd, Kit_Sop_t * cSop, int nVars ) +{ + DdNode * bSum, * bCube, * bTemp, * bVar; + unsigned uCube; + int Value, i, v; + assert( nVars < 16 ); + // start the cover + bSum = Cudd_ReadLogicZero(dd); Cudd_Ref( bSum ); + // check the logic function of the node + Kit_SopForEachCube( cSop, uCube, i ) + { + bCube = Cudd_ReadOne(dd); Cudd_Ref( bCube ); + for ( v = 0; v < nVars; v++ ) + { + Value = ((uCube >> 2*v) & 3); + if ( Value == 1 ) + bVar = Cudd_Not( Cudd_bddIthVar( dd, v ) ); + else if ( Value == 2 ) + bVar = Cudd_bddIthVar( dd, v ); + else + continue; + bCube = Cudd_bddAnd( dd, bTemp = bCube, bVar ); Cudd_Ref( bCube ); + Cudd_RecursiveDeref( dd, bTemp ); + } + bSum = Cudd_bddOr( dd, bTemp = bSum, bCube ); + Cudd_Ref( bSum ); + Cudd_RecursiveDeref( dd, bTemp ); + Cudd_RecursiveDeref( dd, bCube ); + } + // complement the result if necessary + Cudd_Deref( bSum ); + return bSum; +} + +/**Function************************************************************* + + Synopsis [Converts graph to BDD.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +DdNode * Kit_GraphToBdd( DdManager * dd, Kit_Graph_t * pGraph ) +{ + DdNode * bFunc, * bFunc0, * bFunc1; + Kit_Node_t * pNode; + int i; + + // sanity checks + assert( Kit_GraphLeaveNum(pGraph) >= 0 ); + assert( Kit_GraphLeaveNum(pGraph) <= pGraph->nSize ); + + // check for constant function + if ( Kit_GraphIsConst(pGraph) ) + return Cudd_NotCond( b1, Kit_GraphIsComplement(pGraph) ); + // check for a literal + if ( Kit_GraphIsVar(pGraph) ) + return Cudd_NotCond( Cudd_bddIthVar(dd, Kit_GraphVarInt(pGraph)), Kit_GraphIsComplement(pGraph) ); + + // assign the elementary variables + Kit_GraphForEachLeaf( pGraph, pNode, i ) + pNode->pFunc = Cudd_bddIthVar( dd, i ); + + // compute the function for each internal node + Kit_GraphForEachNode( pGraph, pNode, i ) + { + bFunc0 = Cudd_NotCond( Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl ); + bFunc1 = Cudd_NotCond( Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl ); + pNode->pFunc = Cudd_bddAnd( dd, bFunc0, bFunc1 ); Cudd_Ref( pNode->pFunc ); + } + + // deref the intermediate results + bFunc = pNode->pFunc; Cudd_Ref( bFunc ); + Kit_GraphForEachNode( pGraph, pNode, i ) + Cudd_RecursiveDeref( dd, pNode->pFunc ); + Cudd_Deref( bFunc ); + + // complement the result if necessary + return Cudd_NotCond( bFunc, Kit_GraphIsComplement(pGraph) ); +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +DdNode * Kit_TruthToBdd_rec( DdManager * dd, unsigned * pTruth, int iBit, int nVars, int nVarsTotal, int fMSBonTop ) +{ + DdNode * bF0, * bF1, * bF; + int Var; + if ( nVars <= 5 ) + { + unsigned uTruth, uMask; + uMask = ((~(unsigned)0) >> (32 - (1<>5] >> (iBit&31)) & uMask; + if ( uTruth == 0 ) + return b0; + if ( uTruth == uMask ) + return b1; + } + // find the variable to use + Var = fMSBonTop? nVarsTotal-nVars : nVars-1; + // other special cases can be added + bF0 = Kit_TruthToBdd_rec( dd, pTruth, iBit, nVars-1, nVarsTotal, fMSBonTop ); Cudd_Ref( bF0 ); + bF1 = Kit_TruthToBdd_rec( dd, pTruth, iBit+(1<<(nVars-1)), nVars-1, nVarsTotal, fMSBonTop ); Cudd_Ref( bF1 ); + bF = Cudd_bddIte( dd, dd->vars[Var], bF1, bF0 ); Cudd_Ref( bF ); + Cudd_RecursiveDeref( dd, bF0 ); + Cudd_RecursiveDeref( dd, bF1 ); + Cudd_Deref( bF ); + return bF; +} + +/**Function************************************************************* + + Synopsis [Compute BDD corresponding to the truth table.] + + Description [If truth table has N vars, the BDD depends on N topmost + variables of the BDD manager. The most significant variable of the table + is encoded by the topmost variable of the manager. BDD construction is + efficient in this case because BDD is constructed one node at a time, + by simply adding BDD nodes on top of existent BDD nodes.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +DdNode * Kit_TruthToBdd( DdManager * dd, unsigned * pTruth, int nVars, int fMSBonTop ) +{ + return Kit_TruthToBdd_rec( dd, pTruth, 0, nVars, nVars, fMSBonTop ); +} + +/**Function************************************************************* + + Synopsis [Verifies that the factoring is correct.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopFactorVerify( Vec_Int_t * vCover, Kit_Graph_t * pFForm, int nVars ) +{ + static DdManager * dd = NULL; + Kit_Sop_t Sop, * cSop = &Sop; + DdNode * bFunc1, * bFunc2; + Vec_Int_t * vMemory; + int RetValue; + // get the manager + if ( dd == NULL ) + dd = Cudd_Init( 16, 0, CUDD_UNIQUE_SLOTS, CUDD_CACHE_SLOTS, 0 ); + // derive SOP + vMemory = Vec_IntAlloc( Vec_IntSize(vCover) ); + Kit_SopCreate( cSop, vCover, nVars, vMemory ); + // get the functions + bFunc1 = Kit_SopToBdd( dd, cSop, nVars ); Cudd_Ref( bFunc1 ); + bFunc2 = Kit_GraphToBdd( dd, pFForm ); Cudd_Ref( bFunc2 ); +//Extra_bddPrint( dd, bFunc1 ); printf("\n"); +//Extra_bddPrint( dd, bFunc2 ); printf("\n"); + RetValue = (bFunc1 == bFunc2); + if ( bFunc1 != bFunc2 ) + { + int s; + Extra_bddPrint( dd, bFunc1 ); printf("\n"); + Extra_bddPrint( dd, bFunc2 ); printf("\n"); + s = 0; + } + Cudd_RecursiveDeref( dd, bFunc1 ); + Cudd_RecursiveDeref( dd, bFunc2 ); + Vec_IntFree( vMemory ); + return RetValue; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitDsd.c b/src/aig/kit/kitDsd.c new file mode 100644 index 00000000..06377cba --- /dev/null +++ b/src/aig/kit/kitDsd.c @@ -0,0 +1,2185 @@ +/**CFile**************************************************************** + + FileName [kitDsd.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Performs disjoint-support decomposition based on truth tables.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitDsd.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Allocates the DSD manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdMan_t * Kit_DsdManAlloc( int nVars ) +{ + Kit_DsdMan_t * p; + p = ALLOC( Kit_DsdMan_t, 1 ); + memset( p, 0, sizeof(Kit_DsdMan_t) ); + p->nVars = nVars; + p->nWords = Kit_TruthWordNum( p->nVars ); + p->vTtElems = Vec_PtrAllocTruthTables( p->nVars ); + p->vTtNodes = Vec_PtrAllocSimInfo( 1024, p->nWords ); + return p; +} + +/**Function************************************************************* + + Synopsis [Deallocates the DSD manager.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdManFree( Kit_DsdMan_t * p ) +{ + Vec_PtrFree( p->vTtElems ); + Vec_PtrFree( p->vTtNodes ); + free( p ); +} + +/**Function************************************************************* + + Synopsis [Allocates the DSD node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdObj_t * Kit_DsdObjAlloc( Kit_DsdNtk_t * pNtk, Kit_Dsd_t Type, int nFans ) +{ + Kit_DsdObj_t * pObj; + int nSize = sizeof(Kit_DsdObj_t) + sizeof(unsigned) * (Kit_DsdObjOffset(nFans) + (Type == KIT_DSD_PRIME) * Kit_TruthWordNum(nFans)); + pObj = (Kit_DsdObj_t *)ALLOC( char, nSize ); + memset( pObj, 0, nSize ); + pObj->Id = pNtk->nVars + pNtk->nNodes; + pObj->Type = Type; + pObj->nFans = nFans; + pObj->Offset = Kit_DsdObjOffset( nFans ); + // add the object + if ( pNtk->nNodes == pNtk->nNodesAlloc ) + { + pNtk->nNodesAlloc *= 2; + pNtk->pNodes = REALLOC( Kit_DsdObj_t *, pNtk->pNodes, pNtk->nNodesAlloc ); + } + assert( pNtk->nNodes < pNtk->nNodesAlloc ); + pNtk->pNodes[pNtk->nNodes++] = pObj; + return pObj; +} + +/**Function************************************************************* + + Synopsis [Deallocates the DSD node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdObjFree( Kit_DsdNtk_t * p, Kit_DsdObj_t * pObj ) +{ + free( pObj ); +} + +/**Function************************************************************* + + Synopsis [Allocates the DSD network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdNtkAlloc( int nVars ) +{ + Kit_DsdNtk_t * pNtk; + pNtk = ALLOC( Kit_DsdNtk_t, 1 ); + memset( pNtk, 0, sizeof(Kit_DsdNtk_t) ); + pNtk->pNodes = ALLOC( Kit_DsdObj_t *, nVars ); + pNtk->nVars = nVars; + pNtk->nNodesAlloc = nVars; + pNtk->pMem = ALLOC( unsigned, 6 * Kit_TruthWordNum(nVars) ); + return pNtk; +} + +/**Function************************************************************* + + Synopsis [Deallocate the DSD network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdNtkFree( Kit_DsdNtk_t * pNtk ) +{ + Kit_DsdObj_t * pObj; + unsigned i; + Kit_DsdNtkForEachObj( pNtk, pObj, i ) + free( pObj ); + FREE( pNtk->pSupps ); + free( pNtk->pNodes ); + free( pNtk->pMem ); + free( pNtk ); +} + +/**Function************************************************************* + + Synopsis [Prints the hex unsigned into a file.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrintHex( FILE * pFile, unsigned * pTruth, int nFans ) +{ + int nDigits, Digit, k; + nDigits = (1 << nFans) / 4; + for ( k = nDigits - 1; k >= 0; k-- ) + { + Digit = ((pTruth[k/8] >> ((k%8) * 4)) & 15); + if ( Digit < 10 ) + fprintf( pFile, "%d", Digit ); + else + fprintf( pFile, "%c", 'A' + Digit-10 ); + } +} + +/**Function************************************************************* + + Synopsis [Recursively print the DSD formula.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrint_rec( FILE * pFile, Kit_DsdNtk_t * pNtk, int Id ) +{ + Kit_DsdObj_t * pObj; + unsigned iLit, i; + char Symbol; + + pObj = Kit_DsdNtkObj( pNtk, Id ); + if ( pObj == NULL ) + { + assert( Id < pNtk->nVars ); + fprintf( pFile, "%c", 'a' + Id ); + return; + } + + if ( pObj->Type == KIT_DSD_CONST1 ) + { + assert( pObj->nFans == 0 ); + fprintf( pFile, "Const1" ); + return; + } + + if ( pObj->Type == KIT_DSD_VAR ) + assert( pObj->nFans == 1 ); + + if ( pObj->Type == KIT_DSD_AND ) + Symbol = '*'; + else if ( pObj->Type == KIT_DSD_XOR ) + Symbol = '+'; + else + Symbol = ','; + + if ( pObj->Type == KIT_DSD_PRIME ) + Kit_DsdPrintHex( stdout, Kit_DsdObjTruth(pObj), pObj->nFans ); + + fprintf( pFile, "(" ); + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + { + if ( Kit_DsdLitIsCompl(iLit) ) + fprintf( pFile, "!" ); + Kit_DsdPrint_rec( pFile, pNtk, Kit_DsdLit2Var(iLit) ); + if ( i < pObj->nFans - 1 ) + fprintf( pFile, "%c", Symbol ); + } + fprintf( pFile, ")" ); +} + +/**Function************************************************************* + + Synopsis [Print the DSD formula.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk ) +{ + fprintf( pFile, "F = " ); + if ( Kit_DsdLitIsCompl(pNtk->Root) ) + fprintf( pFile, "!" ); + Kit_DsdPrint_rec( pFile, pNtk, Kit_DsdLit2Var(pNtk->Root) ); + fprintf( pFile, "\n" ); +} + +/**Function************************************************************* + + Synopsis [Print the DSD formula.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk ) +{ + Kit_DsdNtk_t * pTemp; + pTemp = Kit_DsdExpand( pNtk ); + Kit_DsdPrint( stdout, pTemp ); + Kit_DsdNtkFree( pTemp ); +} + +/**Function************************************************************* + + Synopsis [Print the DSD formula.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars ) +{ + Kit_DsdNtk_t * pTemp; + pTemp = Kit_DsdDecomposeMux( pTruth, nVars, 5 ); + Kit_DsdVerify( pTemp, pTruth, nVars ); + Kit_DsdPrintExpanded( pTemp ); + Kit_DsdNtkFree( pTemp ); +} + +/**Function************************************************************* + + Synopsis [Derives the truth table of the DSD node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Kit_DsdTruthComputeNode_rec( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, int Id, unsigned uSupp ) +{ + Kit_DsdObj_t * pObj; + unsigned * pTruthRes, * pTruthPrime, * pTruthMint, * pTruthFans[16]; + unsigned i, m, iLit, nMints, fCompl, fPartial = 0; + + // get the node with this ID + pObj = Kit_DsdNtkObj( pNtk, Id ); + pTruthRes = Vec_PtrEntry( p->vTtNodes, Id ); + + // special case: literal of an internal node + if ( pObj == NULL ) + { + assert( Id < pNtk->nVars ); + assert( !uSupp || uSupp != (uSupp & ~(1<Type == KIT_DSD_CONST1 ) + { + assert( pObj->nFans == 0 ); + Kit_TruthFill( pTruthRes, pNtk->nVars ); + return pTruthRes; + } + + // elementary variable node + if ( pObj->Type == KIT_DSD_VAR ) + { + assert( pObj->nFans == 1 ); + iLit = pObj->pFans[0]; + assert( Kit_DsdLitIsLeaf( pNtk, iLit ) ); + pTruthFans[0] = Kit_DsdTruthComputeNode_rec( p, pNtk, Kit_DsdLit2Var(iLit), uSupp ); + if ( Kit_DsdLitIsCompl(iLit) ) + Kit_TruthNot( pTruthRes, pTruthFans[0], pNtk->nVars ); + else + Kit_TruthCopy( pTruthRes, pTruthFans[0], pNtk->nVars ); + return pTruthRes; + } + + // collect the truth tables of the fanins + if ( uSupp ) + { + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + if ( uSupp != (uSupp & ~Kit_DsdLitSupport(pNtk, iLit)) ) + pTruthFans[i] = Kit_DsdTruthComputeNode_rec( p, pNtk, Kit_DsdLit2Var(iLit), uSupp ); + else + { + pTruthFans[i] = NULL; + fPartial = 1; + } + } + else + { + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + pTruthFans[i] = Kit_DsdTruthComputeNode_rec( p, pNtk, Kit_DsdLit2Var(iLit), uSupp ); + } + // create the truth table + + // simple gates + if ( pObj->Type == KIT_DSD_AND ) + { + Kit_TruthFill( pTruthRes, pNtk->nVars ); + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + if ( pTruthFans[i] ) + Kit_TruthAndPhase( pTruthRes, pTruthRes, pTruthFans[i], pNtk->nVars, 0, Kit_DsdLitIsCompl(iLit) ); + return pTruthRes; + } + if ( pObj->Type == KIT_DSD_XOR ) + { + Kit_TruthClear( pTruthRes, pNtk->nVars ); + fCompl = 0; + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + { + if ( pTruthFans[i] ) + { + Kit_TruthXor( pTruthRes, pTruthRes, pTruthFans[i], pNtk->nVars ); + fCompl ^= Kit_DsdLitIsCompl(iLit); + } + } + if ( fCompl ) + Kit_TruthNot( pTruthRes, pTruthRes, pNtk->nVars ); + return pTruthRes; + } + assert( pObj->Type == KIT_DSD_PRIME ); + + if ( uSupp && fPartial ) + { + // find the only non-empty component + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + if ( pTruthFans[i] ) + break; + assert( i < pObj->nFans ); + return pTruthFans[i]; + } + + // get the truth table of the prime node + pTruthPrime = Kit_DsdObjTruth( pObj ); + // get storage for the temporary minterm + pTruthMint = Vec_PtrEntry(p->vTtNodes, pNtk->nVars + pNtk->nNodes); + + // go through the minterms + nMints = (1 << pObj->nFans); + Kit_TruthClear( pTruthRes, pNtk->nVars ); + for ( m = 0; m < nMints; m++ ) + { + if ( !Kit_TruthHasBit(pTruthPrime, m) ) + continue; + Kit_TruthFill( pTruthMint, pNtk->nVars ); + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + Kit_TruthAndPhase( pTruthMint, pTruthMint, pTruthFans[i], pNtk->nVars, 0, ((m & (1<nVars ); + } + return pTruthRes; +} + +/**Function************************************************************* + + Synopsis [Derives the truth table of the DSD network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Kit_DsdTruthCompute( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned uSupp ) +{ + unsigned * pTruthRes; + int i; + // if support is specified, request that supports are available + if ( uSupp ) + Kit_DsdGetSupports( pNtk ); + // assign elementary truth tables + assert( pNtk->nVars <= p->nVars ); + for ( i = 0; i < (int)pNtk->nVars; i++ ) + Kit_TruthCopy( Vec_PtrEntry(p->vTtNodes, i), Vec_PtrEntry(p->vTtElems, i), p->nVars ); + // compute truth table for each node + pTruthRes = Kit_DsdTruthComputeNode_rec( p, pNtk, Kit_DsdLit2Var(pNtk->Root), uSupp ); + // complement the truth table if needed + if ( Kit_DsdLitIsCompl(pNtk->Root) ) + Kit_TruthNot( pTruthRes, pTruthRes, pNtk->nVars ); + return pTruthRes; +} + +/**Function************************************************************* + + Synopsis [Derives the truth table of the DSD network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdTruth( Kit_DsdNtk_t * pNtk, unsigned * pTruthRes ) +{ + Kit_DsdMan_t * p; + unsigned * pTruth; + p = Kit_DsdManAlloc( pNtk->nVars ); + pTruth = Kit_DsdTruthCompute( p, pNtk, 0 ); + Kit_TruthCopy( pTruthRes, pTruth, pNtk->nVars ); + Kit_DsdManFree( p ); +} + +/**Function************************************************************* + + Synopsis [Derives the truth table of the DSD network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdTruthPartial( Kit_DsdMan_t * p, Kit_DsdNtk_t * pNtk, unsigned * pTruthRes, unsigned uSupp ) +{ + unsigned * pTruth = Kit_DsdTruthCompute( p, pNtk, uSupp ); + Kit_TruthCopy( pTruthRes, pTruth, pNtk->nVars ); +} + +/**Function************************************************************* + + Synopsis [Counts the number of blocks of the given number of inputs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdCountLuts_rec( Kit_DsdNtk_t * pNtk, int nLutSize, int Id, int * pCounter ) +{ + Kit_DsdObj_t * pObj; + unsigned iLit, i, Res0, Res1; + pObj = Kit_DsdNtkObj( pNtk, Id ); + if ( pObj == NULL ) + return 0; + if ( pObj->Type == KIT_DSD_AND || pObj->Type == KIT_DSD_XOR ) + { + assert( pObj->nFans == 2 ); + Res0 = Kit_DsdCountLuts_rec( pNtk, nLutSize, Kit_DsdLit2Var(pObj->pFans[0]), pCounter ); + Res1 = Kit_DsdCountLuts_rec( pNtk, nLutSize, Kit_DsdLit2Var(pObj->pFans[1]), pCounter ); + if ( Res0 == 0 && Res1 > 0 ) + return Res1 - 1; + if ( Res0 > 0 && Res1 == 0 ) + return Res0 - 1; + (*pCounter)++; + return nLutSize - 2; + } + assert( pObj->Type == KIT_DSD_PRIME ); + if ( (int)pObj->nFans > nLutSize ) //+ 1 ) + { + *pCounter = 1000; + return 0; + } + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + Kit_DsdCountLuts_rec( pNtk, nLutSize, Kit_DsdLit2Var(iLit), pCounter ); + (*pCounter)++; +// if ( (int)pObj->nFans == nLutSize + 1 ) +// (*pCounter)++; + return nLutSize - pObj->nFans; +} + +/**Function************************************************************* + + Synopsis [Counts the number of blocks of the given number of inputs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdCountLuts( Kit_DsdNtk_t * pNtk, int nLutSize ) +{ + int Counter = 0; + if ( Kit_DsdNtkRoot(pNtk)->Type == KIT_DSD_CONST1 ) + return 0; + if ( Kit_DsdNtkRoot(pNtk)->Type == KIT_DSD_VAR ) + return 0; + Kit_DsdCountLuts_rec( pNtk, nLutSize, Kit_DsdLit2Var(pNtk->Root), &Counter ); + if ( Counter >= 1000 ) + return -1; + return Counter; +} + +/**Function************************************************************* + + Synopsis [Counts the number of blocks of the given number of inputs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdNonDsdSizeMax( Kit_DsdNtk_t * pNtk ) +{ + Kit_DsdObj_t * pObj; + unsigned i, nSizeMax = 0; + Kit_DsdNtkForEachObj( pNtk, pObj, i ) + { + if ( pObj->Type != KIT_DSD_PRIME ) + continue; + if ( nSizeMax < pObj->nFans ) + nSizeMax = pObj->nFans; + } + return nSizeMax; +} + + +/**Function************************************************************* + + Synopsis [Expands the node.] + + Description [Returns the new literal.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdExpandCollectAnd_rec( Kit_DsdNtk_t * p, int iLit, int * piLitsNew, int * nLitsNew ) +{ + Kit_DsdObj_t * pObj; + unsigned i, iLitFanin; + // check the end of the supergate + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + if ( Kit_DsdLitIsCompl(iLit) || Kit_DsdLit2Var(iLit) < p->nVars || pObj->Type != KIT_DSD_AND ) + { + piLitsNew[(*nLitsNew)++] = iLit; + return; + } + // iterate through the fanins + Kit_DsdObjForEachFanin( p, pObj, iLitFanin, i ) + Kit_DsdExpandCollectAnd_rec( p, iLitFanin, piLitsNew, nLitsNew ); +} + +/**Function************************************************************* + + Synopsis [Expands the node.] + + Description [Returns the new literal.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdExpandCollectXor_rec( Kit_DsdNtk_t * p, int iLit, int * piLitsNew, int * nLitsNew ) +{ + Kit_DsdObj_t * pObj; + unsigned i, iLitFanin; + // check the end of the supergate + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + if ( Kit_DsdLit2Var(iLit) < p->nVars || pObj->Type != KIT_DSD_XOR ) + { + piLitsNew[(*nLitsNew)++] = iLit; + return; + } + // iterate through the fanins + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + Kit_DsdObjForEachFanin( p, pObj, iLitFanin, i ) + Kit_DsdExpandCollectXor_rec( p, iLitFanin, piLitsNew, nLitsNew ); + // if the literal was complemented, pass the complemented attribute somewhere + if ( Kit_DsdLitIsCompl(iLit) ) + piLitsNew[0] = Kit_DsdLitNot( piLitsNew[0] ); +} + +/**Function************************************************************* + + Synopsis [Expands the node.] + + Description [Returns the new literal.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdExpandNode_rec( Kit_DsdNtk_t * pNew, Kit_DsdNtk_t * p, int iLit ) +{ + unsigned * pTruth, * pTruthNew; + unsigned i, iLitFanin, piLitsNew[16], nLitsNew = 0; + Kit_DsdObj_t * pObj, * pObjNew; + + // consider the case of simple gate + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + if ( pObj == NULL ) + return iLit; + if ( pObj->Type == KIT_DSD_AND ) + { + Kit_DsdExpandCollectAnd_rec( p, Kit_DsdLitRegular(iLit), piLitsNew, &nLitsNew ); + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_AND, nLitsNew ); + for ( i = 0; i < pObjNew->nFans; i++ ) + pObjNew->pFans[i] = Kit_DsdExpandNode_rec( pNew, p, piLitsNew[i] ); + return Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(iLit) ); + } + if ( pObj->Type == KIT_DSD_XOR ) + { + int fCompl = Kit_DsdLitIsCompl(iLit); + Kit_DsdExpandCollectXor_rec( p, Kit_DsdLitRegular(iLit), piLitsNew, &nLitsNew ); + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_XOR, nLitsNew ); + for ( i = 0; i < pObjNew->nFans; i++ ) + { + pObjNew->pFans[i] = Kit_DsdExpandNode_rec( pNew, p, Kit_DsdLitRegular(piLitsNew[i]) ); + fCompl ^= Kit_DsdLitIsCompl(piLitsNew[i]); + } + return Kit_DsdVar2Lit( pObjNew->Id, fCompl ); + } + assert( pObj->Type == KIT_DSD_PRIME ); + + // create new PRIME node + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_PRIME, pObj->nFans ); + // copy the truth table + pTruth = Kit_DsdObjTruth( pObj ); + pTruthNew = Kit_DsdObjTruth( pObjNew ); + Kit_TruthCopy( pTruthNew, pTruth, pObj->nFans ); + // create fanins + Kit_DsdObjForEachFanin( pNtk, pObj, iLitFanin, i ) + { + pObjNew->pFans[i] = Kit_DsdExpandNode_rec( pNew, p, iLitFanin ); + // complement the corresponding inputs of the truth table + if ( Kit_DsdLitIsCompl(pObjNew->pFans[i]) ) + { + pObjNew->pFans[i] = Kit_DsdLitRegular(pObjNew->pFans[i]); + Kit_TruthChangePhase( pTruthNew, pObjNew->nFans, i ); + } + } + // if the incoming phase is complemented, absorb it into the prime node + if ( Kit_DsdLitIsCompl(iLit) ) + Kit_TruthNot( pTruthNew, pTruthNew, pObj->nFans ); + return Kit_DsdVar2Lit( pObjNew->Id, 0 ); +} + +/**Function************************************************************* + + Synopsis [Expands the network.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdExpand( Kit_DsdNtk_t * p ) +{ + Kit_DsdNtk_t * pNew; + Kit_DsdObj_t * pObjNew; + assert( p->nVars <= 16 ); + // create a new network + pNew = Kit_DsdNtkAlloc( p->nVars ); + // consider simple special cases + if ( Kit_DsdNtkRoot(p)->Type == KIT_DSD_CONST1 ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_CONST1, 0 ); + pNew->Root = Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(p->Root) ); + return pNew; + } + if ( Kit_DsdNtkRoot(p)->Type == KIT_DSD_VAR ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_VAR, 1 ); + pObjNew->pFans[0] = Kit_DsdNtkRoot(p)->pFans[0]; + pNew->Root = Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(p->Root) ); + return pNew; + } + // convert the root node + pNew->Root = Kit_DsdExpandNode_rec( pNew, p, p->Root ); + return pNew; +} + +/**Function************************************************************* + + Synopsis [Sorts the literals by their support.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdCompSort( int pPrios[], unsigned uSupps[], unsigned char * piLits, int nVars, int piLitsRes[] ) +{ + int nSuppSizes[16], Priority[16], pOrder[16]; + int i, k, iVarBest, SuppMax, PrioMax; + // compute support sizes and priorities of the components + for ( i = 0; i < nVars; i++ ) + { + assert( uSupps[i] ); + pOrder[i] = i; + Priority[i] = KIT_INFINITY; + for ( k = 0; k < 16; k++ ) + if ( uSupps[i] & (1 << k) ) + Priority[i] = KIT_MIN( Priority[i], pPrios[k] ); + assert( Priority[i] != 16 ); + nSuppSizes[i] = Kit_WordCountOnes(uSupps[i]); + } + // sort the components by pririty + Extra_BubbleSort( pOrder, Priority, nVars, 0 ); + // find the component by with largest size and lowest priority + iVarBest = -1; + SuppMax = 0; + PrioMax = 0; + for ( i = 0; i < nVars; i++ ) + { + if ( SuppMax < nSuppSizes[i] || (SuppMax == nSuppSizes[i] && PrioMax < Priority[i]) ) + { + SuppMax = nSuppSizes[i]; + PrioMax = Priority[i]; + iVarBest = i; + } + } + assert( iVarBest != -1 ); + // copy the resulting literals + k = 0; + piLitsRes[k++] = piLits[iVarBest]; + for ( i = 0; i < nVars; i++ ) + { + if ( pOrder[i] == iVarBest ) + continue; + piLitsRes[k++] = piLits[pOrder[i]]; + } + assert( k == nVars ); +} + +/**Function************************************************************* + + Synopsis [Shrinks multi-input nodes.] + + Description [Takes the array of variable priorities pPrios.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdShrink_rec( Kit_DsdNtk_t * pNew, Kit_DsdNtk_t * p, int iLit, int pPrios[] ) +{ + Kit_DsdObj_t * pObj, * pObjNew; + unsigned * pTruth, * pTruthNew; + unsigned i, piLitsNew[16], uSupps[16]; + int iLitFanin, iLitNew; + + // consider the case of simple gate + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + if ( pObj == NULL ) + return iLit; + if ( pObj->Type == KIT_DSD_AND ) + { + // get the supports + Kit_DsdObjForEachFanin( p, pObj, iLitFanin, i ) + uSupps[i] = Kit_DsdLitSupport( p, iLitFanin ); + // put the largest component last + // sort other components in the decreasing order of priority of their vars + Kit_DsdCompSort( pPrios, uSupps, pObj->pFans, pObj->nFans, piLitsNew ); + // construct the two-input node network + iLitNew = Kit_DsdShrink_rec( pNew, p, piLitsNew[0], pPrios ); + for ( i = 1; i < pObj->nFans; i++ ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_AND, 2 ); + pObjNew->pFans[0] = Kit_DsdShrink_rec( pNew, p, piLitsNew[i], pPrios ); + pObjNew->pFans[1] = iLitNew; + iLitNew = Kit_DsdVar2Lit( pObjNew->Id, 0 ); + } + return Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(iLit) ); + } + if ( pObj->Type == KIT_DSD_XOR ) + { + // get the supports + Kit_DsdObjForEachFanin( p, pObj, iLitFanin, i ) + { + assert( !Kit_DsdLitIsCompl(iLitFanin) ); + uSupps[i] = Kit_DsdLitSupport( p, iLitFanin ); + } + // put the largest component last + // sort other components in the decreasing order of priority of their vars + Kit_DsdCompSort( pPrios, uSupps, pObj->pFans, pObj->nFans, piLitsNew ); + // construct the two-input node network + iLitNew = Kit_DsdShrink_rec( pNew, p, piLitsNew[0], pPrios ); + for ( i = 1; i < pObj->nFans; i++ ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_XOR, 2 ); + pObjNew->pFans[0] = Kit_DsdShrink_rec( pNew, p, piLitsNew[i], pPrios ); + pObjNew->pFans[1] = iLitNew; + iLitNew = Kit_DsdVar2Lit( pObjNew->Id, 0 ); + } + return Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(iLit) ); + } + assert( pObj->Type == KIT_DSD_PRIME ); + + // create new PRIME node + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_PRIME, pObj->nFans ); + // copy the truth table + pTruth = Kit_DsdObjTruth( pObj ); + pTruthNew = Kit_DsdObjTruth( pObjNew ); + Kit_TruthCopy( pTruthNew, pTruth, pObj->nFans ); + // create fanins + Kit_DsdObjForEachFanin( pNtk, pObj, iLitFanin, i ) + { + pObjNew->pFans[i] = Kit_DsdShrink_rec( pNew, p, iLitFanin, pPrios ); + // complement the corresponding inputs of the truth table + if ( Kit_DsdLitIsCompl(pObjNew->pFans[i]) ) + { + pObjNew->pFans[i] = Kit_DsdLitRegular(pObjNew->pFans[i]); + Kit_TruthChangePhase( pTruthNew, pObjNew->nFans, i ); + } + } + // if the incoming phase is complemented, absorb it into the prime node + if ( Kit_DsdLitIsCompl(iLit) ) + Kit_TruthNot( pTruthNew, pTruthNew, pObj->nFans ); + return Kit_DsdVar2Lit( pObjNew->Id, 0 ); +} + +/**Function************************************************************* + + Synopsis [Shrinks the network.] + + Description [Transforms the network to have two-input nodes so that the + higher-ordered nodes were decomposed out first.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdShrink( Kit_DsdNtk_t * p, int pPrios[] ) +{ + Kit_DsdNtk_t * pNew; + Kit_DsdObj_t * pObjNew; + assert( p->nVars <= 16 ); + // create a new network + pNew = Kit_DsdNtkAlloc( p->nVars ); + // consider simple special cases + if ( Kit_DsdNtkRoot(p)->Type == KIT_DSD_CONST1 ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_CONST1, 0 ); + pNew->Root = Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(p->Root) ); + return pNew; + } + if ( Kit_DsdNtkRoot(p)->Type == KIT_DSD_VAR ) + { + pObjNew = Kit_DsdObjAlloc( pNew, KIT_DSD_VAR, 1 ); + pObjNew->pFans[0] = Kit_DsdNtkRoot(p)->pFans[0]; + pNew->Root = Kit_DsdVar2Lit( pObjNew->Id, Kit_DsdLitIsCompl(p->Root) ); + return pNew; + } + // convert the root node + pNew->Root = Kit_DsdShrink_rec( pNew, p, p->Root, pPrios ); + return pNew; +} + +/**Function************************************************************* + + Synopsis [Rotates the network.] + + Description [Transforms prime nodes to have the fanin with the + highest frequency of supports go first.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdRotate( Kit_DsdNtk_t * p, int pFreqs[] ) +{ + Kit_DsdObj_t * pObj; + unsigned * pIn, * pOut, * pTemp, k; + int i, v, Temp, uSuppFanin, iFaninLit, WeightMax, FaninMax, nSwaps; + int Weights[16]; + // go through the prime nodes + Kit_DsdNtkForEachObj( p, pObj, i ) + { + if ( pObj->Type != KIT_DSD_PRIME ) + continue; + // count the fanin frequencies + Kit_DsdObjForEachFanin( p, pObj, iFaninLit, k ) + { + uSuppFanin = Kit_DsdLitSupport( p, iFaninLit ); + Weights[k] = 0; + for ( v = 0; v < 16; v++ ) + if ( uSuppFanin & (1 << v) ) + Weights[k] += pFreqs[v] - 1; + } + // find the most frequent fanin + WeightMax = 0; + FaninMax = -1; + for ( k = 0; k < pObj->nFans; k++ ) + if ( WeightMax < Weights[k] ) + { + WeightMax = Weights[k]; + FaninMax = k; + } + // no need to reorder if there are no frequent fanins + if ( FaninMax == -1 ) + continue; + // move the fanins number k to the first place + nSwaps = 0; + pIn = Kit_DsdObjTruth(pObj); + pOut = p->pMem; +// for ( v = FaninMax; v < ((int)pObj->nFans)-1; v++ ) + for ( v = FaninMax-1; v >= 0; v-- ) + { + // swap the fanins + Temp = pObj->pFans[v]; + pObj->pFans[v] = pObj->pFans[v+1]; + pObj->pFans[v+1] = Temp; + // swap the truth table variables + Kit_TruthSwapAdjacentVars( pOut, pIn, pObj->nFans, v ); + pTemp = pIn; pIn = pOut; pOut = pTemp; + nSwaps++; + } + if ( nSwaps & 1 ) + Kit_TruthCopy( pOut, pIn, pObj->nFans ); + } +} + +/**Function************************************************************* + + Synopsis [Compute the support.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_DsdGetSupports_rec( Kit_DsdNtk_t * p, int iLit ) +{ + Kit_DsdObj_t * pObj; + unsigned uSupport, k; + int iFaninLit; + pObj = Kit_DsdNtkObj( p, Kit_DsdLit2Var(iLit) ); + if ( pObj == NULL ) + return Kit_DsdLitSupport( p, iLit ); + uSupport = 0; + Kit_DsdObjForEachFanin( p, pObj, iFaninLit, k ) + uSupport |= Kit_DsdGetSupports_rec( p, iFaninLit ); + p->pSupps[pObj->Id - p->nVars] = uSupport; + assert( uSupport <= 0xFFFF ); + return uSupport; +} + +/**Function************************************************************* + + Synopsis [Compute the support.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdGetSupports( Kit_DsdNtk_t * p ) +{ + Kit_DsdObj_t * pRoot; + assert( p->pSupps == NULL ); + p->pSupps = ALLOC( unsigned, p->nNodes ); + // consider simple special cases + pRoot = Kit_DsdNtkRoot(p); + if ( pRoot->Type == KIT_DSD_CONST1 ) + { + assert( p->nNodes == 1 ); + p->pSupps[0] = 0; + } + if ( pRoot->Type == KIT_DSD_VAR ) + { + assert( p->nNodes == 1 ); + p->pSupps[0] = Kit_DsdLitSupport( p, pRoot->pFans[0] ); + } + else + Kit_DsdGetSupports_rec( p, p->Root ); + assert( p->pSupps[0] <= 0xFFFF ); +} + +/**Function************************************************************* + + Synopsis [Returns 1 if there is a component with more than 3 inputs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdFindLargeBox_rec( Kit_DsdNtk_t * pNtk, int Id, int Size ) +{ + Kit_DsdObj_t * pObj; + unsigned iLit, i, RetValue; + pObj = Kit_DsdNtkObj( pNtk, Id ); + if ( pObj == NULL ) + return 0; + if ( pObj->Type == KIT_DSD_PRIME && (int)pObj->nFans > Size ) + return 1; + RetValue = 0; + Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i ) + RetValue |= Kit_DsdFindLargeBox_rec( pNtk, Kit_DsdLit2Var(iLit), Size ); + return RetValue; +} + +/**Function************************************************************* + + Synopsis [Returns 1 if there is a component with more than 3 inputs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdFindLargeBox( Kit_DsdNtk_t * pNtk, int Size ) +{ + return Kit_DsdFindLargeBox_rec( pNtk, Kit_DsdLit2Var(pNtk->Root), Size ); +} + +/**Function************************************************************* + + Synopsis [Returns 1 if the non-DSD 4-var func is implementable with two 3-LUTs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdRootNodeHasCommonVars( Kit_DsdObj_t * pObj0, Kit_DsdObj_t * pObj1 ) +{ + unsigned i, k; + for ( i = 0; i < pObj0->nFans; i++ ) + { + if ( Kit_DsdLit2Var(pObj0->pFans[i]) >= 4 ) + continue; + for ( k = 0; k < pObj1->nFans; k++ ) + if ( Kit_DsdLit2Var(pObj0->pFans[i]) == Kit_DsdLit2Var(pObj1->pFans[k]) ) + return 1; + } + return 0; +} + +/**Function************************************************************* + + Synopsis [Returns 1 if the non-DSD 4-var func is implementable with two 3-LUTs.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdCheckVar4Dec2( Kit_DsdNtk_t * pNtk0, Kit_DsdNtk_t * pNtk1 ) +{ + assert( pNtk0->nVars == 4 ); + assert( pNtk1->nVars == 4 ); + if ( Kit_DsdFindLargeBox(pNtk0, 2) ) + return 0; + if ( Kit_DsdFindLargeBox(pNtk1, 2) ) + return 0; + return Kit_DsdRootNodeHasCommonVars( Kit_DsdNtkRoot(pNtk0), Kit_DsdNtkRoot(pNtk1) ); +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdDecompose_rec( Kit_DsdNtk_t * pNtk, Kit_DsdObj_t * pObj, unsigned uSupp, unsigned char * pPar, int nDecMux ) +{ + Kit_DsdObj_t * pRes, * pRes0, * pRes1; + int nWords = Kit_TruthWordNum(pObj->nFans); + unsigned * pTruth = Kit_DsdObjTruth(pObj); + unsigned * pCofs2[2] = { pNtk->pMem, pNtk->pMem + nWords }; + unsigned * pCofs4[2][2] = { {pNtk->pMem + 2 * nWords, pNtk->pMem + 3 * nWords}, {pNtk->pMem + 4 * nWords, pNtk->pMem + 5 * nWords} }; + int i, iLit0, iLit1, nFans0, nFans1, nPairs; + int fEquals[2][2], fOppos, fPairs[4][4]; + unsigned j, k, nFansNew, uSupp0, uSupp1; + + assert( pObj->nFans > 0 ); + assert( pObj->Type == KIT_DSD_PRIME ); + assert( uSupp == (uSupp0 = (unsigned)Kit_TruthSupport(pTruth, pObj->nFans)) ); + + // compress the truth table + if ( uSupp != Kit_BitMask(pObj->nFans) ) + { + nFansNew = Kit_WordCountOnes(uSupp); + Kit_TruthShrink( pNtk->pMem, pTruth, nFansNew, pObj->nFans, uSupp, 1 ); + for ( j = k = 0; j < pObj->nFans; j++ ) + if ( uSupp & (1 << j) ) + pObj->pFans[k++] = pObj->pFans[j]; + assert( k == nFansNew ); + pObj->nFans = k; + uSupp = Kit_BitMask(pObj->nFans); + } + + // consider the single variable case + if ( pObj->nFans == 1 ) + { + pObj->Type = KIT_DSD_NONE; + if ( pTruth[0] == 0x55555555 ) + pObj->pFans[0] = Kit_DsdLitNot(pObj->pFans[0]); + else + assert( pTruth[0] == 0xAAAAAAAA ); + // update the parent pointer + *pPar = Kit_DsdLitNotCond( pObj->pFans[0], Kit_DsdLitIsCompl(*pPar) ); + return; + } + + // decompose the output + if ( !pObj->fMark ) + for ( i = pObj->nFans - 1; i >= 0; i-- ) + { + // get the two-variable cofactors + Kit_TruthCofactor0New( pCofs2[0], pTruth, pObj->nFans, i ); + Kit_TruthCofactor1New( pCofs2[1], pTruth, pObj->nFans, i ); +// assert( !Kit_TruthVarInSupport( pCofs2[0], pObj->nFans, i) ); +// assert( !Kit_TruthVarInSupport( pCofs2[1], pObj->nFans, i) ); + // get the constant cofs + fEquals[0][0] = Kit_TruthIsConst0( pCofs2[0], pObj->nFans ); + fEquals[0][1] = Kit_TruthIsConst0( pCofs2[1], pObj->nFans ); + fEquals[1][0] = Kit_TruthIsConst1( pCofs2[0], pObj->nFans ); + fEquals[1][1] = Kit_TruthIsConst1( pCofs2[1], pObj->nFans ); + fOppos = Kit_TruthIsOpposite( pCofs2[0], pCofs2[1], pObj->nFans ); + assert( !Kit_TruthIsEqual(pCofs2[0], pCofs2[1], pObj->nFans) ); + if ( fEquals[0][0] + fEquals[0][1] + fEquals[1][0] + fEquals[1][1] + fOppos == 0 ) + { + // check the MUX decomposition + uSupp0 = Kit_TruthSupport( pCofs2[0], pObj->nFans ); + uSupp1 = Kit_TruthSupport( pCofs2[1], pObj->nFans ); + assert( uSupp == (uSupp0 | uSupp1 | (1<nFans ); + pRes1 = Kit_DsdObjAlloc( pNtk, KIT_DSD_PRIME, pObj->nFans ); + for ( k = 0; k < pObj->nFans; k++ ) + { + pRes0->pFans[k] = (uSupp0 & (1 << k))? pObj->pFans[k] : 127; + pRes1->pFans[k] = (uSupp1 & (1 << k))? pObj->pFans[k] : 127; + } + Kit_TruthCopy( Kit_DsdObjTruth(pRes0), pCofs2[0], pObj->nFans ); + Kit_TruthCopy( Kit_DsdObjTruth(pRes1), pCofs2[1], pObj->nFans ); + // update the current one + assert( pObj->Type == KIT_DSD_PRIME ); + pTruth[0] = 0xCACACACA; + pObj->nFans = 3; + pObj->pFans[2] = pObj->pFans[i]; + pObj->pFans[0] = 2*pRes0->Id; pRes0->nRefs++; + pObj->pFans[1] = 2*pRes1->Id; pRes1->nRefs++; + // call recursively + Kit_DsdDecompose_rec( pNtk, pRes0, uSupp0, pObj->pFans + 0, nDecMux ); + Kit_DsdDecompose_rec( pNtk, pRes1, uSupp1, pObj->pFans + 1, nDecMux ); + return; + } + + // create the new node + pRes = Kit_DsdObjAlloc( pNtk, KIT_DSD_AND, 2 ); + pRes->nRefs++; + pRes->nFans = 2; + pRes->pFans[0] = pObj->pFans[i]; pObj->pFans[i] = 127; uSupp &= ~(1 << i); + pRes->pFans[1] = 2*pObj->Id; + // update the parent pointer + *pPar = Kit_DsdLitNotCond( 2 * pRes->Id, Kit_DsdLitIsCompl(*pPar) ); + // consider different decompositions + if ( fEquals[0][0] ) + { + Kit_TruthCopy( pTruth, pCofs2[1], pObj->nFans ); + } + else if ( fEquals[0][1] ) + { + pRes->pFans[0] = Kit_DsdLitNot(pRes->pFans[0]); + Kit_TruthCopy( pTruth, pCofs2[0], pObj->nFans ); + } + else if ( fEquals[1][0] ) + { + *pPar = Kit_DsdLitNot(*pPar); + pRes->pFans[1] = Kit_DsdLitNot(pRes->pFans[1]); + Kit_TruthCopy( pTruth, pCofs2[1], pObj->nFans ); + } + else if ( fEquals[1][1] ) + { + *pPar = Kit_DsdLitNot(*pPar); + pRes->pFans[0] = Kit_DsdLitNot(pRes->pFans[0]); + pRes->pFans[1] = Kit_DsdLitNot(pRes->pFans[1]); + Kit_TruthCopy( pTruth, pCofs2[0], pObj->nFans ); + } + else if ( fOppos ) + { + pRes->Type = KIT_DSD_XOR; + Kit_TruthCopy( pTruth, pCofs2[0], pObj->nFans ); + } + else + assert( 0 ); + // decompose the remainder + assert( Kit_DsdObjTruth(pObj) == pTruth ); + Kit_DsdDecompose_rec( pNtk, pObj, uSupp, pRes->pFans + 1, nDecMux ); + return; + } + pObj->fMark = 1; + + // decompose the input + for ( i = pObj->nFans - 1; i >= 0; i-- ) + { + assert( Kit_TruthVarInSupport( pTruth, pObj->nFans, i ) ); + // get the single variale cofactors + Kit_TruthCofactor0New( pCofs2[0], pTruth, pObj->nFans, i ); + Kit_TruthCofactor1New( pCofs2[1], pTruth, pObj->nFans, i ); + // check the existence of MUX decomposition + uSupp0 = Kit_TruthSupport( pCofs2[0], pObj->nFans ); + uSupp1 = Kit_TruthSupport( pCofs2[1], pObj->nFans ); + assert( uSupp == (uSupp0 | uSupp1 | (1<fMark = 0; + Kit_DsdDecompose_rec( pNtk, pObj, uSupp, pPar, nDecMux ); + return; + } + assert( uSupp0 && uSupp1 ); + // get the number of unique variables + nFans0 = Kit_WordCountOnes( uSupp0 & ~uSupp1 ); + nFans1 = Kit_WordCountOnes( uSupp1 & ~uSupp0 ); + if ( nFans0 == 1 && nFans1 == 1 ) + { + // get the cofactors w.r.t. the unique variables + iLit0 = Kit_WordFindFirstBit( uSupp0 & ~uSupp1 ); + iLit1 = Kit_WordFindFirstBit( uSupp1 & ~uSupp0 ); + // get four cofactors + Kit_TruthCofactor0New( pCofs4[0][0], pCofs2[0], pObj->nFans, iLit0 ); + Kit_TruthCofactor1New( pCofs4[0][1], pCofs2[0], pObj->nFans, iLit0 ); + Kit_TruthCofactor0New( pCofs4[1][0], pCofs2[1], pObj->nFans, iLit1 ); + Kit_TruthCofactor1New( pCofs4[1][1], pCofs2[1], pObj->nFans, iLit1 ); + // check existence conditions + fEquals[0][0] = Kit_TruthIsEqual( pCofs4[0][0], pCofs4[1][0], pObj->nFans ); + fEquals[0][1] = Kit_TruthIsEqual( pCofs4[0][1], pCofs4[1][1], pObj->nFans ); + fEquals[1][0] = Kit_TruthIsEqual( pCofs4[0][0], pCofs4[1][1], pObj->nFans ); + fEquals[1][1] = Kit_TruthIsEqual( pCofs4[0][1], pCofs4[1][0], pObj->nFans ); + if ( (fEquals[0][0] && fEquals[0][1]) || (fEquals[1][0] && fEquals[1][1]) ) + { + // construct the MUX + pRes = Kit_DsdObjAlloc( pNtk, KIT_DSD_PRIME, 3 ); + Kit_DsdObjTruth(pRes)[0] = 0xCACACACA; + pRes->nRefs++; + pRes->nFans = 3; + pRes->pFans[0] = pObj->pFans[iLit0]; pObj->pFans[iLit0] = 127; uSupp &= ~(1 << iLit0); + pRes->pFans[1] = pObj->pFans[iLit1]; pObj->pFans[iLit1] = 127; uSupp &= ~(1 << iLit1); + pRes->pFans[2] = pObj->pFans[i]; pObj->pFans[i] = 2 * pRes->Id; // remains in support + // update the node +// if ( fEquals[0][0] && fEquals[0][1] ) +// Kit_TruthMuxVar( pTruth, pCofs4[0][0], pCofs4[0][1], pObj->nFans, i ); +// else +// Kit_TruthMuxVar( pTruth, pCofs4[0][1], pCofs4[0][0], pObj->nFans, i ); + Kit_TruthMuxVar( pTruth, pCofs4[1][0], pCofs4[1][1], pObj->nFans, i ); + if ( fEquals[1][0] && fEquals[1][1] ) + pRes->pFans[0] = Kit_DsdLitNot(pRes->pFans[0]); + // decompose the remainder + Kit_DsdDecompose_rec( pNtk, pObj, uSupp, pPar, nDecMux ); + return; + } + } + + // try other inputs + for ( k = i+1; k < pObj->nFans; k++ ) + { + // get four cofactors ik + Kit_TruthCofactor0New( pCofs4[0][0], pCofs2[0], pObj->nFans, k ); // 00 + Kit_TruthCofactor1New( pCofs4[0][1], pCofs2[0], pObj->nFans, k ); // 01 + Kit_TruthCofactor0New( pCofs4[1][0], pCofs2[1], pObj->nFans, k ); // 10 + Kit_TruthCofactor1New( pCofs4[1][1], pCofs2[1], pObj->nFans, k ); // 11 + // compare equal pairs + fPairs[0][1] = fPairs[1][0] = Kit_TruthIsEqual( pCofs4[0][0], pCofs4[0][1], pObj->nFans ); + fPairs[0][2] = fPairs[2][0] = Kit_TruthIsEqual( pCofs4[0][0], pCofs4[1][0], pObj->nFans ); + fPairs[0][3] = fPairs[3][0] = Kit_TruthIsEqual( pCofs4[0][0], pCofs4[1][1], pObj->nFans ); + fPairs[1][2] = fPairs[2][1] = Kit_TruthIsEqual( pCofs4[0][1], pCofs4[1][0], pObj->nFans ); + fPairs[1][3] = fPairs[3][1] = Kit_TruthIsEqual( pCofs4[0][1], pCofs4[1][1], pObj->nFans ); + fPairs[2][3] = fPairs[3][2] = Kit_TruthIsEqual( pCofs4[1][0], pCofs4[1][1], pObj->nFans ); + nPairs = fPairs[0][1] + fPairs[0][2] + fPairs[0][3] + fPairs[1][2] + fPairs[1][3] + fPairs[2][3]; + if ( nPairs != 3 && nPairs != 2 ) + continue; + + // decomposition exists + pRes = Kit_DsdObjAlloc( pNtk, KIT_DSD_AND, 2 ); + pRes->nRefs++; + pRes->nFans = 2; + pRes->pFans[0] = pObj->pFans[k]; pObj->pFans[k] = 2 * pRes->Id; // remains in support + pRes->pFans[1] = pObj->pFans[i]; pObj->pFans[i] = 127; uSupp &= ~(1 << i); + if ( !fPairs[0][1] && !fPairs[0][2] && !fPairs[0][3] ) // 00 + { + pRes->pFans[0] = Kit_DsdLitNot(pRes->pFans[0]); + pRes->pFans[1] = Kit_DsdLitNot(pRes->pFans[1]); + Kit_TruthMuxVar( pTruth, pCofs4[1][1], pCofs4[0][0], pObj->nFans, k ); + } + else if ( !fPairs[1][0] && !fPairs[1][2] && !fPairs[1][3] ) // 01 + { + pRes->pFans[1] = Kit_DsdLitNot(pRes->pFans[1]); + Kit_TruthMuxVar( pTruth, pCofs4[0][0], pCofs4[0][1], pObj->nFans, k ); + } + else if ( !fPairs[2][0] && !fPairs[2][1] && !fPairs[2][3] ) // 10 + { + pRes->pFans[0] = Kit_DsdLitNot(pRes->pFans[0]); + Kit_TruthMuxVar( pTruth, pCofs4[0][0], pCofs4[1][0], pObj->nFans, k ); + } + else if ( !fPairs[3][0] && !fPairs[3][1] && !fPairs[3][2] ) // 11 + { +// unsigned uSupp0 = Kit_TruthSupport(pCofs4[0][0], pObj->nFans); +// unsigned uSupp1 = Kit_TruthSupport(pCofs4[1][1], pObj->nFans); +// unsigned uSupp; +// Extra_PrintBinary( stdout, &uSupp0, pObj->nFans ); printf( "\n" ); +// Extra_PrintBinary( stdout, &uSupp1, pObj->nFans ); printf( "\n" ); + Kit_TruthMuxVar( pTruth, pCofs4[0][0], pCofs4[1][1], pObj->nFans, k ); +// uSupp = Kit_TruthSupport(pTruth, pObj->nFans); +// Extra_PrintBinary( stdout, &uSupp, pObj->nFans ); printf( "\n" ); printf( "\n" ); + } + else + { + assert( fPairs[0][3] && fPairs[1][2] ); + pRes->Type = KIT_DSD_XOR;; + Kit_TruthMuxVar( pTruth, pCofs4[0][0], pCofs4[0][1], pObj->nFans, k ); + } + // decompose the remainder + Kit_DsdDecompose_rec( pNtk, pObj, uSupp, pPar, nDecMux ); + return; + } + } +/* + // if all decomposition methods failed and we are still above the limit, perform MUX-decomposition + if ( nDecMux > 0 && (int)pObj->nFans > nDecMux ) + { + int iBestVar = Kit_TruthBestCofVar( pTruth, pObj->nFans, pCofs2[0], pCofs2[1] ); + uSupp0 = Kit_TruthSupport( pCofs2[0], pObj->nFans ); + uSupp1 = Kit_TruthSupport( pCofs2[1], pObj->nFans ); + // perform MUX decomposition + pRes0 = Kit_DsdObjAlloc( pNtk, KIT_DSD_PRIME, pObj->nFans ); + pRes1 = Kit_DsdObjAlloc( pNtk, KIT_DSD_PRIME, pObj->nFans ); + for ( k = 0; k < pObj->nFans; k++ ) + pRes0->pFans[k] = pRes1->pFans[k] = pObj->pFans[k]; + Kit_TruthCopy( Kit_DsdObjTruth(pRes0), pCofs2[0], pObj->nFans ); + Kit_TruthCopy( Kit_DsdObjTruth(pRes1), pCofs2[1], pObj->nFans ); + // update the current one + assert( pObj->Type == KIT_DSD_PRIME ); + pTruth[0] = 0xCACACACA; + pObj->nFans = 3; + pObj->pFans[0] = 2*pRes0->Id; pRes0->nRefs++; + pObj->pFans[1] = 2*pRes1->Id; pRes1->nRefs++; + pObj->pFans[2] = pObj->pFans[iBestVar]; + // call recursively + Kit_DsdDecompose_rec( pNtk, pRes0, uSupp0, pObj->pFans + 0, nDecMux ); + Kit_DsdDecompose_rec( pNtk, pRes1, uSupp1, pObj->pFans + 1, nDecMux ); + } +*/ +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdDecomposeInt( unsigned * pTruth, int nVars, int nDecMux ) +{ + Kit_DsdNtk_t * pNtk; + Kit_DsdObj_t * pObj; + unsigned uSupp; + int i, nVarsReal; + assert( nVars <= 16 ); + pNtk = Kit_DsdNtkAlloc( nVars ); + pNtk->Root = Kit_DsdVar2Lit( pNtk->nVars, 0 ); + // create the first node + pObj = Kit_DsdObjAlloc( pNtk, KIT_DSD_PRIME, nVars ); + assert( pNtk->pNodes[0] == pObj ); + for ( i = 0; i < nVars; i++ ) + pObj->pFans[i] = Kit_DsdVar2Lit( i, 0 ); + Kit_TruthCopy( Kit_DsdObjTruth(pObj), pTruth, nVars ); + uSupp = Kit_TruthSupport( pTruth, nVars ); + // consider special cases + nVarsReal = Kit_WordCountOnes( uSupp ); + if ( nVarsReal == 0 ) + { + pObj->Type = KIT_DSD_CONST1; + pObj->nFans = 0; + if ( pTruth[0] == 0 ) + pNtk->Root = Kit_DsdLitNot(pNtk->Root); + return pNtk; + } + if ( nVarsReal == 1 ) + { + pObj->Type = KIT_DSD_VAR; + pObj->nFans = 1; + pObj->pFans[0] = Kit_DsdVar2Lit( Kit_WordFindFirstBit(uSupp), (pTruth[0] & 1) ); + return pNtk; + } + Kit_DsdDecompose_rec( pNtk, pNtk->pNodes[0], uSupp, &pNtk->Root, nDecMux ); + return pNtk; +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars ) +{ + return Kit_DsdDecomposeInt( pTruth, nVars, 0 ); +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [Uses MUXes to break-down large prime nodes.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_DsdNtk_t * Kit_DsdDecomposeMux( unsigned * pTruth, int nVars, int nDecMux ) +{ + return Kit_DsdDecomposeInt( pTruth, nVars, nDecMux ); +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdTestCofs( Kit_DsdNtk_t * pNtk, unsigned * pTruthInit ) +{ + Kit_DsdNtk_t * pNtk0, * pNtk1, * pTemp; +// Kit_DsdObj_t * pRoot; + unsigned * pCofs2[2] = { pNtk->pMem, pNtk->pMem + Kit_TruthWordNum(pNtk->nVars) }; + unsigned i, * pTruth; + int fVerbose = 1; + int RetValue = 0; + + pTruth = pTruthInit; +// pRoot = Kit_DsdNtkRoot(pNtk); +// pTruth = Kit_DsdObjTruth(pRoot); +// assert( pRoot->nFans == pNtk->nVars ); + + if ( fVerbose ) + { + printf( "Function: " ); +// Extra_PrintBinary( stdout, pTruth, (1 << pNtk->nVars) ); + Extra_PrintHexadecimal( stdout, pTruth, pNtk->nVars ); + printf( "\n" ); + Kit_DsdPrint( stdout, pNtk ); + } + for ( i = 0; i < pNtk->nVars; i++ ) + { + Kit_TruthCofactor0New( pCofs2[0], pTruth, pNtk->nVars, i ); + pNtk0 = Kit_DsdDecompose( pCofs2[0], pNtk->nVars ); + pNtk0 = Kit_DsdExpand( pTemp = pNtk0 ); + Kit_DsdNtkFree( pTemp ); + + if ( fVerbose ) + { + printf( "Cof%d0: ", i ); + Kit_DsdPrint( stdout, pNtk0 ); + } + + Kit_TruthCofactor1New( pCofs2[1], pTruth, pNtk->nVars, i ); + pNtk1 = Kit_DsdDecompose( pCofs2[1], pNtk->nVars ); + pNtk1 = Kit_DsdExpand( pTemp = pNtk1 ); + Kit_DsdNtkFree( pTemp ); + + if ( fVerbose ) + { + printf( "Cof%d1: ", i ); + Kit_DsdPrint( stdout, pNtk1 ); + } + +// if ( Kit_DsdCheckVar4Dec2( pNtk0, pNtk1 ) ) +// RetValue = 1; + + Kit_DsdNtkFree( pNtk0 ); + Kit_DsdNtkFree( pNtk1 ); + } + if ( fVerbose ) + printf( "\n" ); + + return RetValue; +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdEval( unsigned * pTruth, int nVars, int nLutSize ) +{ + Kit_DsdMan_t * p; + Kit_DsdNtk_t * pNtk; + unsigned * pTruthC; + int Result; + + // decompose the function + pNtk = Kit_DsdDecompose( pTruth, nVars ); + Result = Kit_DsdCountLuts( pNtk, nLutSize ); +// printf( "\n" ); +// Kit_DsdPrint( stdout, pNtk ); +// printf( "Eval = %d.\n", Result ); + + // recompute the truth table + p = Kit_DsdManAlloc( nVars ); + pTruthC = Kit_DsdTruthCompute( p, pNtk, 0 ); + if ( !Extra_TruthIsEqual( pTruth, pTruthC, nVars ) ) + printf( "Verification failed.\n" ); + Kit_DsdManFree( p ); + + Kit_DsdNtkFree( pNtk ); + return Result; +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdVerify( Kit_DsdNtk_t * pNtk, unsigned * pTruth, int nVars ) +{ + Kit_DsdMan_t * p; + unsigned * pTruthC; + p = Kit_DsdManAlloc( nVars ); + pTruthC = Kit_DsdTruthCompute( p, pNtk, 0 ); + if ( !Extra_TruthIsEqual( pTruth, pTruthC, nVars ) ) + printf( "Verification failed.\n" ); + Kit_DsdManFree( p ); +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdTest( unsigned * pTruth, int nVars ) +{ + Kit_DsdMan_t * p; + unsigned * pTruthC; + Kit_DsdNtk_t * pNtk, * pTemp; + pNtk = Kit_DsdDecompose( pTruth, nVars ); + +// if ( Kit_DsdFindLargeBox(pNtk, Kit_DsdLit2Var(pNtk->Root)) ) +// Kit_DsdPrint( stdout, pNtk ); + +// if ( Kit_DsdNtkRoot(pNtk)->nFans == (unsigned)nVars && nVars == 6 ) + + printf( "\n" ); + Kit_DsdPrint( stdout, pNtk ); + + pNtk = Kit_DsdExpand( pTemp = pNtk ); + Kit_DsdNtkFree( pTemp ); + + Kit_DsdPrint( stdout, pNtk ); + +// if ( Kit_DsdFindLargeBox(pNtk, Kit_DsdLit2Var(pNtk->Root)) ) +// Kit_DsdTestCofs( pNtk, pTruth ); + + // recompute the truth table + p = Kit_DsdManAlloc( nVars ); + pTruthC = Kit_DsdTruthCompute( p, pNtk, 0 ); +// Extra_PrintBinary( stdout, pTruth, 1 << nVars ); printf( "\n" ); +// Extra_PrintBinary( stdout, pTruthC, 1 << nVars ); printf( "\n" ); + if ( Extra_TruthIsEqual( pTruth, pTruthC, nVars ) ) + { +// printf( "Verification is okay.\n" ); + } + else + printf( "Verification failed.\n" ); + Kit_DsdManFree( p ); + + + Kit_DsdNtkFree( pNtk ); +} + +/**Function************************************************************* + + Synopsis [Performs decomposition of the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrecompute4Vars() +{ + Kit_DsdMan_t * p; + Kit_DsdNtk_t * pNtk, * pTemp; + FILE * pFile; + unsigned uTruth; + unsigned * pTruthC; + char Buffer[256]; + int i, RetValue; + int Counter1 = 0, Counter2 = 0; + + pFile = fopen( "5npn/npn4.txt", "r" ); + for ( i = 0; fgets( Buffer, 100, pFile ); i++ ) + { + Buffer[6] = 0; + Extra_ReadHexadecimal( &uTruth, Buffer+2, 4 ); + uTruth = ((uTruth & 0xffff) << 16) | (uTruth & 0xffff); + pNtk = Kit_DsdDecompose( &uTruth, 4 ); + + pNtk = Kit_DsdExpand( pTemp = pNtk ); + Kit_DsdNtkFree( pTemp ); + + + if ( Kit_DsdFindLargeBox(pNtk, 3) ) + { +// RetValue = 0; + RetValue = Kit_DsdTestCofs( pNtk, &uTruth ); + printf( "\n" ); + printf( "%3d : Non-DSD function %s %s\n", i, Buffer + 2, RetValue? "implementable" : "" ); + Kit_DsdPrint( stdout, pNtk ); + + Counter1++; + Counter2 += RetValue; + } + +/* + printf( "%3d : Function %s ", i, Buffer + 2 ); + if ( !Kit_DsdFindLargeBox(pNtk, 3) ) + Kit_DsdPrint( stdout, pNtk ); + else + printf( "\n" ); +*/ + + p = Kit_DsdManAlloc( 4 ); + pTruthC = Kit_DsdTruthCompute( p, pNtk, 0 ); + if ( !Extra_TruthIsEqual( &uTruth, pTruthC, 4 ) ) + printf( "Verification failed.\n" ); + Kit_DsdManFree( p ); + + Kit_DsdNtkFree( pNtk ); + } + fclose( pFile ); + printf( "non-DSD = %d implementable = %d\n", Counter1, Counter2 ); +} + + +/**Function************************************************************* + + Synopsis [Returns the set of cofactoring variables.] + + Description [If there is no DSD components returns 0.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdCofactoringGetVars( Kit_DsdNtk_t ** ppNtk, int nSize, int * pVars ) +{ + Kit_DsdObj_t * pObj; + unsigned m; + int i, k, v, Var, nVars, iFaninLit; + // go through all the networks + nVars = 0; + for ( i = 0; i < nSize; i++ ) + { + // go through the prime objects of each networks + Kit_DsdNtkForEachObj( ppNtk[i], pObj, k ) + { + if ( pObj->Type != KIT_DSD_PRIME ) + continue; + if ( pObj->nFans == 3 ) + continue; + // collect direct fanin variables + Kit_DsdObjForEachFanin( ppNtk[i], pObj, iFaninLit, m ) + { + if ( !Kit_DsdLitIsLeaf(ppNtk[i], iFaninLit) ) + continue; + // add it to the array + Var = Kit_DsdLit2Var( iFaninLit ); + for ( v = 0; v < nVars; v++ ) + if ( pVars[v] == Var ) + break; + if ( v == nVars ) + pVars[nVars++] = Var; + } + } + } + return nVars; +} + +/**Function************************************************************* + + Synopsis [Canonical decomposition into completely DSD-structure.] + + Description [Returns the number of cofactoring steps. Also returns + the cofactoring variables in pVars.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_DsdCofactoring( unsigned * pTruth, int nVars, int * pCofVars, int nLimit, int fVerbose ) +{ + Kit_DsdNtk_t * ppNtks[5][16] = {0}, * pTemp; + unsigned * ppCofs[5][16]; + int pTryVars[16], nTryVars; + int nPrimeSizeMin, nPrimeSizeMax, nPrimeSizeCur; + int nSuppSizeMin, nSuppSizeMax, iVarBest; + int i, k, v, nStep, nSize, nMemSize; + assert( nLimit < 5 ); + + // allocate storage for cofactors + nMemSize = Kit_TruthWordNum(nVars); + ppCofs[0][0] = ALLOC( unsigned, 80 * nMemSize ); + nSize = 0; + for ( i = 0; i < 5; i++ ) + for ( k = 0; k < 16; k++ ) + ppCofs[i][k] = ppCofs[0][0] + nMemSize * nSize++; + assert( nSize == 80 ); + + // copy the function + Kit_TruthCopy( ppCofs[0][0], pTruth, nVars ); + ppNtks[0][0] = Kit_DsdDecompose( ppCofs[0][0], nVars ); + + if ( fVerbose ) + printf( "\nProcessing prime function with %d support variables:\n", nVars ); + + // perform recursive cofactoring + for ( nStep = 0; nStep < nLimit; nStep++ ) + { + nSize = (1 << nStep); + // find the variables to use in the cofactoring step + nTryVars = Kit_DsdCofactoringGetVars( ppNtks[nStep], nSize, pTryVars ); + if ( nTryVars == 0 ) + break; + // cofactor w.r.t. the above variables + iVarBest = -1; + nPrimeSizeMin = 10000; + nSuppSizeMin = 10000; + for ( v = 0; v < nTryVars; v++ ) + { + nPrimeSizeMax = 0; + nSuppSizeMax = 0; + for ( i = 0; i < nSize; i++ ) + { + // cofactor and decompose cofactors + Kit_TruthCofactor0New( ppCofs[nStep+1][2*i+0], ppCofs[nStep][i], nVars, pTryVars[v] ); + Kit_TruthCofactor1New( ppCofs[nStep+1][2*i+1], ppCofs[nStep][i], nVars, pTryVars[v] ); + ppNtks[nStep+1][2*i+0] = Kit_DsdDecompose( ppCofs[nStep+1][2*i+0], nVars ); + ppNtks[nStep+1][2*i+1] = Kit_DsdDecompose( ppCofs[nStep+1][2*i+1], nVars ); + // compute the largest non-decomp block + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[nStep+1][2*i+0]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[nStep+1][2*i+1]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + // compute the sum total of supports + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nStep+1][2*i+0], nVars ); + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nStep+1][2*i+1], nVars ); + // free the networks + Kit_DsdNtkFree( ppNtks[nStep+1][2*i+0] ); + Kit_DsdNtkFree( ppNtks[nStep+1][2*i+1] ); + } + // find the min max support size of the prime component + if ( nPrimeSizeMin > nPrimeSizeMax || (nPrimeSizeMin == nPrimeSizeMax && nSuppSizeMin > nSuppSizeMax) ) + { + nPrimeSizeMin = nPrimeSizeMax; + nSuppSizeMin = nSuppSizeMax; + iVarBest = pTryVars[v]; + } + } + assert( iVarBest != -1 ); + // save the variable + if ( pCofVars ) + pCofVars[nStep] = iVarBest; + // cofactor w.r.t. the best + for ( i = 0; i < nSize; i++ ) + { + Kit_TruthCofactor0New( ppCofs[nStep+1][2*i+0], ppCofs[nStep][i], nVars, iVarBest ); + Kit_TruthCofactor1New( ppCofs[nStep+1][2*i+1], ppCofs[nStep][i], nVars, iVarBest ); + ppNtks[nStep+1][2*i+0] = Kit_DsdDecompose( ppCofs[nStep+1][2*i+0], nVars ); + ppNtks[nStep+1][2*i+1] = Kit_DsdDecompose( ppCofs[nStep+1][2*i+1], nVars ); + if ( fVerbose ) + { + ppNtks[nStep+1][2*i+0] = Kit_DsdExpand( pTemp = ppNtks[nStep+1][2*i+0] ); + Kit_DsdNtkFree( pTemp ); + ppNtks[nStep+1][2*i+1] = Kit_DsdExpand( pTemp = ppNtks[nStep+1][2*i+1] ); + Kit_DsdNtkFree( pTemp ); + + printf( "Cof%d%d: ", nStep+1, 2*i+0 ); + Kit_DsdPrint( stdout, ppNtks[nStep+1][2*i+0] ); + printf( "Cof%d%d: ", nStep+1, 2*i+1 ); + Kit_DsdPrint( stdout, ppNtks[nStep+1][2*i+1] ); + } + } + } + + // free the networks + for ( i = 0; i < 5; i++ ) + for ( k = 0; k < 16; k++ ) + if ( ppNtks[i][k] ) + Kit_DsdNtkFree( ppNtks[i][k] ); + free( ppCofs[0][0] ); + + assert( nStep <= nLimit ); + return nStep; +} + +/**Function************************************************************* + + Synopsis [Canonical decomposition into completely DSD-structure.] + + Description [Returns the number of cofactoring steps. Also returns + the cofactoring variables in pVars.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_DsdPrintCofactors( unsigned * pTruth, int nVars, int nCofLevel, int fVerbose ) +{ + Kit_DsdNtk_t * ppNtks[32] = {0}, * pTemp; + unsigned * ppCofs[5][16]; + int piCofVar[5]; + int nPrimeSizeMax, nPrimeSizeCur, nSuppSizeMax; + int i, k, v1, v2, v3, v4, s, nSteps, nSize, nMemSize; + assert( nCofLevel < 5 ); + + // print the function + ppNtks[0] = Kit_DsdDecompose( pTruth, nVars ); + ppNtks[0] = Kit_DsdExpand( pTemp = ppNtks[0] ); + Kit_DsdNtkFree( pTemp ); + if ( fVerbose ) + Kit_DsdPrint( stdout, ppNtks[0] ); + Kit_DsdNtkFree( ppNtks[0] ); + + // allocate storage for cofactors + nMemSize = Kit_TruthWordNum(nVars); + ppCofs[0][0] = ALLOC( unsigned, 80 * nMemSize ); + nSize = 0; + for ( i = 0; i < 5; i++ ) + for ( k = 0; k < 16; k++ ) + ppCofs[i][k] = ppCofs[0][0] + nMemSize * nSize++; + assert( nSize == 80 ); + + // copy the function + Kit_TruthCopy( ppCofs[0][0], pTruth, nVars ); + + if ( nCofLevel == 1 ) + for ( v1 = 0; v1 < nVars; v1++ ) + { + nSteps = 0; + piCofVar[nSteps++] = v1; + + printf( " Variables { " ); + for ( i = 0; i < nSteps; i++ ) + printf( "%c ", 'a' + piCofVar[i] ); + printf( "}\n" ); + + // single cofactors + for ( s = 1; s <= nSteps; s++ ) + { + for ( k = 0; k < s; k++ ) + { + nSize = (1 << k); + for ( i = 0; i < nSize; i++ ) + { + Kit_TruthCofactor0New( ppCofs[k+1][2*i+0], ppCofs[k][i], nVars, piCofVar[k] ); + Kit_TruthCofactor1New( ppCofs[k+1][2*i+1], ppCofs[k][i], nVars, piCofVar[k] ); + } + } + } + // compute DSD networks + nSize = (1 << nSteps); + nPrimeSizeMax = 0; + nSuppSizeMax = 0; + for ( i = 0; i < nSize; i++ ) + { + ppNtks[i] = Kit_DsdDecompose( ppCofs[nSteps][i], nVars ); + ppNtks[i] = Kit_DsdExpand( pTemp = ppNtks[i] ); + Kit_DsdNtkFree( pTemp ); + if ( fVerbose ) + { + printf( "Cof%d%d: ", nSteps, i ); + Kit_DsdPrint( stdout, ppNtks[i] ); + } + // compute the largest non-decomp block + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[i]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + Kit_DsdNtkFree( ppNtks[i] ); + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nSteps][i], nVars ); + } + printf( "Max = %2d. Supps = %2d.\n", nPrimeSizeMax, nSuppSizeMax ); + } + + if ( nCofLevel == 2 ) + for ( v1 = 0; v1 < nVars; v1++ ) + for ( v2 = v1+1; v2 < nVars; v2++ ) + { + nSteps = 0; + piCofVar[nSteps++] = v1; + piCofVar[nSteps++] = v2; + + printf( " Variables { " ); + for ( i = 0; i < nSteps; i++ ) + printf( "%c ", 'a' + piCofVar[i] ); + printf( "}\n" ); + + // single cofactors + for ( s = 1; s <= nSteps; s++ ) + { + for ( k = 0; k < s; k++ ) + { + nSize = (1 << k); + for ( i = 0; i < nSize; i++ ) + { + Kit_TruthCofactor0New( ppCofs[k+1][2*i+0], ppCofs[k][i], nVars, piCofVar[k] ); + Kit_TruthCofactor1New( ppCofs[k+1][2*i+1], ppCofs[k][i], nVars, piCofVar[k] ); + } + } + } + // compute DSD networks + nSize = (1 << nSteps); + nPrimeSizeMax = 0; + nSuppSizeMax = 0; + for ( i = 0; i < nSize; i++ ) + { + ppNtks[i] = Kit_DsdDecompose( ppCofs[nSteps][i], nVars ); + ppNtks[i] = Kit_DsdExpand( pTemp = ppNtks[i] ); + Kit_DsdNtkFree( pTemp ); + if ( fVerbose ) + { + printf( "Cof%d%d: ", nSteps, i ); + Kit_DsdPrint( stdout, ppNtks[i] ); + } + // compute the largest non-decomp block + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[i]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + Kit_DsdNtkFree( ppNtks[i] ); + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nSteps][i], nVars ); + } + printf( "Max = %2d. Supps = %2d.\n", nPrimeSizeMax, nSuppSizeMax ); + } + + if ( nCofLevel == 3 ) + for ( v1 = 0; v1 < nVars; v1++ ) + for ( v2 = v1+1; v2 < nVars; v2++ ) + for ( v3 = v2+1; v3 < nVars; v3++ ) + { + nSteps = 0; + piCofVar[nSteps++] = v1; + piCofVar[nSteps++] = v2; + piCofVar[nSteps++] = v3; + + printf( " Variables { " ); + for ( i = 0; i < nSteps; i++ ) + printf( "%c ", 'a' + piCofVar[i] ); + printf( "}\n" ); + + // single cofactors + for ( s = 1; s <= nSteps; s++ ) + { + for ( k = 0; k < s; k++ ) + { + nSize = (1 << k); + for ( i = 0; i < nSize; i++ ) + { + Kit_TruthCofactor0New( ppCofs[k+1][2*i+0], ppCofs[k][i], nVars, piCofVar[k] ); + Kit_TruthCofactor1New( ppCofs[k+1][2*i+1], ppCofs[k][i], nVars, piCofVar[k] ); + } + } + } + // compute DSD networks + nSize = (1 << nSteps); + nPrimeSizeMax = 0; + nSuppSizeMax = 0; + for ( i = 0; i < nSize; i++ ) + { + ppNtks[i] = Kit_DsdDecompose( ppCofs[nSteps][i], nVars ); + ppNtks[i] = Kit_DsdExpand( pTemp = ppNtks[i] ); + Kit_DsdNtkFree( pTemp ); + if ( fVerbose ) + { + printf( "Cof%d%d: ", nSteps, i ); + Kit_DsdPrint( stdout, ppNtks[i] ); + } + // compute the largest non-decomp block + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[i]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + Kit_DsdNtkFree( ppNtks[i] ); + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nSteps][i], nVars ); + } + printf( "Max = %2d. Supps = %2d.\n", nPrimeSizeMax, nSuppSizeMax ); + } + + if ( nCofLevel == 4 ) + for ( v1 = 0; v1 < nVars; v1++ ) + for ( v2 = v1+1; v2 < nVars; v2++ ) + for ( v3 = v2+1; v3 < nVars; v3++ ) + for ( v4 = v3+1; v4 < nVars; v4++ ) + { + nSteps = 0; + piCofVar[nSteps++] = v1; + piCofVar[nSteps++] = v2; + piCofVar[nSteps++] = v3; + piCofVar[nSteps++] = v4; + + printf( " Variables { " ); + for ( i = 0; i < nSteps; i++ ) + printf( "%c ", 'a' + piCofVar[i] ); + printf( "}\n" ); + + // single cofactors + for ( s = 1; s <= nSteps; s++ ) + { + for ( k = 0; k < s; k++ ) + { + nSize = (1 << k); + for ( i = 0; i < nSize; i++ ) + { + Kit_TruthCofactor0New( ppCofs[k+1][2*i+0], ppCofs[k][i], nVars, piCofVar[k] ); + Kit_TruthCofactor1New( ppCofs[k+1][2*i+1], ppCofs[k][i], nVars, piCofVar[k] ); + } + } + } + // compute DSD networks + nSize = (1 << nSteps); + nPrimeSizeMax = 0; + nSuppSizeMax = 0; + for ( i = 0; i < nSize; i++ ) + { + ppNtks[i] = Kit_DsdDecompose( ppCofs[nSteps][i], nVars ); + ppNtks[i] = Kit_DsdExpand( pTemp = ppNtks[i] ); + Kit_DsdNtkFree( pTemp ); + if ( fVerbose ) + { + printf( "Cof%d%d: ", nSteps, i ); + Kit_DsdPrint( stdout, ppNtks[i] ); + } + // compute the largest non-decomp block + nPrimeSizeCur = Kit_DsdNonDsdSizeMax(ppNtks[i]); + nPrimeSizeMax = KIT_MAX( nPrimeSizeMax, nPrimeSizeCur ); + Kit_DsdNtkFree( ppNtks[i] ); + nSuppSizeMax += Kit_TruthSupportSize( ppCofs[nSteps][i], nVars ); + } + printf( "Max = %2d. Supps = %2d.\n", nPrimeSizeMax, nSuppSizeMax ); + } + + + free( ppCofs[0][0] ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitFactor.c b/src/aig/kit/kitFactor.c new file mode 100644 index 00000000..4ef3fd94 --- /dev/null +++ b/src/aig/kit/kitFactor.c @@ -0,0 +1,338 @@ +/**CFile**************************************************************** + + FileName [kitFactor.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Algebraic factoring.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitFactor.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +// factoring fails if intermediate memory usage exceed this limit +#define KIT_FACTOR_MEM_LIMIT (1<<16) + +static Kit_Edge_t Kit_SopFactor_rec( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, int nLits, Vec_Int_t * vMemory ); +static Kit_Edge_t Kit_SopFactorLF_rec( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, Kit_Sop_t * cSimple, int nLits, Vec_Int_t * vMemory ); +static Kit_Edge_t Kit_SopFactorTrivial( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, int nLits ); +static Kit_Edge_t Kit_SopFactorTrivialCube( Kit_Graph_t * pFForm, unsigned uCube, int nLits ); + +extern int Kit_SopFactorVerify( Vec_Int_t * cSop, Kit_Graph_t * pFForm, int nVars ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Factors the cover.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_SopFactor( Vec_Int_t * vCover, int fCompl, int nVars, Vec_Int_t * vMemory ) +{ + Kit_Sop_t Sop, Res; + Kit_Sop_t * cSop = &Sop, * cRes = &Res; + Kit_Graph_t * pFForm; + Kit_Edge_t eRoot; + int nCubes = Vec_IntSize(vCover); + + // works for up to 15 variables because divisin procedure + // used the last bit for marking the cubes going to the remainder + assert( nVars < 16 ); + + // check for trivial functions + if ( Vec_IntSize(vCover) == 0 ) + return Kit_GraphCreateConst0(); + if ( Vec_IntSize(vCover) == 1 && Vec_IntEntry(vCover, 0) == 0 ) //(int)Kit_CubeMask(2 * nVars) ) + return Kit_GraphCreateConst1(); + + // prepare memory manager +// Vec_IntClear( vMemory ); + Vec_IntGrow( vMemory, KIT_FACTOR_MEM_LIMIT ); + + // perform CST + Kit_SopCreateInverse( cSop, vCover, 2 * nVars, vMemory ); // CST + + // start the factored form + pFForm = Kit_GraphCreate( nVars ); + // factor the cover + eRoot = Kit_SopFactor_rec( pFForm, cSop, 2 * nVars, vMemory ); + // finalize the factored form + Kit_GraphSetRoot( pFForm, eRoot ); + if ( fCompl ) + Kit_GraphComplement( pFForm ); + + // verify the factored form +// Vec_IntShrink( vCover, nCubes ); +// if ( !Kit_SopFactorVerify( vCover, pFForm, nVars ) ) +// printf( "Verification has failed.\n" ); + return pFForm; +} + +/**Function************************************************************* + + Synopsis [Recursive factoring procedure.] + + Description [For the pseudo-code, see Hachtel/Somenzi, + Logic synthesis and verification algorithms, Kluwer, 1996, p. 432.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactor_rec( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, int nLits, Vec_Int_t * vMemory ) +{ + Kit_Sop_t Div, Quo, Rem, Com; + Kit_Sop_t * cDiv = &Div, * cQuo = &Quo, * cRem = &Rem, * cCom = &Com; + Kit_Edge_t eNodeDiv, eNodeQuo, eNodeRem, eNodeAnd; + + // make sure the cover contains some cubes + assert( Kit_SopCubeNum(cSop) > 0 ); + + // get the divisor + if ( !Kit_SopDivisor(cDiv, cSop, nLits, vMemory) ) + return Kit_SopFactorTrivial( pFForm, cSop, nLits ); + + // divide the cover by the divisor + Kit_SopDivideInternal( cSop, cDiv, cQuo, cRem, vMemory ); + + // check the trivial case + assert( Kit_SopCubeNum(cQuo) > 0 ); + if ( Kit_SopCubeNum(cQuo) == 1 ) + return Kit_SopFactorLF_rec( pFForm, cSop, cQuo, nLits, vMemory ); + + // make the quotient cube free + Kit_SopMakeCubeFree( cQuo ); + + // divide the cover by the quotient + Kit_SopDivideInternal( cSop, cQuo, cDiv, cRem, vMemory ); + + // check the trivial case + if ( Kit_SopIsCubeFree( cDiv ) ) + { + eNodeDiv = Kit_SopFactor_rec( pFForm, cDiv, nLits, vMemory ); + eNodeQuo = Kit_SopFactor_rec( pFForm, cQuo, nLits, vMemory ); + eNodeAnd = Kit_GraphAddNodeAnd( pFForm, eNodeDiv, eNodeQuo ); + if ( Kit_SopCubeNum(cRem) == 0 ) + return eNodeAnd; + eNodeRem = Kit_SopFactor_rec( pFForm, cRem, nLits, vMemory ); + return Kit_GraphAddNodeOr( pFForm, eNodeAnd, eNodeRem ); + } + + // get the common cube + Kit_SopCommonCubeCover( cCom, cDiv, vMemory ); + + // solve the simple problem + return Kit_SopFactorLF_rec( pFForm, cSop, cCom, nLits, vMemory ); +} + + +/**Function************************************************************* + + Synopsis [Internal recursive factoring procedure for the leaf case.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactorLF_rec( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, Kit_Sop_t * cSimple, int nLits, Vec_Int_t * vMemory ) +{ + Kit_Sop_t Div, Quo, Rem; + Kit_Sop_t * cDiv = &Div, * cQuo = &Quo, * cRem = &Rem; + Kit_Edge_t eNodeDiv, eNodeQuo, eNodeRem, eNodeAnd; + assert( Kit_SopCubeNum(cSimple) == 1 ); + // get the most often occurring literal + Kit_SopBestLiteralCover( cDiv, cSop, Kit_SopCube(cSimple, 0), nLits, vMemory ); + // divide the cover by the literal + Kit_SopDivideByCube( cSop, cDiv, cQuo, cRem, vMemory ); + // get the node pointer for the literal + eNodeDiv = Kit_SopFactorTrivialCube( pFForm, Kit_SopCube(cDiv, 0), nLits ); + // factor the quotient and remainder + eNodeQuo = Kit_SopFactor_rec( pFForm, cQuo, nLits, vMemory ); + eNodeAnd = Kit_GraphAddNodeAnd( pFForm, eNodeDiv, eNodeQuo ); + if ( Kit_SopCubeNum(cRem) == 0 ) + return eNodeAnd; + eNodeRem = Kit_SopFactor_rec( pFForm, cRem, nLits, vMemory ); + return Kit_GraphAddNodeOr( pFForm, eNodeAnd, eNodeRem ); +} + + +/**Function************************************************************* + + Synopsis [Factoring cube.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactorTrivialCube_rec( Kit_Graph_t * pFForm, unsigned uCube, int nStart, int nFinish ) +{ + Kit_Edge_t eNode1, eNode2; + int i, iLit, nLits, nLits1, nLits2; + assert( uCube ); + // count the number of literals in this interval + nLits = 0; + for ( i = nStart; i < nFinish; i++ ) + if ( Kit_CubeHasLit(uCube, i) ) + { + iLit = i; + nLits++; + } + // quit if there is only one literal + if ( nLits == 1 ) + return Kit_EdgeCreate( iLit/2, iLit%2 ); // CST + // split the literals into two parts + nLits1 = nLits/2; + nLits2 = nLits - nLits1; +// nLits2 = nLits/2; +// nLits1 = nLits - nLits2; + // find the splitting point + nLits = 0; + for ( i = nStart; i < nFinish; i++ ) + if ( Kit_CubeHasLit(uCube, i) ) + { + if ( nLits == nLits1 ) + break; + nLits++; + } + // recursively construct the tree for the parts + eNode1 = Kit_SopFactorTrivialCube_rec( pFForm, uCube, nStart, i ); + eNode2 = Kit_SopFactorTrivialCube_rec( pFForm, uCube, i, nFinish ); + return Kit_GraphAddNodeAnd( pFForm, eNode1, eNode2 ); +} + +/**Function************************************************************* + + Synopsis [Factoring cube.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactorTrivialCube( Kit_Graph_t * pFForm, unsigned uCube, int nLits ) +{ + return Kit_SopFactorTrivialCube_rec( pFForm, uCube, 0, nLits ); +} + +/**Function************************************************************* + + Synopsis [Factoring SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactorTrivial_rec( Kit_Graph_t * pFForm, unsigned * pCubes, int nCubes, int nLits ) +{ + Kit_Edge_t eNode1, eNode2; + int nCubes1, nCubes2; + if ( nCubes == 1 ) + return Kit_SopFactorTrivialCube_rec( pFForm, pCubes[0], 0, nLits ); + // split the cubes into two parts + nCubes1 = nCubes/2; + nCubes2 = nCubes - nCubes1; +// nCubes2 = nCubes/2; +// nCubes1 = nCubes - nCubes2; + // recursively construct the tree for the parts + eNode1 = Kit_SopFactorTrivial_rec( pFForm, pCubes, nCubes1, nLits ); + eNode2 = Kit_SopFactorTrivial_rec( pFForm, pCubes + nCubes1, nCubes2, nLits ); + return Kit_GraphAddNodeOr( pFForm, eNode1, eNode2 ); +} + +/**Function************************************************************* + + Synopsis [Factoring the cover, which has no algebraic divisors.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_SopFactorTrivial( Kit_Graph_t * pFForm, Kit_Sop_t * cSop, int nLits ) +{ + return Kit_SopFactorTrivial_rec( pFForm, cSop->pCubes, cSop->nCubes, nLits ); +} + + +/**Function************************************************************* + + Synopsis [Testing procedure for the factoring code.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_FactorTest( unsigned * pTruth, int nVars ) +{ + Vec_Int_t * vCover, * vMemory; + Kit_Graph_t * pGraph; +// unsigned uTruthRes; + int RetValue; + + // derive SOP + vCover = Vec_IntAlloc( 0 ); + RetValue = Kit_TruthIsop( pTruth, nVars, vCover, 0 ); + assert( RetValue == 0 ); + + // derive factored form + vMemory = Vec_IntAlloc( 0 ); + pGraph = Kit_SopFactor( vCover, 0, nVars, vMemory ); +/* + // derive truth table + assert( nVars <= 5 ); + uTruthRes = Kit_GraphToTruth( pGraph ); + if ( uTruthRes != pTruth[0] ) + printf( "Verification failed!" ); +*/ + printf( "Vars = %2d. Cubes = %3d. FFNodes = %3d. FF_memory = %3d.\n", + nVars, Vec_IntSize(vCover), Kit_GraphNodeNum(pGraph), Vec_IntSize(vMemory) ); + + Vec_IntFree( vMemory ); + Vec_IntFree( vCover ); + Kit_GraphFree( pGraph ); +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitGraph.c b/src/aig/kit/kitGraph.c new file mode 100644 index 00000000..8bc7ca91 --- /dev/null +++ b/src/aig/kit/kitGraph.c @@ -0,0 +1,397 @@ +/**CFile**************************************************************** + + FileName [kitGraph.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Decomposition graph representation.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitGraph.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Creates a graph with the given number of leaves.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_GraphCreate( int nLeaves ) +{ + Kit_Graph_t * pGraph; + pGraph = ALLOC( Kit_Graph_t, 1 ); + memset( pGraph, 0, sizeof(Kit_Graph_t) ); + pGraph->nLeaves = nLeaves; + pGraph->nSize = nLeaves; + pGraph->nCap = 2 * nLeaves + 50; + pGraph->pNodes = ALLOC( Kit_Node_t, pGraph->nCap ); + memset( pGraph->pNodes, 0, sizeof(Kit_Node_t) * pGraph->nSize ); + return pGraph; +} + +/**Function************************************************************* + + Synopsis [Creates constant 0 graph.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_GraphCreateConst0() +{ + Kit_Graph_t * pGraph; + pGraph = ALLOC( Kit_Graph_t, 1 ); + memset( pGraph, 0, sizeof(Kit_Graph_t) ); + pGraph->fConst = 1; + pGraph->eRoot.fCompl = 1; + return pGraph; +} + +/**Function************************************************************* + + Synopsis [Creates constant 1 graph.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_GraphCreateConst1() +{ + Kit_Graph_t * pGraph; + pGraph = ALLOC( Kit_Graph_t, 1 ); + memset( pGraph, 0, sizeof(Kit_Graph_t) ); + pGraph->fConst = 1; + return pGraph; +} + +/**Function************************************************************* + + Synopsis [Creates the literal graph.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_GraphCreateLeaf( int iLeaf, int nLeaves, int fCompl ) +{ + Kit_Graph_t * pGraph; + assert( 0 <= iLeaf && iLeaf < nLeaves ); + pGraph = Kit_GraphCreate( nLeaves ); + pGraph->eRoot.Node = iLeaf; + pGraph->eRoot.fCompl = fCompl; + return pGraph; +} + +/**Function************************************************************* + + Synopsis [Creates a graph with the given number of leaves.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_GraphFree( Kit_Graph_t * pGraph ) +{ + FREE( pGraph->pNodes ); + free( pGraph ); +} + +/**Function************************************************************* + + Synopsis [Appends a new node to the graph.] + + Description [This procedure is meant for internal use.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Node_t * Kit_GraphAppendNode( Kit_Graph_t * pGraph ) +{ + Kit_Node_t * pNode; + if ( pGraph->nSize == pGraph->nCap ) + { + pGraph->pNodes = REALLOC( Kit_Node_t, pGraph->pNodes, 2 * pGraph->nCap ); + pGraph->nCap = 2 * pGraph->nCap; + } + pNode = pGraph->pNodes + pGraph->nSize++; + memset( pNode, 0, sizeof(Kit_Node_t) ); + return pNode; +} + +/**Function************************************************************* + + Synopsis [Creates an AND node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_GraphAddNodeAnd( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1 ) +{ + Kit_Node_t * pNode; + // get the new node + pNode = Kit_GraphAppendNode( pGraph ); + // set the inputs and other info + pNode->eEdge0 = eEdge0; + pNode->eEdge1 = eEdge1; + pNode->fCompl0 = eEdge0.fCompl; + pNode->fCompl1 = eEdge1.fCompl; + return Kit_EdgeCreate( pGraph->nSize - 1, 0 ); +} + +/**Function************************************************************* + + Synopsis [Creates an OR node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_GraphAddNodeOr( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1 ) +{ + Kit_Node_t * pNode; + // get the new node + pNode = Kit_GraphAppendNode( pGraph ); + // set the inputs and other info + pNode->eEdge0 = eEdge0; + pNode->eEdge1 = eEdge1; + pNode->fCompl0 = eEdge0.fCompl; + pNode->fCompl1 = eEdge1.fCompl; + // make adjustments for the OR gate + pNode->fNodeOr = 1; + pNode->eEdge0.fCompl = !pNode->eEdge0.fCompl; + pNode->eEdge1.fCompl = !pNode->eEdge1.fCompl; + return Kit_EdgeCreate( pGraph->nSize - 1, 1 ); +} + +/**Function************************************************************* + + Synopsis [Creates an XOR node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_GraphAddNodeXor( Kit_Graph_t * pGraph, Kit_Edge_t eEdge0, Kit_Edge_t eEdge1, int Type ) +{ + Kit_Edge_t eNode0, eNode1, eNode; + if ( Type == 0 ) + { + // derive the first AND + eEdge0.fCompl ^= 1; + eNode0 = Kit_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 ); + eEdge0.fCompl ^= 1; + // derive the second AND + eEdge1.fCompl ^= 1; + eNode1 = Kit_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 ); + // derive the final OR + eNode = Kit_GraphAddNodeOr( pGraph, eNode0, eNode1 ); + } + else + { + // derive the first AND + eNode0 = Kit_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 ); + // derive the second AND + eEdge0.fCompl ^= 1; + eEdge1.fCompl ^= 1; + eNode1 = Kit_GraphAddNodeAnd( pGraph, eEdge0, eEdge1 ); + // derive the final OR + eNode = Kit_GraphAddNodeOr( pGraph, eNode0, eNode1 ); + eNode.fCompl ^= 1; + } + return eNode; +} + +/**Function************************************************************* + + Synopsis [Creates an XOR node.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Edge_t Kit_GraphAddNodeMux( Kit_Graph_t * pGraph, Kit_Edge_t eEdgeC, Kit_Edge_t eEdgeT, Kit_Edge_t eEdgeE, int Type ) +{ + Kit_Edge_t eNode0, eNode1, eNode; + if ( Type == 0 ) + { + // derive the first AND + eNode0 = Kit_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT ); + // derive the second AND + eEdgeC.fCompl ^= 1; + eNode1 = Kit_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE ); + // derive the final OR + eNode = Kit_GraphAddNodeOr( pGraph, eNode0, eNode1 ); + } + else + { + // complement the arguments + eEdgeT.fCompl ^= 1; + eEdgeE.fCompl ^= 1; + // derive the first AND + eNode0 = Kit_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeT ); + // derive the second AND + eEdgeC.fCompl ^= 1; + eNode1 = Kit_GraphAddNodeAnd( pGraph, eEdgeC, eEdgeE ); + // derive the final OR + eNode = Kit_GraphAddNodeOr( pGraph, eNode0, eNode1 ); + eNode.fCompl ^= 1; + } + return eNode; +} + +/**Function************************************************************* + + Synopsis [Derives the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_GraphToTruth( Kit_Graph_t * pGraph ) +{ + unsigned uTruths[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 }; + unsigned uTruth, uTruth0, uTruth1; + Kit_Node_t * pNode; + int i; + + // sanity checks + assert( Kit_GraphLeaveNum(pGraph) >= 0 ); + assert( Kit_GraphLeaveNum(pGraph) <= pGraph->nSize ); + assert( Kit_GraphLeaveNum(pGraph) <= 5 ); + + // check for constant function + if ( Kit_GraphIsConst(pGraph) ) + return Kit_GraphIsComplement(pGraph)? 0 : ~((unsigned)0); + // check for a literal + if ( Kit_GraphIsVar(pGraph) ) + return Kit_GraphIsComplement(pGraph)? ~uTruths[Kit_GraphVarInt(pGraph)] : uTruths[Kit_GraphVarInt(pGraph)]; + + // assign the elementary variables + Kit_GraphForEachLeaf( pGraph, pNode, i ) + pNode->pFunc = (void *)uTruths[i]; + + // compute the function for each internal node + Kit_GraphForEachNode( pGraph, pNode, i ) + { + uTruth0 = (unsigned)Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc; + uTruth1 = (unsigned)Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc; + uTruth0 = pNode->eEdge0.fCompl? ~uTruth0 : uTruth0; + uTruth1 = pNode->eEdge1.fCompl? ~uTruth1 : uTruth1; + uTruth = uTruth0 & uTruth1; + pNode->pFunc = (void *)uTruth; + } + + // complement the result if necessary + return Kit_GraphIsComplement(pGraph)? ~uTruth : uTruth; +} + +/**Function************************************************************* + + Synopsis [Derives the factored form from the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Kit_Graph_t * Kit_TruthToGraph( unsigned * pTruth, int nVars, Vec_Int_t * vMemory ) +{ + Kit_Graph_t * pGraph; + int RetValue; + // derive SOP + RetValue = Kit_TruthIsop( pTruth, nVars, vMemory, 1 ); // tried 1 and found not useful in "renode" + if ( RetValue == -1 ) + return NULL; + if ( Vec_IntSize(vMemory) > 128 ) + return NULL; +// printf( "Isop size = %d.\n", Vec_IntSize(vMemory) ); + assert( RetValue == 0 || RetValue == 1 ); + // derive factored form + pGraph = Kit_SopFactor( vMemory, RetValue, nVars, vMemory ); + return pGraph; +} + +/**Function************************************************************* + + Synopsis [Derives the maximum depth from the leaf to the root.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_GraphLeafDepth_rec( Kit_Graph_t * pGraph, Kit_Node_t * pNode, Kit_Node_t * pLeaf ) +{ + int Depth0, Depth1, Depth; + if ( pNode == pLeaf ) + return 0; + if ( Kit_GraphNodeIsVar(pGraph, pNode) ) + return -100; + Depth0 = Kit_GraphLeafDepth_rec( pGraph, Kit_GraphNodeFanin0(pGraph, pNode), pLeaf ); + Depth1 = Kit_GraphLeafDepth_rec( pGraph, Kit_GraphNodeFanin1(pGraph, pNode), pLeaf ); + Depth = KIT_MAX( Depth0, Depth1 ); + Depth = (Depth == -100) ? -100 : Depth + 1; + return Depth; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + diff --git a/src/aig/kit/kitHop.c b/src/aig/kit/kitHop.c new file mode 100644 index 00000000..95461c4e --- /dev/null +++ b/src/aig/kit/kitHop.c @@ -0,0 +1,115 @@ +/**CFile**************************************************************** + + FileName [kitHop.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Procedures involving AIGs.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitHop.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" +#include "hop.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + + +/**Function************************************************************* + + Synopsis [Transforms the decomposition graph into the AIG.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Hop_Obj_t * Kit_GraphToHopInternal( Hop_Man_t * pMan, Kit_Graph_t * pGraph ) +{ + Kit_Node_t * pNode; + Hop_Obj_t * pAnd0, * pAnd1; + int i; + // check for constant function + if ( Kit_GraphIsConst(pGraph) ) + return Hop_NotCond( Hop_ManConst1(pMan), Kit_GraphIsComplement(pGraph) ); + // check for a literal + if ( Kit_GraphIsVar(pGraph) ) + return Hop_NotCond( Kit_GraphVar(pGraph)->pFunc, Kit_GraphIsComplement(pGraph) ); + // build the AIG nodes corresponding to the AND gates of the graph + Kit_GraphForEachNode( pGraph, pNode, i ) + { + pAnd0 = Hop_NotCond( Kit_GraphNode(pGraph, pNode->eEdge0.Node)->pFunc, pNode->eEdge0.fCompl ); + pAnd1 = Hop_NotCond( Kit_GraphNode(pGraph, pNode->eEdge1.Node)->pFunc, pNode->eEdge1.fCompl ); + pNode->pFunc = Hop_And( pMan, pAnd0, pAnd1 ); + } + // complement the result if necessary + return Hop_NotCond( pNode->pFunc, Kit_GraphIsComplement(pGraph) ); +} + +/**Function************************************************************* + + Synopsis [Strashes one logic node using its SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Hop_Obj_t * Kit_GraphToHop( Hop_Man_t * pMan, Kit_Graph_t * pGraph ) +{ + Kit_Node_t * pNode; + int i; + // collect the fanins + Kit_GraphForEachLeaf( pGraph, pNode, i ) + pNode->pFunc = Hop_IthVar( pMan, i ); + // perform strashing + return Kit_GraphToHopInternal( pMan, pGraph ); +} + +/**Function************************************************************* + + Synopsis [Strashes one logic node using its SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Hop_Obj_t * Kit_CoverToHop( Hop_Man_t * pMan, Vec_Int_t * vCover, int nVars, Vec_Int_t * vMemory ) +{ + Kit_Graph_t * pGraph; + Hop_Obj_t * pFunc; + // perform factoring + pGraph = Kit_SopFactor( vCover, 0, nVars, vMemory ); + // convert graph to the AIG + pFunc = Kit_GraphToHop( pMan, pGraph ); + Kit_GraphFree( pGraph ); + return pFunc; +} + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitIsop.c b/src/aig/kit/kitIsop.c new file mode 100644 index 00000000..cc61a6bd --- /dev/null +++ b/src/aig/kit/kitIsop.c @@ -0,0 +1,325 @@ +/**CFile**************************************************************** + + FileName [kitIsop.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [ISOP computation based on Morreale's algorithm.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitIsop.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +// ISOP computation fails if intermediate memory usage exceed this limit +#define KIT_ISOP_MEM_LIMIT (1<<16) + +// static procedures to compute ISOP +static unsigned * Kit_TruthIsop_rec( unsigned * puOn, unsigned * puOnDc, int nVars, Kit_Sop_t * pcRes, Vec_Int_t * vStore ); +static unsigned Kit_TruthIsop5_rec( unsigned uOn, unsigned uOnDc, int nVars, Kit_Sop_t * pcRes, Vec_Int_t * vStore ); + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Computes ISOP from TT.] + + Description [Returns the cover in vMemory. Uses the rest of array in vMemory + as an intermediate memory storage. Returns the cover with -1 cubes, if the + the computation exceeded the memory limit (KIT_ISOP_MEM_LIMIT words of + intermediate data).] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthIsop( unsigned * puTruth, int nVars, Vec_Int_t * vMemory, int fTryBoth ) +{ + Kit_Sop_t cRes, * pcRes = &cRes; + Kit_Sop_t cRes2, * pcRes2 = &cRes2; + unsigned * pResult; + int RetValue = 0; + assert( nVars >= 0 && nVars < 16 ); + // if nVars < 5, make sure it does not depend on those vars +// for ( i = nVars; i < 5; i++ ) +// assert( !Extra_TruthVarInSupport(puTruth, 5, i) ); + // prepare memory manager + Vec_IntClear( vMemory ); + Vec_IntGrow( vMemory, KIT_ISOP_MEM_LIMIT ); + // compute ISOP for the direct polarity + pResult = Kit_TruthIsop_rec( puTruth, puTruth, nVars, pcRes, vMemory ); + if ( pcRes->nCubes == -1 ) + { + vMemory->nSize = -1; + return -1; + } + assert( Extra_TruthIsEqual( puTruth, pResult, nVars ) ); + if ( pcRes->nCubes == 0 || (pcRes->nCubes == 1 && pcRes->pCubes[0] == 0) ) + { + vMemory->pArray[0] = 0; + Vec_IntShrink( vMemory, pcRes->nCubes ); + return 0; + } + if ( fTryBoth ) + { + // compute ISOP for the complemented polarity + Extra_TruthNot( puTruth, puTruth, nVars ); + pResult = Kit_TruthIsop_rec( puTruth, puTruth, nVars, pcRes2, vMemory ); + if ( pcRes2->nCubes >= 0 ) + { + assert( Extra_TruthIsEqual( puTruth, pResult, nVars ) ); + if ( pcRes->nCubes > pcRes2->nCubes ) + { + RetValue = 1; + pcRes = pcRes2; + } + } + Extra_TruthNot( puTruth, puTruth, nVars ); + } +// printf( "%d ", vMemory->nSize ); + // move the cover representation to the beginning of the memory buffer + memmove( vMemory->pArray, pcRes->pCubes, pcRes->nCubes * sizeof(unsigned) ); + Vec_IntShrink( vMemory, pcRes->nCubes ); + return RetValue; +} + +/**Function************************************************************* + + Synopsis [Computes ISOP 6 variables or more.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned * Kit_TruthIsop_rec( unsigned * puOn, unsigned * puOnDc, int nVars, Kit_Sop_t * pcRes, Vec_Int_t * vStore ) +{ + Kit_Sop_t cRes0, cRes1, cRes2; + Kit_Sop_t * pcRes0 = &cRes0, * pcRes1 = &cRes1, * pcRes2 = &cRes2; + unsigned * puRes0, * puRes1, * puRes2; + unsigned * puOn0, * puOn1, * puOnDc0, * puOnDc1, * pTemp, * pTemp0, * pTemp1; + int i, k, Var, nWords, nWordsAll; +// assert( Extra_TruthIsImply( puOn, puOnDc, nVars ) ); + // allocate room for the resulting truth table + nWordsAll = Extra_TruthWordNum( nVars ); + pTemp = Vec_IntFetch( vStore, nWordsAll ); + if ( pTemp == NULL ) + { + pcRes->nCubes = -1; + return NULL; + } + // check for constants + if ( Extra_TruthIsConst0( puOn, nVars ) ) + { + pcRes->nCubes = 0; + pcRes->pCubes = NULL; + Extra_TruthClear( pTemp, nVars ); + return pTemp; + } + if ( Extra_TruthIsConst1( puOnDc, nVars ) ) + { + pcRes->nCubes = 1; + pcRes->pCubes = Vec_IntFetch( vStore, 1 ); + if ( pcRes->pCubes == NULL ) + { + pcRes->nCubes = -1; + return NULL; + } + pcRes->pCubes[0] = 0; + Extra_TruthFill( pTemp, nVars ); + return pTemp; + } + assert( nVars > 0 ); + // find the topmost var + for ( Var = nVars-1; Var >= 0; Var-- ) + if ( Extra_TruthVarInSupport( puOn, nVars, Var ) || + Extra_TruthVarInSupport( puOnDc, nVars, Var ) ) + break; + assert( Var >= 0 ); + // consider a simple case when one-word computation can be used + if ( Var < 5 ) + { + unsigned uRes = Kit_TruthIsop5_rec( puOn[0], puOnDc[0], Var+1, pcRes, vStore ); + for ( i = 0; i < nWordsAll; i++ ) + pTemp[i] = uRes; + return pTemp; + } + assert( Var >= 5 ); + nWords = Extra_TruthWordNum( Var ); + // cofactor + puOn0 = puOn; puOn1 = puOn + nWords; + puOnDc0 = puOnDc; puOnDc1 = puOnDc + nWords; + pTemp0 = pTemp; pTemp1 = pTemp + nWords; + // solve for cofactors + Extra_TruthSharp( pTemp0, puOn0, puOnDc1, Var ); + puRes0 = Kit_TruthIsop_rec( pTemp0, puOnDc0, Var, pcRes0, vStore ); + if ( pcRes0->nCubes == -1 ) + { + pcRes->nCubes = -1; + return NULL; + } + Extra_TruthSharp( pTemp1, puOn1, puOnDc0, Var ); + puRes1 = Kit_TruthIsop_rec( pTemp1, puOnDc1, Var, pcRes1, vStore ); + if ( pcRes1->nCubes == -1 ) + { + pcRes->nCubes = -1; + return NULL; + } + Extra_TruthSharp( pTemp0, puOn0, puRes0, Var ); + Extra_TruthSharp( pTemp1, puOn1, puRes1, Var ); + Extra_TruthOr( pTemp0, pTemp0, pTemp1, Var ); + Extra_TruthAnd( pTemp1, puOnDc0, puOnDc1, Var ); + puRes2 = Kit_TruthIsop_rec( pTemp0, pTemp1, Var, pcRes2, vStore ); + if ( pcRes2->nCubes == -1 ) + { + pcRes->nCubes = -1; + return NULL; + } + // create the resulting cover + pcRes->nCubes = pcRes0->nCubes + pcRes1->nCubes + pcRes2->nCubes; + pcRes->pCubes = Vec_IntFetch( vStore, pcRes->nCubes ); + if ( pcRes->pCubes == NULL ) + { + pcRes->nCubes = -1; + return NULL; + } + k = 0; + for ( i = 0; i < pcRes0->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes0->pCubes[i] | (1 << ((Var<<1)+0)); + for ( i = 0; i < pcRes1->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes1->pCubes[i] | (1 << ((Var<<1)+1)); + for ( i = 0; i < pcRes2->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes2->pCubes[i]; + assert( k == pcRes->nCubes ); + // create the resulting truth table + Extra_TruthOr( pTemp0, puRes0, puRes2, Var ); + Extra_TruthOr( pTemp1, puRes1, puRes2, Var ); + // copy the table if needed + nWords <<= 1; + for ( i = 1; i < nWordsAll/nWords; i++ ) + for ( k = 0; k < nWords; k++ ) + pTemp[i*nWords + k] = pTemp[k]; + // verify in the end +// assert( Extra_TruthIsImply( puOn, pTemp, nVars ) ); +// assert( Extra_TruthIsImply( pTemp, puOnDc, nVars ) ); + return pTemp; +} + +/**Function************************************************************* + + Synopsis [Computes ISOP for 5 variables or less.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_TruthIsop5_rec( unsigned uOn, unsigned uOnDc, int nVars, Kit_Sop_t * pcRes, Vec_Int_t * vStore ) +{ + unsigned uMasks[5] = { 0xAAAAAAAA, 0xCCCCCCCC, 0xF0F0F0F0, 0xFF00FF00, 0xFFFF0000 }; + Kit_Sop_t cRes0, cRes1, cRes2; + Kit_Sop_t * pcRes0 = &cRes0, * pcRes1 = &cRes1, * pcRes2 = &cRes2; + unsigned uOn0, uOn1, uOnDc0, uOnDc1, uRes0, uRes1, uRes2; + int i, k, Var; + assert( nVars <= 5 ); + assert( (uOn & ~uOnDc) == 0 ); + if ( uOn == 0 ) + { + pcRes->nCubes = 0; + pcRes->pCubes = NULL; + return 0; + } + if ( uOnDc == 0xFFFFFFFF ) + { + pcRes->nCubes = 1; + pcRes->pCubes = Vec_IntFetch( vStore, 1 ); + if ( pcRes->pCubes == NULL ) + { + pcRes->nCubes = -1; + return 0; + } + pcRes->pCubes[0] = 0; + return 0xFFFFFFFF; + } + assert( nVars > 0 ); + // find the topmost var + for ( Var = nVars-1; Var >= 0; Var-- ) + if ( Extra_TruthVarInSupport( &uOn, 5, Var ) || + Extra_TruthVarInSupport( &uOnDc, 5, Var ) ) + break; + assert( Var >= 0 ); + // cofactor + uOn0 = uOn1 = uOn; + uOnDc0 = uOnDc1 = uOnDc; + Extra_TruthCofactor0( &uOn0, Var + 1, Var ); + Extra_TruthCofactor1( &uOn1, Var + 1, Var ); + Extra_TruthCofactor0( &uOnDc0, Var + 1, Var ); + Extra_TruthCofactor1( &uOnDc1, Var + 1, Var ); + // solve for cofactors + uRes0 = Kit_TruthIsop5_rec( uOn0 & ~uOnDc1, uOnDc0, Var, pcRes0, vStore ); + if ( pcRes0->nCubes == -1 ) + { + pcRes->nCubes = -1; + return 0; + } + uRes1 = Kit_TruthIsop5_rec( uOn1 & ~uOnDc0, uOnDc1, Var, pcRes1, vStore ); + if ( pcRes1->nCubes == -1 ) + { + pcRes->nCubes = -1; + return 0; + } + uRes2 = Kit_TruthIsop5_rec( (uOn0 & ~uRes0) | (uOn1 & ~uRes1), uOnDc0 & uOnDc1, Var, pcRes2, vStore ); + if ( pcRes2->nCubes == -1 ) + { + pcRes->nCubes = -1; + return 0; + } + // create the resulting cover + pcRes->nCubes = pcRes0->nCubes + pcRes1->nCubes + pcRes2->nCubes; + pcRes->pCubes = Vec_IntFetch( vStore, pcRes->nCubes ); + if ( pcRes->pCubes == NULL ) + { + pcRes->nCubes = -1; + return 0; + } + k = 0; + for ( i = 0; i < pcRes0->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes0->pCubes[i] | (1 << ((Var<<1)+0)); + for ( i = 0; i < pcRes1->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes1->pCubes[i] | (1 << ((Var<<1)+1)); + for ( i = 0; i < pcRes2->nCubes; i++ ) + pcRes->pCubes[k++] = pcRes2->pCubes[i]; + assert( k == pcRes->nCubes ); + // derive the final truth table + uRes2 |= (uRes0 & ~uMasks[Var]) | (uRes1 & uMasks[Var]); +// assert( (uOn & ~uRes2) == 0 ); +// assert( (uRes2 & ~uOnDc) == 0 ); + return uRes2; +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitSop.c b/src/aig/kit/kitSop.c new file mode 100644 index 00000000..3fa81351 --- /dev/null +++ b/src/aig/kit/kitSop.c @@ -0,0 +1,570 @@ +/**CFile**************************************************************** + + FileName [kitSop.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Procedures involving SOPs.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitSop.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Creates SOP from the cube array.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopCreate( Kit_Sop_t * cResult, Vec_Int_t * vInput, int nVars, Vec_Int_t * vMemory ) +{ + unsigned uCube; + int i; + // start the cover + cResult->nCubes = 0; + cResult->pCubes = Vec_IntFetch( vMemory, Vec_IntSize(vInput) ); + // add the cubes + Vec_IntForEachEntry( vInput, uCube, i ) + Kit_SopPushCube( cResult, uCube ); +} + +/**Function************************************************************* + + Synopsis [Creates SOP from the cube array.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopCreateInverse( Kit_Sop_t * cResult, Vec_Int_t * vInput, int nLits, Vec_Int_t * vMemory ) +{ + unsigned uCube, uMask = 0; + int i, nCubes = Vec_IntSize(vInput); + // start the cover + cResult->nCubes = 0; + cResult->pCubes = Vec_IntFetch( vMemory, nCubes ); + // add the cubes +// Vec_IntForEachEntry( vInput, uCube, i ) + for ( i = 0; i < nCubes; i++ ) + { + uCube = Vec_IntEntry( vInput, i ); + uMask = ((uCube | (uCube >> 1)) & 0x55555555); + uMask |= (uMask << 1); + Kit_SopPushCube( cResult, uCube ^ uMask ); + } +} + +/**Function************************************************************* + + Synopsis [Duplicates SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopDup( Kit_Sop_t * cResult, Kit_Sop_t * cSop, Vec_Int_t * vMemory ) +{ + unsigned uCube; + int i; + // start the cover + cResult->nCubes = 0; + cResult->pCubes = Vec_IntFetch( vMemory, Kit_SopCubeNum(cSop) ); + // add the cubes + Kit_SopForEachCube( cSop, uCube, i ) + Kit_SopPushCube( cResult, uCube ); +} + +/**Function************************************************************* + + Synopsis [Derives the quotient of division by literal.] + + Description [Reduces the cover to be equal to the result of + division of the given cover by the literal.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopDivideByLiteralQuo( Kit_Sop_t * cSop, int iLit ) +{ + unsigned uCube; + int i, k = 0; + Kit_SopForEachCube( cSop, uCube, i ) + { + if ( Kit_CubeHasLit(uCube, iLit) ) + Kit_SopWriteCube( cSop, Kit_CubeRemLit(uCube, iLit), k++ ); + } + Kit_SopShrink( cSop, k ); +} + + +/**Function************************************************************* + + Synopsis [Divides cover by one cube.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopDivideByCube( Kit_Sop_t * cSop, Kit_Sop_t * cDiv, Kit_Sop_t * vQuo, Kit_Sop_t * vRem, Vec_Int_t * vMemory ) +{ + unsigned uCube, uDiv; + int i; + // get the only cube + assert( Kit_SopCubeNum(cDiv) == 1 ); + uDiv = Kit_SopCube(cDiv, 0); + // allocate covers + vQuo->nCubes = 0; + vQuo->pCubes = Vec_IntFetch( vMemory, Kit_SopCubeNum(cSop) ); + vRem->nCubes = 0; + vRem->pCubes = Vec_IntFetch( vMemory, Kit_SopCubeNum(cSop) ); + // sort the cubes + Kit_SopForEachCube( cSop, uCube, i ) + { + if ( Kit_CubeContains( uCube, uDiv ) ) + Kit_SopPushCube( vQuo, Kit_CubeSharp(uCube, uDiv) ); + else + Kit_SopPushCube( vRem, uCube ); + } +} + +/**Function************************************************************* + + Synopsis [Divides cover by one cube.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopDivideInternal( Kit_Sop_t * cSop, Kit_Sop_t * cDiv, Kit_Sop_t * vQuo, Kit_Sop_t * vRem, Vec_Int_t * vMemory ) +{ + unsigned uCube, uDiv, uCube2, uDiv2, uQuo; + int i, i2, k, k2, nCubesRem; + assert( Kit_SopCubeNum(cSop) >= Kit_SopCubeNum(cDiv) ); + // consider special case + if ( Kit_SopCubeNum(cDiv) == 1 ) + { + Kit_SopDivideByCube( cSop, cDiv, vQuo, vRem, vMemory ); + return; + } + // allocate quotient + vQuo->nCubes = 0; + vQuo->pCubes = Vec_IntFetch( vMemory, Kit_SopCubeNum(cSop) / Kit_SopCubeNum(cDiv) ); + // for each cube of the cover + // it either belongs to the quotient or to the remainder + Kit_SopForEachCube( cSop, uCube, i ) + { + // skip taken cubes + if ( Kit_CubeIsMarked(uCube) ) + continue; + // find a matching cube in the divisor + Kit_SopForEachCube( cDiv, uDiv, k ) + if ( Kit_CubeContains( uCube, uDiv ) ) + break; + // the cube is not found + if ( k == Kit_SopCubeNum(cDiv) ) + continue; + // the quotient cube exists + uQuo = Kit_CubeSharp( uCube, uDiv ); + // find corresponding cubes for other cubes of the divisor + Kit_SopForEachCube( cDiv, uDiv2, k2 ) + { + if ( k2 == k ) + continue; + // find a matching cube + Kit_SopForEachCube( cSop, uCube2, i2 ) + { + // skip taken cubes + if ( Kit_CubeIsMarked(uCube2) ) + continue; + // check if the cube can be used + if ( Kit_CubeContains( uCube2, uDiv2 ) && uQuo == Kit_CubeSharp( uCube2, uDiv2 ) ) + break; + } + // the case when the cube is not found + if ( i2 == Kit_SopCubeNum(cSop) ) + break; + } + // we did not find some cubes - continue looking at other cubes + if ( k2 != Kit_SopCubeNum(cDiv) ) + continue; + // we found all cubes - add the quotient cube + Kit_SopPushCube( vQuo, uQuo ); + + // mark the first cube + Kit_SopWriteCube( cSop, Kit_CubeMark(uCube), i ); + // mark other cubes that have this quotient + Kit_SopForEachCube( cDiv, uDiv2, k2 ) + { + if ( k2 == k ) + continue; + // find a matching cube + Kit_SopForEachCube( cSop, uCube2, i2 ) + { + // skip taken cubes + if ( Kit_CubeIsMarked(uCube2) ) + continue; + // check if the cube can be used + if ( Kit_CubeContains( uCube2, uDiv2 ) && uQuo == Kit_CubeSharp( uCube2, uDiv2 ) ) + break; + } + assert( i2 < Kit_SopCubeNum(cSop) ); + // the cube is found, mark it + // (later we will add all unmarked cubes to the remainder) + Kit_SopWriteCube( cSop, Kit_CubeMark(uCube2), i2 ); + } + } + // determine the number of cubes in the remainder + nCubesRem = Kit_SopCubeNum(cSop) - Kit_SopCubeNum(vQuo) * Kit_SopCubeNum(cDiv); + // allocate remainder + vRem->nCubes = 0; + vRem->pCubes = Vec_IntFetch( vMemory, nCubesRem ); + // finally add the remaining unmarked cubes to the remainder + // and clean the marked cubes in the cover + Kit_SopForEachCube( cSop, uCube, i ) + { + if ( !Kit_CubeIsMarked(uCube) ) + { + Kit_SopPushCube( vRem, uCube ); + continue; + } + Kit_SopWriteCube( cSop, Kit_CubeUnmark(uCube), i ); + } + assert( nCubesRem == Kit_SopCubeNum(vRem) ); +} + +/**Function************************************************************* + + Synopsis [Returns the common cube.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +static inline unsigned Kit_SopCommonCube( Kit_Sop_t * cSop ) +{ + unsigned uMask, uCube; + int i; + uMask = ~(unsigned)0; + Kit_SopForEachCube( cSop, uCube, i ) + uMask &= uCube; + return uMask; +} + +/**Function************************************************************* + + Synopsis [Makes the cover cube-free.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopMakeCubeFree( Kit_Sop_t * cSop ) +{ + unsigned uMask, uCube; + int i; + uMask = Kit_SopCommonCube( cSop ); + if ( uMask == 0 ) + return; + // remove the common cube + Kit_SopForEachCube( cSop, uCube, i ) + Kit_SopWriteCube( cSop, Kit_CubeSharp(uCube, uMask), i ); +} + +/**Function************************************************************* + + Synopsis [Checks if the cover is cube-free.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopIsCubeFree( Kit_Sop_t * cSop ) +{ + return Kit_SopCommonCube( cSop ) == 0; +} + +/**Function************************************************************* + + Synopsis [Creates SOP composes of the common cube of the given SOP.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopCommonCubeCover( Kit_Sop_t * cResult, Kit_Sop_t * cSop, Vec_Int_t * vMemory ) +{ + assert( Kit_SopCubeNum(cSop) > 0 ); + cResult->nCubes = 0; + cResult->pCubes = Vec_IntFetch( vMemory, 1 ); + Kit_SopPushCube( cResult, Kit_SopCommonCube(cSop) ); +} + + +/**Function************************************************************* + + Synopsis [Find any literal that occurs more than once.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopAnyLiteral( Kit_Sop_t * cSop, int nLits ) +{ + unsigned uCube; + int i, k, nLitsCur; + // go through each literal + for ( i = 0; i < nLits; i++ ) + { + // go through all the cubes + nLitsCur = 0; + Kit_SopForEachCube( cSop, uCube, k ) + if ( Kit_CubeHasLit(uCube, i) ) + nLitsCur++; + if ( nLitsCur > 1 ) + return i; + } + return -1; +} + +/**Function************************************************************* + + Synopsis [Find the least often occurring literal.] + + Description [Find the least often occurring literal among those + that occur more than once.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopWorstLiteral( Kit_Sop_t * cSop, int nLits ) +{ + unsigned uCube; + int i, k, iMin, nLitsMin, nLitsCur; + int fUseFirst = 1; + + // go through each literal + iMin = -1; + nLitsMin = 1000000; + for ( i = 0; i < nLits; i++ ) + { + // go through all the cubes + nLitsCur = 0; + Kit_SopForEachCube( cSop, uCube, k ) + if ( Kit_CubeHasLit(uCube, i) ) + nLitsCur++; + // skip the literal that does not occur or occurs once + if ( nLitsCur < 2 ) + continue; + // check if this is the best literal + if ( fUseFirst ) + { + if ( nLitsMin > nLitsCur ) + { + nLitsMin = nLitsCur; + iMin = i; + } + } + else + { + if ( nLitsMin >= nLitsCur ) + { + nLitsMin = nLitsCur; + iMin = i; + } + } + } + if ( nLitsMin < 1000000 ) + return iMin; + return -1; +} + +/**Function************************************************************* + + Synopsis [Find the least often occurring literal.] + + Description [Find the least often occurring literal among those + that occur more than once.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopBestLiteral( Kit_Sop_t * cSop, int nLits, unsigned uMask ) +{ + unsigned uCube; + int i, k, iMax, nLitsMax, nLitsCur; + int fUseFirst = 1; + + // go through each literal + iMax = -1; + nLitsMax = -1; + for ( i = 0; i < nLits; i++ ) + { + if ( !Kit_CubeHasLit(uMask, i) ) + continue; + // go through all the cubes + nLitsCur = 0; + Kit_SopForEachCube( cSop, uCube, k ) + if ( Kit_CubeHasLit(uCube, i) ) + nLitsCur++; + // skip the literal that does not occur or occurs once + if ( nLitsCur < 2 ) + continue; + // check if this is the best literal + if ( fUseFirst ) + { + if ( nLitsMax < nLitsCur ) + { + nLitsMax = nLitsCur; + iMax = i; + } + } + else + { + if ( nLitsMax <= nLitsCur ) + { + nLitsMax = nLitsCur; + iMax = i; + } + } + } + if ( nLitsMax >= 0 ) + return iMax; + return -1; +} + +/**Function************************************************************* + + Synopsis [Computes a level-zero kernel.] + + Description [Modifies the cover to contain one level-zero kernel.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopDivisorZeroKernel_rec( Kit_Sop_t * cSop, int nLits ) +{ + int iLit; + // find any literal that occurs at least two times + iLit = Kit_SopWorstLiteral( cSop, nLits ); + if ( iLit == -1 ) + return; + // derive the cube-free quotient + Kit_SopDivideByLiteralQuo( cSop, iLit ); // the same cover + Kit_SopMakeCubeFree( cSop ); // the same cover + // call recursively + Kit_SopDivisorZeroKernel_rec( cSop, nLits ); // the same cover +} + +/**Function************************************************************* + + Synopsis [Computes the quick divisor of the cover.] + + Description [Returns 0, if there is no divisor other than trivial.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_SopDivisor( Kit_Sop_t * cResult, Kit_Sop_t * cSop, int nLits, Vec_Int_t * vMemory ) +{ + if ( Kit_SopCubeNum(cSop) <= 1 ) + return 0; + if ( Kit_SopAnyLiteral( cSop, nLits ) == -1 ) + return 0; + // duplicate the cover + Kit_SopDup( cResult, cSop, vMemory ); + // perform the kerneling + Kit_SopDivisorZeroKernel_rec( cResult, nLits ); + assert( Kit_SopCubeNum(cResult) > 0 ); + return 1; +} + + +/**Function************************************************************* + + Synopsis [Create the one-literal cover with the best literal from cSop.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_SopBestLiteralCover( Kit_Sop_t * cResult, Kit_Sop_t * cSop, unsigned uCube, int nLits, Vec_Int_t * vMemory ) +{ + int iLitBest; + // get the best literal + iLitBest = Kit_SopBestLiteral( cSop, nLits, uCube ); + // start the cover + cResult->nCubes = 0; + cResult->pCubes = Vec_IntFetch( vMemory, 1 ); + // set the cube + Kit_SopPushCube( cResult, Kit_CubeSetLit(0, iLitBest) ); +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kitTruth.c b/src/aig/kit/kitTruth.c new file mode 100644 index 00000000..d41e5d4e --- /dev/null +++ b/src/aig/kit/kitTruth.c @@ -0,0 +1,1640 @@ +/**CFile**************************************************************** + + FileName [kitTruth.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [Procedures involving truth tables.] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kitTruth.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +static unsigned s_VarMasks[5][2] = { + { 0x33333333, 0xAAAAAAAA }, + { 0x55555555, 0xCCCCCCCC }, + { 0x0F0F0F0F, 0xF0F0F0F0 }, + { 0x00FF00FF, 0xFF00FF00 }, + { 0x0000FFFF, 0xFFFF0000 } +}; + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [Swaps two adjacent variables in the truth table.] + + Description [Swaps var number Start and var number Start+1 (0-based numbers). + The input truth table is pIn. The output truth table is pOut.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthSwapAdjacentVars( unsigned * pOut, unsigned * pIn, int nVars, int iVar ) +{ + static unsigned PMasks[4][3] = { + { 0x99999999, 0x22222222, 0x44444444 }, + { 0xC3C3C3C3, 0x0C0C0C0C, 0x30303030 }, + { 0xF00FF00F, 0x00F000F0, 0x0F000F00 }, + { 0xFF0000FF, 0x0000FF00, 0x00FF0000 } + }; + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step, Shift; + + assert( iVar < nVars - 1 ); + if ( iVar < 4 ) + { + Shift = (1 << iVar); + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & PMasks[iVar][0]) | ((pIn[i] & PMasks[iVar][1]) << Shift) | ((pIn[i] & PMasks[iVar][2]) >> Shift); + } + else if ( iVar > 4 ) + { + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 4*Step ) + { + for ( i = 0; i < Step; i++ ) + pOut[i] = pIn[i]; + for ( i = 0; i < Step; i++ ) + pOut[Step+i] = pIn[2*Step+i]; + for ( i = 0; i < Step; i++ ) + pOut[2*Step+i] = pIn[Step+i]; + for ( i = 0; i < Step; i++ ) + pOut[3*Step+i] = pIn[3*Step+i]; + pIn += 4*Step; + pOut += 4*Step; + } + } + else // if ( iVar == 4 ) + { + for ( i = 0; i < nWords; i += 2 ) + { + pOut[i] = (pIn[i] & 0x0000FFFF) | ((pIn[i+1] & 0x0000FFFF) << 16); + pOut[i+1] = (pIn[i+1] & 0xFFFF0000) | ((pIn[i] & 0xFFFF0000) >> 16); + } + } +} + +/**Function************************************************************* + + Synopsis [Swaps two adjacent variables in the truth table.] + + Description [Swaps var number Start and var number Start+1 (0-based numbers). + The input truth table is pIn. The output truth table is pOut.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthSwapAdjacentVars2( unsigned * pIn, unsigned * pOut, int nVars, int Start ) +{ + int nWords = (nVars <= 5)? 1 : (1 << (nVars-5)); + int i, k, Step; + + assert( Start < nVars - 1 ); + switch ( Start ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x99999999) | ((pIn[i] & 0x22222222) << 1) | ((pIn[i] & 0x44444444) >> 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xC3C3C3C3) | ((pIn[i] & 0x0C0C0C0C) << 2) | ((pIn[i] & 0x30303030) >> 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xF00FF00F) | ((pIn[i] & 0x00F000F0) << 4) | ((pIn[i] & 0x0F000F00) >> 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xFF0000FF) | ((pIn[i] & 0x0000FF00) << 8) | ((pIn[i] & 0x00FF0000) >> 8); + return; + case 4: + for ( i = 0; i < nWords; i += 2 ) + { + pOut[i] = (pIn[i] & 0x0000FFFF) | ((pIn[i+1] & 0x0000FFFF) << 16); + pOut[i+1] = (pIn[i+1] & 0xFFFF0000) | ((pIn[i] & 0xFFFF0000) >> 16); + } + return; + default: + Step = (1 << (Start - 5)); + for ( k = 0; k < nWords; k += 4*Step ) + { + for ( i = 0; i < Step; i++ ) + pOut[i] = pIn[i]; + for ( i = 0; i < Step; i++ ) + pOut[Step+i] = pIn[2*Step+i]; + for ( i = 0; i < Step; i++ ) + pOut[2*Step+i] = pIn[Step+i]; + for ( i = 0; i < Step; i++ ) + pOut[3*Step+i] = pIn[3*Step+i]; + pIn += 4*Step; + pOut += 4*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Expands the truth table according to the phase.] + + Description [The input and output truth tables are in pIn/pOut. The current number + of variables is nVars. The total number of variables in nVarsAll. The last argument + (Phase) contains shows where the variables should go.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthStretch( unsigned * pOut, unsigned * pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn ) +{ + unsigned * pTemp; + int i, k, Var = nVars - 1, Counter = 0; + for ( i = nVarsAll - 1; i >= 0; i-- ) + if ( Phase & (1 << i) ) + { + for ( k = Var; k < i; k++ ) + { + Kit_TruthSwapAdjacentVars( pOut, pIn, nVarsAll, k ); + pTemp = pIn; pIn = pOut; pOut = pTemp; + Counter++; + } + Var--; + } + assert( Var == -1 ); + // swap if it was moved an even number of times + if ( fReturnIn ^ !(Counter & 1) ) + Kit_TruthCopy( pOut, pIn, nVarsAll ); +} + +/**Function************************************************************* + + Synopsis [Shrinks the truth table according to the phase.] + + Description [The input and output truth tables are in pIn/pOut. The current number + of variables is nVars. The total number of variables in nVarsAll. The last argument + (Phase) contains shows what variables should remain.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthShrink( unsigned * pOut, unsigned * pIn, int nVars, int nVarsAll, unsigned Phase, int fReturnIn ) +{ + unsigned * pTemp; + int i, k, Var = 0, Counter = 0; + for ( i = 0; i < nVarsAll; i++ ) + if ( Phase & (1 << i) ) + { + for ( k = i-1; k >= Var; k-- ) + { + Kit_TruthSwapAdjacentVars( pOut, pIn, nVarsAll, k ); + pTemp = pIn; pIn = pOut; pOut = pTemp; + Counter++; + } + Var++; + } + assert( Var == nVars ); + // swap if it was moved an even number of times + if ( fReturnIn ^ !(Counter & 1) ) + Kit_TruthCopy( pOut, pIn, nVarsAll ); +} + + +/**Function************************************************************* + + Synopsis [Returns 1 if TT depends on the given variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthVarInSupport( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + if ( (pTruth[i] & 0x55555555) != ((pTruth[i] & 0xAAAAAAAA) >> 1) ) + return 1; + return 0; + case 1: + for ( i = 0; i < nWords; i++ ) + if ( (pTruth[i] & 0x33333333) != ((pTruth[i] & 0xCCCCCCCC) >> 2) ) + return 1; + return 0; + case 2: + for ( i = 0; i < nWords; i++ ) + if ( (pTruth[i] & 0x0F0F0F0F) != ((pTruth[i] & 0xF0F0F0F0) >> 4) ) + return 1; + return 0; + case 3: + for ( i = 0; i < nWords; i++ ) + if ( (pTruth[i] & 0x00FF00FF) != ((pTruth[i] & 0xFF00FF00) >> 8) ) + return 1; + return 0; + case 4: + for ( i = 0; i < nWords; i++ ) + if ( (pTruth[i] & 0x0000FFFF) != ((pTruth[i] & 0xFFFF0000) >> 16) ) + return 1; + return 0; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + if ( pTruth[i] != pTruth[Step+i] ) + return 1; + pTruth += 2*Step; + } + return 0; + } +} + +/**Function************************************************************* + + Synopsis [Returns the number of support vars.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthSupportSize( unsigned * pTruth, int nVars ) +{ + int i, Counter = 0; + for ( i = 0; i < nVars; i++ ) + Counter += Kit_TruthVarInSupport( pTruth, nVars, i ); + return Counter; +} + +/**Function************************************************************* + + Synopsis [Returns support of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_TruthSupport( unsigned * pTruth, int nVars ) +{ + int i, Support = 0; + for ( i = 0; i < nVars; i++ ) + if ( Kit_TruthVarInSupport( pTruth, nVars, i ) ) + Support |= (1 << i); + return Support; +} + + + +/**Function************************************************************* + + Synopsis [Computes negative cofactor of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCofactor0( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0x55555555) | ((pTruth[i] & 0x55555555) << 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0x33333333) | ((pTruth[i] & 0x33333333) << 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0x0F0F0F0F) | ((pTruth[i] & 0x0F0F0F0F) << 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0x00FF00FF) | ((pTruth[i] & 0x00FF00FF) << 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0x0000FFFF) | ((pTruth[i] & 0x0000FFFF) << 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + pTruth[Step+i] = pTruth[i]; + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Computes positive cofactor of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCofactor1( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0xAAAAAAAA) | ((pTruth[i] & 0xAAAAAAAA) >> 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0xCCCCCCCC) | ((pTruth[i] & 0xCCCCCCCC) >> 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0xF0F0F0F0) | ((pTruth[i] & 0xF0F0F0F0) >> 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0xFF00FF00) | ((pTruth[i] & 0xFF00FF00) >> 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = (pTruth[i] & 0xFFFF0000) | ((pTruth[i] & 0xFFFF0000) >> 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + pTruth[i] = pTruth[Step+i]; + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Computes positive cofactor of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCofactor0New( unsigned * pOut, unsigned * pIn, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x55555555) | ((pIn[i] & 0x55555555) << 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x33333333) | ((pIn[i] & 0x33333333) << 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x0F0F0F0F) | ((pIn[i] & 0x0F0F0F0F) << 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x00FF00FF) | ((pIn[i] & 0x00FF00FF) << 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0x0000FFFF) | ((pIn[i] & 0x0000FFFF) << 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + pOut[i] = pOut[Step+i] = pIn[i]; + pIn += 2*Step; + pOut += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Computes positive cofactor of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCofactor1New( unsigned * pOut, unsigned * pIn, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xAAAAAAAA) | ((pIn[i] & 0xAAAAAAAA) >> 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xCCCCCCCC) | ((pIn[i] & 0xCCCCCCCC) >> 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xF0F0F0F0) | ((pIn[i] & 0xF0F0F0F0) >> 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xFF00FF00) | ((pIn[i] & 0xFF00FF00) >> 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pIn[i] & 0xFFFF0000) | ((pIn[i] & 0xFFFF0000) >> 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + pOut[i] = pOut[Step+i] = pIn[Step+i]; + pIn += 2*Step; + pOut += 2*Step; + } + return; + } +} + + +/**Function************************************************************* + + Synopsis [Existentially quantifies the variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthExist( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pTruth[i] |= ((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pTruth[i] |= ((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pTruth[i] |= ((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pTruth[i] |= ((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pTruth[i] |= ((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pTruth[i] |= pTruth[Step+i]; + pTruth[Step+i] = pTruth[i]; + } + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Existentially quantifies the variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthExistNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] | ((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] | ((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] | ((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] | ((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] | ((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pRes[i] = pTruth[i] | pTruth[Step+i]; + pRes[Step+i] = pRes[i]; + } + pRes += 2*Step; + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Existantially quantifies the set of variables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthExistSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask ) +{ + int v; + Kit_TruthCopy( pRes, pTruth, nVars ); + for ( v = 0; v < nVars; v++ ) + if ( uMask & (1 << v) ) + Kit_TruthExist( pRes, nVars, v ); +} + +/**Function************************************************************* + + Synopsis [Unversally quantifies the variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthForall( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pTruth[i] &= ((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pTruth[i] &= ((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pTruth[i] &= ((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pTruth[i] &= ((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pTruth[i] &= ((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pTruth[i] &= pTruth[Step+i]; + pTruth[Step+i] = pTruth[i]; + } + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Universally quantifies the variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthForallNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] & (((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1)); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] & (((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2)); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] & (((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4)); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] & (((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8)); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] & (((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16)); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pRes[i] = pTruth[i] & pTruth[Step+i]; + pRes[Step+i] = pRes[i]; + } + pRes += 2*Step; + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Universally quantifies the variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthUniqueNew( unsigned * pRes, unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] ^ (((pTruth[i] & 0xAAAAAAAA) >> 1) | ((pTruth[i] & 0x55555555) << 1)); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] ^ (((pTruth[i] & 0xCCCCCCCC) >> 2) | ((pTruth[i] & 0x33333333) << 2)); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] ^ (((pTruth[i] & 0xF0F0F0F0) >> 4) | ((pTruth[i] & 0x0F0F0F0F) << 4)); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] ^ (((pTruth[i] & 0xFF00FF00) >> 8) | ((pTruth[i] & 0x00FF00FF) << 8)); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pRes[i] = pTruth[i] ^ (((pTruth[i] & 0xFFFF0000) >> 16) | ((pTruth[i] & 0x0000FFFF) << 16)); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pRes[i] = pTruth[i] ^ pTruth[Step+i]; + pRes[Step+i] = pRes[i]; + } + pRes += 2*Step; + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Universally quantifies the set of variables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthForallSet( unsigned * pRes, unsigned * pTruth, int nVars, unsigned uMask ) +{ + int v; + Kit_TruthCopy( pRes, pTruth, nVars ); + for ( v = 0; v < nVars; v++ ) + if ( uMask & (1 << v) ) + Kit_TruthForall( pRes, nVars, v ); +} + + +/**Function************************************************************* + + Synopsis [Computes negative cofactor of the function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthMuxVar( unsigned * pOut, unsigned * pCof0, unsigned * pCof1, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pCof0[i] & 0x55555555) | (pCof1[i] & 0xAAAAAAAA); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pCof0[i] & 0x33333333) | (pCof1[i] & 0xCCCCCCCC); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pCof0[i] & 0x0F0F0F0F) | (pCof1[i] & 0xF0F0F0F0); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pCof0[i] & 0x00FF00FF) | (pCof1[i] & 0xFF00FF00); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pOut[i] = (pCof0[i] & 0x0000FFFF) | (pCof1[i] & 0xFFFF0000); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + pOut[i] = pCof0[i]; + pOut[Step+i] = pCof1[Step+i]; + } + pOut += 2*Step; + pCof0 += 2*Step; + pCof1 += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Checks symmetry of two variables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthVarsSymm( unsigned * pTruth, int nVars, int iVar0, int iVar1 ) +{ + static unsigned uTemp0[16], uTemp1[16]; + assert( nVars <= 9 ); + // compute Cof01 + Kit_TruthCopy( uTemp0, pTruth, nVars ); + Kit_TruthCofactor0( uTemp0, nVars, iVar0 ); + Kit_TruthCofactor1( uTemp0, nVars, iVar1 ); + // compute Cof10 + Kit_TruthCopy( uTemp1, pTruth, nVars ); + Kit_TruthCofactor1( uTemp1, nVars, iVar0 ); + Kit_TruthCofactor0( uTemp1, nVars, iVar1 ); + // compare + return Kit_TruthIsEqual( uTemp0, uTemp1, nVars ); +} + +/**Function************************************************************* + + Synopsis [Checks antisymmetry of two variables.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthVarsAntiSymm( unsigned * pTruth, int nVars, int iVar0, int iVar1 ) +{ + static unsigned uTemp0[16], uTemp1[16]; + assert( nVars <= 9 ); + // compute Cof00 + Kit_TruthCopy( uTemp0, pTruth, nVars ); + Kit_TruthCofactor0( uTemp0, nVars, iVar0 ); + Kit_TruthCofactor0( uTemp0, nVars, iVar1 ); + // compute Cof11 + Kit_TruthCopy( uTemp1, pTruth, nVars ); + Kit_TruthCofactor1( uTemp1, nVars, iVar0 ); + Kit_TruthCofactor1( uTemp1, nVars, iVar1 ); + // compare + return Kit_TruthIsEqual( uTemp0, uTemp1, nVars ); +} + +/**Function************************************************************* + + Synopsis [Changes phase of the function w.r.t. one variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthChangePhase( unsigned * pTruth, int nVars, int iVar ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Step; + unsigned Temp; + + assert( iVar < nVars ); + switch ( iVar ) + { + case 0: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = ((pTruth[i] & 0x55555555) << 1) | ((pTruth[i] & 0xAAAAAAAA) >> 1); + return; + case 1: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = ((pTruth[i] & 0x33333333) << 2) | ((pTruth[i] & 0xCCCCCCCC) >> 2); + return; + case 2: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = ((pTruth[i] & 0x0F0F0F0F) << 4) | ((pTruth[i] & 0xF0F0F0F0) >> 4); + return; + case 3: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = ((pTruth[i] & 0x00FF00FF) << 8) | ((pTruth[i] & 0xFF00FF00) >> 8); + return; + case 4: + for ( i = 0; i < nWords; i++ ) + pTruth[i] = ((pTruth[i] & 0x0000FFFF) << 16) | ((pTruth[i] & 0xFFFF0000) >> 16); + return; + default: + Step = (1 << (iVar - 5)); + for ( k = 0; k < nWords; k += 2*Step ) + { + for ( i = 0; i < Step; i++ ) + { + Temp = pTruth[i]; + pTruth[i] = pTruth[Step+i]; + pTruth[Step+i] = Temp; + } + pTruth += 2*Step; + } + return; + } +} + +/**Function************************************************************* + + Synopsis [Computes minimum overlap in supports of cofactors.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthMinCofSuppOverlap( unsigned * pTruth, int nVars, int * pVarMin ) +{ + static unsigned uCofactor[16]; + int i, ValueCur, ValueMin, VarMin; + unsigned uSupp0, uSupp1; + int nVars0, nVars1; + assert( nVars <= 9 ); + ValueMin = 32; + VarMin = -1; + for ( i = 0; i < nVars; i++ ) + { + // get negative cofactor + Kit_TruthCopy( uCofactor, pTruth, nVars ); + Kit_TruthCofactor0( uCofactor, nVars, i ); + uSupp0 = Kit_TruthSupport( uCofactor, nVars ); + nVars0 = Kit_WordCountOnes( uSupp0 ); +//Kit_PrintBinary( stdout, &uSupp0, 8 ); printf( "\n" ); + // get positive cofactor + Kit_TruthCopy( uCofactor, pTruth, nVars ); + Kit_TruthCofactor1( uCofactor, nVars, i ); + uSupp1 = Kit_TruthSupport( uCofactor, nVars ); + nVars1 = Kit_WordCountOnes( uSupp1 ); +//Kit_PrintBinary( stdout, &uSupp1, 8 ); printf( "\n" ); + // get the number of common vars + ValueCur = Kit_WordCountOnes( uSupp0 & uSupp1 ); + if ( ValueMin > ValueCur && nVars0 <= 5 && nVars1 <= 5 ) + { + ValueMin = ValueCur; + VarMin = i; + } + if ( ValueMin == 0 ) + break; + } + if ( pVarMin ) + *pVarMin = VarMin; + return ValueMin; +} + + +/**Function************************************************************* + + Synopsis [Find the best cofactoring variable.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthBestCofVar( unsigned * pTruth, int nVars, unsigned * pCof0, unsigned * pCof1 ) +{ + int i, iBestVar, nSuppSizeCur0, nSuppSizeCur1, nSuppSizeCur, nSuppSizeMin; + if ( Kit_TruthIsConst0(pTruth, nVars) || Kit_TruthIsConst1(pTruth, nVars) ) + return -1; + // iterate through variables + iBestVar = -1; + nSuppSizeMin = KIT_INFINITY; + for ( i = 0; i < nVars; i++ ) + { + // cofactor the functiona and get support sizes + Kit_TruthCofactor0New( pCof0, pTruth, nVars, i ); + Kit_TruthCofactor1New( pCof1, pTruth, nVars, i ); + nSuppSizeCur0 = Kit_TruthSupportSize( pCof0, nVars ); + nSuppSizeCur1 = Kit_TruthSupportSize( pCof1, nVars ); + nSuppSizeCur = nSuppSizeCur0 + nSuppSizeCur1; + // compare this variable with other variables + if ( nSuppSizeMin > nSuppSizeCur ) + { + nSuppSizeMin = nSuppSizeCur; + iBestVar = i; + } + } + assert( iBestVar != -1 ); + // cofactor w.r.t. this variable + Kit_TruthCofactor0New( pCof0, pTruth, nVars, iBestVar ); + Kit_TruthCofactor1New( pCof1, pTruth, nVars, iBestVar ); + return iBestVar; +} + + +/**Function************************************************************* + + Synopsis [Counts the number of 1's in each cofactor.] + + Description [The resulting numbers are stored in the array of shorts, + whose length is 2*nVars. The number of 1's is counted in a different + space than the original function. For example, if the function depends + on k variables, the cofactors are assumed to depend on k-1 variables.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCountOnesInCofs( unsigned * pTruth, int nVars, short * pStore ) +{ + int nWords = Kit_TruthWordNum( nVars ); + int i, k, Counter; + memset( pStore, 0, sizeof(short) * 2 * nVars ); + if ( nVars <= 5 ) + { + if ( nVars > 0 ) + { + pStore[2*0+0] = Kit_WordCountOnes( pTruth[0] & 0x55555555 ); + pStore[2*0+1] = Kit_WordCountOnes( pTruth[0] & 0xAAAAAAAA ); + } + if ( nVars > 1 ) + { + pStore[2*1+0] = Kit_WordCountOnes( pTruth[0] & 0x33333333 ); + pStore[2*1+1] = Kit_WordCountOnes( pTruth[0] & 0xCCCCCCCC ); + } + if ( nVars > 2 ) + { + pStore[2*2+0] = Kit_WordCountOnes( pTruth[0] & 0x0F0F0F0F ); + pStore[2*2+1] = Kit_WordCountOnes( pTruth[0] & 0xF0F0F0F0 ); + } + if ( nVars > 3 ) + { + pStore[2*3+0] = Kit_WordCountOnes( pTruth[0] & 0x00FF00FF ); + pStore[2*3+1] = Kit_WordCountOnes( pTruth[0] & 0xFF00FF00 ); + } + if ( nVars > 4 ) + { + pStore[2*4+0] = Kit_WordCountOnes( pTruth[0] & 0x0000FFFF ); + pStore[2*4+1] = Kit_WordCountOnes( pTruth[0] & 0xFFFF0000 ); + } + return; + } + // nVars >= 6 + // count 1's for all other variables + for ( k = 0; k < nWords; k++ ) + { + Counter = Kit_WordCountOnes( pTruth[k] ); + for ( i = 5; i < nVars; i++ ) + if ( k & (1 << (i-5)) ) + pStore[2*i+1] += Counter; + else + pStore[2*i+0] += Counter; + } + // count 1's for the first five variables + for ( k = 0; k < nWords/2; k++ ) + { + pStore[2*0+0] += Kit_WordCountOnes( (pTruth[0] & 0x55555555) | ((pTruth[1] & 0x55555555) << 1) ); + pStore[2*0+1] += Kit_WordCountOnes( (pTruth[0] & 0xAAAAAAAA) | ((pTruth[1] & 0xAAAAAAAA) >> 1) ); + pStore[2*1+0] += Kit_WordCountOnes( (pTruth[0] & 0x33333333) | ((pTruth[1] & 0x33333333) << 2) ); + pStore[2*1+1] += Kit_WordCountOnes( (pTruth[0] & 0xCCCCCCCC) | ((pTruth[1] & 0xCCCCCCCC) >> 2) ); + pStore[2*2+0] += Kit_WordCountOnes( (pTruth[0] & 0x0F0F0F0F) | ((pTruth[1] & 0x0F0F0F0F) << 4) ); + pStore[2*2+1] += Kit_WordCountOnes( (pTruth[0] & 0xF0F0F0F0) | ((pTruth[1] & 0xF0F0F0F0) >> 4) ); + pStore[2*3+0] += Kit_WordCountOnes( (pTruth[0] & 0x00FF00FF) | ((pTruth[1] & 0x00FF00FF) << 8) ); + pStore[2*3+1] += Kit_WordCountOnes( (pTruth[0] & 0xFF00FF00) | ((pTruth[1] & 0xFF00FF00) >> 8) ); + pStore[2*4+0] += Kit_WordCountOnes( (pTruth[0] & 0x0000FFFF) | ((pTruth[1] & 0x0000FFFF) << 16) ); + pStore[2*4+1] += Kit_WordCountOnes( (pTruth[0] & 0xFFFF0000) | ((pTruth[1] & 0xFFFF0000) >> 16) ); + pTruth += 2; + } +} + +/**Function************************************************************* + + Synopsis [Counts the number of 1's in each cofactor.] + + Description [Verifies the above procedure.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCountOnesInCofsSlow( unsigned * pTruth, int nVars, short * pStore, unsigned * pAux ) +{ + int i; + for ( i = 0; i < nVars; i++ ) + { + Kit_TruthCofactor0New( pAux, pTruth, nVars, i ); + pStore[2*i+0] = Kit_TruthCountOnes( pAux, nVars ) / 2; + Kit_TruthCofactor1New( pAux, pTruth, nVars, i ); + pStore[2*i+1] = Kit_TruthCountOnes( pAux, nVars ) / 2; + } +} + +/**Function************************************************************* + + Synopsis [Canonicize the truth table.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_TruthHash( unsigned * pIn, int nWords ) +{ + // The 1,024 smallest prime numbers used to compute the hash value + // http://www.math.utah.edu/~alfeld/math/primelist.html + static int HashPrimes[1024] = { 2, 3, 5, + 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, + 101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, + 193, 197, 199, 211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, + 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, + 409, 419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499, 503, 509, + 521, 523, 541, 547, 557, 563, 569, 571, 577, 587, 593, 599, 601, 607, 613, 617, 619, 631, + 641, 643, 647, 653, 659, 661, 673, 677, 683, 691, 701, 709, 719, 727, 733, 739, 743, 751, + 757, 761, 769, 773, 787, 797, 809, 811, 821, 823, 827, 829, 839, 853, 857, 859, 863, 877, + 881, 883, 887, 907, 911, 919, 929, 937, 941, 947, 953, 967, 971, 977, 983, 991, 997, + 1009, 1013, 1019, 1021, 1031, 1033, 1039, 1049, 1051, 1061, 1063, 1069, 1087, 1091, + 1093, 1097, 1103, 1109, 1117, 1123, 1129, 1151, 1153, 1163, 1171, 1181, 1187, 1193, + 1201, 1213, 1217, 1223, 1229, 1231, 1237, 1249, 1259, 1277, 1279, 1283, 1289, 1291, + 1297, 1301, 1303, 1307, 1319, 1321, 1327, 1361, 1367, 1373, 1381, 1399, 1409, 1423, + 1427, 1429, 1433, 1439, 1447, 1451, 1453, 1459, 1471, 1481, 1483, 1487, 1489, 1493, + 1499, 1511, 1523, 1531, 1543, 1549, 1553, 1559, 1567, 1571, 1579, 1583, 1597, 1601, + 1607, 1609, 1613, 1619, 1621, 1627, 1637, 1657, 1663, 1667, 1669, 1693, 1697, 1699, + 1709, 1721, 1723, 1733, 1741, 1747, 1753, 1759, 1777, 1783, 1787, 1789, 1801, 1811, + 1823, 1831, 1847, 1861, 1867, 1871, 1873, 1877, 1879, 1889, 1901, 1907, 1913, 1931, + 1933, 1949, 1951, 1973, 1979, 1987, 1993, 1997, 1999, 2003, 2011, 2017, 2027, 2029, + 2039, 2053, 2063, 2069, 2081, 2083, 2087, 2089, 2099, 2111, 2113, 2129, 2131, 2137, + 2141, 2143, 2153, 2161, 2179, 2203, 2207, 2213, 2221, 2237, 2239, 2243, 2251, 2267, + 2269, 2273, 2281, 2287, 2293, 2297, 2309, 2311, 2333, 2339, 2341, 2347, 2351, 2357, + 2371, 2377, 2381, 2383, 2389, 2393, 2399, 2411, 2417, 2423, 2437, 2441, 2447, 2459, + 2467, 2473, 2477, 2503, 2521, 2531, 2539, 2543, 2549, 2551, 2557, 2579, 2591, 2593, + 2609, 2617, 2621, 2633, 2647, 2657, 2659, 2663, 2671, 2677, 2683, 2687, 2689, 2693, + 2699, 2707, 2711, 2713, 2719, 2729, 2731, 2741, 2749, 2753, 2767, 2777, 2789, 2791, + 2797, 2801, 2803, 2819, 2833, 2837, 2843, 2851, 2857, 2861, 2879, 2887, 2897, 2903, + 2909, 2917, 2927, 2939, 2953, 2957, 2963, 2969, 2971, 2999, 3001, 3011, 3019, 3023, + 3037, 3041, 3049, 3061, 3067, 3079, 3083, 3089, 3109, 3119, 3121, 3137, 3163, 3167, + 3169, 3181, 3187, 3191, 3203, 3209, 3217, 3221, 3229, 3251, 3253, 3257, 3259, 3271, + 3299, 3301, 3307, 3313, 3319, 3323, 3329, 3331, 3343, 3347, 3359, 3361, 3371, 3373, + 3389, 3391, 3407, 3413, 3433, 3449, 3457, 3461, 3463, 3467, 3469, 3491, 3499, 3511, + 3517, 3527, 3529, 3533, 3539, 3541, 3547, 3557, 3559, 3571, 3581, 3583, 3593, 3607, + 3613, 3617, 3623, 3631, 3637, 3643, 3659, 3671, 3673, 3677, 3691, 3697, 3701, 3709, + 3719, 3727, 3733, 3739, 3761, 3767, 3769, 3779, 3793, 3797, 3803, 3821, 3823, 3833, + 3847, 3851, 3853, 3863, 3877, 3881, 3889, 3907, 3911, 3917, 3919, 3923, 3929, 3931, + 3943, 3947, 3967, 3989, 4001, 4003, 4007, 4013, 4019, 4021, 4027, 4049, 4051, 4057, + 4073, 4079, 4091, 4093, 4099, 4111, 4127, 4129, 4133, 4139, 4153, 4157, 4159, 4177, + 4201, 4211, 4217, 4219, 4229, 4231, 4241, 4243, 4253, 4259, 4261, 4271, 4273, 4283, + 4289, 4297, 4327, 4337, 4339, 4349, 4357, 4363, 4373, 4391, 4397, 4409, 4421, 4423, + 4441, 4447, 4451, 4457, 4463, 4481, 4483, 4493, 4507, 4513, 4517, 4519, 4523, 4547, + 4549, 4561, 4567, 4583, 4591, 4597, 4603, 4621, 4637, 4639, 4643, 4649, 4651, 4657, + 4663, 4673, 4679, 4691, 4703, 4721, 4723, 4729, 4733, 4751, 4759, 4783, 4787, 4789, + 4793, 4799, 4801, 4813, 4817, 4831, 4861, 4871, 4877, 4889, 4903, 4909, 4919, 4931, + 4933, 4937, 4943, 4951, 4957, 4967, 4969, 4973, 4987, 4993, 4999, 5003, 5009, 5011, + 5021, 5023, 5039, 5051, 5059, 5077, 5081, 5087, 5099, 5101, 5107, 5113, 5119, 5147, + 5153, 5167, 5171, 5179, 5189, 5197, 5209, 5227, 5231, 5233, 5237, 5261, 5273, 5279, + 5281, 5297, 5303, 5309, 5323, 5333, 5347, 5351, 5381, 5387, 5393, 5399, 5407, 5413, + 5417, 5419, 5431, 5437, 5441, 5443, 5449, 5471, 5477, 5479, 5483, 5501, 5503, 5507, + 5519, 5521, 5527, 5531, 5557, 5563, 5569, 5573, 5581, 5591, 5623, 5639, 5641, 5647, + 5651, 5653, 5657, 5659, 5669, 5683, 5689, 5693, 5701, 5711, 5717, 5737, 5741, 5743, + 5749, 5779, 5783, 5791, 5801, 5807, 5813, 5821, 5827, 5839, 5843, 5849, 5851, 5857, + 5861, 5867, 5869, 5879, 5881, 5897, 5903, 5923, 5927, 5939, 5953, 5981, 5987, 6007, + 6011, 6029, 6037, 6043, 6047, 6053, 6067, 6073, 6079, 6089, 6091, 6101, 6113, 6121, + 6131, 6133, 6143, 6151, 6163, 6173, 6197, 6199, 6203, 6211, 6217, 6221, 6229, 6247, + 6257, 6263, 6269, 6271, 6277, 6287, 6299, 6301, 6311, 6317, 6323, 6329, 6337, 6343, + 6353, 6359, 6361, 6367, 6373, 6379, 6389, 6397, 6421, 6427, 6449, 6451, 6469, 6473, + 6481, 6491, 6521, 6529, 6547, 6551, 6553, 6563, 6569, 6571, 6577, 6581, 6599, 6607, + 6619, 6637, 6653, 6659, 6661, 6673, 6679, 6689, 6691, 6701, 6703, 6709, 6719, 6733, + 6737, 6761, 6763, 6779, 6781, 6791, 6793, 6803, 6823, 6827, 6829, 6833, 6841, 6857, + 6863, 6869, 6871, 6883, 6899, 6907, 6911, 6917, 6947, 6949, 6959, 6961, 6967, 6971, + 6977, 6983, 6991, 6997, 7001, 7013, 7019, 7027, 7039, 7043, 7057, 7069, 7079, 7103, + 7109, 7121, 7127, 7129, 7151, 7159, 7177, 7187, 7193, 7207, 7211, 7213, 7219, 7229, + 7237, 7243, 7247, 7253, 7283, 7297, 7307, 7309, 7321, 7331, 7333, 7349, 7351, 7369, + 7393, 7411, 7417, 7433, 7451, 7457, 7459, 7477, 7481, 7487, 7489, 7499, 7507, 7517, + 7523, 7529, 7537, 7541, 7547, 7549, 7559, 7561, 7573, 7577, 7583, 7589, 7591, 7603, + 7607, 7621, 7639, 7643, 7649, 7669, 7673, 7681, 7687, 7691, 7699, 7703, 7717, 7723, + 7727, 7741, 7753, 7757, 7759, 7789, 7793, 7817, 7823, 7829, 7841, 7853, 7867, 7873, + 7877, 7879, 7883, 7901, 7907, 7919, 7927, 7933, 7937, 7949, 7951, 7963, 7993, 8009, + 8011, 8017, 8039, 8053, 8059, 8069, 8081, 8087, 8089, 8093, 8101, 8111, 8117, 8123, + 8147, 8161 }; + int i; + unsigned uHashKey; + assert( nWords <= 1024 ); + uHashKey = 0; + for ( i = 0; i < nWords; i++ ) + uHashKey ^= HashPrimes[i] * pIn[i]; + return uHashKey; +} + + +/**Function************************************************************* + + Synopsis [Canonicize the truth table.] + + Description [Returns the phase. ] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +unsigned Kit_TruthSemiCanonicize( unsigned * pInOut, unsigned * pAux, int nVars, char * pCanonPerm, short * pStore ) +{ +// short pStore2[32]; + unsigned * pIn = pInOut, * pOut = pAux, * pTemp; + int nWords = Kit_TruthWordNum( nVars ); + int i, Temp, fChange, Counter;//, nOnes;//, k, j, w, Limit; + unsigned uCanonPhase; + + // canonicize output + uCanonPhase = 0; +/* + nOnes = Kit_TruthCountOnes(pIn, nVars); + if ( (nOnes > nWords * 16) )//|| ((nOnes == nWords * 16) && (pIn[0] & 1)) ) + { + uCanonPhase |= (1 << nVars); + Kit_TruthNot( pIn, pIn, nVars ); + } +*/ + // collect the minterm counts + Kit_TruthCountOnesInCofs( pIn, nVars, pStore ); +// Kit_TruthCountOnesInCofsSlow( pIn, nVars, pStore2, pAux ); +// for ( i = 0; i < 2*nVars; i++ ) +// { +// assert( pStore[i] == pStore2[i] ); +// } + + // canonicize phase + for ( i = 0; i < nVars; i++ ) + { + if ( pStore[2*i+0] >= pStore[2*i+1] ) + continue; + uCanonPhase |= (1 << i); + Temp = pStore[2*i+0]; + pStore[2*i+0] = pStore[2*i+1]; + pStore[2*i+1] = Temp; + Kit_TruthChangePhase( pIn, nVars, i ); + } + +// Kit_PrintHexadecimal( stdout, pIn, nVars ); +// printf( "\n" ); + + // permute + Counter = 0; + do { + fChange = 0; + for ( i = 0; i < nVars-1; i++ ) + { + if ( pStore[2*i] >= pStore[2*(i+1)] ) + continue; + Counter++; + fChange = 1; + + Temp = pCanonPerm[i]; + pCanonPerm[i] = pCanonPerm[i+1]; + pCanonPerm[i+1] = Temp; + + Temp = pStore[2*i]; + pStore[2*i] = pStore[2*(i+1)]; + pStore[2*(i+1)] = Temp; + + Temp = pStore[2*i+1]; + pStore[2*i+1] = pStore[2*(i+1)+1]; + pStore[2*(i+1)+1] = Temp; + + // if the polarity of variables is different, swap them + if ( ((uCanonPhase & (1 << i)) > 0) != ((uCanonPhase & (1 << (i+1))) > 0) ) + { + uCanonPhase ^= (1 << i); + uCanonPhase ^= (1 << (i+1)); + } + + Kit_TruthSwapAdjacentVars( pOut, pIn, nVars, i ); + pTemp = pIn; pIn = pOut; pOut = pTemp; + } + } while ( fChange ); + +/* + Extra_PrintBinary( stdout, &uCanonPhase, nVars+1 ); printf( " : " ); + for ( i = 0; i < nVars; i++ ) + printf( "%d=%d/%d ", pCanonPerm[i], pStore[2*i], pStore[2*i+1] ); + printf( " C = %d\n", Counter ); + Extra_PrintHexadecimal( stdout, pIn, nVars ); + printf( "\n" ); +*/ + +/* + // process symmetric variable groups + uSymms = 0; + for ( i = 0; i < nVars-1; i++ ) + { + if ( pStore[2*i] != pStore[2*(i+1)] ) // i and i+1 cannot be symmetric + continue; + if ( pStore[2*i] != pStore[2*i+1] ) + continue; + if ( Kit_TruthVarsSymm( pIn, nVars, i, i+1 ) ) + continue; + if ( Kit_TruthVarsAntiSymm( pIn, nVars, i, i+1 ) ) + Kit_TruthChangePhase( pIn, nVars, i+1 ); + } +*/ + +/* + // process symmetric variable groups + uSymms = 0; + for ( i = 0; i < nVars-1; i++ ) + { + if ( pStore[2*i] != pStore[2*(i+1)] ) // i and i+1 cannot be symmetric + continue; + // i and i+1 can be symmetric + // find the end of this group + for ( k = i+1; k < nVars; k++ ) + if ( pStore[2*i] != pStore[2*k] ) + break; + Limit = k; + assert( i < Limit-1 ); + // go through the variables in this group + for ( j = i + 1; j < Limit; j++ ) + { + // check symmetry + if ( Kit_TruthVarsSymm( pIn, nVars, i, j ) ) + { + uSymms |= (1 << j); + continue; + } + // they are phase-unknown + if ( pStore[2*i] == pStore[2*i+1] ) + { + if ( Kit_TruthVarsAntiSymm( pIn, nVars, i, j ) ) + { + Kit_TruthChangePhase( pIn, nVars, j ); + uCanonPhase ^= (1 << j); + uSymms |= (1 << j); + continue; + } + } + + // they are not symmetric - move j as far as it goes in the group + for ( k = j; k < Limit-1; k++ ) + { + Counter++; + + Temp = pCanonPerm[k]; + pCanonPerm[k] = pCanonPerm[k+1]; + pCanonPerm[k+1] = Temp; + + assert( pStore[2*k] == pStore[2*(k+1)] ); + Kit_TruthSwapAdjacentVars( pOut, pIn, nVars, k ); + pTemp = pIn; pIn = pOut; pOut = pTemp; + } + Limit--; + j--; + } + i = Limit - 1; + } +*/ + + // swap if it was moved an even number of times + if ( Counter & 1 ) + Kit_TruthCopy( pOut, pIn, nVars ); + return uCanonPhase; +} + + +/**Function************************************************************* + + Synopsis [Fast counting minterms in the cofactors of a function.] + + Description [Returns the total number of minterms in the function. + The resulting array (pRes) contains the number of minterms in 0-cofactor + w.r.t. each variables. The additional array (pBytes) is used for internal + storage. It should have the size equal to the number of truth table bytes.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +int Kit_TruthCountMinterms( unsigned * pTruth, int nVars, int * pRes, int * pBytes ) +{ + // the number of 1s if every byte as well as in the 0-cofactors w.r.t. three variables + static unsigned Table[256] = { + 0x00000000, 0x01010101, 0x01010001, 0x02020102, 0x01000101, 0x02010202, 0x02010102, 0x03020203, + 0x01000001, 0x02010102, 0x02010002, 0x03020103, 0x02000102, 0x03010203, 0x03010103, 0x04020204, + 0x00010101, 0x01020202, 0x01020102, 0x02030203, 0x01010202, 0x02020303, 0x02020203, 0x03030304, + 0x01010102, 0x02020203, 0x02020103, 0x03030204, 0x02010203, 0x03020304, 0x03020204, 0x04030305, + 0x00010001, 0x01020102, 0x01020002, 0x02030103, 0x01010102, 0x02020203, 0x02020103, 0x03030204, + 0x01010002, 0x02020103, 0x02020003, 0x03030104, 0x02010103, 0x03020204, 0x03020104, 0x04030205, + 0x00020102, 0x01030203, 0x01030103, 0x02040204, 0x01020203, 0x02030304, 0x02030204, 0x03040305, + 0x01020103, 0x02030204, 0x02030104, 0x03040205, 0x02020204, 0x03030305, 0x03030205, 0x04040306, + 0x00000101, 0x01010202, 0x01010102, 0x02020203, 0x01000202, 0x02010303, 0x02010203, 0x03020304, + 0x01000102, 0x02010203, 0x02010103, 0x03020204, 0x02000203, 0x03010304, 0x03010204, 0x04020305, + 0x00010202, 0x01020303, 0x01020203, 0x02030304, 0x01010303, 0x02020404, 0x02020304, 0x03030405, + 0x01010203, 0x02020304, 0x02020204, 0x03030305, 0x02010304, 0x03020405, 0x03020305, 0x04030406, + 0x00010102, 0x01020203, 0x01020103, 0x02030204, 0x01010203, 0x02020304, 0x02020204, 0x03030305, + 0x01010103, 0x02020204, 0x02020104, 0x03030205, 0x02010204, 0x03020305, 0x03020205, 0x04030306, + 0x00020203, 0x01030304, 0x01030204, 0x02040305, 0x01020304, 0x02030405, 0x02030305, 0x03040406, + 0x01020204, 0x02030305, 0x02030205, 0x03040306, 0x02020305, 0x03030406, 0x03030306, 0x04040407, + 0x00000001, 0x01010102, 0x01010002, 0x02020103, 0x01000102, 0x02010203, 0x02010103, 0x03020204, + 0x01000002, 0x02010103, 0x02010003, 0x03020104, 0x02000103, 0x03010204, 0x03010104, 0x04020205, + 0x00010102, 0x01020203, 0x01020103, 0x02030204, 0x01010203, 0x02020304, 0x02020204, 0x03030305, + 0x01010103, 0x02020204, 0x02020104, 0x03030205, 0x02010204, 0x03020305, 0x03020205, 0x04030306, + 0x00010002, 0x01020103, 0x01020003, 0x02030104, 0x01010103, 0x02020204, 0x02020104, 0x03030205, + 0x01010003, 0x02020104, 0x02020004, 0x03030105, 0x02010104, 0x03020205, 0x03020105, 0x04030206, + 0x00020103, 0x01030204, 0x01030104, 0x02040205, 0x01020204, 0x02030305, 0x02030205, 0x03040306, + 0x01020104, 0x02030205, 0x02030105, 0x03040206, 0x02020205, 0x03030306, 0x03030206, 0x04040307, + 0x00000102, 0x01010203, 0x01010103, 0x02020204, 0x01000203, 0x02010304, 0x02010204, 0x03020305, + 0x01000103, 0x02010204, 0x02010104, 0x03020205, 0x02000204, 0x03010305, 0x03010205, 0x04020306, + 0x00010203, 0x01020304, 0x01020204, 0x02030305, 0x01010304, 0x02020405, 0x02020305, 0x03030406, + 0x01010204, 0x02020305, 0x02020205, 0x03030306, 0x02010305, 0x03020406, 0x03020306, 0x04030407, + 0x00010103, 0x01020204, 0x01020104, 0x02030205, 0x01010204, 0x02020305, 0x02020205, 0x03030306, + 0x01010104, 0x02020205, 0x02020105, 0x03030206, 0x02010205, 0x03020306, 0x03020206, 0x04030307, + 0x00020204, 0x01030305, 0x01030205, 0x02040306, 0x01020305, 0x02030406, 0x02030306, 0x03040407, + 0x01020205, 0x02030306, 0x02030206, 0x03040307, 0x02020306, 0x03030407, 0x03030307, 0x04040408 + }; + unsigned uSum; + unsigned char * pTruthC, * pLimit; + int i, iVar, Step, nWords, nBytes, nTotal; + + assert( nVars <= 20 ); + + // clear storage + memset( pRes, 0, sizeof(int) * nVars ); + + // count the number of one's in 0-cofactors of the first three variables + nTotal = uSum = 0; + nWords = Kit_TruthWordNum( nVars ); + nBytes = nWords * 4; + pTruthC = (unsigned char *)pTruth; + pLimit = pTruthC + nBytes; + for ( ; pTruthC < pLimit; pTruthC++ ) + { + uSum += Table[*pTruthC]; + *pBytes++ = (Table[*pTruthC] & 0xff); + if ( (uSum & 0xff) > 246 ) + { + nTotal += (uSum & 0xff); + pRes[0] += ((uSum >> 8) & 0xff); + pRes[2] += ((uSum >> 16) & 0xff); + pRes[3] += ((uSum >> 24) & 0xff); + uSum = 0; + } + } + if ( uSum ) + { + nTotal += (uSum & 0xff); + pRes[0] += ((uSum >> 8) & 0xff); + pRes[1] += ((uSum >> 16) & 0xff); + pRes[2] += ((uSum >> 24) & 0xff); + } + + // count all other variables + for ( iVar = 3, Step = 1; Step < nBytes; Step *= 2, iVar++ ) + for ( i = 0; i < nBytes; i += Step + Step ) + { + pRes[iVar] += pBytes[i]; + pBytes[i] += pBytes[i+Step]; + } + assert( pBytes[0] == nTotal ); + assert( iVar == nVars ); + return nTotal; +} + +/**Function************************************************************* + + Synopsis [Fast counting minterms for the functions.] + + Description [Returns 0 if the function is a constant.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Kit_TruthCountMintermsPrecomp() +{ + int bit_count[256] = { + 0,1,1,2,1,2,2,3,1,2,2,3,2,3,3,4,1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 1,2,2,3,2,3,3,4,2,3,3,4,3,4,4,5,2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 2,3,3,4,3,4,4,5,3,4,4,5,4,5,5,6,3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7, + 3,4,4,5,4,5,5,6,4,5,5,6,5,6,6,7,4,5,5,6,5,6,6,7,5,6,6,7,6,7,7,8 + }; + unsigned i, uWord; + for ( i = 0; i < 256; i++ ) + { + if ( i % 8 == 0 ) + printf( "\n" ); + uWord = bit_count[i]; + uWord |= (bit_count[i & 0x55] << 8); + uWord |= (bit_count[i & 0x33] << 16); + uWord |= (bit_count[i & 0x0f] << 24); + printf( "0x" ); + Extra_PrintHexadecimal( stdout, &uWord, 5 ); + printf( ", " ); + } +} + +/**Function************************************************************* + + Synopsis [Dumps truth table into a file.] + + Description [Generates script file for reading into ABC.] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +char * Kit_TruthDumpToFile( unsigned * pTruth, int nVars, int nFile ) +{ + static char pFileName[100]; + FILE * pFile; + sprintf( pFileName, "s%03d", nFile ); + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "rt " ); + Extra_PrintHexadecimal( pFile, pTruth, nVars ); + fprintf( pFile, "; bdd; sop; ps\n" ); + fclose( pFile ); + return pFileName; +} + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/kit_.c b/src/aig/kit/kit_.c new file mode 100644 index 00000000..5c68ee3c --- /dev/null +++ b/src/aig/kit/kit_.c @@ -0,0 +1,48 @@ +/**CFile**************************************************************** + + FileName [kit_.c] + + SystemName [ABC: Logic synthesis and verification system.] + + PackageName [Computation kit.] + + Synopsis [] + + Author [Alan Mishchenko] + + Affiliation [UC Berkeley] + + Date [Ver. 1.0. Started - Dec 6, 2006.] + + Revision [$Id: kit_.c,v 1.00 2006/12/06 00:00:00 alanmi Exp $] + +***********************************************************************/ + +#include "kit.h" + +//////////////////////////////////////////////////////////////////////// +/// DECLARATIONS /// +//////////////////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////////////////// +/// FUNCTION DEFINITIONS /// +//////////////////////////////////////////////////////////////////////// + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ + + +//////////////////////////////////////////////////////////////////////// +/// END OF FILE /// +//////////////////////////////////////////////////////////////////////// + + diff --git a/src/aig/kit/module.make b/src/aig/kit/module.make new file mode 100644 index 00000000..a01690d0 --- /dev/null +++ b/src/aig/kit/module.make @@ -0,0 +1,8 @@ +SRC += src/aig/kit/kitBdd.c \ + src/aig/kit/kitDsd.c \ + src/aig/kit/kitFactor.c \ + src/aig/kit/kitGraph.c \ + src/aig/kit/kitHop.c \ + src/aig/kit/kitIsop.c \ + src/aig/kit/kitSop.c \ + src/aig/kit/kitTruth.c -- cgit v1.2.3