abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cgtCore.c File Reference
#include "cgtInt.h"
#include "misc/bar/bar.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Cgt_SetDefaultParams (Cgt_Par_t *p)
 DECLARATIONS ///. More...
 
int Cgt_SimulationFilter (Cgt_Man_t *p, Aig_Obj_t *pCandPart, Aig_Obj_t *pMiterPart)
 
void Cgt_SimulationRecord (Cgt_Man_t *p)
 
void Cgt_ClockGatingRangeCheck (Cgt_Man_t *p, int iStart, int nOutputs)
 
int Cgt_ClockGatingRange (Cgt_Man_t *p, int iStart)
 
Vec_Vec_tCgt_ClockGatingCandidates (Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars, Vec_Int_t *vUseful)
 
Vec_Vec_tCgt_ClockGatingInt (Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars, Vec_Int_t *vUseful)
 
Aig_Man_tCgt_ClockGating (Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars)
 

Function Documentation

Aig_Man_t* Cgt_ClockGating ( Aig_Man_t pAig,
Aig_Man_t pCare,
Cgt_Par_t pPars 
)

Definition at line 298 of file cgtCore.c.

299 {
300  Aig_Man_t * pGated;
301  Vec_Vec_t * vGates = Cgt_ClockGatingInt( pAig, pCare, pPars, NULL );
302  int nNodesUsed;
303  if ( pPars->fVerbose )
304  {
305 // printf( "Before CG: " );
306 // Aig_ManPrintStats( pAig );
307  }
308  pGated = Cgt_ManDeriveGatedAig( pAig, vGates, pPars->fAreaOnly, &nNodesUsed );
309  if ( pPars->fVerbose )
310  {
311 // printf( "After CG: " );
312 // Aig_ManPrintStats( pGated );
313  printf( "Nodes: Before CG = %6d. After CG = %6d. (%6.2f %%). Total after CG = %6d.\n",
314  Aig_ManNodeNum(pAig), nNodesUsed,
315  100.0*nNodesUsed/Aig_ManNodeNum(pAig),
316  Aig_ManNodeNum(pGated) );
317  }
318  Vec_VecFree( vGates );
319  return pGated;
320 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition: aig.h:50
Vec_Vec_t * Cgt_ClockGatingInt(Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars, Vec_Int_t *vUseful)
Definition: cgtCore.c:287
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
static int Aig_ManNodeNum(Aig_Man_t *p)
Definition: aig.h:256
Aig_Man_t * Cgt_ManDeriveGatedAig(Aig_Man_t *pAig, Vec_Vec_t *vGates, int fReduce, int *pnUsedNodes)
Definition: cgtAig.c:524
Vec_Vec_t* Cgt_ClockGatingCandidates ( Aig_Man_t pAig,
Aig_Man_t pCare,
Cgt_Par_t pPars,
Vec_Int_t vUseful 
)

Function*************************************************************

Synopsis [Performs clock-gating for the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 245 of file cgtCore.c.

246 {
247  Bar_Progress_t * pProgress = NULL;
248  Cgt_Par_t Pars;
249  Cgt_Man_t * p;
250  Vec_Vec_t * vGatesAll;
251  int iStart;
252  abctime clk = Abc_Clock(), clkTotal = Abc_Clock();
253  // reset random numbers
254  Aig_ManRandom( 1 );
255  if ( pPars == NULL )
256  Cgt_SetDefaultParams( pPars = &Pars );
257  p = Cgt_ManCreate( pAig, pCare, pPars );
258  p->vUseful = vUseful;
259  p->pFrame = Cgt_ManDeriveAigForGating( p );
260 p->timeAig += Abc_Clock() - clk;
261  assert( Aig_ManCoNum(p->pFrame) == Saig_ManRegNum(p->pAig) );
262  pProgress = Bar_ProgressStart( stdout, Aig_ManCoNum(p->pFrame) );
263  for ( iStart = 0; iStart < Aig_ManCoNum(p->pFrame); )
264  {
265  Bar_ProgressUpdate( pProgress, iStart, NULL );
266  iStart = Cgt_ClockGatingRange( p, iStart );
267  }
268  Bar_ProgressStop( pProgress );
269  vGatesAll = p->vGatesAll;
270  p->vGatesAll = NULL;
271 p->timeTotal = Abc_Clock() - clkTotal;
272  Cgt_ManStop( p );
273  return vGatesAll;
274 }
void Cgt_ManStop(Cgt_Man_t *p)
Definition: cgtMan.c:154
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static Llb_Mgr_t * p
Definition: llb3Image.c:950
ABC_NAMESPACE_IMPL_START void Cgt_SetDefaultParams(Cgt_Par_t *p)
DECLARATIONS ///.
Definition: cgtCore.c:46
unsigned Aig_ManRandom(int fReset)
Definition: aigUtil.c:1157
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static void Bar_ProgressUpdate(Bar_Progress_t *p, int nItemsCur, char *pString)
Definition: bar.h:63
Cgt_Man_t * Cgt_ManCreate(Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars)
DECLARATIONS ///.
Definition: cgtMan.c:45
typedefABC_NAMESPACE_HEADER_START struct Cgt_Par_t_ Cgt_Par_t
INCLUDES ///.
Definition: cgt.h:48
DECLARATIONS ///.
Definition: bar.c:36
static int Saig_ManRegNum(Aig_Man_t *p)
Definition: saig.h:77
int Cgt_ClockGatingRange(Cgt_Man_t *p, int iStart)
Definition: cgtCore.c:201
Aig_Man_t * Cgt_ManDeriveAigForGating(Cgt_Man_t *p)
Definition: cgtAig.c:266
#define assert(ex)
Definition: util_old.h:213
ABC_INT64_T abctime
Definition: abc_global.h:278
void Bar_ProgressStop(Bar_Progress_t *p)
Definition: bar.c:126
Bar_Progress_t * Bar_ProgressStart(FILE *pFile, int nItemsTotal)
FUNCTION DEFINITIONS ///.
Definition: bar.c:66
typedefABC_NAMESPACE_HEADER_START struct Cgt_Man_t_ Cgt_Man_t
INCLUDES ///.
Definition: cgtInt.h:47
Vec_Vec_t* Cgt_ClockGatingInt ( Aig_Man_t pAig,
Aig_Man_t pCare,
Cgt_Par_t pPars,
Vec_Int_t vUseful 
)

Function*************************************************************

Synopsis [Performs clock-gating for the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 287 of file cgtCore.c.

288 {
289  Vec_Vec_t * vGatesAll, * vGates;
290  vGatesAll = Cgt_ClockGatingCandidates( pAig, pCare, pPars, vUseful );
291  if ( pPars->fAreaOnly )
292  vGates = Cgt_ManDecideArea( pAig, vGatesAll, pPars->nOdcMax, pPars->fVerbose );
293  else
294  vGates = Cgt_ManDecideSimple( pAig, vGatesAll, pPars->nOdcMax, pPars->fVerbose );
295  Vec_VecFree( vGatesAll );
296  return vGates;
297 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition: vecVec.h:42
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
Vec_Vec_t * Cgt_ManDecideSimple(Aig_Man_t *pAig, Vec_Vec_t *vGatesAll, int nOdcMax, int fVerbose)
Definition: cgtDecide.c:184
Vec_Vec_t * Cgt_ManDecideArea(Aig_Man_t *pAig, Vec_Vec_t *vGatesAll, int nOdcMax, int fVerbose)
Definition: cgtDecide.c:255
Vec_Vec_t * Cgt_ClockGatingCandidates(Aig_Man_t *pAig, Aig_Man_t *pCare, Cgt_Par_t *pPars, Vec_Int_t *vUseful)
Definition: cgtCore.c:245
int Cgt_ClockGatingRange ( Cgt_Man_t p,
int  iStart 
)

Function*************************************************************

Synopsis [Performs clock-gating for the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 201 of file cgtCore.c.

202 {
203  int nOutputs, iStop;
204  abctime clk, clkTotal = Abc_Clock();
205  int nCallsUnsat = p->nCallsUnsat;
206  int nCallsSat = p->nCallsSat;
207  int nCallsUndec = p->nCallsUndec;
208  int nCallsFiltered = p->nCallsFiltered;
209 clk = Abc_Clock();
210  p->pPart = Cgt_ManDupPartition( p->pFrame, p->pPars->nVarsMin, p->pPars->nFlopsMin, iStart, p->pCare, p->vSuppsInv, &nOutputs );
211  p->pCnf = Cnf_DeriveSimple( p->pPart, nOutputs );
212  p->pSat = (sat_solver *)Cnf_DataWriteIntoSolver( p->pCnf, 1, 0 );
213  sat_solver_compress( p->pSat );
214  p->vPatts = Vec_PtrAllocSimInfo( Aig_ManObjNumMax(p->pPart), p->nPattWords );
215  Vec_PtrCleanSimInfo( p->vPatts, 0, p->nPattWords );
216 p->timePrepare += Abc_Clock() - clk;
217  Cgt_ClockGatingRangeCheck( p, iStart, nOutputs );
218  iStop = iStart + nOutputs;
219  if ( p->pPars->fVeryVerbose )
220  {
221  printf( "%5d : D =%4d. C =%5d. Var =%6d. Pr =%5d. Cex =%5d. F =%4d. Saved =%6d. ",
222  iStart, iStop-iStart, Aig_ManCoNum(p->pPart)-nOutputs, p->pSat->size,
223  p->nCallsUnsat-nCallsUnsat,
224  p->nCallsSat -nCallsSat,
225  p->nCallsUndec-nCallsUndec,
226  p->nCallsFiltered-nCallsFiltered );
227  ABC_PRT( "Time", Abc_Clock() - clkTotal );
228  }
229  Cgt_ManClean( p );
230  p->nRecycles++;
231  return iStop;
232 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void Cgt_ManClean(Cgt_Man_t *p)
Definition: cgtMan.c:86
static void sat_solver_compress(sat_solver *s)
Definition: satSolver.h:217
static void Vec_PtrCleanSimInfo(Vec_Ptr_t *vInfo, int iWord, int nWords)
Definition: vecPtr.h:968
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
void Cgt_ClockGatingRangeCheck(Cgt_Man_t *p, int iStart, int nOutputs)
Definition: cgtCore.c:130
Aig_Man_t * Cgt_ManDupPartition(Aig_Man_t *pFrame, int nVarsMin, int nFlopsMin, int iStart, Aig_Man_t *pCare, Vec_Vec_t *vSuppsInv, int *pnOutputs)
Definition: cgtAig.c:441
static int Aig_ManObjNumMax(Aig_Man_t *p)
Definition: aig.h:259
void * Cnf_DataWriteIntoSolver(Cnf_Dat_t *p, int nFrames, int fInit)
Definition: cnfMan.c:463
Cnf_Dat_t * Cnf_DeriveSimple(Aig_Man_t *p, int nOutputs)
Definition: cnfWrite.c:587
#define ABC_PRT(a, t)
Definition: abc_global.h:220
ABC_INT64_T abctime
Definition: abc_global.h:278
static Vec_Ptr_t * Vec_PtrAllocSimInfo(int nEntries, int nWords)
Definition: vecPtr.h:929
void Cgt_ClockGatingRangeCheck ( Cgt_Man_t p,
int  iStart,
int  nOutputs 
)

Function*************************************************************

Synopsis [Performs clock-gating for the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 130 of file cgtCore.c.

131 {
132  Vec_Ptr_t * vNodes = p->vFanout;
133  Aig_Obj_t * pMiter, * pCand, * pMiterFrame, * pCandFrame, * pMiterPart, * pCandPart;
134  int i, k, RetValue, nCalls;
135  assert( Vec_VecSize(p->vGatesAll) == Aig_ManCoNum(p->pFrame) );
136  // go through all the registers inputs of this range
137  for ( i = iStart; i < iStart + nOutputs; i++ )
138  {
139  nCalls = p->nCalls;
140  pMiter = Saig_ManLi( p->pAig, i );
141  Cgt_ManDetectCandidates( p->pAig, p->vUseful, Aig_ObjFanin0(pMiter), p->pPars->nLevelMax, vNodes );
142  // go through the candidates of this PO
143  Vec_PtrForEachEntry( Aig_Obj_t *, vNodes, pCand, k )
144  {
145  // get the corresponding nodes from the frames
146  pCandFrame = (Aig_Obj_t *)pCand->pData;
147  pMiterFrame = (Aig_Obj_t *)pMiter->pData;
148  // get the corresponding nodes from the part
149  pCandPart = (Aig_Obj_t *)pCandFrame->pData;
150  pMiterPart = (Aig_Obj_t *)pMiterFrame->pData;
151  // try direct polarity
152  if ( Cgt_SimulationFilter( p, pCandPart, pMiterPart ) )
153  {
154  RetValue = Cgt_CheckImplication( p, pCandPart, pMiterPart );
155  if ( RetValue == 1 )
156  {
157  Vec_VecPush( p->vGatesAll, i, pCand );
158  continue;
159  }
160  if ( RetValue == 0 )
162  }
163  else
164  p->nCallsFiltered++;
165  // try reverse polarity
166  if ( Cgt_SimulationFilter( p, Aig_Not(pCandPart), pMiterPart ) )
167  {
168  RetValue = Cgt_CheckImplication( p, Aig_Not(pCandPart), pMiterPart );
169  if ( RetValue == 1 )
170  {
171  Vec_VecPush( p->vGatesAll, i, Aig_Not(pCand) );
172  continue;
173  }
174  if ( RetValue == 0 )
176  }
177  else
178  p->nCallsFiltered++;
179  }
180 
181  if ( p->pPars->fVerbose )
182  {
183 // printf( "Flop %3d : Cand = %4d. Gate = %4d. SAT calls = %3d.\n",
184 // i, Vec_PtrSize(vNodes), Vec_PtrSize(Vec_VecEntry(p->vGatesAll, i)), p->nCalls-nCalls );
185  }
186 
187  }
188 }
void Cgt_SimulationRecord(Cgt_Man_t *p)
Definition: cgtCore.c:103
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static void Vec_VecPush(Vec_Vec_t *p, int Level, void *Entry)
Definition: vecVec.h:456
Aig_Man_t * pAig
Definition: llb3Image.c:49
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * pData
Definition: aig.h:87
static Aig_Obj_t * Aig_ObjFanin0(Aig_Obj_t *pObj)
Definition: aig.h:308
static Aig_Obj_t * Aig_Not(Aig_Obj_t *p)
Definition: aig.h:247
int Cgt_SimulationFilter(Cgt_Man_t *p, Aig_Obj_t *pCandPart, Aig_Obj_t *pMiterPart)
Definition: cgtCore.c:70
static int Aig_ManCoNum(Aig_Man_t *p)
Definition: aig.h:252
static Aig_Obj_t * Saig_ManLi(Aig_Man_t *p, int i)
Definition: saig.h:80
Definition: aig.h:69
static int Vec_VecSize(Vec_Vec_t *p)
Definition: vecVec.h:222
#define assert(ex)
Definition: util_old.h:213
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
int Cgt_CheckImplication(Cgt_Man_t *p, Aig_Obj_t *pGate, Aig_Obj_t *pFlop)
DECLARATIONS ///.
Definition: cgtSat.c:46
void Cgt_ManDetectCandidates(Aig_Man_t *pAig, Vec_Int_t *vUseful, Aig_Obj_t *pObj, int nLevelMax, Vec_Ptr_t *vCands)
MACRO DEFINITIONS ///.
Definition: cgtAig.c:70
ABC_NAMESPACE_IMPL_START void Cgt_SetDefaultParams ( Cgt_Par_t p)

DECLARATIONS ///.

MACRO DEFINITIONS ///.

CFile****************************************************************

FileName [cgtCore.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Clock gating package.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - June 20, 2005.]

Revision [

Id:
cgtCore.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis [This procedure sets default parameters.]

Description []

SideEffects []

SeeAlso []

Definition at line 46 of file cgtCore.c.

47 {
48  memset( p, 0, sizeof(Cgt_Par_t) );
49  p->nLevelMax = 25; // the max number of levels to look for clock-gates
50  p->nCandMax = 1000; // the max number of candidates at each node
51  p->nOdcMax = 0; // the max number of ODC levels to consider
52  p->nConfMax = 10; // the max number of conflicts at a node
53  p->nVarsMin = 1000; // the min number of vars to recycle the SAT solver
54  p->nFlopsMin = 10; // the min number of flops to recycle the SAT solver
55  p->fAreaOnly = 0; // derive clock-gating to minimize area
56  p->fVerbose = 0; // verbosity flag
57 }
char * memset()
static Llb_Mgr_t * p
Definition: llb3Image.c:950
typedefABC_NAMESPACE_HEADER_START struct Cgt_Par_t_ Cgt_Par_t
INCLUDES ///.
Definition: cgt.h:48
int Cgt_SimulationFilter ( Cgt_Man_t p,
Aig_Obj_t pCandPart,
Aig_Obj_t pMiterPart 
)

Function*************************************************************

Synopsis [Returns 1 if simulation does not filter out this candidate.]

Description []

SideEffects []

SeeAlso []

Definition at line 70 of file cgtCore.c.

71 {
72  unsigned * pInfoCand, * pInfoMiter;
73  int w, nWords = Abc_BitWordNum( p->nPatts );
74  pInfoCand = (unsigned *)Vec_PtrEntry( p->vPatts, Aig_ObjId(Aig_Regular(pCandPart)) );
75  pInfoMiter = (unsigned *)Vec_PtrEntry( p->vPatts, Aig_ObjId(pMiterPart) );
76  // C => !M -- true is the same as C & M -- false
77  if ( !Aig_IsComplement(pCandPart) )
78  {
79  for ( w = 0; w < nWords; w++ )
80  if ( pInfoCand[w] & pInfoMiter[w] )
81  return 0;
82  }
83  else
84  {
85  for ( w = 0; w < nWords; w++ )
86  if ( ~pInfoCand[w] & pInfoMiter[w] )
87  return 0;
88  }
89  return 1;
90 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Aig_IsComplement(Aig_Obj_t *p)
Definition: aig.h:249
static Aig_Obj_t * Aig_Regular(Aig_Obj_t *p)
Definition: aig.h:246
int nWords
Definition: abcNpn.c:127
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static int Abc_BitWordNum(int nBits)
Definition: abc_global.h:255
static int Aig_ObjId(Aig_Obj_t *pObj)
Definition: aig.h:286
void Cgt_SimulationRecord ( Cgt_Man_t p)

Function*************************************************************

Synopsis [Saves one simulation pattern.]

Description []

SideEffects []

SeeAlso []

Definition at line 103 of file cgtCore.c.

104 {
105  Aig_Obj_t * pObj;
106  int i;
107  Aig_ManForEachObj( p->pPart, pObj, i )
108  if ( sat_solver_var_value( p->pSat, p->pCnf->pVarNums[i] ) )
109  Abc_InfoSetBit( (unsigned *)Vec_PtrEntry(p->vPatts, i), p->nPatts );
110  p->nPatts++;
111  if ( p->nPatts == 32 * p->nPattWords )
112  {
113  Vec_PtrReallocSimInfo( p->vPatts );
114  Vec_PtrCleanSimInfo( p->vPatts, p->nPattWords, 2 * p->nPattWords );
115  p->nPattWords *= 2;
116  }
117 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static void Vec_PtrCleanSimInfo(Vec_Ptr_t *vInfo, int iWord, int nWords)
Definition: vecPtr.h:968
static int sat_solver_var_value(sat_solver *s, int v)
Definition: satSolver.h:200
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
static void Abc_InfoSetBit(unsigned *p, int i)
Definition: abc_global.h:259
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
static void Vec_PtrReallocSimInfo(Vec_Ptr_t *vInfo)
Definition: vecPtr.h:1035