abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
abcSymm.c
Go to the documentation of this file.
1 /**CFile****************************************************************
2 
3  FileName [abcSymm.c]
4 
5  SystemName [ABC: Logic synthesis and verification system.]
6 
7  PackageName [Network and node package.]
8 
9  Synopsis [Computation of two-variable symmetries.]
10 
11  Author [Alan Mishchenko]
12 
13  Affiliation [UC Berkeley]
14 
15  Date [Ver. 1.0. Started - June 20, 2005.]
16 
17  Revision [$Id: abcSymm.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include "base/abc/abc.h"
22 #include "opt/sim/sim.h"
23 #include "misc/extra/extraBdd.h"
24 
26 
27 
28 ////////////////////////////////////////////////////////////////////////
29 /// DECLARATIONS ///
30 ////////////////////////////////////////////////////////////////////////
31 
32 static void Abc_NtkSymmetriesUsingBdds( Abc_Ntk_t * pNtk, int fNaive, int fReorder, int fVerbose );
33 static void Abc_NtkSymmetriesUsingSandS( Abc_Ntk_t * pNtk, int fVerbose );
34 static void Ntk_NetworkSymmsBdd( DdManager * dd, Abc_Ntk_t * pNtk, int fNaive, int fVerbose );
35 static void Ntk_NetworkSymmsPrint( Abc_Ntk_t * pNtk, Extra_SymmInfo_t * pSymms );
36 
37 ////////////////////////////////////////////////////////////////////////
38 /// FUNCTION DEFINITIONS ///
39 ////////////////////////////////////////////////////////////////////////
40 
41 /**Function*************************************************************
42 
43  Synopsis [The top level procedure to compute symmetries.]
44 
45  Description []
46 
47  SideEffects []
48 
49  SeeAlso []
50 
51 ***********************************************************************/
52 void Abc_NtkSymmetries( Abc_Ntk_t * pNtk, int fUseBdds, int fNaive, int fReorder, int fVerbose )
53 {
54  if ( fUseBdds || fNaive )
55  Abc_NtkSymmetriesUsingBdds( pNtk, fNaive, fReorder, fVerbose );
56  else
57  Abc_NtkSymmetriesUsingSandS( pNtk, fVerbose );
58 }
59 
60 /**Function*************************************************************
61 
62  Synopsis [Symmetry computation using simulation and SAT.]
63 
64  Description []
65 
66  SideEffects []
67 
68  SeeAlso []
69 
70 ***********************************************************************/
71 void Abc_NtkSymmetriesUsingSandS( Abc_Ntk_t * pNtk, int fVerbose )
72 {
73 // extern int Sim_ComputeTwoVarSymms( Abc_Ntk_t * pNtk, int fVerbose );
74  int nSymms = Sim_ComputeTwoVarSymms( pNtk, fVerbose );
75  printf( "The total number of symmetries is %d.\n", nSymms );
76 }
77 
78 /**Function*************************************************************
79 
80  Synopsis [Symmetry computation using BDDs (both naive and smart).]
81 
82  Description []
83 
84  SideEffects []
85 
86  SeeAlso []
87 
88 ***********************************************************************/
89 void Abc_NtkSymmetriesUsingBdds( Abc_Ntk_t * pNtk, int fNaive, int fReorder, int fVerbose )
90 {
91  DdManager * dd;
92  abctime clk, clkBdd, clkSym;
93  int fGarbCollect = 1;
94 
95  // compute the global functions
96 clk = Abc_Clock();
97  dd = (DdManager *)Abc_NtkBuildGlobalBdds( pNtk, 10000000, 1, fReorder, fVerbose );
98  printf( "Shared BDD size = %d nodes.\n", Abc_NtkSizeOfGlobalBdds(pNtk) );
99  Cudd_AutodynDisable( dd );
100  if ( !fGarbCollect )
102  Cudd_zddVarsFromBddVars( dd, 2 );
103 clkBdd = Abc_Clock() - clk;
104  // create the collapsed network
105 clk = Abc_Clock();
106  Ntk_NetworkSymmsBdd( dd, pNtk, fNaive, fVerbose );
107 clkSym = Abc_Clock() - clk;
108  // undo the global functions
109  Abc_NtkFreeGlobalBdds( pNtk, 1 );
110 printf( "Statistics of BDD-based symmetry detection:\n" );
111 printf( "Algorithm = %s. Reordering = %s. Garbage collection = %s.\n",
112  fNaive? "naive" : "fast", fReorder? "yes" : "no", fGarbCollect? "yes" : "no" );
113 ABC_PRT( "Constructing BDDs", clkBdd );
114 ABC_PRT( "Computing symms ", clkSym );
115 ABC_PRT( "TOTAL ", clkBdd + clkSym );
116 }
117 
118 /**Function*************************************************************
119 
120  Synopsis [Symmetry computation using BDDs (both naive and smart).]
121 
122  Description []
123 
124  SideEffects []
125 
126  SeeAlso []
127 
128 ***********************************************************************/
129 void Ntk_NetworkSymmsBdd( DdManager * dd, Abc_Ntk_t * pNtk, int fNaive, int fVerbose )
130 {
131  Extra_SymmInfo_t * pSymms;
132  Abc_Obj_t * pNode;
133  DdNode * bFunc;
134  int nSymms = 0;
135  int nSupps = 0;
136  int i;
137 
138  // compute symmetry info for each PO
139  Abc_NtkForEachCo( pNtk, pNode, i )
140  {
141 // bFunc = pNtk->vFuncsGlob->pArray[i];
142  bFunc = (DdNode *)Abc_ObjGlobalBdd( pNode );
143  nSupps += Cudd_SupportSize( dd, bFunc );
144  if ( Cudd_IsConstant(bFunc) )
145  continue;
146  if ( fNaive )
147  pSymms = Extra_SymmPairsComputeNaive( dd, bFunc );
148  else
149  pSymms = Extra_SymmPairsCompute( dd, bFunc );
150  nSymms += pSymms->nSymms;
151  if ( fVerbose )
152  {
153  printf( "Output %6s (%d): ", Abc_ObjName(pNode), pSymms->nSymms );
154  Ntk_NetworkSymmsPrint( pNtk, pSymms );
155  }
156 //Extra_SymmPairsPrint( pSymms );
157  Extra_SymmPairsDissolve( pSymms );
158  }
159  printf( "Total number of vars in functional supports = %8d.\n", nSupps );
160  printf( "Total number of two-variable symmetries = %8d.\n", nSymms );
161 }
162 
163 /**Function*************************************************************
164 
165  Synopsis [Printing symmetry groups from the symmetry data structure.]
166 
167  Description []
168 
169  SideEffects []
170 
171  SeeAlso []
172 
173 ***********************************************************************/
175 {
176  char ** pInputNames;
177  int * pVarTaken;
178  int i, k, nVars, nSize, fStart;
179 
180  // get variable names
181  nVars = Abc_NtkCiNum(pNtk);
182  pInputNames = Abc_NtkCollectCioNames( pNtk, 0 );
183 
184  // alloc the array of marks
185  pVarTaken = ABC_ALLOC( int, nVars );
186  memset( pVarTaken, 0, sizeof(int) * nVars );
187 
188  // print the groups
189  fStart = 1;
190  nSize = pSymms->nVars;
191  for ( i = 0; i < nSize; i++ )
192  {
193  // skip the variable already considered
194  if ( pVarTaken[i] )
195  continue;
196  // find all the vars symmetric with this one
197  for ( k = 0; k < nSize; k++ )
198  {
199  if ( k == i )
200  continue;
201  if ( pSymms->pSymms[i][k] == 0 )
202  continue;
203  // vars i and k are symmetric
204  assert( pVarTaken[k] == 0 );
205  // there is a new symmetry pair
206  if ( fStart == 1 )
207  { // start a new symmetry class
208  fStart = 0;
209  printf( " { %s", pInputNames[ pSymms->pVars[i] ] );
210  // mark the var as taken
211  pVarTaken[i] = 1;
212  }
213  printf( " %s", pInputNames[ pSymms->pVars[k] ] );
214  // mark the var as taken
215  pVarTaken[k] = 1;
216  }
217  if ( fStart == 0 )
218  {
219  printf( " }" );
220  fStart = 1;
221  }
222  }
223  printf( "\n" );
224 
225  ABC_FREE( pInputNames );
226  ABC_FREE( pVarTaken );
227 }
228 
229 
230 ////////////////////////////////////////////////////////////////////////
231 /// END OF FILE ///
232 ////////////////////////////////////////////////////////////////////////
233 
234 
236 
char * memset()
char ** pSymms
Definition: extraBdd.h:219
void Abc_NtkSymmetries(Abc_Ntk_t *pNtk, int fUseBdds, int fNaive, int fReorder, int fVerbose)
FUNCTION DEFINITIONS ///.
Definition: abcSymm.c:52
Definition: cudd.h:278
Extra_SymmInfo_t * Extra_SymmPairsComputeNaive(DdManager *dd, DdNode *bFunc)
Definition: extraBddSymm.c:396
#define Cudd_IsConstant(node)
Definition: cudd.h:352
ABC_DLL char ** Abc_NtkCollectCioNames(Abc_Ntk_t *pNtk, int fCollectCos)
Definition: abcNames.c:278
static int Abc_NtkCiNum(Abc_Ntk_t *pNtk)
Definition: abc.h:287
int Sim_ComputeTwoVarSymms(Abc_Ntk_t *pNtk, int fVerbose)
DECLARATIONS ///.
Definition: simSym.c:46
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition: abc.h:519
static void Ntk_NetworkSymmsPrint(Abc_Ntk_t *pNtk, Extra_SymmInfo_t *pSymms)
Definition: abcSymm.c:174
static void Ntk_NetworkSymmsBdd(DdManager *dd, Abc_Ntk_t *pNtk, int fNaive, int fVerbose)
Definition: abcSymm.c:129
static abctime Abc_Clock()
Definition: abc_global.h:279
Extra_SymmInfo_t * Extra_SymmPairsCompute(DdManager *dd, DdNode *bFunc)
Definition: extraBddSymm.c:73
static void * Abc_ObjGlobalBdd(Abc_Obj_t *pObj)
Definition: abc.h:431
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
Definition: abcNtbdd.c:476
#define ABC_NAMESPACE_IMPL_END
Definition: abc_global.h:108
#define ABC_NAMESPACE_IMPL_START
Definition: abc_global.h:107
void Cudd_AutodynDisable(DdManager *unique)
Definition: cuddAPI.c:708
ABC_DLL int Abc_NtkSizeOfGlobalBdds(Abc_Ntk_t *pNtk)
Definition: abcNtbdd.c:492
static ABC_NAMESPACE_IMPL_START void Abc_NtkSymmetriesUsingBdds(Abc_Ntk_t *pNtk, int fNaive, int fReorder, int fVerbose)
DECLARATIONS ///.
Definition: abcSymm.c:89
void Cudd_DisableGarbageCollection(DdManager *dd)
Definition: cuddAPI.c:2563
void Extra_SymmPairsDissolve(Extra_SymmInfo_t *)
Definition: extraBddSymm.c:238
#define ABC_FREE(obj)
Definition: abc_global.h:232
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition: abcNames.c:48
#define ABC_PRT(a, t)
Definition: abc_global.h:220
int Cudd_zddVarsFromBddVars(DdManager *dd, int multiplicity)
Definition: cuddAPI.c:519
#define assert(ex)
Definition: util_old.h:213
static void Abc_NtkSymmetriesUsingSandS(Abc_Ntk_t *pNtk, int fVerbose)
Definition: abcSymm.c:71
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fVerbose)
Definition: abcNtbdd.c:251
ABC_INT64_T abctime
Definition: abc_global.h:278
int Cudd_SupportSize(DdManager *dd, DdNode *f)
Definition: cuddUtil.c:857