summaryrefslogtreecommitdiffstats
path: root/src/aig/saig/saigCone.c
blob: 7ca077c8a9aebd47c91037a3b1fc3030aa61f0e2 (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
/**CFile****************************************************************

  FileName    [saigCone.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Sequential AIG package.]

  Synopsis    [Cone of influence computation.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "saig.h"

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

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

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

  Synopsis    [Counts the support size of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Saig_ManSupport_rec( Aig_Man_t * p, Aig_Obj_t * pObj, Vec_Ptr_t * vSupp )
{
    if ( Aig_ObjIsTravIdCurrent(p, pObj) )
        return;
    Aig_ObjSetTravIdCurrent(p, pObj);
    if ( Aig_ObjIsConst1(pObj) )
        return;
    if ( Aig_ObjIsPi(pObj) )
    {
        if ( Saig_ObjIsLo(p,pObj) )
        {
            pObj = Saig_ManLi( p, Aig_ObjPioNum(pObj)-Saig_ManPiNum(p) );
            Vec_PtrPush( vSupp, pObj );
        }
        return;
    }
    assert( Aig_ObjIsNode(pObj) );
    Saig_ManSupport_rec( p, Aig_ObjFanin0(pObj), vSupp );
    Saig_ManSupport_rec( p, Aig_ObjFanin1(pObj), vSupp );
}

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

  Synopsis    [Counts the support size of the node.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Ptr_t * Saig_ManSupport( Aig_Man_t * p, Vec_Ptr_t * vNodes )
{
    Vec_Ptr_t * vSupp;
    Aig_Obj_t * pObj;
    int i;
    vSupp = Vec_PtrAlloc( 100 );
    Aig_ManIncrementTravId( p );
    Vec_PtrForEachEntry( vNodes, pObj, i )
    {
        assert( Aig_ObjIsPo(pObj) );
        Saig_ManSupport_rec( p, Aig_ObjFanin0(pObj), vSupp );
    }
    return vSupp;
}

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

  Synopsis    [Prints information about cones of influence of the POs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Saig_ManPrintConeOne( Aig_Man_t * p, Aig_Obj_t * pObj )
{
    Vec_Ptr_t * vPrev, * vCur, * vTotal;
    int s, i, nCurNew, nCurPrev, nCurOld;
    assert( Saig_ObjIsPo(p, pObj) );
    // start the array
    vPrev = Vec_PtrAlloc( 100 );
    Vec_PtrPush( vPrev, pObj );
    // get the current support
    vCur = Saig_ManSupport( p, vPrev );  
    Vec_PtrClear( vPrev );
    printf( "    PO %3d  ", Aig_ObjPioNum(pObj) );
    // continue computing supports as long as there are now nodes
    vTotal = Vec_PtrAlloc( 100 );
    for ( s = 0; ; s++ )
    {
        // classify current into those new, prev, and older 
        nCurNew = nCurPrev = nCurOld = 0;
        Vec_PtrForEachEntry( vCur, pObj, i )
        {
            if ( Vec_PtrFind(vTotal, pObj) == -1 )
            {
                Vec_PtrPush( vTotal, pObj );
                nCurNew++;
            }
            else if ( Vec_PtrFind(vPrev, pObj) >= 0 )
                nCurPrev++;
            else
                nCurOld++;
        }
        assert( nCurNew + nCurPrev + nCurOld == Vec_PtrSize(vCur) );
        // print the result
        printf( "%d:%d %d=%d+%d+%d  ", s, Vec_PtrSize(vTotal), Vec_PtrSize(vCur), nCurNew, nCurPrev, nCurOld ); 
        if ( nCurNew == 0 )
            break;
        // compute one more step
        Vec_PtrFree( vPrev );
        vCur = Saig_ManSupport( p, vPrev = vCur );
    }
    printf( "\n" );
    Vec_PtrFree( vPrev );
    Vec_PtrFree( vCur );
    Vec_PtrFree( vTotal );
}

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

  Synopsis    [Prints information about cones of influence of the POs.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Saig_ManPrintCones( Aig_Man_t * p )
{
    Aig_Obj_t * pObj;
    int i;
    printf( "The format of this print-out: For each PO, x:a b=c+d+e, where \n" );
    printf( "- x is the time-frame counting back from the PO\n" );
    printf( "- a is the total number of registers in the COI of the PO so far\n" );
    printf( "- b is the number of registers in the COI of the PO in this time-frame\n" );
    printf( "- c is the number of registers in b that are new (appear for the first time)\n" );
    printf( "- d is the number of registers in b in common with the previous time-frame\n" );
    printf( "- e is the number of registers in b in common with other time-frames\n" );
    Aig_ManSetPioNumbers( p );
    Saig_ManForEachPo( p, pObj, i )
        Saig_ManPrintConeOne( p, pObj );
}

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