diff options
| author | Alan Mishchenko <alanmi@berkeley.edu> | 2012-03-06 11:53:07 +0100 | 
|---|---|---|
| committer | Alan Mishchenko <alanmi@berkeley.edu> | 2012-03-06 11:53:07 +0100 | 
| commit | f7c7cb5c657058a60d7f7f92b68877c0e14ffb51 (patch) | |
| tree | 3edb99a1a54612cd7184d51c85f67f95f563e262 /src | |
| parent | 5ad0fea6060e84269bdd37526d97d0d70f5e70c5 (diff) | |
| download | abc-f7c7cb5c657058a60d7f7f92b68877c0e14ffb51.tar.gz abc-f7c7cb5c657058a60d7f7f92b68877c0e14ffb51.tar.bz2 abc-f7c7cb5c657058a60d7f7f92b68877c0e14ffb51.zip | |
Adding switch '-n' to 'permute' to derive random topological ordering of internal nodes.
Diffstat (limited to 'src')
| -rw-r--r-- | src/base/abci/abc.c | 23 | ||||
| -rw-r--r-- | src/base/abci/abcStrash.c | 74 | 
2 files changed, 93 insertions, 4 deletions
| diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index c4d5df4c..079d1336 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -16962,12 +16962,15 @@ usage:  ***********************************************************************/  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;      int fInputs = 1;      int fOutputs = 1; -    int c, fFlops = 1; +    int fFlops = 1; +    int fNodes = 1; +    int c;      Extra_UtilGetoptReset(); -    while ( ( c = Extra_UtilGetopt( argc, argv, "iofh" ) ) != EOF ) +    while ( ( c = Extra_UtilGetopt( argc, argv, "iofnh" ) ) != EOF )      {          switch ( c )          { @@ -16980,6 +16983,9 @@ int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )          case 'f':              fFlops ^= 1;              break; +        case 'n': +            fNodes ^= 1; +            break;          case 'h':              goto usage;          default: @@ -16992,7 +16998,15 @@ int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )          Abc_Print( -1, "Empty network.\n" );          return 1;      } -    pNtkRes = Abc_NtkDup( pNtk ); +    if ( fNodes && !Abc_NtkIsStrash(pNtk) ) +    { +        Abc_Print( -1, "To permute nodes, the network should be structurally hashed.\n" ); +        return 1; +    } +    if ( fNodes ) +        pNtkRes = Abc_NtkRestrashRandom( pNtk ); +    else +        pNtkRes = Abc_NtkDup( pNtk );      if ( pNtkRes == NULL )      {          Abc_Print( -1, "Command \"permute\" has failed.\n" ); @@ -17003,11 +17017,12 @@ int Abc_CommandPermute( Abc_Frame_t * pAbc, int argc, char ** argv )      return 0;  usage: -    Abc_Print( -2, "usage: permute [-iofh]\n" ); +    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");      return 1;  } diff --git a/src/base/abci/abcStrash.c b/src/base/abci/abcStrash.c index 996c9db0..835cf925 100644 --- a/src/base/abci/abcStrash.c +++ b/src/base/abci/abcStrash.c @@ -89,6 +89,80 @@ Abc_Ntk_t * Abc_NtkRestrash( Abc_Ntk_t * pNtk, int fCleanup )  /**Function************************************************************* +  Synopsis    [Performs structural hashing by generating random number.] + +  Description [] +                +  SideEffects [] + +  SeeAlso     [] + +***********************************************************************/ +void Abc_NtkRestrashRandom_rec( Abc_Ntk_t * pNtk, Abc_Obj_t * pObj ) +{ +    if ( Abc_NodeIsTravIdCurrent( pObj ) ) +        return; +    Abc_NodeSetTravIdCurrent( pObj ); +    if ( !Abc_ObjIsNode(pObj) ) +        return; +    if ( rand() & 1 ) +    { +        Abc_NtkRestrashRandom_rec( pNtk, Abc_ObjFanin0(pObj) ); +        Abc_NtkRestrashRandom_rec( pNtk, Abc_ObjFanin1(pObj) ); +    } +    else +    { +        Abc_NtkRestrashRandom_rec( pNtk, Abc_ObjFanin1(pObj) ); +        Abc_NtkRestrashRandom_rec( pNtk, Abc_ObjFanin0(pObj) ); +    } +    pObj->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtk->pManFunc, Abc_ObjChild0Copy(pObj), Abc_ObjChild1Copy(pObj) ); +} + +/**Function************************************************************* + +  Synopsis    [Reapplies structural hashing to the AIG.] + +  Description [Because of the structural hashing, this procedure should not  +  change the number of nodes. It is useful to detect the bugs in the original AIG.] +                +  SideEffects [] + +  SeeAlso     [] + +***********************************************************************/ +Abc_Ntk_t * Abc_NtkRestrashRandom( Abc_Ntk_t * pNtk ) +{ +    Abc_Ntk_t * pNtkAig; +    Abc_Obj_t * pObj; +    int i; +    assert( Abc_NtkIsStrash(pNtk) ); +    // print warning about choice nodes +    if ( Abc_NtkGetChoiceNum( pNtk ) ) +        printf( "Warning: The choice nodes in the original AIG are removed by strashing.\n" ); +    // start the new network (constants and CIs of the old network will point to the their counterparts in the new network) +    pNtkAig = Abc_NtkStartFrom( pNtk, ABC_NTK_STRASH, ABC_FUNC_AIG ); +    // restrash the nodes (assuming a topological order of the old network) +    Abc_NtkIncrementTravId( pNtk ); +    Abc_NtkForEachCo( pNtk, pObj, i ) +        Abc_NtkRestrashRandom_rec( pNtkAig, Abc_ObjFanin0(pObj) ); +    // finalize the network +    Abc_NtkFinalize( pNtk, pNtkAig ); +    // duplicate EXDC  +    if ( pNtk->pExdc ) +        pNtkAig->pExdc = Abc_NtkDup( pNtk->pExdc ); +    // make sure everything is okay +    if ( !Abc_NtkCheck( pNtkAig ) ) +    { +        printf( "Abc_NtkStrash: The network check has failed.\n" ); +        Abc_NtkDelete( pNtkAig ); +        return NULL; +    } +    return pNtkAig; + +} + +/**Function************************************************************* +    Synopsis    [Reapplies structural hashing to the AIG.]    Description [Because of the structural hashing, this procedure should not  | 
