summaryrefslogtreecommitdiffstats
path: root/src/opt/sbd/sbd.c
blob: 75fc875013c0058d4ba27724ae8cb19edb6f2f7c (plain)
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
/**CFile****************************************************************

  FileName    [sbd.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [SAT-based optimization using internal don't-cares.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 20, 2005.]

  Revision    [$Id: sbd.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]

***********************************************************************/

#include "sbdInt.h"
#include "misc/vec/vecHsh.h"

ABC_NAMESPACE_IMPL_START


////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Sbd_CountConfigVars( Vec_Int_t * vSet, int nVars, int Degree )
{
    int i, k, Entry = 0, Entry2, Count = 0, Below;
    int Prev = Vec_IntEntry( vSet, 0 );
    Vec_IntForEachEntryStart( vSet, Entry, i, 1 )
    {
        assert( Degree*Prev >= Entry );
        if ( Degree*Prev == Entry )
        {
            Prev = Entry;
            continue;
        }
        Below = nVars; 
        Vec_IntForEachEntryStart( vSet, Entry2, k, i )
            Below += Entry2;
        Count += Below * (Degree*Prev - 1);
        Prev = Entry;
    }
    Count += nVars * Degree*Prev;
    return Vec_IntSum(vSet) < nVars - 1 ? 0 : Count;
}
void Sbd_CountTopos()
{
    int nInputs  =  9;
    int nNodes   = 10;
    int Degree   =  3;
    int fVerbose =  1;
    Hsh_VecMan_t * p = Hsh_VecManStart( 10000 ); // hash table for arrays
    Vec_Int_t * vSet = Vec_IntAlloc( 100 );
    int i, k, e, Start, Stop;
    printf( "Counting topologies for %d inputs and %d degree-%d nodes.\n", nInputs, nNodes, Degree );
    Start = Hsh_VecManAdd( p, vSet );
    for ( i = 1; i <= nNodes; i++ )
    {
        Stop = Hsh_VecSize( p );
        for ( e = Start; e < Stop; e++ )
        {
            Vec_Int_t * vTemp = Hsh_VecReadEntry( p, e );
            Vec_IntClear( vSet );
            Vec_IntAppend( vSet, vTemp );
            for ( k = 0; k < Vec_IntSize(vSet); k++ )
            {
                // skip if the number of entries on this level is equal to the number of fanins on the previous level
                if ( k ? (Vec_IntEntry(vSet, k) == Degree*Vec_IntEntry(vSet, k-1)) : (Vec_IntEntry(vSet, 0) > 0) )
                    continue;
                Vec_IntAddToEntry( vSet, k, 1 );
                Hsh_VecManAdd( p, vSet );
                Vec_IntAddToEntry( vSet, k, -1 );
            }
            Vec_IntPush( vSet, 1 );
            Hsh_VecManAdd( p, vSet );
        }
        printf( "Nodes = %2d : This = %8d  All = %8d\n", i, Hsh_VecSize(p) - Stop, Hsh_VecSize(p) );
        if ( fVerbose )
        {
            for ( e = Stop; e < Hsh_VecSize(p); e++ )
            {
                Vec_Int_t * vTemp = Hsh_VecReadEntry( p, e );
                printf( "Params = %3d.  ", Sbd_CountConfigVars(vTemp, nInputs, Degree) );
                Vec_IntPrint( vTemp );
            }
            printf( "\n" );
        }
        Start = Stop;
    }
    Vec_IntFree( vSet );
    Hsh_VecManStop( p );
}


////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


ABC_NAMESPACE_IMPL_END