abcFxu.c 8.18 KB
Newer Older
Alan Mishchenko committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
/**CFile****************************************************************

  FileName    [abcFxu.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Network and node package.]

  Synopsis    [Interface with the fast extract package.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

21 22
#include "base/abc/abc.h"
#include "opt/fxu/fxu.h"
Alan Mishchenko committed
23

24 25 26
ABC_NAMESPACE_IMPL_START


Alan Mishchenko committed
27 28 29 30
////////////////////////////////////////////////////////////////////////
///                        DECLARATIONS                              ///
////////////////////////////////////////////////////////////////////////
 
31
static int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk );
Alan Mishchenko committed
32 33 34 35
static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );

////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
36
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
////////////////////////////////////////////////////////////////////////


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

  Synopsis    [Performs fast_extract on the current network.]

  Description [Takes the network and the maximum number of nodes to extract.
  Uses the concurrent double-cube and single cube divisor extraction procedure.
  Modifies the network in the end, after extracting all nodes. Note that 
  Ntk_NetworkSweep() may increase the performance of this procedure because 
  the single-literal nodes will not be created in the sparse matrix. Returns 1 
  if the network has been changed.]
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
56
int Abc_NtkFastExtract( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
Alan Mishchenko committed
57
{
Alan Mishchenko committed
58
    assert( Abc_NtkIsLogic(pNtk) );
Alan Mishchenko committed
59
    // if the network is already in the SOP form, it may come from BLIF file
Alan Mishchenko committed
60
    // and it may not be SCC-ABC_FREE, in which case FXU will not work correctly
Alan Mishchenko committed
61
    if ( Abc_NtkIsSopLogic(pNtk) )
Alan Mishchenko committed
62
    { // to make sure the SOPs are SCC-ABC_FREE
Alan Mishchenko committed
63 64 65
//        Abc_NtkSopToBdd(pNtk);
//        Abc_NtkBddToSop(pNtk);
    }
Alan Mishchenko committed
66 67 68 69 70 71
    // get the network in the SOP form
    if ( !Abc_NtkToSop(pNtk, 0) )
    {
        printf( "Abc_NtkFastExtract(): Converting to SOPs has failed.\n" );
        return 0;
    }
Alan Mishchenko committed
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    // check if the network meets the requirements
    if ( !Abc_NtkFxuCheck(pNtk) )
    {
        printf( "Abc_NtkFastExtract: Nodes have duplicated or complemented fanins. FXU is not performed.\n" );
        return 0;
    }
    // sweep removes useless nodes
    Abc_NtkCleanup( pNtk, 0 );
    // collect information about the covers
    Abc_NtkFxuCollectInfo( pNtk, p );
    // call the fast extract procedure
    if ( Fxu_FastExtract(p) > 0 )
    {
        // update the network
        Abc_NtkFxuReconstruct( pNtk, p );
        // make sure everything is okay
Alan Mishchenko committed
88
        if ( !Abc_NtkCheck( pNtk ) )
Alan Mishchenko committed
89 90 91
            printf( "Abc_NtkFastExtract: The network check has failed.\n" );
        return 1;
    }
Alan Mishchenko committed
92 93
    else
        printf( "Warning: The network has not been changed by \"fx\".\n" );
Alan Mishchenko committed
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108
    return 0;
}


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

  Synopsis    [Makes sure the nodes do not have complemented and duplicated fanins.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
109
int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk )
Alan Mishchenko committed
110 111 112 113 114 115 116
{
    Abc_Obj_t * pNode, * pFanin1, * pFanin2;
    int n, i, k;
    Abc_NtkForEachNode( pNtk, pNode, n )
    {
        Abc_ObjForEachFanin( pNode, pFanin1, i )
        {
Alan Mishchenko committed
117
            if ( i < 2 && Abc_ObjFaninC(pNode, i) )
Alan Mishchenko committed
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
                return 0;
            Abc_ObjForEachFanin( pNode, pFanin2, k )
            {
                if ( i == k )
                    continue;
                if ( pFanin1 == pFanin2 )
                    return 0;
            }
        }
    }
    return 1;
}

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

  Synopsis    [Collect information about the network for fast_extract.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
{
    Abc_Obj_t * pNode;
    int i;
    // add information to the manager
147
    p->pManSop    = (Mem_Flex_t *)pNtk->pManFunc;
Alan Mishchenko committed
148 149 150 151
    p->vSops      = Vec_PtrAlloc(0);
    p->vFanins    = Vec_PtrAlloc(0);
    p->vSopsNew   = Vec_PtrAlloc(0);
    p->vFaninsNew = Vec_PtrAlloc(0);
Alan Mishchenko committed
152 153 154 155
    Vec_PtrFill( p->vSops,      Abc_NtkObjNumMax(pNtk), NULL );
    Vec_PtrFill( p->vFanins,    Abc_NtkObjNumMax(pNtk), NULL );
    Vec_PtrFill( p->vSopsNew,   Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
    Vec_PtrFill( p->vFaninsNew, Abc_NtkObjNumMax(pNtk) + p->nNodesExt, NULL );
Alan Mishchenko committed
156 157 158
    // add SOPs and fanin array
    Abc_NtkForEachNode( pNtk, pNode, i )
    {
159
        if ( Abc_SopGetVarNum((char *)pNode->pData) < 2 )
Alan Mishchenko committed
160
            continue;
161
        if ( Abc_SopGetCubeNum((char *)pNode->pData) < 1 )
Alan Mishchenko committed
162 163 164 165
            continue;
        p->vSops->pArray[i]   = pNode->pData;
        p->vFanins->pArray[i] = &pNode->vFanins;
    }
Alan Mishchenko committed
166
    p->nNodesOld = Abc_NtkObjNumMax(pNtk);
Alan Mishchenko committed
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkFxuFreeInfo( Fxu_Data_t * p )
{
    int i;
Alan Mishchenko committed
183
    // free the arrays of new fanins
Alan Mishchenko committed
184 185 186
    if ( p->vFaninsNew )
        for ( i = 0; i < p->vFaninsNew->nSize; i++ )
            if ( p->vFaninsNew->pArray[i] )
187
                Vec_IntFree( (Vec_Int_t *)p->vFaninsNew->pArray[i] );
Alan Mishchenko committed
188
    // free the arrays
Alan Mishchenko committed
189 190 191 192
    if ( p->vSops      ) Vec_PtrFree( p->vSops      );
    if ( p->vSopsNew   ) Vec_PtrFree( p->vSopsNew   );
    if ( p->vFanins    ) Vec_PtrFree( p->vFanins    );
    if ( p->vFaninsNew ) Vec_PtrFree( p->vFaninsNew );
Alan Mishchenko committed
193
    ABC_FREE( p );
Alan Mishchenko committed
194 195 196 197
}

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

Alan Mishchenko committed
198
  Synopsis    [Reconstructs the network after FX.]
Alan Mishchenko committed
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
{
    Vec_Int_t * vFanins;
    Abc_Obj_t * pNode, * pFanin;
    int i, k;

    assert( p->vFanins->nSize < p->vFaninsNew->nSize );
    // create the new nodes
    for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
    {
        // start the node
        pNode = Abc_NtkCreateNode( pNtk );
        assert( i == (int)pNode->Id );
    }
    // update the old nodes
    for ( i = 0; i < p->vFanins->nSize; i++ )
    {
        // the new array of fanins
225
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
226 227 228 229
        if ( vFanins == NULL )
            continue;
        // remove old fanins
        pNode = Abc_NtkObj( pNtk, i );
Alan Mishchenko committed
230
        Abc_ObjRemoveFanins( pNode );
Alan Mishchenko committed
231
        // add new fanins
232
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
233 234 235 236 237 238 239 240 241 242 243 244 245 246
        for ( k = 0; k < vFanins->nSize; k++ )
        {
            pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
            Abc_ObjAddFanin( pNode, pFanin );
        }
        pNode->pData = p->vSopsNew->pArray[i];
        assert( pNode->pData != NULL );
    }
    // set up the new nodes
    for ( i = p->vFanins->nSize; i < p->vFanins->nSize + p->nNodesNew; i++ )
    {
        // get the new node
        pNode = Abc_NtkObj( pNtk, i );
        // add the fanins
247
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263
        for ( k = 0; k < vFanins->nSize; k++ )
        {
            pFanin = Abc_NtkObj( pNtk, vFanins->pArray[k] );
            Abc_ObjAddFanin( pNode, pFanin );
        }
        pNode->pData = p->vSopsNew->pArray[i];
        assert( pNode->pData != NULL );
    }
}


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


264 265
ABC_NAMESPACE_IMPL_END