1 /**CFile****************************************************************
2
3 FileName [timBox.c]
4
5 SystemName [ABC: Logic synthesis and verification system.]
6
7 PackageName [Hierarchy/timing manager.]
8
9 Synopsis [Manipulation of timing boxes.]
10
11 Author [Alan Mishchenko]
12
13 Affiliation [UC Berkeley]
14
15 Date [Ver. 1.0. Started - April 28, 2007.]
16
17 Revision [$Id: timBox.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18
19 ***********************************************************************/
20
21 #include "timInt.h"
22
23 ABC_NAMESPACE_IMPL_START
24
25 ////////////////////////////////////////////////////////////////////////
26 /// DECLARATIONS ///
27 ////////////////////////////////////////////////////////////////////////
28
29 ////////////////////////////////////////////////////////////////////////
30 /// FUNCTION DEFINITIONS ///
31 ////////////////////////////////////////////////////////////////////////
32
33 /**Function*************************************************************
34
35 Synopsis [Creates the new timing box.]
36
37 Description []
38
39 SideEffects []
40
41 SeeAlso []
42
43 ***********************************************************************/
Tim_ManCreateBox(Tim_Man_t * p,int firstIn,int nIns,int firstOut,int nOuts,int iDelayTable,int fBlack)44 void Tim_ManCreateBox( Tim_Man_t * p, int firstIn, int nIns, int firstOut, int nOuts, int iDelayTable, int fBlack )
45 {
46 Tim_Box_t * pBox;
47 int i;
48 if ( p->vBoxes == NULL )
49 p->vBoxes = Vec_PtrAlloc( 100 );
50 pBox = (Tim_Box_t *)Mem_FlexEntryFetch( p->pMemObj, sizeof(Tim_Box_t) + sizeof(int) * (nIns+nOuts) );
51 memset( pBox, 0, sizeof(Tim_Box_t) );
52 pBox->iBox = Vec_PtrSize( p->vBoxes );
53 Vec_PtrPush( p->vBoxes, pBox );
54 pBox->iDelayTable = iDelayTable;
55 pBox->nInputs = nIns;
56 pBox->nOutputs = nOuts;
57 pBox->fBlack = fBlack;
58 for ( i = 0; i < nIns; i++ )
59 {
60 assert( firstIn+i < p->nCos );
61 pBox->Inouts[i] = firstIn+i;
62 p->pCos[firstIn+i].iObj2Box = pBox->iBox;
63 p->pCos[firstIn+i].iObj2Num = i;
64 }
65 for ( i = 0; i < nOuts; i++ )
66 {
67 assert( firstOut+i < p->nCis );
68 pBox->Inouts[nIns+i] = firstOut+i;
69 p->pCis[firstOut+i].iObj2Box = pBox->iBox;
70 p->pCis[firstOut+i].iObj2Num = i;
71 }
72 // if ( pBox->iBox < 20 )
73 // printf( "%4d %4d %4d %4d \n", firstIn, nIns, firstOut, nOuts );
74 }
75
76 /**Function*************************************************************
77
78 Synopsis [Returns the box number for the given input.]
79
80 Description []
81
82 SideEffects []
83
84 SeeAlso []
85
86 ***********************************************************************/
Tim_ManBoxForCi(Tim_Man_t * p,int iCi)87 int Tim_ManBoxForCi( Tim_Man_t * p, int iCi )
88 {
89 if ( iCi >= p->nCis )
90 return -1;
91 return p->pCis[iCi].iObj2Box;
92 }
93
94 /**Function*************************************************************
95
96 Synopsis [Returns the box number for the given output.]
97
98 Description []
99
100 SideEffects []
101
102 SeeAlso []
103
104 ***********************************************************************/
Tim_ManBoxForCo(Tim_Man_t * p,int iCo)105 int Tim_ManBoxForCo( Tim_Man_t * p, int iCo )
106 {
107 if ( iCo >= p->nCos )
108 return -1;
109 return p->pCos[iCo].iObj2Box;
110 }
111
112 /**Function*************************************************************
113
114 Synopsis [Returns the first input of the box.]
115
116 Description []
117
118 SideEffects []
119
120 SeeAlso []
121
122 ***********************************************************************/
Tim_ManBoxInputFirst(Tim_Man_t * p,int iBox)123 int Tim_ManBoxInputFirst( Tim_Man_t * p, int iBox )
124 {
125 return Tim_ManBox(p, iBox)->Inouts[0];
126 }
127
128 /**Function*************************************************************
129
130 Synopsis [Returns the last input of the box.]
131
132 Description []
133
134 SideEffects []
135
136 SeeAlso []
137
138 ***********************************************************************/
Tim_ManBoxInputLast(Tim_Man_t * p,int iBox)139 int Tim_ManBoxInputLast( Tim_Man_t * p, int iBox )
140 {
141 return Tim_ManBox(p, iBox)->Inouts[0] + Tim_ManBoxInputNum(p, iBox) - 1;
142 }
143
144 /**Function*************************************************************
145
146 Synopsis [Returns the first output of the box.]
147
148 Description []
149
150 SideEffects []
151
152 SeeAlso []
153
154 ***********************************************************************/
Tim_ManBoxOutputFirst(Tim_Man_t * p,int iBox)155 int Tim_ManBoxOutputFirst( Tim_Man_t * p, int iBox )
156 {
157 return Tim_ManBox(p, iBox)->Inouts[Tim_ManBox(p, iBox)->nInputs];
158 }
159
160 /**Function*************************************************************
161
162 Synopsis [Returns the last output of the box.]
163
164 Description []
165
166 SideEffects []
167
168 SeeAlso []
169
170 ***********************************************************************/
Tim_ManBoxOutputLast(Tim_Man_t * p,int iBox)171 int Tim_ManBoxOutputLast( Tim_Man_t * p, int iBox )
172 {
173 return Tim_ManBox(p, iBox)->Inouts[Tim_ManBox(p, iBox)->nInputs] + Tim_ManBoxOutputNum(p, iBox) - 1;
174 }
175
176 /**Function*************************************************************
177
178 Synopsis [Returns the number of box inputs.]
179
180 Description []
181
182 SideEffects []
183
184 SeeAlso []
185
186 ***********************************************************************/
Tim_ManBoxInputNum(Tim_Man_t * p,int iBox)187 int Tim_ManBoxInputNum( Tim_Man_t * p, int iBox )
188 {
189 return Tim_ManBox(p, iBox)->nInputs;
190 }
191
192 /**Function*************************************************************
193
194 Synopsis [Returns the number of box outputs.]
195
196 Description []
197
198 SideEffects []
199
200 SeeAlso []
201
202 ***********************************************************************/
Tim_ManBoxOutputNum(Tim_Man_t * p,int iBox)203 int Tim_ManBoxOutputNum( Tim_Man_t * p, int iBox )
204 {
205 return Tim_ManBox(p, iBox)->nOutputs;
206 }
207
208 /**Function*************************************************************
209
210 Synopsis [Return the delay table id.]
211
212 Description []
213
214 SideEffects []
215
216 SeeAlso []
217
218 ***********************************************************************/
Tim_ManBoxDelayTableId(Tim_Man_t * p,int iBox)219 int Tim_ManBoxDelayTableId( Tim_Man_t * p, int iBox )
220 {
221 return Tim_ManBox(p, iBox)->iDelayTable;
222 }
223
224 /**Function*************************************************************
225
226 Synopsis [Return the delay table.]
227
228 Description []
229
230 SideEffects []
231
232 SeeAlso []
233
234 ***********************************************************************/
Tim_ManBoxDelayTable(Tim_Man_t * p,int iBox)235 float * Tim_ManBoxDelayTable( Tim_Man_t * p, int iBox )
236 {
237 float * pTable;
238 Tim_Box_t * pBox = Tim_ManBox(p, iBox);
239 if ( pBox->iDelayTable < 0 )
240 return NULL;
241 pTable = (float *)Vec_PtrEntry( p->vDelayTables, pBox->iDelayTable );
242 assert( (int)pTable[1] == pBox->nInputs );
243 assert( (int)pTable[2] == pBox->nOutputs );
244 return pTable;
245 }
246
247 /**Function*************************************************************
248
249 Synopsis [Return 1 if the box is black.]
250
251 Description []
252
253 SideEffects []
254
255 SeeAlso []
256
257 ***********************************************************************/
Tim_ManBoxIsBlack(Tim_Man_t * p,int iBox)258 int Tim_ManBoxIsBlack( Tim_Man_t * p, int iBox )
259 {
260 return Tim_ManBox(p, iBox)->fBlack;
261 }
262
263
264 /**Function*************************************************************
265
266 Synopsis [Returns the copy of the box.]
267
268 Description []
269
270 SideEffects []
271
272 SeeAlso []
273
274 ***********************************************************************/
Tim_ManBoxCopy(Tim_Man_t * p,int iBox)275 int Tim_ManBoxCopy( Tim_Man_t * p, int iBox )
276 {
277 return Tim_ManBox(p, iBox)->iCopy;
278 }
279
280 /**Function*************************************************************
281
282 Synopsis [Sets the copy of the box.]
283
284 Description []
285
286 SideEffects []
287
288 SeeAlso []
289
290 ***********************************************************************/
Tim_ManBoxSetCopy(Tim_Man_t * p,int iBox,int iCopy)291 void Tim_ManBoxSetCopy( Tim_Man_t * p, int iBox, int iCopy )
292 {
293 Tim_ManBox(p, iBox)->iCopy = iCopy;
294 }
295
296 /**Function*************************************************************
297
298 Synopsis []
299
300 Description []
301
302 SideEffects []
303
304 SeeAlso []
305
306 ***********************************************************************/
Tim_ManBoxFindFromCiNum(Tim_Man_t * p,int iCiNum)307 int Tim_ManBoxFindFromCiNum( Tim_Man_t * p, int iCiNum )
308 {
309 Tim_Box_t * pBox;
310 int i;
311 assert( iCiNum >= 0 && iCiNum < Tim_ManCiNum(p) );
312 if ( iCiNum < Tim_ManPiNum(p) )
313 return -1;
314 Tim_ManForEachBox( p, pBox, i )
315 if ( iCiNum < Tim_ManBoxOutputFirst(p, i) )
316 return i - 1;
317 return -2;
318 }
319
320 ////////////////////////////////////////////////////////////////////////
321 /// END OF FILE ///
322 ////////////////////////////////////////////////////////////////////////
323
324
325 ABC_NAMESPACE_IMPL_END
326
327