From 091ff4e7a9adf6ee5a7705d99b27de571eb7edbc Mon Sep 17 00:00:00 2001 From: Alan Mishchenko Date: Tue, 5 Nov 2024 19:23:04 -0800 Subject: [PATCH] Adding generation of random functions to "lutexact" --- src/base/abci/abc.c | 23 +++++++++++++++++++---- src/sat/bmc/bmc.h | 1 + src/sat/bmc/bmcMaj.c | 17 +++++++++++++++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/base/abci/abc.c b/src/base/abci/abc.c index 6bf1c2338..ec891dea8 100644 --- a/src/base/abci/abc.c +++ b/src/base/abci/abc.c @@ -9805,11 +9805,12 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) { extern void Exa3_ManExactSynthesis( Bmc_EsPar_t * pPars ); extern void Exa3_ManExactSynthesis2( Bmc_EsPar_t * pPars ); + extern void Exa3_ManExactSynthesisRand( Bmc_EsPar_t * pPars ); int c; Bmc_EsPar_t Pars, * pPars = &Pars; Bmc_EsParSetDefault( pPars ); Extra_UtilGetoptReset(); - while ( ( c = Extra_UtilGetopt( argc, argv, "INKTSiaocgvh" ) ) != EOF ) + while ( ( c = Extra_UtilGetopt( argc, argv, "INKTSRiaocgvh" ) ) != EOF ) { switch ( c ) { @@ -9866,6 +9867,15 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) pPars->pSymStr = argv[globalUtilOptind]; globalUtilOptind++; break; + case 'R': + if ( globalUtilOptind >= argc ) + { + Abc_Print( -1, "Command line switch \"-R\" should be followed by a file name.\n" ); + goto usage; + } + pPars->nRandFuncs = atoi(argv[globalUtilOptind]); + globalUtilOptind++; + break; case 'i': pPars->fUseIncr ^= 1; break; @@ -9892,7 +9902,7 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) } if ( argc == globalUtilOptind + 1 ) pPars->pTtStr = argv[globalUtilOptind]; - if ( pPars->pTtStr == NULL && pPars->pSymStr == NULL ) + if ( pPars->pTtStr == NULL && pPars->pSymStr == NULL && pPars->nRandFuncs == 0 ) { Abc_Print( -1, "Truth table should be given on the command line.\n" ); return 1; @@ -9922,19 +9932,24 @@ int Abc_CommandLutExact( Abc_Frame_t * pAbc, int argc, char ** argv ) Abc_Print( -1, "Node size should not be more than 6 inputs.\n" ); return 1; } - if ( pPars->fGlucose ) + if ( pPars->nRandFuncs ) { + pPars->fGlucose = 1; + Exa3_ManExactSynthesisRand( pPars ); + } + else if ( pPars->fGlucose ) Exa3_ManExactSynthesis( pPars ); else Exa3_ManExactSynthesis2( pPars ); return 0; usage: - Abc_Print( -2, "usage: lutexact [-INKT ] [-S string] [-iaocgvh] \n" ); + Abc_Print( -2, "usage: lutexact [-INKTR ] [-S string] [-iaocgvh] \n" ); Abc_Print( -2, "\t exact synthesis of I-input function using N K-input gates\n" ); Abc_Print( -2, "\t-I : the number of input variables [default = %d]\n", pPars->nVars ); Abc_Print( -2, "\t-N : the number of K-input nodes [default = %d]\n", pPars->nNodes ); Abc_Print( -2, "\t-K : the number of node fanins [default = %d]\n", pPars->nLutSize ); Abc_Print( -2, "\t-T : the runtime limit in seconds [default = %d]\n", pPars->RuntimeLim ); + Abc_Print( -2, "\t-R : the number of random functions to try [default = unused]\n" ); Abc_Print( -2, "\t-S : charasteristic string of a symmetric function [default = %d]\n", pPars->pSymStr ); Abc_Print( -2, "\t-i : toggle using incremental solving [default = %s]\n", pPars->fUseIncr ? "yes" : "no" ); Abc_Print( -2, "\t-a : toggle using only AND-gates when K = 2 [default = %s]\n", pPars->fOnlyAnd ? "yes" : "no" ); diff --git a/src/sat/bmc/bmc.h b/src/sat/bmc/bmc.h index 11578a56b..f39a09726 100644 --- a/src/sat/bmc/bmc.h +++ b/src/sat/bmc/bmc.h @@ -64,6 +64,7 @@ struct Bmc_EsPar_t_ int fUniqFans; int fLutCascade; int RuntimeLim; + int nRandFuncs; int fVerbose; char * pTtStr; char * pSymStr; diff --git a/src/sat/bmc/bmcMaj.c b/src/sat/bmc/bmcMaj.c index f89d74ea1..d03b1aba0 100644 --- a/src/sat/bmc/bmcMaj.c +++ b/src/sat/bmc/bmcMaj.c @@ -1555,6 +1555,23 @@ void Exa3_ManExactSynthesis( Bmc_EsPar_t * pPars ) ABC_FREE( pPars->pTtStr ); Exa3_ManFree( p ); } +void Exa3_ManExactSynthesisRand( Bmc_EsPar_t * pPars ) +{ + int i, k, nWords = Abc_TtWordNum(pPars->nVars); + word * pFun = ABC_ALLOC( word, nWords ); + Abc_RandomW(1); + for ( i = 0; i < pPars->nRandFuncs; i++ ) { + for ( k = 0; k < nWords; k++ ) + pFun[k] = Abc_RandomW(0); + pPars->pTtStr = ABC_CALLOC( char, pPars->nVars > 2 ? (1 << (pPars->nVars-2)) + 1 : 2 ); + Extra_PrintHexadecimalString( pPars->pTtStr, (unsigned *)pFun, pPars->nVars ); + printf( "Generated random function: %s\n", pPars->pTtStr ); + Exa3_ManExactSynthesis( pPars ); + ABC_FREE( pPars->pTtStr ); + } + ABC_FREE( pFun ); +} + /**Function*************************************************************