Commit 6a4e94e7 by Alan Mishchenko

Improvements to Cba data-structure.

parent 356217ef
......@@ -489,7 +489,7 @@ void Cba_NtkCollapse_rec( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vSigs, in
}
Cba_Man_t * Cba_ManCollapse( Cba_Man_t * p, int TypeBuf )
{
Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24) );
Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24), Hash_IntManRef(p->vHash) );
Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew;
Vec_Int_t * vSigs = Vec_IntAlloc( 1000 );
int i, iObj, iObjNew, iFon, nObjs = 0, nFins = 0, nFons = 0;
......@@ -660,7 +660,7 @@ void Cba_ManExtractGroupInt( Cba_Ntk_t * pNew, Cba_Ntk_t * p, Vec_Int_t * vObjs,
}
Cba_Man_t * Cba_ManExtractGroup( Cba_Man_t * p, Vec_Int_t * vObjs )
{
Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24) );
Cba_Man_t * pNew = Cba_ManAlloc( p->pSpec, 1, Abc_NamRef(p->pStrs), Abc_NamRef(p->pFuns), Abc_NamStart(100, 24), Hash_IntManRef(p->vHash) );
Cba_Ntk_t * pRoot = Cba_ManRoot( p ), * pRootNew;
Vec_Int_t * vFonIns = Cba_NtkCollectInFons( pRoot, vObjs );
Vec_Int_t * vFonOuts = Cba_NtkCollectOutFons( pRoot, vObjs );
......@@ -743,7 +743,7 @@ static inline int Cba_NtkInsertGiaObj( Cba_Ntk_t * p, Gia_Man_t * pGia, int iObj
}
Cba_Man_t * Cba_ManDeriveFromGia( Gia_Man_t * pGia )
{
Cba_Man_t * p = Cba_ManAlloc( pGia->pSpec, 1, NULL, NULL, NULL );
Cba_Man_t * p = Cba_ManAlloc( pGia->pSpec, 1, NULL, NULL, NULL, NULL );
Cba_Ntk_t * pNtk = Cba_NtkAlloc( p, Abc_NamStrFindOrAdd(p->pStrs, pGia->pName, NULL), Gia_ManCiNum(pGia), Gia_ManCoNum(pGia), 1000, 2000, 2000 );
Vec_Int_t * vLit2Fon = Vec_IntStartFull( 2*Gia_ManObjNum(pGia) );
int i, iObj, iObjNew, NameId, iLit0, iFon0;
......
......@@ -52,32 +52,33 @@ typedef struct Prs_Ntk_t_ Prs_Ntk_t;
struct Prs_Ntk_t_
{
// general info
int iModuleName;
unsigned fMapped : 1;
unsigned fSlices : 1;
unsigned fHasC0s : 1;
unsigned fHasC1s : 1;
unsigned fHasCXs : 1;
unsigned fHasCZs : 1;
Abc_Nam_t * pStrs;
Abc_Nam_t * pFuns;
int iModuleName;
unsigned fMapped : 1;
unsigned fSlices : 1;
unsigned fHasC0s : 1;
unsigned fHasC1s : 1;
unsigned fHasCXs : 1;
unsigned fHasCZs : 1;
Abc_Nam_t * pStrs;
Abc_Nam_t * pFuns;
Hash_IntMan_t * vHash;
// interface
Vec_Int_t vOrder; // order of signals
Vec_Int_t vOrder; // order of signals
// signal names
Vec_Int_t vInouts; // inouts
Vec_Int_t vInputs; // inputs
Vec_Int_t vOutputs; // outputs
Vec_Int_t vWires; // wires
Vec_Int_t vInouts; // inouts
Vec_Int_t vInputs; // inputs
Vec_Int_t vOutputs; // outputs
Vec_Int_t vWires; // wires
// signal ranges
Vec_Int_t vInoutsR; // inouts
Vec_Int_t vInputsR; // inputs
Vec_Int_t vOutputsR; // outputs
Vec_Int_t vWiresR; // wires
Vec_Int_t vInoutsR; // inouts
Vec_Int_t vInputsR; // inputs
Vec_Int_t vOutputsR; // outputs
Vec_Int_t vWiresR; // wires
// slices/concatenations/objects
Vec_Int_t vSlices; // NameId + RangeId
Vec_Int_t vConcats; // array of NameId/SliceId/ConstId
Vec_Int_t vBoxes; // ModuleId + InstId + array of pairs {FormNameId, ActSignalId(NameId/SliceId/ConstId/ConcatId)}
Vec_Int_t vObjs; // box handles
Vec_Int_t vSlices; // NameId + RangeId
Vec_Int_t vConcats; // array of NameId/SliceId/ConstId
Vec_Int_t vBoxes; // ModuleId + InstId + array of pairs {FormNameId, ActSignalId(NameId/SliceId/ConstId/ConcatId)}
Vec_Int_t vObjs; // box handles
};
// parser
......@@ -85,24 +86,25 @@ typedef struct Prs_Man_t_ Prs_Man_t;
struct Prs_Man_t_
{
// input data
char * pName; // file name
char * pBuffer; // file contents
char * pLimit; // end of file
char * pCur; // current position
Abc_Nam_t * pStrs; // string manager
Abc_Nam_t * pFuns; // cover manager
Prs_Ntk_t * pNtk; // current network
Vec_Ptr_t * vNtks; // input networks
char * pName; // file name
char * pBuffer; // file contents
char * pLimit; // end of file
char * pCur; // current position
Abc_Nam_t * pStrs; // string manager
Abc_Nam_t * pFuns; // cover manager
Hash_IntMan_t * vHash; // variable ranges
Prs_Ntk_t * pNtk; // current network
Vec_Ptr_t * vNtks; // input networks
// temporary data
Vec_Str_t vCover; // one SOP cover
Vec_Int_t vTemp; // array of tokens
Vec_Int_t vTemp2; // array of tokens
Vec_Str_t vCover; // one SOP cover
Vec_Int_t vTemp; // array of tokens
Vec_Int_t vTemp2; // array of tokens
// statistics
Vec_Int_t vKnown;
Vec_Int_t vFailed;
Vec_Int_t vSucceeded;
Vec_Int_t vKnown;
Vec_Int_t vFailed;
Vec_Int_t vSucceeded;
// error handling
int fUsingTemp2; // vTemp2 is in use
int fUsingTemp2; // vTemp2 is in use
char ErrorStr[1000]; // error
};
......@@ -188,6 +190,7 @@ static inline void Prs_ManInitializeNtk( Prs_Man_t * p, int iName, int fSlices )
p->pNtk->fSlices = fSlices;
p->pNtk->pStrs = Abc_NamRef( p->pStrs );
p->pNtk->pFuns = Abc_NamRef( p->pFuns );
p->pNtk->vHash = Hash_IntManRef( p->vHash );
Vec_PtrPush( p->vNtks, p->pNtk );
}
static inline void Prs_ManFinalizeNtk( Prs_Man_t * p )
......@@ -229,16 +232,6 @@ static inline void Prs_NtkAddBox( Prs_Ntk_t * p, int ModName, int InstName, Vec_
Vec_IntPush( &p->vBoxes, InstName );
Vec_IntAppend( &p->vBoxes, vTemp );
}
// parsing range
static inline void Prs_NtkParseRange( Prs_Ntk_t * p, int RangeId, int * pLeft, int * pRight )
{
char * pRange = Prs_NtkStr(p, RangeId);
char * pPivot = strchr( pRange, ':' );
*pLeft = atoi(pRange + 1);
*pRight = pPivot ? atoi(pPivot + 1) : *pLeft;
}
static inline char * Prs_ManLoadFile( char * pFileName, char ** ppLimit )
{
char * pBuffer;
......@@ -280,6 +273,8 @@ static inline Prs_Man_t * Prs_ManAlloc( char * pFileName )
p->pStrs = Abc_NamStart( 1000, 24 );
p->pFuns = Abc_NamStart( 100, 24 );
p->vNtks = Vec_PtrAlloc( 100 );
p->vHash = Hash_IntManStart( 1000 );
// Hash_Int2ManInsert( p->vHash, 0, 0, 0 );
return p;
}
......@@ -287,6 +282,7 @@ static inline void Prs_NtkFree( Prs_Ntk_t * p )
{
if ( p->pStrs ) Abc_NamDeref( p->pStrs );
if ( p->pFuns ) Abc_NamDeref( p->pFuns );
if ( p->vHash ) Hash_IntManDeref( p->vHash );
Vec_IntErase( &p->vOrder );
Vec_IntErase( &p->vInouts );
Vec_IntErase( &p->vInputs );
......@@ -315,6 +311,7 @@ static inline void Prs_ManFree( Prs_Man_t * p )
{
if ( p->pStrs ) Abc_NamDeref( p->pStrs );
if ( p->pFuns ) Abc_NamDeref( p->pFuns );
if ( p->vHash ) Hash_IntManDeref( p->vHash );
if ( p->vNtks ) Prs_ManVecFree( p->vNtks );
// temporary
Vec_StrErase( &p->vCover );
......@@ -424,6 +421,7 @@ static inline char * Ptr_TypeToName( Cba_ObjType_t Type )
if ( Type == CBA_BOX_MAJ ) return "maj";
if ( Type == CBA_BOX_SHARP ) return "sharp";
if ( Type == CBA_BOX_SHARPL) return "sharpl";
if ( Type == CBA_BOX_TRI) return "bufifl";
assert( 0 );
return "???";
}
......
......@@ -592,7 +592,7 @@ Cba_Man_t * Prs_ManBuildCbaBlif( char * pFileName, Vec_Ptr_t * vDes )
Abc_Nam_t * pStrs = Abc_NamRef(pPrsRoot->pStrs);
Abc_Nam_t * pFuns = Abc_NamRef(pPrsRoot->pFuns);
Abc_Nam_t * pMods = Abc_NamStart( 100, 24 );
Cba_Man_t * p = Cba_ManAlloc( pFileName, Vec_PtrSize(vDes), pStrs, pFuns, pMods );
Cba_Man_t * p = Cba_ManAlloc( pFileName, Vec_PtrSize(vDes), pStrs, pFuns, pMods, NULL );
// initialize networks
Vec_PtrForEachEntry( Prs_Ntk_t *, vDes, pPrsNtk, i )
{
......
......@@ -112,6 +112,7 @@ static void Prs_ManWriteVerilogBoxes( FILE * pFile, Prs_Ntk_t * p )
Prs_NtkForEachBox( p, vBox, i )
{
Cba_ObjType_t NtkId = Prs_BoxNtk(p, i);
char * pNtkName = Prs_NtkStr(p, Prs_BoxName(p, i));
if ( NtkId == CBA_BOX_MUX )
Prs_ManWriteVerilogMux( pFile, p, vBox );
else if ( Prs_BoxIsNode(p, i) ) // node ------- check order of fanins
......@@ -304,16 +305,31 @@ char * Cba_FonGetName( Cba_Ntk_t * p, int i )
char * pName = Cba_FonNameStr(p, i);
if ( pName == NULL )
return pName;
if ( Cba_ObjType(p, Cba_FonObj(p, i)) == CBA_BOX_SLICE )
return pName;
if ( Cba_NameIsLegalInVerilog(pName) )
return pName;
return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s ", pName );
}
char * Cba_ManGetSliceName( Cba_Ntk_t * p, int iFon, int Left, int Right )
{
char * pName = Cba_FonNameStr(p, iFon);
if ( Cba_NameIsLegalInVerilog(pName) )
if ( Left == Right )
return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "%s[%d]", pName, Right );
else
return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "%s[%d:%d]", pName, Left, Right );
else
if ( Left == Right )
return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s [%d]", pName, Right );
else
return Vec_StrPrintF( Abc_NamBuffer(Cba_NtkNam(p)), "\\%s [%d:%d]", pName, Left, Right );
}
void Cba_ManWriteFonRange( Cba_Ntk_t * p, int iFon )
{
Vec_Str_t * vStr = &p->pDesign->vOut;
if ( Cba_FonIsConst(iFon) || (Cba_FonRange(p, iFon) == 1 && Cba_FonRight(p, iFon) == 0) )
if ( Cba_FonIsConst(iFon) || (Cba_FonRangeSize(p, iFon) == 1 && Cba_FonRight(p, iFon) == 0) )
return;
Vec_StrPrintF( vStr, "[%d:%d] ", Cba_FonLeft(p, iFon), Cba_FonRight(p, iFon) );
......@@ -329,7 +345,7 @@ void Cba_ManWriteFonName( Cba_Ntk_t * p, int iFon, int fInlineConcat, int fInput
Cba_ManWriteCatIn( p, Cba_FonObj(p, iFon) );
else
{
int Range = fInput ? Cba_FonRange( p, iFon ) : 0;
int Range = fInput ? Cba_FonRangeSize( p, iFon ) : 0;
if ( fInput && Range > 1 )
Vec_StrPush( vStr, '{' );
Vec_StrPrintStr( vStr, Cba_FonIsConst(iFon) ? Cba_NtkConst(p, Cba_FonConst(iFon)) : Cba_FonGetName(p, iFon) );
......@@ -590,8 +606,8 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat )
{
int iFonIn = Cba_ObjFinFon(p, iObj, 0);
int iFonOut = Cba_ObjFon0(p, iObj);
int nBitsIn = Cba_FonRange(p, iFonIn);
int nBitsOut = Cba_FonRange(p, iFonOut);
int nBitsIn = Cba_FonRangeSize(p, iFonIn);
int nBitsOut = Cba_FonRangeSize(p, iFonOut);
assert( (1 << nBitsIn) == nBitsOut );
// function [15:0] res;
Vec_StrPrintStr( vStr, " function " );
......@@ -606,12 +622,14 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat )
// casez (i)
Vec_StrPrintStr( vStr, " casez(i)\n" );
// 2'b00: res = 4'b0001;
Cba_ObjForEachFinFon( p, iObj, iFin, iFon, i )
for ( i = 0; i < (1 << nBitsIn); i++ )
{
Vec_StrPrintF( vStr, " %d\'b: ", nBitsIn );
Vec_StrPrintF( vStr, " %d\'b", nBitsIn );
for ( k = nBitsIn-1; k >= 0; k-- )
Vec_StrPrintNum( vStr, (i >> k) & 1 );
Vec_StrPrintStr( vStr, ": _func_" );
Cba_ManWriteFonName( p, iFonOut, 0, 0 );
Vec_StrPrintF( vStr, " = %d\'b%*d;\n", nBitsOut, nBitsOut, 0 );
Vec_StrPrintF( vStr, " = %d\'b%0*d;\n", nBitsOut, nBitsOut, 0 );
Vec_StrWriteEntry( vStr, Vec_StrSize(vStr) - i - 3, '1' );
}
Vec_StrPrintStr( vStr, " endcase\n" );
......@@ -639,8 +657,8 @@ void Cba_ManWriteVerilogNtk( Cba_Ntk_t * p, int fInlineConcat )
int iFonSet = Cba_ObjFinFon(p, iObj, 1);
int iFonRst = Cba_ObjFinFon(p, iObj, 2);
int iFonC = Cba_ObjFinFon(p, iObj, 3);
int Range = Cba_FonRange( p, iFonQ );
assert( Cba_FonRange(p, iFonSet) == 1 && Cba_FonRange(p, iFonRst) == 1 );
int Range = Cba_FonRangeSize( p, iFonQ );
assert( Cba_FonRangeSize(p, iFonSet) == 1 && Cba_FonRangeSize(p, iFonRst) == 1 );
// reg [3:0] Q;
Vec_StrPrintStr( vStr, " reg " );
Cba_ManWriteFonRange( p, iFonQ );
......
......@@ -133,13 +133,9 @@ void Abc_NamStop( Abc_Nam_t * p )
***********************************************************************/
void Abc_NamPrint( Abc_Nam_t * p )
{
int h, i, Counter = 0;
int h, i;
Vec_IntForEachEntryStart( &p->vInt2Handle, h, i, 1 )
if ( Abc_NamHandleToStr(p, h)[0] == '[' )
Abc_Print( 1, "%s ", Abc_NamHandleToStr(p, h) ), Counter++;
// Abc_Print( 1, "%d=\n%s\n", i, Abc_NamHandleToStr(p, h) );
// Abc_Print( 1, "\n" );
printf( " %d\n", Counter );
Abc_Print( 1, "%d=\n%s\n", i, Abc_NamHandleToStr(p, h) );
}
/**Function*************************************************************
......
......@@ -53,6 +53,7 @@ struct Hash_IntMan_t_
{
Vec_Int_t * vTable; // hash table
Vec_Int_t * vObjs; // hash objects
int nRefs; // reference counter for the manager
};
////////////////////////////////////////////////////////////////////////
......@@ -74,7 +75,7 @@ static inline void Hash_Int2ObjSetData2( Hash_IntMan_t * p, int i, in
/**Function*************************************************************
Synopsis [Hashing data entries composed of nSize integers.]
Synopsis [Hashes pairs of intergers.]
Description []
......@@ -90,6 +91,7 @@ static inline Hash_IntMan_t * Hash_IntManStart( int nSize )
p->vTable = Vec_IntStart( Abc_PrimeCudd(nSize) );
p->vObjs = Vec_IntAlloc( 4*nSize );
Vec_IntFill( p->vObjs, 4, 0 );
p->nRefs = 1;
return p;
}
static inline void Hash_IntManStop( Hash_IntMan_t * p )
......@@ -98,6 +100,18 @@ static inline void Hash_IntManStop( Hash_IntMan_t * p )
Vec_IntFree( p->vTable );
ABC_FREE( p );
}
static inline Hash_IntMan_t * Hash_IntManRef( Hash_IntMan_t * p )
{
p->nRefs++;
return p;
}
static inline void Hash_IntManDeref( Hash_IntMan_t * p )
{
if ( p == NULL )
return;
if ( --p->nRefs == 0 )
Hash_IntManStop( p );
}
static inline int Hash_IntManEntryNum( Hash_IntMan_t * p )
{
return Vec_IntSize(p->vObjs)/4 - 1;
......@@ -172,7 +186,7 @@ static inline int Hash_Int2ManInsert( Hash_IntMan_t * p, int iData0, int iData1,
/**Function*************************************************************
Synopsis []
Synopsis [Hashes triples of intergers.]
Description []
......
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