ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
rwrEva.c File Reference
#include "rwr.h"
#include "bool/dec/dec.h"
#include "aig/ivy/ivy.h"
Include dependency graph for rwrEva.c:

Go to the source code of this file.

Functions

int Rwr_NodeRewrite (Rwr_Man_t *p, Cut_Man_t *pManCut, Abc_Obj_t *pNode, int fUpdateLevel, int fUseZeros, int fPlaceEnable)
 FUNCTION DEFINITIONS ///.
 
void Rwr_CutIsBoolean_rec (Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, int fMarkA)
 
void Rwr_CutCountNumNodes_rec (Abc_Obj_t *pObj, Cut_Cut_t *pCut, Vec_Ptr_t *vNodes)
 
void Rwr_ScoresClean (Rwr_Man_t *p)
 
int Rwr_ScoresCompare (int *pNum1, int *pNum2)
 
void Rwr_ScoresReport (Rwr_Man_t *p)
 

Function Documentation

◆ Rwr_CutCountNumNodes_rec()

void Rwr_CutCountNumNodes_rec ( Abc_Obj_t * pObj,
Cut_Cut_t * pCut,
Vec_Ptr_t * vNodes )

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

Synopsis [Count the nodes in the cut space of a node.]

Description []

SideEffects []

SeeAlso []

Definition at line 412 of file rwrEva.c.

413{
414 int i;
415 for ( i = 0; i < (int)pCut->nLeaves; i++ )
416 if ( pCut->pLeaves[i] == pObj->Id )
417 {
418 // check if the node is collected
419 if ( pObj->fMarkC == 0 )
420 {
421 pObj->fMarkC = 1;
422 Vec_PtrPush( vNodes, pObj );
423 }
424 return;
425 }
426 assert( Abc_ObjIsNode(pObj) );
427 // check if the node is collected
428 if ( pObj->fMarkC == 0 )
429 {
430 pObj->fMarkC = 1;
431 Vec_PtrPush( vNodes, pObj );
432 }
433 // traverse the fanins
434 Rwr_CutCountNumNodes_rec( Abc_ObjFanin0(pObj), pCut, vNodes );
435 Rwr_CutCountNumNodes_rec( Abc_ObjFanin1(pObj), pCut, vNodes );
436}
void Rwr_CutCountNumNodes_rec(Abc_Obj_t *pObj, Cut_Cut_t *pCut, Vec_Ptr_t *vNodes)
Definition rwrEva.c:412
unsigned fMarkC
Definition abc.h:136
int Id
Definition abc.h:132
int pLeaves[0]
Definition cut.h:89
unsigned nLeaves
Definition cut.h:84
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Rwr_CutIsBoolean_rec()

void Rwr_CutIsBoolean_rec ( Abc_Obj_t * pObj,
Vec_Ptr_t * vLeaves,
int fMarkA )

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

Synopsis [Checks the type of the cut.]

Description []

SideEffects []

SeeAlso []

Definition at line 353 of file rwrEva.c.

354{
355 if ( Vec_PtrFind(vLeaves, pObj) >= 0 || Vec_PtrFind(vLeaves, Abc_ObjNot(pObj)) >= 0 )
356 {
357 if ( fMarkA )
358 pObj->fMarkA = 1;
359 else
360 pObj->fMarkB = 1;
361 return;
362 }
363 assert( !Abc_ObjIsCi(pObj) );
364 Rwr_CutIsBoolean_rec( Abc_ObjFanin0(pObj), vLeaves, fMarkA );
365 Rwr_CutIsBoolean_rec( Abc_ObjFanin1(pObj), vLeaves, fMarkA );
366}
void Rwr_CutIsBoolean_rec(Abc_Obj_t *pObj, Vec_Ptr_t *vLeaves, int fMarkA)
Definition rwrEva.c:353
unsigned fMarkB
Definition abc.h:135
unsigned fMarkA
Definition abc.h:134
Here is the call graph for this function:
Here is the caller graph for this function:

◆ Rwr_NodeRewrite()

int Rwr_NodeRewrite ( Rwr_Man_t * p,
Cut_Man_t * pManCut,
Abc_Obj_t * pNode,
int fUpdateLevel,
int fUseZeros,
int fPlaceEnable )

FUNCTION DEFINITIONS ///.

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

Synopsis [Performs rewriting for one node.]

Description [This procedure considers all the cuts computed for the node and tries to rewrite each of them using the "forest" of different AIG structures precomputed and stored in the RWR manager. Determines the best rewriting and computes the gain in the number of AIG nodes in the final network. In the end, p->vFanins contains information about the best cut that can be used for rewriting, while p->pGraph gives the decomposition dag (represented using decomposition graph data structure). Returns gain in the number of nodes or -1 if node cannot be rewritten.]

SideEffects []

SeeAlso []

Definition at line 59 of file rwrEva.c.

60{
61 int fVeryVerbose = 0;
62 Dec_Graph_t * pGraph;
63 Cut_Cut_t * pCut;//, * pTemp;
64 Abc_Obj_t * pFanin;
65 unsigned uPhase;
66 unsigned uTruthBest = 0; // Suppress "might be used uninitialized"
67 unsigned uTruth;
68 char * pPerm;
69 int Required, nNodesSaved;
70 int nNodesSaveCur = -1; // Suppress "might be used uninitialized"
71 int i, GainCur = -1, GainBest = -1;
72 abctime clk, clk2;//, Counter;
73
74 p->nNodesConsidered++;
75 // get the required times
76 Required = fUpdateLevel? Abc_ObjRequiredLevel(pNode) : ABC_INFINITY;
77
78 // get the node's cuts
79clk = Abc_Clock();
80 pCut = (Cut_Cut_t *)Abc_NodeGetCutsRecursive( pManCut, pNode, 0, 0 );
81 assert( pCut != NULL );
82p->timeCut += Abc_Clock() - clk;
83
84//printf( " %d", Rwr_CutCountNumNodes(pNode, pCut) );
85/*
86 Counter = 0;
87 for ( pTemp = pCut->pNext; pTemp; pTemp = pTemp->pNext )
88 Counter++;
89 printf( "%d ", Counter );
90*/
91 // go through the cuts
92clk = Abc_Clock();
93 for ( pCut = pCut->pNext; pCut; pCut = pCut->pNext )
94 {
95 // consider only 4-input cuts
96 if ( pCut->nLeaves < 4 )
97 continue;
98// Cut_CutPrint( pCut, 0 ), printf( "\n" );
99
100 // get the fanin permutation
101 uTruth = 0xFFFF & *Cut_CutReadTruth(pCut);
102 pPerm = p->pPerms4[ (int)p->pPerms[uTruth] ];
103 uPhase = p->pPhases[uTruth];
104 // collect fanins with the corresponding permutation/phase
105 Vec_PtrClear( p->vFaninsCur );
106 Vec_PtrFill( p->vFaninsCur, (int)pCut->nLeaves, 0 );
107 for ( i = 0; i < (int)pCut->nLeaves; i++ )
108 {
109 pFanin = Abc_NtkObj( pNode->pNtk, pCut->pLeaves[(int)pPerm[i]] );
110 if ( pFanin == NULL )
111 break;
112 pFanin = Abc_ObjNotCond(pFanin, ((uPhase & (1<<i)) > 0) );
113 Vec_PtrWriteEntry( p->vFaninsCur, i, pFanin );
114 }
115 if ( i != (int)pCut->nLeaves )
116 {
117 p->nCutsBad++;
118 continue;
119 }
120 p->nCutsGood++;
121
122 {
123 int Counter = 0;
124 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
125 if ( Abc_ObjFanoutNum(Abc_ObjRegular(pFanin)) == 1 )
126 Counter++;
127 if ( Counter > 2 )
128 continue;
129 }
130
131clk2 = Abc_Clock();
132/*
133 printf( "Considering: (" );
134 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
135 printf( "%d ", Abc_ObjFanoutNum(Abc_ObjRegular(pFanin)) );
136 printf( ")\n" );
137*/
138 // mark the fanin boundary
139 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
140 Abc_ObjRegular(pFanin)->vFanouts.nSize++;
141
142 // label MFFC with current ID
143 Abc_NtkIncrementTravId( pNode->pNtk );
144 nNodesSaved = Abc_NodeMffcLabelAig( pNode );
145 // unmark the fanin boundary
146 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
147 Abc_ObjRegular(pFanin)->vFanouts.nSize--;
148p->timeMffc += Abc_Clock() - clk2;
149
150 // evaluate the cut
151clk2 = Abc_Clock();
152 pGraph = Rwr_CutEvaluate( p, pNode, pCut, p->vFaninsCur, nNodesSaved, Required, &GainCur, fPlaceEnable );
153p->timeEval += Abc_Clock() - clk2;
154
155 // check if the cut is better than the current best one
156 if ( pGraph != NULL && GainBest < GainCur )
157 {
158 // save this form
159 nNodesSaveCur = nNodesSaved;
160 GainBest = GainCur;
161 p->pGraph = pGraph;
162 p->fCompl = ((uPhase & (1<<4)) > 0);
163 uTruthBest = 0xFFFF & *Cut_CutReadTruth(pCut);
164 // collect fanins in the
165 Vec_PtrClear( p->vFanins );
166 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFaninsCur, pFanin, i )
167 Vec_PtrPush( p->vFanins, pFanin );
168 }
169 }
170p->timeRes += Abc_Clock() - clk;
171
172 if ( GainBest == -1 )
173 return -1;
174/*
175 if ( GainBest > 0 )
176 {
177 printf( "Class %d ", p->pMap[uTruthBest] );
178 printf( "Gain = %d. Node %d : ", GainBest, pNode->Id );
179 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
180 printf( "%d ", Abc_ObjRegular(pFanin)->Id );
181 Dec_GraphPrint( stdout, p->pGraph, NULL, NULL );
182 printf( "\n" );
183 }
184*/
185
186// printf( "%d", nNodesSaveCur - GainBest );
187/*
188 if ( GainBest > 0 )
189 {
190 if ( Rwr_CutIsBoolean( pNode, p->vFanins ) )
191 printf( "b" );
192 else
193 {
194 printf( "Node %d : ", pNode->Id );
195 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
196 printf( "%d ", Abc_ObjRegular(pFanin)->Id );
197 printf( "a" );
198 }
199 }
200*/
201/*
202 if ( GainBest > 0 )
203 if ( p->fCompl )
204 printf( "c" );
205 else
206 printf( "." );
207*/
208
209 // copy the leaves
210 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
211 Dec_GraphNode((Dec_Graph_t *)p->pGraph, i)->pFunc = pFanin;
212/*
213 printf( "(" );
214 Vec_PtrForEachEntry( Abc_Obj_t *, p->vFanins, pFanin, i )
215 printf( " %d", Abc_ObjRegular(pFanin)->vFanouts.nSize - 1 );
216 printf( " ) " );
217*/
218// printf( "%d ", Rwr_NodeGetDepth_rec( pNode, p->vFanins ) );
219
220 p->nScores[p->pMap[uTruthBest]]++;
221 p->nNodesGained += GainBest;
222 if ( fUseZeros || GainBest > 0 )
223 {
224 p->nNodesRewritten++;
225 }
226
227 // report the progress
228 if ( fVeryVerbose && GainBest > 0 )
229 {
230 printf( "Node %6s : ", Abc_ObjName(pNode) );
231 printf( "Fanins = %d. ", p->vFanins->nSize );
232 printf( "Save = %d. ", nNodesSaveCur );
233 printf( "Add = %d. ", nNodesSaveCur-GainBest );
234 printf( "GAIN = %d. ", GainBest );
235 printf( "Cone = %d. ", p->pGraph? Dec_GraphNodeNum((Dec_Graph_t *)p->pGraph) : 0 );
236 printf( "Class = %d. ", p->pMap[uTruthBest] );
237 printf( "\n" );
238 }
239 return GainBest;
240}
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
ABC_DLL int Abc_ObjRequiredLevel(Abc_Obj_t *pObj)
Definition abcTiming.c:1214
ABC_DLL int Abc_NodeMffcLabelAig(Abc_Obj_t *pNode)
Definition abcRefs.c:100
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
Definition abcNames.c:49
ABC_DLL void * Abc_NodeGetCutsRecursive(void *p, Abc_Obj_t *pObj, int fDag, int fTree)
Definition abcCut.c:412
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
struct Cut_CutStruct_t_ Cut_Cut_t
Definition cut.h:50
struct Dec_Graph_t_ Dec_Graph_t
Definition dec.h:68
Cube * p
Definition exorList.c:222
Abc_Ntk_t * pNtk
Definition abc.h:130
Cut_Cut_t * pNext
Definition cut.h:88
#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:

◆ Rwr_ScoresClean()

void Rwr_ScoresClean ( Rwr_Man_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 504 of file rwrEva.c.

505{
506 Vec_Ptr_t * vSubgraphs;
507 Rwr_Node_t * pNode;
508 int i, k;
509 for ( i = 0; i < p->vClasses->nSize; i++ )
510 {
511 vSubgraphs = Vec_VecEntry( p->vClasses, i );
512 Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
513 pNode->nScore = pNode->nGain = pNode->nAdded = 0;
514 }
515}
struct Rwr_Node_t_ Rwr_Node_t
Definition rwr.h:48
short nGain
Definition rwr.h:103
short nAdded
Definition rwr.h:104
short nScore
Definition rwr.h:102
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
Here is the caller graph for this function:

◆ Rwr_ScoresCompare()

int Rwr_ScoresCompare ( int * pNum1,
int * pNum2 )

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 530 of file rwrEva.c.

531{
532 if ( Gains[*pNum1] > Gains[*pNum2] )
533 return -1;
534 if ( Gains[*pNum1] < Gains[*pNum2] )
535 return 1;
536 return 0;
537}
Here is the caller graph for this function:

◆ Rwr_ScoresReport()

void Rwr_ScoresReport ( Rwr_Man_t * p)

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

Synopsis []

Description []

SideEffects []

SeeAlso []

Definition at line 550 of file rwrEva.c.

551{
552 extern void Ivy_TruthDsdComputePrint( unsigned uTruth );
553 int Perm[222];
554 Vec_Ptr_t * vSubgraphs;
555 Rwr_Node_t * pNode;
556 int i, iNew, k;
557 unsigned uTruth;
558 // collect total gains
559 assert( p->vClasses->nSize == 222 );
560 for ( i = 0; i < p->vClasses->nSize; i++ )
561 {
562 Perm[i] = i;
563 Gains[i] = 0;
564 vSubgraphs = Vec_VecEntry( p->vClasses, i );
565 Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
566 Gains[i] += pNode->nGain;
567 }
568 // sort the gains
569 qsort( Perm, (size_t)222, sizeof(int), (int (*)(const void *, const void *))Rwr_ScoresCompare );
570
571 // print classes
572 for ( i = 0; i < p->vClasses->nSize; i++ )
573 {
574 iNew = Perm[i];
575 if ( Gains[iNew] == 0 )
576 break;
577 vSubgraphs = Vec_VecEntry( p->vClasses, iNew );
578 printf( "CLASS %3d: Subgr = %3d. Total gain = %6d. ", iNew, Vec_PtrSize(vSubgraphs), Gains[iNew] );
579 uTruth = (unsigned)p->pMapInv[iNew];
580 Extra_PrintBinary( stdout, &uTruth, 16 );
581 printf( " " );
582 Ivy_TruthDsdComputePrint( (unsigned)p->pMapInv[iNew] | ((unsigned)p->pMapInv[iNew] << 16) );
583 Vec_PtrForEachEntry( Rwr_Node_t *, vSubgraphs, pNode, k )
584 {
585 if ( pNode->nScore == 0 )
586 continue;
587 printf( " %2d: S=%5d. A=%5d. G=%6d. ", k, pNode->nScore, pNode->nAdded, pNode->nGain );
588 Dec_GraphPrint( stdout, (Dec_Graph_t *)pNode->pNext, NULL, NULL );
589 }
590 }
591}
void Dec_GraphPrint(FILE *pFile, Dec_Graph_t *pGraph, char *pNamesIn[], char *pNameOut)
FUNCTION DEFINITIONS ///.
Definition decPrint.c:49
void Extra_PrintBinary(FILE *pFile, unsigned Sign[], int nBits)
void Ivy_TruthDsdComputePrint(unsigned uTruth)
Definition ivyDsd.c:678
int Rwr_ScoresCompare(int *pNum1, int *pNum2)
Definition rwrEva.c:530
Rwr_Node_t * pNext
Definition rwr.h:112
Here is the call graph for this function:
Here is the caller graph for this function: