Commit 089a8bbf by Alan Mishchenko

Several improvements to CBA data-structure.

parent fd877c3f
...@@ -757,6 +757,7 @@ extern void Abc_FrameImportPtr( Vec_Ptr_t * vPtr ); ...@@ -757,6 +757,7 @@ extern void Abc_FrameImportPtr( Vec_Ptr_t * vPtr );
extern Vec_Ptr_t * Abc_FrameExportPtr(); extern Vec_Ptr_t * Abc_FrameExportPtr();
/*=== cbaBlast.c =============================================================*/ /*=== cbaBlast.c =============================================================*/
extern int Cba_NtkBuildLibrary( Cba_Man_t * p );
extern Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose ); extern Gia_Man_t * Cba_ManExtract( Cba_Man_t * p, int fBuffers, int fVerbose );
extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia ); extern Cba_Man_t * Cba_ManInsertGia( Cba_Man_t * p, Gia_Man_t * pGia );
extern void * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc ); extern void * Cba_ManInsertAbc( Cba_Man_t * p, void * pAbc );
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include "base/abc/abc.h" #include "base/abc/abc.h"
#include "map/mio/mio.h" #include "map/mio/mio.h"
#include "bool/dec/dec.h" #include "bool/dec/dec.h"
#include "base/main/mainInt.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -489,6 +490,17 @@ void Cba_NtkPrepareLibrary( Cba_Man_t * p, Mio_Library_t * pLib ) ...@@ -489,6 +490,17 @@ void Cba_NtkPrepareLibrary( Cba_Man_t * p, Mio_Library_t * pLib )
Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate), NULL ); Abc_NamStrFindOrAdd( p->pMods, Mio_GateReadName(pGate), NULL );
assert( Abc_NamObjNumMax(p->pMods) > 1 ); assert( Abc_NamObjNumMax(p->pMods) > 1 );
} }
int Cba_NtkBuildLibrary( Cba_Man_t * p )
{
int RetValue = 1;
Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen( Abc_FrameGetGlobalFrame() );
if ( pLib == NULL )
printf( "The standard cell library is not available.\n" ), RetValue = 0;
else
Cba_NtkPrepareLibrary( p, pLib );
p->pMioLib = pLib;
return RetValue;
}
void Cba_NtkInsertNtk( Cba_Man_t * p, Abc_Ntk_t * pNtk ) void Cba_NtkInsertNtk( Cba_Man_t * p, Abc_Ntk_t * pNtk )
{ {
Cba_Ntk_t * pCbaNtk, * pRoot = Cba_ManRoot( p ); Cba_Ntk_t * pCbaNtk, * pRoot = Cba_ManRoot( p );
......
...@@ -278,17 +278,15 @@ Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p ) ...@@ -278,17 +278,15 @@ Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p )
Cba_ObjAlloc( pRootNew, CBA_OBJ_PO, Vec_IntEntry(vSigs, i) ); Cba_ObjAlloc( pRootNew, CBA_OBJ_PO, Vec_IntEntry(vSigs, i) );
assert( Cba_NtkObjNum(pRootNew) == Cba_NtkObjNumAlloc(pRootNew) ); assert( Cba_NtkObjNum(pRootNew) == Cba_NtkObjNumAlloc(pRootNew) );
Vec_IntFree( vSigs ); Vec_IntFree( vSigs );
/*
// transfer PI/PO names // transfer PI/PO names
if ( Cba_NtkHasNames(pRoot) ) if ( Cba_NtkHasNames(pRoot) )
{ {
Cba_NtkStartNames( pRootNew ); Cba_NtkStartNames( pRootNew );
Cba_NtkForEachPo( pRoot, iObj, i ) Cba_NtkForEachPi( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) ); Cba_ObjSetName( pRootNew, Cba_NtkPi(pRootNew, i), Cba_ObjName(pRoot, iObj) );
Cba_NtkForEachPo( pRoot, iObj, i ) Cba_NtkForEachPo( pRoot, iObj, i )
Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) ); Cba_ObjSetName( pRootNew, Cba_NtkPo(pRootNew, i), Cba_ObjName(pRoot, iObj) );
} }
*/
return pNew; return pNew;
} }
......
...@@ -100,7 +100,7 @@ struct Prs_Man_t_ ...@@ -100,7 +100,7 @@ struct Prs_Man_t_
char ErrorStr[1000]; // error char ErrorStr[1000]; // error
}; };
static inline Prs_Ntk_t * Prs_ManNtk( Vec_Ptr_t * vPrs, int i ) { return (Prs_Ntk_t *)Vec_PtrEntry(vPrs, i); } static inline Prs_Ntk_t * Prs_ManNtk( Vec_Ptr_t * vPrs, int i ) { return i >= 0 && i < Vec_PtrSize(vPrs) ? (Prs_Ntk_t *)Vec_PtrEntry(vPrs, i) : NULL; }
static inline Prs_Ntk_t * Prs_ManRoot( Vec_Ptr_t * vPrs ) { return Prs_ManNtk(vPrs, 0); } static inline Prs_Ntk_t * Prs_ManRoot( Vec_Ptr_t * vPrs ) { return Prs_ManNtk(vPrs, 0); }
static inline Abc_Nam_t * Prs_ManNameMan( Vec_Ptr_t * vPrs ) { return Prs_ManRoot(vPrs)->pStrs; } static inline Abc_Nam_t * Prs_ManNameMan( Vec_Ptr_t * vPrs ) { return Prs_ManRoot(vPrs)->pStrs; }
......
...@@ -20,6 +20,8 @@ ...@@ -20,6 +20,8 @@
#include "cba.h" #include "cba.h"
#include "cbaPrs.h" #include "cbaPrs.h"
#include "map/mio/mio.h"
#include "base/main/main.h"
ABC_NAMESPACE_IMPL_START ABC_NAMESPACE_IMPL_START
...@@ -42,6 +44,33 @@ ABC_NAMESPACE_IMPL_START ...@@ -42,6 +44,33 @@ ABC_NAMESPACE_IMPL_START
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Prs_ManIsMapped( Prs_Ntk_t * pNtk )
{
Vec_Int_t * vSigs; int iBox;
Mio_Library_t * pLib = (Mio_Library_t *)Abc_FrameReadLibGen( Abc_FrameGetGlobalFrame() );
if ( pLib == NULL )
return 0;
Prs_NtkForEachBox( pNtk, vSigs, iBox )
if ( !Prs_BoxIsNode(pNtk, iBox) )
{
int NtkId = Prs_BoxNtk( pNtk, iBox );
if ( Mio_LibraryReadGateByName(pLib, Prs_NtkStr(pNtk, NtkId), NULL) )
return 1;
}
return 0;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Prs_ManVecFree( Vec_Ptr_t * vPrs ) void Prs_ManVecFree( Vec_Ptr_t * vPrs )
{ {
Prs_Ntk_t * pNtk; int i; Prs_Ntk_t * pNtk; int i;
...@@ -109,6 +138,12 @@ void Prs_ManRemapOne( Vec_Int_t * vSigs, Prs_Ntk_t * pNtkBox, Vec_Int_t * vMap ) ...@@ -109,6 +138,12 @@ void Prs_ManRemapOne( Vec_Int_t * vSigs, Prs_Ntk_t * pNtkBox, Vec_Int_t * vMap )
Prs_NtkForEachPo( pNtkBox, NameId, i ) Prs_NtkForEachPo( pNtkBox, NameId, i )
Vec_IntWriteEntry( vMap, NameId, -1 ); Vec_IntWriteEntry( vMap, NameId, -1 );
} }
void Prs_ManRemapGate( Vec_Int_t * vSigs )
{
int i, FormId;
Vec_IntForEachEntry( vSigs, FormId, i )
Vec_IntWriteEntry( vSigs, i, i/2 + 1 ), i++;
}
void Prs_ManRemapBoxes( Cba_Man_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_Int_t * vMap ) void Prs_ManRemapBoxes( Cba_Man_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_Int_t * vMap )
{ {
Vec_Int_t * vSigs; int iBox; Vec_Int_t * vSigs; int iBox;
...@@ -118,7 +153,10 @@ void Prs_ManRemapBoxes( Cba_Man_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Ve ...@@ -118,7 +153,10 @@ void Prs_ManRemapBoxes( Cba_Man_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Ve
int NtkId = Prs_BoxNtk( pNtk, iBox ); int NtkId = Prs_BoxNtk( pNtk, iBox );
int NtkIdNew = Cba_ManNtkFindId( pNew, Prs_NtkStr(pNtk, NtkId) ); int NtkIdNew = Cba_ManNtkFindId( pNew, Prs_NtkStr(pNtk, NtkId) );
Prs_BoxSetNtk( pNtk, iBox, NtkIdNew ); Prs_BoxSetNtk( pNtk, iBox, NtkIdNew );
if ( NtkId < Cba_ManNtkNum(pNew) )
Prs_ManRemapOne( vSigs, Prs_ManNtk(vDes, NtkIdNew), vMap ); Prs_ManRemapOne( vSigs, Prs_ManNtk(vDes, NtkIdNew), vMap );
else
Prs_ManRemapGate( vSigs );
} }
} }
void Prs_ManCleanMap( Prs_Ntk_t * pNtk, Vec_Int_t * vMap ) void Prs_ManCleanMap( Prs_Ntk_t * pNtk, Vec_Int_t * vMap )
...@@ -157,6 +195,21 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_ ...@@ -157,6 +195,21 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
if ( !Prs_BoxIsNode(pNtk, iBox) ) if ( !Prs_BoxIsNode(pNtk, iBox) )
{ {
pNtkBox = Prs_ManNtk( vDes, Prs_BoxNtk(pNtk, iBox) ); pNtkBox = Prs_ManNtk( vDes, Prs_BoxNtk(pNtk, iBox) );
if ( pNtkBox == NULL )
{
iObj = Cba_BoxAlloc( pNew, CBA_BOX_GATE, Vec_IntSize(vSigs)/2-1, 1, Prs_BoxNtk(pNtk, iBox) + 1 ); // +1 to map NtkId into gate name
Cba_ObjSetName( pNew, iObj, Prs_BoxName(pNtk, iBox) );
// consider box output
NameId = Vec_IntEntryLast( vSigs );
NameId = Prs_NtkSigName( pNtk, NameId );
if ( Vec_IntEntry(vMap, NameId) != -1 )
printf( "Box output name %d is already driven.\n", NameId );
iTerm = Cba_BoxBo( pNew, iObj, 0 );
Cba_ObjSetName( pNew, iTerm, NameId );
Vec_IntWriteEntry( vMap, NameId, iTerm );
}
else
{
iObj = Cba_BoxAlloc( pNew, CBA_OBJ_BOX, Prs_NtkPiNum(pNtkBox), Prs_NtkPoNum(pNtkBox), Prs_BoxNtk(pNtk, iBox) ); iObj = Cba_BoxAlloc( pNew, CBA_OBJ_BOX, Prs_NtkPiNum(pNtkBox), Prs_NtkPoNum(pNtkBox), Prs_BoxNtk(pNtk, iBox) );
Cba_ObjSetName( pNew, iObj, Prs_BoxName(pNtk, iBox) ); Cba_ObjSetName( pNew, iObj, Prs_BoxName(pNtk, iBox) );
Cba_NtkSetHost( Cba_ManNtk(pNew->pDesign, Prs_BoxNtk(pNtk, iBox)), Cba_NtkId(pNew), iObj ); Cba_NtkSetHost( Cba_ManNtk(pNew->pDesign, Prs_BoxNtk(pNtk, iBox)), Cba_NtkId(pNew), iObj );
...@@ -175,6 +228,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_ ...@@ -175,6 +228,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
Cba_ObjSetName( pNew, iTerm, NameId ); Cba_ObjSetName( pNew, iTerm, NameId );
Vec_IntWriteEntry( vMap, NameId, iTerm ); Vec_IntWriteEntry( vMap, NameId, iTerm );
} }
}
// remember box // remember box
Vec_IntPush( vBoxes, iObj ); Vec_IntPush( vBoxes, iObj );
} }
...@@ -198,6 +252,28 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_ ...@@ -198,6 +252,28 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
{ {
pNtkBox = Prs_ManNtk( vDes, Prs_BoxNtk(pNtk, iBox) ); pNtkBox = Prs_ManNtk( vDes, Prs_BoxNtk(pNtk, iBox) );
iObj = Vec_IntEntry( vBoxes, iBox ); iObj = Vec_IntEntry( vBoxes, iBox );
if ( pNtkBox == NULL )
{
Vec_IntForEachEntryStop( vSigs, Index, i, Vec_IntSize(vSigs)-2 )
{
i++;
NameId = Vec_IntEntry( vSigs, i );
NameId = Prs_NtkSigName( pNtk, NameId );
iTerm = Cba_BoxBi( pNew, iObj, i/2 );
if ( Vec_IntEntry(vMap, NameId) == -1 )
{
iConst0 = Cba_BoxAlloc( pNew, CBA_BOX_C0, 0, 1, -1 );
Vec_IntWriteEntry( vMap, NameId, iConst0+1 );
if ( iNonDriven == -1 )
iNonDriven = NameId;
nNonDriven++;
}
Cba_ObjSetFanin( pNew, iTerm, Vec_IntEntry(vMap, NameId) );
Cba_ObjSetName( pNew, iTerm, NameId );
}
}
else
{
Vec_IntForEachEntry( vSigs, Index, i ) Vec_IntForEachEntry( vSigs, Index, i )
{ {
i++; i++;
...@@ -218,6 +294,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_ ...@@ -218,6 +294,7 @@ void Prs_ManBuildNtk( Cba_Ntk_t * pNew, Vec_Ptr_t * vDes, Prs_Ntk_t * pNtk, Vec_
Cba_ObjSetName( pNew, iTerm, NameId ); Cba_ObjSetName( pNew, iTerm, NameId );
} }
} }
}
else else
{ {
iObj = Vec_IntEntry( vBoxes, iBox ); iObj = Vec_IntEntry( vBoxes, iBox );
...@@ -279,6 +356,9 @@ Cba_Man_t * Prs_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes ) ...@@ -279,6 +356,9 @@ Cba_Man_t * Prs_ManBuildCba( char * pFileName, Vec_Ptr_t * vDes )
pNew->pStrs = Abc_NamRef( pNtk->pStrs ); pNew->pStrs = Abc_NamRef( pNtk->pStrs );
Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pNtk, i ) Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pNtk, i )
Cba_NtkAlloc( Cba_ManNtk(pNew, i), Prs_NtkId(pNtk), Prs_NtkPiNum(pNtk), Prs_NtkPoNum(pNtk), Prs_NtkCountObjects(pNtk) ); Cba_NtkAlloc( Cba_ManNtk(pNew, i), Prs_NtkId(pNtk), Prs_NtkPiNum(pNtk), Prs_NtkPoNum(pNtk), Prs_NtkCountObjects(pNtk) );
if ( (pNtk->fMapped || (pNtk->fSlices && Prs_ManIsMapped(pNtk))) && !Cba_NtkBuildLibrary(pNew) )
Cba_ManFree(pNew), pNew = NULL;
else
Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pNtk, i ) Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pNtk, i )
Prs_ManBuildNtk( Cba_ManNtk(pNew, i), vDes, pNtk, vMap, vTmp ); Prs_ManBuildNtk( Cba_ManNtk(pNew, i), vDes, pNtk, vMap, vTmp );
assert( Vec_IntCountEntry(vMap, -1) == Vec_IntSize(vMap) ); assert( Vec_IntCountEntry(vMap, -1) == Vec_IntSize(vMap) );
......
...@@ -330,7 +330,7 @@ void Cba_ManWriteVerilogNtk( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vMap, Vec_ ...@@ -330,7 +330,7 @@ void Cba_ManWriteVerilogNtk( FILE * pFile, Cba_Ntk_t * p, Vec_Int_t * vMap, Vec_
for ( s = 0; s < 2; s++ ) for ( s = 0; s < 2; s++ )
{ {
fprintf( pFile, " " ); fprintf( pFile, " " );
Cba_ManWriteVerilogSignalList( pFile, p, s, s==2, 1, vWires ); Cba_ManWriteVerilogSignalList( pFile, p, s, s==1, 1, vWires );
fprintf( pFile, "\n" ); fprintf( pFile, "\n" );
} }
fprintf( pFile, " );\n" ); fprintf( pFile, " );\n" );
......
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