abc/src/base/abci/abcCollapse.c

300 lines
9.5 KiB
C
Raw Normal View History

2005-07-29 17:01:00 +02:00
/**CFile****************************************************************
FileName [abcCollapse.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Collapsing the network into two-levels.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: abcCollapse.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "base/abc/abc.h"
#ifdef ABC_USE_CUDD
#include "bdd/extrab/extraBdd.h"
#endif
2005-07-29 17:01:00 +02:00
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_START
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#ifdef ABC_USE_CUDD
2005-08-31 17:01:00 +02:00
static Abc_Ntk_t * Abc_NtkFromGlobalBdds( Abc_Ntk_t * pNtk );
2005-07-29 17:01:00 +02:00
static Abc_Obj_t * Abc_NodeFromGlobalBdds( Abc_Ntk_t * pNtkNew, DdManager * dd, DdNode * bFunc );
extern int Abc_NodeSupport( DdNode * bFunc, Vec_Str_t * vSupport, int nVars );
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
2008-01-31 05:01:00 +01:00
/// FUNCTION DEFINITIONS ///
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Makes nodes minimum base.]
Description [Returns the number of changed nodes.]
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_NodeMinimumBase2( Abc_Obj_t * pNode )
{
Vec_Str_t * vSupport;
Vec_Ptr_t * vFanins;
DdNode * bTemp;
int i, nVars;
assert( Abc_NtkIsBddLogic(pNode->pNtk) );
assert( Abc_ObjIsNode(pNode) );
// compute support
vSupport = Vec_StrAlloc( 10 );
nVars = Abc_NodeSupport( Cudd_Regular(pNode->pData), vSupport, Abc_ObjFaninNum(pNode) );
if ( nVars == Abc_ObjFaninNum(pNode) )
{
Vec_StrFree( vSupport );
return 0;
}
// add fanins
vFanins = Vec_PtrAlloc( Abc_ObjFaninNum(pNode) );
Abc_NodeCollectFanins( pNode, vFanins );
Vec_IntClear( &pNode->vFanins );
for ( i = 0; i < vFanins->nSize; i++ )
if ( vSupport->pArray[i] != 0 ) // useful
Vec_IntPush( &pNode->vFanins, Abc_ObjId((Abc_Obj_t *)vFanins->pArray[i]) );
assert( nVars == Abc_ObjFaninNum(pNode) );
// update the function of the node
pNode->pData = Extra_bddRemapUp( (DdManager *)pNode->pNtk->pManFunc, bTemp = (DdNode *)pNode->pData ); Cudd_Ref( (DdNode *)pNode->pData );
Cudd_RecursiveDeref( (DdManager *)pNode->pNtk->pManFunc, bTemp );
Vec_PtrFree( vFanins );
Vec_StrFree( vSupport );
return 1;
}
int Abc_NtkMinimumBase2( Abc_Ntk_t * pNtk )
{
Abc_Obj_t * pNode, * pFanin;
int i, k, Counter;
assert( Abc_NtkIsBddLogic(pNtk) );
// remove all fanouts
Abc_NtkForEachObj( pNtk, pNode, i )
Vec_IntClear( &pNode->vFanouts );
// add useful fanins
Counter = 0;
Abc_NtkForEachNode( pNtk, pNode, i )
Counter += Abc_NodeMinimumBase2( pNode );
// add fanouts
Abc_NtkForEachObj( pNtk, pNode, i )
Abc_ObjForEachFanin( pNode, pFanin, k )
Vec_IntPush( &pFanin->vFanouts, Abc_ObjId(pNode) );
return Counter;
}
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis [Collapses the network.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2008-01-31 05:01:00 +01:00
Abc_Ntk_t * Abc_NtkCollapse( Abc_Ntk_t * pNtk, int fBddSizeMax, int fDualRail, int fReorder, int fVerbose )
2005-07-29 17:01:00 +02:00
{
Abc_Ntk_t * pNtkNew;
abctime clk = Abc_Clock();
2005-07-29 17:01:00 +02:00
2005-08-29 17:01:00 +02:00
assert( Abc_NtkIsStrash(pNtk) );
2005-08-07 17:01:00 +02:00
// compute the global BDDs
2008-01-31 05:01:00 +01:00
if ( Abc_NtkBuildGlobalBdds(pNtk, fBddSizeMax, 1, fReorder, fVerbose) == NULL )
2005-07-29 17:01:00 +02:00
return NULL;
if ( fVerbose )
2008-01-31 05:01:00 +01:00
{
DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
2008-01-31 05:01:00 +01:00
printf( "Shared BDD size = %6d nodes. ", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );
ABC_PRT( "BDD construction time", Abc_Clock() - clk );
2008-01-31 05:01:00 +01:00
}
2005-07-29 17:01:00 +02:00
2005-08-07 17:01:00 +02:00
// create the new network
2006-08-24 17:01:00 +02:00
pNtkNew = Abc_NtkFromGlobalBdds( pNtk );
2008-01-31 05:01:00 +01:00
// Abc_NtkFreeGlobalBdds( pNtk );
Abc_NtkFreeGlobalBdds( pNtk, 1 );
2005-07-29 17:01:00 +02:00
if ( pNtkNew == NULL )
{
2008-01-31 05:01:00 +01:00
// Cudd_Quit( pNtk->pManGlob );
// pNtk->pManGlob = NULL;
2005-07-29 17:01:00 +02:00
return NULL;
}
2008-01-31 05:01:00 +01:00
// Extra_StopManager( pNtk->pManGlob );
// pNtk->pManGlob = NULL;
2005-07-29 17:01:00 +02:00
// make the network minimum base
Abc_NtkMinimumBase2( pNtkNew );
2005-07-29 17:01:00 +02:00
2008-01-31 05:01:00 +01:00
if ( pNtk->pExdc )
pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );
2005-07-29 17:01:00 +02:00
// make sure that everything is okay
2005-09-05 17:01:00 +02:00
if ( !Abc_NtkCheck( pNtkNew ) )
2005-07-29 17:01:00 +02:00
{
printf( "Abc_NtkCollapse: The network check has failed.\n" );
Abc_NtkDelete( pNtkNew );
return NULL;
}
return pNtkNew;
}
2008-01-31 05:01:00 +01:00
//int runtime1, runtime2;
2005-07-29 17:01:00 +02:00
/**Function*************************************************************
Synopsis [Derives the network with the given global BDD.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
2005-08-31 17:01:00 +02:00
Abc_Ntk_t * Abc_NtkFromGlobalBdds( Abc_Ntk_t * pNtk )
2005-07-29 17:01:00 +02:00
{
2008-01-31 05:01:00 +01:00
// extern void Extra_ShuffleTest( reo_man * p, DdManager * dd, DdNode * Func );
// reo_man * pReo;
2005-07-29 17:01:00 +02:00
ProgressBar * pProgress;
Abc_Ntk_t * pNtkNew;
2008-01-31 05:01:00 +01:00
Abc_Obj_t * pNode, * pDriver, * pNodeNew;
// DdManager * dd = pNtk->pManGlob;
DdManager * dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );
2005-07-29 17:01:00 +02:00
int i;
2008-01-31 05:01:00 +01:00
// extract don't-care and compute ISOP
if ( pNtk->pExdc )
{
DdManager * ddExdc = NULL;
DdNode * bBddMin, * bBddDc, * bBddL, * bBddU;
assert( Abc_NtkIsStrash(pNtk->pExdc) );
assert( Abc_NtkCoNum(pNtk->pExdc) == 1 );
// compute the global BDDs
if ( Abc_NtkBuildGlobalBdds(pNtk->pExdc, 10000000, 1, 1, 0) == NULL )
return NULL;
// transfer tot the same manager
ddExdc = (DdManager *)Abc_NtkGlobalBddMan( pNtk->pExdc );
bBddDc = (DdNode *)Abc_ObjGlobalBdd(Abc_NtkCo(pNtk->pExdc, 0));
bBddDc = Cudd_bddTransfer( ddExdc, dd, bBddDc ); Cudd_Ref( bBddDc );
Abc_NtkFreeGlobalBdds( pNtk->pExdc, 1 );
// minimize the output
Abc_NtkForEachCo( pNtk, pNode, i )
{
bBddMin = (DdNode *)Abc_ObjGlobalBdd(pNode);
// derive lower and uppwer bound
bBddL = Cudd_bddAnd( dd, bBddMin, Cudd_Not(bBddDc) ); Cudd_Ref( bBddL );
bBddU = Cudd_bddAnd( dd, Cudd_Not(bBddMin), Cudd_Not(bBddDc) ); Cudd_Ref( bBddU );
Cudd_RecursiveDeref( dd, bBddMin );
// compute new one
bBddMin = Cudd_bddIsop( dd, bBddL, Cudd_Not(bBddU) ); Cudd_Ref( bBddMin );
Cudd_RecursiveDeref( dd, bBddL );
Cudd_RecursiveDeref( dd, bBddU );
// update global BDD
Abc_ObjSetGlobalBdd( pNode, bBddMin );
//Extra_bddPrint( dd, bBddMin ); printf( "\n" );
}
Cudd_RecursiveDeref( dd, bBddDc );
}
2008-01-31 05:01:00 +01:00
// pReo = Extra_ReorderInit( Abc_NtkCiNum(pNtk), 1000 );
// runtime1 = runtime2 = 0;
2005-07-29 17:01:00 +02:00
// start the new network
2008-01-31 05:01:00 +01:00
pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
2005-07-29 17:01:00 +02:00
// make sure the new manager has the same number of inputs
2010-11-01 09:35:04 +01:00
Cudd_bddIthVar( (DdManager *)pNtkNew->pManFunc, dd->size-1 );
2005-07-29 17:01:00 +02:00
// process the POs
pProgress = Extra_ProgressBarStart( stdout, Abc_NtkCoNum(pNtk) );
Abc_NtkForEachCo( pNtk, pNode, i )
{
Extra_ProgressBarUpdate( pProgress, i, NULL );
2008-01-31 05:01:00 +01:00
pDriver = Abc_ObjFanin0(pNode);
if ( Abc_ObjIsCi(pDriver) && !strcmp(Abc_ObjName(pNode), Abc_ObjName(pDriver)) )
{
Abc_ObjAddFanin( pNode->pCopy, pDriver->pCopy );
continue;
}
// pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, Vec_PtrEntry(pNtk->vFuncsGlob, i) );
pNodeNew = Abc_NodeFromGlobalBdds( pNtkNew, dd, (DdNode *)Abc_ObjGlobalBdd(pNode) );
2005-07-29 17:01:00 +02:00
Abc_ObjAddFanin( pNode->pCopy, pNodeNew );
2008-01-31 05:01:00 +01:00
// Extra_ShuffleTest( pReo, dd, Abc_ObjGlobalBdd(pNode) );
2005-07-29 17:01:00 +02:00
}
Extra_ProgressBarStop( pProgress );
2008-01-31 05:01:00 +01:00
// Extra_ReorderQuit( pReo );
2009-02-15 17:01:00 +01:00
//ABC_PRT( "Reo ", runtime1 );
//ABC_PRT( "Cudd", runtime2 );
2008-01-31 05:01:00 +01:00
2005-07-29 17:01:00 +02:00
return pNtkNew;
}
/**Function*************************************************************
Synopsis [Derives the network with the given global BDD.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abc_Obj_t * Abc_NodeFromGlobalBdds( Abc_Ntk_t * pNtkNew, DdManager * dd, DdNode * bFunc )
{
Abc_Obj_t * pNodeNew, * pTemp;
int i;
// create a new node
pNodeNew = Abc_NtkCreateNode( pNtkNew );
// add the fanins in the order, in which they appear in the reordered manager
Abc_NtkForEachCi( pNtkNew, pTemp, i )
Abc_ObjAddFanin( pNodeNew, Abc_NtkCi(pNtkNew, dd->invperm[i]) );
// transfer the function
2010-11-01 09:35:04 +01:00
pNodeNew->pData = Extra_TransferLevelByLevel( dd, (DdManager *)pNtkNew->pManFunc, bFunc ); Cudd_Ref( (DdNode *)pNodeNew->pData );
2005-07-29 17:01:00 +02:00
return pNodeNew;
}
#else
Abc_Ntk_t * Abc_NtkCollapse( Abc_Ntk_t * pNtk, int fBddSizeMax, int fDualRail, int fReorder, int fVerbose )
{
return NULL;
}
#endif
2005-07-29 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
2010-11-01 09:35:04 +01:00
ABC_NAMESPACE_IMPL_END