summaryrefslogtreecommitdiffstats
path: root/src/base/abci/abcNpn.c
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2012-08-25 10:30:53 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2012-08-25 10:30:53 -0700
commit49c5799934a5ab4f4ca2143e0edb43823ed4b0dd (patch)
tree87a3da17000ac869ff54ab4a9489d698273fa878 /src/base/abci/abcNpn.c
parentf85db9dd1f1020aef4fd1ecef9ac6506b48afb25 (diff)
downloadabc-49c5799934a5ab4f4ca2143e0edb43823ed4b0dd.tar.gz
abc-49c5799934a5ab4f4ca2143e0edb43823ed4b0dd.tar.bz2
abc-49c5799934a5ab4f4ca2143e0edb43823ed4b0dd.zip
Several improvements to command 'testnpn'.
Diffstat (limited to 'src/base/abci/abcNpn.c')
-rw-r--r--src/base/abci/abcNpn.c78
1 files changed, 47 insertions, 31 deletions
diff --git a/src/base/abci/abcNpn.c b/src/base/abci/abcNpn.c
index 70c08da7..6e753e3b 100644
--- a/src/base/abci/abcNpn.c
+++ b/src/base/abci/abcNpn.c
@@ -49,7 +49,7 @@ struct Abc_TtStore_t_
extern Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName );
extern void Abc_TtStoreFree( Abc_TtStore_t * p );
-extern void Abc_TtStoreTest( char * pFileName );
+extern void Abc_TtStoreWrite( char * pFileName, Abc_TtStore_t * p );
////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS ///
@@ -67,20 +67,19 @@ extern void Abc_TtStoreTest( char * pFileName );
***********************************************************************/
int nWords = 0; // unfortunate global variable
-int Abc_TruthCompare( word * p1, word * p2 ) { return memcmp(p1, p2, sizeof(word) * nWords); }
+int Abc_TruthCompare( word ** p1, word ** p2 ) { return memcmp(*p1, *p2, sizeof(word) * nWords); }
int Abc_TruthNpnCountUnique( Abc_TtStore_t * p )
{
- int i, nUnique;
+ int i, k;
// sort them by value
nWords = p->nWords;
assert( nWords > 0 );
- qsort( (void *)p->pFuncs[0], p->nFuncs, nWords * sizeof(word), (int(*)(const void *,const void *))Abc_TruthCompare );
+ qsort( (void *)p->pFuncs, p->nFuncs, sizeof(word *), (int(*)(const void *,const void *))Abc_TruthCompare );
// count the number of unqiue functions
- nUnique = p->nFuncs;
- for ( i = 1; i < p->nFuncs; i++ )
- if ( !memcmp( p->pFuncs[i-1], p->pFuncs[i], sizeof(word) * nWords ) )
- nUnique--;
- return nUnique;
+ for ( i = k = 1; i < p->nFuncs; i++ )
+ if ( memcmp( p->pFuncs[i-1], p->pFuncs[i], sizeof(word) * nWords ) )
+ p->pFuncs[k++] = p->pFuncs[i];
+ return (p->nFuncs = k);
}
/**Function*************************************************************
@@ -104,14 +103,16 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
int i;//, nFuncs = 0;
char * pAlgoName = NULL;
- if ( NpnType == 1 )
- pAlgoName = "counting 1s ";
+ if ( NpnType == 0 )
+ pAlgoName = "uniqifying ";
+ else if ( NpnType == 1 )
+ pAlgoName = "exact NPN ";
else if ( NpnType == 2 )
- pAlgoName = "minimizing TT";
+ pAlgoName = "counting 1s ";
else if ( NpnType == 3 )
- pAlgoName = "exact NPN ";
+ pAlgoName = "minimizing TT";
else if ( NpnType == 4 )
- pAlgoName = "heuristic NPN";
+ pAlgoName = "hybrid NPN ";
assert( p->nVars <= 16 );
if ( pAlgoName )
@@ -120,29 +121,17 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
if ( fVerbose )
printf( "\n" );
- if ( NpnType == 1 )
- {
- for ( i = 0; i < p->nFuncs; i++ )
- {
- if ( fVerbose )
- printf( "%7d : ", i );
- Kit_TruthSemiCanonicize( (unsigned *)p->pFuncs[i], pAux, p->nVars, pCanonPerm, pStore );
- if ( fVerbose )
- Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
- }
- }
- else if ( NpnType == 2 )
+ if ( NpnType == 0 )
{
for ( i = 0; i < p->nFuncs; i++ )
{
if ( fVerbose )
printf( "%7d : ", i );
- Kit_TruthSemiCanonicize_new( (unsigned *)p->pFuncs[i], pAux, p->nVars, pCanonPerm );
if ( fVerbose )
Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
}
}
- else if ( NpnType == 3 )
+ else if ( NpnType == 1 )
{
int * pComp = Extra_GreyCodeSchedule( p->nVars );
int * pPerm = Extra_PermSchedule( p->nVars );
@@ -162,6 +151,28 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
ABC_FREE( pComp );
ABC_FREE( pPerm );
}
+ else if ( NpnType == 2 )
+ {
+ for ( i = 0; i < p->nFuncs; i++ )
+ {
+ if ( fVerbose )
+ printf( "%7d : ", i );
+ Kit_TruthSemiCanonicize( (unsigned *)p->pFuncs[i], pAux, p->nVars, pCanonPerm, pStore );
+ if ( fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
+ }
+ }
+ else if ( NpnType == 3 )
+ {
+ for ( i = 0; i < p->nFuncs; i++ )
+ {
+ if ( fVerbose )
+ printf( "%7d : ", i );
+ Kit_TruthSemiCanonicize_new( (unsigned *)p->pFuncs[i], pAux, p->nVars, pCanonPerm );
+ if ( fVerbose )
+ Extra_PrintHex( stdout, (unsigned *)p->pFuncs[i], p->nVars ), printf( "\n" );
+ }
+ }
else if ( NpnType == 4 )
{
if ( p->nVars == 6 )
@@ -200,6 +211,7 @@ void Abc_TruthNpnPerform( Abc_TtStore_t * p, int NpnType, int fVerbose )
void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
{
Abc_TtStore_t * p;
+ char * pFileNameOut;
// read info from file
p = Abc_TtStoreLoad( pFileName );
@@ -209,6 +221,12 @@ void Abc_TruthNpnTest( char * pFileName, int NpnType, int fVerbose )
// consider functions from the file
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 );
+
// delete data-structure
Abc_TtStoreFree( p );
// printf( "Finished computing canonical forms for functions from file \"%s\".\n", pFileName );
@@ -230,9 +248,7 @@ int Abc_NpnTest( char * pFileName, int NpnType, int fVerbose )
{
if ( fVerbose )
printf( "Using truth tables from file \"%s\"...\n", pFileName );
- if ( NpnType == 0 )
- Abc_TtStoreTest( pFileName );
- else if ( NpnType >= 1 && NpnType <= 4 )
+ if ( NpnType >= 0 && NpnType <= 4 )
Abc_TruthNpnTest( pFileName, NpnType, fVerbose );
else
printf( "Unknown canonical form value (%d).\n", NpnType );