summaryrefslogtreecommitdiffstats
path: root/src/sat/sim/simMan.c
blob: 1dd4053c4328d50e8c779fce138b71d07dd6bd31 (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
/**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 $]

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

#include "abc.h"
#include "sim.h"

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

////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFITIONS                           ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Starts the simulatin manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Sim_Man_t * Sim_ManStart( Abc_Ntk_t * pNtk )
{
    Sim_Man_t * p;
    int i;
    // start the manager
    p = ALLOC( Sim_Man_t, 1 );
    memset( p, 0, sizeof(Sim_Man_t) );
    p->pNtk = pNtk;
    // internal simulation information
    p->nSimBits   = 2048;
    p->nSimWords  = SIM_NUM_WORDS(p->nSimBits);
    p->vSim0      = Sim_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), p->nSimWords, 0 );
    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_UtilInfoAlloc( Abc_NtkObjNumMax(pNtk), p->nSuppWords, 1 );
    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
    p->vSuppTargs = Vec_PtrAlloc( p->nSuppBits );
    p->vSuppTargs->nSize = p->nSuppBits;
    for ( i = 0; i < p->nSuppBits; i++ )
        p->vSuppTargs->pArray[i] = Vec_IntAlloc( 8 );
    return p;
}

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

  Synopsis    [Stops the simulatin manager.]

  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 );    
    if ( p->vSuppFun )     Sim_UtilInfoFree( p->vSuppFun );    
    if ( p->vUnateVarsP )  Sim_UtilInfoFree( p->vUnateVarsP ); 
    if ( p->vUnateVarsN )  Sim_UtilInfoFree( p->vUnateVarsN ); 
    if ( p->pMatSym )      Extra_BitMatrixStop( p->pMatSym );
    if ( p->pMatNonSym )   Extra_BitMatrixStop( p->pMatNonSym );
    if ( p->vSuppTargs )   Vec_PtrFreeFree( p->vSuppTargs );
    if ( p->vUnateTargs )  Vec_PtrFree( p->vUnateTargs );
    if ( p->vSymmTargs )   Vec_PtrFree( p->vSymmTargs );
    if ( p->pMmPat )       Extra_MmFixedStop( p->pMmPat, 0 );
    if ( p->vFifo )        Vec_PtrFree( p->vFifo );
    if ( p->vDiffs )       Vec_IntFree( p->vDiffs );
    free( p );
}

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

  Synopsis    [Returns one simulation pattern.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Sim_Pat_t * Sim_ManPatAlloc( Sim_Man_t * p )
{
    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;
}

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

  Synopsis    [Returns one simulation pattern.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sim_ManPatFree( Sim_Man_t * p, Sim_Pat_t * pPat )
{
    Extra_MmFixedEntryRecycle( p->pMmPat, (char *)pPat );
}

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

  Synopsis    [Prints the manager statisticis.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Sim_ManPrintStats( Sim_Man_t * p )
{
    printf( "Inputs = %d. Outputs = %d. Sim words = %d.\n", 
        Abc_NtkCiNum(p->pNtk), Abc_NtkCoNum(p->pNtk), p->nSimWords );
    printf( "Total struct supps = %6d.\n", Sim_UtilCountSuppSizes(p, 1) );
    printf( "Total func supps   = %6d.\n", Sim_UtilCountSuppSizes(p, 0) );
    printf( "Total targets      = %6d.\n", Vec_PtrSizeSize(p->vSuppTargs) );
    printf( "Total sim patterns = %6d.\n", Vec_PtrSize(p->vFifo) );
}

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