abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaSat.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [giaSat.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Scalable AIG package.]
8 
9  Synopsis [New constraint-propagation procedures.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: giaSat.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "gia.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 #define GIA_LIMIT 10
31 
32 
33 typedef struct Gia_ManSat_t_ Gia_ManSat_t;
35 {
37 };
38 
41 {
42  char nFans;
43  char nOffset;
44  char PathsH;
45  char PathsV;
46 };
47 
50 {
51  unsigned fTerm : 1;
52  unsigned iLit : 31;
53 };
54 
55 typedef struct Gia_ObjSat_t_ Gia_ObjSat_t;
57 {
58  union {
61  };
62 };
63 
64 
65 ////////////////////////////////////////////////////////////////////////
66 /// FUNCTION DEFINITIONS ///
67 ////////////////////////////////////////////////////////////////////////
68 
69 /**Function*************************************************************
70 
71  Synopsis []
72 
73  Description []
74 
75  SideEffects []
76 
77  SeeAlso []
78 
79 ***********************************************************************/
81 {
82  Gia_ManSat_t * p;
83  p = ABC_CALLOC( Gia_ManSat_t, 1 );
84  p->pMem = Aig_MmFlexStart();
85  return p;
86 }
87 
88 /**Function*************************************************************
89 
90  Synopsis []
91 
92  Description []
93 
94  SideEffects []
95 
96  SeeAlso []
97 
98 ***********************************************************************/
100 {
101  Aig_MmFlexStop( p->pMem, 0 );
102  ABC_FREE( p );
103 }
104 
105 
106 /**Function*************************************************************
107 
108  Synopsis [Collects the supergate rooted at this ]
109 
110  Description []
111 
112  SideEffects []
113 
114  SeeAlso []
115 
116 ***********************************************************************/
117 void Gia_ManSatPartCollectSuper( Gia_Man_t * p, Gia_Obj_t * pObj, int * pLits, int * pnLits )
118 {
119  Gia_Obj_t * pFanin;
120  assert( Gia_ObjIsAnd(pObj) );
121  assert( pObj->fMark0 == 0 );
122  pFanin = Gia_ObjFanin0(pObj);
123  if ( pFanin->fMark0 || Gia_ObjFaninC0(pObj) )
124  pLits[(*pnLits)++] = Gia_Var2Lit(Gia_ObjId(p, pFanin), Gia_ObjFaninC0(pObj));
125  else
126  Gia_ManSatPartCollectSuper(p, pFanin, pLits, pnLits);
127  pFanin = Gia_ObjFanin1(pObj);
128  if ( pFanin->fMark0 || Gia_ObjFaninC1(pObj) )
129  pLits[(*pnLits)++] = Gia_Var2Lit(Gia_ObjId(p, pFanin), Gia_ObjFaninC1(pObj));
130  else
131  Gia_ManSatPartCollectSuper(p, pFanin, pLits, pnLits);
132 }
133 
134 /**Function*************************************************************
135 
136  Synopsis [Returns the number of words used.]
137 
138  Description []
139 
140  SideEffects []
141 
142  SeeAlso []
143 
144 ***********************************************************************/
145 int Gia_ManSatPartCreate_rec( Gia_Man_t * p, Gia_Obj_t * pObj, int * pObjPlace, int * pStore )
146 {
147  Gia_Obj_t * pFanin;
148  int i, nWordsUsed, nSuperSize = 0, Super[2*GIA_LIMIT];
149  // make sure this is a valid node
150  assert( Gia_ObjIsAnd(pObj) );
151  assert( pObj->fMark0 == 0 );
152  // collect inputs to the supergate
153  Gia_ManSatPartCollectSuper( p, pObj, Super, &nSuperSize );
154  assert( nSuperSize <= 2*GIA_LIMIT );
155  // create the root entry
156  *pObjPlace = 0;
157  ((Gia_ObjSat1_t *)pObjPlace)->nFans = Gia_Var2Lit( nSuperSize, 0 );
158  ((Gia_ObjSat1_t *)pObjPlace)->nOffset = pStore - pObjPlace;
159  nWordsUsed = nSuperSize;
160  for ( i = 0; i < nSuperSize; i++ )
161  {
162  pFanin = Gia_ManObj( p, Gia_Lit2Var(Super[i]) );
163  if ( pFanin->fMark0 )
164  {
165  ((Gia_ObjSat2_t *)(pStore + i))->fTerm = 1;
166  ((Gia_ObjSat2_t *)(pStore + i))->iLit = Super[i];
167  }
168  else
169  {
170  assert( Gia_LitIsCompl(Super[i]) );
171  nWordsUsed += Gia_ManSatPartCreate_rec( p, pFanin, pStore + i, pStore + nWordsUsed );
172  }
173  }
174  return nWordsUsed;
175 }
176 
177 /**Function*************************************************************
178 
179  Synopsis [Creates part and returns the number of words used.]
180 
181  Description []
182 
183  SideEffects []
184 
185  SeeAlso []
186 
187 ***********************************************************************/
188 int Gia_ManSatPartCreate( Gia_Man_t * p, Gia_Obj_t * pObj, int * pStore )
189 {
190  return 1 + Gia_ManSatPartCreate_rec( p, pObj, pStore, pStore + 1 );
191 }
192 
193 
194 /**Function*************************************************************
195 
196  Synopsis [Count the number of internal nodes in the leaf-DAG.]
197 
198  Description []
199 
200  SideEffects []
201 
202  SeeAlso []
203 
204 ***********************************************************************/
205 void Gia_ManSatPartCountClauses( Gia_Man_t * p, Gia_Obj_t * pObj, int * pnOnset, int * pnOffset )
206 {
207  Gia_Obj_t * pFanin;
208  int nOnset0, nOnset1, nOffset0, nOffset1;
209  assert( Gia_ObjIsAnd(pObj) );
210  pFanin = Gia_ObjFanin0(pObj);
211  if ( pFanin->fMark0 )
212  nOnset0 = 1, nOffset0 = 1;
213  else
214  {
215  Gia_ManSatPartCountClauses(p, pFanin, &nOnset0, &nOffset0);
216  if ( Gia_ObjFaninC0(pObj) )
217  {
218  int Temp = nOnset0;
219  nOnset0 = nOffset0;
220  nOffset0 = Temp;
221  }
222  }
223  pFanin = Gia_ObjFanin1(pObj);
224  if ( pFanin->fMark0 )
225  nOnset1 = 1, nOffset1 = 1;
226  else
227  {
228  Gia_ManSatPartCountClauses(p, pFanin, &nOnset1, &nOffset1);
229  if ( Gia_ObjFaninC1(pObj) )
230  {
231  int Temp = nOnset1;
232  nOnset1 = nOffset1;
233  nOffset1 = Temp;
234  }
235  }
236  *pnOnset = nOnset0 * nOnset1;
237  *pnOffset = nOffset0 + nOffset1;
238 }
239 
240 /**Function*************************************************************
241 
242  Synopsis [Count the number of internal nodes in the leaf-DAG.]
243 
244  Description []
245 
246  SideEffects []
247 
248  SeeAlso []
249 
250 ***********************************************************************/
251 int Gia_ManSatPartCount( Gia_Man_t * p, Gia_Obj_t * pObj, int * pnLeaves, int * pnNodes )
252 {
253  Gia_Obj_t * pFanin;
254  int Level0 = 0, Level1 = 0;
255  assert( Gia_ObjIsAnd(pObj) );
256  assert( pObj->fMark0 == 0 );
257  (*pnNodes)++;
258  pFanin = Gia_ObjFanin0(pObj);
259  if ( pFanin->fMark0 )
260  (*pnLeaves)++;
261  else
262  Level0 = Gia_ManSatPartCount(p, pFanin, pnLeaves, pnNodes) + Gia_ObjFaninC0(pObj);
263  pFanin = Gia_ObjFanin1(pObj);
264  if ( pFanin->fMark0 )
265  (*pnLeaves)++;
266  else
267  Level1 = Gia_ManSatPartCount(p, pFanin, pnLeaves, pnNodes) + Gia_ObjFaninC1(pObj);
268  return Abc_MaxInt( Level0, Level1 );
269 }
270 
271 /**Function*************************************************************
272 
273  Synopsis [Count the number of internal nodes in the leaf-DAG.]
274 
275  Description []
276 
277  SideEffects []
278 
279  SeeAlso []
280 
281 ***********************************************************************/
283 {
284  Gia_Obj_t * pFanin;
285  int nNodes0 = 0, nNodes1 = 0;
286  assert( Gia_ObjIsAnd(pObj) );
287  assert( pObj->fMark0 == 0 );
288  pFanin = Gia_ObjFanin0(pObj);
289  if ( !(pFanin->fMark0) )
290  nNodes0 = Gia_ManSatPartCountNodes(p, pFanin);
291  pFanin = Gia_ObjFanin1(pObj);
292  if ( !(pFanin->fMark0) )
293  nNodes1 = Gia_ManSatPartCountNodes(p, pFanin);
294  return nNodes0 + nNodes1 + 1;
295 }
296 
297 /**Function*************************************************************
298 
299  Synopsis [Count the number of internal nodes in the leaf-DAG.]
300 
301  Description []
302 
303  SideEffects []
304 
305  SeeAlso []
306 
307 ***********************************************************************/
308 void Gia_ManSatPartPrint( Gia_Man_t * p, Gia_Obj_t * pObj, int Step )
309 {
310  Gia_Obj_t * pFanin;
311  assert( Gia_ObjIsAnd(pObj) );
312  assert( pObj->fMark0 == 0 );
313  pFanin = Gia_ObjFanin0(pObj);
314  if ( pFanin->fMark0 )
315  printf( "%s%d", Gia_ObjFaninC0(pObj)?"!":"", Gia_ObjId(p,pFanin) );
316  else
317  {
318  if ( Gia_ObjFaninC0(pObj) )
319  printf( "(" );
320  Gia_ManSatPartPrint(p, pFanin, Step + Gia_ObjFaninC0(pObj));
321  if ( Gia_ObjFaninC0(pObj) )
322  printf( ")" );
323  }
324  printf( "%s", (Step & 1)? " + " : "*" );
325  pFanin = Gia_ObjFanin1(pObj);
326  if ( pFanin->fMark0 )
327  printf( "%s%d", Gia_ObjFaninC1(pObj)?"!":"", Gia_ObjId(p,pFanin) );
328  else
329  {
330  if ( Gia_ObjFaninC1(pObj) )
331  printf( "(" );
332  Gia_ManSatPartPrint(p, pFanin, Step + Gia_ObjFaninC1(pObj));
333  if ( Gia_ObjFaninC1(pObj) )
334  printf( ")" );
335  }
336 }
337 
338 
339 /**Function*************************************************************
340 
341  Synopsis []
342 
343  Description []
344 
345  SideEffects []
346 
347  SeeAlso []
348 
349 ***********************************************************************/
351 {
352  int nStored, Storage[1000], * pStart;
353  Gia_ManSat_t * pMan;
354  Gia_Obj_t * pObj;
355  int i, nLevels, nLeaves, nNodes, nCount[2*GIA_LIMIT+2] = {0}, nCountAll = 0;
356  int Num0 = 0, Num1 = 0;
357  clock_t clk = clock();
358  int nWords = 0, nWords2 = 0;
359  pMan = Gia_ManSatStart();
360  // mark the nodes to become roots of leaf-DAGs
362  Gia_ManForEachObj( p, pObj, i )
363  {
364  pObj->fMark0 = 0;
365  if ( Gia_ObjIsCo(pObj) )
366  Gia_ObjFanin0(pObj)->fMark0 = 1;
367  else if ( Gia_ObjIsCi(pObj) )
368  pObj->fMark0 = 1;
369  else if ( Gia_ObjIsAnd(pObj) )
370  {
371  if ( pObj->Value > 1 || Gia_ManSatPartCountNodes(p,pObj) >= GIA_LIMIT )
372  pObj->fMark0 = 1;
373  }
374  pObj->Value = 0;
375  }
376  // compute the sizes of leaf-DAGs
377  Gia_ManForEachAnd( p, pObj, i )
378  {
379  if ( pObj->fMark0 == 0 )
380  continue;
381  pObj->fMark0 = 0;
382 
383  nCountAll++;
384  nStored = Gia_ManSatPartCreate( p, pObj, Storage );
385  nWords2 += nStored;
386  assert( nStored < 500 );
387  pStart = (int *)Aig_MmFlexEntryFetch( pMan->pMem, sizeof(int) * nStored );
388  memcpy( pStart, Storage, sizeof(int) * nStored );
389 
390  nLeaves = nNodes = 0;
391  nLevels = 1+Gia_ManSatPartCount( p, pObj, &nLeaves, &nNodes );
392  nWords += nLeaves + nNodes;
393  if ( nNodes <= 2*GIA_LIMIT )
394  nCount[nNodes]++;
395  else
396  nCount[2*GIA_LIMIT+1]++;
397 // if ( nNodes > 10 && i % 100 == 0 )
398 // if ( nNodes > 5 )
399  if ( 0 )
400  {
401  Gia_ManSatPartCountClauses( p, pObj, &Num0, &Num1 );
402  printf( "%8d : And = %3d. Lev = %2d. Clauses = %3d. (%3d + %3d).\n", i, nNodes, nLevels, Num0+Num1, Num0, Num1 );
403  Gia_ManSatPartPrint( p, pObj, 0 );
404  printf( "\n" );
405  }
406 
407  pObj->fMark0 = 1;
408  }
409  printf( "\n" );
410  Gia_ManForEachObj( p, pObj, i )
411  pObj->fMark0 = 0;
412  Gia_ManSatStop( pMan );
413  for ( i = 0; i < 2*GIA_LIMIT+2; i++ )
414  printf( "%2d=%6d %7.2f %% %7.2f %%\n", i, nCount[i], 100.0*nCount[i]/nCountAll, 100.0*i*nCount[i]/Gia_ManAndNum(p) );
415  ABC_PRMn( "MemoryEst", 4*nWords );
416  ABC_PRMn( "MemoryReal", 4*nWords2 );
417  printf( "%5.2f bpn ", 4.0*nWords2/Gia_ManObjNum(p) );
418  ABC_PRT( "Time", clock() - clk );
419 }
420 
421 ////////////////////////////////////////////////////////////////////////
422 /// END OF FILE ///
423 ////////////////////////////////////////////////////////////////////////
424 
425 
427 
#define ABC_PRMn(a, f)
Definition: abc_global.h:226
char nFans
Definition: giaSat.c:42
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char nOffset
Definition: giaSat.c:43
Gia_ManSat_t * Gia_ManSatStart()
FUNCTION DEFINITIONS ///.
Definition: giaSat.c:80
int Gia_ManSatPartCreate_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int *pObjPlace, int *pStore)
Definition: giaSat.c:145
char * Aig_MmFlexEntryFetch(Aig_MmFlex_t *p, int nBytes)
Definition: aigMem.c:366
void Gia_ManSatPartPrint(Gia_Man_t *p, Gia_Obj_t *pObj, int Step)
Definition: giaSat.c:308
char * memcpy()
int Gia_ManSatPartCount(Gia_Man_t *p, Gia_Obj_t *pObj, int *pnLeaves, int *pnNodes)
Definition: giaSat.c:251
static int Abc_MaxInt(int a, int b)
Definition: abc_global.h:238
int nWords
Definition: abcNpn.c:127
unsigned iLit
Definition: giaSat.c:52
int Gia_ManSatPartCreate(Gia_Man_t *p, Gia_Obj_t *pObj, int *pStore)
Definition: giaSat.c:188
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
Aig_MmFlex_t * pMem
Definition: giaSat.c:36
void Gia_ManCreateValueRefs(Gia_Man_t *p)
Definition: giaUtil.c:687
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
char PathsV
Definition: giaSat.c:45
unsigned fTerm
Definition: giaSat.c:51
void Gia_ManSatExperiment(Gia_Man_t *p)
Definition: giaSat.c:350
Gia_ObjSat1_t Obj1
Definition: giaSat.c:59
void Gia_ManSatPartCountClauses(Gia_Man_t *p, Gia_Obj_t *pObj, int *pnOnset, int *pnOffset)
Definition: giaSat.c:205
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
char PathsH
Definition: giaSat.c:44
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
unsigned fMark0
Definition: gia.h:79
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
#define ABC_PRT(a, t)
Definition: abc_global.h:220
#define GIA_LIMIT
DECLARATIONS ///.
Definition: giaSat.c:30
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
#define Gia_ManForEachObj(p, pObj, i)
MACRO DEFINITIONS ///.
Definition: gia.h:984
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
void Gia_ManSatPartCollectSuper(Gia_Man_t *p, Gia_Obj_t *pObj, int *pLits, int *pnLits)
Definition: giaSat.c:117
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
void Gia_ManSatStop(Gia_ManSat_t *p)
Definition: giaSat.c:99
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
int Gia_ManSatPartCountNodes(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaSat.c:282
Gia_ObjSat2_t Obj2
Definition: giaSat.c:60