Changeset: 9e2af4b1eb1c for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=9e2af4b1eb1c
Modified Files:
gdk/gdk_calc.c
gdk/gdk_calc_compare.h
Branch: Oct2020
Log Message:
Only call canditer_next when needed, and avoid multiplication.
diffs (truncated from 1665 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
@@ -83,12 +83,13 @@ checkbats(BAT *b1, BAT *b2, const char *
#define BINARY_3TYPE_FUNC(TYPE1, TYPE2, TYPE3, FUNC) \
do { \
+ i = j = 0; \
if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next_dense(ci1) - candoff1; \
- x2 = canditer_next_dense(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next_dense(ci1) -
candoff1; \
+ if (incr2) \
+ j = canditer_next_dense(ci2) -
candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -100,10 +101,10 @@ checkbats(BAT *b1, BAT *b2, const char *
} \
} else { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next(ci1) - candoff1; \
- x2 = canditer_next(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next(ci1) - candoff1; \
+ if (incr2) \
+ j = canditer_next(ci2) - candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -120,12 +121,13 @@ checkbats(BAT *b1, BAT *b2, const char *
* when it is set */
#define BINARY_3TYPE_FUNC_nilmatch(TYPE1, TYPE2, TYPE3, FUNC) \
do { \
+ i = j = 0; \
if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next_dense(ci1) - candoff1; \
- x2 = canditer_next_dense(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next_dense(ci1) -
candoff1; \
+ if (incr2) \
+ j = canditer_next_dense(ci2) -
candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -136,10 +138,10 @@ checkbats(BAT *b1, BAT *b2, const char *
} \
} else { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next(ci1) - candoff1; \
- x2 = canditer_next(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next(ci1) - candoff1; \
+ if (incr2) \
+ j = canditer_next(ci2) - candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -153,22 +155,23 @@ checkbats(BAT *b1, BAT *b2, const char *
#define BINARY_3TYPE_FUNC_nonil(TYPE1, TYPE2, TYPE3, FUNC) \
do { \
+ i = j = 0; \
if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next_dense(ci1) - candoff1; \
- x2 = canditer_next_dense(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next_dense(ci1) -
candoff1; \
+ if (incr2) \
+ j = canditer_next_dense(ci2) -
candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
((TYPE3 *) dst)[k] = FUNC(v1, v2); \
} \
} else { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next(ci1) - candoff1; \
- x2 = canditer_next(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next(ci1) - candoff1; \
+ if (incr2) \
+ j = canditer_next(ci2) - candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
((TYPE3 *) dst)[k] = FUNC(v1, v2); \
@@ -178,12 +181,13 @@ checkbats(BAT *b1, BAT *b2, const char *
#define BINARY_3TYPE_FUNC_CHECK(TYPE1, TYPE2, TYPE3, FUNC, CHECK) \
do { \
+ i = j = 0; \
if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next_dense(ci1) - candoff1; \
- x2 = canditer_next_dense(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next_dense(ci1) -
candoff1; \
+ if (incr2) \
+ j = canditer_next_dense(ci2) -
candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -206,10 +210,10 @@ checkbats(BAT *b1, BAT *b2, const char *
} \
} else { \
for (k = 0; k < ci1->ncand; k++) { \
- x1 = canditer_next(ci1) - candoff1; \
- x2 = canditer_next(ci2) - candoff2; \
- i = x1 * incr1; \
- j = x2 * incr2; \
+ if (incr1) \
+ i = canditer_next(ci1) - candoff1; \
+ if (incr2) \
+ j = canditer_next(ci2) - candoff2; \
TYPE1 v1 = ((const TYPE1 *) lft)[i]; \
TYPE2 v2 = ((const TYPE2 *) rgt)[j]; \
if (is_##TYPE1##_nil(v1) ||
is_##TYPE2##_nil(v2)) { \
@@ -1700,8 +1704,8 @@ BATcalccstmax_no_nil(const ValRecord *v,
#define ADD_3TYPE(TYPE1, TYPE2, TYPE3, IF) \
static BUN \
-add_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
- const TYPE2 *rgt, int incr2, \
+add_##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, \
@@ -1709,13 +1713,14 @@ add_##TYPE1##_##TYPE2##_##TYPE3(const TY
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++) { \
- oid x1 = canditer_next_dense(ci1) - candoff1; \
- oid x2 = canditer_next_dense(ci2) - candoff2; \
- BUN i = x1 * incr1; \
- BUN j = x2 * incr2; \
+ 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++; \
@@ -1728,10 +1733,10 @@ add_##TYPE1##_##TYPE2##_##TYPE3(const TY
} \
} else { \
for (BUN k = 0; k < ci1->ncand; k++) { \
- oid x1 = canditer_next(ci1) - candoff1; \
- oid x2 = canditer_next(ci2) - candoff2; \
- BUN i = x1 * incr1; \
- BUN j = x2 * incr2; \
+ 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++; \
@@ -1748,8 +1753,8 @@ add_##TYPE1##_##TYPE2##_##TYPE3(const TY
#define ADD_3TYPE_enlarge(TYPE1, TYPE2, TYPE3, IF) \
static BUN \
-add_##TYPE1##_##TYPE2##_##TYPE3(const TYPE1 *lft, int incr1, \
- const TYPE2 *rgt, int incr2, \
+add_##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, \
@@ -1757,14 +1762,15 @@ add_##TYPE1##_##TYPE2##_##TYPE3(const TY
bool abort_on_error) \
{ \
BUN nils = 0; \
+ BUN i = 0, j = 0; \
const bool couldoverflow = (max < (TYPE3) GDK_##TYPE1##_max + (TYPE3)
GDK_##TYPE2##_max); \
\
if (ci1->tpe == cand_dense && ci2->tpe == cand_dense) { \
for (BUN k = 0; k < ci1->ncand; k++) { \
- oid x1 = canditer_next_dense(ci1) - candoff1; \
- oid x2 = canditer_next_dense(ci2) - candoff2; \
- BUN i = x1 * incr1; \
- BUN j = x2 * incr2; \
+ 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++; \
@@ -1779,10 +1785,10 @@ add_##TYPE1##_##TYPE2##_##TYPE3(const TY
} \
} else { \
for (BUN k = 0; k < ci1->ncand; k++) { \
- oid x1 = canditer_next(ci1) - candoff1; \
- oid x2 = canditer_next(ci2) - candoff2; \
- BUN i = x1 * incr1; \
- BUN j = x2 * incr2; \
+ 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++; \
@@ -1987,8 +1993,8 @@ ADD_3TYPE(dbl, flt, dbl, F)
ADD_3TYPE(dbl, dbl, dbl, F)
static BUN
-add_typeswitchloop(const void *lft, int tp1, int incr1,
- const void *rgt, int tp2, int incr2,
+add_typeswitchloop(const void *lft, int tp1, bool incr1,
+ const void *rgt, int tp2, bool incr2,
void *restrict dst, int tp,
struct canditer *restrict ci1, struct canditer *restrict ci2,
oid candoff1, oid candoff2, bool abort_on_error,
@@ -3318,10 +3324,8 @@ BATcalcadd(BAT *b1, BAT *b2, BAT *s1, BA
if (b1->ttype == TYPE_str && b2->ttype == TYPE_str && tp == TYPE_str) {
nils = addstr_loop(b1, NULL, b2, NULL, bn, &ci1, &ci2);
} else {
- nils = add_typeswitchloop(Tloc(b1, 0),
- b1->ttype, 1,
- Tloc(b2, 0),
- b2->ttype, 1,
+ nils = add_typeswitchloop(Tloc(b1, 0), b1->ttype, true,
+ Tloc(b2, 0), b2->ttype, true,
Tloc(bn, 0), tp,
&ci1, &ci2,
b1->hseqbase, b2->hseqbase,
@@ -3380,8 +3384,8 @@ BATcalcaddcst(BAT *b, const ValRecord *v
if (b->ttype == TYPE_str && v->vtype == TYPE_str && tp == TYPE_str) {
nils = addstr_loop(b, NULL, NULL, v->val.sval, bn, &ci,
&(struct canditer){.tpe=cand_dense, .ncand=ncand});
} else {
- nils = add_typeswitchloop(Tloc(b, 0), b->ttype, 1,
- VALptr(v), v->vtype, 0,
+ nils = add_typeswitchloop(Tloc(b, 0), b->ttype, true,
+ VALptr(v), v->vtype, false,
Tloc(bn, 0), tp,
&ci,
&(struct canditer){.tpe=cand_dense,
.ncand=ncand},
@@ -3439,8 +3443,8 @@ BATcalccstadd(const ValRecord *v, BAT *b
if (b->ttype == TYPE_str && v->vtype == TYPE_str && tp == TYPE_str) {
nils = addstr_loop(NULL, v->val.sval, b, NULL, bn, &(struct
canditer){.tpe=cand_dense, .ncand=ncand}, &ci);
} else {
- nils = add_typeswitchloop(VALptr(v), v->vtype, 0,
- Tloc(b, 0), b->ttype, 1,
+ nils = add_typeswitchloop(VALptr(v), v->vtype, false,
+ Tloc(b, 0), b->ttype, true,
Tloc(bn, 0), tp,
&(struct canditer){.tpe=cand_dense,
.ncand=ncand},
&ci,
@@ -3478,8 +3482,8 @@ gdk_return
VARcalcadd(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
bool abort_on_error)
{
- if (add_typeswitchloop(VALptr(lft), lft->vtype, 0,
- VALptr(rgt), rgt->vtype, 0,
+ if (add_typeswitchloop(VALptr(lft), lft->vtype, false,
+ VALptr(rgt), rgt->vtype, false,
VALget(ret), ret->vtype,
&(struct canditer){.tpe=cand_dense, .ncand=1},
&(struct canditer){.tpe=cand_dense, .ncand=1},
@@ -3490,8 +3494,8 @@ VARcalcadd(ValPtr ret, const ValRecord *
static BAT *
BATcalcincrdecr(BAT *b, BAT *s, bool abort_on_error,
- BUN (*typeswitchloop)(const void *, int, int,
- const void *, int, int,
+ BUN (*typeswitchloop)(const void *, int, bool,
+ const void *, int, bool,
void *, int,
struct canditer *restrict,
struct canditer *restrict,
@@ -3516,8 +3520,8 @@ BATcalcincrdecr(BAT *b, BAT *s, bool abo
if (ncand == 0)
return bn;
- nils = (*typeswitchloop)(Tloc(b, 0), b->ttype, 1,
- &(bte){1}, TYPE_bte, 0,
+ nils = (*typeswitchloop)(Tloc(b, 0), b->ttype, true,
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list