SVF
Functions | Variables
cuddCache.c File Reference
#include "CUDD/util.h"
#include "CUDD/cuddInt.h"

Go to the source code of this file.

Functions

int cuddInitCache (DdManager *unique, unsigned int cacheSize, unsigned int maxCacheSize)
 
void cuddCacheInsert (DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h, DdNode *data)
 
void cuddCacheInsert2 (DdManager *table, DD_CTFP op, DdNode *f, DdNode *g, DdNode *data)
 
void cuddCacheInsert1 (DdManager *table, DD_CTFP1 op, DdNode *f, DdNode *data)
 
DdNodecuddCacheLookup (DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
 
DdNodecuddCacheLookupZdd (DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
 
DdNodecuddCacheLookup2 (DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
 
DdNodecuddCacheLookup1 (DdManager *table, DD_CTFP1 op, DdNode *f)
 
DdNodecuddCacheLookup2Zdd (DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
 
DdNodecuddCacheLookup1Zdd (DdManager *table, DD_CTFP1 op, DdNode *f)
 
DdNodecuddConstantLookup (DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
 
int cuddCacheProfile (DdManager *table, FILE *fp)
 
void cuddCacheResize (DdManager *table)
 
void cuddCacheFlush (DdManager *table)
 
int cuddComputeFloorLog2 (unsigned int value)
 

Variables

static char rcsid [] DD_UNUSED = "$Id: cuddCache.c,v 1.36 2012/02/05 01:07:18 fabio Exp $"
 

Function Documentation

◆ cuddCacheFlush()

void cuddCacheFlush ( DdManager table)

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

Synopsis [Flushes the cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1004 of file cuddCache.c.

1006 {
1007  int i, slots;
1008  DdCache *cache;
1009 
1010  slots = table->cacheSlots;
1011  cache = table->cache;
1012  for (i = 0; i < slots; i++) {
1013  table->cachedeletions += cache[i].data != NULL;
1014  cache[i].data = NULL;
1015  }
1016  table->cacheLastInserts = table->cacheinserts;
1017 
1018  return;
1019 
1020 } /* end of cuddCacheFlush */
DdNode * data
Definition: cuddInt.h:304
double cacheinserts
Definition: cuddInt.h:438
unsigned int cacheSlots
Definition: cuddInt.h:337
DdCache * cache
Definition: cuddInt.h:336
double cacheLastInserts
Definition: cuddInt.h:439
double cachedeletions
Definition: cuddInt.h:440

◆ cuddCacheInsert()

void cuddCacheInsert ( DdManager table,
ptruint  op,
DdNode f,
DdNode g,
DdNode h,
DdNode data 
)

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

Synopsis [Inserts a result in the cache for a function with three operands.]

Description [Inserts a result in the cache for a function with three operands. The operator tag (see CUDD/cuddInt.h for details) is split and stored into unused bits of the first two pointers.]

SideEffects [None]

SeeAlso [cuddCacheInsert2 cuddCacheInsert1]

Definition at line 217 of file cuddCache.c.

224 {
225  int posn;
226  register DdCache *entry;
227  ptruint uf, ug, uh;
228 
229  uf = (ptruint) f | (op & 0xe);
230  ug = (ptruint) g | (op >> 4);
231  uh = (ptruint) h;
232 
233  posn = ddCHash2(uh,uf,ug,table->cacheShift);
234  entry = &table->cache[posn];
235 
236  table->cachecollisions += entry->data != NULL;
237  table->cacheinserts++;
238 
239  entry->f = (DdNode *) uf;
240  entry->g = (DdNode *) ug;
241  entry->h = uh;
242  entry->data = data;
243 #ifdef DD_CACHE_PROFILE
244  entry->count++;
245 #endif
246 
247 } /* end of cuddCacheInsert */
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
DdNode * g
Definition: cuddInt.h:302
double cachecollisions
Definition: cuddInt.h:437
double cacheinserts
Definition: cuddInt.h:438
static int * entry
Definition: cuddGroup.c:119
DdCache * cache
Definition: cuddInt.h:336
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
int cacheShift
Definition: cuddInt.h:338

◆ cuddCacheInsert1()

void cuddCacheInsert1 ( DdManager table,
DD_CTFP1  op,
DdNode f,
DdNode data 
)

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

Synopsis [Inserts a result in the cache for a function with two operands.]

Description []

SideEffects [None]

SeeAlso [cuddCacheInsert cuddCacheInsert2]

Definition at line 305 of file cuddCache.c.

310 {
311  int posn;
312  register DdCache *entry;
313 
314  posn = ddCHash2(op,f,f,table->cacheShift);
315  entry = &table->cache[posn];
316 
317  if (entry->data != NULL) {
318  table->cachecollisions++;
319  }
320  table->cacheinserts++;
321 
322  entry->f = f;
323  entry->g = f;
324  entry->h = (ptruint) op;
325  entry->data = data;
326 #ifdef DD_CACHE_PROFILE
327  entry->count++;
328 #endif
329 
330 } /* end of cuddCacheInsert1 */
DdNode * f
Definition: cuddInt.h:302
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
DdNode * g
Definition: cuddInt.h:302
double cachecollisions
Definition: cuddInt.h:437
double cacheinserts
Definition: cuddInt.h:438
static int * entry
Definition: cuddGroup.c:119
DdCache * cache
Definition: cuddInt.h:336
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
int cacheShift
Definition: cuddInt.h:338

◆ cuddCacheInsert2()

void cuddCacheInsert2 ( DdManager table,
DD_CTFP  op,
DdNode f,
DdNode g,
DdNode data 
)

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

Synopsis [Inserts a result in the cache for a function with two operands.]

Description []

SideEffects [None]

SeeAlso [cuddCacheInsert cuddCacheInsert1]

Definition at line 263 of file cuddCache.c.

269 {
270  int posn;
271  register DdCache *entry;
272 
273  posn = ddCHash2(op,f,g,table->cacheShift);
274  entry = &table->cache[posn];
275 
276  if (entry->data != NULL) {
277  table->cachecollisions++;
278  }
279  table->cacheinserts++;
280 
281  entry->f = f;
282  entry->g = g;
283  entry->h = (ptruint) op;
284  entry->data = data;
285 #ifdef DD_CACHE_PROFILE
286  entry->count++;
287 #endif
288 
289 } /* end of cuddCacheInsert2 */
DdNode * f
Definition: cuddInt.h:302
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
DdNode * g
Definition: cuddInt.h:302
double cachecollisions
Definition: cuddInt.h:437
double cacheinserts
Definition: cuddInt.h:438
static int * entry
Definition: cuddGroup.c:119
DdCache * cache
Definition: cuddInt.h:336
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
int cacheShift
Definition: cuddInt.h:338

◆ cuddCacheLookup()

DdNode* cuddCacheLookup ( DdManager table,
ptruint  op,
DdNode f,
DdNode g,
DdNode h 
)

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

Synopsis [Looks up in the cache for the result of op applied to f, g, and h.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookup2 cuddCacheLookup1]

Definition at line 347 of file cuddCache.c.

353 {
354  int posn;
355  DdCache *en,*cache;
356  DdNode *data;
357  ptruint uf, ug, uh;
358 
359  uf = (ptruint) f | (op & 0xe);
360  ug = (ptruint) g | (op >> 4);
361  uh = (ptruint) h;
362 
363  cache = table->cache;
364 #ifdef DD_DEBUG
365  if (cache == NULL) {
366  return(NULL);
367  }
368 #endif
369 
370  posn = ddCHash2(uh,uf,ug,table->cacheShift);
371  en = &cache[posn];
372  if (en->data != NULL && en->f==(DdNodePtr)uf && en->g==(DdNodePtr)ug &&
373  en->h==uh) {
374  data = Cudd_Regular(en->data);
375  table->cacheHits++;
376  if (data->ref == 0) {
377  cuddReclaim(table,data);
378  }
379  return(en->data);
380  }
381 
382  /* Cache miss: decide whether to resize. */
383  table->cacheMisses++;
384 
385  if (table->cacheSlack >= 0 &&
386  table->cacheHits > table->cacheMisses * table->minHit) {
387  cuddCacheResize(table);
388  }
389 
390  return(NULL);
391 
392 } /* end of cuddCacheLookup */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
void cuddReclaim(DdManager *table, DdNode *n)
Definition: cuddRef.c:580
DdNode * g
Definition: cuddInt.h:302
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheLookup1()

DdNode* cuddCacheLookup1 ( DdManager table,
DD_CTFP1  op,
DdNode f 
)

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

Synopsis [Looks up in the cache for the result of op applied to f.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookup cuddCacheLookup2]

Definition at line 525 of file cuddCache.c.

529 {
530  int posn;
531  DdCache *en,*cache;
532  DdNode *data;
533 
534  cache = table->cache;
535 #ifdef DD_DEBUG
536  if (cache == NULL) {
537  return(NULL);
538  }
539 #endif
540 
541  posn = ddCHash2(op,f,f,table->cacheShift);
542  en = &cache[posn];
543  if (en->data != NULL && en->f==f && en->h==(ptruint)op) {
544  data = Cudd_Regular(en->data);
545  table->cacheHits++;
546  if (data->ref == 0) {
547  cuddReclaim(table,data);
548  }
549  return(en->data);
550  }
551 
552  /* Cache miss: decide whether to resize. */
553  table->cacheMisses++;
554 
555  if (table->cacheSlack >= 0 &&
556  table->cacheHits > table->cacheMisses * table->minHit) {
557  cuddCacheResize(table);
558  }
559 
560  return(NULL);
561 
562 } /* end of cuddCacheLookup1 */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
void cuddReclaim(DdManager *table, DdNode *n)
Definition: cuddRef.c:580
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheLookup1Zdd()

DdNode* cuddCacheLookup1Zdd ( DdManager table,
DD_CTFP1  op,
DdNode f 
)

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

Synopsis [Looks up in the cache for the result of op applied to f.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookupZdd cuddCacheLookup2Zdd]

Definition at line 633 of file cuddCache.c.

637 {
638  int posn;
639  DdCache *en,*cache;
640  DdNode *data;
641 
642  cache = table->cache;
643 #ifdef DD_DEBUG
644  if (cache == NULL) {
645  return(NULL);
646  }
647 #endif
648 
649  posn = ddCHash2(op,f,f,table->cacheShift);
650  en = &cache[posn];
651  if (en->data != NULL && en->f==f && en->h==(ptruint)op) {
652  data = Cudd_Regular(en->data);
653  table->cacheHits++;
654  if (data->ref == 0) {
655  cuddReclaimZdd(table,data);
656  }
657  return(en->data);
658  }
659 
660  /* Cache miss: decide whether to resize. */
661  table->cacheMisses++;
662 
663  if (table->cacheSlack >= 0 &&
664  table->cacheHits > table->cacheMisses * table->minHit) {
665  cuddCacheResize(table);
666  }
667 
668  return(NULL);
669 
670 } /* end of cuddCacheLookup1Zdd */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
void cuddReclaimZdd(DdManager *table, DdNode *n)
Definition: cuddRef.c:634
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheLookup2()

DdNode* cuddCacheLookup2 ( DdManager table,
DD_CTFP  op,
DdNode f,
DdNode g 
)

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

Synopsis [Looks up in the cache for the result of op applied to f and g.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookup cuddCacheLookup1]

Definition at line 471 of file cuddCache.c.

476 {
477  int posn;
478  DdCache *en,*cache;
479  DdNode *data;
480 
481  cache = table->cache;
482 #ifdef DD_DEBUG
483  if (cache == NULL) {
484  return(NULL);
485  }
486 #endif
487 
488  posn = ddCHash2(op,f,g,table->cacheShift);
489  en = &cache[posn];
490  if (en->data != NULL && en->f==f && en->g==g && en->h==(ptruint)op) {
491  data = Cudd_Regular(en->data);
492  table->cacheHits++;
493  if (data->ref == 0) {
494  cuddReclaim(table,data);
495  }
496  return(en->data);
497  }
498 
499  /* Cache miss: decide whether to resize. */
500  table->cacheMisses++;
501 
502  if (table->cacheSlack >= 0 &&
503  table->cacheHits > table->cacheMisses * table->minHit) {
504  cuddCacheResize(table);
505  }
506 
507  return(NULL);
508 
509 } /* end of cuddCacheLookup2 */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
void cuddReclaim(DdManager *table, DdNode *n)
Definition: cuddRef.c:580
DdNode * g
Definition: cuddInt.h:302
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheLookup2Zdd()

DdNode* cuddCacheLookup2Zdd ( DdManager table,
DD_CTFP  op,
DdNode f,
DdNode g 
)

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

Synopsis [Looks up in the cache for the result of op applied to f and g.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookupZdd cuddCacheLookup1Zdd]

Definition at line 579 of file cuddCache.c.

584 {
585  int posn;
586  DdCache *en,*cache;
587  DdNode *data;
588 
589  cache = table->cache;
590 #ifdef DD_DEBUG
591  if (cache == NULL) {
592  return(NULL);
593  }
594 #endif
595 
596  posn = ddCHash2(op,f,g,table->cacheShift);
597  en = &cache[posn];
598  if (en->data != NULL && en->f==f && en->g==g && en->h==(ptruint)op) {
599  data = Cudd_Regular(en->data);
600  table->cacheHits++;
601  if (data->ref == 0) {
602  cuddReclaimZdd(table,data);
603  }
604  return(en->data);
605  }
606 
607  /* Cache miss: decide whether to resize. */
608  table->cacheMisses++;
609 
610  if (table->cacheSlack >= 0 &&
611  table->cacheHits > table->cacheMisses * table->minHit) {
612  cuddCacheResize(table);
613  }
614 
615  return(NULL);
616 
617 } /* end of cuddCacheLookup2Zdd */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
DdNode * g
Definition: cuddInt.h:302
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
void cuddReclaimZdd(DdManager *table, DdNode *n)
Definition: cuddRef.c:634
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheLookupZdd()

DdNode* cuddCacheLookupZdd ( DdManager table,
ptruint  op,
DdNode f,
DdNode g,
DdNode h 
)

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

Synopsis [Looks up in the cache for the result of op applied to f, g, and h.]

Description [Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso [cuddCacheLookup2Zdd cuddCacheLookup1Zdd]

Definition at line 409 of file cuddCache.c.

415 {
416  int posn;
417  DdCache *en,*cache;
418  DdNode *data;
419  ptruint uf, ug, uh;
420 
421  uf = (ptruint) f | (op & 0xe);
422  ug = (ptruint) g | (op >> 4);
423  uh = (ptruint) h;
424 
425  cache = table->cache;
426 #ifdef DD_DEBUG
427  if (cache == NULL) {
428  return(NULL);
429  }
430 #endif
431 
432  posn = ddCHash2(uh,uf,ug,table->cacheShift);
433  en = &cache[posn];
434  if (en->data != NULL && en->f==(DdNodePtr)uf && en->g==(DdNodePtr)ug &&
435  en->h==uh) {
436  data = Cudd_Regular(en->data);
437  table->cacheHits++;
438  if (data->ref == 0) {
439  cuddReclaimZdd(table,data);
440  }
441  return(en->data);
442  }
443 
444  /* Cache miss: decide whether to resize. */
445  table->cacheMisses++;
446 
447  if (table->cacheSlack >= 0 &&
448  table->cacheHits > table->cacheMisses * table->minHit) {
449  cuddCacheResize(table);
450  }
451 
452  return(NULL);
453 
454 } /* end of cuddCacheLookupZdd */
DdHalfWord ref
Definition: cudd.h:272
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
#define Cudd_Regular(node)
Definition: cudd.h:384
DdNode * g
Definition: cuddInt.h:302
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
void cuddReclaimZdd(DdManager *table, DdNode *n)
Definition: cuddRef.c:634
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddCacheProfile()

int cuddCacheProfile ( DdManager table,
FILE *  fp 
)

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

Synopsis [Computes and prints a profile of the cache usage.]

Description [Computes and prints a profile of the cache usage. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso []

Definition at line 749 of file cuddCache.c.

752 {
753  DdCache *cache = table->cache;
754  int slots = table->cacheSlots;
755  int nzeroes = 0;
756  int i, retval;
757  double exUsed;
758 
759 #ifdef DD_CACHE_PROFILE
760  double count, mean, meansq, stddev, expected;
761  long max, min;
762  int imax, imin;
763  double *hystogramQ, *hystogramR; /* histograms by quotient and remainder */
764  int nbins = DD_HYSTO_BINS;
765  int bin;
766  long thiscount;
767  double totalcount, exStddev;
768 
769  meansq = mean = expected = 0.0;
770  max = min = (long) cache[0].count;
771  imax = imin = 0;
772  totalcount = 0.0;
773 
774  hystogramQ = ALLOC(double, nbins);
775  if (hystogramQ == NULL) {
776  table->errorCode = CUDD_MEMORY_OUT;
777  return(0);
778  }
779  hystogramR = ALLOC(double, nbins);
780  if (hystogramR == NULL) {
781  FREE(hystogramQ);
782  table->errorCode = CUDD_MEMORY_OUT;
783  return(0);
784  }
785  for (i = 0; i < nbins; i++) {
786  hystogramQ[i] = 0;
787  hystogramR[i] = 0;
788  }
789 
790  for (i = 0; i < slots; i++) {
791  thiscount = (long) cache[i].count;
792  if (thiscount > max) {
793  max = thiscount;
794  imax = i;
795  }
796  if (thiscount < min) {
797  min = thiscount;
798  imin = i;
799  }
800  if (thiscount == 0) {
801  nzeroes++;
802  }
803  count = (double) thiscount;
804  mean += count;
805  meansq += count * count;
806  totalcount += count;
807  expected += count * (double) i;
808  bin = (i * nbins) / slots;
809  hystogramQ[bin] += (double) thiscount;
810  bin = i % nbins;
811  hystogramR[bin] += (double) thiscount;
812  }
813  mean /= (double) slots;
814  meansq /= (double) slots;
815 
816  /* Compute the standard deviation from both the data and the
817  ** theoretical model for a random distribution. */
818  stddev = sqrt(meansq - mean*mean);
819  exStddev = sqrt((1 - 1/(double) slots) * totalcount / (double) slots);
820 
821  retval = fprintf(fp,"Cache average accesses = %g\n", mean);
822  if (retval == EOF) return(0);
823  retval = fprintf(fp,"Cache access standard deviation = %g ", stddev);
824  if (retval == EOF) return(0);
825  retval = fprintf(fp,"(expected = %g)\n", exStddev);
826  if (retval == EOF) return(0);
827  retval = fprintf(fp,"Cache max accesses = %ld for slot %d\n", max, imax);
828  if (retval == EOF) return(0);
829  retval = fprintf(fp,"Cache min accesses = %ld for slot %d\n", min, imin);
830  if (retval == EOF) return(0);
831  exUsed = 100.0 * (1.0 - exp(-totalcount / (double) slots));
832  retval = fprintf(fp,"Cache used slots = %.2f%% (expected %.2f%%)\n",
833  100.0 - (double) nzeroes * 100.0 / (double) slots,
834  exUsed);
835  if (retval == EOF) return(0);
836 
837  if (totalcount > 0) {
838  expected /= totalcount;
839  retval = fprintf(fp,"Cache access hystogram for %d bins", nbins);
840  if (retval == EOF) return(0);
841  retval = fprintf(fp," (expected bin value = %g)\nBy quotient:",
842  expected);
843  if (retval == EOF) return(0);
844  for (i = nbins - 1; i>=0; i--) {
845  retval = fprintf(fp," %.0f", hystogramQ[i]);
846  if (retval == EOF) return(0);
847  }
848  retval = fprintf(fp,"\nBy residue: ");
849  if (retval == EOF) return(0);
850  for (i = nbins - 1; i>=0; i--) {
851  retval = fprintf(fp," %.0f", hystogramR[i]);
852  if (retval == EOF) return(0);
853  }
854  retval = fprintf(fp,"\n");
855  if (retval == EOF) return(0);
856  }
857 
858  FREE(hystogramQ);
859  FREE(hystogramR);
860 #else
861  for (i = 0; i < slots; i++) {
862  nzeroes += cache[i].h == 0;
863  }
864  exUsed = 100.0 *
865  (1.0 - exp(-(table->cacheinserts - table->cacheLastInserts) /
866  (double) slots));
867  retval = fprintf(fp,"Cache used slots = %.2f%% (expected %.2f%%)\n",
868  100.0 - (double) nzeroes * 100.0 / (double) slots,
869  exUsed);
870  if (retval == EOF) return(0);
871 #endif
872  return(1);
873 
874 } /* end of cuddCacheProfile */
#define FREE(obj)
Definition: util.h:80
ptruint h
Definition: cuddInt.h:303
double cacheinserts
Definition: cuddInt.h:438
unsigned int cacheSlots
Definition: cuddInt.h:337
#define ALLOC(type, num)
Definition: util.h:76
DdCache * cache
Definition: cuddInt.h:336
double cacheLastInserts
Definition: cuddInt.h:439
Cudd_ErrorType errorCode
Definition: cuddInt.h:425

◆ cuddCacheResize()

void cuddCacheResize ( DdManager table)

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

Synopsis [Resizes the cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 889 of file cuddCache.c.

891 {
892  DdCache *cache, *oldcache, *oldacache, *entry, *old;
893  int i;
894  int posn, shift;
895  unsigned int slots, oldslots;
896  double offset;
897  int moved = 0;
898  extern DD_OOMFP MMoutOfMemory;
899  DD_OOMFP saveHandler;
900 #ifndef DD_CACHE_PROFILE
901  ptruint misalignment;
902  DdNodePtr *mem;
903 #endif
904 
905  oldcache = table->cache;
906  oldacache = table->acache;
907  oldslots = table->cacheSlots;
908  slots = table->cacheSlots = oldslots << 1;
909 
910 #ifdef DD_VERBOSE
911  (void) fprintf(table->err,"Resizing the cache from %d to %d entries\n",
912  oldslots, slots);
913  (void) fprintf(table->err,
914  "\thits = %g\tmisses = %g\thit ratio = %5.3f\n",
915  table->cacheHits, table->cacheMisses,
916  table->cacheHits / (table->cacheHits + table->cacheMisses));
917 #endif
918 
919  saveHandler = MMoutOfMemory;
920  MMoutOfMemory = Cudd_OutOfMem;
921  table->acache = cache = ALLOC(DdCache,slots+1);
922  MMoutOfMemory = saveHandler;
923  /* If we fail to allocate the new table we just give up. */
924  if (cache == NULL) {
925 #ifdef DD_VERBOSE
926  (void) fprintf(table->err,"Resizing failed. Giving up.\n");
927 #endif
928  table->cacheSlots = oldslots;
929  table->acache = oldacache;
930  /* Do not try to resize again. */
931  table->maxCacheHard = oldslots - 1;
932  table->cacheSlack = - (int) (oldslots + 1);
933  return;
934  }
935  /* If the size of the cache entry is a power of 2, we want to
936  ** enforce alignment to that power of two. This happens when
937  ** DD_CACHE_PROFILE is not defined. */
938 #ifdef DD_CACHE_PROFILE
939  table->cache = cache;
940 #else
941  mem = (DdNodePtr *) cache;
942  misalignment = (ptruint) mem & (sizeof(DdCache) - 1);
943  mem += (sizeof(DdCache) - misalignment) / sizeof(DdNodePtr);
944  table->cache = cache = (DdCache *) mem;
945  assert(((ptruint) table->cache & (sizeof(DdCache) - 1)) == 0);
946 #endif
947  shift = --(table->cacheShift);
948  table->memused += (slots - oldslots) * sizeof(DdCache);
949  table->cacheSlack -= slots; /* need these many slots to double again */
950 
951  /* Clear new cache. */
952  for (i = 0; (unsigned) i < slots; i++) {
953  cache[i].data = NULL;
954  cache[i].h = 0;
955 #ifdef DD_CACHE_PROFILE
956  cache[i].count = 0;
957 #endif
958  }
959 
960  /* Copy from old cache to new one. */
961  for (i = 0; (unsigned) i < oldslots; i++) {
962  old = &oldcache[i];
963  if (old->data != NULL) {
964  posn = ddCHash2(old->h,old->f,old->g,shift);
965  entry = &cache[posn];
966  entry->f = old->f;
967  entry->g = old->g;
968  entry->h = old->h;
969  entry->data = old->data;
970 #ifdef DD_CACHE_PROFILE
971  entry->count = 1;
972 #endif
973  moved++;
974  }
975  }
976 
977  FREE(oldacache);
978 
979  /* Reinitialize measurements so as to avoid division by 0 and
980  ** immediate resizing.
981  */
982  offset = (double) (int) (slots * table->minHit + 1);
983  table->totCacheMisses += table->cacheMisses - offset;
984  table->cacheMisses = offset;
985  table->totCachehits += table->cacheHits;
986  table->cacheHits = 0;
987  table->cacheLastInserts = table->cacheinserts - (double) moved;
988 
989 } /* end of cuddCacheResize */
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2845
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
#define FREE(obj)
Definition: util.h:80
DdNode * data
Definition: cuddInt.h:304
#define assert(ex)
Definition: util.h:141
unsigned int maxCacheHard
Definition: cuddInt.h:343
ptruint h
Definition: cuddInt.h:303
FILE * err
Definition: cuddInt.h:424
DdNode * g
Definition: cuddInt.h:302
DdNode * DdNodePtr
Definition: cuddInt.h:253
double cacheinserts
Definition: cuddInt.h:438
void(* DD_OOMFP)(long)
Definition: cudd.h:311
static int * entry
Definition: cuddGroup.c:119
unsigned int cacheSlots
Definition: cuddInt.h:337
#define ALLOC(type, num)
Definition: util.h:76
DdCache * cache
Definition: cuddInt.h:336
double totCacheMisses
Definition: cuddInt.h:436
double cacheLastInserts
Definition: cuddInt.h:439
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
void(* MMoutOfMemory)(long)
Definition: safe_mem.c:32
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned long memused
Definition: cuddInt.h:429
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
DdCache * acache
Definition: cuddInt.h:335
struct DdCache DdCache
double totCachehits
Definition: cuddInt.h:435

◆ cuddComputeFloorLog2()

int cuddComputeFloorLog2 ( unsigned int  value)

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

Synopsis [Returns the floor of the logarithm to the base 2.]

Description [Returns the floor of the logarithm to the base 2. The input value is assumed to be greater than 0.]

SideEffects [None]

SeeAlso []

Definition at line 1036 of file cuddCache.c.

1038 {
1039  int floorLog = 0;
1040 #ifdef DD_DEBUG
1041  assert(value > 0);
1042 #endif
1043  while (value > 1) {
1044  floorLog++;
1045  value >>= 1;
1046  }
1047  return(floorLog);
1048 
1049 } /* end of cuddComputeFloorLog2 */
#define assert(ex)
Definition: util.h:141

◆ cuddConstantLookup()

DdNode* cuddConstantLookup ( DdManager table,
ptruint  op,
DdNode f,
DdNode g,
DdNode h 
)

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

Synopsis [Looks up in the cache for the result of op applied to f, g, and h.]

Description [Looks up in the cache for the result of op applied to f, g, and h. Assumes that the calling procedure (e.g., Cudd_bddIteConstant) is only interested in whether the result is constant or not. Returns the result if found (possibly DD_NON_CONSTANT); otherwise it returns NULL.]

SideEffects [None]

SeeAlso [cuddCacheLookup]

Definition at line 690 of file cuddCache.c.

696 {
697  int posn;
698  DdCache *en,*cache;
699  ptruint uf, ug, uh;
700 
701  uf = (ptruint) f | (op & 0xe);
702  ug = (ptruint) g | (op >> 4);
703  uh = (ptruint) h;
704 
705  cache = table->cache;
706 #ifdef DD_DEBUG
707  if (cache == NULL) {
708  return(NULL);
709  }
710 #endif
711  posn = ddCHash2(uh,uf,ug,table->cacheShift);
712  en = &cache[posn];
713 
714  /* We do not reclaim here because the result should not be
715  * referenced, but only tested for being a constant.
716  */
717  if (en->data != NULL &&
718  en->f == (DdNodePtr)uf && en->g == (DdNodePtr)ug && en->h == uh) {
719  table->cacheHits++;
720  return(en->data);
721  }
722 
723  /* Cache miss: decide whether to resize. */
724  table->cacheMisses++;
725 
726  if (table->cacheSlack >= 0 &&
727  table->cacheHits > table->cacheMisses * table->minHit) {
728  cuddCacheResize(table);
729  }
730 
731  return(NULL);
732 
733 } /* end of cuddConstantLookup */
DdNode * f
Definition: cuddInt.h:302
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
ptruint h
Definition: cuddInt.h:303
DdNode * g
Definition: cuddInt.h:302
DdCache * cache
Definition: cuddInt.h:336
double cacheHits
Definition: cuddInt.h:340
int cacheSlack
Definition: cuddInt.h:342
#define ddCHash2(o, f, g, s)
Definition: cuddInt.h:741
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
void cuddCacheResize(DdManager *table)
Definition: cuddCache.c:889

◆ cuddInitCache()

int cuddInitCache ( DdManager unique,
unsigned int  cacheSize,
unsigned int  maxCacheSize 
)

AutomaticStart AutomaticEnd Function********************************************************************

Synopsis [Initializes the computed table.]

Description [Initializes the computed table. It is called by Cudd_Init. Returns 1 in case of success; 0 otherwise.]

SideEffects [None]

SeeAlso [Cudd_Init]

Definition at line 132 of file cuddCache.c.

136 {
137  int i;
138  unsigned int logSize;
139 #ifndef DD_CACHE_PROFILE
140  DdNodePtr *mem;
141  ptruint offset;
142 #endif
143 
144  /* Round cacheSize to largest power of 2 not greater than the requested
145  ** initial cache size. */
146  logSize = cuddComputeFloorLog2(ddMax(cacheSize,unique->slots/2));
147  cacheSize = 1 << logSize;
148  unique->acache = ALLOC(DdCache,cacheSize+1);
149  if (unique->acache == NULL) {
150  unique->errorCode = CUDD_MEMORY_OUT;
151  return(0);
152  }
153  /* If the size of the cache entry is a power of 2, we want to
154  ** enforce alignment to that power of two. This happens when
155  ** DD_CACHE_PROFILE is not defined. */
156 #ifdef DD_CACHE_PROFILE
157  unique->cache = unique->acache;
158  unique->memused += (cacheSize) * sizeof(DdCache);
159 #else
160  mem = (DdNodePtr *) unique->acache;
161  offset = (ptruint) mem & (sizeof(DdCache) - 1);
162  mem += (sizeof(DdCache) - offset) / sizeof(DdNodePtr);
163  unique->cache = (DdCache *) mem;
164  assert(((ptruint) unique->cache & (sizeof(DdCache) - 1)) == 0);
165  unique->memused += (cacheSize+1) * sizeof(DdCache);
166 #endif
167  unique->cacheSlots = cacheSize;
168  unique->cacheShift = sizeof(int) * 8 - logSize;
169  unique->maxCacheHard = maxCacheSize;
170  /* If cacheSlack is non-negative, we can resize. */
171  unique->cacheSlack = (int) ddMin(maxCacheSize,
173  2 * (int) cacheSize;
174  Cudd_SetMinHit(unique,DD_MIN_HIT);
175  /* Initialize to avoid division by 0 and immediate resizing. */
176  unique->cacheMisses = (double) (int) (cacheSize * unique->minHit + 1);
177  unique->cacheHits = 0;
178  unique->totCachehits = 0;
179  /* The sum of cacheMisses and totCacheMisses is always correct,
180  ** even though cacheMisses is larger than it should for the reasons
181  ** explained above. */
182  unique->totCacheMisses = -unique->cacheMisses;
183  unique->cachecollisions = 0;
184  unique->cacheinserts = 0;
185  unique->cacheLastInserts = 0;
186  unique->cachedeletions = 0;
187 
188  /* Initialize the cache */
189  for (i = 0; (unsigned) i < cacheSize; i++) {
190  unique->cache[i].h = 0; /* unused slots */
191  unique->cache[i].data = NULL; /* invalid entry */
192 #ifdef DD_CACHE_PROFILE
193  unique->cache[i].count = 0;
194 #endif
195  }
196 
197  return(1);
198 
199 } /* end of cuddInitCache */
Definition: cudd.h:270
DdNode * data
Definition: cuddInt.h:304
#define assert(ex)
Definition: util.h:141
unsigned int maxCacheHard
Definition: cuddInt.h:343
unsigned int slots
Definition: cuddInt.h:352
ptruint h
Definition: cuddInt.h:303
double cachecollisions
Definition: cuddInt.h:437
DdNode * DdNodePtr
Definition: cuddInt.h:253
#define DD_MIN_HIT
Definition: cuddInt.h:137
double cacheinserts
Definition: cuddInt.h:438
unsigned int cacheSlots
Definition: cuddInt.h:337
#define ALLOC(type, num)
Definition: util.h:76
DdCache * cache
Definition: cuddInt.h:336
double totCacheMisses
Definition: cuddInt.h:436
int cuddComputeFloorLog2(unsigned int value)
Definition: cuddCache.c:1036
#define ddMax(x, y)
Definition: cuddInt.h:785
double cacheLastInserts
Definition: cuddInt.h:439
double cacheHits
Definition: cuddInt.h:340
#define ddMin(x, y)
Definition: cuddInt.h:771
#define DD_MAX_CACHE_TO_SLOTS_RATIO
Definition: cuddInt.h:145
void Cudd_SetMinHit(DdManager *dd, unsigned int hr)
Definition: cuddAPI.c:1538
int cacheSlack
Definition: cuddInt.h:342
unsigned long memused
Definition: cuddInt.h:429
unsigned int ptruint
Definition: cuddInt.h:250
double cacheMisses
Definition: cuddInt.h:339
double minHit
Definition: cuddInt.h:341
int cacheShift
Definition: cuddInt.h:338
double cachedeletions
Definition: cuddInt.h:440
DdCache * acache
Definition: cuddInt.h:335
struct DdCache DdCache
Cudd_ErrorType errorCode
Definition: cuddInt.h:425
double totCachehits
Definition: cuddInt.h:435

Variable Documentation

◆ DD_UNUSED

char rcsid [] DD_UNUSED = "$Id: cuddCache.c,v 1.36 2012/02/05 01:07:18 fabio Exp $"
static

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

FileName [cuddCache.c]

PackageName [cudd]

Synopsis [Functions for cache insertion and lookup.]

Description [Internal procedures included in this module:

Static procedures included in this module:

]

SeeAlso []

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2012, Regents of the University of Colorado

All rights reserved.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

Neither the name of the University of Colorado nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.]

Definition at line 92 of file cuddCache.c.