abc-master
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
cuddLCache.c File Reference
#include "misc/util/util_hack.h"
#include "cuddInt.h"

Go to the source code of this file.

Macros

#define DD_MAX_HASHTABLE_DENSITY   2 /* tells when to resize a table */
 
#define ddLCHash2(f, g, shift)   ((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2) >> (shift))
 
#define ddLCHash3(f, g, h, shift)   ddCHash2(f,g,h,shift)
 

Functions

static void cuddLocalCacheResize (DdLocalCache *cache)
 
static DD_INLINE unsigned int ddLCHash (DdNodePtr *key, unsigned int keysize, int shift)
 
static void cuddLocalCacheAddToList (DdLocalCache *cache)
 
static void cuddLocalCacheRemoveFromList (DdLocalCache *cache)
 
static int cuddHashTableResize (DdHashTable *hash)
 
static DD_INLINE DdHashItemcuddHashTableAlloc (DdHashTable *hash)
 
DdLocalCachecuddLocalCacheInit (DdManager *manager, unsigned int keySize, unsigned int cacheSize, unsigned int maxCacheSize)
 
void cuddLocalCacheQuit (DdLocalCache *cache)
 
void cuddLocalCacheInsert (DdLocalCache *cache, DdNodePtr *key, DdNode *value)
 
DdNodecuddLocalCacheLookup (DdLocalCache *cache, DdNodePtr *key)
 
void cuddLocalCacheClearDead (DdManager *manager)
 
void cuddLocalCacheClearAll (DdManager *manager)
 
DdHashTablecuddHashTableInit (DdManager *manager, unsigned int keySize, unsigned int initSize)
 
void cuddHashTableQuit (DdHashTable *hash)
 
int cuddHashTableInsert (DdHashTable *hash, DdNodePtr *key, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup (DdHashTable *hash, DdNodePtr *key)
 
int cuddHashTableInsert1 (DdHashTable *hash, DdNode *f, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup1 (DdHashTable *hash, DdNode *f)
 
int cuddHashTableInsert2 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup2 (DdHashTable *hash, DdNode *f, DdNode *g)
 
int cuddHashTableInsert3 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *h, DdNode *value, ptrint count)
 
DdNodecuddHashTableLookup3 (DdHashTable *hash, DdNode *f, DdNode *g, DdNode *h)
 

Variables

static char rcsid[] DD_UNUSED = "$Id: cuddLCache.c,v 1.24 2009/03/08 02:49:02 fabio Exp $"
 

Macro Definition Documentation

#define DD_MAX_HASHTABLE_DENSITY   2 /* tells when to resize a table */

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

FileName [cuddLCache.c]

PackageName [cudd]

Synopsis [Functions for local caches.]

Description [Internal procedures included in this module:

Static procedures included in this module:

]

SeeAlso []

Author [Fabio Somenzi]

Copyright [Copyright (c) 1995-2004, 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 86 of file cuddLCache.c.

#define ddLCHash2 (   f,
  g,
  shift 
)    ((((unsigned)(f) * DD_P1 + (unsigned)(g)) * DD_P2) >> (shift))

Macro***********************************************************************

Synopsis [Computes hash function for keys of two operands.]

Description []

SideEffects [None]

SeeAlso [ddLCHash3 ddLCHash]

Definition at line 126 of file cuddLCache.c.

#define ddLCHash3 (   f,
  g,
  h,
  shift 
)    ddCHash2(f,g,h,shift)

Macro***********************************************************************

Synopsis [Computes hash function for keys of three operands.]

Description []

SideEffects [None]

SeeAlso [ddLCHash2 ddLCHash]

Definition at line 142 of file cuddLCache.c.

Function Documentation

static DD_INLINE DdHashItem * cuddHashTableAlloc ( DdHashTable hash)
static

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

Synopsis [Fast storage allocation for items in a hash table.]

Description [Fast storage allocation for items in a hash table. The first 4 bytes of a chunk contain a pointer to the next block; the rest contains DD_MEM_CHUNK spaces for hash items. Returns a pointer to a new item if successful; NULL is memory is full.]

SideEffects [None]

SeeAlso [cuddAllocNode cuddDynamicAllocNode]

Definition at line 1393 of file cuddLCache.c.

1395 {
1396  int i;
1397  unsigned int itemsize = hash->itemsize;
1398  extern DD_OOMFP MMoutOfMemory;
1399  DD_OOMFP saveHandler;
1400 #ifdef __osf__
1401 #pragma pointer_size save
1402 #pragma pointer_size short
1403 #endif
1404  DdHashItem **mem, *thisOne, *next, *item;
1405 
1406  if (hash->nextFree == NULL) {
1407  saveHandler = MMoutOfMemory;
1408  MMoutOfMemory = Cudd_OutOfMem;
1409  mem = (DdHashItem **) ABC_ALLOC(char,(DD_MEM_CHUNK+1) * itemsize);
1410  MMoutOfMemory = saveHandler;
1411 #ifdef __osf__
1412 #pragma pointer_size restore
1413 #endif
1414  if (mem == NULL) {
1415  if (hash->manager->stash != NULL) {
1416  ABC_FREE(hash->manager->stash);
1417  hash->manager->stash = NULL;
1418  /* Inhibit resizing of tables. */
1419  hash->manager->maxCacheHard = hash->manager->cacheSlots - 1;
1420  hash->manager->cacheSlack = - (int) (hash->manager->cacheSlots + 1);
1421  for (i = 0; i < hash->manager->size; i++) {
1422  hash->manager->subtables[i].maxKeys <<= 2;
1423  }
1424  hash->manager->gcFrac = 0.2;
1425  hash->manager->minDead =
1426  (unsigned) (0.2 * (double) hash->manager->slots);
1427 #ifdef __osf__
1428 #pragma pointer_size save
1429 #pragma pointer_size short
1430 #endif
1431  mem = (DdHashItem **) ABC_ALLOC(char,(DD_MEM_CHUNK+1) * itemsize);
1432 #ifdef __osf__
1433 #pragma pointer_size restore
1434 #endif
1435  }
1436  if (mem == NULL) {
1437  (*MMoutOfMemory)((long)((DD_MEM_CHUNK + 1) * itemsize));
1439  return(NULL);
1440  }
1441  }
1442 
1443  mem[0] = (DdHashItem *) hash->memoryList;
1444  hash->memoryList = mem;
1445 
1446  thisOne = (DdHashItem *) ((char *) mem + itemsize);
1447  hash->nextFree = thisOne;
1448  for (i = 1; i < DD_MEM_CHUNK; i++) {
1449  next = (DdHashItem *) ((char *) thisOne + itemsize);
1450  thisOne->next = next;
1451  thisOne = next;
1452  }
1453 
1454  thisOne->next = NULL;
1455 
1456  }
1457  item = hash->nextFree;
1458  hash->nextFree = item->next;
1459  return(item);
1460 
1461 } /* end of cuddHashTableAlloc */
void(* DD_OOMFP)(long)
Definition: cudd.h:324
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2837
DdManager * manager
Definition: cuddInt.h:313
int size
Definition: cuddInt.h:361
double gcFrac
Definition: cuddInt.h:375
unsigned int maxCacheHard
Definition: cuddInt.h:359
unsigned int slots
Definition: cuddInt.h:368
struct DdHashItem * next
Definition: cuddInt.h:296
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DdSubtable * subtables
Definition: cuddInt.h:365
unsigned int cacheSlots
Definition: cuddInt.h:353
char * stash
Definition: cuddInt.h:399
unsigned int maxKeys
Definition: cuddInt.h:331
int cacheSlack
Definition: cuddInt.h:358
unsigned int itemsize
Definition: cuddInt.h:305
DdHashItem * nextFree
Definition: cuddInt.h:307
#define ABC_FREE(obj)
Definition: abc_global.h:232
#define DD_MEM_CHUNK
Definition: cuddInt.h:104
DdHashItem ** memoryList
Definition: cuddInt.h:308
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
unsigned int minDead
Definition: cuddInt.h:374
#define MMoutOfMemory
Definition: util_hack.h:38
DdHashTable* cuddHashTableInit ( DdManager manager,
unsigned int  keySize,
unsigned int  initSize 
)

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

Synopsis [Initializes a hash table.]

Description [Initializes a hash table. Returns a pointer to the new table if successful; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableQuit]

Definition at line 538 of file cuddLCache.c.

542 {
543  DdHashTable *hash;
544  int logSize;
545 
546 #ifdef __osf__
547 #pragma pointer_size save
548 #pragma pointer_size short
549 #endif
550  hash = ABC_ALLOC(DdHashTable, 1);
551  if (hash == NULL) {
552  manager->errorCode = CUDD_MEMORY_OUT;
553  return(NULL);
554  }
555  hash->keysize = keySize;
556  hash->manager = manager;
557  hash->memoryList = NULL;
558  hash->nextFree = NULL;
559  hash->itemsize = (keySize + 1) * sizeof(DdNode *) +
560  sizeof(ptrint) + sizeof(DdHashItem *);
561  /* We have to guarantee that the shift be < 32. */
562  if (initSize < 2) initSize = 2;
563  logSize = cuddComputeFloorLog2(initSize);
564  hash->numBuckets = 1 << logSize;
565  hash->shift = sizeof(int) * 8 - logSize;
566  hash->bucket = ABC_ALLOC(DdHashItem *, hash->numBuckets);
567  if (hash->bucket == NULL) {
568  manager->errorCode = CUDD_MEMORY_OUT;
569  ABC_FREE(hash);
570  return(NULL);
571  }
572  memset(hash->bucket, 0, hash->numBuckets * sizeof(DdHashItem *));
573  hash->size = 0;
575 #ifdef __osf__
576 #pragma pointer_size restore
577 #endif
578  return(hash);
579 
580 } /* end of cuddHashTableInit */
char * memset()
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
unsigned int size
Definition: cuddInt.h:311
Definition: cudd.h:278
DdManager * manager
Definition: cuddInt.h:313
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
ABC_PTRINT_T ptrint
Definition: cuddInt.h:260
unsigned int numBuckets
Definition: cuddInt.h:309
int cuddComputeFloorLog2(unsigned int value)
Definition: cuddCache.c:1079
static uint32_t hash(uint32_t x)
Definition: Map.h:38
unsigned int maxsize
Definition: cuddInt.h:312
unsigned int itemsize
Definition: cuddInt.h:305
DdHashItem * nextFree
Definition: cuddInt.h:307
#define ABC_FREE(obj)
Definition: abc_global.h:232
int shift
Definition: cuddInt.h:310
DdHashItem ** memoryList
Definition: cuddInt.h:308
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
#define DD_MAX_HASHTABLE_DENSITY
Definition: cuddLCache.c:86
int cuddHashTableInsert ( DdHashTable hash,
DdNodePtr key,
DdNode value,
ptrint  count 
)

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

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key has more than three pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [[cuddHashTableInsert1 cuddHashTableInsert2 cuddHashTableInsert3 cuddHashTableLookup]

Definition at line 648 of file cuddLCache.c.

653 {
654  int result;
655  unsigned int posn;
656  DdHashItem *item;
657  unsigned int i;
658 
659 #ifdef DD_DEBUG
660  assert(hash->keysize > 3);
661 #endif
662 
663  if (hash->size > hash->maxsize) {
664  result = cuddHashTableResize(hash);
665  if (result == 0) return(0);
666  }
667  item = cuddHashTableAlloc(hash);
668  if (item == NULL) return(0);
669  hash->size++;
670  item->value = value;
671  cuddRef(value);
672  item->count = count;
673  for (i = 0; i < hash->keysize; i++) {
674  item->key[i] = key[i];
675  }
676  posn = ddLCHash(key,hash->keysize,hash->shift);
677  item->next = hash->bucket[posn];
678  hash->bucket[posn] = item;
679 
680  return(1);
681 
682 } /* end of cuddHashTableInsert */
unsigned int keysize
Definition: cuddInt.h:304
#define cuddRef(n)
Definition: cuddInt.h:584
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1393
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
unsigned int maxsize
Definition: cuddInt.h:312
int value
DdNode * key[1]
Definition: cuddInt.h:299
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
static int result
Definition: cuddGenetic.c:125
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1277
int cuddHashTableInsert1 ( DdHashTable hash,
DdNode f,
DdNode value,
ptrint  count 
)

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

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is one pointer. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert2 cuddHashTableInsert3 cuddHashTableLookup1]

Definition at line 767 of file cuddLCache.c.

772 {
773  int result;
774  unsigned int posn;
775  DdHashItem *item;
776 
777 #ifdef DD_DEBUG
778  assert(hash->keysize == 1);
779 #endif
780 
781  if (hash->size > hash->maxsize) {
782  result = cuddHashTableResize(hash);
783  if (result == 0) return(0);
784  }
785  item = cuddHashTableAlloc(hash);
786  if (item == NULL) return(0);
787  hash->size++;
788  item->value = value;
789  cuddRef(value);
790  item->count = count;
791  item->key[0] = f;
792  posn = ddLCHash2(cuddF2L(f),cuddF2L(f),hash->shift);
793  item->next = hash->bucket[posn];
794  hash->bucket[posn] = item;
795 
796  return(1);
797 
798 } /* end of cuddHashTableInsert1 */
unsigned int keysize
Definition: cuddInt.h:304
#define cuddRef(n)
Definition: cuddInt.h:584
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1393
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
unsigned int maxsize
Definition: cuddInt.h:312
int value
DdNode * key[1]
Definition: cuddInt.h:299
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:126
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
static int result
Definition: cuddGenetic.c:125
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1277
int cuddHashTableInsert2 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode value,
ptrint  count 
)

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

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is composed of two pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert1 cuddHashTableInsert3 cuddHashTableLookup2]

Definition at line 874 of file cuddLCache.c.

880 {
881  int result;
882  unsigned int posn;
883  DdHashItem *item;
884 
885 #ifdef DD_DEBUG
886  assert(hash->keysize == 2);
887 #endif
888 
889  if (hash->size > hash->maxsize) {
890  result = cuddHashTableResize(hash);
891  if (result == 0) return(0);
892  }
893  item = cuddHashTableAlloc(hash);
894  if (item == NULL) return(0);
895  hash->size++;
896  item->value = value;
897  cuddRef(value);
898  item->count = count;
899  item->key[0] = f;
900  item->key[1] = g;
901  posn = ddLCHash2(cuddF2L(f),cuddF2L(g),hash->shift);
902  item->next = hash->bucket[posn];
903  hash->bucket[posn] = item;
904 
905  return(1);
906 
907 } /* end of cuddHashTableInsert2 */
unsigned int keysize
Definition: cuddInt.h:304
#define cuddRef(n)
Definition: cuddInt.h:584
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1393
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
unsigned int maxsize
Definition: cuddInt.h:312
int value
DdNode * key[1]
Definition: cuddInt.h:299
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:126
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
static int result
Definition: cuddGenetic.c:125
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1277
int cuddHashTableInsert3 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode h,
DdNode value,
ptrint  count 
)

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

Synopsis [Inserts an item in a hash table.]

Description [Inserts an item in a hash table when the key is composed of three pointers. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert cuddHashTableInsert1 cuddHashTableInsert2 cuddHashTableLookup3]

Definition at line 984 of file cuddLCache.c.

991 {
992  int result;
993  unsigned int posn;
994  DdHashItem *item;
995 
996 #ifdef DD_DEBUG
997  assert(hash->keysize == 3);
998 #endif
999 
1000  if (hash->size > hash->maxsize) {
1001  result = cuddHashTableResize(hash);
1002  if (result == 0) return(0);
1003  }
1004  item = cuddHashTableAlloc(hash);
1005  if (item == NULL) return(0);
1006  hash->size++;
1007  item->value = value;
1008  cuddRef(value);
1009  item->count = count;
1010  item->key[0] = f;
1011  item->key[1] = g;
1012  item->key[2] = h;
1013  posn = ddLCHash3(cuddF2L(f),cuddF2L(g),cuddF2L(h),hash->shift);
1014  item->next = hash->bucket[posn];
1015  hash->bucket[posn] = item;
1016 
1017  return(1);
1018 
1019 } /* end of cuddHashTableInsert3 */
unsigned int keysize
Definition: cuddInt.h:304
#define cuddRef(n)
Definition: cuddInt.h:584
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
static DD_INLINE DdHashItem * cuddHashTableAlloc(DdHashTable *hash)
Definition: cuddLCache.c:1393
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
unsigned int maxsize
Definition: cuddInt.h:312
int value
DdNode * key[1]
Definition: cuddInt.h:299
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
static int result
Definition: cuddGenetic.c:125
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:142
static int cuddHashTableResize(DdHashTable *hash)
Definition: cuddLCache.c:1277
DdNode* cuddHashTableLookup ( DdHashTable hash,
DdNodePtr key 
)

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

Synopsis [Looks up a key in a hash table.]

Description [Looks up a key consisting of more than three pointers in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup1 cuddHashTableLookup2 cuddHashTableLookup3 cuddHashTableInsert]

Definition at line 703 of file cuddLCache.c.

706 {
707  unsigned int posn;
708  DdHashItem *item, *prev;
709  unsigned int i, keysize;
710 
711 #ifdef DD_DEBUG
712  assert(hash->keysize > 3);
713 #endif
714 
715  posn = ddLCHash(key,hash->keysize,hash->shift);
716  item = hash->bucket[posn];
717  prev = NULL;
718 
719  keysize = hash->keysize;
720  while (item != NULL) {
721  DdNodePtr *key2 = item->key;
722  int equal = 1;
723  for (i = 0; i < keysize; i++) {
724  if (key[i] != key2[i]) {
725  equal = 0;
726  break;
727  }
728  }
729  if (equal) {
730  DdNode *value = item->value;
731  cuddSatDec(item->count);
732  if (item->count == 0) {
733  cuddDeref(value);
734  if (prev == NULL) {
735  hash->bucket[posn] = item->next;
736  } else {
737  prev->next = item->next;
738  }
739  item->next = hash->nextFree;
740  hash->nextFree = item;
741  hash->size--;
742  }
743  return(value);
744  }
745  prev = item;
746  item = item->next;
747  }
748  return(NULL);
749 
750 } /* end of cuddHashTableLookup */
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
#define cuddDeref(n)
Definition: cuddInt.h:604
Definition: cudd.h:278
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
DdHashItem * nextFree
Definition: cuddInt.h:307
int value
#define cuddSatDec(x)
Definition: cuddInt.h:896
DdNode * key[1]
Definition: cuddInt.h:299
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
#define equal(a, b)
Definition: espresso.h:326
DdNode* cuddHashTableLookup1 ( DdHashTable hash,
DdNode f 
)

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

Synopsis [Looks up a key consisting of one pointer in a hash table.]

Description [Looks up a key consisting of one pointer in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup2 cuddHashTableLookup3 cuddHashTableInsert1]

Definition at line 819 of file cuddLCache.c.

822 {
823  unsigned int posn;
824  DdHashItem *item, *prev;
825 
826 #ifdef DD_DEBUG
827  assert(hash->keysize == 1);
828 #endif
829 
830  posn = ddLCHash2(cuddF2L(f),cuddF2L(f),hash->shift);
831  item = hash->bucket[posn];
832  prev = NULL;
833 
834  while (item != NULL) {
835  DdNodePtr *key = item->key;
836  if (f == key[0]) {
837  DdNode *value = item->value;
838  cuddSatDec(item->count);
839  if (item->count == 0) {
840  cuddDeref(value);
841  if (prev == NULL) {
842  hash->bucket[posn] = item->next;
843  } else {
844  prev->next = item->next;
845  }
846  item->next = hash->nextFree;
847  hash->nextFree = item;
848  hash->size--;
849  }
850  return(value);
851  }
852  prev = item;
853  item = item->next;
854  }
855  return(NULL);
856 
857 } /* end of cuddHashTableLookup1 */
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
#define cuddDeref(n)
Definition: cuddInt.h:604
Definition: cudd.h:278
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
DdHashItem * nextFree
Definition: cuddInt.h:307
enum keys key
int value
#define cuddSatDec(x)
Definition: cuddInt.h:896
DdNode * key[1]
Definition: cuddInt.h:299
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:126
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
DdNode* cuddHashTableLookup2 ( DdHashTable hash,
DdNode f,
DdNode g 
)

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

Synopsis [Looks up a key consisting of two pointers in a hash table.]

Description [Looks up a key consisting of two pointer in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup1 cuddHashTableLookup3 cuddHashTableInsert2]

Definition at line 928 of file cuddLCache.c.

932 {
933  unsigned int posn;
934  DdHashItem *item, *prev;
935 
936 #ifdef DD_DEBUG
937  assert(hash->keysize == 2);
938 #endif
939 
940  posn = ddLCHash2(cuddF2L(f),cuddF2L(g),hash->shift);
941  item = hash->bucket[posn];
942  prev = NULL;
943 
944  while (item != NULL) {
945  DdNodePtr *key = item->key;
946  if ((f == key[0]) && (g == key[1])) {
947  DdNode *value = item->value;
948  cuddSatDec(item->count);
949  if (item->count == 0) {
950  cuddDeref(value);
951  if (prev == NULL) {
952  hash->bucket[posn] = item->next;
953  } else {
954  prev->next = item->next;
955  }
956  item->next = hash->nextFree;
957  hash->nextFree = item;
958  hash->size--;
959  }
960  return(value);
961  }
962  prev = item;
963  item = item->next;
964  }
965  return(NULL);
966 
967 } /* end of cuddHashTableLookup2 */
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
#define cuddDeref(n)
Definition: cuddInt.h:604
Definition: cudd.h:278
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
DdHashItem * nextFree
Definition: cuddInt.h:307
enum keys key
int value
#define cuddSatDec(x)
Definition: cuddInt.h:896
DdNode * key[1]
Definition: cuddInt.h:299
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:126
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
DdNode* cuddHashTableLookup3 ( DdHashTable hash,
DdNode f,
DdNode g,
DdNode h 
)

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

Synopsis [Looks up a key consisting of three pointers in a hash table.]

Description [Looks up a key consisting of three pointers in a hash table. Returns the value associated to the key if there is an entry for the given key in the table; NULL otherwise. If the entry is present, its reference counter is decremented if not saturated. If the counter reaches 0, the value of the entry is dereferenced, and the entry is returned to the free list.]

SideEffects [None]

SeeAlso [cuddHashTableLookup cuddHashTableLookup1 cuddHashTableLookup2 cuddHashTableInsert3]

Definition at line 1040 of file cuddLCache.c.

1045 {
1046  unsigned int posn;
1047  DdHashItem *item, *prev;
1048 
1049 #ifdef DD_DEBUG
1050  assert(hash->keysize == 3);
1051 #endif
1052 
1053  posn = ddLCHash3(cuddF2L(f),cuddF2L(g),cuddF2L(h),hash->shift);
1054  item = hash->bucket[posn];
1055  prev = NULL;
1056 
1057  while (item != NULL) {
1058  DdNodePtr *key = item->key;
1059  if ((f == key[0]) && (g == key[1]) && (h == key[2])) {
1060  DdNode *value = item->value;
1061  cuddSatDec(item->count);
1062  if (item->count == 0) {
1063  cuddDeref(value);
1064  if (prev == NULL) {
1065  hash->bucket[posn] = item->next;
1066  } else {
1067  prev->next = item->next;
1068  }
1069  item->next = hash->nextFree;
1070  hash->nextFree = item;
1071  hash->size--;
1072  }
1073  return(value);
1074  }
1075  prev = item;
1076  item = item->next;
1077  }
1078  return(NULL);
1079 
1080 } /* end of cuddHashTableLookup3 */
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
unsigned int size
Definition: cuddInt.h:311
#define cuddDeref(n)
Definition: cuddInt.h:604
Definition: cudd.h:278
ptrint count
Definition: cuddInt.h:297
struct DdHashItem * next
Definition: cuddInt.h:296
#define cuddF2L(f)
Definition: cuddInt.h:718
DdHashItem * nextFree
Definition: cuddInt.h:307
enum keys key
int value
#define cuddSatDec(x)
Definition: cuddInt.h:896
DdNode * key[1]
Definition: cuddInt.h:299
#define assert(ex)
Definition: util_old.h:213
int shift
Definition: cuddInt.h:310
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:142
void cuddHashTableQuit ( DdHashTable hash)

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

Synopsis [Shuts down a hash table.]

Description [Shuts down a hash table, dereferencing all the values.]

SideEffects [None]

SeeAlso [cuddHashTableInit]

Definition at line 595 of file cuddLCache.c.

597 {
598 #ifdef __osf__
599 #pragma pointer_size save
600 #pragma pointer_size short
601 #endif
602  unsigned int i;
603  DdManager *dd = hash->manager;
604  DdHashItem *bucket;
605  DdHashItem **memlist, **nextmem;
606  unsigned int numBuckets = hash->numBuckets;
607 
608  for (i = 0; i < numBuckets; i++) {
609  bucket = hash->bucket[i];
610  while (bucket != NULL) {
611  Cudd_RecursiveDeref(dd, bucket->value);
612  bucket = bucket->next;
613  }
614  }
615 
616  memlist = hash->memoryList;
617  while (memlist != NULL) {
618  nextmem = (DdHashItem **) memlist[0];
619  ABC_FREE(memlist);
620  memlist = nextmem;
621  }
622 
623  ABC_FREE(hash->bucket);
624  ABC_FREE(hash);
625 #ifdef __osf__
626 #pragma pointer_size restore
627 #endif
628 
629  return;
630 
631 } /* end of cuddHashTableQuit */
DdHashItem ** bucket
Definition: cuddInt.h:306
DdNode * value
Definition: cuddInt.h:298
void Cudd_RecursiveDeref(DdManager *table, DdNode *n)
Definition: cuddRef.c:154
DdManager * manager
Definition: cuddInt.h:313
struct DdHashItem * next
Definition: cuddInt.h:296
unsigned int numBuckets
Definition: cuddInt.h:309
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdHashItem ** memoryList
Definition: cuddInt.h:308
static int cuddHashTableResize ( DdHashTable hash)
static

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

Synopsis [Resizes a hash table.]

Description [Resizes a hash table. Returns 1 if successful; 0 otherwise.]

SideEffects [None]

SeeAlso [cuddHashTableInsert]

Definition at line 1277 of file cuddLCache.c.

1279 {
1280  int j;
1281  unsigned int posn;
1282  DdHashItem *item;
1283  DdHashItem *next;
1284 #ifdef __osf__
1285 #pragma pointer_size save
1286 #pragma pointer_size short
1287 #endif
1288  DdNode **key;
1289  int numBuckets;
1290  DdHashItem **buckets;
1291  DdHashItem **oldBuckets = hash->bucket;
1292 #ifdef __osf__
1293 #pragma pointer_size restore
1294 #endif
1295  int shift;
1296  int oldNumBuckets = hash->numBuckets;
1297  extern DD_OOMFP MMoutOfMemory;
1298  DD_OOMFP saveHandler;
1299 
1300  /* Compute the new size of the table. */
1301  numBuckets = oldNumBuckets << 1;
1302  saveHandler = MMoutOfMemory;
1303  MMoutOfMemory = Cudd_OutOfMem;
1304 #ifdef __osf__
1305 #pragma pointer_size save
1306 #pragma pointer_size short
1307 #endif
1308  buckets = ABC_ALLOC(DdHashItem *, numBuckets);
1309  MMoutOfMemory = saveHandler;
1310  if (buckets == NULL) {
1311  hash->maxsize <<= 1;
1312  return(1);
1313  }
1314 
1315  hash->bucket = buckets;
1316  hash->numBuckets = numBuckets;
1317  shift = --(hash->shift);
1318  hash->maxsize <<= 1;
1319  memset(buckets, 0, numBuckets * sizeof(DdHashItem *));
1320 #ifdef __osf__
1321 #pragma pointer_size restore
1322 #endif
1323  if (hash->keysize == 1) {
1324  for (j = 0; j < oldNumBuckets; j++) {
1325  item = oldBuckets[j];
1326  while (item != NULL) {
1327  next = item->next;
1328  key = item->key;
1329  posn = ddLCHash2(cuddF2L(key[0]), cuddF2L(key[0]), shift);
1330  item->next = buckets[posn];
1331  buckets[posn] = item;
1332  item = next;
1333  }
1334  }
1335  } else if (hash->keysize == 2) {
1336  for (j = 0; j < oldNumBuckets; j++) {
1337  item = oldBuckets[j];
1338  while (item != NULL) {
1339  next = item->next;
1340  key = item->key;
1341  posn = ddLCHash2(cuddF2L(key[0]), cuddF2L(key[1]), shift);
1342  item->next = buckets[posn];
1343  buckets[posn] = item;
1344  item = next;
1345  }
1346  }
1347  } else if (hash->keysize == 3) {
1348  for (j = 0; j < oldNumBuckets; j++) {
1349  item = oldBuckets[j];
1350  while (item != NULL) {
1351  next = item->next;
1352  key = item->key;
1353  posn = ddLCHash3(cuddF2L(key[0]), cuddF2L(key[1]), cuddF2L(key[2]), shift);
1354  item->next = buckets[posn];
1355  buckets[posn] = item;
1356  item = next;
1357  }
1358  }
1359  } else {
1360  for (j = 0; j < oldNumBuckets; j++) {
1361  item = oldBuckets[j];
1362  while (item != NULL) {
1363  next = item->next;
1364  posn = ddLCHash(item->key, hash->keysize, shift);
1365  item->next = buckets[posn];
1366  buckets[posn] = item;
1367  item = next;
1368  }
1369  }
1370  }
1371  ABC_FREE(oldBuckets);
1372  return(1);
1373 
1374 } /* end of cuddHashTableResize */
char * memset()
unsigned int keysize
Definition: cuddInt.h:304
DdHashItem ** bucket
Definition: cuddInt.h:306
void(* DD_OOMFP)(long)
Definition: cudd.h:324
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2837
Definition: cudd.h:278
struct DdHashItem * next
Definition: cuddInt.h:296
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
unsigned int numBuckets
Definition: cuddInt.h:309
#define cuddF2L(f)
Definition: cuddInt.h:718
unsigned int maxsize
Definition: cuddInt.h:312
#define ABC_FREE(obj)
Definition: abc_global.h:232
enum keys key
DdNode * key[1]
Definition: cuddInt.h:299
#define ddLCHash2(f, g, shift)
Definition: cuddLCache.c:126
int shift
Definition: cuddInt.h:310
#define ddLCHash3(f, g, h, shift)
Definition: cuddLCache.c:142
#define MMoutOfMemory
Definition: util_hack.h:38
static void cuddLocalCacheAddToList ( DdLocalCache cache)
static

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

Synopsis [Inserts a local cache in the manager list.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1211 of file cuddLCache.c.

1213 {
1214  DdManager *manager = cache->manager;
1215 
1216  cache->next = manager->localCaches;
1217  manager->localCaches = cache;
1218  return;
1219 
1220 } /* end of cuddLocalCacheAddToList */
struct DdLocalCache * next
Definition: cuddInt.h:291
DdLocalCache * localCaches
Definition: cuddInt.h:432
DdManager * manager
Definition: cuddInt.h:290
void cuddLocalCacheClearAll ( DdManager manager)

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

Synopsis [Clears the local caches of a manager.]

Description [Clears the local caches of a manager. Used before reordering.]

SideEffects [None]

SeeAlso []

Definition at line 404 of file cuddLCache.c.

406 {
407  DdLocalCache *cache = manager->localCaches;
408 
409  while (cache != NULL) {
410  memset(cache->item, 0, cache->slots * cache->itemsize);
411  cache = cache->next;
412  }
413  return;
414 
415 } /* end of cuddLocalCacheClearAll */
char * memset()
DdLocalCacheItem * item
Definition: cuddInt.h:281
struct DdLocalCache * next
Definition: cuddInt.h:291
unsigned int itemsize
Definition: cuddInt.h:282
unsigned int slots
Definition: cuddInt.h:284
DdLocalCache * localCaches
Definition: cuddInt.h:432
void cuddLocalCacheClearDead ( DdManager manager)

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

Synopsis [Clears the dead entries of the local caches of a manager.]

Description [Clears the dead entries of the local caches of a manager. Used during garbage collection.]

SideEffects [None]

SeeAlso []

Definition at line 352 of file cuddLCache.c.

354 {
355  DdLocalCache *cache = manager->localCaches;
356  unsigned int keysize;
357  unsigned int itemsize;
358  unsigned int slots;
359  DdLocalCacheItem *item;
360  DdNodePtr *key;
361  unsigned int i, j;
362 
363  while (cache != NULL) {
364  keysize = cache->keysize;
365  itemsize = cache->itemsize;
366  slots = cache->slots;
367  item = cache->item;
368  for (i = 0; i < slots; i++) {
369  if (item->value != NULL) {
370  if (Cudd_Regular(item->value)->ref == 0) {
371  item->value = NULL;
372  } else {
373  key = item->key;
374  for (j = 0; j < keysize; j++) {
375  if (Cudd_Regular(key[j])->ref == 0) {
376  item->value = NULL;
377  break;
378  }
379  }
380  }
381  }
382  item = (DdLocalCacheItem *) ((char *) item + itemsize);
383  }
384  cache = cache->next;
385  }
386  return;
387 
388 } /* end of cuddLocalCacheClearDead */
Definition: cudd.h:278
#define Cudd_Regular(node)
Definition: cudd.h:397
DdNode * value
Definition: cuddInt.h:272
unsigned int keysize
Definition: cuddInt.h:283
DdLocalCacheItem * item
Definition: cuddInt.h:281
struct DdLocalCache * next
Definition: cuddInt.h:291
unsigned int itemsize
Definition: cuddInt.h:282
unsigned int slots
Definition: cuddInt.h:284
DdLocalCache * localCaches
Definition: cuddInt.h:432
DdNode * key[1]
Definition: cuddInt.h:276
enum keys key
DdLocalCache* cuddLocalCacheInit ( DdManager manager,
unsigned int  keySize,
unsigned int  cacheSize,
unsigned int  maxCacheSize 
)

AutomaticEnd Function********************************************************************

Synopsis [Initializes a local computed table.]

Description [Initializes a computed table. Returns a pointer the the new local cache in case of success; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddInitCache]

Definition at line 183 of file cuddLCache.c.

188 {
189  DdLocalCache *cache;
190  int logSize;
191 
192  cache = ABC_ALLOC(DdLocalCache,1);
193  if (cache == NULL) {
194  manager->errorCode = CUDD_MEMORY_OUT;
195  return(NULL);
196  }
197  cache->manager = manager;
198  cache->keysize = keySize;
199  cache->itemsize = (keySize + 1) * sizeof(DdNode *);
200 #ifdef DD_CACHE_PROFILE
201  cache->itemsize += sizeof(ptrint);
202 #endif
203  logSize = cuddComputeFloorLog2(ddMax(cacheSize,manager->slots/2));
204  cacheSize = 1 << logSize;
205  cache->item = (DdLocalCacheItem *)
206  ABC_ALLOC(char, cacheSize * cache->itemsize);
207  if (cache->item == NULL) {
208  manager->errorCode = CUDD_MEMORY_OUT;
209  ABC_FREE(cache);
210  return(NULL);
211  }
212  cache->slots = cacheSize;
213  cache->shift = sizeof(int) * 8 - logSize;
214  cache->maxslots = ddMin(maxCacheSize,manager->slots);
215  cache->minHit = manager->minHit;
216  /* Initialize to avoid division by 0 and immediate resizing. */
217  cache->lookUps = (double) (int) (cacheSize * cache->minHit + 1);
218  cache->hits = 0;
219  manager->memused += cacheSize * cache->itemsize + sizeof(DdLocalCache);
220 
221  /* Initialize the cache. */
222  memset(cache->item, 0, cacheSize * cache->itemsize);
223 
224  /* Add to manager's list of local caches for GC. */
226 
227  return(cache);
228 
229 } /* end of cuddLocalCacheInit */
char * memset()
Definition: cudd.h:278
unsigned int slots
Definition: cuddInt.h:368
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
double minHit
Definition: cuddInt.h:287
unsigned int keysize
Definition: cuddInt.h:283
DdLocalCacheItem * item
Definition: cuddInt.h:281
unsigned int maxslots
Definition: cuddInt.h:289
unsigned int itemsize
Definition: cuddInt.h:282
ABC_PTRINT_T ptrint
Definition: cuddInt.h:260
double hits
Definition: cuddInt.h:288
double lookUps
Definition: cuddInt.h:286
int cuddComputeFloorLog2(unsigned int value)
Definition: cuddCache.c:1079
unsigned int slots
Definition: cuddInt.h:284
#define ddMax(x, y)
Definition: cuddInt.h:832
#define ddMin(x, y)
Definition: cuddInt.h:818
unsigned long memused
Definition: cuddInt.h:449
#define ABC_FREE(obj)
Definition: abc_global.h:232
double minHit
Definition: cuddInt.h:357
struct DdLocalCache DdLocalCache
DdManager * manager
Definition: cuddInt.h:290
static void cuddLocalCacheAddToList(DdLocalCache *cache)
Definition: cuddLCache.c:1211
Cudd_ErrorType errorCode
Definition: cuddInt.h:447
void cuddLocalCacheInsert ( DdLocalCache cache,
DdNodePtr key,
DdNode value 
)

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

Synopsis [Inserts a result in a local cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 272 of file cuddLCache.c.

276 {
277  unsigned int posn;
279 
280  posn = ddLCHash(key,cache->keysize,cache->shift);
281  entry = (DdLocalCacheItem *) ((char *) cache->item +
282  posn * cache->itemsize);
283  memcpy(entry->key,key,cache->keysize * sizeof(DdNode *));
284  entry->value = value;
285 #ifdef DD_CACHE_PROFILE
286  entry->count++;
287 #endif
288 
289 } /* end of cuddLocalCacheInsert */
Definition: cudd.h:278
char * memcpy()
DdNode * value
Definition: cuddInt.h:272
unsigned int keysize
Definition: cuddInt.h:283
DdLocalCacheItem * item
Definition: cuddInt.h:281
static int * entry
Definition: cuddGroup.c:122
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
unsigned int itemsize
Definition: cuddInt.h:282
DdNode * key[1]
Definition: cuddInt.h:276
int value
DdNode* cuddLocalCacheLookup ( DdLocalCache cache,
DdNodePtr key 
)

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

Synopsis [Looks up in a local cache.]

Description [Looks up in a local cache. Returns the result if found; it returns NULL if no result is found.]

SideEffects [None]

SeeAlso []

Definition at line 305 of file cuddLCache.c.

308 {
309  unsigned int posn;
311  DdNode *value;
312 
313  cache->lookUps++;
314  posn = ddLCHash(key,cache->keysize,cache->shift);
315  entry = (DdLocalCacheItem *) ((char *) cache->item +
316  posn * cache->itemsize);
317  if (entry->value != NULL &&
318  memcmp(key,entry->key,cache->keysize*sizeof(DdNode *)) == 0) {
319  cache->hits++;
320  value = Cudd_Regular(entry->value);
321  if (value->ref == 0) {
322  cuddReclaim(cache->manager,value);
323  }
324  return(entry->value);
325  }
326 
327  /* Cache miss: decide whether to resize */
328 
329  if (cache->slots < cache->maxslots &&
330  cache->hits > cache->lookUps * cache->minHit) {
331  cuddLocalCacheResize(cache);
332  }
333 
334  return(NULL);
335 
336 } /* end of cuddLocalCacheLookup */
DdHalfWord ref
Definition: cudd.h:280
Definition: cudd.h:278
#define Cudd_Regular(node)
Definition: cudd.h:397
void cuddReclaim(DdManager *table, DdNode *n)
Definition: cuddRef.c:584
DdNode * value
Definition: cuddInt.h:272
double minHit
Definition: cuddInt.h:287
unsigned int keysize
Definition: cuddInt.h:283
DdLocalCacheItem * item
Definition: cuddInt.h:281
static int * entry
Definition: cuddGroup.c:122
unsigned int maxslots
Definition: cuddInt.h:289
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
unsigned int itemsize
Definition: cuddInt.h:282
double hits
Definition: cuddInt.h:288
double lookUps
Definition: cuddInt.h:286
unsigned int slots
Definition: cuddInt.h:284
int memcmp()
static void cuddLocalCacheResize(DdLocalCache *cache)
Definition: cuddLCache.c:1100
DdNode * key[1]
Definition: cuddInt.h:276
int value
DdManager * manager
Definition: cuddInt.h:290
void cuddLocalCacheQuit ( DdLocalCache cache)

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

Synopsis [Shuts down a local computed table.]

Description [Initializes the computed table. It is called by Cudd_Init. Returns a pointer the the new local cache in case of success; NULL otherwise.]

SideEffects [None]

SeeAlso [cuddLocalCacheInit]

Definition at line 246 of file cuddLCache.c.

248 {
249  cache->manager->memused -=
250  cache->slots * cache->itemsize + sizeof(DdLocalCache);
252  ABC_FREE(cache->item);
253  ABC_FREE(cache);
254 
255  return;
256 
257 } /* end of cuddLocalCacheQuit */
static void cuddLocalCacheRemoveFromList(DdLocalCache *cache)
Definition: cuddLCache.c:1235
DdLocalCacheItem * item
Definition: cuddInt.h:281
unsigned int itemsize
Definition: cuddInt.h:282
unsigned int slots
Definition: cuddInt.h:284
unsigned long memused
Definition: cuddInt.h:449
#define ABC_FREE(obj)
Definition: abc_global.h:232
struct DdLocalCache DdLocalCache
DdManager * manager
Definition: cuddInt.h:290
static void cuddLocalCacheRemoveFromList ( DdLocalCache cache)
static

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

Synopsis [Removes a local cache from the manager list.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1235 of file cuddLCache.c.

1237 {
1238  DdManager *manager = cache->manager;
1239 #ifdef __osf__
1240 #pragma pointer_size save
1241 #pragma pointer_size short
1242 #endif
1243  DdLocalCache **prevCache, *nextCache;
1244 #ifdef __osf__
1245 #pragma pointer_size restore
1246 #endif
1247 
1248  prevCache = &(manager->localCaches);
1249  nextCache = manager->localCaches;
1250 
1251  while (nextCache != NULL) {
1252  if (nextCache == cache) {
1253  *prevCache = nextCache->next;
1254  return;
1255  }
1256  prevCache = &(nextCache->next);
1257  nextCache = nextCache->next;
1258  }
1259  return; /* should never get here */
1260 
1261 } /* end of cuddLocalCacheRemoveFromList */
struct DdLocalCache * next
Definition: cuddInt.h:291
DdLocalCache * localCaches
Definition: cuddInt.h:432
DdManager * manager
Definition: cuddInt.h:290
static void cuddLocalCacheResize ( DdLocalCache cache)
static

AutomaticStart

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

Synopsis [Resizes a local cache.]

Description []

SideEffects [None]

SeeAlso []

Definition at line 1100 of file cuddLCache.c.

1102 {
1103  DdLocalCacheItem *item, *olditem, *entry, *old;
1104  int i, shift;
1105  unsigned int posn;
1106  unsigned int slots, oldslots;
1107  extern DD_OOMFP MMoutOfMemory;
1108  DD_OOMFP saveHandler;
1109 
1110  olditem = cache->item;
1111  oldslots = cache->slots;
1112  slots = cache->slots = oldslots << 1;
1113 
1114 #ifdef DD_VERBOSE
1115  (void) fprintf(cache->manager->err,
1116  "Resizing local cache from %d to %d entries\n",
1117  oldslots, slots);
1118  (void) fprintf(cache->manager->err,
1119  "\thits = %.0f\tlookups = %.0f\thit ratio = %5.3f\n",
1120  cache->hits, cache->lookUps, cache->hits / cache->lookUps);
1121 #endif
1122 
1123  saveHandler = MMoutOfMemory;
1124  MMoutOfMemory = Cudd_OutOfMem;
1125  cache->item = item =
1126  (DdLocalCacheItem *) ABC_ALLOC(char, slots * cache->itemsize);
1127  MMoutOfMemory = saveHandler;
1128  /* If we fail to allocate the new table we just give up. */
1129  if (item == NULL) {
1130 #ifdef DD_VERBOSE
1131  (void) fprintf(cache->manager->err,"Resizing failed. Giving up.\n");
1132 #endif
1133  cache->slots = oldslots;
1134  cache->item = olditem;
1135  /* Do not try to resize again. */
1136  cache->maxslots = oldslots - 1;
1137  return;
1138  }
1139  shift = --(cache->shift);
1140  cache->manager->memused += (slots - oldslots) * cache->itemsize;
1141 
1142  /* Clear new cache. */
1143  memset(item, 0, slots * cache->itemsize);
1144 
1145  /* Copy from old cache to new one. */
1146  for (i = 0; (unsigned) i < oldslots; i++) {
1147  old = (DdLocalCacheItem *) ((char *) olditem + i * cache->itemsize);
1148  if (old->value != NULL) {
1149  posn = ddLCHash(old->key,cache->keysize,shift);
1150  entry = (DdLocalCacheItem *) ((char *) item +
1151  posn * cache->itemsize);
1152  memcpy(entry->key,old->key,cache->keysize*sizeof(DdNode *));
1153  entry->value = old->value;
1154  }
1155  }
1156 
1157  ABC_FREE(olditem);
1158 
1159  /* Reinitialize measurements so as to avoid division by 0 and
1160  ** immediate resizing.
1161  */
1162  cache->lookUps = (double) (int) (slots * cache->minHit + 1);
1163  cache->hits = 0;
1164 
1165 } /* end of cuddLocalCacheResize */
char * memset()
void(* DD_OOMFP)(long)
Definition: cudd.h:324
void Cudd_OutOfMem(long size)
Definition: cuddUtil.c:2837
Definition: cudd.h:278
FILE * err
Definition: cuddInt.h:442
char * memcpy()
#define ABC_ALLOC(type, num)
Definition: abc_global.h:229
DdNode * value
Definition: cuddInt.h:272
double minHit
Definition: cuddInt.h:287
unsigned int keysize
Definition: cuddInt.h:283
DdLocalCacheItem * item
Definition: cuddInt.h:281
static int * entry
Definition: cuddGroup.c:122
unsigned int maxslots
Definition: cuddInt.h:289
static DD_INLINE unsigned int ddLCHash(DdNodePtr *key, unsigned int keysize, int shift)
Definition: cuddLCache.c:1182
unsigned int itemsize
Definition: cuddInt.h:282
double hits
Definition: cuddInt.h:288
double lookUps
Definition: cuddInt.h:286
unsigned int slots
Definition: cuddInt.h:284
unsigned long memused
Definition: cuddInt.h:449
DdNode * key[1]
Definition: cuddInt.h:276
#define ABC_FREE(obj)
Definition: abc_global.h:232
DdManager * manager
Definition: cuddInt.h:290
#define MMoutOfMemory
Definition: util_hack.h:38
static DD_INLINE unsigned int ddLCHash ( DdNodePtr key,
unsigned int  keysize,
int  shift 
)
static

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

Synopsis [Computes the hash value for a local cache.]

Description [Computes the hash value for a local cache. Returns the bucket index.]

SideEffects [None]

SeeAlso []

Definition at line 1182 of file cuddLCache.c.

1186 {
1187  unsigned int val = (unsigned int) (ptrint) key[0] * DD_P2;
1188  unsigned int i;
1189 
1190  for (i = 1; i < keysize; i++) {
1191  val = val * DD_P1 + (int) (ptrint) key[i];
1192  }
1193 
1194  return(val >> shift);
1195 
1196 } /* end of ddLCHash */
ABC_PTRINT_T ptrint
Definition: cuddInt.h:260
#define DD_P2
Definition: cuddInt.h:156
#define DD_P1
Definition: cuddInt.h:155

Variable Documentation

char rcsid [] DD_UNUSED = "$Id: cuddLCache.c,v 1.24 2009/03/08 02:49:02 fabio Exp $"
static

Definition at line 103 of file cuddLCache.c.