ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
mpmMap.c
Go to the documentation of this file.
1
20
21#include "mpmInt.h"
22
24
28
29//#define MIG_RUNTIME
30
34
46static inline int Mpm_CutAlloc( Mpm_Man_t * p, int nLeaves, Mpm_Cut_t ** ppCut )
47{
48 int hHandle = Mmr_StepFetch( p->pManCuts, Mpm_CutWordNum(nLeaves) );
49 *ppCut = (Mpm_Cut_t *)Mmr_StepEntry( p->pManCuts, hHandle );
50 (*ppCut)->nLeaves = nLeaves;
51 (*ppCut)->hNext = 0;
52 (*ppCut)->fUseless = 0;
53 (*ppCut)->fCompl = 0;
54 return hHandle;
55}
56static inline int Mpm_CutCreateZero( Mpm_Man_t * p )
57{
58 Mpm_Cut_t * pCut;
59 int hCut = Mpm_CutAlloc( p, 0, &pCut );
60 pCut->iFunc = 0; // const0
61 return hCut;
62}
63static inline int Mpm_CutCreateUnit( Mpm_Man_t * p, int Id )
64{
65 Mpm_Cut_t * pCut;
66 int hCut = Mpm_CutAlloc( p, 1, &pCut );
67 pCut->iFunc = Abc_Var2Lit( p->funcVar0, 0 ); // var
68 pCut->pLeaves[0] = Abc_Var2Lit( Id, 0 );
69 return hCut;
70}
71static inline int Mpm_CutCreate( Mpm_Man_t * p, Mpm_Cut_t * pUni, Mpm_Cut_t ** ppCut )
72{
73 int hCutNew = Mpm_CutAlloc( p, pUni->nLeaves, ppCut );
74 (*ppCut)->iFunc = pUni->iFunc;
75 (*ppCut)->fCompl = pUni->fCompl;
76 (*ppCut)->fUseless = pUni->fUseless;
77 (*ppCut)->nLeaves = pUni->nLeaves;
78 memcpy( (*ppCut)->pLeaves, pUni->pLeaves, sizeof(int) * pUni->nLeaves );
79 return hCutNew;
80}
81static inline int Mpm_CutDup( Mpm_Man_t * p, Mpm_Cut_t * pCut, int fCompl )
82{
83 Mpm_Cut_t * pCutNew;
84 int hCutNew = Mpm_CutAlloc( p, pCut->nLeaves, &pCutNew );
85 pCutNew->iFunc = Abc_LitNotCond( pCut->iFunc, fCompl );
86 pCutNew->fUseless = pCut->fUseless;
87 pCutNew->nLeaves = pCut->nLeaves;
88 memcpy( pCutNew->pLeaves, pCut->pLeaves, sizeof(int) * pCut->nLeaves );
89 return hCutNew;
90}
91static inline int Mpm_CutCopySet( Mpm_Man_t * p, Mig_Obj_t * pObj, int fCompl )
92{
93 Mpm_Cut_t * pCut;
94 int hCut, iList = 0, * pList = &iList;
95 Mpm_ObjForEachCut( p, pObj, hCut, pCut )
96 {
97 *pList = Mpm_CutDup( p, pCut, fCompl );
98 pList = &Mpm_CutFetch( p, *pList )->hNext;
99 }
100 *pList = 0;
101 return iList;
102}
103void Mpm_CutPrint( Mpm_Cut_t * pCut )
104{
105 int i;
106 printf( "%d : { ", pCut->nLeaves );
107 for ( i = 0; i < (int)pCut->nLeaves; i++ )
108 printf( "%d ", pCut->pLeaves[i] );
109 printf( "}\n" );
110}
111static inline void Mpm_CutPrintAll( Mpm_Man_t * p )
112{
113 int i;
114 for ( i = 0; i < p->nCutStore; i++ )
115 {
116 printf( "%2d : ", i );
117 Mpm_CutPrint( &p->pCutStore[i]->pCut );
118 }
119}
120static inline int Mpm_CutFindLeaf( Mpm_Cut_t * pNew, int iObj )
121{
122 int i;
123 for ( i = 0; i < (int)pNew->nLeaves; i++ )
124 if ( Abc_Lit2Var(pNew->pLeaves[i]) == iObj )
125 return i;
126 return i;
127}
128static inline int Mpm_CutIsContained( Mpm_Man_t * p, Mpm_Cut_t * pBase, Mpm_Cut_t * pCut ) // check if pCut is contained pBase
129{
130 int i;
131 for ( i = 0; i < (int)pCut->nLeaves; i++ )
132 if ( Mpm_CutFindLeaf( pBase, Abc_Lit2Var(pCut->pLeaves[i]) ) == (int)pBase->nLeaves )
133 return 0;
134 return 1;
135}
136
148static inline int Mpm_CutGetArea( Mpm_Man_t * p, Mpm_Cut_t * pCut )
149{
150 if ( p->pPars->fMap4Cnf )
151 return MPM_UNIT_AREA * p->pDsd6[Abc_Lit2Var(pCut->iFunc)].nClauses;
152 if ( p->pPars->fMap4Aig )
153 return MPM_UNIT_AREA * p->pDsd6[Abc_Lit2Var(pCut->iFunc)].nAnds;
154 if ( p->pPars->fMap4Gates )
155 return MPM_UNIT_AREA * 1;
156 return p->pLibLut->pLutAreas[pCut->nLeaves];
157}
158static inline word Mpm_CutGetSign( Mpm_Cut_t * pCut )
159{
160 int i, iLeaf;
161 word uSign = 0;
162 Mpm_CutForEachLeafId( pCut, iLeaf, i )
163 uSign |= ((word)1 << (iLeaf & 0x3F));
164 return uSign;
165}
166static inline int Mpm_CutGetArrTime( Mpm_Man_t * p, Mpm_Cut_t * pCut )
167{
168 int * pmTimes = Vec_IntArray( &p->vTimes );
169 int * pDelays = p->pLibLut->pLutDelays[pCut->nLeaves];
170 int i, iLeaf, ArrTime = 0;
171 Mpm_CutForEachLeafId( pCut, iLeaf, i )
172 ArrTime = Abc_MaxInt( ArrTime, pmTimes[iLeaf] + pDelays[i] );
173 return ArrTime;
174}
175static inline Mpm_Uni_t * Mpm_CutSetupInfo( Mpm_Man_t * p, Mpm_Cut_t * pCut, int ArrTime )
176{
177 int * pMigRefs = Vec_IntArray( &p->vMigRefs );
178 int * pMapRefs = Vec_IntArray( &p->vMapRefs );
179 int * pEstRefs = Vec_IntArray( &p->vEstRefs );
180 int * pmArea = Vec_IntArray( &p->vAreas );
181 int * pmEdge = Vec_IntArray( &p->vEdges );
182 int i, iLeaf;
183 Mpm_Uni_t * pUnit = (Mpm_Uni_t *)Vec_PtrEntryLast(&p->vFreeUnits);
184 assert( &pUnit->pCut == pCut );
185 pUnit->mTime = ArrTime;
186 pUnit->mArea = Mpm_CutGetArea( p, pCut );
187 pUnit->mEdge = MPM_UNIT_EDGE * pCut->nLeaves;
188 pUnit->mAveRefs = 0;
189 pUnit->Cost = 0;
190 pUnit->uSign = 0;
191 Mpm_CutForEachLeafId( pCut, iLeaf, i )
192 {
193 if ( p->fMainRun && pMapRefs[iLeaf] == 0 ) // not used in the mapping
194 {
195 pUnit->mArea += pmArea[iLeaf];
196 pUnit->mEdge += pmEdge[iLeaf];
197 }
198 else
199 {
200 assert( pEstRefs[iLeaf] > 0 );
201 pUnit->mArea += MPM_UNIT_REFS * pmArea[iLeaf] / pEstRefs[iLeaf];
202 pUnit->mEdge += MPM_UNIT_REFS * pmEdge[iLeaf] / pEstRefs[iLeaf];
203 pUnit->mAveRefs += p->fMainRun ? pMapRefs[iLeaf] : pMigRefs[iLeaf];
204 }
205 pUnit->uSign |= ((word)1 << (iLeaf & 0x3F));
206 }
207 pUnit->mAveRefs = pUnit->mAveRefs * MPM_UNIT_EDGE / Abc_MaxInt(pCut->nLeaves, 1);
208 assert( pUnit->mTime <= 0x3FFFFFFF );
209 assert( pUnit->mArea <= 0x3FFFFFFF );
210 assert( pUnit->mEdge <= 0x3FFFFFFF );
211 return pUnit;
212}
213
225int Mpm_ObjAddCutToStore( Mpm_Man_t * p, Mpm_Cut_t * pCut, int ArrTime )
226{
227 int fEnableContainment = 1;
228 Mpm_Uni_t * pUnit, * pUnitNew;
229 int k, iPivot, last;
230 // create new unit
231#ifdef MIG_RUNTIME
232 abctime clk;
233clk = Abc_Clock();
234#endif
235 pUnitNew = Mpm_CutSetupInfo( p, pCut, ArrTime );
236#ifdef MIG_RUNTIME
237p->timeEval += Abc_Clock() - clk;
238#endif
239 // special case when the cut store is empty
240 if ( p->nCutStore == 0 )
241 {
242 p->pCutStore[p->nCutStore++] = pUnitNew;
243 Vec_PtrPop( &p->vFreeUnits );
244 return 1;
245 }
246 // special case when the cut store is full and last cut is better than new cut
247 if ( p->nCutStore == p->nNumCuts-1 && p->pCutCmp(pUnitNew, p->pCutStore[p->nCutStore-1]) > 0 )
248 return 0;
249
250 // find place of the given cut in the store
251 assert( p->nCutStore <= p->nNumCuts );
252 for ( iPivot = p->nCutStore - 1; iPivot >= 0; iPivot-- )
253 if ( p->pCutCmp(pUnitNew, p->pCutStore[iPivot]) > 0 ) // iPivot-th cut is better than new cut
254 break;
255
256 if ( fEnableContainment )
257 {
258#ifdef MIG_RUNTIME
259clk = Abc_Clock();
260#endif
261 // filter this cut using other cuts
262 for ( k = 0; k <= iPivot; k++ )
263 {
264 pUnit = p->pCutStore[k];
265 if ( pUnitNew->pCut.nLeaves >= pUnit->pCut.nLeaves &&
266 (pUnitNew->uSign & pUnit->uSign) == pUnit->uSign &&
267 Mpm_CutIsContained(p, &pUnitNew->pCut, &pUnit->pCut) )
268 {
269#ifdef MIG_RUNTIME
270p->timeCompare += Abc_Clock() - clk;
271#endif
272 return 0;
273 }
274 }
275 }
276
277 // special case when the best cut is useless while the new cut is not
278 if ( p->pCutStore[0]->pCut.fUseless && !pUnitNew->pCut.fUseless )
279 iPivot = -1;
280
281 // add the cut to storage
282 assert( pUnitNew == (Mpm_Uni_t *)Vec_PtrEntryLast(&p->vFreeUnits) );
283 Vec_PtrPop( &p->vFreeUnits );
284
285 // insert this cut at location iPivot
286 iPivot++;
287 for ( k = p->nCutStore++; k > iPivot; k-- )
288 p->pCutStore[k] = p->pCutStore[k-1];
289 p->pCutStore[iPivot] = pUnitNew;
290
291 if ( fEnableContainment )
292 {
293 // filter other cuts using this cut
294 for ( k = last = iPivot+1; k < p->nCutStore; k++ )
295 {
296 pUnit = p->pCutStore[k];
297 if ( pUnitNew->pCut.nLeaves <= pUnit->pCut.nLeaves &&
298 (pUnitNew->uSign & pUnit->uSign) == pUnitNew->uSign &&
299 Mpm_CutIsContained(p, &pUnit->pCut, &pUnitNew->pCut) )
300 {
301 Vec_PtrPush( &p->vFreeUnits, pUnit );
302 continue;
303 }
304 p->pCutStore[last++] = p->pCutStore[k];
305 }
306 p->nCutStore = last;
307#ifdef MIG_RUNTIME
308p->timeCompare += Abc_Clock() - clk;
309#endif
310 }
311
312 // remove the last cut if too many
313 if ( p->nCutStore == p->nNumCuts )
314 Vec_PtrPush( &p->vFreeUnits, p->pCutStore[--p->nCutStore] );
315 assert( p->nCutStore < p->nNumCuts );
316 return 1;
317}
318
330static inline Mpm_Cut_t * Mpm_ManMergeCuts( Mpm_Man_t * p, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCut2 )
331{
332 Mpm_Cut_t * pTemp, * pCut = &((Mpm_Uni_t *)Vec_PtrEntryLast(&p->vFreeUnits))->pCut;
333 int i, c, iPlace;
334 // base cut
335 memcpy( pCut->pLeaves, pCut0->pLeaves, sizeof(int) * pCut0->nLeaves );
336 pCut->nLeaves = pCut0->nLeaves;
337 // remaining cuts
338 if ( p->pPars->fUseDsd )
339 {
340 for ( c = 1; c < 3; c++ )
341 {
342 pTemp = (c == 1) ? pCut1 : pCut2;
343 if ( pTemp == NULL )
344 break;
345 p->uPermMask[c] = 0x3FFFF; // 18 bits
346 p->uComplMask[c] = 0;
347 for ( i = 0; i < (int)pTemp->nLeaves; i++ )
348 {
349 iPlace = Mpm_CutFindLeaf( pCut, Abc_Lit2Var(pTemp->pLeaves[i]) );
350 if ( iPlace == (int)pCut->nLeaves )
351 {
352 if ( (int)pCut->nLeaves == p->nLutSize )
353 return NULL;
354 pCut->pLeaves[pCut->nLeaves++] = pTemp->pLeaves[i];
355 }
356 p->uPermMask[c] ^= (((i & 7) ^ 7) << (3*iPlace));
357 if ( pTemp->pLeaves[i] != pCut->pLeaves[iPlace] )
358 p->uComplMask[c] |= (1 << iPlace);
359 }
360 }
361 }
362 else
363 {
364 for ( c = 1; c < 3; c++ )
365 {
366 pTemp = (c == 1) ? pCut1 : pCut2;
367 if ( pTemp == NULL )
368 break;
369 for ( i = 0; i < (int)pTemp->nLeaves; i++ )
370 {
371 iPlace = Mpm_CutFindLeaf( pCut, Abc_Lit2Var(pTemp->pLeaves[i]) );
372 if ( iPlace == (int)pCut->nLeaves )
373 {
374 if ( (int)pCut->nLeaves == p->nLutSize )
375 return NULL;
376 pCut->pLeaves[pCut->nLeaves++] = pTemp->pLeaves[i];
377 }
378 }
379 }
380 }
381 if ( pCut1 == NULL )
382 {
383 pCut->hNext = 0;
384 pCut->iFunc = pCut0->iFunc;
385 pCut->fUseless = pCut0->fUseless;
386 pCut->fCompl = pCut0->fCompl;
387 }
388 else
389 {
390 pCut->hNext = 0;
391 pCut->iFunc = 0; pCut->iFunc = ~pCut->iFunc;
392 pCut->fUseless = 0;
393 pCut->fCompl = 0;
394 }
395 p->nCutsMerged++;
396 p->nCutsMergedAll++;
397 if ( p->pPars->fUseTruth )
398 Vec_IntSelectSort( pCut->pLeaves, pCut->nLeaves );
399 return pCut;
400}
401static inline int Mpm_ManExploreNewCut( Mpm_Man_t * p, Mig_Obj_t * pObj, Mpm_Cut_t * pCut0, Mpm_Cut_t * pCut1, Mpm_Cut_t * pCut2, int Required )
402{
403 Mpm_Cut_t * pCut;
404 int ArrTime;
405#ifdef MIG_RUNTIME
406abctime clk = clock();
407#endif
408
409 if ( pCut0->nLeaves >= pCut1->nLeaves )
410 {
411 pCut = Mpm_ManMergeCuts( p, pCut0, pCut1, pCut2 );
412#ifdef MIG_RUNTIME
413p->timeMerge += clock() - clk;
414#endif
415 if ( pCut == NULL )
416 return 1;
417 if ( p->pPars->fUseTruth )
418 Mpm_CutComputeTruth( p, pCut, pCut0, pCut1, pCut2, Mig_ObjFaninC0(pObj), Mig_ObjFaninC1(pObj), Mig_ObjFaninC2(pObj), Mig_ObjNodeType(pObj) );
419 else if ( p->pPars->fUseDsd )
420 {
421 if ( !Mpm_CutComputeDsd6( p, pCut, pCut0, pCut1, pCut2, Mig_ObjFaninC0(pObj), Mig_ObjFaninC1(pObj), Mig_ObjFaninC2(pObj), Mig_ObjNodeType(pObj) ) )
422 return 1;
423 }
424 }
425 else
426 {
427 pCut = Mpm_ManMergeCuts( p, pCut1, pCut0, pCut2 );
428#ifdef MIG_RUNTIME
429p->timeMerge += clock() - clk;
430#endif
431 if ( pCut == NULL )
432 return 1;
433 if ( p->pPars->fUseTruth )
434 Mpm_CutComputeTruth( p, pCut, pCut1, pCut0, pCut2, Mig_ObjFaninC1(pObj), Mig_ObjFaninC0(pObj), 1 ^ Mig_ObjFaninC2(pObj), Mig_ObjNodeType(pObj) );
435 else if ( p->pPars->fUseDsd )
436 {
437 if ( !Mpm_CutComputeDsd6( p, pCut, pCut1, pCut0, pCut2, Mig_ObjFaninC1(pObj), Mig_ObjFaninC0(pObj), 1 ^ Mig_ObjFaninC2(pObj), Mig_ObjNodeType(pObj) ) )
438 return 1;
439 }
440 }
441
442#ifdef MIG_RUNTIME
443clk = clock();
444#endif
445 ArrTime = Mpm_CutGetArrTime( p, pCut );
446#ifdef MIG_RUNTIME
447p->timeEval += clock() - clk;
448#endif
449 if ( p->fMainRun && ArrTime > Required )
450 return 1;
451
452#ifdef MIG_RUNTIME
453clk = Abc_Clock();
454#endif
455 Mpm_ObjAddCutToStore( p, pCut, ArrTime );
456#ifdef MIG_RUNTIME
457p->timeStore += Abc_Clock() - clk;
458#endif
459
460/*
461 // return 0 if const or buffer cut is derived - reset all cuts to contain only one --- does not work
462// if ( pCut->nLeaves < 2 && p->nCutStore == 1 )
463// return 0;
464 if ( pCut->nLeaves < 2 )
465 {
466 int i;
467 assert( p->nCutStore >= 1 );
468 for ( i = 1; i < p->nCutStore; i++ )
469 Vec_PtrPush( &p->vFreeUnits, p->pCutStore[i] );
470 p->nCutStore = 1;
471 return 0;
472 }
473*/
474 return 1;
475}
476
477
489static inline void Mpm_ObjRecycleCuts( Mpm_Man_t * p, Mig_Obj_t * pObj )
490{
491 Mpm_Cut_t * pCut;
492 int hCut, hNext;
493 Mpm_ObjForEachCutSafe( p, pObj, hCut, pCut, hNext )
494 Mmr_StepRecycle( p->pManCuts, hCut );
495 Mpm_ObjSetCutList( p, pObj, 0 );
496}
497static inline void Mpm_ObjDerefFaninCuts( Mpm_Man_t * p, Mig_Obj_t * pObj )
498{
499 Mig_Obj_t * pFanin;
500 int i;
501 Mig_ObjForEachFanin( pObj, pFanin, i )
502 if ( Mig_ObjIsNode(pFanin) && Mig_ObjMigRefDec(p, pFanin) == 0 )
503 Mpm_ObjRecycleCuts( p, pFanin );
504 pFanin = Mig_ObjSibl(pObj);
505 if ( pFanin && Mig_ObjMigRefDec(p, pFanin) == 0 )
506 Mpm_ObjRecycleCuts( p, pFanin );
507 if ( Mig_ObjMigRefNum(p, pObj) == 0 )
508 Mpm_ObjRecycleCuts( p, pObj );
509}
510static inline void Mpm_ObjCollectFaninsAndSigns( Mpm_Man_t * p, Mig_Obj_t * pObj, int i )
511{
512 Mpm_Cut_t * pCut;
513 int hCut, nCuts = 0;
514 Mpm_ObjForEachCut( p, pObj, hCut, pCut )
515 {
516 p->pCuts[i][nCuts] = pCut;
517 p->pSigns[i][nCuts++] = Mpm_CutGetSign( pCut );
518 }
519 p->nCuts[i] = nCuts;
520}
521static inline void Mpm_ObjPrepareFanins( Mpm_Man_t * p, Mig_Obj_t * pObj )
522{
523 Mig_Obj_t * pFanin;
524 int i;
525 Mig_ObjForEachFanin( pObj, pFanin, i )
526 Mpm_ObjCollectFaninsAndSigns( p, pFanin, i );
527}
528// create storage from cuts at the node
529void Mpm_ObjAddChoiceCutsToStore( Mpm_Man_t * p, Mig_Obj_t * pRoot, Mig_Obj_t * pObj, int ReqTime )
530{
531 Mpm_Cut_t * pCut;
532 int hCut, hNext, ArrTime;
533 int fCompl = Mig_ObjPhase(pRoot) ^ Mig_ObjPhase(pObj);
534 Mpm_ObjForEachCutSafe( p, pObj, hCut, pCut, hNext )
535 {
536 if ( Abc_Lit2Var(pCut->pLeaves[0]) == Mig_ObjId(pObj) )
537 continue;
538 ArrTime = Mpm_CutGetArrTime( p, pCut );
539 if ( ArrTime > ReqTime )
540 continue;
541 pCut->fCompl ^= fCompl;
542 pCut = Mpm_ManMergeCuts( p, pCut, NULL, NULL );
543 Mpm_ObjAddCutToStore( p, pCut, ArrTime );
544 }
545}
546// create cuts at the node from storage
548{
549 Mpm_Cut_t * pCut = NULL;
550 Mpm_Uni_t * pUnit;
551 int i, *pList = Mpm_ObjCutListP( p, pObj );
552 assert( p->nCutStore > 0 && p->nCutStore <= p->nNumCuts );
553 assert( *pList == 0 );
554 // translate cuts
555 for ( i = 0; i < p->nCutStore; i++ )
556 {
557 pUnit = p->pCutStore[i];
558 *pList = Mpm_CutCreate( p, &pUnit->pCut, &pCut );
559 pList = &pCut->hNext;
560 Vec_PtrPush( &p->vFreeUnits, pUnit );
561 }
562 assert( Vec_PtrSize(&p->vFreeUnits) == p->nNumCuts + 1 );
563 if ( p->nCutStore == 1 && pCut->nLeaves < 2 )
564 *pList = 0;
565 else
566 *pList = Mpm_CutCreateUnit( p, Mig_ObjId(pObj) );
567}
568
581{
582 Mpm_Cut_t * pCut0, * pCut1, * pCut2;
583 int Required = Mpm_ObjRequired( p, pObj );
584 int hCutBest = Mpm_ObjCutBest( p, pObj );
585 int c0, c1, c2;
586#ifdef MIG_RUNTIME
587abctime clk;
588#endif
589
590 assert( Vec_PtrSize( &p->vFreeUnits ) == p->nNumCuts + 1 );
591 assert( Mpm_ObjCutList(p, pObj) == 0 );
592 p->nCutStore = 0;
593 if ( hCutBest > 0 ) // cut list is assigned
594 {
595 Mpm_Cut_t * pCut = Mpm_ObjCutBestP( p, pObj );
596 int Times = Mpm_CutGetArrTime( p, pCut );
597 assert( pCut->hNext == 0 );
598 if ( Times > Required )
599 printf( "Arrival time (%d) exceeds required time (%d) at object %d.\n", Times, Required, Mig_ObjId(pObj) );
600 if ( p->fMainRun )
601 Mpm_ObjAddCutToStore( p, Mpm_ManMergeCuts(p, pCut, NULL, NULL), Times );
602 else
603 Mpm_ObjSetTime( p, pObj, Times );
604 }
605 // start storage with choice cuts
606 if ( Mig_ManChoiceNum(p->pMig) && Mig_ObjSiblId(pObj) )
607 Mpm_ObjAddChoiceCutsToStore( p, pObj, Mig_ObjSibl(pObj), Required );
608
609#ifdef MIG_RUNTIME
610clk = Abc_Clock();
611#endif
612 Mpm_ObjPrepareFanins( p, pObj );
613 if ( Mig_ObjIsNode2(pObj) )
614 {
615 // go through cut pairs
616 for ( c0 = 0; c0 < p->nCuts[0] && (pCut0 = p->pCuts[0][c0]); c0++ )
617 for ( c1 = 0; c1 < p->nCuts[1] && (pCut1 = p->pCuts[1][c1]); c1++ )
618 if ( Abc_TtCountOnes(p->pSigns[0][c0] | p->pSigns[1][c1]) <= p->nLutSize )
619 if ( !Mpm_ManExploreNewCut( p, pObj, pCut0, pCut1, NULL, Required ) )
620 goto finish;
621 }
622 else if ( Mig_ObjIsNode3(pObj) )
623 {
624 // go through cut triples
625 for ( c0 = 0; c0 < p->nCuts[0] && (pCut0 = p->pCuts[0][c0]); c0++ )
626 for ( c1 = 0; c1 < p->nCuts[1] && (pCut1 = p->pCuts[1][c1]); c1++ )
627 for ( c2 = 0; c2 < p->nCuts[2] && (pCut2 = p->pCuts[2][c2]); c2++ )
628 if ( Abc_TtCountOnes(p->pSigns[0][c0] | p->pSigns[1][c1] | p->pSigns[2][c2]) <= p->nLutSize )
629 if ( !Mpm_ManExploreNewCut( p, pObj, pCut0, pCut1, pCut2, Required ) )
630 goto finish;
631 }
632 else assert( 0 );
633#ifdef MIG_RUNTIME
634p->timeDerive += Abc_Clock() - clk;
635#endif
636
637finish:
638 // save best cut
639 assert( p->nCutStore > 0 );
640 if ( p->pCutStore[0]->mTime <= Required )
641 {
642 Mpm_Cut_t * pCut;
643 if ( hCutBest )
644 Mmr_StepRecycle( p->pManCuts, hCutBest );
645 hCutBest = Mpm_CutCreate( p, &p->pCutStore[0]->pCut, &pCut );
646 Mpm_ObjSetCutBest( p, pObj, hCutBest );
647 Mpm_ObjSetTime( p, pObj, p->pCutStore[0]->mTime );
648 Mpm_ObjSetArea( p, pObj, p->pCutStore[0]->mArea );
649 Mpm_ObjSetEdge( p, pObj, p->pCutStore[0]->mEdge );
650 }
651 else assert( !p->fMainRun );
652 assert( hCutBest > 0 );
653 // transform internal storage into regular cuts
655 // dereference fanin cuts and reference node
656 Mpm_ObjDerefFaninCuts( p, pObj );
657 return 1;
658}
659
660
672static inline int Mpm_ManFindArrivalMax( Mpm_Man_t * p )
673{
674 int * pmTimes = Vec_IntArray( &p->vTimes );
675 Mig_Obj_t * pObj;
676 int i, ArrMax = 0;
677 Mig_ManForEachCo( p->pMig, pObj, i )
678 ArrMax = Abc_MaxInt( ArrMax, pmTimes[ Mig_ObjFaninId0(pObj) ] );
679 return ArrMax;
680}
681static inline void Mpm_ManFinalizeRound( Mpm_Man_t * p )
682{
683 int * pMapRefs = Vec_IntArray( &p->vMapRefs );
684 int * pRequired = Vec_IntArray( &p->vRequireds );
685 Mig_Obj_t * pObj;
686 Mpm_Cut_t * pCut;
687 int * pDelays;
688 int i, iLeaf;
689 p->GloArea = 0;
690 p->GloEdge = 0;
691 p->GloRequired = Mpm_ManFindArrivalMax(p);
692 if ( p->pPars->DelayTarget != -1 )
693 p->GloRequired = Abc_MaxInt( p->GloRequired, p->pPars->DelayTarget );
694 Mpm_ManCleanMapRefs( p );
695 Mpm_ManCleanRequired( p );
696 Mig_ManForEachObjReverse( p->pMig, pObj )
697 {
698 if ( Mig_ObjIsCo(pObj) )
699 {
700 pRequired[Mig_ObjFaninId0(pObj)] = p->GloRequired;
701 pMapRefs [Mig_ObjFaninId0(pObj)]++;
702 }
703 else if ( Mig_ObjIsNode(pObj) )
704 {
705 int Required = pRequired[Mig_ObjId(pObj)];
706 assert( Required > 0 );
707 if ( pMapRefs[Mig_ObjId(pObj)] > 0 )
708 {
709 pCut = Mpm_ObjCutBestP( p, pObj );
710 pDelays = p->pLibLut->pLutDelays[pCut->nLeaves];
711 Mpm_CutForEachLeafId( pCut, iLeaf, i )
712 {
713 pRequired[iLeaf] = Abc_MinInt( pRequired[iLeaf], Required - pDelays[i] );
714 pMapRefs [iLeaf]++;
715 }
716 p->GloArea += Mpm_CutGetArea( p, pCut );
717 p->GloEdge += pCut->nLeaves;
718 }
719 }
720 else if ( Mig_ObjIsBuf(pObj) )
721 {
722 }
723 }
724 p->GloArea /= MPM_UNIT_AREA;
725}
726static inline void Mpm_ManComputeEstRefs( Mpm_Man_t * p )
727{
728 int * pMapRefs = Vec_IntArray( &p->vMapRefs );
729 int * pEstRefs = Vec_IntArray( &p->vEstRefs );
730 int i;
731 assert( p->fMainRun );
732// pObj->EstRefs = (float)((2.0 * pObj->EstRefs + pObj->nRefs) / 3.0);
733 for ( i = 0; i < Mig_ManObjNum(p->pMig); i++ )
734 pEstRefs[i] = (1 * pEstRefs[i] + MPM_UNIT_REFS * pMapRefs[i]) / 2;
735}
736
749{
750 if ( pOld->mTime != pNew->mTime ) return pOld->mTime - pNew->mTime;
751 if ( pOld->pCut.nLeaves != pNew->pCut.nLeaves ) return pOld->pCut.nLeaves - pNew->pCut.nLeaves;
752 if ( pOld->mArea != pNew->mArea ) return pOld->mArea - pNew->mArea;
753 if ( pOld->mEdge != pNew->mEdge ) return pOld->mEdge - pNew->mEdge;
754 return 0;
755}
757{
758 if ( pOld->mTime != pNew->mTime ) return pOld->mTime - pNew->mTime;
759 if ( pOld->mArea != pNew->mArea ) return pOld->mArea - pNew->mArea;
760 if ( pOld->mEdge != pNew->mEdge ) return pOld->mEdge - pNew->mEdge;
761 if ( pOld->pCut.nLeaves != pNew->pCut.nLeaves ) return pOld->pCut.nLeaves - pNew->pCut.nLeaves;
762 return 0;
763}
765{
766 if ( pOld->mArea != pNew->mArea ) return pOld->mArea - pNew->mArea;
767 if ( pOld->pCut.nLeaves != pNew->pCut.nLeaves ) return pOld->pCut.nLeaves - pNew->pCut.nLeaves;
768 if ( pOld->mEdge != pNew->mEdge ) return pOld->mEdge - pNew->mEdge;
769 if ( pOld->mAveRefs != pNew->mAveRefs ) return pOld->mAveRefs - pNew->mAveRefs;
770 if ( pOld->mTime != pNew->mTime ) return pOld->mTime - pNew->mTime;
771 return 0;
772}
774{
775 if ( pOld->mArea != pNew->mArea ) return pOld->mArea - pNew->mArea;
776 if ( pOld->mEdge != pNew->mEdge ) return pOld->mEdge - pNew->mEdge;
777 if ( pOld->mAveRefs != pNew->mAveRefs ) return pOld->mAveRefs - pNew->mAveRefs;
778 if ( pOld->pCut.nLeaves != pNew->pCut.nLeaves ) return pOld->pCut.nLeaves - pNew->pCut.nLeaves;
779 if ( pOld->mTime != pNew->mTime ) return pOld->mTime - pNew->mTime;
780 return 0;
781}
782
795{
796 Mig_Obj_t * pObj;
797 int i, hCut;
798 Mig_ManForEachCi( p->pMig, pObj, i )
799 {
800 hCut = Mpm_CutCreateUnit( p, Mig_ObjId(pObj) );
801 Mpm_ObjSetCutBest( p, pObj, hCut );
802 Mpm_ObjSetCutList( p, pObj, hCut );
803 }
804 Mig_ManForEachCand( p->pMig, pObj )
805 Mpm_ObjSetEstRef( p, pObj, MPM_UNIT_REFS * Mig_ObjRefNum(pObj) );
806}
808{
809 Mig_Obj_t * pObj;
810 abctime clk = Abc_Clock();
811 int i;
812 // copy references
813 assert( Vec_IntSize(&p->vMigRefs) == Vec_IntSize(&p->pMig->vRefs) );
814 memcpy( Vec_IntArray(&p->vMigRefs), Vec_IntArray(&p->pMig->vRefs), sizeof(int) * Mig_ManObjNum(p->pMig) );
815 Mig_ManForEachCo( p->pMig, pObj, i )
816 Mig_ObjMigRefDec( p, Mig_ObjFanin0(pObj) );
817 // derive cuts
818 p->nCutsMerged = 0;
819 Mig_ManForEachNode( p->pMig, pObj )
820 Mpm_ManDeriveCuts( p, pObj );
821 assert( Mig_ManCandNum(p->pMig) == p->pManCuts->nEntries );
822 Mpm_ManFinalizeRound( p );
823 // report results
824 if ( p->pPars->fVerbose )
825 {
826 printf( "Del =%5d. Ar =%8d. Edge =%8d. Cut =%10d. Max =%8d. Tru =%8d. Small =%6d. ",
827 p->GloRequired, (int)p->GloArea, (int)p->GloEdge,
828 p->nCutsMerged, p->pManCuts->nEntriesMax,
829 p->vTtMem ? p->vTtMem->nEntries : 0, p->nSmallSupp );
830 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
831 }
832}
834{
835 if ( p->pPars->fMap4Cnf )
836 {
837 p->pCutCmp = Mpm_CutCompareArea;
839 }
840 else
841 {
842 p->pCutCmp = Mpm_CutCompareDelay;
844 if ( p->pPars->fOneRound )
845 return;
846
847 p->pCutCmp = Mpm_CutCompareDelay2;
849
850 p->pCutCmp = Mpm_CutCompareArea;
852
853 p->fMainRun = 1;
854
855 p->pCutCmp = Mpm_CutCompareArea;
856 Mpm_ManComputeEstRefs( p );
858
859 p->pCutCmp = Mpm_CutCompareArea2;
860 Mpm_ManComputeEstRefs( p );
862 }
863}
864
865
869
870
872
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
Cube * p
Definition exorList.c:222
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Mpm_CutComputeDsd6(Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
Definition mpmDsd.c:930
struct Mpm_Uni_t_ Mpm_Uni_t
Definition mpmInt.h:71
int Mpm_CutComputeTruth(Mpm_Man_t *p, Mpm_Cut_t *pCut, Mpm_Cut_t *pCut0, Mpm_Cut_t *pCut1, Mpm_Cut_t *pCutC, int fCompl0, int fCompl1, int fComplC, int Type)
Definition mpmTruth.c:215
struct Mpm_Man_t_ Mpm_Man_t
Definition mpmInt.h:94
#define MPM_UNIT_REFS
Definition mpmInt.h:55
#define Mpm_ObjForEachCutSafe(p, pObj, hCut, pCut, hNext)
Definition mpmInt.h:214
#define Mpm_CutForEachLeafId(pCut, iLeafId, i)
Definition mpmInt.h:218
struct Mpm_Cut_t_ Mpm_Cut_t
BASIC TYPES ///.
Definition mpmInt.h:61
#define MPM_UNIT_AREA
Definition mpmInt.h:53
#define MPM_UNIT_EDGE
Definition mpmInt.h:54
#define Mpm_ObjForEachCut(p, pObj, hCut, pCut)
Definition mpmInt.h:212
void Mpm_ObjAddChoiceCutsToStore(Mpm_Man_t *p, Mig_Obj_t *pRoot, Mig_Obj_t *pObj, int ReqTime)
Definition mpmMap.c:529
int Mpm_ObjAddCutToStore(Mpm_Man_t *p, Mpm_Cut_t *pCut, int ArrTime)
Definition mpmMap.c:225
void Mpm_ManPerformRound(Mpm_Man_t *p)
Definition mpmMap.c:807
int Mpm_CutCompareDelay2(Mpm_Uni_t *pOld, Mpm_Uni_t *pNew)
Definition mpmMap.c:756
int Mpm_ManDeriveCuts(Mpm_Man_t *p, Mig_Obj_t *pObj)
Definition mpmMap.c:580
void Mpm_ObjTranslateCutsFromStore(Mpm_Man_t *p, Mig_Obj_t *pObj)
Definition mpmMap.c:547
void Mpm_CutPrint(Mpm_Cut_t *pCut)
Definition mpmMap.c:103
int Mpm_CutCompareDelay(Mpm_Uni_t *pOld, Mpm_Uni_t *pNew)
Definition mpmMap.c:748
void Mpm_ManPerform(Mpm_Man_t *p)
Definition mpmMap.c:833
void Mpm_ManPrepare(Mpm_Man_t *p)
Definition mpmMap.c:794
int Mpm_CutCompareArea(Mpm_Uni_t *pOld, Mpm_Uni_t *pNew)
Definition mpmMap.c:764
int Mpm_CutCompareArea2(Mpm_Uni_t *pOld, Mpm_Uni_t *pNew)
Definition mpmMap.c:773
#define Mig_ManForEachObjReverse(p, pObj)
Definition mpmMig.h:312
struct Mig_Obj_t_ Mig_Obj_t
Definition mpmMig.h:54
#define Mig_ObjForEachFanin(p, pFanin, i)
Definition mpmMig.h:335
#define Mig_ManForEachNode(p, pObj)
Definition mpmMig.h:322
#define Mig_ManForEachCand(p, pObj)
Definition mpmMig.h:324
#define Mig_ManForEachCi(p, pObj, i)
Definition mpmMig.h:327
#define Mig_ManForEachCo(p, pObj, i)
Definition mpmMig.h:329
int hNext
Definition mpmInt.h:64
unsigned fCompl
Definition mpmInt.h:66
unsigned nLeaves
Definition mpmInt.h:68
unsigned fUseless
Definition mpmInt.h:67
int pLeaves[1]
Definition mpmInt.h:69
unsigned iFunc
Definition mpmInt.h:65
word uSign
Definition mpmInt.h:78
Mpm_Cut_t pCut
Definition mpmInt.h:80
int mTime
Definition mpmInt.h:74
int mEdge
Definition mpmInt.h:76
int mArea
Definition mpmInt.h:75
int mAveRefs
Definition mpmInt.h:77
int Cost
Definition mpmInt.h:79
#define assert(ex)
Definition util_old.h:213
char * memcpy()