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/abci/abcGen.c | |
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/abci/abcGen.c')
-rw-r--r-- | src/base/abci/abcGen.c | 84 |
1 files changed, 84 insertions, 0 deletions
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 /// //////////////////////////////////////////////////////////////////////// |