summaryrefslogtreecommitdiffstats
path: root/src/base/acb/acbPush.c
blob: 08edc4d10e22e4aa9b6de07ce7eeaef005dc8bcb (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
/**CFile****************************************************************

  FileName    [acbPush.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Hierarchical word-level netlist.]

  Synopsis    [Implementation of logic pushing.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - July 21, 2015.]

  Revision    [$Id: acbPush.c,v 1.00 2014/11/29 00:00:00 alanmi Exp $]

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

#include "acb.h"
#include "misc/util/utilTruth.h"

ABC_NAMESPACE_IMPL_START

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

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

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

  Synopsis    [Check if the node can have its logic pushed.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Acb_ObjCheckFaninDsd( Acb_Ntk_t * p, int iObj, int iFanIndex )
{
    int k, iFanin, * pFanins;
    Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
        if ( Abc_TtCheckDsdAnd(Acb_ObjTruth(p, iObj), iFanIndex, k, NULL) >= 0 )
            return 1;
    return 0;
}
int Acb_ObjCountFaninAbsorb( Acb_Ntk_t * p, int iObj, int iFanin, int iFanIndex, int nLutSize )
{
    if ( Acb_ObjSetTravIdCur(p, iFanin) )
        return 0;
    if ( Acb_ObjIsCi(p, iFanin) )
        return 0;
    if ( Acb_ObjFanoutNum(p, iFanin) > 1 )
        return 0;
    if ( !Acb_ObjCheckFaninDsd(p, iObj, iFanIndex) ) 
        return 0;
    if ( Acb_ObjFaninNum(p, iFanin) == nLutSize )
        return 0;
    return 1;
}
int Acb_NtkObjPushEstimate( Acb_Ntk_t * p, int iObj, int nLutSize )
{
    int k, iFanin, * pFanins;
    int Count = Acb_ObjFaninNum(p, iObj);
    Acb_NtkIncTravId( p );
    Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
    {
        Count -= Acb_ObjCountFaninAbsorb( p, iObj, iFanin, k, nLutSize );
        if ( Count <= 0 )
            return 1;
    }
    if ( Acb_ObjFanoutNum(p, iObj) > 1 )
        return 0;
    Acb_ObjForEachFaninFast( p, iObj, pFanins, iFanin, k )
        if ( Abc_TtCheckOutAnd(Acb_ObjTruth(p, iObj), k, NULL) )
            break;
    if ( k == Acb_ObjFaninNum(p, iFanin) )
        return 0;
    iFanin = Vec_IntEntry( Acb_ObjFanout(p, iObj), 0 );
    if ( Acb_ObjFaninNum(p, iFanin) == nLutSize )
        return 0;
    return 1;
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Acb_NtkPushLogic( Acb_Ntk_t * p, int nLutSize, int fVerbose )
{
    //Vec_Bit_t * vVisited = Vec_BitStart( Acb_NtkObjNumMax(p) );
    int n = 0, iObj, nNodes = 0;
    Acb_NtkCreateFanout( p );  // fanout data structure
    for ( n = 2; n <= nLutSize; n++ )
        Acb_NtkForEachNode( p, iObj )
        {
            if ( !Acb_NtkObjPushEstimate(p, iObj, nLutSize) )
                continue;
            nNodes++;
        }
    printf( "Performed optimization at %d nodes.\n", nNodes );
    //Vec_BitFree( vVisited );
}

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


ABC_NAMESPACE_IMPL_END