ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaMf.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "misc/vec/vecMem.h"
23#include "misc/util/utilTruth.h"
24#include "misc/extra/extra.h"
25#include "sat/cnf/cnf.h"
26#include "opt/dau/dau.h"
27#include "bool/kit/kit.h"
28
30
34
35#define MF_LEAF_MAX 10
36#define MF_CUT_MAX 16
37#define MF_LOG_PAGE 12
38#define MF_NO_LEAF 31
39#define MF_TT_WORDS ((MF_LEAF_MAX > 6) ? 1 << (MF_LEAF_MAX-6) : 1)
40#define MF_NO_FUNC 134217727 // (1<<27)-1
41#define MF_EPSILON 0.005
42
43typedef struct Mf_Cut_t_ Mf_Cut_t;
45{
46 word Sign; // signature
47 int Delay; // delay
48 float Flow; // flow
49 unsigned iFunc : 27; // function (MF_NO_FUNC)
50 unsigned nLeaves : 5; // leaf number (MF_NO_LEAF)
51 int pLeaves[MF_LEAF_MAX+1]; // leaves
52};
53typedef struct Mf_Obj_t_ Mf_Obj_t;
55{
56 int iCutSet; // cutset
57 float Flow; // area
58 float nFlowRefs; // flow references
59 unsigned Delay : 16; // delay
60 unsigned nMapRefs : 16; // map references
61};
62typedef struct Mf_Man_t_ Mf_Man_t;
64{
65 // user data
66 Gia_Man_t * pGia0; // original manager
67 Gia_Man_t * pGia; // derived manager
68 Jf_Par_t * pPars; // parameters
69 // cut data
70 Mf_Obj_t * pLfObjs; // best cuts
71 Vec_Ptr_t vPages; // cut memory
72 Vec_Mem_t * vTtMem; // truth tables
73 Vec_Int_t vCnfSizes; // handles to CNF
74 Vec_Int_t vCnfMem; // memory for CNF
75 Vec_Int_t vTemp; // temporary array
76 int iCur; // current position
77 int Iter; // mapping iterations
78 int fUseEla; // use exact area
79 // statistics
80 abctime clkStart; // starting time
81 double CutCount[4]; // cut counts
83};
84
85static inline Mf_Obj_t * Mf_ManObj( Mf_Man_t * p, int i ) { return p->pLfObjs + i; }
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; }
89
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; }
93
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; }
98
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++ )
101
102extern int Kit_TruthToGia( Gia_Man_t * pMan, unsigned * pTruth, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
103
107
119static int s_nCalls = 0;
120static Vec_Mem_t * s_vTtMem = NULL;
121int Mf_ManTruthCanonicize( word * t, int nVars )
122{
123 word Temp, Best = *t;
124 int r, i, Config = 0;
125 for ( r = 0; r < 1; r++ )
126 {
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);
132 }
133 *t = Best;
134 if ( s_vTtMem == NULL )
135 s_vTtMem = Vec_MemAllocForTT( 6, 0 );
136 Vec_MemHashInsert( s_vTtMem, t );
137 s_nCalls++;
138 return Config;
139}
141{
142 if ( s_vTtMem == NULL )
143 return;
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 );
147 s_vTtMem = NULL;
148 s_nCalls = 0;
149}
150
152{
153 extern Vec_Wrd_t * Mpm_ManGetTruthWithCnf( int Limit );
154 int * pPerm = Extra_PermSchedule( 6 );
155 int * pComp = Extra_GreyCodeSchedule( 6 );
156 Vec_Wrd_t * vTruths = Mpm_ManGetTruthWithCnf( Limit );
157 Vec_Wrd_t * vResult = Vec_WrdAlloc( 1 << 20 );
158 word uTruth, tCur, tTemp1, tTemp2;
159 int i, p, c, k;
160 Vec_WrdForEachEntry( vTruths, uTruth, k )
161 {
162 for ( i = 0; i < 2; i++ )
163 {
164 tCur = i ? ~uTruth : uTruth;
165 tTemp1 = tCur;
166 for ( p = 0; p < 720; p++ )
167 {
168 tTemp2 = tCur;
169 for ( c = 0; c < 64; c++ )
170 {
171 tCur = Abc_Tt6Flip( tCur, pComp[c] );
172 Vec_WrdPush( vResult, tCur );
173 }
174 assert( tTemp2 == tCur );
175 tCur = Abc_Tt6SwapAdjacent( tCur, pPerm[p] );
176 }
177 assert( tTemp1 == tCur );
178 }
179 }
180 ABC_FREE( pPerm );
181 ABC_FREE( pComp );
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) );
188 Vec_WrdForEachEntry( vTruths, uTruth, k )
189 {
190 Mf_ManTruthCanonicize( &uTruth, 6 );
191 Vec_WrdWriteEntry( vTruths, k, uTruth );
192 }
193 vResult = Vec_WrdUniqifyHash( vTruths, 1 );
194 Vec_WrdFree( vTruths );
195 printf( "Unique = %d. \n", Vec_WrdSize(vResult) );
196 return vResult;
197}
199{
200 Vec_Wrd_t * vTruths = Mf_ManTruthCollect( 10 );
201 int RetValue = Vec_WrdSize( vTruths );
202 Vec_WrdFree( vTruths );
203 return RetValue;
204}
205
218{
219 Vec_Int_t * vCounts;
220 int i, Entry, * pCut, Counter = 0;
221 vCounts = Vec_IntStart( Vec_IntSize(&p->vCnfSizes) );
222 Gia_ManForEachAndId( p->pGia, i )
223 {
224 if ( !Mf_ObjMapRefNum(p, i) )
225 continue;
226 pCut = Mf_ObjCutBest( p, i );
227 Vec_IntAddToEntry( vCounts, Abc_Lit2Var(Mf_CutFunc(pCut)), 1 );
228 }
229 Vec_IntForEachEntry( vCounts, Entry, i )
230 {
231 if ( Entry == 0 )
232 continue;
233 printf( "%6d : ", Counter++ );
234 printf( "%6d : ", i );
235 printf( "Occur = %4d ", Entry );
236 printf( "CNF size = %2d ", Vec_IntEntry(&p->vCnfSizes, i) );
237 Dau_DsdPrintFromTruth( Vec_MemReadEntry(p->vTtMem, i), p->pPars->nLutSize );
238 }
239 Vec_IntFree( vCounts );
240}
241
253static inline void Mf_CutPrintOne( int * pCut )
254{
255 int i;
256 printf( "%d {", Mf_CutSize(pCut) );
257 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
258 printf( " %d", pCut[i] );
259 printf( " }\n" );
260}
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 )
263{
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) )
268 nLits++;
269 return nLits;
270}
271Vec_Int_t * Mf_ManDeriveCnfs( Mf_Man_t * p, int * pnVars, int * pnClas, int * pnLits )
272{
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 );
278 // constant/buffer
279 for ( iFunc = 0; iFunc < 2; iFunc++ )
280 {
281 if ( p->pPars->nLutSize <= 6 )
282 nCubes = Abc_Tt6Cnf( *Vec_MemReadEntry(p->vTtMem, iFunc), iFunc, pCnf );
283 else
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] );
291 }
292 // other functions
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);
296 Gia_ManForEachAndId( p->pGia, i )
297 {
298 if ( !Mf_ObjMapRefNum(p, i) )
299 continue;
300 pCut = Mf_ObjCutBest( p, i );
301 //Mf_CutPrintOne( pCut );
302 iFunc = Abc_Lit2Var( Mf_CutFunc(pCut) );
303 if ( Vec_IntEntry(vCnfs, iFunc) == -1 )
304 {
305 if ( p->pPars->nLutSize <= 6 )
306 nCubes = Abc_Tt6Cnf( *Vec_MemReadEntry(p->vTtMem, iFunc), Mf_CutSize(pCut), pCnf );
307 else
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) );
311 // save CNF
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] );
317 }
318 *pnVars += 1;
319 *pnClas += Vec_IntEntry(&p->vCnfSizes, iFunc);
320 *pnLits += Vec_IntEntry(vLits, iFunc);
321 }
322 Vec_IntFree( vLits );
323 return vCnfs;
324}
325
337Cnf_Dat_t * Mf_ManDeriveCnf( Mf_Man_t * p, int fCnfObjIds, int fAddOrCla )
338{
339 Cnf_Dat_t * pCnf;
340 Gia_Obj_t * pObj;
341 int Id, DriId, nVars, nClas, nLits, iVar = 1, iCla = 0, iLit = 0;
342 Vec_Int_t * vCnfs = Mf_ManDeriveCnfs( p, &nVars, &nClas, &nLits );
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;
346 nVars++; // zero-ID to remain unused
347 if ( fAddOrCla )
348 {
349 nClas++;
350 nLits += Gia_ManCoNum(p->pGia);
351 }
352 // create CNF IDs
353 if ( fCnfObjIds )
354 {
355 iVar += 1 + Gia_ManCiNum(p->pGia) + Gia_ManCoNum(p->pGia);
356 Gia_ManForEachCoId( p->pGia, Id, i )
357 Vec_IntWriteEntry( vCnfIds, Id, Id );
358 Gia_ManForEachAndReverseId( p->pGia, Id )
359 if ( Mf_ObjMapRefNum(p, Id) )
360 Vec_IntWriteEntry( vCnfIds, Id, Id ), iVar++;
361 Vec_IntWriteEntry( vCnfIds, 0, 0 );
362 Gia_ManForEachCiId( p->pGia, Id, i )
363 Vec_IntWriteEntry( vCnfIds, Id, Id );
364 assert( iVar == nVars );
365 }
366 else
367 {
368 Gia_ManForEachCoId( p->pGia, Id, i )
369 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
370 Gia_ManForEachAndReverseId( p->pGia, Id )
371 if ( Mf_ObjMapRefNum(p, Id) )
372 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
373 Vec_IntWriteEntry( vCnfIds, 0, iVar++ );
374 Gia_ManForEachCiId( p->pGia, Id, i )
375 Vec_IntWriteEntry( vCnfIds, Id, iVar++ );
376 assert( iVar == nVars );
377 }
378 // generate CNF
379 pCnf = ABC_CALLOC( Cnf_Dat_t, 1 );
380 pCnf->pMan = (Aig_Man_t *)p->pGia;
381 pCnf->nVars = nVars;
382 pCnf->nLiterals = nLits;
383 pCnf->nClauses = nClas;
384 pCnf->pClauses = ABC_ALLOC( int *, nClas+1 );
385 pCnf->pClauses[0] = ABC_ALLOC( int, nLits );
386 // add last clause
387 if ( fAddOrCla )
388 {
389 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
390 Gia_ManForEachCoId( p->pGia, Id, i )
391 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 0);
392 }
393 if ( p->pPars->fCnfMapping )
394 pCnf->vMapping = Vec_IntStart( nVars );
395 // add clauses for the COs
396 Gia_ManForEachCo( p->pGia, pObj, i )
397 {
398 Id = Gia_ObjId( p->pGia, pObj );
399 DriId = Gia_ObjFaninId0( pObj, Id );
400
401 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
402 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 0);
403 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[DriId], !Gia_ObjFaninC0(pObj));
404
405 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
406 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], 1);
407 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[DriId], Gia_ObjFaninC0(pObj));
408 // generate mapping
409 if ( pCnf->vMapping )
410 {
411 Vec_IntWriteEntry( pCnf->vMapping, pCnfIds[Id], Vec_IntSize(pCnf->vMapping) );
412 Vec_IntPush( pCnf->vMapping, 1 );
413 Vec_IntPush( pCnf->vMapping, pCnfIds[DriId] );
414 Vec_IntPush( pCnf->vMapping, Gia_ObjFaninC0(pObj) ? 0x55555555 : 0xAAAAAAAA );
415 }
416 }
417 // add clauses for the mapping
418 Gia_ManForEachAndReverseId( p->pGia, Id )
419 {
420 if ( !Mf_ObjMapRefNum(p, Id) )
421 continue;
422 pCut = Mf_ObjCutBest( p, Id );
423 iFunc = Abc_Lit2Var( Mf_CutFunc(pCut) );
424 fComplLast = Abc_LitIsCompl( Mf_CutFunc(pCut) );
425 if ( iFunc == 0 ) // constant cut
426 {
427 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
428 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[Id], !fComplLast);
429 assert( pCnf->vMapping == NULL ); // bug fix does not handle generated mapping
430 continue;
431 }
432 for ( k = 0; k < Mf_CutSize(pCut); k++ )
433 pFanins[k] = pCnfIds[pCut[k+1]];
434 pFanins[k++] = pCnfIds[Id];
435 // get clauses
436 pCubes = Vec_IntEntryP( vCnfs, Vec_IntEntry(vCnfs, iFunc) );
437 nCubes = *pCubes++;
438 for ( c = 0; c < nCubes; c++ )
439 {
440 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
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 );
447 }
448 // generate mapping
449 if ( pCnf->vMapping )
450 {
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 )
461 {
462 Vec_IntPush( pCnf->vMapping, (unsigned)(pTruth[0] >> 32) );
463 if ( Mf_CutSize(pCut) >= 7 )
464 {
465 Vec_IntPush( pCnf->vMapping, (unsigned)(pTruth[1]) );
466 Vec_IntPush( pCnf->vMapping, (unsigned)(pTruth[1] >> 32) );
467 }
468 if ( Mf_CutSize(pCut) >= 8 )
469 {
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) );
474 }
475 }
476 }
477 }
478 // constant clause
479 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
480 pCnf->pClauses[0][iLit++] = Abc_Var2Lit(pCnfIds[0], 1);
481 assert( iCla == nClas );
482 assert( iLit == nLits );
483 // add closing pointer
484 pCnf->pClauses[iCla++] = pCnf->pClauses[0] + iLit;
485 // cleanup
486 Vec_IntFree( vCnfs );
487 // create mapping of objects into their clauses
488 if ( fCnfObjIds )
489 {
490 pCnf->pObj2Clause = ABC_FALLOC( int, Gia_ManObjNum(p->pGia) );
491 pCnf->pObj2Count = ABC_FALLOC( int, Gia_ManObjNum(p->pGia) );
492 for ( i = 0; i < pCnf->nClauses; i++ )
493 {
494 Id = Abc_Lit2Var(pCnf->pClauses[i][0]);
495 if ( pCnf->pObj2Clause[Id] == -1 )
496 {
497 pCnf->pObj2Clause[Id] = i;
498 pCnf->pObj2Count[Id] = 1;
499 }
500 else
501 {
502 assert( pCnf->pObj2Count[Id] > 0 );
503 pCnf->pObj2Count[Id]++;
504 }
505 }
506 }
507 else
508 {
509 if ( p->pGia != p->pGia0 ) // diff managers - create map for CIs/COs
510 {
511 pCnf->pVarNums = ABC_FALLOC( int, Gia_ManObjNum(p->pGia0) );
512 Gia_ManForEachCiId( p->pGia0, Id, i )
513 pCnf->pVarNums[Id] = pCnfIds[Gia_ManCiIdToId(p->pGia, i)];
514 Gia_ManForEachCoId( p->pGia0, Id, i )
515 pCnf->pVarNums[Id] = pCnfIds[Gia_ManCoIdToId(p->pGia, i)];
516/*
517 // transform polarity of the internal nodes
518 Gia_ManSetPhase( p->pGia );
519 Gia_ManForEachCo( p->pGia, pObj, i )
520 pObj->fPhase = 0;
521 for ( i = 0; i < pCnf->nLiterals; i++ )
522 if ( Gia_ManObj(p->pGia, Abc_Lit2Var(pCnf->pClauses[0][i]))->fPhase )
523 pCnf->pClauses[0][i] = Abc_LitNot( pCnf->pClauses[0][i] );
524*/
525 }
526 else
527 pCnf->pVarNums = Vec_IntReleaseArray(vCnfIds);
528 }
529 Vec_IntFree( vCnfIds );
530 return pCnf;
531}
532
544static inline int Mf_CutComputeTruth6( Mf_Man_t * p, Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, int fCompl0, int fCompl1, Mf_Cut_t * pCutR, int fIsXor )
545{
546// extern int Mf_ManTruthCanonicize( word * t, int nVars );
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;
552 t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
553 t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
554 t = fIsXor ? t0 ^ t1 : t0 & t1;
555 if ( (fCompl = (int)(t & 1)) ) t = ~t;
556 if ( !p->pPars->fCnfObjIds )
557 pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
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) )
562 Vec_IntPush( &p->vCnfSizes, p->pPars->fGenCnf ? Abc_Tt6CnfSize(t, pCutR->nLeaves) : Kit_TruthLitNum((unsigned *)&t, pCutR->nLeaves, &p->vCnfMem) );
563// p->nCutMux += Mf_ManTtIsMux( t );
564 assert( (int)pCutR->nLeaves <= nOldSupp );
565// Mf_ManTruthCanonicize( &t, pCutR->nLeaves );
566 return (int)pCutR->nLeaves < nOldSupp;
567}
568static inline int Mf_CutComputeTruth( Mf_Man_t * p, Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, int fCompl0, int fCompl1, Mf_Cut_t * pCutR, int fIsXor )
569{
570 if ( p->pPars->nLutSize <= 6 )
571 return Mf_CutComputeTruth6( p, pCut0, pCut1, fCompl0, fCompl1, pCutR, fIsXor );
572 {
573 word uTruth[MF_TT_WORDS], uTruth0[MF_TT_WORDS], uTruth1[MF_TT_WORDS];
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 );
581 Abc_TtExpand( uTruth0, LutSize, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
582 Abc_TtExpand( uTruth1, LutSize, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
583 if ( fIsXor )
584 Abc_TtXor( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] ^ uTruth1[0]) & 1)) );
585 else
586 Abc_TtAnd( uTruth, uTruth0, uTruth1, nWords, (fCompl = (int)((uTruth0[0] & uTruth1[0]) & 1)) );
587 pCutR->nLeaves = Abc_TtMinBase( uTruth, pCutR->pLeaves, pCutR->nLeaves, LutSize );
588 assert( (uTruth[0] & 1) == 0 );
589//Kit_DsdPrintFromTruth( uTruth, pCutR->nLeaves ), printf("\n" ), printf("\n" );
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) );
594 assert( (int)pCutR->nLeaves <= nOldSupp );
595 return (int)pCutR->nLeaves < nOldSupp;
596 }
597}
598static inline int Mf_CutComputeTruthMux6( Mf_Man_t * p, Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, Mf_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Mf_Cut_t * pCutR )
599{
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;
607 t0 = Abc_Tt6Expand( t0, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
608 t1 = Abc_Tt6Expand( t1, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
609 tC = Abc_Tt6Expand( tC, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
610 t = (tC & t1) | (~tC & t0);
611 if ( (fCompl = (int)(t & 1)) ) t = ~t;
612 pCutR->nLeaves = Abc_Tt6MinBase( &t, pCutR->pLeaves, pCutR->nLeaves );
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) )
617 Vec_IntPush( &p->vCnfSizes, p->pPars->fGenCnf ? Abc_Tt6CnfSize(t, pCutR->nLeaves) : Kit_TruthLitNum((unsigned *)&t, pCutR->nLeaves, &p->vCnfMem) );
618 assert( (int)pCutR->nLeaves <= nOldSupp );
619 return (int)pCutR->nLeaves < nOldSupp;
620}
621static inline int Mf_CutComputeTruthMux( Mf_Man_t * p, Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, Mf_Cut_t * pCutC, int fCompl0, int fCompl1, int fComplC, Mf_Cut_t * pCutR )
622{
623 if ( p->pPars->nLutSize <= 6 )
624 return Mf_CutComputeTruthMux6( p, pCut0, pCut1, pCutC, fCompl0, fCompl1, fComplC, pCutR );
625 {
626 word uTruth[MF_TT_WORDS], uTruth0[MF_TT_WORDS], uTruth1[MF_TT_WORDS], uTruthC[MF_TT_WORDS];
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 );
636 Abc_TtExpand( uTruth0, LutSize, pCut0->pLeaves, pCut0->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
637 Abc_TtExpand( uTruth1, LutSize, pCut1->pLeaves, pCut1->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
638 Abc_TtExpand( uTruthC, LutSize, pCutC->pLeaves, pCutC->nLeaves, pCutR->pLeaves, pCutR->nLeaves );
639 Abc_TtMux( uTruth, uTruthC, uTruth1, uTruth0, nWords );
640 fCompl = (int)(uTruth[0] & 1);
641 if ( fCompl ) Abc_TtNot( uTruth, nWords );
642 pCutR->nLeaves = Abc_TtMinBase( uTruth, pCutR->pLeaves, pCutR->nLeaves, LutSize );
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) );
648 assert( (int)pCutR->nLeaves <= nOldSupp );
649 return (int)pCutR->nLeaves < nOldSupp;
650 }
651}
652
653
665static inline int Mf_CutCountBits( word i )
666{
667 i = i - ((i >> 1) & 0x5555555555555555);
668 i = (i & 0x3333333333333333) + ((i >> 2) & 0x3333333333333333);
669 i = ((i + (i >> 4)) & 0x0F0F0F0F0F0F0F0F);
670 return (i*(0x0101010101010101))>>56;
671}
672static inline word Mf_CutGetSign( int * pLeaves, int nLeaves )
673{
674 word Sign = 0; int i;
675 for ( i = 0; i < nLeaves; i++ )
676 Sign |= ((word)1) << (pLeaves[i] & 0x3F);
677 return Sign;
678}
679static inline int Mf_CutCreateUnit( Mf_Cut_t * p, int i )
680{
681 p->Delay = 0;
682 p->Flow = 0;
683 p->iFunc = 2;
684 p->nLeaves = 1;
685 p->pLeaves[0] = i;
686 p->Sign = ((word)1) << (i & 0x3F);
687 return 1;
688}
689static inline void Mf_CutPrint( Mf_Man_t * p, Mf_Cut_t * pCut )
690{
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 ",
698 pCut->Delay, pCut->Flow, pCut->iFunc );
699 if ( p->vTtMem )
700 {
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)) );
705 Dau_DsdPrintFromTruth( Vec_MemReadEntry(p->vTtMem, Abc_Lit2Var(pCut->iFunc)), pCut->nLeaves );
706 }
707 else
708 printf( "\n" );
709}
710static inline int Mf_ManPrepareCuts( Mf_Cut_t * pCuts, Mf_Man_t * p, int iObj, int fAddUnit )
711{
712 if ( Mf_ManObj(p, iObj)->iCutSet )
713 {
714 Mf_Cut_t * pMfCut = pCuts;
715 int i, * pCut, * pList = Mf_ObjCutSet(p, iObj);
716 Mf_SetForEachCut( pList, pCut, i )
717 {
718 pMfCut->Delay = 0;
719 pMfCut->Flow = 0;
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) );
724 pMfCut++;
725 }
726 if ( fAddUnit && pCuts->nLeaves > 1 )
727 return pList[0] + Mf_CutCreateUnit( pMfCut, iObj );
728 return pList[0];
729 }
730 return Mf_CutCreateUnit( pCuts, iObj );
731}
732static inline int Mf_ManSaveCuts( Mf_Man_t * p, Mf_Cut_t ** pCuts, int nCuts )
733{
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 );
743 *pPlace++ = nCuts;
744 for ( i = 0; i < nCuts; i++ )
745 {
746 *pPlace++ = Mf_CutSetBoth(pCuts[i]->nLeaves, pCuts[i]->iFunc);
747 memcpy( pPlace, pCuts[i]->pLeaves, sizeof(int) * pCuts[i]->nLeaves );
748 pPlace += pCuts[i]->nLeaves;
749 }
750 return iCur;
751}
752static inline void Mf_ObjSetBestCut( int * pCuts, int * pCut )
753{
754 assert( pCuts < pCut );
755 if ( ++pCuts < pCut )
756 {
757 int pTemp[MF_CUT_MAX*(MF_LEAF_MAX+2)];
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 );
763 }
764}
765
777static inline int Mf_CutCheck( Mf_Cut_t * pBase, Mf_Cut_t * pCut ) // check if pCut is contained in pBase
778{
779 int nSizeB = pBase->nLeaves;
780 int nSizeC = pCut->nLeaves;
781 int i, * pB = pBase->pLeaves;
782 int k, * pC = pCut->pLeaves;
783 for ( i = 0; i < nSizeC; i++ )
784 {
785 for ( k = 0; k < nSizeB; k++ )
786 if ( pC[i] == pB[k] )
787 break;
788 if ( k == nSizeB )
789 return 0;
790 }
791 return 1;
792}
793static inline int Mf_SetCheckArray( Mf_Cut_t ** ppCuts, int nCuts )
794{
795 Mf_Cut_t * pCut0, * pCut1;
796 int i, k, m, n, Value;
797 assert( nCuts > 0 );
798 for ( i = 0; i < nCuts; i++ )
799 {
800 pCut0 = ppCuts[i];
801 assert( pCut0->nLeaves <= MF_LEAF_MAX );
802 assert( pCut0->Sign == Mf_CutGetSign(pCut0->pLeaves, pCut0->nLeaves) );
803 // check duplicates
804 for ( m = 0; m < (int)pCut0->nLeaves; m++ )
805 for ( n = m + 1; n < (int)pCut0->nLeaves; n++ )
806 assert( pCut0->pLeaves[m] < pCut0->pLeaves[n] );
807 // check pairs
808 for ( k = 0; k < nCuts; k++ )
809 {
810 pCut1 = ppCuts[k];
811 if ( pCut0 == pCut1 )
812 continue;
813 // check containments
814 Value = Mf_CutCheck( pCut0, pCut1 );
815 assert( Value == 0 );
816 }
817 }
818 return 1;
819}
820
821
833static inline int Mf_CutMergeOrder( Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, Mf_Cut_t * pCut, int nLutSize )
834{
835 int nSize0 = pCut0->nLeaves;
836 int nSize1 = pCut1->nLeaves;
837 int i, * pC0 = pCut0->pLeaves;
838 int k, * pC1 = pCut1->pLeaves;
839 int c, * pC = pCut->pLeaves;
840 // the case of the largest cut sizes
841 if ( nSize0 == nLutSize && nSize1 == nLutSize )
842 {
843 for ( i = 0; i < nSize0; i++ )
844 {
845 if ( pC0[i] != pC1[i] ) return 0;
846 pC[i] = pC0[i];
847 }
848 pCut->nLeaves = nLutSize;
849 pCut->iFunc = MF_NO_FUNC;
850 pCut->Sign = pCut0->Sign | pCut1->Sign;
851 return 1;
852 }
853 // compare two cuts with different numbers
854 i = k = c = 0;
855 if ( nSize0 == 0 ) goto FlushCut1;
856 if ( nSize1 == 0 ) goto FlushCut0;
857 while ( 1 )
858 {
859 if ( c == nLutSize ) return 0;
860 if ( pC0[i] < pC1[k] )
861 {
862 pC[c++] = pC0[i++];
863 if ( i >= nSize0 ) goto FlushCut1;
864 }
865 else if ( pC0[i] > pC1[k] )
866 {
867 pC[c++] = pC1[k++];
868 if ( k >= nSize1 ) goto FlushCut0;
869 }
870 else
871 {
872 pC[c++] = pC0[i++]; k++;
873 if ( i >= nSize0 ) goto FlushCut1;
874 if ( k >= nSize1 ) goto FlushCut0;
875 }
876 }
877
878FlushCut0:
879 if ( c + nSize0 > nLutSize + i ) return 0;
880 while ( i < nSize0 )
881 pC[c++] = pC0[i++];
882 pCut->nLeaves = c;
883 pCut->iFunc = MF_NO_FUNC;
884 pCut->Sign = pCut0->Sign | pCut1->Sign;
885 return 1;
886
887FlushCut1:
888 if ( c + nSize1 > nLutSize + k ) return 0;
889 while ( k < nSize1 )
890 pC[c++] = pC1[k++];
891 pCut->nLeaves = c;
892 pCut->iFunc = MF_NO_FUNC;
893 pCut->Sign = pCut0->Sign | pCut1->Sign;
894 return 1;
895}
896static inline int Mf_CutMergeOrderMux( Mf_Cut_t * pCut0, Mf_Cut_t * pCut1, Mf_Cut_t * pCut2, Mf_Cut_t * pCut, int nLutSize )
897{
898 int x0, i0 = 0, nSize0 = pCut0->nLeaves, * pC0 = pCut0->pLeaves;
899 int x1, i1 = 0, nSize1 = pCut1->nLeaves, * pC1 = pCut1->pLeaves;
900 int x2, i2 = 0, nSize2 = pCut2->nLeaves, * pC2 = pCut2->pLeaves;
901 int xMin, c = 0, * pC = pCut->pLeaves;
902 while ( 1 )
903 {
904 x0 = (i0 == nSize0) ? ABC_INFINITY : pC0[i0];
905 x1 = (i1 == nSize1) ? ABC_INFINITY : pC1[i1];
906 x2 = (i2 == nSize2) ? ABC_INFINITY : pC2[i2];
907 xMin = Abc_MinInt( Abc_MinInt(x0, x1), x2 );
908 if ( xMin == ABC_INFINITY ) break;
909 if ( c == nLutSize ) return 0;
910 pC[c++] = xMin;
911 if (x0 == xMin) i0++;
912 if (x1 == xMin) i1++;
913 if (x2 == xMin) i2++;
914 }
915 pCut->nLeaves = c;
916 pCut->iFunc = MF_NO_FUNC;
917 pCut->Sign = pCut0->Sign | pCut1->Sign | pCut2->Sign;
918 return 1;
919}
920static inline int Mf_SetCutIsContainedOrder( Mf_Cut_t * pBase, Mf_Cut_t * pCut ) // check if pCut is contained in pBase
921{
922 int i, nSizeB = pBase->nLeaves;
923 int k, nSizeC = pCut->nLeaves;
924 if ( nSizeB == nSizeC )
925 {
926 for ( i = 0; i < nSizeB; i++ )
927 if ( pBase->pLeaves[i] != pCut->pLeaves[i] )
928 return 0;
929 return 1;
930 }
931 assert( nSizeB > nSizeC );
932 if ( nSizeC == 0 )
933 return 1;
934 for ( i = k = 0; i < nSizeB; i++ )
935 {
936 if ( pBase->pLeaves[i] > pCut->pLeaves[k] )
937 return 0;
938 if ( pBase->pLeaves[i] == pCut->pLeaves[k] )
939 {
940 if ( ++k == nSizeC )
941 return 1;
942 }
943 }
944 return 0;
945}
946static inline int Mf_SetLastCutIsContained( Mf_Cut_t ** pCuts, int nCuts )
947{
948 int i;
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]) )
951 return 1;
952 return 0;
953}
954static inline int Mf_SetLastCutContainsArea( Mf_Cut_t ** pCuts, int nCuts )
955{
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]) )
959 pCuts[i]->nLeaves = MF_NO_LEAF, fChanges = 1;
960 if ( !fChanges )
961 return nCuts;
962 for ( i = k = 0; i <= nCuts; i++ )
963 {
964 if ( pCuts[i]->nLeaves == MF_NO_LEAF )
965 continue;
966 if ( k < i )
967 ABC_SWAP( Mf_Cut_t *, pCuts[k], pCuts[i] );
968 k++;
969 }
970 return k - 1;
971}
972static inline int Mf_CutCompareArea( Mf_Cut_t * pCut0, Mf_Cut_t * pCut1 )
973{
974 if ( pCut0->Flow < pCut1->Flow - MF_EPSILON ) return -1;
975 if ( pCut0->Flow > pCut1->Flow + MF_EPSILON ) return 1;
976 if ( pCut0->Delay < pCut1->Delay ) return -1;
977 if ( pCut0->Delay > pCut1->Delay ) return 1;
978 if ( pCut0->nLeaves < pCut1->nLeaves ) return -1;
979 if ( pCut0->nLeaves > pCut1->nLeaves ) return 1;
980 return 0;
981}
982static inline void Mf_SetSortByArea( Mf_Cut_t ** pCuts, int nCuts )
983{
984 int i;
985 for ( i = nCuts; i > 0; i-- )
986 {
987 if ( Mf_CutCompareArea(pCuts[i - 1], pCuts[i]) < 0 )
988 return;
989 ABC_SWAP( Mf_Cut_t *, pCuts[i - 1], pCuts[i] );
990 }
991}
992static inline int Mf_SetAddCut( Mf_Cut_t ** pCuts, int nCuts, int nCutNum )
993{
994 if ( nCuts == 0 )
995 return 1;
996 nCuts = Mf_SetLastCutContainsArea(pCuts, nCuts);
997 Mf_SetSortByArea( pCuts, nCuts );
998 return Abc_MinInt( nCuts + 1, nCutNum - 1 );
999}
1000static inline int Mf_CutArea( Mf_Man_t * p, int nLeaves, int iFunc )
1001{
1002 if ( nLeaves < 2 )
1003 return 0;
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;
1008 return 1;
1009}
1010static inline void Mf_CutParams( Mf_Man_t * p, Mf_Cut_t * pCut, float FlowRefs )
1011{
1012 Mf_Obj_t * pBest;
1013 int i, nLeaves = pCut->nLeaves;
1014 assert( nLeaves <= p->pPars->nLutSize );
1015 pCut->Delay = 0;
1016 pCut->Flow = 0;
1017 for ( i = 0; i < nLeaves; i++ )
1018 {
1019 pBest = Mf_ManObj(p, pCut->pLeaves[i]);
1020 pCut->Delay = Abc_MaxInt( pCut->Delay, pBest->Delay );
1021 pCut->Flow += pBest->Flow;
1022 }
1023 pCut->Delay += (int)(nLeaves > 1);
1024 pCut->Flow = (pCut->Flow + Mf_CutArea(p, nLeaves, pCut->iFunc)) / FlowRefs;
1025}
1026void Mf_ObjMergeOrder( Mf_Man_t * p, int iObj )
1027{
1028 Mf_Cut_t pCuts0[MF_CUT_MAX], pCuts1[MF_CUT_MAX], pCuts[MF_CUT_MAX], * pCutsR[MF_CUT_MAX];
1029 Gia_Obj_t * pObj = Gia_ManObj(p->pGia, iObj);
1030 Mf_Obj_t * pBest = Mf_ManObj(p, 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;
1039 int i, nCutsR = 0;
1040 for ( i = 0; i < nCutNum; i++ )
1041 pCutsR[i] = pCuts + i;
1042 if ( iSibl )
1043 {
1044 Mf_Cut_t pCuts2[MF_CUT_MAX];
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++ )
1050 {
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 );
1056 }
1057 }
1058 if ( Gia_ObjIsMuxId(p->pGia, iObj) )
1059 {
1060 Mf_Cut_t pCuts2[MF_CUT_MAX];
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++ )
1068 {
1069 if ( Mf_CutCountBits(pCut0->Sign | pCut1->Sign | pCut2->Sign) > nLutSize )
1070 continue;
1071 p->CutCount[1]++;
1072 if ( !Mf_CutMergeOrderMux(pCut0, pCut1, pCut2, pCutsR[nCutsR], nLutSize) )
1073 continue;
1074 if ( Mf_SetLastCutIsContained(pCutsR, nCutsR) )
1075 continue;
1076 p->CutCount[2]++;
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 );
1081 }
1082 }
1083 else
1084 {
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++ )
1089 {
1090 if ( (int)(pCut0->nLeaves + pCut1->nLeaves) > nLutSize && Mf_CutCountBits(pCut0->Sign | pCut1->Sign) > nLutSize )
1091 continue;
1092 p->CutCount[1]++;
1093 if ( !Mf_CutMergeOrder(pCut0, pCut1, pCutsR[nCutsR], nLutSize) )
1094 continue;
1095 if ( Mf_SetLastCutIsContained(pCutsR, nCutsR) )
1096 continue;
1097 p->CutCount[2]++;
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 );
1102 }
1103 }
1104 // debug printout
1105 if ( 0 )
1106// if ( iObj % 1000 == 0 )
1107// if ( iObj == 474 )
1108 {
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] );
1112 printf( "\n" );
1113 }
1114 // store the cutset
1115 pBest->Flow = pCutsR[0]->Flow;
1116 pBest->Delay = pCutsR[0]->Delay;
1117 pBest->iCutSet = Mf_ManSaveCuts( p, pCutsR, nCutsR );
1118 // verify
1119 assert( nCutsR > 0 && nCutsR < nCutNum );
1120// assert( Mf_SetCheckArray(pCutsR, nCutsR) );
1121 p->nCutCounts[pCutsR[0]->nLeaves]++;
1122 p->CutCount[3] += nCutsR;
1123}
1124
1125
1138{
1139 int fDiscount = 1;
1140 Gia_Obj_t * pObj, * pCtrl, * pData0, * pData1;
1141 int i, Id;
1142 Vec_IntFill( vRefs, Gia_ManObjNum(p), 0 );
1143 Gia_ManForEachAnd( p, pObj, i )
1144 {
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 );
1149 if ( p->pMuxes )
1150 {
1151 if ( Gia_ObjIsMuxId(p, i) && Gia_ObjIsAnd(Gia_ObjFanin2(p, pObj)) )
1152 Vec_IntAddToEntry( vRefs, Gia_ObjFaninId2(p, i), 1 );
1153 }
1154 else if ( fDiscount && Gia_ObjIsMuxType(pObj) ) // discount XOR/MUX
1155 {
1156 pCtrl = Gia_Regular(Gia_ObjRecognizeMux(pObj, &pData1, &pData0));
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 );
1163 }
1164 }
1165 Gia_ManForEachCoDriverId( p, Id, i )
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 );
1170}
1172{
1173 float Coef = 1.0 / (1.0 + (p->Iter + 1) * (p->Iter + 1));
1174 int * pCut, i, k, Id;
1175 // compute delay
1176 int Delay = 0;
1177 Gia_ManForEachCoDriverId( p->pGia, Id, i )
1178 Delay = Abc_MaxInt( Delay, Mf_ManObj(p, Id)->Delay );
1179 // check delay target
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 )
1183 {
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 );
1188 }
1189 p->pPars->Delay = Delay;
1190 // check references
1191// Gia_ManForEachAndId( p->pGia, i )
1192// assert( Mf_ManObj(p, i)->nMapRefs == 0 );
1193 // compute area and edges
1194 if ( !p->fUseEla )
1195 Gia_ManForEachCoDriverId( p->pGia, Id, i )
1196 Mf_ObjMapRefInc( p, Id );
1197 p->pPars->Area = p->pPars->Edge = p->pPars->Clause = 0;
1198 Gia_ManForEachAndReverseId( p->pGia, i )
1199 {
1200 if ( !Mf_ObjMapRefNum(p, i) )
1201 continue;
1202 pCut = Mf_ObjCutBest( p, i );
1203 if ( !p->fUseEla )
1204 for ( k = 1; k <= Mf_CutSize(pCut); k++ )
1205 Mf_ObjMapRefInc( p, pCut[k] );
1206 p->pPars->Edge += Mf_CutSize(pCut);
1207 p->pPars->Area++;
1208 if ( p->pPars->fGenCnf || p->pPars->fGenLit )
1209 p->pPars->Clause += Mf_CutArea(p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1210 }
1211 // blend references
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);
1214// p->pLfObjs[i]. = 0.2 * p->pLfObjs[i]. + 0.8 * Abc_MaxFloat(1, p->pLfObjs[i].nMapRefs);
1215 return p->pPars->Area;
1216}
1217
1230{
1231 Vec_Int_t * vMapping;
1232 int i, k, * pCut;
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 );
1236 Gia_ManForEachAndId( p->pGia, i )
1237 {
1238 if ( !Mf_ObjMapRefNum(p, i) )
1239 continue;
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 );
1246 }
1247 assert( Vec_IntCap(vMapping) == 16 || Vec_IntSize(vMapping) == Vec_IntCap(vMapping) );
1248 p->pGia->vMapping = vMapping;
1249 return p->pGia;
1250}
1252{
1253 Gia_Man_t * pNew, * pGia = p->pGia;
1254 Gia_Obj_t * pObj;
1255 int i, k, * pCut;
1256 assert( !p->pPars->fCutMin && pGia->pMuxes );
1257 // create new manager
1258 pNew = Gia_ManStart( Gia_ManObjNum(pGia) );
1259 pNew->pName = Abc_UtilStrsav( pGia->pName );
1260 pNew->pSpec = Abc_UtilStrsav( pGia->pSpec );
1261 // map primary inputs
1262 Gia_ManConst0(pGia)->Value = 0;
1263 Gia_ManForEachCi( pGia, pObj, i )
1264 pObj->Value = Gia_ManAppendCi( pNew );
1265 // start mapping
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 );
1268 // iterate through nodes used in the mapping
1269 Gia_ManForEachAnd( pGia, pObj, i )
1270 {
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) );
1275 else
1276 pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
1277 if ( !Mf_ObjMapRefNum(p, i) )
1278 continue;
1279 pCut = Mf_ObjCutBest( p, i );
1280 Vec_IntWriteEntry( pNew->vMapping, Abc_Lit2Var(pObj->Value), Vec_IntSize(pNew->vMapping) );
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) );
1284 Vec_IntPush( pNew->vMapping, Abc_Lit2Var(pObj->Value) );
1285 }
1286 Gia_ManForEachCo( pGia, pObj, i )
1287 pObj->Value = Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(pObj) );
1288 Gia_ManSetRegNum( pNew, Gia_ManRegNum(pGia) );
1289 assert( Vec_IntCap(pNew->vMapping) == 16 || Vec_IntSize(pNew->vMapping) == Vec_IntCap(pNew->vMapping) );
1290 return pNew;
1291}
1293{
1294 Gia_Man_t * pNew;
1295 Gia_Obj_t * 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;
1303 assert( p->pPars->fCutMin );
1304 // create new manager
1305 pNew = Gia_ManStart( Gia_ManObjNum(p->pGia) );
1306 pNew->pName = Abc_UtilStrsav( p->pGia->pName );
1307 pNew->pSpec = Abc_UtilStrsav( p->pGia->pSpec );
1308 // map primary inputs
1309 Vec_IntWriteEntry( vCopies, 0, 0 );
1310 Gia_ManForEachCiId( p->pGia, Id, i )
1311 Vec_IntWriteEntry( vCopies, Id, Gia_ManAppendCi(pNew) );
1312 // iterate through nodes used in the mapping
1313 Gia_ManForEachAnd( p->pGia, pObj, i )
1314 {
1315 if ( !Mf_ObjMapRefNum(p, i) )
1316 continue;
1317 pCut = Mf_ObjCutBest( p, i );
1318 if ( Mf_CutSize(pCut) == 0 )
1319 {
1320 assert( Abc_Lit2Var(Mf_CutFunc(pCut)) == 0 );
1321 Vec_IntWriteEntry( vCopies, i, Mf_CutFunc(pCut) );
1322 continue;
1323 }
1324 if ( Mf_CutSize(pCut) == 1 )
1325 {
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))) );
1329 continue;
1330 }
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))) );
1337 // create mapping
1338 Vec_IntSetEntry( vMapping, Abc_Lit2Var(iLit), Vec_IntSize(vMapping2) );
1339 Vec_IntPush( vMapping2, Vec_IntSize(vLeaves) );
1340 Vec_IntForEachEntry( vLeaves, iLit, k )
1341 Vec_IntPush( vMapping2, Abc_Lit2Var(iLit) );
1342 Vec_IntPush( vMapping2, Abc_Lit2Var(Vec_IntEntry(vCopies, i)) );
1343 }
1344 Gia_ManForEachCo( p->pGia, pObj, i )
1345 {
1346 iLit = Vec_IntEntry( vCopies, Gia_ObjFaninId0p(p->pGia, pObj) );
1347 iLit = Gia_ManAppendCo( pNew, Abc_LitNotCond(iLit, Gia_ObjFaninC0(pObj)) );
1348 }
1349 Vec_IntFree( vCopies );
1350 Vec_IntFree( vCover );
1351 Vec_IntFree( vLeaves );
1352 // finish mapping
1353 if ( Vec_IntSize(vMapping) > Gia_ManObjNum(pNew) )
1354 Vec_IntShrink( vMapping, Gia_ManObjNum(pNew) );
1355 else
1356 Vec_IntFillExtra( vMapping, Gia_ManObjNum(pNew), 0 );
1357 assert( Vec_IntSize(vMapping) == Gia_ManObjNum(pNew) );
1358 Vec_IntForEachEntry( vMapping, iLit, i )
1359 if ( iLit > 0 )
1360 Vec_IntAddToEntry( vMapping, i, Gia_ManObjNum(pNew) );
1361 Vec_IntAppend( vMapping, vMapping2 );
1362 Vec_IntFree( vMapping2 );
1363 // attach mapping and packing
1364 assert( pNew->vMapping == NULL );
1365 pNew->vMapping = vMapping;
1366 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p->pGia) );
1367 return pNew;
1368}
1369
1382{
1383 Mf_Man_t * p;
1384 Vec_Int_t * vFlowRefs;
1385 int i, Entry;
1386 assert( pPars->nCutNum > 1 && pPars->nCutNum <= MF_CUT_MAX );
1387 assert( pPars->nLutSize > 1 && pPars->nLutSize <= MF_LEAF_MAX );
1388 ABC_FREE( pGia->pRefs );
1389 Vec_IntFreeP( &pGia->vMapping );
1390 if ( Gia_ManHasChoices(pGia) )
1391 Gia_ManSetPhase(pGia);
1392 p = ABC_CALLOC( Mf_Man_t, 1 );
1393 p->clkStart = Abc_Clock();
1394 p->pGia = pGia;
1395 p->pPars = pPars;
1396 p->vTtMem = pPars->fCutMin ? Vec_MemAllocForTT( pPars->nLutSize, 0 ) : NULL;
1397 p->pLfObjs = ABC_CALLOC( Mf_Obj_t, Gia_ManObjNum(pGia) );
1398 p->iCur = 2;
1399 Vec_PtrGrow( &p->vPages, 256 );
1400 if ( pPars->fGenCnf || pPars->fGenLit )
1401 {
1402 Vec_IntGrow( &p->vCnfSizes, 10000 );
1403 Vec_IntPush( &p->vCnfSizes, 1 );
1404 Vec_IntPush( &p->vCnfSizes, 2 );
1405 Vec_IntGrow( &p->vCnfMem, 10000 );
1406 }
1407 vFlowRefs = Vec_IntAlloc(0);
1408 Mf_ManSetFlowRefs( pGia, vFlowRefs );
1409 Vec_IntForEachEntry( vFlowRefs, Entry, i )
1410 p->pLfObjs[i].nFlowRefs = Entry;
1411 Vec_IntFree(vFlowRefs);
1412 return p;
1413}
1415{
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 );
1422 ABC_FREE( p->vCnfSizes.pArray );
1423 ABC_FREE( p->vCnfMem.pArray );
1424 ABC_FREE( p->vPages.pArray );
1425 ABC_FREE( p->vTemp.pArray );
1426 ABC_FREE( p->pLfObjs );
1427 ABC_FREE( p );
1428}
1429
1442{
1443 memset( pPars, 0, sizeof(Jf_Par_t) );
1444 pPars->nLutSize = 6;
1445 pPars->nCutNum = 8;
1446 pPars->nProcNum = 0;
1447 pPars->nRounds = 2;
1448 pPars->nRoundsEla = 1;
1449 pPars->nRelaxRatio = 0;
1450 pPars->nCoarseLimit = 3;
1451 pPars->nAreaTuner = 1;
1452 pPars->nVerbLimit = 5;
1453 pPars->DelayTarget = -1;
1454 pPars->fAreaOnly = 0;
1455 pPars->fOptEdge = 1;
1456 pPars->fCoarsen = 1;
1457 pPars->fCutMin = 0;
1458 pPars->fGenCnf = 0;
1459 pPars->fGenLit = 0;
1460 pPars->fPureAig = 0;
1461 pPars->fVerbose = 0;
1462 pPars->fVeryVerbose = 0;
1463 pPars->nLutSizeMax = MF_LEAF_MAX;
1464 pPars->nCutNumMax = MF_CUT_MAX;
1465}
1466void Mf_ManPrintStats( Mf_Man_t * p, char * pTitle )
1467{
1468 if ( !p->pPars->fVerbose )
1469 return;
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 );
1479 fflush( stdout );
1480}
1482{
1483 if ( !p->pPars->fVerbose )
1484 return;
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 );
1493 printf( "\n" );
1494 printf( "Computing cuts...\r" );
1495 fflush( stdout );
1496}
1498{
1499 float MemGia = Gia_ManMemory(p->pGia) / (1<<20);
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 )
1505 p->CutCount[0] = 1;
1506 if ( !p->pPars->fVerbose )
1507 return;
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] );
1512 printf( "\n" );
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 );
1519 printf( "\n" );
1520 if ( 1 )
1521 {
1522 int i;
1523 for ( i = 0; i <= p->pPars->nLutSize; i++ )
1524 printf( "%d = %d ", i, p->nCutCounts[i] );
1525 if ( p->vTtMem )
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 );
1528 }
1529 fflush( stdout );
1530}
1532{
1533 int i;
1534 Gia_ManForEachAndId( p->pGia, i )
1535 Mf_ObjMergeOrder( p, i );
1537 Mf_ManPrintStats( p, (char *)(p->fUseEla ? "Ela " : (p->Iter ? "Area " : "Delay")) );
1538}
1539
1551int Mf_CutRef_rec( Mf_Man_t * p, int * pCut )
1552{
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 )
1556 Count += Mf_CutRef_rec( p, Mf_ObjCutBest(p, pCut[i]) );
1557 return Count;
1558}
1559int Mf_CutDeref_rec( Mf_Man_t * p, int * pCut )
1560{
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 )
1564 Count += Mf_CutDeref_rec( p, Mf_ObjCutBest(p, pCut[i]) );
1565 return Count;
1566}
1567static inline int Mf_CutAreaRefed( Mf_Man_t * p, int * pCut )
1568{
1569 int Ela1 = Mf_CutDeref_rec( p, pCut );
1570 int Ela2 = Mf_CutRef_rec( p, pCut );
1571 assert( Ela1 == Ela2 );
1572 return Ela1;
1573}
1574static inline int Mf_CutAreaDerefed( Mf_Man_t * p, int * pCut )
1575{
1576 int Ela1 = Mf_CutRef_rec( p, pCut );
1577 int Ela2 = Mf_CutDeref_rec( p, pCut );
1578 assert( Ela1 == Ela2 );
1579 return Ela1;
1580}
1581static inline int Mf_CutAreaMffc( Mf_Man_t * p, int iObj )
1582{
1583 return Mf_ObjMapRefNum(p, iObj) ?
1584 Mf_CutAreaRefed (p, Mf_ObjCutBest(p, iObj)) :
1585 Mf_CutAreaDerefed(p, Mf_ObjCutBest(p, iObj));
1586}
1587
1588int Mf_CutRef2_rec( Mf_Man_t * p, int * pCut, Vec_Int_t * vTemp, int Limit )
1589{
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++ )
1593 {
1594 Vec_IntPush( vTemp, pCut[i] );
1595 if ( !Mf_ObjMapRefInc(p, pCut[i]) && Mf_ManObj(p, pCut[i])->iCutSet )
1596 Count += Mf_CutRef2_rec( p, Mf_ObjCutBest(p, pCut[i]), vTemp, Limit-1 );
1597 }
1598 return Count;
1599}
1600int Mf_CutDeref2_rec( Mf_Man_t * p, int * pCut, Vec_Int_t * vTemp, int Limit )
1601{
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++ )
1605 {
1606 Vec_IntPush( vTemp, pCut[i] );
1607 if ( !Mf_ObjMapRefDec(p, pCut[i]) && Mf_ManObj(p, pCut[i])->iCutSet )
1608 Count += Mf_CutDeref2_rec( p, Mf_ObjCutBest(p, pCut[i]), vTemp, Limit-1 );
1609 }
1610 return Count;
1611}
1612static inline int Mf_CutAreaRefed2( Mf_Man_t * p, int * pCut )
1613{
1614 int Ela1, iObj, i;
1615 Vec_IntClear( &p->vTemp );
1616 Ela1 = Mf_CutDeref2_rec( p, pCut, &p->vTemp, 8 );
1617 Vec_IntForEachEntry( &p->vTemp, iObj, i )
1618 Mf_ObjMapRefInc( p, iObj );
1619 return Ela1;
1620}
1621static inline int Mf_CutAreaDerefed2( Mf_Man_t * p, int * pCut )
1622{
1623 int Ela1, iObj, i;
1624 Vec_IntClear( &p->vTemp );
1625 Ela1 = Mf_CutRef2_rec( p, pCut, &p->vTemp, 8 );
1626 Vec_IntForEachEntry( &p->vTemp, iObj, i )
1627 Mf_ObjMapRefDec( p, iObj );
1628 return Ela1;
1629}
1630static inline int Mf_CutAreaRefed2Multi( Mf_Man_t * p, int iObj, int ** ppCuts, int nCuts )
1631{
1632 int Ela1 = 0, iTemp, i;
1633 Vec_IntClear( &p->vTemp );
1634 for ( i = 0; i < nCuts; i++ )
1635 Ela1 += Mf_CutDeref2_rec( p, ppCuts[i], &p->vTemp, ABC_INFINITY );
1636 assert( Mf_ObjMapRefNum(p, iObj) == 0 );
1637 Vec_IntForEachEntry( &p->vTemp, iTemp, i )
1638 Mf_ObjMapRefInc( p, iTemp );
1639 return Ela1;
1640}
1641
1642static inline float Mf_CutFlow( Mf_Man_t * p, int * pCut, int * pTime )
1643{
1644 Mf_Obj_t * pObj;
1645 float Flow = 0;
1646 int i, Time = 0;
1647 for ( i = 1; i <= Mf_CutSize(pCut); i++ )
1648 {
1649 pObj = Mf_ManObj( p, pCut[i] );
1650 Time = Abc_MaxInt( Time, pObj->Delay );
1651 Flow += pObj->Flow;
1652 }
1653 *pTime = Time + 1;
1654 return Flow + Mf_CutArea(p, Mf_CutSize(pCut), Mf_CutFunc(pCut));
1655}
1656static inline void Mf_ObjComputeBestCut( Mf_Man_t * p, int iObj )
1657{
1658 Mf_Obj_t * pBest = Mf_ManObj(p, iObj);
1659 int * pCutSet = Mf_ObjCutSet( p, iObj );
1660 int * pCut, * pCutBest = NULL;
1661 int Value1 = -1, Value2 = -1;
1662 int i, Time = 0, TimeBest = ABC_INFINITY;
1663 float Flow, FlowBest = ABC_INFINITY;
1664 if ( p->fUseEla && pBest->nMapRefs )
1665 Value1 = Mf_CutDeref_rec( p, Mf_ObjCutBest(p, iObj) );
1666 Mf_SetForEachCut( pCutSet, pCut, i )
1667 {
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;
1673 }
1674 assert( pCutBest != NULL );
1675 if ( p->fUseEla && pBest->nMapRefs )
1676 Value1 = Mf_CutRef_rec( p, pCutBest );
1677 else
1678 pBest->nMapRefs = 0;
1679 assert( Value1 >= Value2 );
1680 if ( p->fUseEla )
1681 Mf_CutFlow( p, pCutBest, &TimeBest );
1682 pBest->Delay = TimeBest;
1683 pBest->Flow = FlowBest / Mf_ManObj(p, iObj)->nFlowRefs;
1684 Mf_ObjSetBestCut( pCutSet, pCutBest );
1685// Mf_CutPrint( Mf_ObjCutBest(p, iObj) ); printf( "\n" );
1686}
1687
1688
1701{
1702 Gia_Man_t * pGia = p->pGia0;
1703 Gia_Obj_t * pObj;
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 );
1707 Gia_ManForEachAnd( pGia, pObj, iObj )
1708 if ( Mf_ObjMapRefNum(p, iObj) )
1709 {
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 );
1716 Count++;
1717 }
1718 assert( pGia->vMapping == NULL );
1719 pGia->vMapping = vMapping;
1720 printf( "Mapping is %.2fx larger than AIG manager.\n", 1.0*Vec_IntSize(vMapping)/Gia_ManObjNum(pGia) );
1721 return Count;
1722}
1723
1736{
1737 Gia_Man_t * pGia = p->pGia0;
1738 int i, Count, nMax = Vec_IntFindMax( vFanCounts );
1739 Vec_Int_t * vCounts = Vec_IntStart( nMax + 1 );
1740 Vec_IntForEachEntry( vFanCounts, Count, i )
1741 if ( Count && Gia_ObjIsAnd(Gia_ManObj(pGia, i)) )
1742 Vec_IntAddToEntry( vCounts, Count, 1 );
1743 printf( "\nFanout distribution for internal nodes:\n" );
1744 Vec_IntForEachEntry( vCounts, Count, i )
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 );
1748}
1750{
1751 Gia_Man_t * pGia = p->pGia0;
1752 int Area;
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)) );
1755 return Area;
1756}
1758{
1759 Gia_Man_t * pGia = p->pGia0;
1760 int * ppCuts[32], nCuts = 0;
1761 int iFanout, i, nAreaSum = 0, nAreaBest = 0;
1762 // skip pivots whose MFFC fanouts are pointed to by COs
1763 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1764 if ( Gia_ObjIsCo(Gia_ManObj(pGia, iFanout)) )
1765 return;
1766 // the pivot is used in the mapping as well as all of its fanouts
1767 assert( Mf_ObjMapRefNum(p, iObj) > 1 );
1768 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1769 assert( Mf_ObjMapRefNum(p, iFanout) > 0 );
1770 // print this pivot and its fanouts
1771 printf( "\nPivot node = %d\n", iObj );
1772 printf( "Pivot " ), Mf_ManPrintMfccStats( p, iObj );
1773 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1774 printf( "Node " ), nAreaSum += Mf_ManPrintMfccStats( p, iFanout );
1775 // calculate the shared MFFC
1776 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1777 Mf_ObjMapRefInc( p, iFanout );
1778 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1779 ppCuts[nCuts++] = Mf_ObjCutBest( p, iFanout );
1780 nAreaBest = Mf_CutAreaRefed2Multi( p, iObj, ppCuts, nCuts );
1781 Gia_ObjForEachFanoutStaticId( pGia, iObj, iFanout, i )
1782 Mf_ObjMapRefDec( p, iFanout );
1783 printf( "Sum of MFFC sizes = %d\n", nAreaSum );
1784 printf( "Shared MFFC size = %d\n", nAreaBest );
1785}
1787{
1788 int nOutMax = 3;
1789 Gia_Man_t * pGia = p->pGia0;
1790 int i, Count, nNodes = Mf_ManMappingFromMapping( p );
1791 Gia_ManLevelNum( pGia );
1792 Gia_ManStaticMappingFanoutStart( pGia, NULL );
1794 printf( "\nIndividual logic cones for mapping with %d nodes:\n", nNodes );
1795 Vec_IntForEachEntry( pGia->vFanoutNums, Count, i )
1796 if ( Count >= 2 && Count <= nOutMax && Gia_ObjIsAnd(Gia_ManObj(pGia, i)) )
1798 printf( "\nFinished printing individual logic cones.\n" );
1800 Vec_IntFreeP( &pGia->vMapping );
1801}
1802
1815{
1816 int i;
1817 Gia_ManForEachAndId( p->pGia, i )
1818 Mf_ObjComputeBestCut( p, i );
1820 Mf_ManPrintStats( p, (char *)(p->fUseEla ? "Ela " : (p->Iter ? "Area " : "Delay")) );
1821}
1823{
1824 Mf_Man_t * p;
1825 Gia_Man_t * pNew, * pCls;
1826 if ( pPars->fGenCnf || pPars->fGenLit )
1827 pPars->fCutMin = 1;
1828 if ( Gia_ManHasChoices(pGia) )
1829 pPars->fCutMin = 1, pPars->fCoarsen = 0;
1830 pCls = pPars->fCoarsen ? Gia_ManDupMuxes(pGia, pPars->nCoarseLimit) : pGia;
1831 p = Mf_ManAlloc( pCls, pPars );
1832 p->pGia0 = pGia;
1833 if ( pPars->fVerbose && pPars->fCoarsen )
1834 {
1835 printf( "Initial " ); Gia_ManPrintMuxStats( pGia ); printf( "\n" );
1836 printf( "Derived " ); Gia_ManPrintMuxStats( pCls ); printf( "\n" );
1837 }
1838 Mf_ManPrintInit( p );
1840 for ( p->Iter = 1; p->Iter < p->pPars->nRounds; p->Iter++ )
1842 p->fUseEla = 1;
1843 for ( ; p->Iter < p->pPars->nRounds + pPars->nRoundsEla; p->Iter++ )
1845 //Mf_ManOptimization( p );
1846 if ( pPars->fVeryVerbose && pPars->fCutMin )
1847 Vec_MemDumpTruthTables( p->vTtMem, Gia_ManName(p->pGia), pPars->nLutSize );
1848 if ( pPars->fCutMin )
1849 pNew = Mf_ManDeriveMappingGia( p );
1850 else if ( pPars->fCoarsen )
1851 pNew = Mf_ManDeriveMappingCoarse( p );
1852 else
1853 pNew = Mf_ManDeriveMapping( p );
1854 if ( p->pPars->fGenCnf )
1855 pGia->pData = Mf_ManDeriveCnf( p, p->pPars->fCnfObjIds, p->pPars->fAddOrCla );
1856 //if ( p->pPars->fGenCnf || p->pPars->fGenLit )
1857 // Mf_ManProfileTruths( p );
1858 Gia_ManMappingVerify( pNew );
1859 Mf_ManPrintQuit( p, pNew );
1860 Mf_ManFree( p );
1861 if ( pCls != pGia )
1862 Gia_ManStop( pCls );
1863 return pNew;
1864}
1865
1877void * Mf_ManGenerateCnf( Gia_Man_t * pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose )
1878{
1879 Gia_Man_t * pNew;
1880 Jf_Par_t Pars, * pPars = &Pars;
1881 assert( nLutSize >= 3 && nLutSize <= 8 );
1882 Mf_ManSetDefaultPars( pPars );
1883 pPars->fGenCnf = 1;
1884 pPars->fCoarsen = !fCnfObjIds;
1885 pPars->nLutSize = nLutSize;
1886 pPars->fCnfObjIds = fCnfObjIds;
1887 pPars->fAddOrCla = fAddOrCla;
1888 pPars->fCnfMapping = fMapping;
1889 pPars->fVerbose = fVerbose;
1890 pNew = Mf_ManPerformMapping( pGia, pPars );
1891 Gia_ManStopP( &pNew );
1892// Cnf_DataPrint( (Cnf_Dat_t *)pGia->pData, 1 );
1893 return pGia->pData;
1894}
1895void Mf_ManDumpCnf( Gia_Man_t * p, char * pFileName, int nLutSize, int fCnfObjIds, int fAddOrCla, int fVerbose )
1896{
1897 abctime clk = Abc_Clock();
1898 Cnf_Dat_t * pCnf;
1899 pCnf = (Cnf_Dat_t *)Mf_ManGenerateCnf( p, nLutSize, fCnfObjIds, fAddOrCla, 0, fVerbose );
1900 Cnf_DataWriteIntoFile( pCnf, pFileName, 0, NULL, NULL );
1901// if ( fVerbose )
1902 {
1903 printf( "CNF stats: Vars = %6d. Clauses = %7d. Literals = %8d. ", pCnf->nVars, pCnf->nClauses, pCnf->nLiterals );
1904 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
1905 }
1906 Cnf_DataFree(pCnf);
1907}
1908
1912
1913
1915
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_FALLOC(type, num)
Definition abc_global.h:266
#define ABC_ALLOC(type, num)
Definition abc_global.h:264
#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_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct Cnf_Dat_t_ Cnf_Dat_t
Definition cnf.h:52
void Cnf_DataFree(Cnf_Dat_t *p)
Definition cnfMan.c:207
void Cnf_DataWriteIntoFile(Cnf_Dat_t *p, char *pFileName, int fReadable, Vec_Int_t *vForAlls, Vec_Int_t *vExists)
Definition cnfMan.c:387
void Dau_DsdPrintFromTruth(word *pTruth, int nVarsInit)
Definition dauDsd.c:1968
Cube * p
Definition exorList.c:222
struct cube Cube
int * Extra_PermSchedule(int n)
int * Extra_GreyCodeSchedule(int n)
void Mf_ManPrintQuit(Mf_Man_t *p, Gia_Man_t *pNew)
Definition giaMf.c:1497
struct Mf_Cut_t_ Mf_Cut_t
Definition giaMf.c:43
#define Mf_SetForEachCut(pList, pCut, i)
Definition giaMf.c:99
#define MF_LEAF_MAX
DECLARATIONS ///.
Definition giaMf.c:35
Gia_Man_t * Mf_ManDeriveMapping(Mf_Man_t *p)
Definition giaMf.c:1229
#define MF_NO_LEAF
Definition giaMf.c:38
Vec_Int_t * Mf_ManDeriveCnfs(Mf_Man_t *p, int *pnVars, int *pnClas, int *pnLits)
Definition giaMf.c:271
Vec_Wrd_t * Mf_ManTruthCollect(int Limit)
Definition giaMf.c:151
int Mf_ManSetMapRefs(Mf_Man_t *p)
Definition giaMf.c:1171
void Mf_ManPrintFanoutProfile(Mf_Man_t *p, Vec_Int_t *vFanCounts)
Definition giaMf.c:1735
#define MF_CUT_MAX
Definition giaMf.c:36
void Mf_ManTruthQuit()
Definition giaMf.c:140
void Mf_ManPrintStats(Mf_Man_t *p, char *pTitle)
Definition giaMf.c:1466
int Mf_ManTruthCount()
Definition giaMf.c:198
int Mf_ManMappingFromMapping(Mf_Man_t *p)
Definition giaMf.c:1700
int Mf_CutDeref_rec(Mf_Man_t *p, int *pCut)
Definition giaMf.c:1559
Gia_Man_t * Mf_ManPerformMapping(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition giaMf.c:1822
int Mf_CutRef2_rec(Mf_Man_t *p, int *pCut, Vec_Int_t *vTemp, int Limit)
Definition giaMf.c:1588
int Mf_CutRef_rec(Mf_Man_t *p, int *pCut)
Definition giaMf.c:1551
void Mf_ManProfileTruths(Mf_Man_t *p)
Definition giaMf.c:217
Cnf_Dat_t * Mf_ManDeriveCnf(Mf_Man_t *p, int fCnfObjIds, int fAddOrCla)
Definition giaMf.c:337
void Mf_ManSetDefaultPars(Jf_Par_t *pPars)
Definition giaMf.c:1441
void Mf_ManSetFlowRefs(Gia_Man_t *p, Vec_Int_t *vRefs)
Definition giaMf.c:1137
void Mf_ManOptimizationOne(Mf_Man_t *p, int iObj)
Definition giaMf.c:1757
int Mf_ManTruthCanonicize(word *t, int nVars)
Definition giaMf.c:121
struct Mf_Man_t_ Mf_Man_t
Definition giaMf.c:62
Gia_Man_t * Mf_ManDeriveMappingCoarse(Mf_Man_t *p)
Definition giaMf.c:1251
void Mf_ManDumpCnf(Gia_Man_t *p, char *pFileName, int nLutSize, int fCnfObjIds, int fAddOrCla, int fVerbose)
Definition giaMf.c:1895
void Mf_ManFree(Mf_Man_t *p)
Definition giaMf.c:1414
int Kit_TruthToGia(Gia_Man_t *pMan, unsigned *pTruth, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
DECLARATIONS ///.
Definition kitHop.c:80
int Mf_ManPrintMfccStats(Mf_Man_t *p, int iObj)
Definition giaMf.c:1749
void Mf_ManComputeMapping(Mf_Man_t *p)
Definition giaMf.c:1814
#define MF_NO_FUNC
Definition giaMf.c:40
void Mf_ObjMergeOrder(Mf_Man_t *p, int iObj)
Definition giaMf.c:1026
void Mf_ManPrintInit(Mf_Man_t *p)
Definition giaMf.c:1481
void Mf_ManOptimization(Mf_Man_t *p)
Definition giaMf.c:1786
struct Mf_Obj_t_ Mf_Obj_t
Definition giaMf.c:53
int Mf_CutDeref2_rec(Mf_Man_t *p, int *pCut, Vec_Int_t *vTemp, int Limit)
Definition giaMf.c:1600
Gia_Man_t * Mf_ManDeriveMappingGia(Mf_Man_t *p)
Definition giaMf.c:1292
void Mf_ManComputeCuts(Mf_Man_t *p)
Definition giaMf.c:1531
#define MF_EPSILON
Definition giaMf.c:41
void * Mf_ManGenerateCnf(Gia_Man_t *pGia, int nLutSize, int fCnfObjIds, int fAddOrCla, int fMapping, int fVerbose)
Definition giaMf.c:1877
Mf_Man_t * Mf_ManAlloc(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition giaMf.c:1381
#define MF_TT_WORDS
Definition giaMf.c:39
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_ManStaticFanoutStop(Gia_Man_t *p)
Definition giaFanout.c:393
double Gia_ManMemory(Gia_Man_t *p)
Definition giaMan.c:194
Gia_Obj_t * Gia_ObjRecognizeMux(Gia_Obj_t *pNode, Gia_Obj_t **ppNodeT, Gia_Obj_t **ppNodeE)
Definition giaUtil.c:1056
#define Gia_ManForEachAnd(p, pObj, i)
Definition gia.h:1214
void Gia_ManStaticMappingFanoutStart(Gia_Man_t *p, Vec_Int_t **pvIndex)
Definition giaFanout.c:335
#define Gia_ManForEachCoId(p, Id, i)
Definition gia.h:1240
void Gia_ManStopP(Gia_Man_t **p)
Definition giaMan.c:224
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
#define Gia_ManForEachCoDriverId(p, DriverId, i)
Definition gia.h:1246
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_ObjIsMuxType(Gia_Obj_t *pNode)
Definition giaUtil.c:982
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
void Gia_ManPrintMuxStats(Gia_Man_t *p)
Definition giaMuxes.c:63
#define Gia_ManForEachAndReverseId(p, i)
Definition gia.h:1224
void Gia_ManMappingVerify(Gia_Man_t *p)
Definition giaIf.c:2257
struct Jf_Par_t_ Jf_Par_t
Definition gia.h:333
#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_ManSetPhase(Gia_Man_t *p)
Definition giaUtil.c:420
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
#define Gia_ManForEachAndId(p, i)
Definition gia.h:1216
#define Gia_ManForEachCiId(p, Id, i)
Definition gia.h:1230
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
int Kit_TruthLitNum(unsigned *pTruth, int nVars, Vec_Int_t *vMemory)
Definition kitGraph.c:511
Vec_Wrd_t * Mpm_ManGetTruthWithCnf(int Limit)
FUNCTION DEFINITIONS ///.
Definition mpmDsd.c:644
int nVars
Definition cnf.h:59
int * pObj2Count
Definition cnf.h:65
int * pObj2Clause
Definition cnf.h:64
int nLiterals
Definition cnf.h:60
int * pVarNums
Definition cnf.h:63
Vec_Int_t * vMapping
Definition cnf.h:67
int ** pClauses
Definition cnf.h:62
int nClauses
Definition cnf.h:61
Aig_Man_t * pMan
Definition cnf.h:58
unsigned * pMuxes
Definition gia.h:106
char * pSpec
Definition gia.h:100
Vec_Int_t * vFanoutNums
Definition gia.h:134
Vec_Int_t * vMapping
Definition gia.h:136
void * pData
Definition gia.h:198
char * pName
Definition gia.h:99
int * pRefs
Definition gia.h:118
unsigned Value
Definition gia.h:89
int nRounds
Definition gia.h:339
int fGenCnf
Definition gia.h:360
int nProcNum
Definition gia.h:338
int nRelaxRatio
Definition gia.h:341
int nCutNum
Definition gia.h:337
int nRoundsEla
Definition gia.h:340
int fOptEdge
Definition gia.h:354
int fCnfObjIds
Definition gia.h:362
int fCnfMapping
Definition gia.h:364
int fAreaOnly
Definition gia.h:350
int nCutNumMax
Definition gia.h:373
int fCoarsen
Definition gia.h:357
int nLutSizeMax
Definition gia.h:372
int nLutSize
Definition gia.h:336
int nAreaTuner
Definition gia.h:343
int fVeryVerbose
Definition gia.h:371
int fCutMin
Definition gia.h:358
int fPureAig
Definition gia.h:365
int nCoarseLimit
Definition gia.h:342
int fVerbose
Definition gia.h:370
int nVerbLimit
Definition gia.h:345
int fGenLit
Definition gia.h:361
int fAddOrCla
Definition gia.h:363
int DelayTarget
Definition gia.h:349
unsigned nLeaves
Definition giaMf.c:50
int Delay
Definition giaMf.c:47
word Sign
Definition giaMf.c:46
int pLeaves[MF_LEAF_MAX+1]
Definition giaMf.c:51
unsigned iFunc
Definition giaMf.c:49
float Flow
Definition giaMf.c:48
int nCutCounts[MF_LEAF_MAX+1]
Definition giaMf.c:82
Vec_Ptr_t vPages
Definition giaMf.c:71
abctime clkStart
Definition giaMf.c:80
Gia_Man_t * pGia
Definition giaMf.c:67
Jf_Par_t * pPars
Definition giaMf.c:68
int iCur
Definition giaMf.c:76
Vec_Int_t vTemp
Definition giaMf.c:75
int fUseEla
Definition giaMf.c:78
Vec_Int_t vCnfSizes
Definition giaMf.c:73
Gia_Man_t * pGia0
Definition giaMf.c:66
double CutCount[4]
Definition giaMf.c:81
int Iter
Definition giaMf.c:77
Vec_Mem_t * vTtMem
Definition giaMf.c:72
Mf_Obj_t * pLfObjs
Definition giaMf.c:70
Vec_Int_t vCnfMem
Definition giaMf.c:74
float nFlowRefs
Definition giaMf.c:58
unsigned Delay
Definition giaMf.c:59
int iCutSet
Definition giaMf.c:56
unsigned nMapRefs
Definition giaMf.c:60
float Flow
Definition giaMf.c:57
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.
Definition utilMem.c:35
#define assert(ex)
Definition util_old.h:213
char * memcpy()
char * memset()
char * memmove()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_WrdForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecWrd.h:54
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42