28#define CLU_MEM_MAX 1000
29#define CLU_UNUSED 0xff
58static inline unsigned If_CluGrp2Uns2(
If_Grp_t * pG )
60 char * pChar = (
char *)pG;
63 for ( i = 0; i < 8; i++ )
64 Res |= ((pChar[i] & 15) << (i << 2));
68static inline void If_CluUns2Grp2(
unsigned Group,
If_Grp_t * pG )
70 char * pChar = (
char *)pG;
72 for ( i = 0; i < 8; i++ )
73 pChar[i] = ((Group >> (i << 2)) & 15);
86 while ((
unsigned) (i * i) <=
p) {
102static inline int If_CluWordNum2(
int nVars )
104 return nVars <= 6 ? 1 : 1 << (nVars-6);
107static inline word If_CluAdjust2(
word t,
int nVars )
109 assert( nVars >= 0 && nVars <= 6 );
112 t &= (((
word)1) << (1 << nVars)) - 1;
114 t |= t << (1<<nVars++);
116 t |= t << (1<<nVars++);
118 t |= t << (1<<nVars++);
120 t |= t << (1<<nVars++);
122 t |= t << (1<<nVars++);
124 t |= t << (1<<nVars++);
132 int i, Max = 0, Total = 0, Half = 0;
133 vCounters = Vec_IntStart( 1000 );
134 for ( i = 0; i <
p->nTableSize[t]; i++ )
136 for ( pEntry = ((
If_Hte_t **)
p->pHashTable[t])[i]; pEntry; pEntry = pEntry->
pNext )
138 if ( Max < (
int)pEntry->
Counter )
141 Vec_IntSetEntry( vCounters, pEntry->
Counter, 0 );
143 Vec_IntAddToEntry( vCounters, pEntry->
Counter, 1 );
147 for ( i = Max; i > 0; i-- )
149 Half += Vec_IntEntry( vCounters, i );
150 if ( Half > Total/2 )
159 Vec_IntFree( vCounters );
160 return Abc_MaxInt( i, 1 );
165 static unsigned BigPrimes[8] = {12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};
170 unsigned char * s = (
unsigned char *)pTruth;
171 for ( i = 0; i < 8 *
nWords; i++ )
172 Value ^= BigPrimes[i % 7] * s[i];
176 unsigned * s = (
unsigned *)pTruth;
177 for ( i = 0; i < 2 *
nWords; i++ )
178 Value ^= BigPrimes[i % 7] * s[i];
189 nWords = If_CluWordNum2(
p->pPars->nLutSize);
190 if (
p->pMemEntries == NULL )
192 if (
p->pHashTable[t] == NULL )
195 int nEntriesMax1 = 4 *
If_CluPrimeCudd2( Vec_PtrSize(
p->vObjs) *
p->pPars->nCutsMax );
196 int nEntriesMax2 = (int)(((
double)
CLU_MEM_MAX * (1 << 20)) / If_CluWordNum2(
p->pPars->nLutSize) / 8);
200 p->pHashTable[t] =
ABC_CALLOC(
void *,
p->nTableSize[t] );
204 for ( pEntry = ((
If_Hte_t **)
p->pHashTable[t])[HashKey]; pEntry; pEntry = pEntry->
pNext )
208 return &pEntry->
Group;
211 if (
p->nTableEntries[t] >= 2 *
p->nTableSize[t] )
215 Vec_Ptr_t * vUseful = Vec_PtrAlloc(
p->nTableEntries[t] );
217 for ( i = 0; i <
p->nTableSize[t]; i++ )
219 for ( pEntry = ((
If_Hte_t **)
p->pHashTable[t])[i]; pEntry; )
221 if ( (
int)pEntry->Counter > Median )
223 Vec_PtrPush( vUseful, pEntry );
224 pEntry = pEntry->pNext;
228 pPrev = pEntry->
pNext;
235 memset(
p->pHashTable[t], 0,
sizeof(
void *) *
p->nTableSize[t] );
239 pPrev = ((
If_Hte_t **)
p->pHashTable[t])[HashKey];
242 pEntry->
pNext = pPrev;
243 ((
If_Hte_t **)
p->pHashTable[t])[HashKey] = pEntry;
248 pPrev = pPrev->
pNext;
250 pPrev->
pNext = pEntry;
253 p->nTableEntries[t] = Vec_PtrSize( vUseful );
254 Vec_PtrFree( vUseful );
257 p->nTableEntries[t]++;
266 pEntry->
pNext = NULL;
267 for ( pPrev = ((
If_Hte_t **)
p->pHashTable[t])[HashKey]; pPrev && pPrev->
pNext; pPrev = pPrev->
pNext );
269 ((
If_Hte_t **)
p->pHashTable[t])[HashKey] = pEntry;
271 pPrev->
pNext = pEntry;
272 return &pEntry->
Group;
279 unsigned * pHashed = NULL;
285 If_CluUns2Grp2( *pHashed, &G1 );
295 *pHashed = If_CluGrp2Uns2( &G1 );
302 char * pLut0,
char * pLut1,
word * pFunc0,
word * pFunc1 )
305 assert( nLutLeaf == nLutRoot );
306 unsigned char result[32];
316 unsigned char * pResult = result + 2;
317 int Lut1Size = (int) (*pResult++);
320 for (i = 0; i < Lut1Size; ++i)
322 pLut1[2+i] = *pResult++;
324 int func_num_bytes = ( Lut1Size <= 3 ) ? 1 : ( 1 << ( Lut1Size - 3 ) );
326 for (i = 0; i < func_num_bytes; ++i)
328 *pFunc1 |= ( ( (
word) *pResult++ ) & 0xFF ) << 8*i;
332 int Lut0Size = (int) (*pResult++);
335 for (i = 0; i < Lut0Size; ++i)
337 pLut0[2+i] = *pResult++;
339 func_num_bytes = ( Lut0Size <= 3 ) ? 1 : ( 1 << ( Lut0Size - 3 ) );
341 for (i = 0; i < func_num_bytes; ++i)
343 *pFunc0 |= ( ( (
word) *pResult++ ) & 0xFF ) << 8*i;
346 *pFunc1 = If_CluAdjust2( *pFunc1, Lut1Size );
347 *pFunc0 = If_CluAdjust2( *pFunc0, Lut0Size );
368 memcpy( pTruth, pTruth0,
sizeof(
word) * Abc_TtWordNum(nVars) );
369 Abc_TtStretch6( (
word *)pTruth, nLeaves,
p->pPars->nLutSize );
372 if ( !
p->pPars->fCutMin )
373 nLeaves = Abc_TtMinBase( (
word *)pTruth, NULL, nLeaves, nVars );
379 printf(
"Wrong LUT struct (%s)\n", pStr );
383 int lutSize = pStr[0] -
'0';
384 if ( lutSize < 3 || lutSize > 6 )
386 printf(
"The LUT size (%d) should belong to {3,4,5,6}.\n", lutSize );
390 if ( nLeaves >= 2 * lutSize )
392 printf(
"The cut size (%d) is too large for the LUT structure %s.\n", nLeaves, pStr );
397 if ( nLeaves <= lutSize )
#define ABC_CALLOC(type, num)
#define ABC_NAMESPACE_IMPL_START
#define ABC_NAMESPACE_IMPL_END
int acdXX_decompose(word *pTruth, unsigned lutSize, unsigned nVars, unsigned char *decomposition)
int acdXX_evaluate(word *pTruth, unsigned lutSize, unsigned nVars)
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
struct If_Hte_t_ If_Hte_t
struct If_Grp_t_ If_Grp_t
DECLARATIONS ///.
#define CLU_VAR_MAX
DECLARATIONS ///.
int If_CluCheckXXExt(void *pMan, word *pTruth, int nVars, int nLutLeaf, int nLutRoot, char *pLut0, char *pLut1, word *pFunc0, word *pFunc1)
unsigned int If_CluPrimeCudd2(unsigned int p)
int If_CluCheckXX(If_Man_t *p, word *pTruth0, int lutSize, int nVars, int fHashing)
int If_CutPerformCheckXX(If_Man_t *p, unsigned *pTruth0, int nVars, int nLeaves, char *pStr)
unsigned * If_CluHashLookup2(If_Man_t *p, word *pTruth, int t)
int If_CluHashFindMedian2(If_Man_t *p, int t)
int If_CluHashKey2(word *pTruth, int nWords, int Size)
#define IF_MAX_FUNC_LUTSIZE
struct If_Man_t_ If_Man_t
BASIC TYPES ///.
unsigned __int64 word
DECLARATIONS ///.
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
void Mem_FixedEntryRecycle(Mem_Fixed_t *p, char *pEntry)
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.