abcFxu.c 8.86 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
static void Abc_NtkFxuCollectInfo( Abc_Ntk_t * pNtk, Fxu_Data_t * p );
static void Abc_NtkFxuReconstruct( Abc_Ntk_t * pNtk, Fxu_Data_t * p );

35 36
extern int  Fxu_FastExtract( Fxu_Data_t * pData );

Alan Mishchenko committed
37
////////////////////////////////////////////////////////////////////////
Alan Mishchenko committed
38
///                     FUNCTION DEFINITIONS                         ///
Alan Mishchenko committed
39 40
////////////////////////////////////////////////////////////////////////

41 42 43 44 45 46 47 48 49 50 51
/**Function*************************************************************

  Synopsis    [Sets default values of the FXU parameters.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
52
void Abc_NtkSetDefaultFxParams( Fxu_Data_t * p )
53 54
{
    memset( p, 0, sizeof(Fxu_Data_t) );
55 56
    p->nSingleMax =  20000;
    p->nPairsMax  =  30000;
57
    p->nNodesExt  =1000000;
58 59
    p->WeightMin  =      0;
    p->LitCountMax=      0;
60 61 62 63 64
    p->fOnlyS     =      0;
    p->fOnlyD     =      0;
    p->fUse0      =      0;
    p->fUseCompl  =      1;
    p->fVerbose   =      0;
65
}
Alan Mishchenko committed
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82

/**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     []

***********************************************************************/
83
int Abc_NtkFastExtract( Abc_Ntk_t * pNtk, Fxu_Data_t * p )
Alan Mishchenko committed
84
{
Alan Mishchenko committed
85
    assert( Abc_NtkIsLogic(pNtk) );
Alan Mishchenko committed
86
    // if the network is already in the SOP form, it may come from BLIF file
Alan Mishchenko committed
87
    // and it may not be SCC-free, in which case FXU will not work correctly
Alan Mishchenko committed
88
    if ( Abc_NtkIsSopLogic(pNtk) )
Alan Mishchenko committed
89
    { // to make sure the SOPs are SCC-free
Alan Mishchenko committed
90 91 92
//        Abc_NtkSopToBdd(pNtk);
//        Abc_NtkBddToSop(pNtk);
    }
Alan Mishchenko committed
93 94 95 96 97 98
    // 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
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114
    // 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
115
        if ( !Abc_NtkCheck( pNtk ) )
Alan Mishchenko committed
116 117 118
            printf( "Abc_NtkFastExtract: The network check has failed.\n" );
        return 1;
    }
Alan Mishchenko committed
119 120
    else
        printf( "Warning: The network has not been changed by \"fx\".\n" );
Alan Mishchenko committed
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
    return 0;
}


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

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

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
136
int Abc_NtkFxuCheck( Abc_Ntk_t * pNtk )
Alan Mishchenko committed
137 138 139 140 141 142 143
{
    Abc_Obj_t * pNode, * pFanin1, * pFanin2;
    int n, i, k;
    Abc_NtkForEachNode( pNtk, pNode, n )
    {
        Abc_ObjForEachFanin( pNode, pFanin1, i )
        {
Alan Mishchenko committed
144
            if ( i < 2 && Abc_ObjFaninC(pNode, i) )
Alan Mishchenko committed
145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173
                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
174
    p->pManSop    = (Mem_Flex_t *)pNtk->pManFunc;
Alan Mishchenko committed
175 176 177 178
    p->vSops      = Vec_PtrAlloc(0);
    p->vFanins    = Vec_PtrAlloc(0);
    p->vSopsNew   = Vec_PtrAlloc(0);
    p->vFaninsNew = Vec_PtrAlloc(0);
Alan Mishchenko committed
179 180 181 182
    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
183 184 185
    // add SOPs and fanin array
    Abc_NtkForEachNode( pNtk, pNode, i )
    {
186
        if ( Abc_SopGetVarNum((char *)pNode->pData) < 2 )
Alan Mishchenko committed
187
            continue;
188
        if ( Abc_SopGetCubeNum((char *)pNode->pData) < 1 )
Alan Mishchenko committed
189 190 191 192
            continue;
        p->vSops->pArray[i]   = pNode->pData;
        p->vFanins->pArray[i] = &pNode->vFanins;
    }
Alan Mishchenko committed
193
    p->nNodesOld = Abc_NtkObjNumMax(pNtk);
Alan Mishchenko committed
194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209
}

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

  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Abc_NtkFxuFreeInfo( Fxu_Data_t * p )
{
    int i;
Alan Mishchenko committed
210
    // free the arrays of new fanins
Alan Mishchenko committed
211 212 213
    if ( p->vFaninsNew )
        for ( i = 0; i < p->vFaninsNew->nSize; i++ )
            if ( p->vFaninsNew->pArray[i] )
214
                Vec_IntFree( (Vec_Int_t *)p->vFaninsNew->pArray[i] );
Alan Mishchenko committed
215
    // free the arrays
Alan Mishchenko committed
216 217 218 219
    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 );
220
//    ABC_FREE( p );
Alan Mishchenko committed
221 222 223 224
}

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

Alan Mishchenko committed
225
  Synopsis    [Reconstructs the network after FX.]
Alan Mishchenko committed
226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251

  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
252
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
253 254 255 256
        if ( vFanins == NULL )
            continue;
        // remove old fanins
        pNode = Abc_NtkObj( pNtk, i );
Alan Mishchenko committed
257
        Abc_ObjRemoveFanins( pNode );
Alan Mishchenko committed
258
        // add new fanins
259
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
260 261 262 263 264 265 266 267 268 269 270 271 272 273
        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
274
        vFanins = (Vec_Int_t *)p->vFaninsNew->pArray[i];
Alan Mishchenko committed
275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
        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                                ///
////////////////////////////////////////////////////////////////////////


291 292
ABC_NAMESPACE_IMPL_END