Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/netbsd-9]: src Pull up following revision(s) (requested by riastradh in ...
details: https://anonhg.NetBSD.org/src/rev/6d8dbac3628d
branches: netbsd-9
changeset: 465975:6d8dbac3628d
user: martin <martin%NetBSD.org@localhost>
date: Sun Dec 08 13:23:23 2019 +0000
description:
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)
diffstat:
common/lib/libc/hash/murmurhash/murmurhash.c | 15 +++++++++++----
sys/arch/amd64/include/param.h | 5 +++--
sys/arch/i386/include/param.h | 5 +++--
sys/sys/param.h | 24 ++++++++++++++++++++----
4 files changed, 37 insertions(+), 12 deletions(-)
diffs (126 lines):
diff -r 9a6448b992ff -r 6d8dbac3628d common/lib/libc/hash/murmurhash/murmurhash.c
--- a/common/lib/libc/hash/murmurhash/murmurhash.c Sun Dec 08 13:16:53 2019 +0000
+++ b/common/lib/libc/hash/murmurhash/murmurhash.c Sun Dec 08 13:23:23 2019 +0000
@@ -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 @@
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;
diff -r 9a6448b992ff -r 6d8dbac3628d sys/arch/amd64/include/param.h
--- a/sys/arch/amd64/include/param.h Sun Dec 08 13:16:53 2019 +0000
+++ b/sys/arch/amd64/include/param.h Sun Dec 08 13:23:23 2019 +0000
@@ -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
diff -r 9a6448b992ff -r 6d8dbac3628d sys/arch/i386/include/param.h
--- a/sys/arch/i386/include/param.h Sun Dec 08 13:16:53 2019 +0000
+++ b/sys/arch/i386/include/param.h Sun Dec 08 13:23:23 2019 +0000
@@ -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 */
diff -r 9a6448b992ff -r 6d8dbac3628d sys/sys/param.h
--- a/sys/sys/param.h Sun Dec 08 13:16:53 2019 +0000
+++ b/sys/sys/param.h Sun Dec 08 13:23:23 2019 +0000
@@ -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
Home |
Main Index |
Thread Index |
Old Index