ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
sfmDec.c
Go to the documentation of this file.
1
20
21#include "sfmInt.h"
22#include "misc/st/st.h"
23#include "map/mio/mio.h"
24#include "base/abc/abc.h"
25#include "misc/util/utilTruth.h"
26#include "opt/dau/dau.h"
27#include "map/mio/exp.h"
28#include "map/scl/sclCon.h"
29#include "base/main/main.h"
30
32
33
37
38typedef struct Sfm_Dec_t_ Sfm_Dec_t;
40{
41 // external
42 Sfm_Par_t * pPars; // parameters
43 Sfm_Lib_t * pLib; // library
44 Sfm_Tim_t * pTim; // timing
45 Sfm_Mit_t * pMit; // timing
46 Abc_Ntk_t * pNtk; // network
47 // library
48 Vec_Int_t vGateSizes; // fanin counts
49 Vec_Wrd_t vGateFuncs; // gate truth tables
50 Vec_Wec_t vGateCnfs; // gate CNFs
51 Vec_Ptr_t vGateHands; // gate handles
52 int GateConst0; // special gates
53 int GateConst1; // special gates
54 int GateBuffer; // special gates
55 int GateInvert; // special gates
56 int GateAnd[4]; // special gates
57 int GateOr[4]; // special gates
58 // objects
59 int nDivs; // the number of divisors
60 int nMffc; // the number of divisors
61 int AreaMffc; // the area of gates in MFFC
62 int DelayMin; // temporary min delay
63 int iTarget; // target node
64 int iUseThis; // next cofactoring var to try
65 int DeltaCrit; // critical delta
66 int AreaInv; // inverter area
67 int DelayInv; // inverter delay
68 Mio_Gate_t * pGateInv; // inverter
69 word uCareSet; // computed careset
70 Vec_Int_t vObjRoots; // roots of the window
71 Vec_Int_t vObjGates; // functionality
72 Vec_Wec_t vObjFanins; // fanin IDs
73 Vec_Int_t vObjMap; // object map
74 Vec_Int_t vObjDec; // decomposition
75 Vec_Int_t vObjMffc; // MFFC nodes
76 Vec_Int_t vObjInMffc; // inputs of MFFC nodes
77 Vec_Wrd_t vObjSims; // simulation patterns
78 Vec_Wrd_t vObjSims2; // simulation patterns
79 Vec_Ptr_t vMatchGates; // matched gates
80 Vec_Ptr_t vMatchFans; // matched fanins
81 // solver
82 sat_solver * pSat; // reusable solver
83 Vec_Wec_t vClauses; // CNF clauses for the node
84 Vec_Int_t vImpls[2]; // onset/offset implications
85 Vec_Wrd_t vSets[2]; // onset/offset patterns
86 int nPats[2]; // CEX count
87 int nPatWords[2];// CEX words
88 int nDivWords; // div words
89 int nDivWordsAlloc; // div words
93 // temporary
103 // statistics
140};
141
142#define SFM_MASK_PI 1 // supp(node) is contained in supp(TFI(pivot))
143#define SFM_MASK_INPUT 2 // supp(node) does not overlap with supp(TFI(pivot))
144#define SFM_MASK_FANIN 4 // the same as above (pointed to by node with SFM_MASK_PI | SFM_MASK_INPUT)
145#define SFM_MASK_MFFC 8 // MFFC nodes, including the target node
146#define SFM_MASK_PIVOT 16 // the target node
147
148static inline Sfm_Dec_t * Sfm_DecMan( Abc_Obj_t * p ) { return (Sfm_Dec_t *)p->pNtk->pData; }
149static inline word Sfm_DecObjSim( Sfm_Dec_t * p, Abc_Obj_t * pObj ) { return Vec_WrdEntry(&p->vObjSims, Abc_ObjId(pObj)); }
150static inline word Sfm_DecObjSim2( Sfm_Dec_t * p, Abc_Obj_t * pObj ) { return Vec_WrdEntry(&p->vObjSims2, Abc_ObjId(pObj)); }
151static inline word * Sfm_DecDivPats( Sfm_Dec_t * p, int d, int c ) { return Vec_WrdEntryP(&p->vSets[c], d*SFM_SIM_WORDS); }
152
153static inline int Sfm_ManReadObjDelay( Sfm_Dec_t * p, int Id ) { return p->pMit ? Sfm_MitReadObjDelay(p->pMit, Id) : Sfm_TimReadObjDelay(p->pTim, Id); }
154static inline int Sfm_ManReadNtkDelay( Sfm_Dec_t * p ) { return p->pMit ? Sfm_MitReadNtkDelay(p->pMit) : Sfm_TimReadNtkDelay(p->pTim); }
155static inline int Sfm_ManReadNtkMinSlack( Sfm_Dec_t * p ) { return p->pMit ? Sfm_MitReadNtkMinSlack(p->pMit) : 0; }
156
157
158
162
175{
176 memset( pPars, 0, sizeof(Sfm_Par_t) );
177 pPars->nTfoLevMax = 100; // the maximum fanout levels
178 pPars->nTfiLevMax = 100; // the maximum fanin levels
179 pPars->nFanoutMax = 10; // the maximum number of fanouts
180 pPars->nMffcMin = 1; // the maximum MFFC size
181 pPars->nMffcMax = 3; // the maximum MFFC size
182 pPars->nVarMax = 6; // the maximum variable count
183 pPars->nDecMax = 1; // the maximum number of decompositions
184 pPars->nWinSizeMax = 0; // the maximum window size
185 pPars->nGrowthLevel = 0; // the maximum allowed growth in level
186 pPars->nBTLimit = 0; // the maximum number of conflicts in one SAT run
187 pPars->nTimeWin = 1; // the size of timing window in percents
188 pPars->DeltaCrit = 0; // delta delay in picoseconds
189 pPars->fUseAndOr = 0; // enable internal detection of AND/OR gates
190 pPars->fZeroCost = 0; // enable zero-cost replacement
191 pPars->fMoreEffort = 0; // enables using more effort
192 pPars->fUseSim = 0; // enable simulation
193 pPars->fArea = 0; // performs optimization for area
194 pPars->fVerbose = 0; // enable basic stats
195 pPars->fVeryVerbose = 0; // enable detailed stats
196}
197
210{
211 extern void Sfm_LibPreprocess( Mio_Library_t * pLib, Vec_Int_t * vGateSizes, Vec_Wrd_t * vGateFuncs, Vec_Wec_t * vGateCnfs, Vec_Ptr_t * vGateHands );
212 Sfm_Dec_t * p = ABC_CALLOC( Sfm_Dec_t, 1 ); int i;
213 p->timeStart = Abc_Clock();
214 p->pPars = pPars;
215 p->pNtk = pNtk;
216 p->pSat = sat_solver_new();
217 p->pGateInv = Mio_LibraryReadInv( pLib );
218 p->AreaInv = Scl_Flt2Int(Mio_GateReadArea(p->pGateInv));
219 p->DelayInv = Scl_Flt2Int(Mio_GateReadDelayMax(p->pGateInv));
220 p->DeltaCrit = pPars->DeltaCrit ? Scl_Flt2Int((float)pPars->DeltaCrit) : 5 * Scl_Flt2Int(Mio_LibraryReadDelayInvMax(pLib)) / 2;
221p->timeLib = Abc_Clock();
222 p->pLib = Sfm_LibPrepare( pPars->nVarMax, 1, !pPars->fArea, pPars->fVerbose, pPars->fLibVerbose );
223p->timeLib = Abc_Clock() - p->timeLib;
224 if ( !pPars->fArea )
225 {
226 if ( Abc_FrameReadLibScl() )
227 p->pMit = Sfm_MitStart( pLib, (SC_Lib *)Abc_FrameReadLibScl(), Scl_ConReadMan(), pNtk, p->DeltaCrit );
228 if ( p->pMit == NULL )
229 p->pTim = Sfm_TimStart( pLib, Scl_ConReadMan(), pNtk, p->DeltaCrit );
230 }
231 if ( pPars->fVeryVerbose )
232// if ( pPars->fVerbose )
233 Sfm_LibPrint( p->pLib );
234 pNtk->pData = p;
235 // enter library
236 assert( Abc_NtkIsMappedLogic(pNtk) );
237 Sfm_LibPreprocess( pLib, &p->vGateSizes, &p->vGateFuncs, &p->vGateCnfs, &p->vGateHands );
238 p->GateConst0 = Mio_GateReadValue( Mio_LibraryReadConst0(pLib) );
239 p->GateConst1 = Mio_GateReadValue( Mio_LibraryReadConst1(pLib) );
240 p->GateBuffer = Mio_GateReadValue( Mio_LibraryReadBuf(pLib) );
241 p->GateInvert = Mio_GateReadValue( Mio_LibraryReadInv(pLib) );
242 // elementary truth tables
243 for ( i = 0; i < SFM_SUPP_MAX; i++ )
244 p->pTtElems[i] = p->TtElems[i];
245 Abc_TtElemInit( p->pTtElems, SFM_SUPP_MAX );
246 p->iUseThis = -1;
247 return p;
248}
250{
251 Abc_Ntk_t * pNtk = p->pNtk;
252 Abc_Obj_t * pObj; int i;
253 Abc_NtkForEachNode( pNtk, pObj, i )
254 if ( (int)pObj->Level != Abc_ObjLevelNew(pObj) )
255 printf( "Level count mismatch at node %d.\n", i );
256 Sfm_LibStop( p->pLib );
257 if ( p->pTim ) Sfm_TimStop( p->pTim );
258 if ( p->pMit ) Sfm_MitStop( p->pMit );
259 // divisors
260 for ( i = 0; i < SFM_SUPP_MAX; i++ )
261 ABC_FREE( p->pDivWords[i] );
262 // library
263 Vec_IntErase( &p->vGateSizes );
264 Vec_WrdErase( &p->vGateFuncs );
265 Vec_WecErase( &p->vGateCnfs );
266 Vec_PtrErase( &p->vGateHands );
267 // objects
268 Vec_IntErase( &p->vObjRoots );
269 Vec_IntErase( &p->vObjGates );
270 Vec_WecErase( &p->vObjFanins );
271 Vec_IntErase( &p->vObjMap );
272 Vec_IntErase( &p->vObjDec );
273 Vec_IntErase( &p->vObjMffc );
274 Vec_IntErase( &p->vObjInMffc );
275 Vec_WrdErase( &p->vObjSims );
276 Vec_WrdErase( &p->vObjSims2 );
277 Vec_PtrErase( &p->vMatchGates );
278 Vec_PtrErase( &p->vMatchFans );
279 // solver
280 sat_solver_delete( p->pSat );
281 Vec_WecErase( &p->vClauses );
282 Vec_IntErase( &p->vImpls[0] );
283 Vec_IntErase( &p->vImpls[1] );
284 Vec_WrdErase( &p->vSets[0] );
285 Vec_WrdErase( &p->vSets[1] );
286 // temporary
287 Vec_IntErase( &p->vNewNodes );
288 Vec_IntErase( &p->vGateTfi );
289 Vec_IntErase( &p->vGateTfo );
290 Vec_IntErase( &p->vGateCut );
291 Vec_IntErase( &p->vGateTemp );
292 Vec_IntErase( &p->vGateMffc );
293 Vec_IntErase( &p->vCands );
294 ABC_FREE( p );
295 pNtk->pData = NULL;
296}
297
309static inline word Sfm_ObjSimulate( Abc_Obj_t * pObj )
310{
311 Sfm_Dec_t * p = Sfm_DecMan( pObj );
312 Vec_Int_t * vExpr = Mio_GateReadExpr( (Mio_Gate_t *)pObj->pData );
313 Abc_Obj_t * pFanin; int i; word uFanins[6];
314 assert( Abc_ObjFaninNum(pObj) <= 6 );
315 Abc_ObjForEachFanin( pObj, pFanin, i )
316 uFanins[i] = Sfm_DecObjSim( p, pFanin );
317 return Exp_Truth6( Abc_ObjFaninNum(pObj), vExpr, uFanins );
318}
319static inline word Sfm_ObjSimulate2( Abc_Obj_t * pObj )
320{
321 Sfm_Dec_t * p = Sfm_DecMan( pObj );
322 Vec_Int_t * vExpr = Mio_GateReadExpr( (Mio_Gate_t *)pObj->pData );
323 Abc_Obj_t * pFanin; int i; word uFanins[6];
324 Abc_ObjForEachFanin( pObj, pFanin, i )
325 if ( (pFanin->iTemp & SFM_MASK_PIVOT) )
326 uFanins[i] = Sfm_DecObjSim2( p, pFanin );
327 else
328 uFanins[i] = Sfm_DecObjSim( p, pFanin );
329 return Exp_Truth6( Abc_ObjFaninNum(pObj), vExpr, uFanins );
330}
331static inline void Sfm_NtkSimulate( Abc_Ntk_t * pNtk )
332{
333 Vec_Ptr_t * vNodes;
334 Abc_Obj_t * pObj; int i; word uTemp;
335 Sfm_Dec_t * p = Sfm_DecMan( Abc_NtkPi(pNtk, 0) );
336 Vec_WrdFill( &p->vObjSims, 2*Abc_NtkObjNumMax(pNtk), 0 );
337 Vec_WrdFill( &p->vObjSims2, 2*Abc_NtkObjNumMax(pNtk), 0 );
339 assert( p->pPars->fUseSim );
340 Abc_NtkForEachCi( pNtk, pObj, i )
341 {
342 Vec_WrdWriteEntry( &p->vObjSims, Abc_ObjId(pObj), (uTemp = Gia_ManRandomW(0)) );
343 //printf( "Inpt = %5d : ", Abc_ObjId(pObj) );
344 //Extra_PrintBinary( stdout, (unsigned *)&uTemp, 64 );
345 //printf( "\n" );
346 }
347 vNodes = Abc_NtkDfs( pNtk, 1 );
348 Vec_PtrForEachEntry( Abc_Obj_t *, vNodes, pObj, i )
349 {
350 Vec_WrdWriteEntry( &p->vObjSims, Abc_ObjId(pObj), (uTemp = Sfm_ObjSimulate(pObj)) );
351 //printf( "Obj = %5d : ", Abc_ObjId(pObj) );
352 //Extra_PrintBinary( stdout, (unsigned *)&uTemp, 64 );
353 //printf( "\n" );
354 }
355 Vec_PtrFree( vNodes );
356}
357static inline void Sfm_ObjSimulateNode( Abc_Obj_t * pObj )
358{
359 Sfm_Dec_t * p = Sfm_DecMan( pObj );
360 if ( !p->pPars->fUseSim )
361 return;
362 Vec_WrdWriteEntry( &p->vObjSims, Abc_ObjId(pObj), Sfm_ObjSimulate(pObj) );
363 if ( (pObj->iTemp & SFM_MASK_PIVOT) )
364 Vec_WrdWriteEntry( &p->vObjSims2, Abc_ObjId(pObj), Sfm_ObjSimulate2(pObj) );
365}
366static inline void Sfm_ObjFlipNode( Abc_Obj_t * pObj )
367{
368 Sfm_Dec_t * p = Sfm_DecMan( pObj );
369 if ( !p->pPars->fUseSim )
370 return;
371 Vec_WrdWriteEntry( &p->vObjSims2, Abc_ObjId(pObj), ~Sfm_DecObjSim(p, pObj) );
372}
373static inline word Sfm_ObjFindCareSet( Abc_Ntk_t * pNtk, Vec_Int_t * vRoots )
374{
375 Sfm_Dec_t * p = Sfm_DecMan( Abc_NtkPi(pNtk, 0) );
376 Abc_Obj_t * pObj; int i; word Res = 0;
377 if ( !p->pPars->fUseSim )
378 return 0;
379 Abc_NtkForEachObjVec( vRoots, pNtk, pObj, i )
380 Res |= Sfm_DecObjSim(p, pObj) ^ Sfm_DecObjSim2(p, pObj);
381 return Res;
382}
383static inline void Sfm_ObjSetupSimInfo( Abc_Obj_t * pObj )
384{
385 Sfm_Dec_t * p = Sfm_DecMan( pObj ); int i;
386 p->nPats[0] = p->nPats[1] = 0;
387 p->nPatWords[0] = p->nPatWords[1] = 0;
388 Vec_WrdFill( &p->vSets[0], p->nDivs*SFM_SIM_WORDS, 0 );
389 Vec_WrdFill( &p->vSets[1], p->nDivs*SFM_SIM_WORDS, 0 );
390 // alloc divwords
391 p->nDivWords = Abc_Bit6WordNum( 4 * p->nDivs );
392 if ( p->nDivWordsAlloc < p->nDivWords )
393 {
394 p->nDivWordsAlloc = Abc_MaxInt( 16, p->nDivWords );
395 for ( i = 0; i < SFM_SUPP_MAX; i++ )
396 p->pDivWords[i] = ABC_REALLOC( word, p->pDivWords[i], p->nDivWordsAlloc );
397 }
398 memset( p->pDivWords[0], 0, sizeof(word) * p->nDivWords );
399 // collect simulation info
400 if ( p->pPars->fUseSim && p->uCareSet != 0 )
401 {
402 word uCareSet = p->uCareSet;
403 word uValues = Sfm_DecObjSim(p, pObj);
404 int c, d, i, Indexes[2][64];
405 assert( p->iTarget == pObj->iTemp );
406 assert( p->pPars->fUseSim );
407 // find what patterns go to on-set/off-set
408 for ( i = 0; i < 64; i++ )
409 if ( (uCareSet >> i) & 1 )
410 {
411 c = !((uValues >> i) & 1);
412 Indexes[c][p->nPats[c]++] = i;
413 }
414 for ( c = 0; c < 2; c++ )
415 p->nPatWords[c] = 1 + (p->nPats[c] >> 6);
416 // write patterns
417 for ( d = 0; d < p->nDivs; d++ )
418 {
419 word uSim = Vec_WrdEntry( &p->vObjSims, Vec_IntEntry(&p->vObjMap, d) );
420 for ( c = 0; c < 2; c++ )
421 for ( i = 0; i < p->nPats[c]; i++ )
422 if ( (uSim >> Indexes[c][i]) & 1 )
423 Abc_TtSetBit( Sfm_DecDivPats(p, d, c), i );
424 }
425 //printf( "Node %d : Onset = %d. Offset = %d.\n", pObj->Id, p->nPats[0], p->nPats[1] );
426 }
427}
428static inline void Sfm_ObjSetdownSimInfo( Abc_Obj_t * pObj )
429{
430 int nPatKeep = 32;
431 Sfm_Dec_t * p = Sfm_DecMan( pObj );
432 int c, d; word uSim, uSims[2], uMask;
433 if ( !p->pPars->fUseSim )
434 return;
435 for ( d = 0; d < p->nDivs; d++ )
436 {
437 uSim = Vec_WrdEntry( &p->vObjSims, Vec_IntEntry(&p->vObjMap, d) );
438 for ( c = 0; c < 2; c++ )
439 {
440 uMask = Abc_Tt6Mask( Abc_MinInt(p->nPats[c], nPatKeep) );
441 uSims[c] = (Sfm_DecDivPats(p, d, c)[0] & uMask) | (uSim & ~uMask);
442 uSim >>= 32;
443 }
444 uSim = (uSims[0] & 0xFFFFFFFF) | (uSims[1] << 32);
445 Vec_WrdWriteEntry( &p->vObjSims, Vec_IntEntry(&p->vObjMap, d), uSim );
446 }
447}
448/*
449void Sfm_ObjSetdownSimInfo( Abc_Obj_t * pObj )
450{
451 int nPatKeep = 32;
452 Sfm_Dec_t * p = Sfm_DecMan( pObj );
453 word uSim, uMaskKeep[2];
454 int c, d, nKeeps[2];
455 for ( c = 0; c < 2; c++ )
456 {
457 nKeeps[c] = Abc_MaxInt(p->nPats[c], nPatKeep);
458 uMaskKeep[c] = Abc_Tt6Mask( nKeeps[c] );
459 }
460 for ( d = 0; d < p->nDivs; d++ )
461 {
462 uSim = Vec_WrdEntry( &p->vObjSims, Vec_IntEntry(&p->vObjMap, d) ) << (nKeeps[0] + nKeeps[1]);
463 uSim |= (Vec_WrdEntry(&p->vSets[0], d) & uMaskKeep[0]) | ((Vec_WrdEntry(&p->vSets[1], d) & uMaskKeep[1]) << nKeeps[0]);
464 Vec_WrdWriteEntry( &p->vObjSims, Vec_IntEntry(&p->vObjMap, d), uSim );
465 }
466}
467*/
468
481{
482 Vec_Int_t * vRoots = &p->vObjRoots;
483 Vec_Int_t * vFaninVars = &p->vGateTemp;
484 Vec_Int_t * vLevel, * vClause;
485 int i, k, Gate, iObj, RetValue;
486 int nTfiSize = p->iTarget + 1; // including node
487 int nWinSize = Vec_IntSize(&p->vObjGates);
488 int nSatVars = 2 * nWinSize - nTfiSize;
489 assert( nWinSize == Vec_IntSize(&p->vObjGates) );
490 assert( p->iTarget < nWinSize );
491 // create SAT solver
492 sat_solver_restart( p->pSat );
493 sat_solver_setnvars( p->pSat, nSatVars + Vec_IntSize(vRoots) );
494 // add CNF clauses for the TFI
495 Vec_IntForEachEntry( &p->vObjGates, Gate, i )
496 {
497 if ( Gate == -1 )
498 continue;
499 // generate CNF
500 vLevel = Vec_WecEntry( &p->vObjFanins, i );
501 Vec_IntPush( vLevel, i );
502 Sfm_TranslateCnf( &p->vClauses, (Vec_Str_t *)Vec_WecEntry(&p->vGateCnfs, Gate), vLevel, -1 );
503 Vec_IntPop( vLevel );
504 // add clauses
505 Vec_WecForEachLevel( &p->vClauses, vClause, k )
506 {
507 if ( Vec_IntSize(vClause) == 0 )
508 break;
509 RetValue = sat_solver_addclause( p->pSat, Vec_IntArray(vClause), Vec_IntArray(vClause) + Vec_IntSize(vClause) );
510 if ( RetValue == 0 )
511 return 0;
512 }
513 }
514 // add CNF clauses for the TFO
515 Vec_IntForEachEntryStart( &p->vObjGates, Gate, i, nTfiSize )
516 {
517 assert( Gate != -1 );
518 vLevel = Vec_WecEntry( &p->vObjFanins, i );
519 Vec_IntClear( vFaninVars );
520 Vec_IntForEachEntry( vLevel, iObj, k )
521 Vec_IntPush( vFaninVars, iObj <= p->iTarget ? iObj : iObj + nWinSize - nTfiSize );
522 Vec_IntPush( vFaninVars, i + nWinSize - nTfiSize );
523 // generate CNF
524 Sfm_TranslateCnf( &p->vClauses, (Vec_Str_t *)Vec_WecEntry(&p->vGateCnfs, Gate), vFaninVars, p->iTarget );
525 // add clauses
526 Vec_WecForEachLevel( &p->vClauses, vClause, k )
527 {
528 if ( Vec_IntSize(vClause) == 0 )
529 break;
530 RetValue = sat_solver_addclause( p->pSat, Vec_IntArray(vClause), Vec_IntArray(vClause) + Vec_IntSize(vClause) );
531 if ( RetValue == 0 )
532 return 0;
533 }
534 }
535 if ( nTfiSize < nWinSize )
536 {
537 // create XOR clauses for the roots
538 Vec_IntClear( vFaninVars );
539 Vec_IntForEachEntry( vRoots, iObj, i )
540 {
541 Vec_IntPush( vFaninVars, Abc_Var2Lit(nSatVars, 0) );
542 sat_solver_add_xor( p->pSat, iObj, iObj + nWinSize - nTfiSize, nSatVars++, 0 );
543 }
544 // make OR clause for the last nRoots variables
545 RetValue = sat_solver_addclause( p->pSat, Vec_IntArray(vFaninVars), Vec_IntLimit(vFaninVars) );
546 if ( RetValue == 0 )
547 return 0;
548 assert( nSatVars == sat_solver_nvars(p->pSat) );
549 }
550 else assert( Vec_IntSize(vRoots) == 1 );
551 // finalize
552 RetValue = sat_solver_simplify( p->pSat );
553 return 1;
554}
555
567int Sfm_DecFindCost( Sfm_Dec_t * p, int c, int iLit, word * pMask )
568{
569 word * pPats = Sfm_DecDivPats( p, Abc_Lit2Var(iLit), !c );
570 return Abc_TtCountOnesVecMask( pPats, pMask, p->nPatWords[!c], Abc_LitIsCompl(iLit) );
571}
573{
574 int c, i, k, Entry;
575 for ( c = 0; c < 2; c++ )
576 {
577 Vec_Int_t * vLevel = Vec_WecEntry( &p->vObjFanins, p->iTarget );
578 printf( "%s-SET of object %d (divs = %d) with gate \"%s\" and fanins: ",
579 c ? "OFF": "ON", p->iTarget, p->nDivs,
580 Mio_GateReadName((Mio_Gate_t *)Vec_PtrEntry(&p->vGateHands, Vec_IntEntry(&p->vObjGates,p->iTarget))) );
581 Vec_IntForEachEntry( vLevel, Entry, i )
582 printf( "%d ", Entry );
583 printf( "\n" );
584
585 printf( "Implications: " );
586 Vec_IntForEachEntry( &p->vImpls[c], Entry, i )
587 printf( "%s%d(%d) ", Abc_LitIsCompl(Entry)? "!":"", Abc_Lit2Var(Entry), Sfm_DecFindCost(p, c, Entry, Masks[!c]) );
588 printf( "\n" );
589 printf( " " );
590 for ( i = 0; i < p->nDivs; i++ )
591 printf( "%d", (i / 10) % 10 );
592 printf( "\n" );
593 printf( " " );
594 for ( i = 0; i < p->nDivs; i++ )
595 printf( "%d", i % 10 );
596 printf( "\n" );
597 for ( k = 0; k < p->nPats[c]; k++ )
598 {
599 printf( "%2d : ", k );
600 for ( i = 0; i < p->nDivs; i++ )
601 printf( "%d", Abc_TtGetBit(Sfm_DecDivPats(p, i, c), k) );
602 printf( "\n" );
603 }
604 //printf( "\n" );
605 }
606}
607
619void Sfm_DecVarCost( Sfm_Dec_t * p, word Masks[2][SFM_SIM_WORDS], int d, int Counts[2][2] )
620{
621 int c;
622 for ( c = 0; c < 2; c++ )
623 {
624 word * pPats = Sfm_DecDivPats( p, d, c );
625 int Num = Abc_TtCountOnesVec( Masks[c], p->nPatWords[c] );
626 Counts[c][1] = Abc_TtCountOnesVecMask( pPats, Masks[c], p->nPatWords[c], 0 );
627 Counts[c][0] = Num - Counts[c][1];
628 assert( Counts[c][0] >= 0 && Counts[c][1] >= 0 );
629 }
630 //printf( "%5d %5d %5d %5d \n", Counts[0][0], Counts[0][1], Counts[1][0], Counts[1][1] );
631}
633{
634 int Counts[2][2];
635 int d, VarBest = -1, CostBest = ABC_INFINITY, Cost;
636 for ( d = 0; d < p->nDivs; d++ )
637 {
638 Sfm_DecVarCost( p, Masks, d, Counts );
639 if ( (Counts[0][0] < Counts[0][1]) == (Counts[1][0] < Counts[1][1]) )
640 continue;
641 Cost = Abc_MinInt(Counts[0][0], Counts[0][1]) + Abc_MinInt(Counts[1][0], Counts[1][1]);
642 if ( CostBest > Cost )
643 {
644 CostBest = Cost;
645 VarBest = d;
646 }
647 }
648 return VarBest;
649}
651{
652 int c, i, iLit, Var = -1, Cost, CostMin = ABC_INFINITY;
653 for ( c = 0; c < 2; c++ )
654 {
655 Vec_IntForEachEntry( &p->vImpls[c], iLit, i )
656 {
657 if ( Vec_IntSize(&p->vImpls[c]) > 1 && Vec_IntFind(&p->vObjDec, Abc_Lit2Var(iLit)) >= 0 )
658 continue;
659 Cost = Sfm_DecFindCost( p, c, iLit, Masks[!c] );
660 if ( CostMin > Cost )
661 {
662 CostMin = Cost;
663 Var = Abc_Lit2Var(iLit);
664 }
665 }
666 }
667 return Var;
668}
669
681int Sfm_DecMffcArea( Abc_Ntk_t * pNtk, Vec_Int_t * vMffc )
682{
683 Abc_Obj_t * pObj;
684 int i, nAreaMffc = 0;
685 Abc_NtkForEachObjVec( vMffc, pNtk, pObj, i )
686 nAreaMffc += Scl_Flt2Int(Mio_GateReadArea((Mio_Gate_t *)pObj->pData));
687 return nAreaMffc;
688}
690{
691 Abc_Obj_t * pFanin;
692 int i, Area = Scl_Flt2Int(Mio_GateReadArea((Mio_Gate_t *)pObj->pData));
693 Abc_ObjForEachFanin( pObj, pFanin, i )
694 {
695 assert( pFanin->vFanouts.nSize > 0 );
696 if ( --pFanin->vFanouts.nSize == 0 && !Abc_ObjIsCi(pFanin) )
697 Area += Sfm_MffcDeref_rec( pFanin );
698 }
699 return Area;
700}
701int Sfm_MffcRef_rec( Abc_Obj_t * pObj, Vec_Int_t * vMffc )
702{
703 Abc_Obj_t * pFanin;
704 int i, Area = Scl_Flt2Int(Mio_GateReadArea((Mio_Gate_t *)pObj->pData));
705 Abc_ObjForEachFanin( pObj, pFanin, i )
706 {
707 if ( pFanin->vFanouts.nSize++ == 0 && !Abc_ObjIsCi(pFanin) )
708 Area += Sfm_MffcRef_rec( pFanin, vMffc );
709 }
710 if ( vMffc )
711 Vec_IntPush( vMffc, Abc_ObjId(pObj) );
712 return Area;
713}
714int Sfm_DecMffcAreaReal( Abc_Obj_t * pPivot, Vec_Int_t * vCut, Vec_Int_t * vMffc )
715{
716 Abc_Ntk_t * pNtk = pPivot->pNtk;
717 Abc_Obj_t * pObj;
718 int i, Area1, Area2;
719 assert( Abc_ObjIsNode(pPivot) );
720 if ( vMffc )
721 Vec_IntClear( vMffc );
722 Abc_NtkForEachObjVec( vCut, pNtk, pObj, i )
723 pObj->vFanouts.nSize++;
724 Area1 = Sfm_MffcDeref_rec( pPivot );
725 Area2 = Sfm_MffcRef_rec( pPivot, vMffc );
726 Abc_NtkForEachObjVec( vCut, pNtk, pObj, i )
727 pObj->vFanouts.nSize--;
728 assert( Area1 == Area2 );
729 return Area1;
730}
731void Sfm_DecPrepareVec( Vec_Int_t * vMap, int * pNodes, int nNodes, Vec_Int_t * vCut )
732{
733 int i;
734 Vec_IntClear( vCut );
735 for ( i = 0; i < nNodes; i++ )
736 Vec_IntPush( vCut, Vec_IntEntry(vMap, pNodes[i]) );
737}
738int Sfm_DecComputeFlipInvGain( Sfm_Dec_t * p, Abc_Obj_t * pPivot, int * pfNeedInv )
739{
740 Abc_Obj_t * pFanout;
741 Mio_Gate_t * pGate, * pGateNew;
742 int i, Handle, fNeedInv = 0, Gain = 0;
743 Abc_ObjForEachFanout( pPivot, pFanout, i )
744 {
745 if ( !Abc_ObjIsNode(pFanout) )
746 {
747 fNeedInv = 1;
748 continue;
749 }
750 pGate = (Mio_Gate_t*)pFanout->pData;
751 if ( Abc_ObjFaninNum(pFanout) == 1 && Mio_GateIsInv(pGate) )
752 {
753 Gain += p->AreaInv;
754 continue;
755 }
756 Handle = Sfm_LibFindComplInputGate( &p->vGateFuncs, Mio_GateReadValue(pGate), Abc_ObjFaninNum(pFanout), Abc_NodeFindFanin(pFanout, pPivot), NULL );
757 if ( Handle == -1 )
758 {
759 fNeedInv = 1;
760 continue;
761 }
762 pGateNew = (Mio_Gate_t *)Vec_PtrEntry( &p->vGateHands, Handle );
763 Gain += Scl_Flt2Int(Mio_GateReadArea(pGate)) - Scl_Flt2Int(Mio_GateReadArea(pGateNew));
764 }
765 if ( fNeedInv )
766 Gain -= p->AreaInv;
767 if ( pfNeedInv )
768 *pfNeedInv = fNeedInv;
769 return Gain;
770}
771
783int Sfm_DecCombineDec( Sfm_Dec_t * p, word * pTruth0, word * pTruth1, int * pSupp0, int * pSupp1, int nSupp0, int nSupp1, word * pTruth, int * pSupp, int Var )
784{
785 Vec_Int_t vVec0 = { 2*SFM_SUPP_MAX, nSupp0, pSupp0 };
786 Vec_Int_t vVec1 = { 2*SFM_SUPP_MAX, nSupp1, pSupp1 };
787 Vec_Int_t vVec = { 2*SFM_SUPP_MAX, 0, pSupp };
788 int nWords0 = Abc_TtWordNum(nSupp0);
789 int nSupp, iSuppVar;
790 // check the case of equal cofactors
791 if ( nSupp0 == nSupp1 && !memcmp(pSupp0, pSupp1, sizeof(int)*nSupp0) && !memcmp(pTruth0, pTruth1, sizeof(word)*nWords0) )
792 {
793 memcpy( pSupp, pSupp0, sizeof(int)*nSupp0 );
794 memcpy( pTruth, pTruth0, sizeof(word)*nWords0 );
795 Abc_TtStretch6( pTruth, nSupp0, p->pPars->nVarMax );
796 return nSupp0;
797 }
798 // merge support variables
799 Vec_IntTwoMerge2Int( &vVec0, &vVec1, &vVec );
800 Vec_IntPushOrder( &vVec, Var );
801 nSupp = Vec_IntSize( &vVec );
802 if ( nSupp > p->pPars->nVarMax )
803 return -2;
804 // expand truth tables
805 Abc_TtStretch6( pTruth0, nSupp0, nSupp );
806 Abc_TtStretch6( pTruth1, nSupp1, nSupp );
807 Abc_TtExpand( pTruth0, nSupp, pSupp0, nSupp0, pSupp, nSupp );
808 Abc_TtExpand( pTruth1, nSupp, pSupp1, nSupp1, pSupp, nSupp );
809 // perform operation
810 iSuppVar = Vec_IntFind( &vVec, Var );
811 Abc_TtMux( pTruth, p->pTtElems[iSuppVar], pTruth1, pTruth0, Abc_TtWordNum(nSupp) );
812 Abc_TtStretch6( pTruth, nSupp, p->pPars->nVarMax );
813 return nSupp;
814}
815int Sfm_DecPeformDec_rec( Sfm_Dec_t * p, word * pTruth, int * pSupp, int * pAssump, int nAssump, word Masks[2][SFM_SIM_WORDS], int fCofactor, int nSuppAdd )
816{
817 int nBTLimit = p->pPars->nBTLimit;
818// int fVerbose = p->pPars->fVeryVerbose;
819 int c, i, d, iLit, status, Var = -1;
820 word * pDivWords = p->pDivWords[nAssump];
821 abctime clk;
822 assert( nAssump <= SFM_SUPP_MAX );
823 if ( p->pPars->fVeryVerbose )
824 {
825 printf( "\nObject %d\n", p->iTarget );
826 printf( "Divs = %d. Nodes = %d. Mffc = %d. Mffc area = %.2f. ", p->nDivs, Vec_IntSize(&p->vObjGates), p->nMffc, Scl_Int2Flt(p->AreaMffc) );
827 printf( "Pat0 = %d. Pat1 = %d. ", p->nPats[0], p->nPats[1] );
828 printf( "\n" );
829 if ( nAssump )
830 {
831 printf( "Cofactor: " );
832 for ( i = 0; i < nAssump; i++ )
833 printf( " %s%d", Abc_LitIsCompl(pAssump[i])? "!":"", Abc_Lit2Var(pAssump[i]) );
834 printf( "\n" );
835 }
836 }
837 // check constant
838 for ( c = 0; c < 2; c++ )
839 {
840 if ( !Abc_TtIsConst0(Masks[c], p->nPatWords[c]) ) // there are some patterns
841 continue;
842 p->nSatCalls++;
843 pAssump[nAssump] = Abc_Var2Lit( p->iTarget, c );
844 clk = Abc_Clock();
845 status = sat_solver_solve( p->pSat, pAssump, pAssump + nAssump + 1, nBTLimit, 0, 0, 0 );
846 if ( status == l_Undef )
847 {
848 p->nTimeOuts++;
849 return -2;
850 }
851 if ( status == l_False )
852 {
853 p->nSatCallsUnsat++;
854 p->timeSatUnsat += Abc_Clock() - clk;
855 Abc_TtConst( pTruth, Abc_TtWordNum(p->pPars->nVarMax), c );
856 if ( p->pPars->fVeryVerbose )
857 printf( "Found constant %d.\n", c );
858 return 0;
859 }
860 assert( status == l_True );
861 p->nSatCallsSat++;
862 p->timeSatSat += Abc_Clock() - clk;
863 if ( p->nPats[c] == 64*SFM_SIM_WORDS )
864 {
865 p->nSatCallsOver++;
866 continue;//return -2;//continue;
867 }
868 for ( i = 0; i < p->nDivs; i++ )
869 if ( sat_solver_var_value(p->pSat, i) )
870 Abc_TtSetBit( Sfm_DecDivPats(p, i, c), p->nPats[c] );
871 p->nPatWords[c] = 1 + (p->nPats[c] >> 6);
872 Abc_TtSetBit( Masks[c], p->nPats[c]++ );
873 }
874
875 if ( p->iUseThis != -1 )
876 {
877 Var = p->iUseThis;
878 p->iUseThis = -1;
879 goto cofactor;
880 }
881
882 // check implications
883 Vec_IntClear( &p->vImpls[0] );
884 Vec_IntClear( &p->vImpls[1] );
885 for ( d = 0; d < p->nDivs; d++ )
886 {
887 int Impls[2] = {-1, -1};
888 for ( c = 0; c < 2; c++ )
889 {
890 word * pPats = Sfm_DecDivPats( p, d, c );
891 int fHas0s = Abc_TtIntersect( pPats, Masks[c], p->nPatWords[c], 1 );
892 int fHas1s = Abc_TtIntersect( pPats, Masks[c], p->nPatWords[c], 0 );
893 if ( fHas0s && fHas1s )
894 continue;
895 pAssump[nAssump] = Abc_Var2Lit( p->iTarget, c );
896 pAssump[nAssump+1] = Abc_Var2Lit( d, fHas1s ); // if there are 1s, check if 0 is SAT
897 clk = Abc_Clock();
898 if ( Abc_TtGetBit( pDivWords, 4*d+2*c+fHas1s ) )
899 {
900 p->nSatCallsUnsat--;
901 status = l_False;
902 }
903 else
904 {
905 p->nSatCalls++;
906 status = sat_solver_solve( p->pSat, pAssump, pAssump + nAssump + 2, nBTLimit, 0, 0, 0 );
907 }
908 if ( status == l_Undef )
909 {
910 p->nTimeOuts++;
911 return -2;
912 }
913 if ( status == l_False )
914 {
915 p->nSatCallsUnsat++;
916 p->timeSatUnsat += Abc_Clock() - clk;
917 Impls[c] = Abc_LitNot(pAssump[nAssump+1]);
918 Vec_IntPush( &p->vImpls[c], Abc_LitNot(pAssump[nAssump+1]) );
919 Abc_TtSetBit( pDivWords, 4*d+2*c+fHas1s );
920 continue;
921 }
922 assert( status == l_True );
923 p->nSatCallsSat++;
924 p->timeSatSat += Abc_Clock() - clk;
925 if ( p->nPats[c] == 64*SFM_SIM_WORDS )
926 {
927 p->nSatCallsOver++;
928 continue;//return -2;//continue;
929 }
930 // record this status
931 for ( i = 0; i < p->nDivs; i++ )
932 if ( sat_solver_var_value(p->pSat, i) )
933 Abc_TtSetBit( Sfm_DecDivPats(p, i, c), p->nPats[c] );
934 p->nPatWords[c] = 1 + (p->nPats[c] >> 6);
935 Abc_TtSetBit( Masks[c], p->nPats[c]++ );
936 }
937 if ( Impls[0] == -1 || Impls[1] == -1 )
938 continue;
939 if ( Impls[0] == Impls[1] )
940 {
941 Vec_IntPop( &p->vImpls[0] );
942 Vec_IntPop( &p->vImpls[1] );
943 continue;
944 }
945 assert( Abc_Lit2Var(Impls[0]) == Abc_Lit2Var(Impls[1]) );
946 // found buffer/inverter
947 Abc_TtUnit( pTruth, Abc_TtWordNum(p->pPars->nVarMax), Abc_LitIsCompl(Impls[0]) );
948 pSupp[0] = Abc_Lit2Var(Impls[0]);
949 if ( p->pPars->fVeryVerbose )
950 printf( "Found variable %s%d.\n", Abc_LitIsCompl(Impls[0]) ? "!":"", pSupp[0] );
951 return 1;
952 }
953 if ( nSuppAdd > p->pPars->nVarMax - 2 )
954 {
955 if ( p->pPars->fVeryVerbose )
956 printf( "The number of assumption is more than MFFC size.\n" );
957 return -2;
958 }
959 // try using all implications at once
960 if ( p->pPars->fUseAndOr )
961 for ( c = 0; c < 2; c++ )
962 {
963 if ( Vec_IntSize(&p->vImpls[!c]) < 2 )
964 continue;
965 p->nSatCalls++;
966 pAssump[nAssump] = Abc_Var2Lit( p->iTarget, c );
967 assert( Vec_IntSize(&p->vImpls[!c]) < SFM_WIN_MAX-10 );
968 Vec_IntForEachEntry( &p->vImpls[!c], iLit, i )
969 pAssump[nAssump+1+i] = iLit;
970 clk = Abc_Clock();
971 status = sat_solver_solve( p->pSat, pAssump, pAssump + nAssump+1+i, nBTLimit, 0, 0, 0 );
972 if ( status == l_Undef )
973 {
974 p->nTimeOuts++;
975 return -2;
976 }
977 if ( status == l_False )
978 {
979 int * pFinal, nFinal = sat_solver_final( p->pSat, &pFinal );
980 p->nSatCallsUnsat++;
981 p->timeSatUnsat += Abc_Clock() - clk;
982 if ( nFinal + nSuppAdd > 6 )
983 continue;
984 // collect only relevant literals
985 for ( i = d = 0; i < nFinal; i++ )
986 if ( Vec_IntFind(&p->vImpls[!c], Abc_LitNot(pFinal[i])) >= 0 )
987 pSupp[d++] = Abc_LitNot(pFinal[i]);
988 nFinal = d;
989 // create AND/OR gate
990 assert( nFinal <= 6 );
991 if ( c )
992 {
993 *pTruth = ~(word)0;
994 for ( i = 0; i < nFinal; i++ )
995 {
996 *pTruth &= Abc_LitIsCompl(pSupp[i]) ? ~s_Truths6[i] : s_Truths6[i];
997 pSupp[i] = Abc_Lit2Var(pSupp[i]);
998 }
999 }
1000 else
1001 {
1002 *pTruth = 0;
1003 for ( i = 0; i < nFinal; i++ )
1004 {
1005 *pTruth |= Abc_LitIsCompl(pSupp[i]) ? s_Truths6[i] : ~s_Truths6[i];
1006 pSupp[i] = Abc_Lit2Var(pSupp[i]);
1007 }
1008 }
1009 Abc_TtStretch6( pTruth, nFinal, p->pPars->nVarMax );
1010 p->nNodesAndOr++;
1011 if ( p->pPars->fVeryVerbose )
1012 printf( "Found %d-input AND/OR gate.\n", nFinal );
1013 return nFinal;
1014 }
1015 assert( status == l_True );
1016 p->nSatCallsSat++;
1017 p->timeSatSat += Abc_Clock() - clk;
1018 if ( p->nPats[c] == 64*SFM_SIM_WORDS )
1019 {
1020 p->nSatCallsOver++;
1021 continue;//return -2;//continue;
1022 }
1023 for ( i = 0; i < p->nDivs; i++ )
1024 if ( sat_solver_var_value(p->pSat, i) )
1025 Abc_TtSetBit( Sfm_DecDivPats(p, i, c), p->nPats[c] );
1026 p->nPatWords[c] = 1 + (p->nPats[c] >> 6);
1027 Abc_TtSetBit( Masks[c], p->nPats[c]++ );
1028 }
1029
1030 // find the best cofactoring variable
1031// if ( !fCofactor || Vec_IntSize(&p->vImpls[0]) + Vec_IntSize(&p->vImpls[1]) > 2 )
1032 Var = Sfm_DecFindBestVar( p, Masks );
1033// if ( Var == -1 )
1034// Var = Sfm_DecFindBestVar2( p, Masks );
1035
1036/*
1037 {
1038 int Lit0 = Vec_IntSize(&p->vImpls[0]) ? Vec_IntEntry(&p->vImpls[0], 0) : -1;
1039 int Lit1 = Vec_IntSize(&p->vImpls[1]) ? Vec_IntEntry(&p->vImpls[1], 0) : -1;
1040 if ( Lit0 == -1 && Lit1 >= 0 )
1041 Var = Abc_Lit2Var(Lit1);
1042 else if ( Lit1 == -1 && Lit0 >= 0 )
1043 Var = Abc_Lit2Var(Lit0);
1044 else if ( Lit0 >= 0 && Lit1 >= 0 )
1045 {
1046 if ( Lit0 < Lit1 )
1047 Var = Abc_Lit2Var(Lit0);
1048 else
1049 Var = Abc_Lit2Var(Lit1);
1050 }
1051 }
1052*/
1053
1054 if ( Var == -1 && fCofactor )
1055 {
1056 //for ( Var = p->nDivs - 1; Var >= 0; Var-- )
1057 Vec_IntForEachEntryReverse( &p->vObjInMffc, Var, i )
1058 if ( Vec_IntFind(&p->vObjDec, Var) == -1 )
1059 break;
1060// if ( i == Vec_IntSize(&p->vObjInMffc) )
1061 if ( i == -1 )
1062 Var = -1;
1063 fCofactor = 0;
1064 }
1065
1066 if ( p->pPars->fVeryVerbose )
1067 {
1068 Sfm_DecPrint( p, Masks );
1069 printf( "Best var %d\n", Var );
1070 printf( "\n" );
1071 }
1072cofactor:
1073 // cofactor the problem
1074 if ( Var >= 0 )
1075 {
1076 word uTruth[2][SFM_WORD_MAX], MasksNext[2][SFM_SIM_WORDS];
1077 int w, Supp[2][2*SFM_SUPP_MAX], nSupp[2] = {0};
1078 Vec_IntPush( &p->vObjDec, Var );
1079 for ( i = 0; i < 2; i++ )
1080 {
1081 for ( c = 0; c < 2; c++ )
1082 {
1083 Abc_TtAndSharp( MasksNext[c], Masks[c], Sfm_DecDivPats(p, Var, c), p->nPatWords[c], !i );
1084 for ( w = p->nPatWords[c]; w < SFM_SIM_WORDS; w++ )
1085 MasksNext[c][w] = 0;
1086 }
1087 pAssump[nAssump] = Abc_Var2Lit( Var, !i );
1088 memcpy( p->pDivWords[nAssump+1], p->pDivWords[nAssump], sizeof(word) * p->nDivWords );
1089 nSupp[i] = Sfm_DecPeformDec_rec( p, uTruth[i], Supp[i], pAssump, nAssump+1, MasksNext, fCofactor, (i ? nSupp[0] : 0) + nSuppAdd + 1 );
1090 if ( nSupp[i] == -2 )
1091 return -2;
1092 }
1093 // combine solutions
1094 return Sfm_DecCombineDec( p, uTruth[0], uTruth[1], Supp[0], Supp[1], nSupp[0], nSupp[1], pTruth, pSupp, Var );
1095 }
1096 return -2;
1097}
1099{
1100 word uTruth[SFM_DEC_MAX][SFM_WORD_MAX], Masks[2][SFM_SIM_WORDS];
1101 int pSupp[SFM_DEC_MAX][2*SFM_SUPP_MAX];
1102 int nSupp[SFM_DEC_MAX], pAssump[SFM_WIN_MAX];
1103 int fVeryVerbose = p->pPars->fPrintDecs || p->pPars->fVeryVerbose;
1104 int nDecs = Abc_MaxInt(p->pPars->nDecMax, 1);
1105 //int fNeedInv, AreaGainInv = Sfm_DecComputeFlipInvGain(p, pObj, &fNeedInv);
1106 int i, RetValue, Prev = 0, iBest = -1, AreaThis, AreaNew;//, AreaNewInv;
1107 int GainThis, GainBest = -1, iLibObj, iLibObjBest = -1;
1108 assert( p->pPars->fArea == 1 );
1109//printf( "AreaGainInv = %8.2f ", Scl_Int2Flt(AreaGainInv) );
1110 //Sfm_DecPrint( p, NULL );
1111 if ( fVeryVerbose )
1112 printf( "\nNode %4d : MFFC %2d\n", p->iTarget, p->nMffc );
1113 assert( p->pPars->nDecMax <= SFM_DEC_MAX );
1114 Sfm_ObjSetupSimInfo( pObj );
1115 Vec_IntClear( &p->vObjDec );
1116 for ( i = 0; i < nDecs; i++ )
1117 {
1118 // reduce the variable array
1119 if ( Vec_IntSize(&p->vObjDec) > Prev )
1120 Vec_IntShrink( &p->vObjDec, Prev );
1121 Prev = Vec_IntSize(&p->vObjDec) + 1;
1122 // perform decomposition
1123 Abc_TtMask( Masks[0], SFM_SIM_WORDS, p->nPats[0] );
1124 Abc_TtMask( Masks[1], SFM_SIM_WORDS, p->nPats[1] );
1125 nSupp[i] = Sfm_DecPeformDec_rec( p, uTruth[i], pSupp[i], pAssump, 0, Masks, 1, 0 );
1126 if ( nSupp[i] == -2 )
1127 {
1128 if ( fVeryVerbose )
1129 printf( "Dec %d: Pat0 = %2d Pat1 = %2d NO DEC.\n", i, p->nPats[0], p->nPats[1] );
1130 continue;
1131 }
1132 if ( fVeryVerbose )
1133 printf( "Dec %d: Pat0 = %2d Pat1 = %2d Supp = %d ", i, p->nPats[0], p->nPats[1], nSupp[i] );
1134 if ( fVeryVerbose )
1135 Dau_DsdPrintFromTruth( uTruth[i], nSupp[i] );
1136 if ( nSupp[i] < 2 )
1137 {
1138 p->nSuppVars = nSupp[i];
1139 Abc_TtCopy( p->Copy, uTruth[i], SFM_WORD_MAX, 0 );
1140 RetValue = Sfm_LibImplementSimple( p->pLib, uTruth[i], pSupp[i], nSupp[i], &p->vObjGates, &p->vObjFanins );
1141 assert( nSupp[i] <= p->pPars->nVarMax );
1142 p->nLuckySizes[nSupp[i]]++;
1143 assert( RetValue <= 2 );
1144 p->nLuckyGates[RetValue]++;
1145 //printf( "\n" );
1146 return RetValue;
1147 }
1148
1149 p->nSuppVars = nSupp[i];
1150 Abc_TtCopy( p->Copy, uTruth[i], SFM_WORD_MAX, 0 );
1151 AreaNew = Sfm_LibFindAreaMatch( p->pLib, uTruth[i], nSupp[i], &iLibObj );
1152/*
1153 uTruth[i][0] = ~uTruth[i][0];
1154 AreaNewInv = Sfm_LibFindAreaMatch( p->pLib, uTruth[i], nSupp[i], NULL );
1155 uTruth[i][0] = ~uTruth[i][0];
1156
1157 if ( AreaNew > 0 && AreaNewInv > 0 && AreaNew - AreaNewInv + AreaGainInv > 0 )
1158 printf( "AreaNew = %8.2f AreaNewInv = %8.2f Gain = %8.2f Total = %8.2f\n",
1159 Scl_Int2Flt(AreaNew), Scl_Int2Flt(AreaNewInv), Scl_Int2Flt(AreaNew - AreaNewInv), Scl_Int2Flt(AreaNew - AreaNewInv + AreaGainInv) );
1160 else
1161 printf( "\n" );
1162*/
1163 if ( AreaNew == -1 )
1164 continue;
1165
1166
1167 // compute area savings
1168 Sfm_DecPrepareVec( &p->vObjMap, pSupp[i], nSupp[i], &p->vGateCut );
1169 AreaThis = Sfm_DecMffcAreaReal(pObj, &p->vGateCut, NULL);
1170 assert( p->AreaMffc <= AreaThis );
1171 if ( p->pPars->fZeroCost ? (AreaNew > AreaThis) : (AreaNew >= AreaThis) )
1172 continue;
1173 // find the best gain
1174 GainThis = AreaThis - AreaNew;
1175 assert( GainThis >= 0 );
1176 if ( GainBest < GainThis )
1177 {
1178 GainBest = GainThis;
1179 iLibObjBest = iLibObj;
1180 iBest = i;
1181 }
1182 }
1183 Sfm_ObjSetdownSimInfo( pObj );
1184 if ( iBest == -1 )
1185 {
1186 if ( fVeryVerbose )
1187 printf( "Best : NO DEC.\n" );
1188 p->nNoDecs++;
1189 //printf( "\n" );
1190 return -2;
1191 }
1192 if ( fVeryVerbose )
1193 printf( "Best %d: %d ", iBest, nSupp[iBest] );
1194 if ( fVeryVerbose )
1195 Dau_DsdPrintFromTruth( uTruth[iBest], nSupp[iBest] );
1196 // implement
1197 assert( iLibObjBest >= 0 );
1198 RetValue = Sfm_LibImplementGatesArea( p->pLib, pSupp[iBest], nSupp[iBest], iLibObjBest, &p->vObjGates, &p->vObjFanins );
1199 assert( nSupp[iBest] <= p->pPars->nVarMax );
1200 p->nLuckySizes[nSupp[iBest]]++;
1201 assert( RetValue <= 2 );
1202 p->nLuckyGates[RetValue]++;
1203 return 1;
1204}
1206{
1207 word uTruth[SFM_DEC_MAX][SFM_WORD_MAX], Masks[2][SFM_SIM_WORDS];
1208 int pSupp[SFM_DEC_MAX][2*SFM_SUPP_MAX];
1209 int nSupp[SFM_DEC_MAX], pAssump[SFM_WIN_MAX];
1210 int fVeryVerbose = p->pPars->fPrintDecs || p->pPars->fVeryVerbose;
1211 int nDecs = Abc_MaxInt(p->pPars->nDecMax, 1);
1212 int i, k, DelayOrig = 0, DelayMin, GainMax, AreaMffc, nMatches, iBest = -1, RetValue, Prev = 0;
1213 Mio_Gate_t * pGate1Best = NULL, * pGate2Best = NULL;
1214 char * pFans1Best = NULL, * pFans2Best = NULL;
1215 assert( p->pPars->fArea == 0 );
1216 p->DelayMin = 0;
1217 //Sfm_DecPrint( p, NULL );
1218 if ( fVeryVerbose )
1219 printf( "\nNode %4d : MFFC %2d\n", p->iTarget, p->nMffc );
1220 // set limit on search for decompositions in delay-model
1221 assert( p->pPars->nDecMax <= SFM_DEC_MAX );
1222 Sfm_ObjSetupSimInfo( pObj );
1223 Vec_IntClear( &p->vObjDec );
1224 for ( i = 0; i < nDecs; i++ )
1225 {
1226 GainMax = 0;
1227 DelayMin = DelayOrig = Sfm_ManReadObjDelay( p, Abc_ObjId(pObj) );
1228 // reduce the variable array
1229 if ( Vec_IntSize(&p->vObjDec) > Prev )
1230 Vec_IntShrink( &p->vObjDec, Prev );
1231 Prev = Vec_IntSize(&p->vObjDec) + 1;
1232 // perform decomposition
1233 Abc_TtMask( Masks[0], SFM_SIM_WORDS, p->nPats[0] );
1234 Abc_TtMask( Masks[1], SFM_SIM_WORDS, p->nPats[1] );
1235 nSupp[i] = Sfm_DecPeformDec_rec( p, uTruth[i], pSupp[i], pAssump, 0, Masks, 1, 0 );
1236 if ( nSupp[i] == -2 )
1237 {
1238 if ( fVeryVerbose )
1239 printf( "Dec %d: Pat0 = %2d Pat1 = %2d NO DEC.\n", i, p->nPats[0], p->nPats[1] );
1240 continue;
1241 }
1242 if ( fVeryVerbose )
1243 printf( "Dec %d: Pat0 = %2d Pat1 = %2d Supp = %d ", i, p->nPats[0], p->nPats[1], nSupp[i] );
1244 if ( fVeryVerbose )
1245 Dau_DsdPrintFromTruth( uTruth[i], nSupp[i] );
1246 if ( p->pTim && nSupp[i] == 1 && uTruth[i][0] == ABC_CONST(0x5555555555555555) && DelayMin <= p->DelayInv + Sfm_ManReadObjDelay(p, Vec_IntEntry(&p->vObjMap, pSupp[i][0])) )
1247 {
1248 if ( fVeryVerbose )
1249 printf( "Dec %d: Pat0 = %2d Pat1 = %2d NO DEC.\n", i, p->nPats[0], p->nPats[1] );
1250 continue;
1251 }
1252 if ( p->pMit && nSupp[i] == 1 && uTruth[i][0] == ABC_CONST(0x5555555555555555) )
1253 {
1254 if ( fVeryVerbose )
1255 printf( "Dec %d: Pat0 = %2d Pat1 = %2d NO DEC.\n", i, p->nPats[0], p->nPats[1] );
1256 continue;
1257 }
1258 if ( nSupp[i] < 2 )
1259 {
1260 p->nSuppVars = nSupp[i];
1261 Abc_TtCopy( p->Copy, uTruth[i], SFM_WORD_MAX, 0 );
1262 RetValue = Sfm_LibImplementSimple( p->pLib, uTruth[i], pSupp[i], nSupp[i], &p->vObjGates, &p->vObjFanins );
1263 assert( nSupp[i] <= p->pPars->nVarMax );
1264 p->nLuckySizes[nSupp[i]]++;
1265 assert( RetValue <= 2 );
1266 p->nLuckyGates[RetValue]++;
1267 return RetValue;
1268 }
1269
1270 // get MFFC
1271 Sfm_DecPrepareVec( &p->vObjMap, pSupp[i], nSupp[i], &p->vGateCut ); // returns cut in p->vGateCut
1272 AreaMffc = Sfm_DecMffcAreaReal(pObj, &p->vGateCut, &p->vGateMffc ); // returns MFFC in p->vGateMffc
1273
1274 // try the delay
1275 p->nSuppVars = nSupp[i];
1276 Abc_TtCopy( p->Copy, uTruth[i], SFM_WORD_MAX, 0 );
1277 nMatches = Sfm_LibFindDelayMatches( p->pLib, uTruth[i], pSupp[i], nSupp[i], &p->vMatchGates, &p->vMatchFans );
1278 for ( k = 0; k < nMatches; k++ )
1279 {
1280 abctime clk = Abc_Clock();
1281 Mio_Gate_t * pGate1 = (Mio_Gate_t *)Vec_PtrEntry( &p->vMatchGates, 2*k+0 );
1282 Mio_Gate_t * pGate2 = (Mio_Gate_t *)Vec_PtrEntry( &p->vMatchGates, 2*k+1 );
1283 int AreaNew = Scl_Flt2Int( Mio_GateReadArea(pGate1) + (pGate2 ? Mio_GateReadArea(pGate2) : 0.0) );
1284 char * pFans1 = (char *)Vec_PtrEntry( &p->vMatchFans, 2*k+0 );
1285 char * pFans2 = (char *)Vec_PtrEntry( &p->vMatchFans, 2*k+1 );
1286 Vec_Int_t vFanins = { nSupp[i], nSupp[i], pSupp[i] };
1287 // skip identical gate
1288 //if ( pGate2 == NULL && pGate1 == (Mio_Gate_t *)pObj->pData )
1289 // continue;
1290 if ( p->pMit )
1291 {
1292 int Gain = Sfm_MitEvalRemapping( p->pMit, &p->vGateMffc, pObj, &vFanins, &p->vObjMap, pGate1, pFans1, pGate2, pFans2 );
1293 if ( p->pPars->DelAreaRatio && AreaNew > AreaMffc && (Gain / (AreaNew - AreaMffc)) < p->pPars->DelAreaRatio )
1294 continue;
1295 if ( GainMax < Gain )
1296 {
1297 GainMax = Gain;
1298 pGate1Best = pGate1;
1299 pGate2Best = pGate2;
1300 pFans1Best = pFans1;
1301 pFans2Best = pFans2;
1302 iBest = i;
1303 }
1304 }
1305 else
1306 {
1307 int Delay = Sfm_TimEvalRemapping( p->pTim, &vFanins, &p->vObjMap, pGate1, pFans1, pGate2, pFans2 );
1308 if ( p->pPars->DelAreaRatio && AreaNew > AreaMffc && (Delay / (AreaNew - AreaMffc)) < p->pPars->DelAreaRatio )
1309 continue;
1310 if ( DelayMin > Delay )
1311 {
1312 DelayMin = Delay;
1313 pGate1Best = pGate1;
1314 pGate2Best = pGate2;
1315 pFans1Best = pFans1;
1316 pFans2Best = pFans2;
1317 iBest = i;
1318 }
1319 }
1320 p->timeEval += Abc_Clock() - clk;
1321 }
1322 }
1323//printf( "Gain max = %d.\n", GainMax );
1324 Sfm_ObjSetdownSimInfo( pObj );
1325 if ( iBest == -1 )
1326 {
1327 if ( fVeryVerbose )
1328 printf( "Best : NO DEC.\n" );
1329 p->nNoDecs++;
1330 return -2;
1331 }
1332 if ( fVeryVerbose )
1333 printf( "Best %d: %d ", iBest, nSupp[iBest] );
1334// if ( fVeryVerbose )
1335// Dau_DsdPrintFromTruth( uTruth[iBest], nSupp[iBest] );
1336 RetValue = Sfm_LibImplementGatesDelay( p->pLib, pSupp[iBest], pGate1Best, pGate2Best, pFans1Best, pFans2Best, &p->vObjGates, &p->vObjFanins );
1337 assert( nSupp[iBest] <= p->pPars->nVarMax );
1338 p->nLuckySizes[nSupp[iBest]]++;
1339 assert( RetValue <= 2 );
1340 p->nLuckyGates[RetValue]++;
1341 p->DelayMin = DelayMin;
1342 return 1;
1343}
1344
1357{
1358 Abc_Obj_t * pFanout;
1359 int i, LevelNew = Abc_ObjLevelNew(pObj);
1360 if ( LevelNew == Abc_ObjLevel(pObj) && Abc_ObjIsNode(pObj) && Abc_ObjFaninNum(pObj) > 0 )
1361 return;
1362 pObj->Level = LevelNew;
1363 if ( !Abc_ObjIsCo(pObj) )
1364 Abc_ObjForEachFanout( pObj, pFanout, i )
1365 Abc_NtkUpdateIncLevel_rec( pFanout );
1366}
1367
1380{
1381 Abc_Obj_t * pFanin; int i;
1382 if ( pObj == pPivot )
1383 return 0;
1384 if ( Abc_NodeIsTravIdCurrent( pObj ) )
1385 return 1;
1386 Abc_NodeSetTravIdCurrent( pObj );
1387 if ( Abc_ObjIsCi(pObj) )
1388 return 1;
1389 assert( Abc_ObjIsNode(pObj) );
1390 Abc_ObjForEachFanin( pObj, pFanin, i )
1391 if ( !Abc_NtkDfsCheck_rec(pFanin, pPivot) )
1392 return 0;
1393 return 1;
1394}
1395void Abc_NtkDfsReverseOne_rec( Abc_Obj_t * pObj, Vec_Int_t * vTfo, int nLevelMax, int nFanoutMax )
1396{
1397 Abc_Obj_t * pFanout; int i;
1398 if ( Abc_NodeIsTravIdCurrent( pObj ) )
1399 return;
1400 Abc_NodeSetTravIdCurrent( pObj );
1401 if ( Abc_ObjIsCo(pObj) || Abc_ObjLevel(pObj) > nLevelMax )
1402 return;
1403 assert( Abc_ObjIsNode( pObj ) );
1404 if ( Abc_ObjFanoutNum(pObj) <= nFanoutMax )
1405 {
1406 Abc_ObjForEachFanout( pObj, pFanout, i )
1407 if ( Abc_ObjIsCo(pFanout) || Abc_ObjLevel(pFanout) > nLevelMax )
1408 break;
1409 if ( i == Abc_ObjFanoutNum(pObj) )
1410 Abc_ObjForEachFanout( pObj, pFanout, i )
1411 Abc_NtkDfsReverseOne_rec( pFanout, vTfo, nLevelMax, nFanoutMax );
1412 }
1413 Vec_IntPush( vTfo, Abc_ObjId(pObj) );
1414 pObj->iTemp = 0;
1415}
1416int Abc_NtkDfsOne_rec( Abc_Obj_t * pObj, Vec_Int_t * vTfi, int nLevelMin, int CiLabel )
1417{
1418 Abc_Obj_t * pFanin; int i;
1419 if ( Abc_NodeIsTravIdCurrent( pObj ) )
1420 return pObj->iTemp;
1421 Abc_NodeSetTravIdCurrent( pObj );
1422 if ( Abc_ObjIsCi(pObj) || (Abc_ObjLevel(pObj) < nLevelMin && Abc_ObjFaninNum(pObj) > 0) )
1423 {
1424 Vec_IntPush( vTfi, Abc_ObjId(pObj) );
1425 return (pObj->iTemp = CiLabel);
1426 }
1427 assert( Abc_ObjIsNode(pObj) );
1428 pObj->iTemp = Abc_ObjFaninNum(pObj) ? 0 : CiLabel;
1429 Abc_ObjForEachFanin( pObj, pFanin, i )
1430 pObj->iTemp |= Abc_NtkDfsOne_rec( pFanin, vTfi, nLevelMin, CiLabel );
1431 Vec_IntPush( vTfi, Abc_ObjId(pObj) );
1432 Sfm_ObjSimulateNode( pObj );
1433 return pObj->iTemp;
1434}
1435void Sfm_DecAddNode( Abc_Obj_t * pObj, Vec_Int_t * vMap, Vec_Int_t * vGates, int fSkip, int fVeryVerbose )
1436{
1437 if ( fVeryVerbose )
1438 printf( "%d:%d(%d) ", Vec_IntSize(vMap), Abc_ObjId(pObj), pObj->iTemp );
1439 if ( fVeryVerbose )
1440 Abc_ObjPrint( stdout, pObj );
1441 Vec_IntPush( vMap, Abc_ObjId(pObj) );
1442 Vec_IntPush( vGates, fSkip ? -1 : Mio_GateReadValue((Mio_Gate_t *)pObj->pData) );
1443}
1444static inline int Sfm_DecNodeIsMffc( Abc_Obj_t * p, int nLevelMin )
1445{
1446 return Abc_ObjIsNode(p) && Abc_ObjFanoutNum(p) == 1 && Abc_NodeIsTravIdCurrent(p) && (Abc_ObjLevel(p) >= nLevelMin || Abc_ObjFaninNum(p) == 0);
1447}
1448static inline int Sfm_DecNodeIsMffcInput( Abc_Obj_t * p, int nLevelMin, Sfm_Tim_t * pTim, Abc_Obj_t * pPivot )
1449{
1450 return Abc_NodeIsTravIdCurrent(p) && Sfm_TimNodeIsNonCritical(pTim, pPivot, p);
1451}
1452static inline int Sfm_DecNodeIsMffcInput2( Abc_Obj_t * p, int nLevelMin, Sfm_Mit_t * pMit, Abc_Obj_t * pPivot )
1453{
1454 return Abc_NodeIsTravIdCurrent(p) && Sfm_MitNodeIsNonCritical(pMit, pPivot, p);
1455}
1456void Sfm_DecMarkMffc( Abc_Obj_t * pPivot, int nLevelMin, int nMffcMax, int fVeryVerbose, Vec_Int_t * vMffc, Vec_Int_t * vInMffc, Sfm_Tim_t * pTim, Sfm_Mit_t * pMit )
1457{
1458 Abc_Obj_t * pFanin, * pFanin2, * pFanin3, * pObj; int i, k, n;
1459 assert( nMffcMax > 0 );
1460 Vec_IntFill( vMffc, 1, Abc_ObjId(pPivot) );
1461 if ( pMit != NULL )
1462 {
1463 pPivot->iTemp |= SFM_MASK_MFFC;
1464 pPivot->iTemp |= SFM_MASK_PIVOT;
1465 // collect MFFC inputs (these are low-delay nodes close to the pivot)
1466 Vec_IntClear(vInMffc);
1467 Abc_ObjForEachFanin( pPivot, pFanin, i )
1468 if ( Sfm_DecNodeIsMffcInput2(pFanin, nLevelMin, pMit, pPivot) )
1469 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin) );
1470 Abc_ObjForEachFanin( pPivot, pFanin, i )
1471 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1472 if ( Sfm_DecNodeIsMffcInput2(pFanin2, nLevelMin, pMit, pPivot) )
1473 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin2) );
1474 Abc_ObjForEachFanin( pPivot, pFanin, i )
1475 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1476 Abc_ObjForEachFanin( pFanin2, pFanin3, n )
1477 if ( Sfm_DecNodeIsMffcInput2(pFanin3, nLevelMin, pMit, pPivot) )
1478 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin3) );
1479 }
1480 else if ( pTim != NULL )
1481 {
1482 pPivot->iTemp |= SFM_MASK_MFFC;
1483 pPivot->iTemp |= SFM_MASK_PIVOT;
1484 // collect MFFC inputs (these are low-delay nodes close to the pivot)
1485 Vec_IntClear(vInMffc);
1486 Abc_ObjForEachFanin( pPivot, pFanin, i )
1487 if ( Sfm_DecNodeIsMffcInput(pFanin, nLevelMin, pTim, pPivot) )
1488 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin) );
1489 Abc_ObjForEachFanin( pPivot, pFanin, i )
1490 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1491 if ( Sfm_DecNodeIsMffcInput(pFanin2, nLevelMin, pTim, pPivot) )
1492 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin2) );
1493 Abc_ObjForEachFanin( pPivot, pFanin, i )
1494 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1495 Abc_ObjForEachFanin( pFanin2, pFanin3, n )
1496 if ( Sfm_DecNodeIsMffcInput(pFanin3, nLevelMin, pTim, pPivot) )
1497 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin3) );
1498
1499/*
1500 printf( "Node %d: (%.2f) ", pPivot->Id, Scl_Int2Flt(Sfm_ManReadObjDelay(p, Abc_ObjId(pPivot))) );
1501 Abc_ObjForEachFanin( pPivot, pFanin, i )
1502 printf( "%d: %.2f ", Abc_ObjLevel(pFanin), Scl_Int2Flt(Sfm_ManReadObjDelay(p, Abc_ObjId(pFanin))) );
1503 printf( "\n" );
1504
1505 printf( "Node %d: ", pPivot->Id );
1506 Abc_NtkForEachObjVec( vInMffc, pPivot->pNtk, pObj, i )
1507 printf( "%d: %.2f ", Abc_ObjLevel(pObj), Scl_Int2Flt(Sfm_ManReadObjDelay(p, Abc_ObjId(pObj))) );
1508 printf( "\n" );
1509*/
1510 }
1511 else
1512 {
1513
1514 // collect MFFC
1515 Abc_ObjForEachFanin( pPivot, pFanin, i )
1516 if ( Sfm_DecNodeIsMffc(pFanin, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1517 Vec_IntPushUnique( vMffc, Abc_ObjId(pFanin) );
1518 Abc_ObjForEachFanin( pPivot, pFanin, i )
1519 if ( Sfm_DecNodeIsMffc(pFanin, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1520 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1521 if ( Sfm_DecNodeIsMffc(pFanin2, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1522 Vec_IntPushUnique( vMffc, Abc_ObjId(pFanin2) );
1523 Abc_ObjForEachFanin( pPivot, pFanin, i )
1524 if ( Sfm_DecNodeIsMffc(pFanin, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1525 Abc_ObjForEachFanin( pFanin, pFanin2, k )
1526 if ( Sfm_DecNodeIsMffc(pFanin2, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1527 Abc_ObjForEachFanin( pFanin2, pFanin3, n )
1528 if ( Sfm_DecNodeIsMffc(pFanin3, nLevelMin) && Vec_IntSize(vMffc) < nMffcMax )
1529 Vec_IntPushUnique( vMffc, Abc_ObjId(pFanin3) );
1530 // mark MFFC
1531 assert( Vec_IntSize(vMffc) <= nMffcMax );
1532 Abc_NtkForEachObjVec( vMffc, pPivot->pNtk, pObj, i )
1533 pObj->iTemp |= SFM_MASK_MFFC;
1534 pPivot->iTemp |= SFM_MASK_PIVOT;
1535 // collect MFFC inputs
1536 Vec_IntClear(vInMffc);
1537 Abc_NtkForEachObjVec( vMffc, pPivot->pNtk, pObj, i )
1538 Abc_ObjForEachFanin( pObj, pFanin, k )
1539 if ( Abc_NodeIsTravIdCurrent(pFanin) && pFanin->iTemp == SFM_MASK_PI )
1540 Vec_IntPushUnique( vInMffc, Abc_ObjId(pFanin) );
1541
1542// printf( "Node %d: ", pPivot->Id );
1543// Abc_ObjForEachFanin( pPivot, pFanin, i )
1544// printf( "%d ", Abc_ObjFanoutNum(pFanin) );
1545// printf( "\n" );
1546
1547// Abc_NtkForEachObjVec( vInMffc, pPivot->pNtk, pObj, i )
1548// printf( "%d ", Abc_ObjFanoutNum(pObj) );
1549// printf( "\n" );
1550
1551 }
1552}
1553
1565int Sfm_DecExtract( Abc_Ntk_t * pNtk, Sfm_Par_t * pPars, Abc_Obj_t * pPivot, Vec_Int_t * vRoots, Vec_Int_t * vGates, Vec_Wec_t * vFanins, Vec_Int_t * vMap, Vec_Int_t * vTfi, Vec_Int_t * vTfo, Vec_Int_t * vMffc, Vec_Int_t * vInMffc, Sfm_Tim_t * pTim, Sfm_Mit_t * pMit )
1566{
1567 int fVeryVerbose = 0;//pPars->fVeryVerbose;
1568 Vec_Int_t * vLevel;
1569 Abc_Obj_t * pObj, * pFanin;
1570 int nLevelMax = pPivot->Level + pPars->nTfoLevMax;
1571 int nLevelMin = pPivot->Level - pPars->nTfiLevMax;
1572 int i, k, nTfiSize, nDivs = -1;
1573 assert( Abc_ObjIsNode(pPivot) );
1574if ( fVeryVerbose )
1575printf( "\n\nTarget %d\n", Abc_ObjId(pPivot) );
1576 // collect TFO nodes
1577 Vec_IntClear( vTfo );
1578 Abc_NtkIncrementTravId( pNtk );
1579 Abc_NtkDfsReverseOne_rec( pPivot, vTfo, nLevelMax, pPars->nFanoutMax );
1580 // count internal fanouts
1581 Abc_NtkForEachObjVec( vTfo, pNtk, pObj, i )
1582 Abc_ObjForEachFanin( pObj, pFanin, k )
1583 pFanin->iTemp++;
1584 // compute roots
1585 Vec_IntClear( vRoots );
1586 Abc_NtkForEachObjVec( vTfo, pNtk, pObj, i )
1587 if ( pObj->iTemp != Abc_ObjFanoutNum(pObj) )
1588 Vec_IntPush( vRoots, Abc_ObjId(pObj) );
1589 assert( Vec_IntSize(vRoots) > 0 );
1590 // collect TFI and mark nodes
1591 Vec_IntClear( vTfi );
1592 Abc_NtkIncrementTravId( pNtk );
1593 Abc_NtkDfsOne_rec( pPivot, vTfi, nLevelMin, SFM_MASK_PI );
1594 nTfiSize = Vec_IntSize(vTfi);
1595 Sfm_ObjFlipNode( pPivot );
1596 // additinally mark MFFC
1597 Sfm_DecMarkMffc( pPivot, nLevelMin, pPars->nMffcMax, fVeryVerbose, vMffc, vInMffc, pTim, pMit );
1598 assert( Vec_IntSize(vMffc) <= pPars->nMffcMax );
1599if ( fVeryVerbose )
1600printf( "Mffc size = %d. Mffc area = %.2f. InMffc size = %d.\n", Vec_IntSize(vMffc), Scl_Int2Flt(Sfm_DecMffcArea(pNtk, vMffc)), Vec_IntSize(vInMffc) );
1601 // collect TFI(TFO)
1602 Abc_NtkForEachObjVec( vRoots, pNtk, pObj, i )
1603 Abc_NtkDfsOne_rec( pObj, vTfi, nLevelMin, SFM_MASK_INPUT );
1604 // mark input-only nodes pointed to by mixed nodes
1605 Abc_NtkForEachObjVecStart( vTfi, pNtk, pObj, i, nTfiSize )
1606 if ( pObj->iTemp != SFM_MASK_INPUT )
1607 Abc_ObjForEachFanin( pObj, pFanin, k )
1608 if ( pFanin->iTemp == SFM_MASK_INPUT )
1609 pFanin->iTemp = SFM_MASK_FANIN;
1610 // collect nodes supported only on TFI fanins and not MFFC
1611if ( fVeryVerbose )
1612printf( "\nDivs:\n" );
1613 Vec_IntClear( vMap );
1614 Vec_IntClear( vGates );
1615 Abc_NtkForEachObjVec( vTfi, pNtk, pObj, i )
1616 if ( pObj->iTemp == SFM_MASK_PI )
1617 Sfm_DecAddNode( pObj, vMap, vGates, Abc_ObjIsCi(pObj) || (Abc_ObjLevel(pObj) < nLevelMin && Abc_ObjFaninNum(pObj) > 0), fVeryVerbose );
1618 nDivs = Vec_IntSize(vMap);
1619 // add other nodes that are not in TFO and not in MFFC
1620if ( fVeryVerbose )
1621printf( "\nSides:\n" );
1622 Abc_NtkForEachObjVec( vTfi, pNtk, pObj, i )
1623 if ( pObj->iTemp == (SFM_MASK_PI | SFM_MASK_INPUT) || pObj->iTemp == SFM_MASK_FANIN )
1624 Sfm_DecAddNode( pObj, vMap, vGates, pObj->iTemp == SFM_MASK_FANIN, fVeryVerbose );
1625 // reorder nodes acording to delay
1626 if ( pMit )
1627 {
1628 int nDivsNew, nOldSize = Vec_IntSize(vMap);
1629 Vec_IntClear( vTfo );
1630 Vec_IntAppend( vTfo, vMap );
1631 nDivsNew = Sfm_MitSortArrayByArrival( pMit, vTfo, Abc_ObjId(pPivot) );
1632 // collect again
1633 Vec_IntClear( vMap );
1634 Vec_IntClear( vGates );
1635 Abc_NtkForEachObjVec( vTfo, pNtk, pObj, i )
1636 Sfm_DecAddNode( pObj, vMap, vGates, Abc_ObjIsCi(pObj) || (Abc_ObjLevel(pObj) < nLevelMin && Abc_ObjFaninNum(pObj) > 0) || pObj->iTemp == SFM_MASK_FANIN, 0 );
1637 assert( nOldSize == Vec_IntSize(vMap) );
1638 // update divisor count
1639 nDivs = nDivsNew;
1640 }
1641 else if ( pTim )
1642 {
1643 int nDivsNew, nOldSize = Vec_IntSize(vMap);
1644 Vec_IntClear( vTfo );
1645 Vec_IntAppend( vTfo, vMap );
1646 nDivsNew = Sfm_TimSortArrayByArrival( pTim, vTfo, Abc_ObjId(pPivot) );
1647 // collect again
1648 Vec_IntClear( vMap );
1649 Vec_IntClear( vGates );
1650 Abc_NtkForEachObjVec( vTfo, pNtk, pObj, i )
1651 Sfm_DecAddNode( pObj, vMap, vGates, Abc_ObjIsCi(pObj) || (Abc_ObjLevel(pObj) < nLevelMin && Abc_ObjFaninNum(pObj) > 0) || pObj->iTemp == SFM_MASK_FANIN, 0 );
1652 assert( nOldSize == Vec_IntSize(vMap) );
1653 // update divisor count
1654 nDivs = nDivsNew;
1655 }
1656 // add the TFO nodes
1657if ( fVeryVerbose )
1658printf( "\nTFO:\n" );
1659 Abc_NtkForEachObjVec( vTfi, pNtk, pObj, i )
1660 if ( pObj->iTemp >= SFM_MASK_MFFC )
1661 Sfm_DecAddNode( pObj, vMap, vGates, 0, fVeryVerbose );
1662 assert( Vec_IntSize(vMap) == Vec_IntSize(vGates) );
1663if ( fVeryVerbose )
1664printf( "\n" );
1665 // create node IDs
1666 Vec_WecClear( vFanins );
1667 Abc_NtkForEachObjVec( vMap, pNtk, pObj, i )
1668 {
1669 pObj->iTemp = i;
1670 vLevel = Vec_WecPushLevel( vFanins );
1671 if ( Vec_IntEntry(vGates, i) >= 0 )
1672 Abc_ObjForEachFanin( pObj, pFanin, k )
1673 Vec_IntPush( vLevel, pFanin->iTemp );
1674 }
1675 // compute care set
1676 Sfm_DecMan(pPivot)->uCareSet = Sfm_ObjFindCareSet(pPivot->pNtk, vRoots);
1677
1678 //printf( "care = %5d : ", Abc_ObjId(pPivot) );
1679 //Extra_PrintBinary( stdout, (unsigned *)&Sfm_DecMan(pPivot)->uCareSet, 64 );
1680 //printf( "\n" );
1681
1682 // remap roots
1683 Abc_NtkForEachObjVec( vRoots, pNtk, pObj, i )
1684 Vec_IntWriteEntry( vRoots, i, pObj->iTemp );
1685 // remap inputs to MFFC
1686 Abc_NtkForEachObjVec( vInMffc, pNtk, pObj, i )
1687 Vec_IntWriteEntry( vInMffc, i, pObj->iTemp );
1688
1689/*
1690 // check
1691 Abc_NtkForEachObjVec( vMap, pNtk, pObj, i )
1692 {
1693 if ( i == nDivs )
1694 break;
1695 Abc_NtkIncrementTravId( pNtk );
1696 assert( Abc_NtkDfsCheck_rec(pObj, pPivot) );
1697 }
1698*/
1699 return nDivs;
1700}
1701Abc_Obj_t * Sfm_DecInsert( Abc_Ntk_t * pNtk, Abc_Obj_t * pPivot, int Limit, Vec_Int_t * vGates, Vec_Wec_t * vFanins, Vec_Int_t * vMap, Vec_Ptr_t * vGateHandles, int GateBuf, int GateInv, Vec_Wrd_t * vFuncs, Vec_Int_t * vNewNodes, Sfm_Mit_t * pMit )
1702{
1703 Abc_Obj_t * pObjNew = NULL;
1704 Vec_Int_t * vLevel;
1705 int i, k, iObj, Gate;
1706 if ( vNewNodes )
1707 Vec_IntClear( vNewNodes );
1708 // assuming that new gates are appended at the end
1709 assert( Limit < Vec_IntSize(vGates) );
1710 assert( Limit == Vec_IntSize(vMap) );
1711 if ( Limit + 1 == Vec_IntSize(vGates) )
1712 {
1713 Gate = Vec_IntEntryLast(vGates);
1714 if ( Gate == GateBuf )
1715 {
1716 iObj = Vec_WecEntryEntry( vFanins, Limit, 0 );
1717 pObjNew = Abc_NtkObj( pNtk, Vec_IntEntry(vMap, iObj) );
1718 // transfer load
1719 if ( pMit )
1720 Sfm_MitTransferLoad( pMit, pObjNew, pPivot );
1721 // replace logic cone
1722 Abc_ObjReplace( pPivot, pObjNew );
1723 // update level
1724 pObjNew->Level = 0;
1725 Abc_NtkUpdateIncLevel_rec( pObjNew );
1726 if ( vNewNodes )
1727 Vec_IntPush( vNewNodes, Abc_ObjId(pObjNew) );
1728 return pObjNew;
1729 }
1730 else if ( vNewNodes == NULL && Gate == GateInv )
1731 {
1732 // check if fanouts can be updated
1733 Abc_Obj_t * pFanout;
1734 Abc_ObjForEachFanout( pPivot, pFanout, i )
1735 if ( !Abc_ObjIsNode(pFanout) || Sfm_LibFindComplInputGate(vFuncs, Mio_GateReadValue((Mio_Gate_t*)pFanout->pData), Abc_ObjFaninNum(pFanout), Abc_NodeFindFanin(pFanout, pPivot), NULL) == -1 )
1736 break;
1737 // update fanouts
1738 if ( i == Abc_ObjFanoutNum(pPivot) )
1739 {
1740 Abc_ObjForEachFanout( pPivot, pFanout, i )
1741 {
1742 int iFanin = Abc_NodeFindFanin(pFanout, pPivot), iFaninNew = -1;
1743 int iGate = Mio_GateReadValue((Mio_Gate_t*)pFanout->pData);
1744 int iGateNew = Sfm_LibFindComplInputGate( vFuncs, iGate, Abc_ObjFaninNum(pFanout), iFanin, &iFaninNew );
1745 assert( iGateNew >= 0 && iGateNew != iGate && iFaninNew >= 0 );
1746 pFanout->pData = Vec_PtrEntry( vGateHandles, iGateNew );
1747 //assert( iFanin == iFaninNew );
1748 // swap fanins
1749 if ( iFanin != iFaninNew )
1750 {
1751 int * pArray = Vec_IntArray( &pFanout->vFanins );
1752 ABC_SWAP( int, pArray[iFanin], pArray[iFaninNew] );
1753 }
1754 }
1755 iObj = Vec_WecEntryEntry( vFanins, Limit, 0 );
1756 pObjNew = Abc_NtkObj( pNtk, Vec_IntEntry(vMap, iObj) );
1757 Abc_ObjReplace( pPivot, pObjNew );
1758 // update level
1759 pObjNew->Level = 0;
1760 Abc_NtkUpdateIncLevel_rec( pObjNew );
1761 return pObjNew;
1762 }
1763 }
1764 }
1765 // introduce new gates
1766 Vec_IntForEachEntryStart( vGates, Gate, i, Limit )
1767 {
1768 vLevel = Vec_WecEntry( vFanins, i );
1769 pObjNew = Abc_NtkCreateNode( pNtk );
1770 Vec_IntForEachEntry( vLevel, iObj, k )
1771 Abc_ObjAddFanin( pObjNew, Abc_NtkObj(pNtk, Vec_IntEntry(vMap, iObj)) );
1772 pObjNew->pData = Vec_PtrEntry( vGateHandles, Gate );
1773 assert( Abc_ObjFaninNum(pObjNew) == Mio_GateReadPinNum((Mio_Gate_t *)pObjNew->pData) );
1774 Vec_IntPush( vMap, Abc_ObjId(pObjNew) );
1775 if ( vNewNodes )
1776 Vec_IntPush( vNewNodes, Abc_ObjId(pObjNew) );
1777 }
1778 // transfer load
1779 if ( pMit )
1780 {
1781 Sfm_MitTimingGrow( pMit );
1782 Sfm_MitTransferLoad( pMit, pObjNew, pPivot );
1783 }
1784 // replace logic cone
1785 Abc_ObjReplace( pPivot, pObjNew );
1786 // update level
1787 Abc_NtkForEachObjVecStart( vMap, pNtk, pObjNew, i, Limit )
1788 Abc_NtkUpdateIncLevel_rec( pObjNew );
1789 return pObjNew;
1790}
1792{
1793 int i;
1794 printf( "Node = %d. Try = %d. Change = %d. Const0 = %d. Const1 = %d. Buf = %d. Inv = %d. Gate = %d. AndOr = %d. Effort = %d. NoDec = %d.\n",
1795 p->nTotalNodesBeg, p->nNodesTried, p->nNodesChanged, p->nNodesConst0, p->nNodesConst1, p->nNodesBuf, p->nNodesInv, p->nNodesResyn, p->nNodesAndOr, p->nEfforts, p->nNoDecs );
1796 printf( "MaxDiv = %d. MaxWin = %d. AveDiv = %d. AveWin = %d. Calls = %d. (Sat = %d. Unsat = %d.) Over = %d. T/O = %d.\n",
1797 p->nMaxDivs, p->nMaxWin, (int)(p->nAllDivs/Abc_MaxInt(1, p->nNodesTried)), (int)(p->nAllWin/Abc_MaxInt(1, p->nNodesTried)), p->nSatCalls, p->nSatCallsSat, p->nSatCallsUnsat, p->nSatCallsOver, p->nTimeOuts );
1798
1799 p->timeTotal = Abc_Clock() - p->timeStart;
1800 p->timeOther = p->timeTotal - p->timeLib - p->timeWin - p->timeCnf - p->timeSat - p->timeTime;
1801
1802 ABC_PRTP( "Lib ", p->timeLib , p->timeTotal );
1803 ABC_PRTP( "Win ", p->timeWin , p->timeTotal );
1804 ABC_PRTP( "Cnf ", p->timeCnf , p->timeTotal );
1805 ABC_PRTP( "Sat ", p->timeSat-p->timeEval, p->timeTotal );
1806 ABC_PRTP( " Sat ", p->timeSatSat, p->timeTotal );
1807 ABC_PRTP( " Unsat", p->timeSatUnsat, p->timeTotal );
1808 ABC_PRTP( "Eval ", p->timeEval , p->timeTotal );
1809 ABC_PRTP( "Timing", p->timeTime , p->timeTotal );
1810 ABC_PRTP( "Other ", p->timeOther, p->timeTotal );
1811 ABC_PRTP( "ALL ", p->timeTotal, p->timeTotal );
1812
1813 printf( "Cone sizes: " );
1814 for ( i = 0; i <= SFM_SUPP_MAX; i++ )
1815 if ( p->nLuckySizes[i] )
1816 printf( "%d=%d ", i, p->nLuckySizes[i] );
1817 printf( " " );
1818
1819 printf( "Gate sizes: " );
1820 for ( i = 0; i <= SFM_SUPP_MAX; i++ )
1821 if ( p->nLuckyGates[i] )
1822 printf( "%d=%d ", i, p->nLuckyGates[i] );
1823 printf( "\n" );
1824
1825 printf( "Reduction: " );
1826 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) );
1827 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) );
1828 printf( "\n" );
1829}
1830void Abc_NtkCountStats( Sfm_Dec_t * p, int Limit )
1831{
1832 int Gate, nGates = Vec_IntSize(&p->vObjGates);
1833 if ( nGates == Limit )
1834 return;
1835 Gate = Vec_IntEntryLast(&p->vObjGates);
1836 if ( nGates > Limit + 1 )
1837 p->nNodesResyn++;
1838 else if ( Gate == p->GateConst0 )
1839 p->nNodesConst0++;
1840 else if ( Gate == p->GateConst1 )
1841 p->nNodesConst1++;
1842 else if ( Gate == p->GateBuffer )
1843 p->nNodesBuf++;
1844 else if ( Gate == p->GateInvert )
1845 p->nNodesInv++;
1846 else
1847 p->nNodesResyn++;
1848}
1849
1862{
1863 abctime clk;
1864 Abc_Ntk_t * pNtk = p->pNtk;
1865 Sfm_Par_t * pPars = p->pPars;
1866 Abc_Obj_t * pObj = Abc_NtkObj( p->pNtk, i );
1867 int Limit, RetValue;
1868 if ( pPars->nMffcMin > 1 && Abc_NodeMffcLabel(pObj, NULL) < pPars->nMffcMin )
1869 return NULL;
1870 if ( pPars->iNodeOne && i != pPars->iNodeOne )
1871 return NULL;
1872 if ( pPars->iNodeOne )
1873 pPars->fVeryVerbose = (int)(i == pPars->iNodeOne);
1874 p->nNodesTried++;
1875clk = Abc_Clock();
1876 p->nDivs = Sfm_DecExtract( pNtk, pPars, pObj, &p->vObjRoots, &p->vObjGates, &p->vObjFanins, &p->vObjMap, &p->vGateTfi, &p->vGateTfo, &p->vObjMffc, &p->vObjInMffc, NULL, NULL );
1877p->timeWin += Abc_Clock() - clk;
1878 if ( pPars->nWinSizeMax && pPars->nWinSizeMax < Vec_IntSize(&p->vObjGates) )
1879 return NULL;
1880 p->nMffc = Vec_IntSize(&p->vObjMffc);
1881 p->AreaMffc = Sfm_DecMffcArea(pNtk, &p->vObjMffc);
1882 p->nMaxDivs = Abc_MaxInt( p->nMaxDivs, p->nDivs );
1883 p->nAllDivs += p->nDivs;
1884 p->iTarget = pObj->iTemp;
1885 Limit = Vec_IntSize( &p->vObjGates );
1886 p->nMaxWin = Abc_MaxInt( p->nMaxWin, Limit );
1887 p->nAllWin += Limit;
1888clk = Abc_Clock();
1889 RetValue = Sfm_DecPrepareSolver( p );
1890p->timeCnf += Abc_Clock() - clk;
1891 if ( !RetValue )
1892 return NULL;
1893clk = Abc_Clock();
1894 RetValue = Sfm_DecPeformDec2( p, pObj );
1895 if ( pPars->fMoreEffort && RetValue < 0 )
1896 {
1897 int Var, i;
1898 Vec_IntForEachEntryReverse( &p->vObjInMffc, Var, i )
1899 {
1900 p->iUseThis = Var;
1901 RetValue = Sfm_DecPeformDec2( p, pObj );
1902 p->iUseThis = -1;
1903 if ( RetValue < 0 )
1904 {
1905 //printf( "Node %d: Not found among %d.\n", Abc_ObjId(pObj), Vec_IntSize(&p->vObjInMffc) );
1906 }
1907 else
1908 {
1909 p->nEfforts++;
1910 if ( p->pPars->fVerbose )
1911 {
1912 //printf( "Node %5d: (%2d out of %2d) Gate=%s ", Abc_ObjId(pObj), i, Vec_IntSize(&p->vObjInMffc), Mio_GateReadName((Mio_Gate_t*)pObj->pData) );
1913 //Dau_DsdPrintFromTruth( p->Copy, p->nSuppVars );
1914 }
1915 break;
1916 }
1917 }
1918 }
1919 if ( p->pPars->fVeryVerbose )
1920 printf( "\n\n" );
1921p->timeSat += Abc_Clock() - clk;
1922 if ( RetValue < 0 )
1923 return NULL;
1924 p->nNodesChanged++;
1925 Abc_NtkCountStats( p, Limit );
1926 return Sfm_DecInsert( pNtk, pObj, Limit, &p->vObjGates, &p->vObjFanins, &p->vObjMap, &p->vGateHands, p->GateBuffer, p->GateInvert, &p->vGateFuncs, NULL, p->pMit );
1927}
1929{
1930 Abc_Obj_t * pObj;
1931 int i, nStop = Abc_NtkObjNumMax(p->pNtk);
1932 Abc_NtkForEachNode( p->pNtk, pObj, i )
1933 {
1934 if ( i >= nStop || (p->pPars->nNodesMax && i > p->pPars->nNodesMax) )
1935 break;
1936 Abc_NtkAreaOptOne( p, i );
1937 }
1938}
1940{
1941 Abc_Obj_t * pObj, * pObjNew, * pFanin;
1942 int i, k, nStop = Abc_NtkObjNumMax(p->pNtk);
1943 Vec_Ptr_t * vFront = Vec_PtrAlloc( 1000 );
1944 Abc_NtkForEachObj( p->pNtk, pObj, i )
1945 assert( pObj->fMarkB == 0 );
1946 // start the queue of nodes to be tried
1947 Abc_NtkForEachCo( p->pNtk, pObj, i )
1948 if ( Abc_ObjIsNode(Abc_ObjFanin0(pObj)) && !Abc_ObjFanin0(pObj)->fMarkB )
1949 {
1950 Abc_ObjFanin0(pObj)->fMarkB = 1;
1951 Vec_PtrPush( vFront, Abc_ObjFanin0(pObj) );
1952 }
1953 // process nodes in this order
1954 Vec_PtrForEachEntry( Abc_Obj_t *, vFront, pObj, i )
1955 {
1956 if ( Abc_ObjIsNone(pObj) )
1957 continue;
1958 pObjNew = Abc_NtkAreaOptOne( p, Abc_ObjId(pObj) );
1959 if ( pObjNew != NULL )
1960 {
1961 if ( !Abc_ObjIsNode(pObjNew) || Abc_ObjFaninNum(pObjNew) == 0 || pObjNew->fMarkB )
1962 continue;
1963 if ( (int)Abc_ObjId(pObjNew) < nStop )
1964 {
1965 pObjNew->fMarkB = 1;
1966 Vec_PtrPush( vFront, pObjNew );
1967 continue;
1968 }
1969 }
1970 else
1971 pObjNew = pObj;
1972 Abc_ObjForEachFanin( pObjNew, pFanin, k )
1973 if ( Abc_ObjIsNode(pFanin) && Abc_ObjFaninNum(pObjNew) > 0 && !pFanin->fMarkB )
1974 {
1975 pFanin->fMarkB = 1;
1976 Vec_PtrPush( vFront, pFanin );
1977 }
1978 }
1979 Abc_NtkForEachObj( p->pNtk, pObj, i )
1980 pObj->fMarkB = 0;
1981 Vec_PtrFree( vFront );
1982}
1983
1985{
1986 Abc_Ntk_t * pNtk = p->pNtk;
1987 Sfm_Par_t * pPars = p->pPars; int n;
1988 Abc_NtkCleanMarkABC( pNtk );
1989 for ( n = 0; pPars->nNodesMax == 0 || n < pPars->nNodesMax; n++ )
1990 {
1991 Abc_Obj_t * pObj, * pObjNew; abctime clk;
1992 int i = 0, Limit, RetValue;
1993 // collect nodes
1994 if ( pPars->iNodeOne )
1995 Vec_IntFill( &p->vCands, 1, pPars->iNodeOne );
1996 else if ( p->pTim && !Sfm_TimPriorityNodes(p->pTim, &p->vCands, p->pPars->nTimeWin) )
1997 break;
1998 else if ( p->pMit && !Sfm_MitPriorityNodes(p->pMit, &p->vCands, p->pPars->nTimeWin) )
1999 break;
2000 // try improving delay for the nodes according to the priority
2001 Abc_NtkForEachObjVec( &p->vCands, p->pNtk, pObj, i )
2002 {
2003 int OldId = Abc_ObjId(pObj);
2004 int DelayOld = Sfm_ManReadObjDelay(p, OldId);
2005 assert( pObj->fMarkA == 0 );
2006 p->nNodesTried++;
2007clk = Abc_Clock();
2008 p->nDivs = Sfm_DecExtract( pNtk, pPars, pObj, &p->vObjRoots, &p->vObjGates, &p->vObjFanins, &p->vObjMap, &p->vGateTfi, &p->vGateTfo, &p->vObjMffc, &p->vObjInMffc, p->pTim, p->pMit );
2009p->timeWin += Abc_Clock() - clk;
2010 if ( p->nDivs < 2 || (pPars->nWinSizeMax && pPars->nWinSizeMax < Vec_IntSize(&p->vObjGates)) )
2011 {
2012 pObj->fMarkA = 1;
2013 continue;
2014 }
2015 p->nMffc = Vec_IntSize(&p->vObjMffc);
2016 p->AreaMffc = Sfm_DecMffcArea(pNtk, &p->vObjMffc);
2017 p->nMaxDivs = Abc_MaxInt( p->nMaxDivs, p->nDivs );
2018 p->nAllDivs += p->nDivs;
2019 p->iTarget = pObj->iTemp;
2020 Limit = Vec_IntSize( &p->vObjGates );
2021 p->nMaxWin = Abc_MaxInt( p->nMaxWin, Limit );
2022 p->nAllWin += Limit;
2023clk = Abc_Clock();
2024 RetValue = Sfm_DecPrepareSolver( p );
2025p->timeCnf += Abc_Clock() - clk;
2026 if ( !RetValue )
2027 {
2028 pObj->fMarkA = 1;
2029 continue;
2030 }
2031clk = Abc_Clock();
2032 RetValue = Sfm_DecPeformDec3( p, pObj );
2033 if ( pPars->fMoreEffort && RetValue < 0 )
2034 {
2035 int Var, i;
2036 Vec_IntForEachEntryReverse( &p->vObjInMffc, Var, i )
2037 {
2038 p->iUseThis = Var;
2039 RetValue = Sfm_DecPeformDec3( p, pObj );
2040 p->iUseThis = -1;
2041 if ( RetValue < 0 )
2042 {
2043 //printf( "Node %d: Not found among %d.\n", Abc_ObjId(pObj), Vec_IntSize(&p->vObjInMffc) );
2044 }
2045 else
2046 {
2047 p->nEfforts++;
2048 if ( p->pPars->fVerbose )
2049 {
2050 //printf( "Node %5d: (%2d out of %2d) Gate=%s ", Abc_ObjId(pObj), i, Vec_IntSize(&p->vObjInMffc), Mio_GateReadName((Mio_Gate_t*)pObj->pData) );
2051 //Dau_DsdPrintFromTruth( p->Copy, p->nSuppVars );
2052 }
2053 break;
2054 }
2055 }
2056 }
2057 if ( p->pPars->fVeryVerbose )
2058 printf( "\n\n" );
2059p->timeSat += Abc_Clock() - clk;
2060 if ( RetValue < 0 )
2061 {
2062 pObj->fMarkA = 1;
2063 continue;
2064 }
2065 assert( Vec_IntSize(&p->vObjGates) - Limit > 0 );
2066 assert( Vec_IntSize(&p->vObjGates) - Limit <= 2 );
2067 p->nNodesChanged++;
2068 Abc_NtkCountStats( p, Limit );
2069 // reduce load due to removed MFFC
2070 if ( p->pMit ) Sfm_MitUpdateLoad( p->pMit, &p->vGateMffc, 0 ); // assuming &p->vGateMffc contains MFFC
2071 Sfm_DecInsert( pNtk, pObj, Limit, &p->vObjGates, &p->vObjFanins, &p->vObjMap, &p->vGateHands, p->GateBuffer, p->GateInvert, &p->vGateFuncs, &p->vNewNodes, p->pMit );
2072 // increase load due to added new nodes
2073 if ( p->pMit ) Sfm_MitUpdateLoad( p->pMit, &p->vNewNodes, 1 ); // assuming &p->vNewNodes contains new nodes
2074clk = Abc_Clock();
2075 if ( p->pMit )
2076 Sfm_MitUpdateTiming( p->pMit, &p->vNewNodes );
2077 else
2078 Sfm_TimUpdateTiming( p->pTim, &p->vNewNodes );
2079p->timeTime += Abc_Clock() - clk;
2080 pObjNew = Abc_NtkObj( pNtk, Abc_NtkObjNumMax(pNtk)-1 );
2081 assert( p->pMit || p->DelayMin == 0 || p->DelayMin == Sfm_ManReadObjDelay(p, Abc_ObjId(pObjNew)) );
2082 // report
2083 if ( pPars->fDelayVerbose )
2084 printf( "Node %5d %5d : I =%3d. Cand = %5d (%6.2f %%) Old =%8.2f. New =%8.2f. Final =%8.2f. WNS =%8.2f.\n",
2085 OldId, Abc_NtkObjNumMax(p->pNtk), i, Vec_IntSize(&p->vCands), 100.0 * Vec_IntSize(&p->vCands) / Abc_NtkNodeNum(p->pNtk),
2086 Scl_Int2Flt(DelayOld), Scl_Int2Flt(Sfm_ManReadObjDelay(p, Abc_ObjId(pObjNew))),
2087 Scl_Int2Flt(Sfm_ManReadNtkDelay(p)), Scl_Int2Flt(Sfm_ManReadNtkMinSlack(p)) );
2088 break;
2089 }
2090 if ( pPars->iNodeOne )
2091 break;
2092 }
2093 Abc_NtkCleanMarkABC( pNtk );
2094}
2096{
2097 Sfm_Dec_t * p = Sfm_DecStart( pPars, (Mio_Library_t *)pNtk->pManFunc, pNtk );
2098 if ( pPars->fVerbose )
2099 {
2100 printf( "Remapping parameters: " );
2101 if ( pPars->nTfoLevMax )
2102 printf( "TFO = %d. ", pPars->nTfoLevMax );
2103 if ( pPars->nTfiLevMax )
2104 printf( "TFI = %d. ", pPars->nTfiLevMax );
2105 if ( pPars->nFanoutMax )
2106 printf( "FanMax = %d. ", pPars->nFanoutMax );
2107 if ( pPars->nWinSizeMax )
2108 printf( "WinMax = %d. ", pPars->nWinSizeMax );
2109 if ( pPars->nBTLimit )
2110 printf( "Confl = %d. ", pPars->nBTLimit );
2111 if ( pPars->nMffcMin && pPars->fArea )
2112 printf( "MffcMin = %d. ", pPars->nMffcMin );
2113 if ( pPars->nMffcMax && pPars->fArea )
2114 printf( "MffcMax = %d. ", pPars->nMffcMax );
2115 if ( pPars->nDecMax )
2116 printf( "DecMax = %d. ", pPars->nDecMax );
2117 if ( pPars->iNodeOne )
2118 printf( "Pivot = %d. ", pPars->iNodeOne );
2119 if ( !pPars->fArea )
2120 printf( "Win = %d. ", pPars->nTimeWin );
2121 if ( !pPars->fArea )
2122 printf( "Delta = %.2f ps. ", Scl_Int2Flt(p->DeltaCrit) );
2123 if ( pPars->fArea )
2124 printf( "0-cost = %s. ", pPars->fZeroCost ? "yes" : "no" );
2125 printf( "Effort = %s. ", pPars->fMoreEffort ? "yes" : "no" );
2126 printf( "Sim = %s. ", pPars->fUseSim ? "yes" : "no" );
2127 printf( "\n" );
2128 }
2129 // preparation steps
2130 Abc_NtkLevel( pNtk );
2131 if ( p->pPars->fUseSim )
2132 Sfm_NtkSimulate( pNtk );
2133 // record statistics
2134 if ( pPars->fVerbose ) p->nTotalNodesBeg = Abc_NtkNodeNum(pNtk);
2135 if ( pPars->fVerbose ) p->nTotalEdgesBeg = Abc_NtkGetTotalFanins(pNtk);
2136 // perform optimization
2137 if ( pPars->fArea )
2138 {
2139 if ( pPars->fAreaRev )
2140 Abc_NtkAreaOpt2( p );
2141 else
2142 Abc_NtkAreaOpt( p );
2143 }
2144 else
2145 Abc_NtkDelayOpt( p );
2146 // record statistics
2147 if ( pPars->fVerbose ) p->nTotalNodesEnd = Abc_NtkNodeNum(pNtk);
2148 if ( pPars->fVerbose ) p->nTotalEdgesEnd = Abc_NtkGetTotalFanins(pNtk);
2149 // print stats and quit
2150 if ( pPars->fVerbose )
2152 if ( pPars->fLibVerbose )
2153 Sfm_LibPrint( p->pLib );
2154 Sfm_DecStop( p );
2155 if ( pPars->fArea )
2156 {
2157 extern void Abc_NtkChangePerform( Abc_Ntk_t * pNtk, int fVerbose );
2158 Abc_NtkChangePerform( pNtk, pPars->fVerbose );
2159 }
2160}
2161
2165
2166
2168
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL void Abc_NtkCleanMarkABC(Abc_Ntk_t *pNtk)
Definition abcUtil.c:772
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Vec_Ptr_t * Abc_NtkDfs(Abc_Ntk_t *pNtk, int fCollectAll)
Definition abcDfs.c:82
#define Abc_NtkForEachObj(pNtk, pObj, i)
ITERATORS ///.
Definition abc.h:449
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
#define Abc_ObjForEachFanout(pObj, pFanout, i)
Definition abc.h:529
ABC_DLL void Abc_ObjPrint(FILE *pFile, Abc_Obj_t *pObj)
Definition abcPrint.c:1674
ABC_DLL int Abc_NodeMffcLabel(Abc_Obj_t *pNode, Vec_Ptr_t *vNodes)
Definition abcRefs.c:439
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
ABC_DLL void Abc_ObjReplace(Abc_Obj_t *pObjOld, Abc_Obj_t *pObjNew)
Definition abcFanio.c:325
ABC_DLL int Abc_NtkLevel(Abc_Ntk_t *pNtk)
Definition abcDfs.c:1449
#define Abc_NtkForEachCi(pNtk, pCi, i)
Definition abc.h:518
#define Abc_NtkForEachObjVecStart(vIds, pNtk, pObj, i, Start)
Definition abc.h:458
ABC_DLL int Abc_ObjLevelNew(Abc_Obj_t *pObj)
Definition abcTiming.c:1170
#define Abc_NtkForEachObjVec(vIds, pNtk, pObj, i)
Definition abc.h:455
ABC_DLL int Abc_NtkGetTotalFanins(Abc_Ntk_t *pNtk)
Definition abcUtil.c:520
ABC_DLL int Abc_NodeFindFanin(Abc_Obj_t *pNode, Abc_Obj_t *pFanin)
Definition abcUtil.c:791
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_PRTP(a, t, T)
Definition abc_global.h:258
#define ABC_REALLOC(type, obj, num)
Definition abc_global.h:268
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define ABC_FREE(obj)
Definition abc_global.h:267
#define ABC_CONST(number)
PARAMETERS ///.
Definition abc_global.h:240
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
ABC_DLL void * Abc_FrameReadLibScl()
Definition mainFrame.c:62
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
#define l_True
Definition bmcBmcS.c:35
#define l_Undef
Definition bmcBmcS.c:34
#define l_False
Definition bmcBmcS.c:36
#define sat_solver_addclause
Definition cecSatG2.c:37
#define sat_solver_add_xor
Definition cecSatG2.c:39
#define sat_solver
Definition cecSatG2.c:34
#define sat_solver_solve
Definition cecSatG2.c:45
ABC_NAMESPACE_IMPL_START pcube * cofactor(IN pcube *T, IN register pcube c)
Definition cofactor.c:44
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
Definition dauDsd.c:1968
Cube * p
Definition exorList.c:222
int Var
Definition exorList.c:228
word Gia_ManRandomW(int fReset)
Definition giaUtil.c:67
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
float Mio_LibraryReadDelayInvMax(Mio_Library_t *pLib)
Definition mioApi.c:59
Mio_Gate_t * Mio_LibraryReadConst0(Mio_Library_t *pLib)
Definition mioApi.c:51
int Mio_GateReadPinNum(Mio_Gate_t *pGate)
Definition mioApi.c:177
double Mio_GateReadArea(Mio_Gate_t *pGate)
Definition mioApi.c:171
struct Mio_LibraryStruct_t_ Mio_Library_t
Definition mio.h:42
Vec_Int_t * Mio_GateReadExpr(Mio_Gate_t *pGate)
Definition mioApi.c:180
int Mio_GateIsInv(Mio_Gate_t *pGate)
Definition mioApi.c:195
int Mio_GateReadValue(Mio_Gate_t *pGate)
Definition mioApi.c:183
char * Mio_GateReadName(Mio_Gate_t *pGate)
Definition mioApi.c:169
Mio_Gate_t * Mio_LibraryReadConst1(Mio_Library_t *pLib)
Definition mioApi.c:52
Mio_Gate_t * Mio_LibraryReadInv(Mio_Library_t *pLib)
Definition mioApi.c:50
struct Mio_GateStruct_t_ Mio_Gate_t
Definition mio.h:43
Mio_Gate_t * Mio_LibraryReadBuf(Mio_Library_t *pLib)
Definition mioApi.c:49
double Mio_GateReadDelayMax(Mio_Gate_t *pGate)
Definition mioApi.c:178
sat_solver * sat_solver_new(void)
Definition satSolver.c:1137
int sat_solver_simplify(sat_solver *s)
Definition satSolver.c:1515
void sat_solver_restart(sat_solver *s)
Definition satSolver.c:1389
void sat_solver_setnvars(sat_solver *s, int n)
Definition satSolver.c:1272
int sat_solver_nvars(sat_solver *s)
Definition satSolver.c:2369
void sat_solver_delete(sat_solver *s)
Definition satSolver.c:1341
struct SC_Lib_ SC_Lib
Definition sclLib.h:128
Scl_Con_t * Scl_ConReadMan()
Definition scl.c:62
void Abc_NtkChangePerform(Abc_Ntk_t *pNtk, int fVerbose)
Definition sfmArea.c:333
void Sfm_TranslateCnf(Vec_Wec_t *vRes, Vec_Str_t *vCnf, Vec_Int_t *vFaninMap, int iPivotVar)
Definition sfmCnf.c:201
int Sfm_DecMffcArea(Abc_Ntk_t *pNtk, Vec_Int_t *vMffc)
Definition sfmDec.c:681
#define SFM_MASK_PI
Definition sfmDec.c:142
void Sfm_DecStop(Sfm_Dec_t *p)
Definition sfmDec.c:249
void Abc_NtkCountStats(Sfm_Dec_t *p, int Limit)
Definition sfmDec.c:1830
void Sfm_ParSetDefault3(Sfm_Par_t *pPars)
FUNCTION DEFINITIONS ///.
Definition sfmDec.c:174
int Sfm_DecComputeFlipInvGain(Sfm_Dec_t *p, Abc_Obj_t *pPivot, int *pfNeedInv)
Definition sfmDec.c:738
int Abc_NtkDfsOne_rec(Abc_Obj_t *pObj, Vec_Int_t *vTfi, int nLevelMin, int CiLabel)
Definition sfmDec.c:1416
void Sfm_DecPrintStats(Sfm_Dec_t *p)
Definition sfmDec.c:1791
#define SFM_MASK_INPUT
Definition sfmDec.c:143
void Abc_NtkDfsReverseOne_rec(Abc_Obj_t *pObj, Vec_Int_t *vTfo, int nLevelMax, int nFanoutMax)
Definition sfmDec.c:1395
int Sfm_DecPeformDec2(Sfm_Dec_t *p, Abc_Obj_t *pObj)
Definition sfmDec.c:1098
int Sfm_MffcDeref_rec(Abc_Obj_t *pObj)
Definition sfmDec.c:689
int Sfm_DecPeformDec_rec(Sfm_Dec_t *p, word *pTruth, int *pSupp, int *pAssump, int nAssump, word Masks[2][SFM_SIM_WORDS], int fCofactor, int nSuppAdd)
Definition sfmDec.c:815
typedefABC_NAMESPACE_IMPL_START struct Sfm_Dec_t_ Sfm_Dec_t
DECLARATIONS ///.
Definition sfmDec.c:38
int Sfm_DecMffcAreaReal(Abc_Obj_t *pPivot, Vec_Int_t *vCut, Vec_Int_t *vMffc)
Definition sfmDec.c:714
void Sfm_DecVarCost(Sfm_Dec_t *p, word Masks[2][SFM_SIM_WORDS], int d, int Counts[2][2])
Definition sfmDec.c:619
#define SFM_MASK_MFFC
Definition sfmDec.c:145
void Abc_NtkAreaOpt(Sfm_Dec_t *p)
Definition sfmDec.c:1928
void Sfm_DecMarkMffc(Abc_Obj_t *pPivot, int nLevelMin, int nMffcMax, int fVeryVerbose, Vec_Int_t *vMffc, Vec_Int_t *vInMffc, Sfm_Tim_t *pTim, Sfm_Mit_t *pMit)
Definition sfmDec.c:1456
void Abc_NtkUpdateIncLevel_rec(Abc_Obj_t *pObj)
Definition sfmDec.c:1356
void Abc_NtkPerformMfs3(Abc_Ntk_t *pNtk, Sfm_Par_t *pPars)
Definition sfmDec.c:2095
void Sfm_DecPrepareVec(Vec_Int_t *vMap, int *pNodes, int nNodes, Vec_Int_t *vCut)
Definition sfmDec.c:731
void Abc_NtkDelayOpt(Sfm_Dec_t *p)
Definition sfmDec.c:1984
#define SFM_MASK_PIVOT
Definition sfmDec.c:146
int Sfm_DecPeformDec3(Sfm_Dec_t *p, Abc_Obj_t *pObj)
Definition sfmDec.c:1205
Sfm_Dec_t * Sfm_DecStart(Sfm_Par_t *pPars, Mio_Library_t *pLib, Abc_Ntk_t *pNtk)
Definition sfmDec.c:209
int Sfm_DecPrepareSolver(Sfm_Dec_t *p)
Definition sfmDec.c:480
Abc_Obj_t * Abc_NtkAreaOptOne(Sfm_Dec_t *p, int i)
Definition sfmDec.c:1861
#define SFM_MASK_FANIN
Definition sfmDec.c:144
int Sfm_MffcRef_rec(Abc_Obj_t *pObj, Vec_Int_t *vMffc)
Definition sfmDec.c:701
int Abc_NtkDfsCheck_rec(Abc_Obj_t *pObj, Abc_Obj_t *pPivot)
Definition sfmDec.c:1379
int Sfm_DecFindBestVar(Sfm_Dec_t *p, word Masks[2][SFM_SIM_WORDS])
Definition sfmDec.c:650
int Sfm_DecFindBestVar2(Sfm_Dec_t *p, word Masks[2][SFM_SIM_WORDS])
Definition sfmDec.c:632
void Sfm_DecPrint(Sfm_Dec_t *p, word Masks[2][SFM_SIM_WORDS])
Definition sfmDec.c:572
void Sfm_DecAddNode(Abc_Obj_t *pObj, Vec_Int_t *vMap, Vec_Int_t *vGates, int fSkip, int fVeryVerbose)
Definition sfmDec.c:1435
int Sfm_DecFindCost(Sfm_Dec_t *p, int c, int iLit, word *pMask)
Definition sfmDec.c:567
int Sfm_DecCombineDec(Sfm_Dec_t *p, word *pTruth0, word *pTruth1, int *pSupp0, int *pSupp1, int nSupp0, int nSupp1, word *pTruth, int *pSupp, int Var)
Definition sfmDec.c:783
Abc_Obj_t * Sfm_DecInsert(Abc_Ntk_t *pNtk, Abc_Obj_t *pPivot, int Limit, Vec_Int_t *vGates, Vec_Wec_t *vFanins, Vec_Int_t *vMap, Vec_Ptr_t *vGateHandles, int GateBuf, int GateInv, Vec_Wrd_t *vFuncs, Vec_Int_t *vNewNodes, Sfm_Mit_t *pMit)
Definition sfmDec.c:1701
int Sfm_DecExtract(Abc_Ntk_t *pNtk, Sfm_Par_t *pPars, Abc_Obj_t *pPivot, Vec_Int_t *vRoots, Vec_Int_t *vGates, Vec_Wec_t *vFanins, Vec_Int_t *vMap, Vec_Int_t *vTfi, Vec_Int_t *vTfo, Vec_Int_t *vMffc, Vec_Int_t *vInMffc, Sfm_Tim_t *pTim, Sfm_Mit_t *pMit)
Definition sfmDec.c:1565
void Abc_NtkAreaOpt2(Sfm_Dec_t *p)
Definition sfmDec.c:1939
int Sfm_TimSortArrayByArrival(Sfm_Tim_t *p, Vec_Int_t *vNodes, int iPivot)
Definition sfmTim.c:336
#define SFM_WORD_MAX
Definition sfmInt.h:57
void Sfm_MitTimingGrow(Sfm_Mit_t *p)
Definition sfmMit.c:58
int Sfm_LibImplementGatesArea(Sfm_Lib_t *p, int *pFanins, int nFanins, int iObj, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
Definition sfmLib.c:704
void Sfm_MitUpdateTiming(Sfm_Mit_t *p, Vec_Int_t *vTimeNodes)
Definition sfmMit.c:60
void Sfm_MitTransferLoad(Sfm_Mit_t *p, Abc_Obj_t *pNew, Abc_Obj_t *pOld)
Definition sfmMit.c:57
void Sfm_LibPrint(Sfm_Lib_t *p)
Definition sfmLib.c:567
void Sfm_MitStop(Sfm_Mit_t *p)
Definition sfmMit.c:53
struct Sfm_Tim_t_ Sfm_Tim_t
Definition sfmInt.h:68
Sfm_Tim_t * Sfm_TimStart(Mio_Library_t *pLib, Scl_Con_t *pExt, Abc_Ntk_t *pNtk, int DeltaCrit)
Definition sfmTim.c:229
struct Sfm_Mit_t_ Sfm_Mit_t
Definition sfmInt.h:69
int Sfm_MitReadNtkDelay(Sfm_Mit_t *p)
Definition sfmMit.c:54
int Sfm_TimReadObjDelay(Sfm_Tim_t *p, int iObj)
Definition sfmTim.c:255
int Sfm_TimNodeIsNonCritical(Sfm_Tim_t *p, Abc_Obj_t *pPivot, Abc_Obj_t *pNode)
Definition sfmTim.c:412
#define SFM_SIM_WORDS
Definition sfmInt.h:60
void Sfm_MitUpdateLoad(Sfm_Mit_t *p, Vec_Int_t *vTimeNodes, int fAdd)
Definition sfmMit.c:59
int Sfm_MitReadObjDelay(Sfm_Mit_t *p, int iObj)
Definition sfmMit.c:56
#define SFM_DEC_MAX
Definition sfmInt.h:59
Sfm_Lib_t * Sfm_LibPrepare(int nVars, int fTwo, int fDelay, int fVerbose, int fLibVerbose)
Definition sfmLib.c:438
int Sfm_LibFindComplInputGate(Vec_Wrd_t *vFuncs, int iGate, int nFanins, int iFanin, int *piFaninNew)
Definition sfmLib.c:161
void Sfm_LibStop(Sfm_Lib_t *p)
Definition sfmLib.c:226
int Sfm_TimReadNtkDelay(Sfm_Tim_t *p)
Definition sfmTim.c:251
void Sfm_TimUpdateTiming(Sfm_Tim_t *p, Vec_Int_t *vTimeNodes)
Definition sfmTim.c:317
int Sfm_MitPriorityNodes(Sfm_Mit_t *p, Vec_Int_t *vCands, int Window)
Definition sfmMit.c:62
void Sfm_TimStop(Sfm_Tim_t *p)
Definition sfmTim.c:242
int Sfm_LibImplementGatesDelay(Sfm_Lib_t *p, int *pFanins, Mio_Gate_t *pGateB, Mio_Gate_t *pGateT, char *pFansB, char *pFansT, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
Definition sfmLib.c:736
#define SFM_SUPP_MAX
Definition sfmInt.h:56
int Sfm_LibFindDelayMatches(Sfm_Lib_t *p, word *pTruth, int *pFanins, int nFanins, Vec_Ptr_t *vGates, Vec_Ptr_t *vFans)
Definition sfmLib.c:625
struct Sfm_Lib_t_ Sfm_Lib_t
Definition sfmInt.h:67
int Sfm_LibImplementSimple(Sfm_Lib_t *p, word *pTruth, int *pFanins, int nFanins, Vec_Int_t *vGates, Vec_Wec_t *vFanins)
Definition sfmLib.c:679
#define SFM_WIN_MAX
Definition sfmInt.h:58
int Sfm_MitSortArrayByArrival(Sfm_Mit_t *p, Vec_Int_t *vNodes, int iPivot)
Definition sfmMit.c:61
int Sfm_MitNodeIsNonCritical(Sfm_Mit_t *p, Abc_Obj_t *pPivot, Abc_Obj_t *pNode)
Definition sfmMit.c:63
int Sfm_LibFindAreaMatch(Sfm_Lib_t *p, word *pTruth, int nFanins, int *piObj)
Definition sfmLib.c:613
int Sfm_MitReadNtkMinSlack(Sfm_Mit_t *p)
Definition sfmMit.c:55
int Sfm_TimEvalRemapping(Sfm_Tim_t *p, Vec_Int_t *vFanins, Vec_Int_t *vMap, Mio_Gate_t *pGate1, char *pFans1, Mio_Gate_t *pGate2, char *pFans2)
Definition sfmTim.c:428
int Sfm_MitEvalRemapping(Sfm_Mit_t *p, Vec_Int_t *vMffc, Abc_Obj_t *pObj, Vec_Int_t *vFanins, Vec_Int_t *vMap, Mio_Gate_t *pGate1, char *pFans1, Mio_Gate_t *pGate2, char *pFans2)
Definition sfmMit.c:64
int Sfm_TimPriorityNodes(Sfm_Tim_t *p, Vec_Int_t *vCands, int Window)
Definition sfmTim.c:374
Sfm_Mit_t * Sfm_MitStart(Mio_Library_t *pLib, SC_Lib *pScl, Scl_Con_t *pExt, Abc_Ntk_t *pNtk, int DeltaCrit)
FUNCTION DEFINITIONS ///.
Definition sfmMit.c:52
void Sfm_LibPreprocess(Mio_Library_t *pLib, Vec_Int_t *vGateSizes, Vec_Wrd_t *vGateFuncs, Vec_Wec_t *vGateCnfs, Vec_Ptr_t *vGateHands)
Definition sfmLib.c:131
struct Sfm_Par_t_ Sfm_Par_t
Definition sfm.h:42
void * pManFunc
Definition abc.h:191
void * pData
Definition abc.h:203
void * pData
Definition abc.h:145
Vec_Int_t vFanins
Definition abc.h:143
Abc_Ntk_t * pNtk
Definition abc.h:130
unsigned fMarkB
Definition abc.h:135
int iTemp
Definition abc.h:149
Vec_Int_t vFanouts
Definition abc.h:144
unsigned fMarkA
Definition abc.h:134
unsigned Level
Definition abc.h:142
word TtElems[SFM_SUPP_MAX][SFM_WORD_MAX]
Definition sfmDec.c:90
word * pTtElems[SFM_SUPP_MAX]
Definition sfmDec.c:91
Vec_Ptr_t vGateHands
Definition sfmDec.c:51
Vec_Int_t vObjGates
Definition sfmDec.c:71
int GateConst1
Definition sfmDec.c:53
abctime timeTotal
Definition sfmDec.c:114
abctime timeSatSat
Definition sfmDec.c:108
abctime timeOther
Definition sfmDec.c:112
int AreaMffc
Definition sfmDec.c:61
int nNodesInv
Definition sfmDec.c:124
int nDivWords
Definition sfmDec.c:88
Vec_Wec_t vObjFanins
Definition sfmDec.c:72
Mio_Gate_t * pGateInv
Definition sfmDec.c:68
int nNodesBuf
Definition sfmDec.c:123
Sfm_Tim_t * pTim
Definition sfmDec.c:44
Vec_Wrd_t vSets[2]
Definition sfmDec.c:85
abctime timeSatUnsat
Definition sfmDec.c:109
word uCareSet
Definition sfmDec.c:69
int nTimeOuts
Definition sfmDec.c:131
int AreaInv
Definition sfmDec.c:66
abctime timeWin
Definition sfmDec.c:105
int nMaxWin
Definition sfmDec.c:135
Vec_Int_t vGateTfi
Definition sfmDec.c:95
sat_solver * pSat
Definition sfmDec.c:82
int nSatCallsOver
Definition sfmDec.c:130
Vec_Int_t vObjInMffc
Definition sfmDec.c:76
int nPats[2]
Definition sfmDec.c:86
word * pDivWords[SFM_SUPP_MAX]
Definition sfmDec.c:92
int nSatCallsUnsat
Definition sfmDec.c:129
abctime timeLib
Definition sfmDec.c:104
Vec_Ptr_t vMatchFans
Definition sfmDec.c:80
Vec_Int_t vGateTfo
Definition sfmDec.c:96
Vec_Int_t vObjMap
Definition sfmDec.c:73
int nDivs
Definition sfmDec.c:59
Abc_Ntk_t * pNtk
Definition sfmDec.c:46
word Copy[4]
Definition sfmDec.c:101
int iUseThis
Definition sfmDec.c:64
int nSuppVars
Definition sfmDec.c:102
abctime timeTime
Definition sfmDec.c:111
Vec_Int_t vGateCut
Definition sfmDec.c:97
Vec_Wrd_t vObjSims
Definition sfmDec.c:77
int nNoDecs
Definition sfmDec.c:132
int nTotalNodesEnd
Definition sfmDec.c:117
Vec_Wrd_t vGateFuncs
Definition sfmDec.c:49
Vec_Int_t vCands
Definition sfmDec.c:100
Vec_Int_t vGateTemp
Definition sfmDec.c:98
int GateInvert
Definition sfmDec.c:55
int nNodesChanged
Definition sfmDec.c:120
Sfm_Par_t * pPars
Definition sfmDec.c:42
Vec_Int_t vObjRoots
Definition sfmDec.c:70
int DeltaCrit
Definition sfmDec.c:65
Sfm_Lib_t * pLib
Definition sfmDec.c:43
int nMaxDivs
Definition sfmDec.c:134
int GateOr[4]
Definition sfmDec.c:57
int GateConst0
Definition sfmDec.c:52
Vec_Int_t vGateSizes
Definition sfmDec.c:48
int nTotalEdgesEnd
Definition sfmDec.c:118
abctime timeEval
Definition sfmDec.c:110
Vec_Wec_t vClauses
Definition sfmDec.c:83
int nDivWordsAlloc
Definition sfmDec.c:89
int DelayMin
Definition sfmDec.c:62
Vec_Ptr_t vMatchGates
Definition sfmDec.c:79
int nLuckySizes[SFM_SUPP_MAX+1]
Definition sfmDec.c:138
Vec_Int_t vNewNodes
Definition sfmDec.c:94
abctime timeStart
Definition sfmDec.c:113
word nAllDivs
Definition sfmDec.c:136
int GateAnd[4]
Definition sfmDec.c:56
int nNodesAndOr
Definition sfmDec.c:125
word nAllWin
Definition sfmDec.c:137
Vec_Int_t vObjMffc
Definition sfmDec.c:75
int nEfforts
Definition sfmDec.c:133
abctime timeSat
Definition sfmDec.c:107
int nNodesConst1
Definition sfmDec.c:122
int GateBuffer
Definition sfmDec.c:54
int nSatCalls
Definition sfmDec.c:127
int nTotalEdgesBeg
Definition sfmDec.c:116
Vec_Wrd_t vObjSims2
Definition sfmDec.c:78
Vec_Int_t vImpls[2]
Definition sfmDec.c:84
int DelayInv
Definition sfmDec.c:67
int nPatWords[2]
Definition sfmDec.c:87
abctime timeCnf
Definition sfmDec.c:106
int nNodesTried
Definition sfmDec.c:119
Sfm_Mit_t * pMit
Definition sfmDec.c:45
int nTotalNodesBeg
Definition sfmDec.c:115
int iTarget
Definition sfmDec.c:63
int nLuckyGates[SFM_SUPP_MAX+1]
Definition sfmDec.c:139
int nMffc
Definition sfmDec.c:60
int nNodesConst0
Definition sfmDec.c:121
Vec_Int_t vGateMffc
Definition sfmDec.c:99
Vec_Int_t vObjDec
Definition sfmDec.c:74
int nSatCallsSat
Definition sfmDec.c:128
Vec_Wec_t vGateCnfs
Definition sfmDec.c:50
int nNodesResyn
Definition sfmDec.c:126
int nMffcMax
Definition sfm.h:51
int nGrowthLevel
Definition sfm.h:54
int nVarMax
Definition sfm.h:49
int nTfoLevMax
Definition sfm.h:45
int fVeryVerbose
Definition sfm.h:75
int fZeroCost
Definition sfm.h:67
int nDecMax
Definition sfm.h:52
int nTimeWin
Definition sfm.h:59
int DeltaCrit
Definition sfm.h:60
int nFanoutMax
Definition sfm.h:47
int fMoreEffort
Definition sfm.h:65
int fUseSim
Definition sfm.h:68
int fArea
Definition sfm.h:63
int nWinSizeMax
Definition sfm.h:53
int nNodesMax
Definition sfm.h:56
int fUseAndOr
Definition sfm.h:66
int nTfiLevMax
Definition sfm.h:46
int nBTLimit
Definition sfm.h:55
int iNodeOne
Definition sfm.h:57
int fDelayVerbose
Definition sfm.h:73
int fVerbose
Definition sfm.h:74
int fLibVerbose
Definition sfm.h:72
int fAreaRev
Definition sfm.h:64
int nMffcMin
Definition sfm.h:50
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * memset()
int memcmp()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryReverse(vVec, pEntry, i)
Definition vecInt.h:62
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
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
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42