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
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
|
/**CFile****************************************************************
FileName [saigTrans.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Sequential AIG package.]
Synopsis [Dynamic simplication of the transition relation.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: saigTrans.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "saig.h"
#include "proof/fra/fra.h"
ABC_NAMESPACE_IMPL_START
/*
A similar approach is presented in the his paper:
A. Kuehlmann. Dynamic transition relation simplification for
bounded property checking. ICCAD'04, pp. 50-57.
*/
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Maps a node/frame into a node of a different manager.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Saig_ManStartMap1( Aig_Man_t * p, int nFrames )
{
Vec_Int_t * vMap;
int i;
assert( p->pData == NULL );
vMap = Vec_IntAlloc( Aig_ManObjNumMax(p) * nFrames );
for ( i = 0; i < vMap->nCap; i++ )
vMap->pArray[i] = -1;
vMap->nSize = vMap->nCap;
p->pData = vMap;
}
static inline void Saig_ManStopMap1( Aig_Man_t * p )
{
assert( p->pData != NULL );
Vec_IntFree( (Vec_Int_t *)p->pData );
p->pData = NULL;
}
static inline int Saig_ManHasMap1( Aig_Man_t * p )
{
return (int)(p->pData != NULL);
}
static inline void Saig_ManSetMap1( Aig_Man_t * p, Aig_Obj_t * pOld, int f1, Aig_Obj_t * pNew )
{
Vec_Int_t * vMap = (Vec_Int_t *)p->pData;
int nOffset = f1 * Aig_ManObjNumMax(p) + pOld->Id;
assert( !Aig_IsComplement(pOld) );
assert( !Aig_IsComplement(pNew) );
Vec_IntWriteEntry( vMap, nOffset, pNew->Id );
}
static inline int Saig_ManGetMap1( Aig_Man_t * p, Aig_Obj_t * pOld, int f1 )
{
Vec_Int_t * vMap = (Vec_Int_t *)p->pData;
int nOffset = f1 * Aig_ManObjNumMax(p) + pOld->Id;
return Vec_IntEntry( vMap, nOffset );
}
/**Function*************************************************************
Synopsis [Maps a node/frame into a node/frame of a different manager.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline void Saig_ManStartMap2( Aig_Man_t * p, int nFrames )
{
Vec_Int_t * vMap;
int i;
assert( p->pData2 == NULL );
vMap = Vec_IntAlloc( Aig_ManObjNumMax(p) * nFrames * 2 );
for ( i = 0; i < vMap->nCap; i++ )
vMap->pArray[i] = -1;
vMap->nSize = vMap->nCap;
p->pData2 = vMap;
}
static inline void Saig_ManStopMap2( Aig_Man_t * p )
{
assert( p->pData2 != NULL );
Vec_IntFree( (Vec_Int_t *)p->pData2 );
p->pData2 = NULL;
}
static inline int Saig_ManHasMap2( Aig_Man_t * p )
{
return (int)(p->pData2 != NULL);
}
static inline void Saig_ManSetMap2( Aig_Man_t * p, Aig_Obj_t * pOld, int f1, Aig_Obj_t * pNew, int f2 )
{
Vec_Int_t * vMap = (Vec_Int_t *)p->pData2;
int nOffset = f1 * Aig_ManObjNumMax(p) + pOld->Id;
assert( !Aig_IsComplement(pOld) );
assert( !Aig_IsComplement(pNew) );
Vec_IntWriteEntry( vMap, 2*nOffset + 0, pNew->Id );
Vec_IntWriteEntry( vMap, 2*nOffset + 1, f2 );
}
static inline int Saig_ManGetMap2( Aig_Man_t * p, Aig_Obj_t * pOld, int f1, int * pf2 )
{
Vec_Int_t * vMap = (Vec_Int_t *)p->pData2;
int nOffset = f1 * Aig_ManObjNumMax(p) + pOld->Id;
*pf2 = Vec_IntEntry( vMap, 2*nOffset + 1 );
return Vec_IntEntry( vMap, 2*nOffset );
}
/**Function*************************************************************
Synopsis [Create mapping for the first nFrames timeframes of pAig.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Saig_ManCreateMapping( Aig_Man_t * pAig, Aig_Man_t * pFrames, int nFrames )
{
Aig_Obj_t * pObj, * pObjFrame, * pObjRepr;
int i, f, iNum, iFrame;
assert( pFrames->pReprs != NULL ); // mapping from nodes into their representatives
// start step mapping for both orignal manager and fraig
Saig_ManStartMap2( pAig, nFrames );
Saig_ManStartMap2( pFrames, 1 );
// for each object in each frame
for ( f = 0; f < nFrames; f++ )
Aig_ManForEachObj( pAig, pObj, i )
{
// get the frame object
iNum = Saig_ManGetMap1( pAig, pObj, f );
pObjFrame = Aig_ManObj( pFrames, iNum );
// if the node has no prototype, map it into itself
if ( pObjFrame == NULL )
{
Saig_ManSetMap2( pAig, pObj, f, pObj, f );
continue;
}
// get the representative object
pObjRepr = Aig_ObjRepr( pFrames, pObjFrame );
if ( pObjRepr == NULL )
pObjRepr = pObjFrame;
// check if this is the first time this object is reached
if ( Saig_ManGetMap2( pFrames, pObjRepr, 0, &iFrame ) == -1 )
Saig_ManSetMap2( pFrames, pObjRepr, 0, pObj, f );
// set the map for the main object
iNum = Saig_ManGetMap2( pFrames, pObjRepr, 0, &iFrame );
Saig_ManSetMap2( pAig, pObj, f, Aig_ManObj(pAig, iNum), iFrame );
}
Saig_ManStopMap2( pFrames );
assert( Saig_ManHasMap2(pAig) );
}
/**Function*************************************************************
Synopsis [Unroll without initialization.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Aig_Man_t * Saig_ManFramesNonInitial( Aig_Man_t * pAig, int nFrames )
{
Aig_Man_t * pFrames;
Aig_Obj_t * pObj, * pObjLi, * pObjLo;
int i, f;
assert( Saig_ManRegNum(pAig) > 0 );
// start node map
Saig_ManStartMap1( pAig, nFrames );
// start the new manager
pFrames = Aig_ManStart( Aig_ManNodeNum(pAig) * nFrames );
// map the constant node
Aig_ManConst1(pAig)->pData = Aig_ManConst1( pFrames );
// create variables for register outputs
Saig_ManForEachLo( pAig, pObj, i )
pObj->pData = Aig_ObjCreateCi( pFrames );
// add timeframes
for ( f = 0; f < nFrames; f++ )
{
// create PI nodes for this frame
Saig_ManForEachPi( pAig, pObj, i )
pObj->pData = Aig_ObjCreateCi( pFrames );
// add internal nodes of this frame
Aig_ManForEachNode( pAig, pObj, i )
pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
// create POs for this frame
Saig_ManForEachPo( pAig, pObj, i )
pObj->pData = Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
// save register inputs
Saig_ManForEachLi( pAig, pObj, i )
pObj->pData = Aig_ObjChild0Copy(pObj);
// save the mapping
Aig_ManForEachObj( pAig, pObj, i )
{
assert( pObj->pData != NULL );
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
// quit if the last frame
if ( f == nFrames - 1 )
break;
// transfer to register outputs
Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
pObjLo->pData = pObjLi->pData;
}
// remember register outputs
Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
Aig_ObjCreateCo( pFrames, (Aig_Obj_t *)pObjLi->pData );
Aig_ManCleanup( pFrames );
return pFrames;
}
/**Function*************************************************************
Synopsis [Unroll with initialization and mapping.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Aig_Man_t * Saig_ManFramesInitialMapped( Aig_Man_t * pAig, int nFrames, int nFramesMax, int fInit )
{
Aig_Man_t * pFrames;
Aig_Obj_t * pObj, * pObjLi, * pObjLo, * pRepr;
int i, f, iNum1, iNum2, iFrame2;
assert( nFrames <= nFramesMax );
assert( Saig_ManRegNum(pAig) > 0 );
// start node map
Saig_ManStartMap1( pAig, nFramesMax );
// start the new manager
pFrames = Aig_ManStart( Aig_ManNodeNum(pAig) * nFramesMax );
// create variables for register outputs
if ( fInit )
{
Saig_ManForEachLo( pAig, pObj, i )
{
pObj->pData = Aig_ManConst0( pFrames );
Saig_ManSetMap1( pAig, pObj, 0, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
}
else
{
// create PIs first
for ( f = 0; f < nFramesMax; f++ )
Saig_ManForEachPi( pAig, pObj, i )
Aig_ObjCreateCi( pFrames );
// create registers second
Saig_ManForEachLo( pAig, pObj, i )
{
pObj->pData = Aig_ObjCreateCi( pFrames );
Saig_ManSetMap1( pAig, pObj, 0, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
}
// add timeframes
for ( f = 0; f < nFramesMax; f++ )
{
// map the constant node
pObj = Aig_ManConst1(pAig);
pObj->pData = Aig_ManConst1( pFrames );
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
// create PI nodes for this frame
Saig_ManForEachPi( pAig, pObj, i )
{
if ( fInit )
pObj->pData = Aig_ObjCreateCi( pFrames );
else
pObj->pData = Aig_ManCi( pFrames, f * Saig_ManPiNum(pAig) + i );
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
// add internal nodes of this frame
Aig_ManForEachNode( pAig, pObj, i )
{
pObj->pData = Aig_And( pFrames, Aig_ObjChild0Copy(pObj), Aig_ObjChild1Copy(pObj) );
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
if ( !Saig_ManHasMap2(pAig) )
continue;
if ( f < nFrames )
{
// get the mapping for this node
iNum2 = Saig_ManGetMap2( pAig, pObj, f, &iFrame2 );
}
else
{
// get the mapping for this node
iNum2 = Saig_ManGetMap2( pAig, pObj, nFrames-1, &iFrame2 );
iFrame2 += f - (nFrames-1);
}
assert( iNum2 != -1 );
assert( f >= iFrame2 );
// get the corresponding frames node
iNum1 = Saig_ManGetMap1( pAig, Aig_ManObj(pAig, iNum2), iFrame2 );
pRepr = Aig_ManObj( pFrames, iNum1 );
// compare the phases of these nodes
pObj->pData = Aig_NotCond( pRepr, pRepr->fPhase ^ Aig_ObjPhaseReal((Aig_Obj_t *)pObj->pData) );
}
// create POs for this frame
Saig_ManForEachPo( pAig, pObj, i )
{
pObj->pData = Aig_ObjCreateCo( pFrames, Aig_ObjChild0Copy(pObj) );
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
// save register inputs
Saig_ManForEachLi( pAig, pObj, i )
{
pObj->pData = Aig_ObjChild0Copy(pObj);
Saig_ManSetMap1( pAig, pObj, f, Aig_Regular((Aig_Obj_t *)pObj->pData) );
}
// quit if the last frame
if ( f == nFramesMax - 1 )
break;
// transfer to register outputs
Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
{
pObjLo->pData = pObjLi->pData;
if ( !fInit )
Saig_ManSetMap1( pAig, pObjLo, f+1, Aig_Regular((Aig_Obj_t *)pObjLo->pData) );
}
}
if ( !fInit )
{
// create registers
Saig_ManForEachLiLo( pAig, pObjLi, pObjLo, i )
Aig_ObjCreateCo( pFrames, (Aig_Obj_t *)pObjLi->pData );
// set register number
Aig_ManSetRegNum( pFrames, pAig->nRegs );
}
Aig_ManCleanup( pFrames );
Saig_ManStopMap1( pAig );
return pFrames;
}
/**Function*************************************************************
Synopsis [Implements dynamic simplification.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Aig_Man_t * Saig_ManTimeframeSimplify( Aig_Man_t * pAig, int nFrames, int nFramesMax, int fInit, int fVerbose )
{
// extern Aig_Man_t * Fra_FraigEquivence( Aig_Man_t * pManAig, int nConfMax, int fProve );
Aig_Man_t * pFrames, * pFraig, * pRes1, * pRes2;
abctime clk;
// create uninitialized timeframes with map1
pFrames = Saig_ManFramesNonInitial( pAig, nFrames );
// perform fraiging for the unrolled timeframes
clk = Abc_Clock();
pFraig = Fra_FraigEquivence( pFrames, 1000, 0 );
// report the results
if ( fVerbose )
{
Aig_ManPrintStats( pFrames );
Aig_ManPrintStats( pFraig );
ABC_PRT( "Fraiging", Abc_Clock() - clk );
}
Aig_ManStop( pFraig );
assert( pFrames->pReprs != NULL );
// create AIG with map2
Saig_ManCreateMapping( pAig, pFrames, nFrames );
Aig_ManStop( pFrames );
Saig_ManStopMap1( pAig );
// create reduced initialized timeframes
clk = Abc_Clock();
pRes2 = Saig_ManFramesInitialMapped( pAig, nFrames, nFramesMax, fInit );
ABC_PRT( "Mapped", Abc_Clock() - clk );
// free mapping
Saig_ManStopMap2( pAig );
clk = Abc_Clock();
pRes1 = Saig_ManFramesInitialMapped( pAig, nFrames, nFramesMax, fInit );
ABC_PRT( "Normal", Abc_Clock() - clk );
// report the results
if ( fVerbose )
{
Aig_ManPrintStats( pRes1 );
Aig_ManPrintStats( pRes2 );
}
Aig_ManStop( pRes1 );
assert( !Saig_ManHasMap1(pAig) );
assert( !Saig_ManHasMap2(pAig) );
return pRes2;
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|