summaryrefslogtreecommitdiffstats
path: root/src/opt/lpk/lpkAbcCore.c
blob: 53b2668decdbf5e511c6b56e68627d9a7f2407d8 (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
/**CFile****************************************************************

  FileName    [lpkAbcCore.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Fast Boolean matching for LUT structures.]

  Synopsis    [The new core procedure.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - April 28, 2007.]

  Revision    [$Id: lpkAbcCore.c,v 1.00 2007/04/28 00:00:00 alanmi Exp $]

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

#include "lpkInt.h"

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

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

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

  Synopsis    [Implements the function.]

  Description [Returns the node implementing this function.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Obj_t * Lpk_FunImplement( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, Lpk_Fun_t * p )
{
    Abc_Obj_t * pObjNew;
    int i;
    pObjNew = Abc_NtkCreateNode( pNtk );
    for ( i = 0; i < (int)p->nVars; i++ )
        Abc_ObjAddFanin( pObjNew, Vec_PtrEntry(vLeaves, p->pFanins[i]) );
    Abc_ObjLevelNew( pObjNew );
    // create the logic function
    {
        extern Hop_Obj_t * Kit_GraphToHop( Hop_Man_t * pMan, Kit_Graph_t * pGraph );
        // allocate memory for the ISOP
        Vec_Int_t * vCover = Vec_IntAlloc( 0 );
        // transform truth table into the decomposition tree
        Kit_Graph_t * pGraph = Kit_TruthToGraph( Lpk_FunTruth(p, 0), p->nVars, vCover );
        // derive the AIG for the decomposition tree
        pObjNew->pData = Kit_GraphToHop( pNtk->pManFunc, pGraph );
        Kit_GraphFree( pGraph );
        Vec_IntFree( vCover );
    }
    return pObjNew;
}

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

  Synopsis    [Implements the function.]

  Description [Returns the node implementing this function.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Obj_t * Lpk_LptImplement( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, int nLeavesOld )
{
    Lpk_Fun_t * pFun;
    Abc_Obj_t * pRes;
    int i;
    for ( i = Vec_PtrSize(vLeaves) - 1; i >= nLeavesOld; i-- )
    {
        pFun = Vec_PtrEntry( vLeaves, i );
        pRes = Lpk_FunImplement( pNtk, vLeaves, pFun );
        Vec_PtrWriteEntry( vLeaves, i, pRes );
        Lpk_FunFree( pFun );
    }
    return pRes;
}

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

  Synopsis    [Decomposes the function using recursive MUX decomposition.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Lpk_LpkDecompose_rec( Lpk_Fun_t * p )
{
    Lpk_Fun_t * p2;
    int VarPol;
    assert( p->nAreaLim > 0 );
    if ( p->nVars <= p->nLutK )
        return 1;
    // check if decomposition exists
    VarPol = Lpk_FunAnalizeMux( p );
    if ( VarPol == -1 )
        return 0;
    // split and call recursively
    p2 = Lpk_FunSplitMux( p, VarPol );
    if ( !Lpk_LpkDecompose_rec( p2 ) )
        return 0;
    return Lpk_LpkDecompose_rec( p );
}


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

  Synopsis    [Decomposes the function using recursive MUX decomposition.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Obj_t * Lpk_LpkDecompose( Abc_Ntk_t * pNtk, Vec_Ptr_t * vLeaves, unsigned * pTruth, int nLutK, int AreaLim, int DelayLim )
{
    Lpk_Fun_t * p;
    Abc_Obj_t * pObjNew = NULL;
    int i, nLeaves;
    // create the starting function
    nLeaves = Vec_PtrSize( vLeaves );
    p = Lpk_FunCreate( pNtk, vLeaves, pTruth, nLutK, AreaLim, DelayLim );
    Lpk_FunSuppMinimize( p );
    // decompose the function 
    if ( Lpk_LpkDecompose_rec(p) )
        pObjNew = Lpk_LptImplement( pNtk, vLeaves, nLeaves );
    else
    {
        for ( i = Vec_PtrSize(vLeaves) - 1; i >= nLeaves; i-- )
            Lpk_FunFree( Vec_PtrEntry(vLeaves, i) );
    }
    Vec_PtrShrink( vLeaves, nLeaves );
    return pObjNew;
}


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