Changeset: aad1b6165211 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/aad1b6165211
Modified Files:
        sql/backends/monet5/vaults/parquet/pqc_reader.c
        sql/backends/monet5/vaults/parquet/pqc_thrift.h
Branch: pp_hashjoin
Log Message:

some small big endian fixes.


diffs (116 lines):

diff --git a/sql/backends/monet5/vaults/parquet/pqc_reader.c 
b/sql/backends/monet5/vaults/parquet/pqc_reader.c
--- a/sql/backends/monet5/vaults/parquet/pqc_reader.c
+++ b/sql/backends/monet5/vaults/parquet/pqc_reader.c
@@ -34,15 +34,6 @@
 #ifdef HAVE_LIBZ
 #include <zlib.h>
 
-#ifdef _MSC_VER
-/* use intrinsic functions on Windows */
-#define short_int_SWAP(s)      ((int16_t) _byteswap_ushort((uint16_t) (s)))
-#else
-#define short_int_SWAP(s)                              \
-       ((int16_t) (((0x00ff & (uint16_t) (s)) << 8) |  \
-                 ((0xff00 & (uint16_t) (s)) >> 8)))
-#endif
-
 static int
 gzip_uncompress( char *dest, size_t ul, char *src, size_t cl)
 {
@@ -756,12 +747,26 @@ pqc_page_header( pqc_reader_t *r, pqc_cr
                        if (blob_read_dict(pr, num_values) < 0)
                                return -1;
                }
+#ifdef WORDS_BIGENDIAN
+               if (num_values && (r->pse->type == inttype || r->pse->type == 
floattype)) {
+                       char *s = pr->dict;
+                       if (r->pse->size == 16)
+                               for(uint32_t i = 0; i < num_values; i++, 
s+=sizeof(uint16_t))
+                                       *(uint16_t*)s = pqc_sht(*(uint16_t*)s);
+                       if (r->pse->size == 32)
+                               for(uint32_t i = 0; i < num_values; i++, 
s+=sizeof(uint32_t))
+                                       *(uint32_t*)s = pqc_int(*(uint32_t*)s);
+                       if (r->pse->size == 64)
+                               for(uint32_t i = 0; i < num_values; i++, 
s+=sizeof(uint64_t))
+                                       *(uint64_t*)s = pqc_lng(*(uint64_t*)s);
+               }
+#endif
                if (num_values && r->pse->type == inttype && r->pse->precision 
== 96) { /* remove the 32 useless bits */
                        ulng *d = (ulng*)pr->dict;
                        char *s = pr->dict;
                        for(uint32_t i = 0; i < num_values; i++, s += 12) {
-                               uint64_t nanoseconds = *(uint64_t*)s;
-                               uint32_t julian_day = *(uint32_t*)(s+8);
+                               uint64_t nanoseconds = pqc_lng(*(uint64_t*)s);
+                               uint32_t julian_day = 
pqc_int(*(uint32_t*)(s+8));
 
                                nanoseconds /= LL_CONSTANT(1000);
                                julian_day -= 2440588;
diff --git a/sql/backends/monet5/vaults/parquet/pqc_thrift.h 
b/sql/backends/monet5/vaults/parquet/pqc_thrift.h
--- a/sql/backends/monet5/vaults/parquet/pqc_thrift.h
+++ b/sql/backends/monet5/vaults/parquet/pqc_thrift.h
@@ -55,4 +55,64 @@ pqc_export int pqc_get_field( char *in, 
 pqc_export int pqc_get_list( char *in, int *size, int *type);
 pqc_export int pqc_get_string( char *in, char **s, int *len); /* need way to 
buffer 0 */
 
+#ifdef _MSC_VER
+/* use intrinsic functions on Windows */
+#define short_int_SWAP(s)      ((int16_t) _byteswap_ushort((uint16_t) (s)))
+/* on Windows, long is the same size as int */
+#define normal_int_SWAP(i)     ((int) _byteswap_ulong((unsigned long) (i)))
+#define long_int_SWAP(l)       ((int64_t) _byteswap_uint64((unsigned __int64) 
(l)))
+#else
+#define short_int_SWAP(s)                              \
+       ((int16_t) (((0x00ff & (uint16_t) (s)) << 8) |  \
+                 ((0xff00 & (uint16_t) (s)) >> 8)))
+
+#define normal_int_SWAP(i)                                             \
+       ((int) (((((unsigned) 0xff <<  0) & (unsigned) (i)) << 24) |    \
+               ((((unsigned) 0xff <<  8) & (unsigned) (i)) <<  8) |    \
+               ((((unsigned) 0xff << 16) & (unsigned) (i)) >>  8) |    \
+               ((((unsigned) 0xff << 24) & (unsigned) (i)) >> 24)))
+
+#define long_int_SWAP(l)                                               \
+       ((int64_t) (((((uint64_t) 0xff <<  0) & (uint64_t) (l)) << 56) | \
+               ((((uint64_t) 0xff <<  8) & (uint64_t) (l)) << 40) |    \
+               ((((uint64_t) 0xff << 16) & (uint64_t) (l)) << 24) |    \
+               ((((uint64_t) 0xff << 24) & (uint64_t) (l)) <<  8) |    \
+               ((((uint64_t) 0xff << 32) & (uint64_t) (l)) >>  8) |    \
+               ((((uint64_t) 0xff << 40) & (uint64_t) (l)) >> 24) |    \
+               ((((uint64_t) 0xff << 48) & (uint64_t) (l)) >> 40) |    \
+               ((((uint64_t) 0xff << 56) & (uint64_t) (l)) >> 56)))
+#endif
+
+#ifdef HAVE_HGE
+#define huge_int_SWAP(h)                                       \
+       ((hge) (((((uhge) 0xff <<   0) & (uhge) (h)) << 120) |  \
+               ((((uhge) 0xff <<   8) & (uhge) (h)) << 104) |  \
+               ((((uhge) 0xff <<  16) & (uhge) (h)) <<  88) |  \
+               ((((uhge) 0xff <<  24) & (uhge) (h)) <<  72) |  \
+               ((((uhge) 0xff <<  32) & (uhge) (h)) <<  56) |  \
+               ((((uhge) 0xff <<  40) & (uhge) (h)) <<  40) |  \
+               ((((uhge) 0xff <<  48) & (uhge) (h)) <<  24) |  \
+               ((((uhge) 0xff <<  56) & (uhge) (h)) <<   8) |  \
+               ((((uhge) 0xff <<  64) & (uhge) (h)) >>   8) |  \
+               ((((uhge) 0xff <<  72) & (uhge) (h)) >>  24) |  \
+               ((((uhge) 0xff <<  80) & (uhge) (h)) >>  40) |  \
+               ((((uhge) 0xff <<  88) & (uhge) (h)) >>  56) |  \
+               ((((uhge) 0xff <<  96) & (uhge) (h)) >>  72) |  \
+               ((((uhge) 0xff << 104) & (uhge) (h)) >>  88) |  \
+               ((((uhge) 0xff << 112) & (uhge) (h)) >> 104) |  \
+               ((((uhge) 0xff << 120) & (uhge) (h)) >> 120)))
+#endif
+
+#ifdef WORDS_BIGENDIAN
+#define pqc_sht(s) short_int_SWAP(s)
+#define pqc_int(s) normal_int_SWAP(s)
+#define pqc_lng(s) long_int_SWAP(s)
+#define pqc_hge(s) huge_int_SWAP(s)
+#else
+#define pqc_sht(s) (s)
+#define pqc_int(s) (s)
+#define pqc_lng(s) (s)
+#define pqc_hge(s) (s)
+#endif
+
 #endif /*_PQC_THRIFT_H_*/
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to