39#define MF_TT_WORDS ((MF_LEAF_MAX > 6) ? 1 << (MF_LEAF_MAX-6) : 1)
40#define MF_NO_FUNC 134217727
41#define MF_EPSILON 0.005
86static inline int * Mf_ManCutSet(
Mf_Man_t *
p,
int i ) {
return (
int *)Vec_PtrEntry(&
p->vPages, i >> 16) + (i & 0xFFFF); }
87static inline int * Mf_ObjCutSet(
Mf_Man_t *
p,
int i ) {
return Mf_ManCutSet(
p, Mf_ManObj(
p, i)->iCutSet); }
88static inline int * Mf_ObjCutBest(
Mf_Man_t *
p,
int i ) {
return Mf_ObjCutSet(
p, i) + 1; }
90static inline int Mf_ObjMapRefNum(
Mf_Man_t *
p,
int i ) {
return Mf_ManObj(
p, i)->nMapRefs; }
91static inline int Mf_ObjMapRefInc(
Mf_Man_t *
p,
int i ) {
return Mf_ManObj(
p, i)->nMapRefs++; }
92static inline int Mf_ObjMapRefDec(
Mf_Man_t *
p,
int i ) {
return --Mf_ManObj(
p, i)->nMapRefs; }
94static inline int Mf_CutSize(
int * pCut ) {
return pCut[0] &
MF_NO_LEAF; }
95static inline int Mf_CutFunc(
int * pCut ) {
return ((
unsigned)pCut[0] >> 5); }
96static inline int Mf_CutSetBoth(
int n,
int f ) {
return n | (f << 5); }
97static inline int Mf_CutIsTriv(
int * pCut,
int i ) {
return Mf_CutSize(pCut) == 1 && pCut[1] == i; }
99#define Mf_SetForEachCut( pList, pCut, i ) for ( i = 0, pCut = pList + 1; i < pList[0]; i++, pCut += Mf_CutSize(pCut) + 1 )
100#define Mf_ObjForEachCut( pCuts, i, nCuts ) for ( i = 0, i < nCuts; i++ )
119static int s_nCalls = 0;
123 word Temp, Best = *t;
124 int r, i, Config = 0;
125 for ( r = 0; r < 1; r++ )
127 if ( Best > (Temp = ~Best) )
128 Best = Temp, Config ^= (1 << nVars);
129 for ( i = 0; i < nVars; i++ )
130 if ( Best > (Temp = Abc_Tt6Flip(Best, i)) )
131 Best = Temp, Config ^= (1 << i);
134 if ( s_vTtMem == NULL )
135 s_vTtMem = Vec_MemAllocForTT( 6, 0 );
136 Vec_MemHashInsert( s_vTtMem, t );
142 if ( s_vTtMem == NULL )
144 printf(
"TT = %d (%.2f %%)\n", Vec_MemEntryNum(s_vTtMem), 100.0 * Vec_MemEntryNum(s_vTtMem) / s_nCalls );
145 Vec_MemHashFree( s_vTtMem );
146 Vec_MemFree( s_vTtMem );
157 Vec_Wrd_t * vResult = Vec_WrdAlloc( 1 << 20 );
158 word uTruth, tCur, tTemp1, tTemp2;
162 for ( i = 0; i < 2; i++ )
164 tCur = i ? ~uTruth : uTruth;
166 for (
p = 0;
p < 720;
p++ )
169 for ( c = 0; c < 64; c++ )
171 tCur = Abc_Tt6Flip( tCur, pComp[c] );
172 Vec_WrdPush( vResult, tCur );
175 tCur = Abc_Tt6SwapAdjacent( tCur, pPerm[
p] );
182 printf(
"Original = %d. ", Vec_WrdSize(vTruths) );
183 Vec_WrdFree( vTruths );
184 printf(
"Total = %d. ", Vec_WrdSize(vResult) );
185 vTruths = Vec_WrdUniqifyHash( vResult, 1 );
186 Vec_WrdFree( vResult );
187 printf(
"Unique = %d. ", Vec_WrdSize(vTruths) );
191 Vec_WrdWriteEntry( vTruths, k, uTruth );
193 vResult = Vec_WrdUniqifyHash( vTruths, 1 );
194 Vec_WrdFree( vTruths );
195 printf(
"Unique = %d. \n", Vec_WrdSize(vResult) );
201 int RetValue = Vec_WrdSize( vTruths );
202 Vec_WrdFree( vTruths );
220 int i, Entry, * pCut, Counter = 0;
221 vCounts = Vec_IntStart( Vec_IntSize(&
p->vCnfSizes) );
224 if ( !Mf_ObjMapRefNum(
p, i) )
226 pCut = Mf_ObjCutBest(
p, i );
227 Vec_IntAddToEntry( vCounts, Abc_Lit2Var(Mf_CutFunc(pCut)), 1 );
233 printf(
"%6d : ", Counter++ );
234 printf(
"%6d : ", i );
235 printf(
"Occur = %4d ", Entry );
236 printf(
"CNF size = %2d ", Vec_IntEntry(&
p->vCnfSizes, i) );
239 Vec_IntFree( vCounts );
253static inline void Mf_CutPrintOne(
int * pCut )
256 printf(
"%d {", Mf_CutSize(pCut) );
257 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
258 printf(
" %d", pCut[i] );
261static inline int Mf_CubeLit(
int Cube,
int iVar ) {
return (
Cube >> (iVar << 1)) & 3; }
262static inline int Mf_ManCountLits(
int * pCnf,
int nCubes,
int nVars )
264 int i, k, nLits = nCubes;
265 for ( i = 0; i < nCubes; i++ )
266 for ( k = 0; k < nVars; k++ )
267 if ( Mf_CubeLit(pCnf[i], k) )
273 int i, k, iFunc, nCubes, nLits, * pCut, pCnf[512];
274 Vec_Int_t * vLits = Vec_IntStart( Vec_IntSize(&
p->vCnfSizes) );
275 Vec_Int_t * vCnfs = Vec_IntAlloc( 3 * Vec_IntSize(&
p->vCnfSizes) );
276 Vec_IntFill( vCnfs, Vec_IntSize(&
p->vCnfSizes), -1 );
277 assert(
p->pPars->nLutSize <= 8 );
279 for ( iFunc = 0; iFunc < 2; iFunc++ )
281 if (
p->pPars->nLutSize <= 6 )
282 nCubes = Abc_Tt6Cnf( *Vec_MemReadEntry(
p->vTtMem, iFunc), iFunc, pCnf );
284 nCubes = Abc_Tt8Cnf( Vec_MemReadEntry(
p->vTtMem, iFunc), iFunc, pCnf );
285 nLits = Mf_ManCountLits( pCnf, nCubes, iFunc );
286 Vec_IntWriteEntry( vLits, iFunc, nLits );
287 Vec_IntWriteEntry( vCnfs, iFunc, Vec_IntSize(vCnfs) );
288 Vec_IntPush( vCnfs, nCubes );
289 for ( k = 0; k < nCubes; k++ )
290 Vec_IntPush( vCnfs, pCnf[k] );
293 *pnVars = 1 + Gia_ManCiNum(
p->pGia) + Gia_ManCoNum(
p->pGia);
294 *pnClas = 1 + 2 * Gia_ManCoNum(
p->pGia);
295 *pnLits = 1 + 4 * Gia_ManCoNum(
p->pGia);
298 if ( !Mf_ObjMapRefNum(
p, i) )
300 pCut = Mf_ObjCutBest(
p, i );
302 iFunc = Abc_Lit2Var( Mf_CutFunc(pCut) );
303 if ( Vec_IntEntry(vCnfs, iFunc) == -1 )
305 if (
p->pPars->nLutSize <= 6 )
306 nCubes = Abc_Tt6Cnf( *Vec_MemReadEntry(
p->vTtMem, iFunc), Mf_CutSize(pCut), pCnf );
308 nCubes = Abc_Tt8Cnf( Vec_MemReadEntry(
p->vTtMem, iFunc), Mf_CutSize(pCut), pCnf );
309 assert( nCubes == Vec_IntEntry(&
p->vCnfSizes, iFunc) );
310 nLits = Mf_ManCountLits( pCnf, nCubes, Mf_CutSize(pCut) );
312 Vec_IntWriteEntry( vLits, iFunc, nLits );
313 Vec_IntWriteEntry( vCnfs, iFunc, Vec_IntSize(vCnfs) );
314 Vec_IntPush( vCnfs, nCubes );
315 for ( k = 0; k < nCubes; k++ )
316 Vec_IntPush( vCnfs, pCnf[k] );
319 *pnClas += Vec_IntEntry(&
p->vCnfSizes, iFunc);
320 *pnLits += Vec_IntEntry(vLits, iFunc);
322 Vec_IntFree( vLits );
341 int Id, DriId, nVars, nClas, nLits, iVar = 1, iCla = 0, iLit = 0;
343 Vec_Int_t * vCnfIds = Vec_IntStartFull( Gia_ManObjNum(
p->pGia) );
344 int pFanins[16], * pCut, * pCnfIds = Vec_IntArray( vCnfIds );
345 int i, k, c, iFunc, nCubes, * pCubes, fComplLast;
350 nLits += Gia_ManCoNum(
p->pGia);
355 iVar += 1 + Gia_ManCiNum(
p->pGia) + Gia_ManCoNum(
p->pGia);
357 Vec_IntWriteEntry( vCnfIds, Id, Id );
359 if ( Mf_ObjMapRefNum(
p, Id) )
360 Vec_IntWriteEntry( vCnfIds, Id, Id ), iVar++;
361 Vec_IntWriteEntry( vCnfIds, 0, 0 );
363 Vec_IntWriteEntry( vCnfIds, Id, Id );
369 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
371 if ( Mf_ObjMapRefNum(
p, Id) )
372 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
373 Vec_IntWriteEntry( vCnfIds, 0, iVar++ );
375 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
391 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 0);
393 if (
p->pPars->fCnfMapping )
394 pCnf->
vMapping = Vec_IntStart( nVars );
398 Id = Gia_ObjId(
p->pGia, pObj );
399 DriId = Gia_ObjFaninId0( pObj, Id );
402 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 0);
403 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[DriId], !Gia_ObjFaninC0(pObj));
406 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 1);
407 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[DriId], Gia_ObjFaninC0(pObj));
411 Vec_IntWriteEntry( pCnf->
vMapping, pCnfIds[Id], Vec_IntSize(pCnf->
vMapping) );
413 Vec_IntPush( pCnf->
vMapping, pCnfIds[DriId] );
414 Vec_IntPush( pCnf->
vMapping, Gia_ObjFaninC0(pObj) ? 0x55555555 : 0xAAAAAAAA );
420 if ( !Mf_ObjMapRefNum(
p, Id) )
422 pCut = Mf_ObjCutBest(
p, Id );
423 iFunc = Abc_Lit2Var( Mf_CutFunc(pCut) );
424 fComplLast = Abc_LitIsCompl( Mf_CutFunc(pCut) );
428 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], !fComplLast);
432 for ( k = 0; k < Mf_CutSize(pCut); k++ )
433 pFanins[k] = pCnfIds[pCut[k+1]];
434 pFanins[k++] = pCnfIds[Id];
436 pCubes = Vec_IntEntryP( vCnfs, Vec_IntEntry(vCnfs, iFunc) );
438 for ( c = 0; c < nCubes; c++ )
441 k = Mf_CutSize(pCut);
442 assert( Mf_CubeLit(pCubes[c], k) );
443 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit( pFanins[k], (Mf_CubeLit(pCubes[c], k) == 2) ^ fComplLast );
444 for ( k = 0; k < Mf_CutSize(pCut); k++ )
445 if ( Mf_CubeLit(pCubes[c], k) )
446 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit( pFanins[k], Mf_CubeLit(pCubes[c], k) == 2 );
451 word pTruth[4], * pTruthP = Vec_MemReadEntry(
p->vTtMem, iFunc);
452 assert(
p->pPars->nLutSize <= 8 );
453 Abc_TtCopy( pTruth, pTruthP, Abc_Truth6WordNum(
p->pPars->nLutSize), Abc_LitIsCompl(iFunc) );
454 assert( pCnfIds[Id] >= 0 && pCnfIds[Id] < nVars );
455 Vec_IntWriteEntry( pCnf->
vMapping, pCnfIds[Id], Vec_IntSize(pCnf->
vMapping) );
456 Vec_IntPush( pCnf->
vMapping, Mf_CutSize(pCut) );
457 for ( k = 0; k < Mf_CutSize(pCut); k++ )
458 Vec_IntPush( pCnf->
vMapping, pCnfIds[pCut[k+1]] );
459 Vec_IntPush( pCnf->
vMapping, (
unsigned)pTruth[0] );
460 if ( Mf_CutSize(pCut) >= 6 )
462 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[0] >> 32) );
463 if ( Mf_CutSize(pCut) >= 7 )
465 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[1]) );
466 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[1] >> 32) );
468 if ( Mf_CutSize(pCut) >= 8 )
470 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[2]) );
471 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[2] >> 32) );
472 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[3]) );
473 Vec_IntPush( pCnf->
vMapping, (
unsigned)(pTruth[3] >> 32) );
480 pCnf->
pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[0], 1);
486 Vec_IntFree( vCnfs );
492 for ( i = 0; i < pCnf->
nClauses; i++ )
494 Id = Abc_Lit2Var(pCnf->
pClauses[i][0]);
509 if (
p->pGia !=
p->pGia0 )
513 pCnf->
pVarNums[Id] = pCnfIds[Gia_ManCiIdToId(
p->pGia, i)];
515 pCnf->
pVarNums[Id] = pCnfIds[Gia_ManCoIdToId(
p->pGia, i)];
527 pCnf->
pVarNums = Vec_IntReleaseArray(vCnfIds);
529 Vec_IntFree( vCnfIds );
547 int nOldSupp = pCutR->
nLeaves, truthId, fCompl;
word t;
548 word t0 = *Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut0->
iFunc));
549 word t1 = *Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut1->
iFunc));
550 if ( Abc_LitIsCompl(pCut0->
iFunc) ^ fCompl0 ) t0 = ~t0;
551 if ( Abc_LitIsCompl(pCut1->
iFunc) ^ fCompl1 ) t1 = ~t1;
554 t = fIsXor ? t0 ^ t1 : t0 & t1;
555 if ( (fCompl = (
int)(t & 1)) ) t = ~t;
556 if ( !
p->pPars->fCnfObjIds )
558 assert( (
int)(t & 1) == 0 );
559 truthId = Vec_MemHashInsert(
p->vTtMem, &t);
560 pCutR->
iFunc = Abc_Var2Lit( truthId, fCompl );
561 if ( (
p->pPars->fGenCnf ||
p->pPars->fGenLit) && truthId == Vec_IntSize(&
p->vCnfSizes) )
566 return (
int)pCutR->
nLeaves < nOldSupp;
570 if (
p->pPars->nLutSize <= 6 )
571 return Mf_CutComputeTruth6(
p, pCut0, pCut1, fCompl0, fCompl1, pCutR, fIsXor );
574 int nOldSupp = pCutR->
nLeaves, truthId;
575 int LutSize =
p->pPars->nLutSize, fCompl;
576 int nWords = Abc_Truth6WordNum(LutSize);
577 word * pTruth0 = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut0->
iFunc));
578 word * pTruth1 = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut1->
iFunc));
579 Abc_TtCopy( uTruth0, pTruth0,
nWords, Abc_LitIsCompl(pCut0->
iFunc) ^ fCompl0 );
580 Abc_TtCopy( uTruth1, pTruth1,
nWords, Abc_LitIsCompl(pCut1->
iFunc) ^ fCompl1 );
584 Abc_TtXor( uTruth, uTruth0, uTruth1,
nWords, (fCompl = (
int)((uTruth0[0] ^ uTruth1[0]) & 1)) );
586 Abc_TtAnd( uTruth, uTruth0, uTruth1,
nWords, (fCompl = (
int)((uTruth0[0] & uTruth1[0]) & 1)) );
588 assert( (uTruth[0] & 1) == 0 );
590 truthId = Vec_MemHashInsert(
p->vTtMem, uTruth);
591 pCutR->
iFunc = Abc_Var2Lit( truthId, fCompl );
592 if ( (
p->pPars->fGenCnf ||
p->pPars->fGenLit) && truthId == Vec_IntSize(&
p->vCnfSizes) && LutSize <= 8 )
593 Vec_IntPush( &
p->vCnfSizes,
p->pPars->fGenCnf ? Abc_Tt8CnfSize(uTruth, pCutR->
nLeaves) :
Kit_TruthLitNum((
unsigned *)uTruth, pCutR->
nLeaves, &
p->vCnfMem) );
595 return (
int)pCutR->
nLeaves < nOldSupp;
600 int nOldSupp = pCutR->
nLeaves, truthId, fCompl;
word t;
601 word t0 = *Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut0->
iFunc));
602 word t1 = *Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut1->
iFunc));
603 word tC = *Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCutC->
iFunc));
604 if ( Abc_LitIsCompl(pCut0->
iFunc) ^ fCompl0 ) t0 = ~t0;
605 if ( Abc_LitIsCompl(pCut1->
iFunc) ^ fCompl1 ) t1 = ~t1;
606 if ( Abc_LitIsCompl(pCutC->
iFunc) ^ fComplC ) tC = ~tC;
610 t = (tC & t1) | (~tC & t0);
611 if ( (fCompl = (
int)(t & 1)) ) t = ~t;
613 assert( (
int)(t & 1) == 0 );
614 truthId = Vec_MemHashInsert(
p->vTtMem, &t);
615 pCutR->
iFunc = Abc_Var2Lit( truthId, fCompl );
616 if ( (
p->pPars->fGenCnf ||
p->pPars->fGenLit) && truthId == Vec_IntSize(&
p->vCnfSizes) )
619 return (
int)pCutR->
nLeaves < nOldSupp;
623 if (
p->pPars->nLutSize <= 6 )
624 return Mf_CutComputeTruthMux6(
p, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, pCutR );
627 int nOldSupp = pCutR->
nLeaves, truthId;
628 int LutSize =
p->pPars->nLutSize, fCompl;
629 int nWords = Abc_Truth6WordNum(LutSize);
630 word * pTruth0 = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut0->
iFunc));
631 word * pTruth1 = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCut1->
iFunc));
632 word * pTruthC = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(pCutC->
iFunc));
633 Abc_TtCopy( uTruth0, pTruth0,
nWords, Abc_LitIsCompl(pCut0->
iFunc) ^ fCompl0 );
634 Abc_TtCopy( uTruth1, pTruth1,
nWords, Abc_LitIsCompl(pCut1->
iFunc) ^ fCompl1 );
635 Abc_TtCopy( uTruthC, pTruthC,
nWords, Abc_LitIsCompl(pCutC->
iFunc) ^ fComplC );
639 Abc_TtMux( uTruth, uTruthC, uTruth1, uTruth0,
nWords );
640 fCompl = (int)(uTruth[0] & 1);
641 if ( fCompl ) Abc_TtNot( uTruth,
nWords );
643 assert( (uTruth[0] & 1) == 0 );
644 truthId = Vec_MemHashInsert(
p->vTtMem, uTruth);
645 pCutR->
iFunc = Abc_Var2Lit( truthId, fCompl );
646 if ( (
p->pPars->fGenCnf ||
p->pPars->fGenLit) && truthId == Vec_IntSize(&
p->vCnfSizes) && LutSize <= 8 )
647 Vec_IntPush( &
p->vCnfSizes,
p->pPars->fGenCnf ? Abc_Tt8CnfSize(uTruth, pCutR->
nLeaves) :
Kit_TruthLitNum((
unsigned *)uTruth, pCutR->
nLeaves, &
p->vCnfMem) );
649 return (
int)pCutR->
nLeaves < nOldSupp;
665static inline int Mf_CutCountBits(
word i )
667 i = i - ((i >> 1) & 0x5555555555555555);
668 i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
669 i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
670 return (i*(0x0101010101010101))>>56;
672static inline word Mf_CutGetSign(
int * pLeaves,
int nLeaves )
674 word Sign = 0;
int i;
675 for ( i = 0; i < nLeaves; i++ )
676 Sign |= ((
word)1) << (pLeaves[i] & 0x3F);
679static inline int Mf_CutCreateUnit(
Mf_Cut_t *
p,
int i )
686 p->Sign = ((
word)1) << (i & 0x3F);
691 int i, nDigits = Abc_Base10Log(Gia_ManObjNum(
p->pGia));
692 printf(
"%d {", pCut->
nLeaves );
693 for ( i = 0; i < (int)pCut->
nLeaves; i++ )
694 printf(
" %*d", nDigits, pCut->
pLeaves[i] );
695 for ( ; i < (int)
p->pPars->nLutSize; i++ )
696 printf(
" %*s", nDigits,
" " );
697 printf(
" } D = %4d A = %9.4f F = %6d ",
701 if (
p->pPars->fGenCnf )
702 printf(
"CNF = %2d ", Vec_IntEntry(&
p->vCnfSizes, Abc_Lit2Var(pCut->
iFunc)) );
703 if (
p->pPars->fGenLit )
704 printf(
"Lit = %2d ", Vec_IntEntry(&
p->vCnfSizes, Abc_Lit2Var(pCut->
iFunc)) );
710static inline int Mf_ManPrepareCuts(
Mf_Cut_t * pCuts,
Mf_Man_t *
p,
int iObj,
int fAddUnit )
712 if ( Mf_ManObj(
p, iObj)->iCutSet )
715 int i, * pCut, * pList = Mf_ObjCutSet(
p, iObj);
720 pMfCut->
iFunc = Mf_CutFunc( pCut );
721 pMfCut->
nLeaves = Mf_CutSize( pCut );
722 pMfCut->
Sign = Mf_CutGetSign( pCut+1, Mf_CutSize(pCut) );
723 memcpy( pMfCut->
pLeaves, pCut+1,
sizeof(
int) * Mf_CutSize(pCut) );
726 if ( fAddUnit && pCuts->
nLeaves > 1 )
727 return pList[0] + Mf_CutCreateUnit( pMfCut, iObj );
730 return Mf_CutCreateUnit( pCuts, iObj );
734 int i, * pPlace, iCur, nInts = 1;
735 for ( i = 0; i < nCuts; i++ )
736 nInts += pCuts[i]->nLeaves + 1;
737 if ( (
p->iCur & 0xFFFF) + nInts > 0xFFFF )
738 p->iCur = ((
p->iCur >> 16) + 1) << 16;
739 if ( Vec_PtrSize(&
p->vPages) == (
p->iCur >> 16) )
740 Vec_PtrPush( &
p->vPages,
ABC_ALLOC(
int, (1<<16)) );
741 iCur =
p->iCur;
p->iCur += nInts;
742 pPlace = Mf_ManCutSet(
p, iCur );
744 for ( i = 0; i < nCuts; i++ )
746 *pPlace++ = Mf_CutSetBoth(pCuts[i]->nLeaves, pCuts[i]->iFunc);
747 memcpy( pPlace, pCuts[i]->pLeaves,
sizeof(
int) * pCuts[i]->nLeaves );
752static inline void Mf_ObjSetBestCut(
int * pCuts,
int * pCut )
755 if ( ++pCuts < pCut )
758 int nBlock = pCut - pCuts;
759 int nSize = Mf_CutSize(pCut) + 1;
760 memmove( pTemp, pCuts,
sizeof(
int) * nBlock );
761 memmove( pCuts, pCut,
sizeof(
int) * nSize );
762 memmove( pCuts + nSize, pTemp,
sizeof(
int) * nBlock );
783 for ( i = 0; i < nSizeC; i++ )
785 for ( k = 0; k < nSizeB; k++ )
786 if ( pC[i] == pB[k] )
793static inline int Mf_SetCheckArray(
Mf_Cut_t ** ppCuts,
int nCuts )
796 int i, k, m, n, Value;
798 for ( i = 0; i < nCuts; i++ )
804 for ( m = 0; m < (int)pCut0->
nLeaves; m++ )
805 for ( n = m + 1; n < (int)pCut0->
nLeaves; n++ )
808 for ( k = 0; k < nCuts; k++ )
811 if ( pCut0 == pCut1 )
814 Value = Mf_CutCheck( pCut0, pCut1 );
841 if ( nSize0 == nLutSize && nSize1 == nLutSize )
843 for ( i = 0; i < nSize0; i++ )
845 if ( pC0[i] != pC1[i] )
return 0;
855 if ( nSize0 == 0 )
goto FlushCut1;
856 if ( nSize1 == 0 )
goto FlushCut0;
859 if ( c == nLutSize )
return 0;
860 if ( pC0[i] < pC1[k] )
863 if ( i >= nSize0 )
goto FlushCut1;
865 else if ( pC0[i] > pC1[k] )
868 if ( k >= nSize1 )
goto FlushCut0;
872 pC[c++] = pC0[i++]; k++;
873 if ( i >= nSize0 )
goto FlushCut1;
874 if ( k >= nSize1 )
goto FlushCut0;
879 if ( c + nSize0 > nLutSize + i )
return 0;
888 if ( c + nSize1 > nLutSize + k )
return 0;
901 int xMin, c = 0, * pC = pCut->
pLeaves;
907 xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
909 if ( c == nLutSize )
return 0;
911 if (x0 == xMin) i0++;
912 if (x1 == xMin) i1++;
913 if (x2 == xMin) i2++;
920static inline int Mf_SetCutIsContainedOrder(
Mf_Cut_t * pBase,
Mf_Cut_t * pCut )
922 int i, nSizeB = pBase->
nLeaves;
924 if ( nSizeB == nSizeC )
926 for ( i = 0; i < nSizeB; i++ )
931 assert( nSizeB > nSizeC );
934 for ( i = k = 0; i < nSizeB; i++ )
946static inline int Mf_SetLastCutIsContained(
Mf_Cut_t ** pCuts,
int nCuts )
949 for ( i = 0; i < nCuts; i++ )
950 if ( pCuts[i]->nLeaves <= pCuts[nCuts]->nLeaves && (pCuts[i]->Sign & pCuts[nCuts]->Sign) == pCuts[i]->Sign && Mf_SetCutIsContainedOrder(pCuts[nCuts], pCuts[i]) )
954static inline int Mf_SetLastCutContainsArea(
Mf_Cut_t ** pCuts,
int nCuts )
956 int i, k, fChanges = 0;
957 for ( i = 0; i < nCuts; i++ )
958 if ( pCuts[nCuts]->nLeaves < pCuts[i]->nLeaves && (pCuts[nCuts]->Sign & pCuts[i]->Sign) == pCuts[nCuts]->Sign && Mf_SetCutIsContainedOrder(pCuts[i], pCuts[nCuts]) )
962 for ( i = k = 0; i <= nCuts; i++ )
982static inline void Mf_SetSortByArea(
Mf_Cut_t ** pCuts,
int nCuts )
985 for ( i = nCuts; i > 0; i-- )
987 if ( Mf_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )
992static inline int Mf_SetAddCut(
Mf_Cut_t ** pCuts,
int nCuts,
int nCutNum )
996 nCuts = Mf_SetLastCutContainsArea(pCuts, nCuts);
997 Mf_SetSortByArea( pCuts, nCuts );
998 return Abc_MinInt( nCuts + 1, nCutNum - 1 );
1000static inline int Mf_CutArea(
Mf_Man_t *
p,
int nLeaves,
int iFunc )
1004 if (
p->pPars->fGenCnf ||
p->pPars->fGenLit )
1005 return Vec_IntEntry(&
p->vCnfSizes, Abc_Lit2Var(iFunc));
1006 if (
p->pPars->fOptEdge )
1007 return nLeaves +
p->pPars->nAreaTuner;
1013 int i, nLeaves = pCut->
nLeaves;
1014 assert( nLeaves <= p->pPars->nLutSize );
1017 for ( i = 0; i < nLeaves; i++ )
1019 pBest = Mf_ManObj(
p, pCut->
pLeaves[i]);
1023 pCut->
Delay += (int)(nLeaves > 1);
1024 pCut->
Flow = (pCut->
Flow + Mf_CutArea(
p, nLeaves, pCut->
iFunc)) / FlowRefs;
1029 Gia_Obj_t * pObj = Gia_ManObj(
p->pGia, iObj);
1031 int nLutSize =
p->pPars->nLutSize;
1032 int nCutNum =
p->pPars->nCutNum;
1033 int nCuts0 = Mf_ManPrepareCuts(pCuts0,
p, Gia_ObjFaninId0(pObj, iObj), 1);
1034 int nCuts1 = Mf_ManPrepareCuts(pCuts1,
p, Gia_ObjFaninId1(pObj, iObj), 1);
1035 int fComp0 = Gia_ObjFaninC0(pObj);
1036 int fComp1 = Gia_ObjFaninC1(pObj);
1037 int iSibl = Gia_ObjSibl(
p->pGia, iObj);
1038 Mf_Cut_t * pCut0, * pCut1, * pCut0Lim = pCuts0 + nCuts0, * pCut1Lim = pCuts1 + nCuts1;
1040 for ( i = 0; i < nCutNum; i++ )
1041 pCutsR[i] = pCuts + i;
1045 Gia_Obj_t * pObjE = Gia_ObjSiblObj(
p->pGia, iObj);
1046 int fCompE = Gia_ObjPhase(pObj) ^ Gia_ObjPhase(pObjE);
1047 int nCuts2 = Mf_ManPrepareCuts(pCuts2,
p, iSibl, 0);
1048 Mf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
1049 for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
1051 *pCutsR[nCutsR] = *pCut2;
1052 if ( pCutsR[nCutsR]->iFunc >= 0 )
1053 pCutsR[nCutsR]->
iFunc = Abc_LitNotCond( pCutsR[nCutsR]->iFunc, fCompE );
1054 Mf_CutParams(
p, pCutsR[nCutsR], pBest->
nFlowRefs );
1055 nCutsR = Mf_SetAddCut( pCutsR, nCutsR, nCutNum );
1058 if ( Gia_ObjIsMuxId(
p->pGia, iObj) )
1061 int nCuts2 = Mf_ManPrepareCuts(pCuts2,
p, Gia_ObjFaninId2(
p->pGia, iObj), 1);
1062 int fComp2 = Gia_ObjFaninC2(
p->pGia, pObj);
1063 Mf_Cut_t * pCut2, * pCut2Lim = pCuts2 + nCuts2;
1064 p->CutCount[0] += nCuts0 * nCuts1 * nCuts2;
1065 for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
1066 for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
1067 for ( pCut2 = pCuts2; pCut2 < pCut2Lim; pCut2++ )
1069 if ( Mf_CutCountBits(pCut0->
Sign | pCut1->
Sign | pCut2->
Sign) > nLutSize )
1072 if ( !Mf_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
1074 if ( Mf_SetLastCutIsContained(pCutsR, nCutsR) )
1077 if (
p->pPars->fCutMin && Mf_CutComputeTruthMux(
p, pCut0, pCut1, pCut2, fComp0, fComp1, fComp2, pCutsR[nCutsR]) )
1078 pCutsR[nCutsR]->
Sign = Mf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
1079 Mf_CutParams(
p, pCutsR[nCutsR], pBest->
nFlowRefs );
1080 nCutsR = Mf_SetAddCut( pCutsR, nCutsR, nCutNum );
1085 int fIsXor = Gia_ObjIsXor(pObj);
1086 p->CutCount[0] += nCuts0 * nCuts1;
1087 for ( pCut0 = pCuts0; pCut0 < pCut0Lim; pCut0++ )
1088 for ( pCut1 = pCuts1; pCut1 < pCut1Lim; pCut1++ )
1090 if ( (
int)(pCut0->
nLeaves + pCut1->
nLeaves) > nLutSize && Mf_CutCountBits(pCut0->
Sign | pCut1->
Sign) > nLutSize )
1093 if ( !Mf_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
1095 if ( Mf_SetLastCutIsContained(pCutsR, nCutsR) )
1098 if (
p->pPars->fCutMin && Mf_CutComputeTruth(
p, pCut0, pCut1, fComp0, fComp1, pCutsR[nCutsR], fIsXor) )
1099 pCutsR[nCutsR]->
Sign = Mf_CutGetSign(pCutsR[nCutsR]->pLeaves, pCutsR[nCutsR]->nLeaves);
1100 Mf_CutParams(
p, pCutsR[nCutsR], pBest->
nFlowRefs );
1101 nCutsR = Mf_SetAddCut( pCutsR, nCutsR, nCutNum );
1109 printf(
"*** Obj = %d FlowRefs = %.2f MapRefs = %2d\n", iObj, pBest->
nFlowRefs, pBest->
nMapRefs );
1110 for ( i = 0; i < nCutsR; i++ )
1111 Mf_CutPrint(
p, pCutsR[i] );
1117 pBest->
iCutSet = Mf_ManSaveCuts(
p, pCutsR, nCutsR );
1119 assert( nCutsR > 0 && nCutsR < nCutNum );
1121 p->nCutCounts[pCutsR[0]->
nLeaves]++;
1122 p->CutCount[3] += nCutsR;
1140 Gia_Obj_t * pObj, * pCtrl, * pData0, * pData1;
1142 Vec_IntFill( vRefs, Gia_ManObjNum(
p), 0 );
1145 if ( Gia_ObjIsAnd(Gia_ObjFanin0(pObj)) )
1146 Vec_IntAddToEntry( vRefs, Gia_ObjFaninId0(pObj, i), 1 );
1147 if ( Gia_ObjIsAnd(Gia_ObjFanin1(pObj)) )
1148 Vec_IntAddToEntry( vRefs, Gia_ObjFaninId1(pObj, i), 1 );
1151 if ( Gia_ObjIsMuxId(
p, i) && Gia_ObjIsAnd(Gia_ObjFanin2(
p, pObj)) )
1152 Vec_IntAddToEntry( vRefs, Gia_ObjFaninId2(
p, i), 1 );
1157 pData0 = Gia_Regular(pData0);
1158 pData1 = Gia_Regular(pData1);
1159 if ( Gia_ObjIsAnd(pCtrl) )
1160 Vec_IntAddToEntry( vRefs, Gia_ObjId(
p, pCtrl), -1 );
1161 if ( pData0 == pData1 && Gia_ObjIsAnd(pData0) )
1162 Vec_IntAddToEntry( vRefs, Gia_ObjId(
p, pData0), -1 );
1166 if ( Gia_ObjIsAnd(Gia_ManObj(
p, Id)) )
1167 Vec_IntAddToEntry( vRefs, Id, 1 );
1168 for ( i = 0; i < Vec_IntSize(vRefs); i++ )
1169 Vec_IntUpdateEntry( vRefs, i, 1 );
1173 float Coef = 1.0 / (1.0 + (
p->Iter + 1) * (
p->Iter + 1));
1174 int * pCut, i, k, Id;
1178 Delay = Abc_MaxInt( Delay, Mf_ManObj(
p, Id)->Delay );
1180 if (
p->pPars->DelayTarget == -1 &&
p->pPars->nRelaxRatio )
1181 p->pPars->DelayTarget = (int)((
float)Delay * (100.0 +
p->pPars->nRelaxRatio) / 100.0);
1182 if (
p->pPars->DelayTarget != -1 )
1184 if ( Delay < p->pPars->DelayTarget + 0.01 )
1185 Delay =
p->pPars->DelayTarget;
1186 else if (
p->pPars->nRelaxRatio == 0 )
1187 Abc_Print( 0,
"Relaxing user-specified delay target from %d to %d.\n",
p->pPars->DelayTarget, Delay );
1189 p->pPars->Delay = Delay;
1196 Mf_ObjMapRefInc(
p, Id );
1197 p->pPars->Area =
p->pPars->Edge =
p->pPars->Clause = 0;
1200 if ( !Mf_ObjMapRefNum(
p, i) )
1202 pCut = Mf_ObjCutBest(
p, i );
1204 for ( k = 1; k <= Mf_CutSize(pCut); k++ )
1205 Mf_ObjMapRefInc(
p, pCut[k] );
1206 p->pPars->Edge += Mf_CutSize(pCut);
1208 if (
p->pPars->fGenCnf ||
p->pPars->fGenLit )
1209 p->pPars->Clause += Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1212 for ( i = 0; i < Gia_ManObjNum(
p->pGia); i++ )
1213 p->pLfObjs[i].nFlowRefs = Coef *
p->pLfObjs[i].nFlowRefs + (1.0 - Coef) * Abc_MaxFloat(1,
p->pLfObjs[i].nMapRefs);
1215 return p->pPars->Area;
1233 assert( !
p->pPars->fCutMin &&
p->pGia->vMapping == NULL );
1234 vMapping = Vec_IntAlloc( Gia_ManObjNum(
p->pGia) + (
int)
p->pPars->Edge + (
int)
p->pPars->Area * 2 );
1235 Vec_IntFill( vMapping, Gia_ManObjNum(
p->pGia), 0 );
1238 if ( !Mf_ObjMapRefNum(
p, i) )
1240 pCut = Mf_ObjCutBest(
p, i );
1241 Vec_IntWriteEntry( vMapping, i, Vec_IntSize(vMapping) );
1242 Vec_IntPush( vMapping, Mf_CutSize(pCut) );
1243 for ( k = 1; k <= Mf_CutSize(pCut); k++ )
1244 Vec_IntPush( vMapping, pCut[k] );
1245 Vec_IntPush( vMapping, i );
1247 assert( Vec_IntCap(vMapping) == 16 || Vec_IntSize(vMapping) == Vec_IntCap(vMapping) );
1248 p->pGia->vMapping = vMapping;
1262 Gia_ManConst0(pGia)->Value = 0;
1264 pObj->
Value = Gia_ManAppendCi( pNew );
1266 pNew->
vMapping = Vec_IntAlloc( Gia_ManObjNum(pGia) + 2*Gia_ManXorNum(pGia) + 2*Gia_ManMuxNum(pGia) + (
int)
p->pPars->Edge + (
int)
p->pPars->Area * 2 );
1267 Vec_IntFill( pNew->
vMapping, Gia_ManObjNum(pGia) + 2*Gia_ManXorNum(pGia) + 2*Gia_ManMuxNum(pGia), 0 );
1271 if ( Gia_ObjIsMuxId(pGia, i) )
1272 pObj->
Value = Gia_ManAppendMux( pNew, Gia_ObjFanin2Copy(pGia, pObj), Gia_ObjFanin1Copy(pObj), Gia_ObjFanin0Copy(pObj) );
1273 else if ( Gia_ObjIsXor(pObj) )
1274 pObj->
Value = Gia_ManAppendXor( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1276 pObj->
Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1277 if ( !Mf_ObjMapRefNum(
p, i) )
1279 pCut = Mf_ObjCutBest(
p, i );
1281 Vec_IntPush( pNew->
vMapping, Mf_CutSize(pCut));
1282 for ( k = 1; k <= Mf_CutSize(pCut); k++ )
1283 Vec_IntPush( pNew->
vMapping, Abc_Lit2Var(Gia_ManObj(pGia, pCut[k])->Value) );
1287 pObj->
Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1296 Vec_Int_t * vCopies = Vec_IntStartFull( Gia_ManObjNum(
p->pGia) );
1297 Vec_Int_t * vMapping = Vec_IntStart( 2 * Gia_ManObjNum(
p->pGia) + (
int)
p->pPars->Edge + 2 * (
int)
p->pPars->Area );
1298 Vec_Int_t * vMapping2 = Vec_IntStart( (
int)
p->pPars->Edge + 2 * (
int)
p->pPars->Area + 1000 );
1299 Vec_Int_t * vCover = Vec_IntAlloc( 1 << 16 );
1300 Vec_Int_t * vLeaves = Vec_IntAlloc( 16 );
1301 int i, k, Id, iLit, * pCut;
1302 word uTruth = 0, * pTruth = &uTruth;
1306 pNew->
pName = Abc_UtilStrsav(
p->pGia->pName );
1307 pNew->
pSpec = Abc_UtilStrsav(
p->pGia->pSpec );
1309 Vec_IntWriteEntry( vCopies, 0, 0 );
1311 Vec_IntWriteEntry( vCopies, Id, Gia_ManAppendCi(pNew) );
1315 if ( !Mf_ObjMapRefNum(
p, i) )
1317 pCut = Mf_ObjCutBest(
p, i );
1318 if ( Mf_CutSize(pCut) == 0 )
1320 assert( Abc_Lit2Var(Mf_CutFunc(pCut)) == 0 );
1321 Vec_IntWriteEntry( vCopies, i, Mf_CutFunc(pCut) );
1324 if ( Mf_CutSize(pCut) == 1 )
1326 assert( Abc_Lit2Var(Mf_CutFunc(pCut)) == 1 );
1327 iLit = Vec_IntEntry( vCopies, pCut[1] );
1328 Vec_IntWriteEntry( vCopies, i, Abc_LitNotCond(iLit, Abc_LitIsCompl(Mf_CutFunc(pCut))) );
1331 Vec_IntClear( vLeaves );
1332 for ( k = 1; k <= Mf_CutSize(pCut); k++ )
1333 Vec_IntPush( vLeaves, Vec_IntEntry(vCopies, pCut[k]) );
1334 pTruth = Vec_MemReadEntry(
p->vTtMem, Abc_Lit2Var(Mf_CutFunc(pCut)) );
1335 iLit =
Kit_TruthToGia( pNew, (
unsigned *)pTruth, Vec_IntSize(vLeaves), vCover, vLeaves, 0 );
1336 Vec_IntWriteEntry( vCopies, i, Abc_LitNotCond(iLit, Abc_LitIsCompl(Mf_CutFunc(pCut))) );
1338 Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLit), Vec_IntSize(vMapping2) );
1339 Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1341 Vec_IntPush( vMapping2, Abc_Lit2Var(iLit) );
1342 Vec_IntPush( vMapping2, Abc_Lit2Var(Vec_IntEntry(vCopies, i)) );
1346 iLit = Vec_IntEntry( vCopies, Gia_ObjFaninId0p(
p->pGia, pObj) );
1347 iLit = Gia_ManAppendCo( pNew, Abc_LitNotCond(iLit, Gia_ObjFaninC0(pObj)) );
1349 Vec_IntFree( vCopies );
1350 Vec_IntFree( vCover );
1351 Vec_IntFree( vLeaves );
1353 if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
1354 Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
1356 Vec_IntFillExtra( vMapping, Gia_ManObjNum(pNew), 0 );
1357 assert( Vec_IntSize(vMapping) == Gia_ManObjNum(pNew) );
1360 Vec_IntAddToEntry( vMapping, i, Gia_ManObjNum(pNew) );
1361 Vec_IntAppend( vMapping, vMapping2 );
1362 Vec_IntFree( vMapping2 );
1390 if ( Gia_ManHasChoices(pGia) )
1393 p->clkStart = Abc_Clock();
1396 p->vTtMem = pPars->
fCutMin ? Vec_MemAllocForTT( pPars->
nLutSize, 0 ) : NULL;
1399 Vec_PtrGrow( &
p->vPages, 256 );
1402 Vec_IntGrow( &
p->vCnfSizes, 10000 );
1403 Vec_IntPush( &
p->vCnfSizes, 1 );
1404 Vec_IntPush( &
p->vCnfSizes, 2 );
1405 Vec_IntGrow( &
p->vCnfMem, 10000 );
1407 vFlowRefs = Vec_IntAlloc(0);
1410 p->pLfObjs[i].nFlowRefs = Entry;
1411 Vec_IntFree(vFlowRefs);
1416 assert( !
p->pPars->fGenCnf || !
p->pPars->fGenLit || Vec_IntSize(&
p->vCnfSizes) == Vec_MemEntryNum(
p->vTtMem) );
1417 if (
p->pPars->fCutMin )
1418 Vec_MemHashFree(
p->vTtMem );
1419 if (
p->pPars->fCutMin )
1420 Vec_MemFree(
p->vTtMem );
1421 Vec_PtrFreeData( &
p->vPages );
1468 if ( !
p->pPars->fVerbose )
1470 printf(
"%s : ", pTitle );
1471 printf(
"Level =%6lu ", (
long)
p->pPars->Delay );
1472 printf(
"Area =%9lu ", (
long)
p->pPars->Area );
1473 printf(
"Edge =%9lu ", (
long)
p->pPars->Edge );
1474 if (
p->pPars->fGenCnf )
1475 printf(
"CNF =%9lu ", (
long)
p->pPars->Clause );
1476 if (
p->pPars->fGenLit )
1477 printf(
"FFL =%9lu ", (
long)
p->pPars->Clause );
1478 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
1483 if ( !
p->pPars->fVerbose )
1485 printf(
"LutSize = %d ",
p->pPars->nLutSize );
1486 printf(
"CutNum = %d ",
p->pPars->nCutNum );
1487 printf(
"Iter = %d ",
p->pPars->nRounds +
p->pPars->nRoundsEla );
1488 printf(
"Edge = %d ",
p->pPars->fOptEdge );
1489 printf(
"CutMin = %d ",
p->pPars->fCutMin );
1490 printf(
"Coarse = %d ",
p->pPars->fCoarsen );
1491 printf(
"CNF = %d ",
p->pPars->fGenCnf );
1492 printf(
"FFL = %d ",
p->pPars->fGenLit );
1494 printf(
"Computing cuts...\r" );
1500 float MemMan = 1.0 *
sizeof(
Mf_Obj_t) * Gia_ManObjNum(
p->pGia) / (1<<20);
1501 float MemCuts = 1.0 *
sizeof(int) * (1 << 16) * Vec_PtrSize(&
p->vPages) / (1<<20);
1502 float MemTt =
p->vTtMem ? Vec_MemMemory(
p->vTtMem) / (1<<20) : 0;
1503 float MemMap = Vec_IntMemory(pNew->
vMapping) / (1<<20);
1504 if (
p->CutCount[0] == 0 )
1506 if ( !
p->pPars->fVerbose )
1508 printf(
"CutPair = %.0f ",
p->CutCount[0] );
1509 printf(
"Merge = %.0f (%.2f %%) ",
p->CutCount[1], 100.0*
p->CutCount[1]/
p->CutCount[0] );
1510 printf(
"Eval = %.0f (%.2f %%) ",
p->CutCount[2], 100.0*
p->CutCount[2]/
p->CutCount[0] );
1511 printf(
"Cut = %.0f (%.2f %%) ",
p->CutCount[3], 100.0*
p->CutCount[3]/
p->CutCount[0] );
1513 printf(
"Gia = %.2f MB ", MemGia );
1514 printf(
"Man = %.2f MB ", MemMan );
1515 printf(
"Cut = %.2f MB ", MemCuts );
1516 printf(
"Map = %.2f MB ", MemMap );
1517 printf(
"TT = %.2f MB ", MemTt );
1518 printf(
"Total = %.2f MB", MemGia + MemMan + MemCuts + MemMap + MemTt );
1523 for ( i = 0; i <=
p->pPars->nLutSize; i++ )
1524 printf(
"%d = %d ", i,
p->nCutCounts[i] );
1526 printf(
"TT = %d (%.2f %%) ", Vec_MemEntryNum(
p->vTtMem), 100.0 * Vec_MemEntryNum(
p->vTtMem) /
p->CutCount[2] );
1527 Abc_PrintTime( 1,
"Time", Abc_Clock() -
p->clkStart );
1553 int i, Count = Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1554 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1555 if ( !Mf_ObjMapRefInc(
p, pCut[i]) && Mf_ManObj(
p, pCut[i])->iCutSet )
1561 int i, Count = Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1562 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1563 if ( !Mf_ObjMapRefDec(
p, pCut[i]) && Mf_ManObj(
p, pCut[i])->iCutSet )
1567static inline int Mf_CutAreaRefed(
Mf_Man_t *
p,
int * pCut )
1574static inline int Mf_CutAreaDerefed(
Mf_Man_t *
p,
int * pCut )
1581static inline int Mf_CutAreaMffc(
Mf_Man_t *
p,
int iObj )
1583 return Mf_ObjMapRefNum(
p, iObj) ?
1584 Mf_CutAreaRefed (
p, Mf_ObjCutBest(
p, iObj)) :
1585 Mf_CutAreaDerefed(
p, Mf_ObjCutBest(
p, iObj));
1590 int i, Count = Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1591 if ( Limit == 0 )
return Count;
1592 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1594 Vec_IntPush( vTemp, pCut[i] );
1595 if ( !Mf_ObjMapRefInc(
p, pCut[i]) && Mf_ManObj(
p, pCut[i])->iCutSet )
1602 int i, Count = Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1603 if ( Limit == 0 )
return Count;
1604 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1606 Vec_IntPush( vTemp, pCut[i] );
1607 if ( !Mf_ObjMapRefDec(
p, pCut[i]) && Mf_ManObj(
p, pCut[i])->iCutSet )
1612static inline int Mf_CutAreaRefed2(
Mf_Man_t *
p,
int * pCut )
1615 Vec_IntClear( &
p->vTemp );
1618 Mf_ObjMapRefInc(
p, iObj );
1621static inline int Mf_CutAreaDerefed2(
Mf_Man_t *
p,
int * pCut )
1624 Vec_IntClear( &
p->vTemp );
1627 Mf_ObjMapRefDec(
p, iObj );
1630static inline int Mf_CutAreaRefed2Multi(
Mf_Man_t *
p,
int iObj,
int ** ppCuts,
int nCuts )
1632 int Ela1 = 0, iTemp, i;
1633 Vec_IntClear( &
p->vTemp );
1634 for ( i = 0; i < nCuts; i++ )
1636 assert( Mf_ObjMapRefNum(
p, iObj) == 0 );
1638 Mf_ObjMapRefInc(
p, iTemp );
1642static inline float Mf_CutFlow(
Mf_Man_t *
p,
int * pCut,
int * pTime )
1647 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1649 pObj = Mf_ManObj(
p, pCut[i] );
1650 Time = Abc_MaxInt( Time, pObj->
Delay );
1654 return Flow + Mf_CutArea(
p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1656static inline void Mf_ObjComputeBestCut(
Mf_Man_t *
p,
int iObj )
1659 int * pCutSet = Mf_ObjCutSet(
p, iObj );
1660 int * pCut, * pCutBest = NULL;
1661 int Value1 = -1, Value2 = -1;
1668 assert( !Mf_CutIsTriv(pCut, iObj) );
1669 assert( Mf_CutSize(pCut) <=
p->pPars->nLutSize );
1670 Flow =
p->fUseEla ? Mf_CutAreaDerefed2(
p, pCut) : Mf_CutFlow(
p, pCut, &Time);
1671 if ( pCutBest == NULL || FlowBest > Flow +
MF_EPSILON || (FlowBest > Flow -
MF_EPSILON && TimeBest > Time) )
1672 pCutBest = pCut, FlowBest = Flow, TimeBest = Time;
1674 assert( pCutBest != NULL );
1679 assert( Value1 >= Value2 );
1681 Mf_CutFlow(
p, pCutBest, &TimeBest );
1682 pBest->
Delay = TimeBest;
1683 pBest->
Flow = FlowBest / Mf_ManObj(
p, iObj)->nFlowRefs;
1684 Mf_ObjSetBestCut( pCutSet, pCutBest );
1704 int i, iObj, Count = 0;
1705 Vec_Int_t * vMapping = Vec_IntAlloc( 3 * Gia_ManObjNum(pGia) );
1706 Vec_IntFill( vMapping, Gia_ManObjNum(pGia), 0 );
1708 if ( Mf_ObjMapRefNum(
p, iObj) )
1710 int * pCut = Mf_ObjCutBest(
p, iObj);
1711 Vec_IntWriteEntry( vMapping, iObj, Vec_IntSize(vMapping) );
1712 Vec_IntPush( vMapping, Mf_CutSize(pCut) );
1713 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1714 Vec_IntPush( vMapping, pCut[i] );
1715 Vec_IntPush( vMapping, iObj );
1720 printf(
"Mapping is %.2fx larger than AIG manager.\n", 1.0*Vec_IntSize(vMapping)/Gia_ManObjNum(pGia) );
1738 int i, Count, nMax = Vec_IntFindMax( vFanCounts );
1739 Vec_Int_t * vCounts = Vec_IntStart( nMax + 1 );
1741 if ( Count && Gia_ObjIsAnd(Gia_ManObj(pGia, i)) )
1742 Vec_IntAddToEntry( vCounts, Count, 1 );
1743 printf(
"\nFanout distribution for internal nodes:\n" );
1745 if ( Count ) printf(
"Fanout = %5d : Nodes = %5d.\n", i, Count );
1746 printf(
"Total nodes with fanout = %d. Max fanout = %d.\n\n", Vec_IntCountPositive(vCounts), nMax );
1747 Vec_IntFree( vCounts );
1753 printf(
"%5d : Level = %5d Refs = %5d Mffc = %5d\n",
1754 iObj, Gia_ObjLevelId(pGia, iObj), Mf_ObjMapRefNum(
p, iObj), (Area = Mf_CutAreaMffc(
p, iObj)) );
1760 int * ppCuts[32], nCuts = 0;
1761 int iFanout, i, nAreaSum = 0, nAreaBest = 0;
1764 if ( Gia_ObjIsCo(Gia_ManObj(pGia, iFanout)) )
1767 assert( Mf_ObjMapRefNum(
p, iObj) > 1 );
1769 assert( Mf_ObjMapRefNum(
p, iFanout) > 0 );
1771 printf(
"\nPivot node = %d\n", iObj );
1777 Mf_ObjMapRefInc(
p, iFanout );
1779 ppCuts[nCuts++] = Mf_ObjCutBest(
p, iFanout );
1780 nAreaBest = Mf_CutAreaRefed2Multi(
p, iObj, ppCuts, nCuts );
1782 Mf_ObjMapRefDec(
p, iFanout );
1783 printf(
"Sum of MFFC sizes = %d\n", nAreaSum );
1784 printf(
"Shared MFFC size = %d\n", nAreaBest );
1794 printf(
"\nIndividual logic cones for mapping with %d nodes:\n", nNodes );
1796 if ( Count >= 2 && Count <= nOutMax && Gia_ObjIsAnd(Gia_ManObj(pGia, i)) )
1798 printf(
"\nFinished printing individual logic cones.\n" );
1818 Mf_ObjComputeBestCut(
p, i );
1828 if ( Gia_ManHasChoices(pGia) )
1840 for (
p->Iter = 1;
p->Iter <
p->pPars->nRounds;
p->Iter++ )
1843 for ( ;
p->Iter <
p->pPars->nRounds + pPars->
nRoundsEla;
p->Iter++ )
1847 Vec_MemDumpTruthTables(
p->vTtMem, Gia_ManName(
p->pGia), pPars->
nLutSize );
1854 if (
p->pPars->fGenCnf )
1881 assert( nLutSize >= 3 && nLutSize <= 8 );
1903 printf(
"CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->
nVars, pCnf->
nClauses, pCnf->
nLiterals );
1904 Abc_PrintTime( 1,
"Time", Abc_Clock() - clk );
#define ABC_SWAP(Type, a, b)
#define ABC_FALLOC(type, num)
#define ABC_ALLOC(type, num)
#define ABC_INFINITY
MACRO DEFINITIONS ///.
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct Cnf_Dat_t_ Cnf_Dat_t
void Cnf_DataFree(Cnf_Dat_t *p)
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
void Mf_ManPrintQuit(Mf_Man_t *p, Gia_Man_t *pNew)
struct Mf_Cut_t_ Mf_Cut_t
#define Mf_SetForEachCut(pList, pCut, i)
#define MF_LEAF_MAX
DECLARATIONS ///.
Gia_Man_t * Mf_ManDeriveMapping(Mf_Man_t *p)
Vec_Int_t * Mf_ManDeriveCnfs(Mf_Man_t *p, int *pnVars, int *pnClas, int *pnLits)
Vec_Wrd_t * Mf_ManTruthCollect(int Limit)
int Mf_ManSetMapRefs(Mf_Man_t *p)
void Mf_ManPrintFanoutProfile(Mf_Man_t *p, Vec_Int_t *vFanCounts)
void Mf_ManPrintStats(Mf_Man_t *p, char *pTitle)
int Mf_ManMappingFromMapping(Mf_Man_t *p)
int Mf_CutDeref_rec(Mf_Man_t *p, int *pCut)
Gia_Man_t * Mf_ManPerformMapping(Gia_Man_t *pGia, Jf_Par_t *pPars)
int Mf_CutRef2_rec(Mf_Man_t *p, int *pCut, Vec_Int_t *vTemp, int Limit)
int Mf_CutRef_rec(Mf_Man_t *p, int *pCut)
void Mf_ManProfileTruths(Mf_Man_t *p)
Cnf_Dat_t * Mf_ManDeriveCnf(Mf_Man_t *p, int fCnfObjIds, int fAddOrCla)
void Mf_ManSetDefaultPars(Jf_Par_t *pPars)
void Mf_ManSetFlowRefs(Gia_Man_t *p, Vec_Int_t *vRefs)
void Mf_ManOptimizationOne(Mf_Man_t *p, int iObj)
int Mf_ManTruthCanonicize(word *t, int nVars)
struct Mf_Man_t_ Mf_Man_t
Gia_Man_t * Mf_ManDeriveMappingCoarse(Mf_Man_t *p)
void Mf_ManDumpCnf(Gia_Man_t *p, char *pFileName, int nLutSize, int fCnfObjIds, int fAddOrCla, int fVerbose)
void Mf_ManFree(Mf_Man_t *p)
int Kit_TruthToGia(Gia_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
DECLARATIONS ///.
int Mf_ManPrintMfccStats(Mf_Man_t *p, int iObj)
void Mf_ManComputeMapping(Mf_Man_t *p)
void Mf_ObjMergeOrder(Mf_Man_t *p, int iObj)
void Mf_ManPrintInit(Mf_Man_t *p)
void Mf_ManOptimization(Mf_Man_t *p)
struct Mf_Obj_t_ Mf_Obj_t
int Mf_CutDeref2_rec(Mf_Man_t *p, int *pCut, Vec_Int_t *vTemp, int Limit)
Gia_Man_t * Mf_ManDeriveMappingGia(Mf_Man_t *p)
void Mf_ManComputeCuts(Mf_Man_t *p)
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
Mf_Man_t * Mf_ManAlloc(Gia_Man_t *pGia, Jf_Par_t *pPars)
void Gia_ManStop(Gia_Man_t *p)
Gia_Man_t * Gia_ManDupMuxes(Gia_Man_t *p, int Limit)
void Gia_ManStaticFanoutStop(Gia_Man_t *p)
double Gia_ManMemory(Gia_Man_t *p)
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
#define Gia_ManForEachAnd(p, pObj, i)
void Gia_ManStaticMappingFanoutStart(Gia_Man_t *p, Vec_Int_t **pvIndex)
#define Gia_ManForEachCoId(p, Id, i)
void Gia_ManStopP(Gia_Man_t **p)
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
#define Gia_ManForEachCoDriverId(p, DriverId, i)
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
struct Gia_Obj_t_ Gia_Obj_t
int Gia_ObjIsMuxType(Gia_Obj_t *pNode)
struct Gia_Man_t_ Gia_Man_t
void Gia_ManPrintMuxStats(Gia_Man_t *p)
#define Gia_ManForEachAndReverseId(p, i)
void Gia_ManMappingVerify(Gia_Man_t *p)
struct Jf_Par_t_ Jf_Par_t
#define Gia_ObjForEachFanoutStaticId(p, Id, FanId, i)
#define Gia_ManForEachCo(p, pObj, i)
#define Gia_ManForEachCi(p, pObj, i)
void Gia_ManSetPhase(Gia_Man_t *p)
int Gia_ManLevelNum(Gia_Man_t *p)
#define Gia_ManForEachAndId(p, i)
#define Gia_ManForEachCiId(p, Id, i)
unsigned __int64 word
DECLARATIONS ///.
int Kit_TruthLitNum(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Vec_Wrd_t * Mpm_ManGetTruthWithCnf(int Limit)
FUNCTION DEFINITIONS ///.
int pLeaves[MF_LEAF_MAX+1]
int nCutCounts[MF_LEAF_MAX+1]
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.