summaryrefslogtreecommitdiffstats
path: root/src/bool
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 /src/bool
parent0d24b4e4cab591e0b39862f5e4abd6f37725469a (diff)
downloadabc-8752613e3ae41ae904efdb77889bc2fe52d872e0.tar.gz
abc-8752613e3ae41ae904efdb77889bc2fe52d872e0.tar.bz2
abc-8752613e3ae41ae904efdb77889bc2fe52d872e0.zip
Experiments with truth tables.
Diffstat (limited to 'src/bool')
-rw-r--r--src/bool/kit/kitGraph.c74
1 files changed, 74 insertions, 0 deletions
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 ///
////////////////////////////////////////////////////////////////////////