summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcAuto.c
blob: 02d5fd176f743cbf7c9a67f24733e2576972034f (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
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
/**CFile****************************************************************

  FileName    [abcAuto.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Computation of autosymmetries.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "abc.h"
#include "extra.h"

ABC_NAMESPACE_IMPL_START


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

static void Abc_NtkAutoPrintAll( DdManager * dd, int nInputs, DdNode * pbOutputs[], int nOutputs, char * pInputNames[], char * pOutputNames[], int fNaive );
static void Abc_NtkAutoPrintOne( DdManager * dd, int nInputs, DdNode * pbOutputs[], int Output, char * pInputNames[], char * pOutputNames[], int fNaive );
 
////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkAutoPrint( Abc_Ntk_t * pNtk, int Output, int fNaive, int fVerbose )
{
    DdManager * dd;         // the BDD manager used to hold shared BDDs
    DdNode ** pbGlobal;     // temporary storage for global BDDs
    char ** pInputNames;    // pointers to the CI names
    char ** pOutputNames;   // pointers to the CO names
    int nOutputs, nInputs, i;
    Vec_Ptr_t * vFuncsGlob;
    Abc_Obj_t * pObj;

    // compute the global BDDs
    if ( Abc_NtkBuildGlobalBdds(pNtk, 10000000, 1, 1, fVerbose) == NULL )
        return;

    // get information about the network
    nInputs  = Abc_NtkCiNum(pNtk);
    nOutputs = Abc_NtkCoNum(pNtk);
//    dd       = pNtk->pManGlob;
    dd = (DdManager *)Abc_NtkGlobalBddMan( pNtk );

    // complement the global functions
    vFuncsGlob = Vec_PtrAlloc( Abc_NtkCoNum(pNtk) );
    Abc_NtkForEachCo( pNtk, pObj, i )
        Vec_PtrPush( vFuncsGlob, Abc_ObjGlobalBdd(pObj) );
    pbGlobal = (DdNode **)Vec_PtrArray( vFuncsGlob );

    // get the network names
    pInputNames = Abc_NtkCollectCioNames( pNtk, 0 );
    pOutputNames = Abc_NtkCollectCioNames( pNtk, 1 );

    // print the size of the BDDs
    if ( fVerbose )
        printf( "Shared BDD size = %6d nodes.\n", Cudd_ReadKeys(dd) - Cudd_ReadDead(dd) );

    // allocate additional variables
    for ( i = 0; i < nInputs; i++ )
        Cudd_bddNewVar( dd );
    assert( Cudd_ReadSize(dd) == 2 * nInputs );

    // create ZDD variables in the manager
    Cudd_zddVarsFromBddVars( dd, 2 );

    // perform the analysis of the primary output functions for auto-symmetry
    if ( Output == -1 )
        Abc_NtkAutoPrintAll( dd, nInputs, pbGlobal, nOutputs, pInputNames, pOutputNames, fNaive );
    else
        Abc_NtkAutoPrintOne( dd, nInputs, pbGlobal, Output, pInputNames, pOutputNames, fNaive );

    // deref the PO functions
//    Abc_NtkFreeGlobalBdds( pNtk );
    // stop the global BDD manager
//    Extra_StopManager( pNtk->pManGlob );
//    pNtk->pManGlob = NULL;
    Abc_NtkFreeGlobalBdds( pNtk, 1 );
    ABC_FREE( pInputNames );
    ABC_FREE( pOutputNames );
    Vec_PtrFree( vFuncsGlob );
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkAutoPrintAll( DdManager * dd, int nInputs, DdNode * pbOutputs[], int nOutputs, char * pInputNames[], char * pOutputNames[], int fNaive )
{
    DdNode * bSpace1, * bSpace2, * bCanVars, * bReduced, * zEquations;
    double nMints; 
    int nSupp, SigCounter, o;

    int nAutos;
    int nAutoSyms;
    int nAutoSymsMax;
    int nAutoSymsMaxSupp;
    int nAutoSymOuts;
    int nSuppSizeMax;
    int clk;
    
    nAutoSymOuts = 0;
    nAutoSyms    = 0;
    nAutoSymsMax = 0;
    nAutoSymsMaxSupp = 0;
    nSuppSizeMax = 0;
    clk = clock();

    SigCounter = 0;
    for ( o = 0; o < nOutputs; o++ )
    {
//        bSpace1  = Extra_bddSpaceFromFunctionFast( dd, pbOutputs[o] );           Cudd_Ref( bSpace1 );
        bSpace1  = Extra_bddSpaceFromFunction( dd, pbOutputs[o], pbOutputs[o] ); Cudd_Ref( bSpace1 );
        bCanVars = Extra_bddSpaceCanonVars( dd, bSpace1 );                       Cudd_Ref( bCanVars );
        bReduced = Extra_bddSpaceReduce( dd, pbOutputs[o], bCanVars );           Cudd_Ref( bReduced );
        zEquations = Extra_bddSpaceEquations( dd, bSpace1 );                     Cudd_Ref( zEquations );

        nSupp  = Cudd_SupportSize( dd, bSpace1 );
        nMints = Cudd_CountMinterm( dd, bSpace1, nSupp );
        nAutos = Extra_Base2LogDouble(nMints);
        printf( "Output #%3d: Inputs = %2d. AutoK = %2d.\n", o, nSupp, nAutos );

        if ( nAutos > 0 )
        {
            nAutoSymOuts++;
            nAutoSyms += nAutos;
            if ( nAutoSymsMax < nAutos )
            {
                nAutoSymsMax = nAutos;
                nAutoSymsMaxSupp = nSupp;
            }
        }
        if ( nSuppSizeMax < nSupp )
            nSuppSizeMax = nSupp;


//ABC_PRB( dd, bCanVars );
//ABC_PRB( dd, bReduced );
//Cudd_PrintMinterm( dd, bReduced );
//printf( "The equations are:\n" );
//Cudd_zddPrintCover( dd, zEquations );
//printf( "\n" );
//fflush( stdout );

        bSpace2 = Extra_bddSpaceFromMatrixPos( dd, zEquations );   Cudd_Ref( bSpace2 );
//ABC_PRB( dd, bSpace1 );
//ABC_PRB( dd, bSpace2 );
        if ( bSpace1 != bSpace2 )
            printf( "Spaces are NOT EQUAL!\n" );
//        else
//            printf( "Spaces are equal.\n" );
    
        Cudd_RecursiveDeref( dd, bSpace1 );
        Cudd_RecursiveDeref( dd, bSpace2 );
        Cudd_RecursiveDeref( dd, bCanVars );
        Cudd_RecursiveDeref( dd, bReduced );
        Cudd_RecursiveDerefZdd( dd, zEquations );
    }

    printf( "The cumulative statistics for all outputs:\n" );
    printf( "Ins=%3d ",      nInputs );
    printf( "InMax=%3d   ",  nSuppSizeMax );
    printf( "Outs=%3d ",     nOutputs );
    printf( "Auto=%3d   ",   nAutoSymOuts );
    printf( "SumK=%3d ",     nAutoSyms );
    printf( "KMax=%2d ",     nAutoSymsMax );
    printf( "Supp=%3d   ",   nAutoSymsMaxSupp );
    printf( "Time=%4.2f ", (float)(clock() - clk)/(float)(CLOCKS_PER_SEC) );
    printf( "\n" );
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkAutoPrintOne( DdManager * dd, int nInputs, DdNode * pbOutputs[], int Output, char * pInputNames[], char * pOutputNames[], int fNaive )
{
    DdNode * bSpace1, * bCanVars, * bReduced, * zEquations;
    double nMints; 
    int nSupp, SigCounter;
    int nAutos;

    SigCounter = 0;
    bSpace1  = Extra_bddSpaceFromFunctionFast( dd, pbOutputs[Output] );                Cudd_Ref( bSpace1 );
//    bSpace1  = Extra_bddSpaceFromFunction( dd, pbOutputs[Output], pbOutputs[Output] ); Cudd_Ref( bSpace1 );
    bCanVars = Extra_bddSpaceCanonVars( dd, bSpace1 );                                 Cudd_Ref( bCanVars );
    bReduced = Extra_bddSpaceReduce( dd, pbOutputs[Output], bCanVars );                Cudd_Ref( bReduced );
    zEquations = Extra_bddSpaceEquations( dd, bSpace1 );                               Cudd_Ref( zEquations );

    nSupp  = Cudd_SupportSize( dd, bSpace1 );
    nMints = Cudd_CountMinterm( dd, bSpace1, nSupp );
    nAutos = Extra_Base2LogDouble(nMints);
    printf( "Output #%3d: Inputs = %2d. AutoK = %2d.\n", Output, nSupp, nAutos );

    Cudd_RecursiveDeref( dd, bSpace1 );
    Cudd_RecursiveDeref( dd, bCanVars );
    Cudd_RecursiveDeref( dd, bReduced );
    Cudd_RecursiveDerefZdd( dd, zEquations );
}

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


ABC_NAMESPACE_IMPL_END