ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
hopBalance.c File Reference
#include "hop.h"
Include dependency graph for hopBalance.c:

Go to the source code of this file.

Functions

Hop_Man_tHop_ManBalance (Hop_Man_t *p, int fUpdateLevel)
 FUNCTION DEFINITIONS ///.
 
int Hop_NodeBalanceCone_rec (Hop_Obj_t *pRoot, Hop_Obj_t *pObj, Vec_Ptr_t *vSuper)
 
int Hop_NodeCompareLevelsDecrease (Hop_Obj_t **pp1, Hop_Obj_t **pp2)
 
Hop_Obj_tHop_NodeBalanceBuildSuper (Hop_Man_t *p, Vec_Ptr_t *vSuper, Hop_Type_t Type, int fUpdateLevel)
 

Function Documentation

◆ Hop_ManBalance()

Hop_Man_t * Hop_ManBalance ( Hop_Man_t * p,
int fUpdateLevel )

FUNCTION DEFINITIONS ///.

FUNCTION DECLARATIONS ///.

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

Synopsis [Performs algebraic balancing of the AIG.]

Description []

SideEffects []

SeeAlso []

Definition at line 51 of file hopBalance.c.

52{
53 Hop_Man_t * pNew;
54 Hop_Obj_t * pObj, * pObjNew;
55 Vec_Vec_t * vStore;
56 int i;
57 // create the new manager
58 pNew = Hop_ManStart();
59 pNew->fRefCount = 0;
60 // map the PI nodes
62 Hop_ManConst1(p)->pData = Hop_ManConst1(pNew);
63 Hop_ManForEachPi( p, pObj, i )
64 pObj->pData = Hop_ObjCreatePi(pNew);
65 // balance the AIG
66 vStore = Vec_VecAlloc( 50 );
67 Hop_ManForEachPo( p, pObj, i )
68 {
69 pObjNew = Hop_NodeBalance_rec( pNew, Hop_ObjFanin0(pObj), vStore, 0, fUpdateLevel );
70 Hop_ObjCreatePo( pNew, Hop_NotCond( pObjNew, Hop_ObjFaninC0(pObj) ) );
71 }
72 Vec_VecFree( vStore );
73 // remove dangling nodes
74// Hop_ManCreateRefs( pNew );
75// if ( i = Hop_ManCleanup( pNew ) )
76// printf( "Cleanup after balancing removed %d dangling nodes.\n", i );
77 // check the resulting AIG
78 if ( !Hop_ManCheck(pNew) )
79 printf( "Hop_ManBalance(): The check has failed.\n" );
80 return pNew;
81}
Cube * p
Definition exorList.c:222
Hop_Obj_t * Hop_ObjCreatePo(Hop_Man_t *p, Hop_Obj_t *pDriver)
Definition hopObj.c:67
typedefABC_NAMESPACE_HEADER_START struct Hop_Man_t_ Hop_Man_t
INCLUDES ///.
Definition hop.h:49
int Hop_ManCheck(Hop_Man_t *p)
DECLARATIONS ///.
Definition hopCheck.c:45
#define Hop_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition hop.h:259
#define Hop_ManForEachPo(p, pObj, i)
Definition hop.h:262
Hop_Obj_t * Hop_ObjCreatePi(Hop_Man_t *p)
DECLARATIONS ///.
Definition hopObj.c:45
Hop_Man_t * Hop_ManStart()
DECLARATIONS ///.
Definition hopMan.c:45
struct Hop_Obj_t_ Hop_Obj_t
Definition hop.h:50
void Hop_ManCleanData(Hop_Man_t *p)
Definition hopUtil.c:63
void * pData
Definition hop.h:68
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition vecVec.h:42
Here is the call graph for this function:

◆ Hop_NodeBalanceBuildSuper()

Hop_Obj_t * Hop_NodeBalanceBuildSuper ( Hop_Man_t * p,
Vec_Ptr_t * vSuper,
Hop_Type_t Type,
int fUpdateLevel )

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

Synopsis [Builds implication supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 243 of file hopBalance.c.

244{
245 Hop_Obj_t * pObj1, * pObj2;
246 int LeftBound;
247 assert( vSuper->nSize > 1 );
248 // sort the new nodes by level in the decreasing order
249 Vec_PtrSort( vSuper, (int (*)(const void *, const void *))Hop_NodeCompareLevelsDecrease );
250 // balance the nodes
251 while ( vSuper->nSize > 1 )
252 {
253 // find the left bound on the node to be paired
254 LeftBound = (!fUpdateLevel)? 0 : Hop_NodeBalanceFindLeft( vSuper );
255 // find the node that can be shared (if no such node, randomize choice)
256 Hop_NodeBalancePermute( p, vSuper, LeftBound, Type == AIG_EXOR );
257 // pull out the last two nodes
258 pObj1 = (Hop_Obj_t *)Vec_PtrPop(vSuper);
259 pObj2 = (Hop_Obj_t *)Vec_PtrPop(vSuper);
260 Hop_NodeBalancePushUniqueOrderByLevel( vSuper, Hop_Oper(p, pObj1, pObj2, Type) );
261 }
262 return (Hop_Obj_t *)Vec_PtrEntry(vSuper, 0);
263}
int Hop_NodeCompareLevelsDecrease(Hop_Obj_t **pp1, Hop_Obj_t **pp2)
Definition hopBalance.c:217
@ AIG_EXOR
Definition hop.h:60
Hop_Obj_t * Hop_Oper(Hop_Man_t *p, Hop_Obj_t *p0, Hop_Obj_t *p1, Hop_Type_t Type)
Definition hopOper.c:83
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ Hop_NodeBalanceCone_rec()

int Hop_NodeBalanceCone_rec ( Hop_Obj_t * pRoot,
Hop_Obj_t * pObj,
Vec_Ptr_t * vSuper )

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

Synopsis [Collects the nodes of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 136 of file hopBalance.c.

137{
138 int RetValue1, RetValue2, i;
139 // check if the node is visited
140 if ( Hop_Regular(pObj)->fMarkB )
141 {
142 // check if the node occurs in the same polarity
143 for ( i = 0; i < vSuper->nSize; i++ )
144 if ( vSuper->pArray[i] == pObj )
145 return 1;
146 // check if the node is present in the opposite polarity
147 for ( i = 0; i < vSuper->nSize; i++ )
148 if ( vSuper->pArray[i] == Hop_Not(pObj) )
149 return -1;
150 assert( 0 );
151 return 0;
152 }
153 // if the new node is complemented or a PI, another gate begins
154 if ( pObj != pRoot && (Hop_IsComplement(pObj) || Hop_ObjType(pObj) != Hop_ObjType(pRoot) || Hop_ObjRefs(pObj) > 1 || Vec_PtrSize(vSuper) > 10000) )
155 {
156 Vec_PtrPush( vSuper, pObj );
157 Hop_Regular(pObj)->fMarkB = 1;
158 return 0;
159 }
160 assert( !Hop_IsComplement(pObj) );
161 assert( Hop_ObjIsNode(pObj) );
162 // go through the branches
163 RetValue1 = Hop_NodeBalanceCone_rec( pRoot, Hop_ObjChild0(pObj), vSuper );
164 RetValue2 = Hop_NodeBalanceCone_rec( pRoot, Hop_ObjChild1(pObj), vSuper );
165 if ( RetValue1 == -1 || RetValue2 == -1 )
166 return -1;
167 // return 1 if at least one branch has a duplicate
168 return RetValue1 || RetValue2;
169}
int Hop_NodeBalanceCone_rec(Hop_Obj_t *pRoot, Hop_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition hopBalance.c:136
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Hop_NodeCompareLevelsDecrease()

int Hop_NodeCompareLevelsDecrease ( Hop_Obj_t ** pp1,
Hop_Obj_t ** pp2 )

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 217 of file hopBalance.c.

218{
219 int Diff = Hop_ObjLevel(Hop_Regular(*pp1)) - Hop_ObjLevel(Hop_Regular(*pp2));
220 if ( Diff > 0 )
221 return -1;
222 if ( Diff < 0 )
223 return 1;
224 Diff = Hop_Regular(*pp1)->Id - Hop_Regular(*pp2)->Id;
225 if ( Diff > 0 )
226 return -1;
227 if ( Diff < 0 )
228 return 1;
229 return 0;
230}
Here is the caller graph for this function: