Commit 455ecb6a by Alan Mishchenko

Adding barrier buffers.

parent 2a219cf1
...@@ -27,6 +27,8 @@ ABC_NAMESPACE_IMPL_START ...@@ -27,6 +27,8 @@ ABC_NAMESPACE_IMPL_START
/// DECLARATIONS /// /// DECLARATIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
#define ABC_OBJ_VOID ((Abc_Obj_t *)(ABC_PTRINT_T)1)
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
/// FUNCTION DEFINITIONS /// /// FUNCTION DEFINITIONS ///
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
...@@ -87,22 +89,27 @@ int Abc_NtkCheckSingleInstance( Abc_Ntk_t * pNtk ) ...@@ -87,22 +89,27 @@ int Abc_NtkCheckSingleInstance( Abc_Ntk_t * pNtk )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Abc_NtkCollectPiPos_rec( Abc_Obj_t * pNet, Vec_Ptr_t * vPiPos ) void Abc_NtkCollectPiPos_rec( Abc_Obj_t * pNet, Vec_Ptr_t * vBiBos, Vec_Ptr_t * vPiPos )
{ {
extern void Abc_NtkCollectPiPos_int( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPiPos, int fAdd ); extern void Abc_NtkCollectPiPos_int( Abc_Obj_t * pBox, Abc_Ntk_t * pNtk, Vec_Ptr_t * vBiBos, Vec_Ptr_t * vPiPos );
Abc_Obj_t * pObj, * pFanin; int i; Abc_Obj_t * pObj, * pFanin; int i;
assert( Abc_ObjIsNet(pNet) ); assert( Abc_ObjIsNet(pNet) );
if ( Abc_NodeIsTravIdCurrent( pNet ) ) if ( Abc_NodeIsTravIdCurrent( pNet ) )
return; return;
Abc_NodeSetTravIdCurrent( pNet ); Abc_NodeSetTravIdCurrent( pNet );
pObj = Abc_ObjFanin0(pNet); pObj = Abc_ObjFanin0(pNet);
if ( Abc_ObjIsBo(pObj) )
pObj = Abc_ObjFanin0(pObj);
assert( Abc_ObjIsNode(pObj) || Abc_ObjIsBox(pObj) ); assert( Abc_ObjIsNode(pObj) || Abc_ObjIsBox(pObj) );
Abc_ObjForEachFanin( pObj, pFanin, i ) Abc_ObjForEachFanin( pObj, pFanin, i )
Abc_NtkCollectPiPos_rec( pFanin, vPiPos ); Abc_NtkCollectPiPos_rec( Abc_ObjIsNode(pObj) ? pFanin : Abc_ObjFanin0(pFanin), vBiBos, vPiPos );
if ( Abc_ObjIsBox(pObj) ) if ( Abc_ObjIsNode(pObj) )
Abc_NtkCollectPiPos_int( (Abc_Ntk_t *)pObj->pData, vPiPos, 1 ); return;
Abc_ObjForEachFanin( pObj, pFanin, i )
Abc_NtkCollectPiPos_rec( Abc_ObjFanin0(pFanin), vBiBos, vPiPos );
Abc_NtkCollectPiPos_int( pObj, Abc_ObjModel(pObj), vBiBos, vPiPos );
} }
void Abc_NtkCollectPiPos_int( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPiPos, int fAdd ) void Abc_NtkCollectPiPos_int( Abc_Obj_t * pBox, Abc_Ntk_t * pNtk, Vec_Ptr_t * vBiBos, Vec_Ptr_t * vPiPos )
{ {
Abc_Obj_t * pObj; int i; Abc_Obj_t * pObj; int i;
// mark primary inputs // mark primary inputs
...@@ -110,22 +117,31 @@ void Abc_NtkCollectPiPos_int( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPiPos, int fAdd ) ...@@ -110,22 +117,31 @@ void Abc_NtkCollectPiPos_int( Abc_Ntk_t * pNtk, Vec_Ptr_t * vPiPos, int fAdd )
Abc_NtkForEachPi( pNtk, pObj, i ) Abc_NtkForEachPi( pNtk, pObj, i )
Abc_NodeSetTravIdCurrent( Abc_ObjFanout0(pObj) ); Abc_NodeSetTravIdCurrent( Abc_ObjFanout0(pObj) );
// add primary inputs // add primary inputs
if ( fAdd ) if ( pBox )
Abc_NtkForEachPi( pNtk, pObj, i ) {
Vec_PtrPush( vPiPos, pObj ); Abc_ObjForEachFanin( pBox, pObj, i )
Vec_PtrPush( vBiBos, pObj );
Abc_NtkForEachPi( pNtk, pObj, i )
Vec_PtrPush( vPiPos, pObj );
}
// visit primary outputs // visit primary outputs
Abc_NtkForEachPo( pNtk, pObj, i ) Abc_NtkForEachPo( pNtk, pObj, i )
Abc_NtkCollectPiPos_rec( Abc_ObjFanin0(pObj), vPiPos ); Abc_NtkCollectPiPos_rec( Abc_ObjFanin0(pObj), vBiBos, vPiPos );
// add primary outputs // add primary outputs
if ( fAdd ) if ( pBox )
Abc_NtkForEachPo( pNtk, pObj, i ) {
Vec_PtrPush( vPiPos, pObj ); Abc_ObjForEachFanout( pBox, pObj, i )
Vec_PtrPush( vBiBos, pObj );
Abc_NtkForEachPo( pNtk, pObj, i )
Vec_PtrPush( vPiPos, pObj );
}
} }
Vec_Ptr_t * Abc_NtkCollectPiPos( Abc_Ntk_t * pNtk ) void Abc_NtkCollectPiPos( Abc_Ntk_t * pNtk, Vec_Ptr_t ** pvBiBos, Vec_Ptr_t ** pvPiPos )
{ {
Vec_Ptr_t * vPiPos = Vec_PtrAlloc( 1000 ); assert( Abc_NtkIsNetlist(pNtk) );
Abc_NtkCollectPiPos_int( pNtk, vPiPos, 0 ); *pvBiBos = Vec_PtrAlloc( 1000 );
return vPiPos; *pvPiPos = Vec_PtrAlloc( 1000 );
Abc_NtkCollectPiPos_int( NULL, pNtk, *pvBiBos, *pvPiPos );
} }
/**Function************************************************************* /**Function*************************************************************
...@@ -147,10 +163,13 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet ) ...@@ -147,10 +163,13 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet )
assert( Abc_ObjIsNet(pNet) ); assert( Abc_ObjIsNet(pNet) );
if ( pNet->pCopy ) if ( pNet->pCopy )
return; return;
pNet->pCopy = ABC_OBJ_VOID;
pObj = Abc_ObjFanin0(pNet); pObj = Abc_ObjFanin0(pNet);
if ( Abc_ObjIsBo(pObj) )
pObj = Abc_ObjFanin0(pObj);
assert( Abc_ObjIsNode(pObj) || Abc_ObjIsBox(pObj) ); assert( Abc_ObjIsNode(pObj) || Abc_ObjIsBox(pObj) );
Abc_ObjForEachFanin( pObj, pFanin, i ) Abc_ObjForEachFanin( pObj, pFanin, i )
Abc_NtkToBarBufs_rec( pNtkNew, pFanin ); Abc_NtkToBarBufs_rec( pNtkNew, Abc_ObjIsNode(pObj) ? pFanin : Abc_ObjFanin0(pFanin) );
// create and connect object // create and connect object
if ( Abc_ObjIsNode(pObj) ) if ( Abc_ObjIsNode(pObj) )
{ {
...@@ -163,7 +182,7 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet ) ...@@ -163,7 +182,7 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet )
Abc_NtkCleanCopy( pModel ); Abc_NtkCleanCopy( pModel );
Abc_ObjForEachFanin( pObj, pFanin, i ) Abc_ObjForEachFanin( pObj, pFanin, i )
{ {
pLatch = Abc_NtkAddLatch( pNtkNew, pFanin->pCopy, ABC_INIT_ZERO ); pLatch = Abc_NtkAddLatch( pNtkNew, Abc_ObjFanin0(pFanin)->pCopy, ABC_INIT_ZERO );
Abc_ObjFanout0(Abc_NtkPi(pModel, i))->pCopy = Abc_ObjFanout0(pLatch); Abc_ObjFanout0(Abc_NtkPi(pModel, i))->pCopy = Abc_ObjFanout0(pLatch);
} }
Abc_NtkForEachPo( pModel, pObj, i ) Abc_NtkForEachPo( pModel, pObj, i )
...@@ -171,8 +190,9 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet ) ...@@ -171,8 +190,9 @@ void Abc_NtkToBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pNet )
Abc_ObjForEachFanout( pObj, pFanout, i ) Abc_ObjForEachFanout( pObj, pFanout, i )
{ {
pLatch = Abc_NtkAddLatch( pNtkNew, Abc_ObjFanin0(Abc_NtkPo(pModel, i))->pCopy, ABC_INIT_ZERO ); pLatch = Abc_NtkAddLatch( pNtkNew, Abc_ObjFanin0(Abc_NtkPo(pModel, i))->pCopy, ABC_INIT_ZERO );
pFanout->pCopy = Abc_ObjFanout0(pLatch); Abc_ObjFanout0(pFanout)->pCopy = Abc_ObjFanout0(pLatch);
} }
assert( pNet->pCopy != ABC_OBJ_VOID );
} }
Abc_Ntk_t * Abc_NtkToBarBufs( Abc_Ntk_t * pNtk ) Abc_Ntk_t * Abc_NtkToBarBufs( Abc_Ntk_t * pNtk )
{ {
...@@ -182,12 +202,12 @@ Abc_Ntk_t * Abc_NtkToBarBufs( Abc_Ntk_t * pNtk ) ...@@ -182,12 +202,12 @@ Abc_Ntk_t * Abc_NtkToBarBufs( Abc_Ntk_t * pNtk )
assert( Abc_NtkIsNetlist(pNtk) ); assert( Abc_NtkIsNetlist(pNtk) );
if ( !Abc_NtkCheckSingleInstance(pNtk) ) if ( !Abc_NtkCheckSingleInstance(pNtk) )
return NULL; return NULL;
Abc_NtkCleanCopy( pNtk );
// start the network // start the network
pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, pNtk->ntkFunc, 1 ); pNtkNew = Abc_NtkAlloc( ABC_NTK_LOGIC, pNtk->ntkFunc, 1 );
pNtkNew->pName = Extra_UtilStrsav(pNtk->pName); pNtkNew->pName = Extra_UtilStrsav(pNtk->pName);
pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec); pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec);
// clone CIs/CIs/boxes // clone CIs/CIs/boxes
Abc_NtkCleanCopy( pNtk );
Abc_NtkForEachPi( pNtk, pObj, i ) Abc_NtkForEachPi( pNtk, pObj, i )
Abc_ObjFanout0(pObj)->pCopy = Abc_NtkDupObj( pNtkNew, pObj, 1 ); Abc_ObjFanout0(pObj)->pCopy = Abc_NtkDupObj( pNtkNew, pObj, 1 );
Abc_NtkForEachPo( pNtk, pObj, i ) Abc_NtkForEachPo( pNtk, pObj, i )
...@@ -227,86 +247,27 @@ Abc_Obj_t * Abc_NtkFromBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pObj ) ...@@ -227,86 +247,27 @@ Abc_Obj_t * Abc_NtkFromBarBufs_rec( Abc_Ntk_t * pNtkNew, Abc_Obj_t * pObj )
Abc_ObjAddFanin( pObj->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, pFanin) ); Abc_ObjAddFanin( pObj->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, pFanin) );
return pObj->pCopy; return pObj->pCopy;
} }
Abc_Ntk_t * Abc_NtkFromBarBufsInt( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk, int fRoot ) Abc_Ntk_t * Abc_NtkFromBarBufsInt( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk )
{ {
Abc_Ntk_t * pNtkNew; Abc_Ntk_t * pNtkNew;
Abc_Obj_t * pObj, * pTerm, * pLatch, * pNet; Abc_Obj_t * pObj;
int i, k; int i;
// start the network // start the network
pNtkNew = Abc_NtkAlloc( pNtk->ntkType, pNtk->ntkFunc, 1 ); pNtkNew = Abc_NtkStartFrom( pNtkBase, pNtk->ntkType, pNtk->ntkFunc );
// clone CIs/CIs/boxes // move copy pointers
if ( fRoot ) Abc_NtkForEachCi( pNtkBase, pObj, i )
{ pObj->pNext->pCopy = pObj->pCopy;
pNtkNew->pName = Extra_UtilStrsav(pNtk->pName); Abc_NtkForEachCo( pNtkBase, pObj, i )
pNtkNew->pSpec = Extra_UtilStrsav(pNtk->pSpec); pObj->pNext->pCopy = pObj->pCopy;
Abc_NtkCleanCopy( pNtk ); // construct the network
Abc_NtkForEachCi( pNtk, pObj, i ) Abc_NtkForEachCo( pNtkBase, pObj, i )
Abc_NtkDupObj( pNtkNew, pObj, 1 ); Abc_ObjAddFanin( pObj->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, Abc_ObjFanin0(pObj->pNext)) );
Abc_NtkForEachCo( pNtk, pObj, i )
Abc_NtkDupObj( pNtkNew, pObj, 1 );
}
else
{
pNtkNew->pName = Extra_UtilStrsav(pNtkBase->pName);
pNtkNew->pSpec = Extra_UtilStrsav(pNtkBase->pSpec);
Abc_NtkForEachCi( pNtkBase, pObj, i )
Abc_NtkDupObj( pNtkNew, pObj, 1 );
Abc_NtkForEachCo( pNtkBase, pObj, i )
Abc_NtkDupObj( pNtkNew, pObj, 1 );
}
Abc_NtkForEachBox( pNtkBase, pObj, i )
{
Abc_NtkDupObj( pNtkNew, pObj, 1 );
Abc_ObjForEachFanout( pObj, pTerm, k )
{
pNet = Abc_ObjFanout0(pTerm);
assert( Abc_ObjIsNet(pNet) );
Abc_NtkDupObj( pNtkNew, pNet, 0 );
pLatch = Abc_NtkCi( Abc_ObjModel(pObj), k )->pNext;
assert( Abc_ObjIsLatch(pLatch) );
assert( Abc_ObjIsCi(Abc_ObjFanout0(pLatch)->pCopy) );
Abc_ObjAddFanin( Abc_ObjFanout0(pLatch)->pCopy, pObj->pCopy );
Abc_ObjAddFanin( pNet->pCopy, Abc_ObjFanout0(pLatch)->pCopy );
assert( Abc_ObjFanout0(Abc_ObjFanout0(pLatch))->pCopy == NULL );
Abc_ObjFanout0(Abc_ObjFanout0(pLatch))->pCopy = pNet->pCopy;
}
}
// build PO cones
if ( fRoot )
{
Abc_NtkForEachPo( pNtk, pObj, i )
Abc_ObjAddFanin( pObj->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, Abc_ObjFanin0(pObj)) );
}
else
{
Abc_NtkForEachPo( pNtkBase, pObj, i )
{
pLatch = pObj->pNext;
assert( Abc_ObjIsLatch(pLatch) );
Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pLatch)->pCopy );
Abc_ObjAddFanin( Abc_ObjFanin0(pLatch)->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, Abc_ObjFanin0(Abc_ObjFanin0(pLatch))) );
}
}
// build BI cones
Abc_NtkForEachBox( pNtkBase, pObj, i )
{
Abc_ObjForEachFanin( pObj, pTerm, k )
{
pNet = Abc_ObjFanin0(pTerm);
assert( Abc_ObjIsNet(pNet) );
pLatch = Abc_NtkCo( Abc_ObjModel(pObj), k )->pNext;
assert( Abc_ObjIsLatch(pLatch) );
assert( Abc_ObjIsCo(Abc_ObjFanin0(pLatch)->pCopy) );
Abc_ObjAddFanin( pObj->pCopy, Abc_ObjFanin0(pLatch)->pCopy );
Abc_ObjAddFanin( Abc_ObjFanin0(pLatch)->pCopy, Abc_NtkFromBarBufs_rec(pNtkNew, Abc_ObjFanin0(Abc_ObjFanin0(pLatch))) );
}
}
return (pNtkBase->pCopy = pNtkNew); return (pNtkBase->pCopy = pNtkNew);
} }
Abc_Ntk_t * Abc_NtkFromBarBufs( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk ) Abc_Ntk_t * Abc_NtkFromBarBufs( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk )
{ {
Abc_Ntk_t * pNtkNew, * pTemp; Abc_Ntk_t * pNtkNew, * pTemp;
Vec_Ptr_t * vPiPos; Vec_Ptr_t * vBiBos, * vPiPos;
Abc_Obj_t * pObj; Abc_Obj_t * pObj;
int i, k; int i, k;
assert( pNtkBase->pDesign != NULL ); assert( pNtkBase->pDesign != NULL );
...@@ -314,25 +275,37 @@ Abc_Ntk_t * Abc_NtkFromBarBufs( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk ) ...@@ -314,25 +275,37 @@ Abc_Ntk_t * Abc_NtkFromBarBufs( Abc_Ntk_t * pNtkBase, Abc_Ntk_t * pNtk )
assert( Abc_NtkIsNetlist(pNtkBase) ); assert( Abc_NtkIsNetlist(pNtkBase) );
assert( Abc_NtkLatchNum(pNtkBase) == 0 ); assert( Abc_NtkLatchNum(pNtkBase) == 0 );
assert( Abc_NtkLatchNum(pNtk) == pNtk->nBarBufs ); assert( Abc_NtkLatchNum(pNtk) == pNtk->nBarBufs );
assert( Abc_NtkPiNum(pNtk) == Abc_NtkPiNum(pNtkBase) );
assert( Abc_NtkPoNum(pNtk) == Abc_NtkPoNum(pNtkBase) );
assert( Abc_NtkCiNum(pNtk) == Abc_NtkCiNum(pNtkBase) ); assert( Abc_NtkCiNum(pNtk) == Abc_NtkCiNum(pNtkBase) );
assert( Abc_NtkCoNum(pNtk) == Abc_NtkCoNum(pNtkBase) ); assert( Abc_NtkCoNum(pNtk) == Abc_NtkCoNum(pNtkBase) );
// annotate PIs/POs of base with flops from optimized network // annotate PIs/POs of base with flops from optimized network
vPiPos = Abc_NtkCollectPiPos( pNtkBase ); Abc_NtkCollectPiPos( pNtkBase, &vBiBos, &vPiPos );
assert( Vec_PtrSize(vBiBos) == Abc_NtkLatchNum(pNtk) );
assert( Vec_PtrSize(vPiPos) == Abc_NtkLatchNum(pNtk) ); assert( Vec_PtrSize(vPiPos) == Abc_NtkLatchNum(pNtk) );
Abc_NtkCleanCopy_rec( pNtkBase ); Abc_NtkCleanCopy_rec( pNtkBase );
Abc_NtkCleanNext_rec( pNtkBase ); Abc_NtkCleanNext_rec( pNtkBase );
Vec_PtrForEachEntry( Abc_Obj_t *, vPiPos, pObj, i ) Abc_NtkForEachPi( pNtk, pObj, i )
pObj->pNext = Abc_NtkBox( pNtk, i ); Abc_NtkPi(pNtkBase, i)->pNext = pObj;
Abc_NtkForEachPo( pNtk, pObj, i )
Abc_NtkPo(pNtkBase, i)->pNext = pObj;
Abc_NtkForEachLatch( pNtk, pObj, i )
{
((Abc_Obj_t *)Vec_PtrEntry(vBiBos, i))->pNext = Abc_ObjFanin0(pObj);
((Abc_Obj_t *)Vec_PtrEntry(vPiPos, i))->pNext = Abc_ObjFanout0(pObj);
}
Vec_PtrFree( vBiBos );
Vec_PtrFree( vPiPos ); Vec_PtrFree( vPiPos );
// duplicate the networks // duplicate the networks
pNtkNew = Abc_NtkFromBarBufsInt( pNtkBase, pNtk, 1 ); pNtkNew = Abc_NtkFromBarBufsInt( pNtkBase, pNtk );
// finalize the design
pNtkNew->pDesign = Abc_LibCreate( pNtkBase->pDesign->pName ); pNtkNew->pDesign = Abc_LibCreate( pNtkBase->pDesign->pName );
Abc_LibAddModel( pNtkNew->pDesign, pNtkNew ); Abc_LibAddModel( pNtkNew->pDesign, pNtkNew );
Vec_PtrPush( pNtkNew->pDesign->vTops, pNtkNew ); Vec_PtrPush( pNtkNew->pDesign->vTops, pNtkNew );
Vec_PtrForEachEntry( Abc_Ntk_t *, pNtkBase->pDesign->vModules, pTemp, i ) Vec_PtrForEachEntry( Abc_Ntk_t *, pNtkBase->pDesign->vModules, pTemp, i )
if ( pTemp != pNtkBase ) if ( pTemp != pNtkBase )
{ {
pTemp = Abc_NtkFromBarBufsInt( pTemp, pNtk, 0 ); pTemp = Abc_NtkFromBarBufsInt( pTemp, pNtk );
Abc_LibAddModel( pNtkNew->pDesign, pTemp ); Abc_LibAddModel( pNtkNew->pDesign, pTemp );
} }
// set node models // set node models
......
...@@ -267,6 +267,7 @@ Abc_Obj_t * Abc_NtkAddLatch( Abc_Ntk_t * pNtk, Abc_Obj_t * pDriver, Abc_InitType ...@@ -267,6 +267,7 @@ Abc_Obj_t * Abc_NtkAddLatch( Abc_Ntk_t * pNtk, Abc_Obj_t * pDriver, Abc_InitType
Abc_ObjAssignName( pLatchIn, Abc_ObjName(pLatch), "_li" ); Abc_ObjAssignName( pLatchIn, Abc_ObjName(pLatch), "_li" );
Abc_ObjAddFanin( pLatchOut, pLatch ); Abc_ObjAddFanin( pLatchOut, pLatch );
Abc_ObjAddFanin( pLatch, pLatchIn ); Abc_ObjAddFanin( pLatch, pLatchIn );
if ( pDriver )
Abc_ObjAddFanin( pLatchIn, pDriver ); Abc_ObjAddFanin( pLatchIn, pDriver );
pLatch->pData = (void *)Init; pLatch->pData = (void *)Init;
return pLatchOut; return pLatchOut;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment