cswMan.c 4.56 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    [cswMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Cut sweeping.]

  Synopsis    []

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - July 11, 2007.]

  Revision    [$Id: cswMan.c,v 1.00 2007/07/11 00:00:00 alanmi Exp $]

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

#include "cswInt.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 47 48 49 50 51 52
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

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

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

  Synopsis    [Starts the cut sweeping manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Csw_Man_t * Csw_ManStart( Aig_Man_t * pMan, int nCutsMax, int nLeafMax, int fVerbose )
{
    Csw_Man_t * p;
    Aig_Obj_t * pObj;
    int i;
    assert( nCutsMax >= 2  );
    assert( nLeafMax <= 16 );
    // allocate the fraiging manager
Alan Mishchenko committed
53
    p = ABC_ALLOC( Csw_Man_t, 1 );
Alan Mishchenko committed
54 55 56 57 58 59 60 61 62
    memset( p, 0, sizeof(Csw_Man_t) );
    p->nCutsMax = nCutsMax;
    p->nLeafMax = nLeafMax;
    p->fVerbose = fVerbose;
    p->pManAig  = pMan;
    // create the new manager
    p->pManRes  = Aig_ManStartFrom( pMan );
    assert( Aig_ManPiNum(p->pManAig) == Aig_ManPiNum(p->pManRes) );
    // allocate room for cuts and equivalent nodes
Alan Mishchenko committed
63 64 65
    p->pnRefs   = ABC_ALLOC( int, Aig_ManObjNumMax(pMan) );
    p->pEquiv   = ABC_ALLOC( Aig_Obj_t *, Aig_ManObjNumMax(pMan) );
    p->pCuts    = ABC_ALLOC( Csw_Cut_t *, Aig_ManObjNumMax(pMan) );
Alan Mishchenko committed
66 67 68 69 70 71 72 73
    memset( p->pCuts, 0, sizeof(Aig_Obj_t *) * Aig_ManObjNumMax(pMan) );
    memset( p->pnRefs, 0, sizeof(int) * Aig_ManObjNumMax(pMan) );
    // allocate memory manager
    p->nTruthWords = Aig_TruthWordNum(nLeafMax);
    p->nCutSize = sizeof(Csw_Cut_t) + sizeof(int) * nLeafMax + sizeof(unsigned) * p->nTruthWords;
    p->pMemCuts = Aig_MmFixedStart( p->nCutSize * p->nCutsMax, 512 );
    // allocate hash table for cuts
    p->nTableSize = Aig_PrimeCudd( Aig_ManNodeNum(pMan) * p->nCutsMax / 2 );
Alan Mishchenko committed
74
    p->pTable = ABC_ALLOC( Csw_Cut_t *, p->nTableSize );
Alan Mishchenko committed
75 76 77 78 79 80
    memset( p->pTable, 0, sizeof(Aig_Obj_t *) * p->nTableSize );
    // set the pointers to the available fraig nodes
    Csw_ObjSetEquiv( p, Aig_ManConst1(p->pManAig), Aig_ManConst1(p->pManRes) );
    Aig_ManForEachPi( p->pManAig, pObj, i )
        Csw_ObjSetEquiv( p, pObj, Aig_ManPi(p->pManRes, i) );
    // room for temporary truth tables
Alan Mishchenko committed
81
    p->puTemp[0] = ABC_ALLOC( unsigned, 4 * p->nTruthWords );
Alan Mishchenko committed
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
    p->puTemp[1] = p->puTemp[0] + p->nTruthWords;
    p->puTemp[2] = p->puTemp[1] + p->nTruthWords;
    p->puTemp[3] = p->puTemp[2] + p->nTruthWords;
    return p;
}

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

  Synopsis    [Stops the fraiging manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Csw_ManStop( Csw_Man_t * p )
{
    if ( p->fVerbose )
    {
        int nNodesBeg = Aig_ManNodeNum(p->pManAig);
        int nNodesEnd = Aig_ManNodeNum(p->pManRes);
        printf( "Beg = %7d.  End = %7d.  (%6.2f %%)  Try = %7d.  Cuts = %8d.\n", 
            nNodesBeg, nNodesEnd, 100.0*(nNodesBeg-nNodesEnd)/nNodesBeg,
            p->nNodesTried, Csw_TableCountCuts( p ) );
        printf( "Triv0 = %6d.  Triv1 = %6d.  Triv2 = %6d.  Cut-replace = %6d.\n", 
            p->nNodesTriv0, p->nNodesTriv1, p->nNodesTriv2, p->nNodesCuts );
Alan Mishchenko committed
110 111 112 113
        ABC_PRTP( "Cuts    ", p->timeCuts,     p->timeTotal );
        ABC_PRTP( "Hashing ", p->timeHash,     p->timeTotal );
        ABC_PRTP( "Other   ", p->timeOther,    p->timeTotal );
        ABC_PRTP( "TOTAL   ", p->timeTotal,    p->timeTotal );
Alan Mishchenko committed
114
    }
Alan Mishchenko committed
115
    ABC_FREE( p->puTemp[0] );
Alan Mishchenko committed
116
    Aig_MmFixedStop( p->pMemCuts, 0 );
Alan Mishchenko committed
117 118 119 120 121
    ABC_FREE( p->pnRefs );
    ABC_FREE( p->pEquiv );
    ABC_FREE( p->pCuts );
    ABC_FREE( p->pTable );
    ABC_FREE( p );
Alan Mishchenko committed
122 123 124 125 126 127 128
}

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


129 130
ABC_NAMESPACE_IMPL_END