77 #ifdef DD_CACHE_PROFILE
78 #define DD_HYSTO_BINS 8
96 static char rcsid[]
DD_UNUSED =
"$Id: cuddCache.c,v 1.34 2009/02/19 16:17:50 fabio Exp $";
138 unsigned int cacheSize ,
139 unsigned int maxCacheSize )
142 unsigned int logSize;
143 #ifndef DD_CACHE_PROFILE
151 cacheSize = 1 << logSize;
154 if (unique->
acache == NULL) {
161 #ifdef DD_CACHE_PROFILE
168 offset = (
ptruint) mem & (32 - 1);
169 mem += (32 - offset) /
sizeof(
DdNodePtr);
176 unique->
cacheShift =
sizeof(int) * 8 - logSize;
197 for (i = 0; (unsigned) i < cacheSize; i++) {
200 #ifdef DD_CACHE_PROFILE
201 unique->
cache[i].count = 0;
247 entry = &table->
cache[posn];
256 #ifdef DD_CACHE_PROFILE
291 entry = &table->
cache[posn];
293 if (entry->
data != NULL) {
302 #ifdef DD_CACHE_PROFILE
336 entry = &table->
cache[posn];
338 if (entry->
data != NULL) {
347 #ifdef DD_CACHE_PROFILE
390 cache = table->
cache;
402 if (data->
ref == 0) {
456 cache = table->
cache;
469 if (data->
ref == 0) {
512 cache = table->
cache;
521 if (en->
data != NULL && en->
f==f && en->
g==g && en->
h==(
ptruint)op) {
524 if (data->
ref == 0) {
565 cache = table->
cache;
577 if (data->
ref == 0) {
620 cache = table->
cache;
629 if (en->
data != NULL && en->
f==f && en->
g==g && en->
h==(
ptruint)op) {
632 if (data->
ref == 0) {
673 cache = table->
cache;
685 if (data->
ref == 0) {
741 cache = table->
cache;
753 if (en->
data != NULL &&
795 #ifdef DD_CACHE_PROFILE
796 double count, mean, meansq, stddev, expected;
799 double *hystogramQ, *hystogramR;
800 int nbins = DD_HYSTO_BINS;
803 double totalcount, exStddev;
805 meansq = mean = expected = 0.0;
806 max = min = (long) cache[0].count;
811 if (hystogramQ == NULL) {
816 if (hystogramR == NULL) {
821 for (i = 0; i < nbins; i++) {
826 for (i = 0; i < slots; i++) {
827 thiscount = (long) cache[i].count;
828 if (thiscount > max) {
832 if (thiscount < min) {
836 if (thiscount == 0) {
839 count = (double) thiscount;
841 meansq += count * count;
843 expected += count * (double) i;
844 bin = (i * nbins) / slots;
845 hystogramQ[bin] += (double) thiscount;
847 hystogramR[bin] += (double) thiscount;
849 mean /= (double) slots;
850 meansq /= (double) slots;
854 stddev = sqrt(meansq - mean*mean);
855 exStddev = sqrt((1 - 1/(
double) slots) * totalcount / (
double) slots);
857 retval = fprintf(fp,
"Cache average accesses = %g\n", mean);
858 if (retval == EOF)
return(0);
859 retval = fprintf(fp,
"Cache access standard deviation = %g ", stddev);
860 if (retval == EOF)
return(0);
861 retval = fprintf(fp,
"(expected = %g)\n", exStddev);
862 if (retval == EOF)
return(0);
863 retval = fprintf(fp,
"Cache max accesses = %ld for slot %d\n", max, imax);
864 if (retval == EOF)
return(0);
865 retval = fprintf(fp,
"Cache min accesses = %ld for slot %d\n", min, imin);
866 if (retval == EOF)
return(0);
867 exUsed = 100.0 * (1.0 - exp(-totalcount / (
double) slots));
868 retval = fprintf(fp,
"Cache used slots = %.2f%% (expected %.2f%%)\n",
869 100.0 - (
double) nzeroes * 100.0 / (
double) slots,
871 if (retval == EOF)
return(0);
873 if (totalcount > 0) {
874 expected /= totalcount;
875 retval = fprintf(fp,
"Cache access hystogram for %d bins", nbins);
876 if (retval == EOF)
return(0);
877 retval = fprintf(fp,
" (expected bin value = %g)\nBy quotient:",
879 if (retval == EOF)
return(0);
880 for (i = nbins - 1; i>=0; i--) {
881 retval = fprintf(fp,
" %.0f", hystogramQ[i]);
882 if (retval == EOF)
return(0);
884 retval = fprintf(fp,
"\nBy residue: ");
885 if (retval == EOF)
return(0);
886 for (i = nbins - 1; i>=0; i--) {
887 retval = fprintf(fp,
" %.0f", hystogramR[i]);
888 if (retval == EOF)
return(0);
890 retval = fprintf(fp,
"\n");
891 if (retval == EOF)
return(0);
897 for (i = 0; i < slots; i++) {
898 nzeroes += cache[i].
h == 0;
903 retval = fprintf(fp,
"Cache used slots = %.2f%% (expected %.2f%%)\n",
904 100.0 - (
double) nzeroes * 100.0 / (
double) slots,
906 if (retval == EOF)
return(0);
931 unsigned int slots, oldslots;
936 #ifndef DD_CACHE_PROFILE
941 oldcache = table->
cache;
942 oldacache = table->
acache;
947 (void) fprintf(table->
err,
"Resizing the cache from %d to %d entries\n",
949 (void) fprintf(table->
err,
950 "\thits = %g\tmisses = %g\thit ratio = %5.3f\n",
959 MMoutOfMemory = saveHandler;
963 (void) fprintf(table->
err,
"Resizing failed. Giving up.\n");
966 table->
acache = oldacache;
975 #ifdef DD_CACHE_PROFILE
976 table->
cache = cache;
983 misalignment = (
ptruint) mem & (32 - 1);
984 mem += (32 - misalignment) /
sizeof(
DdNodePtr);
993 for (i = 0; (unsigned) i < slots; i++) {
994 cache[i].
data = NULL;
996 #ifdef DD_CACHE_PROFILE
1002 for (i = 0; (unsigned) i < oldslots; i++) {
1004 if (old->
data != NULL) {
1006 posn = old->
hash >> shift;
1007 entry = &cache[posn];
1012 #ifdef DD_CACHE_PROFILE
1025 offset = (double) (
int) (slots * table->
minHit + 1);
1054 cache = table->
cache;
1055 for (i = 0; i < slots; i++) {
1057 cache[i].
data = NULL;
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)
DdNode *(* DD_CTFP)(DdManager *, DdNode *, DdNode *)
DdNode *(* DD_CTFP1)(DdManager *, DdNode *)
#define ABC_ALLOC(type, num)
int cuddInitCache(DdManager *unique, unsigned int cacheSize, unsigned int maxCacheSize)
static ABC_NAMESPACE_IMPL_START char rcsid[] DD_UNUSED
DdNode * cuddCacheLookup2(DdManager *table, DD_CTFP op, DdNode *f, DdNode *g)
DdNode * cuddCacheLookup1(DdManager *table, DD_CTFP1 op, DdNode *f)
int cuddComputeFloorLog2(unsigned int value)
#define ABC_NAMESPACE_IMPL_END
static uint32_t hash(uint32_t x)
#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)
#define ddCHash2(o, f, g, s)
void cuddReclaimZdd(DdManager *table, DdNode *n)
#define ABC_NAMESPACE_IMPL_START
int cuddCacheProfile(DdManager *table, FILE *fp)
#define ddCHash2_(o, f, g)
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)