ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaBalLut.c File Reference
#include "gia.h"
#include "misc/vec/vecHash.h"
#include "misc/vec/vecQue.h"
#include "opt/dau/dau.h"
Include dependency graph for giaBalLut.c:

Go to the source code of this file.

Classes

struct  Bal_Cut_t_
 
struct  Bal_Man_t_
 

Macros

#define BAL_LEAF_MAX   6
 DECLARATIONS ///.
 
#define BAL_CUT_MAX   8
 
#define BAL_SUPER   50
 
#define BAL_NO_LEAF   31
 
#define BAL_NO_FUNC   134217727
 

Typedefs

typedef struct Bal_Cut_t_ Bal_Cut_t
 
typedef struct Bal_Man_t_ Bal_Man_t
 

Functions

Bal_Man_tBal_ManAlloc (Gia_Man_t *pGia, Gia_Man_t *pNew, int nLutSize, int nCutNum, int fVerbose)
 FUNCTION DEFINITIONS ///.
 
void Bal_ManFree (Bal_Man_t *p)
 
int Bal_ManDeriveCuts (Bal_Man_t *p, int iFan0, int iFan1, int iFan2, int fCompl0, int fCompl1, int fCompl2, int fUnit0, int fUnit1, int fUnit2, int fIsXor, int Target, int fSave)
 
int Bal_ManSetGateLevel (Bal_Man_t *p, Gia_Obj_t *pObjOld, int iLitNew)
 
int Bal_ManEvalTwo (Bal_Man_t *p, int iLitNew0, int iLitNew1, int iLitNew2, int fIsXor)
 
Gia_Man_tGia_ManBalanceLut (Gia_Man_t *p, int nLutSize, int nCutNum, int fVerbose)
 

Macro Definition Documentation

◆ BAL_CUT_MAX

#define BAL_CUT_MAX   8

Definition at line 34 of file giaBalLut.c.

◆ BAL_LEAF_MAX

#define BAL_LEAF_MAX   6

DECLARATIONS ///.

CFile****************************************************************

FileName [giaBalance.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [AIG balancing.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

Id
giaBalance.c,v 1.00 2005/06/20 00:00:00 alanmi Exp

]

Definition at line 33 of file giaBalLut.c.

◆ BAL_NO_FUNC

#define BAL_NO_FUNC   134217727

Definition at line 37 of file giaBalLut.c.

◆ BAL_NO_LEAF

#define BAL_NO_LEAF   31

Definition at line 36 of file giaBalLut.c.

◆ BAL_SUPER

#define BAL_SUPER   50

Definition at line 35 of file giaBalLut.c.

Typedef Documentation

◆ Bal_Cut_t

typedef struct Bal_Cut_t_ Bal_Cut_t

Definition at line 39 of file giaBalLut.c.

◆ Bal_Man_t

typedef struct Bal_Man_t_ Bal_Man_t

Definition at line 50 of file giaBalLut.c.

Function Documentation

◆ Bal_ManAlloc()

Bal_Man_t * Bal_ManAlloc ( Gia_Man_t * pGia,
Gia_Man_t * pNew,
int nLutSize,
int nCutNum,
int fVerbose )

FUNCTION DEFINITIONS ///.

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 86 of file giaBalLut.c.

87{
88 Bal_Man_t * p;
89 p = ABC_CALLOC( Bal_Man_t, 1 );
90 p->clkStart = Abc_Clock();
91 p->pGia = pGia;
92 p->pNew = pNew;
93 p->nLutSize = nLutSize;
94 p->nCutNum = nCutNum;
95 p->fVerbose = fVerbose;
96 p->vCosts = Vec_IntAlloc( 3 * Gia_ManObjNum(pGia) / 2 );
97 p->vCutSets = Vec_PtrAlloc( 3 * Gia_ManObjNum(pGia) / 2 );
98 Vec_IntFill( p->vCosts, Gia_ManObjNum(pNew), 0 );
99 Vec_PtrFill( p->vCutSets, Gia_ManObjNum(pNew), NULL );
100 pNew->pData = p;
101 return p;
102}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
Cube * p
Definition exorList.c:222
struct Bal_Man_t_ Bal_Man_t
Definition giaBalLut.c:50
void * pData
Definition gia.h:198

◆ Bal_ManDeriveCuts()

int Bal_ManDeriveCuts ( Bal_Man_t * p,
int iFan0,
int iFan1,
int iFan2,
int fCompl0,
int fCompl1,
int fCompl2,
int fUnit0,
int fUnit1,
int fUnit2,
int fIsXor,
int Target,
int fSave )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 402 of file giaBalLut.c.

403{
404 Bal_Cut_t pCutSet[BAL_CUT_MAX], * pCutsR[BAL_CUT_MAX];
405 Bal_Cut_t * pCutSet0, * pCutSet1, * pCutSet2;
406 int nCuts0 = Bal_ManPrepareSet( p, iFan0, 0, fUnit0, &pCutSet0 );
407 int nCuts1 = Bal_ManPrepareSet( p, iFan1, 1, fUnit1, &pCutSet1 );
408 Bal_Cut_t * pCut0, * pCut0Lim = pCutSet0 + nCuts0;
409 Bal_Cut_t * pCut1, * pCut1Lim = pCutSet1 + nCuts1;
410 int i, Cost, nCutsR = 0;
411 memset( pCutSet, 0, sizeof(Bal_Cut_t) * p->nCutNum );
412 for ( i = 0; i < p->nCutNum; i++ )
413 pCutsR[i] = pCutSet + i;
414 // enumerate cuts
415 if ( iFan2 > 0 )
416 {
417 int nCuts2 = Bal_ManPrepareSet( p, iFan2, 2, fUnit2, &pCutSet2 );
418 Bal_Cut_t * pCut2, * pCut2Lim = pCutSet2 + nCuts2;
419 for ( pCut0 = pCutSet0; pCut0 < pCut0Lim; pCut0++ )
420 for ( pCut1 = pCutSet1; pCut1 < pCut1Lim; pCut1++ )
421 for ( pCut2 = pCutSet2; pCut2 < pCut2Lim; pCut2++ )
422 {
423 if ( Bal_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > p->nLutSize )
424 continue;
425 if ( !Bal_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], p->nLutSize) )
426 continue;
427 assert( pCutsR[nCutsR]->Delay == Target );
428 if ( Bal_SetLastCutIsContained(pCutsR, nCutsR) )
429 continue;
430// if ( p->fCutMin && Bal_CutComputeTruthMux(p, pCut0, pCut1, pCut2, fCompl0, fCompl1, fCompl2, pCutsR[nCutsR]) )
431// pCutsR[nCutsR]->Sign = Bal_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
432 nCutsR = Bal_SetAddCut( pCutsR, nCutsR, p->nCutNum );
433 }
434 }
435 else
436 {
437 for ( pCut0 = pCutSet0; pCut0 < pCut0Lim; pCut0++ )
438 for ( pCut1 = pCutSet1; pCut1 < pCut1Lim; pCut1++ )
439 {
440 if ( Bal_CutCountBits(pCut0->Sign | pCut1->Sign) > p->nLutSize )
441 continue;
442 if ( !Bal_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], p->nLutSize) )
443 continue;
444 assert( pCutsR[nCutsR]->Delay == Target );
445 if ( Bal_SetLastCutIsContained(pCutsR, nCutsR) )
446 continue;
447// if ( p->fCutMin && Bal_CutComputeTruth(p, pCut0, pCut1, fCompl0, fCompl1, pCutsR[nCutsR], fIsXor) )
448// pCutsR[nCutsR]->Sign = Bal_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
449 nCutsR = Bal_SetAddCut( pCutsR, nCutsR, p->nCutNum );
450 }
451 }
452 if ( nCutsR == 0 )
453 return -1;
454//printf( "%d ", nCutsR );
455 Cost = ((pCutsR[0]->Delay << 4) | pCutsR[0]->nLeaves);
456 // verify
457 assert( nCutsR > 0 && nCutsR < p->nCutNum );
458 assert( Bal_SetCheckArray(pCutsR, nCutsR) );
459 // save cuts
460 if ( fSave && Cost >= 0 )
461 {
462 pCutSet0 = ABC_CALLOC( Bal_Cut_t, p->nCutNum );
463 Vec_PtrPush( p->vCutSets, pCutSet0 );
464 assert( Vec_PtrSize(p->vCutSets) == Gia_ManObjNum(p->pNew) );
465 for ( i = 0; i < nCutsR; i++ )
466 pCutSet0[i] = *pCutsR[i];
467 for ( ; i < p->nCutNum; i++ )
468 pCutSet0[i].nLeaves = BAL_NO_LEAF;
469 Vec_IntPush( p->vCosts, Cost );
470 assert( Vec_IntSize(p->vCosts) == Gia_ManObjNum(p->pNew) );
471 }
472 return Cost;
473}
#define BAL_NO_LEAF
Definition giaBalLut.c:36
struct Bal_Cut_t_ Bal_Cut_t
Definition giaBalLut.c:39
#define BAL_CUT_MAX
Definition giaBalLut.c:34
unsigned nLeaves
Definition giaBalLut.c:45
word Sign
Definition giaBalLut.c:42
#define assert(ex)
Definition util_old.h:213
char * memset()
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Bal_ManEvalTwo()

int Bal_ManEvalTwo ( Bal_Man_t * p,
int iLitNew0,
int iLitNew1,
int iLitNew2,
int fIsXor )

Definition at line 526 of file giaBalLut.c.

527{
528 int iFan0 = Abc_Lit2Var( iLitNew0 );
529 int iFan1 = Abc_Lit2Var( iLitNew1 );
530 int iFan2 = Abc_Lit2Var( iLitNew2 );
531 int fCompl0 = Abc_LitIsCompl( iLitNew0 );
532 int fCompl1 = Abc_LitIsCompl( iLitNew1 );
533 int fCompl2 = Abc_LitIsCompl( iLitNew2 );
534 int Delay0 = Bal_ObjDelay( p, iFan0 );
535 int Delay1 = Bal_ObjDelay( p, iFan1 );
536 int Delay2 = Bal_ObjDelay( p, iFan2 );
537 int DelayMax = Abc_MaxInt( Delay0, Abc_MaxInt(Delay1, Delay2) );
538 int fUnit0 = (int)(Delay0 != DelayMax);
539 int fUnit1 = (int)(Delay1 != DelayMax);
540 int fUnit2 = (int)(Delay2 != DelayMax);
541 if ( DelayMax == 0 )
542 return -1;
543 return Bal_ManDeriveCuts(p, iFan0, iFan1, iFan2, fCompl0, fCompl1, fCompl2, fUnit0, fUnit1, fUnit2, fIsXor, DelayMax, 0 );
544}
int Bal_ManDeriveCuts(Bal_Man_t *p, int iFan0, int iFan1, int iFan2, int fCompl0, int fCompl1, int fCompl2, int fUnit0, int fUnit1, int fUnit2, int fIsXor, int Target, int fSave)
Definition giaBalLut.c:402
Here is the call graph for this function:

◆ Bal_ManFree()

void Bal_ManFree ( Bal_Man_t * p)

Definition at line 103 of file giaBalLut.c.

104{
105 Vec_PtrFreeFree( p->vCutSets );
106 Vec_IntFree( p->vCosts );
107 ABC_FREE( p );
108}
#define ABC_FREE(obj)
Definition abc_global.h:267

◆ Bal_ManSetGateLevel()

int Bal_ManSetGateLevel ( Bal_Man_t * p,
Gia_Obj_t * pObjOld,
int iLitNew )

Function*************************************************************

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 486 of file giaBalLut.c.

487{
488 int iFan0, iFan1, iFan2, Cost;
489 int fCompl0, fCompl1, fCompl2;
490 int fUnit0, fUnit1, fUnit2;
491 int Delay0, Delay1, Delay2, DelayMax;
492 int iObjNew = Abc_Lit2Var(iLitNew);
493 Gia_Obj_t * pObjNew = Gia_ManObj( p->pNew, iObjNew );
494 int fMux = Gia_ObjIsMux(p->pNew, pObjNew);
495 if ( iObjNew < Vec_PtrSize(p->vCutSets) )
496 return -1;
497 iFan0 = Gia_ObjFaninId0( pObjNew, iObjNew );
498 iFan1 = Gia_ObjFaninId1( pObjNew, iObjNew );
499 iFan2 = fMux ? Gia_ObjFaninId2(p->pNew, iObjNew) : 0;
500 fCompl0 = Gia_ObjFaninC0( pObjNew );
501 fCompl1 = Gia_ObjFaninC1( pObjNew );
502 fCompl2 = fMux ? Gia_ObjFaninC2(p->pNew, pObjNew) : 0;
503 Delay0 = Bal_ObjDelay( p, iFan0 );
504 Delay1 = Bal_ObjDelay( p, iFan1 );
505 Delay2 = Bal_ObjDelay( p, iFan2 );
506 DelayMax = Abc_MaxInt( Delay0, Abc_MaxInt(Delay1, Delay2) );
507 fUnit0 = (int)(Delay0 != DelayMax);
508 fUnit1 = (int)(Delay1 != DelayMax);
509 fUnit2 = (int)(Delay2 != DelayMax);
510 if ( DelayMax > 0 )
511 {
512//printf( "A" );
513 Cost = Bal_ManDeriveCuts(p, iFan0, iFan1, iFan2, fCompl0, fCompl1, fCompl2, fUnit0, fUnit1, fUnit2, Gia_ObjIsXor(pObjNew), DelayMax, 1 );
514//printf( "B" );
515 if ( Cost >= 0 )
516 return Cost;
517 }
518 DelayMax++;
519 fUnit0 = fUnit1 = fUnit2 = 1;
520//printf( "A" );
521 Cost = Bal_ManDeriveCuts(p, iFan0, iFan1, iFan2, fCompl0, fCompl1, fCompl2, fUnit0, fUnit1, fUnit2, Gia_ObjIsXor(pObjNew), DelayMax, 1 );
522//printf( "B" );
523 assert( Cost >= 0 );
524 return Cost;
525}
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
Here is the call graph for this function:

◆ Gia_ManBalanceLut()

Gia_Man_t * Gia_ManBalanceLut ( Gia_Man_t * p,
int nLutSize,
int nCutNum,
int fVerbose )

Definition at line 959 of file giaBalLut.c.

960{
961 Gia_Man_t * pNew, * pNew1, * pNew2;
962 if ( fVerbose ) Gia_ManPrintStats( p, NULL );
963 pNew = Gia_ManDupMuxes( p, 2 );
964 if ( fVerbose ) Gia_ManPrintStats( pNew, NULL );
965 pNew1 = Gia_ManBalanceInt( pNew, nLutSize, nCutNum, fVerbose );
966 if ( fVerbose ) Gia_ManPrintStats( pNew1, NULL );
967 Gia_ManStop( pNew );
968 pNew2 = Gia_ManDupNoMuxes( pNew1, 0 );
969 if ( fVerbose ) Gia_ManPrintStats( pNew2, NULL );
970 Gia_ManStop( pNew1 );
971 return pNew2;
972}
Gia_Man_t * Gia_ManBalanceInt(Gia_Man_t *p, int fStrict)
Definition giaBalAig.c:378
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition giaMuxes.c:98
Gia_Man_t * Gia_ManDupNoMuxes(Gia_Man_t *p, int fSkipBufs)
Definition giaMuxes.c:228
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void Gia_ManPrintStats(Gia_Man_t *p, Gps_Par_t *pPars)
Definition giaMan.c:495
Here is the call graph for this function: