nwkUtil.c 19.1 KB
Newer Older
Alan Mishchenko committed
1 2
/**CFile****************************************************************

Alan Mishchenko committed
3
  FileName    [nwkUtil.c]
Alan Mishchenko committed
4 5 6

  SystemName  [ABC: Logic synthesis and verification system.]

Alan Mishchenko committed
7
  PackageName [Logic network representation.]
Alan Mishchenko committed
8 9 10 11 12 13 14 15 16

  Synopsis    [Various utilities.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

Alan Mishchenko committed
17
  Revision    [$Id: nwkUtil.c,v 1.00 2005/06/20 00:00:00 alanmi Exp $]
Alan Mishchenko committed
18 19 20

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

21
#include <math.h>
Alan Mishchenko committed
22
#include "nwk.h"
23
#include "src/bool/kit/kit.h"
24 25 26

ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46

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

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

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

  Synopsis    [Increments the current traversal ID of the network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
47
void Nwk_ManIncrementTravId( Nwk_Man_t * pNtk )
Alan Mishchenko committed
48
{
Alan Mishchenko committed
49
    Nwk_Obj_t * pObj;
Alan Mishchenko committed
50 51 52 53
    int i;
    if ( pNtk->nTravIds >= (1<<26)-1 )
    {
        pNtk->nTravIds = 0;
Alan Mishchenko committed
54
        Nwk_ManForEachObj( pNtk, pObj, i )
Alan Mishchenko committed
55 56 57 58 59 60 61
            pObj->TravId = 0;
    }
    pNtk->nTravIds++;
}

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

Alan Mishchenko committed
62
  Synopsis    [Reads the maximum number of fanins of a node.]
Alan Mishchenko committed
63 64 65 66 67 68 69 70

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
71
int Nwk_ManGetFaninMax( Nwk_Man_t * pNtk )
Alan Mishchenko committed
72
{
Alan Mishchenko committed
73
    Nwk_Obj_t * pNode;
Alan Mishchenko committed
74
    int i, nFaninsMax = 0;
Alan Mishchenko committed
75
    Nwk_ManForEachNode( pNtk, pNode, i )
Alan Mishchenko committed
76
    {
Alan Mishchenko committed
77 78
        if ( nFaninsMax < Nwk_ObjFaninNum(pNode) )
            nFaninsMax = Nwk_ObjFaninNum(pNode);
Alan Mishchenko committed
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
    }
    return nFaninsMax;
}

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

  Synopsis    [Reads the total number of all fanins.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
94
int Nwk_ManGetTotalFanins( Nwk_Man_t * pNtk )
Alan Mishchenko committed
95
{
Alan Mishchenko committed
96
    Nwk_Obj_t * pNode;
Alan Mishchenko committed
97
    int i, nFanins = 0;
Alan Mishchenko committed
98 99
    Nwk_ManForEachNode( pNtk, pNode, i )
        nFanins += Nwk_ObjFaninNum(pNode);
Alan Mishchenko committed
100 101 102
    return nFanins;
}

Alan Mishchenko committed
103

Alan Mishchenko committed
104 105
/**Function*************************************************************

Alan Mishchenko committed
106
  Synopsis    [Returns the number of true PIs.]
Alan Mishchenko committed
107

Alan Mishchenko committed
108
  Description []
Alan Mishchenko committed
109 110 111 112 113 114
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
115
int Nwk_ManPiNum( Nwk_Man_t * pNtk )
Alan Mishchenko committed
116
{
Alan Mishchenko committed
117
    Nwk_Obj_t * pNode;
Alan Mishchenko committed
118
    int i, Counter = 0;
Alan Mishchenko committed
119 120
    Nwk_ManForEachCi( pNtk, pNode, i )
        Counter += Nwk_ObjIsPi( pNode );
Alan Mishchenko committed
121
    return Counter;
Alan Mishchenko committed
122 123 124 125
}

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

Alan Mishchenko committed
126
  Synopsis    [Returns the number of true POs.]
Alan Mishchenko committed
127 128 129 130 131 132 133 134

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
135
int Nwk_ManPoNum( Nwk_Man_t * pNtk )
Alan Mishchenko committed
136
{
Alan Mishchenko committed
137
    Nwk_Obj_t * pNode;
Alan Mishchenko committed
138
    int i, Counter = 0;
Alan Mishchenko committed
139 140
    Nwk_ManForEachCo( pNtk, pNode, i )
        Counter += Nwk_ObjIsPo( pNode );
Alan Mishchenko committed
141 142 143 144 145
    return Counter;
}

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

Alan Mishchenko committed
146
  Synopsis    [Reads the number of AIG nodes.]
Alan Mishchenko committed
147 148 149 150 151 152 153 154

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
155
int Nwk_ManGetAigNodeNum( Nwk_Man_t * pNtk )
Alan Mishchenko committed
156
{
Alan Mishchenko committed
157
    Nwk_Obj_t * pNode;
Alan Mishchenko committed
158
    int i, nNodes = 0;
Alan Mishchenko committed
159
    Nwk_ManForEachNode( pNtk, pNode, i )
Alan Mishchenko committed
160 161 162
    {
        if ( pNode->pFunc == NULL )
        {
Alan Mishchenko committed
163
            printf( "Nwk_ManGetAigNodeNum(): Local AIG of node %d is not assigned.\n", pNode->Id );
Alan Mishchenko committed
164 165
            continue;
        }
Alan Mishchenko committed
166
        if ( Nwk_ObjFaninNum(pNode) < 2 )
Alan Mishchenko committed
167 168 169 170
            continue;
        nNodes += Hop_DagSize( pNode->pFunc );
    }
    return nNodes;
Alan Mishchenko committed
171 172
}

Alan Mishchenko committed
173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
/**Function*************************************************************

  Synopsis    [Procedure used for sorting the nodes in increasing order of levels.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Nwk_NodeCompareLevelsIncrease( Nwk_Obj_t ** pp1, Nwk_Obj_t ** pp2 )
{
    int Diff = (*pp1)->Level - (*pp2)->Level;
    if ( Diff < 0 )
        return -1;
    if ( Diff > 0 ) 
        return 1;
    return 0; 
}

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

  Synopsis    [Procedure used for sorting the nodes in decreasing order of levels.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
int Nwk_NodeCompareLevelsDecrease( Nwk_Obj_t ** pp1, Nwk_Obj_t ** pp2 )
{
    int Diff = (*pp1)->Level - (*pp2)->Level;
    if ( Diff > 0 )
        return -1;
    if ( Diff < 0 ) 
        return 1;
    return 0; 
}

Alan Mishchenko committed
215 216
/**Function*************************************************************

Alan Mishchenko committed
217
  Synopsis    [Prints the objects.]
Alan Mishchenko committed
218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ObjPrint( Nwk_Obj_t * pObj )
{
    Nwk_Obj_t * pNext;
    int i;
    printf( "ObjId = %5d.  ", pObj->Id );
    if ( Nwk_ObjIsPi(pObj) )
        printf( "PI" );
    if ( Nwk_ObjIsPo(pObj) )
        printf( "PO" );
    if ( Nwk_ObjIsNode(pObj) )
        printf( "Node" );
    printf( "   Fanins = " );
    Nwk_ObjForEachFanin( pObj, pNext, i )
        printf( "%d ", pNext->Id );
    printf( "   Fanouts = " );
    Nwk_ObjForEachFanout( pObj, pNext, i )
        printf( "%d ", pNext->Id );
    printf( "\n" );
}

Alan Mishchenko committed
246 247
/**Function*************************************************************

Alan Mishchenko committed
248
  Synopsis    [Dumps the BLIF file for the network.]
Alan Mishchenko committed
249 250 251 252 253 254 255 256

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
257
void Nwk_ManDumpBlif( Nwk_Man_t * pNtk, char * pFileName, Vec_Ptr_t * vPiNames, Vec_Ptr_t * vPoNames )
Alan Mishchenko committed
258
{
Alan Mishchenko committed
259 260 261 262 263 264 265 266
    FILE * pFile;
    Vec_Ptr_t * vNodes;
    Vec_Int_t * vTruth;
    Vec_Int_t * vCover;
    Nwk_Obj_t * pObj, * pFanin;
    Aig_MmFlex_t * pMem;
    char * pSop = NULL;
    unsigned * pTruth;
Alan Mishchenko committed
267
    int i, k, nDigits;
Alan Mishchenko committed
268 269 270 271 272 273
    if ( Nwk_ManPoNum(pNtk) == 0 )
    {
        printf( "Nwk_ManDumpBlif(): Network does not have POs.\n" );
        return;
    }
    // collect nodes in the DFS order
274
    nDigits = Abc_Base10Log( Nwk_ManObjNumMax(pNtk) );
Alan Mishchenko committed
275 276 277 278 279 280 281 282 283
    // write the file 
    pFile = fopen( pFileName, "w" );
    fprintf( pFile, "# BLIF file written by procedure Nwk_ManDumpBlif()\n" );
//    fprintf( pFile, "# http://www.eecs.berkeley.edu/~alanmi/abc/\n" );
    fprintf( pFile, ".model %s\n", pNtk->pName );
    // write PIs
    fprintf( pFile, ".inputs" );
    Nwk_ManForEachCi( pNtk, pObj, i )
        if ( vPiNames )
Alan Mishchenko committed
284
            fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, i) );
Alan Mishchenko committed
285 286 287 288 289 290 291
        else
            fprintf( pFile, " n%0*d", nDigits, pObj->Id );
    fprintf( pFile, "\n" );
    // write POs
    fprintf( pFile, ".outputs" );
    Nwk_ManForEachCo( pNtk, pObj, i )
        if ( vPoNames )
Alan Mishchenko committed
292
            fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPoNames, i) );
Alan Mishchenko committed
293 294 295 296 297 298 299 300
        else
            fprintf( pFile, " n%0*d", nDigits, pObj->Id );
    fprintf( pFile, "\n" );
    // write nodes
    pMem = Aig_MmFlexStart();
    vTruth = Vec_IntAlloc( 1 << 16 );
    vCover = Vec_IntAlloc( 1 << 16 );
    vNodes = Nwk_ManDfs( pNtk );
301
    Vec_PtrForEachEntry( Nwk_Obj_t *, vNodes, pObj, i )
Alan Mishchenko committed
302 303 304 305 306 307 308 309 310 311 312 313 314 315
    {
        if ( !Nwk_ObjIsNode(pObj) )
            continue;
        // derive SOP for the AIG
        pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 );
        if ( Hop_IsComplement(pObj->pFunc) )
            Kit_TruthNot( pTruth, pTruth, Nwk_ObjFaninNum(pObj) );
        pSop = Kit_PlaFromTruth( pMem, pTruth, Nwk_ObjFaninNum(pObj), vCover );
        // write the node
        fprintf( pFile, ".names" );
        if ( !Kit_TruthIsConst0(pTruth, Nwk_ObjFaninNum(pObj)) && !Kit_TruthIsConst1(pTruth, Nwk_ObjFaninNum(pObj)) )
        {
            Nwk_ObjForEachFanin( pObj, pFanin, k )
                if ( vPiNames && Nwk_ObjIsPi(pFanin) )
Alan Mishchenko committed
316
                    fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, Nwk_ObjPioNum(pFanin)) );
Alan Mishchenko committed
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332
                else
                    fprintf( pFile, " n%0*d", nDigits, pFanin->Id );
        }
        fprintf( pFile, " n%0*d\n", nDigits, pObj->Id );
        // write the function
        fprintf( pFile, "%s", pSop );
    }
    Vec_IntFree( vCover );
    Vec_IntFree( vTruth );
    Vec_PtrFree( vNodes );
    Aig_MmFlexStop( pMem, 0 );
    // write POs
    Nwk_ManForEachCo( pNtk, pObj, i )
    {
        fprintf( pFile, ".names" );
        if ( vPiNames && Nwk_ObjIsPi(Nwk_ObjFanin0(pObj)) )
Alan Mishchenko committed
333
            fprintf( pFile, " %s", (char*)Vec_PtrEntry(vPiNames, Nwk_ObjPioNum(Nwk_ObjFanin0(pObj))) );
Alan Mishchenko committed
334 335 336
        else
            fprintf( pFile, " n%0*d", nDigits, Nwk_ObjFanin0(pObj)->Id );
        if ( vPoNames )
Alan Mishchenko committed
337
            fprintf( pFile, " %s\n", (char*)Vec_PtrEntry(vPoNames, Nwk_ObjPioNum(pObj)) );
Alan Mishchenko committed
338 339 340 341 342 343
        else
            fprintf( pFile, " n%0*d\n", nDigits, pObj->Id );
        fprintf( pFile, "%d 1\n", !pObj->fInvert );
    }
    fprintf( pFile, ".end\n\n" );
    fclose( pFile );
Alan Mishchenko committed
344
}
Alan Mishchenko committed
345

Alan Mishchenko committed
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373
/**Function*************************************************************

  Synopsis    [Prints the distribution of fanins/fanouts in the network.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManPrintFanioNew( Nwk_Man_t * pNtk )
{
    char Buffer[100];
    Nwk_Obj_t * pNode;
    Vec_Int_t * vFanins, * vFanouts;
    int nFanins, nFanouts, nFaninsMax, nFanoutsMax, nFaninsAll, nFanoutsAll;
    int i, k, nSizeMax;

    // determine the largest fanin and fanout
    nFaninsMax = nFanoutsMax = 0;
    nFaninsAll = nFanoutsAll = 0;
    Nwk_ManForEachNode( pNtk, pNode, i )
    {
        nFanins  = Nwk_ObjFaninNum(pNode);
        nFanouts = Nwk_ObjFanoutNum(pNode);
        nFaninsAll  += nFanins;
        nFanoutsAll += nFanouts;
374 375
        nFaninsMax   = Abc_MaxInt( nFaninsMax, nFanins );
        nFanoutsMax  = Abc_MaxInt( nFanoutsMax, nFanouts );
Alan Mishchenko committed
376 377 378
    }

    // allocate storage for fanin/fanout numbers
379
    nSizeMax = Abc_MaxInt( 10 * (Abc_Base10Log(nFaninsMax) + 1), 10 * (Abc_Base10Log(nFanoutsMax) + 1) );
Alan Mishchenko committed
380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430
    vFanins  = Vec_IntStart( nSizeMax );
    vFanouts = Vec_IntStart( nSizeMax );

    // count the number of fanins and fanouts
    Nwk_ManForEachNode( pNtk, pNode, i )
    {
        nFanins  = Nwk_ObjFaninNum(pNode);
        nFanouts = Nwk_ObjFanoutNum(pNode);
//        nFanouts = Nwk_NodeMffcSize(pNode);

        if ( nFanins < 10 )
            Vec_IntAddToEntry( vFanins, nFanins, 1 );
        else if ( nFanins < 100 )
            Vec_IntAddToEntry( vFanins, 10 + nFanins/10, 1 );
        else if ( nFanins < 1000 )
            Vec_IntAddToEntry( vFanins, 20 + nFanins/100, 1 );
        else if ( nFanins < 10000 )
            Vec_IntAddToEntry( vFanins, 30 + nFanins/1000, 1 );
        else if ( nFanins < 100000 )
            Vec_IntAddToEntry( vFanins, 40 + nFanins/10000, 1 );
        else if ( nFanins < 1000000 )
            Vec_IntAddToEntry( vFanins, 50 + nFanins/100000, 1 );
        else if ( nFanins < 10000000 )
            Vec_IntAddToEntry( vFanins, 60 + nFanins/1000000, 1 );

        if ( nFanouts < 10 )
            Vec_IntAddToEntry( vFanouts, nFanouts, 1 );
        else if ( nFanouts < 100 )
            Vec_IntAddToEntry( vFanouts, 10 + nFanouts/10, 1 );
        else if ( nFanouts < 1000 )
            Vec_IntAddToEntry( vFanouts, 20 + nFanouts/100, 1 );
        else if ( nFanouts < 10000 )
            Vec_IntAddToEntry( vFanouts, 30 + nFanouts/1000, 1 );
        else if ( nFanouts < 100000 )
            Vec_IntAddToEntry( vFanouts, 40 + nFanouts/10000, 1 );
        else if ( nFanouts < 1000000 )
            Vec_IntAddToEntry( vFanouts, 50 + nFanouts/100000, 1 );
        else if ( nFanouts < 10000000 )
            Vec_IntAddToEntry( vFanouts, 60 + nFanouts/1000000, 1 );
    }

    printf( "The distribution of fanins and fanouts in the network:\n" );
    printf( "         Number   Nodes with fanin  Nodes with fanout\n" );
    for ( k = 0; k < nSizeMax; k++ )
    {
        if ( vFanins->pArray[k] == 0 && vFanouts->pArray[k] == 0 )
            continue;
        if ( k < 10 )
            printf( "%15d : ", k );
        else
        {
431
            sprintf( Buffer, "%d - %d", (int)pow((double)10, k/10) * (k%10), (int)pow((double)10, k/10) * (k%10+1) - 1 ); 
Alan Mishchenko committed
432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
            printf( "%15s : ", Buffer );
        }
        if ( vFanins->pArray[k] == 0 )
            printf( "              " );
        else
            printf( "%12d  ", vFanins->pArray[k] );
        printf( "    " );
        if ( vFanouts->pArray[k] == 0 )
            printf( "              " );
        else
            printf( "%12d  ", vFanouts->pArray[k] );
        printf( "\n" );
    }
    Vec_IntFree( vFanins );
    Vec_IntFree( vFanouts );

    printf( "Fanins: Max = %d. Ave = %.2f.  Fanouts: Max = %d. Ave =  %.2f.\n", 
        nFaninsMax,  1.0*nFaninsAll/Nwk_ManNodeNum(pNtk), 
        nFanoutsMax, 1.0*nFanoutsAll/Nwk_ManNodeNum(pNtk)  );
}

Alan Mishchenko committed
453 454
/**Function*************************************************************

Alan Mishchenko committed
455
  Synopsis    [Cleans the temporary marks of the nodes.]
Alan Mishchenko committed
456 457 458 459 460 461 462 463 464 465 466 467 468 469 470

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManCleanMarks( Nwk_Man_t * pMan )
{
    Nwk_Obj_t * pObj;
    int i;
    Nwk_ManForEachObj( pMan, pObj, i )
        pObj->MarkA = pObj->MarkB = 0;
}
Alan Mishchenko committed
471

Alan Mishchenko committed
472 473 474 475 476 477 478 479 480 481 482
/**Function*************************************************************

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
483
int Nwk_ManMinimumBaseNode( Nwk_Obj_t * pObj, Vec_Int_t * vTruth, int fVerbose )
Alan Mishchenko committed
484 485
{
    unsigned * pTruth;
Alan Mishchenko committed
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518
    Nwk_Obj_t * pFanin, * pObjNew;
    Nwk_Man_t * pNtk = pObj->pMan;
    int uSupp, nSuppSize, k, Counter = 0;
    pTruth = Hop_ManConvertAigToTruth( pNtk->pManHop, Hop_Regular(pObj->pFunc), Nwk_ObjFaninNum(pObj), vTruth, 0 );
    nSuppSize = Kit_TruthSupportSize(pTruth, Nwk_ObjFaninNum(pObj));
    if ( nSuppSize == Nwk_ObjFaninNum(pObj) )
        return 0;
    Counter++;
    uSupp = Kit_TruthSupport( pTruth, Nwk_ObjFaninNum(pObj) );
    // create new node with the given support
    pObjNew = Nwk_ManCreateNode( pNtk, nSuppSize, Nwk_ObjFanoutNum(pObj) );
    Nwk_ObjForEachFanin( pObj, pFanin, k )
        if ( uSupp & (1 << k) )
            Nwk_ObjAddFanin( pObjNew, pFanin );
    pObjNew->pFunc = Hop_Remap( pNtk->pManHop, pObj->pFunc, uSupp, Nwk_ObjFaninNum(pObj) );
    if ( fVerbose )
        printf( "Reducing node %d fanins from %d to %d.\n", 
            pObj->Id, Nwk_ObjFaninNum(pObj), Nwk_ObjFaninNum(pObjNew) );
    Nwk_ObjReplace( pObj, pObjNew );
    return 1;
}

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

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561
int Nwk_ManMinimumBaseInt( Nwk_Man_t * pNtk, int fVerbose )
{
    Vec_Int_t * vTruth;
    Nwk_Obj_t * pObj;
    int i, Counter = 0;
    vTruth = Vec_IntAlloc( 1 << 16 );
    Nwk_ManForEachNode( pNtk, pObj, i )
        Counter += Nwk_ManMinimumBaseNode( pObj, vTruth, fVerbose );
    if ( fVerbose && Counter )
        printf( "Support minimization reduced support of %d nodes.\n", Counter );
    Vec_IntFree( vTruth );
    return Counter;
}

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

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManMinimumBaseRec( Nwk_Man_t * pNtk, int fVerbose )
{
    int i, clk = clock();
    for ( i = 0; Nwk_ManMinimumBaseInt( pNtk, fVerbose ); i++ );
    ABC_PRT( "Minbase", clock() - clk );
}

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

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
562 563
void Nwk_ManMinimumBase( Nwk_Man_t * pNtk, int fVerbose )
{
Alan Mishchenko committed
564
    Vec_Int_t * vTruth;
Alan Mishchenko committed
565 566
    Nwk_Obj_t * pObj;
    int i, Counter = 0;
Alan Mishchenko committed
567 568
    vTruth = Vec_IntAlloc( 1 << 16 );
    Nwk_ManForEachNode( pNtk, pObj, i )
Alan Mishchenko committed
569
        Counter += Nwk_ManMinimumBaseNode( pObj, vTruth, fVerbose );
Alan Mishchenko committed
570 571 572 573 574
    if ( fVerbose && Counter )
        printf( "Support minimization reduced support of %d nodes.\n", Counter );
    Vec_IntFree( vTruth );
}

Alan Mishchenko committed
575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633
/**Function*************************************************************

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManRemoveDupFaninsNode( Nwk_Obj_t * pObj, int iFan0, int iFan1, Vec_Int_t * vTruth )
{
    Hop_Man_t * pManHop = pObj->pMan->pManHop;
//    Nwk_Obj_t * pFanin0 = pObj->pFanio[iFan0];
//    Nwk_Obj_t * pFanin1 = pObj->pFanio[iFan1];
    assert( pObj->pFanio[iFan0] == pObj->pFanio[iFan1] );
    pObj->pFunc = Hop_Compose( pManHop, pObj->pFunc, Hop_IthVar(pManHop,iFan0), iFan1 );
    Nwk_ManMinimumBaseNode( pObj, vTruth, 0 );
}

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

  Synopsis    [Minimizes the support of all nodes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Nwk_ManRemoveDupFanins( Nwk_Man_t * pNtk, int fVerbose )
{
    Vec_Int_t * vTruth;
    Nwk_Obj_t * pObj;
    int i, k, m, fFound;
    // check if the nodes have duplicated fanins
    vTruth = Vec_IntAlloc( 1 << 16 );
    Nwk_ManForEachNode( pNtk, pObj, i )
    {
        fFound = 0;
        for ( k = 0; k < pObj->nFanins; k++ )
        {
            for ( m = k + 1; m < pObj->nFanins; m++ )
                if ( pObj->pFanio[k] == pObj->pFanio[m] )
                {
                    if ( fVerbose )
                        printf( "Removing duplicated fanins of node %d (fanins %d and %d).\n", 
                            pObj->Id, pObj->pFanio[k]->Id, pObj->pFanio[m]->Id );
                    Nwk_ManRemoveDupFaninsNode( pObj, k, m, vTruth );
                    fFound = 1;
                    break;
                }
            if ( fFound )
                break;
        }
    }
    Vec_IntFree( vTruth );
Alan Mishchenko committed
634
//    Nwk_ManMinimumBase( pNtk, fVerbose );
Alan Mishchenko committed
635 636
}

Alan Mishchenko committed
637 638 639 640 641
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


642 643
ABC_NAMESPACE_IMPL_END