ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sfmCore.c
Go to the documentation of this file.
1
20
21#include "sfmInt.h"
22#include "bool/kit/kit.h"
23
25
26
30
34
47{
48 memset( pPars, 0, sizeof(Sfm_Par_t) );
49 pPars->nTfoLevMax = 2; // the maximum fanout levels
50 pPars->nFanoutMax = 30; // the maximum number of fanouts
51 pPars->nDepthMax = 20; // the maximum depth to try
52 pPars->nWinSizeMax = 300; // the maximum window size
53 pPars->nGrowthLevel = 0; // the maximum allowed growth in level
54 pPars->nBTLimit = 5000; // the maximum number of conflicts in one SAT run
55 pPars->fRrOnly = 0; // perform redundancy removal
56 pPars->fArea = 0; // performs optimization for area
57 pPars->fMoreEffort = 0; // performs high-affort minimization
58 pPars->fAllBoxes = 0; // enable preserving all boxes
59 pPars->fVerbose = 0; // enable basic stats
60 pPars->fVeryVerbose = 0; // enable detailed stats
61}
62
75{
76 p->timeOther = p->timeTotal - p->timeWin - p->timeDiv - p->timeCnf - p->timeSat;
77 printf( "Nodes = %d. Try = %d. Resub = %d. Div = %d (ave = %d). SAT calls = %d. Timeouts = %d. MaxDivs = %d.\n",
78 Sfm_NtkNodeNum(p), p->nNodesTried, p->nRemoves + p->nResubs, p->nTotalDivs, p->nTotalDivs/Abc_MaxInt(1, p->nNodesTried), p->nSatCalls, p->nTimeOuts, p->nMaxDivs );
79
80 printf( "Attempts : " );
81 printf( "Remove %6d out of %6d (%6.2f %%) ", p->nRemoves, p->nTryRemoves, 100.0*p->nRemoves/Abc_MaxInt(1, p->nTryRemoves) );
82 printf( "Resub %6d out of %6d (%6.2f %%) ", p->nResubs, p->nTryResubs, 100.0*p->nResubs /Abc_MaxInt(1, p->nTryResubs) );
83 if ( p->pPars->fUseDcs )
84 printf( "Improves %6d out of %6d (%6.2f %%) ", p->nImproves,p->nTryImproves,100.0*p->nImproves/Abc_MaxInt(1, p->nTryImproves));
85 printf( "\n" );
86
87 printf( "Reduction: " );
88 printf( "Nodes %6d out of %6d (%6.2f %%) ", p->nTotalNodesBeg-p->nTotalNodesEnd, p->nTotalNodesBeg, 100.0*(p->nTotalNodesBeg-p->nTotalNodesEnd)/Abc_MaxInt(1, p->nTotalNodesBeg) );
89 printf( "Edges %6d out of %6d (%6.2f %%) ", p->nTotalEdgesBeg-p->nTotalEdgesEnd, p->nTotalEdgesBeg, 100.0*(p->nTotalEdgesBeg-p->nTotalEdgesEnd)/Abc_MaxInt(1, p->nTotalEdgesBeg) );
90 printf( "\n" );
91
92 ABC_PRTP( "Win", p->timeWin , p->timeTotal );
93 ABC_PRTP( "Div", p->timeDiv , p->timeTotal );
94 ABC_PRTP( "Cnf", p->timeCnf , p->timeTotal );
95 ABC_PRTP( "Sat", p->timeSat , p->timeTotal );
96 ABC_PRTP( "Oth", p->timeOther, p->timeTotal );
97 ABC_PRTP( "ALL", p->timeTotal, p->timeTotal );
98// ABC_PRTP( " ", p->time1 , p->timeTotal );
99}
100
112int Sfm_NodeResubSolve( Sfm_Ntk_t * p, int iNode, int f, int fRemoveOnly )
113{
114 int fSkipUpdate = 0;
115 int fVeryVerbose = 0;//p->pPars->fVeryVerbose && Vec_IntSize(p->vDivs) < 200;// || pNode->Id == 556;
116 int i, iFanin, iVar = -1;
117 int iFaninRem = -1, iFaninSkip = -1;
118 int nFanins = Sfm_ObjFaninNum(p, iNode);
119 word uTruth, uSign, uMask;
120 abctime clk;
121 assert( Sfm_ObjIsNode(p, iNode) );
122 assert( f >= 0 && f < Sfm_ObjFaninNum(p, iNode) );
123 p->nTryRemoves++;
124 // report init stats
125 if ( p->pPars->fVeryVerbose )
126 printf( "%5d : Lev =%3d. Leaf =%3d. Node =%3d. Div=%3d. Fanin =%4d (%d/%d). MFFC = %d\n",
127 iNode, Sfm_ObjLevel(p, iNode), 0, Vec_IntSize(p->vNodes), Vec_IntSize(p->vDivs),
128 Sfm_ObjFanin(p, iNode, f), f, Sfm_ObjFaninNum(p, iNode), Sfm_ObjMffcSize(p, Sfm_ObjFanin(p, iNode, f)) );
129 // clean simulation info
130 p->nCexes = 0;
131 Vec_WrdFill( p->vDivCexes, Vec_IntSize(p->vDivs), 0 );
132 // try removing the critical fanin
133 Vec_IntClear( p->vDivIds );
134 Sfm_ObjForEachFanin( p, iNode, iFanin, i )
135 if ( i != f )
136 Vec_IntPush( p->vDivIds, Sfm_ObjSatVar(p, iFanin) );
137 else
138 iFaninRem = iFanin;
139 assert( iFaninRem != -1 );
140 // find fanin to skip
141 if ( Sfm_ObjIsFixed(p, iFaninRem) && Sfm_ObjFaninNum(p, iFaninRem) == 1 )
142 iFaninSkip = Sfm_ObjFanin(p, iFaninRem, 0);
143clk = Abc_Clock();
144 uTruth = Sfm_ComputeInterpolant( p );
145p->timeSat += Abc_Clock() - clk;
146 // analyze outcomes
147 if ( uTruth == SFM_SAT_UNDEC )
148 {
149 p->nTimeOuts++;
150 return 0;
151 }
152 if ( uTruth != SFM_SAT_SAT )
153 goto finish;
154 if ( fRemoveOnly || p->pPars->fRrOnly || Vec_IntSize(p->vDivs) == 0 )
155 return 0;
156
157 p->nTryResubs++;
158 if ( fVeryVerbose )
159 {
160 for ( i = 0; i < 9; i++ )
161 printf( " " );
162 for ( i = 0; i < Vec_IntSize(p->vDivs); i++ )
163 printf( "%d", i % 10 );
164 printf( "\n" );
165 }
166 while ( 1 )
167 {
168 if ( fVeryVerbose )
169 {
170 printf( "%3d: %3d ", p->nCexes, iVar );
171 Vec_WrdForEachEntry( p->vDivCexes, uSign, i )
172 printf( "%d", Abc_TtGetBit(&uSign, p->nCexes-1) );
173 printf( "\n" );
174 }
175 // find the next divisor to try
176 uMask = (~(word)0) >> (64 - p->nCexes);
177 Vec_WrdForEachEntry( p->vDivCexes, uSign, iVar )
178 if ( uSign == uMask && Vec_IntEntry(p->vDivs, iVar) != iFaninSkip )
179 break;
180 if ( iVar == Vec_IntSize(p->vDivs) )
181 return 0;
182 assert( Vec_IntEntry(p->vDivs, iVar) != iFaninSkip );
183 // try replacing the critical fanin
184 Vec_IntPush( p->vDivIds, Sfm_ObjSatVar(p, Vec_IntEntry(p->vDivs, iVar)) );
185clk = Abc_Clock();
186 uTruth = Sfm_ComputeInterpolant( p );
187p->timeSat += Abc_Clock() - clk;
188 // analyze outcomes
189 if ( uTruth == SFM_SAT_UNDEC )
190 {
191 p->nTimeOuts++;
192 return 0;
193 }
194 if ( uTruth != SFM_SAT_SAT )
195 goto finish;
196 if ( p->nCexes == 64 )
197 return 0;
198 // remove the last variable
199 Vec_IntPop( p->vDivIds );
200 }
201finish:
202 if ( p->pPars->fVeryVerbose )
203 {
204 if ( iVar == -1 )
205 printf( "Node %d: Fanin %d (%d) can be removed. ", iNode, f, Sfm_ObjFanin(p, iNode, f) );
206 else
207 printf( "Node %d: Fanin %d (%d) can be replaced by divisor %d (%d). ",
208 iNode, f, Sfm_ObjFanin(p, iNode, f), iVar, Vec_IntEntry(p->vDivs, iVar) );
209 Kit_DsdPrintFromTruth( (unsigned *)&uTruth, Vec_IntSize(p->vDivIds) ); printf( "\n" );
210 }
211 if ( iVar == -1 )
212 p->nRemoves++;
213 else
214 p->nResubs++;
215 if ( fSkipUpdate )
216 return 0;
217 // update the network
218 Sfm_NtkUpdate( p, iNode, f, (iVar == -1 ? iVar : Vec_IntEntry(p->vDivs, iVar)), uTruth, p->pTruth );
219 // the number of fanins cannot increase
220 assert( nFanins >= Sfm_ObjFaninNum(p, iNode) );
221 //printf( "Modifying node %d with %d fanins (resulting in %d fanins). ", iNode, nFanins, Sfm_ObjFaninNum(p, iNode) );
222 //Abc_TtPrintHexRev( stdout, p->pTruth, Sfm_ObjFaninNum(p, iNode) );
223 //printf( "\n" );
224 return 1;
225}
226
238int Sfm_NodeResubOne( Sfm_Ntk_t * p, int iNode )
239{
240 int fSkipUpdate = 0;
241 int i, iFanin;
242 word uTruth;
243 abctime clk;
244 assert( Sfm_ObjIsNode(p, iNode) );
245 p->nTryImproves++;
246 // report init stats
247 if ( p->pPars->fVeryVerbose )
248 printf( "%5d : Lev =%3d. Leaf =%3d. Node =%3d. Div=%3d. Fanins = %d. MFFC = %d\n",
249 iNode, Sfm_ObjLevel(p, iNode), 0, Vec_IntSize(p->vNodes), Vec_IntSize(p->vDivs),
250 Sfm_ObjFaninNum(p, iNode), Sfm_ObjMffcSize(p, iNode) );
251 // collect fanins
252 Vec_IntClear( p->vDivIds );
253 Sfm_ObjForEachFanin( p, iNode, iFanin, i )
254 Vec_IntPush( p->vDivIds, Sfm_ObjSatVar(p, iFanin) );
255clk = Abc_Clock();
256 uTruth = Sfm_ComputeInterpolant2( p );
257p->timeSat += Abc_Clock() - clk;
258 // analyze outcomes
259 if ( uTruth == SFM_SAT_UNDEC )
260 {
261 p->nTimeOuts++;
262 return 0;
263 }
264 assert( uTruth != SFM_SAT_SAT );
265 if ( uTruth == Vec_WrdEntry(p->vTruths, iNode) )
266 return 0;
267 else
268 {
269 word uTruth0 = Vec_WrdEntry(p->vTruths, iNode);
270 //word uTruth0N = ~uTruth0;
271 //word uTruthN = ~uTruth;
272 int Old = Kit_TruthLitNum((unsigned*)&uTruth0, Sfm_ObjFaninNum(p, iNode), p->vCover);
273 //int OldN = Kit_TruthLitNum((unsigned*)&uTruth0N, Sfm_ObjFaninNum(p, iNode), p->vCover);
274 int New = Kit_TruthLitNum((unsigned*)&uTruth, Sfm_ObjFaninNum(p, iNode), p->vCover);
275 //int NewN = Kit_TruthLitNum((unsigned*)&uTruthN, Sfm_ObjFaninNum(p, iNode), p->vCover);
276 //if ( Abc_MinInt(New, NewN) > Abc_MinInt(Old, OldN) )
277 if ( New > Old )
278 return 0;
279 }
280 p->nImproves++;
281 if ( fSkipUpdate )
282 return 0;
283 // update truth table
284 Vec_WrdWriteEntry( p->vTruths, iNode, uTruth );
285 Sfm_TruthToCnf( uTruth, NULL, Sfm_ObjFaninNum(p, iNode), p->vCover, (Vec_Str_t *)Vec_WecEntry(p->vCnfs, iNode) );
286 return 1;
287}
288int Sfm_NodeResub( Sfm_Ntk_t * p, int iNode )
289{
290 int i, iFanin;
291 p->nNodesTried++;
292 // prepare SAT solver
293 if ( !Sfm_NtkCreateWindow( p, iNode, p->pPars->fVeryVerbose ) )
294 return 0;
295 if ( !Sfm_NtkWindowToSolver( p ) )
296 return 0;
297 // try replacing area critical fanins
298 Sfm_ObjForEachFanin( p, iNode, iFanin, i )
299 if ( Sfm_ObjIsNode(p, iFanin) && Sfm_ObjFanoutNum(p, iFanin) == 1 )
300 {
301 if ( Sfm_NodeResubSolve( p, iNode, i, 0 ) )
302 return 1;
303 }
304 // try removing redundant edges
305 if ( !p->pPars->fArea )
306 Sfm_ObjForEachFanin( p, iNode, iFanin, i )
307 if ( !(Sfm_ObjIsNode(p, iFanin) && Sfm_ObjFanoutNum(p, iFanin) == 1) )
308 {
309 if ( Sfm_NodeResubSolve( p, iNode, i, 1 ) )
310 return 1;
311 }
312 // try simplifying local functions
313 if ( p->pPars->fUseDcs && Sfm_ObjFaninNum(p, iNode) <= 6 )
314 if ( Sfm_NodeResubOne( p, iNode ) )
315 return 1;
316/*
317 // try replacing area critical fanins while adding two new fanins
318 if ( Sfm_ObjFaninNum(p, iNode) < p->nFaninMax )
319 Abc_ObjForEachFanin( pNode, pFanin, i )
320 if ( !Abc_ObjIsCi(pFanin) && Abc_ObjFanoutNum(pFanin) == 1 )
321 {
322 if ( Abc_NtkMfsSolveSatResub2( p, pNode, i, -1 ) )
323 return 1;
324 }
325*/
326 return 0;
327}
328
341{
342 int i;
343 for ( i = 0; i < p->nObjs; i++ )
344 {
345 Vec_Int_t * vArray = Vec_WecEntry( &p->vFanins, i );
346 printf( "Obj %3d : ", i );
347 printf( "Fixed %d ", Vec_StrEntry(p->vFixed, i) );
348 printf( "Empty %d ", Vec_StrEntry(p->vEmpty, i) );
349 printf( "Truth " );
350 Extra_PrintHex( stdout, (unsigned *)Vec_WrdEntryP(p->vTruths, i), Vec_IntSize(vArray) );
351 printf( " " );
352 Vec_IntPrint( vArray );
353 }
354}
355
368{
369 int i, k, Counter = 0, CounterLarge = 0;
370 //Sfm_NtkPrint( p );
371 p->timeTotal = Abc_Clock();
372 if ( pPars->fVerbose )
373 {
374 int nFixed = p->vFixed ? Vec_StrSum(p->vFixed) : 0;
375 int nEmpty = p->vEmpty ? Vec_StrSum(p->vEmpty) : 0;
376 printf( "Performing MFS with %d PIs, %d POs, %d nodes (%d flexible, %d fixed, %d empty).\n",
377 p->nPis, p->nPos, p->nNodes, p->nNodes-nFixed, nFixed, nEmpty );
378 }
379 p->pPars = pPars;
380 Sfm_NtkPrepare( p );
381// Sfm_ComputeInterpolantCheck( p );
382// return 0;
383 p->nTotalNodesBeg = Vec_WecSizeUsedLimits( &p->vFanins, Sfm_NtkPiNum(p), Vec_WecSize(&p->vFanins) - Sfm_NtkPoNum(p) );
384 p->nTotalEdgesBeg = Vec_WecSizeSize(&p->vFanins) - Sfm_NtkPoNum(p);
386 {
387 if ( Sfm_ObjIsFixed( p, i ) )
388 continue;
389 if ( p->pPars->nDepthMax && Sfm_ObjLevel(p, i) > p->pPars->nDepthMax )
390 continue;
391 //if ( Sfm_ObjFaninNum(p, i) < 2 )
392 // continue;
393 if ( Sfm_ObjFaninNum(p, i) > SFM_SUPP_MAX )
394 {
395 CounterLarge++;
396 continue;
397 }
398 for ( k = 0; Sfm_NodeResub(p, i); k++ )
399 {
400// Counter++;
401// break;
402 }
403 Counter += (k > 0);
404 if ( pPars->nNodesMax && Counter >= pPars->nNodesMax )
405 break;
406 }
407 p->nTotalNodesEnd = Vec_WecSizeUsedLimits( &p->vFanins, Sfm_NtkPiNum(p), Vec_WecSize(&p->vFanins) - Sfm_NtkPoNum(p) );
408 p->nTotalEdgesEnd = Vec_WecSizeSize(&p->vFanins) - Sfm_NtkPoNum(p);
409 p->timeTotal = Abc_Clock() - p->timeTotal;
410 if ( pPars->fVerbose && CounterLarge )
411 printf( "MFS skipped %d (out of %d) nodes with more than %d fanins.\n", CounterLarge, p->nNodes, SFM_SUPP_MAX );
412 if ( pPars->fVerbose )
414 //Sfm_NtkPrint( p );
415 return Counter;
416}
417
421
422
424
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Vec_Str_t_ Vec_Str_t
Definition bblif.c:46
Cube * p
Definition exorList.c:222
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Kit_TruthLitNum(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition kitGraph.c:511
void Kit_DsdPrintFromTruth(unsigned *pTruth, int nVars)
Definition kitDsd.c:491
int Sfm_TruthToCnf(word Truth, word *pTruth, int nVars, Vec_Int_t *vCover, Vec_Str_t *vCnf)
Definition sfmCnf.c:71
int Sfm_NodeResub(Sfm_Ntk_t *p, int iNode)
Definition sfmCore.c:288
int Sfm_NtkPerform(Sfm_Ntk_t *p, Sfm_Par_t *pPars)
Definition sfmCore.c:367
void Sfm_NtkPrint(Sfm_Ntk_t *p)
Definition sfmCore.c:340
int Sfm_NodeResubSolve(Sfm_Ntk_t *p, int iNode, int f, int fRemoveOnly)
Definition sfmCore.c:112
int Sfm_NodeResubOne(Sfm_Ntk_t *p, int iNode)
Definition sfmCore.c:238
void Sfm_NtkPrintStats(Sfm_Ntk_t *p)
Definition sfmCore.c:74
ABC_NAMESPACE_IMPL_START void Sfm_ParSetDefault(Sfm_Par_t *pPars)
DECLARATIONS ///.
Definition sfmCore.c:46
int Sfm_NtkCreateWindow(Sfm_Ntk_t *p, int iNode, int fVerbose)
Definition sfmWin.c:340
#define Sfm_ObjForEachFanin(p, Node, Fan, i)
Definition sfmInt.h:199
void Sfm_NtkUpdate(Sfm_Ntk_t *p, int iNode, int f, int iFaninNew, word uTruth, word *pTruth)
Definition sfmNtk.c:322
#define Sfm_NtkForEachNode(p, i)
Definition sfmInt.h:197
int Sfm_NtkWindowToSolver(Sfm_Ntk_t *p)
DECLARATIONS ///.
Definition sfmSat.c:46
#define SFM_SAT_SAT
Definition sfmInt.h:54
void Sfm_NtkPrepare(Sfm_Ntk_t *p)
Definition sfmNtk.c:201
word Sfm_ComputeInterpolant(Sfm_Ntk_t *p)
Definition sfmSat.c:154
#define SFM_SUPP_MAX
Definition sfmInt.h:56
word Sfm_ComputeInterpolant2(Sfm_Ntk_t *p)
Definition sfmSat.c:294
int Sfm_ObjMffcSize(Sfm_Ntk_t *p, int iObj)
Definition sfmWin.c:89
#define SFM_SAT_UNDEC
Definition sfmInt.h:53
struct Sfm_Par_t_ Sfm_Par_t
Definition sfm.h:42
typedefABC_NAMESPACE_HEADER_START struct Sfm_Ntk_t_ Sfm_Ntk_t
INCLUDES ///.
Definition sfm.h:41
int fRrOnly
Definition sfm.h:62
int nGrowthLevel
Definition sfm.h:54
int nTfoLevMax
Definition sfm.h:45
int fVeryVerbose
Definition sfm.h:75
int nFanoutMax
Definition sfm.h:47
int fMoreEffort
Definition sfm.h:65
int fAllBoxes
Definition sfm.h:71
int fArea
Definition sfm.h:63
int nWinSizeMax
Definition sfm.h:53
int nNodesMax
Definition sfm.h:56
int nDepthMax
Definition sfm.h:48
int nBTLimit
Definition sfm.h:55
int fVerbose
Definition sfm.h:74
#define assert(ex)
Definition util_old.h:213
char * memset()
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecWrd.h:54