mirror of https://github.com/YosysHQ/abc.git
Experiments with truth tables.
This commit is contained in:
parent
0d24b4e4ca
commit
8752613e3a
|
|
@ -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 );
|
||||
|
|
@ -6920,6 +6922,53 @@ usage:
|
|||
return 1;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis []
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
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 []
|
||||
|
|
|
|||
|
|
@ -428,6 +428,36 @@ Abc_TtStore_t * Abc_TtStoreLoad( char * pFileName, int nVarNum )
|
|||
return p;
|
||||
}
|
||||
|
||||
/**Function*************************************************************
|
||||
|
||||
Synopsis [Read truth tables from input file and write them into output file.]
|
||||
|
||||
Description []
|
||||
|
||||
SideEffects []
|
||||
|
||||
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.]
|
||||
|
|
|
|||
|
|
@ -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 ///
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
|
|
|||
Loading…
Reference in New Issue