diff options
author | Alan Mishchenko <alanmi@berkeley.edu> | 2013-06-22 14:03:23 -0700 |
---|---|---|
committer | Alan Mishchenko <alanmi@berkeley.edu> | 2013-06-22 14:03:23 -0700 |
commit | faa220401c849b10b40dd815837e489d4b0a7daf (patch) | |
tree | 0506852bd84805fba2cee5a4a244f5b1de01e15e /src/base | |
parent | 7ea3cdffb4afea2d632cb6255f303c25363110e1 (diff) | |
download | abc-faa220401c849b10b40dd815837e489d4b0a7daf.tar.gz abc-faa220401c849b10b40dd815837e489d4b0a7daf.tar.bz2 abc-faa220401c849b10b40dd815837e489d4b0a7daf.zip |
New random FSM generation command 'genfsm'.
Diffstat (limited to 'src/base')
-rw-r--r-- | src/base/abci/abc.c | 136 | ||||
-rw-r--r-- | src/base/abci/abcGen.c | 84 |
2 files changed, 220 insertions, 0 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 063388f7..3279cf46 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -162,6 +162,7 @@ static int Abc_CommandCareSet ( Abc_Frame_t * pAbc, int argc, cha static int Abc_CommandCut ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandEspresso ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandGen ( Abc_Frame_t * pAbc, int argc, char ** argv ); +static int Abc_CommandGenFsm ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandCover ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandDouble ( Abc_Frame_t * pAbc, int argc, char ** argv ); static int Abc_CommandInter ( Abc_Frame_t * pAbc, int argc, char ** argv ); @@ -713,6 +714,7 @@ void Abc_Init( Abc_Frame_t * pAbc ) Cmd_CommandAdd( pAbc, "Various", "cut", Abc_CommandCut, 0 ); Cmd_CommandAdd( pAbc, "Various", "espresso", Abc_CommandEspresso, 1 ); Cmd_CommandAdd( pAbc, "Various", "gen", Abc_CommandGen, 0 ); + Cmd_CommandAdd( pAbc, "Various", "genfsm", Abc_CommandGenFsm, 0 ); Cmd_CommandAdd( pAbc, "Various", "cover", Abc_CommandCover, 1 ); Cmd_CommandAdd( pAbc, "Various", "double", Abc_CommandDouble, 1 ); Cmd_CommandAdd( pAbc, "Various", "inter", Abc_CommandInter, 1 ); @@ -9416,6 +9418,140 @@ usage: SeeAlso [] ***********************************************************************/ +int Abc_CommandGenFsm( Abc_Frame_t * pAbc, int argc, char ** argv ) +{ + extern void Abc_GenFsm( char * pFileName, int nIns, int nOuts, int nStates, int nLines, int ProbI, int ProbO ); + int c, nIns, nOuts, nStates, nLines, ProbI, ProbO, fVerbose; + char * FileName; + // set defaults + nIns = 30; + nOuts = 1; + nStates = 20; + nLines = 100; + ProbI = 10; + ProbO = 100; + fVerbose = 0; + Extra_UtilGetoptReset(); + while ( ( c = Extra_UtilGetopt( argc, argv, "IOSLPQvh" ) ) != EOF ) + { + switch ( c ) + { + case 'I': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-I\" should be followed by an integer.\n" ); + goto usage; + } + nIns = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( nIns < 0 ) + goto usage; + break; + case 'O': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-O\" should be followed by an integer.\n" ); + goto usage; + } + nOuts = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( nOuts < 0 ) + goto usage; + break; + case 'S': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" ); + goto usage; + } + nStates = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( nStates < 0 ) + goto usage; + break; + case 'L': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-L\" should be followed by an integer.\n" ); + goto usage; + } + nLines = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( nLines < 0 ) + goto usage; + break; + case 'P': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-P\" should be followed by an integer.\n" ); + goto usage; + } + ProbI = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( ProbI < 0 ) + goto usage; + break; + case 'Q': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-Q\" should be followed by an integer.\n" ); + goto usage; + } + ProbO = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( ProbO < 0 ) + goto usage; + break; + case 'v': + fVerbose ^= 1; + break; + case 'h': + goto usage; + default: + goto usage; + } + } + + if ( argc != globalUtilOptind + 1 ) + { + goto usage; + } + if ( nIns < 1 || nStates < 1 || nLines < 1 || ProbI < 1 || ProbO < 1 ) + { + Abc_Print( -1, "The number of inputs. states, lines, and probablity should be positive integers.\n" ); + goto usage; + } + // get the input file name + FileName = argv[globalUtilOptind]; + Abc_GenFsm( FileName, nIns, nOuts, nStates, nLines, ProbI, ProbO ); + return 0; + +usage: + Abc_Print( -2, "usage: genfsm [-IOSLPQ num] [-vh] <file>\n" ); + Abc_Print( -2, "\t generates random FSM in KISS format\n" ); + Abc_Print( -2, "\t-I num : the number of input variables [default = %d]\n", nIns ); + Abc_Print( -2, "\t-O num : the number of output variables [default = %d]\n", nOuts ); + Abc_Print( -2, "\t-S num : the number of state variables [default = %d]\n", nStates ); + Abc_Print( -2, "\t-L num : the number of lines (product terms) [default = %d]\n", nLines ); + Abc_Print( -2, "\t-P num : percentage propability of a variable present in the input cube [default = %d]\n", ProbI ); + Abc_Print( -2, "\t-Q num : percentage propability of a variable present in the output cube [default = %d]\n", ProbO ); + Abc_Print( -2, "\t-v : prints verbose information [default = %s]\n", fVerbose? "yes": "no" ); + Abc_Print( -2, "\t-h : print the command usage\n"); + Abc_Print( -2, "\t<file> : output file name\n"); + return 1; +} + +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ int Abc_CommandCover( Abc_Frame_t * pAbc, int argc, char ** argv ) { Abc_Ntk_t * pNtk, * pNtkRes; diff --git a/src/base/abci/abcGen.c b/src/base/abci/abcGen.c index fb6f8b27..f54dc407 100644 --- a/src/base/abci/abcGen.c +++ b/src/base/abci/abcGen.c @@ -714,6 +714,90 @@ void Abc_GenRandom( char * pFileName, int nPis ) } +/**Function************************************************************* + + Synopsis [Generates structure of L K-LUTs implementing an N-var function.] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_GenFsmCond( Vec_Str_t * vCond, int nPis, int Prob ) +{ + int i, Rand; + Vec_StrClear( vCond ); + for ( i = 0; i < nPis; i++ ) + { + Rand = Aig_ManRandom( 0 ); + if ( Rand % 100 > Prob ) + Vec_StrPush( vCond, '-' ); + else if ( Rand & 1 ) + Vec_StrPush( vCond, '1' ); + else + Vec_StrPush( vCond, '0' ); + } + Vec_StrPush( vCond, '\0' ); +} +void Abc_GenFsm( char * pFileName, int nPis, int nPos, int nStates, int nLines, int ProbI, int ProbO ) +{ + FILE * pFile; + Vec_Wrd_t * vStates; + Vec_Str_t * vCond; + int i, iState, iState2; + int nDigits = Abc_Base10Log( nStates ); + Aig_ManRandom( 1 ); + vStates = Vec_WrdAlloc( nLines ); + vCond = Vec_StrAlloc( 1000 ); + for ( i = 0; i < nStates; ) + { + iState = Aig_ManRandom( 0 ) % nStates; + if ( iState == i ) + continue; + Vec_WrdPush( vStates, ((word)i << 32) | iState ); + i++; + } + for ( ; i < nLines; ) + { + iState = Aig_ManRandom( 0 ) % nStates; + iState2 = Aig_ManRandom( 0 ) % nStates; + if ( iState2 == iState ) + continue; + Vec_WrdPush( vStates, ((word)iState << 32) | iState2 ); + i++; + } + Vec_WrdSort( vStates, 0 ); + // write the file + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# This random FSM was generated by ABC on %s\n", Extra_TimeStamp() ); + fprintf( pFile, "# Command line was: \"genfsm -I %d -O %d -S %d -L %d -P %d -Q %d %s\"\n", nPis, nPos, nStates, nLines, ProbI, ProbO, pFileName ); + fprintf( pFile, "# FSM has %d inputs, %d outputs, %d states, and %d products\n", nPis, nPos, nStates, nLines ); + fprintf( pFile, ".i %d\n", nPis ); + fprintf( pFile, ".o %d\n", nPos ); + fprintf( pFile, ".p %d\n", nLines ); + fprintf( pFile, ".s %d\n", nStates ); + for ( i = 0; i < nLines; i++ ) + { + Abc_GenFsmCond( vCond, nPis, ProbI ); + fprintf( pFile, "%s ", Vec_StrArray(vCond) ); + fprintf( pFile, "%0*d ", nDigits, (int)(Vec_WrdEntry(vStates, i) >> 32) ); + fprintf( pFile, "%0*d ", nDigits, (int)(Vec_WrdEntry(vStates, i)) ); + if ( nPos > 0 ) + { + Abc_GenFsmCond( vCond, nPos, ProbO ); + fprintf( pFile, "%s", Vec_StrArray(vCond) ); + } + fprintf( pFile, "\n" ); + } + fprintf( pFile, ".e" ); + fprintf( pFile, "\n" ); + fclose( pFile ); + Vec_WrdFree( vStates ); + Vec_StrFree( vCond ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// |