Changeset: fcb1e0adc632 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/fcb1e0adc632
Added Files:
        gdk/gdk_calc_div.c
        gdk/gdk_calc_mod.c
        gdk/gdk_calc_mul.c
Removed Files:
        gdk/gdk_calc_muldiv.c
Modified Files:
        gdk/CMakeLists.txt
        gdk/gdk_calc_private.h
Branch: Sep2022
Log Message:

Split gdk_calc_muldiv in three parts to speed up release builds


diffs (truncated from 11293 to 300 lines):

diff --git a/gdk/CMakeLists.txt b/gdk/CMakeLists.txt
--- a/gdk/CMakeLists.txt
+++ b/gdk/CMakeLists.txt
@@ -40,7 +40,7 @@ target_sources(bat
   PRIVATE
   gdk_select.c
   gdk_calc.c gdk_calc.h
-  gdk_calc_addsub.c gdk_calc_muldiv.c gdk_calc_convert.c gdk_calc_compare.c
+  gdk_calc_addsub.c gdk_calc_mul.c gdk_calc_div.c gdk_calc_mod.c 
gdk_calc_convert.c gdk_calc_compare.c
   gdk_calc_compare.h gdk_calc_private.h
   gdk_ssort.c gdk_ssort_impl.h
   gdk_aggr.c
diff --git a/gdk/gdk_calc_div.c b/gdk/gdk_calc_div.c
new file mode 100644
--- /dev/null
+++ b/gdk/gdk_calc_div.c
@@ -0,0 +1,2084 @@
+/*
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0.  If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * Copyright 1997 - July 2008 CWI, August 2008 - 2022 MonetDB B.V.
+ */
+
+#include "monetdb_config.h"
+#include "gdk.h"
+#include "gdk_private.h"
+#include "gdk_calc_private.h"
+
+/* ---------------------------------------------------------------------- */
+/* division (any numeric type) */
+
+#define DIV_3TYPE(TYPE1, TYPE2, TYPE3)                                 \
+static BUN                                                             \
+div_##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)             \
+{                                                                      \
+       BUN nils = 0;                                                   \
+       BUN i = 0, j = 0, ncand = ci1->ncand;                           \
+       lng timeoffset = 0;                                             \
+       QryCtx *qry_ctx = MT_thread_get_qry_ctx();                      \
+       if (qry_ctx != NULL) {                                          \
+               timeoffset = (qry_ctx->starttime && qry_ctx->querytimeout) ? 
(qry_ctx->starttime + qry_ctx->querytimeout) : 0; \
+       }                                                               \
+                                                                       \
+       if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) {         \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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 (rgt[j] == 0) {                       \
+                               return BUN_NONE + 1;                    \
+                       } else {                                        \
+                               dst[k] = (TYPE3) (lft[i] / rgt[j]);     \
+                               if (dst[k] < -max || dst[k] > max) {    \
+                                       return BUN_NONE + 2;            \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       } else {                                                        \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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 (rgt[j] == 0) {                       \
+                               return BUN_NONE + 1;                    \
+                       } else {                                        \
+                               dst[k] = (TYPE3) (lft[i] / rgt[j]);     \
+                               if (dst[k] < -max || dst[k] > max) {    \
+                                       return BUN_NONE + 2;            \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       }                                                               \
+       return nils;                                                    \
+}
+
+#define DIV_3TYPE_float(TYPE1, TYPE2, TYPE3)                           \
+static BUN                                                             \
+div_##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)             \
+{                                                                      \
+       BUN nils = 0;                                                   \
+       BUN i = 0, j = 0, ncand = ci1->ncand;                           \
+       lng timeoffset = 0;                                             \
+       QryCtx *qry_ctx = MT_thread_get_qry_ctx();                      \
+       if (qry_ctx != NULL) {                                          \
+               timeoffset = (qry_ctx->starttime && qry_ctx->querytimeout) ? 
(qry_ctx->starttime + qry_ctx->querytimeout) : 0; \
+       }                                                               \
+                                                                       \
+       if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) {         \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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 (rgt[j] == 0 ||                       \
+                                  (ABSOLUTE(rgt[j]) < 1 &&             \
+                                   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
ABSOLUTE(lft[i]))) { \
+                               /* only check for overflow, not for underflow 
*/ \
+                               if (rgt[j] == 0)                        \
+                                       return BUN_NONE + 1;            \
+                               ON_OVERFLOW(TYPE1, TYPE2, "/");         \
+                       } else {                                        \
+                               dst[k] = (TYPE3) lft[i] / rgt[j];       \
+                               if (dst[k] < -max || dst[k] > max) {    \
+                                       return BUN_NONE + 2;            \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       } else {                                                        \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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 (rgt[j] == 0 ||                       \
+                                  (ABSOLUTE(rgt[j]) < 1 &&             \
+                                   GDK_##TYPE3##_max * ABSOLUTE(rgt[j]) < 
ABSOLUTE(lft[i]))) { \
+                               /* only check for overflow, not for underflow 
*/ \
+                               if (rgt[j] == 0)                        \
+                                       return BUN_NONE + 1;            \
+                               ON_OVERFLOW(TYPE1, TYPE2, "/");         \
+                       } else {                                        \
+                               dst[k] = (TYPE3) lft[i] / rgt[j];       \
+                               if (dst[k] < -max || dst[k] > max) {    \
+                                       return BUN_NONE + 2;            \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       }                                                               \
+       return nils;                                                    \
+}
+
+#define DIV_INT_FLT_INT(TYPE1, TYPE2, TYPE3)                           \
+static BUN                                                             \
+div_##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)             \
+{                                                                      \
+       BUN nils = 0;                                                   \
+       BUN i = 0, j = 0, ncand = ci1->ncand;                           \
+       lng timeoffset = 0;                                             \
+       QryCtx *qry_ctx = MT_thread_get_qry_ctx();                      \
+       if (qry_ctx != NULL) {                                          \
+               timeoffset = (qry_ctx->starttime && qry_ctx->querytimeout) ? 
(qry_ctx->starttime + qry_ctx->querytimeout) : 0; \
+       }                                                               \
+                                                                       \
+       if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) {         \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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) {                       \
+                               dst[k] = 0;                             \
+                       } else if (rgt[j] == 0) {                       \
+                               return BUN_NONE + 1;                    \
+                       } else {                                        \
+                               double m = fabs(rgt[j]);                \
+                               if (m < 1 && abs##TYPE1(lft[i]) > m * max) { \
+                                       ON_OVERFLOW(TYPE1, TYPE2, "/"); \
+                               } else {                                \
+                                       dst[k] = (TYPE3) rounddbl(lft[i] / 
(ldouble) rgt[j]); \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       } else {                                                        \
+               TIMEOUT_LOOP_IDX_DECL(k, ncand, timeoffset) {           \
+                       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) {                       \
+                               dst[k] = 0;                             \
+                       } else if (rgt[j] == 0) {                       \
+                               return BUN_NONE + 1;                    \
+                       } else {                                        \
+                               double m = fabs(rgt[j]);                \
+                               if (m < 1 && abs##TYPE1(lft[i]) > m * max) { \
+                                       ON_OVERFLOW(TYPE1, TYPE2, "/"); \
+                               } else {                                \
+                                       dst[k] = (TYPE3) rounddbl(lft[i] / 
(ldouble) rgt[j]); \
+                               }                                       \
+                       }                                               \
+               }                                                       \
+               TIMEOUT_CHECK(timeoffset, TIMEOUT_HANDLER(BUN_NONE));   \
+       }                                                               \
+       return nils;                                                    \
+}
+
+DIV_INT_FLT_INT(bte, flt, bte)
+DIV_INT_FLT_INT(bte, flt, sht)
+DIV_INT_FLT_INT(bte, flt, int)
+DIV_INT_FLT_INT(bte, flt, lng)
+DIV_INT_FLT_INT(sht, flt, bte)
+DIV_INT_FLT_INT(sht, flt, sht)
+DIV_INT_FLT_INT(sht, flt, int)
+DIV_INT_FLT_INT(sht, flt, lng)
+DIV_INT_FLT_INT(int, flt, bte)
+DIV_INT_FLT_INT(int, flt, sht)
+DIV_INT_FLT_INT(int, flt, int)
+DIV_INT_FLT_INT(int, flt, lng)
+DIV_INT_FLT_INT(lng, flt, bte)
+DIV_INT_FLT_INT(lng, flt, sht)
+DIV_INT_FLT_INT(lng, flt, int)
+DIV_INT_FLT_INT(lng, flt, lng)
+#ifdef HAVE_HGE
+DIV_INT_FLT_INT(bte, flt, hge)
+DIV_INT_FLT_INT(sht, flt, hge)
+DIV_INT_FLT_INT(int, flt, hge)
+DIV_INT_FLT_INT(lng, flt, hge)
+DIV_INT_FLT_INT(hge, flt, bte)
+DIV_INT_FLT_INT(hge, flt, sht)
+DIV_INT_FLT_INT(hge, flt, int)
+DIV_INT_FLT_INT(hge, flt, lng)
+DIV_INT_FLT_INT(hge, flt, hge)
+#endif
+
+DIV_INT_FLT_INT(bte, dbl, bte)
+DIV_INT_FLT_INT(bte, dbl, sht)
+DIV_INT_FLT_INT(bte, dbl, int)
+DIV_INT_FLT_INT(bte, dbl, lng)
+DIV_INT_FLT_INT(sht, dbl, bte)
+DIV_INT_FLT_INT(sht, dbl, sht)
+DIV_INT_FLT_INT(sht, dbl, int)
+DIV_INT_FLT_INT(sht, dbl, lng)
+DIV_INT_FLT_INT(int, dbl, bte)
+DIV_INT_FLT_INT(int, dbl, sht)
+DIV_INT_FLT_INT(int, dbl, int)
+DIV_INT_FLT_INT(int, dbl, lng)
+DIV_INT_FLT_INT(lng, dbl, bte)
+DIV_INT_FLT_INT(lng, dbl, sht)
+DIV_INT_FLT_INT(lng, dbl, int)
+DIV_INT_FLT_INT(lng, dbl, lng)
+#ifdef HAVE_HGE
+DIV_INT_FLT_INT(bte, dbl, hge)
+DIV_INT_FLT_INT(sht, dbl, hge)
+DIV_INT_FLT_INT(int, dbl, hge)
+DIV_INT_FLT_INT(lng, dbl, hge)
+DIV_INT_FLT_INT(hge, dbl, bte)
+DIV_INT_FLT_INT(hge, dbl, sht)
+DIV_INT_FLT_INT(hge, dbl, int)
+DIV_INT_FLT_INT(hge, dbl, lng)
+DIV_INT_FLT_INT(hge, dbl, hge)
+#endif
+
+DIV_3TYPE(bte, bte, bte)
+DIV_3TYPE(bte, bte, sht)
+DIV_3TYPE(bte, bte, int)
+DIV_3TYPE(bte, bte, lng)
+#ifdef HAVE_HGE
+DIV_3TYPE(bte, bte, hge)
+#endif
+DIV_3TYPE(bte, bte, flt)
+DIV_3TYPE(bte, bte, dbl)
+DIV_3TYPE(bte, sht, bte)
+DIV_3TYPE(bte, sht, sht)
+DIV_3TYPE(bte, sht, int)
+DIV_3TYPE(bte, sht, lng)
+#ifdef HAVE_HGE
+DIV_3TYPE(bte, sht, hge)
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to