summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlan Mishchenko <alanmi@berkeley.edu>2020-07-11 10:14:43 -0700
committerAlan Mishchenko <alanmi@berkeley.edu>2020-07-11 10:14:43 -0700
commit2ba092e4cc73ec8d6001cdc1a1784a799be745af (patch)
treef18d0fcd892c60e2a740627d3944bfd89c822dd9
parent0b734d10e0ecf498865f5ff5f900c0a3bb5ece32 (diff)
downloadabc-2ba092e4cc73ec8d6001cdc1a1784a799be745af.tar.gz
abc-2ba092e4cc73ec8d6001cdc1a1784a799be745af.tar.bz2
abc-2ba092e4cc73ec8d6001cdc1a1784a799be745af.zip
Fixing commands 'putontop' and 'topmost'; adding command 'bottommost'.
-rw-r--r--src/base/abci/abc.c99
-rw-r--r--src/base/abci/abcStrash.c88
2 files changed, 171 insertions, 16 deletions
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index d9498510..ead8228a 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -193,6 +193,7 @@ static int Abc_CommandCone ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandNode ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandCof ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTopmost ( Abc_Frame_t * pAbc, int argc, char ** argv );
+static int Abc_CommandBottommost ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTopAnd ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTrim ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandShortNames ( Abc_Frame_t * pAbc, int argc, char ** argv );
@@ -915,6 +916,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Various", "node", Abc_CommandNode, 1 );
Cmd_CommandAdd( pAbc, "Various", "cof", Abc_CommandCof, 1 );
Cmd_CommandAdd( pAbc, "Various", "topmost", Abc_CommandTopmost, 1 );
+ Cmd_CommandAdd( pAbc, "Various", "bottommost", Abc_CommandBottommost, 1 );
Cmd_CommandAdd( pAbc, "Various", "topand", Abc_CommandTopAnd, 1 );
Cmd_CommandAdd( pAbc, "Various", "trim", Abc_CommandTrim, 1 );
Cmd_CommandAdd( pAbc, "Various", "short_names", Abc_CommandShortNames, 0 );
@@ -10423,7 +10425,15 @@ int Abc_CommandPutOnTop( Abc_Frame_t * pAbc, int argc, char ** argv )
}
// get the new network
- pNtkRes = Abc_NtkPutOnTop( pNtk, pNtk2 );
+ if ( Abc_NtkIsLogic(pNtk2) )
+ pNtkRes = Abc_NtkPutOnTop( pNtk, pNtk2 );
+ else if ( Abc_NtkIsStrash(pNtk2) )
+ {
+ Abc_Ntk_t * pLogic = Abc_NtkToLogic( pNtk2 );
+ pNtkRes = Abc_NtkPutOnTop( pNtk, pLogic );
+ Abc_NtkDelete( pLogic );
+ }
+ else assert( 0 );
Abc_NtkDelete( pNtk2 );
// replace the current network
Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
@@ -11903,12 +11913,7 @@ int Abc_CommandTopmost( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( Abc_NtkLatchNum(pNtk) > 0 )
{
- Abc_Print( -1, "Currently can only works for combinational circuits.\n" );
- return 0;
- }
- if ( Abc_NtkPoNum(pNtk) != 1 )
- {
- Abc_Print( -1, "Currently expects a single-output miter.\n" );
+ Abc_Print( -1, "Currently only works for combinational circuits.\n" );
return 0;
}
@@ -11942,6 +11947,86 @@ usage:
SeeAlso []
***********************************************************************/
+int Abc_CommandBottommost( Abc_Frame_t * pAbc, int argc, char ** argv )
+{
+ Abc_Ntk_t * pNtk, * pNtkRes;
+ int c, nLevels;
+ extern Abc_Ntk_t * Abc_NtkBottommost( Abc_Ntk_t * pNtk, int nLevels );
+
+ pNtk = Abc_FrameReadNtk(pAbc);
+ // set defaults
+ nLevels = 10;
+ Extra_UtilGetoptReset();
+ while ( ( c = Extra_UtilGetopt( argc, argv, "Nh" ) ) != EOF )
+ {
+ switch ( c )
+ {
+ case 'N':
+ if ( globalUtilOptind >= argc )
+ {
+ Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
+ goto usage;
+ }
+ nLevels = atoi(argv[globalUtilOptind]);
+ globalUtilOptind++;
+ if ( nLevels < 0 )
+ goto usage;
+ break;
+ case 'h':
+ goto usage;
+ default:
+ goto usage;
+ }
+ }
+
+ if ( pNtk == NULL )
+ {
+ Abc_Print( -1, "Empty network.\n" );
+ return 1;
+ }
+
+ if ( !Abc_NtkIsStrash(pNtk) )
+ {
+ Abc_Print( -1, "Currently only works for structurally hashed circuits.\n" );
+ return 0;
+ }
+
+ if ( Abc_NtkLatchNum(pNtk) > 0 )
+ {
+ Abc_Print( -1, "Currently only works for combinational circuits.\n" );
+ return 0;
+ }
+
+ pNtkRes = Abc_NtkBottommost( pNtk, nLevels );
+ if ( pNtkRes == NULL )
+ {
+ Abc_Print( -1, "The command has failed.\n" );
+ return 1;
+ }
+ // replace the current network
+ Abc_FrameReplaceCurrentNetwork( pAbc, pNtkRes );
+ return 0;
+
+usage:
+ Abc_Print( -2, "usage: bottommost [-N num] [-h]\n" );
+ Abc_Print( -2, "\t replaces the current network by several of its bottommost levels\n" );
+ Abc_Print( -2, "\t-N num : max number of levels [default = %d]\n", nLevels );
+ Abc_Print( -2, "\t-h : print the command usage\n");
+ Abc_Print( -2, "\tname : the node name\n");
+ return 1;
+}
+
+/**Function*************************************************************
+
+ Synopsis []
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
int Abc_CommandTopAnd( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk, * pNtkRes;
diff --git a/src/base/abci/abcStrash.c b/src/base/abci/abcStrash.c
index e4868d7e..050f3647 100644
--- a/src/base/abci/abcStrash.c
+++ b/src/base/abci/abcStrash.c
@@ -548,25 +548,27 @@ Abc_Obj_t * Abc_NtkTopmost_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNode, int Leve
Abc_Ntk_t * Abc_NtkTopmost( Abc_Ntk_t * pNtk, int nLevels )
{
Abc_Ntk_t * pNtkNew;
- Abc_Obj_t * pObjNew, * pObjPo;
- int LevelCut;
+ Abc_Obj_t * pObjNew, * pObj;
+ int LevelCut, i;
assert( Abc_NtkIsStrash(pNtk) );
- assert( Abc_NtkCoNum(pNtk) == 1 );
// get the cutoff level
LevelCut = Abc_MaxInt( 0, Abc_AigLevel(pNtk) - nLevels );
// start the network
pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
- Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
// create PIs below the cut and nodes above the cut
Abc_NtkCleanCopy( pNtk );
- pObjNew = Abc_NtkTopmost_rec( pNtkNew, Abc_ObjFanin0(Abc_NtkPo(pNtk, 0)), LevelCut );
- pObjNew = Abc_ObjNotCond( pObjNew, Abc_ObjFaninC0(Abc_NtkPo(pNtk, 0)) );
+ Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
+ Abc_NtkForEachCo( pNtk, pObj, i )
+ {
+ pObjNew = Abc_NtkTopmost_rec( pNtkNew, Abc_ObjFanin0(pObj), LevelCut );
+ pObjNew = Abc_ObjNotCond( pObjNew, Abc_ObjFaninC0(pObj) );
+ Abc_ObjAddFanin( (pObj->pCopy = Abc_NtkCreatePo(pNtkNew)), pObjNew );
+ }
// add the PO node and name
- pObjPo = Abc_NtkCreatePo(pNtkNew);
- Abc_ObjAddFanin( pObjPo, pObjNew );
Abc_NtkAddDummyPiNames( pNtkNew );
- Abc_ObjAssignName( pObjPo, Abc_ObjName(Abc_NtkPo(pNtk, 0)), NULL );
+ Abc_NtkForEachCo( pNtk, pObj, i )
+ Abc_ObjAssignName( pObj->pCopy, Abc_ObjName(pObj), NULL );
// make sure everything is okay
if ( !Abc_NtkCheck( pNtkNew ) )
{
@@ -578,6 +580,74 @@ Abc_Ntk_t * Abc_NtkTopmost( Abc_Ntk_t * pNtk, int nLevels )
}
+/**Function*************************************************************
+
+ Synopsis [Copies the bottommost levels of the network.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Obj_t * Abc_NtkBottommost_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNode, int LevelCut )
+{
+ assert( !Abc_ObjIsComplement(pNode) );
+ if ( pNode->pCopy )
+ return pNode->pCopy;
+ Abc_NtkBottommost_rec( pNtkNew, Abc_ObjFanin0(pNode), LevelCut );
+ Abc_NtkBottommost_rec( pNtkNew, Abc_ObjFanin1(pNode), LevelCut );
+ if ( pNode->Level > (unsigned)LevelCut )
+ return NULL;
+ return pNode->pCopy = Abc_AigAnd( (Abc_Aig_t *)pNtkNew->pManFunc, Abc_ObjChild0Copy(pNode), Abc_ObjChild1Copy(pNode) );
+}
+
+/**Function*************************************************************
+
+ Synopsis [Copies the topmost levels of the network.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Abc_Ntk_t * Abc_NtkBottommost( Abc_Ntk_t * pNtk, int nLevels )
+{
+ Abc_Ntk_t * pNtkNew;
+ Abc_Obj_t * pObj, * pObjNew;
+ int i;
+ assert( Abc_NtkIsStrash(pNtk) );
+ assert( nLevels >= 0 );
+ // start the network
+ pNtkNew = Abc_NtkAlloc( ABC_NTK_STRASH, ABC_FUNC_AIG, 1 );
+ pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
+ // create PIs below the cut and nodes above the cut
+ Abc_NtkCleanCopy( pNtk );
+ Abc_AigConst1(pNtk)->pCopy = Abc_AigConst1(pNtkNew);
+ Abc_NtkForEachCi( pNtk, pObj, i )
+ pObj->pCopy = Abc_NtkCreatePi( pNtkNew );
+ Abc_NtkForEachCo( pNtk, pObj, i )
+ Abc_NtkBottommost_rec( pNtkNew, Abc_ObjFanin0(pObj), nLevels );
+ // add POs to nodes without fanout
+ Abc_NtkForEachNode( pNtkNew, pObjNew, i )
+ if ( Abc_ObjFanoutNum(pObjNew) == 0 )
+ Abc_ObjAddFanin( Abc_NtkCreatePo(pNtkNew), pObjNew );
+ Abc_NtkAddDummyPiNames( pNtkNew );
+ Abc_NtkAddDummyPoNames( pNtkNew );
+ // make sure everything is okay
+ if ( !Abc_NtkCheck( pNtkNew ) )
+ {
+ printf( "Abc_NtkBottommost: The network check has failed.\n" );
+ Abc_NtkDelete( pNtkNew );
+ return NULL;
+ }
+ return pNtkNew;
+}
+
+
/**Function*************************************************************