Changeset: 5e412c2a62c5 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=5e412c2a62c5
Modified Files:
        gdk/gdk_calc.c
        gdk/gdk_value.c
Branch: default
Log Message:

Make a bit more general.
Comparisons can be between any "linear" types, isnil can be any type
at all.


diffs (truncated from 4575 to 300 lines):

diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -126,6 +126,9 @@ checkbats(BAT *b1, BAT *b2, const char *
                }                                                       \
        } while (0)
 
+/* ---------------------------------------------------------------------- */
+/* logical (for type bit) or bitwise (for integral types) NOT */
+
 #define NOT(x)         (~(x))
 #define NOTBIT(x)      (!(x))
 
@@ -254,6 +257,9 @@ VARcalcnot(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* negate value (any numeric type) */
+
 #define NEGATE(x)      (-(x))
 
 BAT *
@@ -388,6 +394,9 @@ VARcalcnegate(ValPtr ret, const ValRecor
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* absolute value (any numeric type) */
+
 #ifdef ABSOLUTE
 /* Windows seems to define this somewhere */
 #undef ABSOLUTE
@@ -529,6 +538,9 @@ VARcalcabsolute(ValPtr ret, const ValRec
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* is the value equal to zero (any numeric type) */
+
 #define ISZERO(x)              ((bit) ((x) == 0))
 
 BAT *
@@ -652,6 +664,10 @@ VARcalciszero(ValPtr ret, const ValRecor
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* sign of value (-1 for negative, 0 for 0, +1 for positive; any
+ * numeric type) */
+
 #define SIGN(x)                ((bte) ((x) < 0 ? -1 : (x) > 0))
 
 BAT *
@@ -778,6 +794,9 @@ VARcalcsign(ValPtr ret, const ValRecord 
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* is the value nil (any type) */
+
 #define ISNIL_TYPE(TYPE)                                               \
        do {                                                            \
                const TYPE *src = (const TYPE *) Tloc(b, b->U->first);  \
@@ -791,6 +810,9 @@ BATcalcisnil(BAT *b)
        BAT *bn;
        BUN i;
        bit *dst;
+       int t;
+       const void *nil;
+       int (*atomcmp)(const void *, const void *);
 
        BATcheck(b, "BATcalcisnil");
 
@@ -811,9 +833,17 @@ BATcalcisnil(BAT *b)
 
        dst = (bit *) Tloc(bn, bn->U->first);
 
+
        BATaccessBegin(b, USE_TAIL, MMAP_SEQUENTIAL);
 
-       switch (ATOMstorage(b->T->type)) {
+       t = b->T->type;
+       nil = ATOMnilptr(t);
+       atomcmp = BATatoms[t].atomCmp;
+       if (t != ATOMstorage(t) &&
+           ATOMnilptr(ATOMstorage(t)) == nil &&
+           BATatoms[ATOMstorage(t)].atomCmp == atomcmp)
+               t = ATOMstorage(t);
+       switch (t) {
        case TYPE_bte:
                ISNIL_TYPE(bte);
                break;
@@ -836,9 +866,7 @@ BATcalcisnil(BAT *b)
        {
                BATiter bi = bat_iterator(b);
                BUN j;
-               ptr v;
-               ptr nil = ATOMnilptr(b->T->type);
-               int (*atomcmp)(const void *, const void *) = 
BATatoms[b->T->type].atomCmp;
+               const void *v;
 
                BATloop(b, i, j) {
                        v = BUNtail(bi, i);
@@ -887,6 +915,9 @@ VARcalcisnotnil(ValPtr ret, const ValRec
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* addition (any numeric type) */
+
 #define ADD_3TYPE(TYPE1, TYPE2, TYPE3)                                 \
        static BUN                                                      \
        add_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, const 
TYPE2 *rgt, int incr2, TYPE3 *dst, BUN cnt, int abort_on_error) \
@@ -2072,6 +2103,9 @@ VARcalcincr(ValPtr ret, const ValRecord 
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* subtraction (any numeric type) */
+
 #define SUB_3TYPE(TYPE1, TYPE2, TYPE3)                                 \
        static BUN                                                      \
        sub_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, const 
TYPE2 *rgt, int incr2, TYPE3 *dst, BUN cnt, int abort_on_error) \
@@ -3258,6 +3292,9 @@ VARcalcdecr(ValPtr ret, const ValRecord 
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* multiplication (any numeric type) */
+
 /* TYPE4 must be a type larger than both TYPE1 and TYPE2 so that
  * multiplying into it doesn't cause overflow */
 #define MUL_4TYPE(TYPE1, TYPE2, TYPE3, TYPE4)                          \
@@ -4458,6 +4495,9 @@ VARcalcmul(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* division (any numeric type) */
+
 #define DIV_3TYPE(TYPE1, TYPE2, TYPE3)                                 \
        static BUN                                                      \
        div_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, const 
TYPE2 *rgt, int incr2, TYPE3 *dst, BUN cnt, int abort_on_error) \
@@ -5662,6 +5702,9 @@ VARcalcdiv(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* modulo (any numeric type) */
+
 #define MOD_3TYPE(TYPE1, TYPE2, TYPE3)                                 \
        static BUN                                                      \
        mod_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1,    \
@@ -6674,6 +6717,9 @@ VARcalcmod(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* logical (for type bit) or bitwise (for integral types) exclusive OR */
+
 #define XOR(a, b)      ((a) ^ (b))
 #define XORBIT(a, b)   (((a) == 0) != ((b) == 0))
 
@@ -6952,6 +6998,9 @@ VARcalcxor(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* logical (for type bit) or bitwise (for integral types) OR */
+
 #define OR(a, b)       ((a) | (b))
 
 static BUN
@@ -7244,6 +7293,9 @@ VARcalcor(ValPtr ret, const ValRecord *l
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* logical (for type bit) or bitwise (for integral types) exclusive AND */
+
 #define AND(a, b)      ((a) & (b))
 
 static BUN
@@ -7532,6 +7584,9 @@ VARcalcand(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* left shift (any integral type) */
+
 #define LSH(a, b)              ((a) << (b))
 
 #define SHIFT_CHECK(a, b)      ((b) < 0 || (b) >= 8 * (int) sizeof(a))
@@ -7815,6 +7870,9 @@ VARcalclsh(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* right shift (any integral type) */
+
 #define RSH(a, b)      ((a) >> (b))
 
 static BUN
@@ -8096,6 +8154,9 @@ VARcalcrsh(ValPtr ret, const ValRecord *
        return GDK_SUCCEED;
 }
 
+/* ---------------------------------------------------------------------- */
+/* less than (any "linear" type) */
+
 #define LT(a, b)       ((bit) ((a) < (b)))
 
 static BUN
@@ -8105,15 +8166,10 @@ lt_typeswitchloop(const void *lft, int t
 {
        BUN nils = 0;
        BUN i, j, k;
-       const char *s1, *s2;
-
-       /* bit and oid can only be compared with each other */
-       if ((tp1 == TYPE_bit) != (tp2 == TYPE_bit))
-               goto unsupported;
-       if ((tp1 == TYPE_oid || tp1 == TYPE_void) != (tp2 == TYPE_oid || tp2 == 
TYPE_void))
-               goto unsupported;
-
-       switch (ATOMstorage(tp1)) {
+       const void *nil;
+       int (*atomcmp)(const void *, const void *);
+
+       switch (tp1) {
        case TYPE_void: {
                oid v;
 
@@ -8141,8 +8197,16 @@ lt_typeswitchloop(const void *lft, int t
                }
                break;
        }
+       case TYPE_bit:
+               if (tp2 != TYPE_bit)
+                       goto unsupported;
+               if (nonil)
+                       BINARY_3TYPE_FUNC_nonil(bit, bit, bit, LT);
+               else
+                       BINARY_3TYPE_FUNC(bit, bit, bit, LT);
+               break;
        case TYPE_bte:
-               switch (ATOMstorage(tp2)) {
+               switch (tp2) {
                case TYPE_bte:
                        if (nonil)
                                BINARY_3TYPE_FUNC_nonil(bte, bte, bit, LT);
@@ -8156,9 +8220,8 @@ lt_typeswitchloop(const void *lft, int t
                                BINARY_3TYPE_FUNC(bte, sht, bit, LT);
                        break;
                case TYPE_int:
-#if SIZEOF_OID == SIZEOF_INT
-                       if (tp2 == TYPE_oid)
-                               goto unsupported;
+#if SIZEOF_WRD == SIZEOF_INT
+               case TYPE_wrd:
 #endif
                        if (nonil)
                                BINARY_3TYPE_FUNC_nonil(bte, int, bit, LT);
@@ -8166,9 +8229,8 @@ lt_typeswitchloop(const void *lft, int t
                                BINARY_3TYPE_FUNC(bte, int, bit, LT);
                        break;
                case TYPE_lng:
-#if SIZEOF_OID == SIZEOF_LNG
-                       if (tp2 == TYPE_oid)
-                               goto unsupported;
+#if SIZEOF_WRD == SIZEOF_LNG
+               case TYPE_wrd:
 #endif
                        if (nonil)
                                BINARY_3TYPE_FUNC_nonil(bte, lng, bit, LT);
@@ -8192,7 +8254,7 @@ lt_typeswitchloop(const void *lft, int t
                }
                break;
        case TYPE_sht:
-               switch (ATOMstorage(tp2)) {
+               switch (tp2) {
                case TYPE_bte:
                        if (nonil)
                                BINARY_3TYPE_FUNC_nonil(sht, bte, bit, LT);
@@ -8206,9 +8268,8 @@ lt_typeswitchloop(const void *lft, int t
                                BINARY_3TYPE_FUNC(sht, sht, bit, LT);
                        break;
                case TYPE_int:
-#if SIZEOF_OID == SIZEOF_INT
-                       if (tp2 == TYPE_oid)
-                               goto unsupported;
+#if SIZEOF_WRD == SIZEOF_INT
+               case TYPE_wrd:
 #endif
                        if (nonil)
                                BINARY_3TYPE_FUNC_nonil(sht, int, bit, LT);
@@ -8216,9 +8277,8 @@ lt_typeswitchloop(const void *lft, int t
                                BINARY_3TYPE_FUNC(sht, int, bit, LT);
                        break;
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to