Author: sewardj
Date: 2008-02-15 22:02:30 +0000 (Fri, 15 Feb 2008)
New Revision: 7409

Log:
Try to sort out signedness problems in hg_wordfm.[ch], and do a bunch
of other tidying too.

* All these word-based abstractions (WordFM, WordSet, WordBag) now
  operate on unsigned words (UWord), whereas they previously operated
  on signed words (Word).  This became a problem, when using unboxed
  comparisons, with the introduction of HG_(initIterAtFM), which
  allows iteration over parts of mappings.  Iterating over a mapping in
  increasing order of signed Word keys is not what callers expect when
  iterating through maps whose keys representing addresses (Addr) since
  Addr is unsigned, and causes logical problems and assertion
  failures.

* Change various size-of-things types from signed to unsigned, and
  make them consistently word sized.  For example the return type
  of HG_(sizeFM) used to be an Int, which never made any sense
  (the size can't be negative, and, on a 64-bit platform, the 
  map could have more than 2G elements, in which case an Int can't
  represent the result).  So make the return value a UWord instead.
  This should generally help avoid obscure overflow problems on 64-bit 
  platforms.



Modified:
   trunk/helgrind/hg_main.c
   trunk/helgrind/hg_wordfm.c
   trunk/helgrind/hg_wordfm.h
   trunk/helgrind/hg_wordset.c
   trunk/helgrind/hg_wordset.h


Modified: trunk/helgrind/hg_main.c
===================================================================
--- trunk/helgrind/hg_main.c    2008-02-14 16:55:01 UTC (rev 7408)
+++ trunk/helgrind/hg_main.c    2008-02-15 22:02:30 UTC (rev 7409)
@@ -2516,7 +2516,7 @@
    Char*     how = "no error";
    Thread*   thr;
    WordSetID wsA, wsW;
-   Word*     ls_words;
+   UWord*    ls_words;
    Word      ls_size, i;
    Lock*     lk;
    Segment*  seg;
@@ -2676,7 +2676,7 @@
    Word    smga;
    SecMap* sm;
    Word    i, j, ws_size, n_valid_tags;
-   Word*   ws_words;
+   UWord*  ws_words;
    Addr*   valid_tags;
    HG_(initIterFM)( map_shmem );
    // for sm in SecMaps {
@@ -6614,7 +6614,7 @@
    }
    LAOGLinkExposition;
 
-static Word cmp_LAOGLinkExposition ( Word llx1W, Word llx2W ) {
+static Word cmp_LAOGLinkExposition ( UWord llx1W, UWord llx2W ) {
    /* Compare LAOGLinkExposition*s by (src_ga,dst_ga) field pair. */
    LAOGLinkExposition* llx1 = (LAOGLinkExposition*)llx1W;
    LAOGLinkExposition* llx2 = (LAOGLinkExposition*)llx2W;
@@ -6631,7 +6631,7 @@
 
 static void laog__show ( Char* who ) {
    Word i, ws_size;
-   Word* ws_words;
+   UWord* ws_words;
    Lock* me;
    LAOGLinks* links;
    VG_(printf)("laog (requested by %s) {\n", who);
@@ -6791,7 +6791,7 @@
 __attribute__((noinline))
 static void laog__sanity_check ( Char* who ) {
    Word i, ws_size;
-   Word* ws_words;
+   UWord* ws_words;
    Lock* me;
    LAOGLinks* links;
    if ( !laog )
@@ -6845,7 +6845,7 @@
    Lock*     here;
    WordSetID succs;
    Word      succs_size;
-   Word*     succs_words;
+   UWord*    succs_words;
    //laog__sanity_check();
 
    /* If the destination set is empty, we can never get there from
@@ -6897,7 +6897,7 @@
                Lock*   lk
             )
 {
-   Word*    ls_words;
+   UWord*   ls_words;
    Word     ls_size, i;
    Lock*    other;
 
@@ -6982,7 +6982,7 @@
 {
    WordSetID preds, succs;
    Word preds_size, succs_size, i, j;
-   Word *preds_words, *succs_words;
+   UWord *preds_words, *succs_words;
 
    preds = laog__preds( lk );
    succs = laog__succs( lk );
@@ -7012,8 +7012,8 @@
                WordSetID /* in univ_laog */ locksToDelete
             )
 {
-   Word  i, ws_size;
-   Word* ws_words;
+   Word   i, ws_size;
+   UWord* ws_words;
 
    if (!laog)
       laog = HG_(newFM)( hg_zalloc, hg_free, NULL/*unboxedcmp*/ );
@@ -7716,7 +7716,7 @@
 /* maps (by value) strings to a copy of them in ARENA_TOOL */
 static UWord stats__string_table_queries = 0;
 static WordFM* string_table = NULL;
-static Word string_table_cmp ( Word s1, Word s2 ) {
+static Word string_table_cmp ( UWord s1, UWord s2 ) {
    return (Word)VG_(strcmp)( (HChar*)s1, (HChar*)s2 );
 }
 static HChar* string_table_strdup ( HChar* str ) {
@@ -7744,7 +7744,7 @@
 /* maps from Lock .unique fields to LockP*s */
 static UWord stats__ga_LockN_to_P_queries = 0;
 static WordFM* yaWFM = NULL;
-static Word lock_unique_cmp ( Word lk1W, Word lk2W )
+static Word lock_unique_cmp ( UWord lk1W, UWord lk2W )
 {
    Lock* lk1 = (Lock*)lk1W;
    Lock* lk2 = (Lock*)lk2W;
@@ -8084,8 +8084,8 @@
 static XArray* /* of Thread* */ get_sorted_thread_set ( WordSetID tset )
 {
    XArray* xa;
-   Word*   ts_words;
-   Word    ts_size, i;
+   UWord*  ts_words;
+   UWord   ts_size, i;
    xa = VG_(newXA)( hg_zalloc, hg_free, sizeof(Thread*) );
    tl_assert(xa);
    HG_(getPayloadWS)( &ts_words, &ts_size, univ_tsets, tset );

Modified: trunk/helgrind/hg_wordfm.c
===================================================================
--- trunk/helgrind/hg_wordfm.c  2008-02-14 16:55:01 UTC (rev 7408)
+++ trunk/helgrind/hg_wordfm.c  2008-02-15 22:02:30 UTC (rev 7409)
@@ -82,8 +82,8 @@
 /* One element of the AVL tree */
 typedef
    struct _AvlNode {
-      Word key;
-      Word val;
+      UWord key;
+      UWord val;
       struct _AvlNode* child[2]; /* [0] is left subtree, [1] is right */
       Char balance; /* do not make this unsigned */
    }
@@ -91,7 +91,7 @@
 
 typedef 
    struct {
-      Word w;
+      UWord w;
       Bool b;
    }
    MaybeWord;
@@ -102,14 +102,14 @@
    AvlNode* root;
    void*    (*alloc_nofail)( SizeT );
    void     (*dealloc)(void*);
-   Word     (*kCmp)(Word,Word);
+   Word     (*kCmp)(UWord,UWord);
    AvlNode* nodeStack[WFM_STKMAX]; // Iterator node stack
    Int      numStack[WFM_STKMAX];  // Iterator num stack
    Int      stackTop;              // Iterator stack pointer, one past end
 }; 
 
 /* forward */
-static Bool avl_removeroot_wrk(AvlNode** t, Word(*kCmp)(Word,Word));
+static Bool avl_removeroot_wrk(AvlNode** t, Word(*kCmp)(UWord,UWord));
 
 /* Swing to the left.  Warning: no balance maintainance. */
 static void avl_swl ( AvlNode** root )
@@ -154,16 +154,16 @@
 }
 
 /* Find size of a non-NULL tree. */
-static Word size_avl_nonNull ( AvlNode* nd )
+static UWord size_avl_nonNull ( AvlNode* nd )
 {
    return 1 + (nd->child[0] ? size_avl_nonNull(nd->child[0]) : 0)
             + (nd->child[1] ? size_avl_nonNull(nd->child[1]) : 0);
 }
 
-/* Signedly compare w1 and w2.  If w1 < w2, produce a negative number;
-   if w1 > w2 produce a positive number, and if w1 == w2 produce
-   zero. */
-static inline Word cmp_signed_Words ( Word w1, Word w2 ) {
+/* Unsignedly compare w1 and w2.  If w1 < w2, produce a negative
+   number; if w1 > w2 produce a positive number, and if w1 == w2
+   produce zero. */
+static inline Word cmp_unsigned_Words ( UWord w1, UWord w2 ) {
    if (w1 < w2) return -1;
    if (w1 > w2) return 1;
    return 0;
@@ -179,7 +179,7 @@
 Bool avl_insert_wrk ( AvlNode**         rootp, 
                       /*OUT*/MaybeWord* oldV,
                       AvlNode*          a, 
-                      Word              (*kCmp)(Word,Word) )
+                      Word              (*kCmp)(UWord,UWord) )
 {
    Word cmpres;
 
@@ -196,8 +196,8 @@
    }
 
    cmpres = kCmp ? /*boxed*/   kCmp( (*rootp)->key, a->key )
-                 : /*unboxed*/ cmp_signed_Words( (Word)(*rootp)->key,
-                                                 (Word)a->key );
+                 : /*unboxed*/ cmp_unsigned_Words( (UWord)(*rootp)->key,
+                                                   (UWord)a->key );
 
    if (cmpres > 0) {
       /* insert into the left subtree */
@@ -280,13 +280,13 @@
 static
 Bool avl_remove_wrk ( AvlNode** rootp, 
                       AvlNode*  a, 
-                      Word(*kCmp)(Word,Word) )
+                      Word(*kCmp)(UWord,UWord) )
 {
    Bool ch;
    Word cmpres;
    cmpres = kCmp ? /*boxed*/   kCmp( (*rootp)->key, a->key )
-                 : /*unboxed*/ cmp_signed_Words( (Word)(*rootp)->key,
-                                                 (Word)a->key );
+                 : /*unboxed*/ cmp_unsigned_Words( (UWord)(*rootp)->key,
+                                                   (UWord)a->key );
 
    if (cmpres > 0){
       /* remove from the left subtree */
@@ -372,7 +372,7 @@
  */
 static 
 Bool avl_removeroot_wrk ( AvlNode** rootp, 
-                          Word(*kCmp)(Word,Word) )
+                          Word(*kCmp)(UWord,UWord) )
 {
    Bool     ch;
    AvlNode* a;
@@ -407,7 +407,7 @@
 }
 
 static 
-AvlNode* avl_find_node ( AvlNode* t, Word k, Word(*kCmp)(Word,Word) )
+AvlNode* avl_find_node ( AvlNode* t, Word k, Word(*kCmp)(UWord,UWord) )
 {
    if (kCmp) {
       /* Boxed comparisons */
@@ -425,7 +425,7 @@
       UWord cmpresU; /* unsigned */
       while (True) {
          if (t == NULL) return NULL; /* unlikely ==> predictable */
-         cmpresS = cmp_signed_Words( (Word)t->key, (Word)k );
+         cmpresS = cmp_unsigned_Words( (UWord)t->key, (UWord)k );
          if (cmpresS == 0) return t; /* unlikely ==> predictable */
          cmpresU = (UWord)cmpresS;
          cmpresU >>=/*unsigned*/ (8 * sizeof(cmpresU) - 1);
@@ -476,8 +476,8 @@
 
 static 
 AvlNode* avl_dopy ( AvlNode* nd, 
-                    Word(*dopyK)(Word), 
-                    Word(*dopyV)(Word),
+                    UWord(*dopyK)(UWord), 
+                    UWord(*dopyV)(UWord),
                     void*(alloc_nofail)(SizeT) )
 {
    AvlNode* nyu;
@@ -529,7 +529,7 @@
 static void initFM ( WordFM* fm,
                      void*   (*alloc_nofail)( SizeT ),
                      void    (*dealloc)(void*),
-                     Word    (*kCmp)(Word,Word) )
+                     Word    (*kCmp)(UWord,UWord) )
 {
    fm->root         = 0;
    fm->kCmp         = kCmp;
@@ -540,10 +540,14 @@
 
 /* --- Public interface functions --- */
 
-/* Allocate and Initialise a WordFM. */
+/* Allocate and initialise a WordFM.  If kCmp is non-NULL, elements in
+   the set are ordered according to the ordering specified by kCmp,
+   which becomes obvious if you use VG_(initIterFM),
+   VG_(initIterAtFM), VG_(nextIterFM), VG_(doneIterFM) to iterate over
+   sections of the map, or the whole thing. */
 WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
                      void  (*dealloc)(void*),
-                     Word  (*kCmp)(Word,Word) )
+                     Word  (*kCmp)(UWord,UWord) )
 {
    WordFM* fm = alloc_nofail(sizeof(WordFM));
    tl_assert(fm);
@@ -552,8 +556,8 @@
 }
 
 static void avl_free ( AvlNode* nd, 
-                       void(*kFin)(Word),
-                       void(*vFin)(Word),
+                       void(*kFin)(UWord),
+                       void(*vFin)(UWord),
                        void(*dealloc)(void*) )
 {
    if (!nd)
@@ -572,7 +576,7 @@
 
 /* Free up the FM.  If kFin is non-NULL, it is applied to keys
    before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM* fm, void(*kFin)(Word), void(*vFin)(Word) )
+void HG_(deleteFM) ( WordFM* fm, void(*kFin)(UWord), void(*vFin)(UWord) )
 {
    void(*dealloc)(void*) = fm->dealloc;
    avl_free( fm->root, kFin, vFin, dealloc );
@@ -581,7 +585,7 @@
 }
 
 /* Add (k,v) to fm. */
-void HG_(addToFM) ( WordFM* fm, Word k, Word v )
+void HG_(addToFM) ( WordFM* fm, UWord k, UWord v )
 {
    MaybeWord oldV;
    AvlNode* node;
@@ -599,7 +603,7 @@
 
 // Delete key from fm, returning associated key and val if found
 Bool HG_(delFromFM) ( WordFM* fm,
-                      /*OUT*/Word* oldK, /*OUT*/Word* oldV, Word key )
+                      /*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key )
 {
    AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
    if (node) {
@@ -617,7 +621,7 @@
 
 // Look up in fm, assigning found key & val at spec'd addresses
 Bool HG_(lookupFM) ( WordFM* fm, 
-                     /*OUT*/Word* keyP, /*OUT*/Word* valP, Word key )
+                     /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key )
 {
    AvlNode* node = avl_find_node( fm->root, key, fm->kCmp );
    if (node) {
@@ -631,7 +635,7 @@
    }
 }
 
-Word HG_(sizeFM) ( WordFM* fm )
+UWord HG_(sizeFM) ( WordFM* fm )
 {
    // Hmm, this is a bad way to do this
    return fm->root ? size_avl_nonNull( fm->root ) : 0;
@@ -646,10 +650,11 @@
       stackPush(fm, fm->root, 1);
 }
 
-// set up FM for iteration 
-// so that the first key subsequently produced by HG_(nextIterFM) is
-// the smallest key in the map >= start_at.
-void HG_(initIterAtFM) ( WordFM* fm, Word start_at )
+// set up FM for iteration so that the first key subsequently produced
+// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// Naturally ">=" is defined by the comparison function supplied to
+// HG_(newFM), as documented above.
+void HG_(initIterAtFM) ( WordFM* fm, UWord start_at )
 {
    Int     i;
    AvlNode *n, *t;
@@ -671,7 +676,7 @@
 
       cmpresS 
          = fm->kCmp ? /*boxed*/   fm->kCmp( t->key, start_at )
-                    : /*unboxed*/ cmp_signed_Words( t->key, start_at );
+                    : /*unboxed*/ cmp_unsigned_Words( t->key, start_at );
 
       if (cmpresS == 0) {
          // We found the exact key -- we are done. 
@@ -699,7 +704,7 @@
 
 // get next key/val pair.  Will tl_assert if fm has been modified
 // or looked up in since initIter{,At}FM was called.
-Bool HG_(nextIterFM) ( WordFM* fm, /*OUT*/Word* pKey, /*OUT*/Word* pVal )
+Bool HG_(nextIterFM) ( WordFM* fm, /*OUT*/UWord* pKey, /*OUT*/UWord* pVal )
 {
    Int i = 0;
    AvlNode* n = NULL;
@@ -740,7 +745,7 @@
 {
 }
 
-WordFM* HG_(dopyFM) ( WordFM* fm, Word(*dopyK)(Word), Word(*dopyV)(Word) )
+WordFM* HG_(dopyFM) ( WordFM* fm, UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) )
 {
    WordFM* nyu; 
 
@@ -796,9 +801,9 @@
    dealloc(bag);
 }
 
-void HG_(addToBag)( WordBag* bag, Word w )
+void HG_(addToBag)( WordBag* bag, UWord w )
 {
-   Word key, count;
+   UWord key, count;
    if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
@@ -808,9 +813,9 @@
    }
 }
 
-Word HG_(elemBag) ( WordBag* bag, Word w )
+UWord HG_(elemBag) ( WordBag* bag, UWord w )
 {
-   Word key, count;
+   UWord key, count;
    if (HG_(lookupFM)( bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
@@ -820,15 +825,15 @@
    }
 }
 
-Word HG_(sizeUniqueBag) ( WordBag* bag )
+UWord HG_(sizeUniqueBag) ( WordBag* bag )
 {
    return HG_(sizeFM)( bag->fm );
 }
 
-static Word sizeTotalBag_wrk ( AvlNode* nd )
+static UWord sizeTotalBag_wrk ( AvlNode* nd )
 {
    /* unchecked pre: nd is non-NULL */
-   Word w = nd->val;
+   UWord w = nd->val;
    tl_assert(w >= 1);
    if (nd->child[0])
       w += sizeTotalBag_wrk(nd->child[0]);
@@ -836,7 +841,7 @@
       w += sizeTotalBag_wrk(nd->child[1]);
    return w;
 }
-Word HG_(sizeTotalBag)( WordBag* bag )
+UWord HG_(sizeTotalBag)( WordBag* bag )
 {
    if (bag->fm->root)
       return sizeTotalBag_wrk(bag->fm->root);
@@ -844,9 +849,9 @@
       return 0;
 }
 
-Bool HG_(delFromBag)( WordBag* bag, Word w )
+Bool HG_(delFromBag)( WordBag* bag, UWord w )
 {
-   Word key, count;
+   UWord key, count;
    if (HG_(lookupFM)(bag->fm, &key, &count, w)) {
       tl_assert(key == w);
       tl_assert(count >= 1);
@@ -879,7 +884,7 @@
    return nd->val == 1;
 }
 
-Word HG_(anyElementOfBag)( WordBag* bag )
+UWord HG_(anyElementOfBag)( WordBag* bag )
 {
    /* Return an arbitrarily chosen element in the bag.  We might as
       well return the one at the root of the underlying AVL tree. */
@@ -894,7 +899,7 @@
    HG_(initIterFM)(bag->fm);
 }
 
-Bool HG_(nextIterBag)( WordBag* bag, /*OUT*/Word* pVal, /*OUT*/Word* pCount )
+Bool HG_(nextIterBag)( WordBag* bag, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount )
 {
    return HG_(nextIterFM)( bag->fm, pVal, pCount );
 }
@@ -924,14 +929,14 @@
 // Just lookup for each element in range and count. 
 int search_all_elements_in_range_1(WordFM *map, long beg, long end)
 {
-   int n_found = 0;
-   int i;
-   for(i = beg; i < end; i++) {
-      Word key, val;
-      if(HG_(lookupFM)(map, &key, &val, (Word)i)){
+   long n_found = 0;
+   long i;
+   for (i = beg; i < end; i++) {
+      UWord key, val;
+      if (HG_(lookupFM)(map, &key, &val, (Word)i)) {
          n_found++;
          assert(key == -val);
-         assert(key == (Word)i);
+         assert(key == (UWord)i);
       }
    }
    return n_found;
@@ -943,9 +948,9 @@
 int search_all_elements_in_range_2(WordFM *map, long beg, long end)
 {
    int n_found = 0;
-   Word key, val;
+   UWord key, val;
    HG_(initIterAtFM)(map, beg);
-   while(HG_(nextIterFM)(map, &key, &val) && (int)key < end) {
+   while (HG_(nextIterFM)(map, &key, &val) && (long)key < end) {
       assert(key == -val);
       n_found++;
    }
@@ -955,11 +960,11 @@
 
 int main(void)
 {
-   int i, n = 10;
-   Word key, val;
-   int beg, end;
+   long i, n = 10;
+   UWord key, val;
+   long beg, end;
 
-   printf("Create the map, n=%d\n", n);
+   printf("Create the map, n=%ld\n", n);
    WordFM *map = HG_(newFM)(malloc, free, NULL/*unboxed Word cmp*/);
 
    printf("Add keys: ");
@@ -968,12 +973,12 @@
       printf("%ld ", val);
       HG_(addToFM)(map, val, -val);
    }
-   assert(HG_(sizeFM)(map) == n);
+   assert(HG_(sizeFM)(map) == (UWord)n);
    printf("\n");
    printf("Iterate elements, size=%d\n", (int)HG_(sizeFM)(map));
    HG_(initIterFM)(map);
 
-   while(HG_(nextIterFM(map, &key, &val))){
+   while (HG_(nextIterFM(map, &key, &val))) {
    //   int j;
    //   printf("Stack k=%d\n", (int)key);
    //   for(j = map->stackTop-1; j >= 0; j--) {
@@ -988,7 +993,7 @@
    for(beg = 0; beg <= n*2; beg++) {
       HG_(initIterAtFM)(map, (Word)beg);
       int prev = -1; 
-      printf("StartWith: %d: ", beg);
+      printf("StartWith: %ld: ", beg);
       int n_iter = 0;
 
       while(HG_(nextIterFM(map, &key, &val))) {

Modified: trunk/helgrind/hg_wordfm.h
===================================================================
--- trunk/helgrind/hg_wordfm.h  2008-02-14 16:55:01 UTC (rev 7408)
+++ trunk/helgrind/hg_wordfm.h  2008-02-15 22:02:30 UTC (rev 7409)
@@ -59,43 +59,48 @@
 
 typedef  struct _WordFM  WordFM; /* opaque */
 
-/* Allocate and initialise a WordFM */
+/* Allocate and initialise a WordFM.  If kCmp is non-NULL, elements in
+   the set are ordered according to the ordering specified by kCmp,
+   which becomes obvious if you use VG_(initIterFM),
+   VG_(initIterAtFM), VG_(nextIterFM), VG_(doneIterFM) to iterate over
+   sections of the map, or the whole thing. */
 WordFM* HG_(newFM) ( void* (*alloc_nofail)( SizeT ),
                      void  (*dealloc)(void*),
-                     Word  (*kCmp)(Word,Word) );
+                     Word  (*kCmp)(UWord,UWord) );
 
 /* Free up the FM.  If kFin is non-NULL, it is applied to keys
    before the FM is deleted; ditto with vFin for vals. */
-void HG_(deleteFM) ( WordFM*, void(*kFin)(Word), void(*vFin)(Word) );
+void HG_(deleteFM) ( WordFM*, void(*kFin)(UWord), void(*vFin)(UWord) );
 
 /* Add (k,v) to fm.  If a binding for k already exists, it is updated
    to map to this new v.  In that case we should really return the
    previous v so that caller can finalise it.  Oh well. */
-void HG_(addToFM) ( WordFM* fm, Word k, Word v );
+void HG_(addToFM) ( WordFM* fm, UWord k, UWord v );
 
 // Delete key from fm, returning associated key and val if found
 Bool HG_(delFromFM) ( WordFM* fm,
-                      /*OUT*/Word* oldK, /*OUT*/Word* oldV, Word key );
+                      /*OUT*/UWord* oldK, /*OUT*/UWord* oldV, UWord key );
 
 // Look up in fm, assigning found key & val at spec'd addresses
 Bool HG_(lookupFM) ( WordFM* fm, 
-                     /*OUT*/Word* keyP, /*OUT*/Word* valP, Word key );
+                     /*OUT*/UWord* keyP, /*OUT*/UWord* valP, UWord key );
 
 // How many elements are there in fm?
-Word HG_(sizeFM) ( WordFM* fm );
+UWord HG_(sizeFM) ( WordFM* fm );
 
 // set up FM for iteration
 void HG_(initIterFM) ( WordFM* fm );
 
-// set up FM for iteration 
-// so that the first key subsequently produced by HG_(nextIterFM) is
-// the smallest key in the map >= start_at.
-void HG_(initIterAtFM) ( WordFM* fm, Word start_at );
+// set up FM for iteration so that the first key subsequently produced
+// by HG_(nextIterFM) is the smallest key in the map >= start_at.
+// Naturally ">=" is defined by the comparison function supplied to
+// HG_(newFM), as documented above.
+void HG_(initIterAtFM) ( WordFM* fm, UWord start_at );
 
 // get next key/val pair.  Will assert if fm has been modified
 // or looked up in since initIterFM/initIterWithStartFM was called.
 Bool HG_(nextIterFM) ( WordFM* fm,
-                       /*OUT*/Word* pKey, /*OUT*/Word* pVal );
+                       /*OUT*/UWord* pKey, /*OUT*/UWord* pVal );
 
 // clear the I'm iterating flag
 void HG_(doneIterFM) ( WordFM* fm );
@@ -107,7 +112,7 @@
 // could not allocate memory, in which case the copy is abandoned
 // and NULL is returned.  Ditto with dopyV for values.
 WordFM* HG_(dopyFM) ( WordFM* fm,
-                      Word(*dopyK)(Word), Word(*dopyV)(Word) );
+                      UWord(*dopyK)(UWord), UWord(*dopyV)(UWord) );
 
 //------------------------------------------------------------------//
 //---                         end WordFM                         ---//
@@ -129,13 +134,13 @@
 void HG_(deleteBag) ( WordBag* );
 
 /* Add a word. */
-void HG_(addToBag)( WordBag*, Word );
+void HG_(addToBag)( WordBag*, UWord );
 
 /* Find out how many times the given word exists in the bag. */
-Word HG_(elemBag) ( WordBag*, Word );
+UWord HG_(elemBag) ( WordBag*, UWord );
 
 /* Delete a word from the bag. */
-Bool HG_(delFromBag)( WordBag*, Word );
+Bool HG_(delFromBag)( WordBag*, UWord );
 
 /* Is the bag empty? */
 Bool HG_(isEmptyBag)( WordBag* );
@@ -144,15 +149,15 @@
 Bool HG_(isSingletonTotalBag)( WordBag* );
 
 /* Return an arbitrary element from the bag. */
-Word HG_(anyElementOfBag)( WordBag* );
+UWord HG_(anyElementOfBag)( WordBag* );
 
 /* How many different / total elements are in the bag? */
-Word HG_(sizeUniqueBag)( WordBag* ); /* fast */
-Word HG_(sizeTotalBag)( WordBag* );  /* warning: slow */
+UWord HG_(sizeUniqueBag)( WordBag* ); /* fast */
+UWord HG_(sizeTotalBag)( WordBag* );  /* warning: slow */
 
 /* Iterating over the elements of a bag. */
 void HG_(initIterBag)( WordBag* );
-Bool HG_(nextIterBag)( WordBag*, /*OUT*/Word* pVal, /*OUT*/Word* pCount );
+Bool HG_(nextIterBag)( WordBag*, /*OUT*/UWord* pVal, /*OUT*/UWord* pCount );
 void HG_(doneIterBag)( WordBag* );
 
 //------------------------------------------------------------------//

Modified: trunk/helgrind/hg_wordset.c
===================================================================
--- trunk/helgrind/hg_wordset.c 2008-02-14 16:55:01 UTC (rev 7408)
+++ trunk/helgrind/hg_wordset.c 2008-02-15 22:02:30 UTC (rev 7409)
@@ -62,8 +62,8 @@
 typedef
    struct {
       WCacheEnt ent[N_WCACHE_STAT_MAX];
-      Word      dynMax; /* 1 .. N_WCACHE_STAT_MAX inclusive */
-      Word      inUse;  /* 0 .. dynMax inclusive */
+      UWord     dynMax; /* 1 .. N_WCACHE_STAT_MAX inclusive */
+      UWord     inUse;  /* 0 .. dynMax inclusive */
    }
    WCache;
 
@@ -77,7 +77,7 @@
 
 #define WCache_LOOKUP_AND_RETURN(_retty,_zzcache,_zzarg1,_zzarg2)    \
    do {                                                              \
-      Word    _i;                                                    \
+      UWord   _i;                                                    \
       UWord   _arg1  = (UWord)(_zzarg1);                             \
       UWord   _arg2  = (UWord)(_zzarg2);                             \
       WCache* _cache = &(_zzcache);                                  \
@@ -130,8 +130,8 @@
 typedef
    struct {
       WordSetU* owner; /* for sanity checking */
-      Word*     words;
-      Int       size; /* Really this should be SizeT */
+      UWord*    words;
+      UWord     size; /* Really this should be SizeT */
    }
    WordVec;
 
@@ -144,8 +144,8 @@
       void      (*dealloc)(void*);
       WordFM*   vec2ix; /* WordVec-to-WordSet mapping tree */
       WordVec** ix2vec; /* WordSet-to-WordVec mapping array */
-      UInt      ix2vec_size;
-      UInt      ix2vec_used;
+      UWord     ix2vec_size;
+      UWord     ix2vec_used;
       WordSet   empty; /* cached, for speed */
       /* Caches for some operations */
       WCache    cache_addTo;
@@ -172,7 +172,7 @@
 
 /* Create a new WordVec of the given size. */
 
-static WordVec* new_WV_of_size ( WordSetU* wsu, Int sz )
+static WordVec* new_WV_of_size ( WordSetU* wsu, UWord sz )
 {
    WordVec* wv;
    tl_assert(sz >= 0);
@@ -181,7 +181,7 @@
    wv->words = NULL;
    wv->size = sz;
    if (sz > 0) {
-     wv->words = wsu->alloc( (SizeT)sz * sizeof(Word) );
+     wv->words = wsu->alloc( (SizeT)sz * sizeof(UWord) );
    }
    return wv;
 }
@@ -194,16 +194,16 @@
    }
    dealloc(wv);
 }
-static void delete_WV_for_FM ( Word wv ) {
+static void delete_WV_for_FM ( UWord wv ) {
    delete_WV( (WordVec*)wv );
 }
 
-static Word cmp_WordVecs_for_FM ( Word wv1W, Word wv2W )
+static Word cmp_WordVecs_for_FM ( UWord wv1W, UWord wv2W )
 {
-   Int      i;
+   UWord    i;
    WordVec* wv1    = (WordVec*)wv1W;
    WordVec* wv2    = (WordVec*)wv2W;
-   Int      common = wv1->size < wv2->size ? wv1->size : wv2->size;
+   UWord    common = wv1->size < wv2->size ? wv1->size : wv2->size;
    for (i = 0; i < common; i++) {
       if (wv1->words[i] == wv2->words[i])
          continue;
@@ -275,7 +275,7 @@
 {
    Bool     have;
    WordVec* wv_old;
-   Word/*Set*/ ix_old = -1;
+   UWord/*Set*/ ix_old = -1;
    /* Really WordSet, but need something that can safely be casted to
       a Word* in the lookupFM.  Making it WordSet (which is 32 bits)
       causes failures on a 64-bit platform. */
@@ -358,7 +358,7 @@
    }
 }
 
-Bool HG_(isSingletonWS) ( WordSetU* wsu, WordSet ws, Word w )
+Bool HG_(isSingletonWS) ( WordSetU* wsu, WordSet ws, UWord w )
 {
    WordVec* wv;
    tl_assert(wsu);
@@ -367,7 +367,7 @@
    return (Bool)(wv->size == 1 && wv->words[0] == w);
 }
 
-Int HG_(cardinalityWS) ( WordSetU* wsu, WordSet ws )
+UWord HG_(cardinalityWS) ( WordSetU* wsu, WordSet ws )
 {
    WordVec* wv;
    tl_assert(wsu);
@@ -376,7 +376,7 @@
    return wv->size;
 }
 
-Word HG_(anyElementOfWS) ( WordSetU* wsu, WordSet ws )
+UWord HG_(anyElementOfWS) ( WordSetU* wsu, WordSet ws )
 {
    WordVec* wv;
    tl_assert(wsu);
@@ -386,13 +386,13 @@
    return wv->words[0];
 }
 
-Int HG_(cardinalityWSU) ( WordSetU* wsu )
+UWord HG_(cardinalityWSU) ( WordSetU* wsu )
 {
    tl_assert(wsu);
-   return (Int)wsu->ix2vec_used;
+   return wsu->ix2vec_used;
 }
 
-void HG_(getPayloadWS) ( /*OUT*/Word** words, /*OUT*/Word* nWords, 
+void HG_(getPayloadWS) ( /*OUT*/UWord** words, /*OUT*/UWord* nWords, 
                          WordSetU* wsu, WordSet ws )
 {
    WordVec* wv;
@@ -414,7 +414,7 @@
 Bool HG_(saneWS_SLOW) ( WordSetU* wsu, WordSet ws )
 {
    WordVec* wv;
-   Int      i;
+   UWord    i;
    if (wsu == NULL) return False;
    if (ws < 0 || ws >= wsu->ix2vec_used)
       return False;
@@ -431,9 +431,9 @@
    return True;
 }
 
-Bool HG_(elemWS) ( WordSetU* wsu, WordSet ws, Word w )
+Bool HG_(elemWS) ( WordSetU* wsu, WordSet ws, UWord w )
 {
-   Int      i;
+   UWord    i;
    WordVec* wv = do_ix2vec( wsu, ws );
    wsu->n_elem++;
    for (i = 0; i < wv->size; i++) {
@@ -443,7 +443,7 @@
    return False;
 }
 
-WordSet HG_(doubletonWS) ( WordSetU* wsu, Word w1, Word w2 )
+WordSet HG_(doubletonWS) ( WordSetU* wsu, UWord w1, UWord w2 )
 {
    WordVec* wv;
    wsu->n_doubleton++;
@@ -465,7 +465,7 @@
    return add_or_dealloc_WordVec( wsu, wv );
 }
 
-WordSet HG_(singletonWS) ( WordSetU* wsu, Word w )
+WordSet HG_(singletonWS) ( WordSetU* wsu, UWord w )
 {
    return HG_(doubletonWS)( wsu, w, w );
 }
@@ -478,7 +478,7 @@
 
 void HG_(ppWS) ( WordSetU* wsu, WordSet ws )
 {
-   Int      i;
+   UWord    i;
    WordVec* wv;
    tl_assert(wsu);
    wv = do_ix2vec( wsu, ws );
@@ -511,9 +511,9 @@
    VG_(printf)("      isSubsetOf   %10u\n",   wsu->n_isSubsetOf);
 }
 
-WordSet HG_(addToWS) ( WordSetU* wsu, WordSet ws, Word w )
+WordSet HG_(addToWS) ( WordSetU* wsu, WordSet ws, UWord w )
 {
-   Int      k, j;
+   UWord    k, j;
    WordVec* wv_new;
    WordVec* wv;
    WordSet  result = (WordSet)(-1); /* bogus */
@@ -552,9 +552,9 @@
    return result;
 }
 
-WordSet HG_(delFromWS) ( WordSetU* wsu, WordSet ws, Word w )
+WordSet HG_(delFromWS) ( WordSetU* wsu, WordSet ws, UWord w )
 {
-   Int      i, j, k;
+   UWord    i, j, k;
    WordVec* wv_new;
    WordSet  result = (WordSet)(-1); /* bogus */
    WordVec* wv = do_ix2vec( wsu, ws );
@@ -605,7 +605,7 @@
 
 WordSet HG_(unionWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 )
 {
-   Int      i1, i2, k, sz;
+   UWord    i1, i2, k, sz;
    WordVec* wv_new;
    WordVec* wv1 = do_ix2vec( wsu, ws1 );
    WordVec* wv2 = do_ix2vec( wsu, ws2 );
@@ -675,7 +675,7 @@
 
 WordSet HG_(intersectWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 )
 {
-   Int      i1, i2, k, sz;
+   UWord    i1, i2, k, sz;
    WordSet  ws_new = (WordSet)(-1); /* bogus */
    WordVec* wv_new;
    WordVec* wv1; 
@@ -756,7 +756,7 @@
 
 WordSet HG_(minusWS) ( WordSetU* wsu, WordSet ws1, WordSet ws2 )
 {
-   Int      i1, i2, k, sz;
+   UWord    i1, i2, k, sz;
    WordSet  ws_new = (WordSet)(-1); /* bogus */
    WordVec* wv_new;
    WordVec* wv1;
@@ -833,7 +833,7 @@
 static __attribute__((unused))
 void show_WS ( WordSetU* wsu, WordSet ws )
 {
-   Int i;
+   UWord i;
    WordVec* wv = do_ix2vec( wsu, ws );
    VG_(printf)("#%u{", ws);
    for (i = 0; i < wv->size; i++) {

Modified: trunk/helgrind/hg_wordset.h
===================================================================
--- trunk/helgrind/hg_wordset.h 2008-02-14 16:55:01 UTC (rev 7408)
+++ trunk/helgrind/hg_wordset.h 2008-02-15 22:02:30 UTC (rev 7409)
@@ -55,7 +55,7 @@
 void HG_(deleteWordSetU) ( WordSetU* );
 
 /* Get the number of elements in this WordSetU. */
-Int HG_(cardinalityWSU) ( WordSetU* );
+UWord HG_(cardinalityWSU) ( WordSetU* );
 
 /* Show performance stats for this WordSetU. */
 void HG_(ppWSUstats) ( WordSetU* wsu, HChar* name );
@@ -66,25 +66,25 @@
    represents the empty set. */
 
 WordSet HG_(emptyWS)        ( WordSetU* );
-WordSet HG_(addToWS)        ( WordSetU*, WordSet, Word );
-WordSet HG_(delFromWS)      ( WordSetU*, WordSet, Word );
+WordSet HG_(addToWS)        ( WordSetU*, WordSet, UWord );
+WordSet HG_(delFromWS)      ( WordSetU*, WordSet, UWord );
 WordSet HG_(unionWS)        ( WordSetU*, WordSet, WordSet );
 WordSet HG_(intersectWS)    ( WordSetU*, WordSet, WordSet );
 WordSet HG_(minusWS)        ( WordSetU*, WordSet, WordSet );
 Bool    HG_(isEmptyWS)      ( WordSetU*, WordSet );
-Bool    HG_(isSingletonWS)  ( WordSetU*, WordSet, Word );
-Word    HG_(anyElementOfWS) ( WordSetU*, WordSet );
-Int     HG_(cardinalityWS)  ( WordSetU*, WordSet );
-Bool    HG_(elemWS)         ( WordSetU*, WordSet, Word );
-WordSet HG_(doubletonWS)    ( WordSetU*, Word, Word );
-WordSet HG_(singletonWS)    ( WordSetU*, Word );
+Bool    HG_(isSingletonWS)  ( WordSetU*, WordSet, UWord );
+UWord   HG_(anyElementOfWS) ( WordSetU*, WordSet );
+UWord   HG_(cardinalityWS)  ( WordSetU*, WordSet );
+Bool    HG_(elemWS)         ( WordSetU*, WordSet, UWord );
+WordSet HG_(doubletonWS)    ( WordSetU*, UWord, UWord );
+WordSet HG_(singletonWS)    ( WordSetU*, UWord );
 WordSet HG_(isSubsetOf)     ( WordSetU*, WordSet, WordSet );
 
 Bool    HG_(plausibleWS)    ( WordSetU*, WordSet );
 Bool    HG_(saneWS_SLOW)    ( WordSetU*, WordSet );
 
 void    HG_(ppWS)           ( WordSetU*, WordSet );
-void    HG_(getPayloadWS)   ( /*OUT*/Word** words, /*OUT*/Word* nWords, 
+void    HG_(getPayloadWS)   ( /*OUT*/UWord** words, /*OUT*/UWord* nWords, 
                              WordSetU*, WordSet );
 
 


-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Valgrind-developers mailing list
Valgrind-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-developers

Reply via email to