73 #ifdef DD_CACHE_PROFILE 74 #define DD_HYSTO_BINS 8 92 static char rcsid[]
DD_UNUSED =
"$Id: cuddCache.c,v 1.36 2012/02/05 01:07:18 fabio Exp $";
134 unsigned int cacheSize ,
135 unsigned int maxCacheSize )
138 unsigned int logSize;
139 #ifndef DD_CACHE_PROFILE 147 cacheSize = 1 << logSize;
149 if (unique->
acache == NULL) {
156 #ifdef DD_CACHE_PROFILE 168 unique->
cacheShift =
sizeof(int) * 8 - logSize;
189 for (i = 0; (unsigned) i < cacheSize; i++) {
192 #ifdef DD_CACHE_PROFILE 193 unique->
cache[i].count = 0;
234 entry = &table->
cache[posn];
243 #ifdef DD_CACHE_PROFILE 274 entry = &table->
cache[posn];
276 if (entry->
data != NULL) {
285 #ifdef DD_CACHE_PROFILE 315 entry = &table->
cache[posn];
317 if (entry->
data != NULL) {
326 #ifdef DD_CACHE_PROFILE 363 cache = table->
cache;
376 if (data->
ref == 0) {
425 cache = table->
cache;
438 if (data->
ref == 0) {
481 cache = table->
cache;
490 if (en->
data != NULL && en->
f==f && en->
g==g && en->
h==(
ptruint)op) {
493 if (data->
ref == 0) {
534 cache = table->
cache;
546 if (data->
ref == 0) {
589 cache = table->
cache;
598 if (en->
data != NULL && en->
f==f && en->
g==g && en->
h==(
ptruint)op) {
601 if (data->
ref == 0) {
642 cache = table->
cache;
654 if (data->
ref == 0) {
705 cache = table->
cache;
717 if (en->
data != NULL &&
759 #ifdef DD_CACHE_PROFILE 760 double count, mean, meansq, stddev, expected;
763 double *hystogramQ, *hystogramR;
764 int nbins = DD_HYSTO_BINS;
767 double totalcount, exStddev;
769 meansq = mean = expected = 0.0;
770 max = min = (long) cache[0].count;
774 hystogramQ =
ALLOC(
double, nbins);
775 if (hystogramQ == NULL) {
779 hystogramR =
ALLOC(
double, nbins);
780 if (hystogramR == NULL) {
785 for (i = 0; i < nbins; i++) {
790 for (i = 0; i < slots; i++) {
791 thiscount = (long) cache[i].count;
792 if (thiscount > max) {
796 if (thiscount < min) {
800 if (thiscount == 0) {
803 count = (double) thiscount;
805 meansq += count * count;
807 expected += count * (double) i;
808 bin = (i * nbins) / slots;
809 hystogramQ[bin] += (double) thiscount;
811 hystogramR[bin] += (double) thiscount;
813 mean /= (double) slots;
814 meansq /= (double) slots;
818 stddev = sqrt(meansq - mean*mean);
819 exStddev = sqrt((1 - 1/(
double) slots) * totalcount / (
double) slots);
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,
835 if (retval == EOF)
return(0);
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:",
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);
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);
854 retval = fprintf(fp,
"\n");
855 if (retval == EOF)
return(0);
861 for (i = 0; i < slots; i++) {
862 nzeroes += cache[i].
h == 0;
867 retval = fprintf(fp,
"Cache used slots = %.2f%% (expected %.2f%%)\n",
868 100.0 - (
double) nzeroes * 100.0 / (
double) slots,
870 if (retval == EOF)
return(0);
895 unsigned int slots, oldslots;
900 #ifndef DD_CACHE_PROFILE 905 oldcache = table->
cache;
906 oldacache = table->
acache;
911 (void) fprintf(table->
err,
"Resizing the cache from %d to %d entries\n",
913 (void) fprintf(table->
err,
914 "\thits = %g\tmisses = %g\thit ratio = %5.3f\n",
922 MMoutOfMemory = saveHandler;
926 (void) fprintf(table->
err,
"Resizing failed. Giving up.\n");
929 table->
acache = oldacache;
938 #ifdef DD_CACHE_PROFILE 939 table->
cache = cache;
952 for (i = 0; (unsigned) i < slots; i++) {
953 cache[i].
data = NULL;
955 #ifdef DD_CACHE_PROFILE 961 for (i = 0; (unsigned) i < oldslots; i++) {
963 if (old->
data != NULL) {
965 entry = &cache[posn];
970 #ifdef DD_CACHE_PROFILE 982 offset = (double) (
int) (slots * table->
minHit + 1);
1011 cache = table->
cache;
1012 for (i = 0; i < slots; i++) {
1014 cache[i].
data = NULL;
static char rcsid [] DD_UNUSED
DdNode * cuddCacheLookupZdd(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
DdNode * cuddCacheLookup2Zdd(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
void cuddCacheFlush(DdManager *table)
void Cudd_OutOfMem(long size)
void cuddCacheInsert2(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g, DdNode *data)
unsigned int maxCacheHard
#define Cudd_Regular(node)
void cuddReclaim(DdManager *table, DdNode *n)
void cuddCacheInsert(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h, DdNode *data)
int cuddInitCache(DdManager *unique, unsigned int cacheSize, unsigned int maxCacheSize)
DdNode * cuddCacheLookup2(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
DdNode *(* DD_CTFP)(DdManager *, DdNode *, DdNode *)
DdNode * cuddCacheLookup1(DdManager *table, DD_CTFP1 op, DdNode *f)
int cuddComputeFloorLog2(unsigned int value)
#define DD_MAX_CACHE_TO_SLOTS_RATIO
void Cudd_SetMinHit(DdManager *dd, unsigned int hr)
DdNode * cuddConstantLookup(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
void(* MMoutOfMemory)(long)
#define ddCHash2(o, f, g, s)
void cuddReclaimZdd(DdManager *table, DdNode *n)
int cuddCacheProfile(DdManager *table, FILE *fp)
DdNode *(* DD_CTFP1)(DdManager *, DdNode *)
DdNode * cuddCacheLookup(DdManager *table, ptruint op, DdNode *f, DdNode *g, DdNode *h)
DdNode * cuddCacheLookup1Zdd(DdManager *table, DD_CTFP1 op, DdNode *f)
void cuddCacheInsert1(DdManager *table, DD_CTFP1 op, DdNode *f, DdNode *data)
void cuddCacheResize(DdManager *table)