abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
giaShrink.c File Reference
#include "gia.h"
#include "aig/aig/aig.h"
#include "opt/dar/dar.h"

Go to the source code of this file.

Functions

ABC_NAMESPACE_IMPL_START int Dar_LibEvalBuild (Gia_Man_t *p, Vec_Int_t *vCut, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest)
 DECLARATIONS ///. More...
 
Gia_Man_tGia_ManMapShrink4 (Gia_Man_t *p, int fKeepLevel, int fVerbose)
 FUNCTION DEFINITIONS ///. More...
 

Function Documentation

ABC_NAMESPACE_IMPL_START int Dar_LibEvalBuild ( Gia_Man_t p,
Vec_Int_t vCutLits,
unsigned  uTruth,
int  fKeepLevel,
Vec_Int_t vLeavesBest2 
)

DECLARATIONS ///.

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

FileName [giaShrink.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [Scalable AIG package.]

Synopsis [Implementation of mapShrink based on ideas of Niklas Een.]

Author [Alan Mishchenko]

Affiliation [UC Berkeley]

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

Revision [

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

]

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

Synopsis [Evaluate and build the new node.]

Description []

SideEffects []

SeeAlso []

Definition at line 1329 of file darLib.c.

1330 {
1331  int OutBest = Dar2_LibEval( p, vCutLits, uTruth, fKeepLevel, vLeavesBest2 );
1332  return Dar2_LibBuildBest( p, vLeavesBest2, OutBest );
1333 }
int Dar2_LibEval(Gia_Man_t *p, Vec_Int_t *vCutLits, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest2)
Definition: darLib.c:1184
int Dar2_LibBuildBest(Gia_Man_t *p, Vec_Int_t *vLeavesBest2, int OutBest)
Definition: darLib.c:1308
Gia_Man_t* Gia_ManMapShrink4 ( Gia_Man_t p,
int  fKeepLevel,
int  fVerbose 
)

FUNCTION DEFINITIONS ///.

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

Synopsis [Performs AIG shrinking using the current mapping.]

Description []

SideEffects []

SeeAlso []

Definition at line 49 of file giaShrink.c.

50 {
51  Vec_Int_t * vLeaves, * vTruth, * vVisited, * vLeavesBest;
52  Gia_Man_t * pNew, * pTemp;
53  Gia_Obj_t * pObj, * pFanin;
54  unsigned * pTruth;
55  int i, k, iFan;
56  abctime clk = Abc_Clock();
57 // int ClassCounts[222] = {0};
58  int * pLutClass, Counter = 0;
60  if ( Gia_ManLutSizeMax( p ) > 4 )
61  {
62  printf( "Resynthesis is not performed when nodes have more than 4 inputs.\n" );
63  return NULL;
64  }
65  pLutClass = ABC_CALLOC( int, Gia_ManObjNum(p) );
66  vLeaves = Vec_IntAlloc( 0 );
67  vTruth = Vec_IntAlloc( (1<<16) );
68  vVisited = Vec_IntAlloc( 0 );
69  vLeavesBest = Vec_IntAlloc( 4 );
70  // prepare the library
71  Dar_LibPrepare( 5 );
72  // clean the old manager
73  Gia_ManCleanTruth( p );
74  Gia_ManSetPhase( p );
75  Gia_ManFillValue( p );
76  Gia_ManConst0(p)->Value = 0;
77  // start the new manager
78  pNew = Gia_ManStart( Gia_ManObjNum(p) );
79  pNew->pName = Abc_UtilStrsav( p->pName );
80  pNew->pSpec = Abc_UtilStrsav( p->pSpec );
81  Gia_ManHashAlloc( pNew );
83  Gia_ManForEachObj1( p, pObj, i )
84  {
85  if ( Gia_ObjIsCi(pObj) )
86  {
87  pObj->Value = Gia_ManAppendCi( pNew );
88  if ( p->vLevels )
89  Gia_ObjSetLevel( pNew, Gia_ObjFromLit(pNew, Gia_ObjValue(pObj)), Gia_ObjLevel(p, pObj) );
90  }
91  else if ( Gia_ObjIsCo(pObj) )
92  {
93  pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
94  }
95  else if ( Gia_ObjIsLut(p, i) )
96  {
97  Counter++;
98  // collect leaves of this gate
99  Vec_IntClear( vLeaves );
100  Gia_LutForEachFanin( p, i, iFan, k )
101  Vec_IntPush( vLeaves, iFan );
102  for ( ; k < 4; k++ )
103  Vec_IntPush( vLeaves, 0 );
104  //.compute the truth table
105  pTruth = Gia_ManConvertAigToTruth( p, pObj, vLeaves, vTruth, vVisited );
106  // change from node IDs to their literals
107  Gia_ManForEachObjVec( vLeaves, p, pFanin, k )
108  {
109 // assert( Gia_ObjValue(pFanin) != ~0 );
110  Vec_IntWriteEntry( vLeaves, k, Gia_ObjValue(pFanin) != ~0 ? Gia_ObjValue(pFanin) : 0 );
111  }
112  // derive new structre
113  if ( Gia_ManTruthIsConst0(pTruth, Vec_IntSize(vLeaves)) )
114  pObj->Value = 0;
115  else if ( Gia_ManTruthIsConst1(pTruth, Vec_IntSize(vLeaves)) )
116  pObj->Value = 1;
117  else
118  {
119  pObj->Value = Dar_LibEvalBuild( pNew, vLeaves, 0xffff & *pTruth, fKeepLevel, vLeavesBest );
120  pObj->Value = Abc_LitNotCond( pObj->Value, Gia_ObjPhaseRealLit(pNew, pObj->Value) ^ pObj->fPhase );
121  }
122  }
123  }
124  // cleanup the AIG
125  Gia_ManHashStop( pNew );
126  // check the presence of dangling nodes
127  if ( Gia_ManHasDangling(pNew) )
128  {
129  pNew = Gia_ManCleanup( pTemp = pNew );
130  if ( fVerbose && Gia_ManAndNum(pNew) != Gia_ManAndNum(pTemp) )
131  printf( "Gia_ManMapShrink4() node reduction after sweep %6d -> %6d.\n", Gia_ManAndNum(pTemp), Gia_ManAndNum(pNew) );
132  Gia_ManStop( pTemp );
133  }
134  Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
135  Vec_IntFree( vLeaves );
136  Vec_IntFree( vTruth );
137  Vec_IntFree( vVisited );
138  Vec_IntFree( vLeavesBest );
139  if ( fVerbose )
140  {
141  printf( "Total gain in AIG nodes = %d. ", Gia_ManObjNum(p)-Gia_ManObjNum(pNew) );
142  ABC_PRT( "Total runtime", Abc_Clock() - clk );
143  }
144  ABC_FREE( pLutClass );
145  return pNew;
146 }
void Gia_ManStop(Gia_Man_t *p)
Definition: giaMan.c:77
static int Gia_ManAppendCo(Gia_Man_t *p, int iLit0)
Definition: gia.h:703
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition: bblif.c:37
static Gia_Obj_t * Gia_ObjFromLit(Gia_Man_t *p, int iLit)
Definition: gia.h:496
static int Gia_ObjPhaseRealLit(Gia_Man_t *p, int iLit)
Definition: gia.h:498
static int Gia_ManAppendCi(Gia_Man_t *p)
Definition: gia.h:583
static int Gia_ObjValue(Gia_Obj_t *pObj)
Definition: gia.h:413
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition: giaMan.c:628
static abctime Abc_Clock()
Definition: abc_global.h:279
void Gia_ManCleanTruth(Gia_Man_t *p)
Definition: giaUtil.c:487
static int Abc_LitNotCond(int Lit, int c)
Definition: abc_global.h:267
for(p=first;p->value< newval;p=p->next)
Definition: gia.h:75
ABC_NAMESPACE_IMPL_START int Dar_LibEvalBuild(Gia_Man_t *p, Vec_Int_t *vCut, unsigned uTruth, int fKeepLevel, Vec_Int_t *vLeavesBest)
DECLARATIONS ///.
Definition: darLib.c:1329
int Gia_ManHasDangling(Gia_Man_t *p)
Definition: giaUtil.c:1155
static int Gia_ManTruthIsConst0(unsigned *pIn, int nVars)
Definition: gia.h:330
static void Vec_IntWriteEntry(Vec_Int_t *p, int i, int Entry)
Definition: bblif.c:285
static int Gia_ManAndNum(Gia_Man_t *p)
Definition: gia.h:389
static int Gia_ObjLevel(Gia_Man_t *p, Gia_Obj_t *pObj)
Definition: gia.h:501
char * pName
Definition: gia.h:97
static Vec_Int_t * Vec_IntAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Definition: bblif.c:149
char * pSpec
Definition: gia.h:98
Gia_Man_t * Gia_ManStart(int nObjsMax)
DECLARATIONS ///.
Definition: giaMan.c:52
unsigned * Gia_ManConvertAigToTruth(Gia_Man_t *p, Gia_Obj_t *pRoot, Vec_Int_t *vLeaves, Vec_Int_t *vTruth, Vec_Int_t *vVisited)
Definition: giaBidec.c:90
static void Vec_IntPush(Vec_Int_t *p, int Entry)
Definition: bblif.c:468
void Gia_ManCleanLevels(Gia_Man_t *p, int Size)
Definition: giaUtil.c:470
static int Counter
void Gia_ManFillValue(Gia_Man_t *p)
Definition: giaUtil.c:328
int Gia_ManLutSizeMax(Gia_Man_t *p)
Definition: giaIf.c:125
void Dar_LibPrepare(int nSubgraphs)
Definition: darLib.c:478
static int Gia_ObjFanin0Copy(Gia_Obj_t *pObj)
Definition: gia.h:481
static int Gia_ObjIsCo(Gia_Obj_t *pObj)
Definition: gia.h:421
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition: gia.h:988
static int Gia_ManTruthIsConst1(unsigned *pIn, int nVars)
Definition: gia.h:338
static int Vec_IntSize(Vec_Int_t *p)
Definition: bblif.c:252
static int Gia_ManHasMapping(Gia_Man_t *p)
Definition: gia.h:951
#define ABC_FREE(obj)
Definition: abc_global.h:232
Definition: gia.h:95
#define ABC_PRT(a, t)
Definition: abc_global.h:220
static Gia_Obj_t * Gia_ManConst0(Gia_Man_t *p)
Definition: gia.h:400
#define ABC_CALLOC(type, num)
Definition: abc_global.h:230
#define assert(ex)
Definition: util_old.h:213
void Gia_ManSetPhase(Gia_Man_t *p)
Definition: giaUtil.c:379
unsigned Value
Definition: gia.h:87
Vec_Int_t * vLevels
Definition: gia.h:115
static int Gia_ObjIsLut(Gia_Man_t *p, int Id)
Definition: gia.h:952
void Gia_ManHashAlloc(Gia_Man_t *p)
Definition: giaHash.c:99
#define Gia_ManForEachObj1(p, pObj, i)
Definition: gia.h:986
static void Vec_IntFree(Vec_Int_t *p)
Definition: bblif.c:235
static void Vec_IntClear(Vec_Int_t *p)
Definition: bblif.c:452
ABC_INT64_T abctime
Definition: abc_global.h:278
static int Gia_ObjIsCi(Gia_Obj_t *pObj)
Definition: gia.h:420
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition: giaScl.c:84
char * Abc_UtilStrsav(char *s)
Definition: starter.c:47
#define Gia_LutForEachFanin(p, i, iFan, k)
Definition: gia.h:970
static int Gia_ManObjNum(Gia_Man_t *p)
Definition: gia.h:388
void Gia_ManHashStop(Gia_Man_t *p)
Definition: giaHash.c:142
static void Gia_ObjSetLevel(Gia_Man_t *p, Gia_Obj_t *pObj, int l)
Definition: gia.h:503
static int Gia_ManRegNum(Gia_Man_t *p)
Definition: gia.h:387