abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
retInt.h File Reference
#include "base/abc/abc.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_HEADER_START int Abc_NtkRetimeMinArea (Abc_Ntk_t *pNtk, int fForwardOnly, int fBackwardOnly, int fVerbose)
 INCLUDES ///. More...
 
int Abc_NtkRetime (Abc_Ntk_t *pNtk, int Mode, int nDelayLim, int fForwardOnly, int fBackwardOnly, int fOneStep, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
int Abc_NtkRetimeMinDelay (Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkCopy, int nDelayLim, int nIterLimit, int fForward, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
int Abc_NtkRetimeIncremental (Abc_Ntk_t *pNtk, int nDelayLim, int fForward, int fMinDelay, int fOneStep, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
void Abc_NtkRetimeShareLatches (Abc_Ntk_t *pNtk, int fInitial)
 
int Abc_NtkRetimeNodeIsEnabled (Abc_Obj_t *pObj, int fForward)
 
void Abc_NtkRetimeNode (Abc_Obj_t *pObj, int fForward, int fInitial)
 
st__tableAbc_NtkRetimePrepareLatches (Abc_Ntk_t *pNtk)
 
int Abc_NtkRetimeFinalizeLatches (Abc_Ntk_t *pNtk, st__table *tLatches, int nIdMaxStart)
 
void Abc_NtkMaxFlowTest (Abc_Ntk_t *pNtk)
 FUNCTION DEFINITIONS ///. More...
 
Vec_Ptr_tAbc_NtkMaxFlow (Abc_Ntk_t *pNtk, int fForward, int fVerbose)
 
Vec_Int_tAbc_NtkRetimeInitialValues (Abc_Ntk_t *pNtkSat, Vec_Int_t *vValues, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 
int Abc_ObjSopSimulate (Abc_Obj_t *pObj)
 
void Abc_NtkRetimeTranferToCopy (Abc_Ntk_t *pNtk)
 
void Abc_NtkRetimeTranferFromCopy (Abc_Ntk_t *pNtk)
 
Vec_Int_tAbc_NtkRetimeCollectLatchValues (Abc_Ntk_t *pNtk)
 
void Abc_NtkRetimeInsertLatchValues (Abc_Ntk_t *pNtk, Vec_Int_t *vValues)
 
Abc_Ntk_tAbc_NtkRetimeBackwardInitialStart (Abc_Ntk_t *pNtk)
 
void Abc_NtkRetimeBackwardInitialFinish (Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew, Vec_Int_t *vValuesOld, int fVerbose)
 
int Abc_NtkRetimeLValue (Abc_Ntk_t *pNtk, int nIterLimit, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 

Function Documentation

Vec_Ptr_t* Abc_NtkMaxFlow ( Abc_Ntk_t pNtk,
int  fForward,
int  fVerbose 
)

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

Synopsis [Implementation of max-flow/min-cut computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 143 of file retFlow.c.

144 {
145  Vec_Ptr_t * vMinCut;
146  Abc_Obj_t * pLatch;
147  int Flow, FlowCur, RetValue, i;
148  abctime clk = Abc_Clock();
149  int fUseDirectedFlow = 1;
150 
151  // find the max-flow
152  Abc_NtkCleanCopy( pNtk );
153  Flow = 0;
155  Abc_NtkForEachLatch( pNtk, pLatch, i )
156  {
157  if ( fForward )
158  {
159 // assert( !Abc_ObjFanout0(pLatch)->fMarkA );
160  FlowCur = Abc_NtkMaxFlowFwdPath2_rec( Abc_ObjFanout0(pLatch) );
161 // FlowCur = Abc_NtkMaxFlowFwdPath3_rec( Abc_ObjFanout0(pLatch), pLatch, 1 );
162  Flow += FlowCur;
163  }
164  else
165  {
166  assert( !Abc_ObjFanin0(pLatch)->fMarkA );
167  FlowCur = Abc_NtkMaxFlowBwdPath2_rec( Abc_ObjFanin0(pLatch) );
168  Flow += FlowCur;
169  }
170  if ( FlowCur )
172  }
173 
174  if ( !fUseDirectedFlow )
175  {
177  Abc_NtkForEachLatch( pNtk, pLatch, i )
178  {
179  if ( fForward )
180  {
181  // assert( !Abc_ObjFanout0(pLatch)->fMarkA );
182  FlowCur = Abc_NtkMaxFlowFwdPath_rec( Abc_ObjFanout0(pLatch) );
183  Flow += FlowCur;
184  }
185  else
186  {
187  assert( !Abc_ObjFanin0(pLatch)->fMarkA );
188  FlowCur = Abc_NtkMaxFlowBwdPath_rec( Abc_ObjFanin0(pLatch) );
189  Flow += FlowCur;
190  }
191  if ( FlowCur )
193  }
194  }
195 // Abc_NtkMaxFlowPrintFlow( pNtk, fForward );
196 
197  // mark the nodes reachable from the latches
199  Abc_NtkForEachLatch( pNtk, pLatch, i )
200  {
201  if ( fForward )
202  {
203 // assert( !Abc_ObjFanout0(pLatch)->fMarkA );
204  if ( fUseDirectedFlow )
205  RetValue = Abc_NtkMaxFlowFwdPath2_rec( Abc_ObjFanout0(pLatch) );
206 // RetValue = Abc_NtkMaxFlowFwdPath3_rec( Abc_ObjFanout0(pLatch), pLatch, 1 );
207  else
208  RetValue = Abc_NtkMaxFlowFwdPath_rec( Abc_ObjFanout0(pLatch) );
209  }
210  else
211  {
212  assert( !Abc_ObjFanin0(pLatch)->fMarkA );
213  if ( fUseDirectedFlow )
214  RetValue = Abc_NtkMaxFlowBwdPath2_rec( Abc_ObjFanin0(pLatch) );
215  else
216  RetValue = Abc_NtkMaxFlowBwdPath_rec( Abc_ObjFanin0(pLatch) );
217  }
218  assert( RetValue == 0 );
219  }
220 
221  // find the min-cut with the smallest volume
222  vMinCut = Abc_NtkMaxFlowMinCut( pNtk, fForward );
223  // verify the cut
224  if ( !Abc_NtkMaxFlowVerifyCut(pNtk, vMinCut, fForward) )
225  printf( "Abc_NtkMaxFlow() error! The computed min-cut is not a cut!\n" );
226  // make the cut retimable
227  Abc_NtkMaxFlowMinCutUpdate( pNtk, vMinCut, fForward );
228 
229  // report the results
230  if ( fVerbose )
231  {
232  printf( "L = %6d. %s max-flow = %6d. Min-cut = %6d. ",
233  Abc_NtkLatchNum(pNtk), fForward? "Forward " : "Backward", Flow, Vec_PtrSize(vMinCut) );
234 ABC_PRT( "Time", Abc_Clock() - clk );
235  }
236 
237 // Abc_NtkMaxFlowPrintCut( pNtk, vMinCut );
238  return vMinCut;
239 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_NtkMaxFlowFwdPath2_rec(Abc_Obj_t *pObj)
Definition: retFlow.c:442
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static void Abc_NtkMaxFlowMinCutUpdate(Abc_Ntk_t *pNtk, Vec_Ptr_t *vMinCut, int fForward)
Definition: retFlow.c:570
static abctime Abc_Clock()
Definition: abc_global.h:279
static int Abc_NtkMaxFlowBwdPath2_rec(Abc_Obj_t *pObj)
Definition: retFlow.c:397
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
static int Abc_NtkMaxFlowFwdPath_rec(Abc_Obj_t *pObj)
Definition: retFlow.c:304
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
static int Abc_NtkMaxFlowVerifyCut(Abc_Ntk_t *pNtk, Vec_Ptr_t *vMinCut, int fForward)
Definition: retFlow.c:668
static int Abc_NtkMaxFlowBwdPath_rec(Abc_Obj_t *pObj)
Definition: retFlow.c:252
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static void Abc_NtkIncrementTravId(Abc_Ntk_t *p)
Definition: abc.h:406
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:507
#define assert(ex)
Definition: util_old.h:213
static Vec_Ptr_t * Abc_NtkMaxFlowMinCut(Abc_Ntk_t *pNtk, int fForward)
Definition: retFlow.c:487
ABC_INT64_T abctime
Definition: abc_global.h:278
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Abc_NtkMaxFlowTest ( Abc_Ntk_t pNtk)

FUNCTION DEFINITIONS ///.

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

Synopsis [Test-bench for the max-flow computation.]

Description []

SideEffects []

SeeAlso []

Definition at line 104 of file retFlow.c.

105 {
106  Vec_Ptr_t * vMinCut;
107  Abc_Obj_t * pObj;
108  int i;
109 
110  // forward flow
111  Abc_NtkForEachPo( pNtk, pObj, i )
112  pObj->fMarkA = 1;
113  Abc_NtkForEachLatch( pNtk, pObj, i )
114  pObj->fMarkA = Abc_ObjFanin0(pObj)->fMarkA = 1;
115 // Abc_ObjFanin0(pObj)->fMarkA = 1;
116  vMinCut = Abc_NtkMaxFlow( pNtk, 1, 1 );
117  Vec_PtrFree( vMinCut );
118  Abc_NtkCleanMarkA( pNtk );
119 
120  // backward flow
121  Abc_NtkForEachPi( pNtk, pObj, i )
122  pObj->fMarkA = 1;
123  Abc_NtkForEachLatch( pNtk, pObj, i )
124  pObj->fMarkA = Abc_ObjFanout0(pObj)->fMarkA = 1;
125 // Abc_ObjFanout0(pObj)->fMarkA = 1;
126  vMinCut = Abc_NtkMaxFlow( pNtk, 0, 1 );
127  Vec_PtrFree( vMinCut );
128  Abc_NtkCleanMarkA( pNtk );
129 
130 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Ptr_t * Abc_NtkMaxFlow(Abc_Ntk_t *pNtk, int fForward, int fVerbose)
Definition: retFlow.c:143
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:663
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
#define Abc_NtkForEachPo(pNtk, pPo, i)
Definition: abc.h:517
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
#define Abc_NtkForEachPi(pNtk, pPi, i)
Definition: abc.h:513
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkRetime ( Abc_Ntk_t pNtk,
int  Mode,
int  nDelayLim,
int  fForwardOnly,
int  fBackwardOnly,
int  fOneStep,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Implementation of retiming.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file retCore.c.

48 {
49  int nLatches = Abc_NtkLatchNum(pNtk);
50  int nLevels = Abc_NtkLevel(pNtk);
51  int RetValue = 0;
52  abctime clkTotal = Abc_Clock();
53  int nNodesOld, nLatchesOld;
54  assert( Mode > 0 && Mode < 7 );
55  assert( !fForwardOnly || !fBackwardOnly );
56 
57  // cleanup the network
58  nNodesOld = Abc_NtkNodeNum(pNtk);
59  nLatchesOld = Abc_NtkLatchNum(pNtk);
60  Abc_NtkCleanupSeq(pNtk, 0, 0, 0);
61  if ( nNodesOld > Abc_NtkNodeNum(pNtk) || nLatchesOld > Abc_NtkLatchNum(pNtk) )
62  printf( "Cleanup before retiming removed %d dangling nodes and %d dangling latches.\n",
63  nNodesOld - Abc_NtkNodeNum(pNtk), nLatchesOld - Abc_NtkLatchNum(pNtk) );
64 
65  // perform retiming
66  switch ( Mode )
67  {
68  case 1: // forward
69  RetValue = Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 0, 0, fVerbose );
70  break;
71  case 2: // backward
72  RetValue = Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 0, 0, fVerbose );
73  break;
74  case 3: // min-area
75  RetValue = Abc_NtkRetimeMinArea( pNtk, fForwardOnly, fBackwardOnly, fVerbose );
76  break;
77  case 4: // min-delay
78  if ( !fBackwardOnly )
79  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 1, fOneStep, fVerbose );
80  if ( !fForwardOnly )
81  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 1, fOneStep, fVerbose );
82  break;
83  case 5: // min-area + min-delay
84  RetValue = Abc_NtkRetimeMinArea( pNtk, fForwardOnly, fBackwardOnly, fVerbose );
85  if ( !fBackwardOnly )
86  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 1, 1, 0, fVerbose );
87  if ( !fForwardOnly )
88  RetValue += Abc_NtkRetimeIncremental( pNtk, nDelayLim, 0, 1, 0, fVerbose );
89  break;
90  case 6: // Pan's algorithm
91  RetValue = Abc_NtkRetimeLValue( pNtk, 500, fVerbose );
92  break;
93  default:
94  printf( "Unknown retiming option.\n" );
95  break;
96  }
97  if ( fVerbose )
98  {
99  printf( "Reduction in area = %3d. Reduction in delay = %3d. ",
100  nLatches - Abc_NtkLatchNum(pNtk), nLevels - Abc_NtkLevel(pNtk) );
101  ABC_PRT( "Total runtime", Abc_Clock() - clkTotal );
102  }
103  timeRetime = Abc_Clock() - clkTotal;
104  return RetValue;
105 }
int Abc_NtkRetimeLValue(Abc_Ntk_t *pNtk, int nIterLimit, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retLvalue.c:61
ABC_NAMESPACE_IMPL_START abctime timeRetime
DECLARATIONS ///.
Definition: retCore.c:30
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static abctime Abc_Clock()
Definition: abc_global.h:279
int Abc_NtkRetimeMinArea(Abc_Ntk_t *pNtk, int fForwardOnly, int fBackwardOnly, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retArea.c:53
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Abc_NtkRetimeIncremental(Abc_Ntk_t *pNtk, int nDelayLim, int fForward, int fMinDelay, int fOneStep, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retIncrem.c:47
#define assert(ex)
Definition: util_old.h:213
ABC_DLL int Abc_NtkCleanupSeq(Abc_Ntk_t *pNtk, int fLatchSweep, int fAutoSweep, int fVerbose)
Definition: abcSweep.c:909
ABC_INT64_T abctime
Definition: abc_global.h:278
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
void Abc_NtkRetimeBackwardInitialFinish ( Abc_Ntk_t pNtk,
Abc_Ntk_t pNtkNew,
Vec_Int_t vValuesOld,
int  fVerbose 
)

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

Synopsis [Transfer latch initial values to pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 279 of file retInit.c.

280 {
281  Vec_Int_t * vValuesNew;
282  Abc_Obj_t * pObj;
283  int i;
284  // create PIs corresponding to the initial values
285  Abc_NtkForEachObj( pNtk, pObj, i )
286  if ( Abc_ObjIsLatch(pObj) )
287  Abc_ObjAddFanin( pObj->pCopy, Abc_NtkCreatePi(pNtkNew) );
288  // assign dummy node names
289  Abc_NtkAddDummyPiNames( pNtkNew );
290  Abc_NtkAddDummyPoNames( pNtkNew );
291  // check the network
292  if ( !Abc_NtkCheck( pNtkNew ) )
293  fprintf( stdout, "Abc_NtkRetimeBackwardInitialFinish(): Network check has failed.\n" );
294  // derive new initial values
295  vValuesNew = Abc_NtkRetimeInitialValues( pNtkNew, vValuesOld, fVerbose );
296  // insert new initial values
297  Abc_NtkRetimeInsertLatchValues( pNtk, vValuesNew );
298  if ( vValuesNew ) Vec_IntFree( vValuesNew );
299 }
void Abc_NtkRetimeInsertLatchValues(Abc_Ntk_t *pNtk, Vec_Int_t *vValues)
Definition: retInit.c:231
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
static void check(int expr)
Definition: satSolver.c:46
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:398
Vec_Int_t * Abc_NtkRetimeInitialValues(Abc_Ntk_t *pNtkCone, Vec_Int_t *vValues, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retInit.c:47
if(last==0)
Definition: sparse_int.h:34
static Abc_Obj_t * Abc_NtkCreatePi(Abc_Ntk_t *pNtk)
Definition: abc.h:303
void Abc_NtkRetimeBackwardInitialFinish(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew, Vec_Int_t *vValuesOld, int fVerbose)
Definition: retInit.c:279
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition: abcNames.c:378
Abc_Ntk_t* Abc_NtkRetimeBackwardInitialStart ( Abc_Ntk_t pNtk)

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

Synopsis [Transfer latch initial values to pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 254 of file retInit.c.

255 {
256  Abc_Ntk_t * pNtkNew;
257  Abc_Obj_t * pObj;
258  int i;
259  // create the network used for the initial state computation
260  pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, ABC_FUNC_SOP, 1 );
261  // create POs corresponding to the initial values
262  Abc_NtkForEachObj( pNtk, pObj, i )
263  if ( Abc_ObjIsLatch(pObj) )
264  pObj->pCopy = Abc_NtkCreatePo(pNtkNew);
265  return pNtkNew;
266 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition: abcNtk.c:50
if(last==0)
Definition: sparse_int.h:34
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static Abc_Obj_t * Abc_NtkCreatePo(Abc_Ntk_t *pNtk)
Definition: abc.h:304
Vec_Int_t* Abc_NtkRetimeCollectLatchValues ( Abc_Ntk_t pNtk)

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

Synopsis [Transfer latch initial values to pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file retInit.c.

209 {
210  Vec_Int_t * vValues;
211  Abc_Obj_t * pObj;
212  int i;
213  vValues = Vec_IntAlloc( Abc_NtkLatchNum(pNtk) );
214  Abc_NtkForEachObj( pNtk, pObj, i )
215  if ( Abc_ObjIsLatch(pObj) )
216  Vec_IntPush( vValues, Abc_LatchIsInit1(pObj) );
217  return vValues;
218 }
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
if(last==0)
Definition: sparse_int.h:34
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
static int Abc_LatchIsInit1(Abc_Obj_t *pLatch)
Definition: abc.h:423
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Abc_NtkRetimeFinalizeLatches ( Abc_Ntk_t pNtk,
st__table tLatches,
int  nIdMaxStart 
)

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

Synopsis [Finalizes the latches after retiming.]

Description [Reuses the LIs/LOs for old latches.]

SideEffects []

SeeAlso []

Definition at line 146 of file retIncrem.c.

147 {
148  Vec_Ptr_t * vCisOld, * vCosOld, * vBoxesOld, * vCisNew, * vCosNew, * vBoxesNew;
149  Abc_Obj_t * pObj, * pLatch, * pLatchIn, * pLatchOut;
150  int i, Index;
151  // create new arrays
152  vCisOld = pNtk->vCis; pNtk->vCis = NULL; vCisNew = Vec_PtrAlloc( 100 );
153  vCosOld = pNtk->vCos; pNtk->vCos = NULL; vCosNew = Vec_PtrAlloc( 100 );
154  vBoxesOld = pNtk->vBoxes; pNtk->vBoxes = NULL; vBoxesNew = Vec_PtrAlloc( 100 );
155  // copy boxes and their CIs/COs
156  Vec_PtrForEachEntryStop( Abc_Obj_t *, vCisOld, pObj, i, Vec_PtrSize(vCisOld) - st__count(tLatches) )
157  Vec_PtrPush( vCisNew, pObj );
158  Vec_PtrForEachEntryStop( Abc_Obj_t *, vCosOld, pObj, i, Vec_PtrSize(vCosOld) - st__count(tLatches) )
159  Vec_PtrPush( vCosNew, pObj );
160  Vec_PtrForEachEntryStop( Abc_Obj_t *, vBoxesOld, pObj, i, Vec_PtrSize(vBoxesOld) - st__count(tLatches) )
161  Vec_PtrPush( vBoxesNew, pObj );
162  // go through the latches
163  Abc_NtkForEachObj( pNtk, pLatch, i )
164  {
165  if ( !Abc_ObjIsLatch(pLatch) )
166  continue;
167  if ( Abc_ObjId(pLatch) >= (unsigned)nIdMaxStart )
168  {
169  // this is a new latch
170  pLatchIn = Abc_NtkCreateBi(pNtk);
171  pLatchOut = Abc_NtkCreateBo(pNtk);
172  Abc_ObjAssignName( pLatchOut, Abc_ObjName(pLatch), "_out" );
173  Abc_ObjAssignName( pLatchIn, Abc_ObjName(pLatch), "_in" );
174  }
175  else
176  {
177  // this is an old latch
178  // get its number in the original order
179  if ( ! st__lookup( tLatches, (char *)pLatch, (char **)&Index ) )
180  {
181  printf( "Abc_NtkRetimeFinalizeLatches(): Internal error.\n" );
182  return 0;
183  }
184  assert( pLatch == Vec_PtrEntry(vBoxesOld, Vec_PtrSize(vBoxesOld) - st__count(tLatches) + Index) );
185  // reconnect with the old LIs/LOs
186  pLatchIn = (Abc_Obj_t *)Vec_PtrEntry( vCosOld, Vec_PtrSize(vCosOld) - st__count(tLatches) + Index );
187  pLatchOut = (Abc_Obj_t *)Vec_PtrEntry( vCisOld, Vec_PtrSize(vCisOld) - st__count(tLatches) + Index );
188  }
189  // connect
190  Abc_ObjAddFanin( pLatchIn, Abc_ObjFanin0(pLatch) );
191  Abc_ObjPatchFanin( pLatch, Abc_ObjFanin0(pLatch), pLatchIn );
192  if ( Abc_ObjFanoutNum(pLatch) > 0 )
193  Abc_ObjTransferFanout( pLatch, pLatchOut );
194  Abc_ObjAddFanin( pLatchOut, pLatch );
195  // add to the arrays
196  Vec_PtrPush( vCisNew, pLatchOut );
197  Vec_PtrPush( vCosNew, pLatchIn );
198  Vec_PtrPush( vBoxesNew, pLatch );
199  }
200  // free useless Cis/Cos
201  Vec_PtrForEachEntry( Abc_Obj_t *, vCisOld, pObj, i )
202  if ( !Abc_ObjIsPi(pObj) && Abc_ObjFaninNum(pObj) == 0 && Abc_ObjFanoutNum(pObj) == 0 )
203  Abc_NtkDeleteObj(pObj);
204  Vec_PtrForEachEntry( Abc_Obj_t *, vCosOld, pObj, i )
205  if ( !Abc_ObjIsPo(pObj) && Abc_ObjFaninNum(pObj) == 0 && Abc_ObjFanoutNum(pObj) == 0 )
206  Abc_NtkDeleteObj(pObj);
207  // set the new arrays
208  pNtk->vCis = vCisNew; Vec_PtrFree( vCisOld );
209  pNtk->vCos = vCosNew; Vec_PtrFree( vCosOld );
210  pNtk->vBoxes = vBoxesNew; Vec_PtrFree( vBoxesOld );
211  return 1;
212 }
static unsigned Abc_ObjId(Abc_Obj_t *pObj)
Definition: abc.h:329
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Vec_Ptr_t * vBoxes
Definition: abc.h:168
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
static int Abc_ObjIsPi(Abc_Obj_t *pObj)
Definition: abc.h:347
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
Definition: vecPtr.h:606
ABC_DLL char * Abc_ObjAssignName(Abc_Obj_t *pObj, char *pName, char *pSuffix)
Definition: abcNames.c:68
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
Vec_Ptr_t * vCis
Definition: abc.h:165
static Abc_Obj_t * Abc_NtkCreateBo(Abc_Ntk_t *pNtk)
Definition: abc.h:306
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
#define st__count(table)
Definition: st.h:71
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
Vec_Ptr_t * vCos
Definition: abc.h:166
if(last==0)
Definition: sparse_int.h:34
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
static void * Vec_PtrEntry(Vec_Ptr_t *p, int i)
Definition: vecPtr.h:362
int st__lookup(st__table *table, const char *key, char **value)
Definition: st.c:114
#define Vec_PtrForEachEntryStop(Type, vVec, pEntry, i, Stop)
Definition: vecPtr.h:59
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
static int Abc_ObjIsPo(Abc_Obj_t *pObj)
Definition: abc.h:348
#define assert(ex)
Definition: util_old.h:213
static Abc_Obj_t * Abc_NtkCreateBi(Abc_Ntk_t *pNtk)
Definition: abc.h:305
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkRetimeIncremental ( Abc_Ntk_t pNtk,
int  nDelayLim,
int  fForward,
int  fMinDelay,
int  fOneStep,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Performs retiming in one direction.]

Description [Currently does not retime over black boxes.]

SideEffects []

SeeAlso []

Definition at line 47 of file retIncrem.c.

48 {
49  Abc_Ntk_t * pNtkCopy = NULL;
50  Vec_Ptr_t * vBoxes;
51  st__table * tLatches;
52  int nLatches = Abc_NtkLatchNum(pNtk);
53  int nIdMaxStart = Abc_NtkObjNumMax(pNtk);
54  int RetValue;
55  int nIterLimit = -1; // Suppress "might be used uninitialized"
56  if ( Abc_NtkNodeNum(pNtk) == 0 )
57  return 0;
58  // reorder CI/CO/latch inputs
59  Abc_NtkOrderCisCos( pNtk );
60  if ( fMinDelay )
61  {
62  nIterLimit = fOneStep? 1 : 2 * Abc_NtkLevel(pNtk);
63  pNtkCopy = Abc_NtkDup( pNtk );
64  tLatches = Abc_NtkRetimePrepareLatches( pNtkCopy );
65  st__free_table( tLatches );
66  }
67  // collect latches and remove CIs/COs
68  tLatches = Abc_NtkRetimePrepareLatches( pNtk );
69  // share the latches
70  Abc_NtkRetimeShareLatches( pNtk, 0 );
71  // save boxes
72  vBoxes = pNtk->vBoxes; pNtk->vBoxes = NULL;
73  // perform the retiming
74  if ( fMinDelay )
75  Abc_NtkRetimeMinDelay( pNtk, pNtkCopy, nDelayLim, nIterLimit, fForward, fVerbose );
76  else
77  Abc_NtkRetimeOneWay( pNtk, fForward, fVerbose );
78  if ( fMinDelay )
79  Abc_NtkDelete( pNtkCopy );
80  // share the latches
81  Abc_NtkRetimeShareLatches( pNtk, 0 );
82  // restore boxes
83  pNtk->vBoxes = vBoxes;
84  // finalize the latches
85  RetValue = Abc_NtkRetimeFinalizeLatches( pNtk, tLatches, nIdMaxStart );
86  st__free_table( tLatches );
87  if ( RetValue == 0 )
88  return 0;
89  // fix the COs
90 // Abc_NtkLogicMakeSimpleCos( pNtk, 0 );
91  // check for correctness
92  if ( !Abc_NtkCheck( pNtk ) )
93  fprintf( stdout, "Abc_NtkRetimeForward(): Network check has failed.\n" );
94  // return the number of latches saved
95  return nLatches - Abc_NtkLatchNum(pNtk);
96 }
void st__free_table(st__table *table)
Definition: st.c:81
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_NtkObjNumMax(Abc_Ntk_t *pNtk)
Definition: abc.h:284
Vec_Ptr_t * vBoxes
Definition: abc.h:168
int Abc_NtkRetimeMinDelay(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkCopy, int nDelayLim, int nIterLimit, int fForward, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retDelay.c:50
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
st__table * Abc_NtkRetimePrepareLatches(Abc_Ntk_t *pNtk)
Definition: retIncrem.c:109
void Abc_NtkRetimeShareLatches(Abc_Ntk_t *pNtk, int fInitial)
Definition: retIncrem.c:426
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
Definition: st.h:52
static ABC_NAMESPACE_IMPL_START int Abc_NtkRetimeOneWay(Abc_Ntk_t *pNtk, int fForward, int fVerbose)
DECLARATIONS ///.
Definition: retIncrem.c:225
int Abc_NtkRetimeFinalizeLatches(Abc_Ntk_t *pNtk, st__table *tLatches, int nIdMaxStart)
Definition: retIncrem.c:146
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition: abcDfs.c:1265
ABC_DLL void Abc_NtkOrderCisCos(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:71
Vec_Int_t* Abc_NtkRetimeInitialValues ( Abc_Ntk_t pNtkCone,
Vec_Int_t vValues,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Computes initial values of the new latches.]

Description []

SideEffects []

SeeAlso []

Definition at line 47 of file retInit.c.

48 {
49  Vec_Int_t * vSolution;
50  Abc_Ntk_t * pNtkMiter, * pNtkLogic;
51  int RetValue;
52  abctime clk;
53  if ( pNtkCone == NULL )
54  return Vec_IntDup( vValues );
55  // convert the target network to AIG
56  pNtkLogic = Abc_NtkDup( pNtkCone );
57  Abc_NtkToAig( pNtkLogic );
58  // get the miter
59  pNtkMiter = Abc_NtkCreateTarget( pNtkLogic, pNtkLogic->vCos, vValues );
60  if ( fVerbose )
61  printf( "The miter for initial state computation has %d AIG nodes. ", Abc_NtkNodeNum(pNtkMiter) );
62  // solve the miter
63  clk = Abc_Clock();
64  RetValue = Abc_NtkMiterSat( pNtkMiter, (ABC_INT64_T)500000, (ABC_INT64_T)50000000, 0, NULL, NULL );
65  if ( fVerbose )
66  { ABC_PRT( "SAT solving time", Abc_Clock() - clk ); }
67  // analyze the result
68  if ( RetValue == 1 )
69  printf( "Abc_NtkRetimeInitialValues(): The problem is unsatisfiable. DC latch values are used.\n" );
70  else if ( RetValue == -1 )
71  printf( "Abc_NtkRetimeInitialValues(): The SAT problem timed out. DC latch values are used.\n" );
72  else if ( !Abc_NtkRetimeVerifyModel( pNtkCone, vValues, pNtkMiter->pModel ) )
73  printf( "Abc_NtkRetimeInitialValues(): The computed counter-example is incorrect.\n" );
74  // set the values of the latches
75  vSolution = RetValue? NULL : Vec_IntAllocArray( pNtkMiter->pModel, Abc_NtkPiNum(pNtkLogic) );
76  pNtkMiter->pModel = NULL;
77  Abc_NtkDelete( pNtkMiter );
78  Abc_NtkDelete( pNtkLogic );
79  return vSolution;
80 }
static Vec_Int_t * Vec_IntDup(Vec_Int_t *pVec)
Definition: vecInt.h:214
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Vec_Int_t * Vec_IntAllocArray(int *pArray, int nSize)
Definition: bblif.c:214
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:419
static abctime Abc_Clock()
Definition: abc_global.h:279
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
int * pModel
Definition: abc.h:198
static int Abc_NtkNodeNum(Abc_Ntk_t *pNtk)
Definition: abc.h:293
ABC_DLL Abc_Ntk_t * Abc_NtkCreateTarget(Abc_Ntk_t *pNtk, Vec_Ptr_t *vRoots, Vec_Int_t *vValues)
Definition: abcNtk.c:1094
Vec_Ptr_t * vCos
Definition: abc.h:166
ABC_DLL int Abc_NtkMiterSat(Abc_Ntk_t *pNtk, ABC_INT64_T nConfLimit, ABC_INT64_T nInsLimit, int fVerbose, ABC_INT64_T *pNumConfs, ABC_INT64_T *pNumInspects)
FUNCTION DEFINITIONS ///.
Definition: abcSat.c:53
static ABC_NAMESPACE_IMPL_START int Abc_NtkRetimeVerifyModel(Abc_Ntk_t *pNtkCone, Vec_Int_t *vValues, int *pModel)
DECLARATIONS ///.
Definition: retInit.c:133
static int Abc_NtkPiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:285
#define ABC_PRT(a, t)
Definition: abc_global.h:220
ABC_DLL int Abc_NtkToAig(Abc_Ntk_t *pNtk)
Definition: abcFunc.c:1192
ABC_INT64_T abctime
Definition: abc_global.h:278
void Abc_NtkRetimeInsertLatchValues ( Abc_Ntk_t pNtk,
Vec_Int_t vValues 
)

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

Synopsis [Transfer latch initial values from pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 231 of file retInit.c.

232 {
233  Abc_Obj_t * pObj;
234  int i, Counter = 0;
235  Abc_NtkForEachObj( pNtk, pObj, i )
236  if ( Abc_ObjIsLatch(pObj) )
237  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)Counter++;
238  Abc_NtkForEachObj( pNtk, pObj, i )
239  if ( Abc_ObjIsLatch(pObj) )
240  pObj->pData = (Abc_Obj_t *)(ABC_PTRUINT_T)(vValues? (Vec_IntEntry(vValues,(int)(ABC_PTRUINT_T)pObj->pCopy)? ABC_INIT_ONE : ABC_INIT_ZERO) : ABC_INIT_DC);
241 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Vec_IntEntry(Vec_Int_t *p, int i)
Definition: bblif.c:268
if(last==0)
Definition: sparse_int.h:34
static int Counter
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Abc_NtkRetimeLValue ( Abc_Ntk_t pNtk,
int  nIterLimit,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Implements Pan's retiming algorithm.]

Description []

SideEffects []

SeeAlso []

Definition at line 61 of file retLvalue.c.

62 {
63  Vec_Int_t * vLags;
64  int nLatches = Abc_NtkLatchNum(pNtk);
65  assert( Abc_NtkIsLogic( pNtk ) );
66  // get the lags
67  vLags = Abc_NtkRetimeGetLags( pNtk, nIterLimit, fVerbose );
68  // compute the retiming
69 // Abc_NtkRetimeUsingLags( pNtk, vLags, fVerbose );
70  Vec_IntFree( vLags );
71  // fix the COs
72 // Abc_NtkLogicMakeSimpleCos( pNtk, 0 );
73  // check for correctness
74  if ( !Abc_NtkCheck( pNtk ) )
75  fprintf( stdout, "Abc_NtkRetimeLValue(): Network check has failed.\n" );
76  // return the number of latches saved
77  return nLatches - Abc_NtkLatchNum(pNtk);
78 }
static int Abc_NtkIsLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:250
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static Vec_Int_t * Abc_NtkRetimeGetLags(Abc_Ntk_t *pNtk, int nIterLimit, int fVerbose)
Definition: retLvalue.c:91
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_NAMESPACE_HEADER_START int Abc_NtkRetimeMinArea ( Abc_Ntk_t pNtk,
int  fForwardOnly,
int  fBackwardOnly,
int  fVerbose 
)

INCLUDES ///.

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

FileName [retInt.h]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Retiming package.]

Synopsis [Internal declarations.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - Oct 31, 2006.]

Revision [

Id:
retInt.h,v 1.00 2006/10/31 00:00:00 alanmi Exp

]PARAMETERS ///STRUCTURE DEFINITIONS ///MACRO DEFINITIONS ///FUNCTION DECLARATIONS ///

INCLUDES ///.

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

Synopsis [Performs min-area retiming.]

Description [Returns the number of latches reduced.]

SideEffects []

SeeAlso []

Definition at line 53 of file retArea.c.

54 {
55  Abc_Ntk_t * pNtkTotal = NULL, * pNtkBottom;
56  Vec_Int_t * vValuesNew = NULL, * vValues;
57  int nLatches = Abc_NtkLatchNum(pNtk);
58  int fOneFrame = 0;
59  assert( !fForwardOnly || !fBackwardOnly );
60  // there should not be black boxes
61  assert( Abc_NtkIsSopLogic(pNtk) );
62  assert( Abc_NtkLatchNum(pNtk) == Vec_PtrSize(pNtk->vBoxes) );
63  // reorder CI/CO/latch inputs
64  Abc_NtkOrderCisCos( pNtk );
65  // perform forward retiming
66  if ( !fBackwardOnly )
67  {
68  if ( fOneFrame )
69  Abc_NtkRetimeMinAreaOne( pNtk, 1, fVerbose );
70  else
71  while ( Abc_NtkRetimeMinAreaOne( pNtk, 1, fVerbose ) );
72  }
73  // remember initial values
74  vValues = Abc_NtkCollectLatchValues( pNtk );
75  // perform backward retiming
76  if ( !fForwardOnly )
77  {
78  if ( fOneFrame )
79  pNtkTotal = Abc_NtkRetimeMinAreaOne( pNtk, 0, fVerbose );
80  else
81  while ( (pNtkBottom = Abc_NtkRetimeMinAreaOne( pNtk, 0, fVerbose )) )
82  pNtkTotal = Abc_NtkAttachBottom( pNtkTotal, pNtkBottom );
83  }
84  // compute initial values
85  vValuesNew = Abc_NtkRetimeInitialValues( pNtkTotal, vValues, fVerbose );
86  if ( pNtkTotal ) Abc_NtkDelete( pNtkTotal );
87  // insert new initial values
88  Abc_NtkInsertLatchValues( pNtk, vValuesNew );
89  if ( vValuesNew ) Vec_IntFree( vValuesNew );
90  if ( vValues ) Vec_IntFree( vValues );
91  // fix the COs (this changes the circuit structure)
92 // Abc_NtkLogicMakeSimpleCos( pNtk, 0 );
93  // check for correctness
94  if ( !Abc_NtkCheck( pNtk ) )
95  fprintf( stdout, "Abc_NtkRetimeMinArea(): Network check has failed.\n" );
96  // return the number of latches saved
97  return nLatches - Abc_NtkLatchNum(pNtk);
98 }
ABC_DLL void Abc_NtkInsertLatchValues(Abc_Ntk_t *pNtk, Vec_Int_t *vValues)
Definition: abcLatch.c:241
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
Vec_Ptr_t * vBoxes
Definition: abc.h:168
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition: abcCheck.c:61
static int Abc_NtkIsSopLogic(Abc_Ntk_t *pNtk)
Definition: abc.h:264
static int Vec_PtrSize(Vec_Ptr_t *p)
Definition: vecPtr.h:295
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition: abcNtk.c:1233
Vec_Int_t * Abc_NtkRetimeInitialValues(Abc_Ntk_t *pNtkCone, Vec_Int_t *vValues, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: retInit.c:47
ABC_DLL Vec_Int_t * Abc_NtkCollectLatchValues(Abc_Ntk_t *pNtk)
Definition: abcLatch.c:187
Abc_Ntk_t * Abc_NtkAttachBottom(Abc_Ntk_t *pNtkTop, Abc_Ntk_t *pNtkBottom)
Definition: abcNtk.c:760
static ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkRetimeMinAreaOne(Abc_Ntk_t *pNtk, int fForward, int fVerbose)
DECLARATIONS ///.
Definition: retArea.c:111
#define assert(ex)
Definition: util_old.h:213
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_DLL void Abc_NtkOrderCisCos(Abc_Ntk_t *pNtk)
Definition: abcUtil.c:71
int Abc_NtkRetimeMinDelay ( Abc_Ntk_t pNtk,
Abc_Ntk_t pNtkCopy,
int  nDelayLim,
int  nIterLimit,
int  fForward,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Retimes incrementally for minimum delay.]

Description [This procedure cannot be called in the application code because it assumes that the network is preprocessed by removing LIs/LOs.]

SideEffects []

SeeAlso []

Definition at line 50 of file retDelay.c.

51 {
52  int IterBest, DelayBest;
53  int IterBest2, DelayBest2;
54  // try to find the best delay iteration on a copy
55  DelayBest = Abc_NtkRetimeMinDelayTry( pNtkCopy, nDelayLim, fForward, 0, nIterLimit, &IterBest, fVerbose );
56  if ( IterBest == 0 )
57  return 1;
58  // perform the given number of iterations on the original network
59  DelayBest2 = Abc_NtkRetimeMinDelayTry( pNtk, nDelayLim, fForward, 1, IterBest, &IterBest2, fVerbose );
60  assert( DelayBest == DelayBest2 );
61  assert( IterBest == IterBest2 );
62  return 1;
63 }
static ABC_NAMESPACE_IMPL_START int Abc_NtkRetimeMinDelayTry(Abc_Ntk_t *pNtk, int nDelayLim, int fForward, int fInitial, int nIterLimit, int *pIterBest, int fVerbose)
DECLARATIONS ///.
Definition: retDelay.c:76
#define assert(ex)
Definition: util_old.h:213
void Abc_NtkRetimeNode ( Abc_Obj_t pObj,
int  fForward,
int  fInitial 
)

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

Synopsis [Retimes the node backward or forward.]

Description []

SideEffects []

SeeAlso []

Definition at line 315 of file retIncrem.c.

316 {
317  Abc_Ntk_t * pNtkNew = NULL;
318  Vec_Ptr_t * vNodes;
319  Abc_Obj_t * pNext, * pLatch;
320  int i;
321  vNodes = Vec_PtrAlloc( 10 );
322  if ( fForward )
323  {
324  // compute the initial value
325  if ( fInitial )
326  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)Abc_ObjSopSimulate( pObj );
327  // collect fanins
328  Abc_NodeCollectFanins( pObj, vNodes );
329  // make the node point to the fanins fanins
330  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNext, i )
331  {
332  assert( Abc_ObjIsLatch(pNext) );
333  Abc_ObjPatchFanin( pObj, pNext, Abc_ObjFanin0(pNext) );
334  if ( Abc_ObjFanoutNum(pNext) == 0 )
335  Abc_NtkDeleteObj(pNext);
336  }
337  // add a new latch on top
338  pNext = Abc_NtkCreateLatch(pObj->pNtk);
339  if ( Abc_ObjFanoutNum(pObj) > 0 )
340  Abc_ObjTransferFanout( pObj, pNext );
341  Abc_ObjAddFanin( pNext, pObj );
342  // set the initial value
343  if ( fInitial )
344  pNext->pCopy = pObj->pCopy;
345  }
346  else
347  {
348  // compute the initial value
349  if ( fInitial )
350  {
351  pNtkNew = Abc_ObjFanout0(pObj)->pCopy->pNtk;
352  Abc_NtkDupObj( pNtkNew, pObj, 0 );
353  Abc_ObjForEachFanout( pObj, pNext, i )
354  {
355  assert( Abc_ObjFaninNum(pNext->pCopy) == 0 );
356  Abc_ObjAddFanin( pNext->pCopy, pObj->pCopy );
357  }
358  }
359  // collect fanouts
360  Abc_NodeCollectFanouts( pObj, vNodes );
361  // make the fanouts fanouts point to the node
362  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNext, i )
363  {
364  assert( Abc_ObjIsLatch(pNext) );
365  Abc_ObjTransferFanout( pNext, pObj );
366  Abc_NtkDeleteObj( pNext );
367  }
368  // add new latches to the fanins
369  Abc_ObjForEachFanin( pObj, pNext, i )
370  {
371  pLatch = Abc_NtkCreateLatch(pObj->pNtk);
372  Abc_ObjPatchFanin( pObj, pNext, pLatch );
373  Abc_ObjAddFanin( pLatch, pNext );
374  // create buffer isomorphic to this latch
375  if ( fInitial )
376  {
377  pLatch->pCopy = Abc_NtkCreateNodeBuf( pNtkNew, NULL );
378  Abc_ObjAddFanin( pObj->pCopy, pLatch->pCopy );
379  }
380  }
381  }
382  Vec_PtrFree( vNodes );
383 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_ObjFaninNum(Abc_Obj_t *pObj)
Definition: abc.h:364
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition: abcObj.c:337
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL void Abc_ObjPatchFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFaninOld, Abc_Obj_t *pFaninNew)
Definition: abcFanio.c:172
Abc_Obj_t * pCopy
Definition: abc.h:148
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
int Abc_ObjSopSimulate(Abc_Obj_t *pObj)
Definition: retInit.c:93
ABC_DLL Abc_Obj_t * Abc_NtkCreateNodeBuf(Abc_Ntk_t *pNtk, Abc_Obj_t *pFanin)
Definition: abcObj.c:692
static Abc_Obj_t * Abc_NtkCreateLatch(Abc_Ntk_t *pNtk)
Definition: abc.h:309
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
Abc_Ntk_t * pNtk
Definition: abc.h:130
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
ABC_DLL void Abc_NodeCollectFanins(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: abcUtil.c:1587
#define assert(ex)
Definition: util_old.h:213
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: abcUtil.c:1607
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
int Abc_NtkRetimeNodeIsEnabled ( Abc_Obj_t pObj,
int  fForward 
)

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

Synopsis [Returns 1 if retiming forward/backward is possible.]

Description []

SideEffects []

SeeAlso []

Definition at line 284 of file retIncrem.c.

285 {
286  Abc_Obj_t * pNext;
287  int i;
288  assert( Abc_ObjIsNode(pObj) );
289  if ( fForward )
290  {
291  Abc_ObjForEachFanin( pObj, pNext, i )
292  if ( !Abc_ObjIsLatch(pNext) )
293  return 0;
294  }
295  else
296  {
297  Abc_ObjForEachFanout( pObj, pNext, i )
298  if ( !Abc_ObjIsLatch(pNext) )
299  return 0;
300  }
301  return 1;
302 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
static int Abc_ObjIsNode(Abc_Obj_t *pObj)
Definition: abc.h:355
if(last==0)
Definition: sparse_int.h:34
else
Definition: sparse_int.h:55
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition: abc.h:524
#define assert(ex)
Definition: util_old.h:213
st__table* Abc_NtkRetimePrepareLatches ( Abc_Ntk_t pNtk)

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

Synopsis [Prepares the network for retiming.]

Description [Hash latches into their number in the original network.]

SideEffects []

SeeAlso []

Definition at line 109 of file retIncrem.c.

110 {
111  st__table * tLatches;
112  Abc_Obj_t * pLatch, * pLatchIn, * pLatchOut, * pFanin;
113  int i, nOffSet = Abc_NtkBoxNum(pNtk) - Abc_NtkLatchNum(pNtk);
114  // collect latches and remove CIs/COs
115  tLatches = st__init_table( st__ptrcmp, st__ptrhash );
116  Abc_NtkForEachLatch( pNtk, pLatch, i )
117  {
118  // map latch into its true number
119  st__insert( tLatches, (char *)(ABC_PTRUINT_T)pLatch, (char *)(ABC_PTRUINT_T)(i-nOffSet) );
120  // disconnect LI
121  pLatchIn = Abc_ObjFanin0(pLatch);
122  pFanin = Abc_ObjFanin0(pLatchIn);
123  Abc_ObjTransferFanout( pLatchIn, pFanin );
124  Abc_ObjDeleteFanin( pLatchIn, pFanin );
125  // disconnect LO
126  pLatchOut = Abc_ObjFanout0(pLatch);
127  pFanin = Abc_ObjFanin0(pLatchOut);
128  if ( Abc_ObjFanoutNum(pLatchOut) > 0 )
129  Abc_ObjTransferFanout( pLatchOut, pFanin );
130  Abc_ObjDeleteFanin( pLatchOut, pFanin );
131  }
132  return tLatches;
133 }
int st__insert(st__table *table, const char *key, char *value)
Definition: st.c:171
static int Abc_ObjFanoutNum(Abc_Obj_t *pObj)
Definition: abc.h:365
static int Abc_NtkBoxNum(Abc_Ntk_t *pNtk)
Definition: abc.h:289
int st__ptrcmp(const char *, const char *)
Definition: st.c:480
static int Abc_NtkLatchNum(Abc_Ntk_t *pNtk)
Definition: abc.h:294
static Abc_Obj_t * Abc_ObjFanin0(Abc_Obj_t *pObj)
Definition: abc.h:373
st__table * st__init_table(st__compare_func_type compare, st__hash_func_type hash)
Definition: st.c:72
Definition: st.h:52
#define Abc_NtkForEachLatch(pNtk, pObj, i)
Definition: abc.h:497
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
ABC_DLL void Abc_ObjDeleteFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:111
int st__ptrhash(const char *, int)
Definition: st.c:468
static Abc_Obj_t * Abc_ObjFanout0(Abc_Obj_t *pObj)
Definition: abc.h:371
void Abc_NtkRetimeShareLatches ( Abc_Ntk_t pNtk,
int  fInitial 
)

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

Synopsis [Retimes the node backward or forward.]

Description []

SideEffects []

SeeAlso []

Definition at line 426 of file retIncrem.c.

427 {
428  Vec_Ptr_t * vNodes;
429  Abc_Obj_t * pFanin, * pLatchTop, * pLatchCur;
430  int i, k;
431  vNodes = Vec_PtrAlloc( 10 );
432  // consider latch fanins
433  Abc_NtkForEachObj( pNtk, pFanin, i )
434  {
435  if ( Abc_NtkRetimeCheckCompatibleLatchFanouts(pFanin) <= 1 )
436  continue;
437  // get the first latch
438  pLatchTop = NULL;
439  Abc_ObjForEachFanout( pFanin, pLatchTop, k )
440  if ( Abc_ObjIsLatch(pLatchTop) )
441  break;
442  assert( pLatchTop && Abc_ObjIsLatch(pLatchTop) );
443  // redirect compatible fanout latches to the first latch
444  Abc_NodeCollectFanouts( pFanin, vNodes );
445  Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pLatchCur, k )
446  {
447  if ( !Abc_ObjIsLatch(pLatchCur) )
448  continue;
449  if ( pLatchCur == pLatchTop )
450  continue;
451  if ( pLatchCur->pData != pLatchTop->pData )
452  continue;
453  // connect the initial state
454  if ( fInitial )
455  Abc_ObjAddFanin( pLatchCur->pCopy, pLatchTop->pCopy );
456  // redirect the fanouts
457  Abc_ObjTransferFanout( pLatchCur, pLatchTop );
458  Abc_NtkDeleteObj(pLatchCur);
459  }
460  }
461  Vec_PtrFree( vNodes );
462 }
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
int Abc_NtkRetimeCheckCompatibleLatchFanouts(Abc_Obj_t *pObj)
Definition: retIncrem.c:396
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition: abcFanio.c:84
ABC_DLL void Abc_NtkDeleteObj(Abc_Obj_t *pObj)
Definition: abcObj.c:167
if(last==0)
Definition: sparse_int.h:34
ABC_DLL void Abc_ObjTransferFanout(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition: abcFanio.c:264
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition: abc.h:526
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
#define assert(ex)
Definition: util_old.h:213
ABC_DLL void Abc_NodeCollectFanouts(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition: abcUtil.c:1607
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition: vecPtr.h:55
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Abc_NtkRetimeTranferFromCopy ( Abc_Ntk_t pNtk)

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

Synopsis [Transfer latch initial values from pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 188 of file retInit.c.

189 {
190  Abc_Obj_t * pObj;
191  int i;
192  Abc_NtkForEachObj( pNtk, pObj, i )
193  if ( Abc_ObjIsLatch(pObj) )
194  pObj->pData = (void *)(ABC_PTRUINT_T)(pObj->pCopy? ABC_INIT_ONE : ABC_INIT_ZERO);
195 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
if(last==0)
Definition: sparse_int.h:34
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
void Abc_NtkRetimeTranferToCopy ( Abc_Ntk_t pNtk)

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

Synopsis [Transfer latch initial values to pCopy.]

Description []

SideEffects []

SeeAlso []

Definition at line 168 of file retInit.c.

169 {
170  Abc_Obj_t * pObj;
171  int i;
172  Abc_NtkForEachObj( pNtk, pObj, i )
173  if ( Abc_ObjIsLatch(pObj) )
174  pObj->pCopy = (Abc_Obj_t *)(ABC_PTRUINT_T)Abc_LatchIsInit1(pObj);
175 }
static int Abc_ObjIsLatch(Abc_Obj_t *pObj)
Definition: abc.h:356
if(last==0)
Definition: sparse_int.h:34
static int Abc_LatchIsInit1(Abc_Obj_t *pLatch)
Definition: abc.h:423
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition: abc.h:446
int Abc_ObjSopSimulate ( Abc_Obj_t pObj)

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

Synopsis [Computes the results of simulating one node.]

Description [Assumes that fanins have pCopy set to the input values.]

SideEffects []

SeeAlso []

Definition at line 93 of file retInit.c.

94 {
95  char * pCube, * pSop = (char *)pObj->pData;
96  int nVars, Value, v, ResOr, ResAnd, ResVar;
97  assert( pSop && !Abc_SopIsExorType(pSop) );
98  // simulate the SOP of the node
99  ResOr = 0;
100  nVars = Abc_SopGetVarNum(pSop);
101  Abc_SopForEachCube( pSop, nVars, pCube )
102  {
103  ResAnd = 1;
104  Abc_CubeForEachVar( pCube, Value, v )
105  {
106  if ( Value == '0' )
107  ResVar = 1 ^ ((int)(ABC_PTRUINT_T)Abc_ObjFanin(pObj, v)->pCopy);
108  else if ( Value == '1' )
109  ResVar = (int)(ABC_PTRUINT_T)Abc_ObjFanin(pObj, v)->pCopy;
110  else
111  continue;
112  ResAnd &= ResVar;
113  }
114  ResOr |= ResAnd;
115  }
116  // complement the result if necessary
117  if ( !Abc_SopGetPhase(pSop) )
118  ResOr ^= 1;
119  return ResOr;
120 }
#define Abc_SopForEachCube(pSop, nFanins, pCube)
Definition: abc.h:531
#define Abc_CubeForEachVar(pCube, Value, i)
Definition: abc.h:529
ABC_DLL int Abc_SopIsExorType(char *pSop)
Definition: abcSop.c:802
Abc_Obj_t * pCopy
Definition: abc.h:148
ABC_DLL int Abc_SopGetVarNum(char *pSop)
Definition: abcSop.c:536
#define assert(ex)
Definition: util_old.h:213
void * pData
Definition: abc.h:145
static Abc_Obj_t * Abc_ObjFanin(Abc_Obj_t *pObj, int i)
Definition: abc.h:372
ABC_DLL int Abc_SopGetPhase(char *pSop)
Definition: abcSop.c:556