summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-10-05 20:38:46 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-10-05 20:38:46 -0700
commitb852db94fbe7f6652ffcef6964195a4ea4d02108 (patch)
treed954257c377e63e629c82f92d1c7713c1b55b6fc /src
parent6eb2e7156aaa62cef58f5e7b1f6d944c09688a41 (diff)
downloadabc-b852db94fbe7f6652ffcef6964195a4ea4d02108.tar.gz
abc-b852db94fbe7f6652ffcef6964195a4ea4d02108.tar.bz2
abc-b852db94fbe7f6652ffcef6964195a4ea4d02108.zip
Allow for binary input file in 'testdec' and 'testnpn'.
Diffstat (limited to 'src')
-rw-r--r--src/base/abci/abc.c54
-rw-r--r--src/base/abci/abcDec.c119
-rw-r--r--src/base/abci/abcNpn.c25
3 files changed, 144 insertions, 54 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index 39064d93..d515fb5c 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -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;
}
diff --git a/src/base/abci/abcDec.c b/src/base/abci/abcDec.c
index 962efb87..7b8370cd 100644
--- a/src/base/abci/abcDec.c
+++ b/src/base/abci/abcDec.c
@@ -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 );
diff --git a/src/base/abci/abcNpn.c b/src/base/abci/abcNpn.c
index 0ca6c70b..9494cba2 100644
--- a/src/base/abci/abcNpn.c
+++ b/src/base/abci/abcNpn.c
@@ -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 );