summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcPga.c
blob: 1227d7b8de265fe1e3e7d6c2cff393f98baa188a (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
/**CFile****************************************************************

  FileName    [abcPga.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Interface with the FPGA mapping package.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "abc.h"
#include "fraig.h"
#include "fpga.h"
#include "pga.h"
#include "cut.h"

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

static Abc_Ntk_t * Abc_NtkFromPga( Abc_Ntk_t * pNtk, Vec_Ptr_t * vNodeCuts );
 
////////////////////////////////////////////////////////////////////////
///                     FUNCTION DEFINITIONS                         ///
////////////////////////////////////////////////////////////////////////

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

  Synopsis    [Interface with the FPGA mapping package.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkPga( Pga_Params_t * pParams )
{
    Abc_Ntk_t * pNtkNew, * pNtk = pParams->pNtk;
    Pga_Man_t * pMan;
    Vec_Ptr_t * vNodeCuts;

    assert( Abc_NtkIsStrash(pNtk) );

    // print a warning about choice nodes
    if ( Abc_NtkGetChoiceNum( pNtk ) )
        printf( "Performing FPGA mapping with choices.\n" );

    // start the mapping manager
    pMan = Pga_ManStart( pParams );    
    if ( pMan == NULL )
        return NULL;

    // perform mapping
    vNodeCuts = Pga_DoMapping( pMan );

    // transform the result of mapping into a BDD logic network
    pNtkNew = Abc_NtkFromPga( pNtk, vNodeCuts );
    if ( pNtkNew == NULL )
        return NULL;
    Pga_ManStop( pMan );
    Vec_PtrFree( vNodeCuts );

    // make the network minimum base
    Abc_NtkMinimumBase( pNtkNew );

    if ( pNtk->pExdc )
        pNtkNew->pExdc = Abc_NtkDup( pNtk->pExdc );

    // make sure that everything is okay
    if ( !Abc_NtkCheck( pNtkNew ) )
    {
        printf( "Abc_NtkPga: The network check has failed.\n" );
        Abc_NtkDelete( pNtkNew );
        return NULL;
    }
    return pNtkNew;
}


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

  Synopsis    [Creates the mapped network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Abc_Ntk_t * Abc_NtkFromPga( Abc_Ntk_t * pNtk, Vec_Ptr_t * vNodeCuts )
{
    ProgressBar * pProgress;
    DdManager * dd;
    Abc_Ntk_t * pNtkNew;
    Abc_Obj_t * pNode, * pFanin, * pNodeNew;
    Cut_Cut_t * pCut;
    Vec_Ptr_t * vLeaves, * vVisited;
    int i, k, nDupGates;
    // create the new network
    pNtkNew = Abc_NtkStartFrom( pNtk, ABC_NTK_LOGIC, ABC_FUNC_BDD );
    dd = pNtkNew->pManFunc;
    // add new nodes in topologic order
    vLeaves  = Vec_PtrAlloc( 6 );
    vVisited = Vec_PtrAlloc( 100 );
    pProgress = Extra_ProgressBarStart( stdout, Vec_PtrSize(vNodeCuts) );
    Vec_PtrForEachEntry( vNodeCuts, pCut, i )
    {
        Extra_ProgressBarUpdate( pProgress, i, NULL );
        // create the new node
        pNodeNew = Abc_NtkCreateNode( pNtkNew );
        Vec_PtrClear( vLeaves );
        for ( k = 0; k < (int)pCut->nLeaves; k++ )
        {
            // add the node representing the old fanin in the new network
            pFanin = Abc_NtkObj( pNtk, pCut->pLeaves[k] );
            Vec_PtrPush( vLeaves, pFanin );
            Abc_ObjAddFanin( pNodeNew, pFanin->pCopy );
        }
        // set the new node at the old node
        pNode = Abc_NtkObj( pNtk, pCut->uSign );  // pCut->uSign contains the ID of the root node
        pNode->pCopy = pNodeNew;
        // create the function of the new node
        pNodeNew->pData = Abc_NodeConeBdd( dd, dd->vars, pNode, vLeaves, vVisited );   Cudd_Ref( pNodeNew->pData );
    }
    Extra_ProgressBarStop( pProgress );
    Vec_PtrFree( vVisited );
    Vec_PtrFree( vLeaves );
    // finalize the new network
    Abc_NtkFinalize( pNtk, pNtkNew );
    // decouple the PO driver nodes to reduce the number of levels
    nDupGates = Abc_NtkLogicMakeSimpleCos( pNtkNew, 1 );
//    if ( nDupGates && Fpga_ManReadVerbose(pMan) )
//        printf( "Duplicated %d gates to decouple the CO drivers.\n", nDupGates );
    return pNtkNew;
}

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