ABC: A System for Sequential Synthesis and Verification
 
Loading...
Searching...
No Matches
ifDec66.c File Reference
#include "if.h"
#include "bool/kit/kit.h"
#include "misc/vec/vecMem.h"
Include dependency graph for ifDec66.c:

Go to the source code of this file.

Classes

struct  If_Grp_t_
 
struct  If_Hte_t_
 

Macros

#define CLU_VAR_MAX   11
 
#define CLU_MEM_MAX   1000
 
#define CLU_UNUSED   0xff
 

Functions

unsigned int If_CluPrimeCudd2 (unsigned int p)
 
int If_CluHashFindMedian2 (If_Man_t *p, int t)
 
int If_CluHashKey2 (word *pTruth, int nWords, int Size)
 
unsigned * If_CluHashLookup2 (If_Man_t *p, word *pTruth, int t)
 
int If_CluCheckXX (If_Man_t *p, word *pTruth0, int lutSize, int nVars, int fHashing)
 
int If_CluCheckXXExt (void *pMan, word *pTruth, int nVars, int nLutLeaf, int nLutRoot, char *pLut0, char *pLut1, word *pFunc0, word *pFunc1)
 
int If_CutPerformCheckXX (If_Man_t *p, unsigned *pTruth0, int nVars, int nLeaves, char *pStr)
 

Macro Definition Documentation

◆ CLU_MEM_MAX

#define CLU_MEM_MAX   1000

Definition at line 28 of file ifDec66.c.

◆ CLU_UNUSED

#define CLU_UNUSED   0xff

Definition at line 29 of file ifDec66.c.

◆ CLU_VAR_MAX

#define CLU_VAR_MAX   11

CFile****************************************************************

FileName [ifDec66.c]

SystemName [ABC: Logic synthesis and verification system.]

PackageName [FPGA mapping based on priority cuts.]

Synopsis [Fast checking procedures.]

Author [Alessandro Tempia Calvino]

Affiliation [EPFL]

Date [Ver. 1.0. Started - Feb 8, 2024.]

Revision [

Id
ifDec66.c,v 1.00 2008/02/08 00:00:00 tempia Exp

]

Definition at line 27 of file ifDec66.c.

Function Documentation

◆ If_CluCheckXX()

int If_CluCheckXX ( If_Man_t * p,
word * pTruth0,
int lutSize,
int nVars,
int fHashing )

Definition at line 276 of file ifDec66.c.

277{
278 If_Grp_t G1 = {0};
279 unsigned * pHashed = NULL;
280
281 if ( p && fHashing )
282 {
283 pHashed = If_CluHashLookup2( p, pTruth0, 0 );
284 if ( pHashed && *pHashed != CLU_UNUSED )
285 If_CluUns2Grp2( *pHashed, &G1 );
286 }
287
288 /* new entry */
289 if ( G1.nVars == 0 )
290 {
291 G1.nVars = acdXX_evaluate( pTruth0, lutSize, nVars );
292 }
293
294 if ( pHashed )
295 *pHashed = If_CluGrp2Uns2( &G1 );
296
297 return G1.nVars;
298}
int acdXX_evaluate(word *pTruth, unsigned lutSize, unsigned nVars)
Cube * p
Definition exorList.c:222
#define CLU_UNUSED
Definition ifDec16.c:34
struct If_Grp_t_ If_Grp_t
DECLARATIONS ///.
Definition ifDec16.c:37
unsigned * If_CluHashLookup2(If_Man_t *p, word *pTruth, int t)
Definition ifDec66.c:183
char nVars
Definition ifDec16.c:40
Here is the call graph for this function:
Here is the caller graph for this function:

◆ If_CluCheckXXExt()

int If_CluCheckXXExt ( void * pMan,
word * pTruth,
int nVars,
int nLutLeaf,
int nLutRoot,
char * pLut0,
char * pLut1,
word * pFunc0,
word * pFunc1 )

Definition at line 301 of file ifDec66.c.

303{
304 (void)pMan;
305 assert( nLutLeaf == nLutRoot );
306 unsigned char result[32];
307 int i;
308
309 if ( acdXX_decompose( pTruth, nLutRoot, nVars, result ) )
310 {
311 /* decomposition failed */
312 return 0;
313 }
314
315 /* copy LUT bound set */
316 unsigned char * pResult = result + 2;
317 int Lut1Size = (int) (*pResult++);
318 pLut1[0] = Lut1Size;
319 pLut1[1] = 0; /* not used */
320 for (i = 0; i < Lut1Size; ++i)
321 {
322 pLut1[2+i] = *pResult++;
323 }
324 int func_num_bytes = ( Lut1Size <= 3 ) ? 1 : ( 1 << ( Lut1Size - 3 ) );
325 *pFunc1 = 0;
326 for (i = 0; i < func_num_bytes; ++i)
327 {
328 *pFunc1 |= ( ( (word) *pResult++ ) & 0xFF ) << 8*i;
329 }
330
331 /* copy LUT composition */
332 int Lut0Size = (int) (*pResult++);
333 pLut0[0] = Lut0Size;
334 pLut0[1] = 0; /* not used */
335 for (i = 0; i < Lut0Size; ++i)
336 {
337 pLut0[2+i] = *pResult++;
338 }
339 func_num_bytes = ( Lut0Size <= 3 ) ? 1 : ( 1 << ( Lut0Size - 3 ) );
340 *pFunc0 = 0;
341 for (i = 0; i < func_num_bytes; ++i)
342 {
343 *pFunc0 |= ( ( (word) *pResult++ ) & 0xFF ) << 8*i;
344 }
345
346 *pFunc1 = If_CluAdjust2( *pFunc1, Lut1Size );
347 *pFunc0 = If_CluAdjust2( *pFunc0, Lut0Size );
348
349 return 1;
350}
int acdXX_decompose(word *pTruth, unsigned lutSize, unsigned nVars, unsigned char *decomposition)
unsigned __int64 word
DECLARATIONS ///.
Definition kitPerm.c:36
#define assert(ex)
Definition util_old.h:213
Here is the call graph for this function:
Here is the caller graph for this function:

◆ If_CluHashFindMedian2()

int If_CluHashFindMedian2 ( If_Man_t * p,
int t )

Definition at line 128 of file ifDec66.c.

129{
130 If_Hte_t * pEntry;
131 Vec_Int_t * vCounters;
132 int i, Max = 0, Total = 0, Half = 0;
133 vCounters = Vec_IntStart( 1000 );
134 for ( i = 0; i < p->nTableSize[t]; i++ )
135 {
136 for ( pEntry = ((If_Hte_t **)p->pHashTable[t])[i]; pEntry; pEntry = pEntry->pNext )
137 {
138 if ( Max < (int)pEntry->Counter )
139 {
140 Max = pEntry->Counter;
141 Vec_IntSetEntry( vCounters, pEntry->Counter, 0 );
142 }
143 Vec_IntAddToEntry( vCounters, pEntry->Counter, 1 );
144 Total++;
145 }
146 }
147 for ( i = Max; i > 0; i-- )
148 {
149 Half += Vec_IntEntry( vCounters, i );
150 if ( Half > Total/2 )
151 break;
152 }
153/*
154 printf( "total = %d ", Total );
155 printf( "half = %d ", Half );
156 printf( "i = %d ", i );
157 printf( "Max = %d.\n", Max );
158*/
159 Vec_IntFree( vCounters );
160 return Abc_MaxInt( i, 1 );
161}
typedefABC_NAMESPACE_IMPL_START struct Vec_Int_t_ Vec_Int_t
DECLARATIONS ///.
Definition bblif.c:37
struct If_Hte_t_ If_Hte_t
Definition ifDec16.c:46
If_Hte_t * pNext
Definition ifDec16.c:49
unsigned Counter
Definition ifDec16.c:51
Here is the caller graph for this function:

◆ If_CluHashKey2()

int If_CluHashKey2 ( word * pTruth,
int nWords,
int Size )

Definition at line 163 of file ifDec66.c.

164{
165 static unsigned BigPrimes[8] = {12582917, 25165843, 50331653, 100663319, 201326611, 402653189, 805306457, 1610612741};
166 unsigned Value = 0;
167 int i;
168 if ( nWords < 4 )
169 {
170 unsigned char * s = (unsigned char *)pTruth;
171 for ( i = 0; i < 8 * nWords; i++ )
172 Value ^= BigPrimes[i % 7] * s[i];
173 }
174 else
175 {
176 unsigned * s = (unsigned *)pTruth;
177 for ( i = 0; i < 2 * nWords; i++ )
178 Value ^= BigPrimes[i % 7] * s[i];
179 }
180 return Value % Size;
181}
int nWords
Definition abcNpn.c:127
Here is the caller graph for this function:

◆ If_CluHashLookup2()

unsigned * If_CluHashLookup2 ( If_Man_t * p,
word * pTruth,
int t )

Definition at line 183 of file ifDec66.c.

184{
185 If_Hte_t * pEntry, * pPrev;
186 int nWords, HashKey;
187 if ( p == NULL )
188 return NULL;
189 nWords = If_CluWordNum2(p->pPars->nLutSize);
190 if ( p->pMemEntries == NULL )
191 p->pMemEntries = Mem_FixedStart( sizeof(If_Hte_t) + sizeof(word) * (If_CluWordNum2(p->pPars->nLutSize) - 1) );
192 if ( p->pHashTable[t] == NULL )
193 {
194 // decide how large should be the table
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);
197// int nEntriesMax2 = 10000;
198 // create table
199 p->nTableSize[t] = If_CluPrimeCudd2( Abc_MinInt(nEntriesMax1, nEntriesMax2)/2 );
200 p->pHashTable[t] = ABC_CALLOC( void *, p->nTableSize[t] );
201 }
202 // check if this entry exists
203 HashKey = If_CluHashKey2( pTruth, nWords, p->nTableSize[t] );
204 for ( pEntry = ((If_Hte_t **)p->pHashTable[t])[HashKey]; pEntry; pEntry = pEntry->pNext )
205 if ( memcmp(pEntry->pTruth, pTruth, sizeof(word) * nWords) == 0 )
206 {
207 pEntry->Counter++;
208 return &pEntry->Group;
209 }
210 // resize the hash table
211 if ( p->nTableEntries[t] >= 2 * p->nTableSize[t] )
212 {
213 // collect useful entries
214 If_Hte_t * pPrev;
215 Vec_Ptr_t * vUseful = Vec_PtrAlloc( p->nTableEntries[t] );
216 int i, Median = If_CluHashFindMedian2( p, t );
217 for ( i = 0; i < p->nTableSize[t]; i++ )
218 {
219 for ( pEntry = ((If_Hte_t **)p->pHashTable[t])[i]; pEntry; )
220 {
221 if ( (int)pEntry->Counter > Median )
222 {
223 Vec_PtrPush( vUseful, pEntry );
224 pEntry = pEntry->pNext;
225 }
226 else
227 {
228 pPrev = pEntry->pNext;
229 Mem_FixedEntryRecycle( p->pMemEntries, (char *)pEntry );
230 pEntry = pPrev;
231 }
232 }
233 }
234 // add useful entries
235 memset( p->pHashTable[t], 0, sizeof(void *) * p->nTableSize[t] );
236 Vec_PtrForEachEntry( If_Hte_t *, vUseful, pEntry, i )
237 {
238 HashKey = If_CluHashKey2( pEntry->pTruth, nWords, p->nTableSize[t] );
239 pPrev = ((If_Hte_t **)p->pHashTable[t])[HashKey];
240 if ( pPrev == NULL || pEntry->Counter >= pPrev->Counter )
241 {
242 pEntry->pNext = pPrev;
243 ((If_Hte_t **)p->pHashTable[t])[HashKey] = pEntry;
244 }
245 else
246 {
247 while ( pPrev->pNext && pEntry->Counter < pPrev->pNext->Counter )
248 pPrev = pPrev->pNext;
249 pEntry->pNext = pPrev->pNext;
250 pPrev->pNext = pEntry;
251 }
252 }
253 p->nTableEntries[t] = Vec_PtrSize( vUseful );
254 Vec_PtrFree( vUseful );
255 }
256 // create entry
257 p->nTableEntries[t]++;
258 pEntry = (If_Hte_t *)Mem_FixedEntryFetch( p->pMemEntries );
259 memcpy( pEntry->pTruth, pTruth, sizeof(word) * nWords );
260 pEntry->Group = CLU_UNUSED;
261 pEntry->Counter = 1;
262 // insert at the beginning
263// pEntry->pNext = ((If_Hte_t **)p->pHashTable[t])[HashKey];
264// ((If_Hte_t **)p->pHashTable[t])[HashKey] = pEntry;
265 // insert at the end
266 pEntry->pNext = NULL;
267 for ( pPrev = ((If_Hte_t **)p->pHashTable[t])[HashKey]; pPrev && pPrev->pNext; pPrev = pPrev->pNext );
268 if ( pPrev == NULL )
269 ((If_Hte_t **)p->pHashTable[t])[HashKey] = pEntry;
270 else
271 pPrev->pNext = pEntry;
272 return &pEntry->Group;
273}
#define ABC_CALLOC(type, num)
Definition abc_global.h:265
#define CLU_MEM_MAX
Definition ifDec16.c:33
unsigned int If_CluPrimeCudd2(unsigned int p)
Definition ifDec66.c:76
int If_CluHashFindMedian2(If_Man_t *p, int t)
Definition ifDec66.c:128
int If_CluHashKey2(word *pTruth, int nWords, int Size)
Definition ifDec66.c:163
char * Mem_FixedEntryFetch(Mem_Fixed_t *p)
Definition mem.c:184
Mem_Fixed_t * Mem_FixedStart(int nEntrySize)
FUNCTION DEFINITIONS ///.
Definition mem.c:100
void Mem_FixedEntryRecycle(Mem_Fixed_t *p, char *pEntry)
Definition mem.c:235
unsigned Group
Definition ifDec16.c:50
word pTruth[1]
Definition ifDec16.c:52
char * memcpy()
char * memset()
int memcmp()
typedefABC_NAMESPACE_HEADER_START struct Vec_Ptr_t_ Vec_Ptr_t
INCLUDES ///.
Definition vecPtr.h:42
#define Vec_PtrForEachEntry(Type, vVec, pEntry, i)
MACRO DEFINITIONS ///.
Definition vecPtr.h:55
Here is the call graph for this function:
Here is the caller graph for this function:

◆ If_CluPrimeCudd2()

unsigned int If_CluPrimeCudd2 ( unsigned int p)

Definition at line 76 of file ifDec66.c.

77{
78 int i,pn;
79
80 p--;
81 do {
82 p++;
83 if (p&1) {
84 pn = 1;
85 i = 3;
86 while ((unsigned) (i * i) <= p) {
87 if (p % i == 0) {
88 pn = 0;
89 break;
90 }
91 i += 2;
92 }
93 } else {
94 pn = 0;
95 }
96 } while (!pn);
97 return(p);
98
99} /* end of Cudd_Prime */
Here is the caller graph for this function:

◆ If_CutPerformCheckXX()

int If_CutPerformCheckXX ( If_Man_t * p,
unsigned * pTruth0,
int nVars,
int nLeaves,
char * pStr )

Function*************************************************************

Synopsis [Performs ACD into 66 cascade.]

Description []

SideEffects []

SeeAlso []

Definition at line 363 of file ifDec66.c.

364{
365 unsigned pTruth[IF_MAX_FUNC_LUTSIZE > 5 ? 1 << (IF_MAX_FUNC_LUTSIZE - 5) : 1];
366 int Length;
367 // stretch the truth table
368 memcpy( pTruth, pTruth0, sizeof(word) * Abc_TtWordNum(nVars) );
369 Abc_TtStretch6( (word *)pTruth, nLeaves, p->pPars->nLutSize );
370
371 // if cutmin is disabled, minimize the function
372 if ( !p->pPars->fCutMin )
373 nLeaves = Abc_TtMinBase( (word *)pTruth, NULL, nLeaves, nVars );
374
375 // quit if parameters are wrong
376 Length = strlen(pStr);
377 if ( Length != 2 )
378 {
379 printf( "Wrong LUT struct (%s)\n", pStr );
380 return 0;
381 }
382
383 int lutSize = pStr[0] - '0';
384 if ( lutSize < 3 || lutSize > 6 )
385 {
386 printf( "The LUT size (%d) should belong to {3,4,5,6}.\n", lutSize );
387 return 0;
388 }
389
390 if ( nLeaves >= 2 * lutSize )
391 {
392 printf( "The cut size (%d) is too large for the LUT structure %s.\n", nLeaves, pStr );
393 return 0;
394 }
395
396 // consider trivial case
397 if ( nLeaves <= lutSize )
398 return 1;
399
400 return If_CluCheckXX(p, (word*)pTruth, lutSize, nVars, 1);
401}
int If_CluCheckXX(If_Man_t *p, word *pTruth0, int lutSize, int nVars, int fHashing)
Definition ifDec66.c:276
#define IF_MAX_FUNC_LUTSIZE
Definition if.h:55
int strlen()
Here is the call graph for this function: