Commit f49e8f0f by Alan Mishchenko

Adding command 'majgen'.

parent 7522e68b
......@@ -3655,6 +3655,10 @@ SOURCE=.\src\misc\extra\extraUtilFile.c
# End Source File
# Begin Source File
SOURCE=.\src\misc\extra\extraUtilMaj.c
# End Source File
# Begin Source File
SOURCE=.\src\misc\extra\extraUtilMemory.c
# End Source File
# Begin Source File
......
......@@ -155,6 +155,7 @@ static int Abc_CommandTwoExact ( Abc_Frame_t * pAbc, int argc, cha
static int Abc_CommandLutExact ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandAllExact ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandTestExact ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandMajGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandLogic ( Abc_Frame_t * pAbc, int argc, char ** argv );
static int Abc_CommandComb ( Abc_Frame_t * pAbc, int argc, char ** argv );
......@@ -847,6 +848,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
Cmd_CommandAdd( pAbc, "Exact synthesis", "lutexact", Abc_CommandLutExact, 0 );
Cmd_CommandAdd( pAbc, "Exact synthesis", "allexact", Abc_CommandAllExact, 0 );
Cmd_CommandAdd( pAbc, "Exact synthesis", "testexact", Abc_CommandTestExact, 0 );
Cmd_CommandAdd( pAbc, "Exact synthesis", "majgen", Abc_CommandMajGen, 0 );
Cmd_CommandAdd( pAbc, "Various", "logic", Abc_CommandLogic, 1 );
Cmd_CommandAdd( pAbc, "Various", "comb", Abc_CommandComb, 1 );
......@@ -8753,6 +8755,58 @@ usage:
SeeAlso []
***********************************************************************/
int Abc_CommandMajGen( Abc_Frame_t * pAbc, int argc, char ** argv )
{
extern int Gem_Enumerate( int nVars, int fVerbose );
int c, nVars = 8, fVerbose = 0;
Extra_UtilGetoptReset();
while ( ( c = Extra_UtilGetopt( argc, argv, "Nvh" ) ) != EOF )
{
switch ( c )
{
case 'N':
if ( globalUtilOptind >= argc )
{
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
goto usage;
}
nVars = atoi(argv[globalUtilOptind]);
globalUtilOptind++;
if ( nVars < 0 )
goto usage;
break;
case 'v':
fVerbose ^= 1;
break;
case 'h':
goto usage;
default:
goto usage;
}
}
Gem_Enumerate( nVars, fVerbose );
return 0;
usage:
Abc_Print( -2, "usage: majgen [-N <num>] [-vh]>\n" );
Abc_Print( -2, "\t generates networks for majority gates\n" );
Abc_Print( -2, "\t-N <num> : the maximum number of variables [default = %d]\n", nVars );
Abc_Print( -2, "\t-v : toggle verbose printout [default = %s]\n", fVerbose ? "yes" : "no" );
Abc_Print( -2, "\t-h : print the command usage\n" );
return 1;
}
/**Function*************************************************************
Synopsis []
Description []
SideEffects []
SeeAlso []
***********************************************************************/
int Abc_CommandLogic( Abc_Frame_t * pAbc, int argc, char ** argv )
{
Abc_Ntk_t * pNtk, * pNtkRes;
......@@ -119,6 +119,7 @@ extern char * Extra_StringAppend( char * pStrGiven, char * pStrAdd );
extern void Extra_StringClean( char * pStrGiven, char * pCharKeep );
extern unsigned Extra_ReadBinary( char * Buffer );
extern void Extra_PrintBinary( FILE * pFile, unsigned Sign[], int nBits );
extern void Extra_PrintBinary2( FILE * pFile, unsigned Sign[], int nBits );
extern int Extra_ReadHex( unsigned Sign[], char * pString, int nDigits );
extern int Extra_ReadHexadecimal( unsigned Sign[], char * pString, int nVars );
extern void Extra_PrintHexadecimal( FILE * pFile, unsigned Sign[], int nVars );
......
......@@ -508,6 +508,23 @@ void Extra_PrintBinary( FILE * pFile, unsigned Sign[], int nBits )
// fprintf( pFile, "\n" );
}
void Extra_PrintBinary2( FILE * pFile, unsigned Sign[], int nBits )
{
int Remainder, nWords;
int w, i;
Remainder = (nBits%(sizeof(unsigned)*8));
nWords = (nBits/(sizeof(unsigned)*8)) + (Remainder>0);
for ( w = 0; w < nWords; w++ )
{
int Limit = w == nWords-1 ? Remainder : 32;
for ( i = 0; i < Limit; i++ )
fprintf( pFile, "%c", '0' + (int)((Sign[w] & (1<<i)) > 0) );
}
// fprintf( pFile, "\n" );
}
/**Function*************************************************************
......
......@@ -4,6 +4,7 @@ SRC += src/misc/extra/extraUtilBitMatrix.c \
src/misc/extra/extraUtilDsd.c \
src/misc/extra/extraUtilEnum.c \
src/misc/extra/extraUtilFile.c \
src/misc/extra/extraUtilMaj.c \
src/misc/extra/extraUtilMemory.c \
src/misc/extra/extraUtilMisc.c \
src/misc/extra/extraUtilMult.c \
......
......@@ -3094,6 +3094,75 @@ static inline int Abc_Tt4Check( int t )
return 0;
}
/**Function*************************************************************
Synopsis [Returns symmetry profile of the function.]
Description []
SideEffects []
SeeAlso []
***********************************************************************/
static inline int Abc_TtVarsAreSymmetric( word * pTruth, int nVars, int i, int j, word * pCof0, word * pCof1 )
{
int nWords = Abc_TtWordNum( nVars );
assert( i < nVars && j < nVars );
Abc_TtCofactor0p( pCof0, pTruth, nWords, i );
Abc_TtCofactor1p( pCof1, pTruth, nWords, i );
Abc_TtCofactor1( pCof0, nWords, j );
Abc_TtCofactor0( pCof1, nWords, j );
return Abc_TtEqual( pCof0, pCof1, nWords );
}
static inline int Abc_TtIsFullySymmetric( word * pTruth, int nVars )
{
int m, v, Polar = 0, Seen = 0;
for ( m = 0; m < (1<<nVars); m++ )
{
int Count = 0;
int Value = Abc_TtGetBit( pTruth, m );
for ( v = 0; v < nVars; v++ )
Count += ((m >> v) & 1);
if ( (Seen >> Count) & 1 ) // seen this count
{
if ( Value != ((Polar >> Count) & 1) )
return -1;
}
else // new count
{
Seen |= 1 << Count;
if ( Value )
Polar |= 1 << Count;
}
}
return Polar;
}
static inline void Abc_TtGenFullySymmetric( word * pTruth, int nVars, int Polar )
{
int m, v, nWords = Abc_TtWordNum( nVars );
Abc_TtClear( pTruth, nWords );
for ( m = 0; m < (1<<nVars); m++ )
{
int Count = 0;
for ( v = 0; v < nVars; v++ )
Count += ((m >> v) & 1);
if ( (Polar >> Count) & 1 )
Abc_TtSetBit( pTruth, m );
}
}
static inline void Abc_TtTestFullySymmetric()
{
word pTruth[4]; // 8-var function
int PolarOut, PolarIn = 271;
Abc_TtGenFullySymmetric( pTruth, 8, PolarIn );
//Abc_TtXorBit( pTruth, 171 );
PolarOut = Abc_TtIsFullySymmetric( pTruth, 8 );
assert( PolarIn == PolarOut );
}
/*=== utilTruth.c ===========================================================*/
......
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