Changeset: 43a1e71cad18 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=43a1e71cad18
Modified Files:
        gdk/gdk.h
        monetdb5/mal/mal.c
        monetdb5/mal/mal.h
        monetdb5/mal/mal_atom.c
        monetdb5/mal/mal_parser.c
        monetdb5/modules/kernel/Makefile.ag
        monetdb5/modules/kernel/colcalc.c.mx
        monetdb5/modules/kernel/colcalc.mal.mx
        monetdb5/modules/mal/cbp.c
        monetdb5/optimizer/Makefile.ag
        monetdb5/optimizer/opt_accumulators.c
        monetdb5/optimizer/opt_accumulators.h
Branch: headless
Log Message:

Conversion of colcalc.mx
Splitting the original batcalc into pieces and reducing
the code base


diffs (truncated from 2488 to 300 lines):

diff --git a/gdk/gdk.h b/gdk/gdk.h
--- a/gdk/gdk.h
+++ b/gdk/gdk.h
@@ -2906,6 +2906,9 @@
 #define COLloop(r, p, q) \
        for(q = BUNlast(r), p = BUNfirst(r);p < q; p++)
 
+#define COLforloop(b,o) for( o = 0; o < b->count; o++)
+#define COLgetString(b,o)      (str)(base(b) + ((size_t) 
VarHeapValRaw(b,o,b->width)  << GDK_VARSHIFT))
+
 /*
  * batloop where the current element can be deleted/updated
  * --------------------------------------------------------
diff --git a/monetdb5/mal/mal.c b/monetdb5/mal/mal.c
--- a/monetdb5/mal/mal.c
+++ b/monetdb5/mal/mal.c
@@ -371,3 +371,13 @@
        }
        GDKexit(0);     /* properly end GDK */
 }
+
+str  
+getCOLdescriptor(COL **b,int *l)
+{
+    *b= COLdescriptor(*l);
+    if (*b == 0)
+        return RUNTIME_OBJECT_MISSING;
+    return MAL_SUCCEED;
+}
+
diff --git a/monetdb5/mal/mal.h b/monetdb5/mal/mal.h
--- a/monetdb5/mal/mal.h
+++ b/monetdb5/mal/mal.h
@@ -75,6 +75,8 @@
 mal_export int mal_init(void);
 mal_export void mal_exit(void);
 mal_export int moreClients(int reruns);
+mal_export str getCOLdescriptor(COL **b, int *l);
+#define getCOLbase(b) ((b)->heap.base)
 
 /* This should be here, but cannot, as "Client" isn't known, yet ... |-(
  * For now, we move the prototype declaration to src/mal/mal_client.c,
diff --git a/monetdb5/mal/mal_atom.c b/monetdb5/mal/mal_atom.c
--- a/monetdb5/mal/mal_atom.c
+++ b/monetdb5/mal/mal_atom.c
@@ -238,73 +238,10 @@
                        return 1;
                }
                if (idcmp("heapcheck", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomHeapCheck = (int (*)(Heap *, 
HeapRepair *))pci->fcn;
+                       COLatoms[tpe].atomHeapCheck = (int (*)(Heap *, 
HeapRepair *))pci->fcn;
                        setAtomName(pci);
                        return 1;
                }
-               break;
-       case 'l':
-               if (idcmp("length", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomLen = (int (*)(ptr))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 'n':
-               if (idcmp("null", name) == 0 && pci->argc == 1) {
-                       ptr atmnull = ((ptr (*)(void))pci->fcn)();
-
-                       BATatoms[tpe].atomNull = atmnull;
-                       setAtomName(pci);
-                       return 1;
-               }
-               if (idcmp("nequal", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomCmp = (int (*)(ptr, ptr))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 'p':
-               if (idcmp("put", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomPut = (var_t (*)(Heap *, var_t *, 
ptr))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 's':
-               @ : setItem("storage", storage, TYPE_int, long) @;
-               break;
-       case 't':
-               if (idcmp("tostr", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomToStr = (int (*)(str *, int *, 
ptr))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 'u':
-               if (idcmp("unfix", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomUnfix = (int (*)(ptr))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 'v':
-               @ : setItem("varsized", varsized, TYPE_int, long) @
-               break;
-       case 'r':
-               if (idcmp("read", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomRead = (void *(*)(void *, stream *, 
size_t))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
-       case 'w':
-               if (idcmp("write", name) == 0 && pci->argc == 1) {
-                       BATatoms[tpe].atomWrite = (int (*)(void *, stream *, 
size_t))pci->fcn;
-                       setAtomName(pci);
-                       return 1;
-               }
-               break;
        }
        return 0;
 }
@@ -339,11 +276,11 @@
        i = ATOMindex(name);
        /* overload atom ? */
        if (tpe) {
-               BATatoms[i] = BATatoms[tpe];
-               strncpy(BATatoms[i].name, name, sizeof(BATatoms[i].name));
-               BATatoms[i].storage = BATatoms[tpe].storage;
+               COLatoms[i] = COLatoms[tpe];
+               strncpy(COLatoms[i].name, name, sizeof(COLatoms[i].name));
+               COLatoms[i].storage = COLatoms[tpe].storage;
        } else { /* cannot overload void atoms */
-               BATatoms[i].storage = i;
+               COLatoms[i].storage = i;
        }
 }
 
diff --git a/monetdb5/mal/mal_parser.c b/monetdb5/mal/mal_parser.c
--- a/monetdb5/mal/mal_parser.c
+++ b/monetdb5/mal/mal_parser.c
@@ -1394,13 +1394,14 @@
        if( MALkeyword(cntxt,"address",7)){
                str nme;
                int i;
+               InstrPtr curInstr = getInstrPtr(curBlk,0);
                i = idLength(cntxt);
                if( i==0){
                        parseError(cntxt,"<identifier> expected\n");
                        return 0;
                }
                nme = idCopy(cntxt,i);
-               getInstrPtr(curBlk,0)->fcn = getAddress(cntxt->srcFile, 
cntxt->nspace->name, nme,TRUE);
+               curInstr->fcn = getAddress(cntxt->srcFile, cntxt->nspace->name, 
nme,TRUE);
                GDKfree(nme);
                if (curInstr->fcn == NULL) {
                        parseError(cntxt, "<address> not found\n");
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
@@ -42,7 +42,9 @@
 #              algebra.mx \
 #              array.mx \
 #              column.mx \
-#              colcalc.mx \
+               colcalc.mal.mx \
+               colcalc.h.mx \
+               colcalc.c.mx \
 #              colcast.mx \
 #              colcolor.mx \
 #              colifthen.mx \
@@ -66,7 +68,7 @@
        DIR = libdir/monetdb5
        SOURCES = calc.mx column.mx algebra.mx status.mal unix.mal \
                mmath.mx lock.mal sema.mal alarm.mx colstr.mx colmtime.mx \
-               colcolor.mx colifthen.mx colcast.mx colcalc.mx colmmath.mx \
+               colcolor.mx colifthen.mx colcast.mx colcalc.mal.mx colmmath.mx \
                group.mx aggr.mx array.mx \
                mx logger.mal microbenchmark.mx
 }
diff --git a/monetdb5/modules/kernel/colcalc.c.mx 
b/monetdb5/modules/kernel/colcalc.c.mx
--- a/monetdb5/modules/kernel/colcalc.c.mx
+++ b/monetdb5/modules/kernel/colcalc.c.mx
@@ -1,3 +1,5 @@
+@f colcalc
+@c
 /*
  * 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
@@ -17,650 +19,25 @@
  * All Rights Reserved.
 */
 
+#include "colcalc.h"
 /* Author(s) M.L. Kersten
- * @+ BAT calculator
+ * @+ Column calculator
  * Many applications require extension of the basic calculator and
- * mathematic functions to work on BAT arguments. Although the
- * MAL multiplex optimizer contains a command ('optimizer.multiplex')
- * to generate the necessary code, it is often much more efficient to 
- * use one of the dedidacted batcalc functions introduced below.
- * 
- * The operators supported are limited to the built-in fixed length
+ * mathematic functions to work on column arguments. 
+ * The operators supported  here are limited to the built-in fixed length
  * atoms, because they permit ease of storage of the operation result.
  * Variable sized atoms, especially user defined, may require more
  * administrative activities.
  * Furthermore, the operands involved are assumed to be aligned
  * to assure the fastest possible join evaluation.
  * 
- * Optimal processing performance is further obtained when the operators
- * can work as 'accumulators', for then we do not pay the price
- * of space allocation for a new intermediate. It may imply a COLcopy
- * before the accummulator function is being called.
- * A new BAT is of course created when the result of a function does not fit 
- * the accumulator.
- * 
  * The implementation does not take into account possible overflows
  * caused by the operators. However, the operators respect the NIL
  * semantics and division by zero produces a NIL.
  * 
  * In addition to arithmetic and comparison operators, casting and
  * mathematical functions are directly supported.
- * 
- * @+ NULL semantics
- * The batcalc arithmetic is already constraint to BATs of equal size.
- * Another improvement is obtained when we do not have to check
- * for NULLs in each and every basic operation +,-,/,* and comparisons.
- * A problem is to propagate the general 'nonil' property, because
- * this depends on the semantics of the operator. Checking the result
- * for a nil value depleats most of the expected gain.
- * 
- * Currently only set for the NOT operation and comparisons operators when
- * neither argument has nils.
 */
-@h
-#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 batcalc_export extern __declspec(dllimport)
-#else
-#define batcalc_export extern __declspec(dllexport)
-#endif
-#else
-#define batcalc_export extern
-#endif
-
-@-
-The new module always create the target column first
-and then fills it.
-@-
-@= accum
-{
-       @4 *o = (@4*)COLvalue(bn, COLfirst(bn));
-       @2 *p = (@2*)COLvalue(b, COLfirst(b));
-       @2 *q = (@2*)COLvalue(b, COLlast(b));
-       @3 *r = (@3*)COLvalue(right, COLfirst(right));
-
-       COLaccessBegin(b, USE_HEAP, MMAP_SEQUENTIAL);
-       COLaccessBegin(right, USE_HEAP, MMAP_SEQUENTIAL);
-       if (b->nonil && right->nonil)
-               for (; p<q; o++, p++, r++)
-                       *o = (@4) (*p @1 *r);
-       else if (b->nonil) {
-               for (; p<q; o++, p++, r++){
-                       /* this code is better as x?nil:y  */
-                       if(*r == @3_nil) {
-                               *o = @4_nil;
-                               bn->nonil = 0;
-                       } else 
-                               *o = (@4) (*p @1 *r);
-               }
-       } else if (right->nonil)
-               for (; p<q; o++, p++, r++){
-                       /* this code is better as x?nil:y  */
-                       if(*p == @2_nil ) {
-                               *o = @4_nil;
-                               bn->nonil = 0;
-                       } else 
-                               *o = (@4) (*p @1 *r);
-               }
-       else
-               for (; p<q; o++, p++, r++){
-                       /* this code is better as x?nil:y  */
-                       if(*p == @2_nil || *r == @3_nil) {
-                               *o = @4_nil;
-                               bn->nonil = 0;
-                       } else 
-                               *o = (@4) (*p @1 *r);
-               }
-       COLaccessEnd(right, USE_HEAP, MMAP_SEQUENTIAL);
-       COLaccessEnd(b, USE_HEAP, MMAP_SEQUENTIAL);
-}
-@= accumCst
-{
-       @4 *o = (@4*)COLvalue(bn, COLfirst(bn)); 
-       @2 *p = (@2*)COLvalue(b, COLfirst(b));
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to