Skip to content

Commit 362661f

Browse files
committed
Command "genpop".
1 parent e67af0a commit 362661f

File tree

4 files changed

+411
-6
lines changed

4 files changed

+411
-6
lines changed

src/aig/gia/giaTruth.c

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "misc/vec/vecMem.h"
2323
#include "misc/vec/vecWec.h"
2424
#include "misc/util/utilTruth.h"
25+
#include "bool/lucky/lucky.h"
2526
#include "opt/dau/dau.h"
2627

2728
ABC_NAMESPACE_IMPL_START
@@ -809,10 +810,73 @@ Gia_Man_t * Gia_ManIsoNpnReduce( Gia_Man_t * p, Vec_Ptr_t ** pvPosEquivs, int fV
809810
return pNew;
810811
}
811812

813+
/**Function*************************************************************
814+
815+
Synopsis []
816+
817+
Description []
818+
819+
SideEffects []
820+
821+
SeeAlso []
822+
823+
***********************************************************************/
824+
void Gia_ManNodeFunctionProfile( Gia_Man_t * p, int nVars )
825+
{
826+
int fCanonicize = 1;
827+
Gia_Obj_t * pObj;
828+
Vec_Int_t * vLeaves = Vec_IntAlloc( 100 );
829+
int nWords = Abc_Truth6WordNum( nVars );
830+
Vec_Mem_t * pTtMem = Vec_MemAlloc( nWords, 12 ); // supports up to nVars words
831+
Vec_MemHashAlloc( pTtMem, 1000 );
832+
Vec_Int_t * vCounts = Vec_IntAlloc( 100 );
833+
permInfo * pi = setPermInfoPtr( nVars );
834+
word pAuxWord[DAU_MAX_WORD], pAuxWord1[DAU_MAX_WORD], Truth[DAU_MAX_WORD], * pTruth; int i;
835+
assert( nVars <= 7 );
836+
Gia_ObjComputeTruthTableStart( p, nVars );
837+
Gia_ManForEachAnd( p, pObj, i ) {
838+
if ( Gia_ManSuppSize(p, &i, 1) != nVars )
839+
continue;
840+
Gia_ManCollectCis( p, &i, 1, vLeaves );
841+
assert( Vec_IntSize(vLeaves) == nVars );
842+
pTruth = Gia_ObjComputeTruthTableCut( p, pObj, vLeaves );
843+
if ( fCanonicize ) {
844+
memcpy( Truth, pTruth, sizeof(word) * nWords );
845+
simpleMinimal( Truth, pAuxWord, pAuxWord1, pi, nVars ); // NPN canonical form
846+
}
847+
else {
848+
memcpy( Truth, pTruth, sizeof(word) * nWords );
849+
}
850+
{
851+
int nEntries = Vec_MemEntryNum( pTtMem );
852+
int Value = Vec_MemHashInsert( pTtMem, Truth );
853+
if ( Vec_MemEntryNum( pTtMem ) == nEntries )
854+
Vec_IntAddToEntry( vCounts, Value, 1 );
855+
else
856+
{
857+
assert( Value == nEntries );
858+
Vec_IntPush( vCounts, 1 );
859+
}
860+
}
861+
}
862+
for ( i = 0; i < Vec_MemEntryNum(pTtMem); i++ ) {
863+
word * pCanon = Vec_MemReadEntry( pTtMem, i );
864+
int Count = Vec_IntEntry( vCounts, i );
865+
Abc_TtPrintHexRev( stdout, pCanon, nVars );
866+
printf( " %d\n", Count );
867+
}
868+
Gia_ObjComputeTruthTableStop( p );
869+
Vec_IntFree( vLeaves );
870+
Vec_IntFree( vCounts );
871+
Vec_MemHashFree( pTtMem );
872+
Vec_MemFree( pTtMem );
873+
freePermInfoPtr( pi );
874+
}
875+
876+
812877
////////////////////////////////////////////////////////////////////////
813878
/// END OF FILE ///
814879
////////////////////////////////////////////////////////////////////////
815880

816881

817882
ABC_NAMESPACE_IMPL_END
818-

src/base/abci/abc.c

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ static int Abc_CommandEspresso ( Abc_Frame_t * pAbc, int argc, cha
229229
static int Abc_CommandGen ( Abc_Frame_t * pAbc, int argc, char ** argv );
230230
static int Abc_CommandGenTF ( Abc_Frame_t * pAbc, int argc, char ** argv );
231231
static int Abc_CommandGenAT ( Abc_Frame_t * pAbc, int argc, char ** argv );
232+
static int Abc_CommandGenPop ( Abc_Frame_t * pAbc, int argc, char ** argv );
232233
static int Abc_CommandGenFsm ( Abc_Frame_t * pAbc, int argc, char ** argv );
233234
static int Abc_CommandCover ( Abc_Frame_t * pAbc, int argc, char ** argv );
234235
static int Abc_CommandDouble ( Abc_Frame_t * pAbc, int argc, char ** argv );
@@ -1060,6 +1061,7 @@ void Abc_Init( Abc_Frame_t * pAbc )
10601061
Cmd_CommandAdd( pAbc, "Various", "gen", Abc_CommandGen, 0 );
10611062
Cmd_CommandAdd( pAbc, "Various", "gentf", Abc_CommandGenTF, 0 );
10621063
Cmd_CommandAdd( pAbc, "Various", "genat", Abc_CommandGenAT, 0 );
1064+
Cmd_CommandAdd( pAbc, "Various", "genpop", Abc_CommandGenPop, 0 );
10631065
Cmd_CommandAdd( pAbc, "Various", "genfsm", Abc_CommandGenFsm, 0 );
10641066
Cmd_CommandAdd( pAbc, "Various", "cover", Abc_CommandCover, 1 );
10651067
Cmd_CommandAdd( pAbc, "Various", "double", Abc_CommandDouble, 1 );
@@ -16031,6 +16033,81 @@ int Abc_CommandGenAT( Abc_Frame_t * pAbc, int argc, char ** argv )
1603116033
return 1;
1603216034
}
1603316035

16036+
/**Function*************************************************************
16037+
16038+
Synopsis []
16039+
16040+
Description []
16041+
16042+
SideEffects []
16043+
16044+
SeeAlso []
16045+
16046+
***********************************************************************/
16047+
int Abc_CommandGenPop( Abc_Frame_t * pAbc, int argc, char ** argv )
16048+
{
16049+
extern Abc_Ntk_t * Abc_NtkLutCascadeFromPopcountLuts( int nVars, int nLutSize, int fVerbose, char * pFileName );
16050+
char * pFileName = NULL;
16051+
Abc_Ntk_t * pNtk = NULL;
16052+
int c, nVars = 10, nLutSize = 6, fVerbose = 0;
16053+
Extra_UtilGetoptReset();
16054+
while ( ( c = Extra_UtilGetopt( argc, argv, "NKvh" ) ) != EOF )
16055+
{
16056+
switch ( c )
16057+
{
16058+
case 'N':
16059+
if ( globalUtilOptind >= argc )
16060+
{
16061+
Abc_Print( -1, "Command line switch \"-N\" should be followed by an integer.\n" );
16062+
goto usage;
16063+
}
16064+
nVars = atoi(argv[globalUtilOptind]);
16065+
globalUtilOptind++;
16066+
if ( nVars < 0 )
16067+
goto usage;
16068+
break;
16069+
case 'K':
16070+
if ( globalUtilOptind >= argc )
16071+
{
16072+
Abc_Print( -1, "Command line switch \"-K\" should be followed by an integer.\n" );
16073+
goto usage;
16074+
}
16075+
nLutSize = atoi(argv[globalUtilOptind]);
16076+
globalUtilOptind++;
16077+
if ( nLutSize < 0 )
16078+
goto usage;
16079+
break;
16080+
case 'v':
16081+
fVerbose ^= 1;
16082+
break;
16083+
case 'h':
16084+
goto usage;
16085+
default:
16086+
goto usage;
16087+
}
16088+
}
16089+
if ( argc == globalUtilOptind + 1 )
16090+
pFileName = argv[globalUtilOptind];
16091+
pNtk = Abc_NtkLutCascadeFromPopcountLuts( nVars, nLutSize, fVerbose, pFileName );
16092+
if ( pNtk == NULL )
16093+
{
16094+
fprintf( pAbc->Err, "Deriving the network has failed.\n" );
16095+
return 1;
16096+
}
16097+
Abc_FrameReplaceCurrentNetwork( pAbc, pNtk );
16098+
return 0;
16099+
16100+
usage:
16101+
Abc_Print( -2, "usage: genpop [-NK num] [-vh] <file.v>\n" );
16102+
Abc_Print( -2, "\t generates the adder tree\n" );
16103+
Abc_Print( -2, "\t-N <num> : the number of support variables [default = %d]\n", nVars );
16104+
Abc_Print( -2, "\t-K <num> : the number of LUT inputs [default = %d]\n", nLutSize );
16105+
Abc_Print( -2, "\t-v : prints verbose information [default = %s]\n", fVerbose? "yes": "no" );
16106+
Abc_Print( -2, "\t-h : print the command usage\n");
16107+
Abc_Print( -2, "\t-<file.v> : (optional) Verilog file name\n");
16108+
return 1;
16109+
}
16110+
1603416111
/**Function*************************************************************
1603516112

1603616113
Synopsis []

0 commit comments

Comments
 (0)