1 /**CFile****************************************************************
2 
3   FileName    [fretime.h]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [Flow-based retiming package.]
8 
9   Synopsis    [Header file for retiming package.]
10 
11   Author      [Aaron Hurst]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - January 1, 2008.]
16 
17   Revision    [$Id: fretime.h,v 1.00 2008/01/01 00:00:00 ahurst Exp $]
18 
19 ***********************************************************************/
20 
21 #if !defined(RETIME_H_)
22 #define RETIME_H_
23 
24 
25 #include "base/abc/abc.h"
26 #include "misc/vec/vec.h"
27 
28 
29 ABC_NAMESPACE_HEADER_START
30 
31 
32 // #define IGNORE_TIMING
33 // #define DEBUG_PRINT_FLOWS
34 // #define DEBUG_VISITED
35 // #define DEBUG_PREORDER
36 #define DEBUG_CHECK
37 // #define DEBUG_PRINT_LEVELS
38 
39 ////////////////////////////////////////////////////////////////////////
40 ///                        DECLARATIONS                              ///
41 ////////////////////////////////////////////////////////////////////////
42 
43 #define MAX_DIST 30000
44 
45 // flags in Flow_Data structure...
46 #define VISITED_E       0x001
47 #define VISITED_R       0x002
48 #define VISITED  (VISITED_E | VISITED_R)
49 #define FLOW            0x004
50 #define CROSS_BOUNDARY  0x008
51 #define BLOCK           0x010
52 #define INIT_0          0x020
53 #define INIT_1          0x040
54 #define INIT_CARE (INIT_0 | INIT_1)
55 #define CONSERVATIVE    0x080
56 #define BLOCK_OR_CONS (BLOCK | CONSERVATIVE)
57 #define BIAS_NODE       0x100
58 
59 
60 #define MAX(a,b) ((a)>(b)?(a):(b))
61 #define MIN(a,b) ((a)<(b)?(a):(b))
62 
63 
64 typedef struct Flow_Data_t_ {
65   unsigned int mark : 16;
66 
67   union {
68     Abc_Obj_t   *pred;
69     /* unsigned int var; */
70     Abc_Obj_t   *pInitObj;
71     Abc_Obj_t   *pCopy;
72     Vec_Ptr_t   *vNodes;
73   };
74 
75   unsigned int e_dist : 16;
76   unsigned int r_dist : 16;
77 } Flow_Data_t;
78 
79 // useful macros for manipulating Flow_Data structure...
80 #define FDATA( x )     (pManMR->pDataArray+Abc_ObjId(x))
81 #define FSET( x, y )   FDATA(x)->mark |= y
82 #define FUNSET( x, y ) FDATA(x)->mark &= ~y
83 #define FTEST( x, y )  (FDATA(x)->mark & y)
84 #define FTIMEEDGES( x )  &(pManMR->vTimeEdges[Abc_ObjId( x )])
85 
86 typedef struct NodeLag_T_ {
87   int id;
88   int lag;
89 } NodeLag_t;
90 
91 typedef struct InitConstraint_t_ {
92   Abc_Obj_t *pBiasNode;
93 
94   Vec_Int_t  vNodes;
95   Vec_Int_t  vLags;
96 
97 } InitConstraint_t;
98 
99 typedef struct MinRegMan_t_ {
100 
101   // problem description:
102   int         maxDelay;
103   int        fComputeInitState, fGuaranteeInitState, fBlockConst;
104   int         nNodes, nLatches;
105   int        fForwardOnly, fBackwardOnly;
106   int        fConservTimingOnly;
107   int         nMaxIters;
108   int        fVerbose;
109   Abc_Ntk_t  *pNtk;
110 
111   int         nPreRefine;
112 
113   // problem state
114   int        fIsForward;
115   int        fSinkDistTerminate;
116   int         nExactConstraints, nConservConstraints;
117   int         fSolutionIsDc;
118   int         constraintMask;
119   int         iteration, subIteration;
120   Vec_Int_t  *vLags;
121 
122   // problem data
123   Vec_Int_t   *vSinkDistHist;
124   Flow_Data_t *pDataArray;
125   Vec_Ptr_t   *vTimeEdges;
126   Vec_Ptr_t   *vExactNodes;
127   Vec_Ptr_t   *vInitConstraints;
128   Abc_Ntk_t   *pInitNtk;
129   Vec_Ptr_t   *vNodes; // re-useable struct
130 
131   NodeLag_t   *pInitToOrig;
132   int          sizeInitToOrig;
133 
134 } MinRegMan_t ;
135 
136 extern MinRegMan_t *pManMR;
137 
138 #define vprintf if (pManMR->fVerbose) printf
139 
FSETPRED(Abc_Obj_t * pObj,Abc_Obj_t * pPred)140 static inline void FSETPRED(Abc_Obj_t *pObj, Abc_Obj_t *pPred) {
141   assert(!Abc_ObjIsLatch(pObj)); // must preserve field to maintain init state linkage
142   FDATA(pObj)->pred = pPred;
143 }
FGETPRED(Abc_Obj_t * pObj)144 static inline Abc_Obj_t * FGETPRED(Abc_Obj_t *pObj) {
145   return FDATA(pObj)->pred;
146 }
147 
148 /*=== fretMain.c ==========================================================*/
149 
150 Abc_Ntk_t *    Abc_FlowRetime_MinReg( Abc_Ntk_t * pNtk, int fVerbose,
151                                       int fComputeInitState, int fGuaranteeInitState, int fBlockConst,
152                                       int fForward, int fBackward, int nMaxIters,
153                                       int maxDelay, int fFastButConservative);
154 
155 void print_node(Abc_Obj_t *pObj);
156 
157 void Abc_ObjBetterTransferFanout( Abc_Obj_t * pFrom, Abc_Obj_t * pTo, int complement );
158 
159 int  Abc_FlowRetime_PushFlows( Abc_Ntk_t * pNtk, int fVerbose );
160 int Abc_FlowRetime_IsAcrossCut( Abc_Obj_t *pCur, Abc_Obj_t *pNext );
161 void Abc_FlowRetime_ClearFlows( int fClearAll );
162 
163 int  Abc_FlowRetime_GetLag( Abc_Obj_t *pObj );
164 void Abc_FlowRetime_SetLag( Abc_Obj_t *pObj, int lag );
165 
166 void Abc_FlowRetime_UpdateLags( );
167 
168 void Abc_ObjPrintNeighborhood( Abc_Obj_t *pObj, int depth );
169 
170 Abc_Ntk_t * Abc_FlowRetime_NtkSilentRestrash( Abc_Ntk_t * pNtk, int fCleanup );
171 
172 /*=== fretFlow.c ==========================================================*/
173 
174 int  dfsplain_e( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
175 int  dfsplain_r( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
176 
177 void dfsfast_preorder( Abc_Ntk_t *pNtk );
178 int  dfsfast_e( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
179 int  dfsfast_r( Abc_Obj_t *pObj, Abc_Obj_t *pPred );
180 
181 /*=== fretInit.c ==========================================================*/
182 
183 void Abc_FlowRetime_PrintInitStateInfo( Abc_Ntk_t * pNtk );
184 
185 void Abc_FlowRetime_InitState( Abc_Ntk_t * pNtk );
186 
187 void Abc_FlowRetime_UpdateForwardInit( Abc_Ntk_t * pNtk );
188 void Abc_FlowRetime_UpdateBackwardInit( Abc_Ntk_t * pNtk );
189 
190 void Abc_FlowRetime_SetupBackwardInit( Abc_Ntk_t * pNtk );
191 int  Abc_FlowRetime_SolveBackwardInit( Abc_Ntk_t * pNtk );
192 
193 void Abc_FlowRetime_ConstrainInit(  );
194 void Abc_FlowRetime_AddInitBias(  );
195 void Abc_FlowRetime_RemoveInitBias(  );
196 
197 /*=== fretTime.c ==========================================================*/
198 
199 void Abc_FlowRetime_InitTiming( Abc_Ntk_t *pNtk );
200 void Abc_FlowRetime_FreeTiming( Abc_Ntk_t *pNtk );
201 
202 int Abc_FlowRetime_RefineConstraints( );
203 
204 void Abc_FlowRetime_ConstrainConserv( Abc_Ntk_t * pNtk );
205 void Abc_FlowRetime_ConstrainExact( Abc_Obj_t * pObj );
206 void Abc_FlowRetime_ConstrainExactAll( Abc_Ntk_t * pNtk );
207 
208 
209 
210 ABC_NAMESPACE_HEADER_END
211 
212 #endif
213