giaMan.c 19.6 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 21
/**CFile****************************************************************

  FileName    [giaMan.c]

  SystemName  [ABC: Logic synthesis and verification system.]

  PackageName [Scalable AIG package.]

  Synopsis    [Package manager.]

  Author      [Alan Mishchenko]
  
  Affiliation [UC Berkeley]

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

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

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

#include "gia.h"
22
#include "misc/tim/tim.h"
23
#include "proof/abs/abs.h"
24
#include "opt/dar/dar.h"
25 26 27

ABC_NAMESPACE_IMPL_START

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

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

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

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

  Synopsis    [Creates AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
48 49
Gia_Man_t * Gia_ManStart( int nObjsMax )
{
Alan Mishchenko committed
50 51 52 53 54 55 56
    Gia_Man_t * p;
    assert( nObjsMax > 0 );
    p = ABC_CALLOC( Gia_Man_t, 1 );
    p->nObjsAlloc = nObjsMax;
    p->pObjs = ABC_CALLOC( Gia_Obj_t, nObjsMax );
    p->pObjs->iDiff0 = p->pObjs->iDiff1 = GIA_NONE;
    p->nObjs = 1;
57 58
    p->vCis  = Vec_IntAlloc( nObjsMax / 20 );
    p->vCos  = Vec_IntAlloc( nObjsMax / 20 );
Alan Mishchenko committed
59 60 61 62 63 64 65 66 67 68 69 70 71 72
    return p;
}

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

  Synopsis    [Deletes AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
73
void Gia_ManStop( Gia_Man_t * p )
Alan Mishchenko committed
74
{
75 76
    if ( p->vSeqModelVec )
        Vec_PtrFreeFree( p->vSeqModelVec );
77
    Gia_ManStaticFanoutStop( p );
78 79
    Tim_ManStopP( (Tim_Man_t **)&p->pManTime );
    assert( p->pManTime == NULL );
Alan Mishchenko committed
80 81
    Vec_PtrFreeFree( p->vNamesIn );
    Vec_PtrFreeFree( p->vNamesOut );
82
    Vec_IntFreeP( &p->vSwitching );
83 84
    Vec_IntFreeP( &p->vSuper );
    Vec_IntFreeP( &p->vStore );
85 86 87 88
    Vec_IntFreeP( &p->vClassNew );
    Vec_IntFreeP( &p->vClassOld );
    Vec_WrdFreeP( &p->vSims );
    Vec_WrdFreeP( &p->vSimsPi );
89 90 91
    Vec_FltFreeP( &p->vTiming );
    Vec_VecFreeP( &p->vClockDoms );
    Vec_IntFreeP( &p->vLutConfigs );
92 93 94
    Vec_IntFreeP( &p->vUserPiIds );
    Vec_IntFreeP( &p->vUserPoIds );
    Vec_IntFreeP( &p->vUserFfIds );
95
    Vec_IntFreeP( &p->vFlopClasses );
96
    Vec_IntFreeP( &p->vGateClasses );
97
    Vec_IntFreeP( &p->vObjClasses );
98
    Vec_IntFreeP( &p->vInitClasses );
99
    Vec_IntFreeP( &p->vDoms );
100 101
    Vec_IntFreeP( &p->vLevels );
    Vec_IntFreeP( &p->vTruths );
102
    Vec_IntFreeP( &p->vTtNums );
103
    Vec_IntFreeP( &p->vTtNodes );
104
    Vec_WrdFreeP( &p->vTtMemory );
105
    Vec_PtrFreeP( &p->vTtInputs );
106
    Vec_IntFreeP( &p->vMapping );
107 108 109 110
    Vec_IntFreeP( &p->vPacking );
    Vec_FltFreeP( &p->vInArrs );
    Vec_FltFreeP( &p->vOutReqs );
    Gia_ManStopP( &p->pAigExtra );
Alan Mishchenko committed
111 112
    Vec_IntFree( p->vCis );
    Vec_IntFree( p->vCos );
113
    ABC_FREE( p->pData2 );
Alan Mishchenko committed
114
    ABC_FREE( p->pTravIds );
Alan Mishchenko committed
115 116
    ABC_FREE( p->pPlacement );
    ABC_FREE( p->pSwitching );
Alan Mishchenko committed
117
    ABC_FREE( p->pCexSeq );
Alan Mishchenko committed
118 119
    ABC_FREE( p->pCexComb );
    ABC_FREE( p->pIso );
120
//    ABC_FREE( p->pMapping );
Alan Mishchenko committed
121
    ABC_FREE( p->pFanData );
Alan Mishchenko committed
122
    ABC_FREE( p->pReprsOld );
Alan Mishchenko committed
123
    ABC_FREE( p->pReprs );
Alan Mishchenko committed
124
    ABC_FREE( p->pNexts );
125
    ABC_FREE( p->pSibls );
Alan Mishchenko committed
126
    ABC_FREE( p->pRefs );
127
//    ABC_FREE( p->pNodeRefs );
Alan Mishchenko committed
128
    ABC_FREE( p->pHTable );
129
    ABC_FREE( p->pMuxes );
Alan Mishchenko committed
130
    ABC_FREE( p->pObjs );
131 132
    ABC_FREE( p->pSpec );
    ABC_FREE( p->pName );
Alan Mishchenko committed
133 134 135 136 137
    ABC_FREE( p );
}

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

138 139 140 141 142 143 144 145 146
  Synopsis    [Returns memory used in megabytes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
147
double Gia_ManMemory( Gia_Man_t * p )
148
{
149
    double Memory = sizeof(Gia_Man_t);
150 151 152 153
    Memory += sizeof(Gia_Obj_t) * Gia_ManObjNum(p);
    Memory += sizeof(int) * Gia_ManCiNum(p);
    Memory += sizeof(int) * Gia_ManCoNum(p);
    Memory += sizeof(int) * p->nHTable * (p->pHTable != NULL);
154
    return Memory;
155 156 157 158
}

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

159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177
  Synopsis    [Stops the AIG manager.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManStopP( Gia_Man_t ** p )
{
    if ( *p == NULL )
        return;
    Gia_ManStop( *p );
    *p = NULL;
}

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

Alan Mishchenko committed
178 179 180 181 182 183 184 185 186
  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
187
void Gia_ManPrintClasses_old( Gia_Man_t * p )
Alan Mishchenko committed
188 189 190 191 192 193
{
    Gia_Obj_t * pObj;
    int i;
    if ( p->vFlopClasses == NULL )
        return;
    Gia_ManForEachRo( p, pObj, i )
194 195
        Abc_Print( 1, "%d", Vec_IntEntry(p->vFlopClasses, i) );
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
196 197 198 199

    {
        Gia_Man_t * pTemp;
        pTemp = Gia_ManDupFlopClass( p, 1 );
200
        Gia_AigerWrite( pTemp, "dom1.aig", 0, 0 );
Alan Mishchenko committed
201 202
        Gia_ManStop( pTemp );
        pTemp = Gia_ManDupFlopClass( p, 2 );
203
        Gia_AigerWrite( pTemp, "dom2.aig", 0, 0 );
Alan Mishchenko committed
204 205 206 207 208
        Gia_ManStop( pTemp );
    }
}

/**Function*************************************************************
209 210 211 212 213 214 215 216 217 218

  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
219 220 221 222 223 224 225 226 227 228
void Gia_ManPrintPlacement( Gia_Man_t * p )
{
    int i, nFixed = 0, nUndef = 0;
    if ( p->pPlacement == NULL )
        return;
    for ( i = 0; i < Gia_ManObjNum(p); i++ )
    {
        nFixed += p->pPlacement[i].fFixed;
        nUndef += p->pPlacement[i].fUndef;
    }
229
    Abc_Print( 1, "Placement:  Objects = %8d.  Fixed = %8d.  Undef = %8d.\n", Gia_ManObjNum(p), nFixed, nUndef );
Alan Mishchenko committed
230 231
}

232 233 234 235 236 237 238 239 240 241 242 243

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

  Synopsis    [Duplicates AIG for unrolling.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
244
void Gia_ManPrintTents_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vObjs )
245 246 247 248 249 250 251 252 253 254 255
{
    if ( Gia_ObjIsTravIdCurrent(p, pObj) )
        return;
    Gia_ObjSetTravIdCurrent(p, pObj);
    Vec_IntPush( vObjs, Gia_ObjId(p, pObj) );
    if ( Gia_ObjIsCi(pObj) )
        return;
    Gia_ManPrintTents_rec( p, Gia_ObjFanin0(pObj), vObjs );
    if ( Gia_ObjIsAnd(pObj) )
        Gia_ManPrintTents_rec( p, Gia_ObjFanin1(pObj), vObjs );
}
256
void Gia_ManPrintTents( Gia_Man_t * p )
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271
{
    Vec_Int_t * vObjs;
    Gia_Obj_t * pObj;
    int t, i, iObjId, nSizePrev, nSizeCurr;
    assert( Gia_ManPoNum(p) > 0 );
    vObjs = Vec_IntAlloc( 100 );
    // save constant class
    Gia_ManIncrementTravId( p );
    Gia_ObjSetTravIdCurrent( p, Gia_ManConst0(p) );
    Vec_IntPush( vObjs, 0 );
    // create starting root
    nSizePrev = Vec_IntSize(vObjs);
    Gia_ManForEachPo( p, pObj, i )
        Gia_ManPrintTents_rec( p, pObj, vObjs );
    // build tents
272
    Abc_Print( 1, "Tents:  " );
273 274
    for ( t = 1; nSizePrev < Vec_IntSize(vObjs); t++ )
    {
275
        int nPis = 0;
276 277
        nSizeCurr = Vec_IntSize(vObjs);
        Vec_IntForEachEntryStartStop( vObjs, iObjId, i, nSizePrev, nSizeCurr )
278 279
        {
            nPis += Gia_ObjIsPi(p, Gia_ManObj(p, iObjId));
280 281
            if ( Gia_ObjIsRo(p, Gia_ManObj(p, iObjId)) )
                Gia_ManPrintTents_rec( p, Gia_ObjRoToRi(p, Gia_ManObj(p, iObjId)), vObjs );
282
        }
283
        Abc_Print( 1, "%d=%d(%d)  ", t, nSizeCurr - nSizePrev, nPis );
284 285
        nSizePrev = nSizeCurr;
    }
286
    Abc_Print( 1, " Unused=%d\n", Gia_ManObjNum(p) - Vec_IntSize(vObjs) );
287 288 289 290 291 292 293
    Vec_IntFree( vObjs );
    // the remaining objects are PIs without fanout
//    Gia_ManForEachObj( p, pObj, i )
//        if ( !Gia_ObjIsTravIdCurrent(p, pObj) )
//            Gia_ObjPrint( p, pObj );
}

Alan Mishchenko committed
294 295
/**Function*************************************************************

296 297 298 299 300 301 302 303 304 305 306 307
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintInitClasses( Vec_Int_t * vInits )
{
    int i, Value;
308
    int Counts[6] = {0};
309 310
    Vec_IntForEachEntry( vInits, Value, i )
        Counts[Value]++;
311 312 313 314 315 316 317
    for ( i = 0; i < 6; i++ )
        if ( Counts[i] )
            printf( "%d = %d  ", i, Counts[i] );
    printf( "  " );
    printf( "B = %d  ", Counts[0] + Counts[1] );
    printf( "X = %d  ", Counts[2] + Counts[3] );
    printf( "Q = %d\n", Counts[4] + Counts[5] );
318 319 320 321 322 323 324 325
    Vec_IntForEachEntry( vInits, Value, i )
    {
        Counts[Value]++;
        if ( Value == 0 )
            printf( "0" );
        else if ( Value == 1 )
            printf( "1" );
        else if ( Value == 2 )
326
            printf( "2" );
327
        else if ( Value == 3 )
328 329 330 331 332
            printf( "3" );
        else if ( Value == 4 )
            printf( "4" );
        else if ( Value == 5 )
            printf( "5" );
333 334 335 336 337 338 339 340
        else assert( 0 );
    }
    printf( "\n" );
    
}

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

Alan Mishchenko committed
341 342 343 344 345 346 347 348 349
  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365
void Gia_ManPrintChoiceStats( Gia_Man_t * p )
{
    Gia_Obj_t * pObj;
    int i, nEquivs = 0, nChoices = 0;
    Gia_ManMarkFanoutDrivers( p );
    Gia_ManForEachAnd( p, pObj, i )
    {
        if ( !Gia_ObjSibl(p, i) )
            continue;
        nEquivs++;
        if ( pObj->fMark0 )
            nChoices++;
        assert( !Gia_ObjSiblObj(p, i)->fMark0 );
        assert( Gia_ObjIsAnd(Gia_ObjSiblObj(p, i)) );
    }
    Abc_Print( 1, "Choice stats: Equivs =%7d. Choices =%7d.\n", nEquivs, nChoices );
366
    Gia_ManCleanMark0( p );
367 368 369 370 371 372 373 374 375 376 377 378 379
}

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

  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
380
void Gia_ManPrintStats( Gia_Man_t * p, Gps_Par_t * pPars )
Alan Mishchenko committed
381 382
{
    if ( p->pName )
383 384
        Abc_Print( 1, "%-8s : ", p->pName );
    Abc_Print( 1, "i/o =%7d/%7d", Gia_ManPiNum(p), Gia_ManPoNum(p) );
385
    if ( Gia_ManConstrNum(p) )
386
        Abc_Print( 1, "(c=%d)", Gia_ManConstrNum(p) );
Alan Mishchenko committed
387
    if ( Gia_ManRegNum(p) )
388
        Abc_Print( 1, "  ff =%7d", Gia_ManRegNum(p) );
389
    Abc_Print( 1, "  %s =%8d", p->pMuxes? "nod" : "and", Gia_ManAndNum(p) );
390
    Abc_Print( 1, "  lev =%5d", Gia_ManLevelNum(p) ); Vec_IntFreeP( &p->vLevels );
391
    if ( pPars && pPars->fCut )
392 393
        Abc_Print( 1, "  cut = %d(%d)", Gia_ManCrossCut(p, 0), Gia_ManCrossCut(p, 1) );
    Abc_Print( 1, "  mem =%5.2f MB", Gia_ManMemory(p)/(1<<20) );
394
    if ( Gia_ManHasDangling(p) )
395
        Abc_Print( 1, "  ch =%5d", Gia_ManEquivCountClasses(p) );
396 397 398 399 400 401
    if ( p->pMuxes )
    {
        Abc_Print( 1, "  and =%5d", Gia_ManAndNum(p)-Gia_ManXorNum(p)-Gia_ManMuxNum(p) );
        Abc_Print( 1, "  xor =%5d", Gia_ManXorNum(p) );
        Abc_Print( 1, "  mux =%5d", Gia_ManMuxNum(p) );
    }
402
    if ( pPars && pPars->fSwitch )
Alan Mishchenko committed
403 404
    {
        if ( p->pSwitching )
405
            Abc_Print( 1, "  power =%7.2f", Gia_ManEvaluateSwitching(p) );
Alan Mishchenko committed
406
        else
407
            Abc_Print( 1, "  power =%7.2f", Gia_ManComputeSwitching(p, 48, 16, 0) );
Alan Mishchenko committed
408
    }
409 410
//    Abc_Print( 1, "obj =%5d  ", Gia_ManObjNum(p) );
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
411 412

//    Gia_ManSatExperiment( p );
Alan Mishchenko committed
413 414
    if ( p->pReprs && p->pNexts )
        Gia_ManEquivPrintClasses( p, 0, 0.0 );
415 416
    if ( p->pSibls )
        Gia_ManPrintChoiceStats( p );
417
    if ( Gia_ManHasMapping(p) )
418
        Gia_ManPrintMappingStats( p, pPars ? pPars->pDumpFile : NULL );
419 420
    if ( pPars && pPars->fNpn && Gia_ManHasMapping(p) && Gia_ManLutSizeMax(p) <= 4 )
        Gia_ManPrintNpnClasses( p );
421 422
    if ( p->vPacking )
        Gia_ManPrintPackingStats( p );
423 424
    if ( pPars && pPars->fLutProf && Gia_ManHasMapping(p) )
        Gia_ManPrintLutStats( p );
Alan Mishchenko committed
425 426
    if ( p->pPlacement )
        Gia_ManPrintPlacement( p );
427
    if ( p->pManTime )
Alan Mishchenko committed
428
        Tim_ManPrintStats( (Tim_Man_t *)p->pManTime, p->nAnd2Delay );
Alan Mishchenko committed
429
    // print register classes
430 431
    Gia_ManPrintFlopClasses( p );
    Gia_ManPrintGateClasses( p );
432
    Gia_ManPrintObjClasses( p );
433 434
    if ( p->vInitClasses )
        Gia_ManPrintInitClasses( p->vInitClasses );
435
    if ( pPars && pPars->fTents )
436
    {
437
/*
438 439 440
        int k, Entry, Prev = 1;
        Vec_Int_t * vLimit = Vec_IntAlloc( 1000 );
        Gia_Man_t * pNew = Gia_ManUnrollDup( p, vLimit );
441
        Abc_Print( 1, "Tents:  " );
442
        Vec_IntForEachEntryStart( vLimit, Entry, k, 1 )
443 444 445
            Abc_Print( 1, "%d=%d  ", k, Entry-Prev ), Prev = Entry;
        Abc_Print( 1, " Unused=%d.", Gia_ManObjNum(p) - Gia_ManObjNum(pNew) );
        Abc_Print( 1, "\n" );
446 447
        Vec_IntFree( vLimit );
        Gia_ManStop( pNew );
448
*/
449
        Gia_ManPrintTents( p );
450
    }
Alan Mishchenko committed
451 452 453 454 455 456 457
}

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

  Synopsis    [Prints stats for the AIG.]

  Description []
458

Alan Mishchenko committed
459 460 461 462 463 464 465
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintStatsShort( Gia_Man_t * p )
{
466 467 468 469 470 471
    Abc_Print( 1, "i/o =%7d/%7d  ", Gia_ManPiNum(p), Gia_ManPoNum(p) );
    Abc_Print( 1, "ff =%7d  ", Gia_ManRegNum(p) );
    Abc_Print( 1, "and =%8d  ", Gia_ManAndNum(p) );
    Abc_Print( 1, "lev =%5d  ", Gia_ManLevelNum(p) );
//    Abc_Print( 1, "mem =%5.2f MB", 12.0*Gia_ManObjNum(p)/(1<<20) );
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
472
}
473

Alan Mishchenko committed
474 475 476 477 478
/**Function*************************************************************

  Synopsis    [Prints stats for the AIG.]

  Description []
479

Alan Mishchenko committed
480 481 482 483 484 485 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 519 520
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintMiterStatus( Gia_Man_t * p )
{
    Gia_Obj_t * pObj, * pChild;
    int i, nSat = 0, nUnsat = 0, nUndec = 0, iOut = -1;
    Gia_ManForEachPo( p, pObj, i )
    {
        pChild = Gia_ObjChild0(pObj);
        // check if the output is constant 0
        if ( pChild == Gia_ManConst0(p) )
            nUnsat++;
        // check if the output is constant 1
        else if ( pChild == Gia_ManConst1(p) )
        {
            nSat++;
            if ( iOut == -1 )
                iOut = i;
        }
        // check if the output is a primary input
        else if ( Gia_ObjIsPi(p, Gia_Regular(pChild)) )
        {
            nSat++;
            if ( iOut == -1 )
                iOut = i;
        }
/*
        // check if the output is 1 for the 0000 pattern
        else if ( Gia_Regular(pChild)->fPhase != (unsigned)Gia_IsComplement(pChild) )
        {
            nSat++;
            if ( iOut == -1 )
                iOut = i;
        }
*/
        else
            nUndec++;
    }
521
    Abc_Print( 1, "Outputs = %7d.  Unsat = %7d.  Sat = %7d.  Undec = %7d.\n",
Alan Mishchenko committed
522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542
        Gia_ManPoNum(p), nUnsat, nSat, nUndec );
}

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

  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManSetRegNum( Gia_Man_t * p, int nRegs )
{
    assert( p->nRegs == 0 );
    p->nRegs = nRegs;
}


Alan Mishchenko committed
543 544 545 546 547 548 549 550 551 552 553 554 555
/**Function*************************************************************

  Synopsis    [Reports the reduction of the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManReportImprovement( Gia_Man_t * p, Gia_Man_t * pNew )
{
556 557
    Abc_Print( 1, "REG: Beg = %5d. End = %5d. (R =%5.1f %%)  ",
        Gia_ManRegNum(p), Gia_ManRegNum(pNew),
Alan Mishchenko committed
558
        Gia_ManRegNum(p)? 100.0*(Gia_ManRegNum(p)-Gia_ManRegNum(pNew))/Gia_ManRegNum(p) : 0.0 );
559 560
    Abc_Print( 1, "AND: Beg = %6d. End = %6d. (R =%5.1f %%)",
        Gia_ManAndNum(p), Gia_ManAndNum(pNew),
Alan Mishchenko committed
561
        Gia_ManAndNum(p)? 100.0*(Gia_ManAndNum(p)-Gia_ManAndNum(pNew))/Gia_ManAndNum(p) : 0.0 );
562
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
563 564
}

565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583
/**Function*************************************************************

  Synopsis    [Prints NPN class statistics.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintNpnClasses( Gia_Man_t * p )
{
    extern char ** Kit_DsdNpn4ClassNames();
    char ** pNames = Kit_DsdNpn4ClassNames();
    Vec_Int_t * vLeaves, * vTruth, * vVisited;
    int * pLutClass, ClassCounts[222] = {0};
    int i, k, iFan, Class, OtherClasses, OtherClasses2, nTotal, Counter, Counter2;
    unsigned * pTruth;
584
    assert( Gia_ManHasMapping(p) );
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
    assert(  Gia_ManLutSizeMax( p ) <= 4 );
    vLeaves   = Vec_IntAlloc( 100 );
    vVisited  = Vec_IntAlloc( 100 );
    vTruth    = Vec_IntAlloc( (1<<16) );
    pLutClass = ABC_CALLOC( int, Gia_ManObjNum(p) );
    Gia_ManCleanTruth( p );
    Gia_ManForEachLut( p, i )
    {
        if ( Gia_ObjLutSize(p,i) > 4 )
            continue;
        Vec_IntClear( vLeaves );
        Gia_LutForEachFanin( p, i, iFan, k )
            Vec_IntPush( vLeaves, iFan );
        for ( ; k < 4; k++ )
            Vec_IntPush( vLeaves, 0 );
        pTruth = Gia_ManConvertAigToTruth( p, Gia_ManObj(p, i), vLeaves, vTruth, vVisited );
        Class = Dar_LibReturnClass( *pTruth );
        ClassCounts[ Class ]++;
        pLutClass[i] = Class;
    }
    Vec_IntFree( vLeaves );
    Vec_IntFree( vTruth );
    Vec_IntFree( vVisited );
    Vec_IntFreeP( &p->vTruths );
    nTotal = 0;
    for ( i = 0; i < 222; i++ )
        nTotal += ClassCounts[i];
    Abc_Print( 1, "NPN CLASS STATISTICS (for %d LUT4 present in the current mapping):\n", nTotal );
    OtherClasses = 0;
    for ( i = 0; i < 222; i++ )
    {
        if ( ClassCounts[i] == 0 )
            continue;
618 619
//        if ( 100.0 * ClassCounts[i] / (nTotal+1) < 0.1 ) // do not show anything below 0.1 percent
//            continue;
620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654
        OtherClasses += ClassCounts[i];
        Abc_Print( 1, "Class %3d :  Count = %6d   (%7.2f %%)   %s\n", 
            i, ClassCounts[i], 100.0 * ClassCounts[i] / (nTotal+1), pNames[i] );
    }
    OtherClasses = nTotal - OtherClasses;
    Abc_Print( 1, "Other     :  Count = %6d   (%7.2f %%)\n", 
        OtherClasses, 100.0 * OtherClasses / (nTotal+1) );
    // count the number of LUTs that have MUX function and two fanins with MUX functions
    OtherClasses = OtherClasses2 = 0;
    ABC_FREE( p->pRefs );
    Gia_ManSetRefsMapped( p );
    Gia_ManForEachLut( p, i )
    {
        if ( pLutClass[i] != 109 )
            continue;
        Counter = Counter2 = 0;
        Gia_LutForEachFanin( p, i, iFan, k )
        {
            Counter  += (pLutClass[iFan] == 109);
            Counter2 += (pLutClass[iFan] == 109) && (Gia_ObjRefNumId(p, iFan) == 1);
        }
        OtherClasses  += (Counter > 1);
        OtherClasses2 += (Counter2 > 1);
//            Abc_Print( 1, "%d -- ", pLutClass[i] );
//            Gia_LutForEachFanin( p, i, iFan, k )
//                Abc_Print( 1, "%d ", pLutClass[iFan] );
//            Abc_Print( 1, "\n" );
    }
    ABC_FREE( p->pRefs );
    Abc_Print( 1, "Approximate number of 4:1 MUX structures: All = %6d  (%7.2f %%)  MFFC = %6d  (%7.2f %%)\n", 
        OtherClasses,  100.0 * OtherClasses  / (nTotal+1),
        OtherClasses2, 100.0 * OtherClasses2 / (nTotal+1) );
    ABC_FREE( pLutClass );
}

Alan Mishchenko committed
655 656 657 658 659
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


660
ABC_NAMESPACE_IMPL_END