71static inline int Abc_TruthHashKey(
word * pFunc,
int nWords,
int nTableSize )
73 static unsigned s_BigPrimes[7] = {12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457};
76 for ( w = 0; w <
nWords; w++ )
77 Key += pFunc[w] * s_BigPrimes[w % 7];
78 return (
int)(Key % nTableSize);
81static inline int Abc_TruthHashLookup(
word ** pFuncs,
int iThis,
int nWords,
int * pTable,
int * pNexts,
int Key )
84 for ( iThat = pTable[Key]; iThat != -1; iThat = pNexts[iThat] )
93 int nTableSize = Abc_PrimeCudd(
p->nFuncs);
98 for ( i = 0; i <
p->nFuncs; i++ )
100 Key = Abc_TruthHashKey(
p->pFuncs[i],
p->nWords, nTableSize );
101 if ( Abc_TruthHashLookup(
p->pFuncs, i,
p->nWords, pTable, pNexts, Key ) )
104 pNexts[i] = pTable[Key], pTable[Key] = i;
109 assert(
p->pFuncs[0] != NULL );
110 for ( i = k = 1; i <
p->nFuncs; i++ )
111 if (
p->pFuncs[i] != NULL )
112 p->pFuncs[k++] =
p->pFuncs[i];
113 return (
p->nFuncs = k);
135 qsort( (
void *)
p->pFuncs, (
size_t)
p->nFuncs,
sizeof(
word *), (
int(*)(
const void *,
const void *))
Abc_TruthCompare );
137 for ( i = k = 1; i <
p->nFuncs; i++ )
139 p->pFuncs[k++] =
p->pFuncs[i];
140 return (
p->nFuncs = k);
156 char pCanonPerm[16];
int i;
158 for ( i = 0; i < nVars; i++ )
159 pCanonPerm[i] = pCanonPermInit ? pCanonPermInit[i] :
'a' + i;
160 printf(
" %c = ( ", Abc_InfoHasBit(&uCanonPhase, nVars) ?
'Z':
'z' );
161 for ( i = 0; i < nVars; i++ )
162 printf(
"%c%s", pCanonPerm[i] + (
'A'-
'a') * Abc_InfoHasBit(&uCanonPhase, pCanonPerm[i]-
'a'), i == nVars-1 ?
"":
"," );
180 word pAuxWord[1024], pAuxWord1[1024];
182 unsigned uCanonPhase=0;
186 char * pAlgoName = NULL;
188 pAlgoName =
"uniqifying ";
189 else if ( NpnType == 1 )
190 pAlgoName =
"exact NPN ";
191 else if ( NpnType == 2 )
192 pAlgoName =
"counting 1s ";
193 else if ( NpnType == 3 )
194 pAlgoName =
"Jake's hybrid fast ";
195 else if ( NpnType == 4 )
196 pAlgoName =
"Jake's hybrid good ";
197 else if ( NpnType == 5 )
198 pAlgoName =
"new hybrid fast ";
199 else if ( NpnType == 6 )
200 pAlgoName =
"new phase flipping ";
201 else if ( NpnType == 7 )
202 pAlgoName =
"new hier. matching ";
203 else if ( NpnType == 8 )
204 pAlgoName =
"new adap. matching ";
205 else if ( NpnType == 9 )
206 pAlgoName =
"adjustable algorithm (heuristic) ";
207 else if ( NpnType == 10 )
208 pAlgoName =
"adjustable algorithm (exact) ";
209 else if ( NpnType == 11 )
210 pAlgoName =
"new cost-aware exact algorithm ";
211 else if ( NpnType == 12 )
212 pAlgoName =
"new hybrid fast (P) ";
216 printf(
"Applying %-20s to %8d func%s of %2d vars... ",
217 pAlgoName,
p->nFuncs, (
p->nFuncs == 1 ?
"":
"s"),
p->nVars );
223 for ( i = 0; i <
p->nFuncs; i++ )
226 printf(
"%7d : ", i );
228 Extra_PrintHex( stdout, (
unsigned *)
p->pFuncs[i],
p->nVars ), printf(
"\n" );
231 else if ( NpnType == 1 )
236 for ( i = 0; i <
p->nFuncs; i++ )
239 printf(
"%7d : ", i );
246 else if ( NpnType == 2 )
248 for ( i = 0; i <
p->nFuncs; i++ )
251 printf(
"%7d : ", i );
258 else if ( NpnType == 3 )
260 for ( i = 0; i <
p->nFuncs; i++ )
263 printf(
"%7d : ", i );
270 else if ( NpnType == 4 )
272 for ( i = 0; i <
p->nFuncs; i++ )
275 printf(
"%7d : ", i );
282 else if ( NpnType == 5 )
284 for ( i = 0; i <
p->nFuncs; i++ )
287 printf(
"%7d : ", i );
293 else if ( NpnType == 6 )
295 for ( i = 0; i <
p->nFuncs; i++ )
298 printf(
"%7d : ", i );
304 else if ( NpnType == 7 )
308 for ( i = 0; i <
p->nFuncs; i++ )
311 printf(
"%7d : ", i );
320 else if ( NpnType == 8 )
326 int fHigh = 1, iEnumThres = 25;
328 for ( i = 0; i <
p->nFuncs; i++ )
331 printf(
"%7d : ", i );
338 else if ( NpnType == 9 || NpnType == 10 || NpnType == 11 )
346 for ( i = 0; i <
p->nFuncs; i++ )
349 printf(
"%7d : ", i );
352 else if ( NpnType == 10 )
354 else if ( NpnType == 11 )
361 else if ( NpnType == 12 )
363 for ( i = 0; i <
p->nFuncs; i++ )
366 printf(
"%7d : ", i );
373 clk = Abc_Clock() - clk;
375 Abc_PrintTime( 1,
"Time", clk );
389void Abc_TruthNpnTest(
char * pFileName,
int NpnType,
int nVarNum,
int fDumpRes,
int fBinary,
int fVerbose )
411 printf(
"The resulting functions are written into file \"%s\".\n", pFileNameOut );
431int Abc_NpnTest(
char * pFileName,
int NpnType,
int nVarNum,
int fDumpRes,
int fBinary,
int fVerbose )
434 printf(
"Using truth tables from file \"%s\"...\n", pFileName );
435 if ( NpnType >= 0 && NpnType <= 12 )
436 Abc_TruthNpnTest( pFileName, NpnType, nVarNum, fDumpRes, fBinary, fVerbose );
438 printf(
"Unknown canonical form value (%d).\n", NpnType );
int Abc_TruthCompare(word **p1, word **p2)
int Abc_TruthNpnCountUnique(Abc_TtStore_t *p)
void Abc_TruthNpnTest(char *pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose)
void Abc_TruthNpnPrint(char *pCanonPermInit, unsigned uCanonPhase, int nVars)
int Abc_NpnTest(char *pFileName, int NpnType, int nVarNum, int fDumpRes, int fBinary, int fVerbose)
int Abc_TruthNpnCountUniqueSort(Abc_TtStore_t *p)
void Abc_TtStoreWrite(char *pFileName, Abc_TtStore_t *p, int fBinary)
void Abc_TtStoreFree(Abc_TtStore_t *p, int nVarNum)
Abc_TtStore_t * Abc_TtStoreLoad(char *pFileName, int nVarNum)
void Abc_TruthNpnPerform(Abc_TtStore_t *p, int NpnType, int fVerbose)
#define ABC_FALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
void freePermInfoPtr(permInfo *x)
void simpleMinimal(word *x, word *pAux, word *minimal, permInfo *pi, int nVars)
void resetPCanonPermArray(char *x, int nVars)
unsigned luckyCanonicizer_final_fast1(word *pInOut, int nVars, char *pCanonPerm)
permInfo * setPermInfoPtr(int var)
unsigned luckyCanonicizer_final_fast(word *pInOut, int nVars, char *pCanonPerm)
unsigned Abc_TtCanonicizeCA(Abc_TtHieMan_t *p, word *pTruth, int nVars, char *pCanonPerm, int fCA)
struct Abc_TtHieMan_t_ Abc_TtHieMan_t
unsigned Abc_TtCanonicizePhase(word *pTruth, int nVars)
unsigned(* TtCanonicizeFunc)(Abc_TtHieMan_t *p, word *pTruth, int nVars, char *pCanonPerm, int flag)
unsigned Abc_TtCanonicizePerm(word *pTruth, int nVars, char *pCanonPerm)
unsigned Abc_TtCanonicizeAda(Abc_TtHieMan_t *p, word *pTruth, int nVars, char *pCanonPerm, int iThres)
unsigned Abc_TtCanonicizeHie(Abc_TtHieMan_t *p, word *pTruth, int nVars, char *pCanonPerm, int fExact)
Abc_TtHieMan_t * Abc_TtHieManStart(int nVars, int nLevels)
void Abc_TtHieManStop(Abc_TtHieMan_t *p)
unsigned Abc_TtCanonicizeWrap(TtCanonicizeFunc func, Abc_TtHieMan_t *p, word *pTruth, int nVars, char *pCanonPerm, int flag)
unsigned Abc_TtCanonicize(word *pTruth, int nVars, char *pCanonPerm)
FUNCTION DECLARATIONS ///.
void Extra_PrintHex(FILE *pFile, unsigned *pTruth, int nVars)
unsigned __int64 word
DECLARATIONS ///.
unsigned Kit_TruthSemiCanonicize(unsigned *pInOut, unsigned *pAux, int nVars, char *pCanonPerm)