From 55ed1e66980610ec43d9b122e438595c0b7018e7 Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Fri, 21 Jul 2023 16:15:34 -0700 Subject: [PATCH] Changing command &permute to generate random NPNP transformations. --- src/aig/gia/giaDup.c | 45 ++++++++++++++++++++++++++++++++++++++++++++ src/base/abci/abc.c | 36 +++++++++++++++++++++++++++-------- 2 files changed, 73 insertions(+), 8 deletions(-) diff --git a/src/aig/gia/giaDup.c b/src/aig/gia/giaDup.c index 35ad6aab9..3822497af 100644 --- a/src/aig/gia/giaDup.c +++ b/src/aig/gia/giaDup.c @@ -1069,6 +1069,51 @@ Gia_Man_t * Gia_ManDupPiPerm( Gia_Man_t * p ) return pNew; } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +Vec_Int_t * Gia_ManCreatePerm( int n ) +{ + Vec_Int_t * vPerm = Vec_IntStartNatural( n ); + int i, * pPerm = Vec_IntArray( vPerm ); + for ( i = 0; i < n; i++ ) + { + int j = Abc_Random(0) % n; + ABC_SWAP( int, pPerm[i], pPerm[j] ); + + } + return vPerm; +} +Gia_Man_t * Gia_ManDupRandPerm( Gia_Man_t * p ) +{ + Vec_Int_t * vPiPerm = Gia_ManCreatePerm( Gia_ManCiNum(p) ); + Vec_Int_t * vPoPerm = Gia_ManCreatePerm( Gia_ManCoNum(p) ); + Gia_Man_t * pNew; + Gia_Obj_t * pObj; + int i; + pNew = Gia_ManStart( Gia_ManObjNum(p) ); + pNew->pName = Abc_UtilStrsav( p->pName ); + pNew->pSpec = Abc_UtilStrsav( p->pSpec ); + Gia_ManConst0(p)->Value = 0; + Gia_ManForEachPi( p, pObj, i ) + Gia_ManPi(p, Vec_IntEntry(vPiPerm,i))->Value = Gia_ManAppendCi(pNew) ^ (Abc_Random(0) & 1); + Gia_ManForEachAnd( p, pObj, i ) + pObj->Value = Gia_ManAppendAnd( pNew, Gia_ObjFanin0Copy(pObj), Gia_ObjFanin1Copy(pObj) ); + Gia_ManForEachPo( p, pObj, i ) + Gia_ManAppendCo( pNew, Gia_ObjFanin0Copy(Gia_ManPo(p, Vec_IntEntry(vPoPerm,i))) ^ (Abc_Random(0) & 1) ); + Vec_IntFree( vPiPerm ); + Vec_IntFree( vPoPerm ); + return pNew; +} + /**Function************************************************************* Synopsis [Appends second AIG without any changes.] diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 4e70d51f3..564cb399b 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -7380,7 +7380,7 @@ int Abc_CommandOrchestrate( Abc_Frame_t * pAbc, int argc, char ** argv ) int fVerbose; //rewrite/rs/rf verbose int fVeryVerbose; //very verbose option for all - size_t NtkSize; + //size_t NtkSize; extern void Rwr_Precompute(); //local greedy @@ -43941,14 +43941,25 @@ usage: ***********************************************************************/ int Abc_CommandAbc9Permute( Abc_Frame_t * pAbc, int argc, char ** argv ) { - extern Gia_Man_t * Gia_ManDupPiPerm( Gia_Man_t * p ); + extern Gia_Man_t * Gia_ManDupRandPerm( Gia_Man_t * p ); Gia_Man_t * pTemp; - int c, fVerbose = 0; + int c, RandSeed = 0, fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "vh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "Svh" ) ) != EOF ) { switch ( c ) { + case 'S': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-S\" should be followed by an integer.\n" ); + goto usage; + } + RandSeed = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + if ( RandSeed < 0 ) + goto usage; + break; case 'v': fVerbose ^= 1; break; @@ -43960,16 +43971,25 @@ int Abc_CommandAbc9Permute( Abc_Frame_t * pAbc, int argc, char ** argv ) } if ( pAbc->pGia == NULL ) { - Abc_Print( -1, "Abc_CommandAbc9Posplit(): There is no AIG.\n" ); + Abc_Print( -1, "Abc_CommandAbc9Permute(): There is no AIG.\n" ); return 1; } - pTemp = Gia_ManDupPiPerm( pAbc->pGia ); + if ( Gia_ManRegNum(pAbc->pGia) > 0 ) + { + Abc_Print( -1, "Abc_CommandAbc9Permute(): This command does not work for sequential AIGs.\n" ); + return 1; + } + Abc_Random(1); + for ( c = 0; c < RandSeed; c++ ) + Abc_Random(0); + pTemp = Gia_ManDupRandPerm( pAbc->pGia ); Abc_FrameUpdateGia( pAbc, pTemp ); return 0; usage: - Abc_Print( -2, "usage: &permute [-vh]\n" ); - Abc_Print( -2, "\t permutes primary inputs\n" ); + Abc_Print( -2, "usage: &permute [-S num] [-vh]\n" ); + Abc_Print( -2, "\t generates a random NPNP transformation of the combinational AIG\n" ); + Abc_Print( -2, "\t-S num : the seed used to randomize the process [default = %d]\n", RandSeed ); Abc_Print( -2, "\t-v : toggle printing verbose information [default = %s]\n", fVerbose? "yes": "no" ); Abc_Print( -2, "\t-h : print the command usage\n"); return 1;