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

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START void Cnf_ManPostprocess_old (Cnf_Man_t *p)
 DECLARATIONS ///. More...
 
void Cnf_ManTransferCuts (Cnf_Man_t *p)
 
void Cnf_ManFreeCuts (Cnf_Man_t *p)
 
void Cnf_ManPostprocess (Cnf_Man_t *p)
 

Function Documentation

void Cnf_ManFreeCuts ( Cnf_Man_t p)

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

Synopsis [Transfers cuts of the mapped nodes into internal representation.]

Description []

SideEffects []

SeeAlso []

Definition at line 142 of file cnfPost.c.

143 {
144  Aig_Obj_t * pObj;
145  int i;
146  Aig_ManForEachObj( p->pManAig, pObj, i )
147  if ( pObj->pData )
148  {
149  Cnf_CutFree( (Cnf_Cut_t *)pObj->pData );
150  pObj->pData = NULL;
151  }
152 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * pData
Definition: aig.h:87
Definition: cnf.h:71
if(last==0)
Definition: sparse_int.h:34
Definition: aig.h:69
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
void Cnf_ManPostprocess ( Cnf_Man_t p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 165 of file cnfPost.c.

166 {
167  Cnf_Cut_t * pCut, * pCutFan, * pCutRes;
168  Aig_Obj_t * pObj, * pFan;
169  int Order[16], Costs[16];
170  int i, k, fChanges;
171  Aig_ManForEachNode( p->pManAig, pObj, i )
172  {
173  if ( pObj->nRefs == 0 )
174  continue;
175  pCut = Cnf_ObjBestCut(pObj);
176 
177  // sort fanins according to their size
178  Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k )
179  {
180  Order[k] = k;
181  Costs[k] = Aig_ObjIsNode(pFan)? Cnf_ObjBestCut(pFan)->Cost : 0;
182  }
183  // sort the cuts by Weight
184  do {
185  int Temp;
186  fChanges = 0;
187  for ( k = 0; k < pCut->nFanins - 1; k++ )
188  {
189  if ( Costs[Order[k]] <= Costs[Order[k+1]] )
190  continue;
191  Temp = Order[k];
192  Order[k] = Order[k+1];
193  Order[k+1] = Temp;
194  fChanges = 1;
195  }
196  } while ( fChanges );
197 
198 
199 // Cnf_CutForEachLeaf( p->pManAig, pCut, pFan, k )
200  for ( k = 0; (k < (int)(pCut)->nFanins) && ((pFan) = Aig_ManObj(p->pManAig, (pCut)->pFanins[Order[k]])); k++ )
201  {
202  if ( !Aig_ObjIsNode(pFan) )
203  continue;
204  assert( pFan->nRefs != 0 );
205  if ( pFan->nRefs != 1 )
206  continue;
207  pCutFan = Cnf_ObjBestCut(pFan);
208  // try composing these two cuts
209 // Cnf_CutPrint( pCut );
210  pCutRes = Cnf_CutCompose( p, pCut, pCutFan, pFan->Id );
211 // Cnf_CutPrint( pCut );
212 // printf( "\n" );
213  // check if the cost if reduced
214  if ( pCutRes == NULL || pCutRes->Cost == 127 || pCutRes->Cost > pCut->Cost + pCutFan->Cost )
215  {
216  if ( pCutRes )
217  Cnf_CutFree( pCutRes );
218  continue;
219  }
220  // update the cut
221  Cnf_ObjSetBestCut( pObj, pCutRes );
222  Cnf_ObjSetBestCut( pFan, NULL );
223  Cnf_CutUpdateRefs( p, pCut, pCutFan, pCutRes );
224  assert( pFan->nRefs == 0 );
225  Cnf_CutFree( pCut );
226  Cnf_CutFree( pCutFan );
227  break;
228  }
229  }
230 }
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static Aig_Obj_t * Aig_ManObj(Aig_Man_t *p, int i)
Definition: aig.h:270
static void Cnf_ObjSetBestCut(Aig_Obj_t *pObj, Cnf_Cut_t *pCut)
Definition: cnf.h:106
char Cost
Definition: cnf.h:74
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
Cnf_Cut_t * Cnf_CutCompose(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, int iFan)
Definition: cnfCut.c:294
#define Aig_ManForEachNode(p, pObj, i)
Definition: aig.h:413
Definition: cnf.h:71
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: cnf.h:121
Definition: aig.h:69
void Cnf_CutUpdateRefs(Cnf_Man_t *p, Cnf_Cut_t *pCut, Cnf_Cut_t *pCutFan, Cnf_Cut_t *pCutRes)
Definition: cnfCut.c:178
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
#define assert(ex)
Definition: util_old.h:213
char nFanins
Definition: cnf.h:73
int Id
Definition: aig.h:85
unsigned int nRefs
Definition: aig.h:81
ABC_NAMESPACE_IMPL_START void Cnf_ManPostprocess_old ( Cnf_Man_t p)

DECLARATIONS ///.

CFile****************************************************************

FileName [cnfPost.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [AIG-to-CNF conversion.]

Synopsis []

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

Date [Ver. 1.0. Started - April 28, 2007.]

Revision [

Id:
cnfPost.c,v 1.00 2007/04/28 00:00:00 alanmi Exp

]FUNCTION DEFINITIONS /// Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 45 of file cnfPost.c.

46 {
47 // extern int Aig_ManLargeCutEval( Aig_Man_t * p, Aig_Obj_t * pRoot, Dar_Cut_t * pCutR, Dar_Cut_t * pCutL, int Leaf );
48  int nNew, Gain, nGain = 0, nVars = 0;
49 
50  Aig_Obj_t * pObj, * pFan;
51  Dar_Cut_t * pCutBest, * pCut;
52  int i, k;//, a, b, Counter;
53  Aig_ManForEachObj( p->pManAig, pObj, i )
54  {
55  if ( !Aig_ObjIsNode(pObj) )
56  continue;
57  if ( pObj->nRefs == 0 )
58  continue;
59 // pCutBest = Aig_ObjBestCut(pObj);
60  pCutBest = NULL;
61 
62  Dar_CutForEachLeaf( p->pManAig, pCutBest, pFan, k )
63  {
64  if ( !Aig_ObjIsNode(pFan) )
65  continue;
66  assert( pFan->nRefs != 0 );
67  if ( pFan->nRefs != 1 )
68  continue;
69 // pCut = Aig_ObjBestCut(pFan);
70  pCut = NULL;
71 /*
72  // find how many common variable they have
73  Counter = 0;
74  for ( a = 0; a < (int)pCut->nLeaves; a++ )
75  {
76  for ( b = 0; b < (int)pCutBest->nLeaves; b++ )
77  if ( pCut->pLeaves[a] == pCutBest->pLeaves[b] )
78  break;
79  if ( b == (int)pCutBest->nLeaves )
80  continue;
81  Counter++;
82  }
83  printf( "%d ", Counter );
84 */
85  // find the new truth table after collapsing these two cuts
86 
87 
88 // nNew = Aig_ManLargeCutEval( p->pManAig, pObj, pCutBest, pCut, pFan->Id );
89  nNew = 0;
90 
91 
92 // printf( "%d+%d=%d:%d(%d) ", pCutBest->Cost, pCut->Cost,
93 // pCutBest->Cost+pCut->Cost, nNew, pCutBest->Cost+pCut->Cost-nNew );
94 
95  Gain = pCutBest->Value + pCut->Value - nNew;
96  if ( Gain > 0 )
97  {
98  nGain += Gain;
99  nVars++;
100  }
101  }
102  }
103  printf( "Total gain = %d. Vars = %d.\n", nGain, nVars );
104 }
static Llb_Mgr_t * p
Definition: llb3Image.c:950
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
Definition: aig.h:69
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
#define Dar_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: darInt.h:124
#define assert(ex)
Definition: util_old.h:213
unsigned Value
Definition: darInt.h:59
unsigned int nRefs
Definition: aig.h:81
void Cnf_ManTransferCuts ( Cnf_Man_t p)

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

Synopsis [Transfers cuts of the mapped nodes into internal representation.]

Description []

SideEffects []

SeeAlso []

Definition at line 117 of file cnfPost.c.

118 {
119  Aig_Obj_t * pObj;
120  int i;
121  Aig_MmFlexRestart( p->pMemCuts );
122  Aig_ManForEachObj( p->pManAig, pObj, i )
123  {
124  if ( Aig_ObjIsNode(pObj) && pObj->nRefs > 0 )
125  pObj->pData = Cnf_CutCreate( p, pObj );
126  else
127  pObj->pData = NULL;
128  }
129 }
void Aig_MmFlexRestart(Aig_MmFlex_t *p)
Definition: aigMem.c:411
static Llb_Mgr_t * p
Definition: llb3Image.c:950
void * pData
Definition: aig.h:87
static int Aig_ObjIsNode(Aig_Obj_t *pObj)
Definition: aig.h:280
Definition: aig.h:69
Cnf_Cut_t * Cnf_CutCreate(Cnf_Man_t *p, Aig_Obj_t *pObj)
Definition: cnfCut.c:87
#define Aig_ManForEachObj(p, pObj, i)
Definition: aig.h:403
unsigned int nRefs
Definition: aig.h:81