abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaSat.c File Reference
#include "gia.h"

Go to the source code of this file.

Data Structures

struct  Gia_ManSat_t_
 
struct  Gia_ObjSat1_t_
 
struct  Gia_ObjSat2_t_
 
struct  Gia_ObjSat_t_
 

Macros

#define GIA_LIMIT   10
 DECLARATIONS ///. More...
 

Typedefs

typedef struct Gia_ManSat_t_ Gia_ManSat_t
 
typedef struct Gia_ObjSat1_t_ Gia_ObjSat1_t
 
typedef struct Gia_ObjSat2_t_ Gia_ObjSat2_t
 
typedef struct Gia_ObjSat_t_ Gia_ObjSat_t
 

Functions

Gia_ManSat_tGia_ManSatStart ()
 FUNCTION DEFINITIONS ///. More...
 
void Gia_ManSatStop (Gia_ManSat_t *p)
 
void Gia_ManSatPartCollectSuper (Gia_Man_t *p, Gia_Obj_t *pObj, int *pLits, int *pnLits)
 
int Gia_ManSatPartCreate_rec (Gia_Man_t *p, Gia_Obj_t *pObj, int *pObjPlace, int *pStore)
 
int Gia_ManSatPartCreate (Gia_Man_t *p, Gia_Obj_t *pObj, int *pStore)
 
void Gia_ManSatPartCountClauses (Gia_Man_t *p, Gia_Obj_t *pObj, int *pnOnset, int *pnOffset)
 
int Gia_ManSatPartCount (Gia_Man_t *p, Gia_Obj_t *pObj, int *pnLeaves, int *pnNodes)
 
int Gia_ManSatPartCountNodes (Gia_Man_t *p, Gia_Obj_t *pObj)
 
void Gia_ManSatPartPrint (Gia_Man_t *p, Gia_Obj_t *pObj, int Step)
 
void Gia_ManSatExperiment (Gia_Man_t *p)
 

Macro Definition Documentation

#define GIA_LIMIT   10

DECLARATIONS ///.

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

]

Definition at line 30 of file giaSat.c.

Typedef Documentation

typedef struct Gia_ManSat_t_ Gia_ManSat_t

Definition at line 33 of file giaSat.c.

typedef struct Gia_ObjSat1_t_ Gia_ObjSat1_t

Definition at line 39 of file giaSat.c.

typedef struct Gia_ObjSat2_t_ Gia_ObjSat2_t

Definition at line 48 of file giaSat.c.

typedef struct Gia_ObjSat_t_ Gia_ObjSat_t

Definition at line 55 of file giaSat.c.

Function Documentation

void Gia_ManSatExperiment ( Gia_Man_t p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 350 of file giaSat.c.

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 }
#define ABC_PRMn(a, f)
Definition: abc_global.h:226
Gia_ManSat_t * Gia_ManSatStart()
FUNCTION DEFINITIONS ///.
Definition: giaSat.c:80
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
int nWords
Definition: abcNpn.c:127
int Gia_ManSatPartCreate(Gia_Man_t *p, Gia_Obj_t *pObj, int *pStore)
Definition: giaSat.c:188
for(p=first;p->value< newval;p=p->next)
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 Gia_ManForEachAnd(p, pObj, i)
Definition: gia.h:1002
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
unsigned fMark0
Definition: gia.h:79
#define ABC_PRT(a, t)
Definition: abc_global.h:220
#define GIA_LIMIT
DECLARATIONS ///.
Definition: giaSat.c:30
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 assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: gia.h:87
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
void Gia_ManSatPartCollectSuper ( Gia_Man_t p,
Gia_Obj_t pObj,
int *  pLits,
int *  pnLits 
)

Function*************************************************************

Synopsis [Collects the supergate rooted at this ]

Description []

SideEffects []

SeeAlso []

Definition at line 117 of file giaSat.c.

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 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
Definition: gia.h:75
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
unsigned fMark0
Definition: gia.h:79
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
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
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
int Gia_ManSatPartCount ( Gia_Man_t p,
Gia_Obj_t pObj,
int *  pnLeaves,
int *  pnNodes 
)

Function*************************************************************

Synopsis [Count the number of internal nodes in the leaf-DAG.]

Description []

SideEffects []

SeeAlso []

Definition at line 251 of file giaSat.c.

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 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
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
Definition: gia.h:75
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
unsigned fMark0
Definition: gia.h:79
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
void Gia_ManSatPartCountClauses ( Gia_Man_t p,
Gia_Obj_t pObj,
int *  pnOnset,
int *  pnOffset 
)

Function*************************************************************

Synopsis [Count the number of internal nodes in the leaf-DAG.]

Description []

SideEffects []

SeeAlso []

Definition at line 205 of file giaSat.c.

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 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
Definition: gia.h:75
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
void Gia_ManSatPartCountClauses(Gia_Man_t *p, Gia_Obj_t *pObj, int *pnOnset, int *pnOffset)
Definition: giaSat.c:205
unsigned fMark0
Definition: gia.h:79
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
int Gia_ManSatPartCountNodes ( Gia_Man_t p,
Gia_Obj_t pObj 
)

Function*************************************************************

Synopsis [Count the number of internal nodes in the leaf-DAG.]

Description []

SideEffects []

SeeAlso []

Definition at line 282 of file giaSat.c.

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 }
Definition: gia.h:75
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
unsigned fMark0
Definition: gia.h:79
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
int Gia_ManSatPartCountNodes(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: giaSat.c:282
int Gia_ManSatPartCreate ( Gia_Man_t p,
Gia_Obj_t pObj,
int *  pStore 
)

Function*************************************************************

Synopsis [Creates part and returns the number of words used.]

Description []

SideEffects []

SeeAlso []

Definition at line 188 of file giaSat.c.

189 {
190  return 1 + Gia_ManSatPartCreate_rec( p, pObj, pStore, pStore + 1 );
191 }
int Gia_ManSatPartCreate_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int *pObjPlace, int *pStore)
Definition: giaSat.c:145
int Gia_ManSatPartCreate_rec ( Gia_Man_t p,
Gia_Obj_t pObj,
int *  pObjPlace,
int *  pStore 
)

Function*************************************************************

Synopsis [Returns the number of words used.]

Description []

SideEffects []

SeeAlso []

Definition at line 145 of file giaSat.c.

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 }
int Gia_ManSatPartCreate_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int *pObjPlace, int *pStore)
Definition: giaSat.c:145
static Gia_Obj_t * Gia_ManObj(Gia_Man_t *p, int v)
Definition: gia.h:402
Definition: gia.h:75
unsigned fMark0
Definition: gia.h:79
#define GIA_LIMIT
DECLARATIONS ///.
Definition: giaSat.c:30
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
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
void Gia_ManSatPartPrint ( Gia_Man_t p,
Gia_Obj_t pObj,
int  Step 
)

Function*************************************************************

Synopsis [Count the number of internal nodes in the leaf-DAG.]

Description []

SideEffects []

SeeAlso []

Definition at line 308 of file giaSat.c.

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 }
static int Gia_ObjFaninC1(Gia_Obj_t *pObj)
Definition: gia.h:452
void Gia_ManSatPartPrint(Gia_Man_t *p, Gia_Obj_t *pObj, int Step)
Definition: giaSat.c:308
Definition: gia.h:75
static Gia_Obj_t * Gia_ObjFanin0(Gia_Obj_t *pObj)
Definition: gia.h:454
static int Gia_ObjId(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:410
unsigned fMark0
Definition: gia.h:79
static int Gia_ObjIsAnd(Gia_Obj_t *pObj)
Definition: gia.h:422
static Gia_Obj_t * Gia_ObjFanin1(Gia_Obj_t *pObj)
Definition: gia.h:455
#define assert(ex)
Definition: util_old.h:213
static int Gia_ObjFaninC0(Gia_Obj_t *pObj)
Definition: gia.h:451
Gia_ManSat_t* Gia_ManSatStart ( )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 80 of file giaSat.c.

81 {
82  Gia_ManSat_t * p;
83  p = ABC_CALLOC( Gia_ManSat_t, 1 );
84  p->pMem = Aig_MmFlexStart();
85  return p;
86 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Aig_MmFlex_t * pMem
Definition: giaSat.c:36
Aig_MmFlex_t * Aig_MmFlexStart()
Definition: aigMem.c:305
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
void Gia_ManSatStop ( Gia_ManSat_t p)

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file giaSat.c.

100 {
101  Aig_MmFlexStop( p->pMem, 0 );
102  ABC_FREE( p );
103 }
Aig_MmFlex_t * pMem
Definition: giaSat.c:36
#define ABC_FREE(obj)
Definition: abc_global.h:232
void Aig_MmFlexStop(Aig_MmFlex_t *p, int fVerbose)
Definition: aigMem.c:337