summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2013-06-22 14:03:23 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2013-06-22 14:03:23 -0700
commitfaa220401c849b10b40dd815837e489d4b0a7daf (patch)
tree0506852bd84805fba2cee5a4a244f5b1de01e15e
parent7ea3cdffb4afea2d632cb6255f303c25363110e1 (diff)
downloadabc-faa220401c849b10b40dd815837e489d4b0a7daf.tar.gz
abc-faa220401c849b10b40dd815837e489d4b0a7daf.tar.bz2
abc-faa220401c849b10b40dd815837e489d4b0a7daf.zip
New random FSM generation command 'genfsm'.
-rw-r--r--src/aig/gia/giaStg.c24
-rw-r--r--src/base/abci/abc.c136
-rw-r--r--src/base/abci/abcGen.c84
3 files changed, 235 insertions, 9 deletions
diff --git a/src/aig/gia/giaStg.c b/src/aig/gia/giaStg.c
index 74eb01ed..9588d51c 100644
--- a/src/aig/gia/giaStg.c
+++ b/src/aig/gia/giaStg.c
@@ -214,7 +214,7 @@ Vec_Vec_t * Gia_ManAssignCodes( int kHot, int nStates, int * pnBits )
***********************************************************************/
Gia_Man_t * Gia_ManStgKHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates, int kHot, int fVerbose )
{
- Gia_Man_t * p;
+ Gia_Man_t * p, * pTemp;
Vec_Int_t * vInMints, * vCurs, * vVec;
Vec_Vec_t * vLitsNext, * vLitsOuts, * vCodes;
int i, b, k, nBits, LitC, Lit;
@@ -261,8 +261,8 @@ Gia_Man_t * Gia_ManStgKHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates
for ( i = 0; i < Vec_IntSize(vLines); )
{
int iMint = Vec_IntEntry(vLines, i++);
- int iCur = Vec_IntEntry(vLines, i++) - 1;
- int iNext = Vec_IntEntry(vLines, i++) - 1;
+ int iCur = Vec_IntEntry(vLines, i++);
+ int iNext = Vec_IntEntry(vLines, i++);
int iOut = Vec_IntEntry(vLines, i++);
assert( iMint >= 0 && iMint < (1<<nIns) );
assert( iCur >= 0 && iCur < nStates );
@@ -297,6 +297,8 @@ Gia_Man_t * Gia_ManStgKHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates
Gia_ManSetRegNum( p, nBits );
Gia_ManHashStop( p );
+ p = Gia_ManCleanup( pTemp = p );
+ Gia_ManStop( pTemp );
assert( !Gia_ManHasDangling(p) );
return p;
}
@@ -314,7 +316,7 @@ Gia_Man_t * Gia_ManStgKHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates
***********************************************************************/
Gia_Man_t * Gia_ManStgOneHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStates )
{
- Gia_Man_t * p;
+ Gia_Man_t * p, * pTemp;
Vec_Int_t * vInMints, * vCurs, * vVec;
Vec_Vec_t * vLitsNext, * vLitsOuts;
int i, b, LitC, Lit;
@@ -385,6 +387,8 @@ Gia_Man_t * Gia_ManStgOneHot( Vec_Int_t * vLines, int nIns, int nOuts, int nStat
Gia_ManSetRegNum( p, nStates );
Gia_ManHashStop( p );
+ p = Gia_ManCleanup( pTemp = p );
+ Gia_ManStop( pTemp );
assert( !Gia_ManHasDangling(p) );
return p;
}
@@ -454,8 +458,10 @@ Vec_Int_t * Gia_ManStgReadLines( char * pFileName, int * pnIns, int * pnOuts, in
vLines = Vec_IntAlloc( 1000 );
while ( fgets( pBuffer, 1000, pFile ) != NULL )
{
+ if ( pBuffer[0] == '.' || pBuffer[0] == '#' )
+ continue;
// read condition
- pToken = strtok( pBuffer, " \n" );
+ pToken = strtok( pBuffer, " \r\n" );
if ( nInputs == -1 )
nInputs = strlen(pToken);
else
@@ -463,14 +469,14 @@ Vec_Int_t * Gia_ManStgReadLines( char * pFileName, int * pnIns, int * pnOuts, in
Number = Extra_ReadBinary( pToken );
Vec_IntPush( vLines, Number );
// read current state
- pToken = strtok( NULL, " \n" );
+ pToken = strtok( NULL, " \r\n" );
Vec_IntPush( vLines, atoi(pToken) );
- nStates = Abc_MaxInt( nStates, Vec_IntEntryLast(vLines) );
+ nStates = Abc_MaxInt( nStates, Vec_IntEntryLast(vLines)+1 );
// read next state
- pToken = strtok( NULL, " \n" );
+ pToken = strtok( NULL, " \r\n" );
Vec_IntPush( vLines, atoi(pToken) );
// read output
- pToken = strtok( NULL, " \n" );
+ pToken = strtok( NULL, " \r\n" );
if ( nOutputs == -1 )
nOutputs = strlen(pToken);
else
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 ///
////////////////////////////////////////////////////////////////////////