ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
giaMinLut.c
Go to the documentation of this file.
1
20
21#include "gia.h"
22#include "giaAig.h"
23#include "base/main/mainInt.h"
24#include "opt/sfm/sfm.h"
25
26#ifdef ABC_USE_CUDD
27#include "bdd/extrab/extraBdd.h"
28#include "bdd/dsd/dsd.h"
29#endif
30
32
36
37extern Abc_Ntk_t * Abc_NtkFromAigPhase( Aig_Man_t * pMan );
38
42
54Vec_Wec_t * Vec_WrdReadLayerText( char * pFileName, int * pnIns, int * pnOuts )
55{
56 char * pThis, pLine[1000];
57 Vec_Wec_t * vRes; int iLine;
58 FILE * pFile = fopen( pFileName, "rb" );
59 if ( pFile == NULL )
60 {
61 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
62 return NULL;
63 }
64 vRes = Vec_WecAlloc(100);
65 for ( iLine = 0; fgets( pLine, 1000, pFile ); iLine++ )
66 {
67 if ( iLine == 0 )
68 {
69 pThis = strstr( pLine, "[" );
70 *pnIns = atoi( pThis+1 ) + 1;
71 pThis = strstr( pThis+1, "[" );
72 *pnOuts = atoi( pThis+1 ) + 1;
73 }
74 else
75 {
76 Vec_Int_t * vLevel = NULL;
77 for ( pThis = pLine; (pThis = strstr(pThis, "M0[")); pThis++ )
78 {
79 if ( vLevel == NULL )
80 vLevel = Vec_WecPushLevel( vRes );
81 Vec_IntPush( vLevel, atoi( pThis+3 ) );
82 }
83 if ( vLevel )
84 Vec_IntReverseOrder( vLevel );
85 }
86 }
87 fclose( pFile );
88 //Vec_WecPrint( vRes, 0 );
89 return vRes;
90}
91int Vec_WrdReadTruthTextOne( char * pFileName, int nIns, int nOuts, word * pRes )
92{
93 int i, nWords = Abc_TtWordNum( nIns );
94 char * pStart, * pBuffer = Extra_FileReadContents( pFileName );
95 if ( pBuffer == NULL )
96 {
97 printf( "Cannot read file \"%s\".\n", pFileName );
98 return 0;
99 }
100 pStart = pBuffer;
101 for ( i = 0; i < nOuts; i++ )
102 {
103 pStart = strstr( pStart + 1, "0x" );
104 if ( !Extra_ReadHex( (unsigned *)(pRes + i*nWords), pStart + 2, nWords*16 ) )
105 {
106 printf( "Cannot read truth table %d (out of %d) in file \"%s\".\n", i, nOuts, pFileName );
107 ABC_FREE( pBuffer );
108 return 0;
109 }
110 }
111 ABC_FREE( pBuffer );
112 return 1;
113}
114word * Vec_WrdReadTruthText( char * pFileName, int nIns, int nOuts, int nFiles )
115{
116 char FileName[1000];
117 int i, nWords = Abc_TtWordNum( nIns );
118 word * pRes = ABC_CALLOC( word, nOuts*nFiles*nWords );
119 for ( i = 0; i < nFiles; i++ )
120 {
121 assert( strlen(pFileName) < 900 );
122 strcpy( FileName, pFileName );
123 sprintf( FileName + strlen(FileName) - 2, "_N%d.bench", i );
124 if ( !Vec_WrdReadTruthTextOne( FileName, nIns, nOuts, pRes + i*nOuts*nWords ) )
125 {
126 ABC_FREE( pRes );
127 return NULL;
128 }
129 }
130 return pRes;
131}
132Gia_Man_t * Vec_WrdReadTest( char * pFileName )
133{
134 extern int Gia_ManPerformLNetOpt_rec( Gia_Man_t * pNew, Gia_Man_t * p, Gia_Obj_t * pObj );
135 extern Gia_Man_t * Gia_TryPermOptCare( word * pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose );
136 Gia_Man_t * pPart, * pNew = NULL; Gia_Obj_t * pObj;
137 int i, k, nIns, nOuts, iLit;
138 Vec_Wec_t * vRes = Vec_WrdReadLayerText( pFileName, &nIns, &nOuts );
139 int nBitsI = vRes ? Vec_WecMaxLevelSize(vRes) : 0;
140 int nBitsO = vRes ? nOuts / Vec_WecSize(vRes) : 0;
141 int nWords = Abc_TtWordNum(nBitsI);
142 word * pFuncs = vRes ? Vec_WrdReadTruthText( pFileName, nBitsI, nBitsO, Vec_WecSize(vRes) ) : NULL;
143 Vec_Int_t * vPart, * vLits = Vec_IntAlloc( nOuts );
144 if ( vRes == NULL || pFuncs == NULL )
145 {
146 Vec_WecFreeP( &vRes );
147 Vec_IntFreeP( &vLits );
148 ABC_FREE( pFuncs );
149 return NULL;
150 }
151 assert( nOuts % Vec_WecSize(vRes) == 0 );
152 pNew = Gia_ManStart( 10000 );
153 pNew->pName = Abc_UtilStrsav( pFileName );
154 pNew->pSpec = NULL;
155 for ( i = 0; i < nIns; i++ )
156 Gia_ManAppendCi(pNew);
157 Gia_ManHashStart( pNew );
158 Vec_WecForEachLevel( vRes, vPart, i )
159 {
160 assert( Vec_IntSize(vPart) <= nBitsI );
161 pPart = Gia_TryPermOptCare( pFuncs + i * nBitsO * nWords, nBitsI, nBitsO, nWords, 20, 0 );
162 Gia_ManFillValue( pPart );
163 Gia_ManConst0(pPart)->Value = 0;
164 Gia_ManForEachCi( pPart, pObj, k )
165 pObj->Value = Abc_Var2Lit( 1+Vec_IntEntry(vPart, k), 0 );
166 Gia_ManForEachCo( pPart, pObj, k )
167 {
168 Gia_ManPerformLNetOpt_rec( pNew, pPart, Gia_ObjFanin0(pObj) );
169 Vec_IntPush( vLits, Gia_ObjFanin0Copy(pObj) );
170 }
171 Gia_ManStop( pPart );
172 }
173 Gia_ManHashStop( pNew );
174 Vec_IntForEachEntry( vLits, iLit, i )
175 Gia_ManAppendCo( pNew, iLit );
176 ABC_FREE( pFuncs );
177 Vec_WecFree( vRes );
178 Vec_IntFree( vLits );
179 return pNew;
180}
181
193void Vec_WrdReadText( char * pFileName, Vec_Wrd_t ** pvSimI, Vec_Wrd_t ** pvSimO, int nIns, int nOuts )
194{
195 int i, nSize, iLine, nLines, nWords;
196 char pLine[2000];
197 Vec_Wrd_t * vSimI, * vSimO;
198 FILE * pFile = fopen( pFileName, "rb" );
199 if ( pFile == NULL )
200 {
201 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
202 return;
203 }
204 fseek( pFile, 0, SEEK_END );
205 nSize = ftell( pFile );
206 if ( nSize % (nIns + nOuts + 1) > 0 )
207 {
208 printf( "Cannot read file with simulation data that is not aligned at 8 bytes (remainder = %d).\n", nSize % (nIns + nOuts + 1) );
209 fclose( pFile );
210 return;
211 }
212 rewind( pFile );
213 nLines = nSize / (nIns + nOuts + 1);
214 nWords = (nLines + 63)/64;
215 vSimI = Vec_WrdStart( nIns *nWords );
216 vSimO = Vec_WrdStart( nOuts*nWords );
217 for ( iLine = 0; fgets( pLine, 2000, pFile ); iLine++ )
218 {
219 for ( i = 0; i < nIns; i++ )
220 if ( pLine[nIns-1-i] == '1' )
221 Abc_TtXorBit( Vec_WrdArray(vSimI) + i*nWords, iLine );
222 else assert( pLine[nIns-1-i] == '0' );
223 for ( i = 0; i < nOuts; i++ )
224 if ( pLine[nIns+nOuts-1-i] == '1' )
225 Abc_TtXorBit( Vec_WrdArray(vSimO) + i*nWords, iLine );
226 else assert( pLine[nIns+nOuts-1-i] == '0' );
227 }
228 fclose( pFile );
229 *pvSimI = vSimI;
230 *pvSimO = vSimO;
231 printf( "Read %d words of simulation data for %d inputs and %d outputs (padded %d zero-patterns).\n", nWords, nIns, nOuts, nWords*64-nLines );
232}
233int Vec_WrdReadText2( char * pFileName, Vec_Wrd_t ** pvSimI )
234{
235 int i, nSize, iLine, nLines, nWords, nIns;
236 char pLine[2000];
237 Vec_Wrd_t * vSimI;
238 FILE * pFile = fopen( pFileName, "rb" );
239 if ( pFile == NULL )
240 {
241 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
242 return 0;
243 }
244 if ( !fgets(pLine, 2000, pFile) || (nIns = strlen(pLine)-1) < 1 )
245 {
246 printf( "Cannot find the number of inputs in file \"%s\".\n", pFileName );
247 fclose( pFile );
248 return 0;
249 }
250 fseek( pFile, 0, SEEK_END );
251 nSize = ftell( pFile );
252 if ( nSize % (nIns + 1) > 0 )
253 {
254 printf( "Cannot read file with simulation data that is not aligned at 8 bytes (remainder = %d).\n", nSize % (nIns + 1) );
255 fclose( pFile );
256 return 0;
257 }
258 rewind( pFile );
259 nLines = nSize / (nIns + 1);
260 nWords = (nLines + 63)/64;
261 vSimI = Vec_WrdStart( nIns *nWords );
262 for ( iLine = 0; fgets( pLine, 2000, pFile ); iLine++ )
263 {
264 for ( i = 0; i < nIns; i++ )
265 if ( pLine[nIns-1-i] == '1' )
266 Abc_TtXorBit( Vec_WrdArray(vSimI) + i*nWords, iLine );
267 else assert( pLine[nIns-1-i] == '0' );
268 }
269 fclose( pFile );
270 *pvSimI = vSimI;
271 printf( "Read %d words of simulation data for %d inputs (padded to 64-bit boundary with %d zero-patterns).\n", nWords, nIns, nWords*64-nLines );
272 return nIns;
273}
274Vec_Int_t * Vec_WrdReadNumsOut( char * pFileName, int fVerbose )
275{
276 char pLine[1000];
277 Vec_Int_t * vNums; int iLine;
278 FILE * pFile = fopen( pFileName, "rb" );
279 if ( pFile == NULL )
280 {
281 printf( "Cannot open file \"%s\" for reading.\n", pFileName );
282 return NULL;
283 }
284 vNums = Vec_IntAlloc( 1000 );
285 for ( iLine = 0; fgets( pLine, 1000, pFile ); iLine++ )
286 Vec_IntPush( vNums, atoi(pLine) );
287 fclose( pFile );
288 if ( fVerbose )
289 printf( "Finished reading %d output values from file \"%s\".\n", Vec_IntSize(vNums), pFileName );
290 return vNums;
291}
292Vec_Wrd_t * Vec_WrdReadTextOut( char * pFileName, int nOuts )
293{
294 int i, iLine, nLines, nWords;
295 Vec_Wrd_t * vSimO;
296 Vec_Int_t * vNums = Vec_WrdReadNumsOut( pFileName, 1 );
297 if ( vNums == NULL )
298 return NULL;
299 nLines = Vec_IntSize(vNums);
300 nWords = (nLines + 63)/64;
301 vSimO = Vec_WrdStart( nOuts*nWords );
302 Vec_IntForEachEntry( vNums, i, iLine )
303 Abc_TtXorBit( Vec_WrdArray(vSimO) + i*nWords, iLine );
304 Vec_IntFree( vNums );
305 printf( "Read %d words of simulation data for %d outputs (padded %d zero-patterns).\n", nWords, nOuts, nWords*64-nLines );
306 return vSimO;
307}
308void Gia_ManReadSimInfoInputs( char * pFileName, char * pFileOut1, int fVerbose )
309{
310 Vec_Wrd_t * vSimI;
311 Vec_WrdReadText2( pFileName, &vSimI );
312 Vec_WrdDumpBin( pFileOut1, vSimI, fVerbose );
313 Vec_WrdFree( vSimI );
314}
315void Gia_ManReadSimInfoOutputs( char * pFileName, char * pFileOut, int nOuts )
316{
317 Vec_Wrd_t * vSimO = Vec_WrdReadTextOut( pFileName, nOuts );
318 Vec_WrdDumpBin( pFileOut, vSimO, 1 );
319 Vec_WrdFree( vSimO );
320}
321
333Vec_Wrd_t * Vec_WrdZoneExtract( int ZoneSize, Vec_Wrd_t * p, int iWord, int nWords )
334{
335 int z, nZones = Vec_WrdSize(p)/ZoneSize;
336 int w, Limit = Abc_MinInt( nWords, ZoneSize-iWord );
337 Vec_Wrd_t * pNew = Vec_WrdStart( nZones*nWords );
338 for ( z = 0; z < nZones; z++ )
339 for ( w = 0; w < Limit; w++ )
340 Vec_WrdWriteEntry( pNew, z*nWords + w, Vec_WrdEntry(p, z*ZoneSize + iWord + w) );
341 return pNew;
342}
343void Vec_WrdZoneInsert( Vec_Wrd_t * pNew, int ZoneSize, Vec_Wrd_t * p, int iWord, int nWords )
344{
345 int z, nZones = Vec_WrdSize(pNew)/ZoneSize;
346 int w, Limit = Abc_MinInt( nWords, ZoneSize-iWord );
347 for ( z = 0; z < nZones; z++ )
348 for ( w = 0; w < Limit; w++ )
349 Vec_WrdWriteEntry( pNew, z*ZoneSize + iWord + w, Vec_WrdEntry(p, z*nWords + w) );
350}
351
363void Gia_ManSimInfoPrintOne( Gia_Man_t * p, Vec_Wrd_t * vSimsIn, Vec_Wrd_t * vSimsOut, int nWords, int nPats )
364{
365 int Id, i, k;
366 for ( k = 0; k < nPats; k++ )
367 {
368 Gia_ManForEachCiId( p, Id, i )
369 // printf( "%d", Vec_WrdEntry(p->vSims, p->nSimWords*Id) & 1 );
370 printf( "%d", (int)(Vec_WrdEntry(vSimsIn, nWords*i) >> k) & 1 );
371 printf( " " );
372 Gia_ManForEachCoId( p, Id, i )
373 // printf( "%d", Vec_WrdEntry(p->vSims, p->nSimWords*Id) & 1 );
374 printf( "%d", (int)(Vec_WrdEntry(vSimsOut, nWords*i) >> k) & 1 );
375 printf( "\n" );
376 }
377}
379{
380 extern Vec_Wrd_t * Gia_ManSimulateWordsOut( Gia_Man_t * p, Vec_Wrd_t * vSimsIn );
381 Vec_Wrd_t * vSimsOut = Gia_ManSimulateWordsOut( p, vSimI );
382 int nWords = Vec_WrdSize(vSimI) / Gia_ManCiNum(p);
383 assert( Vec_WrdSize(vSimI) % Gia_ManCiNum(p) == 0 );
384 if ( fPrint )
385 Gia_ManSimInfoPrintOne( p, vSimI, vSimsOut, nWords, 6 );
386 return vSimsOut;
387}
388int Gia_ManSimEvalOne( Gia_Man_t * p, Vec_Wrd_t * vSimO, Vec_Wrd_t * vSimO_new )
389{
390 int i, Count = 0, nWords = Vec_WrdSize(vSimO) / Gia_ManCoNum(p);
391 word * pSim0 = ABC_CALLOC( word, nWords );
392 assert( Vec_WrdSize(vSimO) == Vec_WrdSize(vSimO_new) );
393 for ( i = 0; i < Gia_ManCoNum(p); i++ )
394 {
395 word * pSimGold = Vec_WrdEntryP( vSimO, i * nWords );
396 word * pSimImpl = Vec_WrdEntryP( vSimO_new, i * nWords );
397 Abc_TtOrXor( pSim0, pSimImpl, pSimGold, nWords );
398 }
399 Count = Abc_TtCountOnesVec( pSim0, nWords );
400 printf( "Number of failed patterns is %d (%8.4f %% of %d). The first one is %d.\n",
401 Count, 100.0*Count/(64*nWords), 64*nWords, Abc_TtFindFirstBit2(pSim0, nWords) );
402 ABC_FREE( pSim0 );
403 return Count;
404}
405int Gia_ManSimEvalOne2( Gia_Man_t * p, Vec_Wrd_t * vSimO, Vec_Wrd_t * vSimO_new )
406{
407 int i, Count = 0, nWords = Vec_WrdSize(vSimO) / Gia_ManCoNum(p);
408 word * pSim0 = ABC_CALLOC( word, nWords );
409 assert( Vec_WrdSize(vSimO) == Vec_WrdSize(vSimO_new) );
410 for ( i = 0; i < Gia_ManCoNum(p); i++ )
411 {
412 word * pSimGold = Vec_WrdEntryP( vSimO, i * nWords );
413 word * pSimImpl = Vec_WrdEntryP( vSimO_new, i * nWords );
414 Abc_TtXor( pSim0, pSimImpl, pSimGold, nWords, 0 );
415 Count += Abc_TtCountOnesVec( pSim0, nWords );
416 }
417 printf( "Number of failed patterns is %d (%8.4f %% of %d). The first one is %d.\n",
418 Count, 100.0*Count/(64*nWords*Gia_ManCoNum(p)), 64*nWords*Gia_ManCoNum(p), Abc_TtFindFirstBit2(pSim0, nWords) );
419 ABC_FREE( pSim0 );
420 return Count;
421}
422int Gia_ManSimEvalMaxValue( Vec_Wrd_t * vSimO, int nWords, int nOuts, int nBits, int iPat )
423{
424 int o, ValueMax = -1, OutMax = -1;
425 for ( o = 0; o < nOuts; o++ )
426 {
427 int i, Value = 0;
428 for ( i = 0; i < nBits; i++ )
429 {
430 word * pSim = Vec_WrdEntryP( vSimO, (o*nBits+i) * nWords );
431 if ( Abc_TtGetBit(pSim, iPat) )
432 Value |= 1 << i;
433 }
434 if ( ValueMax <= Value )
435 {
436 ValueMax = Value;
437 OutMax = o;
438 }
439 }
440 return OutMax;
441}
442int Gia_ManSimEvalOne3( Gia_Man_t * p, Vec_Wrd_t * vSimO, Vec_Int_t * vValues, int nBits )
443{
444 int i, Value, nOuts = Gia_ManCoNum(p) / nBits;
445 int First = -1, Count = 0, nWords = Vec_WrdSize(vSimO) / Gia_ManCoNum(p);
446 assert( Gia_ManCoNum(p) % nBits == 0 );
447 assert( 64*(nWords-1) < Vec_IntSize(vValues) && Vec_IntSize(vValues) <= 64*nWords );
448 Vec_IntForEachEntry( vValues, Value, i )
449 if ( Value == Gia_ManSimEvalMaxValue(vSimO, nWords, nOuts, nBits, i) )
450 {
451 Count++;
452 if ( First == -1 )
453 First = i;
454 }
455 printf( "The accuracy is %8.4f %% (%d out of %d output are correct, for example, output number %d).\n",
456 100.0*Count/Vec_IntSize(vValues), Count, Vec_IntSize(vValues), First );
457 if ( 0 )
458 {
459 FILE * pTable = fopen( "stats.txt", "a+" );
460 fprintf( pTable, "%0.2f \n", 100.0*Count/Vec_IntSize(vValues) );
461 fclose( pTable );
462 }
463 return Count;
464}
466{
467 int nWords = Vec_WrdSize(vSimI) / Gia_ManCiNum(p);
468 int w, nWordsOne = 200, nWordBatches = (nWords + nWordsOne - 1)/nWordsOne;
469 Vec_Wrd_t * vSimO_new = Vec_WrdStart( nWords * Gia_ManCoNum(p) );
470 for ( w = 0; w < nWordBatches; w++ )
471 {
472 //int Value = printf( "%3d / %3d : ", w, nWordBatches );
473 Vec_Wrd_t * vSimI_ = Vec_WrdZoneExtract( nWords, vSimI, w*nWordsOne, nWordsOne );
474 Vec_Wrd_t * vSimO_ = Gia_ManSimInfoTryOne( p, vSimI_, 0 );
475 Vec_WrdZoneInsert( vSimO_new, nWords, vSimO_, w*nWordsOne, nWordsOne );
476 Vec_WrdFree( vSimI_ );
477 Vec_WrdFree( vSimO_ );
478 //Value = 0;
479 }
480 return vSimO_new;
481}
483{
484 int nResult = Gia_ManSimEvalOne2(p, vSimO, vSimO_new);
485 //Vec_WrdDumpBin( "temp.simo", vSimO_new, 1 );
486 printf( "Total errors = %d. ", nResult );
487 printf( "Density of output patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSimO_new), Vec_WrdSize(vSimO_new))/(64*Vec_WrdSize(vSimO_new)) );
488 return nResult;
489}
490void Gia_ManSimInfoPassTest( Gia_Man_t * p, char * pFileName, char * pFileName2, int fVerbose )
491{
492 abctime clk = Abc_Clock();
493 Vec_Wrd_t * vSimI = Vec_WrdReadBin( pFileName, fVerbose );
494 Vec_Wrd_t * vSimO = Gia_ManSimInfoTry( p, vSimI );
495 if ( fVerbose )
496 printf( "Density of input patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSimI), Vec_WrdSize(vSimI))/(64*Vec_WrdSize(vSimI)) );
497 if ( fVerbose )
498 printf( "Density of output patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSimO), Vec_WrdSize(vSimO))/(64*Vec_WrdSize(vSimO)) );
499 Vec_WrdDumpBin( pFileName2, vSimO, fVerbose );
500 Vec_WrdFree( vSimI );
501 Vec_WrdFree( vSimO );
502 if ( fVerbose )
503 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
504}
505void Gia_ManSimInfoEval( Gia_Man_t * p, char * pFileName, char * pFileName2, int nOuts, int fVerbose )
506{
507 abctime clk = Abc_Clock();
508 Vec_Wrd_t * vSim1 = Vec_WrdReadBin( pFileName, fVerbose );
509 Vec_Int_t * vNums = Vec_WrdReadNumsOut( pFileName2, fVerbose );
510 assert( nOuts > 0 );
511 if ( fVerbose )
512 printf( "Density of input patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSim1), Vec_WrdSize(vSim1))/(64*Vec_WrdSize(vSim1)) );
513 Gia_ManSimEvalOne3( p, vSim1, vNums, nOuts );
514 Vec_WrdFree( vSim1 );
515 Vec_IntFree( vNums );
516 if ( fVerbose )
517 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
518}
519
531word * Gia_ManCountFraction( Gia_Man_t * p, Vec_Wrd_t * vSimI, Vec_Int_t * vSupp, int Thresh, int fVerbose, int * pCare )
532{
533 Gia_Obj_t * pObj;
534 int i, k, nUsed = 0, nGood = 0;
535 int nWords = Vec_WrdSize(vSimI) / Gia_ManCiNum(p);
536 int nMints = 1 << Vec_IntSize(vSupp);
537 word ** pSims = ABC_ALLOC( word *, Vec_IntSize(vSupp) );
538 word * pRes = ABC_CALLOC( word, Abc_Truth6WordNum(Vec_IntSize(vSupp)) );
539 int * pCounts = ABC_CALLOC( int, nMints );
540 Gia_ManForEachObjVec( vSupp, p, pObj, i )
541 pSims[i] = Vec_WrdEntryP( vSimI, Gia_ObjCioId(pObj) * nWords );
542 for ( k = 0; k < 64*nWords; k++ )
543 {
544 int iMint = 0;
545 for ( i = 0; i < Vec_IntSize(vSupp); i++ )
546 if ( Abc_TtGetBit(pSims[i], k) )
547 iMint |= 1 << i;
548 assert( iMint < nMints );
549 pCounts[iMint]++;
550 }
551 for ( k = 0; k < nMints; k++ )
552 {
553 nUsed += (pCounts[k] > 0);
554 nGood += (pCounts[k] >= Thresh);
555 if ( pCounts[k] >= Thresh )
556 Abc_TtXorBit( pRes, k );
557 //printf( "%d ", pCounts[k] );
558 }
559 if ( Vec_IntSize(vSupp) < 6 )
560 pRes[0] = Abc_Tt6Stretch( pRes[0], Vec_IntSize(vSupp) );
561 //printf( "\n" );
562 if ( fVerbose )
563 printf( "Used %4d and good %4d (out of %4d).\n", nUsed, nGood, nMints );
564 ABC_FREE( pSims );
565 ABC_FREE( pCounts );
566 *pCare = nGood;
567 return pRes;
568}
569void Gia_ManPermuteSupp_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vLevels, Vec_Int_t * vCounts )
570{
571 Gia_Obj_t * pObj; int n;
572 if ( !iObj || Gia_ObjIsTravIdCurrentId(p, iObj) )
573 return;
574 Gia_ObjSetTravIdCurrentId(p, iObj);
575 pObj = Gia_ManObj( p, iObj );
576 if ( Gia_ObjIsCi(pObj) )
577 return;
578 assert( Gia_ObjIsAnd(pObj) );
579 Gia_ManPermuteSupp_rec( p, Gia_ObjFaninId0(pObj, iObj), vLevels, vCounts );
580 Gia_ManPermuteSupp_rec( p, Gia_ObjFaninId1(pObj, iObj), vLevels, vCounts );
581 for ( n = 0; n < 2; n++ )
582 {
583 Gia_Obj_t * pFanin = n ? Gia_ObjFanin1(pObj) : Gia_ObjFanin0(pObj);
584 if ( !Gia_ObjIsCi(pFanin) )
585 continue;
586 Vec_IntAddToEntry( vLevels, Gia_ObjCioId(pFanin), Gia_ObjLevel(p, pObj) );
587 Vec_IntAddToEntry( vCounts, Gia_ObjCioId(pFanin), 1 );
588 }
589}
590void Gia_ManPermuteSupp( Gia_Man_t * p, int iOut, int nOuts, Vec_Int_t * vSupp )
591{
592 Vec_Int_t * vLevels = Vec_IntStart( Gia_ManCiNum(p) );
593 Vec_Int_t * vCounts = Vec_IntStart( Gia_ManCiNum(p) );
594 int i, * pCost = ABC_CALLOC( int, Gia_ManCiNum(p) );
595 Gia_Obj_t * pObj;
597 for ( i = 0; i < nOuts; i++ )
598 Gia_ManPermuteSupp_rec( p, Gia_ObjFaninId0p(p, Gia_ManCo(p, iOut+i)), vLevels, vCounts );
599 Gia_ManForEachObjVec( vSupp, p, pObj, i )
600 pCost[i] = 10000 * Vec_IntEntry(vLevels, Gia_ObjCioId(pObj)) / Abc_MaxInt(1, Vec_IntEntry(vCounts, Gia_ObjCioId(pObj)));
601 Vec_IntFree( vCounts );
602 Vec_IntFree( vLevels );
603 Vec_IntSelectSortCost2( Vec_IntArray(vSupp), Vec_IntSize(vSupp), pCost );
604 assert( Vec_IntSize(vSupp) < 2 || pCost[0] <= pCost[1] );
605 ABC_FREE( pCost );
606}
607void Gia_ManCollectSupp_rec( Gia_Man_t * p, int iObj, Vec_Int_t * vSupp )
608{
609 Gia_Obj_t * pObj;
610 if ( !iObj || Gia_ObjIsTravIdCurrentId(p, iObj) )
611 return;
612 Gia_ObjSetTravIdCurrentId(p, iObj);
613 pObj = Gia_ManObj( p, iObj );
614 if ( Gia_ObjIsCi(pObj) )
615 {
616 //Vec_IntPush( vSupp, Gia_ObjCioId(pObj) );
617 Vec_IntPush( vSupp, Gia_ObjId(p, pObj) );
618 return;
619 }
620 assert( Gia_ObjIsAnd(pObj) );
621 Gia_ManCollectSupp_rec( p, Gia_ObjFaninId0(pObj, iObj), vSupp );
622 Gia_ManCollectSupp_rec( p, Gia_ObjFaninId1(pObj, iObj), vSupp );
623}
624Vec_Int_t * Gia_ManCollectSupp( Gia_Man_t * p, int iOut, int nOuts )
625{
626 Vec_Int_t * vSupp = Vec_IntAlloc( 16 ); int i;
628 for ( i = 0; i < nOuts; i++ )
629 Gia_ManCollectSupp_rec( p, Gia_ObjFaninId0p(p, Gia_ManCo(p, iOut+i)), vSupp );
630 return vSupp;
631}
632Vec_Int_t * Gia_ManCollectSuppNew( Gia_Man_t * p, int iOut, int nOuts )
633{
634 Vec_Int_t * vRes = Gia_ManCollectSupp( p, iOut, nOuts );
635 Gia_ManPermuteSupp( p, iOut, nOuts, vRes );
636 return vRes;
637}
639{
640 if ( ~pObj->Value )
641 return pObj->Value;
642 assert( Gia_ObjIsAnd(pObj) );
643 Gia_ManPerformLNetOpt_rec( pNew, p, Gia_ObjFanin0(pObj) );
644 Gia_ManPerformLNetOpt_rec( pNew, p, Gia_ObjFanin1(pObj) );
645 return pObj->Value = Gia_ManHashAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) );
646}
647Gia_Man_t * Gia_ManPerformLNetOpt( Gia_Man_t * p, int fTryNew, char * pFileName, int nIns, int nOuts, int Thresh, int nRounds, int fVerbose )
648{
649 extern Gia_Man_t * Gia_TryPermOpt( word * pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose );
650 extern Gia_Man_t * Gia_TryPermOptCare( word * pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose );
651 extern int Kit_TruthToGia2( Gia_Man_t * p, unsigned * pTruth0, unsigned * pTruth1, int nVars, Vec_Int_t * vMemory, Vec_Int_t * vLeaves, int fHash );
652 abctime clk = Abc_Clock();
653 Gia_Man_t * pNew; Gia_Obj_t * pObj;
654 Vec_Int_t * vMemory = Vec_IntAlloc( 1 << 18 );
655 Vec_Int_t * vLeaves = Vec_IntAlloc( nIns );
656 Vec_Wrd_t * vSimI = pFileName ? Vec_WrdReadBin( pFileName, fVerbose ) : NULL;
657 word * pTruth0 = ABC_CALLOC( word, Abc_Truth6WordNum(nIns) );
658 word * pTruth1 = ABC_CALLOC( word, Abc_Truth6WordNum(nIns) ); int g, k; float CareAve = 0;
659 word * pTruthsTry = ABC_CALLOC( word, 2*nOuts*Abc_Truth6WordNum(nIns) );
660 if ( vSimI && fVerbose )
661 {
662 //int nPats = 64*Vec_WrdSize(vSimI)/Gia_ManCiNum(p);
663 printf( "Density of input patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSimI), Vec_WrdSize(vSimI))/(64*Vec_WrdSize(vSimI)) );
664 printf( "Using patterns with count %d and higher as cares.\n", Thresh );
665 }
668 pNew = Gia_ManStart( Gia_ManObjNum(p) );
669 pNew->pName = Abc_UtilStrsav( p->pName );
670 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
671 Gia_ManConst0(p)->Value = 0;
672 Gia_ManForEachCi( p, pObj, k )
673 pObj->Value = Gia_ManAppendCi(pNew);
675 Gia_ManHashStart( pNew );
676 for ( g = 0; g < Gia_ManCoNum(p); g += nOuts )
677 {
678 Vec_Int_t * vSupp = Gia_ManCollectSuppNew( p, g, nOuts );
679 int Care = 1 << Vec_IntSize(vSupp), Temp = fVerbose ? printf( "Group %3d / %3d / %3d : Supp = %3d %s", g, nOuts, Gia_ManCoNum(p), Vec_IntSize(vSupp), vSimI ? "":"\n" ) : 0;
680 word * pCare = vSimI ? Gia_ManCountFraction( p, vSimI, vSupp, Thresh, fVerbose, &Care ) : ABC_FALLOC( word, Abc_Truth6WordNum(Vec_IntSize(vSupp)) );
681 int nWords = Abc_Truth6WordNum( Vec_IntSize(vSupp) );
682 CareAve += 100.0*Care/(1 << Vec_IntSize(vSupp));
683 assert( Vec_IntSize(vSupp) <= nIns );
684 Vec_IntClear( vLeaves );
685 Gia_ManForEachObjVec( vSupp, p, pObj, k )
686 Vec_IntPush( vLeaves, pObj->Value );
687 for ( k = 0; k < nOuts; k++ )
688 {
689 Gia_Obj_t * pObj = Gia_ManCo( p, g+k );
690 word * pTruth = Gia_ObjComputeTruthTableCut( p, Gia_ObjFanin0(pObj), vSupp );
691 Abc_TtSharp( pTruth0, pCare, pTruth, nWords );
692 Abc_TtAnd( pTruth1, pCare, pTruth, nWords, 0 );
693 if ( vSimI )
694 {
695 Abc_TtCopy( pTruthsTry + (2*k+0)*nWords, pTruth1, nWords, 0 );
696 Abc_TtCopy( pTruthsTry + (2*k+1)*nWords, pTruth0, nWords, 0 );
697 }
698 else
699 Abc_TtCopy( pTruthsTry + k*nWords, pTruth1, nWords, 0 );
700 if ( !fTryNew )
701 {
702 pObj->Value = Kit_TruthToGia2( pNew, (unsigned *)pTruth0, (unsigned *)pTruth1, Vec_IntSize(vLeaves), vMemory, vLeaves, 1 );
703 pObj->Value ^= Gia_ObjFaninC0(pObj);
704 }
705 }
706 if ( fTryNew )
707 {
708 Gia_Man_t * pMin;
709 if ( vSimI )
710 pMin = Gia_TryPermOpt( pTruthsTry, Vec_IntSize(vSupp), 2*nOuts, nWords, nRounds, fVerbose );
711 else
712 pMin = Gia_TryPermOptCare( pTruthsTry, Vec_IntSize(vSupp), nOuts, nWords, nRounds, fVerbose );
713 Gia_ManFillValue( pMin );
714 Gia_ManConst0(pMin)->Value = 0;
715 Gia_ManForEachCi( pMin, pObj, k )
716 pObj->Value = Vec_IntEntry( vLeaves, k );
717 for ( k = 0; k < nOuts; k++ )
718 {
719 Gia_Obj_t * pObj = Gia_ManCo( p, g+k );
720 Gia_Obj_t * pObj2 = Gia_ManCo( pMin, k );
721 pObj->Value = Gia_ManPerformLNetOpt_rec( pNew, pMin, Gia_ObjFanin0(pObj2) );
722 pObj->Value ^= Gia_ObjFaninC0(pObj2);
723 pObj->Value ^= Gia_ObjFaninC0(pObj);
724 }
725 Gia_ManStop( pMin );
726 }
727 ABC_FREE( pCare );
728 Vec_IntFree( vSupp );
729 Temp = 0;
730 }
731 CareAve /= Gia_ManCoNum(p)/nOuts;
732 Gia_ManHashStop( pNew );
733 Gia_ManForEachCo( p, pObj, k )
734 pObj->Value = Gia_ManAppendCo( pNew, pObj->Value );
736 ABC_FREE( pTruth0 );
737 ABC_FREE( pTruth1 );
738 Vec_IntFree( vLeaves );
739 Vec_IntFree( vMemory );
740 Vec_WrdFreeP( &vSimI );
741 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
742 printf( "Using patterns with count %d and higher as cares. Average care set is %8.4f %%. ", Thresh, CareAve );
743 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
744 if ( 0 )
745 {
746 FILE * pTable = fopen( "stats.txt", "a+" );
747 fprintf( pTable, "%0.2f ", CareAve );
748 fclose( pTable );
749 }
750 ABC_FREE( pTruthsTry );
751 return pNew;
752}
753Gia_Man_t * Gia_ManPerformLNetOptNew( Gia_Man_t * p, char * pFileName, int nIns, int nOuts, int Thresh, int nRounds, int fVerbose )
754{
755 extern Gia_Man_t * Gia_TryPermOptNew( word * pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose );
756 abctime clk = Abc_Clock();
757 Gia_Man_t * pNew, * pMin; Gia_Obj_t * pObj;
758 Vec_Int_t * vLeaves = Vec_IntAlloc( nIns );
759 Vec_Wrd_t * vSimI = pFileName ? Vec_WrdReadBin( pFileName, fVerbose ) : NULL;
760 word * pTruthsTry = ABC_CALLOC( word, (nOuts+1)*Abc_Truth6WordNum(nIns) );
761 int k, g; float CareAve = 0;
762 if ( vSimI && fVerbose )
763 {
764 //int nPats = 64*Vec_WrdSize(vSimI)/Gia_ManCiNum(p);
765 printf( "Density of input patterns %8.4f.\n", (float)Abc_TtCountOnesVec(Vec_WrdArray(vSimI), Vec_WrdSize(vSimI))/(64*Vec_WrdSize(vSimI)) );
766 printf( "Using patterns with count %d and higher as cares.\n", Thresh );
767 }
770 pNew = Gia_ManStart( Gia_ManObjNum(p) );
771 pNew->pName = Abc_UtilStrsav( p->pName );
772 pNew->pSpec = Abc_UtilStrsav( p->pSpec );
773 Gia_ManConst0(p)->Value = 0;
774 Gia_ManForEachCi( p, pObj, k )
775 pObj->Value = Gia_ManAppendCi(pNew);
777 Gia_ManHashStart( pNew );
778 for ( g = 0; g < Gia_ManCoNum(p); g += nOuts )
779 {
780 for ( k = 0; k < nOuts; k++ )
781 if ( Gia_ObjIsAnd(Gia_ObjFanin0(Gia_ManCo( p, g+k ))) )
782 break;
783 if ( k == nOuts )
784 {
785 for ( k = 0; k < nOuts; k++ )
786 {
787 Gia_Obj_t * pObj = Gia_ManCo( p, g+k );
788 pObj->Value = Gia_ObjFanin0Copy(pObj);
789 }
790 continue;
791 }
792 else
793 {
794
795 Vec_Int_t * vSupp = Gia_ManCollectSuppNew( p, g, nOuts );
796 int Care = 1 << Vec_IntSize(vSupp), Temp = fVerbose ? printf( "Group %3d / %3d / %3d : Supp = %3d %s", g, nOuts, Gia_ManCoNum(p), Vec_IntSize(vSupp), vSimI ? "":"\n" ) : 0;
797 word * pCare = vSimI ? Gia_ManCountFraction( p, vSimI, vSupp, Thresh, fVerbose, &Care ) : ABC_FALLOC( word, Abc_Truth6WordNum(Vec_IntSize(vSupp)) );
798 int nWords = Abc_Truth6WordNum( Vec_IntSize(vSupp) );
799 CareAve += 100.0*Care/(1 << Vec_IntSize(vSupp));
800 assert( Vec_IntSize(vSupp) <= nIns );
801 Vec_IntClear( vLeaves );
802 Gia_ManForEachObjVec( vSupp, p, pObj, k )
803 Vec_IntPush( vLeaves, pObj->Value );
804 for ( k = 0; k < nOuts; k++ )
805 {
806 Gia_Obj_t * pObj = Gia_ManCo( p, g+k );
807 word * pTruth = Gia_ObjComputeTruthTableCut( p, Gia_ObjFanin0(pObj), vSupp );
808 Abc_TtCopy( pTruthsTry + k*nWords, pTruth, nWords, Gia_ObjFaninC0(pObj) );
809 }
810 Abc_TtCopy( pTruthsTry + nOuts*nWords, pCare, nWords, 0 );
811 ABC_FREE( pCare );
812 pMin = Gia_TryPermOptNew( pTruthsTry, Vec_IntSize(vSupp), nOuts, nWords, nRounds, fVerbose );
813 Gia_ManFillValue( pMin );
814 Gia_ManConst0(pMin)->Value = 0;
815 Gia_ManForEachCi( pMin, pObj, k )
816 pObj->Value = Vec_IntEntry( vLeaves, k );
817 Gia_ManForEachCo( pMin, pObj, k )
818 {
819 Gia_Obj_t * pObj0 = Gia_ManCo( p, g+k );
820 pObj0->Value = Gia_ManPerformLNetOpt_rec( pNew, pMin, Gia_ObjFanin0(pObj) );
821 pObj0->Value ^= Gia_ObjFaninC0(pObj);
822 }
823 Gia_ManStop( pMin );
824 Vec_IntFree( vSupp );
825 Temp = 0;
826
827 }
828 }
829 CareAve /= Gia_ManCoNum(p)/nOuts;
830 Gia_ManHashStop( pNew );
831 Gia_ManForEachCo( p, pObj, k )
832 pObj->Value = Gia_ManAppendCo( pNew, pObj->Value );
834 Vec_IntFree( vLeaves );
835 Vec_WrdFreeP( &vSimI );
836 Gia_ManSetRegNum( pNew, Gia_ManRegNum(p) );
837 printf( "Using patterns with count %d and higher as cares. Average care set is %8.4f %%. ", Thresh, CareAve );
838 Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
839 if ( 0 )
840 {
841 FILE * pTable = fopen( "stats.txt", "a+" );
842 fprintf( pTable, "%0.2f ", CareAve );
843 fclose( pTable );
844 }
845 ABC_FREE( pTruthsTry );
846 return pNew;
847}
848
849#ifdef ABC_USE_CUDD
850
862Gia_Man_t * Gia_ManDoMuxMapping( Gia_Man_t * p )
863{
864 extern Gia_Man_t * Gia_ManPerformMfs( Gia_Man_t * p, Sfm_Par_t * pPars );
865 Gia_Man_t * pTemp, * pNew = Gia_ManDup( p );
866 Jf_Par_t Pars, * pPars = &Pars; int c, nIters = 2;
867 Sfm_Par_t Pars2, * pPars2 = &Pars2;
868 Lf_ManSetDefaultPars( pPars );
869 Sfm_ParSetDefault( pPars2 );
870 pPars2->nTfoLevMax = 5;
871 pPars2->nDepthMax = 100;
872 pPars2->nWinSizeMax = 2000;
873 for ( c = 0; c < nIters; c++ )
874 {
875 pNew = Lf_ManPerformMapping( pTemp = pNew, pPars );
876 Gia_ManStop( pTemp );
877 pNew = Gia_ManPerformMfs( pTemp = pNew, pPars2 );
878 Gia_ManStop( pTemp );
879 if ( c == nIters-1 )
880 break;
881 pNew = (Gia_Man_t *)Dsm_ManDeriveGia( pTemp = pNew, 0 );
882 Gia_ManStop( pTemp );
883 }
884 return pNew;
885}
886Gia_Man_t * Gia_ManDoMuxTransform( Gia_Man_t * p, int fReorder )
887{
888 extern Gia_Man_t * Abc_NtkStrashToGia( Abc_Ntk_t * pNtk );
889 extern int Abc_NtkBddToMuxesPerformGlo( Abc_Ntk_t * pNtk, Abc_Ntk_t * pNtkNew, int Limit, int fReorder, int fUseAdd );
890 Gia_Man_t * pRes = NULL;
891 Aig_Man_t * pMan = Gia_ManToAig( p, 0 );
892 Abc_Ntk_t * pNtk = Abc_NtkFromAigPhase( pMan );
894 pNtk->pName = Extra_UtilStrsav( pMan->pName );
895 Aig_ManStop( pMan );
896 //pNtkNew = Abc_NtkBddToMuxes( pNtk, 1, 1000000, 1 );
897 if ( Abc_NtkBddToMuxesPerformGlo( pNtk, pNtkNew, 1000000, fReorder, 0 ) )
898 {
899 Abc_Ntk_t * pStrash = Abc_NtkStrash( pNtkNew, 1, 1, 0 );
900 pRes = Abc_NtkStrashToGia( pStrash );
901 Abc_NtkDelete( pStrash );
902 }
903 Abc_NtkDelete( pNtkNew );
904 Abc_NtkDelete( pNtk );
905 return pRes;
906}
907int Gia_ManDoTest1( Gia_Man_t * p, int fReorder )
908{
909 Gia_Man_t * pTemp, * pNew; int Res;
910 pNew = Gia_ManDoMuxTransform( p, fReorder );
911 pNew = Gia_ManDoMuxMapping( pTemp = pNew );
912 Gia_ManStop( pTemp );
913 Res = Gia_ManLutNum( pNew );
914 Gia_ManStop( pNew );
915 return Res;
916}
917Abc_Ntk_t * Gia_ManDoTest2( Gia_Man_t * p, int fReorder, int fTryNew )
918{
919 extern Abc_Ntk_t * Abc_NtkFromMappedGia( Gia_Man_t * p, int fFindEnables, int fUseBuffs );
920 Abc_Ntk_t * pNtkNew;
921 Gia_Man_t * pTemp, * pNew;
922 pNew = fTryNew ? Gia_ManDup(p) : Gia_ManDoMuxTransform( p, fReorder );
923 pNew = Gia_ManDoMuxMapping( pTemp = pNew );
924 Gia_ManStop( pTemp );
925 pNtkNew = Abc_NtkFromMappedGia( pNew, 0, 0 );
926 pNtkNew->pName = Extra_UtilStrsav(p->pName);
927 Gia_ManStop( pNew );
928 Abc_NtkToSop( pNtkNew, 1, ABC_INFINITY );
929 return pNtkNew;
930}
931Abc_Ntk_t * Abc_NtkMapTransform( Gia_Man_t * p, int nOuts, int fUseFixed, int fTryNew, int fVerbose )
932{
933 extern Abc_Ntk_t * Abc_NtkSpecialMapping( Abc_Ntk_t * pNtk, int fVerbose );
934 int i, k, g, nGroups = Gia_ManCoNum(p) / nOuts, CountsAll[3] = {0};
935 Abc_Obj_t * pObjNew, * pFaninNew; Gia_Obj_t * pObj;
937 assert( Gia_ManCoNum(p) % nOuts == 0 );
938 pNtkNew->pName = Extra_UtilStrsav(p->pName);
939 pNtkNew->pSpec = Extra_UtilStrsav(p->pSpec);
941 Gia_ManForEachPi( p, pObj, i )
942 Abc_NtkCreatePi( pNtkNew );
943 Gia_ManForEachPo( p, pObj, i )
944 Abc_NtkCreatePo( pNtkNew );
945 assert( nOuts <= 64 );
946 for ( g = 0; g < nGroups; g++ )
947 {
948 Gia_Man_t * pNew; Aig_Man_t * pMan;
949 Abc_Ntk_t * pNtk, * pNtkRes, * pNtkMap;
950 int pPos[64], Counter = 0, Counts[3] = {0};
951 for ( i = 0; i < nOuts; i++ )
952 pPos[i] = g*nOuts+i;
953 pNew = Gia_ManDupCones( p, pPos, nOuts, 1 );
954 if ( !fUseFixed )
955 pNtkMap = Gia_ManDoTest2( pNew, 1, fTryNew );
956 else
957 {
958 pMan = Gia_ManToAig( pNew, 0 );
959 pNtk = Abc_NtkFromAigPhase( pMan );
960 Aig_ManStop( pMan );
961 pNtkRes = Abc_NtkBddToMuxes( pNtk, 1, 1000000, 1 );
962 Abc_NtkDelete( pNtk );
963 pNtkMap = Abc_NtkSpecialMapping( pNtkRes, 0 );
964 Abc_NtkDelete( pNtkRes );
965 }
966 Gia_ManStop( pNew );
967 Gia_ManForEachCi( p, pObj, i )
968 if ( ~pObj->Value )
969 Abc_NtkCi(pNtkMap, Counter++)->pCopy = Abc_NtkCi(pNtkNew, i);
970 assert( Counter == Abc_NtkCiNum(pNtkMap) );
971 Abc_NtkForEachNode( pNtkMap, pObjNew, i )
972 {
973 pObjNew->pCopy = Abc_NtkDupObj( pNtkNew, pObjNew, 0 );
974 pObjNew->pCopy->fPersist = pObjNew->fPersist;
975 if ( pObjNew->fPersist )
976 Counts[1]++;
977 else
978 Counts[0]++;
979 Abc_ObjForEachFanin( pObjNew, pFaninNew, k )
980 Abc_ObjAddFanin( pObjNew->pCopy, pFaninNew->pCopy );
981 }
982 Abc_NtkForEachCo( pNtkMap, pObjNew, i )
983 Abc_ObjAddFanin( Abc_NtkCo(pNtkNew, g*nOuts+i), Abc_ObjFanin0(pObjNew)->pCopy );
984 Abc_NtkDelete( pNtkMap );
985
986 if ( fVerbose )
987 {
988 printf( "%3d / %3d : ", g, nGroups );
989 printf( "Test = %4d ", Counts[0] );
990 printf( "MarkA = %4d ", Counts[1] );
991 printf( "MarkB = %4d ", Counts[2] );
992 printf( "\n" );
993 }
994
995 CountsAll[0] += Counts[0];
996 CountsAll[1] += Counts[1];
997 CountsAll[2] += Counts[2];
998 }
999 if ( fVerbose )
1000 printf( "Total LUT count = %5d. MarkA = %5d. MarkB = %5d.\n", CountsAll[0], CountsAll[1], CountsAll[2] );
1001 // create names
1002 Abc_NtkAddDummyPiNames( pNtkNew );
1003 Abc_NtkAddDummyPoNames( pNtkNew );
1004 Abc_NtkAddDummyBoxNames( pNtkNew );
1005 // check the resulting AIG
1006 if ( !Abc_NtkCheck( pNtkNew ) )
1007 Abc_Print( 1, "Abc_NtkFromMappedGia(): Network check has failed.\n" );
1008 return pNtkNew;
1009}
1010
1011Abc_Ntk_t * Gia_ManPerformLNetMap( Gia_Man_t * p, int GroupSize, int fUseFixed, int fTryNew, int fVerbose )
1012{
1013 int fPrintOnly = 0;
1014 int Res1, Res2, Result = 0;
1015 int g, nGroups = Gia_ManCoNum(p) / GroupSize;
1016 assert( Gia_ManCoNum(p) % GroupSize == 0 );
1017 assert( GroupSize <= 64 );
1018 if ( fPrintOnly )
1019 {
1020 for ( g = 0; g < nGroups; g++ )
1021 {
1022 Gia_Man_t * pNew;
1023 int o, pPos[64];
1024 for ( o = 0; o < GroupSize; o++ )
1025 pPos[o] = g*GroupSize+o;
1026 pNew = Gia_ManDupCones( p, pPos, GroupSize, 0 );
1027 printf( "%3d / %3d : ", g, nGroups );
1028 printf( "Test1 = %4d ", Res1 = Gia_ManDoTest1(pNew, 0) );
1029 printf( "Test2 = %4d ", Res2 = Gia_ManDoTest1(pNew, 1) );
1030 printf( "Test = %4d ", Abc_MinInt(Res1, Res2) );
1031 printf( "\n" );
1032 Result += Abc_MinInt(Res1, Res2);
1033 //Gia_ManPrintStats( pNew, NULL );
1034 Gia_ManStop( pNew );
1035 }
1036 printf( "Total LUT count = %d.\n", Result );
1037 return NULL;
1038
1039 }
1040 return Abc_NtkMapTransform( p, GroupSize, fUseFixed, fTryNew, fVerbose );
1041}
1042
1043#else
1044
1045Abc_Ntk_t * Gia_ManPerformLNetMap( Gia_Man_t * p, int GroupSize, int fUseFixed, int fTryNew, int fVerbose )
1046{
1047 return NULL;
1048}
1049
1050#endif
1051
1055
1056
1058
Abc_Ntk_t * Abc_NtkFromMappedGia(Gia_Man_t *p, int fFindEnables, int fUseBuffs)
Definition abcDar.c:768
Abc_Ntk_t * Abc_NtkSpecialMapping(Abc_Ntk_t *pNtk, int fVerbose)
Definition abcLut.c:855
int nWords
Definition abcNpn.c:127
Gia_Man_t * Abc_NtkStrashToGia(Abc_Ntk_t *pNtk)
Definition abcUtil.c:3214
struct Abc_Obj_t_ Abc_Obj_t
Definition abc.h:116
#define Abc_NtkForEachCo(pNtk, pCo, i)
Definition abc.h:522
ABC_DLL Abc_Ntk_t * Abc_NtkAlloc(Abc_NtkType_t Type, Abc_NtkFunc_t Func, int fUseMemMan)
DECLARATIONS ///.
Definition abcNtk.c:53
ABC_DLL void Abc_ObjAddFanin(Abc_Obj_t *pObj, Abc_Obj_t *pFanin)
Definition abcFanio.c:84
ABC_DLL Abc_Ntk_t * Abc_NtkBddToMuxes(Abc_Ntk_t *pNtk, int fGlobal, int Limit, int fUseAdd)
Definition abcNtbdd.c:687
ABC_DLL Abc_Obj_t * Abc_NtkDupObj(Abc_Ntk_t *pNtkNew, Abc_Obj_t *pObj, int fCopyName)
Definition abcObj.c:342
ABC_DLL void Abc_NtkAddDummyBoxNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:547
ABC_DLL int Abc_NtkCheck(Abc_Ntk_t *pNtk)
FUNCTION DEFINITIONS ///.
Definition abcCheck.c:64
#define Abc_ObjForEachFanin(pObj, pFanin, i)
Definition abc.h:527
struct Abc_Ntk_t_ Abc_Ntk_t
Definition abc.h:115
@ ABC_NTK_LOGIC
Definition abc.h:57
ABC_DLL void Abc_NtkAddDummyPoNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:521
ABC_DLL int Abc_NtkToSop(Abc_Ntk_t *pNtk, int fMode, int nCubeLimit)
Definition abcFunc.c:1261
ABC_DLL Abc_Ntk_t * Abc_NtkStrash(Abc_Ntk_t *pNtk, int fAllNodes, int fCleanup, int fRecord)
Definition abcStrash.c:265
ABC_DLL void Abc_NtkDelete(Abc_Ntk_t *pNtk)
Definition abcNtk.c:1421
@ ABC_FUNC_SOP
Definition abc.h:65
ABC_DLL Abc_Ntk_t * Abc_NtkStartFrom(Abc_Ntk_t *pNtk, Abc_NtkType_t Type, Abc_NtkFunc_t Func)
Definition abcNtk.c:157
ABC_DLL void Abc_NtkAddDummyPiNames(Abc_Ntk_t *pNtk)
Definition abcNames.c:495
#define Abc_NtkForEachNode(pNtk, pNode, i)
Definition abc.h:464
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
void Aig_ManStop(Aig_Man_t *p)
Definition aigMan.c:187
typedefABC_NAMESPACE_HEADER_START struct Aig_Man_t_ Aig_Man_t
INCLUDES ///.
Definition aig.h:50
int nGood
Definition abcCut.c:34
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
void * Dsm_ManDeriveGia(void *p, int fUseMuxes)
Definition dauGia.c:503
Cube * p
Definition exorList.c:222
int Extra_ReadHex(unsigned Sign[], char *pString, int nDigits)
char * Extra_UtilStrsav(const char *s)
char * Extra_FileReadContents(char *pFileName)
Aig_Man_t * Gia_ManToAig(Gia_Man_t *p, int fChoices)
Definition giaAig.c:318
Vec_Wrd_t * Gia_ManSimulateWordsOut(Gia_Man_t *p, Vec_Wrd_t *vSimsIn)
Definition giaGen.c:198
Gia_Man_t * Gia_ManPerformMfs(Gia_Man_t *p, Sfm_Par_t *pPars)
Definition giaMfs.c:500
Gia_Man_t * Gia_TryPermOpt(word *pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose)
Gia_Man_t * Gia_TryPermOptCare(word *pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose)
Gia_Man_t * Gia_TryPermOptNew(word *pTruths, int nIns, int nOuts, int nWords, int nRounds, int fVerbose)
void Gia_ManSimInfoEval(Gia_Man_t *p, char *pFileName, char *pFileName2, int nOuts, int fVerbose)
Definition giaMinLut.c:505
void Vec_WrdZoneInsert(Vec_Wrd_t *pNew, int ZoneSize, Vec_Wrd_t *p, int iWord, int nWords)
Definition giaMinLut.c:343
void Gia_ManReadSimInfoOutputs(char *pFileName, char *pFileOut, int nOuts)
Definition giaMinLut.c:315
void Vec_WrdReadText(char *pFileName, Vec_Wrd_t **pvSimI, Vec_Wrd_t **pvSimO, int nIns, int nOuts)
Definition giaMinLut.c:193
Gia_Man_t * Vec_WrdReadTest(char *pFileName)
Definition giaMinLut.c:132
Vec_Wrd_t * Vec_WrdReadTextOut(char *pFileName, int nOuts)
Definition giaMinLut.c:292
ABC_NAMESPACE_IMPL_START Abc_Ntk_t * Abc_NtkFromAigPhase(Aig_Man_t *pMan)
DECLARATIONS ///.
Definition abcDar.c:595
Vec_Wec_t * Vec_WrdReadLayerText(char *pFileName, int *pnIns, int *pnOuts)
FUNCTION DEFINITIONS ///.
Definition giaMinLut.c:54
int Vec_WrdReadTruthTextOne(char *pFileName, int nIns, int nOuts, word *pRes)
Definition giaMinLut.c:91
void Gia_ManSimInfoPassTest(Gia_Man_t *p, char *pFileName, char *pFileName2, int fVerbose)
Definition giaMinLut.c:490
Vec_Int_t * Gia_ManCollectSupp(Gia_Man_t *p, int iOut, int nOuts)
Definition giaMinLut.c:624
Abc_Ntk_t * Gia_ManPerformLNetMap(Gia_Man_t *p, int GroupSize, int fUseFixed, int fTryNew, int fVerbose)
Definition giaMinLut.c:1045
int Gia_ManSimEvalOne2(Gia_Man_t *p, Vec_Wrd_t *vSimO, Vec_Wrd_t *vSimO_new)
Definition giaMinLut.c:405
Gia_Man_t * Gia_ManPerformLNetOptNew(Gia_Man_t *p, char *pFileName, int nIns, int nOuts, int Thresh, int nRounds, int fVerbose)
Definition giaMinLut.c:753
int Vec_WrdReadText2(char *pFileName, Vec_Wrd_t **pvSimI)
Definition giaMinLut.c:233
int Gia_ManSimInfoEval_old(Gia_Man_t *p, Vec_Wrd_t *vSimO, Vec_Wrd_t *vSimO_new)
Definition giaMinLut.c:482
Vec_Wrd_t * Gia_ManSimInfoTry(Gia_Man_t *p, Vec_Wrd_t *vSimI)
Definition giaMinLut.c:465
Vec_Wrd_t * Gia_ManSimInfoTryOne(Gia_Man_t *p, Vec_Wrd_t *vSimI, int fPrint)
Definition giaMinLut.c:378
Gia_Man_t * Gia_ManPerformLNetOpt(Gia_Man_t *p, int fTryNew, char *pFileName, int nIns, int nOuts, int Thresh, int nRounds, int fVerbose)
Definition giaMinLut.c:647
Vec_Int_t * Gia_ManCollectSuppNew(Gia_Man_t *p, int iOut, int nOuts)
Definition giaMinLut.c:632
void Gia_ManPermuteSupp_rec(Gia_Man_t *p, int iObj, Vec_Int_t *vLevels, Vec_Int_t *vCounts)
Definition giaMinLut.c:569
Vec_Int_t * Vec_WrdReadNumsOut(char *pFileName, int fVerbose)
Definition giaMinLut.c:274
void Gia_ManReadSimInfoInputs(char *pFileName, char *pFileOut1, int fVerbose)
Definition giaMinLut.c:308
void Gia_ManCollectSupp_rec(Gia_Man_t *p, int iObj, Vec_Int_t *vSupp)
Definition giaMinLut.c:607
void Gia_ManPermuteSupp(Gia_Man_t *p, int iOut, int nOuts, Vec_Int_t *vSupp)
Definition giaMinLut.c:590
word * Gia_ManCountFraction(Gia_Man_t *p, Vec_Wrd_t *vSimI, Vec_Int_t *vSupp, int Thresh, int fVerbose, int *pCare)
Definition giaMinLut.c:531
int Gia_ManSimEvalOne(Gia_Man_t *p, Vec_Wrd_t *vSimO, Vec_Wrd_t *vSimO_new)
Definition giaMinLut.c:388
word * Vec_WrdReadTruthText(char *pFileName, int nIns, int nOuts, int nFiles)
Definition giaMinLut.c:114
void Gia_ManSimInfoPrintOne(Gia_Man_t *p, Vec_Wrd_t *vSimsIn, Vec_Wrd_t *vSimsOut, int nWords, int nPats)
Definition giaMinLut.c:363
Vec_Wrd_t * Vec_WrdZoneExtract(int ZoneSize, Vec_Wrd_t *p, int iWord, int nWords)
Definition giaMinLut.c:333
int Gia_ManSimEvalOne3(Gia_Man_t *p, Vec_Wrd_t *vSimO, Vec_Int_t *vValues, int nBits)
Definition giaMinLut.c:442
int Gia_ManSimEvalMaxValue(Vec_Wrd_t *vSimO, int nWords, int nOuts, int nBits, int iPat)
Definition giaMinLut.c:422
int Gia_ManPerformLNetOpt_rec(Gia_Man_t *pNew, Gia_Man_t *p, Gia_Obj_t *pObj)
Definition giaMinLut.c:638
void Gia_ManStop(Gia_Man_t *p)
Definition giaMan.c:82
Gia_Man_t * Gia_ManDup(Gia_Man_t *p)
Definition giaDup.c:720
word * Gia_ObjComputeTruthTableCut(Gia_Man_t *p, Gia_Obj_t *pObj, Vec_Int_t *vLeaves)
Definition giaTruth.c:628
void Gia_ManHashStart(Gia_Man_t *p)
Definition giaHash.c:125
#define Gia_ManForEachPo(p, pObj, i)
Definition gia.h:1250
#define Gia_ManForEachCoId(p, Id, i)
Definition gia.h:1240
void Gia_ManSetRegNum(Gia_Man_t *p, int nRegs)
Definition giaMan.c:764
#define Gia_ManForEachPi(p, pObj, i)
Definition gia.h:1248
Gia_Man_t * Gia_ManStart(int nObjsMax)
FUNCTION DEFINITIONS ///.
Definition giaMan.c:57
struct Gia_Obj_t_ Gia_Obj_t
Definition gia.h:76
void Gia_ManFillValue(Gia_Man_t *p)
Definition giaUtil.c:369
struct Gia_Man_t_ Gia_Man_t
Definition gia.h:96
Gia_Man_t * Lf_ManPerformMapping(Gia_Man_t *pGia, Jf_Par_t *pPars)
Definition giaLf.c:2242
#define Gia_ManForEachObjVec(vVec, p, pObj, i)
Definition gia.h:1194
Gia_Man_t * Gia_ManDupCones(Gia_Man_t *p, int *pPos, int nPos, int fTrimPis)
Definition giaDup.c:3880
void Gia_ObjComputeTruthTableStart(Gia_Man_t *p, int nVarsMax)
Definition giaTruth.c:552
int Gia_ManLutNum(Gia_Man_t *p)
Definition giaIf.c:146
void Lf_ManSetDefaultPars(Jf_Par_t *pPars)
Definition giaLf.c:2021
void Gia_ObjComputeTruthTableStop(Gia_Man_t *p)
Definition giaTruth.c:568
int Gia_ManHashAnd(Gia_Man_t *p, int iLit0, int iLit1)
Definition giaHash.c:576
void Gia_ManIncrementTravId(Gia_Man_t *p)
Definition giaUtil.c:190
struct Jf_Par_t_ Jf_Par_t
Definition gia.h:333
#define Gia_ManForEachCo(p, pObj, i)
Definition gia.h:1236
#define Gia_ManForEachCi(p, pObj, i)
Definition gia.h:1228
void Gia_ManHashStop(Gia_Man_t *p)
Definition giaHash.c:149
int Gia_ManLevelNum(Gia_Man_t *p)
Definition giaUtil.c:546
#define Gia_ManForEachCiId(p, Id, i)
Definition gia.h:1230
int Kit_TruthToGia2(Gia_Man_t *pMan, unsigned *pTruth0, unsigned *pTruth1, int nVars, Vec_Int_t *vMemory, Vec_Int_t *vLeaves, int fHash)
Definition kitHop.c:103
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
struct Sfm_Par_t_ Sfm_Par_t
Definition sfm.h:42
void Sfm_ParSetDefault(Sfm_Par_t *pPars)
MACRO DEFINITIONS ///.
Definition sfmCore.c:46
char * pName
Definition abc.h:158
char * pSpec
Definition abc.h:159
Abc_Obj_t * pCopy
Definition abc.h:148
unsigned fPersist
Definition abc.h:139
char * pSpec
Definition gia.h:100
char * pName
Definition gia.h:99
unsigned Value
Definition gia.h:89
int nTfoLevMax
Definition sfm.h:45
int nWinSizeMax
Definition sfm.h:53
int nDepthMax
Definition sfm.h:48
#define assert(ex)
Definition util_old.h:213
int strlen()
char * sprintf()
char * strstr()
char * strcpy()
VOID_HACK rewind()
#define Vec_IntForEachEntry(vVec, Entry, i)
MACRO DEFINITIONS ///.
Definition vecInt.h:54
#define Vec_WecForEachLevel(vGlob, vVec, i)
MACRO DEFINITIONS ///.
Definition vecWec.h:55
typedefABC_NAMESPACE_HEADER_START struct Vec_Wec_t_ Vec_Wec_t
INCLUDES ///.
Definition vecWec.h:42
typedefABC_NAMESPACE_HEADER_START struct Vec_Wrd_t_ Vec_Wrd_t
INCLUDES ///.
Definition vecWrd.h:42
#define SEEK_END
Definition zconf.h:392