1 /**CFile****************************************************************
2 
3   FileName    [extraUtilEnum.c]
4 
5   SystemName  [ABC: Logic synthesis and verification system.]
6 
7   PackageName [extra]
8 
9   Synopsis    [Function enumeration.]
10 
11   Author      [Alan Mishchenko]
12 
13   Affiliation [UC Berkeley]
14 
15   Date        [Ver. 1.0. Started - June 20, 2005.]
16 
17   Revision    [$Id: extraUtilEnum.c,v 1.0 2003/02/01 00:00:00 alanmi Exp $]
18 
19 ***********************************************************************/
20 
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <assert.h>
25 #include "misc/vec/vec.h"
26 #include "misc/vec/vecHsh.h"
27 #include "bool/kit/kit.h"
28 
29 ABC_NAMESPACE_IMPL_START
30 
31 ////////////////////////////////////////////////////////////////////////
32 ///                        DECLARATIONS                              ///
33 ////////////////////////////////////////////////////////////////////////
34 
35 ////////////////////////////////////////////////////////////////////////
36 ///                     FUNCTION DEFINITIONS                         ///
37 ////////////////////////////////////////////////////////////////////////
38 
39 /**Function*************************************************************
40 
41   Synopsis    []
42 
43   Description []
44 
45   SideEffects []
46 
47   SeeAlso     []
48 
49 ***********************************************************************/
Abc_GetFirst(int * pnVars,int * pnMints,int * pnFuncs,unsigned * pVars,unsigned * pMints,unsigned * pFuncs)50 void Abc_GetFirst( int * pnVars, int * pnMints, int * pnFuncs, unsigned * pVars, unsigned * pMints, unsigned * pFuncs )
51 {
52     int nVars  = 8;
53     int nMints = 16;
54     int nFuncs = 8;
55     char * pMintStrs[16] = {
56         "1-1-1-1-",
57         "1-1--11-",
58         "1-1-1--1",
59         "1-1--1-1",
60 
61         "-11-1-1-",
62         "-11--11-",
63         "-11-1--1",
64         "-11--1-1",
65 
66         "1--11-1-",
67         "1--1-11-",
68         "1--11--1",
69         "1--1-1-1",
70 
71         "-1-11-1-",
72         "-1-1-11-",
73         "-1-11--1",
74         "-1-1-1-1"
75     };
76     char * pFuncStrs[8] = {
77         "1111101011111010",
78         "0000010100000101",
79         "1111110010101001",
80         "0000001101010110",
81         "1111111111001101",
82         "0000000000110010",
83         "1111111111111110",
84         "0000000000000001",
85     };
86     int i, k;
87     *pnVars  = nVars;
88     *pnMints = nMints;
89     *pnFuncs = nFuncs;
90     // extract mints
91     for ( i = 0; i < nMints; i++ )
92         for ( k = 0; k < nVars; k++ )
93             if ( pMintStrs[i][k] == '1' )
94                 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
95     // extract funcs
96     for ( i = 0; i < nFuncs; i++ )
97         for ( k = 0; k < nMints; k++ )
98             if ( pFuncStrs[i][k] == '1' )
99                 pFuncs[i] |= (1 << k);
100 }
101 
102 /**Function*************************************************************
103 
104   Synopsis    []
105 
106   Description []
107 
108   SideEffects []
109 
110   SeeAlso     []
111 
112 ***********************************************************************/
Abc_GetSecond(int * pnVars,int * pnMints,int * pnFuncs,unsigned * pVars,unsigned * pMints,unsigned * pFuncs)113 void Abc_GetSecond( int * pnVars, int * pnMints, int * pnFuncs, unsigned * pVars, unsigned * pMints, unsigned * pFuncs )
114 {
115     int nVars  = 10;
116     int nMints = 32;
117     int nFuncs = 7;
118     char * pMintStrs[32] = {
119         "1-1---1---",
120         "1-1----1--",
121         "1-1-----1-",
122         "1-1------1",
123 
124         "1--1--1---",
125         "1--1---1--",
126         "1--1----1-",
127         "1--1-----1",
128 
129         "1---1-1---",
130         "1---1--1--",
131         "1---1---1-",
132         "1---1----1",
133 
134         "1----11---",
135         "1----1-1--",
136         "1----1--1-",
137         "1----1---1",
138 
139 
140         "-11---1---",
141         "-11----1--",
142         "-11-----1-",
143         "-11------1",
144 
145         "-1-1--1---",
146         "-1-1---1--",
147         "-1-1----1-",
148         "-1-1-----1",
149 
150         "-1--1-1---",
151         "-1--1--1--",
152         "-1--1---1-",
153         "-1--1----1",
154 
155         "-1---11---",
156         "-1---1-1--",
157         "-1---1--1-",
158         "-1---1---1"
159     };
160     char * pFuncStrs[7] = {
161         "11111110110010001110110010000000",
162         "00000001001101110001001101111111",
163         "10000001001001000001001001001000",
164         "01001000000100101000000100100100",
165         "00100100100000010100100000010010",
166         "00010010010010000010010010000001",
167         "11111111111111111111000000000000"
168     };
169     int i, k;
170     *pnVars  = nVars;
171     *pnMints = nMints;
172     *pnFuncs = nFuncs;
173     // extract mints
174     for ( i = 0; i < nMints; i++ )
175         for ( k = 0; k < nVars; k++ )
176             if ( pMintStrs[i][k] == '1' )
177                 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
178     // extract funcs
179     for ( i = 0; i < nFuncs; i++ )
180         for ( k = 0; k < nMints; k++ )
181             if ( pFuncStrs[i][k] == '1' )
182                 pFuncs[i] |= (1 << k);
183 }
184 
185 /**Function*************************************************************
186 
187   Synopsis    []
188 
189   Description []
190 
191   SideEffects []
192 
193   SeeAlso     []
194 
195 ***********************************************************************/
Abc_GetThird(int * pnVars,int * pnMints,int * pnFuncs,unsigned * pVars,unsigned * pMints,unsigned * pFuncs)196 void Abc_GetThird( int * pnVars, int * pnMints, int * pnFuncs, unsigned * pVars, unsigned * pMints, unsigned * pFuncs )
197 {
198     int nVars  = 8;
199     int nMints = 16;
200     int nFuncs = 7;
201     char * pMintStrs[16] = {
202         "1---1---",
203         "1----1--",
204         "1-----1-",
205         "1------1",
206 
207         "-1--1---",
208         "-1---1--",
209         "-1----1-",
210         "-1-----1",
211 
212         "--1-1---",
213         "--1--1--",
214         "--1---1-",
215         "--1----1",
216 
217         "---11---",
218         "---1-1--",
219         "---1--1-",
220         "---1---1"
221     };
222     char * pFuncStrs[7] = {
223         "1111111011001000",
224         "0000000100110111",
225         "1000000100100100",
226         "0100100000010010",
227         "0010010010000001",
228         "0001001001001000",
229         "1111111111111111"
230     };
231     int i, k;
232     *pnVars  = nVars;
233     *pnMints = nMints;
234     *pnFuncs = nFuncs;
235     // extract mints
236     for ( i = 0; i < nMints; i++ )
237         for ( k = 0; k < nVars; k++ )
238             if ( pMintStrs[i][k] == '1' )
239                 pMints[i] |= (1 << k), pVars[k] |= (1 << i);
240     // extract funcs
241     for ( i = 0; i < nFuncs; i++ )
242         for ( k = 0; k < nMints; k++ )
243             if ( pFuncStrs[i][k] == '1' )
244                 pFuncs[i] |= (1 << k);
245 }
246 
247 /**Function*************************************************************
248 
249   Synopsis    []
250 
251   Description []
252 
253   SideEffects []
254 
255   SeeAlso     []
256 
257 ***********************************************************************/
Abc_EnumPrint_rec(Vec_Int_t * vGates,int i,int nVars)258 void Abc_EnumPrint_rec( Vec_Int_t * vGates, int i, int nVars )
259 {
260     int Fan0 = Vec_IntEntry(vGates, 2*i);
261     int Fan1 = Vec_IntEntry(vGates, 2*i+1);
262     char * pOper = (char*)(Fan0 < Fan1 ? "" : "+");
263     if ( Fan0 > Fan1 )
264         ABC_SWAP( int, Fan0, Fan1 );
265     if ( Fan0 < nVars )
266         printf( "%c", 'a'+Fan0 );
267     else
268     {
269         printf( "(" );
270         Abc_EnumPrint_rec( vGates, Fan0, nVars );
271         printf( ")" );
272     }
273     printf( "%s", pOper );
274     if ( Fan1 < nVars )
275         printf( "%c", 'a'+Fan1 );
276     else
277     {
278         printf( "(" );
279         Abc_EnumPrint_rec( vGates, Fan1, nVars );
280         printf( ")" );
281     }
282 }
Abc_EnumPrint(Vec_Int_t * vGates,int i,int nVars)283 void Abc_EnumPrint( Vec_Int_t * vGates, int i, int nVars )
284 {
285     assert( 2*i < Vec_IntSize(vGates) );
286     Abc_EnumPrint_rec( vGates, i, nVars );
287     printf( "\n" );
288 }
289 
290 /**Function*************************************************************
291 
292   Synopsis    []
293 
294   Description []
295 
296   SideEffects []
297 
298   SeeAlso     []
299 
300 ***********************************************************************/
Abc_DataHasBit(word * p,word i)301 static inline int  Abc_DataHasBit( word * p, word i )  { return (p[(i)>>6] & (((word)1)<<((i) & 63))) > 0; }
Abc_DataXorBit(word * p,word i)302 static inline void Abc_DataXorBit( word * p, word i )  { p[(i)>>6] ^= (((word)1)<<((i) & 63));             }
303 
304 /**Function*************************************************************
305 
306   Synopsis    []
307 
308   Description []
309 
310   SideEffects []
311 
312   SeeAlso     []
313 
314 ***********************************************************************/
Abc_EnumerateFunctions(int nDecMax)315 void Abc_EnumerateFunctions( int nDecMax )
316 {
317     int nVars;
318     int nMints;
319     int nFuncs;
320     unsigned pVars[100] = {0};
321     unsigned pMints[100] = {0};
322     unsigned pFuncs[100] = {0};
323     unsigned Truth;
324     int FuncDone[100] = {0}, nFuncDone = 0;
325     int GateCount[100] = {0};
326     int i, k, n, a, b, v;
327     abctime clk = Abc_Clock();
328     Vec_Int_t * vGates = Vec_IntAlloc( 100000 );
329     Vec_Int_t * vTruths = Vec_IntAlloc( 100000 );
330 //    Vec_Int_t * vHash = Vec_IntStartFull( 1 << 16 );
331     word * pHash;
332 
333     // extract data
334 //    Abc_GetFirst( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
335     Abc_GetSecond( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
336 //    Abc_GetThird( &nVars, &nMints, &nFuncs, pVars, pMints, pFuncs );
337 
338     // create hash table
339     assert( nMints == 16 || nMints == 32 );
340     pHash = (word *)ABC_CALLOC( char, 1 << (nMints-3) );
341 
342     // create elementary gates
343     for ( k = 0; k < nVars; k++ )
344     {
345 //        Vec_IntWriteEntry( vHash, pVars[k], k );
346         Abc_DataXorBit( pHash, pVars[k] );
347         Vec_IntPush( vTruths, pVars[k] );
348         Vec_IntPush( vGates, -1 );
349         Vec_IntPush( vGates, -1 );
350     }
351 
352     // go through different number of variables
353     GateCount[0] = 0;
354     GateCount[1] = nVars;
355     assert( Vec_IntSize(vTruths) == nVars );
356     for ( n = 0; n < nDecMax && nFuncDone < nFuncs; n++ )
357     {
358         for ( a = 0; a <= n; a++ )
359         for ( b = a; b <= n; b++ )
360         if ( a + b == n )
361         {
362             printf( "Trying %d + %d + 1 = %d\n", a, b, n+1 );
363             for ( i = GateCount[a]; i < GateCount[a+1]; i++ )
364             for ( k = GateCount[b]; k < GateCount[b+1]; k++ )
365             if ( i < k )
366             {
367                 Truth = Vec_IntEntry(vTruths, i) & Vec_IntEntry(vTruths, k);
368 //                if ( Vec_IntEntry(vHash, Truth) == -1 )
369                 if ( !Abc_DataHasBit(pHash, Truth) )
370                 {
371 //                    Vec_IntWriteEntry( vHash, Truth, Vec_IntSize(vTruths) );
372                     Abc_DataXorBit( pHash, Truth );
373                     Vec_IntPush( vTruths, Truth );
374                     Vec_IntPush( vGates, i );
375                     Vec_IntPush( vGates, k );
376 
377                     for ( v = 0; v < nFuncs; v++ )
378                     if ( !FuncDone[v] && Truth == pFuncs[v] )
379                     {
380                         printf( "Found function %d with %d gates: ", v, n+1 );
381                         Abc_EnumPrint( vGates, Vec_IntSize(vTruths)-1, nVars );
382                         FuncDone[v] = 1;
383                         nFuncDone++;
384                     }
385                 }
386                 Truth = Vec_IntEntry(vTruths, i) | Vec_IntEntry(vTruths, k);
387 //                if ( Vec_IntEntry(vHash, Truth) == -1 )
388                 if ( !Abc_DataHasBit(pHash, Truth) )
389                 {
390 //                    Vec_IntWriteEntry( vHash, Truth, Vec_IntSize(vTruths) );
391                     Abc_DataXorBit( pHash, Truth );
392                     Vec_IntPush( vTruths, Truth );
393                     Vec_IntPush( vGates, k );
394                     Vec_IntPush( vGates, i );
395 
396                     for ( v = 0; v < nFuncs; v++ )
397                     if ( !FuncDone[v] && Truth == pFuncs[v] )
398                     {
399                         printf( "Found function %d with %d gates: ", v, n+1 );
400                         Abc_EnumPrint( vGates, Vec_IntSize(vTruths)-1, nVars );
401                         FuncDone[v] = 1;
402                         nFuncDone++;
403                     }
404                 }
405             }
406         }
407         GateCount[n+2] = Vec_IntSize(vTruths);
408         printf( "Finished %d gates.  Truths = %10d.  ", n+1, Vec_IntSize(vTruths) );
409         Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
410     }
411     ABC_FREE( pHash );
412 //    Vec_IntFree( vHash );
413     Vec_IntFree( vGates );
414     Vec_IntFree( vTruths );
415 }
416 
417 
418 /**Function*************************************************************
419 
420   Synopsis    []
421 
422   Description []
423 
424   SideEffects []
425 
426   SeeAlso     []
427 
428 ***********************************************************************/
429 #define ABC_ENUM_MAX 16
430 static word s_Truths6[6] = {
431     ABC_CONST(0xAAAAAAAAAAAAAAAA),
432     ABC_CONST(0xCCCCCCCCCCCCCCCC),
433     ABC_CONST(0xF0F0F0F0F0F0F0F0),
434     ABC_CONST(0xFF00FF00FF00FF00),
435     ABC_CONST(0xFFFF0000FFFF0000),
436     ABC_CONST(0xFFFFFFFF00000000)
437 };
438 typedef struct Abc_EnuMan_t_ Abc_EnuMan_t;
439 struct Abc_EnuMan_t_
440 {
441     int              nVars;        // support size
442     int              nVarsFree;    // number of PIs used
443     int              fVerbose;     // verbose flag
444     int              fUseXor;      // using XOR gate
445     int              nNodeMax;     // the max number of nodes
446     int              nNodes;       // current number of gates
447     int              nTops;        // the number of fanoutless gates
448     int              pFans0[ABC_ENUM_MAX];   // fanins
449     int              pFans1[ABC_ENUM_MAX];   // fanins
450     int              fCompl0[ABC_ENUM_MAX];  // complements
451     int              fCompl1[ABC_ENUM_MAX];  // complements
452     int              Polar[ABC_ENUM_MAX];    // polarity
453     int              pRefs[ABC_ENUM_MAX];    // references
454     int              pLevel[ABC_ENUM_MAX];   // level
455     word             pTruths[ABC_ENUM_MAX];  // truth tables
456     word             nTries;       // attempts to build a gate
457     word             nBuilds;      // actually built gates
458     word             nFinished;    // finished structures
459 };
Abc_EnumRef(Abc_EnuMan_t * p,int i)460 static inline void Abc_EnumRef( Abc_EnuMan_t * p, int i )
461 {
462     assert( p->pRefs[i] >= 0 );
463     if ( p->pRefs[i]++ == 0 )
464         p->nTops--;
465 }
Abc_EnumDeref(Abc_EnuMan_t * p,int i)466 static inline void Abc_EnumDeref( Abc_EnuMan_t * p, int i )
467 {
468     if ( --p->pRefs[i] == 0 )
469         p->nTops++;
470     assert( p->pRefs[i] >= 0 );
471 }
Abc_EnumRefNode(Abc_EnuMan_t * p,int i)472 static inline void Abc_EnumRefNode( Abc_EnuMan_t * p, int i )
473 {
474     Abc_EnumRef( p, p->pFans0[i] );
475     Abc_EnumRef( p, p->pFans1[i] );
476     p->nTops++;
477     p->nNodes++;
478     assert( i < p->nNodes );
479 }
Abc_EnumDerefNode(Abc_EnuMan_t * p,int i)480 static inline void Abc_EnumDerefNode( Abc_EnuMan_t * p, int i )
481 {
482     assert( i < p->nNodes );
483     Abc_EnumDeref( p, p->pFans0[i] );
484     Abc_EnumDeref( p, p->pFans1[i] );
485     p->nTops--;
486     p->nNodes--;
487 }
Abc_EnumPrintOne(Abc_EnuMan_t * p)488 static inline void Abc_EnumPrintOne( Abc_EnuMan_t * p )
489 {
490     int i;
491     Kit_DsdPrintFromTruth( (unsigned *)(p->pTruths + p->nNodes - 1), p->nVars );
492     for ( i = p->nVars; i < p->nNodes; i++ )
493         if ( p->Polar[i] == 4 )
494             printf( "  %c=%c+%c", 'a'+i, 'a'+p->pFans0[i], 'a'+p->pFans1[i] );
495         else
496             printf( "  %c=%s%c%s%c", 'a'+i, p->fCompl0[i]?"!":"", 'a'+p->pFans0[i], p->fCompl1[i]?"!":"", 'a'+p->pFans1[i] );
497     printf( "\n" );
498 }
499 
500 /**Function*************************************************************
501 
502   Synopsis    []
503 
504   Description []
505 
506   SideEffects []
507 
508   SeeAlso     []
509 
510 ***********************************************************************/
Abc_EnumEquiv(word a,word b)511 static inline int Abc_EnumEquiv( word a, word b )
512 {
513     return a == b || a == ~b;
514 }
Abc_EnumerateFilter(Abc_EnuMan_t * p)515 static inline int Abc_EnumerateFilter( Abc_EnuMan_t * p )
516 {
517     int fUseFull = 1;
518     int n = p->nNodes;
519     int i = p->pFans0[n];
520     int k = p->pFans1[n], t;
521     word * pTruths = p->pTruths;
522     word uTruth = pTruths[n];
523     assert( i < k );
524     // skip constants
525     if ( Abc_EnumEquiv(uTruth, 0) )
526         return 1;
527     // skip equal ones
528     for ( t = 0; t < n; t++ )
529         if ( Abc_EnumEquiv(uTruth, pTruths[t]) )
530             return 1;
531     if ( fUseFull )
532     {
533         // skip those that can be derived by any pair
534         int a, b;
535         for ( a = 0; a <= i; a++ )
536         for ( b = a + 1; b <= k; b++ )
537         {
538             if ( a == i && b == k )
539                 continue;
540             if ( Abc_EnumEquiv(uTruth,  pTruths[a] &  pTruths[b]) )
541                 return 1;
542             if ( Abc_EnumEquiv(uTruth,  pTruths[a] & ~pTruths[b]) )
543                 return 1;
544             if ( Abc_EnumEquiv(uTruth, ~pTruths[a] &  pTruths[b]) )
545                 return 1;
546             if ( Abc_EnumEquiv(uTruth, ~pTruths[a] & ~pTruths[b]) )
547                 return 1;
548             if ( p->fUseXor && Abc_EnumEquiv(uTruth,  pTruths[a] ^ pTruths[b]) )
549                 return 1;
550         }
551     }
552     else
553     {
554         // skip those that can be derived by fanin and any other one in the cone
555         int uTruthI = p->fCompl0[n] ? ~pTruths[i] : pTruths[i];
556         int uTruthK = p->fCompl1[n] ? ~pTruths[k] : pTruths[k];
557         assert( p->fUseXor == 0 );
558         for ( t = 0; t < k; t++ )
559             if ( Abc_EnumEquiv(uTruth, pTruths[t] & uTruthI) || Abc_EnumEquiv(uTruth, ~pTruths[t] & uTruthI) )
560                 return 1;
561         for ( t = 0; t < i; t++ )
562             if ( Abc_EnumEquiv(uTruth, pTruths[t] & uTruthK) || Abc_EnumEquiv(uTruth, ~pTruths[t] & uTruthK) )
563                 return 1;
564     }
565     return 0;
566 }
Abc_EnumerateFuncs_rec(Abc_EnuMan_t * p,int fNew,int iNode1st)567 void Abc_EnumerateFuncs_rec( Abc_EnuMan_t * p, int fNew, int iNode1st ) // the first node on the last level
568 {
569     if ( p->nNodes == p->nNodeMax )
570     {
571         assert( p->nTops == 1 );
572         if ( p->fVerbose )
573             Abc_EnumPrintOne( p );
574         p->nFinished++;
575         return;
576     }
577     {
578     int i, k, c, cLim = 4 + p->fUseXor, n = p->nNodes;
579     int nRefedFans = p->nNodeMax - n + 1 - p->nTops;
580     int high0 = fNew ? iNode1st : p->pFans1[n-1];
581     int high1 = fNew ? n        : iNode1st;
582     int low0  = fNew ? 0        : p->pFans0[n-1];
583     int c0    = fNew ? 0        : p->Polar[n-1];
584     int Level = p->pLevel[high0];
585     assert( p->nTops > 0 && p->nTops <= p->nNodeMax - n + 1 );
586     // go through nodes
587     for ( k = high0; k < high1; k++ )
588     {
589         if ( nRefedFans == 0 && p->pRefs[k] > 0 )
590             continue;
591         if ( p->pRefs[k] > 0 )
592             nRefedFans--;
593         assert( nRefedFans >= 0 );
594         // try second fanin
595         for ( i = (k == high0) ? low0 : 0; i < k; i++ )
596         {
597             if ( nRefedFans == 0 && p->pRefs[i] > 0 )
598                 continue;
599             if ( Level == 0 && p->pRefs[i] == 0 && p->pRefs[k] == 0 && (i+1 != k || (i > 0 && p->pRefs[i-1] == 0)) ) // NPN
600                 continue;
601             if ( p->pLevel[k] == 0 && p->pRefs[k] == 0 && p->pRefs[i] != 0 && k > 0 && p->pRefs[k-1] == 0 ) // NPN
602                 continue;
603 //            if ( p->pLevel[i] == 0 && p->pRefs[i] == 0 && p->pRefs[k] != 0 && i > 0 && p->pRefs[i-1] == 0 ) // NPN
604 //                continue;
605             // try four polarities
606             for ( c = (k == high0 && i == low0 && !fNew) ? c0 + 1 : 0; c < cLim; c++ )
607             {
608                 if ( p->pLevel[i] == 0 && p->pRefs[i] == 0 && (c & 1) == 1 ) // NPN
609                     continue;
610                 if ( p->pLevel[k] == 0 && p->pRefs[k] == 0 && (c & 2) == 2 ) // NPN
611                     continue;
612                 p->nTries++;
613                 // create node
614                 assert( i < k );
615                 p->pFans0[n]  = i;
616                 p->pFans1[n]  = k;
617                 p->fCompl0[n] = c & 1;
618                 p->fCompl1[n] = (c >> 1) & 1;
619                 p->Polar[n]   = c;
620                 if ( c == 4 )
621                     p->pTruths[n] = p->pTruths[i] ^ p->pTruths[k];
622                 else
623                     p->pTruths[n] = ((c & 1) ? ~p->pTruths[i] : p->pTruths[i]) & ((c & 2) ? ~p->pTruths[k] : p->pTruths[k]);
624                 if ( Abc_EnumerateFilter(p) )
625                     continue;
626                 p->nBuilds++;
627                 assert( Level == Abc_MaxInt(p->pLevel[i], p->pLevel[k]) );
628                 p->pLevel[n]  = Level + 1;
629                 Abc_EnumRefNode( p, n );
630                 Abc_EnumerateFuncs_rec( p, 0, fNew ? n : iNode1st );
631                 Abc_EnumDerefNode( p, n );
632                 assert( n == p->nNodes );
633             }
634         }
635         if ( p->pRefs[k] > 0 )
636             nRefedFans++;
637     }
638     if ( fNew )
639         return;
640     // start a new level
641     Abc_EnumerateFuncs_rec( p, 1, iNode1st );
642     }
643 }
Abc_EnumerateFuncs(int nVars,int nGates,int fVerbose)644 void Abc_EnumerateFuncs( int nVars, int nGates, int fVerbose )
645 {
646     abctime clk = Abc_Clock();
647     Abc_EnuMan_t P, * p = &P;
648     int i;
649     if ( nVars > nGates + 1 )
650     {
651         printf( "The gate count %d is not enough to have functions with %d inputs.\n", nGates, nVars );
652         return;
653     }
654     assert( nVars >= 2 && nVars <= 6 );
655     assert( nGates > 0 && nVars + nGates < ABC_ENUM_MAX );
656     memset( p, 0, sizeof(Abc_EnuMan_t) );
657     p->fVerbose  = fVerbose;
658     p->fUseXor   = 0;
659     p->nVars     = nVars;
660     p->nNodeMax  = nVars + nGates;
661     p->nNodes    = nVars;
662     p->nTops     = nVars;
663     for ( i = 0; i < nVars; i++ )
664         p->pTruths[i] = s_Truths6[i];
665     Abc_EnumerateFuncs_rec( p, 1, 0 );
666     assert( p->nNodes == nVars );
667     assert( p->nTops == nVars );
668     // report statistics
669     printf( "Vars = %d.  Gates = %d.  Tries = %u. Builds = %u.  Finished = %d. ",
670         nVars, nGates, (unsigned)p->nTries, (unsigned)p->nBuilds, (unsigned)p->nFinished );
671     Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
672 }
673 
674 ////////////////////////////////////////////////////////////////////////
675 ///                       END OF FILE                                ///
676 ////////////////////////////////////////////////////////////////////////
677 
678 
679 ABC_NAMESPACE_IMPL_END
680 
681