39static void Abc_NtkSymmetriesUsingBdds(
Abc_Ntk_t * pNtk,
int fNaive,
int fReorder,
int fVerbose );
40static void Abc_NtkSymmetriesUsingSandS(
Abc_Ntk_t * pNtk,
int fVerbose );
41static void Ntk_NetworkSymmsBdd( DdManager * dd,
Abc_Ntk_t * pNtk,
int fNaive,
int fVerbose );
61 if ( fUseBdds || fNaive )
62 Abc_NtkSymmetriesUsingBdds( pNtk, fNaive, fReorder, fVerbose );
64 Abc_NtkSymmetriesUsingSandS( pNtk, fVerbose );
78void Abc_NtkSymmetriesUsingSandS(
Abc_Ntk_t * pNtk,
int fVerbose )
82 printf(
"The total number of symmetries is %d.\n", nSymms );
96void Abc_NtkSymmetriesUsingBdds(
Abc_Ntk_t * pNtk,
int fNaive,
int fReorder,
int fVerbose )
100 int fGarbCollect = 1;
106 Cudd_AutodynDisable( dd );
108 Cudd_DisableGarbageCollection( dd );
109 Cudd_zddVarsFromBddVars( dd, 2 );
110clkBdd = Abc_Clock() - clk;
113 Ntk_NetworkSymmsBdd( dd, pNtk, fNaive, fVerbose );
114clkSym = Abc_Clock() - clk;
117printf(
"Statistics of BDD-based symmetry detection:\n" );
118printf(
"Algorithm = %s. Reordering = %s. Garbage collection = %s.\n",
119 fNaive?
"naive" :
"fast", fReorder?
"yes" :
"no", fGarbCollect?
"yes" :
"no" );
120ABC_PRT(
"Constructing BDDs", clkBdd );
121ABC_PRT(
"Computing symms ", clkSym );
122ABC_PRT(
"TOTAL ", clkBdd + clkSym );
136void Ntk_NetworkSymmsBdd( DdManager * dd,
Abc_Ntk_t * pNtk,
int fNaive,
int fVerbose )
149 bFunc = (DdNode *)Abc_ObjGlobalBdd( pNode );
150 nSupps += Cudd_SupportSize( dd, bFunc );
151 if ( Cudd_IsConstant(bFunc) )
161 Ntk_NetworkSymmsPrint( pNtk, pSymms );
166 printf(
"Total number of vars in functional supports = %8d.\n", nSupps );
167 printf(
"Total number of two-variable symmetries = %8d.\n", nSymms );
185 int i, k, nVars, nSize, fStart;
188 nVars = Abc_NtkCiNum(pNtk);
193 memset( pVarTaken, 0,
sizeof(
int) * nVars );
197 nSize = pSymms->
nVars;
198 for ( i = 0; i < nSize; i++ )
204 for ( k = 0; k < nSize; k++ )
208 if ( pSymms->
pSymms[i][k] == 0 )
211 assert( pVarTaken[k] == 0 );
216 printf(
" { %s", pInputNames[ pSymms->
pVars[i] ] );
220 printf(
" %s", pInputNames[ pSymms->
pVars[k] ] );
255 int Rand[16] = { 17290, 20203, 19027, 12035, 14687, 10920, 10413, 261, 2072, 16899, 4480, 6192, 3978, 8343, 745, 1370 };
256 int i,
nWords = Abc_TtWordNum(nVars);
258 Abc_TtCopy( pFunT, pFun,
nWords, 0 );
259 for ( i = 0; i < 16; i++ )
260 Abc_TtFlip( pFunT,
nWords, Rand[i] % (nVars-1) );
278 int i,
nWords = Abc_TtWordNum(nVars);
280 Abc_TtCopy( pFunB, pFun,
nWords, 1 );
281 if ( Abc_TtCompareRev(pFunB, pFun,
nWords) == 1 )
282 Abc_TtCopy( pFunB, pFun,
nWords, 0 );
283 for ( i = 0; i < (1 << nVars); i++ )
285 Abc_TtFlip( pFun,
nWords, pComp[i] );
286 if ( Abc_TtCompareRev(pFunB, pFun,
nWords) == 1 )
287 Abc_TtCopy( pFunB, pFun,
nWords, 0 );
288 Abc_TtNot( pFun,
nWords );
289 if ( Abc_TtCompareRev(pFunB, pFun,
nWords) == 1 )
290 Abc_TtCopy( pFunB, pFun,
nWords, 0 );
293 Abc_TtCopy( pFun, pFunB,
nWords, 0 );
312 Vec_Mem_t * vTtMem = Vec_MemAlloc( Abc_Truth6WordNum(nVars), 12 );
313 Vec_MemHashAlloc( vTtMem, 10000 );
314 assert( !(nVars < 1 || nVars > 16) );
315 printf(
"Generating truth tables of all symmetric functions of %d variables.\n", nVars );
316 for ( m = 0; m < (1 << (nVars+1)); m++ )
319 char Ones[100] = {0};
320 for ( k = 0; k <= nVars; k++ )
321 Ones[k] =
'0' + ((m >> k) & 1);
323 printf(
"%s : ", Ones );
324 pFun = Abc_TtSymFunGenerate( Ones, nVars );
326 pFun[0] = Abc_Tt6Stretch( pFun[0], nVars );
330 Class = Vec_MemHashInsert( vTtMem, pFun );
335 printf(
" Class %3d", Class );
340 printf(
"The number of different NPN classes is %d.\n", Vec_MemEntryNum(vTtMem) );
341 Vec_MemHashFree( vTtMem );
342 Vec_MemFreeP( &vTtMem );
void Ntk_SymFunGenerate(int nVars, int fVerbose)
void Ntk_SymTryRandomFlips(word *pFun, word *pNpn, int nVars)
ABC_NAMESPACE_IMPL_START void Abc_NtkSymmetries(Abc_Ntk_t *pNtk, int fUseBdds, int fNaive, int fReorder, int fVerbose)
DECLARATIONS ///.
void Ntk_SymFunDeriveNpn(word *pFun, int nVars, int *pComp)
struct Abc_Obj_t_ Abc_Obj_t
#define Abc_NtkForEachCo(pNtk, pCo, i)
ABC_DLL char * Abc_ObjName(Abc_Obj_t *pNode)
DECLARATIONS ///.
struct Abc_Ntk_t_ Abc_Ntk_t
ABC_DLL void * Abc_NtkFreeGlobalBdds(Abc_Ntk_t *pNtk, int fFreeMan)
ABC_DLL void * Abc_NtkBuildGlobalBdds(Abc_Ntk_t *pNtk, int fBddSizeMax, int fDropInternal, int fReorder, int fReverse, int fVerbose)
ABC_DLL char ** Abc_NtkCollectCioNames(Abc_Ntk_t *pNtk, int fCollectCos)
ABC_DLL int Abc_NtkSizeOfGlobalBdds(Abc_Ntk_t *pNtk)
#define ABC_ALLOC(type, num)
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
int Sim_ComputeTwoVarSymms(Abc_Ntk_t *pNtk, int fVerbose)
DECLARATIONS ///.
typedefABC_NAMESPACE_IMPL_START struct Vec_Mem_t_ Vec_Mem_t
DECLARATIONS ///.