Changeset: 6f031ca329fa for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6f031ca329fa Added Files: monetdb5/modules/kernel/batifthen.c monetdb5/modules/kernel/batifthen.h monetdb5/modules/kernel/batifthen.mal Modified Files: monetdb5/modules/kernel/Makefile.ag Branch: default Log Message:
De-mx BAT ifthen module diffs (truncated from 1235 to 300 lines): diff --git a/monetdb5/modules/kernel/Makefile.ag b/monetdb5/modules/kernel/Makefile.ag --- a/monetdb5/modules/kernel/Makefile.ag +++ b/monetdb5/modules/kernel/Makefile.ag @@ -44,7 +44,7 @@ lib_kernel = { bat5.c bat5.h \ batcalc.c \ batcolor.c batcolor.h \ - batifthen.mx \ + batifthen.c batifthen.h \ batmmath.c batmmath.h \ batmtime.mx \ batstr.c batstr.h \ @@ -65,7 +65,7 @@ headers_mal = { DIR = libdir/monetdb5 SOURCES = calc.mal bat5.mal algebra.mx status.mal unix.mal \ mmath.mal lock.mal sema.mal alarm.mal batstr.mal batmtime.mx \ - batcolor.mal batifthen.mx batcalc.mal batmmath.mal \ + batcolor.mal batifthen.mal batcalc.mal batmmath.mal \ group.mx aggr.mx array.mal \ counters.mal logger.mal microbenchmark.mal } diff --git a/monetdb5/modules/kernel/batifthen.mx b/monetdb5/modules/kernel/batifthen.c copy from monetdb5/modules/kernel/batifthen.mx copy to monetdb5/modules/kernel/batifthen.c --- a/monetdb5/modules/kernel/batifthen.mx +++ b/monetdb5/modules/kernel/batifthen.c @@ -1,140 +1,146 @@ -@/ -The contents of this file are subject to the MonetDB Public License -Version 1.1 (the "License"); you may not use this file except in -compliance with the License. You may obtain a copy of the License at -http://www.monetdb.org/Legal/MonetDBLicense +/* + *The contents of this file are subject to the MonetDB Public License + *Version 1.1 (the "License"); you may not use this file except in + *compliance with the License. You may obtain a copy of the License at + *http://www.monetdb.org/Legal/MonetDBLicense + * + *Software distributed under the License is distributed on an "AS IS" + *basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the + *License for the specific language governing rights and limitations + *under the License. + * + *The Original Code is the MonetDB Database System. + * + *The Initial Developer of the Original Code is CWI. + *Portions created by CWI are Copyright (C) 1997-July 2008 CWI. + *Copyright August 2008-2012 MonetDB B.V. + *All Rights Reserved. +*/ -Software distributed under the License is distributed on an "AS IS" -basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the -License for the specific language governing rights and limitations -under the License. - -The Original Code is the MonetDB Database System. - -The Initial Developer of the Original Code is CWI. -Portions created by CWI are Copyright (C) 1997-July 2008 CWI. -Copyright August 2008-2012 MonetDB B.V. -All Rights Reserved. -@ - -@f batifthen - -@c /* - * @a M.L. Kersten - * @+ BAT if-then-else multiplex expressions. + * M.L. Kersten + * BAT if-then-else multiplex expressions. * The assembled code for IF-THEN-ELSE multiplex operations. * Again we assume that the BAT arguments are aligned. - * @- */ -@= ifthenGrp -command batcalc.ifthen(b:bat[:oid,:bit], t:bat[:oid,:@1]) :bat[:oid,:@1] -address CMDifThen_@1 -comment "If-then operation to assemble a conditional result "; -command batcalc.ifthen(b:bat[:oid,:bit], v:@1) :bat[:oid,:@1] -address CMDifThenCst_@1 -comment "Ifthen operation to assemble a conditional result "; +#define resBAT2(X1,X2)\ + bn = BATnew(ATOMtype(b->htype), X1, BATcount(b));\ + if (bn == NULL)\ + throw(MAL, X2, MAL_MALLOC_FAIL);\ + bn->hsorted = b->hsorted;\ + bn->hrevsorted = b->hrevsorted;\ + bn->tsorted = b->tsorted;\ + bn->trevsorted = b->trevsorted;\ + bn->H->nonil = b->H->nonil;\ + bn->T->nonil = b->T->nonil;\ + BATkey(bn, BAThkey(b)); -command batcalc.ifthenelse(b:bat[:oid,:bit], v:@1, w:@1) :bat[:oid,:@1] -address CMDifThenElseCst_@1 -comment "Ifthen operation to assemble a conditional result "; +#define resBAT(X1,X2)\ + bn = BATnew(ATOMtype(b->htype), TYPE_##X1, BATcount(b));\ + if (bn == NULL)\ + throw(MAL, X2, MAL_MALLOC_FAIL);\ + bn->hsorted = b->hsorted;\ + bn->hrevsorted = b->hrevsorted;\ + bn->tsorted = b->tsorted;\ + bn->trevsorted = b->trevsorted;\ + bn->H->nonil = b->H->nonil;\ + bn->T->nonil = b->T->nonil;\ + BATkey(bn, BAThkey(b)); -command batcalc.ifthenelse(b:bat[:oid,:bit], t:bat[:oid,:@1], - e:bat[:oid,:@1]) :bat[:oid,:@1] -address CMDifThenElse_@1 -comment "If-then-else operation to assemble a conditional result "; +#define resultBAT(X1,X2)\ + if (BAThvoid(b)) {\ + bn = BATnew(TYPE_void, TYPE_##X1, BATcount(b));\ + BATseqbase(bn, b->hseqbase);\ + } else {\ + bn = BATnew(b->htype, TYPE_##X1, BATcount(b));\ + }\ + if (bn == NULL) {\ + throw(MAL, X2, MAL_MALLOC_FAIL);\ + }\ + bn->hsorted = b->hsorted;\ + bn->hrevsorted = b->hrevsorted;\ + bn->tsorted = b->tsorted;\ + bn->trevsorted = b->trevsorted;\ + if (!BAThvoid(b))\ + bn->H->nonil = b->H->nonil;\ + bn->T->nonil = b->T->nonil;\ + BATkey(bn, BAThkey(b)); -command batcalc.ifthenelse(b:bat[:oid,:bit], e:@1, t:bat[:oid,:@1]) - :bat[:oid,:@1] -address CMDifThenElseCst1_@1 -comment "If-then-else operation to assemble a conditional result "; +#define voidresultBAT(X1,X2)\ + bn = BATnew(TYPE_void, X1, BATcount(b));\ + BATseqbase(bn, b->hseqbase);\ + if (bn == NULL) {\ + throw(MAL, X2, MAL_MALLOC_FAIL);\ + }\ + bn->hsorted = b->hsorted;\ + bn->hrevsorted = b->hrevsorted;\ + bn->tsorted = b->tsorted;\ + bn->trevsorted = b->trevsorted;\ + bn->H->nonil = 1;\ + bn->T->nonil = b->T->nonil; -command batcalc.ifthenelse(b:bat[:oid,:bit], t:bat[:any_1,:@1], e:@1) - :bat[:oid,:@1] -address CMDifThenElseCst2_@1 -comment "If-then-else operation to assemble a conditional result "; -@ -@mal - @:ifthenGrp(bit)@ - @:ifthenGrp(bte)@ - @:ifthenGrp(sht)@ - @:ifthenGrp(int)@ - @:ifthenGrp(lng)@ - @:ifthenGrp(oid)@ - @:ifthenGrp(flt)@ - @:ifthenGrp(dbl)@ - @:ifthenGrp(str)@ - # @- Implementation -@include kprelude.mx -@h -#ifndef _BATIFTHEN_ -#define _BATIFTHEN_ -#include "gdk.h" -#include "math.h" -#include "mal_exception.h" - -#ifdef WIN32 -#if !defined(LIBMAL) && !defined(LIBATOMS) && !defined(LIBKERNEL) && !defined(LIBMAL) && !defined(LIBOPTIMIZER) && !defined(LIBSCHEDULER) && !defined(LIBMONETDB5) -#define batifthen_export extern __declspec(dllimport) -#else -#define batifthen_export extern __declspec(dllexport) -#endif -#else -#define batifthen_export extern -#endif -#endif /* _BATIFTHEN_ */ +#include "monetdb_config.h" +#include "batifthen.h" /* - * @- * A general assumption in all cases is the bats are synchronized on their * head column. This is not checked and may be mis-used to deploy the * implementation for shifted window arithmetic as well. */ -@= chkSize - if( BATcount(@1) != BATcount(@2) ) - throw(MAL, "batcalc.@3", ILLEGAL_ARGUMENT " Requires bats of identical size"); -@= wrapup - if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); - *ret= bn->batCacheid; - BBPkeepref(*ret); - BBPreleaseref(b->batCacheid); +#define wrapup\ + if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);\ + *ret= bn->batCacheid;\ + BBPkeepref(*ret);\ + BBPreleaseref(b->batCacheid);\ return MAL_SUCCEED; -@= void_wrapup - if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ); - if (b->htype != bn->htype) { - BAT *r = VIEWcreate(b,bn); - - BBPreleaseref(bn->batCacheid); - bn = r; - } - BBPkeepref(*ret = bn->batCacheid); - BBPreleaseref(b->batCacheid); +#define void_wrapup\ + if (!(bn->batDirty&2)) bn = BATsetaccess(bn, BAT_READ);\ + if (b->htype != bn->htype) {\ + BAT *r = VIEWcreate(b,bn);\ + BBPreleaseref(bn->batCacheid);\ + bn = r;\ + }\ + BBPkeepref(*ret = bn->batCacheid);\ + BBPreleaseref(b->batCacheid);\ return MAL_SUCCEED; -@ - * @- IfThenElse - * The conditional multiplex operations . - * @- - * The constant versions are typed by the parser - * String arguments call for an extra type casting. In combination - * with type resolution and runtime checks it provides a dense - * definitoin. -@= ifthenImpl -batifthen_export str CMDifThen_@1(int *ret, int *bid, int *tid); +/* The constant versions are typed by the parser +* String arguments call for an extra type casting. In combination +* with type resolution and runtime checks it provides a dense definition. +*/ +#define ifthenImpl(X1,X2,X3)\ + { X1 nilval= (X1) X3, *val;\ + resBAT2(X2,"batcalc.ifThen")\ + bn->T->nonil = (b->T->nonil && tb->T->nonil);\ + BATloop(b, p, q) {\ + if (*t == bit_nil) {\ + BUNfastins(bn, BUNhead(bi,p), (ptr) & nilval);\ + bn->T->nonil = 0;\ + bn->T->nil = 1;\ + } else if (*t) {\ + val = (X1*) BUNtail(tbi,p);\ + BUNfastins(bn, BUNhead(bi,p), val);\ + }\ + t++;\ + }\ + } str -CMDifThen_@1(int *ret, int *bid, int *tid) +CMDifThen(int *ret, int *bid, int *tid) { BATiter bi, tbi; BAT *b, *tb, *bn; - @1 nilval= (@1) @1_nil, *val; BUN p,q; bit *t; - @:getBATdescriptor(bid,b,"batcalc.ifThen")@ - @:getBATdescriptor(tid,tb,"batcalc.ifThen",BBPreleaseref(b->batCacheid))@ - @:chkSize(b,tb,CMDifThen)@ - @:resBAT(@1,"batcalc.ifThen")@ + if ((b = BATdescriptor(*bid)) == NULL) + throw(MAL, "batcalc.ifthen", RUNTIME_OBJECT_MISSING); + if ((tb = BATdescriptor(*tid)) == NULL) { + BBPreleaseref(b->batCacheid); + throw(MAL, "batcalc.ifthen", RUNTIME_OBJECT_MISSING); + } + if( BATcount(b) != BATcount(tb) ) + throw(MAL, "batcalc.ifthen", ILLEGAL_ARGUMENT " Requires bats of identical size"); bi = bat_iterator(b); tbi = bat_iterator(tb); @@ -142,407 +148,464 @@ CMDifThen_@1(int *ret, int *bid, int *ti BATaccessBegin(b,USE_HEAD, MMAP_SEQUENTIAL); BATaccessBegin(tb,USE_TAIL, MMAP_SEQUENTIAL); - BATloop(b, p, q) { - if (*t == bit_nil) { - BUNfastins(bn, BUNhead(bi,p), (ptr) & nilval); - } else if (*t) { - val = (@1*) BUNtail(tbi,p); - BUNfastins(bn, BUNhead(bi,p), val); + switch(tb->ttype){ + case TYPE_bit: ifthenImpl(bit,TYPE_bit,bit_nil); break; + case TYPE_bte: ifthenImpl(bte,TYPE_bte,bte_nil); break; + case TYPE_sht: ifthenImpl(sht,TYPE_sht,sht_nil); break; + case TYPE_int: ifthenImpl(int,TYPE_int,int_nil); break; + case TYPE_lng: ifthenImpl(lng,TYPE_lng,lng_nil); break; _______________________________________________ Checkin-list mailing list Checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list