ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifCut.c
Go to the documentation of this file.
1
20
21#include "if.h"
22
24
25
29
33
45static inline int If_CutVerifyCut( If_Cut_t * pBase, If_Cut_t * pCut ) // check if pCut is contained in pBase
46{
47 int nSizeB = pBase->nLeaves;
48 int nSizeC = pCut->nLeaves;
49 int * pB = pBase->pLeaves;
50 int * pC = pCut->pLeaves;
51 int i, k;
52 for ( i = 0; i < nSizeC; i++ )
53 {
54 for ( k = 0; k < nSizeB; k++ )
55 if ( pC[i] == pB[k] )
56 break;
57 if ( k == nSizeB )
58 return 0;
59 }
60 return 1;
61}
62int If_CutVerifyCuts( If_Set_t * pCutSet, int fOrdered )
63{
64 static int Count = 0;
65 If_Cut_t * pCut0, * pCut1;
66 int i, k, m, n, Value;
67 assert( pCutSet->nCuts > 0 );
68 for ( i = 0; i < pCutSet->nCuts; i++ )
69 {
70 pCut0 = pCutSet->ppCuts[i];
71 assert( pCut0->uSign == If_ObjCutSignCompute(pCut0) );
72 if ( fOrdered )
73 {
74 // check duplicates
75 for ( m = 1; m < (int)pCut0->nLeaves; m++ )
76 assert( pCut0->pLeaves[m-1] < pCut0->pLeaves[m] );
77 }
78 else
79 {
80 // check duplicates
81 for ( m = 0; m < (int)pCut0->nLeaves; m++ )
82 for ( n = m+1; n < (int)pCut0->nLeaves; n++ )
83 assert( pCut0->pLeaves[m] != pCut0->pLeaves[n] );
84 }
85 // check pairs
86 for ( k = 0; k < pCutSet->nCuts; k++ )
87 {
88 pCut1 = pCutSet->ppCuts[k];
89 if ( pCut0 == pCut1 )
90 continue;
91 Count++;
92 // check containments
93 Value = If_CutVerifyCut( pCut0, pCut1 );
94// assert( Value == 0 );
95 if ( Value )
96 {
97 assert( pCut0->uSign == If_ObjCutSignCompute(pCut0) );
98 assert( pCut1->uSign == If_ObjCutSignCompute(pCut1) );
99 If_CutPrint( pCut0 );
100 If_CutPrint( pCut1 );
101 assert( 0 );
102 }
103 }
104 }
105 return 1;
106}
107
119static inline int If_CutCheckDominance( If_Cut_t * pDom, If_Cut_t * pCut )
120{
121 int i, k;
122 assert( pDom->nLeaves <= pCut->nLeaves );
123 for ( i = 0; i < (int)pDom->nLeaves; i++ )
124 {
125 for ( k = 0; k < (int)pCut->nLeaves; k++ )
126 if ( pDom->pLeaves[i] == pCut->pLeaves[k] )
127 break;
128 if ( k == (int)pCut->nLeaves ) // node i in pDom is not contained in pCut
129 return 0;
130 }
131 // every node in pDom is contained in pCut
132 return 1;
133}
134
146int If_CutFilter( If_Set_t * pCutSet, If_Cut_t * pCut, int fSaveCut0 )
147{
148 If_Cut_t * pTemp;
149 int i, k;
150 assert( pCutSet->ppCuts[pCutSet->nCuts] == pCut );
151 for ( i = 0; i < pCutSet->nCuts; i++ )
152 {
153 pTemp = pCutSet->ppCuts[i];
154 if ( pTemp->nLeaves > pCut->nLeaves )
155 {
156 // do not fiter the first cut
157 if ( i == 0 && ((pCutSet->nCuts > 1 && pCutSet->ppCuts[1]->fUseless) || (fSaveCut0 && pCutSet->nCuts == 1)) )
158 continue;
159 // skip the non-contained cuts
160 if ( (pTemp->uSign & pCut->uSign) != pCut->uSign )
161 continue;
162 // check containment seriously
163 if ( If_CutCheckDominance( pCut, pTemp ) )
164 {
165// p->ppCuts[i] = p->ppCuts[p->nCuts-1];
166// p->ppCuts[p->nCuts-1] = pTemp;
167// p->nCuts--;
168// i--;
169 // remove contained cut
170 for ( k = i; k < pCutSet->nCuts; k++ )
171 pCutSet->ppCuts[k] = pCutSet->ppCuts[k+1];
172 pCutSet->ppCuts[pCutSet->nCuts] = pTemp;
173 pCutSet->nCuts--;
174 i--;
175 }
176 }
177 else
178 {
179 // skip the non-contained cuts
180 if ( (pTemp->uSign & pCut->uSign) != pTemp->uSign )
181 continue;
182 // check containment seriously
183 if ( If_CutCheckDominance( pTemp, pCut ) )
184 return 1;
185 }
186 }
187 return 0;
188}
189
202{
203 int nSizeC0 = pC0->nLeaves;
204 int nSizeC1 = pC1->nLeaves;
205 int nLimit = pC0->nLimit;
206 int i, k, c, s;
207
208 // both cuts are the largest
209 if ( nSizeC0 == nLimit && nSizeC1 == nLimit )
210 {
211 for ( i = 0; i < nSizeC0; i++ )
212 {
213 if ( pC0->pLeaves[i] != pC1->pLeaves[i] )
214 return 0;
215 p->pPerm[0][i] = p->pPerm[1][i] = p->pPerm[2][i] = i;
216 pC->pLeaves[i] = pC0->pLeaves[i];
217 }
218 pC->nLeaves = nLimit;
219 pC->uSign = pC0->uSign | pC1->uSign;
220 p->uSharedMask = Abc_InfoMask( nLimit );
221 return 1;
222 }
223
224 // compare two cuts with different numbers
225 i = k = c = s = 0;
226 p->uSharedMask = 0;
227 if ( nSizeC0 == 0 ) goto FlushCut1;
228 if ( nSizeC1 == 0 ) goto FlushCut0;
229 while ( 1 )
230 {
231 if ( c == nLimit ) return 0;
232 if ( pC0->pLeaves[i] < pC1->pLeaves[k] )
233 {
234 p->pPerm[0][i] = c;
235 pC->pLeaves[c++] = pC0->pLeaves[i++];
236 if ( i == nSizeC0 ) goto FlushCut1;
237 }
238 else if ( pC0->pLeaves[i] > pC1->pLeaves[k] )
239 {
240 p->pPerm[1][k] = c;
241 pC->pLeaves[c++] = pC1->pLeaves[k++];
242 if ( k == nSizeC1 ) goto FlushCut0;
243 }
244 else
245 {
246 p->uSharedMask |= (1 << c);
247 p->pPerm[0][i] = p->pPerm[1][k] = p->pPerm[2][s++] = c;
248 pC->pLeaves[c++] = pC0->pLeaves[i++]; k++;
249 if ( i == nSizeC0 ) goto FlushCut1;
250 if ( k == nSizeC1 ) goto FlushCut0;
251 }
252 }
253
254FlushCut0:
255 if ( c + nSizeC0 > nLimit + i ) return 0;
256 while ( i < nSizeC0 )
257 {
258 p->pPerm[0][i] = c;
259 pC->pLeaves[c++] = pC0->pLeaves[i++];
260 }
261 pC->nLeaves = c;
262 pC->uSign = pC0->uSign | pC1->uSign;
263 assert( c > 0 );
264 return 1;
265
266FlushCut1:
267 if ( c + nSizeC1 > nLimit + k ) return 0;
268 while ( k < nSizeC1 )
269 {
270 p->pPerm[1][k] = c;
271 pC->pLeaves[c++] = pC1->pLeaves[k++];
272 }
273 pC->nLeaves = c;
274 pC->uSign = pC0->uSign | pC1->uSign;
275 assert( c > 0 );
276 return 1;
277}
278
291{
292 int nSizeC0 = pC0->nLeaves;
293 int nSizeC1 = pC1->nLeaves;
294 int nLimit = pC0->nLimit;
295 int i, k, c, s;
296
297 // both cuts are the largest
298 if ( nSizeC0 == nLimit && nSizeC1 == nLimit )
299 {
300 for ( i = 0; i < nSizeC0; i++ )
301 {
302 if ( pC0->pLeaves[i] != pC1->pLeaves[i] )
303 return 0;
304 pC->pLeaves[i] = pC0->pLeaves[i];
305 }
306 pC->nLeaves = nLimit;
307 pC->uSign = pC0->uSign | pC1->uSign;
308 return 1;
309 }
310
311 // compare two cuts with different numbers
312 i = k = c = s = 0;
313 if ( nSizeC0 == 0 ) goto FlushCut1;
314 if ( nSizeC1 == 0 ) goto FlushCut0;
315 while ( 1 )
316 {
317 if ( c == nLimit ) return 0;
318 if ( pC0->pLeaves[i] < pC1->pLeaves[k] )
319 {
320 pC->pLeaves[c++] = pC0->pLeaves[i++];
321 if ( i == nSizeC0 ) goto FlushCut1;
322 }
323 else if ( pC0->pLeaves[i] > pC1->pLeaves[k] )
324 {
325 pC->pLeaves[c++] = pC1->pLeaves[k++];
326 if ( k == nSizeC1 ) goto FlushCut0;
327 }
328 else
329 {
330 pC->pLeaves[c++] = pC0->pLeaves[i++]; k++;
331 if ( i == nSizeC0 ) goto FlushCut1;
332 if ( k == nSizeC1 ) goto FlushCut0;
333 }
334 }
335
336FlushCut0:
337 if ( c + nSizeC0 > nLimit + i ) return 0;
338 while ( i < nSizeC0 )
339 pC->pLeaves[c++] = pC0->pLeaves[i++];
340 pC->nLeaves = c;
341 pC->uSign = pC0->uSign | pC1->uSign;
342 return 1;
343
344FlushCut1:
345 if ( c + nSizeC1 > nLimit + k ) return 0;
346 while ( k < nSizeC1 )
347 pC->pLeaves[c++] = pC1->pLeaves[k++];
348 pC->nLeaves = c;
349 pC->uSign = pC0->uSign | pC1->uSign;
350 return 1;
351}
352
364int If_CutMerge( If_Man_t * p, If_Cut_t * pCut0, If_Cut_t * pCut1, If_Cut_t * pCut )
365{
366 int nLutSize = pCut0->nLimit;
367 int nSize0 = pCut0->nLeaves;
368 int nSize1 = pCut1->nLeaves;
369 int * pC0 = pCut0->pLeaves;
370 int * pC1 = pCut1->pLeaves;
371 int * pC = pCut->pLeaves;
372 int i, k, c;
373 // compare two cuts with different numbers
374 c = nSize0;
375 for ( i = 0; i < nSize1; i++ )
376 {
377 for ( k = 0; k < nSize0; k++ )
378 if ( pC1[i] == pC0[k] )
379 break;
380 if ( k < nSize0 )
381 {
382 p->pPerm[1][i] = k;
383 continue;
384 }
385 if ( c == nLutSize )
386 return 0;
387 p->pPerm[1][i] = c;
388 pC[c++] = pC1[i];
389 }
390 for ( i = 0; i < nSize0; i++ )
391 pC[i] = pC0[i];
392 pCut->nLeaves = c;
393 pCut->uSign = pCut0->uSign | pCut1->uSign;
394 return 1;
395}
396
409{
410 If_Cut_t * pC0 = *ppC0;
411 If_Cut_t * pC1 = *ppC1;
412 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
413 return -1;
414 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
415 return 1;
416 if ( pC0->nLeaves < pC1->nLeaves )
417 return -1;
418 if ( pC0->nLeaves > pC1->nLeaves )
419 return 1;
420 if ( pC0->Area < pC1->Area - p->fEpsilon )
421 return -1;
422 if ( pC0->Area > pC1->Area + p->fEpsilon )
423 return 1;
424 return 0;
425}
426
439{
440 If_Cut_t * pC0 = *ppC0;
441 If_Cut_t * pC1 = *ppC1;
442 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
443 return -1;
444 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
445 return 1;
446 if ( pC0->Area < pC1->Area - p->fEpsilon )
447 return -1;
448 if ( pC0->Area > pC1->Area + p->fEpsilon )
449 return 1;
450 if ( pC0->nLeaves < pC1->nLeaves )
451 return -1;
452 if ( pC0->nLeaves > pC1->nLeaves )
453 return 1;
454 return 0;
455}
456
469{
470 If_Cut_t * pC0 = *ppC0;
471 If_Cut_t * pC1 = *ppC1;
472 if ( pC0->Area < pC1->Area - p->fEpsilon )
473 return -1;
474 if ( pC0->Area > pC1->Area + p->fEpsilon )
475 return 1;
476// if ( pC0->AveRefs > pC1->AveRefs )
477// return -1;
478// if ( pC0->AveRefs < pC1->AveRefs )
479// return 1;
480 if ( pC0->nLeaves < pC1->nLeaves )
481 return -1;
482 if ( pC0->nLeaves > pC1->nLeaves )
483 return 1;
484 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
485 return -1;
486 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
487 return 1;
488 return 0;
489}
490
502static inline int If_ManSortCompare( If_Man_t * p, If_Cut_t * pC0, If_Cut_t * pC1 )
503{
504 if ( p->pPars->fPower )
505 {
506 if ( p->SortMode == 1 ) // area flow
507 {
508 if ( pC0->Area < pC1->Area - p->fEpsilon )
509 return -1;
510 if ( pC0->Area > pC1->Area + p->fEpsilon )
511 return 1;
512 //Abc_Print( 1,"area(%.2f, %.2f), power(%.2f, %.2f), edge(%.2f, %.2f)\n",
513 // pC0->Area, pC1->Area, pC0->Power, pC1->Power, pC0->Edge, pC1->Edge);
514 if ( pC0->Power < pC1->Power - p->fEpsilon )
515 return -1;
516 if ( pC0->Power > pC1->Power + p->fEpsilon )
517 return 1;
518 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
519 return -1;
520 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
521 return 1;
522// if ( pC0->AveRefs > pC1->AveRefs )
523// return -1;
524// if ( pC0->AveRefs < pC1->AveRefs )
525// return 1;
526 if ( pC0->nLeaves < pC1->nLeaves )
527 return -1;
528 if ( pC0->nLeaves > pC1->nLeaves )
529 return 1;
530 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
531 return -1;
532 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
533 return 1;
534 return 0;
535 }
536 if ( p->SortMode == 0 ) // delay
537 {
538 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
539 return -1;
540 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
541 return 1;
542 if ( pC0->nLeaves < pC1->nLeaves )
543 return -1;
544 if ( pC0->nLeaves > pC1->nLeaves )
545 return 1;
546 if ( pC0->Area < pC1->Area - p->fEpsilon )
547 return -1;
548 if ( pC0->Area > pC1->Area + p->fEpsilon )
549 return 1;
550 if ( pC0->Power < pC1->Power - p->fEpsilon )
551 return -1;
552 if ( pC0->Power > pC1->Power + p->fEpsilon )
553 return 1;
554 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
555 return -1;
556 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
557 return 1;
558 return 0;
559 }
560 assert( p->SortMode == 2 ); // delay old, exact area
561 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
562 return -1;
563 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
564 return 1;
565 if ( pC0->Power < pC1->Power - p->fEpsilon )
566 return -1;
567 if ( pC0->Power > pC1->Power + p->fEpsilon )
568 return 1;
569 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
570 return -1;
571 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
572 return 1;
573 if ( pC0->Area < pC1->Area - p->fEpsilon )
574 return -1;
575 if ( pC0->Area > pC1->Area + p->fEpsilon )
576 return 1;
577 if ( pC0->nLeaves < pC1->nLeaves )
578 return -1;
579 if ( pC0->nLeaves > pC1->nLeaves )
580 return 1;
581 return 0;
582 }
583 else // regular
584 {
585 if ( p->SortMode == 1 ) // area
586 {
587 if ( pC0->Area < pC1->Area - p->fEpsilon )
588 return -1;
589 if ( pC0->Area > pC1->Area + p->fEpsilon )
590 return 1;
591 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
592 return -1;
593 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
594 return 1;
595 if ( pC0->Power < pC1->Power - p->fEpsilon )
596 return -1;
597 if ( pC0->Power > pC1->Power + p->fEpsilon )
598 return 1;
599// if ( pC0->AveRefs > pC1->AveRefs )
600// return -1;
601// if ( pC0->AveRefs < pC1->AveRefs )
602// return 1;
603 if ( pC0->nLeaves < pC1->nLeaves )
604 return -1;
605 if ( pC0->nLeaves > pC1->nLeaves )
606 return 1;
607 if ( pC0->fUseless < pC1->fUseless )
608 return -1;
609 if ( pC0->fUseless > pC1->fUseless )
610 return 1;
611 return 0;
612 }
613 if ( p->SortMode == 0 ) // delay
614 {
615 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
616 return -1;
617 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
618 return 1;
619 if ( pC0->nLeaves < pC1->nLeaves )
620 return -1;
621 if ( pC0->nLeaves > pC1->nLeaves )
622 return 1;
623 if ( pC0->Area < pC1->Area - p->fEpsilon )
624 return -1;
625 if ( pC0->Area > pC1->Area + p->fEpsilon )
626 return 1;
627 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
628 return -1;
629 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
630 return 1;
631 if ( pC0->Power < pC1->Power - p->fEpsilon )
632 return -1;
633 if ( pC0->Power > pC1->Power + p->fEpsilon )
634 return 1;
635 if ( pC0->fUseless < pC1->fUseless )
636 return -1;
637 if ( pC0->fUseless > pC1->fUseless )
638 return 1;
639 return 0;
640 }
641 assert( p->SortMode == 2 ); // delay old
642 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
643 return -1;
644 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
645 return 1;
646 if ( pC0->fUseless < pC1->fUseless )
647 return -1;
648 if ( pC0->fUseless > pC1->fUseless )
649 return 1;
650 if ( pC0->Area < pC1->Area - p->fEpsilon )
651 return -1;
652 if ( pC0->Area > pC1->Area + p->fEpsilon )
653 return 1;
654 if ( pC0->Edge < pC1->Edge - p->fEpsilon )
655 return -1;
656 if ( pC0->Edge > pC1->Edge + p->fEpsilon )
657 return 1;
658 if ( pC0->Power < pC1->Power - p->fEpsilon )
659 return -1;
660 if ( pC0->Power > pC1->Power + p->fEpsilon )
661 return 1;
662 if ( pC0->nLeaves < pC1->nLeaves )
663 return -1;
664 if ( pC0->nLeaves > pC1->nLeaves )
665 return 1;
666 return 0;
667 }
668}
669
681static inline int If_ManSortCompare_old( If_Man_t * p, If_Cut_t * pC0, If_Cut_t * pC1 )
682{
683 if ( p->SortMode == 1 ) // area
684 {
685 if ( pC0->Area < pC1->Area - p->fEpsilon )
686 return -1;
687 if ( pC0->Area > pC1->Area + p->fEpsilon )
688 return 1;
689// if ( pC0->AveRefs > pC1->AveRefs )
690// return -1;
691// if ( pC0->AveRefs < pC1->AveRefs )
692// return 1;
693 if ( pC0->nLeaves < pC1->nLeaves )
694 return -1;
695 if ( pC0->nLeaves > pC1->nLeaves )
696 return 1;
697 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
698 return -1;
699 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
700 return 1;
701 return 0;
702 }
703 if ( p->SortMode == 0 ) // delay
704 {
705 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
706 return -1;
707 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
708 return 1;
709 if ( pC0->nLeaves < pC1->nLeaves )
710 return -1;
711 if ( pC0->nLeaves > pC1->nLeaves )
712 return 1;
713 if ( pC0->Area < pC1->Area - p->fEpsilon )
714 return -1;
715 if ( pC0->Area > pC1->Area + p->fEpsilon )
716 return 1;
717 return 0;
718 }
719 assert( p->SortMode == 2 ); // delay old
720 if ( pC0->Delay < pC1->Delay - p->fEpsilon )
721 return -1;
722 if ( pC0->Delay > pC1->Delay + p->fEpsilon )
723 return 1;
724 if ( pC0->Area < pC1->Area - p->fEpsilon )
725 return -1;
726 if ( pC0->Area > pC1->Area + p->fEpsilon )
727 return 1;
728 if ( pC0->nLeaves < pC1->nLeaves )
729 return -1;
730 if ( pC0->nLeaves > pC1->nLeaves )
731 return 1;
732 return 0;
733}
734
746void If_CutSort( If_Man_t * p, If_Set_t * pCutSet, If_Cut_t * pCut )
747{
748// int Counter = 0;
749 int i;
750
751 // the new cut is the last one
752 assert( pCutSet->ppCuts[pCutSet->nCuts] == pCut );
753 assert( pCutSet->nCuts <= pCutSet->nCutsMax );
754
755 // cut structure is empty
756 if ( pCutSet->nCuts == 0 )
757 {
758 pCutSet->nCuts++;
759 return;
760 }
761
762 if ( !pCut->fUseless &&
763 (p->pPars->fUseDsd || p->pPars->pFuncCell2 || p->pPars->fUseBat ||
764 p->pPars->pLutStruct || p->pPars->fUserRecLib || p->pPars->fUserSesLib || p->pPars->fUserLutDec || p->pPars->fUserLut2D ||
765 p->pPars->fEnableCheck07 || p->pPars->fUseCofVars || p->pPars->fUseAndVars || p->pPars->fUse34Spec ||
766 p->pPars->fUseDsdTune || p->pPars->fEnableCheck75 || p->pPars->fEnableCheck75u || p->pPars->fUseCheck1 || p->pPars->fUseCheck2) )
767 {
768 If_Cut_t * pFirst = pCutSet->ppCuts[0];
769 if ( pFirst->fUseless || If_ManSortCompare(p, pFirst, pCut) == 1 )
770 {
771 pCutSet->ppCuts[0] = pCut;
772 pCutSet->ppCuts[pCutSet->nCuts] = pFirst;
773 If_CutSort( p, pCutSet, pFirst );
774 return;
775 }
776 }
777
778 // the cut will be added - find its place
779 for ( i = pCutSet->nCuts-1; i >= 0; i-- )
780 {
781// Counter++;
782 if ( If_ManSortCompare( p, pCutSet->ppCuts[i], pCut ) <= 0 || (i == 0 && !pCutSet->ppCuts[0]->fUseless && pCut->fUseless) )
783 break;
784 pCutSet->ppCuts[i+1] = pCutSet->ppCuts[i];
785 pCutSet->ppCuts[i] = pCut;
786 }
787// Abc_Print( 1, "%d ", Counter );
788
789 // update the number of cuts
790 if ( pCutSet->nCuts < pCutSet->nCutsMax )
791 pCutSet->nCuts++;
792}
793
805void If_CutOrder( If_Cut_t * pCut )
806{
807 int i, Temp, fChanges;
808 do {
809 fChanges = 0;
810 for ( i = 0; i < (int)pCut->nLeaves - 1; i++ )
811 {
812 assert( pCut->pLeaves[i] != pCut->pLeaves[i+1] );
813 if ( pCut->pLeaves[i] <= pCut->pLeaves[i+1] )
814 continue;
815 Temp = pCut->pLeaves[i];
816 pCut->pLeaves[i] = pCut->pLeaves[i+1];
817 pCut->pLeaves[i+1] = Temp;
818 fChanges = 1;
819 }
820 } while ( fChanges );
821}
822
835{
836 int i;
837 assert( pCut->nLeaves <= pCut->nLimit );
838 if ( pCut->nLeaves < 2 )
839 return 1;
840 for ( i = 1; i < (int)pCut->nLeaves; i++ )
841 {
842 if ( pCut->pLeaves[i-1] >= pCut->pLeaves[i] )
843 {
844 Abc_Print( -1, "If_CutCheck(): Cut has wrong ordering of inputs.\n" );
845 return 0;
846 }
847 assert( pCut->pLeaves[i-1] < pCut->pLeaves[i] );
848 }
849 return 1;
850}
851
852
864void If_CutPrint( If_Cut_t * pCut )
865{
866 unsigned i;
867 Abc_Print( 1, "{" );
868 for ( i = 0; i < pCut->nLeaves; i++ )
869 Abc_Print( 1, " %s%d", If_CutLeafBit(pCut, i) ? "!":"", pCut->pLeaves[i] );
870 Abc_Print( 1, " }\n" );
871}
872
885{
886 If_Obj_t * pLeaf;
887 unsigned i;
888 Abc_Print( 1, "{" );
889 If_CutForEachLeaf( p, pCut, pLeaf, i )
890 Abc_Print( 1, " %d(%.2f/%.2f)", pLeaf->Id, If_ObjCutBest(pLeaf)->Delay, pLeaf->Required );
891 Abc_Print( 1, " }\n" );
892}
893
905void If_CutLift( If_Cut_t * pCut )
906{
907 unsigned i;
908 for ( i = 0; i < pCut->nLeaves; i++ )
909 {
910 assert( (pCut->pLeaves[i] & 255) < 255 );
911 pCut->pLeaves[i]++;
912 }
913}
914
915
928{
929 If_Obj_t * pLeaf;
930 float Flow, AddOn;
931 int i;
932 Flow = If_CutLutArea(p, pCut);
933 If_CutForEachLeaf( p, pCut, pLeaf, i )
934 {
935 if ( pLeaf->nRefs == 0 || If_ObjIsConst1(pLeaf) )
936 AddOn = If_ObjCutBest(pLeaf)->Area;
937 else
938 {
939 assert( pLeaf->EstRefs > p->fEpsilon );
940 AddOn = If_ObjCutBest(pLeaf)->Area / pLeaf->EstRefs;
941 }
942 if ( Flow >= (float)1e32 || AddOn >= (float)1e32 )
943 Flow = (float)1e32;
944 else
945 {
946 Flow += AddOn;
947 if ( Flow > (float)1e32 )
948 Flow = (float)1e32;
949 }
950 }
951 return Flow;
952}
953
966{
967 If_Obj_t * pLeaf;
968 float Flow, AddOn;
969 int i;
970 Flow = pCut->nLeaves;
971 If_CutForEachLeaf( p, pCut, pLeaf, i )
972 {
973 if ( pLeaf->nRefs == 0 || If_ObjIsConst1(pLeaf) )
974 AddOn = If_ObjCutBest(pLeaf)->Edge;
975 else
976 {
977 assert( pLeaf->EstRefs > p->fEpsilon );
978 AddOn = If_ObjCutBest(pLeaf)->Edge / pLeaf->EstRefs;
979 }
980 if ( Flow >= (float)1e32 || AddOn >= (float)1e32 )
981 Flow = (float)1e32;
982 else
983 {
984 Flow += AddOn;
985 if ( Flow > (float)1e32 )
986 Flow = (float)1e32;
987 }
988 }
989 return Flow;
990}
991
1003float If_CutPowerFlow( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pRoot )
1004{
1005 If_Obj_t * pLeaf;
1006 float * pSwitching = (float *)p->vSwitching->pArray;
1007 float Power = 0;
1008 int i;
1009 If_CutForEachLeaf( p, pCut, pLeaf, i )
1010 {
1011 Power += pSwitching[pLeaf->Id];
1012 if ( pLeaf->nRefs == 0 || If_ObjIsConst1(pLeaf) )
1013 Power += If_ObjCutBest(pLeaf)->Power;
1014 else
1015 {
1016 assert( pLeaf->EstRefs > p->fEpsilon );
1017 Power += If_ObjCutBest(pLeaf)->Power / pLeaf->EstRefs;
1018 }
1019 }
1020 return Power;
1021}
1022
1035{
1036 If_Obj_t * pLeaf;
1037 int nRefsTotal, i;
1038 nRefsTotal = 0;
1039 If_CutForEachLeaf( p, pCut, pLeaf, i )
1040 nRefsTotal += pLeaf->nRefs;
1041 return ((float)nRefsTotal)/pCut->nLeaves;
1042}
1043
1044
1057{
1058 If_Obj_t * pLeaf;
1059 float Area;
1060 int i;
1061 Area = If_CutLutArea(p, pCut);
1062 If_CutForEachLeaf( p, pCut, pLeaf, i )
1063 {
1064 assert( pLeaf->nRefs > 0 );
1065 if ( --pLeaf->nRefs > 0 || !If_ObjIsAnd(pLeaf) )
1066 continue;
1067 Area += If_CutAreaDeref( p, If_ObjCutBest(pLeaf) );
1068 }
1069 return Area;
1070}
1071
1084{
1085 If_Obj_t * pLeaf;
1086 float Area;
1087 int i;
1088 Area = If_CutLutArea(p, pCut);
1089 If_CutForEachLeaf( p, pCut, pLeaf, i )
1090 {
1091 assert( pLeaf->nRefs >= 0 );
1092 if ( pLeaf->nRefs++ > 0 || !If_ObjIsAnd(pLeaf) )
1093 continue;
1094 Area += If_CutAreaRef( p, If_ObjCutBest(pLeaf) );
1095 }
1096 return Area;
1097}
1098
1111{
1112 float aResult, aResult2;
1113 if ( pCut->nLeaves < 2 )
1114 return 0;
1115 aResult2 = If_CutAreaRef( p, pCut );
1116 aResult = If_CutAreaDeref( p, pCut );
1117 assert( aResult > aResult2 - 3*p->fEpsilon );
1118 assert( aResult < aResult2 + 3*p->fEpsilon );
1119 return aResult;
1120}
1121
1134{
1135 float aResult, aResult2;
1136 if ( pCut->nLeaves < 2 )
1137 return 0;
1138 aResult2 = If_CutAreaDeref( p, pCut );
1139 aResult = If_CutAreaRef( p, pCut );
1140// assert( aResult > aResult2 - p->fEpsilon );
1141// assert( aResult < aResult2 + p->fEpsilon );
1142 return aResult;
1143}
1144
1145
1158{
1159 If_Obj_t * pLeaf;
1160 float Edge;
1161 int i;
1162 Edge = pCut->nLeaves;
1163 If_CutForEachLeaf( p, pCut, pLeaf, i )
1164 {
1165 assert( pLeaf->nRefs > 0 );
1166 if ( --pLeaf->nRefs > 0 || !If_ObjIsAnd(pLeaf) )
1167 continue;
1168 Edge += If_CutEdgeDeref( p, If_ObjCutBest(pLeaf) );
1169 }
1170 return Edge;
1171}
1172
1185{
1186 If_Obj_t * pLeaf;
1187 float Edge;
1188 int i;
1189 Edge = pCut->nLeaves;
1190 If_CutForEachLeaf( p, pCut, pLeaf, i )
1191 {
1192 assert( pLeaf->nRefs >= 0 );
1193 if ( pLeaf->nRefs++ > 0 || !If_ObjIsAnd(pLeaf) )
1194 continue;
1195 Edge += If_CutEdgeRef( p, If_ObjCutBest(pLeaf) );
1196 }
1197 return Edge;
1198}
1199
1212{
1213 float aResult, aResult2;
1214 if ( pCut->nLeaves < 2 )
1215 return pCut->nLeaves;
1216 aResult2 = If_CutEdgeRef( p, pCut );
1217 aResult = If_CutEdgeDeref( p, pCut );
1218// assert( aResult > aResult2 - 3*p->fEpsilon );
1219// assert( aResult < aResult2 + 3*p->fEpsilon );
1220 return aResult;
1221}
1222
1235{
1236 float aResult, aResult2;
1237 if ( pCut->nLeaves < 2 )
1238 return pCut->nLeaves;
1239 aResult2 = If_CutEdgeDeref( p, pCut );
1240 aResult = If_CutEdgeRef( p, pCut );
1241// assert( aResult > aResult2 - p->fEpsilon );
1242// assert( aResult < aResult2 + p->fEpsilon );
1243 return aResult;
1244}
1245
1246
1258float If_CutPowerDeref( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pRoot )
1259{
1260 If_Obj_t * pLeaf;
1261 float * pSwitching = (float *)p->vSwitching->pArray;
1262 float Power = 0;
1263 int i;
1264 If_CutForEachLeaf( p, pCut, pLeaf, i )
1265 {
1266 Power += pSwitching[pLeaf->Id];
1267 assert( pLeaf->nRefs > 0 );
1268 if ( --pLeaf->nRefs > 0 || !If_ObjIsAnd(pLeaf) )
1269 continue;
1270 Power += If_CutPowerDeref( p, If_ObjCutBest(pLeaf), pRoot );
1271 }
1272 return Power;
1273}
1274
1286float If_CutPowerRef( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pRoot )
1287{
1288 If_Obj_t * pLeaf;
1289 float * pSwitching = (float *)p->vSwitching->pArray;
1290 float Power = 0;
1291 int i;
1292 If_CutForEachLeaf( p, pCut, pLeaf, i )
1293 {
1294 Power += pSwitching[pLeaf->Id];
1295 assert( pLeaf->nRefs >= 0 );
1296 if ( pLeaf->nRefs++ > 0 || !If_ObjIsAnd(pLeaf) )
1297 continue;
1298 Power += If_CutPowerRef( p, If_ObjCutBest(pLeaf), pRoot );
1299 }
1300 return Power;
1301}
1302
1314float If_CutPowerDerefed( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pRoot )
1315{
1316 float aResult, aResult2;
1317 if ( pCut->nLeaves < 2 )
1318 return 0;
1319 aResult2 = If_CutPowerRef( p, pCut, pRoot );
1320 aResult = If_CutPowerDeref( p, pCut, pRoot );
1321 assert( aResult > aResult2 - p->fEpsilon );
1322 assert( aResult < aResult2 + p->fEpsilon );
1323 return aResult;
1324}
1325
1337float If_CutPowerRefed( If_Man_t * p, If_Cut_t * pCut, If_Obj_t * pRoot )
1338{
1339 float aResult, aResult2;
1340 if ( pCut->nLeaves < 2 )
1341 return 0;
1342 aResult2 = If_CutPowerDeref( p, pCut, pRoot );
1343 aResult = If_CutPowerRef( p, pCut, pRoot );
1344 assert( aResult > aResult2 - p->fEpsilon );
1345 assert( aResult < aResult2 + p->fEpsilon );
1346 return aResult;
1347}
1348
1361{
1362 If_Obj_t * pLeaf;
1363 int i, nMinLevel = IF_INFINITY;
1364 If_CutForEachLeaf( p, pCut, pLeaf, i )
1365 nMinLevel = IF_MIN( nMinLevel, (int)pLeaf->Level );
1366 return nMinLevel;
1367}
1368
1381{
1382 If_Obj_t * pTemp;
1383 int i, RetValue;
1384 // check if the node is in the cut
1385 for ( i = 0; i < (int)pCut->nLeaves; i++ )
1386 if ( pCut->pLeaves[i] == pObj->Id )
1387 return 1;
1388 else if ( pCut->pLeaves[i] > pObj->Id )
1389 break;
1390 // return if we reached the boundary
1391 if ( If_ObjIsCi(pObj) )
1392 return 0;
1393 // check the choice node
1394 for ( pTemp = pObj; pTemp; pTemp = pTemp->pEquiv )
1395 {
1396 // check if the node itself is bound
1397 RetValue = If_CutGetCone_rec( p, If_ObjFanin0(pTemp), pCut );
1398 if ( RetValue )
1399 RetValue &= If_CutGetCone_rec( p, If_ObjFanin1(pTemp), pCut );
1400 if ( RetValue )
1401 return 1;
1402 }
1403 return 0;
1404}
1405
1418{
1419 If_Obj_t * pObj;
1420 int i, Counter = 0;
1421 abctime clk = Abc_Clock();
1422 If_ManForEachObj( p, pObj, i )
1423 {
1424 if ( If_ObjIsAnd(pObj) && pObj->nRefs )
1425 {
1426 Counter += !If_CutGetCone_rec( p, pObj, If_ObjCutBest(pObj) );
1427// Abc_Print( 1, "%d ", If_CutGetCutMinLevel( p, If_ObjCutBest(pObj) ) );
1428 }
1429 }
1430 Abc_Print( 1, "Cound not find boundary for %d nodes.\n", Counter );
1431 Abc_PrintTime( 1, "Cones", Abc_Clock() - clk );
1432 return 1;
1433}
1434
1435
1448{
1449 if ( pObj->nRefs || If_ObjIsCi(pObj) )
1450 {
1451 Vec_IntPushUnique( vLeaves, pObj->Id );
1452 return;
1453 }
1454 If_CutFoundFanins_rec( If_ObjFanin0(pObj), vLeaves );
1455 If_CutFoundFanins_rec( If_ObjFanin1(pObj), vLeaves );
1456}
1457
1470{
1471 If_Obj_t * pObj;
1472 Vec_Int_t * vLeaves;
1473 int i, nFaninsTotal = 0, Counter = 0;
1474 abctime clk = Abc_Clock();
1475 vLeaves = Vec_IntAlloc( 100 );
1476 If_ManForEachObj( p, pObj, i )
1477 {
1478 if ( If_ObjIsAnd(pObj) && pObj->nRefs )
1479 {
1480 nFaninsTotal += If_ObjCutBest(pObj)->nLeaves;
1481 Vec_IntClear( vLeaves );
1482 If_CutFoundFanins_rec( If_ObjFanin0(pObj), vLeaves );
1483 If_CutFoundFanins_rec( If_ObjFanin1(pObj), vLeaves );
1484 Counter += Vec_IntSize(vLeaves);
1485 }
1486 }
1487 Abc_Print( 1, "Total cut inputs = %d. Total fanins incremental = %d.\n", nFaninsTotal, Counter );
1488 Abc_PrintTime( 1, "Fanins", Abc_Clock() - clk );
1489 Vec_IntFree( vLeaves );
1490 return 1;
1491}
1492
1504int If_CutFilter2_rec( If_Man_t * p, If_Obj_t * pObj, int LevelMin )
1505{
1506 char * pVisited = Vec_StrEntryP(p->vMarks, pObj->Id);
1507 if ( *pVisited )
1508 return *pVisited;
1509 Vec_IntPush( p->vVisited2, pObj->Id );
1510 if ( (int)pObj->Level <= LevelMin )
1511 return (*pVisited = 1);
1512 if ( If_CutFilter2_rec( p, pObj->pFanin0, LevelMin ) == 1 )
1513 return (*pVisited = 1);
1514 if ( If_CutFilter2_rec( p, pObj->pFanin1, LevelMin ) == 1 )
1515 return (*pVisited = 1);
1516 return (*pVisited = 2);
1517}
1518int If_CutFilter2( If_Man_t * p, If_Obj_t * pNode, If_Cut_t * pCut )
1519{
1520 If_Obj_t * pLeaf, * pTemp; int i, Count = 0;
1521// printf( "Considering node %d and cut {", pNode->Id );
1522// If_CutForEachLeaf( p, pCut, pLeaf, i )
1523// printf( " %d", pLeaf->Id );
1524// printf( " }\n" );
1525 If_CutForEachLeaf( p, pCut, pLeaf, i )
1526 {
1527 int k, iObj, RetValue, nLevelMin = ABC_INFINITY;
1528 Vec_IntClear( p->vVisited2 );
1529 If_CutForEachLeaf( p, pCut, pTemp, k )
1530 {
1531 if ( pTemp == pLeaf )
1532 continue;
1533 nLevelMin = Abc_MinInt( nLevelMin, (int)pTemp->Level );
1534 assert( Vec_StrEntry(p->vMarks, pTemp->Id) == 0 );
1535 Vec_StrWriteEntry( p->vMarks, pTemp->Id, 2 );
1536 Vec_IntPush( p->vVisited2, pTemp->Id );
1537 }
1538 RetValue = If_CutFilter2_rec( p, pLeaf, nLevelMin );
1539 Vec_IntForEachEntry( p->vVisited2, iObj, k )
1540 Vec_StrWriteEntry( p->vMarks, iObj, 0 );
1541 if ( RetValue == 2 )
1542 {
1543 Count++;
1544 pCut->nLeaves--;
1545 for ( k = i; k < (int)pCut->nLeaves; k++ )
1546 pCut->pLeaves[k] = pCut->pLeaves[k+1];
1547 i--;
1548 }
1549 }
1550 //if ( Count )
1551 // printf( "%d", Count );
1552 return 0;
1553}
1554
1558
1559
1561
ABC_INT64_T abctime
Definition abc_global.h:332
#define ABC_INFINITY
MACRO DEFINITIONS ///.
Definition abc_global.h:250
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Cube ** ppC1
Definition exorList.c:1013
int If_CutMerge(If_Man_t *p, If_Cut_t *pCut0, If_Cut_t *pCut1, If_Cut_t *pCut)
Definition ifCut.c:364
void If_CutFoundFanins_rec(If_Obj_t *pObj, Vec_Int_t *vLeaves)
Definition ifCut.c:1447
float If_CutEdgeRefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1234
int If_CutCompareDelayOld(If_Man_t *p, If_Cut_t **ppC0, If_Cut_t **ppC1)
Definition ifCut.c:438
int If_CutFilter2_rec(If_Man_t *p, If_Obj_t *pObj, int LevelMin)
Definition ifCut.c:1504
int If_CutCheck(If_Cut_t *pCut)
Definition ifCut.c:834
float If_CutAreaDeref(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1056
int If_CutFilter2(If_Man_t *p, If_Obj_t *pNode, If_Cut_t *pCut)
Definition ifCut.c:1518
float If_CutPowerFlow(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1003
float If_CutEdgeDerefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1211
void If_CutPrint(If_Cut_t *pCut)
Definition ifCut.c:864
float If_CutEdgeFlow(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:965
int If_CutMergeOrdered(If_Man_t *p, If_Cut_t *pC0, If_Cut_t *pC1, If_Cut_t *pC)
Definition ifCut.c:290
int If_CutFilter(If_Set_t *pCutSet, If_Cut_t *pCut, int fSaveCut0)
Definition ifCut.c:146
float If_CutPowerRefed(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1337
int If_CutGetCutMinLevel(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1360
float If_CutAverageRefs(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1034
float If_CutPowerRef(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1286
float If_CutAreaRef(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1083
float If_CutAreaFlow(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:927
int If_CutGetCone_rec(If_Man_t *p, If_Obj_t *pObj, If_Cut_t *pCut)
Definition ifCut.c:1380
void If_CutPrintTiming(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:884
int If_CutGetCones(If_Man_t *p)
Definition ifCut.c:1417
int If_CutVerifyCuts(If_Set_t *pCutSet, int fOrdered)
Definition ifCut.c:62
float If_CutEdgeDeref(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1157
int If_CutCompareDelay(If_Man_t *p, If_Cut_t **ppC0, If_Cut_t **ppC1)
Definition ifCut.c:408
float If_CutEdgeRef(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1184
void If_CutSort(If_Man_t *p, If_Set_t *pCutSet, If_Cut_t *pCut)
Definition ifCut.c:746
void If_CutOrder(If_Cut_t *pCut)
Definition ifCut.c:805
float If_CutAreaRefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1133
void If_CutLift(If_Cut_t *pCut)
Definition ifCut.c:905
float If_CutPowerDeref(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1258
int If_CutCountTotalFanins(If_Man_t *p)
Definition ifCut.c:1469
float If_CutAreaDerefed(If_Man_t *p, If_Cut_t *pCut)
Definition ifCut.c:1110
int If_CutCompareArea(If_Man_t *p, If_Cut_t **ppC0, If_Cut_t **ppC1)
Definition ifCut.c:468
float If_CutPowerDerefed(If_Man_t *p, If_Cut_t *pCut, If_Obj_t *pRoot)
Definition ifCut.c:1314
int If_CutMergeOrdered_(If_Man_t *p, If_Cut_t *pC0, If_Cut_t *pC1, If_Cut_t *pC)
Definition ifCut.c:201
#define If_ManForEachObj(p, pObj, i)
Definition if.h:491
#define IF_MIN(a, b)
MACRO DEFINITIONS ///.
Definition if.h:465
struct If_Cut_t_ If_Cut_t
Definition if.h:80
struct If_Set_t_ If_Set_t
Definition if.h:81
#define If_CutForEachLeaf(p, pCut, pLeaf, i)
Definition if.h:503
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
Definition if.h:77
struct If_Obj_t_ If_Obj_t
Definition if.h:79
#define IF_INFINITY
Definition if.h:57
float Power
Definition if.h:305
int pLeaves[0]
Definition if.h:318
unsigned nLeaves
Definition if.h:316
float Delay
Definition if.h:306
unsigned nLimit
Definition if.h:315
unsigned fUseless
Definition if.h:313
unsigned uSign
Definition if.h:309
float Area
Definition if.h:303
float Edge
Definition if.h:304
int nRefs
Definition if.h:346
float EstRefs
Definition if.h:352
If_Obj_t * pFanin1
Definition if.h:350
If_Obj_t * pFanin0
Definition if.h:349
unsigned Level
Definition if.h:343
float Required
Definition if.h:353
int Id
Definition if.h:344
If_Obj_t * pEquiv
Definition if.h:351
If_Cut_t ** ppCuts
Definition if.h:327
short nCutsMax
Definition if.h:324
short nCuts
Definition if.h:325
#define assert(ex)
Definition util_old.h:213
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54