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

Go to the source code of this file.

Functions

Abc_Ntk_tAbc_NtkBalance (Abc_Ntk_t *pNtk, int fDuplicate, int fSelective, int fUpdateLevel)
 FUNCTION DEFINITIONS ///.
 
int Abc_NodeBalanceFindLeft (Vec_Ptr_t *vSuper)
 
void Abc_NodeBalancePermute (Abc_Ntk_t *pNtkNew, Vec_Ptr_t *vSuper, int LeftBound)
 
int Abc_NodeBalanceConeExor_rec (Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
 
Vec_Ptr_tAbc_NodeFindCone_rec (Abc_Obj_t *pNode)
 
void Abc_NtkBalanceAttach (Abc_Ntk_t *pNtk)
 
void Abc_NtkBalanceDetach (Abc_Ntk_t *pNtk)
 
int Abc_NtkBalanceLevel_rec (Abc_Obj_t *pNode)
 
void Abc_NtkBalanceLevel (Abc_Ntk_t *pNtk)
 

Function Documentation

◆ Abc_NodeBalanceConeExor_rec()

int Abc_NodeBalanceConeExor_rec ( Abc_Obj_t * pNode,
Vec_Ptr_t * vSuper,
int fFirst )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 392 of file abcBalance.c.

393{
394 int RetValue1, RetValue2, i;
395 // check if the node occurs in the same polarity
396 for ( i = 0; i < vSuper->nSize; i++ )
397 if ( vSuper->pArray[i] == pNode )
398 return 1;
399 // if the new node is complemented or a PI, another gate begins
400 if ( !fFirst && (!pNode->fExor || !Abc_ObjIsNode(pNode)) )
401 {
402 Vec_PtrPush( vSuper, pNode );
403 return 0;
404 }
405 assert( !Abc_ObjIsComplement(pNode) );
406 assert( Abc_ObjIsNode(pNode) );
407 assert( pNode->fExor );
408 // go through the branches
409 RetValue1 = Abc_NodeBalanceConeExor_rec( Abc_ObjFanin0(Abc_ObjFanin0(pNode)), vSuper, 0 );
410 RetValue2 = Abc_NodeBalanceConeExor_rec( Abc_ObjFanin1(Abc_ObjFanin0(pNode)), vSuper, 0 );
411 if ( RetValue1 == -1 || RetValue2 == -1 )
412 return -1;
413 // return 1 if at least one branch has a duplicate
414 return RetValue1 || RetValue2;
415}
int Abc_NodeBalanceConeExor_rec(Abc_Obj_t *pNode, Vec_Ptr_t *vSuper, int fFirst)
Definition abcBalance.c:392
unsigned fExor
Definition abc.h:138
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NodeBalanceFindLeft()

int Abc_NodeBalanceFindLeft ( Vec_Ptr_t * vSuper)

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

Synopsis [Finds the left bound on the next candidate to be paired.]

Description [The nodes in the array are in the decreasing order of levels. The last node in the array has the smallest level. By default it would be paired with the next node on the left. However, it may be possible to pair it with some other node on the left, in such a way that the new node is shared. This procedure finds the index of the left-most node, which can be paired with the last node.]

SideEffects []

SeeAlso []

Definition at line 154 of file abcBalance.c.

155{
156 Abc_Obj_t * pNodeRight, * pNodeLeft;
157 int Current;
158 // if two or less nodes, pair with the first
159 if ( Vec_PtrSize(vSuper) < 3 )
160 return 0;
161 // set the pointer to the one before the last
162 Current = Vec_PtrSize(vSuper) - 2;
163 pNodeRight = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
164 // go through the nodes to the left of this one
165 for ( Current--; Current >= 0; Current-- )
166 {
167 // get the next node on the left
168 pNodeLeft = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
169 // if the level of this node is different, quit the loop
170 if ( Abc_ObjRegular(pNodeLeft)->Level != Abc_ObjRegular(pNodeRight)->Level )
171 break;
172 }
173 Current++;
174 // get the node, for which the equality holds
175 pNodeLeft = (Abc_Obj_t *)Vec_PtrEntry( vSuper, Current );
176 assert( Abc_ObjRegular(pNodeLeft)->Level == Abc_ObjRegular(pNodeRight)->Level );
177 return Current;
178}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116

◆ Abc_NodeBalancePermute()

void Abc_NodeBalancePermute ( Abc_Ntk_t * pNtkNew,
Vec_Ptr_t * vSuper,
int LeftBound )

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

Synopsis [Moves closer to the end the node that is best for sharing.]

Description [If there is no node with sharing, randomly chooses one of the legal nodes.]

SideEffects []

SeeAlso []

Definition at line 192 of file abcBalance.c.

193{
194 Abc_Obj_t * pNode1, * pNode2, * pNode3;
195 int RightBound, i;
196 // get the right bound
197 RightBound = Vec_PtrSize(vSuper) - 2;
198 assert( LeftBound <= RightBound );
199 if ( LeftBound == RightBound )
200 return;
201 // get the two last nodes
202 pNode1 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound + 1 );
203 pNode2 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, RightBound );
204 // find the first node that can be shared
205 for ( i = RightBound; i >= LeftBound; i-- )
206 {
207 pNode3 = (Abc_Obj_t *)Vec_PtrEntry( vSuper, i );
208 if ( Abc_AigAndLookup( (Abc_Aig_t *)pNtkNew->pManFunc, pNode1, pNode3 ) )
209 {
210 if ( pNode3 == pNode2 )
211 return;
212 Vec_PtrWriteEntry( vSuper, i, pNode2 );
213 Vec_PtrWriteEntry( vSuper, RightBound, pNode3 );
214 return;
215 }
216 }
217/*
218 // we did not find the node to share, randomize choice
219 {
220 int Choice = rand() % (RightBound - LeftBound + 1);
221 pNode3 = Vec_PtrEntry( vSuper, LeftBound + Choice );
222 if ( pNode3 == pNode2 )
223 return;
224 Vec_PtrWriteEntry( vSuper, LeftBound + Choice, pNode2 );
225 Vec_PtrWriteEntry( vSuper, RightBound, pNode3 );
226 }
227*/
228}
struct Abc_Aig_t_ Abc_Aig_t
Definition abc.h:117
ABC_DLL Abc_Obj_t * Abc_AigAndLookup(Abc_Aig_t *pMan, Abc_Obj_t *p0, Abc_Obj_t *p1)
Definition abcAig.c:403
void * pManFunc
Definition abc.h:191
Here is the call graph for this function:

◆ Abc_NodeFindCone_rec()

Vec_Ptr_t * Abc_NodeFindCone_rec ( Abc_Obj_t * pNode)

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

Synopsis [Collects the nodes in the implication supergate.]

Description []

SideEffects []

SeeAlso []

Definition at line 453 of file abcBalance.c.

454{
455 Vec_Ptr_t * vNodes;
456 Abc_Obj_t * pNodeC, * pNodeT, * pNodeE;
457 int RetValue, i;
458 assert( !Abc_ObjIsComplement(pNode) );
459 if ( Abc_ObjIsCi(pNode) )
460 return NULL;
461 // start the new array
462 vNodes = Vec_PtrAlloc( 4 );
463 // if the node is the MUX collect its fanins
464 if ( Abc_NodeIsMuxType(pNode) )
465 {
466 pNodeC = Abc_NodeRecognizeMux( pNode, &pNodeT, &pNodeE );
467 Vec_PtrPush( vNodes, Abc_ObjRegular(pNodeC) );
468 Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeT) );
469 Vec_PtrPushUnique( vNodes, Abc_ObjRegular(pNodeE) );
470 }
471 else
472 {
473 // collect the nodes in the implication supergate
474 RetValue = Abc_NodeBalanceCone_rec( pNode, vNodes, 1, 1, 0 );
475 assert( vNodes->nSize > 1 );
476 // unmark the visited nodes
477 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
478 Abc_ObjRegular(pNode)->fMarkB = 0;
479 // if we found the node and its complement in the same implication supergate,
480 // return empty set of nodes (meaning that we should use constant-0 node)
481 if ( RetValue == -1 )
482 vNodes->nSize = 0;
483 }
484 // call for the fanin
485 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pNode, i )
486 {
487 pNode = Abc_ObjRegular(pNode);
488 if ( pNode->pCopy )
489 continue;
490 pNode->pCopy = (Abc_Obj_t *)Abc_NodeFindCone_rec( pNode );
491 }
492 return vNodes;
493}
Vec_Ptr_t * Abc_NodeFindCone_rec(Abc_Obj_t *pNode)
Definition abcBalance.c:453
ABC_DLL int Abc_NodeIsMuxType(Abc_Obj_t *pNode)
Definition abcUtil.c:1342
ABC_DLL Abc_Obj_t * Abc_NodeRecognizeMux(Abc_Obj_t *pNode, Abc_Obj_t **ppNodeT, Abc_Obj_t **ppNodeE)
Definition abcUtil.c:1430
Abc_Obj_t * pCopy
Definition abc.h:148
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkBalance()

Abc_Ntk_t * Abc_NtkBalance ( Abc_Ntk_t * pNtk,
int fDuplicate,
int fSelective,
int fUpdateLevel )

FUNCTION DEFINITIONS ///.

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

Synopsis [Balances the AIG network.]

Description []

SideEffects []

SeeAlso []

Definition at line 53 of file abcBalance.c.

54{
55// extern void Abc_NtkHaigTranfer( Abc_Ntk_t * pNtkOld, Abc_Ntk_t * pNtkNew );
56 Abc_Ntk_t * pNtkAig;
57 assert( Abc_NtkIsStrash(pNtk) );
58 // compute the required times
59 if ( fSelective )
60 {
62 Abc_NtkMarkCriticalNodes( pNtk );
63 }
64 // perform balancing
66 // transfer HAIG
67// Abc_NtkHaigTranfer( pNtk, pNtkAig );
68 // perform balancing
69 Abc_NtkBalancePerform( pNtk, pNtkAig, fDuplicate, fSelective, fUpdateLevel );
70 Abc_NtkFinalize( pNtk, pNtkAig );
71 Abc_AigCleanup( (Abc_Aig_t *)pNtkAig->pManFunc );
72 // undo the required times
73 if ( fSelective )
74 {
76 Abc_NtkCleanMarkA( pNtk );
77 }
78 if ( pNtk->pExdc )
79 pNtkAig->pExdc = Abc_NtkDup( pNtk->pExdc );
80 // make sure everything is okay
81 if ( !Abc_NtkCheck( pNtkAig ) )
82 {
83 printf( "Abc_NtkBalance: The network check has failed.\n" );
84 Abc_NtkDelete( pNtkAig );
85 return NULL;
86 }
87//Abc_NtkPrintCiLevels( pNtkAig );
88 return pNtkAig;
89}
ABC_DLL void Abc_NtkCleanMarkA(Abc_Ntk_t *pNtk)
Definition abcUtil.c:696
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_NtkFinalize(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtkNew)
Definition abcNtk.c:355
@ ABC_NTK_STRASH
Definition abc.h:58
ABC_DLL void Abc_NtkStopReverseLevels(Abc_Ntk_t *pNtk)
Definition abcTiming.c:1302
ABC_DLL int Abc_AigCleanup(Abc_Aig_t *pMan)
Definition abcAig.c:194
ABC_DLL void Abc_NtkStartReverseLevels(Abc_Ntk_t *pNtk, int nMaxLevelIncrease)
Definition abcTiming.c:1274
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_AIG
Definition abc.h:67
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL Abc_Ntk_t * Abc_NtkDup(Abc_Ntk_t *pNtk)
Definition abcNtk.c:472
Abc_Ntk_t * pExdc
Definition abc.h:201
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkBalanceAttach()

void Abc_NtkBalanceAttach ( Abc_Ntk_t * pNtk)

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

Synopsis [Attaches the implication supergates to internal nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 506 of file abcBalance.c.

507{
508 Abc_Obj_t * pNode;
509 int i;
510 Abc_NtkCleanCopy( pNtk );
511 Abc_NtkForEachCo( pNtk, pNode, i )
512 {
513 pNode = Abc_ObjFanin0(pNode);
514 if ( pNode->pCopy )
515 continue;
516 pNode->pCopy = (Abc_Obj_t *)Abc_NodeFindCone_rec( pNode );
517 }
518}
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL void Abc_NtkCleanCopy(Abc_Ntk_t *pNtk)
Definition abcUtil.c:540
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Abc_NtkBalanceDetach()

void Abc_NtkBalanceDetach ( Abc_Ntk_t * pNtk)

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

Synopsis [Attaches the implication supergates to internal nodes.]

Description []

SideEffects []

SeeAlso []

Definition at line 531 of file abcBalance.c.

532{
533 Abc_Obj_t * pNode;
534 int i;
535 Abc_NtkForEachNode( pNtk, pNode, i )
536 if ( pNode->pCopy )
537 {
538 Vec_PtrFree( (Vec_Ptr_t *)pNode->pCopy );
539 pNode->pCopy = NULL;
540 }
541}
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
Here is the caller graph for this function:

◆ Abc_NtkBalanceLevel()

void Abc_NtkBalanceLevel ( Abc_Ntk_t * pNtk)

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

Synopsis [Compute levels of implication supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 590 of file abcBalance.c.

591{
592 Abc_Obj_t * pNode;
593 int i;
594 Abc_NtkForEachObj( pNtk, pNode, i )
595 pNode->Level = 0;
596 Abc_NtkForEachCo( pNtk, pNode, i )
597 Abc_NtkBalanceLevel_rec( Abc_ObjFanin0(pNode) );
598}
int Abc_NtkBalanceLevel_rec(Abc_Obj_t *pNode)
Definition abcBalance.c:554
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
unsigned Level
Definition abc.h:142
Here is the call graph for this function:

◆ Abc_NtkBalanceLevel_rec()

int Abc_NtkBalanceLevel_rec ( Abc_Obj_t * pNode)

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

Synopsis [Compute levels of implication supergates.]

Description []

SideEffects []

SeeAlso []

Definition at line 554 of file abcBalance.c.

555{
556 Vec_Ptr_t * vSuper;
557 Abc_Obj_t * pFanin;
558 int i, LevelMax;
559 assert( !Abc_ObjIsComplement(pNode) );
560 if ( pNode->Level > 0 )
561 return pNode->Level;
562 if ( Abc_ObjIsCi(pNode) )
563 return 0;
564 vSuper = (Vec_Ptr_t *)pNode->pCopy;
565 assert( vSuper != NULL );
566 LevelMax = 0;
567 Vec_PtrForEachEntry( Abc_Obj_t *, vSuper, pFanin, i )
568 {
569 pFanin = Abc_ObjRegular(pFanin);
571 if ( LevelMax < (int)pFanin->Level )
572 LevelMax = pFanin->Level;
573 }
574 pNode->Level = LevelMax + 1;
575 return pNode->Level;
576}
Here is the call graph for this function:
Here is the caller graph for this function: