From 3459683e3b5ee9bb3f155fff3bf1041c840266c4 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Fri, 16 Aug 2013 13:13:38 -0700 Subject: Extending 'permute' to handle user-specified flop permutation. --- src/aig/saig/saigIso.c | 2 +- src/base/abc/abc.h | 2 +- src/base/abc/abcNtk.c | 61 ++++++++++++++++++++++++++++++++++++++++++++++++-- src/base/abci/abc.c | 31 ++++++++++++++++--------- src/map/mpm/mpmPre.c | 4 ++-- 5 files changed, 84 insertions(+), 16 deletions(-) (limited to 'src') diff --git a/src/aig/saig/saigIso.c b/src/aig/saig/saigIso.c index 1f931eae..40500361 100644 --- a/src/aig/saig/saigIso.c +++ b/src/aig/saig/saigIso.c @@ -600,7 +600,7 @@ Aig_Man_t * Iso_ManTest888( Aig_Man_t * pAig1, int fVerbose ) Vec_Int_t * vMap; pNtk = Abc_NtkFromAigPhase( pAig1 ); - Abc_NtkPermute( pNtk, 1, 0, 1 ); + Abc_NtkPermute( pNtk, 1, 0, 1, NULL ); pAig2 = Abc_NtkToDar( pNtk, 0, 1 ); Abc_NtkDelete( pNtk ); 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 : (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 ) { diff --git a/src/map/mpm/mpmPre.c b/src/map/mpm/mpmPre.c index f3a4bb08..a1462342 100644 --- a/src/map/mpm/mpmPre.c +++ b/src/map/mpm/mpmPre.c @@ -894,7 +894,7 @@ void Ifd_ComputeSignature( word uTruth, int pCounts[6] ) } Vec_IntSelectSort( pCounts, 6 ); } -int Ifd_ManDsdTest() +int Ifd_ManDsdTest33() { int nVars = 6; Vec_Wrd_t * vTruths = Ifd_ManDsdTruths( nVars ); @@ -926,7 +926,7 @@ int Ifd_ManDsdTest() SeeAlso [] ***********************************************************************/ -int Ifd_ManDsdTest33() +int Ifd_ManDsdTest() { int nVars = 6; FILE * pFile; -- cgit v1.2.3