Commit c899645b by Alan Mishchenko

Adding dumping truth tables from LMS manager.

parent b9c22ba9
...@@ -13437,17 +13437,26 @@ usage: ...@@ -13437,17 +13437,26 @@ usage:
***********************************************************************/ ***********************************************************************/
int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv ) int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv )
{ {
extern void Abc_NtkRecDumpTt3( char * pFileName, int fBinary );
char * FileName; char * FileName;
char ** pArgvNew; char ** pArgvNew;
int nArgcNew; int nArgcNew;
Gia_Man_t * pGia; Gia_Man_t * pGia;
int fAscii = 0;
int fBinary = 0;
int c; int c;
Extra_UtilGetoptReset(); Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "h" ) ) != EOF ) while ( ( c = Extra_UtilGetopt( argc, argv, "abh" ) ) != EOF )
{ {
switch ( c ) switch ( c )
{ {
case 'a':
fAscii ^= 1;
break;
case 'b':
fBinary ^= 1;
break;
case 'h': case 'h':
goto usage; goto usage;
default: default:
...@@ -13460,7 +13469,6 @@ int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -13460,7 +13469,6 @@ int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv )
return 1; return 1;
} }
pGia = Abc_NtkRecGetGia3();
pArgvNew = argv + globalUtilOptind; pArgvNew = argv + globalUtilOptind;
nArgcNew = argc - globalUtilOptind; nArgcNew = argc - globalUtilOptind;
if ( nArgcNew != 1 ) if ( nArgcNew != 1 )
...@@ -13468,22 +13476,34 @@ int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv ) ...@@ -13468,22 +13476,34 @@ int Abc_CommandRecDump3( Abc_Frame_t * pAbc, int argc, char ** argv )
Abc_Print( -1, "File name is not given on the command line.\n" ); Abc_Print( -1, "File name is not given on the command line.\n" );
return 1; return 1;
} }
else if( Gia_ManPoNum(pGia) == 0 ) // get the input file name
FileName = pArgvNew[0];
if ( fAscii )
Abc_NtkRecDumpTt3( FileName, 0 );
else if ( fBinary )
Abc_NtkRecDumpTt3( FileName, 1 );
else
{
pGia = Abc_NtkRecGetGia3();
if( pGia == NULL )
{
Abc_Print( 0, "Library AIG is not available.\n" );
return 1;
}
if( Gia_ManPoNum(pGia) == 0 )
{ {
Abc_Print( 0, "No structure in the library.\n" ); Abc_Print( 0, "No structure in the library.\n" );
return 1; return 1;
} }
else
{
// get the input file name
FileName = pArgvNew[0];
Gia_WriteAiger( pGia, FileName, 0, 0 ); Gia_WriteAiger( pGia, FileName, 0, 0 );
} }
return 0; return 0;
usage: usage:
Abc_Print( -2, "usage: rec_dump3 [-h] <file>\n" ); Abc_Print( -2, "usage: rec_dump3 [-abh] <file>\n" );
Abc_Print( -2, "\t-h : print the command usage\n"); Abc_Print( -2, "\t-h : print the command usage\n");
Abc_Print( -2, "\t-a : toggles dumping TTs into an ASCII file [default = %s]\n", fAscii? "yes": "no" );
Abc_Print( -2, "\t-b : toggles dumping TTs into a binary file [default = %s]\n", fBinary? "yes": "no" );
Abc_Print( -2, "\t<file> : AIGER file to write the library\n"); Abc_Print( -2, "\t<file> : AIGER file to write the library\n");
return 1; return 1;
} }
......
...@@ -66,6 +66,7 @@ struct Lms_Man_t_ ...@@ -66,6 +66,7 @@ struct Lms_Man_t_
Vec_Ptr_t * vNodes; // the temporary nodes Vec_Ptr_t * vNodes; // the temporary nodes
Vec_Ptr_t * vLabelsP; // temporary storage for HOP node labels Vec_Ptr_t * vLabelsP; // temporary storage for HOP node labels
Vec_Int_t * vLabels; // temporary storage for AIG node labels Vec_Int_t * vLabels; // temporary storage for AIG node labels
Vec_Str_t * vSupps; // used temporarily by TT dumping
word pTemp1[1024]; // copy of the truth table word pTemp1[1024]; // copy of the truth table
word pTemp2[1024]; // copy of the truth table word pTemp2[1024]; // copy of the truth table
// statistics // statistics
...@@ -123,6 +124,8 @@ Lms_Man_t * Lms_ManStart( Gia_Man_t * pGia, int nVars, int nCuts, int fFuncOnly, ...@@ -123,6 +124,8 @@ Lms_Man_t * Lms_ManStart( Gia_Man_t * pGia, int nVars, int nCuts, int fFuncOnly,
// internal data for library construction // internal data for library construction
p->vTtMem = Vec_MemAlloc( p->nWords, 12 ); // 32 KB/page for 6-var functions p->vTtMem = Vec_MemAlloc( p->nWords, 12 ); // 32 KB/page for 6-var functions
Vec_MemHashAlloc( p->vTtMem, 10000 ); Vec_MemHashAlloc( p->vTtMem, 10000 );
if ( fFuncOnly )
return p;
p->vTruthIds = Vec_IntAlloc( 10000 ); p->vTruthIds = Vec_IntAlloc( 10000 );
if ( pGia == NULL ) if ( pGia == NULL )
{ {
...@@ -182,7 +185,7 @@ void Lms_ManPrint( Lms_Man_t * p ) ...@@ -182,7 +185,7 @@ void Lms_ManPrint( Lms_Man_t * p )
{ {
// Gia_ManPrintStats( p->pGia, 0, 0 ); // Gia_ManPrintStats( p->pGia, 0, 0 );
printf( "Library with %d vars has %d classes and %d AIG subgraphs with %d AND nodes.\n", printf( "Library with %d vars has %d classes and %d AIG subgraphs with %d AND nodes.\n",
Gia_ManCiNum(p->pGia), Vec_MemEntryNum(p->vTtMem), p->nAdded, Gia_ManAndNum(p->pGia) ); p->nVars, Vec_MemEntryNum(p->vTtMem), p->nAdded, p->pGia ? Gia_ManAndNum(p->pGia) : 0 );
p->nAddedFuncs = Vec_MemEntryNum(p->vTtMem); p->nAddedFuncs = Vec_MemEntryNum(p->vTtMem);
printf( "Subgraphs tried = %10d. (%6.2f %%)\n", p->nTried, !p->nTried? 0 : 100.0*p->nTried/p->nTried ); printf( "Subgraphs tried = %10d. (%6.2f %%)\n", p->nTried, !p->nTried? 0 : 100.0*p->nTried/p->nTried );
...@@ -607,16 +610,6 @@ int Abc_NtkRecAddCut3( If_Man_t * pIfMan, If_Obj_t * pRoot, If_Cut_t * pCut ) ...@@ -607,16 +610,6 @@ int Abc_NtkRecAddCut3( If_Man_t * pIfMan, If_Obj_t * pRoot, If_Cut_t * pCut )
return 1; return 1;
} }
// collect internal nodes and skip redundant cuts
clk = clock();
If_CutTraverse( pIfMan, pRoot, pCut, vNodes );
p->timeTruth += clock() - clk;
if ( Vec_PtrSize(vNodes) > 253 )
{
p->nFilterSize++;
return 1;
}
// semi-canonicize truth table // semi-canonicize truth table
clk = clock(); clk = clock();
memcpy( p->pTemp1, If_CutTruthW(pCut), p->nWords * sizeof(word) ); memcpy( p->pTemp1, If_CutTruthW(pCut), p->nWords * sizeof(word) );
...@@ -629,6 +622,26 @@ clk = clock(); ...@@ -629,6 +622,26 @@ clk = clock();
p->timeCanon += clock() - clk; p->timeCanon += clock() - clk;
// pCanonPerm and uCanonPhase show what was the variable corresponding to each var in the current truth // pCanonPerm and uCanonPhase show what was the variable corresponding to each var in the current truth
if ( p->pGia == NULL )
{
clk = clock();
// add the resulting truth table to the hash table
Vec_MemHashInsert( p->vTtMem, p->pTemp1 );
p->nAdded++;
p->timeInsert += clock() - clk;
return 1;
}
// collect internal nodes and skip redundant cuts
clk = clock();
If_CutTraverse( pIfMan, pRoot, pCut, vNodes );
p->timeTruth += clock() - clk;
if ( Vec_PtrSize(vNodes) > 253 )
{
p->nFilterSize++;
return 1;
}
clk = clock(); clk = clock();
// map cut leaves into elementary variables of GIA // map cut leaves into elementary variables of GIA
for ( i = 0; i < nLeaves; i++ ) for ( i = 0; i < nLeaves; i++ )
...@@ -715,7 +728,7 @@ void Abc_NtkRecAdd3( Abc_Ntk_t * pNtk, int fUseSOPB ) ...@@ -715,7 +728,7 @@ void Abc_NtkRecAdd3( Abc_Ntk_t * pNtk, int fUseSOPB )
// remember that the manager was used for library construction // remember that the manager was used for library construction
s_pMan3->fLibConstr = 1; s_pMan3->fLibConstr = 1;
// create hash table if not available // create hash table if not available
if ( s_pMan3->pGia->pHTable == NULL ) if ( s_pMan3->pGia && s_pMan3->pGia->pHTable == NULL )
Gia_ManHashStart( s_pMan3->pGia ); Gia_ManHashStart( s_pMan3->pGia );
// set defaults // set defaults
...@@ -1199,6 +1212,68 @@ void Lms_GiaNormalize( Lms_Man_t * p ) ...@@ -1199,6 +1212,68 @@ void Lms_GiaNormalize( Lms_Man_t * p )
SeeAlso [] SeeAlso []
***********************************************************************/ ***********************************************************************/
int Abc_NtkRecTruthCompare( int * p1, int * p2 )
{
int Diff = Vec_StrEntry( s_pMan3->vSupps, *p1 ) - Vec_StrEntry( s_pMan3->vSupps, *p2 );
if ( Diff )
return Diff;
return memcmp( Vec_MemReadEntry(s_pMan3->vTtMem, *p1), Vec_MemReadEntry(s_pMan3->vTtMem, *p2), sizeof(word) * s_pMan3->nWords );
}
void Abc_NtkRecDumpTt3( char * pFileName, int fBinary )
{
FILE * pFile;
char pBuffer[1000];
Lms_Man_t * p = s_pMan3;
Vec_Int_t * vEntries;
word * pTruth;
int i, Entry, nVars = p->nVars;
int nEntries = Vec_MemEntryNum(p->vTtMem);
if ( nEntries == 0 )
{
printf( "There is not truth tables.\n" );
return;
}
pFile = fopen( pFileName, "wb" );
if ( pFile == NULL )
{
printf( "The file cannot be opened.\n" );
return;
}
p->vSupps = Vec_StrAlloc( nEntries );
Vec_MemForEachEntry( p->vTtMem, pTruth, i )
Vec_StrPush( p->vSupps, (char)Abc_TtSupportSize(pTruth, nVars) );
vEntries = Vec_IntStartNatural( nEntries );
qsort( (void *)Vec_IntArray(vEntries), nEntries, sizeof(int), (int(*)(const void *,const void *))Abc_NtkRecTruthCompare );
Vec_StrFreeP( &p->vSupps );
// write the file
Vec_IntForEachEntry( vEntries, Entry, i )
{
pTruth = Vec_MemReadEntry(p->vTtMem, Entry);
if ( fBinary )
{
fwrite( pTruth, 1, sizeof(word) * p->nWords, pFile );
continue;
}
Extra_PrintHex( pFile, (unsigned *)pTruth, nVars );
fprintf( pFile, " " );
Kit_DsdWriteFromTruth( pBuffer, (unsigned *)pTruth, nVars );
fprintf( pFile, "%s\n", pBuffer );
}
fclose( pFile );
Vec_IntFree( vEntries );
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
void Abc_NtkRecPs3(int fPrintLib) void Abc_NtkRecPs3(int fPrintLib)
{ {
Lms_ManPrint( s_pMan3 ); Lms_ManPrint( s_pMan3 );
......
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