summaryrefslogtreecommitdiffstats
path: root/src/aig/fsim/fsimMan.c
blob: 872e16041861ced15d3fcb84526c4d994aa524e7 (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
167
168
169
170
171
172
173
174
175
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
201
202
203
204
205
206
207
/**CFile****************************************************************

  FileName    [fsimMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Fast sequential AIG simulator.]

  Synopsis    [Simulation manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "fsimInt.h"

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

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

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

  Synopsis    [Creates fast simulation manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Fsim_ManCreate_rec( Fsim_Man_t * p, Aig_Obj_t * pObj )
{
    int iFan0, iFan1, iTemp;
    assert( !Aig_IsComplement(pObj) );
    if ( pObj->iData )
        return pObj->iData;
    assert( !Aig_ObjIsConst1(pObj) );
    if ( Aig_ObjIsNode(pObj) )
    {
        iFan0 = Fsim_ManCreate_rec( p, Aig_ObjFanin0(pObj) );
        iFan1 = Fsim_ManCreate_rec( p, Aig_ObjFanin1(pObj) );
        assert( iFan0 != iFan1 );
        if ( --p->pRefs[iFan0] == 0 )
            p->nCrossCut--;
        iFan0 = Fsim_Var2Lit( iFan0, Aig_ObjFaninC0(pObj) );
        if ( --p->pRefs[iFan1] == 0 )
            p->nCrossCut--;
        iFan1 = Fsim_Var2Lit( iFan1, Aig_ObjFaninC1(pObj) );
        if ( p->pAig->pEquivs )
            Fsim_ManCreate_rec( p, Aig_ObjEquiv(p->pAig, pObj) );
    }
    else if ( Aig_ObjIsPo(pObj) )
    {
        assert( Aig_ObjRefs(pObj) == 0 );
        iFan0 = Fsim_ManCreate_rec( p, Aig_ObjFanin0(pObj) );
        if ( --p->pRefs[iFan0] == 0 )
            p->nCrossCut--;
        iFan0 = Fsim_Var2Lit( iFan0, Aig_ObjFaninC0(pObj) );
        iFan1 = 0;
    }
    else
    {
        iFan0 = iFan1 = 0;
        Vec_IntPush( p->vCis2Ids, Aig_ObjPioNum(pObj) );
    }
    if ( iFan0 < iFan1 )
        iTemp = iFan0, iFan0 = iFan1, iFan1 = iTemp;
    p->pFans0[p->nObjs] = iFan0;
    p->pFans1[p->nObjs] = iFan1;
    p->pRefs[p->nObjs]  = Aig_ObjRefs(pObj);
    if ( p->pRefs[p->nObjs] )
        if ( p->nCrossCutMax < ++p->nCrossCut ) 
            p->nCrossCutMax = p->nCrossCut;
    return pObj->iData = p->nObjs++;
}

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

  Synopsis    [Creates fast simulation manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Fsim_Man_t * Fsim_ManCreate( Aig_Man_t * pAig )
{
    Fsim_Man_t * p;
    Aig_Obj_t * pObj;
    int i, nObjs;
    Aig_ManCleanData( pAig );
    p = (Fsim_Man_t *)ABC_ALLOC( Fsim_Man_t, 1 );
    memset( p, 0, sizeof(Fsim_Man_t) );
    p->pAig = pAig;
    p->nPis = Saig_ManPiNum(pAig);
    p->nPos = Saig_ManPoNum(pAig);
    p->nCis = Aig_ManPiNum(pAig);
    p->nCos = Aig_ManPoNum(pAig);
    p->nNodes = Aig_ManNodeNum(pAig);
    nObjs = p->nCis + p->nCos + p->nNodes + 2;
    p->pFans0 = ABC_ALLOC( int, nObjs );
    p->pFans1 = ABC_ALLOC( int, nObjs );
    p->pRefs  = ABC_ALLOC( int, nObjs );
    p->vCis2Ids = Vec_IntAlloc( Aig_ManPiNum(pAig) );
    // add objects (0=unused; 1=const1)
    p->pFans0[0] = p->pFans1[0] = 0;
    p->pFans0[1] = p->pFans1[1] = 0;
    p->pRefs[0] = 0;
    p->nObjs = 2;
    pObj = Aig_ManConst1( pAig );
    pObj->iData = 1;
    p->pRefs[1] = Aig_ObjRefs(pObj);
    if ( p->pRefs[1] )
        p->nCrossCut = 1;
    Aig_ManForEachPi( pAig, pObj, i )
        if ( Aig_ObjRefs(pObj) == 0 )
            Fsim_ManCreate_rec( p, pObj );
    Aig_ManForEachPo( pAig, pObj, i )
        Fsim_ManCreate_rec( p, pObj );
    assert( Vec_IntSize(p->vCis2Ids) == Aig_ManPiNum(pAig) );
    assert( p->nObjs == nObjs );
    // check references
    assert( p->nCrossCut == 0 );
    Aig_ManForEachObj( pAig, pObj, i )
    {
        assert( p->pRefs[pObj->iData] == 0 );
        p->pRefs[pObj->iData] = Aig_ObjRefs(pObj);
    }
    // collect flop outputs
    p->vLos = Vec_IntAlloc( Aig_ManRegNum(pAig) );
    Saig_ManForEachLo( pAig, pObj, i )
        Vec_IntPush( p->vLos, pObj->iData );
    // collect flop inputs
    p->vLis = Vec_IntAlloc( Aig_ManRegNum(pAig) );
    Saig_ManForEachLi( pAig, pObj, i )
        Vec_IntPush( p->vLis, pObj->iData );
    // determine the frontier size
    p->nFront = 1 + (int)(1.1 * p->nCrossCutMax); 
    return p;
}

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

  Synopsis    [Deletes fast simulation manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fsim_ManDelete( Fsim_Man_t * p )
{
    Vec_IntFree( p->vCis2Ids );
    Vec_IntFree( p->vLos );
    Vec_IntFree( p->vLis );
    ABC_FREE( p->pDataAig2 );
    ABC_FREE( p->pDataAig );
    ABC_FREE( p->pFans0 );
    ABC_FREE( p->pFans1 );
    ABC_FREE( p->pRefs );
    ABC_FREE( p->pDataSim );
    ABC_FREE( p->pDataSimCis );
    ABC_FREE( p->pDataSimCos );
    ABC_FREE( p->pData1 );
    ABC_FREE( p->pData2 );
    ABC_FREE( p );
}

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

  Synopsis    [Testing procedure.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Fsim_ManTest( Aig_Man_t * pAig )
{
    Fsim_Man_t * p;
    p = Fsim_ManCreate( pAig );
    Fsim_ManFront( p, 0 );
    Fsim_ManDelete( p );
}

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