1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
|
/**CFile****************************************************************
FileName [simUtils.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Various simulation utilities.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: simUtils.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "abc.h"
#include "sim.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Allocates simulation information for all nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Vec_Ptr_t * Sim_UtilInfoAlloc( int nSize, int nWords, bool fClean )
{
Vec_Ptr_t * vInfo;
int i;
vInfo = Vec_PtrAlloc( nSize );
vInfo->pArray[0] = ALLOC( unsigned, nSize * nWords );
if ( fClean )
memset( vInfo->pArray[0], 0, sizeof(unsigned) * nSize * nWords );
for ( i = 1; i < nSize; i++ )
vInfo->pArray[i] = ((unsigned *)vInfo->pArray[i-1]) + nWords;
vInfo->nSize = nSize;
return vInfo;
}
/**Function*************************************************************
Synopsis [Allocates simulation information for all nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilInfoFree( Vec_Ptr_t * p )
{
free( p->pArray[0] );
Vec_PtrFree( p );
}
/**Function*************************************************************
Synopsis [Adds the second supp-info the first.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilInfoAdd( unsigned * pInfo1, unsigned * pInfo2, int nWords )
{
int w;
for ( w = 0; w < nWords; w++ )
pInfo1[w] |= pInfo2[w];
}
/**Function*************************************************************
Synopsis [Returns the positions where pInfo2 is 1 while pInfo1 is 0.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilInfoDetectDiffs( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
{
int w, b;
unsigned uMask;
vDiffs->nSize = 0;
for ( w = 0; w < nWords; w++ )
if ( uMask = (pInfo2[w] ^ pInfo1[w]) )
for ( b = 0; b < 32; b++ )
if ( uMask & (1 << b) )
Vec_IntPush( vDiffs, 32*w + b );
}
/**Function*************************************************************
Synopsis [Returns the positions where pInfo2 is 1 while pInfo1 is 0.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilInfoDetectNews( unsigned * pInfo1, unsigned * pInfo2, int nWords, Vec_Int_t * vDiffs )
{
int w, b;
unsigned uMask;
vDiffs->nSize = 0;
for ( w = 0; w < nWords; w++ )
if ( uMask = (pInfo2[w] & ~pInfo1[w]) )
for ( b = 0; b < 32; b++ )
if ( uMask & (1 << b) )
Vec_IntPush( vDiffs, 32*w + b );
}
/**Function*************************************************************
Synopsis [Computes structural supports.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilComputeStrSupp( Sim_Man_t * p )
{
Abc_Obj_t * pNode;
unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
int i, k;
// assign the structural support to the PIs
Abc_NtkForEachCi( p->pNtk, pNode, i )
Sim_SuppStrSetVar( p, pNode, i );
// derive the structural supports of the internal nodes
Abc_NtkForEachNode( p->pNtk, pNode, i )
{
if ( Abc_NodeIsConst(pNode) )
continue;
pSimmNode = p->vSuppStr->pArray[ pNode->Id ];
pSimmNode1 = p->vSuppStr->pArray[ Abc_ObjFaninId0(pNode) ];
pSimmNode2 = p->vSuppStr->pArray[ Abc_ObjFaninId1(pNode) ];
for ( k = 0; k < p->nSuppWords; k++ )
pSimmNode[k] = pSimmNode1[k] | pSimmNode2[k];
}
// set the structural supports of the PO nodes
Abc_NtkForEachCo( p->pNtk, pNode, i )
{
pSimmNode = p->vSuppStr->pArray[ pNode->Id ];
pSimmNode1 = p->vSuppStr->pArray[ Abc_ObjFaninId0(pNode) ];
for ( k = 0; k < p->nSuppWords; k++ )
pSimmNode[k] = pSimmNode1[k];
}
}
/**Function*************************************************************
Synopsis [Assigns random simulation info to the PIs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilAssignRandom( Sim_Man_t * p )
{
Abc_Obj_t * pNode;
unsigned * pSimInfo;
int i, k;
// assign the random/systematic simulation info to the PIs
Abc_NtkForEachCi( p->pNtk, pNode, i )
{
pSimInfo = p->vSim0->pArray[pNode->Id];
for ( k = 0; k < p->nSimWords; k++ )
pSimInfo[k] = SIM_RANDOM_UNSIGNED;
}
}
/**Function*************************************************************
Synopsis [Flips the simulation info of the node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilFlipSimInfo( Sim_Man_t * p, Abc_Obj_t * pNode )
{
unsigned * pSimInfo1, * pSimInfo2;
int k;
pSimInfo1 = p->vSim1->pArray[pNode->Id];
pSimInfo2 = p->vSim0->pArray[pNode->Id];
for ( k = 0; k < p->nSimWords; k++ )
pSimInfo2[k] = ~pSimInfo1[k];
}
/**Function*************************************************************
Synopsis [Returns 1 if the simulation infos are equal.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
bool Sim_UtilCompareSimInfo( Sim_Man_t * p, Abc_Obj_t * pNode )
{
unsigned * pSimInfo1, * pSimInfo2;
int k;
pSimInfo1 = p->vSim1->pArray[pNode->Id];
pSimInfo2 = p->vSim0->pArray[pNode->Id];
for ( k = 0; k < p->nSimWords; k++ )
if ( pSimInfo2[k] != pSimInfo1[k] )
return 0;
return 1;
}
/**Function*************************************************************
Synopsis [Simulates the internal nodes.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilSimulate( Sim_Man_t * p, bool fType )
{
Abc_Obj_t * pNode;
int i;
// simulate the internal nodes
Abc_NtkForEachNode( p->pNtk, pNode, i )
Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
// assign simulation info of the CO nodes
Abc_NtkForEachCo( p->pNtk, pNode, i )
Sim_UtilSimulateNode( p, pNode, fType, fType, fType );
}
/**Function*************************************************************
Synopsis [Simulates one node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilSimulateNode( Sim_Man_t * p, Abc_Obj_t * pNode, bool fType, bool fType1, bool fType2 )
{
unsigned * pSimmNode, * pSimmNode1, * pSimmNode2;
int k, fComp1, fComp2;
// simulate the internal nodes
if ( Abc_ObjIsNode(pNode) )
{
if ( Abc_NodeIsConst(pNode) )
return;
if ( fType )
pSimmNode = p->vSim1->pArray[ pNode->Id ];
else
pSimmNode = p->vSim0->pArray[ pNode->Id ];
if ( fType1 )
pSimmNode1 = p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
else
pSimmNode1 = p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
if ( fType2 )
pSimmNode2 = p->vSim1->pArray[ Abc_ObjFaninId1(pNode) ];
else
pSimmNode2 = p->vSim0->pArray[ Abc_ObjFaninId1(pNode) ];
fComp1 = Abc_ObjFaninC0(pNode);
fComp2 = Abc_ObjFaninC1(pNode);
if ( fComp1 && fComp2 )
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = ~pSimmNode1[k] & ~pSimmNode2[k];
else if ( fComp1 && !fComp2 )
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = ~pSimmNode1[k] & pSimmNode2[k];
else if ( !fComp1 && fComp2 )
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = pSimmNode1[k] & ~pSimmNode2[k];
else // if ( fComp1 && fComp2 )
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = pSimmNode1[k] & pSimmNode2[k];
}
else
{
assert( Abc_ObjFaninNum(pNode) == 1 );
if ( fType )
pSimmNode = p->vSim1->pArray[ pNode->Id ];
else
pSimmNode = p->vSim0->pArray[ pNode->Id ];
if ( fType1 )
pSimmNode1 = p->vSim1->pArray[ Abc_ObjFaninId0(pNode) ];
else
pSimmNode1 = p->vSim0->pArray[ Abc_ObjFaninId0(pNode) ];
fComp1 = Abc_ObjFaninC0(pNode);
if ( fComp1 )
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = ~pSimmNode1[k];
else
for ( k = 0; k < p->nSimWords; k++ )
pSimmNode[k] = pSimmNode1[k];
}
}
/**Function*************************************************************
Synopsis [Returns 1 if the simulation infos are equal.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Sim_UtilCountSuppSizes( Sim_Man_t * p, int fStruct )
{
Abc_Obj_t * pNode, * pNodeCi;
int i, v, Counter;
Counter = 0;
if ( fStruct )
{
Abc_NtkForEachCo( p->pNtk, pNode, i )
Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
Counter += Sim_SuppStrHasVar( p, pNode, v );
}
else
{
Abc_NtkForEachCo( p->pNtk, pNode, i )
Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
Counter += Sim_SuppFunHasVar( p, i, v );
}
return Counter;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|