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

Go to the source code of this file.

Functions

Ivy_Man_tIvy_ManBalance (Ivy_Man_t *p, int fUpdateLevel)
 FUNCTION DEFINITIONS ///.
 
int Ivy_NodeCompareLevelsDecrease (Ivy_Obj_t **pp1, Ivy_Obj_t **pp2)
 
Ivy_Obj_tIvy_NodeBalanceBuildSuper (Ivy_Man_t *p, Vec_Ptr_t *vSuper, Ivy_Type_t Type, int fUpdateLevel)
 
int Ivy_NodeBalanceCone_rec (Ivy_Obj_t *pRoot, Ivy_Obj_t *pObj, Vec_Ptr_t *vSuper)
 

Function Documentation

◆ Ivy_ManBalance()

Ivy_Man_t * Ivy_ManBalance ( Ivy_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 ivyBalance.c.

52{
53 Ivy_Man_t * pNew;
54 Ivy_Obj_t * pObj, * pDriver;
55 Vec_Vec_t * vStore;
56 int i, NewNodeId;
57 // clean the old manager
59 // create the new manager
60 pNew = Ivy_ManStart();
61 // map the nodes
62 Ivy_ManConst1(p)->TravId = Ivy_EdgeFromNode( Ivy_ManConst1(pNew) );
63 Ivy_ManForEachPi( p, pObj, i )
64 pObj->TravId = Ivy_EdgeFromNode( Ivy_ObjCreatePi(pNew) );
65 // if HAIG is defined, trasfer the pointers to the PIs/latches
66// if ( p->pHaig )
67// Ivy_ManHaigTrasfer( p, pNew );
68 // balance the AIG
69 vStore = Vec_VecAlloc( 50 );
70 Ivy_ManForEachPo( p, pObj, i )
71 {
72 pDriver = Ivy_ObjReal( Ivy_ObjChild0(pObj) );
73 NewNodeId = Ivy_NodeBalance_rec( pNew, Ivy_Regular(pDriver), vStore, 0, fUpdateLevel );
74 NewNodeId = Ivy_EdgeNotCond( NewNodeId, Ivy_IsComplement(pDriver) );
75 Ivy_ObjCreatePo( pNew, Ivy_EdgeToNode(pNew, NewNodeId) );
76 }
77 Vec_VecFree( vStore );
78 if ( (i = Ivy_ManCleanup( pNew )) )
79 {
80// printf( "Cleanup after balancing removed %d dangling nodes.\n", i );
81 }
82 // check the resulting AIG
83 if ( !Ivy_ManCheck(pNew) )
84 printf( "Ivy_ManBalance(): The check has failed.\n" );
85 return pNew;
86}
Cube * p
Definition exorList.c:222
int Ivy_ManCheck(Ivy_Man_t *p)
DECLARATIONS ///.
Definition ivyCheck.c:45
typedefABC_NAMESPACE_HEADER_START struct Ivy_Man_t_ Ivy_Man_t
INCLUDES ///.
Definition ivy.h:46
int Ivy_ManCleanup(Ivy_Man_t *p)
Definition ivyMan.c:265
Ivy_Man_t * Ivy_ManStart()
DECLARATIONS ///.
Definition ivyMan.c:45
Ivy_Obj_t * Ivy_ObjCreatePo(Ivy_Man_t *p, Ivy_Obj_t *pDriver)
Definition ivyObj.c:61
Ivy_Obj_t * Ivy_ObjReal(Ivy_Obj_t *pObj)
Definition ivyUtil.c:609
#define Ivy_ManForEachPo(p, pObj, i)
Definition ivy.h:390
struct Ivy_Obj_t_ Ivy_Obj_t
Definition ivy.h:47
Ivy_Obj_t * Ivy_ObjCreatePi(Ivy_Man_t *p)
DECLARATIONS ///.
Definition ivyObj.c:45
void Ivy_ManCleanTravId(Ivy_Man_t *p)
Definition ivyUtil.c:63
#define Ivy_ManForEachPi(p, pObj, i)
ITERATORS ///.
Definition ivy.h:387
int TravId
Definition ivy.h:76
typedefABC_NAMESPACE_HEADER_START struct Vec_Vec_t_ Vec_Vec_t
INCLUDES ///.
Definition vecVec.h:42
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_NodeBalanceBuildSuper()

Ivy_Obj_t * Ivy_NodeBalanceBuildSuper ( Ivy_Man_t * p,
Vec_Ptr_t * vSuper,
Ivy_Type_t Type,
int fUpdateLevel )

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

Synopsis [Builds implication supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 175 of file ivyBalance.c.

176{
177 Ivy_Obj_t * pObj1, * pObj2;
178 int LeftBound;
179 assert( vSuper->nSize > 1 );
180 // sort the new nodes by level in the decreasing order
181 Vec_PtrSort( vSuper, (int (*)(const void *, const void *))Ivy_NodeCompareLevelsDecrease );
182 // balance the nodes
183 while ( vSuper->nSize > 1 )
184 {
185 // find the left bound on the node to be paired
186 LeftBound = (!fUpdateLevel)? 0 : Ivy_NodeBalanceFindLeft( vSuper );
187 // find the node that can be shared (if no such node, randomize choice)
188 Ivy_NodeBalancePermute( p, vSuper, LeftBound, Type == IVY_EXOR );
189 // pull out the last two nodes
190 pObj1 = (Ivy_Obj_t *)Vec_PtrPop(vSuper);
191 pObj2 = (Ivy_Obj_t *)Vec_PtrPop(vSuper);
192 Ivy_NodeBalancePushUniqueOrderByLevel( vSuper, Ivy_Oper(p, pObj1, pObj2, Type) );
193 }
194 return (Ivy_Obj_t *)Vec_PtrEntry(vSuper, 0);
195}
int Ivy_NodeCompareLevelsDecrease(Ivy_Obj_t **pp1, Ivy_Obj_t **pp2)
Definition ivyBalance.c:99
Ivy_Obj_t * Ivy_Oper(Ivy_Man_t *p, Ivy_Obj_t *p0, Ivy_Obj_t *p1, Ivy_Type_t Type)
FUNCTION DEFINITIONS ///.
Definition ivyOper.c:63
@ IVY_EXOR
Definition ivy.h:59
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:

◆ Ivy_NodeBalanceCone_rec()

int Ivy_NodeBalanceCone_rec ( Ivy_Obj_t * pRoot,
Ivy_Obj_t * pObj,
Vec_Ptr_t * vSuper )

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

Synopsis [Collects the nodes of the supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 208 of file ivyBalance.c.

209{
210 int RetValue1, RetValue2, i;
211 // check if the node is visited
212 if ( Ivy_Regular(pObj)->fMarkB )
213 {
214 // check if the node occurs in the same polarity
215 for ( i = 0; i < vSuper->nSize; i++ )
216 if ( vSuper->pArray[i] == pObj )
217 return 1;
218 // check if the node is present in the opposite polarity
219 for ( i = 0; i < vSuper->nSize; i++ )
220 if ( vSuper->pArray[i] == Ivy_Not(pObj) )
221 return -1;
222 assert( 0 );
223 return 0;
224 }
225 // if the new node is complemented or a PI, another gate begins
226 if ( pObj != pRoot && (Ivy_IsComplement(pObj) || Ivy_ObjType(pObj) != Ivy_ObjType(pRoot) || Ivy_ObjRefs(pObj) > 1 || Vec_PtrSize(vSuper) > 10000) )
227 {
228 Vec_PtrPush( vSuper, pObj );
229 Ivy_Regular(pObj)->fMarkB = 1;
230 return 0;
231 }
232 assert( !Ivy_IsComplement(pObj) );
233 assert( Ivy_ObjIsNode(pObj) );
234 // go through the branches
235 RetValue1 = Ivy_NodeBalanceCone_rec( pRoot, Ivy_ObjReal( Ivy_ObjChild0(pObj) ), vSuper );
236 RetValue2 = Ivy_NodeBalanceCone_rec( pRoot, Ivy_ObjReal( Ivy_ObjChild1(pObj) ), vSuper );
237 if ( RetValue1 == -1 || RetValue2 == -1 )
238 return -1;
239 // return 1 if at least one branch has a duplicate
240 return RetValue1 || RetValue2;
241}
int Ivy_NodeBalanceCone_rec(Ivy_Obj_t *pRoot, Ivy_Obj_t *pObj, Vec_Ptr_t *vSuper)
Definition ivyBalance.c:208
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Ivy_NodeCompareLevelsDecrease()

int Ivy_NodeCompareLevelsDecrease ( Ivy_Obj_t ** pp1,
Ivy_Obj_t ** pp2 )

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

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

Description []

SideEffects []

SeeAlso []

Definition at line 99 of file ivyBalance.c.

100{
101 int Diff = Ivy_Regular(*pp1)->Level - Ivy_Regular(*pp2)->Level;
102 if ( Diff > 0 )
103 return -1;
104 if ( Diff < 0 )
105 return 1;
106 Diff = Ivy_Regular(*pp1)->Id - Ivy_Regular(*pp2)->Id;
107 if ( Diff > 0 )
108 return -1;
109 if ( Diff < 0 )
110 return 1;
111 return 0;
112}
Here is the caller graph for this function: