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
|
/**CFile****************************************************************
FileName [giaSat.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [Scalable AIG package.]
Synopsis [New constraint-propagation procedures.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: giaSat.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "gia.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
#define GIA_LIMIT 10
typedef struct Gia_ManSat_t_ Gia_ManSat_t;
struct Gia_ManSat_t_
{
Aig_MmFlex_t * pMem;
};
typedef struct Gia_ObjSat1_t_ Gia_ObjSat1_t;
struct Gia_ObjSat1_t_
{
char nFans;
char nOffset;
char PathsH;
char PathsV;
};
typedef struct Gia_ObjSat2_t_ Gia_ObjSat2_t;
struct Gia_ObjSat2_t_
{
unsigned fTerm : 1;
unsigned iLit : 31;
};
typedef struct Gia_ObjSat_t_ Gia_ObjSat_t;
struct Gia_ObjSat_t_
{
union {
Gia_ObjSat1_t Obj1;
Gia_ObjSat2_t Obj2;
};
};
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
Gia_ManSat_t * Gia_ManSatStart()
{
Gia_ManSat_t * p;
p = ABC_CALLOC( Gia_ManSat_t, 1 );
p->pMem = Aig_MmFlexStart();
return p;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSatStop( Gia_ManSat_t * p )
{
Aig_MmFlexStop( p->pMem, 0 );
ABC_FREE( p );
}
/**Function*************************************************************
Synopsis [Collects the supergate rooted at this ]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSatPartCollectSuper( Gia_Man_t * p, Gia_Obj_t * pObj, int * pLits, int * pnLits )
{
Gia_Obj_t * pFanin;
assert( Gia_ObjIsAnd(pObj) );
assert( pObj->fMark0 == 0 );
pFanin = Gia_ObjFanin0(pObj);
if ( pFanin->fMark0 || Gia_ObjFaninC0(pObj) )
pLits[(*pnLits)++] = Gia_Var2Lit(Gia_ObjId(p, pFanin), Gia_ObjFaninC0(pObj));
else
Gia_ManSatPartCollectSuper(p, pFanin, pLits, pnLits);
pFanin = Gia_ObjFanin1(pObj);
if ( pFanin->fMark0 || Gia_ObjFaninC1(pObj) )
pLits[(*pnLits)++] = Gia_Var2Lit(Gia_ObjId(p, pFanin), Gia_ObjFaninC1(pObj));
else
Gia_ManSatPartCollectSuper(p, pFanin, pLits, pnLits);
}
/**Function*************************************************************
Synopsis [Returns the number of words used.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSatPartCreate_rec( Gia_Man_t * p, Gia_Obj_t * pObj, int * pObjPlace, int * pStore )
{
Gia_Obj_t * pFanin;
int i, nWordsUsed, nSuperSize = 0, Super[2*GIA_LIMIT];
// make sure this is a valid node
assert( Gia_ObjIsAnd(pObj) );
assert( pObj->fMark0 == 0 );
// collect inputs to the supergate
Gia_ManSatPartCollectSuper( p, pObj, Super, &nSuperSize );
assert( nSuperSize <= 2*GIA_LIMIT );
// create the root entry
*pObjPlace = 0;
((Gia_ObjSat1_t *)pObjPlace)->nFans = Gia_Var2Lit( nSuperSize, 0 );
((Gia_ObjSat1_t *)pObjPlace)->nOffset = pStore - pObjPlace;
nWordsUsed = nSuperSize;
for ( i = 0; i < nSuperSize; i++ )
{
pFanin = Gia_ManObj( p, Gia_Lit2Var(Super[i]) );
if ( pFanin->fMark0 )
{
((Gia_ObjSat2_t *)(pStore + i))->fTerm = 1;
((Gia_ObjSat2_t *)(pStore + i))->iLit = Super[i];
}
else
{
assert( Gia_LitIsCompl(Super[i]) );
nWordsUsed += Gia_ManSatPartCreate_rec( p, pFanin, pStore + i, pStore + nWordsUsed );
}
}
return nWordsUsed;
}
/**Function*************************************************************
Synopsis [Creates part and returns the number of words used.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSatPartCreate( Gia_Man_t * p, Gia_Obj_t * pObj, int * pStore )
{
return 1 + Gia_ManSatPartCreate_rec( p, pObj, pStore, pStore + 1 );
}
/**Function*************************************************************
Synopsis [Count the number of internal nodes in the leaf-DAG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSatPartCountClauses( Gia_Man_t * p, Gia_Obj_t * pObj, int * pnOnset, int * pnOffset )
{
Gia_Obj_t * pFanin;
int nOnset0, nOnset1, nOffset0, nOffset1;
assert( Gia_ObjIsAnd(pObj) );
pFanin = Gia_ObjFanin0(pObj);
if ( pFanin->fMark0 )
nOnset0 = 1, nOffset0 = 1;
else
{
Gia_ManSatPartCountClauses(p, pFanin, &nOnset0, &nOffset0);
if ( Gia_ObjFaninC0(pObj) )
{
int Temp = nOnset0;
nOnset0 = nOffset0;
nOffset0 = Temp;
}
}
pFanin = Gia_ObjFanin1(pObj);
if ( pFanin->fMark0 )
nOnset1 = 1, nOffset1 = 1;
else
{
Gia_ManSatPartCountClauses(p, pFanin, &nOnset1, &nOffset1);
if ( Gia_ObjFaninC1(pObj) )
{
int Temp = nOnset1;
nOnset1 = nOffset1;
nOffset1 = Temp;
}
}
*pnOnset = nOnset0 * nOnset1;
*pnOffset = nOffset0 + nOffset1;
}
/**Function*************************************************************
Synopsis [Count the number of internal nodes in the leaf-DAG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSatPartCount( Gia_Man_t * p, Gia_Obj_t * pObj, int * pnLeaves, int * pnNodes )
{
Gia_Obj_t * pFanin;
int Level0 = 0, Level1 = 0;
assert( Gia_ObjIsAnd(pObj) );
assert( pObj->fMark0 == 0 );
(*pnNodes)++;
pFanin = Gia_ObjFanin0(pObj);
if ( pFanin->fMark0 )
(*pnLeaves)++;
else
Level0 = Gia_ManSatPartCount(p, pFanin, pnLeaves, pnNodes) + Gia_ObjFaninC0(pObj);
pFanin = Gia_ObjFanin1(pObj);
if ( pFanin->fMark0 )
(*pnLeaves)++;
else
Level1 = Gia_ManSatPartCount(p, pFanin, pnLeaves, pnNodes) + Gia_ObjFaninC1(pObj);
return ABC_MAX( Level0, Level1 );
}
/**Function*************************************************************
Synopsis [Count the number of internal nodes in the leaf-DAG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Gia_ManSatPartCountNodes( Gia_Man_t * p, Gia_Obj_t * pObj )
{
Gia_Obj_t * pFanin;
int nNodes0 = 0, nNodes1 = 0;
assert( Gia_ObjIsAnd(pObj) );
assert( pObj->fMark0 == 0 );
pFanin = Gia_ObjFanin0(pObj);
if ( !(pFanin->fMark0) )
nNodes0 = Gia_ManSatPartCountNodes(p, pFanin);
pFanin = Gia_ObjFanin1(pObj);
if ( !(pFanin->fMark0) )
nNodes1 = Gia_ManSatPartCountNodes(p, pFanin);
return nNodes0 + nNodes1 + 1;
}
/**Function*************************************************************
Synopsis [Count the number of internal nodes in the leaf-DAG.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSatPartPrint( Gia_Man_t * p, Gia_Obj_t * pObj, int Step )
{
Gia_Obj_t * pFanin;
assert( Gia_ObjIsAnd(pObj) );
assert( pObj->fMark0 == 0 );
pFanin = Gia_ObjFanin0(pObj);
if ( pFanin->fMark0 )
printf( "%s%d", Gia_ObjFaninC0(pObj)?"!":"", Gia_ObjId(p,pFanin) );
else
{
if ( Gia_ObjFaninC0(pObj) )
printf( "(" );
Gia_ManSatPartPrint(p, pFanin, Step + Gia_ObjFaninC0(pObj));
if ( Gia_ObjFaninC0(pObj) )
printf( ")" );
}
printf( "%s", (Step & 1)? " + " : "*" );
pFanin = Gia_ObjFanin1(pObj);
if ( pFanin->fMark0 )
printf( "%s%d", Gia_ObjFaninC1(pObj)?"!":"", Gia_ObjId(p,pFanin) );
else
{
if ( Gia_ObjFaninC1(pObj) )
printf( "(" );
Gia_ManSatPartPrint(p, pFanin, Step + Gia_ObjFaninC1(pObj));
if ( Gia_ObjFaninC1(pObj) )
printf( ")" );
}
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Gia_ManSatExperiment( Gia_Man_t * p )
{
int nStored, Storage[1000], * pStart;
Gia_ManSat_t * pMan;
Gia_Obj_t * pObj;
int i, nLevels, nLeaves, nNodes, nCount[2*GIA_LIMIT+2] = {0}, nCountAll = 0;
int Num0 = 0, Num1 = 0;
int clk = clock(), nWords = 0, nWords2 = 0;
pMan = Gia_ManSatStart();
// mark the nodes to become roots of leaf-DAGs
Gia_ManSetRefs( p );
Gia_ManForEachObj( p, pObj, i )
{
pObj->fMark0 = 0;
if ( Gia_ObjIsCo(pObj) )
Gia_ObjFanin0(pObj)->fMark0 = 1;
else if ( Gia_ObjIsCi(pObj) )
pObj->fMark0 = 1;
else if ( Gia_ObjIsAnd(pObj) )
{
if ( pObj->Value > 1 || Gia_ManSatPartCountNodes(p,pObj) >= GIA_LIMIT )
pObj->fMark0 = 1;
}
pObj->Value = 0;
}
// compute the sizes of leaf-DAGs
Gia_ManForEachAnd( p, pObj, i )
{
if ( pObj->fMark0 == 0 )
continue;
pObj->fMark0 = 0;
nCountAll++;
nStored = Gia_ManSatPartCreate( p, pObj, Storage );
nWords2 += nStored;
assert( nStored < 500 );
pStart = (int *)Aig_MmFlexEntryFetch( pMan->pMem, sizeof(int) * nStored );
memcpy( pStart, Storage, sizeof(int) * nStored );
nLeaves = nNodes = 0;
nLevels = 1+Gia_ManSatPartCount( p, pObj, &nLeaves, &nNodes );
nWords += nLeaves + nNodes;
if ( nNodes <= 2*GIA_LIMIT )
nCount[nNodes]++;
else
nCount[2*GIA_LIMIT+1]++;
// if ( nNodes > 10 && i % 100 == 0 )
// if ( nNodes > 5 )
if ( 0 )
{
Gia_ManSatPartCountClauses( p, pObj, &Num0, &Num1 );
printf( "%8d : And = %3d. Lev = %2d. Clauses = %3d. (%3d + %3d).\n", i, nNodes, nLevels, Num0+Num1, Num0, Num1 );
Gia_ManSatPartPrint( p, pObj, 0 );
printf( "\n" );
}
pObj->fMark0 = 1;
}
printf( "\n" );
Gia_ManForEachObj( p, pObj, i )
pObj->fMark0 = 0;
Gia_ManSatStop( pMan );
for ( i = 0; i < 2*GIA_LIMIT+2; i++ )
printf( "%2d=%6d %7.2f %% %7.2f %%\n", i, nCount[i], 100.0*nCount[i]/nCountAll, 100.0*i*nCount[i]/Gia_ManAndNum(p) );
ABC_PRM( "MemoryEst", 4*nWords );
ABC_PRM( "MemoryReal", 4*nWords2 );
printf( "%5.2f bpn ", 4.0*nWords2/Gia_ManObjNum(p) );
ABC_PRT( "Time", clock() - clk );
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|