2008-01-31 05:01:00 +01:00
|
|
|
/**CFile****************************************************************
|
|
|
|
|
|
|
|
|
|
FileName [ifMap.c]
|
|
|
|
|
|
|
|
|
|
SystemName [ABC: Logic synthesis and verification system.]
|
|
|
|
|
|
|
|
|
|
PackageName [FPGA mapping based on priority cuts.]
|
|
|
|
|
|
|
|
|
|
Synopsis [Mapping procedures.]
|
|
|
|
|
|
|
|
|
|
Author [Alan Mishchenko]
|
|
|
|
|
|
|
|
|
|
Affiliation [UC Berkeley]
|
|
|
|
|
|
|
|
|
|
Date [Ver. 1.0. Started - November 21, 2006.]
|
|
|
|
|
|
|
|
|
|
Revision [$Id: ifMap.c,v 1.00 2006/11/21 00:00:00 alanmi Exp $]
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "if.h"
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2011-12-29 15:14:01 +01:00
|
|
|
ABC_NAMESPACE_IMPL_START
|
2010-11-01 09:35:04 +01:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// DECLARATIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-11-12 06:37:27 +01:00
|
|
|
extern char * Dau_DsdMerge( char * pDsd0i, int * pPerm0, char * pDsd1i, int * pPerm1, int fCompl0, int fCompl1, int nVars );
|
2014-02-17 04:49:10 +01:00
|
|
|
extern int If_CutDelayRecCost3(If_Man_t* p, If_Cut_t* pCut, If_Obj_t * pObj);
|
2012-11-11 04:37:53 +01:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// FUNCTION DEFINITIONS ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Counts the number of 1s in the signature.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int If_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);
|
|
|
|
|
}
|
|
|
|
|
|
2011-07-09 04:40:07 +02:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Counts the number of 1s in the signature.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
float If_CutDelaySpecial( If_Man_t * p, If_Cut_t * pCut, int fCarry )
|
|
|
|
|
{
|
|
|
|
|
static float Pin2Pin[2][3] = { {1.0, 1.0, 1.0}, {1.0, 1.0, 0.0} };
|
|
|
|
|
If_Obj_t * pLeaf;
|
|
|
|
|
float DelayCur, Delay = -IF_FLOAT_LARGE;
|
|
|
|
|
int i;
|
|
|
|
|
assert( pCut->nLeaves <= 3 );
|
|
|
|
|
If_CutForEachLeaf( p, pCut, pLeaf, i )
|
|
|
|
|
{
|
|
|
|
|
DelayCur = If_ObjCutBest(pLeaf)->Delay;
|
|
|
|
|
Delay = IF_MAX( Delay, Pin2Pin[fCarry][i] + DelayCur );
|
|
|
|
|
}
|
|
|
|
|
return Delay;
|
2012-10-26 07:10:24 +02:00
|
|
|
}
|
|
|
|
|
|
2011-07-09 04:40:07 +02:00
|
|
|
|
2012-11-11 04:37:53 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis []
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
static inline int * If_CutPerm0( If_Cut_t * pCut, If_Cut_t * pCut0 )
|
|
|
|
|
{
|
|
|
|
|
static int pPerm[IF_MAX_LUTSIZE];
|
|
|
|
|
int i, k;
|
|
|
|
|
for ( i = k = 0; i < (int)pCut->nLeaves; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( k == (int)pCut0->nLeaves )
|
|
|
|
|
break;
|
|
|
|
|
if ( pCut->pLeaves[i] < pCut0->pLeaves[k] )
|
|
|
|
|
continue;
|
|
|
|
|
assert( pCut->pLeaves[i] == pCut0->pLeaves[k] );
|
|
|
|
|
pPerm[k++] = i;
|
|
|
|
|
}
|
|
|
|
|
return pPerm;
|
|
|
|
|
}
|
|
|
|
|
static inline int * If_CutPerm1( If_Cut_t * pCut, If_Cut_t * pCut1 )
|
|
|
|
|
{
|
|
|
|
|
static int pPerm[IF_MAX_LUTSIZE];
|
|
|
|
|
int i, k;
|
|
|
|
|
for ( i = k = 0; i < (int)pCut->nLeaves; i++ )
|
|
|
|
|
{
|
|
|
|
|
if ( k == (int)pCut1->nLeaves )
|
|
|
|
|
break;
|
|
|
|
|
if ( pCut->pLeaves[i] < pCut1->pLeaves[k] )
|
|
|
|
|
continue;
|
|
|
|
|
assert( pCut->pLeaves[i] == pCut1->pLeaves[k] );
|
|
|
|
|
pPerm[k++] = i;
|
|
|
|
|
}
|
|
|
|
|
return pPerm;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Finds the best cut for the given node.]
|
|
|
|
|
|
|
|
|
|
Description [Mapping modes: delay (0), area flow (1), area (2).]
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2014-02-17 04:30:38 +01:00
|
|
|
void If_ObjPerformMappingAnd( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess, int fFirst )
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
If_Set_t * pCutSet;
|
|
|
|
|
If_Cut_t * pCut0, * pCut1, * pCut;
|
|
|
|
|
int i, k;
|
2011-07-20 13:23:10 +02:00
|
|
|
assert( p->pPars->fSeqMap || !If_ObjIsAnd(pObj->pFanin0) || pObj->pFanin0->pCutSet->nCuts > 0 );
|
|
|
|
|
assert( p->pPars->fSeqMap || !If_ObjIsAnd(pObj->pFanin1) || pObj->pFanin1->pCutSet->nCuts > 0 );
|
2008-01-31 05:01:00 +01:00
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
if ( !p->pPars->fSeqMap )
|
|
|
|
|
{
|
|
|
|
|
if ( Mode == 0 )
|
|
|
|
|
pObj->EstRefs = (float)pObj->nRefs;
|
|
|
|
|
else if ( Mode == 1 )
|
|
|
|
|
pObj->EstRefs = (float)((2.0 * pObj->EstRefs + pObj->nRefs) / 3.0);
|
|
|
|
|
}
|
2011-07-09 04:40:07 +02:00
|
|
|
// deref the selected cut
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( Mode && pObj->nRefs > 0 )
|
|
|
|
|
If_CutAreaDeref( p, If_ObjCutBest(pObj) );
|
|
|
|
|
|
|
|
|
|
// prepare the cutset
|
|
|
|
|
pCutSet = If_ManSetupNodeCutSet( p, pObj );
|
|
|
|
|
|
|
|
|
|
// get the current assigned best cut
|
|
|
|
|
pCut = If_ObjCutBest(pObj);
|
2014-02-17 04:30:38 +01:00
|
|
|
if ( !fFirst )
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
// recompute the parameters of the best cut
|
2011-12-29 15:14:01 +01:00
|
|
|
if ( p->pPars->fUserRecLib )
|
2014-02-17 04:49:10 +01:00
|
|
|
pCut->Delay = If_CutDelayRecCost3(p, pCut, pObj);
|
2011-12-29 15:14:01 +01:00
|
|
|
else if(p->pPars->fDelayOpt)
|
|
|
|
|
pCut->Delay = If_CutDelaySopCost(p,pCut);
|
2012-03-28 05:15:02 +02:00
|
|
|
else if(p->pPars->nGateSize > 0)
|
|
|
|
|
pCut->Delay = If_CutDelaySop(p,pCut);
|
2010-11-01 09:35:04 +01:00
|
|
|
else
|
2011-07-10 08:56:05 +02:00
|
|
|
pCut->Delay = If_CutDelay( p, pObj, pCut );
|
2008-04-29 17:01:00 +02:00
|
|
|
// assert( pCut->Delay <= pObj->Required + p->fEpsilon );
|
2008-05-07 17:01:00 +02:00
|
|
|
if ( pCut->Delay > pObj->Required + 2*p->fEpsilon )
|
2010-11-01 09:35:04 +01:00
|
|
|
Abc_Print( 1, "If_ObjPerformMappingAnd(): Warning! Delay of node %d (%f) exceeds the required times (%f).\n",
|
2008-04-29 17:01:00 +02:00
|
|
|
pObj->Id, pCut->Delay, pObj->Required + p->fEpsilon );
|
2008-01-31 05:01:00 +01:00
|
|
|
pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
|
|
|
|
|
if ( p->pPars->fEdge )
|
|
|
|
|
pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
|
2009-01-18 17:01:00 +01:00
|
|
|
if ( p->pPars->fPower )
|
|
|
|
|
pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
|
2008-01-31 05:01:00 +01:00
|
|
|
// save the best cut from the previous iteration
|
|
|
|
|
if ( !fPreprocess )
|
|
|
|
|
If_CutCopy( p, pCutSet->ppCuts[pCutSet->nCuts++], pCut );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// generate cuts
|
|
|
|
|
If_ObjForEachCut( pObj->pFanin0, pCut0, i )
|
|
|
|
|
If_ObjForEachCut( pObj->pFanin1, pCut1, k )
|
|
|
|
|
{
|
2010-11-01 09:35:04 +01:00
|
|
|
// get the next free cut
|
2008-01-31 05:01:00 +01:00
|
|
|
assert( pCutSet->nCuts <= pCutSet->nCutsMax );
|
|
|
|
|
pCut = pCutSet->ppCuts[pCutSet->nCuts];
|
|
|
|
|
// make sure K-feasible cut exists
|
|
|
|
|
if ( If_WordCountOnes(pCut0->uSign | pCut1->uSign) > p->pPars->nLutSize )
|
|
|
|
|
continue;
|
2010-11-01 09:35:04 +01:00
|
|
|
// merge the cuts
|
2012-11-14 05:44:34 +01:00
|
|
|
if ( !If_CutMerge( p, pCut0, pCut1, pCut ) )
|
2008-01-31 05:01:00 +01:00
|
|
|
continue;
|
2012-11-14 05:44:34 +01:00
|
|
|
assert( If_CutCheck( pCut ) );
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( pObj->fSpec && pCut->nLeaves == (unsigned)p->pPars->nLutSize )
|
|
|
|
|
continue;
|
2008-01-31 05:01:00 +01:00
|
|
|
p->nCutsMerged++;
|
2010-11-01 09:35:04 +01:00
|
|
|
p->nCutsTotal++;
|
2008-01-31 05:01:00 +01:00
|
|
|
// check if this cut is contained in any of the available cuts
|
|
|
|
|
// if ( p->pPars->pFuncCost == NULL && If_CutFilter( p, pCut ) ) // do not filter functionality cuts
|
2012-01-12 07:08:35 +01:00
|
|
|
if ( !p->pPars->fSkipCutFilter && If_CutFilter( pCutSet, pCut ) )
|
2008-01-31 05:01:00 +01:00
|
|
|
continue;
|
|
|
|
|
// compute the truth table
|
|
|
|
|
pCut->fCompl = 0;
|
2014-02-17 04:30:38 +01:00
|
|
|
pCut->iCutFunc = -1;
|
2014-02-17 21:19:42 +01:00
|
|
|
pCut->iCutDsd = -1;
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( p->pPars->fTruth )
|
2008-03-08 05:01:00 +01:00
|
|
|
{
|
2013-05-28 00:09:23 +02:00
|
|
|
// abctime clk = Abc_Clock();
|
2014-02-17 21:19:42 +01:00
|
|
|
If_CutComputeTruth( p, pCut, pCut0, pCut1, pObj->fCompl0, pObj->fCompl1 );
|
2013-05-28 00:09:23 +02:00
|
|
|
// p->timeTruth += Abc_Clock() - clk;
|
2014-02-26 07:41:34 +01:00
|
|
|
// run user functions
|
2011-05-08 05:19:45 +02:00
|
|
|
pCut->fUseless = 0;
|
2014-02-17 21:19:42 +01:00
|
|
|
if ( p->pPars->pFuncCell )
|
2010-11-01 09:35:04 +01:00
|
|
|
{
|
2011-10-01 12:00:59 +02:00
|
|
|
assert( pCut->nLimit >= 4 && pCut->nLimit <= 16 );
|
2014-02-17 04:30:38 +01:00
|
|
|
pCut->fUseless = !p->pPars->pFuncCell( p, If_CutTruth(p, pCut), pCut->nLimit, pCut->nLeaves, p->pPars->pLutStruct );
|
2011-10-01 12:00:59 +02:00
|
|
|
p->nCutsUselessAll += pCut->fUseless;
|
|
|
|
|
p->nCutsUseless[pCut->nLeaves] += pCut->fUseless;
|
|
|
|
|
p->nCutsCountAll++;
|
|
|
|
|
p->nCutsCount[pCut->nLeaves]++;
|
2013-08-29 23:41:01 +02:00
|
|
|
// skip 5-input cuts, which cannot be decomposed
|
|
|
|
|
if ( (p->pPars->fEnableCheck75 || p->pPars->fEnableCheck75u) && pCut->nLeaves == 5 && pCut->nLimit == 5 )
|
|
|
|
|
{
|
2013-08-30 01:03:40 +02:00
|
|
|
extern int If_CluCheckDecInAny( word t, int nVars );
|
2013-08-29 23:41:01 +02:00
|
|
|
extern int If_CluCheckDecOut( word t, int nVars );
|
2014-02-17 04:30:38 +01:00
|
|
|
unsigned TruthU = *If_CutTruth(p, pCut);
|
2013-08-29 23:41:01 +02:00
|
|
|
word Truth = (((word)TruthU << 32) | (word)TruthU);
|
|
|
|
|
p->nCuts5++;
|
2013-08-30 01:03:40 +02:00
|
|
|
if ( If_CluCheckDecInAny( Truth, 5 ) )
|
2013-08-29 23:41:01 +02:00
|
|
|
p->nCuts5a++;
|
|
|
|
|
else
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
else if ( p->pPars->fVerbose && pCut->nLeaves == 5 )
|
2013-08-18 19:42:57 +02:00
|
|
|
{
|
2013-08-30 01:03:40 +02:00
|
|
|
extern int If_CluCheckDecInAny( word t, int nVars );
|
2013-08-18 19:42:57 +02:00
|
|
|
extern int If_CluCheckDecOut( word t, int nVars );
|
2014-02-17 04:30:38 +01:00
|
|
|
unsigned TruthU = *If_CutTruth(p, pCut);
|
2013-08-18 19:42:57 +02:00
|
|
|
word Truth = (((word)TruthU << 32) | (word)TruthU);
|
|
|
|
|
p->nCuts5++;
|
2013-08-30 01:03:40 +02:00
|
|
|
if ( If_CluCheckDecInAny( Truth, 5 ) || If_CluCheckDecOut( Truth, 5 ) )
|
2013-08-18 19:42:57 +02:00
|
|
|
p->nCuts5a++;
|
|
|
|
|
}
|
2010-11-01 09:35:04 +01:00
|
|
|
}
|
2014-02-26 07:41:34 +01:00
|
|
|
if ( p->pPars->fUseDsd )
|
|
|
|
|
{
|
|
|
|
|
int truthId = Abc_Lit2Var(pCut->iCutFunc);
|
|
|
|
|
if ( Vec_IntSize(p->vDsds) <= truthId || Vec_IntEntry(p->vDsds, truthId) == -1 )
|
|
|
|
|
{
|
|
|
|
|
pCut->iCutDsd = If_DsdManCompute( p->pIfDsdMan, If_CutTruthW(p, pCut), pCut->nLeaves, (unsigned char *)pCut->pPerm, p->pPars->pLutStruct );
|
|
|
|
|
while ( Vec_IntSize(p->vDsds) <= truthId )
|
|
|
|
|
Vec_IntPush( p->vDsds, -1 );
|
|
|
|
|
Vec_IntWriteEntry( p->vDsds, truthId, Abc_LitNotCond(pCut->iCutDsd, Abc_LitIsCompl(pCut->iCutFunc)) );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
pCut->iCutDsd = Abc_LitNotCond( Vec_IntEntry(p->vDsds, truthId), Abc_LitIsCompl(pCut->iCutFunc) );
|
|
|
|
|
if ( p->pPars->pLutStruct )
|
|
|
|
|
{
|
|
|
|
|
int Value = If_DsdManCheckDec( p->pIfDsdMan, pCut->iCutDsd );
|
|
|
|
|
if ( Value != (int)pCut->fUseless )
|
|
|
|
|
printf( "Difference\n" );
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-11-11 04:37:53 +01:00
|
|
|
}
|
2012-01-18 08:38:11 +01:00
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
// compute the application-specific cost and depth
|
|
|
|
|
pCut->fUser = (p->pPars->pFuncCost != NULL);
|
2014-02-17 04:30:38 +01:00
|
|
|
pCut->Cost = p->pPars->pFuncCost? p->pPars->pFuncCost(p, pCut) : 0;
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( pCut->Cost == IF_COST_MAX )
|
|
|
|
|
continue;
|
|
|
|
|
// check if the cut satisfies the required times
|
2011-10-01 12:00:59 +02:00
|
|
|
/// if ( p->pPars->pLutStruct )
|
|
|
|
|
/// pCut->Delay = If_CutDelayLutStruct( p, pCut, p->pPars->pLutStruct, p->pPars->WireDelay );
|
2011-12-29 15:14:01 +01:00
|
|
|
if ( p->pPars->fUserRecLib )
|
2014-02-17 04:49:10 +01:00
|
|
|
pCut->Delay = If_CutDelayRecCost3(p, pCut, pObj);
|
2011-12-29 15:14:01 +01:00
|
|
|
else if (p->pPars->fDelayOpt)
|
|
|
|
|
pCut->Delay = If_CutDelaySopCost(p, pCut);
|
2012-03-28 05:15:02 +02:00
|
|
|
else if(p->pPars->nGateSize > 0)
|
|
|
|
|
pCut->Delay = If_CutDelaySop(p,pCut);
|
2010-11-01 09:35:04 +01:00
|
|
|
else
|
2011-07-10 08:56:05 +02:00
|
|
|
pCut->Delay = If_CutDelay( p, pObj, pCut );
|
2012-01-18 08:38:11 +01:00
|
|
|
//if ( pCut->Cost == IF_COST_MAX )
|
|
|
|
|
// continue;
|
2010-11-01 09:35:04 +01:00
|
|
|
// Abc_Print( 1, "%.2f ", pCut->Delay );
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon )
|
|
|
|
|
continue;
|
|
|
|
|
// compute area of the cut (this area may depend on the application specific cost)
|
|
|
|
|
pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
|
|
|
|
|
if ( p->pPars->fEdge )
|
|
|
|
|
pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
|
2009-01-18 17:01:00 +01:00
|
|
|
if ( p->pPars->fPower )
|
|
|
|
|
pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
|
2008-01-31 05:01:00 +01:00
|
|
|
pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
|
|
|
|
|
// insert the cut into storage
|
|
|
|
|
If_CutSort( p, pCutSet, pCut );
|
2012-10-26 07:10:24 +02:00
|
|
|
// If_CutTraverse( p, pObj, pCut );
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
assert( pCutSet->nCuts > 0 );
|
|
|
|
|
|
|
|
|
|
// update the best cut
|
|
|
|
|
if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
|
2011-12-29 15:14:01 +01:00
|
|
|
{
|
2008-01-31 05:01:00 +01:00
|
|
|
If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
|
2011-12-29 15:14:01 +01:00
|
|
|
if(p->pPars->fUserRecLib)
|
|
|
|
|
assert(If_ObjCutBest(pObj)->Cost < IF_COST_MAX && If_ObjCutBest(pObj)->Delay < ABC_INFINITY);
|
|
|
|
|
}
|
2014-02-17 04:30:38 +01:00
|
|
|
// add the trivial cut to the set
|
|
|
|
|
if ( !pObj->fSkipCut && If_ObjCutBest(pObj)->nLeaves > 1 )
|
|
|
|
|
{
|
|
|
|
|
If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
|
|
|
|
|
assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
|
|
|
|
|
}
|
|
|
|
|
// if ( If_ObjCutBest(pObj)->nLeaves == 0 )
|
|
|
|
|
// p->nBestCutSmall[0]++;
|
|
|
|
|
// else if ( If_ObjCutBest(pObj)->nLeaves == 1 )
|
|
|
|
|
// p->nBestCutSmall[1]++;
|
|
|
|
|
|
2008-01-31 05:01:00 +01:00
|
|
|
// ref the selected cut
|
|
|
|
|
if ( Mode && pObj->nRefs > 0 )
|
|
|
|
|
If_CutAreaRef( p, If_ObjCutBest(pObj) );
|
2010-11-01 09:35:04 +01:00
|
|
|
if ( If_ObjCutBest(pObj)->fUseless )
|
|
|
|
|
Abc_Print( 1, "The best cut is useless.\n" );
|
2008-01-31 05:01:00 +01:00
|
|
|
// call the user specified function for each cut
|
|
|
|
|
if ( p->pPars->pFuncUser )
|
|
|
|
|
If_ObjForEachCut( pObj, pCut, i )
|
|
|
|
|
p->pPars->pFuncUser( p, pObj, pCut );
|
2009-03-10 16:01:00 +01:00
|
|
|
// free the cuts
|
2008-01-31 05:01:00 +01:00
|
|
|
If_ManDerefNodeCutSet( p, pObj );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Finds the best cut for the choice node.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
|
|
|
|
void If_ObjPerformMappingChoice( If_Man_t * p, If_Obj_t * pObj, int Mode, int fPreprocess )
|
|
|
|
|
{
|
|
|
|
|
If_Set_t * pCutSet;
|
|
|
|
|
If_Obj_t * pTemp;
|
|
|
|
|
If_Cut_t * pCutTemp, * pCut;
|
|
|
|
|
int i;
|
|
|
|
|
assert( pObj->pEquiv != NULL );
|
|
|
|
|
|
|
|
|
|
// prepare
|
|
|
|
|
if ( Mode && pObj->nRefs > 0 )
|
|
|
|
|
If_CutAreaDeref( p, If_ObjCutBest(pObj) );
|
|
|
|
|
|
|
|
|
|
// remove elementary cuts
|
|
|
|
|
for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
|
|
|
|
|
pTemp->pCutSet->nCuts--;
|
|
|
|
|
|
|
|
|
|
// update the cutset of the node
|
|
|
|
|
pCutSet = pObj->pCutSet;
|
|
|
|
|
|
|
|
|
|
// generate cuts
|
|
|
|
|
for ( pTemp = pObj->pEquiv; pTemp; pTemp = pTemp->pEquiv )
|
|
|
|
|
{
|
2013-07-17 04:17:41 +02:00
|
|
|
// assert( pTemp->nRefs == 0 );
|
2015-06-23 08:04:53 +02:00
|
|
|
// assert( p->pPars->fSeqMap || pTemp->pCutSet->nCuts > 0 ); // June 9, 2009
|
|
|
|
|
if ( pTemp->pCutSet->nCuts == 0 )
|
|
|
|
|
continue;
|
2008-01-31 05:01:00 +01:00
|
|
|
// go through the cuts of this node
|
|
|
|
|
If_ObjForEachCut( pTemp, pCutTemp, i )
|
|
|
|
|
{
|
|
|
|
|
assert( p->pPars->fSeqMap || pCutTemp->nLeaves > 1 );
|
2012-11-02 06:03:37 +01:00
|
|
|
if ( pCutTemp->fUseless )
|
|
|
|
|
continue;
|
2010-11-01 09:35:04 +01:00
|
|
|
// get the next free cut
|
2008-01-31 05:01:00 +01:00
|
|
|
assert( pCutSet->nCuts <= pCutSet->nCutsMax );
|
|
|
|
|
pCut = pCutSet->ppCuts[pCutSet->nCuts];
|
|
|
|
|
// copy the cut into storage
|
|
|
|
|
If_CutCopy( p, pCut, pCutTemp );
|
|
|
|
|
// check if this cut is contained in any of the available cuts
|
|
|
|
|
if ( If_CutFilter( pCutSet, pCut ) )
|
|
|
|
|
continue;
|
|
|
|
|
// check if the cut satisfies the required times
|
2011-07-11 05:10:46 +02:00
|
|
|
assert( pCut->Delay == If_CutDelay( p, pTemp, pCut ) );
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( Mode && pCut->Delay > pObj->Required + p->fEpsilon )
|
|
|
|
|
continue;
|
|
|
|
|
// set the phase attribute
|
|
|
|
|
assert( pCut->fCompl == 0 );
|
|
|
|
|
pCut->fCompl ^= (pObj->fPhase ^ pTemp->fPhase); // why ^= ?
|
2012-04-13 05:19:47 +02:00
|
|
|
if ( p->pPars->fDelayOpt && pCut->fCompl )
|
|
|
|
|
continue;
|
2008-01-31 05:01:00 +01:00
|
|
|
// compute area of the cut (this area may depend on the application specific cost)
|
|
|
|
|
pCut->Area = (Mode == 2)? If_CutAreaDerefed( p, pCut ) : If_CutAreaFlow( p, pCut );
|
|
|
|
|
if ( p->pPars->fEdge )
|
|
|
|
|
pCut->Edge = (Mode == 2)? If_CutEdgeDerefed( p, pCut ) : If_CutEdgeFlow( p, pCut );
|
2009-01-18 17:01:00 +01:00
|
|
|
if ( p->pPars->fPower )
|
|
|
|
|
pCut->Power = (Mode == 2)? If_CutPowerDerefed( p, pCut, pObj ) : If_CutPowerFlow( p, pCut, pObj );
|
2008-01-31 05:01:00 +01:00
|
|
|
pCut->AveRefs = (Mode == 0)? (float)0.0 : If_CutAverageRefs( p, pCut );
|
|
|
|
|
// insert the cut into storage
|
|
|
|
|
If_CutSort( p, pCutSet, pCut );
|
|
|
|
|
}
|
2010-11-01 09:35:04 +01:00
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
assert( pCutSet->nCuts > 0 );
|
|
|
|
|
|
2014-02-17 04:30:38 +01:00
|
|
|
// update the best cut
|
|
|
|
|
if ( !fPreprocess || pCutSet->ppCuts[0]->Delay <= pObj->Required + p->fEpsilon )
|
|
|
|
|
If_CutCopy( p, If_ObjCutBest(pObj), pCutSet->ppCuts[0] );
|
|
|
|
|
assert( p->pPars->fSeqMap || If_ObjCutBest(pObj)->nLeaves > 1 );
|
2008-01-31 05:01:00 +01:00
|
|
|
// add the trivial cut to the set
|
2014-02-17 04:30:38 +01:00
|
|
|
if ( !pObj->fSkipCut && If_ObjCutBest(pObj)->nLeaves > 1 )
|
2011-07-20 13:23:10 +02:00
|
|
|
{
|
|
|
|
|
If_ManSetupCutTriv( p, pCutSet->ppCuts[pCutSet->nCuts++], pObj->Id );
|
|
|
|
|
assert( pCutSet->nCuts <= pCutSet->nCutsMax+1 );
|
|
|
|
|
}
|
2008-01-31 05:01:00 +01:00
|
|
|
|
|
|
|
|
// ref the selected cut
|
|
|
|
|
if ( Mode && pObj->nRefs > 0 )
|
|
|
|
|
If_CutAreaRef( p, If_ObjCutBest(pObj) );
|
2009-03-10 16:01:00 +01:00
|
|
|
// free the cuts
|
2008-01-31 05:01:00 +01:00
|
|
|
If_ManDerefChoiceCutSet( p, pObj );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**Function*************************************************************
|
|
|
|
|
|
|
|
|
|
Synopsis [Performs one mapping pass over all nodes.]
|
|
|
|
|
|
|
|
|
|
Description []
|
|
|
|
|
|
|
|
|
|
SideEffects []
|
|
|
|
|
|
|
|
|
|
SeeAlso []
|
|
|
|
|
|
|
|
|
|
***********************************************************************/
|
2014-02-17 04:30:38 +01:00
|
|
|
int If_ManPerformMappingRound( If_Man_t * p, int nCutsUsed, int Mode, int fPreprocess, int fFirst, char * pLabel )
|
2008-01-31 05:01:00 +01:00
|
|
|
{
|
|
|
|
|
// ProgressBar * pProgress;
|
|
|
|
|
If_Obj_t * pObj;
|
2012-07-08 02:46:54 +02:00
|
|
|
int i;
|
2013-05-28 00:09:23 +02:00
|
|
|
abctime clk = Abc_Clock();
|
2008-01-31 05:01:00 +01:00
|
|
|
float arrTime;
|
|
|
|
|
assert( Mode >= 0 && Mode <= 2 );
|
2014-02-17 04:30:38 +01:00
|
|
|
p->nBestCutSmall[0] = p->nBestCutSmall[1] = 0;
|
2008-01-31 05:01:00 +01:00
|
|
|
// set the sorting function
|
|
|
|
|
if ( Mode || p->pPars->fArea ) // area
|
|
|
|
|
p->SortMode = 1;
|
|
|
|
|
else if ( p->pPars->fFancy )
|
|
|
|
|
p->SortMode = 2;
|
|
|
|
|
else
|
|
|
|
|
p->SortMode = 0;
|
|
|
|
|
// set the cut number
|
|
|
|
|
p->nCutsUsed = nCutsUsed;
|
|
|
|
|
p->nCutsMerged = 0;
|
|
|
|
|
// make sure the visit counters are all zero
|
|
|
|
|
If_ManForEachNode( p, pObj, i )
|
|
|
|
|
assert( pObj->nVisits == pObj->nVisitsCopy );
|
|
|
|
|
// map the internal nodes
|
|
|
|
|
if ( p->pManTim != NULL )
|
|
|
|
|
{
|
|
|
|
|
Tim_ManIncrementTravId( p->pManTim );
|
|
|
|
|
If_ManForEachObj( p, pObj, i )
|
|
|
|
|
{
|
|
|
|
|
if ( If_ObjIsAnd(pObj) )
|
|
|
|
|
{
|
2014-02-17 04:30:38 +01:00
|
|
|
If_ObjPerformMappingAnd( p, pObj, Mode, fPreprocess, fFirst );
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( pObj->fRepr )
|
|
|
|
|
If_ObjPerformMappingChoice( p, pObj, Mode, fPreprocess );
|
|
|
|
|
}
|
|
|
|
|
else if ( If_ObjIsCi(pObj) )
|
|
|
|
|
{
|
2010-11-01 09:35:04 +01:00
|
|
|
//Abc_Print( 1, "processing CI %d\n", pObj->Id );
|
2008-04-04 17:01:00 +02:00
|
|
|
arrTime = Tim_ManGetCiArrival( p->pManTim, pObj->IdPio );
|
2008-01-31 05:01:00 +01:00
|
|
|
If_ObjSetArrTime( pObj, arrTime );
|
|
|
|
|
}
|
|
|
|
|
else if ( If_ObjIsCo(pObj) )
|
|
|
|
|
{
|
|
|
|
|
arrTime = If_ObjArrTime( If_ObjFanin0(pObj) );
|
2008-04-04 17:01:00 +02:00
|
|
|
Tim_ManSetCoArrival( p->pManTim, pObj->IdPio, arrTime );
|
2008-01-31 05:01:00 +01:00
|
|
|
}
|
|
|
|
|
else if ( If_ObjIsConst1(pObj) )
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
assert( 0 );
|
|
|
|
|
}
|
|
|
|
|
// Tim_ManPrint( p->pManTim );
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// pProgress = Extra_ProgressBarStart( stdout, If_ManObjNum(p) );
|
|
|
|
|
If_ManForEachNode( p, pObj, i )
|
|
|
|
|
{
|
|
|
|
|
// Extra_ProgressBarUpdate( pProgress, i, pLabel );
|
2014-02-17 04:30:38 +01:00
|
|
|
If_ObjPerformMappingAnd( p, pObj, Mode, fPreprocess, fFirst );
|
2008-01-31 05:01:00 +01:00
|
|
|
if ( pObj->fRepr )
|
|
|
|
|
If_ObjPerformMappingChoice( p, pObj, Mode, fPreprocess );
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// Extra_ProgressBarStop( pProgress );
|
|
|
|
|
// make sure the visit counters are all zero
|
|
|
|
|
If_ManForEachNode( p, pObj, i )
|
|
|
|
|
assert( pObj->nVisits == 0 );
|
|
|
|
|
// compute required times and stats
|
|
|
|
|
If_ManComputeRequired( p );
|
|
|
|
|
// Tim_ManPrint( p->pManTim );
|
|
|
|
|
if ( p->pPars->fVerbose )
|
|
|
|
|
{
|
|
|
|
|
char Symb = fPreprocess? 'P' : ((Mode == 0)? 'D' : ((Mode == 1)? 'F' : 'A'));
|
2010-11-01 09:35:04 +01:00
|
|
|
Abc_Print( 1, "%c: Del = %7.2f. Ar = %9.1f. Edge = %8d. Switch = %7.2f. Cut = %8d. ",
|
2009-01-18 17:01:00 +01:00
|
|
|
Symb, p->RequiredGlo, p->AreaGlo, p->nNets, p->dPower, p->nCutsMerged );
|
2014-02-17 04:30:38 +01:00
|
|
|
// printf( "Cut0 =%4d. Cut1 =%4d. ", p->nBestCutSmall[0], p->nBestCutSmall[1] );
|
2013-05-28 00:09:23 +02:00
|
|
|
Abc_PrintTime( 1, "T", Abc_Clock() - clk );
|
2010-11-01 09:35:04 +01:00
|
|
|
// Abc_Print( 1, "Max number of cuts = %d. Average number of cuts = %5.2f.\n",
|
2008-01-31 05:01:00 +01:00
|
|
|
// p->nCutsMax, 1.0 * p->nCutsMerged / If_ManAndNum(p) );
|
|
|
|
|
}
|
|
|
|
|
return 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
/// END OF FILE ///
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
2010-11-01 09:35:04 +01:00
|
|
|
ABC_NAMESPACE_IMPL_END
|
|
|
|
|
|