Skip to content

Commit c5ceff2

Browse files
committed
Dumping a binary file with truth tables in "if".
1 parent e29dcd9 commit c5ceff2

File tree

4 files changed

+53
-6
lines changed

4 files changed

+53
-6
lines changed

src/base/abci/abc.c

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21492,7 +21492,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
2149221492
If_ManSetDefaultPars( pPars );
2149321493
pPars->pLutLib = (If_LibLut_t *)Abc_FrameReadLibLut();
2149421494
Extra_UtilGetoptReset();
21495-
while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRNTXYUZDEWSJqaflepmrsdbgxyzuojiktncvh" ) ) != EOF )
21495+
while ( ( c = Extra_UtilGetopt( argc, argv, "KCFAGRNTXYUZDEWSJqalepmrsdbgxyzuojiktncfvh" ) ) != EOF )
2149621496
{
2149721497
switch ( c )
2149821498
{
@@ -21703,9 +21703,9 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
2170321703
case 'r':
2170421704
pPars->fExpRed ^= 1;
2170521705
break;
21706-
case 'f':
21707-
pPars->fFancy ^= 1;
21708-
break;
21706+
//case 'f':
21707+
// pPars->fFancy ^= 1;
21708+
// break;
2170921709
case 'l':
2171021710
pPars->fLatchPaths ^= 1;
2171121711
break;
@@ -21760,6 +21760,9 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
2176021760
case 'c':
2176121761
pPars->fUseTtPerm ^= 1;
2176221762
break;
21763+
case 'f':
21764+
pPars->fDumpFile ^= 1;
21765+
break;
2176321766
case 'v':
2176421767
pPars->fVerbose ^= 1;
2176521768
break;
@@ -22071,7 +22074,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
2207122074
sprintf(LutSize, "library" );
2207222075
else
2207322076
sprintf(LutSize, "%d", pPars->nLutSize );
22074-
Abc_Print( -2, "usage: if [-KCFAGRNTXYUZ num] [-DEW float] [-SJ str] [-qarlepmsdbgxyuojiktnczvh]\n" );
22077+
Abc_Print( -2, "usage: if [-KCFAGRNTXYUZ num] [-DEW float] [-SJ str] [-qarlepmsdbgxyuojiktnczfvh]\n" );
2207522078
Abc_Print( -2, "\t performs FPGA technology mapping of the network\n" );
2207622079
Abc_Print( -2, "\t-K num : the number of LUT inputs (2 < num < %d) [default = %s]\n", IF_MAX_LUTSIZE+1, LutSize );
2207722080
Abc_Print( -2, "\t-C num : the max number of priority cuts (0 < num < 2^12) [default = %d]\n", pPars->nCutsMax );
@@ -22112,6 +22115,7 @@ int Abc_CommandIf( Abc_Frame_t * pAbc, int argc, char ** argv )
2211222115
Abc_Print( -2, "\t-n : toggles computing DSDs of the cut functions [default = %s]\n", pPars->fUseDsd? "yes": "no" );
2211322116
Abc_Print( -2, "\t-c : toggles computing truth tables in a new way [default = %s]\n", pPars->fUseTtPerm? "yes": "no" );
2211422117
Abc_Print( -2, "\t-z : toggles deriving LUTs when mapping into LUT structures [default = %s]\n", pPars->fDeriveLuts? "yes": "no" );
22118+
Abc_Print( -2, "\t-f : toggles dumping truth tables into a binary file [default = %s]\n", pPars->fDumpFile? "yes": "no" );
2211522119
Abc_Print( -2, "\t-v : toggles verbose output [default = %s]\n", pPars->fVerbose? "yes": "no" );
2211622120
Abc_Print( -2, "\t-h : prints the command usage\n");
2211722121
return 1;

src/base/abci/abcResub.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020

2121
#include "base/abc/abc.h"
2222
#include "bool/dec/dec.h"
23+
#include "misc/extra/extra.h"
2324

2425
ABC_NAMESPACE_IMPL_START
2526

@@ -165,7 +166,9 @@ int Abc_NtkResubstitute( Abc_Ntk_t * pNtk, int nCutMax, int nStepsMax, int nMinS
165166
pManRes->Log2Probs = Log2Probs;
166167
pManRes->Log2Divs = Log2Divs;
167168
pManRes->nProbs = 0;
168-
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d.bin", Log2Probs, nCutMax, Log2Divs );
169+
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(pNtk->pName));
170+
char pFileName[100]; sprintf( pFileName, "p%02dd%02dv%02d_%s.bin", Log2Probs, nCutMax, Log2Divs, pName );
171+
ABC_FREE( pName );
169172
pManRes->pFile = fopen( pFileName, "wb" );
170173
if ( pManRes->pFile == NULL ) {
171174
printf( "Cannot open output file \"%s\".\n", pFileName );

src/map/if/if.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct If_Par_t_
149149
int fHashMapping; // perform AIG hashing after mapping
150150
int fUserLutDec; // perform Boolean decomposition during mapping
151151
int fUserLut2D; // perform Boolean decomposition during mapping
152+
int fDumpFile; // dumping truth tables into a file
152153
int fVerbose; // the verbosity flag
153154
int fVerboseTrace; // the verbosity flag
154155
char * pLutStruct; // LUT structure

src/map/if/ifMan.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
***********************************************************************/
2020

2121
#include "if.h"
22+
#include "misc/extra/extra.h"
2223

2324
ABC_NAMESPACE_IMPL_START
2425

@@ -211,6 +212,44 @@ void If_ManRestart( If_Man_t * p )
211212
***********************************************************************/
212213
void If_ManStop( If_Man_t * p )
213214
{
215+
if ( p->pPars->fDumpFile && p->pPars->fTruth )
216+
{
217+
char pFileName[1000] = {0}, pBuffer[100];
218+
int nUnique = 0, nChunks = 0, nChunkSize = 1 << 10, nBytes = 0;
219+
for ( int i = 7; i <= p->pPars->nLutSize; i++ ) {
220+
nUnique = Vec_MemEntryNum(p->vTtMem[i]);
221+
nChunks = (nUnique + nChunkSize - 1) / nChunkSize;
222+
printf( "LutSize = %2d Unique = %7d Chunks = %7d\n", i, nUnique, nChunks );
223+
sprintf( pBuffer, "%s%02d_%02d", i == 7 ? "":"__", i, nChunks );
224+
strcat( pFileName, pBuffer );
225+
}
226+
char * pName = Extra_FileNameGeneric(Extra_FileNameWithoutPath(p->pName));
227+
sprintf( pBuffer, "__%s.bin", pName );
228+
ABC_FREE( pName );
229+
strcat( pFileName, pBuffer );
230+
FILE * pFile = fopen( pFileName, "wb" );
231+
if ( pFile == NULL )
232+
printf( "Cannot open file \"%s\" for writing.\n", pFileName );
233+
else {
234+
for ( int i = 7; i <= p->pPars->nLutSize; i++ ) {
235+
nUnique = Vec_MemEntryNum(p->vTtMem[i]);
236+
nChunks = (nUnique + nChunkSize - 1) / nChunkSize;
237+
word * pEntry; int k, Count = 0;
238+
int nEntrySize = Vec_MemEntrySize(p->vTtMem[i]);
239+
Vec_MemForEachEntry( p->vTtMem[i], pEntry, k )
240+
Count += fwrite( (unsigned *)pEntry, 1, sizeof(word) * nEntrySize, pFile );
241+
word * pZeros = ABC_CALLOC( word, nEntrySize );
242+
for ( ; k < nChunks * nChunkSize; k++ )
243+
Count += fwrite( (unsigned *)pZeros, 1, sizeof(word) * nEntrySize, pFile );
244+
ABC_FREE( pZeros );
245+
assert( Count == nChunks * nChunkSize * nEntrySize * sizeof(word) );
246+
nBytes += nChunks * nChunkSize * nEntrySize * sizeof(word);
247+
}
248+
fclose( pFile );
249+
printf( "Finished writing truth tables into file \"%s\" (%.3f MB).\n", pFileName, 1.0 * nBytes / (1<<20) );
250+
}
251+
}
252+
214253
extern void If_ManCacheAnalize( If_Man_t * p );
215254
int i;
216255
if ( p->pPars->fVerbose && p->vCutData )

0 commit comments

Comments
 (0)