ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaResub.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "misc/vec/vecWec.h"
23#include "misc/vec/vecQue.h"
24#include "misc/vec/vecHsh.h"
25#include "misc/util/utilTruth.h"
26#include "base/io/ioResub.h"
27
29
33
37
49int Gia_ObjCheckMffc_rec( Gia_Man_t * p,Gia_Obj_t * pObj, int Limit, Vec_Int_t * vNodes )
50{
51 int iFanin;
52 if ( Gia_ObjIsCi(pObj) )
53 return 1;
54 assert( Gia_ObjIsAnd(pObj) );
55 iFanin = Gia_ObjFaninId0p(p, pObj);
56 Vec_IntPush( vNodes, iFanin );
57 if ( !Gia_ObjRefDecId(p, iFanin) && (Vec_IntSize(vNodes) > Limit || !Gia_ObjCheckMffc_rec(p, Gia_ObjFanin0(pObj), Limit, vNodes)) )
58 return 0;
59 iFanin = Gia_ObjFaninId1p(p, pObj);
60 Vec_IntPush( vNodes, iFanin );
61 if ( !Gia_ObjRefDecId(p, iFanin) && (Vec_IntSize(vNodes) > Limit || !Gia_ObjCheckMffc_rec(p, Gia_ObjFanin1(pObj), Limit, vNodes)) )
62 return 0;
63 if ( !Gia_ObjIsMux(p, pObj) )
64 return 1;
65 iFanin = Gia_ObjFaninId2p(p, pObj);
66 Vec_IntPush( vNodes, iFanin );
67 if ( !Gia_ObjRefDecId(p, iFanin) && (Vec_IntSize(vNodes) > Limit || !Gia_ObjCheckMffc_rec(p, Gia_ObjFanin2(p, pObj), Limit, vNodes)) )
68 return 0;
69 return 1;
70}
71int Gia_ObjCheckMffc( Gia_Man_t * p, Gia_Obj_t * pRoot, int Limit, Vec_Int_t * vNodes, Vec_Int_t * vLeaves, Vec_Int_t * vInners )
72{
73 int RetValue, iObj, i;
74 Vec_IntClear( vNodes );
75 RetValue = Gia_ObjCheckMffc_rec( p, pRoot, Limit, vNodes );
76 if ( RetValue )
77 {
78 Vec_IntClear( vLeaves );
79 Vec_IntClear( vInners );
80 Vec_IntSort( vNodes, 0 );
81 Vec_IntForEachEntry( vNodes, iObj, i )
82 if ( Gia_ObjRefNumId(p, iObj) > 0 || Gia_ObjIsCi(Gia_ManObj(p, iObj)) )
83 {
84 if ( !Vec_IntSize(vLeaves) || Vec_IntEntryLast(vLeaves) != iObj )
85 Vec_IntPush( vLeaves, iObj );
86 }
87 else
88 {
89 if ( !Vec_IntSize(vInners) || Vec_IntEntryLast(vInners) != iObj )
90 Vec_IntPush( vInners, iObj );
91 }
92 Vec_IntPush( vInners, Gia_ObjId(p, pRoot) );
93 }
94 Vec_IntForEachEntry( vNodes, iObj, i )
95 Gia_ObjRefIncId( p, iObj );
96 return RetValue;
97}
98Vec_Wec_t * Gia_ManComputeMffcs( Gia_Man_t * p, int LimitMin, int LimitMax, int SuppMax, int RatioBest )
99{
100 Gia_Obj_t * pObj;
101 Vec_Wec_t * vMffcs;
102 Vec_Int_t * vNodes, * vLeaves, * vInners, * vMffc;
103 int i, iPivot;
104 assert( p->pMuxes );
105 vNodes = Vec_IntAlloc( 2 * LimitMax );
106 vLeaves = Vec_IntAlloc( 2 * LimitMax );
107 vInners = Vec_IntAlloc( 2 * LimitMax );
108 vMffcs = Vec_WecAlloc( 1000 );
110 Gia_ManForEachAnd( p, pObj, i )
111 {
112 if ( !Gia_ObjRefNum(p, pObj) )
113 continue;
114 if ( !Gia_ObjCheckMffc(p, pObj, LimitMax, vNodes, vLeaves, vInners) )
115 continue;
116 if ( Vec_IntSize(vInners) < LimitMin )
117 continue;
118 if ( Vec_IntSize(vLeaves) > SuppMax )
119 continue;
120 // improve cut
121 // collect cut
122 vMffc = Vec_WecPushLevel( vMffcs );
123 Vec_IntGrow( vMffc, Vec_IntSize(vLeaves) + Vec_IntSize(vInners) + 20 );
124 Vec_IntPush( vMffc, i );
125 Vec_IntPush( vMffc, Vec_IntSize(vLeaves) );
126 Vec_IntPush( vMffc, Vec_IntSize(vInners) );
127 Vec_IntAppend( vMffc, vLeaves );
128// Vec_IntAppend( vMffc, vInners );
129 // add last entry equal to the ratio
130 Vec_IntPush( vMffc, 1000 * Vec_IntSize(vInners) / Vec_IntSize(vLeaves) );
131 }
132 Vec_IntFree( vNodes );
133 Vec_IntFree( vLeaves );
134 Vec_IntFree( vInners );
135 // sort MFFCs by their inner/leaf ratio
136 Vec_WecSortByLastInt( vMffcs, 1 );
137 Vec_WecForEachLevel( vMffcs, vMffc, i )
138 Vec_IntPop( vMffc );
139 // remove those whose ratio is not good
140 iPivot = RatioBest * Vec_WecSize(vMffcs) / 100;
141 Vec_WecForEachLevelStart( vMffcs, vMffc, i, iPivot )
142 Vec_IntErase( vMffc );
143 assert( iPivot <= Vec_WecSize(vMffcs) );
144 Vec_WecShrink( vMffcs, iPivot );
145 return vMffcs;
146}
147
159void Gia_ManPrintDivStats( Gia_Man_t * p, Vec_Wec_t * vMffcs, Vec_Wec_t * vPivots )
160{
161 int fVerbose = 0;
162 Vec_Int_t * vMffc;
163 int i, nDivs, nDivsAll = 0, nDivs0 = 0;
164 Vec_WecForEachLevel( vMffcs, vMffc, i )
165 {
166 nDivs = Vec_IntSize(vMffc) - 3 - Vec_IntEntry(vMffc, 1) - Vec_IntEntry(vMffc, 2);
167 nDivs0 += (nDivs == 0);
168 nDivsAll += nDivs;
169 if ( !fVerbose )
170 continue;
171 printf( "%6d : ", Vec_IntEntry(vMffc, 0) );
172 printf( "Leaf =%3d ", Vec_IntEntry(vMffc, 1) );
173 printf( "Mffc =%4d ", Vec_IntEntry(vMffc, 2) );
174 printf( "Divs =%4d ", nDivs );
175 printf( "\n" );
176 }
177 printf( "Collected %d (%.1f %%) MFFCs and %d (%.1f %%) have no divisors (div ave for others is %.2f).\n",
178 Vec_WecSize(vMffcs), 100.0 * Vec_WecSize(vMffcs) / Gia_ManAndNum(p),
179 nDivs0, 100.0 * nDivs0 / Gia_ManAndNum(p),
180 1.0*nDivsAll/Abc_MaxInt(1, Vec_WecSize(vMffcs) - nDivs0) );
181 printf( "Using %.2f MB for MFFCs and %.2f MB for pivots. ",
182 Vec_WecMemory(vMffcs)/(1<<20), Vec_WecMemory(vPivots)/(1<<20) );
183}
184
197{
198 Vec_Wec_t * vPivots;
199 Vec_Int_t * vMffc, * vPivot, * vPivot0, * vPivot1;
200 Vec_Int_t * vCommon, * vCommon2, * vMap;
201 Gia_Obj_t * pObj;
202 int i, k, iObj, iPivot, iMffc;
203//abctime clkStart = Abc_Clock();
204 // initialize pivots (mapping of nodes into MFFCs whose leaves they are)
205 vMap = Vec_IntStartFull( Gia_ManObjNum(p) );
206 vPivots = Vec_WecStart( Gia_ManObjNum(p) );
207 Vec_WecForEachLevel( vMffcs, vMffc, i )
208 {
209 assert( Vec_IntSize(vMffc) == 3 + Vec_IntEntry(vMffc, 1) );
210 iPivot = Vec_IntEntry( vMffc, 0 );
211 Vec_IntWriteEntry( vMap, iPivot, i );
212 // iterate through the MFFC leaves
213 Vec_IntForEachEntryStart( vMffc, iObj, k, 3 )
214 {
215 vPivot = Vec_WecEntry( vPivots, iObj );
216 if ( Vec_IntSize(vPivot) == 0 )
217 Vec_IntGrow(vPivot, 4);
218 Vec_IntPush( vPivot, iPivot );
219 }
220 }
221 Vec_WecForEachLevel( vPivots, vPivot, i )
222 Vec_IntSort( vPivot, 0 );
223 // create pivots for internal nodes while growing MFFCs
224 vCommon = Vec_IntAlloc( 100 );
225 vCommon2 = Vec_IntAlloc( 100 );
226 Gia_ManForEachAnd( p, pObj, i )
227 {
228 // find commont pivots
229 // the slow down happens because some PIs have very large sets of pivots
230 vPivot0 = Vec_WecEntry( vPivots, Gia_ObjFaninId0(pObj, i) );
231 vPivot1 = Vec_WecEntry( vPivots, Gia_ObjFaninId1(pObj, i) );
232 Vec_IntTwoFindCommon( vPivot0, vPivot1, vCommon );
233 if ( Gia_ObjIsMuxId(p, i) )
234 {
235 vPivot = Vec_WecEntry( vPivots, Gia_ObjFaninId2(p, i) );
236 Vec_IntTwoFindCommon( vPivot, vCommon, vCommon2 );
237 ABC_SWAP( Vec_Int_t *, vCommon, vCommon2 );
238 }
239 if ( Vec_IntSize(vCommon) == 0 )
240 continue;
241 // add new pivots (this trick increased memory used in vPivots)
242 vPivot = Vec_WecEntry( vPivots, i );
243 Vec_IntTwoMerge2( vPivot, vCommon, vCommon2 );
244 ABC_SWAP( Vec_Int_t, *vPivot, *vCommon2 );
245 // grow MFFCs
246 Vec_IntForEachEntry( vCommon, iObj, k )
247 {
248 iMffc = Vec_IntEntry( vMap, iObj );
249 assert( iMffc != -1 );
250 vMffc = Vec_WecEntry( vMffcs, iMffc );
251 Vec_IntPush( vMffc, i );
252 }
253 }
254//Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
255 Vec_IntFree( vCommon );
256 Vec_IntFree( vCommon2 );
257 Vec_IntFree( vMap );
258 Gia_ManPrintDivStats( p, vMffcs, vPivots );
259 Vec_WecFree( vPivots );
260 // returns the modified array of MFFCs
261}
263{
264 Vec_Wec_t * vMffcs;
265 Gia_Man_t * pNew = Gia_ManDupMuxes( p, 2 );
266abctime clkStart = Abc_Clock();
267 vMffcs = Gia_ManComputeMffcs( pNew, 4, 100, 8, 100 );
268 Gia_ManAddDivisors( pNew, vMffcs );
269 Vec_WecFree( vMffcs );
270Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
271 Gia_ManStop( pNew );
272}
273
274
275
276
277
315{
317 p->nWords = nWords;
318 p->vUnateLits[0] = Vec_IntAlloc( 100 );
319 p->vUnateLits[1] = Vec_IntAlloc( 100 );
320 p->vNotUnateVars[0] = Vec_IntAlloc( 100 );
321 p->vNotUnateVars[1] = Vec_IntAlloc( 100 );
322 p->vUnatePairs[0] = Vec_IntAlloc( 100 );
323 p->vUnatePairs[1] = Vec_IntAlloc( 100 );
324 p->vUnateLitsW[0] = Vec_IntAlloc( 100 );
325 p->vUnateLitsW[1] = Vec_IntAlloc( 100 );
326 p->vUnatePairsW[0] = Vec_IntAlloc( 100 );
327 p->vUnatePairsW[1] = Vec_IntAlloc( 100 );
328 p->vSorter = Vec_WecAlloc( nWords*64 );
329 p->vBinateVars = Vec_IntAlloc( 100 );
330 p->vGates = Vec_IntAlloc( 100 );
331 p->vDivs = Vec_PtrAlloc( 100 );
332 p->pSets[0] = ABC_CALLOC( word, nWords );
333 p->pSets[1] = ABC_CALLOC( word, nWords );
334 p->pDivA = ABC_CALLOC( word, nWords );
335 p->pDivB = ABC_CALLOC( word, nWords );
336 p->vSims = Vec_WrdAlloc( 100 );
337 return p;
338}
339void Gia_ResbInit( Gia_ResbMan_t * p, Vec_Ptr_t * vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int fVeryVerbose )
340{
341 assert( p->nWords == nWords );
342 p->nLimit = nLimit;
343 p->nDivsMax = nDivsMax;
344 p->iChoice = iChoice;
345 p->fUseXor = fUseXor;
346 p->fDebug = fDebug;
347 p->fVerbose = fVerbose;
348 p->fVeryVerbose = fVeryVerbose;
349 Abc_TtCopy( p->pSets[0], (word *)Vec_PtrEntry(vDivs, 0), nWords, 0 );
350 Abc_TtCopy( p->pSets[1], (word *)Vec_PtrEntry(vDivs, 1), nWords, 0 );
351 Vec_PtrClear( p->vDivs );
352 Vec_PtrAppend( p->vDivs, vDivs );
353 Vec_IntClear( p->vGates );
354 Vec_IntClear( p->vUnateLits[0] );
355 Vec_IntClear( p->vUnateLits[1] );
356 Vec_IntClear( p->vNotUnateVars[0] );
357 Vec_IntClear( p->vNotUnateVars[1] );
358 Vec_IntClear( p->vUnatePairs[0] );
359 Vec_IntClear( p->vUnatePairs[1] );
360 Vec_IntClear( p->vUnateLitsW[0] );
361 Vec_IntClear( p->vUnateLitsW[1] );
362 Vec_IntClear( p->vUnatePairsW[0] );
363 Vec_IntClear( p->vUnatePairsW[1] );
364 Vec_IntClear( p->vBinateVars );
365}
367{
368 Vec_IntFree( p->vUnateLits[0] );
369 Vec_IntFree( p->vUnateLits[1] );
370 Vec_IntFree( p->vNotUnateVars[0] );
371 Vec_IntFree( p->vNotUnateVars[1] );
372 Vec_IntFree( p->vUnatePairs[0] );
373 Vec_IntFree( p->vUnatePairs[1] );
374 Vec_IntFree( p->vUnateLitsW[0] );
375 Vec_IntFree( p->vUnateLitsW[1] );
376 Vec_IntFree( p->vUnatePairsW[0] );
377 Vec_IntFree( p->vUnatePairsW[1] );
378 Vec_IntFree( p->vBinateVars );
379 Vec_IntFree( p->vGates );
380 Vec_WrdFree( p->vSims );
381 Vec_PtrFree( p->vDivs );
382 Vec_WecFree( p->vSorter );
383 ABC_FREE( p->pSets[0] );
384 ABC_FREE( p->pSets[1] );
385 ABC_FREE( p->pDivA );
386 ABC_FREE( p->pDivB );
387 ABC_FREE( p );
388}
389
401void Gia_ManResubPrintNode( Vec_Int_t * vRes, int nVars, int Node, int fCompl )
402{
403 extern void Gia_ManResubPrintLit( Vec_Int_t * vRes, int nVars, int iLit );
404 int iLit0 = Vec_IntEntry( vRes, 2*Node + 0 );
405 int iLit1 = Vec_IntEntry( vRes, 2*Node + 1 );
406 assert( iLit0 != iLit1 );
407 if ( iLit0 > iLit1 && Abc_LitIsCompl(fCompl) ) // xor
408 {
409 printf( "~" );
410 fCompl = 0;
411 }
412 printf( "(" );
413 Gia_ManResubPrintLit( vRes, nVars, Abc_LitNotCond(iLit0, fCompl) );
414 printf( " %c ", iLit0 > iLit1 ? '^' : (fCompl ? '|' : '&') );
415 Gia_ManResubPrintLit( vRes, nVars, Abc_LitNotCond(iLit1, fCompl) );
416 printf( ")" );
417}
418void Gia_ManResubPrintLit( Vec_Int_t * vRes, int nVars, int iLit )
419{
420 if ( Abc_Lit2Var(iLit) < nVars )
421 {
422 if ( nVars < 26 )
423 printf( "%s%c", Abc_LitIsCompl(iLit) ? "~":"", 'a' + Abc_Lit2Var(iLit)-2 );
424 else
425 printf( "%si%d", Abc_LitIsCompl(iLit) ? "~":"", Abc_Lit2Var(iLit)-2 );
426 }
427 else
428 Gia_ManResubPrintNode( vRes, nVars, Abc_Lit2Var(iLit) - nVars, Abc_LitIsCompl(iLit) );
429}
430int Gia_ManResubPrint( Vec_Int_t * vRes, int nVars )
431{
432 int iTopLit;
433 if ( Vec_IntSize(vRes) == 0 )
434 return printf( "none" );
435 assert( Vec_IntSize(vRes) % 2 == 1 );
436 iTopLit = Vec_IntEntryLast(vRes);
437 if ( iTopLit == 0 )
438 return printf( "const0" );
439 if ( iTopLit == 1 )
440 return printf( "const1" );
441 Gia_ManResubPrintLit( vRes, nVars, iTopLit );
442 return 0;
443}
444
457{
458 int nVars = Vec_PtrSize(p->vDivs);
459 int iTopLit, RetValue;
460 word * pDivRes;
461 if ( Vec_IntSize(p->vGates) == 0 )
462 return -1;
463 iTopLit = Vec_IntEntryLast(p->vGates);
464 assert( iTopLit >= 0 );
465 if ( iTopLit == 0 )
466 {
467 if ( pFunc ) Abc_TtClear( pFunc, p->nWords );
468 return Abc_TtIsConst0( p->pSets[1], p->nWords );
469 }
470 if ( iTopLit == 1 )
471 {
472 if ( pFunc ) Abc_TtFill( pFunc, p->nWords );
473 return Abc_TtIsConst0( p->pSets[0], p->nWords );
474 }
475 if ( Abc_Lit2Var(iTopLit) < nVars )
476 {
477 assert( Vec_IntSize(p->vGates) == 1 );
478 pDivRes = (word *)Vec_PtrEntry( p->vDivs, Abc_Lit2Var(iTopLit) );
479 }
480 else
481 {
482 int i, iLit0, iLit1;
483 assert( Vec_IntSize(p->vGates) > 1 );
484 assert( Vec_IntSize(p->vGates) % 2 == 1 );
485 assert( Abc_Lit2Var(iTopLit)-nVars == Vec_IntSize(p->vGates)/2-1 );
486 Vec_WrdFill( p->vSims, p->nWords * Vec_IntSize(p->vGates)/2, 0 );
487 Vec_IntForEachEntryDouble( p->vGates, iLit0, iLit1, i )
488 {
489 int iVar0 = Abc_Lit2Var(iLit0);
490 int iVar1 = Abc_Lit2Var(iLit1);
491 word * pDiv0 = iVar0 < nVars ? (word *)Vec_PtrEntry(p->vDivs, iVar0) : Vec_WrdEntryP(p->vSims, p->nWords*(iVar0 - nVars));
492 word * pDiv1 = iVar1 < nVars ? (word *)Vec_PtrEntry(p->vDivs, iVar1) : Vec_WrdEntryP(p->vSims, p->nWords*(iVar1 - nVars));
493 word * pDiv = Vec_WrdEntryP(p->vSims, p->nWords*i/2);
494 if ( iVar0 < iVar1 )
495 Abc_TtAndCompl( pDiv, pDiv0, Abc_LitIsCompl(iLit0), pDiv1, Abc_LitIsCompl(iLit1), p->nWords );
496 else if ( iVar0 > iVar1 )
497 {
498 assert( !Abc_LitIsCompl(iLit0) );
499 assert( !Abc_LitIsCompl(iLit1) );
500 Abc_TtXor( pDiv, pDiv0, pDiv1, p->nWords, 0 );
501 }
502 else assert( 0 );
503 }
504 pDivRes = Vec_WrdEntryP( p->vSims, p->nWords*(Vec_IntSize(p->vGates)/2-1) );
505 }
506 if ( Abc_LitIsCompl(iTopLit) )
507 RetValue = !Abc_TtIntersectOne(p->pSets[1], 0, pDivRes, 0, p->nWords) && !Abc_TtIntersectOne(p->pSets[0], 0, pDivRes, 1, p->nWords);
508 else
509 RetValue = !Abc_TtIntersectOne(p->pSets[0], 0, pDivRes, 0, p->nWords) && !Abc_TtIntersectOne(p->pSets[1], 0, pDivRes, 1, p->nWords);
510 if ( pFunc ) Abc_TtCopy( pFunc, pDivRes, p->nWords, Abc_LitIsCompl(iTopLit) );
511 return RetValue;
512}
513
525int Gia_ManConstructFromMap( Gia_Man_t * pNew, Vec_Int_t * vGates, int nVars, Vec_Int_t * vUsed, Vec_Int_t * vCopy, int fHash )
526{
527 int i, iLit0, iLit1, iLitRes, iTopLit = Vec_IntEntryLast( vGates );
528 assert( Vec_IntSize(vUsed) == nVars );
529 assert( Vec_IntSize(vGates) > 1 );
530 assert( Vec_IntSize(vGates) % 2 == 1 );
531 assert( Abc_Lit2Var(iTopLit)-nVars == Vec_IntSize(vGates)/2-1 );
532 Vec_IntClear( vCopy );
533 Vec_IntForEachEntryDouble( vGates, iLit0, iLit1, i )
534 {
535 int iVar0 = Abc_Lit2Var(iLit0);
536 int iVar1 = Abc_Lit2Var(iLit1);
537 int iRes0 = iVar0 < nVars ? Vec_IntEntry(vUsed, iVar0) : Vec_IntEntry(vCopy, iVar0 - nVars);
538 int iRes1 = iVar1 < nVars ? Vec_IntEntry(vUsed, iVar1) : Vec_IntEntry(vCopy, iVar1 - nVars);
539 if ( iVar0 < iVar1 )
540 {
541 if ( fHash )
542 iLitRes = Gia_ManHashAnd( pNew, Abc_LitNotCond(iRes0, Abc_LitIsCompl(iLit0)), Abc_LitNotCond(iRes1, Abc_LitIsCompl(iLit1)) );
543 else
544 iLitRes = Gia_ManAppendAnd( pNew, Abc_LitNotCond(iRes0, Abc_LitIsCompl(iLit0)), Abc_LitNotCond(iRes1, Abc_LitIsCompl(iLit1)) );
545 }
546 else if ( iVar0 > iVar1 )
547 {
548 assert( !Abc_LitIsCompl(iLit0) );
549 assert( !Abc_LitIsCompl(iLit1) );
550 if ( fHash )
551 iLitRes = Gia_ManHashXor( pNew, Abc_LitNotCond(iRes0, Abc_LitIsCompl(iLit0)), Abc_LitNotCond(iRes1, Abc_LitIsCompl(iLit1)) );
552 else
553 iLitRes = Gia_ManAppendXor( pNew, Abc_LitNotCond(iRes0, Abc_LitIsCompl(iLit0)), Abc_LitNotCond(iRes1, Abc_LitIsCompl(iLit1)) );
554 }
555 else assert( 0 );
556 Vec_IntPush( vCopy, iLitRes );
557 }
558 assert( Vec_IntSize(vCopy) == Vec_IntSize(vGates)/2 );
559 iLitRes = Vec_IntEntry( vCopy, Vec_IntSize(vGates)/2-1 );
560 return iLitRes;
561}
563{
564 Vec_Int_t * vGates; int i, k, iLit;
565 Vec_Int_t * vCopy = Vec_IntAlloc( 100 );
566 Vec_Int_t * vUsed = Vec_IntStartFull( nDivs );
567 Gia_Man_t * pNew = Gia_ManStart( 100 );
568 pNew->pName = Abc_UtilStrsav( "resub" );
569 Vec_WecForEachLevel( vFuncs, vGates, i )
570 {
571 assert( Vec_IntSize(vGates) % 2 == 1 );
572 Vec_IntForEachEntry( vGates, iLit, k )
573 {
574 int iVar = Abc_Lit2Var(iLit);
575 if ( iVar > 0 && iVar < nDivs && Vec_IntEntry(vUsed, iVar) == -1 )
576 Vec_IntWriteEntry( vUsed, iVar, Gia_ManAppendCi(pNew) );
577 }
578 }
579 Vec_WecForEachLevel( vFuncs, vGates, i )
580 {
581 int iLitRes, iTopLit = Vec_IntEntryLast( vGates );
582 if ( Abc_Lit2Var(iTopLit) == 0 )
583 iLitRes = 0;
584 else if ( Abc_Lit2Var(iTopLit) < nDivs )
585 iLitRes = Vec_IntEntry( vUsed, Abc_Lit2Var(iTopLit) );
586 else
587 iLitRes = Gia_ManConstructFromMap( pNew, vGates, nDivs, vUsed, vCopy, 0 );
588 Gia_ManAppendCo( pNew, Abc_LitNotCond( iLitRes, Abc_LitIsCompl(iTopLit) ) );
589 }
590 Vec_IntFree( vCopy );
591 Vec_IntFree( vUsed );
592 return pNew;
593}
594Gia_Man_t * Gia_ManConstructFromGates2( Vec_Wec_t * vFuncs, Vec_Wec_t * vDivs, int nObjs, Vec_Int_t ** pvSupp )
595{
596 Vec_Int_t * vGates; int i, k, iVar, iLit;
597 Vec_Int_t * vSupp = Vec_IntAlloc( 100 );
598 Vec_Int_t * vCopy = Vec_IntAlloc( 100 );
599 Vec_Wec_t * vUseds = Vec_WecStart( Vec_WecSize(vDivs) );
600 Vec_Int_t * vMap = Vec_IntStartFull( nObjs );
601 Gia_Man_t * pNew = Gia_ManStart( 100 );
602 pNew->pName = Abc_UtilStrsav( "resub" );
603 assert( Vec_WecSize(vFuncs) == Vec_WecSize(vDivs) );
604 Vec_WecForEachLevel( vFuncs, vGates, i )
605 {
606 Vec_Int_t * vDiv = Vec_WecEntry( vDivs, i );
607 assert( Vec_IntSize(vGates) % 2 == 1 );
608 Vec_IntForEachEntry( vGates, iLit, k )
609 {
610 int iVar = Abc_Lit2Var(iLit);
611 if ( iVar > 0 && iVar < Vec_IntSize(vDiv) && Vec_IntEntry(vMap, Vec_IntEntry(vDiv, iVar)) == -1 )
612 Vec_IntWriteEntry( vMap, Vec_IntPushReturn(vSupp, Vec_IntEntry(vDiv, iVar)), 0 );
613 }
614 }
615 Vec_IntSort( vSupp, 0 );
616 Vec_IntForEachEntry( vSupp, iVar, k )
617 Vec_IntWriteEntry( vMap, iVar, Gia_ManAppendCi(pNew) );
618 Vec_WecForEachLevel( vFuncs, vGates, i )
619 {
620 Vec_Int_t * vDiv = Vec_WecEntry( vDivs, i );
621 Vec_Int_t * vUsed = Vec_WecEntry( vUseds, i );
622 Vec_IntFill( vUsed, Vec_IntSize(vDiv), -1 );
623 Vec_IntForEachEntry( vGates, iLit, k )
624 {
625 int iVar = Abc_Lit2Var(iLit);
626 if ( iVar > 0 && iVar < Vec_IntSize(vDiv) )
627 {
628 assert( Vec_IntEntry(vMap, Vec_IntEntry(vDiv, iVar)) > 0 );
629 Vec_IntWriteEntry( vUsed, iVar, Vec_IntEntry(vMap, Vec_IntEntry(vDiv, iVar)) );
630 }
631 }
632 }
633 Vec_WecForEachLevel( vFuncs, vGates, i )
634 {
635 Vec_Int_t * vDiv = Vec_WecEntry( vDivs, i );
636 Vec_Int_t * vUsed = Vec_WecEntry( vUseds, i );
637 int iLitRes, iTopLit = Vec_IntEntryLast( vGates );
638 if ( Abc_Lit2Var(iTopLit) == 0 )
639 iLitRes = 0;
640 else if ( Abc_Lit2Var(iTopLit) < Vec_IntSize(vDiv) )
641 iLitRes = Vec_IntEntry( vUsed, Abc_Lit2Var(iTopLit) );
642 else
643 iLitRes = Gia_ManConstructFromMap( pNew, vGates, Vec_IntSize(vDiv), vUsed, vCopy, 0 );
644 Gia_ManAppendCo( pNew, Abc_LitNotCond( iLitRes, Abc_LitIsCompl(iTopLit) ) );
645 }
646 Vec_IntFree( vMap );
647 Vec_IntFree( vCopy );
648 Vec_WecFree( vUseds );
649 if ( pvSupp )
650 *pvSupp = vSupp;
651 else
652 Vec_IntFree( vSupp );
653 return pNew;
654}
656{
657 Vec_Int_t * vRes = Vec_IntAlloc( 2*Gia_ManAndNum(p) + 1 );
658 Gia_Obj_t * pRoot = Gia_ManCo( p, 0 );
659 int iRoot = Gia_ObjFaninId0p(p, pRoot) - 1;
660 int nVars = Gia_ManCiNum(p);
661 assert( Gia_ManCoNum(p) == 1 );
662 if ( iRoot == -1 )
663 Vec_IntPush( vRes, Gia_ObjFaninC0(pRoot) );
664 else if ( iRoot < nVars )
665 Vec_IntPush( vRes, 4 + Abc_Var2Lit(iRoot, Gia_ObjFaninC0(pRoot)) );
666 else
667 {
668 Gia_Obj_t * pObj, * pLast = NULL; int i;
669 Gia_ManForEachCi( p, pObj, i )
670 assert( Gia_ObjId(p, pObj) == i+1 );
671 Gia_ManForEachAnd( p, pObj, i )
672 {
673 int iLit0 = Abc_Var2Lit( Gia_ObjFaninId0(pObj, i) - 1, Gia_ObjFaninC0(pObj) );
674 int iLit1 = Abc_Var2Lit( Gia_ObjFaninId1(pObj, i) - 1, Gia_ObjFaninC1(pObj) );
675 if ( iLit0 > iLit1 )
676 iLit0 ^= iLit1, iLit1 ^= iLit0, iLit0 ^= iLit1;
677 Vec_IntPushTwo( vRes, 4 + iLit0, 4 + iLit1 );
678 pLast = pObj;
679 }
680 assert( pLast == Gia_ObjFanin0(pRoot) );
681 Vec_IntPush( vRes, 4 + Abc_Var2Lit(iRoot, Gia_ObjFaninC0(pRoot)) );
682 }
683 assert( Vec_IntSize(vRes) == 2*Gia_ManAndNum(p) + 1 );
684 return vRes;
685}
686
698void Gia_ManInsertOrder_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vObjs, Vec_Wec_t * vFuncs, Vec_Int_t * vNodes )
699{
700 Gia_Obj_t * pObj = Gia_ManObj( p, iObj );
701 if ( iObj == 0 )
702 return;
703 if ( pObj->fPhase )
704 {
705 int nVars = Gia_ManObjNum(p);
706 int k, iLit, Index = Vec_IntFind( vObjs, iObj );
707 Vec_Int_t * vGates = Vec_WecEntry( vFuncs, Index );
708 assert( Gia_ObjIsCo(pObj) || Gia_ObjIsAnd(pObj) );
709 Vec_IntForEachEntry( vGates, iLit, k )
710 if ( Abc_Lit2Var(iLit) < nVars )
711 Gia_ManInsertOrder_rec( p, Abc_Lit2Var(iLit), vObjs, vFuncs, vNodes );
712 }
713 else if ( Gia_ObjIsCo(pObj) )
714 Gia_ManInsertOrder_rec( p, Gia_ObjFaninId0p(p, pObj), vObjs, vFuncs, vNodes );
715 else if ( Gia_ObjIsAnd(pObj) )
716 {
717 Gia_ManInsertOrder_rec( p, Gia_ObjFaninId0p(p, pObj), vObjs, vFuncs, vNodes );
718 Gia_ManInsertOrder_rec( p, Gia_ObjFaninId1p(p, pObj), vObjs, vFuncs, vNodes );
719 }
720 else assert( Gia_ObjIsCi(pObj) );
721 if ( !Gia_ObjIsCi(pObj) )
722 Vec_IntPush( vNodes, iObj );
723}
725{
726 int i, Id;
727 Vec_Int_t * vNodes = Vec_IntAlloc( Gia_ManObjNum(p) );
728 Gia_ManForEachCoId( p, Id, i )
729 Gia_ManInsertOrder_rec( p, Id, vObjs, vFuncs, vNodes );
730 return vNodes;
731}
733{
734 Gia_Man_t * pNew, * pTemp;
735 Gia_Obj_t * pObj;
736 int i, nVars = Gia_ManObjNum(p);
737 Vec_Int_t * vUsed = Vec_IntStartFull( nVars );
738 Vec_Int_t * vNodes, * vCopy = Vec_IntAlloc(100);
739 Gia_ManForEachObjVec( vObjs, p, pObj, i )
740 pObj->fPhase = 1;
741 vNodes = Gia_ManInsertOrder( p, vObjs, vFuncs );
742 pNew = Gia_ManStart( Gia_ManObjNum(p) + 1000 );
743 Gia_ManHashStart( pNew );
744 Gia_ManConst0(p)->Value = 0;
745 Gia_ManForEachCi( p, pObj, i )
746 pObj->Value = Gia_ManAppendCi( pNew );
747 Gia_ManForEachObjVec( vNodes, p, pObj, i )
748 if ( !pObj->fPhase )
749 {
750 if ( Gia_ObjIsCo(pObj) )
751 pObj->Value = Gia_ObjFanin0Copy(pObj);
752 else if ( Gia_ObjIsAnd(pObj) )
753 pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
754 else assert( 0 );
755 }
756 else
757 {
758 int k, iLit, Index = Vec_IntFind( vObjs, Gia_ObjId(p, pObj) );
759 Vec_Int_t * vGates = Vec_WecEntry( vFuncs, Index );
760 int iLitRes, iTopLit = Vec_IntEntryLast( vGates );
761 if ( Abc_Lit2Var(iTopLit) == 0 )
762 iLitRes = 0;
763 else if ( Abc_Lit2Var(iTopLit) < nVars )
764 iLitRes = Gia_ManObj(p, Abc_Lit2Var(iTopLit))->Value;
765 else
766 {
767 Vec_IntForEachEntry( vGates, iLit, k )
768 Vec_IntWriteEntry( vUsed, Abc_Lit2Var(iLit), Gia_ManObj(p, Abc_Lit2Var(iLit))->Value );
769 iLitRes = Gia_ManConstructFromMap( pNew, vGates, nVars, vUsed, vCopy, 1 );
770 Vec_IntForEachEntry( vGates, iLit, k )
771 Vec_IntWriteEntry( vUsed, Abc_Lit2Var(iLit), -1 );
772 }
773 pObj->Value = Abc_LitNotCond( iLitRes, Abc_LitIsCompl(iTopLit) );
774 }
775 Gia_ManForEachCo( p, pObj, i )
776 Gia_ManAppendCo( pNew, pObj->Value );
777 Gia_ManForEachObjVec( vObjs, p, pObj, i )
778 pObj->fPhase = 0;
779 Gia_ManHashStop( pNew );
780 pNew = Gia_ManCleanup( pTemp = pNew );
781 Gia_ManStop( pTemp );
782 Vec_IntFree( vNodes );
783 Vec_IntFree( vUsed );
784 Vec_IntFree( vCopy );
785 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
786 return pNew;
787}
788
800static inline int Gia_ManFindFirstCommonLit( Vec_Int_t * vArr1, Vec_Int_t * vArr2, int fVerbose )
801{
802 int * pBeg1 = vArr1->pArray;
803 int * pBeg2 = vArr2->pArray;
804 int * pEnd1 = vArr1->pArray + vArr1->nSize;
805 int * pEnd2 = vArr2->pArray + vArr2->nSize;
806 int * pStart1 = vArr1->pArray;
807 int * pStart2 = vArr2->pArray;
808 int nRemoved = 0;
809 while ( pBeg1 < pEnd1 && pBeg2 < pEnd2 )
810 {
811 if ( Abc_Lit2Var(*pBeg1) == Abc_Lit2Var(*pBeg2) )
812 {
813 if ( *pBeg1 != *pBeg2 )
814 return *pBeg1;
815 else
816 pBeg1++, pBeg2++;
817 nRemoved++;
818 }
819 else if ( *pBeg1 < *pBeg2 )
820 *pStart1++ = *pBeg1++;
821 else
822 *pStart2++ = *pBeg2++;
823 }
824 while ( pBeg1 < pEnd1 )
825 *pStart1++ = *pBeg1++;
826 while ( pBeg2 < pEnd2 )
827 *pStart2++ = *pBeg2++;
828 Vec_IntShrink( vArr1, pStart1 - vArr1->pArray );
829 Vec_IntShrink( vArr2, pStart2 - vArr2->pArray );
830 //if ( fVerbose ) printf( "Removed %d duplicated entries. Array1 = %d. Array2 = %d.\n", nRemoved, Vec_IntSize(vArr1), Vec_IntSize(vArr2) );
831 return -1;
832}
833
834void Gia_ManFindOneUnateInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits, Vec_Int_t * vNotUnateVars )
835{
836 word * pDiv; int i;
837 Vec_IntClear( vUnateLits );
838 Vec_IntClear( vNotUnateVars );
839 Vec_PtrForEachEntryStart( word *, vDivs, pDiv, i, 2 )
840 if ( !Abc_TtIntersectOne( pOff, 0, pDiv, 0, nWords ) )
841 Vec_IntPush( vUnateLits, Abc_Var2Lit(i, 0) );
842 else if ( !Abc_TtIntersectOne( pOff, 0, pDiv, 1, nWords ) )
843 Vec_IntPush( vUnateLits, Abc_Var2Lit(i, 1) );
844 else
845 Vec_IntPush( vNotUnateVars, i );
846}
847int Gia_ManFindOneUnate( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits[2], Vec_Int_t * vNotUnateVars[2], int fVerbose )
848{
849 int n;
850 if ( fVerbose ) printf( " " );
851 for ( n = 0; n < 2; n++ )
852 {
853 Gia_ManFindOneUnateInt( pSets[n], pSets[!n], vDivs, nWords, vUnateLits[n], vNotUnateVars[n] );
854 if ( fVerbose ) printf( "U%d =%4d ", n, Vec_IntSize(vUnateLits[n]) );
855 }
856 return Gia_ManFindFirstCommonLit( vUnateLits[0], vUnateLits[1], fVerbose );
857}
858
859static inline int Gia_ManDivCover( word * pOff, word * pOn, word * pDivA, int ComplA, word * pDivB, int ComplB, int nWords )
860{
861 //assert( !Abc_TtIntersectOne(pOff, 0, pDivA, ComplA, nWords) );
862 //assert( !Abc_TtIntersectOne(pOff, 0, pDivB, ComplB, nWords) );
863 return !Abc_TtIntersectTwo( pOn, 0, pDivA, !ComplA, pDivB, !ComplB, nWords );
864}
865int Gia_ManFindTwoUnateInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits, Vec_Int_t * vUnateLitsW, int * pnPairs )
866{
867 int i, k, iDiv0_, iDiv1_, Cover0, Cover1;
868 int nTotal = Abc_TtCountOnesVec( pOn, nWords );
869 (*pnPairs) = 0;
870 Vec_IntForEachEntryTwo( vUnateLits, vUnateLitsW, iDiv0_, Cover0, i )
871 {
872 if ( 2*Cover0 < nTotal )
873 break;
874 Vec_IntForEachEntryTwoStart( vUnateLits, vUnateLitsW, iDiv1_, Cover1, k, i+1 )
875 {
876 int iDiv0 = Abc_MinInt( iDiv0_, iDiv1_ );
877 int iDiv1 = Abc_MaxInt( iDiv0_, iDiv1_ );
878 word * pDiv0 = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iDiv0));
879 word * pDiv1 = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iDiv1));
880 if ( Cover0 + Cover1 < nTotal )
881 break;
882 (*pnPairs)++;
883 if ( Gia_ManDivCover(pOff, pOn, pDiv1, Abc_LitIsCompl(iDiv1), pDiv0, Abc_LitIsCompl(iDiv0), nWords) )
884 return Abc_Var2Lit((Abc_LitNot(iDiv1) << 15) | Abc_LitNot(iDiv0), 1);
885 }
886 }
887 return -1;
888}
889int Gia_ManFindTwoUnate( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits[2], Vec_Int_t * vUnateLitsW[2], int fVerbose )
890{
891 int n, iLit, nPairs;
892 if ( fVerbose ) printf( " " );
893 for ( n = 0; n < 2; n++ )
894 {
895 //int nPairsAll = Vec_IntSize(vUnateLits[n])*(Vec_IntSize(vUnateLits[n])-1)/2;
896 iLit = Gia_ManFindTwoUnateInt( pSets[n], pSets[!n], vDivs, nWords, vUnateLits[n], vUnateLitsW[n], &nPairs );
897 if ( fVerbose ) printf( "UU%d =%5d ", n, nPairs );
898 if ( iLit >= 0 )
899 return Abc_LitNotCond(iLit, n);
900 }
901 return -1;
902}
903
904void Gia_ManFindXorInt( word * pOff, word * pOn, Vec_Int_t * vBinate, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnatePairs )
905{
906 int i, k, iDiv0_, iDiv1_;
907 int Limit2 = Vec_IntSize(vBinate);//Abc_MinInt( Vec_IntSize(vBinate), 100 );
908 Vec_IntForEachEntryStop( vBinate, iDiv1_, i, Limit2 )
909 Vec_IntForEachEntryStop( vBinate, iDiv0_, k, i )
910 {
911 int iDiv0 = Abc_MinInt( iDiv0_, iDiv1_ );
912 int iDiv1 = Abc_MaxInt( iDiv0_, iDiv1_ );
913 word * pDiv0 = (word *)Vec_PtrEntry(vDivs, iDiv0);
914 word * pDiv1 = (word *)Vec_PtrEntry(vDivs, iDiv1);
915 if ( !Abc_TtIntersectXor( pOff, 0, pDiv0, pDiv1, 0, nWords ) )
916 Vec_IntPush( vUnatePairs, Abc_Var2Lit((Abc_Var2Lit(iDiv0, 0) << 15) | Abc_Var2Lit(iDiv1, 0), 0) );
917 else if ( !Abc_TtIntersectXor( pOff, 0, pDiv0, pDiv1, 1, nWords ) )
918 Vec_IntPush( vUnatePairs, Abc_Var2Lit((Abc_Var2Lit(iDiv0, 0) << 15) | Abc_Var2Lit(iDiv1, 0), 1) );
919 }
920}
921int Gia_ManFindXor( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vBinateVars, Vec_Int_t * vUnatePairs[2], int fVerbose )
922{
923 int n;
924 if ( fVerbose ) printf( " " );
925 for ( n = 0; n < 2; n++ )
926 {
927 Vec_IntClear( vUnatePairs[n] );
928 Gia_ManFindXorInt( pSets[n], pSets[!n], vBinateVars, vDivs, nWords, vUnatePairs[n] );
929 if ( fVerbose ) printf( "UX%d =%5d ", n, Vec_IntSize(vUnatePairs[n]) );
930 }
931 return Gia_ManFindFirstCommonLit( vUnatePairs[0], vUnatePairs[1], fVerbose );
932}
933
934void Gia_ManFindUnatePairsInt( word * pOff, word * pOn, Vec_Int_t * vBinate, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnatePairs )
935{
936 int n, i, k, iDiv0_, iDiv1_;
937 int Limit2 = Vec_IntSize(vBinate);//Abc_MinInt( Vec_IntSize(vBinate), 100 );
938 Vec_IntForEachEntryStop( vBinate, iDiv1_, i, Limit2 )
939 Vec_IntForEachEntryStop( vBinate, iDiv0_, k, i )
940 {
941 int iDiv0 = Abc_MinInt( iDiv0_, iDiv1_ );
942 int iDiv1 = Abc_MaxInt( iDiv0_, iDiv1_ );
943 word * pDiv0 = (word *)Vec_PtrEntry(vDivs, iDiv0);
944 word * pDiv1 = (word *)Vec_PtrEntry(vDivs, iDiv1);
945 for ( n = 0; n < 4; n++ )
946 {
947 int iLit0 = Abc_Var2Lit( iDiv0, n&1 );
948 int iLit1 = Abc_Var2Lit( iDiv1, n>>1 );
949 //if ( !Abc_TtIntersectTwo( pOff, 0, pDiv1, n>>1, pDiv0, n&1, nWords ) )
950 if ( !Abc_TtIntersectTwo( pOff, 0, pDiv1, n>>1, pDiv0, n&1, nWords ) && Abc_TtIntersectTwo( pOn, 0, pDiv1, n>>1, pDiv0, n&1, nWords ) )
951 Vec_IntPush( vUnatePairs, Abc_Var2Lit((iLit1 << 15) | iLit0, 0) );
952 }
953 }
954}
955void Gia_ManFindUnatePairs( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vBinateVars, Vec_Int_t * vUnatePairs[2], int fVerbose )
956{
957 int n, RetValue;
958 if ( fVerbose ) printf( " " );
959 for ( n = 0; n < 2; n++ )
960 {
961 int nBefore = Vec_IntSize(vUnatePairs[n]);
962 Gia_ManFindUnatePairsInt( pSets[n], pSets[!n], vBinateVars, vDivs, nWords, vUnatePairs[n] );
963 if ( fVerbose ) printf( "UP%d =%5d ", n, Vec_IntSize(vUnatePairs[n])-nBefore );
964 }
965 RetValue = Gia_ManFindFirstCommonLit( vUnatePairs[0], vUnatePairs[1], fVerbose );
966 assert( RetValue == -1 );
967}
968
969void Gia_ManDeriveDivPair( int iDiv, Vec_Ptr_t * vDivs, int nWords, word * pRes )
970{
971 int fComp = Abc_LitIsCompl(iDiv);
972 int iDiv0 = Abc_Lit2Var(iDiv) & 0x7FFF;
973 int iDiv1 = Abc_Lit2Var(iDiv) >> 15;
974 word * pDiv0 = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iDiv0));
975 word * pDiv1 = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iDiv1));
976 if ( iDiv0 < iDiv1 )
977 {
978 assert( !fComp );
979 Abc_TtAndCompl( pRes, pDiv0, Abc_LitIsCompl(iDiv0), pDiv1, Abc_LitIsCompl(iDiv1), nWords );
980 }
981 else
982 {
983 assert( !Abc_LitIsCompl(iDiv0) );
984 assert( !Abc_LitIsCompl(iDiv1) );
985 Abc_TtXor( pRes, pDiv0, pDiv1, nWords, 0 );
986 }
987}
988int Gia_ManFindDivGateInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits, Vec_Int_t * vUnatePairs, Vec_Int_t * vUnateLitsW, Vec_Int_t * vUnatePairsW, word * pDivTemp )
989{
990 int i, k, iDiv0, iDiv1, Cover0, Cover1;
991 int nTotal = Abc_TtCountOnesVec( pOn, nWords );
992 Vec_IntForEachEntryTwo( vUnateLits, vUnateLitsW, iDiv0, Cover0, i )
993 {
994 word * pDiv0 = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iDiv0));
995 if ( 2*Cover0 < nTotal )
996 break;
997 Vec_IntForEachEntryTwo( vUnatePairs, vUnatePairsW, iDiv1, Cover1, k )
998 {
999 int fComp1 = Abc_LitIsCompl(iDiv1);
1000 if ( Cover0 + Cover1 < nTotal )
1001 break;
1002 Gia_ManDeriveDivPair( iDiv1, vDivs, nWords, pDivTemp );
1003 if ( Gia_ManDivCover(pOff, pOn, pDiv0, Abc_LitIsCompl(iDiv0), pDivTemp, fComp1, nWords) )
1004 return Abc_Var2Lit((Abc_Var2Lit(k, 1) << 15) | Abc_LitNot(iDiv0), 1);
1005 }
1006 }
1007 return -1;
1008}
1009int Gia_ManFindDivGate( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits[2], Vec_Int_t * vUnatePairs[2], Vec_Int_t * vUnateLitsW[2], Vec_Int_t * vUnatePairsW[2], word * pDivTemp )
1010{
1011 int n, iLit;
1012 for ( n = 0; n < 2; n++ )
1013 {
1014 iLit = Gia_ManFindDivGateInt( pSets[n], pSets[!n], vDivs, nWords, vUnateLits[n], vUnatePairs[n], vUnateLitsW[n], vUnatePairsW[n], pDivTemp );
1015 if ( iLit >= 0 )
1016 return Abc_LitNotCond( iLit, n );
1017 }
1018 return -1;
1019}
1020
1021int Gia_ManFindGateGateInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnatePairs, Vec_Int_t * vUnatePairsW, word * pDivTempA, word * pDivTempB )
1022{
1023 int i, k, iDiv0, iDiv1, Cover0, Cover1;
1024 int nTotal = Abc_TtCountOnesVec( pOn, nWords );
1025 Vec_IntForEachEntryTwo( vUnatePairs, vUnatePairsW, iDiv0, Cover0, k )
1026 {
1027 int fCompA = Abc_LitIsCompl(iDiv0);
1028 if ( 2*Cover0 < nTotal )
1029 break;
1030 Gia_ManDeriveDivPair( iDiv0, vDivs, nWords, pDivTempA );
1031 Vec_IntForEachEntryTwoStart( vUnatePairs, vUnatePairsW, iDiv1, Cover1, i, k+1 )
1032 {
1033 int fCompB = Abc_LitIsCompl(iDiv1);
1034 if ( Cover0 + Cover1 < nTotal )
1035 break;
1036 Gia_ManDeriveDivPair( iDiv1, vDivs, nWords, pDivTempB );
1037 if ( Gia_ManDivCover(pOff, pOn, pDivTempA, fCompA, pDivTempB, fCompB, nWords) )
1038 return Abc_Var2Lit((Abc_Var2Lit(i, 1) << 15) | Abc_Var2Lit(k, 1), 1);
1039 }
1040 }
1041 return -1;
1042}
1043int Gia_ManFindGateGate( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnatePairs[2], Vec_Int_t * vUnatePairsW[2], word * pDivTempA, word * pDivTempB )
1044{
1045 int n, iLit;
1046 for ( n = 0; n < 2; n++ )
1047 {
1048 iLit = Gia_ManFindGateGateInt( pSets[n], pSets[!n], vDivs, nWords, vUnatePairs[n], vUnatePairsW[n], pDivTempA, pDivTempB );
1049 if ( iLit >= 0 )
1050 return Abc_LitNotCond( iLit, n );
1051 }
1052 return -1;
1053}
1054
1055void Gia_ManSortUnatesInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits, Vec_Int_t * vUnateLitsW, Vec_Wec_t * vSorter )
1056{
1057 int i, k, iLit;
1058 Vec_Int_t * vLevel;
1059 Vec_WecInit( vSorter, nWords*64 );
1060 Vec_IntForEachEntry( vUnateLits, iLit, i )
1061 {
1062 word * pDiv = (word *)Vec_PtrEntry(vDivs, Abc_Lit2Var(iLit));
1063 //assert( !Abc_TtIntersectOne( pOff, 0, pDiv, Abc_LitIsCompl(iLit), nWords ) );
1064 Vec_WecPush( vSorter, Abc_TtCountOnesVecMask(pDiv, pOn, nWords, Abc_LitIsCompl(iLit)), iLit );
1065 }
1066 Vec_IntClear( vUnateLits );
1067 Vec_IntClear( vUnateLitsW );
1068 Vec_WecForEachLevelReverse( vSorter, vLevel, k )
1069 Vec_IntForEachEntry( vLevel, iLit, i )
1070 {
1071 Vec_IntPush( vUnateLits, iLit );
1072 Vec_IntPush( vUnateLitsW, k );
1073 }
1074 //Vec_IntPrint( Vec_WecEntry(vSorter, 0) );
1075 Vec_WecClear( vSorter );
1076}
1077void Gia_ManSortUnates( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits[2], Vec_Int_t * vUnateLitsW[2], Vec_Wec_t * vSorter )
1078{
1079 int n;
1080 for ( n = 0; n < 2; n++ )
1081 Gia_ManSortUnatesInt( pSets[n], pSets[!n], vDivs, nWords, vUnateLits[n], vUnateLitsW[n], vSorter );
1082}
1083
1084void Gia_ManSortPairsInt( word * pOff, word * pOn, Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnatePairs, Vec_Int_t * vUnatePairsW, Vec_Wec_t * vSorter )
1085{
1086 int i, k, iPair;
1087 Vec_Int_t * vLevel;
1088 Vec_WecInit( vSorter, nWords*64 );
1089 Vec_IntForEachEntry( vUnatePairs, iPair, i )
1090 {
1091 int fComp = Abc_LitIsCompl(iPair);
1092 int iLit0 = Abc_Lit2Var(iPair) & 0x7FFF;
1093 int iLit1 = Abc_Lit2Var(iPair) >> 15;
1094 word * pDiv0 = (word *)Vec_PtrEntry( vDivs, Abc_Lit2Var(iLit0) );
1095 word * pDiv1 = (word *)Vec_PtrEntry( vDivs, Abc_Lit2Var(iLit1) );
1096 if ( iLit0 < iLit1 )
1097 {
1098 assert( !fComp );
1099 //assert( !Abc_TtIntersectTwo( pOff, 0, pDiv0, Abc_LitIsCompl(iLit0), pDiv1, Abc_LitIsCompl(iLit1), nWords ) );
1100 Vec_WecPush( vSorter, Abc_TtCountOnesVecMask2(pDiv0, pDiv1, Abc_LitIsCompl(iLit0), Abc_LitIsCompl(iLit1), pOn, nWords), iPair );
1101 }
1102 else
1103 {
1104 assert( !Abc_LitIsCompl(iLit0) );
1105 assert( !Abc_LitIsCompl(iLit1) );
1106 //assert( !Abc_TtIntersectXor( pOff, 0, pDiv0, pDiv1, fComp, nWords ) );
1107 Vec_WecPush( vSorter, Abc_TtCountOnesVecXorMask(pDiv0, pDiv1, fComp, pOn, nWords), iPair );
1108 }
1109 }
1110 Vec_IntClear( vUnatePairs );
1111 Vec_IntClear( vUnatePairsW );
1112 Vec_WecForEachLevelReverse( vSorter, vLevel, k )
1113 Vec_IntForEachEntry( vLevel, iPair, i )
1114 {
1115 Vec_IntPush( vUnatePairs, iPair );
1116 Vec_IntPush( vUnatePairsW, k );
1117 }
1118 //Vec_IntPrint( Vec_WecEntry(vSorter, 0) );
1119 Vec_WecClear( vSorter );
1120
1121}
1122void Gia_ManSortPairs( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vUnateLits[2], Vec_Int_t * vUnateLitsW[2], Vec_Wec_t * vSorter )
1123{
1124 int n;
1125 for ( n = 0; n < 2; n++ )
1126 Gia_ManSortPairsInt( pSets[n], pSets[!n], vDivs, nWords, vUnateLits[n], vUnateLitsW[n], vSorter );
1127}
1128
1129void Gia_ManSortBinate( word * pSets[2], Vec_Ptr_t * vDivs, int nWords, Vec_Int_t * vBinateVars, Vec_Wec_t * vSorter )
1130{
1131 Vec_Int_t * vLevel;
1132 int nMints[2] = { Abc_TtCountOnesVec(pSets[0], nWords), Abc_TtCountOnesVec(pSets[1], nWords) };
1133 word * pBig = nMints[0] > nMints[1] ? pSets[0] : pSets[1];
1134 word * pSmo = nMints[0] > nMints[1] ? pSets[1] : pSets[0];
1135 int Big = Abc_MaxInt( nMints[0], nMints[1] );
1136 int Smo = Abc_MinInt( nMints[0], nMints[1] );
1137 int i, k, iDiv, Gain;
1138
1139 Vec_WecInit( vSorter, nWords*64 );
1140 Vec_IntForEachEntry( vBinateVars, iDiv, i )
1141 {
1142 word * pDiv = (word *)Vec_PtrEntry( vDivs, iDiv );
1143 int nInter[2] = { Abc_TtCountOnesVecMask(pBig, pDiv, nWords, 0), Abc_TtCountOnesVecMask(pSmo, pDiv, nWords, 0) };
1144 if ( nInter[0] < Big/2 ) // complement the divisor
1145 {
1146 nInter[0] = Big - nInter[0];
1147 nInter[1] = Smo - nInter[1];
1148 }
1149 assert( nInter[0] >= Big/2 );
1150 Gain = Abc_MaxInt( 0, nInter[0] - Big/2 + Smo/2 - nInter[1] );
1151 Vec_WecPush( vSorter, Gain, iDiv );
1152 }
1153
1154 Vec_IntClear( vBinateVars );
1155 Vec_WecForEachLevelReverse( vSorter, vLevel, k )
1156 Vec_IntForEachEntry( vLevel, iDiv, i )
1157 Vec_IntPush( vBinateVars, iDiv );
1158 Vec_WecClear( vSorter );
1159
1160 if ( Vec_IntSize(vBinateVars) > 2000 )
1161 Vec_IntShrink( vBinateVars, 2000 );
1162}
1163
1176{
1177 int nMintsAll = Abc_TtCountOnesVec(p->pSets[0], p->nWords) + Abc_TtCountOnesVec(p->pSets[1], p->nWords);
1178 int i, iDiv, iLitBest = -1, CostBest = -1;
1179//Vec_IntPrint( p->vBinateVars );
1180//Dau_DsdPrintFromTruth( p->pSets[0], 6 );
1181//Dau_DsdPrintFromTruth( p->pSets[1], 6 );
1182 Vec_IntForEachEntry( p->vBinateVars, iDiv, i )
1183 {
1184 word * pDiv = (word *)Vec_PtrEntry(p->vDivs, iDiv);
1185 int nMints0 = Abc_TtCountOnesVecMask( pDiv, p->pSets[0], p->nWords, 0 );
1186 int nMints1 = Abc_TtCountOnesVecMask( pDiv, p->pSets[1], p->nWords, 0 );
1187 if ( CostBest < nMints0 + nMints1 )
1188 {
1189 CostBest = nMints0 + nMints1;
1190 iLitBest = Abc_Var2Lit( iDiv, 0 );
1191 }
1192 if ( CostBest < nMintsAll - nMints0 - nMints1 )
1193 {
1194 CostBest = nMintsAll - nMints0 - nMints1;
1195 iLitBest = Abc_Var2Lit( iDiv, 1 );
1196 }
1197 }
1198 return iLitBest;
1199}
1200int Gia_ManResubAddNode( Gia_ResbMan_t * p, int iLit0, int iLit1, int Type )
1201{
1202 int iNode = Vec_PtrSize(p->vDivs) + Vec_IntSize(p->vGates)/2;
1203 int fFlip = (Type == 2) ^ (iLit0 > iLit1);
1204 int iFan0 = fFlip ? iLit1 : iLit0;
1205 int iFan1 = fFlip ? iLit0 : iLit1;
1206 assert( iLit0 != iLit1 );
1207 if ( Type == 2 )
1208 assert( iFan0 > iFan1 );
1209 else
1210 assert( iFan0 < iFan1 );
1211 Vec_IntPushTwo( p->vGates, Abc_LitNotCond(iFan0, Type==1), Abc_LitNotCond(iFan1, Type==1) );
1212 return Abc_Var2Lit( iNode, Type==1 );
1213}
1214int Gia_ManResubPerformMux_rec( Gia_ResbMan_t * p, int nLimit, int Depth )
1215{
1216 extern int Gia_ManResubPerform_rec( Gia_ResbMan_t * p, int nLimit, int Depth );
1217 int iDivBest, iResLit0, iResLit1, nNodes;
1218 word * pDiv, * pCopy[2];
1219 if ( Depth == 0 )
1220 return -1;
1221 if ( nLimit < 3 )
1222 return -1;
1223 iDivBest = Gia_ManResubFindBestBinate( p );
1224 if ( iDivBest == -1 )
1225 return -1;
1226 pCopy[0] = ABC_CALLOC( word, p->nWords );
1227 pCopy[1] = ABC_CALLOC( word, p->nWords );
1228 Abc_TtCopy( pCopy[0], p->pSets[0], p->nWords, 0 );
1229 Abc_TtCopy( pCopy[1], p->pSets[1], p->nWords, 0 );
1230 pDiv = (word *)Vec_PtrEntry( p->vDivs, Abc_Lit2Var(iDivBest) );
1231 Abc_TtAndSharp( p->pSets[0], pCopy[0], pDiv, p->nWords, !Abc_LitIsCompl(iDivBest) );
1232 Abc_TtAndSharp( p->pSets[1], pCopy[1], pDiv, p->nWords, !Abc_LitIsCompl(iDivBest) );
1233 nNodes = Vec_IntSize(p->vGates)/2;
1234 //iResLit0 = Gia_ManResubPerform_rec( p, nLimit-3 );
1235 iResLit0 = Gia_ManResubPerform_rec( p, nLimit, 0 );
1236 if ( iResLit0 == -1 )
1237 iResLit0 = Gia_ManResubPerformMux_rec( p, nLimit, Depth-1 );
1238 if ( iResLit0 == -1 )
1239 {
1240 ABC_FREE( pCopy[0] );
1241 ABC_FREE( pCopy[1] );
1242 return -1;
1243 }
1244 Abc_TtAndSharp( p->pSets[0], pCopy[0], pDiv, p->nWords, Abc_LitIsCompl(iDivBest) );
1245 Abc_TtAndSharp( p->pSets[1], pCopy[1], pDiv, p->nWords, Abc_LitIsCompl(iDivBest) );
1246 ABC_FREE( pCopy[0] );
1247 ABC_FREE( pCopy[1] );
1248 nNodes = Vec_IntSize(p->vGates)/2 - nNodes;
1249 if ( nLimit-nNodes < 3 )
1250 return -1;
1251 //iResLit1 = Gia_ManResubPerform_rec( p, nLimit-3-nNodes );
1252 iResLit1 = Gia_ManResubPerform_rec( p, nLimit, 0 );
1253 if ( iResLit1 == -1 )
1254 iResLit1 = Gia_ManResubPerformMux_rec( p, nLimit, Depth-1 );
1255 if ( iResLit1 == -1 )
1256 return -1;
1257 else
1258 {
1259 int iLit0 = Gia_ManResubAddNode( p, Abc_LitNot(iDivBest), iResLit0, 0 );
1260 int iLit1 = Gia_ManResubAddNode( p, iDivBest, iResLit1, 0 );
1261 return Gia_ManResubAddNode( p, iLit0, iLit1, 1 );
1262 }
1263}
1264
1276int Gia_ManResubPerform_rec( Gia_ResbMan_t * p, int nLimit, int Depth )
1277{
1278 int TopOneW[2] = {0}, TopTwoW[2] = {0}, Max1, Max2, iResLit, nVars = Vec_PtrSize(p->vDivs);
1279 if ( p->fVerbose )
1280 {
1281 int nMints[2] = { Abc_TtCountOnesVec(p->pSets[0], p->nWords), Abc_TtCountOnesVec(p->pSets[1], p->nWords) };
1282 printf( " " );
1283 printf( "ISF: " );
1284 printf( "0=%5d (%5.2f %%) ", nMints[0], 100.0*nMints[0]/(64*p->nWords) );
1285 printf( "1=%5d (%5.2f %%) ", nMints[1], 100.0*nMints[1]/(64*p->nWords) );
1286 }
1287 if ( Abc_TtIsConst0( p->pSets[1], p->nWords ) )
1288 return 0;
1289 if ( Abc_TtIsConst0( p->pSets[0], p->nWords ) )
1290 return 1;
1291 iResLit = Gia_ManFindOneUnate( p->pSets, p->vDivs, p->nWords, p->vUnateLits, p->vNotUnateVars, p->fVerbose );
1292 if ( iResLit >= 0 ) // buffer
1293 return iResLit;
1294 if ( nLimit == 0 )
1295 return -1;
1296 Gia_ManSortUnates( p->pSets, p->vDivs, p->nWords, p->vUnateLits, p->vUnateLitsW, p->vSorter );
1297 iResLit = Gia_ManFindTwoUnate( p->pSets, p->vDivs, p->nWords, p->vUnateLits, p->vUnateLitsW, p->fVerbose );
1298 if ( iResLit >= 0 ) // and
1299 {
1300 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1301 int fComp = Abc_LitIsCompl(iResLit);
1302 int iDiv0 = Abc_Lit2Var(iResLit) & 0x7FFF;
1303 int iDiv1 = Abc_Lit2Var(iResLit) >> 15;
1304 assert( iDiv0 < iDiv1 );
1305 Vec_IntPushTwo( p->vGates, iDiv0, iDiv1 );
1306 return Abc_Var2Lit( iNode, fComp );
1307 }
1308 Vec_IntTwoFindCommon( p->vNotUnateVars[0], p->vNotUnateVars[1], p->vBinateVars );
1309 if ( Depth )
1310 return Gia_ManResubPerformMux_rec( p, nLimit, Depth );
1311 if ( Vec_IntSize(p->vBinateVars) > p->nDivsMax )
1312 Vec_IntShrink( p->vBinateVars, p->nDivsMax );
1313 if ( p->fVerbose ) printf( " B = %3d", Vec_IntSize(p->vBinateVars) );
1314 //Gia_ManSortBinate( p->pSets, p->vDivs, p->nWords, p->vBinateVars, p->vSorter );
1315 if ( p->fUseXor )
1316 {
1317 iResLit = Gia_ManFindXor( p->pSets, p->vDivs, p->nWords, p->vBinateVars, p->vUnatePairs, p->fVerbose );
1318 if ( iResLit >= 0 ) // xor
1319 {
1320 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1321 int fComp = Abc_LitIsCompl(iResLit);
1322 int iDiv0 = Abc_Lit2Var(iResLit) & 0x7FFF;
1323 int iDiv1 = Abc_Lit2Var(iResLit) >> 15;
1324 assert( !Abc_LitIsCompl(iDiv0) );
1325 assert( !Abc_LitIsCompl(iDiv1) );
1326 assert( iDiv0 > iDiv1 );
1327 Vec_IntPushTwo( p->vGates, iDiv0, iDiv1 );
1328 return Abc_Var2Lit( iNode, fComp );
1329 }
1330 }
1331 if ( nLimit == 1 )
1332 return -1;
1333 Gia_ManFindUnatePairs( p->pSets, p->vDivs, p->nWords, p->vBinateVars, p->vUnatePairs, p->fVerbose );
1334 Gia_ManSortPairs( p->pSets, p->vDivs, p->nWords, p->vUnatePairs, p->vUnatePairsW, p->vSorter );
1335 iResLit = Gia_ManFindDivGate( p->pSets, p->vDivs, p->nWords, p->vUnateLits, p->vUnatePairs, p->vUnateLitsW, p->vUnatePairsW, p->pDivA );
1336 if ( iResLit >= 0 ) // and(div,pair)
1337 {
1338 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1339
1340 int fComp = Abc_LitIsCompl(iResLit);
1341 int iDiv0 = Abc_Lit2Var(iResLit) & 0x7FFF; // div
1342 int iDiv1 = Abc_Lit2Var(iResLit) >> 15; // pair
1343
1344 int Div1 = Vec_IntEntry( p->vUnatePairs[!fComp], Abc_Lit2Var(iDiv1) );
1345 int fComp1 = Abc_LitIsCompl(Div1) ^ Abc_LitIsCompl(iDiv1);
1346 int iDiv10 = Abc_Lit2Var(Div1) & 0x7FFF;
1347 int iDiv11 = Abc_Lit2Var(Div1) >> 15;
1348
1349 Vec_IntPushTwo( p->vGates, iDiv10, iDiv11 );
1350 Vec_IntPushTwo( p->vGates, iDiv0, Abc_Var2Lit(iNode, fComp1) );
1351 return Abc_Var2Lit( iNode+1, fComp );
1352 }
1353// if ( nLimit == 2 )
1354// return -1;
1355 if ( nLimit >= 3 )
1356 {
1357 iResLit = Gia_ManFindGateGate( p->pSets, p->vDivs, p->nWords, p->vUnatePairs, p->vUnatePairsW, p->pDivA, p->pDivB );
1358 if ( iResLit >= 0 ) // and(pair,pair)
1359 {
1360 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1361
1362 int fComp = Abc_LitIsCompl(iResLit);
1363 int iDiv0 = Abc_Lit2Var(iResLit) & 0x7FFF; // pair
1364 int iDiv1 = Abc_Lit2Var(iResLit) >> 15; // pair
1365
1366 int Div0 = Vec_IntEntry( p->vUnatePairs[!fComp], Abc_Lit2Var(iDiv0) );
1367 int fComp0 = Abc_LitIsCompl(Div0) ^ Abc_LitIsCompl(iDiv0);
1368 int iDiv00 = Abc_Lit2Var(Div0) & 0x7FFF;
1369 int iDiv01 = Abc_Lit2Var(Div0) >> 15;
1370
1371 int Div1 = Vec_IntEntry( p->vUnatePairs[!fComp], Abc_Lit2Var(iDiv1) );
1372 int fComp1 = Abc_LitIsCompl(Div1) ^ Abc_LitIsCompl(iDiv1);
1373 int iDiv10 = Abc_Lit2Var(Div1) & 0x7FFF;
1374 int iDiv11 = Abc_Lit2Var(Div1) >> 15;
1375
1376 Vec_IntPushTwo( p->vGates, iDiv00, iDiv01 );
1377 Vec_IntPushTwo( p->vGates, iDiv10, iDiv11 );
1378 Vec_IntPushTwo( p->vGates, Abc_Var2Lit(iNode, fComp0), Abc_Var2Lit(iNode+1, fComp1) );
1379 return Abc_Var2Lit( iNode+2, fComp );
1380 }
1381 }
1382// if ( nLimit == 3 )
1383// return -1;
1384 if ( Vec_IntSize(p->vUnateLits[0]) + Vec_IntSize(p->vUnateLits[1]) + Vec_IntSize(p->vUnatePairs[0]) + Vec_IntSize(p->vUnatePairs[1]) == 0 )
1385 return -1;
1386
1387 TopOneW[0] = Vec_IntSize(p->vUnateLitsW[0]) ? Vec_IntEntry(p->vUnateLitsW[0], 0) : 0;
1388 TopOneW[1] = Vec_IntSize(p->vUnateLitsW[1]) ? Vec_IntEntry(p->vUnateLitsW[1], 0) : 0;
1389
1390 TopTwoW[0] = Vec_IntSize(p->vUnatePairsW[0]) ? Vec_IntEntry(p->vUnatePairsW[0], 0) : 0;
1391 TopTwoW[1] = Vec_IntSize(p->vUnatePairsW[1]) ? Vec_IntEntry(p->vUnatePairsW[1], 0) : 0;
1392
1393 Max1 = Abc_MaxInt(TopOneW[0], TopOneW[1]);
1394 Max2 = Abc_MaxInt(TopTwoW[0], TopTwoW[1]);
1395 if ( Abc_MaxInt(Max1, Max2) == 0 )
1396 return -1;
1397
1398 if ( Max1 > Max2/2 )
1399 {
1400 if ( nLimit >= 2 && (Max1 == TopOneW[0] || Max1 == TopOneW[1]) )
1401 {
1402 int fUseOr = Max1 == TopOneW[0];
1403 int iDiv = Vec_IntEntry( p->vUnateLits[!fUseOr], 0 );
1404 int fComp = Abc_LitIsCompl(iDiv);
1405 word * pDiv = (word *)Vec_PtrEntry( p->vDivs, Abc_Lit2Var(iDiv) );
1406 Abc_TtAndSharp( p->pSets[fUseOr], p->pSets[fUseOr], pDiv, p->nWords, !fComp );
1407 if ( p->fVerbose )
1408 printf( "\n" );
1409 iResLit = Gia_ManResubPerform_rec( p, nLimit-1, Depth );
1410 if ( iResLit >= 0 )
1411 {
1412 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1413 if ( iDiv < iResLit )
1414 Vec_IntPushTwo( p->vGates, Abc_LitNot(iDiv), Abc_LitNotCond(iResLit, fUseOr) );
1415 else
1416 Vec_IntPushTwo( p->vGates, Abc_LitNotCond(iResLit, fUseOr), Abc_LitNot(iDiv) );
1417 return Abc_Var2Lit( iNode, fUseOr );
1418 }
1419 }
1420 if ( Max2 == 0 )
1421 return -1;
1422/*
1423 if ( Max2 == TopTwoW[0] || Max2 == TopTwoW[1] )
1424 {
1425 int fUseOr = Max2 == TopTwoW[0];
1426 int iDiv = Vec_IntEntry( p->vUnatePairs[!fUseOr], 0 );
1427 int fComp = Abc_LitIsCompl(iDiv);
1428 Gia_ManDeriveDivPair( iDiv, p->vDivs, p->nWords, p->pDivA );
1429 Abc_TtAndSharp( p->pSets[fUseOr], p->pSets[fUseOr], p->pDivA, p->nWords, !fComp );
1430 if ( p->fVerbose )
1431 printf( "\n " );
1432 iResLit = Gia_ManResubPerform_rec( p, nLimit-2 );
1433 if ( iResLit >= 0 )
1434 {
1435 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1436 int iDiv0 = Abc_Lit2Var(iDiv) & 0x7FFF;
1437 int iDiv1 = Abc_Lit2Var(iDiv) >> 15;
1438 Vec_IntPushTwo( p->vGates, iDiv0, iDiv1 );
1439 Vec_IntPushTwo( p->vGates, Abc_LitNotCond(iResLit, fUseOr), Abc_Var2Lit(iNode, !fComp) );
1440 return Abc_Var2Lit( iNode+1, fUseOr );
1441 }
1442 }
1443*/
1444 }
1445 else
1446 {
1447 if ( nLimit >= 3 && (Max2 == TopTwoW[0] || Max2 == TopTwoW[1]) )
1448 {
1449 int fUseOr = Max2 == TopTwoW[0];
1450 int iDiv = Vec_IntEntry( p->vUnatePairs[!fUseOr], 0 );
1451 int fComp = Abc_LitIsCompl(iDiv);
1452 Gia_ManDeriveDivPair( iDiv, p->vDivs, p->nWords, p->pDivA );
1453 Abc_TtAndSharp( p->pSets[fUseOr], p->pSets[fUseOr], p->pDivA, p->nWords, !fComp );
1454 if ( p->fVerbose )
1455 printf( "\n" );
1456 iResLit = Gia_ManResubPerform_rec( p, nLimit-2, Depth );
1457 if ( iResLit >= 0 )
1458 {
1459 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1460 int iDiv0 = Abc_Lit2Var(iDiv) & 0x7FFF;
1461 int iDiv1 = Abc_Lit2Var(iDiv) >> 15;
1462 Vec_IntPushTwo( p->vGates, iDiv0, iDiv1 );
1463 Vec_IntPushTwo( p->vGates, Abc_LitNotCond(iResLit, fUseOr), Abc_Var2Lit(iNode, !fComp) );
1464 return Abc_Var2Lit( iNode+1, fUseOr );
1465 }
1466 }
1467 if ( Max1 == 0 )
1468 return -1;
1469/*
1470 if ( Max1 == TopOneW[0] || Max1 == TopOneW[1] )
1471 {
1472 int fUseOr = Max1 == TopOneW[0];
1473 int iDiv = Vec_IntEntry( p->vUnateLits[!fUseOr], 0 );
1474 int fComp = Abc_LitIsCompl(iDiv);
1475 word * pDiv = (word *)Vec_PtrEntry( p->vDivs, Abc_Lit2Var(iDiv) );
1476 Abc_TtAndSharp( p->pSets[fUseOr], p->pSets[fUseOr], pDiv, p->nWords, !fComp );
1477 if ( p->fVerbose )
1478 printf( "\n " );
1479 iResLit = Gia_ManResubPerform_rec( p, nLimit-1 );
1480 if ( iResLit >= 0 )
1481 {
1482 int iNode = nVars + Vec_IntSize(p->vGates)/2;
1483 Vec_IntPushTwo( p->vGates, Abc_LitNot(iDiv), Abc_LitNotCond(iResLit, fUseOr) );
1484 return Abc_Var2Lit( iNode, fUseOr );
1485 }
1486 }
1487*/
1488 }
1489 return -1;
1490}
1491void Gia_ManResubPerform( Gia_ResbMan_t * p, Vec_Ptr_t * vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int Depth )
1492{
1493 int Res;
1494 Gia_ResbInit( p, vDivs, nWords, nLimit, nDivsMax, iChoice, fUseXor, fDebug, fVerbose, fVerbose );
1495 Res = Gia_ManResubPerform_rec( p, nLimit, Depth );
1496 if ( Res >= 0 )
1497 Vec_IntPush( p->vGates, Res );
1498 else
1499 Vec_IntClear( p->vGates );
1500 if ( fVerbose )
1501 printf( "\n" );
1502}
1503Vec_Int_t * Gia_ManResubOne( Vec_Ptr_t * vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, word * pFunc, int Depth )
1504{
1505 Vec_Int_t * vRes;
1507 Gia_ManResubPerform( p, vDivs, nWords, nLimit, nDivsMax, iChoice, fUseXor, fDebug, fVerbose, Depth );
1508 if ( fVerbose )
1509 Gia_ManResubPrint( p->vGates, Vec_PtrSize(vDivs) );
1510 //if ( fVerbose )
1511 // printf( "\n" );
1512 if ( !Gia_ManResubVerify(p, pFunc) )
1513 {
1514 Gia_ManResubPrint( p->vGates, Vec_PtrSize(vDivs) );
1515 printf( "Verification FAILED.\n" );
1516 }
1517 else if ( fDebug && fVerbose )
1518 printf( "Verification succeeded." );
1519 if ( fVerbose )
1520 printf( "\n" );
1521 vRes = Vec_IntDup( p->vGates );
1522 Gia_ResbFree( p );
1523 return vRes;
1524}
1525
1537static Gia_ResbMan_t * s_pResbMan = NULL;
1538
1540{
1541 if ( s_pResbMan != NULL )
1542 Gia_ResbFree( s_pResbMan );
1543 s_pResbMan = NULL;
1544 if ( nWords > 0 )
1545 s_pResbMan = Gia_ResbAlloc( nWords );
1546}
1547
1548int Abc_ResubComputeFunction( void ** ppDivs, int nDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int ** ppArray )
1549{
1550 Vec_Ptr_t Divs = { nDivs, nDivs, ppDivs };
1551 assert( s_pResbMan != NULL ); // first call Abc_ResubPrepareManager()
1552 Gia_ManResubPerform( s_pResbMan, &Divs, nWords, nLimit, nDivsMax, iChoice, fUseXor, fDebug, fVerbose==2, 0 );
1553 if ( fVerbose )
1554 {
1555 int nGates = Vec_IntSize(s_pResbMan->vGates)/2;
1556 if ( nGates )
1557 {
1558 printf( " Gain = %2d Gates = %2d __________ F = ", nLimit+1-nGates, nGates );
1559 Gia_ManResubPrint( s_pResbMan->vGates, nDivs );
1560 printf( "\n" );
1561 }
1562 }
1563 if ( fDebug )
1564 {
1565 if ( !Gia_ManResubVerify(s_pResbMan, NULL) )
1566 {
1567 Gia_ManResubPrint( s_pResbMan->vGates, nDivs );
1568 printf( "Verification FAILED.\n" );
1569 }
1570 //else
1571 // printf( "Verification succeeded.\n" );
1572 }
1573 *ppArray = Vec_IntArray(s_pResbMan->vGates);
1574 assert( Vec_IntSize(s_pResbMan->vGates)/2 <= nLimit );
1575 return Vec_IntSize(s_pResbMan->vGates);
1576}
1577
1578void Abc_ResubDumpProblem( char * pFileName, void ** ppDivs, int nDivs, int nWords )
1579{
1580 Vec_Wrd_t * vSims = Vec_WrdAlloc( nDivs * nWords );
1581 word ** pDivs = (word **)ppDivs;
1582 int d, w;
1583 for ( d = 0; d < nDivs; d++ )
1584 for ( w = 0; w < nWords; w++ )
1585 Vec_WrdPush( vSims, pDivs[d][w] );
1586 Vec_WrdDumpHex( pFileName, vSims, nWords, 1 );
1587 Vec_WrdFree( vSims );
1588}
1589
1601
1602extern void Extra_PrintHex( FILE * pFile, unsigned * pTruth, int nVars );
1603extern void Dau_DsdPrintFromTruth2( word * pTruth, int nVarsInit );
1604
1606{
1607 int nVars = 4;
1608 int fVerbose = 1;
1609 word Divs[6] = { 0, 0,
1610 ABC_CONST(0xAAAAAAAAAAAAAAAA),
1611 ABC_CONST(0xCCCCCCCCCCCCCCCC),
1612 ABC_CONST(0xF0F0F0F0F0F0F0F0),
1613 ABC_CONST(0xFF00FF00FF00FF00)
1614 };
1615 Vec_Ptr_t * vDivs = Vec_PtrAlloc( 6 );
1616 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
1617 int i, k, ArraySize, * pArray;
1618 for ( i = 0; i < 6; i++ )
1619 Vec_PtrPush( vDivs, Divs+i );
1621 for ( i = 0; i < (1<<(1<<nVars)); i++ ) //if ( i == 0xCA )
1622 {
1623 word Truth = Abc_Tt6Stretch( i, nVars );
1624 Divs[0] = ~Truth;
1625 Divs[1] = Truth;
1626 printf( "%3d : ", i );
1627 Extra_PrintHex( stdout, (unsigned*)&Truth, nVars );
1628 printf( " " );
1629 Dau_DsdPrintFromTruth2( &Truth, nVars );
1630 printf( " " );
1631
1632 //Abc_ResubDumpProblem( "temp.resub", (void **)Vec_PtrArray(vDivs), Vec_PtrSize(vDivs), 1 );
1633 ArraySize = Abc_ResubComputeFunction( (void **)Vec_PtrArray(vDivs), Vec_PtrSize(vDivs), 1, 16, 50, 0, 0, 1, fVerbose, &pArray );
1634 printf( "\n" );
1635
1636 Vec_IntClear( vRes );
1637 for ( k = 0; k < ArraySize; k++ )
1638 Vec_IntPush( vRes, pArray[k] );
1639
1640 if ( i == 1000 )
1641 break;
1642 }
1644 Vec_IntFree( vRes );
1645 Vec_PtrFree( vDivs );
1646}
1648{
1649 Gia_ResbMan_t * p = Gia_ResbAlloc( 1 );
1650 word Divs[6] = { 0, 0,
1651 ABC_CONST(0xAAAAAAAAAAAAAAAA),
1652 ABC_CONST(0xCCCCCCCCCCCCCCCC),
1653 ABC_CONST(0xF0F0F0F0F0F0F0F0),
1654 ABC_CONST(0xFF00FF00FF00FF00)
1655 };
1656 Vec_Ptr_t * vDivs = Vec_PtrAlloc( 6 );
1657 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
1658 int i;
1659 for ( i = 0; i < 6; i++ )
1660 Vec_PtrPush( vDivs, Divs+i );
1661
1662 {
1663 word Truth = (Divs[2] | Divs[3]) & (Divs[4] & Divs[5]);
1664// word Truth = (~Divs[2] | Divs[3]) | ~Divs[4];
1665 Divs[0] = ~Truth;
1666 Divs[1] = Truth;
1667 Extra_PrintHex( stdout, (unsigned*)&Truth, 6 );
1668 printf( " " );
1669 Dau_DsdPrintFromTruth2( &Truth, 6 );
1670 printf( " " );
1671 Gia_ManResubPerform( p, vDivs, 1, 100, 0, 50, 1, 1, 0, 0 );
1672 }
1673 Gia_ResbFree( p );
1674 Vec_IntFree( vRes );
1675 Vec_PtrFree( vDivs );
1676}
1677
1689void Gia_ManResubPair( Vec_Wrd_t * vOn, Vec_Wrd_t * vOff, int nWords, int nIns )
1690{
1692 Vec_Ptr_t * vDivs = Vec_PtrAllocSimInfo( nIns+2, nWords*2 );
1693 word * pSim; int i;
1694 Vec_PtrForEachEntry( word *, vDivs, pSim, i )
1695 {
1696 if ( i == 0 )
1697 {
1698 memset( pSim, 0x00, sizeof(word)*nWords );
1699 memset( pSim+nWords, 0xFF, sizeof(word)*nWords );
1700 }
1701 else if ( i == 1 )
1702 {
1703 memset( pSim, 0xFF, sizeof(word)*nWords );
1704 memset( pSim+nWords, 0x00, sizeof(word)*nWords );
1705 }
1706 else
1707 {
1708 memmove( pSim, Vec_WrdEntryP(vOn, (i-2)*nWords), sizeof(word)*nWords );
1709 memmove( pSim+nWords, Vec_WrdEntryP(vOff, (i-2)*nWords), sizeof(word)*nWords );
1710 }
1711 }
1712 Gia_ManResubPerform( p, vDivs, nWords*2, 100, 0, 50, 1, 1, 0, 0 );
1713 Gia_ManResubPrint( p->vGates, Vec_PtrSize(vDivs) );
1714 printf( "\n" );
1715 //Vec_PtrFree( vDivs );
1716 Gia_ResbFree( p );
1717}
1718
1731{
1732 //int i, nVars = 6, pVarSet[10] = { 2, 189, 2127, 2125, 177, 178 };
1733 int i, nVars = 3, pVarSet[10] = { 2, 3, 4 };
1734 word * pOff = (word *)Vec_PtrEntry( vDivs, 0 );
1735 word * pOn = (word *)Vec_PtrEntry( vDivs, 1 );
1736 Vec_Int_t * vValue = Vec_IntStartFull( 1 << 6 );
1737 printf( "Verifying resub:\n" );
1738 for ( i = 0; i < 64*nWords; i++ )
1739 {
1740 int v, Mint = 0, Value = Abc_TtGetBit(pOn, i);
1741 if ( !Abc_TtGetBit(pOff, i) && !Value )
1742 continue;
1743 for ( v = 0; v < nVars; v++ )
1744 if ( Abc_TtGetBit((word *)Vec_PtrEntry(vDivs, pVarSet[v]), i) )
1745 Mint |= 1 << v;
1746 if ( Vec_IntEntry(vValue, Mint) == -1 )
1747 Vec_IntWriteEntry(vValue, Mint, Value);
1748 else if ( Vec_IntEntry(vValue, Mint) != Value )
1749 printf( "Mismatch in pattern %d\n", i );
1750 }
1751 printf( "Finished verifying resub.\n" );
1752 Vec_IntFree( vValue );
1753}
1755{
1756 int i, nDivs = Vec_WrdSize(vSims)/nWords;
1757 Vec_Ptr_t * vDivs = Vec_PtrAlloc( nDivs );
1758 for ( i = 0; i < nDivs; i++ )
1759 Vec_PtrPush( vDivs, Vec_WrdEntryP(vSims, nWords*i) );
1760 return vDivs;
1761}
1762Gia_Man_t * Gia_ManResub2( Gia_Man_t * pGia, int nNodes, int nSupp, int nDivs, int iChoice, int fUseXor, int fVerbose, int fVeryVerbose )
1763{
1764 return NULL;
1765}
1766Gia_Man_t * Gia_ManResub1( char * pFileName, int nNodes, int nSupp, int nDivs, int iChoice, int fUseXor, int fVerbose, int fVeryVerbose )
1767{
1768 int nWords = 0;
1769 Gia_Man_t * pMan = NULL;
1770 Vec_Wrd_t * vSims = Vec_WrdReadHex( pFileName, &nWords, 1 );
1771 Vec_Ptr_t * vDivs = vSims ? Gia_ManDeriveDivs( vSims, nWords ) : NULL;
1773 //Gia_ManCheckResub( vDivs, nWords );
1774 if ( Vec_PtrSize(vDivs) >= (1<<14) )
1775 {
1776 printf( "Reducing all divs from %d to %d.\n", Vec_PtrSize(vDivs), (1<<14)-1 );
1777 Vec_PtrShrink( vDivs, (1<<14)-1 );
1778 }
1779 assert( Vec_PtrSize(vDivs) < (1<<14) );
1780 Gia_ManResubPerform( p, vDivs, nWords, 100, 50, iChoice, fUseXor, 1, 1, 0 );
1781 if ( Vec_IntSize(p->vGates) )
1782 {
1783 Vec_Wec_t * vGates = Vec_WecStart(1);
1784 Vec_IntAppend( Vec_WecEntry(vGates, 0), p->vGates );
1785 pMan = Gia_ManConstructFromGates( vGates, Vec_PtrSize(vDivs) );
1786 Vec_WecFree( vGates );
1787 }
1788 else
1789 printf( "Decomposition did not succeed.\n" );
1790 Gia_ResbFree( p );
1791 Vec_PtrFree( vDivs );
1792 Vec_WrdFree( vSims );
1793 return pMan;
1794}
1795
1807int Gia_ManUnivTfo_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vNodes, Vec_Int_t * vPos )
1808{
1809 int i, iFan, Count = 1;
1810 if ( Gia_ObjIsTravIdCurrentId(p, iObj) )
1811 return 0;
1812 Gia_ObjSetTravIdCurrentId(p, iObj);
1813 if ( vNodes && Gia_ObjIsCo(Gia_ManObj(p, iObj)) )
1814 Vec_IntPush( vNodes, iObj );
1815 if ( vPos && Gia_ObjIsCo(Gia_ManObj(p, iObj)) )
1816 Vec_IntPush( vPos, iObj );
1817 Gia_ObjForEachFanoutStaticId( p, iObj, iFan, i )
1818 Count += Gia_ManUnivTfo_rec( p, iFan, vNodes, vPos );
1819 return Count;
1820}
1821int Gia_ManUnivTfo( Gia_Man_t * p, int * pObjs, int nObjs, Vec_Int_t ** pvNodes, Vec_Int_t ** pvPos )
1822{
1823 int i, Count = 0;
1824 if ( pvNodes )
1825 {
1826 if ( *pvNodes )
1827 Vec_IntClear( *pvNodes );
1828 else
1829 *pvNodes = Vec_IntAlloc( 100 );
1830 }
1831 if ( pvPos )
1832 {
1833 if ( *pvPos )
1834 Vec_IntClear( *pvPos );
1835 else
1836 *pvPos = Vec_IntAlloc( 100 );
1837 }
1839 for ( i = 0; i < nObjs; i++ )
1840 Count += Gia_ManUnivTfo_rec( p, pObjs[i], pvNodes ? *pvNodes : NULL, pvPos ? *pvPos : NULL );
1841 if ( pvNodes )
1842 Vec_IntSort( *pvNodes, 0 );
1843 if ( pvPos )
1844 Vec_IntSort( *pvPos, 0 );
1845 return Count;
1846}
1847
1860{
1861 int nLimit = 20;
1862 int nDivsMax = 200;
1863 int iChoice = 0;
1864 int fUseXor = 1;
1865 int fDebug = 1;
1866 int fVerbose = 0;
1867 abctime clk, clkResub = 0, clkStart = Abc_Clock();
1868 Vec_Ptr_t * vvSims = Vec_PtrAlloc( 100 );
1869 Vec_Wrd_t * vSims;
1870 word * pSets[2], * pFunc;
1871 Gia_Obj_t * pObj, * pObj2;
1872 int i, i2, nWords, nNonDec = 0, nTotal = 0;
1873 assert( Gia_ManCiNum(p) < 16 );
1874 Vec_WrdFreeP( &p->vSimsPi );
1875 p->vSimsPi = Vec_WrdStartTruthTables( Gia_ManCiNum(p) );
1876 nWords = Vec_WrdSize(p->vSimsPi) / Gia_ManCiNum(p);
1877 //Vec_WrdPrintHex( p->vSimsPi, nWords );
1878 pSets[0] = ABC_CALLOC( word, nWords );
1879 pSets[1] = ABC_CALLOC( word, nWords );
1880 vSims = Gia_ManSimPatSim( p );
1885 Gia_ManForEachAnd( p, pObj, i )
1886 {
1887 Vec_Int_t vGates;
1888 int * pArray, nArray, nTfo, iObj = Gia_ObjId(p, pObj);
1889 int Level = Gia_ObjLevel(p, pObj);
1890 int nMffc = Gia_NodeMffcSizeMark(p, pObj);
1891 pFunc = Vec_WrdEntryP( vSims, nWords*iObj );
1892 Abc_TtCopy( pSets[0], pFunc, nWords, 1 );
1893 Abc_TtCopy( pSets[1], pFunc, nWords, 0 );
1894 Vec_PtrClear( vvSims );
1895 Vec_PtrPushTwo( vvSims, pSets[0], pSets[1] );
1896 nTfo = Gia_ManUnivTfo( p, &iObj, 1, NULL, NULL );
1897 Gia_ManForEachCi( p, pObj2, i2 )
1898 Vec_PtrPush( vvSims, Vec_WrdEntryP(vSims, nWords*Gia_ObjId(p, pObj2)) );
1899 Gia_ManForEachAnd( p, pObj2, i2 )
1900 if ( !Gia_ObjIsTravIdCurrent(p, pObj2) && !Gia_ObjIsTravIdPrevious(p, pObj2) && Gia_ObjLevel(p, pObj2) <= Level )
1901 Vec_PtrPush( vvSims, Vec_WrdEntryP(vSims, nWords*Gia_ObjId(p, pObj2)) );
1902 if ( fVerbose )
1903 printf( "%3d : Lev = %2d Mffc = %2d Divs = %3d Tfo = %3d\n", iObj, Level, nMffc, Vec_PtrSize(vvSims)-2, nTfo );
1904 clk = Abc_Clock();
1905 nArray = Abc_ResubComputeFunction( (void **)Vec_PtrArray(vvSims), Vec_PtrSize(vvSims), nWords, Abc_MinInt(nMffc-1, nLimit), nDivsMax, iChoice, fUseXor, fDebug, fVerbose, &pArray );
1906 clkResub += Abc_Clock() - clk;
1907 vGates.nSize = vGates.nCap = nArray;
1908 vGates.pArray = pArray;
1909 assert( nMffc > Vec_IntSize(&vGates)/2 );
1910 if ( Vec_IntSize(&vGates) > 0 )
1911 nTotal += nMffc - Vec_IntSize(&vGates)/2;
1912 nNonDec += Vec_IntSize(&vGates) == 0;
1913 }
1914 printf( "Total nodes = %5d. Non-realizable = %5d. Gain = %6d. ", Gia_ManAndNum(p), nNonDec, nTotal );
1915 Abc_PrintTime( 1, "Time", Abc_Clock() - clkStart );
1916 Abc_PrintTime( 1, "Pure resub time", clkResub );
1919 Vec_PtrFree( vvSims );
1920 Vec_WrdFree( vSims );
1921 ABC_FREE( pSets[0] );
1922 ABC_FREE( pSets[1] );
1923}
1924
1925
1938{
1939 int i, k = 0, nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
1940 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
1941 for ( i = 0; i < nFuncs; i++ )
1942 {
1943 word * pFunc0 = Vec_WrdEntryP(vFuncs, (2*i+0)*nWords);
1944 word * pFunc1 = Vec_WrdEntryP(vFuncs, (2*i+1)*nWords);
1945 if ( Abc_TtIsConst0(pFunc0, nWords) || Abc_TtIsConst0(pFunc1, nWords) )
1946 continue;
1947 if ( k < i ) Abc_TtCopy( Vec_WrdEntryP(vFuncs, (2*k+0)*nWords), pFunc0, nWords, 0 );
1948 if ( k < i ) Abc_TtCopy( Vec_WrdEntryP(vFuncs, (2*k+1)*nWords), pFunc1, nWords, 0 );
1949 k++;
1950 }
1951 Vec_WrdShrink( vFuncs, 2*k*nWords );
1952 return k;
1953}
1954void Gia_ManDeriveCounts( Vec_Wrd_t * vFuncs, int nWords, Vec_Int_t * vCounts )
1955{
1956 int i, nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
1957 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
1958 Vec_IntClear( vCounts );
1959 for ( i = 0; i < 2*nFuncs; i++ )
1960 Vec_IntPush( vCounts, Abc_TtCountOnesVec(Vec_WrdEntryP(vFuncs, i*nWords), nWords) );
1961}
1962int Gia_ManDeriveCost( Vec_Wrd_t * vFuncs, int nWords, word * pMask, Vec_Int_t * vCounts )
1963{
1964 int i, Res = 0, nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
1965 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
1966 assert( Vec_IntSize(vCounts) * nWords == Vec_WrdSize(vFuncs) );
1967 for ( i = 0; i < nFuncs; i++ )
1968 {
1969 int Total[2] = { Vec_IntEntry(vCounts, 2*i+0), Vec_IntEntry(vCounts, 2*i+1) };
1970 int This[2] = { Abc_TtCountOnesVecMask(Vec_WrdEntryP(vFuncs, (2*i+0)*nWords), pMask, nWords, 0),
1971 Abc_TtCountOnesVecMask(Vec_WrdEntryP(vFuncs, (2*i+1)*nWords), pMask, nWords, 0) };
1972 assert( Total[0] >= This[0] && Total[1] >= This[1] );
1973 Res += This[0] * This[1] + (Total[0] - This[0]) * (Total[1] - This[1]);
1974 }
1975 return Res;
1976}
1978{
1979 int i, Ent1, Ent2, Res = 0;
1980 Vec_IntForEachEntryDouble( vCounts, Ent1, Ent2, i )
1981 Res += Ent1*Ent2;
1982 return Res;
1983}
1984void Gia_ManDeriveNext( Vec_Wrd_t * vFuncs, int nWords, word * pMask )
1985{
1986 int i, iStop = Vec_WrdSize(vFuncs); word Data;
1987 int nFuncs = Vec_WrdSize(vFuncs) / nWords / 2;
1988 assert( 2 * nFuncs * nWords == Vec_WrdSize(vFuncs) );
1989 Vec_WrdForEachEntryStop( vFuncs, Data, i, iStop )
1990 Vec_WrdPush( vFuncs, Data );
1991 for ( i = 0; i < nFuncs; i++ )
1992 {
1993 word * pFunc0n = Vec_WrdEntryP(vFuncs, (2*i+0)*nWords);
1994 word * pFunc1n = Vec_WrdEntryP(vFuncs, (2*i+1)*nWords);
1995 word * pFunc0p = Vec_WrdEntryP(vFuncs, (2*i+0)*nWords + iStop);
1996 word * pFunc1p = Vec_WrdEntryP(vFuncs, (2*i+1)*nWords + iStop);
1997 Abc_TtAnd( pFunc0p, pFunc0n, pMask, nWords, 0 );
1998 Abc_TtAnd( pFunc1p, pFunc1n, pMask, nWords, 0 );
1999 Abc_TtSharp( pFunc0n, pFunc0n, pMask, nWords );
2000 Abc_TtSharp( pFunc1n, pFunc1n, pMask, nWords );
2001 }
2002}
2003Vec_Int_t * Gia_ManDeriveSubset( Gia_Man_t * p, Vec_Wrd_t * vFuncs, Vec_Int_t * vObjs, Vec_Wrd_t * vSims, int nWords, int fVerbose )
2004{
2005 int i, k, iObj, CostBestPrev, nFuncs = Vec_WrdSize(vFuncs) / nWords;
2006 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
2007 Vec_Int_t * vCounts = Vec_IntAlloc( nFuncs * 2 );
2008 Vec_Wrd_t * vFSims = Vec_WrdDup( vFuncs );
2009 assert( nFuncs * nWords == Vec_WrdSize(vFuncs) );
2010 assert( Gia_ManObjNum(p) * nWords == Vec_WrdSize(vSims) );
2011 assert( Vec_IntSize(vObjs) <= Gia_ManCandNum(p) );
2012 nFuncs = Gia_ManDeriveShrink( vFSims, nWords );
2013 Gia_ManDeriveCounts( vFSims, nWords, vCounts );
2014 assert( Vec_IntSize(vCounts) * nWords == Vec_WrdSize(vFSims) );
2015 CostBestPrev = Gia_ManDeriveSimpleCost( vCounts );
2016 if ( fVerbose )
2017 printf( "Processing %d functions and %d objects with cost %d\n", nFuncs, Vec_IntSize(vObjs), CostBestPrev );
2018 for ( i = 0; nFuncs > 0; i++ )
2019 {
2020 int iObjBest = -1, CountThis, Count0 = ABC_INFINITY, CountBest = ABC_INFINITY;
2021 Vec_IntForEachEntry( vObjs, iObj, k )
2022 {
2023 if ( Vec_IntFind(vRes, iObj) >= 0 )
2024 continue;
2025 CountThis = Gia_ManDeriveCost( vFSims, nWords, Vec_WrdEntryP(vSims, iObj*nWords), vCounts );
2026 if ( CountBest > CountThis )
2027 {
2028 CountBest = CountThis;
2029 iObjBest = iObj;
2030 }
2031 if ( !k ) Count0 = CountThis;
2032 }
2033 if ( Count0 < CostBestPrev )
2034 {
2035 CountBest = Count0;
2036 iObjBest = Vec_IntEntry(vObjs, 0);
2037 }
2038 Gia_ManDeriveNext( vFSims, nWords, Vec_WrdEntryP(vSims, iObjBest*nWords) );
2039 nFuncs = Gia_ManDeriveShrink( vFSims, nWords );
2040 Gia_ManDeriveCounts( vFSims, nWords, vCounts );
2041 assert( CountBest == Gia_ManDeriveSimpleCost(vCounts) );
2042 Vec_IntPush( vRes, iObjBest );
2043 CostBestPrev = CountBest;
2044 if ( fVerbose )
2045 printf( "Iter %2d : Funcs = %6d. Object %6d. Cost %6d.\n", i, nFuncs, iObjBest, CountBest );
2046 }
2047 Vec_IntFree( vCounts );
2048 Vec_WrdFree( vFSims );
2049 return vRes;
2050}
2051
2063Vec_Int_t * Gia_ManResubFindUsed( Vec_Int_t * vRes, int nDivs, int nNodes, Vec_Int_t * vSupp )
2064{
2065 int i, k, iLit, Counter = 1;
2066 Vec_Int_t * vUsed = Vec_IntStartFull( nDivs );
2067 Vec_Int_t * vRes2 = Vec_IntDup( vRes );
2068 Vec_IntWriteEntry( vUsed, 0, 0 );
2069 assert( Vec_IntSize(vRes) % 2 == 1 );
2070 Vec_IntSort( vRes2, 0 );
2071 Vec_IntForEachEntry( vRes2, iLit, k )
2072 {
2073 int iVar = Abc_Lit2Var(iLit);
2074 if ( iVar > 0 && iVar < nDivs && Vec_IntEntry(vUsed, iVar) == -1 ) {
2075 Vec_IntWriteEntry( vUsed, iVar, Counter++ );
2076 Vec_IntPush( vSupp, iVar-2 );
2077 }
2078 }
2079 Vec_IntFree( vRes2 );
2080 for ( i = nDivs; i < nDivs + nNodes; i++ )
2081 Vec_IntPush( vUsed, Counter++ );
2082 return vUsed;
2083}
2085{
2086 int i, iLit;
2087 Vec_Int_t * vResNew = Vec_IntAlloc( Vec_IntSize(vRes) );
2088 Vec_IntForEachEntry( vRes, iLit, i )
2089 Vec_IntPush( vResNew, Abc_Lit2LitV(Vec_IntArray(vUsed), iLit) );
2090 return vResNew;
2091}
2092void Gia_ManResubRecordSolution( char * pFileName, Vec_Int_t * vRes, int nDivs )
2093{
2094 FILE * pFile = fopen( pFileName, "ab" );
2095 if ( pFile == NULL ) {
2096 printf( "Cannot open file \"%s\" for writing.\n", pFileName );
2097 return;
2098 }
2099 Vec_Int_t * vSupp = Vec_IntAlloc( 100 );
2100 Vec_Int_t * vUsed = Gia_ManResubFindUsed( vRes, nDivs, Vec_IntSize(vRes)/2, vSupp );
2101 Vec_Int_t * vResN = Gia_ManResubRemapSolution( vRes, vUsed );
2102
2103 int i, Temp;
2104 fprintf( pFile, "\n.s" );
2105 Vec_IntForEachEntry( vSupp, Temp, i )
2106 fprintf( pFile, " %d", Temp );
2107 fprintf( pFile, "\n.a" );
2108 Vec_IntForEachEntry( vResN, Temp, i )
2109 fprintf( pFile, " %d", Temp );
2110 fprintf( pFile, "\n" );
2111 fclose( pFile );
2112
2113 Vec_IntFree( vUsed );
2114 Vec_IntFree( vSupp );
2115 Vec_IntFree( vResN );
2116}
2117Gia_Man_t * Gia_ManResubUnateOne( char * pFileName, int nLimit, int nDivMax, int fWriteSol, int fVerbose )
2118{
2119 Gia_Man_t * pNew = NULL;
2120 Abc_RData_t * p = Abc_ReadPla( pFileName );
2121 if ( p == NULL ) return NULL;
2122 assert( p->nOuts == 1 );
2123 Vec_Ptr_t * vDivs = Vec_PtrAlloc( 2+p->nIns );
2124 Vec_Int_t * vRes = Vec_IntAlloc( 100 );
2125 Vec_PtrPush( vDivs, Vec_WrdEntryP(p->vSimsOut, 0*p->nSimWords) );
2126 Vec_PtrPush( vDivs, Vec_WrdEntryP(p->vSimsOut, 1*p->nSimWords) );
2127 int i, k, ArraySize, * pArray;
2128 for ( i = 0; i < p->nIns; i++ )
2129 Vec_PtrPush( vDivs, Vec_WrdEntryP(p->vSimsIn, i*p->nSimWords) );
2130 Abc_ResubPrepareManager( p->nSimWords );
2131 if ( fVerbose )
2132 printf( "The problem has %d divisors and %d outputs.\n", p->nIns, p->nOuts );
2133 ArraySize = Abc_ResubComputeFunction( (void **)Vec_PtrArray(vDivs), Vec_PtrSize(vDivs), p->nSimWords, nLimit, nDivMax, 0, 0, 1, fVerbose, &pArray );
2134 for ( k = 0; k < ArraySize; k++ )
2135 Vec_IntPush( vRes, pArray[k] );
2136 if ( ArraySize ) {
2137 //Vec_IntPrint( vRes );
2138 Vec_Wec_t * vGates = Vec_WecStart(1);
2139 Vec_IntAppend( Vec_WecEntry(vGates, 0), vRes );
2140 pNew = Gia_ManConstructFromGates( vGates, Vec_PtrSize(vDivs) );
2141 Vec_WecFree( vGates );
2142 if ( fVerbose )
2143 printf( "The solution has %d inputs and %d nodes.\n", Gia_ManCiNum(pNew), Gia_ManAndNum(pNew) );
2144 }
2145 if ( fWriteSol && ArraySize )
2146 Gia_ManResubRecordSolution( pFileName, vRes, Vec_PtrSize(vDivs) );
2148 Vec_IntFree( vRes );
2149 Vec_PtrFree( vDivs );
2150 Abc_RDataStop( p );
2151 return pNew;
2152}
2153
2157
2159
int nWords
Definition abcNpn.c:127
#define ABC_SWAP(Type, a, b)
Definition abc_global.h:253
ABC_INT64_T abctime
Definition abc_global.h:332
#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
int nTotal
DECLARATIONS ///.
Definition cutTruth.c:37
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
Cube * p
Definition exorList.c:222
Vec_Wec_t * Gia_ManComputeMffcs(Gia_Man_t *p, int LimitMin, int LimitMax, int SuppMax, int RatioBest)
Definition giaResub.c:98
int Gia_ManDeriveSimpleCost(Vec_Int_t *vCounts)
Definition giaResub.c:1977
Vec_Int_t * Gia_ManToGates(Gia_Man_t *p)
Definition giaResub.c:655
void Gia_ManDeriveCounts(Vec_Wrd_t *vFuncs, int nWords, Vec_Int_t *vCounts)
Definition giaResub.c:1954
int Gia_ObjCheckMffc(Gia_Man_t *p, Gia_Obj_t *pRoot, int Limit, Vec_Int_t *vNodes, Vec_Int_t *vLeaves, Vec_Int_t *vInners)
Definition giaResub.c:71
Gia_ResbMan_t * Gia_ResbAlloc(int nWords)
Definition giaResub.c:314
int Gia_ManDeriveCost(Vec_Wrd_t *vFuncs, int nWords, word *pMask, Vec_Int_t *vCounts)
Definition giaResub.c:1962
void Abc_ResubPrepareManager(int nWords)
Definition giaResub.c:1539
Vec_Int_t * Gia_ManResubRemapSolution(Vec_Int_t *vRes, Vec_Int_t *vUsed)
Definition giaResub.c:2084
void Gia_ManDeriveDivPair(int iDiv, Vec_Ptr_t *vDivs, int nWords, word *pRes)
Definition giaResub.c:969
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
Vec_Int_t * Gia_ManDeriveSubset(Gia_Man_t *p, Vec_Wrd_t *vFuncs, Vec_Int_t *vObjs, Vec_Wrd_t *vSims, int nWords, int fVerbose)
Definition giaResub.c:2003
int Gia_ManResubPerform_rec(Gia_ResbMan_t *p, int nLimit, int Depth)
Definition giaResub.c:1276
int Gia_ManFindTwoUnate(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits[2], Vec_Int_t *vUnateLitsW[2], int fVerbose)
Definition giaResub.c:889
void Gia_ManPrintDivStats(Gia_Man_t *p, Vec_Wec_t *vMffcs, Vec_Wec_t *vPivots)
Definition giaResub.c:159
Vec_Int_t * Gia_ManResubOne(Vec_Ptr_t *vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, word *pFunc, int Depth)
Definition giaResub.c:1503
int Gia_ManResubVerify(Gia_ResbMan_t *p, word *pFunc)
Definition giaResub.c:456
ABC_NAMESPACE_IMPL_START int Gia_ObjCheckMffc_rec(Gia_Man_t *p, Gia_Obj_t *pObj, int Limit, Vec_Int_t *vNodes)
DECLARATIONS ///.
Definition giaResub.c:49
void Gia_ManSortUnates(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits[2], Vec_Int_t *vUnateLitsW[2], Vec_Wec_t *vSorter)
Definition giaResub.c:1077
int Gia_ManFindGateGateInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnatePairs, Vec_Int_t *vUnatePairsW, word *pDivTempA, word *pDivTempB)
Definition giaResub.c:1021
void Gia_ResbInit(Gia_ResbMan_t *p, Vec_Ptr_t *vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int fVeryVerbose)
Definition giaResub.c:339
void Gia_ManResubRecordSolution(char *pFileName, Vec_Int_t *vRes, int nDivs)
Definition giaResub.c:2092
void Gia_ManResubPrintNode(Vec_Int_t *vRes, int nVars, int Node, int fCompl)
Definition giaResub.c:401
int Gia_ManResubFindBestBinate(Gia_ResbMan_t *p)
Definition giaResub.c:1175
void Gia_ManDeriveNext(Vec_Wrd_t *vFuncs, int nWords, word *pMask)
Definition giaResub.c:1984
int Gia_ManDeriveShrink(Vec_Wrd_t *vFuncs, int nWords)
Definition giaResub.c:1937
void Gia_ManResubPair(Vec_Wrd_t *vOn, Vec_Wrd_t *vOff, int nWords, int nIns)
Definition giaResub.c:1689
void Gia_ManFindOneUnateInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits, Vec_Int_t *vNotUnateVars)
Definition giaResub.c:834
void Gia_ManInsertOrder_rec(Gia_Man_t *p, int iObj, Vec_Int_t *vObjs, Vec_Wec_t *vFuncs, Vec_Int_t *vNodes)
Definition giaResub.c:698
int Gia_ManFindOneUnate(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits[2], Vec_Int_t *vNotUnateVars[2], int fVerbose)
Definition giaResub.c:847
int Gia_ManResubPerformMux_rec(Gia_ResbMan_t *p, int nLimit, int Depth)
Definition giaResub.c:1214
int Gia_ManFindDivGateInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits, Vec_Int_t *vUnatePairs, Vec_Int_t *vUnateLitsW, Vec_Int_t *vUnatePairsW, word *pDivTemp)
Definition giaResub.c:988
Vec_Ptr_t * Gia_ManDeriveDivs(Vec_Wrd_t *vSims, int nWords)
Definition giaResub.c:1754
Gia_Man_t * Gia_ManInsertFromGates(Gia_Man_t *p, Vec_Int_t *vObjs, Vec_Wec_t *vFuncs)
Definition giaResub.c:732
void Gia_ManResubTest(Gia_Man_t *p)
Definition giaResub.c:262
int Gia_ManFindDivGate(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits[2], Vec_Int_t *vUnatePairs[2], Vec_Int_t *vUnateLitsW[2], Vec_Int_t *vUnatePairsW[2], word *pDivTemp)
Definition giaResub.c:1009
Gia_Man_t * Gia_ManResubUnateOne(char *pFileName, int nLimit, int nDivMax, int fWriteSol, int fVerbose)
Definition giaResub.c:2117
void Gia_ManSortPairs(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits[2], Vec_Int_t *vUnateLitsW[2], Vec_Wec_t *vSorter)
Definition giaResub.c:1122
void Dau_DsdPrintFromTruth2(word *pTruth, int nVarsInit)
Definition dauDsd.c:1976
void Gia_ManAddDivisors(Gia_Man_t *p, Vec_Wec_t *vMffcs)
Definition giaResub.c:196
void Gia_ManResubTest3_()
Definition giaResub.c:1647
Vec_Int_t * Gia_ManInsertOrder(Gia_Man_t *p, Vec_Int_t *vObjs, Vec_Wec_t *vFuncs)
Definition giaResub.c:724
int Gia_ManUnivTfo(Gia_Man_t *p, int *pObjs, int nObjs, Vec_Int_t **pvNodes, Vec_Int_t **pvPos)
Definition giaResub.c:1821
void Gia_ManResubTest3()
Definition giaResub.c:1605
void Gia_ManSortBinate(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vBinateVars, Vec_Wec_t *vSorter)
Definition giaResub.c:1129
int Gia_ManResubAddNode(Gia_ResbMan_t *p, int iLit0, int iLit1, int Type)
Definition giaResub.c:1200
void Gia_ManFindUnatePairsInt(word *pOff, word *pOn, Vec_Int_t *vBinate, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnatePairs)
Definition giaResub.c:934
void Gia_ManFindXorInt(word *pOff, word *pOn, Vec_Int_t *vBinate, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnatePairs)
Definition giaResub.c:904
void Gia_ManResubPrintLit(Vec_Int_t *vRes, int nVars, int iLit)
Definition giaResub.c:418
Gia_Man_t * Gia_ManConstructFromGates2(Vec_Wec_t *vFuncs, Vec_Wec_t *vDivs, int nObjs, Vec_Int_t **pvSupp)
Definition giaResub.c:594
Gia_Man_t * Gia_ManConstructFromGates(Vec_Wec_t *vFuncs, int nDivs)
Definition giaResub.c:562
struct Gia_ResbMan_t_ Gia_ResbMan_t
Definition giaResub.c:289
Gia_Man_t * Gia_ManResub1(char *pFileName, int nNodes, int nSupp, int nDivs, int iChoice, int fUseXor, int fVerbose, int fVeryVerbose)
Definition giaResub.c:1766
int Gia_ManFindXor(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vBinateVars, Vec_Int_t *vUnatePairs[2], int fVerbose)
Definition giaResub.c:921
void Gia_ManSortUnatesInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits, Vec_Int_t *vUnateLitsW, Vec_Wec_t *vSorter)
Definition giaResub.c:1055
int Gia_ManConstructFromMap(Gia_Man_t *pNew, Vec_Int_t *vGates, int nVars, Vec_Int_t *vUsed, Vec_Int_t *vCopy, int fHash)
Definition giaResub.c:525
int Abc_ResubComputeFunction(void **ppDivs, int nDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int **ppArray)
Definition giaResub.c:1548
void Gia_ManSortPairsInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnatePairs, Vec_Int_t *vUnatePairsW, Vec_Wec_t *vSorter)
Definition giaResub.c:1084
void Gia_ManFindUnatePairs(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vBinateVars, Vec_Int_t *vUnatePairs[2], int fVerbose)
Definition giaResub.c:955
void Gia_ManResubPerform(Gia_ResbMan_t *p, Vec_Ptr_t *vDivs, int nWords, int nLimit, int nDivsMax, int iChoice, int fUseXor, int fDebug, int fVerbose, int Depth)
Definition giaResub.c:1491
Gia_Man_t * Gia_ManResub2(Gia_Man_t *pGia, int nNodes, int nSupp, int nDivs, int iChoice, int fUseXor, int fVerbose, int fVeryVerbose)
Definition giaResub.c:1762
int Gia_ManResubPrint(Vec_Int_t *vRes, int nVars)
Definition giaResub.c:430
void Abc_ResubDumpProblem(char *pFileName, void **ppDivs, int nDivs, int nWords)
Definition giaResub.c:1578
Vec_Int_t * Gia_ManResubFindUsed(Vec_Int_t *vRes, int nDivs, int nNodes, Vec_Int_t *vSupp)
Definition giaResub.c:2063
void Gia_ResbFree(Gia_ResbMan_t *p)
Definition giaResub.c:366
int Gia_ManUnivTfo_rec(Gia_Man_t *p, int iObj, Vec_Int_t *vNodes, Vec_Int_t *vPos)
Definition giaResub.c:1807
int Gia_ManFindTwoUnateInt(word *pOff, word *pOn, Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnateLits, Vec_Int_t *vUnateLitsW, int *pnPairs)
Definition giaResub.c:865
void Gia_ManTryResub(Gia_Man_t *p)
Definition giaResub.c:1859
void Gia_ManCheckResub(Vec_Ptr_t *vDivs, int nWords)
Definition giaResub.c:1730
int Gia_ManFindGateGate(word *pSets[2], Vec_Ptr_t *vDivs, int nWords, Vec_Int_t *vUnatePairs[2], Vec_Int_t *vUnatePairsW[2], word *pDivTempA, word *pDivTempB)
Definition giaResub.c:1043
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
Definition giaMuxes.c:98
void Gia_ManStaticFanoutStart(Gia_Man_t *p)
Definition giaFanout.c:238
void Gia_ManHashStart(Gia_Man_t *p)
Definition giaHash.c:125
void Gia_ManStaticFanoutStop(Gia_Man_t *p)
Definition giaFanout.c:393
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
#define Gia_ManForEachCoId(p, Id, i)
Definition gia.h:1240
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
int Gia_ManHashXor(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:668
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Vec_Wrd_t * Gia_ManSimPatSim(Gia_Man_t *p)
Definition giaSimBase.c:125
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
Gia_Man_t * Gia_ManCleanup(Gia_Man_t *p)
Definition giaScl.c:84
void Gia_ManCreateRefs(Gia_Man_t *p)
Definition giaUtil.c:779
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
#define Gia_ObjForEachFanoutStaticId(p, Id, FanId, i)
Definition gia.h:1127
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
int Gia_NodeMffcSizeMark(Gia_Man_t *p, Gia_Obj_t *pNode)
Definition giaUtil.c:1241
typedefABC_NAMESPACE_HEADER_START struct Abc_RData_t_ Abc_RData_t
INCLUDES ///.
Definition ioResub.h:40
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
unsigned fPhase
Definition gia.h:87
Vec_Ptr_t * vDivs
Definition giaResub.c:300
Vec_Int_t * vNotUnateVars[2]
Definition giaResub.c:303
Vec_Int_t * vUnateLitsW[2]
Definition giaResub.c:306
Vec_Int_t * vUnateLits[2]
Definition giaResub.c:302
Vec_Wrd_t * vSims
Definition giaResub.c:312
Vec_Int_t * vUnatePairsW[2]
Definition giaResub.c:307
Vec_Int_t * vUnatePairs[2]
Definition giaResub.c:304
word * pSets[2]
Definition giaResub.c:309
Vec_Wec_t * vSorter
Definition giaResub.c:308
Vec_Int_t * vGates
Definition giaResub.c:301
Vec_Int_t * vBinateVars
Definition giaResub.c:305
#define assert(ex)
Definition util_old.h:213
char * memset()
char * memmove()
#define Vec_IntForEachEntryDouble(vVec, Entry1, Entry2, i)
Definition vecInt.h:72
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_IntForEachEntryTwoStart(vVec1, vVec2, Entry1, Entry2, i, Start)
Definition vecInt.h:70
#define Vec_IntForEachEntryStop(vVec, Entry, i, Stop)
Definition vecInt.h:58
#define Vec_IntForEachEntryTwo(vVec1, vVec2, Entry1, Entry2, i)
Definition vecInt.h:66
#define Vec_IntForEachEntryStart(vVec, Entry, i, Start)
Definition vecInt.h:56
#define Vec_PtrForEachEntryStart(Type, vVec, pEntry, i, Start)
Definition vecPtr.h:57
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
#define Vec_WecForEachLevelReverse(vGlob, vVec, i)
Definition vecWec.h:65
#define Vec_WecForEachLevelStart(vGlob, vVec, i, LevelStart)
Definition vecWec.h:59
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
#define Vec_WrdForEachEntryStop(vVec, Entry, i, Stop)
Definition vecWrd.h:58