88 printf(
"%03d: %s\n", count++, pTemp );
91 for ( i = mid; i <= end; i++ )
94 pTemp[mid] = pTemp[i];
100 pTemp[mid] = pTemp[i];
119 return ((t &
Truth[v]) >> (1<<v)) != (t & ~
Truth[v]);
136 for ( v = 0; v < 6; v++ )
157 for ( v = 0; v < nVars; v++ )
177 return (Supp & (Supp+1)) == 0;
196 uTruth = ((uTruth &
ABC_CONST(0x00000000FFFFFFFF)) << 32) | (uTruth &
ABC_CONST(0x00000000FFFFFFFF));
198 uTruth = ((uTruth &
ABC_CONST(0x0000FFFF0000FFFF)) << 16) | (uTruth &
ABC_CONST(0x0000FFFF0000FFFF));
200 uTruth = ((uTruth &
ABC_CONST(0x00FF00FF00FF00FF)) << 8) | (uTruth &
ABC_CONST(0x00FF00FF00FF00FF));
202 uTruth = ((uTruth &
ABC_CONST(0x0F0F0F0F0F0F0F0F)) << 4) | (uTruth &
ABC_CONST(0x0F0F0F0F0F0F0F0F));
204 uTruth = ((uTruth &
ABC_CONST(0x3333333333333333)) << 2) | (uTruth &
ABC_CONST(0x3333333333333333));
206 uTruth = ((uTruth &
ABC_CONST(0x5555555555555555)) << 1) | (uTruth &
ABC_CONST(0x5555555555555555));
228 return (t &
ABC_CONST(0x00000000FFFFFFFF)) + (t>>32);
244 return ((t &
Truth[v]) >> (1<<v)) | ((t & ~
Truth[v]) << (1<<v));
268 return (t & PMasks[v][0]) | ((t & PMasks[v][1]) << (1 << v)) | ((t & PMasks[v][2]) >> (1 << v));
284 int fUsePolarity = 0;
285 int fUsePermutation = 0;
286 char Temp, pSigs[13], pCanonPerm[6];
287 int v, fChange, CanonPhase = 0;
290 if ( pSigs[12] > 32 )
293 pSigs[12] = 64 - pSigs[12];
294 CanonPhase |= (1 << 6);
296 if ( fUsePolarity || fUsePermutation )
298 for ( v = 0; v < nVars; v++ )
302 pSigs[2*v] = pSigs[12] - pSigs[2*v+1];
307 for ( v = 0; v < nVars; v++ )
309 if ( pSigs[2*v] >= pSigs[2*v+1] )
311 CanonPhase |= (1 << v);
313 pSigs[2*v] = pSigs[2*v+1];
318 if ( fUsePermutation )
322 for ( v = 0; v < nVars-1; v++ )
326 if ( pSigs[2*v] >= pSigs[2*(v+1)] )
336 Temp = pCanonPerm[v];
337 pCanonPerm[v] = pCanonPerm[v+1];
338 pCanonPerm[v+1] = Temp;
341 pSigs[2*v] = pSigs[2*(v+1)];
342 pSigs[2*(v+1)] = Temp;
345 pSigs[2*v+1] = pSigs[2*(v+1)+1];
346 pSigs[2*(v+1)+1] = Temp;
355 for ( v = 0; v < nVars; v++ )
356 *pPhase |= (pCanonPerm[v] << (4 * v));
357 *pPhase |= (CanonPhase << 24);
376 word Key = (uTruth * (
word)101) ^ (uTruth * (
word)733) ^ (uTruth * (
word)1777);
394 int * pBinsOld, * ppPlace;
407 for ( i = 0; i < nBinsOld; i++ )
409 pNext = pEntry ?
Npn_ManObj(p, pEntry->iNext) : NULL;
412 pNext = pEntry ?
Npn_ManObj(p, pEntry->iNext) : NULL )
417 pEntry->iNext = *ppPlace;
449 pPlace = p->
pBins + Key;
451 pPlace = &pEntry->iNext,
453 if ( pEntry->uTruth == uTruth )
462 pEntry->uTruth = uTruth;
489 FILE * pFile = fopen( pFileName,
"r" );
492 Abc_Print( -1,
"Cannot open NPN function file \"%s\".\n", pFileName );
496 while ( fgets( pBuffer, 1000, pFile ) != NULL )
498 pToken =
strtok( pBuffer,
" \t\n" );
499 if ( pToken == NULL )
501 if ( pToken[0] ==
'#' )
503 if (
strlen(pToken) != 16 )
505 Abc_Print( 0,
"Skipping token %s that does not look like a 16-digit hex number.\n" );
510 uTruth = (((
word)Truth[1]) << 32) | (
word)Truth[0];
513 assert( pEntry->Count == 1 );
515 pToken =
strtok( NULL,
" \t\n" );
516 pEntry->Count = atoi(pToken);
534 if ( (*pp1)->Count > (*pp2)->Count )
536 if ( (*pp1)->Count < (*pp2)->Count )
556 FILE * pFile = fopen( pFileName,
"w" );
560 Abc_Print( -1,
"Cannot open NPN function file \"%s\".\n", pFileName );
564 for ( i = 0; i < p->
nBins; i++ )
571 fprintf( pFile,
" %d %d\n", pEntry->Count,
Npn_TruthSuppSize(pEntry->uTruth, 6) );
592 if ( pFileName == NULL )
603 FILE * pFile = fopen( pFileName,
"r" );
606 Abc_Print( -1,
"Cannot open NPN function file \"%s\".\n", pFileName );
651 if ( pNpnMan != NULL )
672 if ( pNpnMan != NULL )
678 Abc_Print( 1,
"Created new table with %d entries from file \"%s\".\n", pNpnMan->
nEntries, pFileName );
694 if ( pNpnMan == NULL )
696 Abc_Print( 1,
"There is no table with entries.\n" );
700 Abc_Print( 1,
"Dumped table with %d entries from file \"%s\".\n", pNpnMan->
nEntries, pFileName );
716 word uTruth = (((
word)puTruth[1]) << 32) | (
word)puTruth[0];
717 assert( nVars >= 0 && nVars <= 6 );
718 if ( pNpnMan == NULL )
720 Abc_Print( 1,
"Creating new table with 0 entries.\n" );
static int Npn_TruthSuppSize(word t, int nVars)
static int Npn_TruthCountOnes(word t)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
static int Abc_PrimeCudd(unsigned int p)
static int Npn_TruthSupport(word t)
static int Npn_ManCompareEntries(Npn_Obj_t **pp1, Npn_Obj_t **pp2)
#define ABC_REALLOC(type, obj, num)
void Npn_ManResize(Npn_Man_t *p)
void Npn_ManSaveOne(unsigned *puTruth, int nVars)
static void Vec_PtrSort(Vec_Ptr_t *p, int(*Vec_PtrSortCompare)()) ___unused
static void Vec_PtrPush(Vec_Ptr_t *p, void *Entry)
#define ABC_ALLOC(type, num)
static abctime Abc_Clock()
static int Npn_TruthIsMinBase(word t)
void Npn_ManStop(Npn_Man_t *p)
static int Npn_TruthHasVar(word t, int v)
static int Abc_MinInt(int a, int b)
void Npn_ManSave(char *pFileName)
unsigned __int64 word
DECLARATIONS ///.
#define ABC_NAMESPACE_IMPL_END
void Npn_ManWrite(Npn_Man_t *p, char *pFileName)
static word Npn_TruthCanon(word t, int nVars, int *pPhase)
static int Npn_ManHash(Npn_Man_t *p, word uTruth)
static void Abc_Print(int level, const char *format,...)
#define ABC_NAMESPACE_IMPL_START
static int Npn_ManObjNum(Npn_Man_t *p, Npn_Obj_t *pObj)
static Npn_Obj_t * Npn_ManObj(Npn_Man_t *p, int i)
static Vec_Ptr_t * Vec_PtrAlloc(int nCap)
FUNCTION DEFINITIONS ///.
Npn_Man_t * Npn_ManStart(char *pFileName)
#define ABC_CONST(number)
PARAMETERS ///.
static word Npn_TruthSwapAdjacentVars(word t, int v)
typedefABC_NAMESPACE_IMPL_START struct Npn_Obj_t_ Npn_Obj_t
DECLARATIONS ///.
static word Npn_TruthChangePhase(word t, int v)
Npn_Obj_t * Npn_ManAdd(Npn_Man_t *p, word uTruth)
#define ABC_CALLOC(type, num)
void Npn_TruthPermute_rec(char *pStr, int mid, int end)
FUNCTION DEFINITIONS ///.
static Npn_Man_t * pNpnMan
void Npn_ManLoad(char *pFileName)
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
void Npn_ManRead(Npn_Man_t *p, char *pFileName)
char * Abc_UtilStrsav(char *s)
word Npn_TruthPadWord(word uTruth, int nVars)
static void Vec_PtrFree(Vec_Ptr_t *p)