/**CFile**************************************************************** FileName [cutNode.c] SystemName [ABC: Logic synthesis and verification system.] PackageName [K-feasible cut computation package.] Synopsis [Procedures to compute cuts for a node.] Author [Alan Mishchenko] Affiliation [UC Berkeley] Date [Ver. 1.0. Started - June 20, 2005.] Revision [$Id: cutNode.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $] ***********************************************************************/ #include "cutInt.h" ABC_NAMESPACE_IMPL_START //////////////////////////////////////////////////////////////////////// /// DECLARATIONS /// //////////////////////////////////////////////////////////////////////// static int Cut_NodeMapping( Cut_Man_t * p, Cut_Cut_t * pCuts, int Node, int Node0, int Node1 ); static int Cut_NodeMapping2( Cut_Man_t * p, Cut_Cut_t * pCuts, int Node, int Node0, int Node1 ); //////////////////////////////////////////////////////////////////////// /// FUNCTION DEFINITIONS /// //////////////////////////////////////////////////////////////////////// /**Function************************************************************* Synopsis [Returns 1 if pDom is contained in pCut.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline int Cut_CutCheckDominance( Cut_Cut_t * pDom, Cut_Cut_t * pCut ) { int i, k; for ( i = 0; i < (int)pDom->nLeaves; i++ ) { for ( k = 0; k < (int)pCut->nLeaves; k++ ) if ( pDom->pLeaves[i] == pCut->pLeaves[k] ) break; if ( k == (int)pCut->nLeaves ) // node i in pDom is not contained in pCut return 0; } // every node in pDom is contained in pCut return 1; } /**Function************************************************************* Synopsis [Filters cuts using dominance.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ static inline void Cut_CutFilter( Cut_Man_t * p, Cut_Cut_t * pList ) { Cut_Cut_t * pListR, ** ppListR = &pListR; Cut_Cut_t * pCut, * pCut2, * pDom, * pPrev; // save the first cut *ppListR = pList, ppListR = &pList->pNext; // try to filter out other cuts pPrev = pList; Cut_ListForEachCutSafe( pList->pNext, pCut, pCut2 ) { assert( pCut->nLeaves > 1 ); // go through all the previous cuts up to pCut Cut_ListForEachCutStop( pList->pNext, pDom, pCut ) { if ( pDom->nLeaves > pCut->nLeaves ) continue; if ( (pDom->uSign & pCut->uSign) != pDom->uSign ) continue; if ( Cut_CutCheckDominance( pDom, pCut ) ) break; } if ( pDom != pCut ) // pDom is contained in pCut - recycle pCut { // make sure cuts are connected after removing pPrev->pNext = pCut->pNext; // recycle the cut Cut_CutRecycle( p, pCut ); } else // pDom is NOT contained in pCut - save pCut { *ppListR = pCut, ppListR = &pCut->pNext; pPrev = pCut; } } *ppListR = NULL; } /**Function************************************************************* Synopsis [Checks equality of one cut.] Description [Returns 1 if the cut is removed.] SideEffects [] SeeAlso [] ***********************************************************************/ static inline int Cut_CutFilterOneEqual( Cut_Man_t * p, Cut_List_t * pSuperList, Cut_Cut_t * pCut ) { Cut_Cut_t * pTemp; Cut_ListForEachCut( pSuperList->pHead[pCut->nLeaves], pTemp ) { // skip the non-contained cuts if ( pCut->uSign != pTemp->uSign ) continue; // check containment seriously if ( Cut_CutCheckDominance( pTemp, pCut ) ) { p->nCutsFilter++; Cut_CutRecycle( p, pCut ); return 1; } } return 0; } /**Function************************************************************* Synopsis [Checks containment for one cut.] Description [Returns 1 if the cut is removed.] SideEffects [May remove other cuts in the set.] SeeAlso [] ***********************************************************************/ static inline int Cut_CutFilterOne( Cut_Man_t * p, Cut_List_t * pSuperList, Cut_Cut_t * pCut ) { Cut_Cut_t * pTemp, * pTemp2, ** ppTail; int a; // check if this cut is filtered out by smaller cuts for ( a = 2; a <= (int)pCut->nLeaves; a++ ) { Cut_ListForEachCut( pSuperList->pHead[a], pTemp ) { // skip the non-contained cuts if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign ) continue; // check containment seriously if ( Cut_CutCheckDominance( pTemp, pCut ) ) { p->nCutsFilter++; Cut_CutRecycle( p, pCut ); return 1; } } } // filter out other cuts using this one for ( a = pCut->nLeaves + 1; a <= (int)pCut->nVarsMax; a++ ) { ppTail = pSuperList->pHead + a; Cut_ListForEachCutSafe( pSuperList->pHead[a], pTemp, pTemp2 ) { // skip the non-contained cuts if ( (pTemp->uSign & pCut->uSign) != pCut->uSign ) { ppTail = &pTemp->pNext; continue; } // check containment seriously if ( Cut_CutCheckDominance( pCut, pTemp ) ) { p->nCutsFilter++; p->nNodeCuts--; // move the head if ( pSuperList->pHead[a] == pTemp ) pSuperList->pHead[a] = pTemp->pNext; // move the tail if ( pSuperList->ppTail[a] == &pTemp->pNext ) pSuperList->ppTail[a] = ppTail; // skip the given cut in the list *ppTail = pTemp->pNext; // recycle pTemp Cut_CutRecycle( p, pTemp ); } else ppTail = &pTemp->pNext; } assert( ppTail == pSuperList->ppTail[a] ); assert( *ppTail == NULL ); } return 0; } /**Function************************************************************* Synopsis [Checks if the cut is local and can be removed.] Description [Returns 1 if the cut is removed.] SideEffects [] SeeAlso [] ***********************************************************************/ static inline int Cut_CutFilterGlobal( Cut_Man_t * p, Cut_Cut_t * pCut ) { int a; if ( pCut->nLeaves == 1 ) return 0; for ( a = 0; a < (int)pCut->nLeaves; a++ ) if ( Vec_IntEntry( p->vNodeAttrs, pCut->pLeaves[a] ) ) // global return 0; // there is no global nodes, the cut should be removed p->nCutsFilter++; Cut_CutRecycle( p, pCut ); return 1; } /**Function************************************************************* Synopsis [Checks containment for one cut.] Description [Returns 1 if the cut is removed.] SideEffects [May remove other cuts in the set.] SeeAlso [] ***********************************************************************/ static inline int Cut_CutFilterOld( Cut_Man_t * p, Cut_Cut_t * pList, Cut_Cut_t * pCut ) { Cut_Cut_t * pPrev, * pTemp, * pTemp2, ** ppTail; // check if this cut is filtered out by smaller cuts pPrev = NULL; Cut_ListForEachCut( pList, pTemp ) { if ( pTemp->nLeaves > pCut->nLeaves ) break; pPrev = pTemp; // skip the non-contained cuts if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign ) continue; // check containment seriously if ( Cut_CutCheckDominance( pTemp, pCut ) ) { p->nCutsFilter++; Cut_CutRecycle( p, pCut ); return 1; } } assert( pPrev->pNext == pTemp ); // filter out other cuts using this one ppTail = &pPrev->pNext; Cut_ListForEachCutSafe( pTemp, pTemp, pTemp2 ) { // skip the non-contained cuts if ( (pTemp->uSign & pCut->uSign) != pCut->uSign ) { ppTail = &pTemp->pNext; continue; } // check containment seriously if ( Cut_CutCheckDominance( pCut, pTemp ) ) { p->nCutsFilter++; p->nNodeCuts--; // skip the given cut in the list *ppTail = pTemp->pNext; // recycle pTemp Cut_CutRecycle( p, pTemp ); } else ppTail = &pTemp->pNext; } assert( *ppTail == NULL ); return 0; } /**Function************************************************************* Synopsis [Processes two cuts.] Description [Returns 1 if the limit has been reached.] SideEffects [] SeeAlso [] ***********************************************************************/ static inline int Cut_CutProcessTwo( Cut_Man_t * p, Cut_Cut_t * pCut0, Cut_Cut_t * pCut1, Cut_List_t * pSuperList ) { Cut_Cut_t * pCut; // merge the cuts if ( pCut0->nLeaves >= pCut1->nLeaves ) pCut = Cut_CutMergeTwo( p, pCut0, pCut1 ); else pCut = Cut_CutMergeTwo( p, pCut1, pCut0 ); if ( pCut == NULL ) return 0; assert( p->pParams->fSeq || pCut->nLeaves > 1 ); // set the signature pCut->uSign = pCut0->uSign | pCut1->uSign; if ( p->pParams->fRecord ) pCut->Num0 = pCut0->Num0, pCut->Num1 = pCut1->Num0; // check containment if ( p->pParams->fFilter ) { if ( Cut_CutFilterOne(p, pSuperList, pCut) ) // if ( Cut_CutFilterOneEqual(p, pSuperList, pCut) ) return 0; if ( p->pParams->fSeq ) { if ( p->pCompareOld && Cut_CutFilterOld(p, p->pCompareOld, pCut) ) return 0; if ( p->pCompareNew && Cut_CutFilterOld(p, p->pCompareNew, pCut) ) return 0; } } if ( p->pParams->fGlobal ) { assert( p->vNodeAttrs != NULL ); if ( Cut_CutFilterGlobal( p, pCut ) ) return 0; } // compute the truth table if ( p->pParams->fTruth ) Cut_TruthCompute( p, pCut, pCut0, pCut1, p->fCompl0, p->fCompl1 ); // add to the list Cut_ListAdd( pSuperList, pCut ); // return status (0 if okay; 1 if exceeded the limit) return ++p->nNodeCuts == p->pParams->nKeepMax; } /**Function************************************************************* Synopsis [Computes the cuts by merging cuts at two nodes.] Description [] SideEffects [] SeeAlso [] ***********************************************************************/ Cut_Cut_t * Cut_NodeComputeCuts( Cut_Man_t * p, int Node, int Node0, int Node1, int fCompl0, int fCompl1, int fTriv, int TreeCode ) { Cut_List_t Super, * pSuper = &Super; Cut_Cut_t * pList, * pCut; int clk; // start the number of cuts at the node p->nNodes++; p->nNodeCuts = 0; // prepare information for recording if ( p->pParams->fRecord ) { Cut_CutNumberList( Cut_NodeReadCutsNew(p, Node0) ); Cut_CutNumberList( Cut_NodeReadCutsNew(p, Node1) ); } // compute the cuts clk = clock(); Cut_ListStart( pSuper ); Cut_NodeDoComputeCuts( p, pSuper, Node, fCompl0, fCompl1, Cut_NodeReadCutsNew(p, Node0), Cut_NodeReadCutsNew(p, Node1), fTriv, TreeCode ); pList = Cut_ListFinish( pSuper ); p->timeMerge += clock() - clk; // verify the result of cut computation // Cut_CutListVerify( pList ); // performing the recordi