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
|
/**CFile****************************************************************
FileName [simSupp.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Network and node package.]
Synopsis [Simulation to determine functional support.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: simSupp.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "abc.h"
#include "sim.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
static int Sim_ComputeSuppRound( Sim_Man_t * p, bool fUseTargets );
static int Sim_ComputeSuppRoundNode( Sim_Man_t * p, int iNumCi, bool fUseTargets );
static void Sim_ComputeSuppSetTargets( Sim_Man_t * p );
static void Sim_UtilAssignFromFifo( Sim_Man_t * p );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Compute functional supports of the primary outputs.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Sim_Man_t * Sim_ComputeSupp( Abc_Ntk_t * pNtk )
{
Sim_Man_t * p;
int i, nSolved;
// srand( time(NULL) );
srand( 0xedfeedfe );
// start the simulation manager
p = Sim_ManStart( pNtk );
Sim_UtilComputeStrSupp( p );
// compute functional support using one round of random simulation
Sim_UtilAssignRandom( p );
Sim_ComputeSuppRound( p, 0 );
// set the support targets
Sim_ComputeSuppSetTargets( p );
printf( "Initial targets = %5d.\n", Vec_PtrSizeSize(p->vSuppTargs) );
if ( Vec_PtrSizeSize(p->vSuppTargs) == 0 )
goto exit;
// compute patterns using one round of random simulation
Sim_UtilAssignRandom( p );
nSolved = Sim_ComputeSuppRound( p, 1 );
printf( "First step targets = %5d. Solved = %5d.\n", Vec_PtrSizeSize(p->vSuppTargs), nSolved );
if ( Vec_PtrSizeSize(p->vSuppTargs) == 0 )
goto exit;
// simulate until saturation
for ( i = 0; i < 10; i++ )
{
// compute additional functional support
// Sim_UtilAssignFromFifo( p );
Sim_UtilAssignRandom( p );
nSolved = Sim_ComputeSuppRound( p, 1 );
printf( "Next step targets = %5d. Solved = %5d.\n", Vec_PtrSizeSize(p->vSuppTargs), nSolved );
if ( Vec_PtrSizeSize(p->vSuppTargs) == 0 )
goto exit;
}
exit:
// return p;
Sim_ManStop( p );
return NULL;
}
/**Function*************************************************************
Synopsis [Computes functional support using one round of simulation.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Sim_ComputeSuppRound( Sim_Man_t * p, bool fUseTargets )
{
Vec_Int_t * vTargets;
Abc_Obj_t * pNode;
int i, Counter = 0;
// perform one round of random simulation
Sim_UtilSimulate( p, 0 );
// iterate through the CIs and detect COs that depend on them
Abc_NtkForEachCi( p->pNtk, pNode, i )
{
vTargets = p->vSuppTargs->pArray[i];
if ( fUseTargets && vTargets->nSize == 0 )
continue;
Counter += Sim_ComputeSuppRoundNode( p, i, fUseTargets );
}
return Counter;
}
/**Function*************************************************************
Synopsis [Computes functional support for one node.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Sim_ComputeSuppRoundNode( Sim_Man_t * p, int iNumCi, bool fUseTargets )
{
Sim_Pat_t * pPat;
Vec_Int_t * vTargets;
Vec_Vec_t * vNodesByLevel;
Abc_Obj_t * pNodeCi, * pNode;
int i, k, v, Output, LuckyPat, fType0, fType1;
int Counter = 0;
// collect nodes by level in the TFO of the CI
// (this procedure increments TravId of the collected nodes)
pNodeCi = Abc_NtkCi( p->pNtk, iNumCi );
vNodesByLevel = Abc_DfsLevelized( pNodeCi, 0 );
// complement the simulation info of the selected CI
Sim_UtilFlipSimInfo( p, pNodeCi );
// simulate the levelized structure of nodes
Vec_VecForEachEntry( vNodesByLevel, pNode, i, k )
{
fType0 = Abc_NodeIsTravIdCurrent( Abc_ObjFanin0(pNode) );
fType1 = Abc_NodeIsTravIdCurrent( Abc_ObjFanin1(pNode) );
Sim_UtilSimulateNode( p, pNode, 1, fType0, fType1 );
}
// set the simulation info of the affected COs
if ( fUseTargets )
{
vTargets = p->vSuppTargs->pArray[iNumCi];
for ( i = vTargets->nSize - 1; i >= 0; i-- )
{
// get the target output
Output = vTargets->pArray[i];
// get the target node
pNode = Abc_NtkCo( p->pNtk, Output );
// the output should be in the cone
assert( Abc_NodeIsTravIdCurrent(pNode) );
// simulate the node
Sim_UtilSimulateNode( p, pNode, 1, 1, 1 );
// skip if the simulation info is equal
if ( Sim_UtilCompareSimInfo( p, pNode ) )
continue;
// otherwise, we solved a new target
Vec_IntRemove( vTargets, Output );
Counter++;
// make sure this variable is not yet detected
assert( !Sim_SuppFunHasVar(p, Output, iNumCi) );
// set this variable
Sim_SuppFunSetVar( p, Output, iNumCi );
// detect the differences in the simulation info
Sim_UtilInfoDetectDiffs( p->vSim0->pArray[pNode->Id], p->vSim1->pArray[pNode->Id], p->nSimWords, p->vDiffs );
// create new patterns
Vec_IntForEachEntry( p->vDiffs, LuckyPat, k )
{
// set the new pattern
pPat = Sim_ManPatAlloc( p );
pPat->Input = iNumCi;
pPat->Output = Output;
Abc_NtkForEachCi( p->pNtk, pNodeCi, v )
if ( Sim_SimInfoHasVar( p, pNodeCi, LuckyPat ) )
Sim_SetBit( pPat->pData, v );
Vec_PtrPush( p->vFifo, pPat );
break;
}
}
}
else
{
Abc_NtkForEachCo( p->pNtk, pNode, Output )
{
if ( !Abc_NodeIsTravIdCurrent( pNode ) )
continue;
Sim_UtilSimulateNode( p, pNode, 1, 1, 1 );
if ( !Sim_UtilCompareSimInfo( p, pNode ) )
{
if ( !Sim_SuppFunHasVar(p, Output, iNumCi) )
Counter++;
Sim_SuppFunSetVar( p, Output, iNumCi );
}
}
}
Vec_VecFree( vNodesByLevel );
return Counter;
}
/**Function*************************************************************
Synopsis [Sets the simulation targets.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_ComputeSuppSetTargets( Sim_Man_t * p )
{
Abc_Obj_t * pNode;
unsigned * pSuppStr, * pSuppFun;
int i, k, Num;
Abc_NtkForEachCo( p->pNtk, pNode, i )
{
pSuppStr = p->vSuppStr->pArray[pNode->Id];
pSuppFun = p->vSuppFun->pArray[i];
// find vars in the structural support that are not in the functional support
Sim_UtilInfoDetectNews( pSuppFun, pSuppStr, p->nSuppWords, p->vDiffs );
Vec_IntForEachEntry( p->vDiffs, Num, k )
Vec_IntPush( p->vSuppTargs->pArray[Num], i );
}
}
/**Function*************************************************************
Synopsis [Sets the new patterns from fifo.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Sim_UtilAssignFromFifo( Sim_Man_t * p )
{
Sim_Pat_t * pPat;
int i;
for ( i = 0; i < p->nSimBits; i++ )
{
pPat = Vec_PtrPop( p->vFifo );
}
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|