summaryrefslogtreecommitdiffstats
path: root/src/base
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2013-08-16 13:13:38 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2013-08-16 13:13:38 -0700
commit3459683e3b5ee9bb3f155fff3bf1041c840266c4 (patch)
tree67500383a384eaea0120d138eac28e69b0b6646e /src/base
parent7013e0b672a881a979ef05f504ba3b2fb3dfdaf4 (diff)
downloadabc-3459683e3b5ee9bb3f155fff3bf1041c840266c4.tar.gz
abc-3459683e3b5ee9bb3f155fff3bf1041c840266c4.tar.bz2
abc-3459683e3b5ee9bb3f155fff3bf1041c840266c4.zip
Extending 'permute' to handle user-specified flop permutation.
Diffstat (limited to 'src/base')
-rw-r--r--src/base/abc/abc.h2
-rw-r--r--src/base/abc/abcNtk.c61
-rw-r--r--src/base/abci/abc.c31
3 files changed, 81 insertions, 13 deletions
diff --git a/src/base/abc/abc.h b/src/base/abc/abc.h
index b0bae148..bb6bc3cb 100644
--- a/src/base/abc/abc.h
+++ b/src/base/abc/abc.h
@@ -737,7 +737,7 @@ extern ABC_DLL Abc_Ntk_t * Abc_NtkCreateWithNode( char * pSop );
extern ABC_DLL void Abc_NtkDelete( Abc_Ntk_t * pNtk );
extern ABC_DLL void Abc_NtkFixNonDrivenNets( Abc_Ntk_t * pNtk );
extern ABC_DLL void Abc_NtkMakeComb( Abc_Ntk_t * pNtk, int fRemoveLatches );
-extern ABC_DLL void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops );
+extern ABC_DLL void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops, char * pFlopPermFile );
extern ABC_DLL void Abc_NtkUnpermute( Abc_Ntk_t * pNtk );
/*=== abcObj.c ==========================================================*/
extern ABC_DLL Abc_Obj_t * Abc_ObjAlloc( Abc_Ntk_t * pNtk, Abc_ObjType_t Type );
diff --git a/src/base/abc/abcNtk.c b/src/base/abc/abcNtk.c
index 5631902b..e1ec89df 100644
--- a/src/base/abc/abcNtk.c
+++ b/src/base/abc/abcNtk.c
@@ -1878,15 +1878,72 @@ void Abc_NtkRemovePo( Abc_Ntk_t * pNtk, int iOutput, int fRemoveConst0 )
SeeAlso []
***********************************************************************/
-void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops )
+Vec_Int_t * Abc_NtkReadFlopPerm( char * pFileName, int nFlops )
+{
+ char Buffer[1000];
+ FILE * pFile;
+ Vec_Int_t * vFlops;
+ int iFlop;
+ pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ {
+ printf( "Cannot open input file \"%s\".\n", pFileName );
+ return NULL;
+ }
+ vFlops = Vec_IntAlloc( nFlops );
+ while ( fgets( Buffer, 1000, pFile ) != NULL )
+ {
+ if ( Buffer[0] == ' ' || Buffer[0] == '\r' || Buffer[0] == '\n' )
+ continue;
+ iFlop = atoi( Buffer );
+ if ( iFlop < 0 || iFlop >= nFlops )
+ {
+ printf( "Flop ID (%d) is out of range.\n", iFlop );
+ fclose( pFile );
+ Vec_IntFree( vFlops );
+ return NULL;
+ }
+ Vec_IntPush( vFlops, iFlop );
+ }
+ fclose( pFile );
+ if ( Vec_IntSize(vFlops) != nFlops )
+ {
+ printf( "The number of flops read in from file (%d) is different from the number of flops in the circuit (%d).\n", iFlop, nFlops );
+ Vec_IntFree( vFlops );
+ return NULL;
+ }
+ return vFlops;
+}
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Abc_NtkPermute( Abc_Ntk_t * pNtk, int fInputs, int fOutputs, int fFlops, char * pFlopPermFile )
{
Abc_Obj_t * pTemp;
Vec_Int_t * vInputs, * vOutputs, * vFlops, * vTemp;
int i, k, Entry;
// start permutation arrays
+ if ( pFlopPermFile )
+ {
+ vFlops = Abc_NtkReadFlopPerm( pFlopPermFile, Abc_NtkLatchNum(pNtk) );
+ if ( vFlops == NULL )
+ return;
+ fInputs = 0;
+ fOutputs = 0;
+ fFlops = 0;
+ }
+ else
+ vFlops = Vec_IntStartNatural( Abc_NtkLatchNum(pNtk) );
vInputs = Vec_IntStartNatural( Abc_NtkPiNum(pNtk) );
vOutputs = Vec_IntStartNatural( Abc_NtkPoNum(pNtk) );
- vFlops = Vec_IntStartNatural( Abc_NtkLatchNum(pNtk) );
// permute inputs
if ( fInputs )
for ( i = 0; i < Abc_NtkPiNum(pNtk); i++ )
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index e10cd4ff..ba2fa556 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -19404,16 +19404,26 @@ int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern Abc_Ntk_t * Abc_NtkRestrashRandom( Abc_Ntk_t * pNtk );
Abc_Ntk_t * pNtk = pAbc->pNtkCur, * pNtkRes = NULL;
+ char * pFlopPermFile = NULL;
int fInputs = 1;
int fOutputs = 1;
int fFlops = 1;
int fNodes = 1;
int c;
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "iofnh" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "Fiofnh" ) ) != EOF )
{
switch ( c )
{
+ case 'F':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-F\" should be followed by a file name.\n" );
+ goto usage;
+ }
+ pFlopPermFile = argv[globalUtilOptind];
+ globalUtilOptind++;
+ break;
case 'i':
fInputs ^= 1;
break;
@@ -19452,18 +19462,19 @@ int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "Command \"permute\" has failed.\n" );
return 1;
}
- Abc_NtkPermute( pNtkRes, fInputs, fOutputs, fFlops );
+ Abc_NtkPermute( pNtkRes, fInputs, fOutputs, fFlops, pFlopPermFile );
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
return 0;
usage:
- Abc_Print( -2, "usage: permute [-iofnh]\n" );
- Abc_Print( -2, "\t performs random permutation of inputs/outputs/flops\n" );
- Abc_Print( -2, "\t-i : toggle permuting primary inputs [default = %s]\n", fInputs? "yes": "no" );
- Abc_Print( -2, "\t-o : toggle permuting primary outputs [default = %s]\n", fOutputs? "yes": "no" );
- Abc_Print( -2, "\t-f : toggle permuting flip-flops [default = %s]\n", fFlops? "yes": "no" );
- Abc_Print( -2, "\t-n : toggle deriving new topological ordering of nodes [default = %s]\n", fNodes? "yes": "no" );
- Abc_Print( -2, "\t-h : print the command usage\n");
+ Abc_Print( -2, "usage: permute [-iofnh] [-F filename]\n" );
+ Abc_Print( -2, "\t performs random permutation of inputs/outputs/flops\n" );
+ Abc_Print( -2, "\t-i : toggle permuting primary inputs [default = %s]\n", fInputs? "yes": "no" );
+ Abc_Print( -2, "\t-o : toggle permuting primary outputs [default = %s]\n", fOutputs? "yes": "no" );
+ Abc_Print( -2, "\t-f : toggle permuting flip-flops [default = %s]\n", fFlops? "yes": "no" );
+ Abc_Print( -2, "\t-n : toggle deriving new topological ordering of nodes [default = %s]\n", fNodes? "yes": "no" );
+ Abc_Print( -2, "\t-h : print the command usage\n");
+ Abc_Print( -2, "\t-F <filename> : (optional) file with the flop permutation\n" );
return 1;
}
@@ -23227,7 +23238,7 @@ int Abc_CommandBm2( Abc_Frame_t * pAbc, int argc, char ** argv )
return 1;
}
- Abc_NtkPermute(pNtk2, 1, 1, 0 );
+ Abc_NtkPermute(pNtk2, 1, 1, 0, NULL );
Abc_NtkShortNames(pNtk2);
Abc_NtkForEachCi( pNtk1, pObj, i ) {