mirror of https://github.com/YosysHQ/abc.git
Allow for binary input file in 'testdec' and 'testnpn'.
This commit is contained in:
parent
6eb2e7156a
commit
b852db94fb
|
|
@ -4757,13 +4757,14 @@ usage:
|
|||
***********************************************************************/
|
||||
int Abc_CommandTestDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern int Abc_DecTest( char * pFileName, int DecType, int fVerbose );
|
||||
extern int Abc_DecTest( char * pFileName, int DecType, int nVarNum, int fVerbose );
|
||||
char * pFileName;
|
||||
int c;
|
||||
int fVerbose = 0;
|
||||
int DecType = 0;
|
||||
int nVarNum = -1;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "Avh" ) ) != EOF )
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "ANvh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
|
|
@ -4778,6 +4779,17 @@ int Abc_CommandTestDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
if ( DecType < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'N':
|
||||
if ( globalUtilOptind >= argc )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
|
||||
goto usage;
|
||||
}
|
||||
nVarNum = atoi(argv[globalUtilOptind]);
|
||||
globalUtilOptind++;
|
||||
if ( nVarNum < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'v':
|
||||
fVerbose ^= 1;
|
||||
break;
|
||||
|
|
@ -4795,19 +4807,23 @@ int Abc_CommandTestDec( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
// get the output file name
|
||||
pFileName = argv[globalUtilOptind];
|
||||
// call the testbench
|
||||
Abc_DecTest( pFileName, DecType, fVerbose );
|
||||
Abc_DecTest( pFileName, DecType, nVarNum, fVerbose );
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
Abc_Print( -2, "usage: testdec [-A <num>] [-vh] <file_name>\n" );
|
||||
Abc_Print( -2, "usage: testdec [-AN <num>] [-vh] <file>\n" );
|
||||
Abc_Print( -2, "\t testbench for Boolean decomposition algorithms\n" );
|
||||
Abc_Print( -2, "\t-A <num> : decomposition algorithm [default = %d]\n", DecType );
|
||||
Abc_Print( -2, "\t 0: none (reading and writing the file)\n" );
|
||||
Abc_Print( -2, "\t 1: algebraic factoring applied to ISOP\n" );
|
||||
Abc_Print( -2, "\t 2: bi-decomposition with cofactoring\n" );
|
||||
Abc_Print( -2, "\t 3: disjoint-support decomposition with cofactoring\n" );
|
||||
Abc_Print( -2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n" );
|
||||
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
|
||||
Abc_Print( -2, "\t-h : print the command usage\n");
|
||||
Abc_Print( -2, "\t<file> : a text file with truth tables in hexadecimal, listed one per line,\n");
|
||||
Abc_Print( -2, "\t or a binary file with an array of truth tables (in this case,\n");
|
||||
Abc_Print( -2, "\t -N <num> is required to determine how many functions are stored)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
@ -4824,13 +4840,15 @@ usage:
|
|||
***********************************************************************/
|
||||
int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv )
|
||||
{
|
||||
extern int Abc_NpnTest( char * pFileName, int NpnType, int fVerbose );
|
||||
extern int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose );
|
||||
char * pFileName;
|
||||
int c;
|
||||
int fVerbose = 0;
|
||||
int NpnType = 0;
|
||||
int nVarNum = -1;
|
||||
int fDumpRes = 0;
|
||||
Extra_UtilGetoptReset();
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "Avh" ) ) != EOF )
|
||||
while ( ( c = Extra_UtilGetopt( argc, argv, "ANdvh" ) ) != EOF )
|
||||
{
|
||||
switch ( c )
|
||||
{
|
||||
|
|
@ -4845,6 +4863,20 @@ int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
if ( NpnType < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'N':
|
||||
if ( globalUtilOptind >= argc )
|
||||
{
|
||||
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
|
||||
goto usage;
|
||||
}
|
||||
nVarNum = atoi(argv[globalUtilOptind]);
|
||||
globalUtilOptind++;
|
||||
if ( nVarNum < 0 )
|
||||
goto usage;
|
||||
break;
|
||||
case 'd':
|
||||
fDumpRes ^= 1;
|
||||
break;
|
||||
case 'v':
|
||||
fVerbose ^= 1;
|
||||
break;
|
||||
|
|
@ -4862,11 +4894,11 @@ int Abc_CommandTestNpn( Abc_Frame_t * pAbc, int argc, char ** argv )
|
|||
// get the output file name
|
||||
pFileName = argv[globalUtilOptind];
|
||||
// call the testbench
|
||||
Abc_NpnTest( pFileName, NpnType, fVerbose );
|
||||
Abc_NpnTest( pFileName, NpnType, nVarNum, fDumpRes, fVerbose );
|
||||
return 0;
|
||||
|
||||
usage:
|
||||
Abc_Print( -2, "usage: testnpn [-A <num>] [-vh] <file>\n" );
|
||||
Abc_Print( -2, "usage: testnpn [-AN <num>] [-dvh] <file>\n" );
|
||||
Abc_Print( -2, "\t testbench for computing (semi-)canonical forms\n" );
|
||||
Abc_Print( -2, "\t of completely-specified Boolean functions up to 16 varibles\n" );
|
||||
Abc_Print( -2, "\t-A <num> : semi-caninical form computation algorithm [default = %d]\n", NpnType );
|
||||
|
|
@ -4875,9 +4907,13 @@ usage:
|
|||
Abc_Print( -2, "\t 2: semi-canonical form by counting 1s in cofactors\n" );
|
||||
Abc_Print( -2, "\t 3: Jake's hybrid semi-canonical form (fast)\n" );
|
||||
Abc_Print( -2, "\t 4: Jake's hybrid semi-canonical form (high-effort)\n" );
|
||||
Abc_Print( -2, "\t-N <num> : the number of support variables (binary files only) [default = unused]\n" );
|
||||
Abc_Print( -2, "\t-d : toggle dumping resulting functions into a file [default = %s]\n", fDumpRes? "yes": "no" );
|
||||
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose? "yes": "no" );
|
||||
Abc_Print( -2, "\t-h : print the command usage\n");
|
||||
Abc_Print( -2, "\t<file> : the text file with truth tables in hexadecimal, listed one per line\n");
|
||||
Abc_Print( -2, "\t<file> : a text file with truth tables in hexadecimal, listed one per line,\n");
|
||||
Abc_Print( -2, "\t or a binary file with an array of truth tables (in this case,\n");
|
||||
Abc_Print( -2, "\t -N <num> is required to determine how many functions are stored)\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -153,10 +153,57 @@ Abc_TtStore_t * Abc_TruthStoreAlloc( int nVars, int nFuncs )
|
|||
p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
|
||||
return p;
|
||||
}
|
||||
void Abc_TtStoreFree( Abc_TtStore_t * p )
|
||||
Abc_TtStore_t * Abc_TruthStoreAlloc2( int nVars, int nFuncs, word * pBuffer )
|
||||
{
|
||||
free( p->pFuncs );
|
||||
free( p );
|
||||
Abc_TtStore_t * p;
|
||||
int i;
|
||||
p = (Abc_TtStore_t *)malloc( sizeof(Abc_TtStore_t) );
|
||||
p->nVars = nVars;
|
||||
p->nWords = (nVars < 7) ? 1 : (1 << (nVars-6));
|
||||
p->nFuncs = nFuncs;
|
||||
// alloc storage for 'nFuncs' truth tables as one chunk of memory
|
||||
p->pFuncs = (word **)malloc( sizeof(word *) * p->nFuncs );
|
||||
// assign and clean the truth table storage
|
||||
p->pFuncs[0] = pBuffer;
|
||||
// split it up into individual truth tables
|
||||
for ( i = 1; i < p->nFuncs; i++ )
|
||||
p->pFuncs[i] = p->pFuncs[i-1] + p->nWords;
|
||||
return p;
|
||||
}
|
||||
void Abc_TtStoreFree( Abc_TtStore_t * p, int nVarNum )
|
||||
{
|
||||
if ( nVarNum >= 0 )
|
||||
ABC_FREE( p->pFuncs[0] );
|
||||
ABC_FREE( p->pFuncs );
|
||||
ABC_FREE( p );
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Read file contents.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_FileSize( char * pFileName )
|
||||
{
|
||||
FILE * pFile;
|
||||
int nFileSize;
|
||||
pFile = fopen( pFileName, "rb" );
|
||||
if ( pFile == NULL )
|
||||
{
|
||||
printf( "Cannot open file \"%s\" for reading.\n", pFileName );
|
||||
return -1;
|
||||
}
|
||||
// get the file size, in bytes
|
||||
fseek( pFile, 0, SEEK_END );
|
||||
nFileSize = ftell( pFile );
|
||||
fclose( pFile );
|
||||
return nFileSize;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
|
@ -336,22 +383,35 @@ void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName )
|
||||
Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName, int nVarNum )
|
||||
{
|
||||
Abc_TtStore_t * p;
|
||||
char * pFileInput = pFileName;
|
||||
int nVars, nTruths;
|
||||
|
||||
// figure out how many truth table and how many variables
|
||||
Abc_TruthGetParams( pFileInput, &nVars, &nTruths );
|
||||
if ( nVars < 2 || nVars > 16 || nTruths == 0 )
|
||||
return NULL;
|
||||
|
||||
// allocate data-structure
|
||||
p = Abc_TruthStoreAlloc( nVars, nTruths );
|
||||
|
||||
// read info from file
|
||||
Abc_TruthStoreRead( pFileInput, p );
|
||||
if ( nVarNum < 0 )
|
||||
{
|
||||
int nVars, nTruths;
|
||||
// figure out how many truth table and how many variables
|
||||
Abc_TruthGetParams( pFileName, &nVars, &nTruths );
|
||||
if ( nVars < 2 || nVars > 16 || nTruths == 0 )
|
||||
return NULL;
|
||||
// allocate data-structure
|
||||
p = Abc_TruthStoreAlloc( nVars, nTruths );
|
||||
// read info from file
|
||||
Abc_TruthStoreRead( pFileName, p );
|
||||
}
|
||||
else
|
||||
{
|
||||
char * pBuffer;
|
||||
int nFileSize = Abc_FileSize( pFileName );
|
||||
int nBytes = (1 << nVarNum);
|
||||
int nTruths = nFileSize / nBytes;
|
||||
if ( nFileSize == -1 )
|
||||
return NULL;
|
||||
assert( nFileSize % nBytes == 0 );
|
||||
// read file contents
|
||||
pBuffer = Abc_FileRead( pFileName );
|
||||
// allocate data-structure
|
||||
p = Abc_TruthStoreAlloc2( nVarNum, nTruths, (word *)pBuffer );
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
|
|
@ -373,7 +433,7 @@ void Abc_TtStoreTest( char * pFileName )
|
|||
char * pFileOutput = "out.txt";
|
||||
|
||||
// read info from file
|
||||
p = Abc_TtStoreLoad( pFileInput );
|
||||
p = Abc_TtStoreLoad( pFileInput, -1 );
|
||||
if ( p == NULL )
|
||||
return;
|
||||
|
||||
|
|
@ -381,7 +441,7 @@ void Abc_TtStoreTest( char * pFileName )
|
|||
Abc_TtStoreWrite( pFileOutput, p );
|
||||
|
||||
// delete data-structure
|
||||
Abc_TtStoreFree( p );
|
||||
Abc_TtStoreFree( p, -1 );
|
||||
printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
|
||||
}
|
||||
|
||||
|
|
@ -489,27 +549,18 @@ void Abc_TruthDecPerform( Abc_TtStore_t * p, int DecType, int fVerbose )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Abc_TruthDecTest( char * pFileName, int DecType, int fVerbose )
|
||||
void Abc_TruthDecTest( char * pFileName, int DecType, int nVarNum, int fVerbose )
|
||||
{
|
||||
Abc_TtStore_t * p;
|
||||
int nVars, nTruths;
|
||||
|
||||
// figure out how many truth tables and how many variables
|
||||
Abc_TruthGetParams( pFileName, &nVars, &nTruths );
|
||||
if ( nVars < 2 || nVars > 16 || nTruths == 0 )
|
||||
return;
|
||||
|
||||
// allocate data-structure
|
||||
p = Abc_TruthStoreAlloc( nVars, nTruths );
|
||||
|
||||
// read info from file
|
||||
Abc_TruthStoreRead( pFileName, p );
|
||||
p = Abc_TtStoreLoad( pFileName, nVarNum );
|
||||
|
||||
// consider functions from the file
|
||||
Abc_TruthDecPerform( p, DecType, fVerbose );
|
||||
|
||||
// delete data-structure
|
||||
Abc_TtStoreFree( p );
|
||||
Abc_TtStoreFree( p, nVarNum );
|
||||
// printf( "Finished decomposing truth tables from file \"%s\".\n", pFileName );
|
||||
}
|
||||
|
||||
|
|
@ -525,14 +576,14 @@ void Abc_TruthDecTest( char * pFileName, int DecType, int fVerbose )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_DecTest( char * pFileName, int DecType, int fVerbose )
|
||||
int Abc_DecTest( char * pFileName, int DecType, int nVarNum, int fVerbose )
|
||||
{
|
||||
if ( fVerbose )
|
||||
printf( "Using truth tables from file \"%s\"...\n", pFileName );
|
||||
if ( DecType == 0 )
|
||||
Abc_TtStoreTest( pFileName );
|
||||
{ if ( nVarNum < 0 ) Abc_TtStoreTest( pFileName ); }
|
||||
else if ( DecType >= 1 && DecType <= 3 )
|
||||
Abc_TruthDecTest( pFileName, DecType, fVerbose );
|
||||
Abc_TruthDecTest( pFileName, DecType, nVarNum, fVerbose );
|
||||
else
|
||||
printf( "Unknown decomposition type value (%d).\n", DecType );
|
||||
fflush( stdout );
|
||||
|
|
|
|||
|
|
@ -47,8 +47,8 @@ struct Abc_TtStore_t_
|
|||
word ** pFuncs;
|
||||
};
|
||||
|
||||
extern Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName );
|
||||
extern void Abc_TtStoreFree( Abc_TtStore_t * p );
|
||||
extern Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName, int nVarNum );
|
||||
extern void Abc_TtStoreFree( Abc_TtStore_t * p, int nVarNum );
|
||||
extern void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p );
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
@ -276,13 +276,13 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
|
||||
void Abc_TruthNpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose )
|
||||
{
|
||||
Abc_TtStore_t * p;
|
||||
char * pFileNameOut;
|
||||
|
||||
// read info from file
|
||||
p = Abc_TtStoreLoad( pFileName );
|
||||
p = Abc_TtStoreLoad( pFileName, nVarNum );
|
||||
if ( p == NULL )
|
||||
return;
|
||||
|
||||
|
|
@ -290,13 +290,16 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
|
|||
Abc_TruthNpnPerform( p, NpnType, fVerbose );
|
||||
|
||||
// write the result
|
||||
pFileNameOut = Extra_FileNameGenericAppend( pFileName, "_out.txt" );
|
||||
Abc_TtStoreWrite( pFileNameOut, p );
|
||||
if ( fVerbose )
|
||||
printf( "The resulting functions are written into file \"%s\".\n", pFileNameOut );
|
||||
if ( fDumpRes )
|
||||
{
|
||||
pFileNameOut = Extra_FileNameGenericAppend( pFileName, "_out.txt" );
|
||||
Abc_TtStoreWrite( pFileNameOut, p );
|
||||
if ( fVerbose )
|
||||
printf( "The resulting functions are written into file \"%s\".\n", pFileNameOut );
|
||||
}
|
||||
|
||||
// delete data-structure
|
||||
Abc_TtStoreFree( p );
|
||||
Abc_TtStoreFree( p, nVarNum );
|
||||
// printf( "Finished computing canonical forms for functions from file \"%s\".\n", pFileName );
|
||||
}
|
||||
|
||||
|
|
@ -312,12 +315,12 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
|
|||
SeeAlso []
|
||||
|
||||
***********************************************************************/
|
||||
int Abc_NpnTest( char * pFileName, int NpnType, int fVerbose )
|
||||
int Abc_NpnTest( char * pFileName, int NpnType, int nVarNum, int fDumpRes, int fVerbose )
|
||||
{
|
||||
if ( fVerbose )
|
||||
printf( "Using truth tables from file \"%s\"...\n", pFileName );
|
||||
if ( NpnType >= 0 && NpnType <= 4 )
|
||||
Abc_TruthNpnTest( pFileName, NpnType, fVerbose );
|
||||
Abc_TruthNpnTest( pFileName, NpnType, nVarNum, fDumpRes, fVerbose );
|
||||
else
|
||||
printf( "Unknown canonical form value (%d).\n", NpnType );
|
||||
fflush( stdout );
|
||||
|
|
|
|||
Loading…
Reference in New Issue