Changeset: 9f5ec2660b86 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9f5ec2660b86
Modified Files:
        gdk/gdk_calc.c
Branch: Oct2020
Log Message:

Implemented multiplication of floating point with integer giving integer.
GDK level only.


diffs (truncated from 433 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
@@ -5592,6 +5592,107 @@ mul_##TYPE1##_##TYPE2##_##TYPE3(const TY
        return nils;                                                    \
 }
 
+#ifdef TRUNCATE_NUMBERS
+#define roundflt(x)    (x)
+#define rounddbl(x)    (x)
+#else
+#define roundflt(x)    roundf(x)
+#define rounddbl(x)    round(x)
+#endif
+
+#define MUL_INT_FLT_INT(TYPE1, TYPE2, TYPE3)                           \
+static BUN                                                             \
+mul_##TYPE1##_##TYPE2##_##TYPE3(                                       \
+       const TYPE1 *lft, bool incr1, const TYPE2 *rgt, bool incr2,     \
+       TYPE3 *restrict dst, TYPE3 max,                                 \
+       struct canditer *restrict ci1, struct canditer *restrict ci2,   \
+       oid candoff1, oid candoff2, bool abort_on_error)                \
+{                                                                      \
+       BUN nils = 0;                                                   \
+       BUN i = 0, j = 0;                                               \
+                                                                       \
+       if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) {         \
+               for (BUN k = 0; k < ci1->ncand; k++) {                  \
+                       if (incr1)                                      \
+                               i = canditer_next_dense(ci1) - candoff1; \
+                       if (incr2)                                      \
+                               j = canditer_next_dense(ci2) - candoff2; \
+                       if (is_##TYPE1##_nil(lft[i]) || 
is_##TYPE2##_nil(rgt[j])) { \
+                               dst[k] = TYPE3##_nil;                   \
+                               nils++;                                 \
+                       } else if (lft[i] == 0 || rgt[j] == 0) {        \
+                               dst[k] = 0;                             \
+                       } else if (max / rgt[i] < lft[j]) {             \
+                               if (abort_on_error)                     \
+                                       ON_OVERFLOW(TYPE1, TYPE2, "*"); \
+                               dst[k] = TYPE3##_nil;                   \
+                               nils++;                                 \
+                       } else {                                        \
+                               double m = lft[i] * rgt[j];             \
+                               dst[k] = (TYPE3) rounddbl(m);   \
+                       }                                               \
+               }                                                       \
+       } else {                                                        \
+               for (BUN k = 0; k < ci1->ncand; k++) {                  \
+                       if (incr1)                                      \
+                               i = canditer_next(ci1) - candoff1;      \
+                       if (incr2)                                      \
+                               j = canditer_next(ci2) - candoff2;      \
+                       if (is_##TYPE1##_nil(lft[i]) || 
is_##TYPE2##_nil(rgt[j])) { \
+                               dst[k] = TYPE3##_nil;                   \
+                               nils++;                                 \
+                       } else if (lft[i] == 0 || rgt[j] == 0) {        \
+                               dst[k] = 0;                             \
+                       } else if (max / rgt[i] < lft[j]) {             \
+                               if (abort_on_error)                     \
+                                       ON_OVERFLOW(TYPE1, TYPE2, "*"); \
+                               dst[k] = TYPE3##_nil;                   \
+                               nils++;                                 \
+                       } else {                                        \
+                               double m = lft[i] * rgt[j];             \
+                               dst[k] = (TYPE3) rounddbl(m);           \
+                       }                                               \
+               }                                                       \
+       }                                                               \
+       return nils;                                                    \
+}
+
+MUL_INT_FLT_INT(bte, flt, bte)
+MUL_INT_FLT_INT(bte, flt, sht)
+MUL_INT_FLT_INT(bte, flt, int)
+MUL_INT_FLT_INT(bte, flt, lng)
+MUL_INT_FLT_INT(sht, flt, sht)
+MUL_INT_FLT_INT(sht, flt, int)
+MUL_INT_FLT_INT(sht, flt, lng)
+MUL_INT_FLT_INT(int, flt, int)
+MUL_INT_FLT_INT(int, flt, lng)
+MUL_INT_FLT_INT(lng, flt, lng)
+#ifdef HAVE_HGE
+MUL_INT_FLT_INT(bte, flt, hge)
+MUL_INT_FLT_INT(sht, flt, hge)
+MUL_INT_FLT_INT(int, flt, hge)
+MUL_INT_FLT_INT(lng, flt, hge)
+MUL_INT_FLT_INT(hge, flt, hge)
+#endif
+
+MUL_INT_FLT_INT(bte, dbl, bte)
+MUL_INT_FLT_INT(bte, dbl, sht)
+MUL_INT_FLT_INT(bte, dbl, int)
+MUL_INT_FLT_INT(bte, dbl, lng)
+MUL_INT_FLT_INT(sht, dbl, sht)
+MUL_INT_FLT_INT(sht, dbl, int)
+MUL_INT_FLT_INT(sht, dbl, lng)
+MUL_INT_FLT_INT(int, dbl, int)
+MUL_INT_FLT_INT(int, dbl, lng)
+MUL_INT_FLT_INT(lng, dbl, lng)
+#ifdef HAVE_HGE
+MUL_INT_FLT_INT(bte, dbl, hge)
+MUL_INT_FLT_INT(sht, dbl, hge)
+MUL_INT_FLT_INT(int, dbl, hge)
+MUL_INT_FLT_INT(lng, dbl, hge)
+MUL_INT_FLT_INT(hge, dbl, hge)
+#endif
+
 MUL_4TYPE(bte, bte, bte, sht, I)
 MUL_3TYPE_enlarge(bte, bte, sht, I)
 MUL_3TYPE_enlarge(bte, bte, int, I)
@@ -5988,6 +6089,43 @@ mul_typeswitchloop(const void *lft, int 
 #endif
                case TYPE_flt:
                        switch (tp) {
+                       case TYPE_bte:
+                               nils = mul_bte_flt_bte(lft, incr1, rgt, incr2,
+                                                      dst, GDK_bte_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_sht:
+                               nils = mul_bte_flt_sht(lft, incr1, rgt, incr2,
+                                                      dst, GDK_sht_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_int:
+                               nils = mul_bte_flt_int(lft, incr1, rgt, incr2,
+                                                      dst, GDK_int_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_lng:
+                               nils = mul_bte_flt_lng(lft, incr1, rgt, incr2,
+                                                      dst, GDK_lng_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               nils = mul_bte_flt_hge(lft, incr1, rgt, incr2,
+                                                      dst, GDK_hge_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#endif
                        case TYPE_flt:
                                nils = mul_bte_flt_flt(lft, incr1, rgt, incr2,
                                                       dst, GDK_flt_max,
@@ -6006,6 +6144,43 @@ mul_typeswitchloop(const void *lft, int 
                        break;
                case TYPE_dbl:
                        switch (tp) {
+                       case TYPE_bte:
+                               nils = mul_bte_dbl_bte(lft, incr1, rgt, incr2,
+                                                      dst, GDK_bte_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_sht:
+                               nils = mul_bte_dbl_sht(lft, incr1, rgt, incr2,
+                                                      dst, GDK_sht_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_int:
+                               nils = mul_bte_dbl_int(lft, incr1, rgt, incr2,
+                                                      dst, GDK_int_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_lng:
+                               nils = mul_bte_dbl_lng(lft, incr1, rgt, incr2,
+                                                      dst, GDK_lng_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               nils = mul_bte_dbl_hge(lft, incr1, rgt, incr2,
+                                                      dst, GDK_hge_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#endif
                        case TYPE_dbl:
                                nils = mul_bte_dbl_dbl(lft, incr1, rgt, incr2,
                                                       dst, GDK_dbl_max,
@@ -6208,6 +6383,36 @@ mul_typeswitchloop(const void *lft, int 
 #endif
                case TYPE_flt:
                        switch (tp) {
+                       case TYPE_sht:
+                               nils = mul_sht_flt_sht(lft, incr1, rgt, incr2,
+                                                      dst, GDK_sht_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_int:
+                               nils = mul_sht_flt_int(lft, incr1, rgt, incr2,
+                                                      dst, GDK_int_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_lng:
+                               nils = mul_sht_flt_lng(lft, incr1, rgt, incr2,
+                                                      dst, GDK_lng_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               nils = mul_sht_flt_hge(lft, incr1, rgt, incr2,
+                                                      dst, GDK_hge_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#endif
                        case TYPE_flt:
                                nils = mul_sht_flt_flt(lft, incr1, rgt, incr2,
                                                       dst, GDK_flt_max,
@@ -6226,6 +6431,36 @@ mul_typeswitchloop(const void *lft, int 
                        break;
                case TYPE_dbl:
                        switch (tp) {
+                       case TYPE_sht:
+                               nils = mul_sht_dbl_sht(lft, incr1, rgt, incr2,
+                                                      dst, GDK_sht_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_int:
+                               nils = mul_sht_dbl_int(lft, incr1, rgt, incr2,
+                                                      dst, GDK_int_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_lng:
+                               nils = mul_sht_dbl_lng(lft, incr1, rgt, incr2,
+                                                      dst, GDK_lng_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               nils = mul_sht_dbl_hge(lft, incr1, rgt, incr2,
+                                                      dst, GDK_hge_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#endif
                        case TYPE_dbl:
                                nils = mul_sht_dbl_dbl(lft, incr1, rgt, incr2,
                                                       dst, GDK_dbl_max,
@@ -6416,6 +6651,29 @@ mul_typeswitchloop(const void *lft, int 
 #endif
                case TYPE_flt:
                        switch (tp) {
+                       case TYPE_int:
+                               nils = mul_int_flt_int(lft, incr1, rgt, incr2,
+                                                      dst, GDK_int_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+                       case TYPE_lng:
+                               nils = mul_int_flt_lng(lft, incr1, rgt, incr2,
+                                                      dst, GDK_lng_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#ifdef HAVE_HGE
+                       case TYPE_hge:
+                               nils = mul_int_flt_hge(lft, incr1, rgt, incr2,
+                                                      dst, GDK_hge_max,
+                                                      ci1, ci2,
+                                                      candoff1, candoff2,
+                                                      abort_on_error);
+                               break;
+#endif
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to