From 19eaa55c2a96b136900f558db96b99f076e9883e Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Sun, 23 Jul 2023 10:14:35 -0700 Subject: [PATCH] Experiments with cube ordering. --- .gitignore | 1 + src/base/abc/abcFunc.c | 36 ++++++++++++++++++++++++ src/base/abci/abc.c | 16 +++++++++-- src/base/abci/abcGen.c | 64 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 115 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 203869de1..c745dfb57 100644 --- a/.gitignore +++ b/.gitignore @@ -6,6 +6,7 @@ ReleaseLib/ ReleaseExe/ ReleaseExt/ +_/ _TEST/ lib/abc* lib/m114* diff --git a/src/base/abc/abcFunc.c b/src/base/abc/abcFunc.c index 84ecf7bf3..805b91daa 100644 --- a/src/base/abc/abcFunc.c +++ b/src/base/abc/abcFunc.c @@ -1265,6 +1265,42 @@ int Abc_NtkToAig( Abc_Ntk_t * pNtk ) } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_ObjFaninSort( Abc_Obj_t * pObj ) +{ + Vec_Int_t * vFanins = Abc_ObjFaninVec( pObj ); + char * pCube, * pSop = (char*)pObj->pData; + int i, j, nVars = Abc_SopGetVarNum( pSop ); + assert( nVars == Vec_IntSize(vFanins) ); + for ( i = 0; i < Vec_IntSize(vFanins); i++ ) + for ( j = i+1; j < Vec_IntSize(vFanins); j++ ) + { + if ( Vec_IntEntry(vFanins, i) < Vec_IntEntry(vFanins, j) ) + continue; + ABC_SWAP( int, Vec_IntArray(vFanins)[i], Vec_IntArray(vFanins)[j] ); + for ( pCube = pSop; *pCube; pCube += nVars + 3 ) { + ABC_SWAP( char, pCube[i], pCube[j] ); + } + } +} +void Abc_NtkFaninSort( Abc_Ntk_t * pNtk ) +{ + Abc_Obj_t * pObj; int i; + assert( Abc_NtkIsSopLogic(pNtk) ); + Abc_NtkForEachNode( pNtk, pObj, i ) + Abc_ObjFaninSort( pObj ); +} + //////////////////////////////////////////////////////////////////////// /// END OF FILE /// //////////////////////////////////////////////////////////////////////// diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 2a1550b8a..d06867617 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -11017,6 +11017,7 @@ usage: ***********************************************************************/ int Abc_CommandSop( Abc_Frame_t * pAbc, int argc, char ** argv ) { + extern void Abc_NtkFaninSort( Abc_Ntk_t * pNtk ); Abc_Ntk_t * pNtk = Abc_FrameReadNtk(pAbc); int c, fCubeSort = 1, fMode = -1, nCubeLimit = 1000000; @@ -11072,6 +11073,8 @@ int Abc_CommandSop( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "Converting to SOP has failed.\n" ); return 0; } + if ( !fCubeSort ) + Abc_NtkFaninSort( pNtk ); return 0; usage: @@ -13365,6 +13368,7 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) int fFpga; int fOneHot; int fRandom; + int fGraph; int fVerbose; char * FileName; char Command[1000]; @@ -13376,6 +13380,7 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) extern void Abc_GenFpga( char * pFileName, int nLutSize, int nLuts, int nVars ); extern void Abc_GenOneHot( char * pFileName, int nVars ); extern void Abc_GenRandom( char * pFileName, int nPis ); + extern void Abc_GenGraph( char * pFileName, int nPis ); extern void Abc_GenAdderTree( char * pFileName, int nArgs, int nBits ); // set defaults @@ -13390,9 +13395,10 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) fFpga = 0; fOneHot = 0; fRandom = 0; + fGraph = 0; fVerbose = 0; Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "NAKLatsembfnrvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "NAKLatsembfnrgvh" ) ) != EOF ) { switch ( c ) { @@ -13467,6 +13473,9 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) case 'r': fRandom ^= 1; break; + case 'g': + fGraph ^= 1; + break; case 'v': fVerbose ^= 1; break; @@ -13506,6 +13515,8 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_GenOneHot( FileName, nVars ); else if ( fRandom ) Abc_GenRandom( FileName, nVars ); + else if ( fGraph ) + Abc_GenGraph( FileName, nVars ); else if ( fAdderTree ) { printf( "Generating adder tree with %d arguments and %d bits.\n", nArgs, nVars ); @@ -13525,7 +13536,7 @@ int Abc_CommandGen( Abc_Frame_t * pAbc, int argc, char ** argv ) return 0; usage: - Abc_Print( -2, "usage: gen [-NAKL num] [-atsembfnrvh] \n" ); + Abc_Print( -2, "usage: gen [-NAKL num] [-atsembfnrgvh] \n" ); Abc_Print( -2, "\t generates simple circuits\n" ); Abc_Print( -2, "\t-N num : the number of variables [default = %d]\n", nVars ); Abc_Print( -2, "\t-A num : the number of agruments (for adder tree) [default = %d]\n", nArgs ); @@ -13538,6 +13549,7 @@ usage: Abc_Print( -2, "\t-m : generate a multiplier [default = %s]\n", fMulti? "yes": "no" ); Abc_Print( -2, "\t-b : generate a signed Booth multiplier [default = %s]\n", fBooth? "yes": "no" ); Abc_Print( -2, "\t-f : generate a LUT FPGA structure [default = %s]\n", fFpga? "yes": "no" ); + Abc_Print( -2, "\t-g : generate a graph structure [default = %s]\n", fGraph? "yes": "no" ); Abc_Print( -2, "\t-n : generate one-hotness conditions [default = %s]\n", fOneHot? "yes": "no" ); Abc_Print( -2, "\t-r : generate random single-output function [default = %s]\n", fRandom? "yes": "no" ); Abc_Print( -2, "\t-v : prints verbose information [default = %s]\n", fVerbose? "yes": "no" ); diff --git a/src/base/abci/abcGen.c b/src/base/abci/abcGen.c index 5d1c02cef..bea20a6d7 100644 --- a/src/base/abci/abcGen.c +++ b/src/base/abci/abcGen.c @@ -1140,6 +1140,70 @@ void Abc_GenBooth( char * pFileName, int nVars ) } +/**Function************************************************************* + + Synopsis [] + + Description [] + + SideEffects [] + + SeeAlso [] + +***********************************************************************/ +void Abc_GenGraph( char * pFileName, int nPis ) +{ + FILE * pFile; + int i, a, b, w, nDigitsIn, nWords = Abc_TruthWordNum( nPis*(nPis-1)/2 ); + unsigned * pTruth = ABC_CALLOC( unsigned, nWords ); + unsigned char M[10][10] = {{0}}, C[100][2] = {{0}}, nVars = 0; + assert( nPis <= 8 ); + for ( a = 0; a < nPis; a++ ) + for ( b = a+1; b < nPis; b++ ) + C[nVars][0] = a, C[nVars][1] = b, nVars++; + for ( i = 0; i < (1<> w) & 1; + while ( fChanges && !M[0][1] ) { + fChanges = 0; + for ( a = 0; a < nPis; a++ ) + for ( b = 0; b < nPis; b++ ) + if ( M[a][b] ) + for ( w = 0; w < nPis; w++ ) + if ( M[b][w] && !M[a][w] ) + M[a][w] = 1, fChanges = 1; + } + if ( M[0][1] ) + Abc_InfoSetBit(pTruth, i); + } + pFile = fopen( pFileName, "w" ); + fprintf( pFile, "# Function with %d inputs generated by ABC on %s\n", nVars, Extra_TimeStamp() ); + fprintf( pFile, ".model fun%d\n", nVars ); + fprintf( pFile, ".inputs" ); + nDigitsIn = Abc_Base10Log( nVars ); + for ( i = 0; i < nVars; i++ ) + fprintf( pFile, " i%0*d", nDigitsIn, i ); + fprintf( pFile, "\n" ); + fprintf( pFile, ".outputs f\n" ); + fprintf( pFile, ".names" ); + nDigitsIn = Abc_Base10Log( nVars ); + for ( b = nVars-1; b >= 0; b-- ) + fprintf( pFile, " i%0*d", nDigitsIn, b ); + fprintf( pFile, " f\n" ); + for ( i = 0; i < (1<= 0; b-- ) + fprintf( pFile, "%d", (i>>b)&1 ); + fprintf( pFile, " 1\n" ); + } + fprintf( pFile, ".end\n" ); + fprintf( pFile, "\n" ); + fclose( pFile ); + ABC_FREE( pTruth ); +} //////////////////////////////////////////////////////////////////////// /// END OF FILE ///