Module Name: src
Committed By: martin
Date: Sun Dec 8 13:23:23 UTC 2019
Modified Files:
src/common/lib/libc/hash/murmurhash [netbsd-9]: murmurhash.c
src/sys/arch/amd64/include [netbsd-9]: param.h
src/sys/arch/i386/include [netbsd-9]: param.h
src/sys/sys [netbsd-9]: param.h
Log Message:
Pull up following revision(s) (requested by riastradh in ticket #505):
common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.7
common/lib/libc/hash/murmurhash/murmurhash.c: revision 1.8
sys/sys/param.h: revision 1.610
sys/arch/amd64/include/param.h: revision 1.31
sys/arch/i386/include/param.h: revision 1.85
New macro ALIGNED_POINTER_LOAD.
To be used with ALIGNED_POINTER(p,t) instead of writing *(const t *)p
directly. This way, on machines without strict alignment, we can use
memcpy to pacify sanitizers, while getting the same compiled code in
the end with a single (say) MOV instruction.
Fix byte order bug in murmurhash and pacify sanitizers.
add now required includes for memcpy prototypes analogue to other hash functions
(fix the build)
To generate a diff of this commit:
cvs rdiff -u -r1.6 -r1.6.28.1 \
src/common/lib/libc/hash/murmurhash/murmurhash.c
cvs rdiff -u -r1.30 -r1.30.4.1 src/sys/arch/amd64/include/param.h
cvs rdiff -u -r1.84 -r1.84.4.1 src/sys/arch/i386/include/param.h
cvs rdiff -u -r1.599.2.2 -r1.599.2.3 src/sys/sys/param.h
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/common/lib/libc/hash/murmurhash/murmurhash.c
diff -u src/common/lib/libc/hash/murmurhash/murmurhash.c:1.6 src/common/lib/libc/hash/murmurhash/murmurhash.c:1.6.28.1
--- src/common/lib/libc/hash/murmurhash/murmurhash.c:1.6 Sat Oct 26 21:06:38 2013
+++ src/common/lib/libc/hash/murmurhash/murmurhash.c Sun Dec 8 13:23:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $ */
+/* $NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $ */
/*
* MurmurHash2 -- from the original code:
@@ -14,15 +14,19 @@
#include <sys/cdefs.h>
#if defined(_KERNEL) || defined(_STANDALONE)
-__KERNEL_RCSID(0, "$NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $");
+
+#include <lib/libkern/libkern.h>
#else
#if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: murmurhash.c,v 1.6 2013/10/26 21:06:38 rmind Exp $");
+__RCSID("$NetBSD: murmurhash.c,v 1.6.28.1 2019/12/08 13:23:23 martin Exp $");
#endif /* LIBC_SCCS and not lint */
#include "namespace.h"
+#include <string.h>
+
#endif
#include <sys/types.h>
@@ -51,7 +55,10 @@ murmurhash2(const void *key, size_t len,
if (__predict_true(ALIGNED_POINTER(key, uint32_t))) {
while (len >= sizeof(uint32_t)) {
- uint32_t k = *(const uint32_t *)data;
+ uint32_t k;
+
+ ALIGNED_POINTER_LOAD(&k, data, uint32_t);
+ k = htole32(k);
k *= m;
k ^= k >> r;
Index: src/sys/arch/amd64/include/param.h
diff -u src/sys/arch/amd64/include/param.h:1.30 src/sys/arch/amd64/include/param.h:1.30.4.1
--- src/sys/arch/amd64/include/param.h:1.30 Sat Mar 16 11:50:48 2019
+++ src/sys/arch/amd64/include/param.h Sun Dec 8 13:23:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.30 2019/03/16 11:50:48 rin Exp $ */
+/* $NetBSD: param.h,v 1.30.4.1 2019/12/08 13:23:23 martin Exp $ */
#ifdef __x86_64__
@@ -21,7 +21,8 @@
#define MACHINE_ARCH "x86_64"
#define MID_MACHINE MID_X86_64
-#define ALIGNED_POINTER(p,t) 1
+#define ALIGNED_POINTER(p,t) 1
+#define ALIGNED_POINTER_LOAD(q,p,t) memcpy((q), (p), sizeof(t))
/*
* Align stack as required by AMD64 System V ABI. This is because
Index: src/sys/arch/i386/include/param.h
diff -u src/sys/arch/i386/include/param.h:1.84 src/sys/arch/i386/include/param.h:1.84.4.1
--- src/sys/arch/i386/include/param.h:1.84 Mon Jan 7 22:00:31 2019
+++ src/sys/arch/i386/include/param.h Sun Dec 8 13:23:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.84 2019/01/07 22:00:31 jdolecek Exp $ */
+/* $NetBSD: param.h,v 1.84.4.1 2019/12/08 13:23:23 martin Exp $ */
/*-
* Copyright (c) 1990 The Regents of the University of California.
@@ -58,7 +58,8 @@
#define MACHINE_ARCH "i386"
#define MID_MACHINE MID_I386
-#define ALIGNED_POINTER(p,t) 1
+#define ALIGNED_POINTER(p,t) 1
+#define ALIGNED_POINTER_LOAD(q,p,t) memcpy((q), (p), sizeof(t))
#define PGSHIFT 12 /* LOG2(NBPG) */
#define NBPG (1 << PGSHIFT) /* bytes/page */
Index: src/sys/sys/param.h
diff -u src/sys/sys/param.h:1.599.2.2 src/sys/sys/param.h:1.599.2.3
--- src/sys/sys/param.h:1.599.2.2 Wed Nov 27 14:34:31 2019
+++ src/sys/sys/param.h Sun Dec 8 13:23:23 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: param.h,v 1.599.2.2 2019/11/27 14:34:31 martin Exp $ */
+/* $NetBSD: param.h,v 1.599.2.3 2019/12/08 13:23:23 martin Exp $ */
/*-
* Copyright (c) 1982, 1986, 1989, 1993
@@ -253,9 +253,22 @@
* any desired pointer type.
*
* ALIGNED_POINTER is a boolean macro that checks whether an address
- * is valid to fetch data elements of type t from on this architecture.
- * This does not reflect the optimal alignment, just the possibility
- * (within reasonable limits).
+ * is valid to fetch data elements of type t from on this architecture
+ * using ALIGNED_POINTER_LOAD. This does not reflect the optimal
+ * alignment, just the possibility (within reasonable limits).
+ *
+ * uint32_t x;
+ * unsigned char *p = ...;
+ *
+ * if (ALIGNED_POINTER(p, uint32_t)) {
+ * uint32_t t;
+ * ALIGNED_POINTER_LOAD(&t, p, uint32_t);
+ * x = t;
+ * } else {
+ * uint32_t t;
+ * memcpy(&t, p, sizeof(t));
+ * x = t;
+ * }
*
*/
#define ALIGNBYTES __ALIGNBYTES
@@ -265,6 +278,9 @@
#ifndef ALIGNED_POINTER
#define ALIGNED_POINTER(p,t) ((((uintptr_t)(p)) & (sizeof(t) - 1)) == 0)
#endif
+#ifndef ALIGNED_POINTER_LOAD
+#define ALIGNED_POINTER_LOAD(q,p,t) (*(q) = *((const t *)(p)))
+#endif
/*
* Historic priority levels. These are meaningless and remain only