abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cnfPost.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [cnfPost.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [AIG-to-CNF conversion.]
8 
9  Synopsis []
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - April 28, 2007.]
16 
17  Revision [$Id: cnfPost.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "cnf.h"
22 
24 
25 
26 ////////////////////////////////////////////////////////////////////////
27 /// DECLARATIONS ///
28 ////////////////////////////////////////////////////////////////////////
29 
30 ////////////////////////////////////////////////////////////////////////
31 /// FUNCTION DEFINITIONS ///
32 ////////////////////////////////////////////////////////////////////////
33 
34 /**Function*************************************************************
35 
36  Synopsis []
37 
38  Description []
39 
40  SideEffects []
41 
42  SeeAlso []
43 
44 ***********************************************************************/
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 }
105 
106 /**Function*************************************************************
107 
108  Synopsis [Transfers cuts of the mapped nodes into internal representation.]
109 
110  Description []
111 
112  SideEffects []
113 
114  SeeAlso []
115 
116 ***********************************************************************/
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 }
130 
131 /**Function*************************************************************
132 
133  Synopsis [Transfers cuts of the mapped nodes into internal representation.]
134 
135  Description []
136 
137  SideEffects []
138 
139  SeeAlso []
140 
141 ***********************************************************************/
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 }
153 
154 /**Function*************************************************************
155 
156  Synopsis []
157 
158  Description []
159 
160  SideEffects []
161 
162  SeeAlso []
163 
164 ***********************************************************************/
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 }
231 
232 ////////////////////////////////////////////////////////////////////////
233 /// END OF FILE ///
234 ////////////////////////////////////////////////////////////////////////
235 
236 
238 
static Cnf_Cut_t * Cnf_ObjBestCut(Aig_Obj_t *pObj)
Definition: cnf.h:105
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 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
void Cnf_ManPostprocess(Cnf_Man_t *p)
Definition: cnfPost.c:165
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 ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define Cnf_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: cnf.h:121
ABC_NAMESPACE_IMPL_START void Cnf_ManPostprocess_old(Cnf_Man_t *p)
DECLARATIONS ///.
Definition: cnfPost.c:45
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_ManFreeCuts(Cnf_Man_t *p)
Definition: cnfPost.c:142
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Cnf_CutFree(Cnf_Cut_t *pCut)
Definition: cnfCut.c:68
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
#define Dar_CutForEachLeaf(p, pCut, pLeaf, i)
Definition: darInt.h:124
#define assert(ex)
Definition: util_old.h:213
char nFanins
Definition: cnf.h:73
typedefABC_NAMESPACE_HEADER_START struct Cnf_Man_t_ Cnf_Man_t
INCLUDES ///.
Definition: cnf.h:51
unsigned Value
Definition: darInt.h:59
int Id
Definition: aig.h:85
unsigned int nRefs
Definition: aig.h:81
void Cnf_ManTransferCuts(Cnf_Man_t *p)
Definition: cnfPost.c:117