From 8752613e3ae41ae904efdb77889bc2fe52d872e0 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 19 Nov 2019 19:30:31 +0800 Subject: Experiments with truth tables. --- src/bool/kit/kitGraph.c | 74 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) (limited to 'src/bool/kit/kitGraph.c') 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 /// //////////////////////////////////////////////////////////////////////// -- cgit v1.2.3