abc/src/base/abci/abcRewrite.c

203 lines
6.4 KiB
C
Raw Normal View History

2005-08-07 17:01:00 +02:00
/**CFile****************************************************************
2005-09-05 17:01:00 +02:00
FileName [abcRewrite.c]
2005-08-07 17:01:00 +02:00
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
2005-09-05 17:01:00 +02:00
Synopsis [Technology-independent resynthesis of the AIG based on DAG aware rewriting.]
2005-08-07 17:01:00 +02:00
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
2005-09-05 17:01:00 +02:00
Revision [$Id: abcRewrite.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
2005-08-07 17:01:00 +02:00
***********************************************************************/
#include "abc.h"
2005-08-18 17:01:00 +02:00
#include "rwr.h"
2005-09-02 17:01:00 +02:00
#include "dec.h"
2005-08-07 17:01:00 +02:00
2005-09-05 17:01:00 +02:00
/*
The ideas realized in this package are inspired by the paper:
Per Bjesse, Arne Boralv, "DAG-aware circuit compression for
formal verification", Proc. ICCAD 2004, pp. 42-49.
*/
2005-08-07 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
2005-08-27 17:01:00 +02:00
static Cut_Man_t * Abc_NtkStartCutManForRewrite( Abc_Ntk_t * pNtk, int fDrop );
static void Abc_NodePrintCuts( Abc_Obj_t * pNode );
2005-08-07 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
2005-08-17 17:01:00 +02:00
Synopsis [Performs incremental rewriting of the AIG.]
2005-08-07 17:01:00 +02:00
2005-08-17 17:01:00 +02:00
Description []
2005-08-07 17:01:00 +02:00
SideEffects []
SeeAlso []
***********************************************************************/
2005-09-08 17:01:00 +02:00
int Abc_NtkRewrite( Abc_Ntk_t * pNtk, int fUpdateLevel, int fUseZeros, int fVerbose )
2005-08-07 17:01:00 +02:00
{
2005-08-27 17:01:00 +02:00
int fDrop = 0;
2005-08-07 17:01:00 +02:00
ProgressBar * pProgress;
2005-08-27 17:01:00 +02:00
Cut_Man_t * pManCut;
Rwr_Man_t * pManRwr;
2005-08-07 17:01:00 +02:00
Abc_Obj_t * pNode;
2005-08-17 17:01:00 +02:00
int i, nNodes, nGain;
2005-08-27 17:01:00 +02:00
int clk, clkStart = clock();
2005-08-07 17:01:00 +02:00
2005-08-29 17:01:00 +02:00
assert( Abc_NtkIsStrash(pNtk) );
2005-09-01 17:01:00 +02:00
// cleanup the AIG
Abc_AigCleanup(pNtk->pManFunc);
2005-08-17 17:01:00 +02:00
// start the rewriting manager
2005-08-27 17:01:00 +02:00
pManRwr = Rwr_ManStart( 0 );
if ( pManRwr == NULL )
2005-08-19 17:01:00 +02:00
return 0;
2005-09-08 17:01:00 +02:00
// compute the reverse levels if level update is requested
if ( fUpdateLevel )
Abc_NtkStartReverseLevels( pNtk );
2005-08-27 17:01:00 +02:00
// start the cut manager
clk = clock();
pManCut = Abc_NtkStartCutManForRewrite( pNtk, fDrop );
Rwr_ManAddTimeCuts( pManRwr, clock() - clk );
pNtk->pManCut = pManCut;
2005-08-07 17:01:00 +02:00
2005-08-17 17:01:00 +02:00
// resynthesize each node once
nNodes = Abc_NtkObjNumMax(pNtk);
pProgress = Extra_ProgressBarStart( stdout, nNodes );
2005-08-07 17:01:00 +02:00
Abc_NtkForEachNode( pNtk, pNode, i )
{
2005-08-24 17:01:00 +02:00
Extra_ProgressBarUpdate( pProgress, i, NULL );
// stop if all nodes have been tried once
if ( i >= nNodes )
break;
// skip the constant node
if ( Abc_NodeIsConst(pNode) )
continue;
2005-09-05 17:01:00 +02:00
// skip the nodes with many fanouts
if ( Abc_ObjFanoutNum(pNode) > 1000 )
continue;
2005-08-17 17:01:00 +02:00
// for each cut, try to resynthesize it
2005-09-08 17:01:00 +02:00
nGain = Rwr_NodeRewrite( pManRwr, pManCut, pNode, fUpdateLevel, fUseZeros );
2005-08-27 17:01:00 +02:00
if ( nGain > 0 || nGain == 0 && fUseZeros )
{
2005-09-02 17:01:00 +02:00
Dec_Graph_t * pGraph = Rwr_ManReadDecs(pManRwr);
int fCompl = Rwr_ManReadCompl(pManRwr);
2005-08-27 17:01:00 +02:00
// complement the FF if needed
2005-09-02 17:01:00 +02:00
if ( fCompl ) Dec_GraphComplement( pGraph );
2005-09-08 17:01:00 +02:00
clk = clock();
Dec_GraphUpdateNetwork( pNode, pGraph, fUpdateLevel, nGain );
Rwr_ManAddTimeUpdate( pManRwr, clock() - clk );
2005-09-02 17:01:00 +02:00
if ( fCompl ) Dec_GraphComplement( pGraph );
2005-08-27 17:01:00 +02:00
}
2005-08-07 17:01:00 +02:00
}
Extra_ProgressBarStop( pProgress );
2005-08-27 17:01:00 +02:00
Rwr_ManAddTimeTotal( pManRwr, clock() - clkStart );
// print stats
if ( fVerbose )
Rwr_ManPrintStats( pManRwr );
// delete the managers
Rwr_ManStop( pManRwr );
Cut_ManStop( pManCut );
pNtk->pManCut = NULL;
2005-09-08 17:01:00 +02:00
// put the nodes into the DFS order and reassign their IDs
Abc_NtkReassignIds( pNtk );
// fix the levels
if ( fUpdateLevel )
Abc_NtkStopReverseLevels( pNtk );
else
Abc_NtkGetLevelNum( pNtk );
2005-08-07 17:01:00 +02:00
// check
2005-09-05 17:01:00 +02:00
if ( !Abc_NtkCheck( pNtk ) )
2005-08-07 17:01:00 +02:00
{
2005-08-17 17:01:00 +02:00
printf( "Abc_NtkRewrite: The network check has failed.\n" );
2005-08-07 17:01:00 +02:00
return 0;
}
return 1;
}
2005-08-27 17:01:00 +02:00
/**Function*************************************************************
Synopsis [Starts the cut manager for rewriting.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Cut_Man_t * Abc_NtkStartCutManForRewrite( Abc_Ntk_t * pNtk, int fDrop )
{
static Cut_Params_t Params, * pParams = &Params;
Cut_Man_t * pManCut;
Abc_Obj_t * pObj;
int i;
// start the cut manager
memset( pParams, 0, sizeof(Cut_Params_t) );
pParams->nVarsMax = 4; // the max cut size ("k" of the k-feasible cuts)
pParams->nKeepMax = 250; // the max number of cuts kept at a node
pParams->fTruth = 1; // compute truth tables
pParams->fHash = 1; // hash cuts to detect unique
pParams->fFilter = 0; // filter dominated cuts
pParams->fSeq = 0; // compute sequential cuts
pParams->fDrop = fDrop; // drop cuts on the fly
pParams->fVerbose = 0; // the verbosiness flag
pParams->nIdsMax = Abc_NtkObjNumMax( pNtk );
pManCut = Cut_ManStart( pParams );
if ( pParams->fDrop )
Cut_ManSetFanoutCounts( pManCut, Abc_NtkFanoutCounts(pNtk) );
// set cuts for PIs
Abc_NtkForEachCi( pNtk, pObj, i )
if ( Abc_ObjFanoutNum(pObj) > 0 )
Cut_NodeSetTriv( pManCut, pObj->Id );
return pManCut;
}
/**Function*************************************************************
Synopsis [Prints the cuts at the nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NodePrintCuts( Abc_Obj_t * pNode )
{
Cut_Cut_t * pCut;
unsigned uTruth;
printf( "\nNode %s\n", Abc_ObjName(pNode) );
for ( pCut = (Cut_Cut_t *)pNode->pCopy; pCut; pCut = pCut->pNext )
{
uTruth = pCut->uTruth;
Extra_PrintBinary( stdout, &uTruth, 16 );
printf( " " );
Cut_CutPrint( pCut );
printf( "\n" );
}
}
2005-08-07 17:01:00 +02:00
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////