ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rwrExp.c
Go to the documentation of this file.
1
20
21#include "rwr.h"
22
24
25
29
30typedef struct Rwr_Man4_t_ Rwr_Man4_t;
32{
33 // internal lookups
34 int nFuncs; // the number of four-var functions
35 unsigned short * puCanons; // canonical forms
36 int * pnCounts; // the counters of functions in each class
37 int nConsidered; // the number of nodes considered
38 int nClasses; // the number of NN classes
39};
40
41typedef struct Rwr_Man5_t_ Rwr_Man5_t;
43{
44 // internal lookups
45 stmm_table * tTableNN; // the NN canonical forms
46 stmm_table * tTableNPN; // the NPN canonical forms
47};
48
49static Rwr_Man4_t * s_pManRwrExp4 = NULL;
50static Rwr_Man5_t * s_pManRwrExp5 = NULL;
51
55
68{
69 Rwr_Man4_t * p;
70 p = ABC_ALLOC( Rwr_Man4_t, 1 );
71 memset( p, 0, sizeof(Rwr_Man4_t) );
72 // canonical forms
73 p->nFuncs = (1<<16);
74 // canonical forms, phases, perms
75 Extra_Truth4VarNPN( &p->puCanons, NULL, NULL, NULL );
76 // counters
77 p->pnCounts = ABC_ALLOC( int, p->nFuncs );
78 memset( p->pnCounts, 0, sizeof(int) * p->nFuncs );
79 s_pManRwrExp4 = p;
80}
81
93void Rwt_Man4ExploreCount( unsigned uTruth )
94{
95 assert( uTruth < (1<<16) );
96 s_pManRwrExp4->pnCounts[ s_pManRwrExp4->puCanons[uTruth] ]++;
97}
98
111{
112 FILE * pFile;
113 int i, CountMax, CountWrite, nCuts, nClasses;
114 int * pDistrib;
115 int * pReprs;
116 // find the max number of occurences
117 nCuts = nClasses = 0;
118 CountMax = 0;
119 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
120 {
121 if ( CountMax < s_pManRwrExp4->pnCounts[i] )
122 CountMax = s_pManRwrExp4->pnCounts[i];
123 nCuts += s_pManRwrExp4->pnCounts[i];
124 if ( s_pManRwrExp4->pnCounts[i] > 0 )
125 nClasses++;
126 }
127 printf( "Number of cuts considered = %8d.\n", nCuts );
128 printf( "Classes occurring at least once = %8d.\n", nClasses );
129 // print the distribution of classes
130 pDistrib = ABC_ALLOC( int, CountMax + 1 );
131 pReprs = ABC_ALLOC( int, CountMax + 1 );
132 memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
133 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
134 {
135 pDistrib[ s_pManRwrExp4->pnCounts[i] ]++;
136 pReprs[ s_pManRwrExp4->pnCounts[i] ] = i;
137 }
138
139 printf( "Occurence = %6d. Num classes = %4d. \n", 0, 2288-nClasses );
140 for ( i = 1; i <= CountMax; i++ )
141 if ( pDistrib[i] )
142 {
143 printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
144 Extra_PrintBinary( stdout, (unsigned*)&(pReprs[i]), 16 );
145 printf( "\n" );
146 }
147 ABC_FREE( pDistrib );
148 ABC_FREE( pReprs );
149 // write into a file all classes above limit (5)
150 CountWrite = 0;
151 pFile = fopen( "npnclass_stats4.txt", "w" );
152 for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
153 if ( s_pManRwrExp4->pnCounts[i] > 0 )
154 {
155 Extra_PrintHex( pFile, (unsigned *)&i, 4 );
156 fprintf( pFile, " %10d\n", s_pManRwrExp4->pnCounts[i] );
157// fprintf( pFile, "%d ", i );
158 CountWrite++;
159 }
160 fclose( pFile );
161 printf( "%d classes written into file \"%s\".\n", CountWrite, "npnclass_stats4.txt" );
162}
163
164
165
166
179{
180 Rwr_Man5_t * p;
181 p = ABC_ALLOC( Rwr_Man5_t, 1 );
182 memset( p, 0, sizeof(Rwr_Man5_t) );
183 p->tTableNN = stmm_init_table( st__numcmp, st__numhash );
184 p->tTableNPN = stmm_init_table( st__numcmp, st__numhash );
185 s_pManRwrExp5 = p;
186
187//Extra_PrintHex( stdout, Extra_TruthCanonNPN( 0x0000FFFF, 5 ), 5 );
188//printf( "\n" );
189}
190
202void Rwt_Man5ExploreCount( unsigned uTruth )
203{
204 int * pCounter;
205 if ( !stmm_find_or_add( s_pManRwrExp5->tTableNN, (char *)(ABC_PTRUINT_T)uTruth, (char***)&pCounter ) )
206 *pCounter = 0;
207 (*pCounter)++;
208}
209
222{
223 FILE * pFile;
224 stmm_generator * gen;
225 int i, CountMax, nCuts, Counter;
226 int * pDistrib;
227 unsigned * pReprs;
228 unsigned uTruth, uTruthC;
229 abctime clk = Abc_Clock();
230 Vec_Int_t * vClassesNN, * vClassesNPN;
231
232 // find the max number of occurences
233 nCuts = 0;
234 CountMax = 0;
235 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
236 {
237 nCuts += Counter;
238 if ( CountMax < Counter )
239 CountMax = Counter;
240 }
241 printf( "Number of cuts considered = %8d.\n", nCuts );
242 printf( "Classes occurring at least once = %8d.\n", stmm_count(s_pManRwrExp5->tTableNN) );
243 printf( "The largest number of occurrence = %8d.\n", CountMax );
244
245 // print the distribution of classes
246 pDistrib = ABC_ALLOC( int, CountMax + 1 );
247 pReprs = ABC_ALLOC( unsigned, CountMax + 1 );
248 memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
249 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
250 {
251 assert( Counter <= CountMax );
252 pDistrib[ Counter ]++;
253 pReprs[ Counter ] = uTruth;
254 }
255
256 for ( i = 1; i <= CountMax; i++ )
257 if ( pDistrib[i] )
258 {
259 printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
260 Extra_PrintBinary( stdout, pReprs + i, 32 );
261 printf( "\n" );
262 }
263 ABC_FREE( pDistrib );
264 ABC_FREE( pReprs );
265
266
267 // put them into an array
268 vClassesNN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNN) );
269 stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, NULL )
270 Vec_IntPush( vClassesNN, (int)uTruth );
271 Vec_IntSortUnsigned( vClassesNN );
272
273 // write into a file all classes
274 pFile = fopen( "nnclass_stats5.txt", "w" );
275 Vec_IntForEachEntry( vClassesNN, uTruth, i )
276 {
277 if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)(ABC_PTRUINT_T)uTruth, (char **)&Counter ) )
278 {
279 assert( 0 );
280 }
281 Extra_PrintHex( pFile, &uTruth, 5 );
282 fprintf( pFile, " %10d\n", Counter );
283 }
284 fclose( pFile );
285 printf( "%d classes written into file \"%s\".\n", vClassesNN->nSize, "nnclass_stats5.txt" );
286
287
288clk = Abc_Clock();
289 // how many NPN classes exist?
290 Vec_IntForEachEntry( vClassesNN, uTruth, i )
291 {
292 int * pCounter;
293 uTruthC = Extra_TruthCanonNPN( uTruth, 5 );
294 if ( !stmm_find_or_add( s_pManRwrExp5->tTableNPN, (char *)(ABC_PTRUINT_T)uTruthC, (char***)&pCounter ) )
295 *pCounter = 0;
296 if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)(ABC_PTRUINT_T)uTruth, (char **)&Counter ) )
297 {
298 assert( 0 );
299 }
300 (*pCounter) += Counter;
301 }
302 printf( "The numbe of NPN classes = %d.\n", stmm_count(s_pManRwrExp5->tTableNPN) );
303ABC_PRT( "Computing NPN classes", Abc_Clock() - clk );
304
305 // put them into an array
306 vClassesNPN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNPN) );
307 stmm_foreach_item( s_pManRwrExp5->tTableNPN, gen, (char **)&uTruth, NULL )
308 Vec_IntPush( vClassesNPN, (int)uTruth );
309 Vec_IntSortUnsigned( vClassesNPN );
310
311 // write into a file all classes
312 pFile = fopen( "npnclass_stats5.txt", "w" );
313 Vec_IntForEachEntry( vClassesNPN, uTruth, i )
314 {
315 if ( !stmm_lookup( s_pManRwrExp5->tTableNPN, (char *)(ABC_PTRUINT_T)uTruth, (char **)&Counter ) )
316 {
317 assert( 0 );
318 }
319 Extra_PrintHex( pFile, &uTruth, 5 );
320 fprintf( pFile, " %10d\n", Counter );
321 }
322 fclose( pFile );
323 printf( "%d classes written into file \"%s\".\n", vClassesNPN->nSize, "npnclass_stats5.txt" );
324
325
326 // can they be uniquely characterized?
327
328}
329
333
334
336
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRT(a, t)
Definition abc_global.h:255
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
unsigned Extra_TruthCanonNPN(unsigned uTruth, int nVars)
void Extra_Truth4VarNPN(unsigned short **puCanons, char **puPhases, char **puPerms, unsigned char **puMap)
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
void Rwt_Man5ExploreStart()
Definition rwrExp.c:178
void Rwt_Man5ExplorePrint()
Definition rwrExp.c:221
void Rwt_Man4ExploreCount(unsigned uTruth)
Definition rwrExp.c:93
struct Rwr_Man5_t_ Rwr_Man5_t
Definition rwrExp.c:41
void Rwt_Man5ExploreCount(unsigned uTruth)
Definition rwrExp.c:202
typedefABC_NAMESPACE_IMPL_START struct Rwr_Man4_t_ Rwr_Man4_t
DECLARATIONS ///.
Definition rwrExp.c:30
void Rwt_Man4ExploreStart()
FUNCTION DEFINITIONS ///.
Definition rwrExp.c:67
void Rwt_Man4ExplorePrint()
Definition rwrExp.c:110
int st__numhash(const char *, int)
Definition st.c:461
int st__numcmp(const char *, const char *)
Definition st.c:473
int stmm_find_or_add(stmm_table *table, char *key, char ***slot)
Definition stmm.c:266
stmm_table * stmm_init_table(stmm_compare_func_type compare, stmm_hash_func_type hash)
Definition stmm.c:69
int stmm_lookup(stmm_table *table, char *key, char **value)
Definition stmm.c:134
#define stmm_count(table)
Definition stmm.h:76
#define stmm_foreach_item(table, gen, key, value)
Definition stmm.h:121
int nConsidered
Definition rwrExp.c:37
int nFuncs
Definition rwrExp.c:34
unsigned short * puCanons
Definition rwrExp.c:35
int * pnCounts
Definition rwrExp.c:36
int nClasses
Definition rwrExp.c:38
stmm_table * tTableNN
Definition rwrExp.c:45
stmm_table * tTableNPN
Definition rwrExp.c:46
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54