Changeset: ce8ed2e46529 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ce8ed2e46529
Modified Files:
clients/Tests/MAL-signatures.stable.out
clients/Tests/MAL-signatures.stable.out.int128
clients/Tests/exports.stable.out
gdk/gdk.h
gdk/gdk_calc.c
monetdb5/modules/mal/01_batcalc.mal
monetdb5/modules/mal/01_batcalc.mal.sh
Branch: msk-type
Log Message:
Implemented batcalc.ifthenelse() for msk type.
diffs (truncated from 443 to 300 lines):
diff --git a/clients/Tests/MAL-signatures.stable.out
b/clients/Tests/MAL-signatures.stable.out
--- a/clients/Tests/MAL-signatures.stable.out
+++ b/clients/Tests/MAL-signatures.stable.out
@@ -9067,6 +9067,10 @@ stdout of test 'MAL-signatures` in direc
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
v1:any_1, b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
v1:any_1, v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else operation
to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
b1:bat[:any_1], b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
v1:any_1, b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
v1:any_1, v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else operation
to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit,
b1:bat[:any_1], b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;",
"If-then-else operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit,
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit, v1:any_1,
b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else operation to
assemble a conditional result" ]
diff --git a/clients/Tests/MAL-signatures.stable.out.int128
b/clients/Tests/MAL-signatures.stable.out.int128
--- a/clients/Tests/MAL-signatures.stable.out.int128
+++ b/clients/Tests/MAL-signatures.stable.out.int128
@@ -13079,6 +13079,10 @@ stdout of test 'MAL-signatures` in direc
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
v1:any_1, b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:bit],
v1:any_1, v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else operation
to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
b1:bat[:any_1], b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
v1:any_1, b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
+[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(b:bat[:msk],
v1:any_1, v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else operation
to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit,
b1:bat[:any_1], b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;",
"If-then-else operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit,
b1:bat[:any_1], v2:any_1):bat[:any_1] ", "CMDifthen;", "If-then-else
operation to assemble a conditional result" ]
[ "batcalc", "ifthenelse", "pattern batcalc.ifthenelse(v:bit, v1:any_1,
b2:bat[:any_1]):bat[:any_1] ", "CMDifthen;", "If-then-else operation to
assemble a conditional result" ]
diff --git a/clients/Tests/exports.stable.out b/clients/Tests/exports.stable.out
--- a/clients/Tests/exports.stable.out
+++ b/clients/Tests/exports.stable.out
@@ -380,7 +380,7 @@ void VALempty(ValPtr v);
char *VALformat(const ValRecord *res);
void *VALget(ValPtr v);
ValPtr VALinit(ValPtr d, int tpe, const void *s);
-int VALisnil(const ValRecord *v);
+bool VALisnil(const ValRecord *v);
ValPtr VALset(ValPtr v, int t, void *p);
gdk_return VARcalcabsolute(ValPtr ret, const ValRecord *v);
gdk_return VARcalcadd(ValPtr ret, const ValRecord *lft, const ValRecord *rgt,
bool abort_on_error);
diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -782,12 +782,14 @@ typedef struct BATiter {
static inline void
mskSet(BAT *b, BUN p)
{
+ assert(ATOMstorage(b->ttype) == TYPE_msk);
((uint32_t *) b->theap.base)[p / 32] |= 1U << (p % 32);
}
static inline void
mskClr(BAT *b, BUN p)
{
+ assert(ATOMstorage(b->ttype) == TYPE_msk);
((uint32_t *) b->theap.base)[p / 32] &= ~(1U << (p % 32));
}
@@ -803,6 +805,7 @@ mskSetVal(BAT *b, BUN p, msk v)
static inline msk
mskGetVal(BAT *b, BUN p)
{
+ assert(ATOMstorage(b->ttype) == TYPE_msk);
return ((uint32_t *) b->theap.base)[p / 32] & (1U << (p % 32));
}
diff --git a/gdk/gdk_calc.c b/gdk/gdk_calc.c
--- a/gdk/gdk_calc.c
+++ b/gdk/gdk_calc.c
@@ -13380,22 +13380,20 @@ VARcalcbetween(ValPtr ret, const ValReco
l += incr2; \
} \
} while (0)
-#define IFTHENELSELOOP_oid() \
- do { \
- for (i = 0; i < cnt; i++) { \
- if (is_bit_nil(src[i])) { \
- ((oid *) dst)[i] = oid_nil; \
- nils++; \
- } else if (src[i]) { \
- ((oid *) dst)[i] = col1 ? ((oid *) col1)[k] :
seq1; \
- } else { \
- ((oid *) dst)[i] = col2 ? ((oid *) col2)[k] :
seq2; \
- } \
- k += incr1; \
- l += incr2; \
- seq1 += incr1; \
- seq2 += incr2; \
- } \
+#define IFTHENELSELOOP_msk(TYPE) \
+ do { \
+ for (i = 0; i < cnt; i++) { \
+ if (n == 32) { \
+ n = 0; \
+ mask = src[i / 32]; \
+ } \
+ ((TYPE *) dst)[i] = mask & (1U << n) ? \
+ ((TYPE *) col1)[k] : \
+ ((TYPE *) col2)[l]; \
+ k += incr1; \
+ l += incr2; \
+ n++; \
+ } \
} while (0)
static BAT *
@@ -13412,7 +13410,6 @@ BATcalcifthenelse_intern(BAT *b,
BUN nils = 0;
const void *nil;
const void *p;
- const bit *src;
BUN cnt = b->batCount;
/* col1 and col2 can only be NULL for void columns */
@@ -13429,74 +13426,221 @@ BATcalcifthenelse_intern(BAT *b,
if (cnt == 0)
return bn;
- src = (const bit *) Tloc(b, 0);
-
nil = ATOMnilptr(tpe);
dst = (void *) Tloc(bn, 0);
k = l = 0;
if (bn->tvarsized) {
assert((heap1 != NULL && width1 > 0) || (width1 == 0 && incr1
== 0));
assert((heap2 != NULL && width2 > 0) || (width2 == 0 && incr2
== 0));
- for (i = 0; i < cnt; i++) {
- if (is_bit_nil(src[i])) {
- p = nil;
- nils++;
- } else if (src[i]) {
- if (heap1)
- p = heap1 + VarHeapVal(col1, k, width1);
- else
- p = col1;
- } else {
- if (heap2)
- p = heap2 + VarHeapVal(col2, l, width2);
- else
- p = col2;
- }
- if (tfastins_nocheckVAR(bn, i, p, Tsize(bn)) !=
GDK_SUCCEED) {
- BBPreclaim(bn);
- return NULL;
- }
- k += incr1;
- l += incr2;
+ if (ATOMstorage(b->ttype) == TYPE_msk) {
+ const uint32_t *src = Tloc(b, 0);
+ BUN n = cnt / 32;
+ for (i = 0; i <= n; i++) {
+ BUN rem = i == n ? cnt % 32 : 32;
+ uint32_t mask = rem != 0 ? src[i] : 0;
+ for (BUN j = 0; j < rem; j++) {
+ if (mask & (1U << j)) {
+ if (heap1)
+ p = heap1 +
VarHeapVal(col1, k, width1);
+ else
+ p = col1;
+ } else {
+ if (heap2)
+ p = heap2 +
VarHeapVal(col2, l, width2);
+ else
+ p = col2;
+ }
+ if (tfastins_nocheckVAR(bn, i, p,
Tsize(bn)) != GDK_SUCCEED) {
+ BBPreclaim(bn);
+ return NULL;
+ }
+ k += incr1;
+ l += incr2;
+ }
+ }
+ } else {
+ const bit *src = Tloc(b, 0);
+ for (i = 0; i < cnt; i++) {
+ if (is_bit_nil(src[i])) {
+ p = nil;
+ nils++;
+ } else if (src[i]) {
+ if (heap1)
+ p = heap1 + VarHeapVal(col1, k,
width1);
+ else
+ p = col1;
+ } else {
+ if (heap2)
+ p = heap2 + VarHeapVal(col2, l,
width2);
+ else
+ p = col2;
+ }
+ if (tfastins_nocheckVAR(bn, i, p, Tsize(bn)) !=
GDK_SUCCEED) {
+ BBPreclaim(bn);
+ return NULL;
+ }
+ k += incr1;
+ l += incr2;
+ }
}
} else {
assert(heap1 == NULL);
assert(heap2 == NULL);
- if (ATOMtype(tpe) == TYPE_oid) {
- IFTHENELSELOOP_oid();
+ if (ATOMstorage(b->ttype) == TYPE_msk) {
+ const uint32_t *src = Tloc(b, 0);
+ uint32_t mask = 0;
+ BUN n = 32;
+ if (ATOMtype(tpe) == TYPE_oid) {
+ for (i = 0; i < cnt; i++) {
+ if (n == 32) {
+ n = 0;
+ mask = src[i / 32];
+ }
+ ((oid *) dst)[i] = mask & (1U << n) ?
+ col1 ? ((oid *)col1)[k] : seq1 :
+ col2 ? ((oid *)col2)[l] : seq2;
+ k += incr1;
+ l += incr2;
+ seq1 += incr1;
+ seq2 += incr2;
+ n++;
+ }
+ } else if (ATOMstorage(tpe) == TYPE_msk) {
+ uint32_t v1, v2;
+ if (incr1) {
+ v1 = 0;
+ } else {
+ v1 = * (msk *) col1 ? ~0U : 0U;
+ }
+ if (incr2) {
+ v2 = 0;
+ } else {
+ v2 = * (msk *) col2 ? ~0U : 0U;
+ }
+ n = (cnt + 31) / 32;
+ for (i = 0; i < n; i++) {
+ if (incr1)
+ v1 = ((uint32_t *) col1)[i];
+ if (incr2)
+ v2 = ((uint32_t *) col2)[i];
+ ((uint32_t *) dst)[i] = (src[i] & v1)
+ | (~src[i] & v2);
+ }
+ } else {
+ switch (bn->twidth) {
+ case 1:
+ IFTHENELSELOOP_msk(bte);
+ break;
+ case 2:
+ IFTHENELSELOOP_msk(sht);
+ break;
+ case 4:
+ IFTHENELSELOOP_msk(int);
+ break;
+ case 8:
+ IFTHENELSELOOP_msk(lng);
+ break;
+#ifdef HAVE_HGE
+ case 16:
+ IFTHENELSELOOP_msk(hge);
+ break;
+#endif
+ default:
+ for (i = 0; i < cnt; i++) {
+ if (n == 32) {
+ n = 0;
+ mask = src[i / 32];
+ }
+ if (mask & (1U << n))
+ p = ((const char *)
col1) + k * width1;
+ else
+ p = ((const char *)
col2) + l * width2;
+ memcpy(dst, p, bn->twidth);
+ dst = (void *) ((char *) dst +
bn->twidth);
+ k += incr1;
+ l += incr2;
+ n++;
+ }
+ }
+ }
} else {
- switch (bn->twidth) {
- case 1:
- IFTHENELSELOOP(bte);
- break;
- case 2:
- IFTHENELSELOOP(sht);
- break;
- case 4:
- IFTHENELSELOOP(int);
- break;
- case 8:
- IFTHENELSELOOP(lng);
- break;
-#ifdef HAVE_HGE
- case 16:
- IFTHENELSELOOP(hge);
- break;
-#endif
- default:
_______________________________________________
checkin-list mailing list
[email protected]
https://www.monetdb.org/mailman/listinfo/checkin-list