rwrMan.c 8.56 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8
/**CFile****************************************************************

  FileName    [rwrMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [DAG-aware AIG rewriting package.]

Alan Mishchenko committed
9
  Synopsis    [Rewriting manager.]
Alan Mishchenko committed
10 11 12 13 14 15 16 17 18 19 20

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21
#include "extra.h"
Alan Mishchenko committed
22
#include "rwr.h"
Alan Mishchenko committed
23 24
#include "main.h"
#include "dec.h"
Alan Mishchenko committed
25

26 27 28
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
29 30 31 32 33
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
34
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
35 36 37 38
////////////////////////////////////////////////////////////////////////

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

Alan Mishchenko committed
39
  Synopsis    [Starts rewriting manager.]
Alan Mishchenko committed
40 41 42 43 44 45 46 47

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
48
Rwr_Man_t * Rwr_ManStart( int  fPrecompute )
Alan Mishchenko committed
49
{
Alan Mishchenko committed
50
    Dec_Man_t * pManDec;
Alan Mishchenko committed
51
    Rwr_Man_t * p;
Alan Mishchenko committed
52
    int clk = clock();
Alan Mishchenko committed
53
clk = clock();
Alan Mishchenko committed
54
    p = ABC_ALLOC( Rwr_Man_t, 1 );
Alan Mishchenko committed
55
    memset( p, 0, sizeof(Rwr_Man_t) );
Alan Mishchenko committed
56
    p->nFuncs = (1<<16);
57
    pManDec   = (Dec_Man_t *)Abc_FrameReadManDec();
Alan Mishchenko committed
58 59 60 61
    p->puCanons = pManDec->puCanons; 
    p->pPhases  = pManDec->pPhases; 
    p->pPerms   = pManDec->pPerms; 
    p->pMap     = pManDec->pMap; 
Alan Mishchenko committed
62 63 64
    // initialize practical NPN classes
    p->pPractical  = Rwr_ManGetPractical( p );
    // create the table
Alan Mishchenko committed
65
    p->pTable = ABC_ALLOC( Rwr_Node_t *, p->nFuncs );
Alan Mishchenko committed
66 67 68 69 70 71 72 73 74
    memset( p->pTable, 0, sizeof(Rwr_Node_t *) * p->nFuncs );
    // create the elementary nodes
    p->pMmNode  = Extra_MmFixedStart( sizeof(Rwr_Node_t) );
    p->vForest  = Vec_PtrAlloc( 100 );
    Rwr_ManAddVar( p, 0x0000, fPrecompute ); // constant 0
    Rwr_ManAddVar( p, 0xAAAA, fPrecompute ); // var A
    Rwr_ManAddVar( p, 0xCCCC, fPrecompute ); // var B
    Rwr_ManAddVar( p, 0xF0F0, fPrecompute ); // var C
    Rwr_ManAddVar( p, 0xFF00, fPrecompute ); // var D
Alan Mishchenko committed
75
    p->nClasses = 5;
Alan Mishchenko committed
76
    // other stuff
Alan Mishchenko committed
77 78 79 80 81
    p->nTravIds   = 1;
    p->pPerms4    = Extra_Permutations( 4 );
    p->vLevNums   = Vec_IntAlloc( 50 );
    p->vFanins    = Vec_PtrAlloc( 50 );
    p->vFaninsCur = Vec_PtrAlloc( 50 );
Alan Mishchenko committed
82
    p->vNodesTemp = Vec_PtrAlloc( 50 );
Alan Mishchenko committed
83 84
    if ( fPrecompute )
    {   // precompute subgraphs
Alan Mishchenko committed
85
        Rwr_ManPrecompute( p );
Alan Mishchenko committed
86
//        Rwr_ManPrint( p );
Alan Mishchenko committed
87
        Rwr_ManWriteToArray( p );
Alan Mishchenko committed
88 89
    }
    else
Alan Mishchenko committed
90
    {   // load saved subgraphs
Alan Mishchenko committed
91
        Rwr_ManLoadFromArray( p, 0 );
Alan Mishchenko committed
92
//        Rwr_ManPrint( p );
Alan Mishchenko committed
93
        Rwr_ManPreprocess( p );
Alan Mishchenko committed
94
    }
Alan Mishchenko committed
95
p->timeStart = clock() - clk;
Alan Mishchenko committed
96 97 98 99 100
    return p;
}

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

Alan Mishchenko committed
101
  Synopsis    [Stops rewriting manager.]
Alan Mishchenko committed
102 103 104 105 106 107 108 109

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
110
void Rwr_ManStop( Rwr_Man_t * p )
Alan Mishchenko committed
111
{
Alan Mishchenko committed
112 113 114 115
    if ( p->vClasses )
    {
        Rwr_Node_t * pNode;
        int i, k;
116
        Vec_VecForEachEntry( Rwr_Node_t *, p->vClasses, pNode, i, k )
Alan Mishchenko committed
117
            Dec_GraphFree( (Dec_Graph_t *)pNode->pNext );
Alan Mishchenko committed
118 119
    }
    if ( p->vClasses )  Vec_VecFree( p->vClasses );
Alan Mishchenko committed
120
    Vec_PtrFree( p->vNodesTemp );
Alan Mishchenko committed
121
    Vec_PtrFree( p->vForest );
Alan Mishchenko committed
122 123
    Vec_IntFree( p->vLevNums );
    Vec_PtrFree( p->vFanins );
Alan Mishchenko committed
124
    Vec_PtrFree( p->vFaninsCur );
Alan Mishchenko committed
125
    Extra_MmFixedStop( p->pMmNode );
Alan Mishchenko committed
126 127 128 129 130
    ABC_FREE( p->pMapInv );
    ABC_FREE( p->pTable );
    ABC_FREE( p->pPractical );
    ABC_FREE( p->pPerms4 );
    ABC_FREE( p );
Alan Mishchenko committed
131 132 133 134
}

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

Alan Mishchenko committed
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Rwr_ManPrintStats( Rwr_Man_t * p )
{
    int i, Counter = 0;
    for ( i = 0; i < 222; i++ )
        Counter += (p->nScores[i] > 0);

    printf( "Rewriting statistics:\n" );
    printf( "Total cuts tries  = %8d.\n", p->nCutsGood );
    printf( "Bad cuts found    = %8d.\n", p->nCutsBad );
    printf( "Total subgraphs   = %8d.\n", p->nSubgraphs );
    printf( "Used NPN classes  = %8d.\n", Counter );
    printf( "Nodes considered  = %8d.\n", p->nNodesConsidered );
    printf( "Nodes rewritten   = %8d.\n", p->nNodesRewritten );
Alan Mishchenko committed
157
    printf( "Gain              = %8d. (%6.2f %%).\n", p->nNodesBeg-p->nNodesEnd, 100.0*(p->nNodesBeg-p->nNodesEnd)/p->nNodesBeg );
Alan Mishchenko committed
158 159 160 161 162 163 164
    ABC_PRT( "Start       ", p->timeStart );
    ABC_PRT( "Cuts        ", p->timeCut );
    ABC_PRT( "Resynthesis ", p->timeRes );
    ABC_PRT( "    Mffc    ", p->timeMffc );
    ABC_PRT( "    Eval    ", p->timeEval );
    ABC_PRT( "Update      ", p->timeUpdate );
    ABC_PRT( "TOTAL       ", p->timeTotal );
Alan Mishchenko committed
165

Alan Mishchenko committed
166
/*
Alan Mishchenko committed
167
    printf( "The scores are:\n" );
Alan Mishchenko committed
168 169
    for ( i = 0; i < 222; i++ )
        if ( p->nScores[i] > 0 )
Alan Mishchenko committed
170 171 172 173 174
        {
            extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
            printf( "%3d = %8d  canon = %5d  ", i, p->nScores[i], p->pMapInv[i] );
            Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[i] | ((unsigned)p->pMapInv[i] << 16) );
        }
Alan Mishchenko committed
175
*/
Alan Mishchenko committed
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
    printf( "\n" );

}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Rwr_ManPrintStatsFile( Rwr_Man_t * p )
{
    FILE * pTable;
    pTable = fopen( "stats.txt", "a+" );
    fprintf( pTable, "%d ", p->nCutsGood );
    fprintf( pTable, "%d ", p->nSubgraphs );
    fprintf( pTable, "%d ", p->nNodesRewritten );
    fprintf( pTable, "%d", p->nNodesGained );
    fprintf( pTable, "\n" );
    fclose( pTable );
Alan Mishchenko committed
201 202 203 204 205 206 207 208 209 210 211 212 213
}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
214
void * Rwr_ManReadDecs( Rwr_Man_t * p )
Alan Mishchenko committed
215
{
Alan Mishchenko committed
216
    return p->pGraph;
Alan Mishchenko committed
217 218
}

Alan Mishchenko committed
219 220 221 222 223 224 225 226 227 228 229
/**Function*************************************************************

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245
Vec_Ptr_t * Rwr_ManReadLeaves( Rwr_Man_t * p )
{
    return p->vFanins;
}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
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
int Rwr_ManReadCompl( Rwr_Man_t * p )
{
    return p->fCompl;
}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Rwr_ManAddTimeCuts( Rwr_Man_t * p, int Time )
{
    p->timeCut += Time;
}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293
void Rwr_ManAddTimeUpdate( Rwr_Man_t * p, int Time )
{
    p->timeUpdate += Time;
}

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

  Synopsis    [Stops the resynthesis manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
294 295 296 297 298
void Rwr_ManAddTimeTotal( Rwr_Man_t * p, int Time )
{
    p->timeTotal += Time;
}

Alan Mishchenko committed
299

Alan Mishchenko committed
300 301
/**Function*************************************************************

Alan Mishchenko committed
302
  Synopsis    [Precomputes AIG subgraphs.]
Alan Mishchenko committed
303 304 305 306 307 308 309 310

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
311
void Rwr_Precompute()
Alan Mishchenko committed
312
{
Alan Mishchenko committed
313 314 315
    Rwr_Man_t * p;
    p = Rwr_ManStart( 1 );
    Rwr_ManStop( p );
Alan Mishchenko committed
316 317 318 319 320 321 322
}

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


323 324
ABC_NAMESPACE_IMPL_END