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
|
/**CFile****************************************************************
FileName [saigAbsVfa.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Sequential AIG package.]
Synopsis [Intergrated abstraction procedure.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: saigAbsVfa.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "saig.h"
#include "src/sat/cnf/cnf.h"
#include "src/sat/bsat/satSolver.h"
ABC_NAMESPACE_IMPL_START
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct Abs_VfaMan_t_ Abs_VfaMan_t;
struct Abs_VfaMan_t_
{
Aig_Man_t * pAig;
int nConfLimit;
int fVerbose;
// unrolling info
int iFrame;
int nFrames;
Vec_Int_t * vObj2Vec; // maps obj ID into its vec ID
Vec_Int_t * vVec2Var; // maps vec ID into its sat Var (nFrames per vec ID)
Vec_Int_t * vVar2Inf; // maps sat Var into its frame and obj ID
Vec_Int_t * vFra2Var; // maps frame number into the first variable
// SAT solver
sat_solver * pSat;
Cnf_Dat_t * pCnf;
Vec_Int_t * vAssumps;
Vec_Int_t * vCore;
};
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Adds CNF clauses for the MUX.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abs_VfaManSatMux( sat_solver * pSat, int VarF, int VarI, int VarT, int VarE )
{
int RetValue, pLits[3];
// f = ITE(i, t, e)
// i' + t' + f
// i' + t + f'
// i + e' + f
// i + e + f'
// create four clauses
pLits[0] = toLitCond(VarI, 1);
pLits[1] = toLitCond(VarT, 1);
pLits[2] = toLitCond(VarF, 0);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
pLits[0] = toLitCond(VarI, 1);
pLits[1] = toLitCond(VarT, 0);
pLits[2] = toLitCond(VarF, 1);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
pLits[0] = toLitCond(VarI, 0);
pLits[1] = toLitCond(VarE, 1);
pLits[2] = toLitCond(VarF, 0);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
pLits[0] = toLitCond(VarI, 0);
pLits[1] = toLitCond(VarE, 0);
pLits[2] = toLitCond(VarF, 1);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
// two additional clauses
// t' & e' -> f'
// t & e -> f
// t + e + f'
// t' + e' + f
assert( VarT != VarE );
pLits[0] = toLitCond(VarT, 0);
pLits[1] = toLitCond(VarE, 0);
pLits[2] = toLitCond(VarF, 1);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
pLits[0] = toLitCond(VarT, 1);
pLits[1] = toLitCond(VarE, 1);
pLits[2] = toLitCond(VarF, 0);
RetValue = sat_solver_addclause( pSat, pLits, pLits + 3 );
assert( RetValue );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abs_VfaManAddVar( Abs_VfaMan_t * p, Aig_Obj_t * pObj, int f, int * pfNew )
{
int i, SatId, VecId = Vec_IntEntry( p->vObj2Vec, Aig_ObjId(pObj) );
*pfNew = 0;
if ( VecId == -1 )
return -1;
if ( VecId == 0 )
{
VecId = Vec_IntSize( p->vVec2Var ) / p->nFrames;
for ( i = 0; i < p->nFrames; i++ )
Vec_IntPush( p->vVec2Var, 0 );
Vec_IntWriteEntry( p->vObj2Vec, Aig_ObjId(pObj), VecId );
}
SatId = Vec_IntEntry( p->vVec2Var, p->nFrames * VecId + f );
if ( SatId )
return SatId;
SatId = Vec_IntSize( p->vVar2Inf ) / 2;
// save SatId
Vec_IntWriteEntry( p->vVec2Var, p->nFrames * VecId + f, SatId );
Vec_IntPush( p->vVar2Inf, Aig_ObjId(pObj) );
Vec_IntPush( p->vVar2Inf, f );
if ( Saig_ObjIsLo( p->pAig, pObj ) ) // reserve IDs for aux vars
{
Vec_IntPush( p->vVar2Inf, -1 );
Vec_IntPush( p->vVar2Inf, f );
Vec_IntPush( p->vVar2Inf, -2 );
Vec_IntPush( p->vVar2Inf, f );
}
*pfNew = 1;
return SatId;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abs_VfaManCreateFrame_rec( Abs_VfaMan_t * p, Aig_Obj_t * pObj, int f )
{
int SatVar, fNew;
if ( Aig_ObjIsConst1(pObj) )
return -1;
SatVar = Abs_VfaManAddVar( p, pObj, f, &fNew );
if ( (SatVar > 0 && !fNew) || Saig_ObjIsPi(p->pAig, pObj) || (Aig_ObjIsCi(pObj) && f==0) )
return SatVar;
if ( Aig_ObjIsCo(pObj) )
return Abs_VfaManCreateFrame_rec( p, Aig_ObjFanin0(pObj), f );
if ( Aig_ObjIsCi(pObj) )
return Abs_VfaManCreateFrame_rec( p, Saig_ObjLoToLi(p->pAig, pObj), f-1 );
assert( Aig_ObjIsAnd(pObj) );
Abs_VfaManCreateFrame_rec( p, Aig_ObjFanin0(pObj), f );
Abs_VfaManCreateFrame_rec( p, Aig_ObjFanin1(pObj), f );
return SatVar;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abs_VfaManCreateFrame( Abs_VfaMan_t * p, int f )
{
Aig_Obj_t * pObj;
int i, clk = clock();
Saig_ManForEachPo( p->pAig, pObj, i )
Abs_VfaManCreateFrame_rec( p, pObj, f );
Vec_IntPush( p->vFra2Var, Vec_IntSize( p->vVar2Inf ) / 2 );
printf( "Frame = %3d : ", f );
printf( "Vecs = %8d ", Vec_IntSize( p->vVec2Var ) / p->nFrames );
printf( "Vars = %8d ", Vec_IntSize( p->vVar2Inf ) / 2 );
Abc_PrintTime( 1, "Time", clock() - clk );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Abs_VfaMan_t * Abs_VfaManStart( Aig_Man_t * pAig )
{
Abs_VfaMan_t * p;
int i;
p = ABC_CALLOC( Abs_VfaMan_t, 1 );
p->pAig = pAig;
p->vObj2Vec = Vec_IntStart( Aig_ManObjNumMax(pAig) );
p->vVec2Var = Vec_IntAlloc( 1 << 20 );
p->vVar2Inf = Vec_IntAlloc( 1 << 20 );
p->vFra2Var = Vec_IntStart( 1 );
// skip the first variable
Vec_IntPush( p->vVar2Inf, -3 );
Vec_IntPush( p->vVar2Inf, -3 );
for ( i = 0; i < p->nFrames; i++ )
Vec_IntPush( p->vVec2Var, -1 );
// transfer values from CNF
p->pCnf = Cnf_DeriveOther( pAig );
for ( i = 0; i < Aig_ManObjNumMax(pAig); i++ )
if ( p->pCnf->pObj2Clause[i] == -1 )
Vec_IntWriteEntry( p->vObj2Vec, i, -1 );
p->vAssumps = Vec_IntAlloc( 100 );
p->vCore = Vec_IntAlloc( 100 );
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abs_VfaManStop( Abs_VfaMan_t * p )
{
Vec_IntFreeP( &p->vObj2Vec );
Vec_IntFreeP( &p->vVec2Var );
Vec_IntFreeP( &p->vVar2Inf );
Vec_IntFreeP( &p->vFra2Var );
Vec_IntFreeP( &p->vAssumps );
Vec_IntFreeP( &p->vCore );
if ( p->pCnf )
Cnf_DataFree( p->pCnf );
if ( p->pSat )
sat_solver_delete( p->pSat );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Perform variable frame abstraction.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abs_VfaManTest( Aig_Man_t * pAig, int nFrames, int nConfLimit, int fVerbose )
{
Abs_VfaMan_t * p;
int i;
p = Abs_VfaManStart( pAig );
p->nFrames = nFrames;
p->nConfLimit = nConfLimit;
p->fVerbose = fVerbose;
// create unrolling for the given number of frames
for ( i = 0; i < p->nFrames; i++ )
Abs_VfaManCreateFrame( p, i );
Abs_VfaManStop( p );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
ABC_NAMESPACE_IMPL_END
|