abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rwtMan.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [rwtMan.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: rwtMan.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "rwt.h"
22 #include "bool/deco/deco.h"
23 
25 
26 
27 ////////////////////////////////////////////////////////////////////////
28 /// DECLARATIONS ///
29 ////////////////////////////////////////////////////////////////////////
30 
31 static unsigned short * s_puCanons = NULL;
32 static char * s_pPhases = NULL;
33 static char * s_pPerms = NULL;
34 static unsigned char * s_pMap = NULL;
35 
36 ////////////////////////////////////////////////////////////////////////
37 /// FUNCTION DEFINITIONS ///
38 ////////////////////////////////////////////////////////////////////////
39 
40 /**Function*************************************************************
41 
42  Synopsis [Starts residual rewriting manager.]
43 
44  Description []
45 
46  SideEffects []
47 
48  SeeAlso []
49 
50 ***********************************************************************/
52 {
53  if ( s_puCanons == NULL )
55 }
56 
57 /**Function*************************************************************
58 
59  Synopsis [Starts residual rewriting manager.]
60 
61  Description []
62 
63  SideEffects []
64 
65  SeeAlso []
66 
67 ***********************************************************************/
69 {
72  ABC_FREE( s_pPerms );
73  ABC_FREE( s_pMap );
74 }
75 
76 /**Function*************************************************************
77 
78  Synopsis [Starts rewriting manager.]
79 
80  Description []
81 
82  SideEffects []
83 
84  SeeAlso []
85 
86 ***********************************************************************/
87 Rwt_Man_t * Rwt_ManStart( int fPrecompute )
88 {
89  Rwt_Man_t * p;
90  abctime clk = Abc_Clock();
91 clk = Abc_Clock();
92  p = ABC_ALLOC( Rwt_Man_t, 1 );
93  memset( p, 0, sizeof(Rwt_Man_t) );
94  p->nFuncs = (1<<16);
95  // copy the global tables
97  p->puCanons = s_puCanons;
98  p->pPhases = s_pPhases;
99  p->pPerms = s_pPerms;
100  p->pMap = s_pMap;
101  // initialize practical NPN classes
103  // create the table
104  p->pTable = ABC_ALLOC( Rwt_Node_t *, p->nFuncs );
105  memset( p->pTable, 0, sizeof(Rwt_Node_t *) * p->nFuncs );
106  // create the elementary nodes
107  p->pMmNode = Mem_FixedStart( sizeof(Rwt_Node_t) );
108  p->vForest = Vec_PtrAlloc( 100 );
109  Rwt_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
110  Rwt_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
111  Rwt_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
112  Rwt_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
113  Rwt_ManAddVar( p, 0xFF00, fPrecompute ); // var D
114  p->nClasses = 5;
115  // other stuff
116  p->nTravIds = 1;
117  p->pPerms4 = Extra_Permutations( 4 );
118  p->vLevNums = Vec_IntAlloc( 50 );
119  p->vFanins = Vec_PtrAlloc( 50 );
120  p->vFaninsCur = Vec_PtrAlloc( 50 );
121  p->vNodesTemp = Vec_PtrAlloc( 50 );
122  if ( fPrecompute )
123  { // precompute subgraphs
124 // Rwt_ManPrecompute( p );
125 // Rwt_ManPrint( p );
126 // Rwt_ManWriteToArray( p );
127  }
128  else
129  { // load saved subgraphs
130  Rwt_ManLoadFromArray( p, 0 );
131 // Rwt_ManPrint( p );
132  Rwt_ManPreprocess( p );
133  }
134 p->timeStart = Abc_Clock() - clk;
135  return p;
136 }
137 
138 /**Function*************************************************************
139 
140  Synopsis [Stops rewriting manager.]
141 
142  Description []
143 
144  SideEffects []
145 
146  SeeAlso []
147 
148 ***********************************************************************/
150 {
151  if ( p->vClasses )
152  {
153  Rwt_Node_t * pNode;
154  int i, k;
155  Vec_VecForEachEntry( Rwt_Node_t *, p->vClasses, pNode, i, k )
156  Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
157  }
158  if ( p->vClasses ) Vec_VecFree( p->vClasses );
159  Vec_PtrFree( p->vNodesTemp );
160  Vec_PtrFree( p->vForest );
161  Vec_IntFree( p->vLevNums );
162  Vec_PtrFree( p->vFanins );
163  Vec_PtrFree( p->vFaninsCur );
164  Mem_FixedStop( p->pMmNode, 0 );
165  ABC_FREE( p->pMapInv );
166  ABC_FREE( p->pTable );
167  ABC_FREE( p->pPractical );
168  ABC_FREE( p->pPerms4 );
169  ABC_FREE( p );
170 }
171 
172 /**Function*************************************************************
173 
174  Synopsis [Stops the resynthesis manager.]
175 
176  Description []
177 
178  SideEffects []
179 
180  SeeAlso []
181 
182 ***********************************************************************/
184 {
185  int i, Counter = 0;
186  for ( i = 0; i < 222; i++ )
187  Counter += (p->nScores[i] > 0);
188 
189  printf( "Rewriting statistics:\n" );
190  printf( "Total cuts tries = %8d.\n", p->nCutsGood );
191  printf( "Bad cuts found = %8d.\n", p->nCutsBad );
192  printf( "Total subgraphs = %8d.\n", p->nSubgraphs );
193  printf( "Used NPN classes = %8d.\n", Counter );
194  printf( "Nodes considered = %8d.\n", p->nNodesConsidered );
195  printf( "Nodes rewritten = %8d.\n", p->nNodesRewritten );
196  printf( "Calculated gain = %8d.\n", p->nNodesGained );
197  ABC_PRT( "Start ", p->timeStart );
198  ABC_PRT( "Cuts ", p->timeCut );
199  ABC_PRT( "Truth ", p->timeTruth );
200  ABC_PRT( "Resynthesis ", p->timeRes );
201  ABC_PRT( " Mffc ", p->timeMffc );
202  ABC_PRT( " Eval ", p->timeEval );
203  ABC_PRT( "Update ", p->timeUpdate );
204  ABC_PRT( "TOTAL ", p->timeTotal );
205 
206 /*
207  printf( "The scores are:\n" );
208  for ( i = 0; i < 222; i++ )
209  if ( p->nScores[i] > 0 )
210  {
211  extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
212  printf( "%3d = %8d canon = %5d ", i, p->nScores[i], p->pMapInv[i] );
213  Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
214  }
215  printf( "\n" );
216 */
217 }
218 
219 /**Function*************************************************************
220 
221  Synopsis [Stops the resynthesis manager.]
222 
223  Description []
224 
225  SideEffects []
226 
227  SeeAlso []
228 
229 ***********************************************************************/
231 {
232  FILE * pTable;
233  pTable = fopen( "stats.txt", "a+" );
234  fprintf( pTable, "%d ", p->nCutsGood );
235  fprintf( pTable, "%d ", p->nSubgraphs );
236  fprintf( pTable, "%d ", p->nNodesRewritten );
237  fprintf( pTable, "%d", p->nNodesGained );
238  fprintf( pTable, "\n" );
239  fclose( pTable );
240 }
241 
242 /**Function*************************************************************
243 
244  Synopsis [Stops the resynthesis manager.]
245 
246  Description []
247 
248  SideEffects []
249 
250  SeeAlso []
251 
252 ***********************************************************************/
254 {
255  return p->pGraph;
256 }
257 
258 /**Function*************************************************************
259 
260  Synopsis [Stops the resynthesis manager.]
261 
262  Description []
263 
264  SideEffects []
265 
266  SeeAlso []
267 
268 ***********************************************************************/
270 {
271  return p->vFanins;
272 }
273 
274 /**Function*************************************************************
275 
276  Synopsis [Stops the resynthesis manager.]
277 
278  Description []
279 
280  SideEffects []
281 
282  SeeAlso []
283 
284 ***********************************************************************/
286 {
287  return p->fCompl;
288 }
289 
290 /**Function*************************************************************
291 
292  Synopsis [Stops the resynthesis manager.]
293 
294  Description []
295 
296  SideEffects []
297 
298  SeeAlso []
299 
300 ***********************************************************************/
302 {
303  p->timeCut += Time;
304 }
305 
306 /**Function*************************************************************
307 
308  Synopsis [Stops the resynthesis manager.]
309 
310  Description []
311 
312  SideEffects []
313 
314  SeeAlso []
315 
316 ***********************************************************************/
318 {
319  p->timeUpdate += Time;
320 }
321 
322 /**Function*************************************************************
323 
324  Synopsis [Stops the resynthesis manager.]
325 
326  Description []
327 
328  SideEffects []
329 
330  SeeAlso []
331 
332 ***********************************************************************/
334 {
335  p->timeTotal += Time;
336 }
337 
338 
339 /**Function*************************************************************
340 
341  Synopsis [Precomputes AIG subgraphs.]
342 
343  Description []
344 
345  SideEffects []
346 
347  SeeAlso []
348 
349 ***********************************************************************/
351 {
352  Rwt_Man_t * p;
353  p = Rwt_ManStart( 1 );
354  Rwt_ManStop( p );
355 }
356 
357 ////////////////////////////////////////////////////////////////////////
358 /// END OF FILE ///
359 ////////////////////////////////////////////////////////////////////////
360 
361 
363 
char * memset()
void Rwt_ManPrintStatsFile(Rwt_Man_t *p)
Definition: rwtMan.c:230
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition: vecPtr.h:42
Rwt_Node_t * pNext
Definition: rwt.h:118
void Rwt_ManAddTimeTotal(Rwt_Man_t *p, abctime Time)
Definition: rwtMan.c:333
Rwt_Node_t * Rwt_ManAddVar(Rwt_Man_t *p, unsigned uTruth, int fPrecompute)
Definition: rwtUtil.c:446
void Rwt_ManGlobalStart()
FUNCTION DEFINITIONS ///.
Definition: rwtMan.c:51
static Llb_Mgr_t * p
Definition: llb3Image.c:950
char ** pPerms4
Definition: rwt.h:68
unsigned short * pMapInv
Definition: rwt.h:66
#define Vec_VecForEachEntry(Type, vGlob, pEntry, i, k)
Definition: vecVec.h:87
void Rwt_Precompute()
Definition: rwtMan.c:350
static char * s_pPerms
Definition: rwtMan.c:33
abctime timeMffc
Definition: rwt.h:102
static char * s_pPhases
Definition: rwtMan.c:32
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
int Rwt_ManReadCompl(Rwt_Man_t *p)
Definition: rwtMan.c:285
void Mem_FixedStop(Mem_Fixed_t *p, int fVerbose)
Definition: mem.c:139
static abctime Abc_Clock()
Definition: abc_global.h:279
int nFuncs
Definition: rwt.h:61
Rwt_Node_t ** pTable
Definition: rwt.h:71
int fCompl
Definition: rwt.h:80
static void Vec_VecFree(Vec_Vec_t *p)
Definition: vecVec.h:347
void Rwt_ManAddTimeCuts(Rwt_Man_t *p, abctime Time)
Definition: rwtMan.c:301
Mem_Fixed_t * pMmNode
Definition: rwt.h:73
char ** Extra_Permutations(int n)
void Rwt_ManGlobalStop()
Definition: rwtMan.c:68
Vec_Ptr_t * vNodesTemp
Definition: rwt.h:87
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Definition: mem.c:100
void Rwt_ManLoadFromArray(Rwt_Man_t *p, int fVerbose)
Definition: rwtUtil.c:589
char * pPerms
Definition: rwt.h:64
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
Vec_Ptr_t * vFaninsCur
Definition: rwt.h:85
int nNodesGained
Definition: rwt.h:91
void Rwt_ManAddTimeUpdate(Rwt_Man_t *p, abctime Time)
Definition: rwtMan.c:317
abctime timeEval
Definition: rwt.h:101
int nTravIds
Definition: rwt.h:75
abctime timeTotal
Definition: rwt.h:104
void Rwt_ManPrintStats(Rwt_Man_t *p)
Definition: rwtMan.c:183
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
void * Rwt_ManReadDecs(Rwt_Man_t *p)
Definition: rwtMan.c:253
int nNodesRewritten
Definition: rwt.h:90
static int Counter
int nNodesConsidered
Definition: rwt.h:89
abctime timeTruth
Definition: rwt.h:98
Vec_Ptr_t * Rwt_ManReadLeaves(Rwt_Man_t *p)
Definition: rwtMan.c:269
char * pPhases
Definition: rwt.h:63
Vec_Vec_t * vClasses
Definition: rwt.h:72
static ABC_NAMESPACE_IMPL_START unsigned short * s_puCanons
DECLARATIONS ///.
Definition: rwtMan.c:31
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Rwt_ManPreprocess(Rwt_Man_t *p)
MACRO DEFINITIONS ///.
Definition: rwtDec.c:49
void Rwt_ManStop(Rwt_Man_t *p)
Definition: rwtMan.c:149
int nSubgraphs
Definition: rwt.h:95
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: vecPtr.h:83
Rwt_Man_t * Rwt_ManStart(int fPrecompute)
Definition: rwtMan.c:87
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: rwt.h:58
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int nScores[222]
Definition: rwt.h:92
abctime timeUpdate
Definition: rwt.h:103
abctime timeStart
Definition: rwt.h:97
static void Dec_GraphFree(Dec_Graph_t *pGraph)
Definition: dec.h:307
unsigned char * pMap
Definition: rwt.h:65
Vec_Ptr_t * vFanins
Definition: rwt.h:84
void Extra_Truth4VarNPN(unsigned short **puCanons, char **puPhases, char **puPerms, unsigned char **puMap)
abctime timeCut
Definition: rwt.h:99
int nClasses
Definition: rwt.h:78
void * pGraph
Definition: rwt.h:82
int nCutsBad
Definition: rwt.h:94
int nCutsGood
Definition: rwt.h:93
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
ABC_INT64_T abctime
Definition: abc_global.h:278
Vec_Int_t * vLevNums
Definition: rwt.h:86
Vec_Ptr_t * vForest
Definition: rwt.h:70
char * pPractical
Definition: rwt.h:67
unsigned short * puCanons
Definition: rwt.h:62
abctime timeRes
Definition: rwt.h:100
static unsigned char * s_pMap
Definition: rwtMan.c:34
char * Rwt_ManGetPractical(Rwt_Man_t *p)
Definition: rwtUtil.c:640
static void Vec_PtrFree(Vec_Ptr_t *p)
Definition: vecPtr.h:223