summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2019-11-19 19:30:31 +0800
committerAlan Mishchenko <alanmi@berkeley.edu>2019-11-19 19:30:31 +0800
commit8752613e3ae41ae904efdb77889bc2fe52d872e0 (patch)
treeebd4220b844eee2620fcf7bc6f39e41af20c920a
parent0d24b4e4cab591e0b39862f5e4abd6f37725469a (diff)
downloadabc-8752613e3ae41ae904efdb77889bc2fe52d872e0.tar.gz
abc-8752613e3ae41ae904efdb77889bc2fe52d872e0.tar.bz2
abc-8752613e3ae41ae904efdb77889bc2fe52d872e0.zip
Experiments with truth tables.
-rw-r--r--src/base/abci/abc.c49
-rw-r--r--src/base/abci/abcDec.c30
-rw-r--r--src/bool/kit/kitGraph.c74
3 files changed, 153 insertions, 0 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index 11e847ce..1bae5e24 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -135,6 +135,7 @@ static int Abc_CommandMerge ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandTestDec ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTestNpn ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTestRPO ( Abc_Frame_t * pAbc, int argc, char ** argv );
+static int Abc_CommandTestTruth ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandRunEco ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandRunGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandRunSim ( Abc_Frame_t * pAbc, int argc, char ** argv );
@@ -838,6 +839,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Synthesis", "testdec", Abc_CommandTestDec, 0 );
Cmd_CommandAdd( pAbc, "Synthesis", "testnpn", Abc_CommandTestNpn, 0 );
Cmd_CommandAdd( pAbc, "LogiCS", "testrpo", Abc_CommandTestRPO, 0 );
+ Cmd_CommandAdd( pAbc, "Synthesis", "testtruth", Abc_CommandTestTruth, 0 );
Cmd_CommandAdd( pAbc, "Synthesis", "runeco", Abc_CommandRunEco, 0 );
Cmd_CommandAdd( pAbc, "Synthesis", "rungen", Abc_CommandRunGen, 0 );
Cmd_CommandAdd( pAbc, "Synthesis", "runsim", Abc_CommandRunSim, 0 );
@@ -6931,6 +6933,53 @@ usage:
SeeAlso []
***********************************************************************/
+int Abc_CommandTestTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
+{
+ extern int * Kit_TruthTest( char * pFileName );
+ int * pResult = NULL;
+ int c, fVerbose = 0;
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'v':
+ fVerbose ^= 1;
+ break;
+ case 'h':
+ goto usage;
+ default:
+ goto usage;
+ }
+ }
+ if ( argc != globalUtilOptind + 1 )
+ {
+ Abc_Print( 1,"Input file is not given.\n" );
+ return 0;
+ }
+ pResult = Kit_TruthTest( argv[globalUtilOptind] );
+ ABC_FREE( pResult );
+ return 0;
+
+usage:
+ Abc_Print( -2, "usage: testtruth [-vh] <file>\n" );
+ Abc_Print( -2, "\t printing truth table stats\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");
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int Abc_CommandRunEco( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Acb_NtkRunEco( char * pFileNames[4], int fCheck, int fVerbose );
diff --git a/src/base/abci/abcDec.c b/src/base/abci/abcDec.c
index 8bb04f16..dee773ab 100644
--- a/src/base/abci/abcDec.c
+++ b/src/base/abci/abcDec.c
@@ -439,6 +439,36 @@ Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName, int nVarNum )
SeeAlso []
***********************************************************************/
+void Abc_TtStoreLoadSave( char * pFileName )
+{
+ Abc_TtStore_t * p;
+ char * pFileInput = pFileName;
+ char * pFileOutput = Extra_FileNameGenericAppend(pFileName, "_binary.data");
+
+ // read info from file
+ p = Abc_TtStoreLoad( pFileInput, -1 );
+ if ( p == NULL )
+ return;
+
+ // write into another file
+ Abc_TtStoreWrite( pFileOutput, p, 1 );
+
+ // delete data-structure
+ Abc_TtStoreFree( p, -1 );
+ printf( "Input file \"%s\" was copied into output file \"%s\".\n", pFileInput, pFileOutput );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Read truth tables from input file and write them into output file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
void Abc_TtStoreTest( char * pFileName )
{
Abc_TtStore_t * p;
diff --git a/src/bool/kit/kitGraph.c b/src/bool/kit/kitGraph.c
index e4eea885..08dabc7e 100644
--- a/src/bool/kit/kitGraph.c
+++ b/src/bool/kit/kitGraph.c
@@ -394,6 +394,80 @@ int Kit_GraphLeafDepth_rec( Kit_Graph_t * pGraph, Kit_Node_t * pNode, Kit_Node_t
return Depth;
}
+/**Function*************************************************************
+
+ Synopsis [Derives logic level of the node.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Kit_GraphLevelNum_rec( Kit_Graph_t * pGraph, Kit_Node_t * pNode )
+{
+ int Depth0, Depth1;
+ if ( Kit_GraphNodeIsVar(pGraph, pNode) )
+ return 0;
+ Depth0 = Kit_GraphLevelNum_rec( pGraph, Kit_GraphNodeFanin0(pGraph, pNode) );
+ Depth1 = Kit_GraphLevelNum_rec( pGraph, Kit_GraphNodeFanin1(pGraph, pNode) );
+ return 1 + KIT_MAX( Depth0, Depth1 );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Returns FF nodes and levels.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+int Kit_TruthStats( unsigned * pTruth, int nVars, Vec_Int_t * vMemory )
+{
+ Kit_Graph_t * pGraph = Kit_TruthToGraph( pTruth, nVars, vMemory );
+ int nNodes = Kit_GraphNodeNum( pGraph );
+ int nLevels = Kit_GraphLevelNum_rec( pGraph, Kit_GraphNodeLast(pGraph) );
+ Kit_GraphFree( pGraph );
+ return (nLevels << 16) | nNodes;
+}
+int * Kit_TruthStatsArray( unsigned * pArray, int nVars, int nFuncs )
+{
+ int f, * pRes = ABC_CALLOC( int, nFuncs );
+ int nInts = Abc_TruthWordNum( nVars );
+ Vec_Int_t * vMemory = Vec_IntAlloc( 1 << 16 );
+ for ( f = 0; f < nFuncs; f++ )
+ pRes[f] = Kit_TruthStats( pArray + f*nInts, nVars, vMemory );
+ Vec_IntFree( vMemory );
+ return pRes;
+}
+int Kit_TruthFindVarNum( char * pFileName )
+{
+ int i;
+ for ( i = 0; i < (int)strlen(pFileName); i++ )
+ if ( pFileName[i] >= '0' && pFileName[i] <= '9' )
+ return atoi(pFileName+i);
+ return -1;
+}
+int * Kit_TruthTest( char * pFileName )
+{
+ abctime clk = Abc_Clock(); int i;
+ int nFileSize = Extra_FileSize( pFileName );
+ int nVars = Kit_TruthFindVarNum( pFileName );
+ int nFuncs = nFileSize / 4 / Abc_TruthWordNum(nVars);
+ unsigned * pA = (unsigned *)Extra_FileReadContents( pFileName );
+ int * pResult = Kit_TruthStatsArray( pA, nVars, nFuncs );
+ printf( "Finished proceessing %d functions with %d variables. ", nFuncs, nVars );
+ Abc_PrintTime( 1, "Time", Abc_Clock() - clk );
+ ABC_FREE( pA );
+ for ( i = 0; i < 5; i++ )
+ printf( "Function %3d : AND2 = %3d Lev = %3d\n", i, pResult[i] & 0xFFFF, pResult[i] >> 16 );
+ return pResult;
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////