Changeset: a2ab94bd56e8 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=a2ab94bd56e8
Modified Files:
        monetdb5/modules/mosaic/mosaic.h
        monetdb5/modules/mosaic/mosaic_delta.c
        monetdb5/modules/mosaic/mosaic_frame.c
        monetdb5/modules/mosaic/mosaic_linear.c
        monetdb5/modules/mosaic/mosaic_prefix.c
Branch: mosaic
Log Message:

Factor out shared macro's.


diffs (191 lines):

diff --git a/monetdb5/modules/mosaic/mosaic.h b/monetdb5/modules/mosaic/mosaic.h
--- a/monetdb5/modules/mosaic/mosaic.h
+++ b/monetdb5/modules/mosaic/mosaic.h
@@ -53,6 +53,37 @@ typedef Heap *mosaic;        // compressed data
 #define IS_NIL(TPE, VAL) is_##TPE##_nil(VAL)
 #define ARE_EQUAL(v, w, HAS_NIL, TPE) ((v == w || (HAS_NIL && IS_NIL(TPE, v) 
&& IS_NIL(TPE, w)) ) )
 
+#define Deltabte uint8_t
+#define Deltasht uint16_t
+#define Deltaint uint32_t
+#define Deltalng uint64_t
+#define Deltaoid uint64_t
+#ifdef HAVE_HGE
+#define Deltahge uhge
+#endif
+
+#define DeltaTpe(TPE) Delta##TPE
+
+/* Use standard unsigned integer operations 
+ * to avoid undefined behavior due to overflow's
+ */
+#define GET_DELTA(TPE, x, y)  ((DeltaTpe(TPE)) x - (DeltaTpe(TPE)) y)
+#define ADD_DELTA(TPE, x, d)  (TPE) ((DeltaTpe(TPE)) x + (DeltaTpe(TPE)) d)
+
+// types for safe Integer Promotion for the bitwise operations in getSuffixMask
+#define IPbte uint32_t
+#define IPsht uint32_t
+#define IPint uint32_t
+#define IPlng uint64_t
+#define IPoid uint64_t
+#define IPflt uint64_t
+#define IPdbl uint64_t
+#ifdef HAVE_HGE
+#define IPhge uhge
+#endif
+
+#define IPTpe(TPE) IP##TPE
+
 typedef struct MOSAICHEADER{
        int version;
        int top; // TODO: rename to e.g. nblocks because it is the number of 
blocks
diff --git a/monetdb5/modules/mosaic/mosaic_delta.c 
b/monetdb5/modules/mosaic/mosaic_delta.c
--- a/monetdb5/modules/mosaic/mosaic_delta.c
+++ b/monetdb5/modules/mosaic/mosaic_delta.c
@@ -105,20 +105,6 @@ MOSskip_delta(MOStask task)
 
 #define MOScodevectorDelta(Task) (((char*) (Task)->blk)+ 
wordaligned(sizeof(MosaicBlkHeader_delta_t), unsigned int))
 
-#define Deltabte uint8_t
-#define Deltasht uint16_t
-#define Deltaint uint32_t
-#define Deltalng uint64_t
-#define Deltaoid uint64_t
-#ifdef HAVE_HGE
-#define Deltahge uhge
-#endif
-
-#define DeltaTpe(TPE) Delta##TPE
-
-/* Use standard unsigned integer operations because (in theory) we have to be 
careful not to get overflow's and undefined behavior*/\
-#define GET_DELTA(TPE, max, val)  ((DeltaTpe(TPE)) max - (DeltaTpe(TPE)) val)
-
 #define determineDeltaParameters(PARAMETERS, SRC, LIMIT, TPE) \
 do {\
        TPE *val = SRC;\
@@ -195,18 +181,6 @@ MOSestimate_delta(MOStask task, MosaicEs
        return MAL_SUCCEED;
 }
 
-// types for safe Integer Promotion for the bitwise operations in getSuffixMask
-#define IPbte uint32_t
-#define IPsht uint32_t
-#define IPint uint32_t
-#define IPlng uint64_t
-#define IPoid uint64_t
-#ifdef HAVE_HGE
-#define IPhge uhge
-#endif
-
-#define IPTpe(TPE) IP##TPE
-
 #define DELTAcompress(TASK, TPE)\
 do {\
        TPE *src = getSrc(TPE, (TASK));\
diff --git a/monetdb5/modules/mosaic/mosaic_frame.c 
b/monetdb5/modules/mosaic/mosaic_frame.c
--- a/monetdb5/modules/mosaic/mosaic_frame.c
+++ b/monetdb5/modules/mosaic/mosaic_frame.c
@@ -113,21 +113,6 @@ MOSskip_frame(MOStask task)
 
 #define MOScodevectorFrame(Task) (((char*) (Task)->blk)+ 
wordaligned(sizeof(MosaicBlkHeader_frame_t), unsigned int))
 
-#define Deltabte uint8_t
-#define Deltasht uint16_t
-#define Deltaint uint32_t
-#define Deltalng uint64_t
-#define Deltaoid uint64_t
-#ifdef HAVE_HGE
-#define Deltahge uhge
-#endif
-
-#define DeltaTpe(TPE) Delta##TPE
-
-/* Use standard unsigned integer operations because (in theory) we have to be 
careful not to get overflow's and undefined behavior*/\
-#define GET_DELTA(TPE, max, min)  ((DeltaTpe(TPE)) max - (DeltaTpe(TPE)) min)
-#define ADD_DELTA(TPE, min, delta)  (TPE) ((DeltaTpe(TPE)) min + 
(DeltaTpe(TPE)) delta)
-
 #define determineFrameParameters(PARAMETERS, SRC, LIMIT, TPE) \
 do {\
        TPE *val = SRC, max, min;\
diff --git a/monetdb5/modules/mosaic/mosaic_linear.c 
b/monetdb5/modules/mosaic/mosaic_linear.c
--- a/monetdb5/modules/mosaic/mosaic_linear.c
+++ b/monetdb5/modules/mosaic/mosaic_linear.c
@@ -37,17 +37,6 @@ bool MOStypes_linear(BAT* b) {
        return false;
 }
 
-#define Deltabte uint8_t
-#define Deltasht uint16_t
-#define Deltaint uint32_t
-#define Deltalng uint64_t
-#define Deltaoid uint64_t
-#ifdef HAVE_HGE
-#define Deltahge uhge
-#endif
-
-#define DeltaTpe(TPE) Delta##TPE
-
 #define linear_base(BLK) ((void*)(((char*) BLK)+ MosaicBlkSize))
 
 static void*
@@ -122,9 +111,9 @@ MOSskip_linear(MOStask task)
        BUN i = 1;\
        if (limit > 1 ){\
                TPE *p = c++; /*(p)revious value*/\
-               DeltaTpe(TPE) step = (DeltaTpe(TPE)) *c - (DeltaTpe(TPE)) *p;\
+               DeltaTpe(TPE) step = GET_DELTA(TPE, *c, *p);\
                for( ; i < limit; i++, p++, c++) {\
-                       DeltaTpe(TPE) current_step = (DeltaTpe(TPE)) *c - 
(DeltaTpe(TPE)) *p;\
+                       DeltaTpe(TPE) current_step = GET_DELTA(TPE, *c, *p);\
                        if (  current_step != step)\
                                break;\
                }\
@@ -164,7 +153,7 @@ MOSestimate_linear(MOStask task, MosaicE
        *(TPE*) linear_base(blk) = *c;\
        if (limit > 1 ){\
                TPE *p = c++; /*(p)revious value*/\
-               step = (TPE) (DeltaTpe(TPE)) *c - (DeltaTpe(TPE)) *p;\
+               step = (TPE) GET_DELTA(TPE, *c, *p);\
        }\
        MOSsetCnt(blk, limit);\
        *(TPE*) linear_step(task,blk) = step;\
@@ -193,11 +182,11 @@ MOScompress_linear(MOStask task, MosaicB
 
 // the inverse operator, extend the src
 #define LINEARdecompress(TPE)\
-{      TPE val = *(TPE*) linear_base(blk);\
-       TPE step = *(TPE*) linear_step(task,blk);\
+{      DeltaTpe(TPE) val = *(TPE*) linear_base(blk);\
+       DeltaTpe(TPE) step = *(TPE*) linear_step(task,blk);\
        BUN lim = MOSgetCnt(blk);\
-       for(i = 0; i < lim; i++) {\
-               ((TPE*)task->src)[i] = (TPE) ((DeltaTpe(TPE)) val + (TPE) (i * 
(DeltaTpe(TPE)) step));\
+       for(i = 0; i < lim; i++, val += step) {\
+               ((TPE*)task->src)[i] = (TPE) val;\
        }\
        task->src += i * sizeof(TPE);\
 }
diff --git a/monetdb5/modules/mosaic/mosaic_prefix.c 
b/monetdb5/modules/mosaic/mosaic_prefix.c
--- a/monetdb5/modules/mosaic/mosaic_prefix.c
+++ b/monetdb5/modules/mosaic/mosaic_prefix.c
@@ -155,20 +155,6 @@ MOSskip_prefix(MOStask task)
        if ( MOSgetTag(task->blk) == MOSAIC_EOL)
                task->blk = 0; // ENDOFLIST
 }
-
-// types for safe Integer Promotion for the bitwise operations in getSuffixMask
-#define IPbte uint32_t
-#define IPsht uint32_t
-#define IPint uint32_t
-#define IPlng uint64_t
-#define IPoid uint64_t
-#define IPflt uint64_t
-#define IPdbl uint64_t
-#ifdef HAVE_HGE
-#define IPhge uhge
-#endif
-
-#define IPTpe(TPE) IP##TPE
 #define OverShift(TPE) ((sizeof(IPTpe(TPE)) - sizeof(PrefixTpe(TPE))) * 
CHAR_BIT)
 #define getSuffixMask(SUFFIX_BITS, TPE) ((PrefixTpe(TPE)) (~(~((IPTpe(TPE)) 
(0)) << (SUFFIX_BITS))))
 #define getPrefixMask(PREFIX_BITS, TPE) ((PrefixTpe(TPE)) ( (~(~((IPTpe(TPE)) 
(0)) >> (PREFIX_BITS))) >> OverShift(TPE)))
_______________________________________________
checkin-list mailing list
checkin-list@monetdb.org
https://www.monetdb.org/mailman/listinfo/checkin-list

Reply via email to