Commit 200c5cc6 by Alan Mishchenko

Added support for generating a library of real-life truth-tables.

parent 07405ca1
...@@ -539,6 +539,7 @@ extern void Kit_DsdTruthPartialTwo( Kit_DsdMan_t * p, Kit_DsdNtk_t * ...@@ -539,6 +539,7 @@ extern void Kit_DsdTruthPartialTwo( Kit_DsdMan_t * p, Kit_DsdNtk_t *
extern void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk ); extern void Kit_DsdPrint( FILE * pFile, Kit_DsdNtk_t * pNtk );
extern void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk ); extern void Kit_DsdPrintExpanded( Kit_DsdNtk_t * pNtk );
extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars ); extern void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars );
extern void Kit_DsdPrintFromTruth2( FILE * pFile, unsigned * pTruth, int nVars );
extern void Kit_DsdWriteFromTruth( char * pBuffer, unsigned * pTruth, int nVars ); extern void Kit_DsdWriteFromTruth( char * pBuffer, unsigned * pTruth, int nVars );
extern Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars ); extern Kit_DsdNtk_t * Kit_DsdDecompose( unsigned * pTruth, int nVars );
extern Kit_DsdNtk_t * Kit_DsdDecomposeExpand( unsigned * pTruth, int nVars ); extern Kit_DsdNtk_t * Kit_DsdDecomposeExpand( unsigned * pTruth, int nVars );
......
...@@ -234,6 +234,86 @@ char * Kit_DsdWriteHex( char * pBuff, unsigned * pTruth, int nFans ) ...@@ -234,6 +234,86 @@ char * Kit_DsdWriteHex( char * pBuff, unsigned * pTruth, int nFans )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Kit_DsdPrint2_rec( FILE * pFile, Kit_DsdNtk_t * pNtk, int Id )
{
Kit_DsdObj_t * pObj;
unsigned iLit, i;
char Symbol;
pObj = Kit_DsdNtkObj( pNtk, Id );
if ( pObj == NULL )
{
assert( Id < pNtk->nVars );
fprintf( pFile, "%c", 'a' + Id );
return;
}
if ( pObj->Type == KIT_DSD_CONST1 )
{
assert( pObj->nFans == 0 );
fprintf( pFile, "Const1" );
return;
}
if ( pObj->Type == KIT_DSD_VAR )
assert( pObj->nFans == 1 );
if ( pObj->Type == KIT_DSD_AND )
Symbol = '*';
else if ( pObj->Type == KIT_DSD_XOR )
Symbol = '+';
else
Symbol = ',';
if ( pObj->Type == KIT_DSD_PRIME )
fprintf( pFile, "[" );
else
fprintf( pFile, "(" );
Kit_DsdObjForEachFanin( pNtk, pObj, iLit, i )
{
if ( Kit_DsdLitIsCompl(iLit) )
fprintf( pFile, "!" );
Kit_DsdPrint2_rec( pFile, pNtk, Kit_DsdLit2Var(iLit) );
if ( i < pObj->nFans - 1 )
fprintf( pFile, "%c", Symbol );
}
if ( pObj->Type == KIT_DSD_PRIME )
fprintf( pFile, "]" );
else
fprintf( pFile, ")" );
}
/**Function*************************************************************
Synopsis [Print the DSD formula.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Kit_DsdPrint2( FILE * pFile, Kit_DsdNtk_t * pNtk )
{
// fprintf( pFile, "F = " );
if ( Kit_DsdLitIsCompl(pNtk->Root) )
fprintf( pFile, "!" );
Kit_DsdPrint2_rec( pFile, pNtk, Kit_DsdLit2Var(pNtk->Root) );
// fprintf( pFile, "\n" );
}
/**Function*************************************************************
Synopsis [Recursively print the DSD formula.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Kit_DsdPrint_rec( FILE * pFile, Kit_DsdNtk_t * pNtk, int Id ) void Kit_DsdPrint_rec( FILE * pFile, Kit_DsdNtk_t * pNtk, int Id )
{ {
Kit_DsdObj_t * pObj; Kit_DsdObj_t * pObj;
...@@ -431,6 +511,28 @@ void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars ) ...@@ -431,6 +511,28 @@ void Kit_DsdPrintFromTruth( unsigned * pTruth, int nVars )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
void Kit_DsdPrintFromTruth2( FILE * pFile, unsigned * pTruth, int nVars )
{
Kit_DsdNtk_t * pTemp, * pTemp2;
pTemp = Kit_DsdDecomposeMux( pTruth, nVars, 0 );
pTemp2 = Kit_DsdExpand( pTemp );
Kit_DsdPrint2( pFile, pTemp2 );
Kit_DsdVerify( pTemp2, pTruth, nVars );
Kit_DsdNtkFree( pTemp2 );
Kit_DsdNtkFree( pTemp );
}
/**Function*************************************************************
Synopsis [Print the DSD formula.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Kit_DsdWriteFromTruth( char * pBuffer, unsigned * pTruth, int nVars ) void Kit_DsdWriteFromTruth( char * pBuffer, unsigned * pTruth, int nVars )
{ {
Kit_DsdNtk_t * pTemp, * pTemp2; Kit_DsdNtk_t * pTemp, * pTemp2;
......
...@@ -200,12 +200,16 @@ void Abc_NtkRecStart( Abc_Ntk_t * pNtk, int nVars, int nCuts ) ...@@ -200,12 +200,16 @@ void Abc_NtkRecStart( Abc_Ntk_t * pNtk, int nVars, int nCuts )
p->vTtElems->nSize = p->nVars; p->vTtElems->nSize = p->nVars;
p->vTtElems->nCap = p->nVars; p->vTtElems->nCap = p->nVars;
p->vTtElems->pArray = (void **)Extra_TruthElementary( p->nVars ); p->vTtElems->pArray = (void **)Extra_TruthElementary( p->nVars );
/*
// allocate room for node truth tables // allocate room for node truth tables
if ( Abc_NtkObjNum(pNtk) > (1<<14) ) if ( Abc_NtkObjNum(pNtk) > (1<<14) )
p->vTtNodes = Vec_PtrAllocSimInfo( 2 * Abc_NtkObjNum(pNtk), p->nWords ); p->vTtNodes = Vec_PtrAllocSimInfo( 2 * Abc_NtkObjNum(pNtk), p->nWords );
else else
p->vTtNodes = Vec_PtrAllocSimInfo( 1<<14, p->nWords ); p->vTtNodes = Vec_PtrAllocSimInfo( 1<<14, p->nWords );
*/
p->vTtNodes = Vec_PtrAlloc( 1000 );
for ( i = 0; i < Abc_NtkObjNumMax(pNtk); i++ )
Vec_PtrPush( p->vTtNodes, ABC_ALLOC(unsigned, p->nWords) );
// create hash table // create hash table
p->nBins = 50011; p->nBins = 50011;
...@@ -269,6 +273,38 @@ p->timeTotal += clock() - clkTotal; ...@@ -269,6 +273,38 @@ p->timeTotal += clock() - clkTotal;
/**Function************************************************************* /**Function*************************************************************
Synopsis [Dump truth tables into a file.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkRecDumpTruthTables( Abc_ManRec_t * p )
{
FILE * pFile;
Abc_Obj_t * pObj;
unsigned * pTruth;
int i;
pFile = fopen( "tt16.txt", "wb" );
for ( i = 0; i < p->nBins; i++ )
for ( pObj = p->pBins[i]; pObj; pObj = pObj->pCopy )
{
pTruth = Vec_PtrEntry(p->vTtNodes, pObj->Id);
if ( Kit_TruthSupport(pTruth, 16) != (1<<16)-1 )
continue;
Extra_PrintHex( pFile, pTruth, 16 );
fprintf( pFile, " " );
Kit_DsdPrintFromTruth2( pFile, pTruth, 16 );
fprintf( pFile, "\n" );
}
fclose( pFile );
}
/**Function*************************************************************
Synopsis [Returns the given record.] Synopsis [Returns the given record.]
Description [] Description []
...@@ -281,9 +317,12 @@ p->timeTotal += clock() - clkTotal; ...@@ -281,9 +317,12 @@ p->timeTotal += clock() - clkTotal;
void Abc_NtkRecStop() void Abc_NtkRecStop()
{ {
assert( s_pMan != NULL ); assert( s_pMan != NULL );
Abc_NtkRecDumpTruthTables( s_pMan );
if ( s_pMan->pNtk ) if ( s_pMan->pNtk )
Abc_NtkDelete( s_pMan->pNtk ); Abc_NtkDelete( s_pMan->pNtk );
Vec_PtrFree( s_pMan->vTtNodes ); // Vec_PtrFree( s_pMan->vTtNodes );
Vec_PtrFreeFree( s_pMan->vTtNodes );
Vec_PtrFree( s_pMan->vTtElems ); Vec_PtrFree( s_pMan->vTtElems );
ABC_FREE( s_pMan->pBins ); ABC_FREE( s_pMan->pBins );
...@@ -878,8 +917,11 @@ s_pMan->timeCanon += clock() - clk; ...@@ -878,8 +917,11 @@ s_pMan->timeCanon += clock() - clk;
if ( pObj->Id == nNodes ) if ( pObj->Id == nNodes )
{ {
// increase storage for truth tables // increase storage for truth tables
if ( Vec_PtrSize(s_pMan->vTtNodes) <= pObj->Id ) // if ( Vec_PtrSize(s_pMan->vTtNodes) <= pObj->Id )
Vec_PtrDoubleSimInfo(s_pMan->vTtNodes); // Vec_PtrDoubleSimInfo(s_pMan->vTtNodes);
while ( Vec_PtrSize(s_pMan->vTtNodes) <= pObj->Id )
Vec_PtrPush( s_pMan->vTtNodes, ABC_ALLOC(unsigned, s_pMan->nWords) );
// compute the truth table // compute the truth table
RetValue = Abc_NtkRecComputeTruth( pObj, s_pMan->vTtNodes, nInputs ); RetValue = Abc_NtkRecComputeTruth( pObj, s_pMan->vTtNodes, nInputs );
if ( RetValue == 0 ) if ( RetValue == 0 )
......
...@@ -929,6 +929,8 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -929,6 +929,8 @@ int IoCommandReadTruth( Abc_Frame_t * pAbc, int argc, char ** argv )
goto usage; goto usage;
} }
c = strlen(argv[globalUtilOptind]);
// convert truth table to SOP // convert truth table to SOP
if ( fHex ) if ( fHex )
pSopCover = Abc_SopFromTruthHex(argv[globalUtilOptind]); pSopCover = Abc_SopFromTruthHex(argv[globalUtilOptind]);
......
...@@ -70,7 +70,7 @@ char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc ) ...@@ -70,7 +70,7 @@ char * Abc_UtilsGetVersion( Abc_Frame_t * pAbc )
***********************************************************************/ ***********************************************************************/
char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc ) char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
{ {
static char Prompt[1000]; static char Prompt[5000];
#ifndef _WIN32 #ifndef _WIN32
static char * line = NULL; static char * line = NULL;
#endif #endif
...@@ -78,7 +78,7 @@ char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc ) ...@@ -78,7 +78,7 @@ char * Abc_UtilsGetUsersInput( Abc_Frame_t * pAbc )
sprintf( Prompt, "abc %02d> ", pAbc->nSteps ); sprintf( Prompt, "abc %02d> ", pAbc->nSteps );
#ifdef _WIN32 #ifdef _WIN32
fprintf( pAbc->Out, "%s", Prompt ); fprintf( pAbc->Out, "%s", Prompt );
fgets( Prompt, 999, stdin ); fgets( Prompt, 5000, stdin );
return Prompt; return Prompt;
#else #else
if (line != NULL) ABC_FREE(line); if (line != NULL) ABC_FREE(line);
......
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