summaryrefslogtreecommitdiffstats
path: root/src/opt/res/resCore.c
blob: 0335712d140713e0755f4a5c61f0706b3c178fbf (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    [resCore.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Resynthesis package.]

  Synopsis    [Top-level resynthesis procedure.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

  Date        [Ver. 1.0. Started - January 15, 2007.]

  Revision    [$Id: resCore.c,v 1.00 2007/01/15 00:00:00 alanmi Exp $]

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

#include "abc.h"
#include "res.h"

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

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

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

  Synopsis    [Entrace into the resynthesis package.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Abc_NtkResynthesize( Abc_Ntk_t * pNtk, int nWindow, int nSimWords, int fVerbose, int fVeryVerbose )
{
    Res_Win_t * pWin;
    Res_Sim_t * pSim;
    Abc_Ntk_t * pAig;
    Abc_Obj_t * pObj;
    Hop_Obj_t * pFunc;
    Vec_Ptr_t * vFanins;
    int i, nNodesOld;
    assert( Abc_NtkHasAig(pNtk) );
    assert( nWindow > 0 && nWindow < 100 );
    // start the window
    pWin = Res_WinAlloc();
    pSim = Res_SimAlloc( nSimWords );
    // set the number of levels
    Abc_NtkLevel( pNtk );
    // try resynthesizing nodes in the topological order
    nNodesOld = Abc_NtkObjNumMax(pNtk);
    Abc_NtkForEachObj( pNtk, pObj, i )
    {
        if ( !Abc_ObjIsNode(pObj) )
            continue;
        if ( pObj->Id > nNodesOld )
            break;
        // create the window for this node
        if ( !Res_WinCompute(pObj, nWindow/10, nWindow%10, pWin) )
            continue;
        // collect the divisors
        Res_WinDivisors( pWin, pObj->Level - 1 );
        // create the AIG for the window
        pAig = Res_WndStrash( pWin );
        // prepare simulation info
        if ( Res_SimPrepare( pSim, pAig ) )
        {
            // find resub candidates for the node
            vFanins = Res_FilterCandidates( pWin, pSim );
            // check using SAT
            pFunc = Res_SatFindFunction( pNtk->pManFunc, pWin, vFanins, pAig );
            // update the network
            if ( pFunc == NULL )
                Res_UpdateNetwork( pObj, vFanins, pFunc, pWin->vLevels );
        }
        Abc_NtkDelete( pAig );
    }
    Res_WinFree( pWin );
    Res_SimFree( pSim );
    // check the resulting network
    if ( !Abc_NtkCheck( pNtk ) )
    {
        fprintf( stdout, "Abc_NtkResynthesize(): Network check has failed.\n" );
        return 0;
    }
    return 1;
}

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