summaryrefslogtreecommitdiffstats
path: root/src/opt/rwr/rwrUtil.c
blob: ae8665efa14b0c40ce35d385e814085675dcd0c0 (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
/**CFile****************************************************************

  FileName    [rwrUtil.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [DAG-aware AIG rewriting package.]

  Synopsis    [Various utilities.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "rwr.h"

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

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

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

  Synopsis    [Creates the array of fanout counters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Rwt_NtkFanoutCounters( Abc_Ntk_t * pNtk )
{
    Vec_Int_t * vFanNums;
    Abc_Obj_t * pObj;
    int i;
    vFanNums = Vec_IntAlloc( 0 );
    Vec_IntFill( vFanNums, Abc_NtkObjNumMax(pNtk), -1 );
    Abc_NtkForEachObj( pNtk, pObj, i )
        if ( Abc_ObjIsNode( pObj ) )
            Vec_IntWriteEntry( vFanNums, i, Abc_ObjFanoutNum(pObj) );
    return vFanNums;
}

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

  Synopsis    [Creates the array of required times.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Vec_Int_t * Rwt_NtkRequiredLevels( Abc_Ntk_t * pNtk )
{
    Vec_Int_t * vReqTimes;
    Vec_Ptr_t * vNodes;
    Abc_Obj_t * pObj, * pFanout;
    int i, k, nLevelsMax, nLevelsCur;
    // start the required times
    vReqTimes = Vec_IntAlloc( 0 );
    Vec_IntFill( vReqTimes, Abc_NtkObjNumMax(pNtk), ABC_INFINITY );
    // compute levels in reverse topological order
    Abc_NtkForEachCo( pNtk, pObj, i )
        Vec_IntWriteEntry( vReqTimes, pObj->Id, 0 );
    vNodes = Abc_NtkDfsReverse( pNtk );
    Vec_PtrForEachEntry( vNodes, pObj, i )
    {
        nLevelsCur = 0;
        Abc_ObjForEachFanout( pObj, pFanout, k )
            if ( nLevelsCur < Vec_IntEntry(vReqTimes, pFanout->Id) )
                nLevelsCur = Vec_IntEntry(vReqTimes, pFanout->Id);
        Vec_IntWriteEntry( vReqTimes, pObj->Id, nLevelsCur + 1 );
    }
    Vec_PtrFree( vNodes );
    // convert levels into required times: RetTime = NumLevels + 1 - Level
    nLevelsMax = Abc_AigGetLevelNum(pNtk) + 1;
    Abc_NtkForEachNode( pNtk, pObj, i )
        Vec_IntWriteEntry( vReqTimes, pObj->Id, nLevelsMax - Vec_IntEntry(vReqTimes, pObj->Id) );
//    Abc_NtkForEachNode( pNtk, pObj, i )
//        printf( "(%d,%d)", pObj->Level, Vec_IntEntry(vReqTimes, pObj->Id) );
//    printf( "\n" );
    return vReqTimes;
}

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