giaMan.c 21.9 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 28 29
#ifdef WIN32
#include <windows.h>
#endif

30 31
ABC_NAMESPACE_IMPL_START

Alan Mishchenko committed
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51

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

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

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

  Synopsis    [Creates AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
52 53
Gia_Man_t * Gia_ManStart( int nObjsMax )
{
Alan Mishchenko committed
54 55 56 57 58 59 60
    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;
61 62
    p->vCis  = Vec_IntAlloc( nObjsMax / 20 );
    p->vCos  = Vec_IntAlloc( nObjsMax / 20 );
Alan Mishchenko committed
63 64 65 66 67 68 69 70 71 72 73 74 75 76
    return p;
}

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

  Synopsis    [Deletes AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

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

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

144 145 146 147 148 149 150 151 152
  Synopsis    [Returns memory used in megabytes.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
153
double Gia_ManMemory( Gia_Man_t * p )
154
{
155
    double Memory = sizeof(Gia_Man_t);
156 157 158 159
    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);
160
    return Memory;
161 162 163 164
}

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

165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183
  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
184 185 186 187 188 189 190 191 192
  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
193
void Gia_ManPrintClasses_old( Gia_Man_t * p )
Alan Mishchenko committed
194 195 196 197 198 199
{
    Gia_Obj_t * pObj;
    int i;
    if ( p->vFlopClasses == NULL )
        return;
    Gia_ManForEachRo( p, pObj, i )
200 201
        Abc_Print( 1, "%d", Vec_IntEntry(p->vFlopClasses, i) );
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
202 203 204 205

    {
        Gia_Man_t * pTemp;
        pTemp = Gia_ManDupFlopClass( p, 1 );
206
        Gia_AigerWrite( pTemp, "dom1.aig", 0, 0 );
Alan Mishchenko committed
207 208
        Gia_ManStop( pTemp );
        pTemp = Gia_ManDupFlopClass( p, 2 );
209
        Gia_AigerWrite( pTemp, "dom2.aig", 0, 0 );
Alan Mishchenko committed
210 211 212 213 214
        Gia_ManStop( pTemp );
    }
}

/**Function*************************************************************
215 216 217 218 219 220 221 222 223 224

  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
Alan Mishchenko committed
225 226 227 228 229 230 231 232 233 234
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;
    }
235
    Abc_Print( 1, "Placement:  Objects = %8d.  Fixed = %8d.  Undef = %8d.\n", Gia_ManObjNum(p), nFixed, nUndef );
Alan Mishchenko committed
236 237
}

238 239 240 241 242 243 244 245 246 247 248 249

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

  Synopsis    [Duplicates AIG for unrolling.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
250
void Gia_ManPrintTents_rec( Gia_Man_t * p, Gia_Obj_t * pObj, Vec_Int_t * vObjs )
251 252 253 254 255 256 257 258 259 260 261
{
    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 );
}
262
void Gia_ManPrintTents( Gia_Man_t * p )
263 264 265 266 267 268 269 270 271 272 273 274 275 276 277
{
    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
278
    Abc_Print( 1, "Tents:  " );
279 280
    for ( t = 1; nSizePrev < Vec_IntSize(vObjs); t++ )
    {
281
        int nPis = 0;
282 283
        nSizeCurr = Vec_IntSize(vObjs);
        Vec_IntForEachEntryStartStop( vObjs, iObjId, i, nSizePrev, nSizeCurr )
284 285
        {
            nPis += Gia_ObjIsPi(p, Gia_ManObj(p, iObjId));
286 287
            if ( Gia_ObjIsRo(p, Gia_ManObj(p, iObjId)) )
                Gia_ManPrintTents_rec( p, Gia_ObjRoToRi(p, Gia_ManObj(p, iObjId)), vObjs );
288
        }
289
        Abc_Print( 1, "%d=%d(%d)  ", t, nSizeCurr - nSizePrev, nPis );
290 291
        nSizePrev = nSizeCurr;
    }
292
    Abc_Print( 1, " Unused=%d\n", Gia_ManObjNum(p) - Vec_IntSize(vObjs) );
293 294 295 296 297 298 299
    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
300 301
/**Function*************************************************************

302 303 304 305 306 307 308 309 310 311 312 313
  Synopsis    []

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintInitClasses( Vec_Int_t * vInits )
{
    int i, Value;
314
    int Counts[6] = {0};
315 316
    Vec_IntForEachEntry( vInits, Value, i )
        Counts[Value]++;
317 318 319 320 321 322 323
    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] );
324 325 326 327 328 329 330 331
    Vec_IntForEachEntry( vInits, Value, i )
    {
        Counts[Value]++;
        if ( Value == 0 )
            printf( "0" );
        else if ( Value == 1 )
            printf( "1" );
        else if ( Value == 2 )
332
            printf( "2" );
333
        else if ( Value == 3 )
334 335 336 337 338
            printf( "3" );
        else if ( Value == 4 )
            printf( "4" );
        else if ( Value == 5 )
            printf( "5" );
339 340 341 342 343 344 345 346
        else assert( 0 );
    }
    printf( "\n" );
    
}

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

Alan Mishchenko committed
347 348 349 350 351 352 353 354 355
  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371
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 );
372
    Gia_ManCleanMark0( p );
373 374 375 376 377 378 379 380 381 382 383 384 385
}

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

  Synopsis    [Prints stats for the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
386
void Gia_ManPrintStats( Gia_Man_t * p, Gps_Par_t * pPars )
Alan Mishchenko committed
387
{
388
    extern float Gia_ManLevelAve( Gia_Man_t * p );
389
    if ( pPars && pPars->fMiter )
390 391 392 393
    {
        Gia_ManPrintStatsMiter( p, 0 );
        return;
    }
394 395
#ifdef WIN32
    SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 15 ); // bright
Alan Mishchenko committed
396
    if ( p->pName )
397
        Abc_Print( 1, "%-8s : ", p->pName );
398 399 400 401 402
    SetConsoleTextAttribute( GetStdHandle(STD_OUTPUT_HANDLE), 7 );  // normal
#else
    if ( p->pName )
        Abc_Print( 1, "%s%-8s%s : ", "\033[1;37m", p->pName, "\033[0m" );  // bright
#endif
403
    Abc_Print( 1, "i/o =%7d/%7d", Gia_ManPiNum(p), Gia_ManPoNum(p) );
404
    if ( Gia_ManConstrNum(p) )
405
        Abc_Print( 1, "(c=%d)", Gia_ManConstrNum(p) );
Alan Mishchenko committed
406
    if ( Gia_ManRegNum(p) )
407
        Abc_Print( 1, "  ff =%7d", Gia_ManRegNum(p) );
408 409 410 411 412

#ifdef WIN32
    {
    HANDLE hConsole = GetStdHandle(STD_OUTPUT_HANDLE);
    SetConsoleTextAttribute( hConsole, 11 ); // blue
413
    Abc_Print( 1, "  %s =%8d", p->pMuxes? "nod" : "and", Gia_ManAndNum(p) );
414
    SetConsoleTextAttribute( hConsole, 13 ); // magenta
415 416
    Abc_Print( 1, "  lev =%5d", Gia_ManLevelNum(p) ); 
    Abc_Print( 1, " (%.2f)", Gia_ManLevelAve(p) ); 
417 418 419 420 421 422 423
    SetConsoleTextAttribute( hConsole, 7 ); // normal
    }
#else
    Abc_Print( 1, "  %s%s =%8d%s",  "\033[1;36m", p->pMuxes? "nod" : "and", Gia_ManAndNum(p), "\033[0m" ); // blue
    Abc_Print( 1, "  %slev =%5d%s", "\033[1;35m", Gia_ManLevelNum(p), "\033[0m" ); // magenta
    Abc_Print( 1, " %s(%.2f)%s",    "\033[1;35m", Gia_ManLevelAve(p), "\033[0m" ); 
#endif
424
    Vec_IntFreeP( &p->vLevels );
425
    if ( pPars && pPars->fCut )
426 427
        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) );
428 429
    if ( Gia_ManHasChoices(p) )
        Abc_Print( 1, "  ch =%5d", Gia_ManChoiceNum(p) );
Alan Mishchenko committed
430 431
    if ( pPars && pPars->fMuxXor )
        printf( "\nXOR/MUX " ), Gia_ManPrintMuxStats( p );
432
    if ( pPars && pPars->fSwitch )
Alan Mishchenko committed
433
    {
434 435 436 437 438 439 440 441
        static int nPiPo = 0;
        static float PrevSwiTotal = 0;
        float SwiTotal = Gia_ManComputeSwitching( p, 48, 16, 0 );
        Abc_Print( 1, "  power =%8.1f", SwiTotal );
        if ( PrevSwiTotal > 0 && nPiPo == Gia_ManCiNum(p) + Gia_ManCoNum(p) )
            Abc_Print( 1, " %6.2f %%", 100.0*(PrevSwiTotal-SwiTotal)/PrevSwiTotal );
        else if ( PrevSwiTotal == 0 || nPiPo != Gia_ManCiNum(p) + Gia_ManCoNum(p) )
            PrevSwiTotal = SwiTotal, nPiPo = Gia_ManCiNum(p) + Gia_ManCoNum(p);
Alan Mishchenko committed
442
    }
443 444
//    Abc_Print( 1, "obj =%5d  ", Gia_ManObjNum(p) );
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
445 446

//    Gia_ManSatExperiment( p );
Alan Mishchenko committed
447 448
    if ( p->pReprs && p->pNexts )
        Gia_ManEquivPrintClasses( p, 0, 0.0 );
449
    if ( Gia_ManHasMapping(p) && (pPars == NULL || !pPars->fSkipMap) )
450
        Gia_ManPrintMappingStats( p, pPars ? pPars->pDumpFile : NULL );
451 452
    if ( pPars && pPars->fNpn && Gia_ManHasMapping(p) && Gia_ManLutSizeMax(p) <= 4 )
        Gia_ManPrintNpnClasses( p );
453 454
    if ( p->vPacking )
        Gia_ManPrintPackingStats( p );
455 456
    if ( pPars && pPars->fLutProf && Gia_ManHasMapping(p) )
        Gia_ManPrintLutStats( p );
Alan Mishchenko committed
457 458
    if ( p->pPlacement )
        Gia_ManPrintPlacement( p );
459
    if ( p->pManTime )
Alan Mishchenko committed
460
        Tim_ManPrintStats( (Tim_Man_t *)p->pManTime, p->nAnd2Delay );
Alan Mishchenko committed
461
    // print register classes
462 463
    Gia_ManPrintFlopClasses( p );
    Gia_ManPrintGateClasses( p );
464
    Gia_ManPrintObjClasses( p );
465 466
    if ( p->vInitClasses )
        Gia_ManPrintInitClasses( p->vInitClasses );
467
    if ( pPars && pPars->fTents )
468
    {
469
/*
470 471 472
        int k, Entry, Prev = 1;
        Vec_Int_t * vLimit = Vec_IntAlloc( 1000 );
        Gia_Man_t * pNew = Gia_ManUnrollDup( p, vLimit );
473
        Abc_Print( 1, "Tents:  " );
474
        Vec_IntForEachEntryStart( vLimit, Entry, k, 1 )
475 476 477
            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" );
478 479
        Vec_IntFree( vLimit );
        Gia_ManStop( pNew );
480
*/
481
        Gia_ManPrintTents( p );
482
    }
Alan Mishchenko committed
483 484 485 486 487 488 489
}

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

  Synopsis    [Prints stats for the AIG.]

  Description []
490

Alan Mishchenko committed
491 492 493 494 495 496 497
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintStatsShort( Gia_Man_t * p )
{
498 499 500 501 502 503
    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
504
}
505

Alan Mishchenko committed
506 507 508 509 510
/**Function*************************************************************

  Synopsis    [Prints stats for the AIG.]

  Description []
511

Alan Mishchenko committed
512 513 514 515 516 517 518 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
  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++;
    }
553
    Abc_Print( 1, "Outputs = %7d.  Unsat = %7d.  Sat = %7d.  Undec = %7d.\n",
Alan Mishchenko committed
554 555 556 557 558
        Gia_ManPoNum(p), nUnsat, nSat, nUndec );
}

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

559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592
  Synopsis    [Statistics of the miter.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManPrintStatsMiter( Gia_Man_t * p, int fVerbose )
{
    Gia_Obj_t * pObj;
    Vec_Flt_t * vProb;
    int i, iObjId;
    Gia_ManLevelNum( p );
    Gia_ManCreateRefs( p );
    vProb = Gia_ManPrintOutputProb( p );
    printf( "Statistics for each outputs of the miter:\n" );
    Gia_ManForEachPo( p, pObj, i )
    {
        iObjId = Gia_ObjId(p, pObj);
        printf( "%4d : ", i );
        printf( "Level = %5d  ",  Gia_ObjLevelId(p, iObjId) );
        printf( "Supp = %5d  ",   Gia_ManSuppSize(p, &iObjId, 1) );
        printf( "Cone = %5d  ",   Gia_ManConeSize(p, &iObjId, 1) );
        printf( "Mffc = %5d  ",   Gia_NodeMffcSize(p, Gia_ObjFanin0(pObj)) );
        printf( "Prob = %8.4f  ", Vec_FltEntry(vProb, iObjId) );
        printf( "\n" );
    }
    Vec_FltFree( vProb );
}

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

Alan Mishchenko committed
593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608
  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
609 610 611 612 613 614 615 616 617 618 619 620 621
/**Function*************************************************************

  Synopsis    [Reports the reduction of the AIG.]

  Description []
               
  SideEffects []

  SeeAlso     []

***********************************************************************/
void Gia_ManReportImprovement( Gia_Man_t * p, Gia_Man_t * pNew )
{
622 623
    Abc_Print( 1, "REG: Beg = %5d. End = %5d. (R =%5.1f %%)  ",
        Gia_ManRegNum(p), Gia_ManRegNum(pNew),
Alan Mishchenko committed
624
        Gia_ManRegNum(p)? 100.0*(Gia_ManRegNum(p)-Gia_ManRegNum(pNew))/Gia_ManRegNum(p) : 0.0 );
625 626
    Abc_Print( 1, "AND: Beg = %6d. End = %6d. (R =%5.1f %%)",
        Gia_ManAndNum(p), Gia_ManAndNum(pNew),
Alan Mishchenko committed
627
        Gia_ManAndNum(p)? 100.0*(Gia_ManAndNum(p)-Gia_ManAndNum(pNew))/Gia_ManAndNum(p) : 0.0 );
628
    Abc_Print( 1, "\n" );
Alan Mishchenko committed
629 630
}

631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649
/**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;
650
    assert( Gia_ManHasMapping(p) );
651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683
    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;
684 685
//        if ( 100.0 * ClassCounts[i] / (nTotal+1) < 0.1 ) // do not show anything below 0.1 percent
//            continue;
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720
        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
721 722 723 724 725
////////////////////////////////////////////////////////////////////////
///                       END OF FILE                                ///
////////////////////////////////////////////////////////////////////////


726
ABC_NAMESPACE_IMPL_END