Changeset: 6300addff0e2 for MonetDB
URL: https://dev.monetdb.org/hg/MonetDB/rev/6300addff0e2
Modified Files:
monetdb_config.h.in
Branch: default
Log Message:
Define macro for doing unaligned reads.
On some architectures you can, though it's inefficient, on others you
simply can't. On the latter type, we provide an alternative using
memcpy.
diffs (44 lines):
diff --git a/monetdb_config.h.in b/monetdb_config.h.in
--- a/monetdb_config.h.in
+++ b/monetdb_config.h.in
@@ -496,6 +496,40 @@ strndup(const char *s, size_t n)
}
#endif
+#if !defined(SANITIZER) && (defined(__x86_64__) || defined(__amd64__))
+/* we can do unaligned access (e.g. read 8-byte value from a location
+ * which is not a multiple of 8; the list can be extended when we learn
+ * about more architectures */
+#define HAVE_UNALIGNED_ACCESS 1
+#endif
+
+#ifdef HAVE_UNALIGNED_ACCESS
+#define READ_UNALIGNED(bits, ptr) (*(uint##bits##_t*)(ptr))
+#else
+static inline uint16_t
+READ_UNALIGNED16(const void *ptr)
+{
+ uint16_t v;
+ memcpy(&v, ptr, 2);
+ return v;
+}
+static inline uint32_t
+READ_UNALIGNED32(const void *ptr)
+{
+ uint32_t v;
+ memcpy(&v, ptr, 2);
+ return v;
+}
+static inline uint64_t
+READ_UNALIGNED64(const void *ptr)
+{
+ uint64_t v;
+ memcpy(&v, ptr, 2);
+ return v;
+}
+#define READ_UNALIGNED(bits, ptr) READ_UNALIGNED##bits(ptr)
+#endif
+
#ifdef _MSC_VER
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]