1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
|
/**CFile****************************************************************
FileName [rwrExp.c]
SystemName [ABC: Logic synthesis and verification system.]
PackageName [DAG-aware AIG rewriting package.]
Synopsis [Computation of practically used NN-classes of 4-input cuts.]
Author [Alan Mishchenko]
Affiliation [UC Berkeley]
Date [Ver. 1.0. Started - June 20, 2005.]
Revision [$Id: rwrExp.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
***********************************************************************/
#include "rwr.h"
////////////////////////////////////////////////////////////////////////
/// DECLARATIONS ///
////////////////////////////////////////////////////////////////////////
typedef struct Rwr_Man4_t_ Rwr_Man4_t;
struct Rwr_Man4_t_
{
// internal lookups
int nFuncs; // the number of four-var functions
unsigned short * puCanons; // canonical forms
int * pnCounts; // the counters of functions in each class
int nConsidered; // the number of nodes considered
int nClasses; // the number of NN classes
};
typedef struct Rwr_Man5_t_ Rwr_Man5_t;
struct Rwr_Man5_t_
{
// internal lookups
stmm_table * tTableNN; // the NN canonical forms
stmm_table * tTableNPN; // the NPN canonical forms
};
static Rwr_Man4_t * s_pManRwrExp4 = NULL;
static Rwr_Man5_t * s_pManRwrExp5 = NULL;
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
////////////////////////////////////////////////////////////////////////
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man4ExploreStart()
{
Rwr_Man4_t * p;
p = ALLOC( Rwr_Man4_t, 1 );
memset( p, 0, sizeof(Rwr_Man4_t) );
// canonical forms
p->nFuncs = (1<<16);
// canonical forms, phases, perms
Extra_Truth4VarNPN( &p->puCanons, NULL, NULL, NULL );
// counters
p->pnCounts = ALLOC( int, p->nFuncs );
memset( p->pnCounts, 0, sizeof(int) * p->nFuncs );
s_pManRwrExp4 = p;
}
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man4ExploreCount( unsigned uTruth )
{
assert( uTruth < (1<<16) );
s_pManRwrExp4->pnCounts[ s_pManRwrExp4->puCanons[uTruth] ]++;
}
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man4ExplorePrint()
{
FILE * pFile;
int i, CountMax, CountWrite, nCuts, nClasses;
int * pDistrib;
int * pReprs;
// find the max number of occurences
nCuts = nClasses = 0;
CountMax = 0;
for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
{
if ( CountMax < s_pManRwrExp4->pnCounts[i] )
CountMax = s_pManRwrExp4->pnCounts[i];
nCuts += s_pManRwrExp4->pnCounts[i];
if ( s_pManRwrExp4->pnCounts[i] > 0 )
nClasses++;
}
printf( "Number of cuts considered = %8d.\n", nCuts );
printf( "Classes occurring at least once = %8d.\n", nClasses );
// print the distribution of classes
pDistrib = ALLOC( int, CountMax + 1 );
pReprs = ALLOC( int, CountMax + 1 );
memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
{
pDistrib[ s_pManRwrExp4->pnCounts[i] ]++;
pReprs[ s_pManRwrExp4->pnCounts[i] ] = i;
}
printf( "Occurence = %6d. Num classes = %4d. \n", 0, 2288-nClasses );
for ( i = 1; i <= CountMax; i++ )
if ( pDistrib[i] )
{
printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
Extra_PrintBinary( stdout, (unsigned*)&(pReprs[i]), 16 );
printf( "\n" );
}
free( pDistrib );
free( pReprs );
// write into a file all classes above limit (5)
CountWrite = 0;
pFile = fopen( "npnclass_stats4.txt", "w" );
for ( i = 0; i < s_pManRwrExp4->nFuncs; i++ )
if ( s_pManRwrExp4->pnCounts[i] > 0 )
{
Extra_PrintHex( pFile, i, 4 );
fprintf( pFile, " %10d\n", s_pManRwrExp4->pnCounts[i] );
// fprintf( pFile, "%d ", i );
CountWrite++;
}
fclose( pFile );
printf( "%d classes written into file \"%s\".\n", CountWrite, "npnclass_stats4.txt" );
}
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man5ExploreStart()
{
Rwr_Man5_t * p;
p = ALLOC( Rwr_Man5_t, 1 );
memset( p, 0, sizeof(Rwr_Man5_t) );
p->tTableNN = stmm_init_table( st_numcmp, st_numhash );
p->tTableNPN = stmm_init_table( st_numcmp, st_numhash );
s_pManRwrExp5 = p;
//Extra_PrintHex( stdout, Extra_TruthCanonNPN( 0x0000FFFF, 5 ), 5 );
//printf( "\n" );
}
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man5ExploreCount( unsigned uTruth )
{
int * pCounter;
if ( !stmm_find_or_add( s_pManRwrExp5->tTableNN, (char *)uTruth, (char***)&pCounter ) )
*pCounter = 0;
(*pCounter)++;
}
/**Function*************************************************************
Synopsis [Collects stats about 4-var functions appearing in netlists.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Rwt_Man5ExplorePrint()
{
FILE * pFile;
stmm_generator * gen;
int i, CountMax, nCuts, Counter;
int * pDistrib;
unsigned * pReprs;
unsigned uTruth, uTruthC;
int clk = clock();
Vec_Int_t * vClassesNN, * vClassesNPN;
// find the max number of occurences
nCuts = 0;
CountMax = 0;
stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
{
nCuts += Counter;
if ( CountMax < Counter )
CountMax = Counter;
}
printf( "Number of cuts considered = %8d.\n", nCuts );
printf( "Classes occurring at least once = %8d.\n", stmm_count(s_pManRwrExp5->tTableNN) );
printf( "The largest number of occurence = %8d.\n", CountMax );
// print the distribution of classes
pDistrib = ALLOC( int, CountMax + 1 );
pReprs = ALLOC( unsigned, CountMax + 1 );
memset( pDistrib, 0, sizeof(int)*(CountMax + 1) );
stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, (char **)&Counter )
{
assert( Counter <= CountMax );
pDistrib[ Counter ]++;
pReprs[ Counter ] = uTruth;
}
for ( i = 1; i <= CountMax; i++ )
if ( pDistrib[i] )
{
printf( "Occurence = %6d. Num classes = %4d. Repr = ", i, pDistrib[i] );
Extra_PrintBinary( stdout, pReprs + i, 32 );
printf( "\n" );
}
free( pDistrib );
free( pReprs );
// put them into an array
vClassesNN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNN) );
stmm_foreach_item( s_pManRwrExp5->tTableNN, gen, (char **)&uTruth, NULL )
Vec_IntPush( vClassesNN, (int)uTruth );
Vec_IntSortUnsigned( vClassesNN );
// write into a file all classes
pFile = fopen( "nnclass_stats5.txt", "w" );
Vec_IntForEachEntry( vClassesNN, uTruth, i )
{
if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)uTruth, (char **)&Counter ) )
{
assert( 0 );
}
Extra_PrintHex( pFile, uTruth, 5 );
fprintf( pFile, " %10d\n", Counter );
}
fclose( pFile );
printf( "%d classes written into file \"%s\".\n", vClassesNN->nSize, "nnclass_stats5.txt" );
clk = clock();
// how many NPN classes exist?
Vec_IntForEachEntry( vClassesNN, uTruth, i )
{
int * pCounter;
uTruthC = Extra_TruthCanonNPN( uTruth, 5 );
if ( !stmm_find_or_add( s_pManRwrExp5->tTableNPN, (char *)uTruthC, (char***)&pCounter ) )
*pCounter = 0;
if ( !stmm_lookup( s_pManRwrExp5->tTableNN, (char *)uTruth, (char **)&Counter ) )
{
assert( 0 );
}
(*pCounter) += Counter;
}
printf( "The numbe of NPN classes = %d.\n", stmm_count(s_pManRwrExp5->tTableNPN) );
PRT( "Computing NPN classes", clock() - clk );
// put them into an array
vClassesNPN = Vec_IntAlloc( stmm_count(s_pManRwrExp5->tTableNPN) );
stmm_foreach_item( s_pManRwrExp5->tTableNPN, gen, (char **)&uTruth, NULL )
Vec_IntPush( vClassesNPN, (int)uTruth );
Vec_IntSortUnsigned( vClassesNPN );
// write into a file all classes
pFile = fopen( "npnclass_stats5.txt", "w" );
Vec_IntForEachEntry( vClassesNPN, uTruth, i )
{
if ( !stmm_lookup( s_pManRwrExp5->tTableNPN, (char *)uTruth, (char **)&Counter ) )
{
assert( 0 );
}
Extra_PrintHex( pFile, uTruth, 5 );
fprintf( pFile, " %10d\n", Counter );
}
fclose( pFile );
printf( "%d classes written into file \"%s\".\n", vClassesNPN->nSize, "npnclass_stats5.txt" );
// can they be uniquely characterized?
}
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
|