Changeset: ad94610d8298 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=ad94610d8298 Added Files: sql/backends/monet5/sql_fround_impl.h sql/backends/monet5/sql_round_impl.h Modified Files: sql/backends/monet5/Makefile.ag sql/backends/monet5/sql_fround.c sql/backends/monet5/sql_round.c Branch: default Log Message:
Merge with Jan2014 branch. diffs (truncated from 3439 to 300 lines): diff --git a/sql/backends/monet5/Makefile.ag b/sql/backends/monet5/Makefile.ag --- a/sql/backends/monet5/Makefile.ag +++ b/sql/backends/monet5/Makefile.ag @@ -52,7 +52,8 @@ lib__sql = { sql_cast_impl_down_from_int.h \ sql_cast_impl_up_to_flt.h \ sql_cast_impl_up_to_int.h \ - sql_round.c sql_bat2time.c sql_fround.c sql_rdf.c + sql_round.c sql_round_impl.h sql_bat2time.c \ + sql_fround.c sql_fround_impl.h sql_rdf.c LIBS = ../../server/libsqlserver \ ../../storage/libstore \ ../../storage/bat/libbatstore \ diff --git a/sql/backends/monet5/sql_fround.c b/sql/backends/monet5/sql_fround.c --- a/sql/backends/monet5/sql_fround.c +++ b/sql/backends/monet5/sql_fround.c @@ -81,482 +81,21 @@ trunc(double val) } #endif -static inline flt -flt_dec_round_body_nonil(flt v, flt r) -{ - assert(v != flt_nil); +#define CONCAT_2(a, b) a##b +#define CONCAT_3(a, b, c) a##b##c - return v / r; -} +#define NIL(t) CONCAT_2(t, _nil) +#define TPE(t) CONCAT_2(TYPE_, t) +#define GDKmin(t) CONCAT_3(GDK_, t, _min) +#define GDKmax(t) CONCAT_3(GDK_, t, _max) +#define FUN(a, b) CONCAT_3(a, _, b) -static inline flt -flt_dec_round_body(flt v, flt r) -{ - /* shortcut nil */ - if (v == flt_nil) { - return flt_nil; - } else { - return flt_dec_round_body_nonil(v, r); - } -} +#define STRING(a) #a -str -flt_dec_round_wrap(flt *res, flt *v, flt *r) -{ - /* basic sanity checks */ - assert(res && v && r); +#define TYPE flt +#include "sql_fround_impl.h" +#undef TYPE - *res = flt_dec_round_body(*v, *r); - return MAL_SUCCEED; -} - -str -flt_bat_dec_round_wrap(bat *_res, bat *_v, flt *r) -{ - BAT *res, *v; - flt *src, *dst; - BUN i, cnt; - bit nonil; /* TRUE: we know there are no NIL (NULL) values */ - bit nil; /* TRUE: we know there is at least one NIL (NULL) value */ - - /* basic sanity checks */ - assert(_res && _v && r); - - /* get argument BAT descriptor */ - if ((v = BATdescriptor(*_v)) == NULL) - throw(MAL, "round", RUNTIME_OBJECT_MISSING); - - /* more sanity checks */ - if (!BAThdense(v)) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", "argument 1 must have a dense head"); - } - if (v->ttype != TYPE_flt) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", "argument 1 must have a flt tail"); - } - cnt = BATcount(v); - - /* allocate result BAT */ - res = BATnew(TYPE_void, TYPE_flt, cnt); - if (res == NULL) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", MAL_MALLOC_FAIL); - } - - /* access columns as arrays */ - src = (flt *) Tloc(v, BUNfirst(v)); - dst = (flt *) Tloc(res, BUNfirst(res)); - - nil = FALSE; - nonil = TRUE; - if (v->T->nonil == TRUE) { - for (i = 0; i < cnt; i++) - dst[i] = flt_dec_round_body_nonil(src[i], *r); - } else { - for (i = 0; i < cnt; i++) { - if (src[i] == flt_nil) { - nil = TRUE; - nonil = FALSE; - dst[i] = flt_nil; - } else { - dst[i] = flt_dec_round_body_nonil(src[i], *r); - } - } - } - - /* set result BAT properties */ - BATsetcount(res, cnt); - /* result head is aligned with agument head */ - ALIGNsetH(res, v); - /* hard to predict correct tail properties in general */ - res->T->nonil = nonil; - res->T->nil = nil; - res->tdense = FALSE; - res->tsorted = v->tsorted; - BATkey(BATmirror(res), FALSE); - - /* release argument BAT descriptors */ - BBPreleaseref(v->batCacheid); - - /* keep result */ - BBPkeepref(*_res = res->batCacheid); - - return MAL_SUCCEED; -} - -static inline flt -flt_round_body_nonil(flt v, bte r) -{ - flt res = flt_nil; - - assert(v != flt_nil); - - if (r < 0) { - int d = -r; - flt rnd = (flt) (scales[d] >> 1); - - res = (flt) (floor(((v + rnd) / ((flt) (scales[d])))) * scales[d]); - } else if (r > 0) { - int d = r; - - res = (flt) (floor(v * (flt) scales[d] + .5) / scales[d]); - } else { - res = (flt) round(v); - } - return res; -} - -static inline flt -flt_round_body(flt v, bte r) -{ - /* shortcut nil */ - if (v == flt_nil) { - return flt_nil; - } else { - return flt_round_body_nonil(v, r); - } -} - -str -flt_round_wrap(flt *res, flt *v, bte *r) -{ - /* basic sanity checks */ - assert(res && v && r); - - *res = flt_round_body(*v, *r); - return MAL_SUCCEED; -} - -str -flt_bat_round_wrap(bat *_res, bat *_v, bte *r) -{ - BAT *res, *v; - flt *src, *dst; - BUN i, cnt; - bit nonil; /* TRUE: we know there are no NIL (NULL) values */ - bit nil; /* TRUE: we know there is at least one NIL (NULL) value */ - - /* basic sanity checks */ - assert(_res && _v && r); - - /* get argument BAT descriptor */ - if ((v = BATdescriptor(*_v)) == NULL) - throw(MAL, "round", RUNTIME_OBJECT_MISSING); - - /* more sanity checks */ - if (!BAThdense(v)) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", "argument 1 must have a dense head"); - } - if (v->ttype != TYPE_flt) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", "argument 1 must have a flt tail"); - } - cnt = BATcount(v); - - /* allocate result BAT */ - res = BATnew(TYPE_void, TYPE_flt, cnt); - if (res == NULL) { - BBPreleaseref(v->batCacheid); - throw(MAL, "round", MAL_MALLOC_FAIL); - } - - /* access columns as arrays */ - src = (flt *) Tloc(v, BUNfirst(v)); - dst = (flt *) Tloc(res, BUNfirst(res)); - - nil = FALSE; - nonil = TRUE; - if (v->T->nonil == TRUE) { - for (i = 0; i < cnt; i++) - dst[i] = flt_round_body_nonil(src[i], *r); - } else { - for (i = 0; i < cnt; i++) { - if (src[i] == flt_nil) { - nil = TRUE; - nonil = FALSE; - dst[i] = flt_nil; - } else { - dst[i] = flt_round_body_nonil(src[i], *r); - } - } - } - - /* set result BAT properties */ - BATsetcount(res, cnt); - /* result head is aligned with agument head */ - ALIGNsetH(res, v); - /* hard to predict correct tail properties in general */ - res->T->nonil = nonil; - res->T->nil = nil; - res->tdense = FALSE; - res->tsorted = v->tsorted; - BATkey(BATmirror(res), FALSE); - - /* release argument BAT descriptors */ - BBPreleaseref(v->batCacheid); - - /* keep result */ - BBPkeepref(*_res = res->batCacheid); - - return MAL_SUCCEED; -} - -str -flt_trunc_wrap(flt *res, flt *v, int *r) -{ - /* shortcut nil */ - if (*v == flt_nil) { - *res = flt_nil; - } else if (*r < 0) { - int d = -*r; - *res = (flt) (trunc((*v) / ((flt) scales[d])) * scales[d]); - } else if (*r > 0) { - int d = *r; - *res = (flt) (trunc(*v * (flt) scales[d]) / ((flt) scales[d])); - } else { - *res = (flt) trunc(*v); - } - return MAL_SUCCEED; -} - -static inline dbl -dbl_dec_round_body_nonil(dbl v, dbl r) -{ - assert(v != dbl_nil); - - return v / r; -} - -static inline dbl -dbl_dec_round_body(dbl v, dbl r) -{ - /* shortcut nil */ - if (v == dbl_nil) { - return dbl_nil; - } else { - return dbl_dec_round_body_nonil(v, r); - } -} - -str -dbl_dec_round_wrap(dbl *res, dbl *v, dbl *r) -{ - /* basic sanity checks */ - assert(res && v && r); - - *res = dbl_dec_round_body(*v, *r); - return MAL_SUCCEED; -} - _______________________________________________ checkin-list mailing list checkin-list@monetdb.org https://www.monetdb.org/mailman/listinfo/checkin-list