Changeset: 37c3ef175b7a for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=37c3ef175b7a
Modified Files:
        gdk/gdk.h
        gdk/gdk_batop.c
        gdk/gdk_col.c
        monetdb5/modules/kernel/colcast.c.mx
Branch: headless
Log Message:

After an idea from Martin: implement type-specific putvalue macros.
- renamed putvalue as COLputvalue;
- renamed replacevalue as COLreplacevalue;
- implemented type-specific macros for COLputvalue, COLreplacevalue,
  and all the various fastins/bunfastins macros (except
  bunfastins_check which is itself more-or-less an alias of
  bunfastins).


diffs (truncated from 367 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -1142,7 +1142,7 @@
  * @end itemize
  */
 /* NOTE: `p' is evaluated after a possible upgrade of the heap */
-#define putvalue(b, p, v, copyall)                                     \
+#define COLputvalue(b, p, v, copyall)                                  \
        do {                                                            \
                if ((b)->varsized && (b)->type) {                       \
                        var_t _d;                                       \
@@ -1173,7 +1173,55 @@
                } else                                                  \
                        ATOMput((b)->type, (b)->vheap, (p), v);         \
        } while (0)
-#define replacevalue(b, p, v)                                          \
+#define COLputvalue_str(b, p, v, copyall)                              \
+       do {                                                            \
+               var_t _d;                                               \
+               ptr _ptr;                                               \
+               if (strPut((b)->vheap, &_d, (v)) == 0)                  \
+                       goto bunins_failed;                             \
+               if ((b)->width < SIZEOF_VAR_T &&                        \
+                   ((b)->width <= 2 ? _d - GDK_VAROFFSET : _d) >= ((size_t) 1 
<< (8 * (b)->width))) { \
+                       /* doesn't fit in current heap, upgrade it */   \
+                       COLaccessBegin(b, USE_HEAP, MMAP_SEQUENTIAL);   \
+                       GDKupgradevarheap((b), _d, (copyall));          \
+                       COLaccessEnd(b, USE_HEAP, MMAP_SEQUENTIAL);     \
+               }                                                       \
+               _ptr = (p);                                             \
+               switch ((b)->width) {                                   \
+               case 1:                                                 \
+                       * (unsigned char *) _ptr = (unsigned char) (_d - 
GDK_VAROFFSET); \
+                       break;                                          \
+               case 2:                                                 \
+                       * (unsigned short *) _ptr = (unsigned short) (_d - 
GDK_VAROFFSET); \
+                       break;                                          \
+               case 4:                                                 \
+                       * (unsigned int *) _ptr = (unsigned int) _d;    \
+                       break;                                          \
+               case 8:                                                 \
+                       * (var_t *) _ptr = _d;                          \
+                       break;                                          \
+               }                                                       \
+       } while (0)
+#ifdef NDEBUG
+#define COLputvalue_TYPE(b, p, v, TYPE)                (* (TYPE *) (p) = * 
(TYPE *) (v))
+#else
+#define COLputvalue_TYPE(b, p, v, TYPE)                        \
+       do {                                            \
+               assert((b)->type == TYPE_##TYPE);       \
+               (* (TYPE *) (p) = * (TYPE *) (v));      \
+       } while (0)
+#endif
+#define COLputvalue_chr(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, chr)
+#define COLputvalue_bte(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, bte)
+#define COLputvalue_sht(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, sht)
+#define COLputvalue_int(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, int)
+#define COLputvalue_wrd(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, wrd)
+#define COLputvalue_oid(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, oid)
+#define COLputvalue_lng(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, lng)
+#define COLputvalue_flt(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, flt)
+#define COLputvalue_dbl(b, p, v, copyall)      COLputvalue_TYPE(b, p, v, dbl)
+
+#define COLreplacevalue(b, p, v)                                       \
        do {                                                            \
                if ((b)->varsized && (b)->type) {                       \
                        var_t _d;                                       \
@@ -1217,19 +1265,60 @@
                } else                                                  \
                        ATOMreplace((b)->type, (b)->vheap, (p), v);     \
        } while (0)
-#define fastins_nocheck(b, p, v, s)                            \
-       do {                                                    \
-               assert((b)->width == (s));                      \
-               (b)->heap.free += (s);                          \
-               putvalue((b), COLelement((b), (p)), (v), 0);    \
-       } while (0)
-#define bunfastins_nocheck(b, p, v, vs)                                \
+#define COLreplacevalue_str(b, p, v, copyall)  COLputvalue_str(b, p, v, 
copyall)
+#define COLreplacevalue_chr(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, chr)
+#define COLreplacevalue_bte(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, bte)
+#define COLreplacevalue_sht(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, sht)
+#define COLreplacevalue_int(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, int)
+#define COLreplacevalue_wrd(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, wrd)
+#define COLreplacevalue_oid(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, oid)
+#define COLreplacevalue_lng(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, lng)
+#define COLreplacevalue_flt(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, flt)
+#define COLreplacevalue_dbl(b, p, v, copyall)  COLputvalue_TYPE(b, p, v, dbl)
+
+#define fastins_nocheck(b, p, v, vs)                           \
        do {                                                    \
                assert((b)->width == (vs));                     \
                (b)->heap.free += (vs);                         \
-               putvalue((b), COLelement((b), (p)), (v), 0);    \
-               (b)->count++;                                   \
+               COLputvalue((b), COLelement((b), (p)), (v), 0); \
        } while (0)
+#define fastins_nocheck_TYPE(b, p, v, TYPE)            \
+       do {                                            \
+               assert((b)->width == sizeof(TYPE));     \
+               (b)->heap.free += sizeof(TYPE);         \
+               COLputvalue_##TYPE((b), (p), (v), 0);   \
+       } while (0)
+#define fastins_nocheck_bte(b, p, v)   fastins_nocheck_TYPE(b, p, v, bte)
+#define fastins_nocheck_chr(b, p, v)   fastins_nocheck_TYPE(b, p, v, chr)
+#define fastins_nocheck_sht(b, p, v)   fastins_nocheck_TYPE(b, p, v, sht)
+#define fastins_nocheck_int(b, p, v)   fastins_nocheck_TYPE(b, p, v, int)
+#define fastins_nocheck_wrd(b, p, v)   fastins_nocheck_TYPE(b, p, v, wrd)
+#define fastins_nocheck_oid(b, p, v)   fastins_nocheck_TYPE(b, p, v, oid)
+#define fastins_nocheck_lng(b, p, v)   fastins_nocheck_TYPE(b, p, v, lng)
+#define fastins_nocheck_flt(b, p, v)   fastins_nocheck_TYPE(b, p, v, flt)
+#define fastins_nocheck_dbl(b, p, v)   fastins_nocheck_TYPE(b, p, v, dbl)
+#define fastins_nocheck_str(b, p, v)   fastins_nocheck_TYPE(b, p, v, str)
+
+#define bunfastins_nocheck(b, p, v, vs)                \
+       do {                                    \
+               fastins_nocheck(b, p, v, vs);   \
+               (b)->count++;                   \
+       } while (0)
+#define bunfastins_nocheck_TYPE(b, p, v, TYPE)         \
+       do {                                            \
+               fastins_nocheck_TYPE(b, p, v, TYPE);    \
+               (b)->count++;                           \
+       } while (0)
+#define bunfastins_nocheck_bte(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, bte)
+#define bunfastins_nocheck_chr(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, chr)
+#define bunfastins_nocheck_sht(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, sht)
+#define bunfastins_nocheck_int(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, int)
+#define bunfastins_nocheck_wrd(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, wrd)
+#define bunfastins_nocheck_oid(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, oid)
+#define bunfastins_nocheck_lng(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, lng)
+#define bunfastins_nocheck_flt(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, flt)
+#define bunfastins_nocheck_dbl(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, dbl)
+#define bunfastins_nocheck_str(b, p, v)        bunfastins_nocheck_TYPE(b, p, 
v, str)
 
 #define bunfastins(b, v)                                               \
        do {                                                            \
@@ -1242,18 +1331,54 @@
                        if (COLextend((b), COLgrows(b)) == NULL)        \
                                goto bunins_failed;                     \
                }                                                       \
-               fastins_nocheck((b), _p, (v), (b)->width);              \
-               (b)->count++;                                           \
+               bunfastins_nocheck((b), _p, (v), (b)->width);           \
        } while (0)
+#define bunfastins_TYPE(b, v, TYPE)                                    \
+       do {                                                            \
+               register oid _p = COLlast(b);                           \
+               if (_p == BUN_MAX || COLcount(b) == BUN_MAX) {          \
+                       GDKerror("bunfastins: bat too large\n");        \
+                       goto bunins_failed;                             \
+               }                                                       \
+               if (_p + 1 > COLcapacity(b)) {                          \
+                       if (COLextend((b), COLgrows(b)) == NULL)        \
+                               goto bunins_failed;                     \
+               }                                                       \
+               bunfastins_nocheck_TYPE((b), _p, (v), TYPE);            \
+       } while (0)
+#define bunfastins_bte(b, v)   bunfastins_TYPE(b, v, bte)
+#define bunfastins_chr(b, v)   bunfastins_TYPE(b, v, chr)
+#define bunfastins_sht(b, v)   bunfastins_TYPE(b, v, sht)
+#define bunfastins_int(b, v)   bunfastins_TYPE(b, v, int)
+#define bunfastins_wrd(b, v)   bunfastins_TYPE(b, v, wrd)
+#define bunfastins_oid(b, v)   bunfastins_TYPE(b, v, oid)
+#define bunfastins_lng(b, v)   bunfastins_TYPE(b, v, lng)
+#define bunfastins_flt(b, v)   bunfastins_TYPE(b, v, flt)
+#define bunfastins_dbl(b, v)   bunfastins_TYPE(b, v, dbl)
+#define bunfastins_str(b, v)   bunfastins_TYPE(b, v, str)
 
 #define bunfastins_check(b, p, v) bunfastins(b, v)
 
-#define bunfastins_nocheck_inc(b, p, v)                        \
+#define bunfastins_nocheck_inc(b, p, v)                                \
+       do {                                                    \
+               bunfastins_nocheck(b, p, v, (b)->width);        \
+               p++;                                            \
+       } while (0)
+#define bunfastins_nocheck_inc_TYPE(b, p, v, TYPE)     \
        do {                                            \
-               fastins_nocheck(b, p, v, (b)->width);   \
+               bunfastins_nocheck_TYPE(b, p, v, TYPE); \
                p++;                                    \
-               (b)->count++;                           \
        } while (0)
+#define bunfastins_nocheck_inc_bte(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, bte)
+#define bunfastins_nocheck_inc_chr(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, chr)
+#define bunfastins_nocheck_inc_sht(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, sht)
+#define bunfastins_nocheck_inc_int(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, int)
+#define bunfastins_nocheck_inc_wrd(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, wrd)
+#define bunfastins_nocheck_inc_oid(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, oid)
+#define bunfastins_nocheck_inc_lng(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, lng)
+#define bunfastins_nocheck_inc_flt(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, flt)
+#define bunfastins_nocheck_inc_dbl(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, dbl)
+#define bunfastins_nocheck_inc_str(b, p, v)    bunfastins_nocheck_inc_TYPE(b, 
p, v, str)
 
 gdk_export int GDKupgradevarheap(COL *c, var_t v, int copyall);
 gdk_export COL *BUNfastins(COL *b, ptr p);
@@ -1294,7 +1419,7 @@
 /* new semantics ! */
 #define headsize(b,p)  ((b)->type?((size_t)(p))<<(b)->shift:0)
 
-#define COLelement(b,p) ((b)->heap.base+((p)<<(b)->shift))
+#define COLelement(b, p)               ((b)->heap.base+((p)<<(b)->shift))
 
 #if SIZEOF_VAR_T < SIZEOF_VOID_P
 /* NEW 11/4/2009: when compiled with 32-bits oids/var_t on 64-bits
diff --git a/gdk/gdk_batop.c b/gdk/gdk_batop.c
--- a/gdk/gdk_batop.c
+++ b/gdk/gdk_batop.c
@@ -57,7 +57,7 @@
 append_string_col(COL *b, COL *n)
 {
        COLiter ni;             /* iterators */
-       int tt;                 /* col types */
+       int tt;                 /* temporarily changed col type */
        size_t toff = ~(size_t) 0;      /* head and tail offsets */
        oid p, q;               /* loop variables */
        ptr tp;                 /* value pointer */
@@ -70,6 +70,8 @@
        var_t v;                /* value */
        int ntw, btw;           /* shortcuts for {b,n}->width */
 
+       assert(b->type == TYPE_str);
+       assert(n->type == TYPE_str);
        if (n->count == 0)
                return b;
        ni = col_iterator(n);
@@ -77,8 +79,7 @@
        ntw = n->width;
        tp = NULL;
        tt = b->type;
-       if (tt == TYPE_str &&
-           (!GDK_ELIMDOUBLES(b->vheap) || b->count == 0) &&
+       if ((!GDK_ELIMDOUBLES(b->vheap) || b->count == 0) &&
            !GDK_ELIMDOUBLES(n->vheap) &&
            b->vheap->hashash == n->vheap->hashash &&
            (b->key & BOUND2BTRUE) == 0 &&
@@ -93,6 +94,7 @@
                        toff = ~ (size_t) 0;
                        goto bunins_failed;
                }
+               assert(toff != ~ (size_t) 0);
                memcpy(b->vheap->base + toff, n->vheap->base, n->vheap->size);
                b->vheap->free = toff + n->vheap->free;
                /* flush double-elimination hash table */
@@ -122,13 +124,14 @@
                        tt = TYPE_var;
                        break;
                }
+               /* temporarily change type of COL */
                b->varsized = 0;
                n->varsized = 0;
                b->type = tt;
        }
 
        COLloop(n, p, q) {
-               tp = b->type ? BUNhead(ni, p) : NULL;
+               tp = BUNhead(ni, p);
                if (toff != ~ (size_t) 0) {
                        assert(tp != NULL);
                        switch (ntw) {
@@ -181,6 +184,7 @@
                n->varsized = 1;
                b->type = TYPE_str;
        }
+       assert(b->type == TYPE_str);
        return b;
       bunins_failed:
        if (toff != ~(size_t) 0) {
@@ -188,6 +192,7 @@
                n->varsized = 1;
                b->type = TYPE_str;
        }
+       assert(b->type == TYPE_str);
        return NULL;
 }
 
@@ -496,7 +501,6 @@
        COLcheck(b, "COL_hashselect");
        assert(bn->type == TYPE_oid);
        if (COLprepareHash(b)) {
-             bunins_failed:
                CBPreclaim(bn);
                return NULL;
        }
@@ -515,7 +519,7 @@
 #define hashselect_loop(TYPE)                                          \
                HASHloop_typed(bi, b->hash, i, tl, TYPE) {              \
                        if (q < r) {                                    \
-                               bunfastins_nocheck(bn, q, &i, COLwidth(bn)); \
+                               bunfastins_nocheck_oid(bn, q, &i);      \
                                if (q > 0 && bn->revsorted && * (oid *) 
COLelement(bn,q-1) < i) \
                                        bn->revsorted = 0;              \
                        }                                               \
@@ -566,7 +570,7 @@
 
                                HASHloop_fstr(bi, b->hash, p, j, tl) {
                                        if (q < r) {
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to