abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rwrMan.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [rwrMan.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [DAG-aware AIG rewriting package.]
8 
9  Synopsis [Rewriting manager.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: rwrMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "rwr.h"
22 #include "base/main/main.h"
23 #include "bool/dec/dec.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 ////////////////////////////////////////////////////////////////////////
33 /// FUNCTION DEFINITIONS ///
34 ////////////////////////////////////////////////////////////////////////
35 
36 /**Function*************************************************************
37 
38  Synopsis [Starts rewriting manager.]
39 
40  Description []
41 
42  SideEffects []
43 
44  SeeAlso []
45 
46 ***********************************************************************/
47 Rwr_Man_t * Rwr_ManStart( int fPrecompute )
48 {
49  Dec_Man_t * pManDec;
50  Rwr_Man_t * p;
51  abctime clk = Abc_Clock();
52 clk = Abc_Clock();
53  p = ABC_ALLOC( Rwr_Man_t, 1 );
54  memset( p, 0, sizeof(Rwr_Man_t) );
55  p->nFuncs = (1<<16);
56  pManDec = (Dec_Man_t *)Abc_FrameReadManDec();
57  p->puCanons = pManDec->puCanons;
58  p->pPhases = pManDec->pPhases;
59  p->pPerms = pManDec->pPerms;
60  p->pMap = pManDec->pMap;
61  // initialize practical NPN classes
63  // create the table
64  p->pTable = ABC_ALLOC( Rwr_Node_t *, p->nFuncs );
65  memset( p->pTable, 0, sizeof(Rwr_Node_t *) * p->nFuncs );
66  // create the elementary nodes
67  p->pMmNode = Extra_MmFixedStart( sizeof(Rwr_Node_t) );
68  p->vForest = Vec_PtrAlloc( 100 );
69  Rwr_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
70  Rwr_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
71  Rwr_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
72  Rwr_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
73  Rwr_ManAddVar( p, 0xFF00, fPrecompute ); // var D
74  p->nClasses = 5;
75  // other stuff
76  p->nTravIds = 1;
77  p->pPerms4 = Extra_Permutations( 4 );
78  p->vLevNums = Vec_IntAlloc( 50 );
79  p->vFanins = Vec_PtrAlloc( 50 );
80  p->vFaninsCur = Vec_PtrAlloc( 50 );
81  p->vNodesTemp = Vec_PtrAlloc( 50 );
82  if ( fPrecompute )
83  { // precompute subgraphs
84  Rwr_ManPrecompute( p );
85 // Rwr_ManPrint( p );
87  }
88  else
89  { // load saved subgraphs
90  Rwr_ManLoadFromArray( p, 0 );
91 // Rwr_ManPrint( p );
92  Rwr_ManPreprocess( p );
93  }
94 p->timeStart = Abc_Clock() - clk;
95  return p;
96 }
97 
98 /**Function*************************************************************
99 
100  Synopsis [Stops rewriting manager.]
101 
102  Description []
103 
104  SideEffects []
105 
106  SeeAlso []
107 
108 ***********************************************************************/
110 {
111  if ( p->vClasses )
112  {
113  Rwr_Node_t * pNode;
114  int i, k;
115  Vec_VecForEachEntry( Rwr_Node_t *, p->vClasses, pNode, i, k )
116  Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
117  }
118  if ( p->vClasses ) Vec_VecFree( p->vClasses );
119  Vec_PtrFree( p->vNodesTemp );
120  Vec_PtrFree( p->vForest );
121  Vec_IntFree( p->vLevNums );
122  Vec_PtrFree( p->vFanins );
123  Vec_PtrFree( p->vFaninsCur );
125  ABC_FREE( p->pMapInv );
126  ABC_FREE( p->pTable );
127  ABC_FREE( p->pPractical );
128  ABC_FREE( p->pPerms4 );
129  ABC_FREE( p );
130 }
131 
132 /**Function*************************************************************
133 
134  Synopsis [Stops the resynthesis manager.]
135 
136  Description []
137 
138  SideEffects []
139 
140  SeeAlso []
141 
142 ***********************************************************************/
144 {
145  int i, Counter = 0;
146  for ( i = 0; i < 222; i++ )
147  Counter += (p->nScores[i] > 0);
148 
149  printf( "Rewriting statistics:\n" );
150  printf( "Total cuts tries = %8d.\n", p->nCutsGood );
151  printf( "Bad cuts found = %8d.\n", p->nCutsBad );
152  printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
153  printf( "Used NPN classes = %8d.\n", Counter );
154  printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
155  printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
156  printf( "Gain = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
157  ABC_PRT( "Start ", p->timeStart );
158  ABC_PRT( "Cuts ", p->timeCut );
159  ABC_PRT( "Resynthesis ", p->timeRes );
160  ABC_PRT( " Mffc ", p->timeMffc );
161  ABC_PRT( " Eval ", p->timeEval );
162  ABC_PRT( "Update ", p->timeUpdate );
163  ABC_PRT( "TOTAL ", p->timeTotal );
164 
165 /*
166  printf( "The scores are:\n" );
167  for ( i = 0; i < 222; i++ )
168  if ( p->nScores[i] > 0 )
169  {
170  extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
171  printf( "%3d = %8d canon = %5d ", i, p->nScores[i], p->pMapInv[i] );
172  Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
173  }
174 */
175  printf( "\n" );
176 
177 }
178 
179 /**Function*************************************************************
180 
181  Synopsis [Stops the resynthesis manager.]
182 
183  Description []
184 
185  SideEffects []
186 
187  SeeAlso []
188 
189 ***********************************************************************/
191 {
192  FILE * pTable;
193  pTable = fopen( "stats.txt", "a+" );
194  fprintf( pTable, "%d ", p->nCutsGood );
195  fprintf( pTable, "%d ", p->nSubgraphs );
196  fprintf( pTable, "%d ", p->nNodesRewritten );
197  fprintf( pTable, "%d", p->nNodesGained );
198  fprintf( pTable, "\n" );
199  fclose( pTable );
200 }
201 
202 /**Function*************************************************************
203 
204  Synopsis [Stops the resynthesis manager.]
205 
206  Description []
207 
208  SideEffects []
209 
210  SeeAlso []
211 
212 ***********************************************************************/
214 {
215  return p->pGraph;
216 }
217 
218 /**Function*************************************************************
219 
220  Synopsis [Stops the resynthesis manager.]
221 
222  Description []
223 
224  SideEffects []
225 
226  SeeAlso []
227 
228 ***********************************************************************/
230 {
231  return p->vFanins;
232 }
233 
234 /**Function*************************************************************
235 
236  Synopsis [Stops the resynthesis manager.]
237 
238  Description []
239 
240  SideEffects []
241 
242  SeeAlso []
243 
244 ***********************************************************************/
246 {
247  return p->fCompl;
248 }
249 
250 /**Function*************************************************************
251 
252  Synopsis [Stops the resynthesis manager.]
253 
254  Description []
255 
256  SideEffects []
257 
258  SeeAlso []
259 
260 ***********************************************************************/
262 {
263  p->timeCut += Time;
264 }
265 
266 /**Function*************************************************************
267 
268  Synopsis [Stops the resynthesis manager.]
269 
270  Description []
271 
272  SideEffects []
273 
274  SeeAlso []
275 
276 ***********************************************************************/
278 {
279  p->timeUpdate += Time;
280 }
281 
282 /**Function*************************************************************
283 
284  Synopsis [Stops the resynthesis manager.]
285 
286  Description []
287 
288  SideEffects []
289 
290  SeeAlso []
291 
292 ***********************************************************************/
294 {
295  p->timeTotal += Time;
296 }
297 
298 
299 /**Function*************************************************************
300 
301  Synopsis [Precomputes AIG subgraphs.]
302 
303  Description []
304 
305  SideEffects []
306 
307  SeeAlso []
308 
309 ***********************************************************************/
311 {
312  Rwr_Man_t * p;
313  p = Rwr_ManStart( 1 );
314  Rwr_ManStop( p );
315 }
316 
317 ////////////////////////////////////////////////////////////////////////
318 /// END OF FILE ///
319 ////////////////////////////////////////////////////////////////////////
320 
321 
323 
char * memset()
void Rwr_ManAddTimeCuts(Rwr_Man_t *p, abctime Time)
Definition: rwrMan.c:261
abctime timeTotal
Definition: rwr.h:95
char * Rwr_ManGetPractical(Rwr_Man_t *p)
Definition: rwrUtil.c:640
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
abctime timeEval
Definition: rwr.h:92
abctime timeStart
Definition: rwr.h:89
int nNodesEnd
Definition: rwr.h:83
static Llb_Mgr_t * p
Definition: llb3Image.c:950
Rwr_Node_t * Rwr_ManAddVar(Rwr_Man_t *p, unsigned uTruth, int fPrecompute)
Definition: rwrLib.c:253
void Rwr_ManPrecompute(Rwr_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: rwrLib.c:48
unsigned char * pMap
Definition: rwr.h:57
Definition: rwr.h:50
void Rwr_ManWriteToArray(Rwr_Man_t *p)
FUNCTION DEFINITIONS ///.
Definition: rwrUtil.c:426
#define Vec_VecForEachEntry(Type, vGlob, pEntry, i, k)
Definition: vecVec.h:87
int nNodesBeg
Definition: rwr.h:82
unsigned short * puCanons
Definition: rwr.h:54
int nNodesGained
Definition: rwr.h:81
void Extra_MmFixedStop(Extra_MmFixed_t *p)
void Rwr_ManPreprocess(Rwr_Man_t *p)
MACRO DEFINITIONS ///.
Definition: rwrDec.c:49
char ** pPerms4
Definition: rwr.h:60
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
char * pPhases
Definition: dec.h:87
Vec_Ptr_t * vNodesTemp
Definition: rwr.h:77
Vec_Int_t * vLevNums
Definition: rwr.h:76
unsigned char * pMap
Definition: dec.h:89
static abctime Abc_Clock()
Definition: abc_global.h:279
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
abctime timeCut
Definition: rwr.h:90
Extra_MmFixed_t * pMmNode
Definition: rwr.h:65
int nTravIds
Definition: rwr.h:67
ABC_DLL void * Abc_FrameReadManDec()
Definition: mainFrame.c:61
char ** Extra_Permutations(int n)
Vec_Vec_t * vClasses
Definition: rwr.h:64
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Vec_Ptr_t * vFanins
Definition: rwr.h:74
Extra_MmFixed_t * Extra_MmFixedStart(int nEntrySize)
Vec_Ptr_t * vFaninsCur
Definition: rwr.h:75
void Rwr_ManAddTimeUpdate(Rwr_Man_t *p, abctime Time)
Definition: rwrMan.c:277
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
int Rwr_ManReadCompl(Rwr_Man_t *p)
Definition: rwrMan.c:245
void Rwr_ManPrintStatsFile(Rwr_Man_t *p)
Definition: rwrMan.c:190
static int Counter
int nSubgraphs
Definition: rwr.h:87
unsigned short * puCanons
Definition: dec.h:86
char * pPhases
Definition: rwr.h:55
Vec_Ptr_t * Rwr_ManReadLeaves(Rwr_Man_t *p)
Definition: rwrMan.c:229
unsigned short * pMapInv
Definition: rwr.h:58
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
int fCompl
Definition: rwr.h:72
int nCutsGood
Definition: rwr.h:85
void Rwr_Precompute()
Definition: rwrMan.c:310
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
int nClasses
Definition: rwr.h:70
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define ABC_PRT(a, t)
Definition: abc_global.h:220
void Rwr_ManStop(Rwr_Man_t *p)
Definition: rwrMan.c:109
int nCutsBad
Definition: rwr.h:86
Rwr_Node_t ** pTable
Definition: rwr.h:63
ABC_NAMESPACE_IMPL_START Rwr_Man_t * Rwr_ManStart(int fPrecompute)
DECLARATIONS ///.
Definition: rwrMan.c:47
void Rwr_ManLoadFromArray(Rwr_Man_t *p, int fVerbose)
Definition: rwrUtil.c:472
char * pPractical
Definition: rwr.h:59
void * pGraph
Definition: rwr.h:73
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
int nNodesRewritten
Definition: rwr.h:80
int nNodesConsidered
Definition: rwr.h:79
Definition: dec.h:80
abctime timeMffc
Definition: rwr.h:93
void Rwr_ManPrintStats(Rwr_Man_t *p)
Definition: rwrMan.c:143
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
void * Rwr_ManReadDecs(Rwr_Man_t *p)
Definition: rwrMan.c:213
Rwr_Node_t * pNext
Definition: rwr.h:112
ABC_INT64_T abctime
Definition: abc_global.h:278
abctime timeUpdate
Definition: rwr.h:94
char * pPerms
Definition: dec.h:88
Vec_Ptr_t * vForest
Definition: rwr.h:62
abctime timeRes
Definition: rwr.h:91
int nFuncs
Definition: rwr.h:53
char * pPerms
Definition: rwr.h:56
int nScores[222]
Definition: rwr.h:84
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223
void Rwr_ManAddTimeTotal(Rwr_Man_t *p, abctime Time)
Definition: rwrMan.c:293