fraPart.c 7.84 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/**CFile****************************************************************

  FileName    [fraPart.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [New FRAIG package.]

  Synopsis    [Partitioning for induction.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - June 30, 2007.]

  Revision    [$Id: fraPart.c,v 1.00 2007/06/30 00:00:00 alanmi Exp $]

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

#include "fra.h"

23 24 25
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ManPartitionTest( Aig_Man_t * p, int nComLim )
{
Alan Mishchenko committed
47
//    Bar_Progress_t * pProgress;
Alan Mishchenko committed
48 49 50 51 52 53 54 55
    Vec_Vec_t * vSupps, * vSuppsIn;
    Vec_Ptr_t * vSuppsNew;
    Vec_Int_t * vSupNew, * vSup, * vSup2, * vTemp;//, * vSupIn;
    Vec_Int_t * vOverNew, * vQuantNew;
    Aig_Obj_t * pObj;
    int i, k, nCommon, CountOver, CountQuant;
    int nTotalSupp, nTotalSupp2, Entry, Largest;//, iVar;
    double Ratio, R;
56
    abctime clk;
Alan Mishchenko committed
57 58 59 60 61 62

    nTotalSupp = 0;
    nTotalSupp2 = 0;
    Ratio = 0.0;
 
    // compute supports
63
clk = Abc_Clock();
Alan Mishchenko committed
64
    vSupps = (Vec_Vec_t *)Aig_ManSupports( p );
65
ABC_PRT( "Supports", Abc_Clock() - clk );
Alan Mishchenko committed
66
    // remove last entry
67
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
68
    {
69
        vSup = Vec_VecEntryInt( vSupps, i );
Alan Mishchenko committed
70 71 72 73 74 75
        Vec_IntPop( vSup );
        // remember support
//        pObj->pNext = (Aig_Obj_t *)vSup;
    }

    // create reverse supports
76
clk = Abc_Clock();
77
    vSuppsIn = Vec_VecStart( Aig_ManCiNum(p) );
78
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
79
    {
80
        vSup = Vec_VecEntryInt( vSupps, i );
Alan Mishchenko committed
81
        Vec_IntForEachEntry( vSup, Entry, k )
Alan Mishchenko committed
82
            Vec_VecPush( vSuppsIn, Entry, (void *)(ABC_PTRUINT_T)i );
Alan Mishchenko committed
83
    }
84
ABC_PRT( "Inverse ", Abc_Clock() - clk );
Alan Mishchenko committed
85

86
clk = Abc_Clock();
Alan Mishchenko committed
87 88
    // compute extended supports
    Largest = 0;
89 90 91 92
    vSuppsNew = Vec_PtrAlloc( Aig_ManCoNum(p) );
    vOverNew  = Vec_IntAlloc( Aig_ManCoNum(p) );
    vQuantNew = Vec_IntAlloc( Aig_ManCoNum(p) );
//    pProgress = Bar_ProgressStart( stdout, Aig_ManCoNum(p) );
93
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
94
    {
Alan Mishchenko committed
95
//        Bar_ProgressUpdate( pProgress, i, NULL );
Alan Mishchenko committed
96
        // get old supports
97
        vSup = Vec_VecEntryInt( vSupps, i );
Alan Mishchenko committed
98 99 100 101 102 103
        if ( Vec_IntSize(vSup) < 2 )
            continue;
        // compute new supports
        CountOver = CountQuant = 0;
        vSupNew = Vec_IntDup( vSup );
        // go through the nodes where the first var appears
104
        Aig_ManForEachCo( p, pObj, k )
Alan Mishchenko committed
105 106 107 108 109 110 111
//        iVar = Vec_IntEntry( vSup, 0 );
//        vSupIn = Vec_VecEntry( vSuppsIn, iVar );
//        Vec_IntForEachEntry( vSupIn, Entry, k )
        {
//            pObj = Aig_ManObj( p, Entry );
            // get support of this output
//            vSup2 = (Vec_Int_t *)pObj->pNext;
112
            vSup2 = Vec_VecEntryInt( vSupps, k );
Alan Mishchenko committed
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
            // count the number of common vars
            nCommon = Vec_IntTwoCountCommon(vSup, vSup2);
            if ( nCommon < 2 )
                continue;
            if ( nCommon > nComLim )
            {
                vSupNew = Vec_IntTwoMerge( vTemp = vSupNew, vSup2 );
                Vec_IntFree( vTemp );
                CountOver++;
            }
            else
                CountQuant++;
        }
        // save the results
        Vec_PtrPush( vSuppsNew, vSupNew );
        Vec_IntPush( vOverNew, CountOver );
        Vec_IntPush( vQuantNew, CountQuant );

        if ( Largest < Vec_IntSize(vSupNew) )
            Largest = Vec_IntSize(vSupNew);

        nTotalSupp  += Vec_IntSize(vSup);
        nTotalSupp2 += Vec_IntSize(vSupNew);
        if ( Vec_IntSize(vSup) )
            R = Vec_IntSize(vSupNew) / Vec_IntSize(vSup);
        else
            R = 0;
        Ratio += R;

        if ( R < 5.0 )
            continue;

        printf( "%6d : ", i );
        printf( "S = %5d. ", Vec_IntSize(vSup) );
        printf( "SNew = %5d. ", Vec_IntSize(vSupNew) );
        printf( "R = %7.2f. ", R );
        printf( "Over = %5d. ", CountOver );
        printf( "Quant = %5d. ", CountQuant );
        printf( "\n" );
/*
        Vec_IntForEachEntry( vSupNew, Entry, k )
            printf( "%d ", Entry );
        printf( "\n" );
*/
    }
Alan Mishchenko committed
158
//    Bar_ProgressStop( pProgress );
159
ABC_PRT( "Scanning", Abc_Clock() - clk );
Alan Mishchenko committed
160 161 162

    // print cumulative statistics
    printf( "PIs = %6d. POs = %6d. Lim = %3d.   AveS = %3d. SN = %3d. R = %4.2f Max = %5d.\n",
163 164 165
        Aig_ManCiNum(p), Aig_ManCoNum(p), nComLim,
        nTotalSupp/Aig_ManCoNum(p), nTotalSupp2/Aig_ManCoNum(p),
        Ratio/Aig_ManCoNum(p), Largest );
Alan Mishchenko committed
166 167 168 169 170 171 172 173 174 175

    Vec_VecFree( vSupps );
    Vec_VecFree( vSuppsIn );
    Vec_VecFree( (Vec_Vec_t *)vSuppsNew );
    Vec_IntFree( vOverNew );
    Vec_IntFree( vQuantNew );
}



Alan Mishchenko committed
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192
/**Function*************************************************************

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fra_ManPartitionTest2( Aig_Man_t * p )
{
    Vec_Vec_t * vSupps, * vSuppsIn;
    Vec_Int_t * vSup, * vSup2, * vSup3;
    Aig_Obj_t * pObj;
    int Entry, Entry2, Entry3, Counter;
193
    int i, k, m, n;
194
    abctime clk;
Alan Mishchenko committed
195 196 197
    char * pSupp;
 
    // compute supports
198
clk = Abc_Clock();
Alan Mishchenko committed
199
    vSupps = (Vec_Vec_t *)Aig_ManSupports( p );
200
ABC_PRT( "Supports", Abc_Clock() - clk );
Alan Mishchenko committed
201
    // remove last entry
202
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
203
    {
204
        vSup = Vec_VecEntryInt( vSupps, i );
Alan Mishchenko committed
205 206 207 208 209 210
        Vec_IntPop( vSup );
        // remember support
//        pObj->pNext = (Aig_Obj_t *)vSup;
    }

    // create reverse supports
211
clk = Abc_Clock();
212
    vSuppsIn = Vec_VecStart( Aig_ManCiNum(p) );
213
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
214 215 216
    {
        if ( i == p->nAsserts )
            break;
217
        vSup = Vec_VecEntryInt( vSupps, i );
Alan Mishchenko committed
218
        Vec_IntForEachEntry( vSup, Entry, k )
Alan Mishchenko committed
219
            Vec_VecPush( vSuppsIn, Entry, (void *)(ABC_PTRUINT_T)i );
Alan Mishchenko committed
220
    }
221
ABC_PRT( "Inverse ", Abc_Clock() - clk );
Alan Mishchenko committed
222 223

    // create affective supports
224
clk = Abc_Clock();
225
    pSupp = ABC_ALLOC( char, Aig_ManCiNum(p) );
226
    Aig_ManForEachCo( p, pObj, i )
Alan Mishchenko committed
227 228 229
    {
        if ( i % 50 != 0 )
            continue;
230
        vSup = Vec_VecEntryInt( vSupps, i );
231
        memset( pSupp, 0, sizeof(char) * Aig_ManCiNum(p) );
Alan Mishchenko committed
232 233 234 235
        // go through each input of this output
        Vec_IntForEachEntry( vSup, Entry, k )
        {
            pSupp[Entry] = 1;
236
            vSup2 = Vec_VecEntryInt( vSuppsIn, Entry );
Alan Mishchenko committed
237 238 239
            // go though each assert of this input
            Vec_IntForEachEntry( vSup2, Entry2, m )
            {
240
                vSup3 = Vec_VecEntryInt( vSupps, Entry2 );
Alan Mishchenko committed
241 242 243 244 245 246 247 248 249
                // go through each input of this assert
                Vec_IntForEachEntry( vSup3, Entry3, n )
                {
                    pSupp[Entry3] = 1;
                }
            }
        }
        // count the entries
        Counter = 0;
250
        for ( m = 0; m < Aig_ManCiNum(p); m++ )
Alan Mishchenko committed
251 252 253 254
            Counter += pSupp[m];
        printf( "%d(%d) ", Vec_IntSize(vSup), Counter );
    }
    printf( "\n" );
255
ABC_PRT( "Extension ", Abc_Clock() - clk );
Alan Mishchenko committed
256

Alan Mishchenko committed
257
    ABC_FREE( pSupp );
Alan Mishchenko committed
258 259 260 261 262
    Vec_VecFree( vSupps );
    Vec_VecFree( vSuppsIn );
}


Alan Mishchenko committed
263 264 265 266 267
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


268 269
ABC_NAMESPACE_IMPL_END