summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/aig/gia/giaMini.c268
-rw-r--r--src/base/abci/abc.c13
2 files changed, 278 insertions, 3 deletions
diff --git a/src/aig/gia/giaMini.c b/src/aig/gia/giaMini.c
index ce42f73c..ead5e736 100644
--- a/src/aig/gia/giaMini.c
+++ b/src/aig/gia/giaMini.c
@@ -797,6 +797,274 @@ void Gia_MiniAigVerify( Abc_Frame_t * pAbc, char * pFileName )
Mini_AigStop( p );
}
+/**Function*************************************************************
+
+ Synopsis [Collects supergate for the outputs.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Gia_MiniAigSuperGates_rec( Mini_Aig_t * p, int iObj, Vec_Int_t * vRes, Vec_Int_t * vMap )
+{
+ int iFan0, iFan1;
+ if ( Mini_AigNodeIsPi(p, iObj) )
+ {
+ assert( Vec_IntEntry(vMap, iObj) >= 0 );
+ Vec_IntPush( vRes, Vec_IntEntry(vMap, iObj) );
+ return;
+ }
+ iFan0 = Mini_AigNodeFanin0( p, iObj );
+ iFan1 = Mini_AigNodeFanin1( p, iObj );
+ assert( !Abc_LitIsCompl(iFan0) );
+ assert( !Abc_LitIsCompl(iFan1) );
+ Gia_MiniAigSuperGates_rec( p, Abc_Lit2Var(iFan0), vRes, vMap );
+ Gia_MiniAigSuperGates_rec( p, Abc_Lit2Var(iFan1), vRes, vMap );
+}
+Vec_Wec_t * Gia_MiniAigSuperGates( Mini_Aig_t * p )
+{
+ Vec_Wec_t * vRes = Vec_WecStart( Mini_AigPoNum(p) );
+ Vec_Int_t * vMap = Vec_IntStartFull( Mini_AigNodeNum(p) );
+ int i, Index = 0;
+ Mini_AigForEachPi( p, i )
+ Vec_IntWriteEntry( vMap, i, Index++ );
+ assert( Index == Mini_AigPiNum(p) );
+ Index = 0;
+ Mini_AigForEachPo( p, i )
+ {
+ int iFan0 = Mini_AigNodeFanin0( p, i );
+ assert( !Abc_LitIsCompl(iFan0) );
+ Gia_MiniAigSuperGates_rec( p, Abc_Lit2Var(iFan0), Vec_WecEntry(vRes, Index++), vMap );
+ }
+ assert( Index == Mini_AigPoNum(p) );
+ Vec_IntFree( vMap );
+ return vRes;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Transform.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+void Gia_MiniAigSuperPrintDouble( Vec_Int_t * p, int nPis )
+{
+ int i, Entry;
+ printf( "\n" );
+ Vec_IntForEachEntry( p, Entry, i )
+ printf( "%d(%d) ", Entry%nPis, Entry/nPis );
+ printf( " Total = %d\n", Vec_IntSize(p) );
+}
+int Gia_MiniAigSuperMerge( Vec_Int_t * p, int nPis )
+{
+ int i, k = 0, This, Prev = -1, fChange = 0;
+ Vec_IntForEachEntry( p, This, i )
+ {
+ if ( Prev == This )
+ {
+ Vec_IntWriteEntry( p, k++, (This/nPis+1)*nPis + This%nPis );
+ Prev = -1;
+ fChange = 1;
+ }
+ else
+ {
+ if ( Prev != -1 )
+ Vec_IntWriteEntry( p, k++, Prev );
+ Prev = This;
+ }
+ }
+ if ( Prev != -1 )
+ Vec_IntWriteEntry( p, k++, Prev );
+ Vec_IntShrink( p, k );
+ return fChange;
+}
+int Gia_MiniAigSuperPreprocess( Mini_Aig_t * p, Vec_Wec_t * vSuper, int nPis, int fVerbose )
+{
+ Vec_Int_t * vRes;
+ int i, nIters, Multi = 1;
+ Vec_WecForEachLevel( vSuper, vRes, i )
+ {
+ Vec_IntSort( vRes, 0 );
+ if ( fVerbose )
+ printf( "\nOutput %d\n", i );
+ if ( fVerbose )
+ Gia_MiniAigSuperPrintDouble( vRes, nPis );
+ for ( nIters = 1; Gia_MiniAigSuperMerge(vRes, nPis); nIters++ )
+ {
+ if ( fVerbose )
+ Gia_MiniAigSuperPrintDouble( vRes, nPis );
+ }
+ Multi = Abc_MaxInt( Multi, nIters );
+ }
+ if ( fVerbose )
+ printf( "Multi = %d.\n", Multi );
+ return Multi;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Derive AIG.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Gia_Man_t * Gia_MiniAigSuperDeriveGia( Vec_Wec_t * p, int nPis, int Multi )
+{
+ Gia_Man_t * pNew;
+ Vec_Int_t * vTemp, * vLits = Vec_IntAlloc( 100 );
+ Vec_Int_t * vDrivers = Vec_IntAlloc(100);
+ int i, k, iObj, iLit, nInputs = nPis*Multi;
+ pNew = Gia_ManStart( 1000 );
+ pNew->pName = Abc_UtilStrsav( "tree" );
+ for ( i = 0; i < nInputs; i++ )
+ Gia_ManAppendCi( pNew );
+ Gia_ManHashAlloc( pNew );
+ Vec_WecForEachLevel( p, vTemp, i )
+ {
+ Vec_IntClear( vLits );
+ Vec_IntForEachEntry( vTemp, iObj, k )
+ {
+ assert( iObj < nInputs );
+ Vec_IntPush( vLits, 2+2*((iObj%nPis)*Multi+iObj/nPis) );
+ }
+ Vec_IntPush( vDrivers, Gia_ManHashAndMulti2(pNew, vLits) );
+ }
+ Gia_ManHashStop( pNew );
+ Vec_IntFree( vLits );
+ Vec_IntForEachEntry( vDrivers, iLit, i )
+ Gia_ManAppendCo( pNew, iLit );
+ Vec_IntFree( vDrivers );
+ return pNew;
+}
+Gia_Man_t * Gia_MiniAigSuperDerive( char * pFileName, int fVerbose )
+{
+ Mini_Aig_t * p = Mini_AigLoad( pFileName );
+ Vec_Wec_t * vSuper = Gia_MiniAigSuperGates( p );
+ int Multi = Gia_MiniAigSuperPreprocess( p, vSuper, Mini_AigPiNum(p), fVerbose );
+ Gia_Man_t * pNew = Gia_MiniAigSuperDeriveGia( vSuper, Mini_AigPiNum(p), Multi );
+ Vec_WecFree( vSuper );
+ Mini_AigStop( p );
+ return pNew;
+}
+
+/**Function*************************************************************
+
+ Synopsis [Process file.]
+
+ Description []
+
+ SideEffects []
+
+ SeeAlso []
+
+***********************************************************************/
+Vec_Int_t * Gia_MiniAigProcessFile()
+{
+ Vec_Int_t * vTriples = Vec_IntAlloc( 100 );
+ char * pFileName = "test.txt";
+ FILE * pFile = fopen( pFileName, "rb" );
+ if ( pFile == NULL )
+ printf( "Cannot open the file.\n" );
+ else
+ {
+ int nLines = 0, nLinesAll = 0;
+ char * pToken;
+ char Buffer[1000];
+ while ( fgets( Buffer, 1000, pFile ) != NULL )
+ {
+ nLinesAll++;
+ if ( Buffer[0] != '#' )
+ continue;
+ //printf( "%s", Buffer );
+ nLines++;
+ pToken = strtok( Buffer+3, " \r\n\r+=" );
+ while ( pToken )
+ {
+ Vec_IntPush( vTriples, atoi(pToken) );
+ pToken = strtok( NULL, " \r\n\r+=" );
+ }
+ }
+ fclose( pFile );
+ printf( "Collected %d (out of %d) lines.\n", nLines, nLinesAll );
+ printf( "Entries = %d\n", Vec_IntSize(vTriples) );
+ }
+ return vTriples;
+}
+void Gia_MiniAigGenerate_rec( Mini_Aig_t * p, Vec_Int_t * vTriples, int iObj, Vec_Int_t * vDefs, Vec_Int_t * vMap )
+{
+ int Index, Entry0, Entry1, Entry2, Value;
+ if ( Vec_IntEntry(vMap, iObj) >= 0 )
+ return;
+ Index = Vec_IntEntry( vDefs, iObj );
+ Entry0 = Vec_IntEntry( vTriples, 3*Index+0 );
+ Entry1 = Vec_IntEntry( vTriples, 3*Index+1 );
+ Entry2 = Vec_IntEntry( vTriples, 3*Index+2 );
+ Gia_MiniAigGenerate_rec( p, vTriples, Entry1, vDefs, vMap );
+ Gia_MiniAigGenerate_rec( p, vTriples, Entry2, vDefs, vMap );
+ assert( Vec_IntEntry(vMap, Entry1) >= 0 );
+ assert( Vec_IntEntry(vMap, Entry2) >= 0 );
+ Value = Mini_AigAnd( p, Vec_IntEntry(vMap, Entry1), Vec_IntEntry(vMap, Entry2) );
+ Vec_IntWriteEntry( vMap, Entry0, Value );
+}
+void Gia_MiniAigGenerateFromFile()
+{
+ Mini_Aig_t * p = Mini_AigStart();
+ Vec_Int_t * vTriples = Gia_MiniAigProcessFile();
+ Vec_Int_t * vDefs = Vec_IntStartFull( Vec_IntSize(vTriples) );
+ Vec_Int_t * vMap = Vec_IntStartFull( Vec_IntSize(vTriples) );
+ Vec_Int_t * vMapIn = Vec_IntStart( Vec_IntSize(vTriples) );
+ Vec_Int_t * vMapOut = Vec_IntStart( Vec_IntSize(vTriples) );
+ Vec_Int_t * vPis = Vec_IntAlloc( 100 );
+ Vec_Int_t * vPos = Vec_IntAlloc( 100 );
+ int i, ObjOut, ObjIn, nIns = 0, nOuts = 0;
+ assert( Vec_IntSize(vTriples) % 3 == 0 );
+ for ( i = 0; i < Vec_IntSize(vTriples)/3; i++ )
+ {
+ int Entry0 = Vec_IntEntry(vTriples, 3*i+0);
+ int Entry1 = Vec_IntEntry(vTriples, 3*i+1);
+ int Entry2 = Vec_IntEntry(vTriples, 3*i+2);
+ Vec_IntWriteEntry( vDefs, Entry0, i );
+ Vec_IntAddToEntry( vMapOut, Entry0, 1 );
+ Vec_IntAddToEntry( vMapIn, Entry1, 1 );
+ Vec_IntAddToEntry( vMapIn, Entry2, 1 );
+ }
+ Vec_IntForEachEntryTwo( vMapOut, vMapIn, ObjOut, ObjIn, i )
+ if ( !ObjOut && ObjIn )
+ Vec_IntPush( vPis, i );
+ else if ( ObjOut && !ObjIn )
+ Vec_IntPush( vPos, i );
+ Vec_IntForEachEntry( vPis, ObjIn, i )
+ Vec_IntWriteEntry( vMap, ObjIn, Mini_AigCreatePi(p) );
+ Vec_IntForEachEntry( vPos, ObjOut, i )
+ Gia_MiniAigGenerate_rec( p, vTriples, ObjOut, vDefs, vMap );
+ Vec_IntForEachEntry( vPos, ObjOut, i )
+ {
+ assert( Vec_IntEntry(vMap, ObjOut) >= 0 );
+ Mini_AigCreatePo( p, Vec_IntEntry(vMap, ObjOut) );
+ }
+ Vec_IntFree( vTriples );
+ Vec_IntFree( vDefs );
+ Vec_IntFree( vMap );
+ Vec_IntFree( vMapIn );
+ Vec_IntFree( vMapOut );
+ Vec_IntFree( vPis );
+ Vec_IntFree( vPos );
+ Mini_AigDump( p, "test.miniaig" );
+ Mini_AigStop( p );
+}
+
////////////////////////////////////////////////////////////////////////
/// END OF FILE ///
////////////////////////////////////////////////////////////////////////
diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c
index b107bdc9..d1ed5901 100644
--- a/src/base/abci/abc.c
+++ b/src/base/abci/abc.c
@@ -13988,7 +13988,6 @@ int Abc_CommandTest( Abc_Frame_t * pAbc, int argc, char ** argv )
//Dau_NetworkEnumTest();
//Extra_SimulationTest( nDivMax, nNumOnes, fNewOrder );
//Mnist_ExperimentWithScaling( nDecMax );
- //Gia_Gen2CodeTest();
return 0;
usage:
Abc_Print( -2, "usage: test [-CKDNM] [-aovwh] <file_name>\n" );
@@ -29949,18 +29948,20 @@ usage:
int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern void Abc3_ReadShowHie( char * pFileName, int fFlat );
+ extern Gia_Man_t * Gia_MiniAigSuperDerive( char * pFileName, int fVerbose );
Gia_Man_t * pAig = NULL;
FILE * pFile;
char ** pArgvNew;
char * FileName, * pTemp;
int c, nArgcNew;
int fMiniAig = 0;
+ int fMiniAig2 = 0;
int fMiniLut = 0;
int fVerbose = 0;
int fGiaSimple = 0;
int fSkipStrash = 0;
Extra_UtilGetoptReset();
- while ( ( c = Extra_UtilGetopt( argc, argv, "csmlvh" ) ) != EOF )
+ while ( ( c = Extra_UtilGetopt( argc, argv, "csmnlvh" ) ) != EOF )
{
switch ( c )
{
@@ -29973,6 +29974,9 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
case 'm':
fMiniAig ^= 1;
break;
+ case 'n':
+ fMiniAig2 ^= 1;
+ break;
case 'l':
fMiniLut ^= 1;
break;
@@ -30009,6 +30013,8 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
if ( fMiniAig )
pAig = Gia_ManReadMiniAig( FileName );
+ else if ( fMiniAig2 )
+ pAig = Gia_MiniAigSuperDerive( FileName, fVerbose );
else if ( fMiniLut )
pAig = Gia_ManReadMiniLut( FileName );
// else if ( Extra_FileIsType( FileName, ".v", NULL, NULL ) )
@@ -30020,11 +30026,12 @@ int Abc_CommandAbc9Read( Abc_Frame_t * pAbc, int argc, char ** argv )
return 0;
usage:
- Abc_Print( -2, "usage: &r [-csmlvh] <file>\n" );
+ Abc_Print( -2, "usage: &r [-csmnlvh] <file>\n" );
Abc_Print( -2, "\t reads the current AIG from the AIGER file\n" );
Abc_Print( -2, "\t-c : toggles reading simple AIG [default = %s]\n", fGiaSimple? "yes": "no" );
Abc_Print( -2, "\t-s : toggles structural hashing while reading [default = %s]\n", !fSkipStrash? "yes": "no" );
Abc_Print( -2, "\t-m : toggles reading MiniAIG rather than AIGER file [default = %s]\n", fMiniAig? "yes": "no" );
+ Abc_Print( -2, "\t-n : toggles reading MiniAIG as a set of supergates [default = %s]\n", fMiniAig2? "yes": "no" );
Abc_Print( -2, "\t-l : toggles reading MiniLUT rather than AIGER file [default = %s]\n", fMiniLut? "yes": "no" );
Abc_Print( -2, "\t-v : toggles additional verbose output [default = %s]\n", fVerbose? "yes": "no" );
Abc_Print( -2, "\t-h : print the command usage\n");