simMan.c 9.44 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
/**CFile****************************************************************

  FileName    [simMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Simulation manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21
#include "base/abc/abc.h"
Alan Mishchenko committed
22 23
#include "sim.h"

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30 31
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
32
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
33 34 35 36
////////////////////////////////////////////////////////////////////////

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

Alan Mishchenko committed
37
  Synopsis    [Starts the simulation manager.]
Alan Mishchenko committed
38 39 40 41 42 43 44 45

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
46
Sym_Man_t * Sym_ManStart( Abc_Ntk_t * pNtk, int fVerbose )
Alan Mishchenko committed
47 48
{
    Sym_Man_t * p;
Alan Mishchenko committed
49
    int i, v; 
Alan Mishchenko committed
50
    // start the manager
Alan Mishchenko committed
51
    p = ABC_ALLOC( Sym_Man_t, 1 );
Alan Mishchenko committed
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
    memset( p, 0, sizeof(Sym_Man_t) );
    p->pNtk = pNtk;
    p->vNodes     = Abc_NtkDfs( pNtk, 0 );
    p->nInputs    = Abc_NtkCiNum(p->pNtk);
    p->nOutputs   = Abc_NtkCoNum(p->pNtk);
    // internal simulation information
    p->nSimWords  = SIM_NUM_WORDS(p->nInputs);
    p->vSim       = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), p->nSimWords, 0 );
    // symmetry info for each output
    p->vMatrSymms    = Vec_PtrStart( p->nOutputs );
    p->vMatrNonSymms = Vec_PtrStart( p->nOutputs );
    p->vPairsTotal   = Vec_IntStart( p->nOutputs );
    p->vPairsSym     = Vec_IntStart( p->nOutputs );
    p->vPairsNonSym  = Vec_IntStart( p->nOutputs );
    for ( i = 0; i < p->nOutputs; i++ )
    {
        p->vMatrSymms->pArray[i]    = Extra_BitMatrixStart( p->nInputs );
        p->vMatrNonSymms->pArray[i] = Extra_BitMatrixStart( p->nInputs );
    }
    // temporary patterns
Alan Mishchenko committed
72 73 74
    p->uPatRand = ABC_ALLOC( unsigned, p->nSimWords );
    p->uPatCol  = ABC_ALLOC( unsigned, p->nSimWords );
    p->uPatRow  = ABC_ALLOC( unsigned, p->nSimWords );
Alan Mishchenko committed
75 76
    p->vVarsU   = Vec_IntStart( 100 );
    p->vVarsV   = Vec_IntStart( 100 );
Alan Mishchenko committed
77
    // compute supports
Alan Mishchenko committed
78 79 80 81 82
    p->vSuppFun  = Sim_ComputeFunSupp( pNtk, fVerbose );
    p->vSupports = Vec_VecStart( p->nOutputs );
    for ( i = 0; i < p->nOutputs; i++ )
        for ( v = 0; v < p->nInputs; v++ )
            if ( Sim_SuppFunHasVar( p->vSuppFun, i, v ) )
Alan Mishchenko committed
83
                Vec_VecPush( p->vSupports, i, (void *)(ABC_PTRUINT_T)v );
Alan Mishchenko committed
84 85 86 87 88
    return p;
}

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

Alan Mishchenko committed
89
  Synopsis    [Stops the simulation manager.]
Alan Mishchenko committed
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sym_ManStop( Sym_Man_t * p )
{
    int i;
    Sym_ManPrintStats( p );
    if ( p->vSuppFun )     Sim_UtilInfoFree( p->vSuppFun );   
    if ( p->vSim )         Sim_UtilInfoFree( p->vSim );   
    if ( p->vNodes )       Vec_PtrFree( p->vNodes );
Alan Mishchenko committed
105
    if ( p->vSupports )    Vec_VecFree( p->vSupports );
Alan Mishchenko committed
106 107
    for ( i = 0; i < p->nOutputs; i++ )
    {
108 109
        Extra_BitMatrixStop( (Extra_BitMat_t *)p->vMatrSymms->pArray[i] );
        Extra_BitMatrixStop( (Extra_BitMat_t *)p->vMatrNonSymms->pArray[i] );
Alan Mishchenko committed
110
    }
Alan Mishchenko committed
111 112
    Vec_IntFree( p->vVarsU );
    Vec_IntFree( p->vVarsV );
Alan Mishchenko committed
113 114 115 116 117
    Vec_PtrFree( p->vMatrSymms );
    Vec_PtrFree( p->vMatrNonSymms );
    Vec_IntFree( p->vPairsTotal );
    Vec_IntFree( p->vPairsSym );
    Vec_IntFree( p->vPairsNonSym );
Alan Mishchenko committed
118 119 120 121
    ABC_FREE( p->uPatRand );
    ABC_FREE( p->uPatCol );
    ABC_FREE( p->uPatRow );
    ABC_FREE( p );
Alan Mishchenko committed
122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
}

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

  Synopsis    [Prints the manager statisticis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sym_ManPrintStats( Sym_Man_t * p )
{
Alan Mishchenko committed
137 138 139 140 141 142 143 144
//    printf( "Inputs = %5d. Outputs = %5d. Sim words = %5d.\n", 
//        Abc_NtkCiNum(p->pNtk), Abc_NtkCoNum(p->pNtk), p->nSimWords );
    printf( "Total symm         = %8d.\n", p->nPairsSymm );
    printf( "Structural symm    = %8d.\n", p->nPairsSymmStr );
    printf( "Total non-sym      = %8d.\n", p->nPairsNonSymm );
    printf( "Total var pairs    = %8d.\n", p->nPairsTotal );
    printf( "Sat runs SAT       = %8d.\n", p->nSatRunsSat );
    printf( "Sat runs UNSAT     = %8d.\n", p->nSatRunsUnsat );
Alan Mishchenko committed
145 146 147 148 149 150 151
    ABC_PRT( "Structural  ", p->timeStruct );
    ABC_PRT( "Simulation  ", p->timeSim );
    ABC_PRT( "Matrix      ", p->timeMatr );
    ABC_PRT( "Counting    ", p->timeCount );
    ABC_PRT( "Fraiging    ", p->timeFraig );
    ABC_PRT( "SAT         ", p->timeSat );
    ABC_PRT( "TOTAL       ", p->timeTotal );
Alan Mishchenko committed
152 153 154 155 156
}


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

Alan Mishchenko committed
157
  Synopsis    [Starts the simulation manager.]
Alan Mishchenko committed
158 159 160 161 162 163 164 165

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
166
Sim_Man_t * Sim_ManStart( Abc_Ntk_t * pNtk, int fLightweight )
Alan Mishchenko committed
167 168 169
{
    Sim_Man_t * p;
    // start the manager
Alan Mishchenko committed
170
    p = ABC_ALLOC( Sim_Man_t, 1 );
Alan Mishchenko committed
171 172
    memset( p, 0, sizeof(Sim_Man_t) );
    p->pNtk = pNtk;
Alan Mishchenko committed
173 174
    p->nInputs    = Abc_NtkCiNum(p->pNtk);
    p->nOutputs   = Abc_NtkCoNum(p->pNtk);
Alan Mishchenko committed
175 176 177
    // internal simulation information
    p->nSimBits   = 2048;
    p->nSimWords  = SIM_NUM_WORDS(p->nSimBits);
Alan Mishchenko committed
178
    p->vSim0      = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), p->nSimWords, 0 );
Alan Mishchenko committed
179 180 181 182 183 184 185 186 187 188 189 190 191 192 193
    p->fLightweight = fLightweight;
    if (!p->fLightweight) {
        p->vSim1      = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), p->nSimWords, 0 );
        // support information
        p->nSuppBits  = Abc_NtkCiNum(pNtk);
        p->nSuppWords = SIM_NUM_WORDS(p->nSuppBits);
        p->vSuppStr   = Sim_ComputeStrSupp( pNtk );
        p->vSuppFun   = Sim_UtilInfoAlloc( Abc_NtkCoNum(p->pNtk),  p->nSuppWords, 1 );
        // other data
        p->pMmPat     = Extra_MmFixedStart( sizeof(Sim_Pat_t) + p->nSuppWords * sizeof(unsigned) ); 
        p->vFifo      = Vec_PtrAlloc( 100 );
        p->vDiffs     = Vec_IntAlloc( 100 );
        // allocate support targets (array of unresolved outputs for each input)
        p->vSuppTargs = Vec_VecStart( p->nInputs );
    }
Alan Mishchenko committed
194 195 196 197 198
    return p;
}

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

Alan Mishchenko committed
199
  Synopsis    [Stops the simulation manager.]
Alan Mishchenko committed
200 201 202 203 204 205 206 207 208 209 210 211 212 213

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sim_ManStop( Sim_Man_t * p )
{
    Sim_ManPrintStats( p );
    if ( p->vSim0 )        Sim_UtilInfoFree( p->vSim0 );       
    if ( p->vSim1 )        Sim_UtilInfoFree( p->vSim1 );       
    if ( p->vSuppStr )     Sim_UtilInfoFree( p->vSuppStr );    
Alan Mishchenko committed
214 215
//    if ( p->vSuppFun )     Sim_UtilInfoFree( p->vSuppFun );    
    if ( p->vSuppTargs )   Vec_VecFree( p->vSuppTargs );
Alan Mishchenko committed
216
    if ( p->pMmPat )       Extra_MmFixedStop( p->pMmPat );
Alan Mishchenko committed
217 218
    if ( p->vFifo )        Vec_PtrFree( p->vFifo );
    if ( p->vDiffs )       Vec_IntFree( p->vDiffs );
Alan Mishchenko committed
219
    ABC_FREE( p );
Alan Mishchenko committed
220 221 222 223
}

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

Alan Mishchenko committed
224
  Synopsis    [Prints the manager statisticis.]
Alan Mishchenko committed
225 226 227 228 229 230 231 232

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
233
void Sim_ManPrintStats( Sim_Man_t * p )
Alan Mishchenko committed
234
{
Alan Mishchenko committed
235 236 237 238 239 240
//    printf( "Inputs = %5d. Outputs = %5d. Sim words = %5d.\n", 
//        Abc_NtkCiNum(p->pNtk), Abc_NtkCoNum(p->pNtk), p->nSimWords );
    printf( "Total func supps   = %8d.\n", Sim_UtilCountSuppSizes(p, 0) );
    printf( "Total struct supps = %8d.\n", Sim_UtilCountSuppSizes(p, 1) );
    printf( "Sat runs SAT       = %8d.\n", p->nSatRunsSat );
    printf( "Sat runs UNSAT     = %8d.\n", p->nSatRunsUnsat );
Alan Mishchenko committed
241 242 243 244 245
    ABC_PRT( "Simulation  ", p->timeSim );
    ABC_PRT( "Traversal   ", p->timeTrav );
    ABC_PRT( "Fraiging    ", p->timeFraig );
    ABC_PRT( "SAT         ", p->timeSat );
    ABC_PRT( "TOTAL       ", p->timeTotal );
Alan Mishchenko committed
246 247
}

Alan Mishchenko committed
248 249


Alan Mishchenko committed
250 251 252 253 254 255 256 257 258 259 260
/**Function*************************************************************

  Synopsis    [Returns one simulation pattern.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
261
Sim_Pat_t * Sim_ManPatAlloc( Sim_Man_t * p )
Alan Mishchenko committed
262
{
Alan Mishchenko committed
263 264 265 266 267 268
    Sim_Pat_t * pPat;
    pPat = (Sim_Pat_t *)Extra_MmFixedEntryFetch( p->pMmPat );
    pPat->Output = -1;
    pPat->pData  = (unsigned *)((char *)pPat + sizeof(Sim_Pat_t));
    memset( pPat->pData, 0, p->nSuppWords * sizeof(unsigned) );
    return pPat;
Alan Mishchenko committed
269 270 271 272
}

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

Alan Mishchenko committed
273
  Synopsis    [Returns one simulation pattern.]
Alan Mishchenko committed
274 275 276 277 278 279 280 281

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
282
void Sim_ManPatFree( Sim_Man_t * p, Sim_Pat_t * pPat )
Alan Mishchenko committed
283
{
Alan Mishchenko committed
284
    Extra_MmFixedEntryRecycle( p->pMmPat, (char *)pPat );
Alan Mishchenko committed
285 286 287 288 289 290 291
}

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


292 293
ABC_NAMESPACE_IMPL_END