public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] [LIBPHOBOS] Fix ualigned access in murmurhash.d (PR d/89177)
@ 2019-02-12 12:08 Bernd Edlinger
  0 siblings, 0 replies; only message in thread
From: Bernd Edlinger @ 2019-02-12 12:08 UTC (permalink / raw)
  To: gcc-patches, Iain Buclaw

[-- Attachment #1: Type: text/plain, Size: 361 bytes --]

Hi,

in the function MurmurHash3::put an unaligned access fault happens on an arm system.
The linux kernel is able to emulate the unaligned LDM instruction, but it is still not
desirable, to generate code that depends on that.


Fixed by the attached patch.

Bootstrapped and reg-tested on arm-linux-gnueabihf
Is it OK for trunk?


Thanks
Bernd.

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #2: patch-libphobos-unaligned.diff --]
[-- Type: text/x-patch; name="patch-libphobos-unaligned.diff", Size: 1119 bytes --]

2019-02-08  Bernd Edlinger  <bernd.edlinger@hotmail.de>

	PR d/89177
	* src/std/digest/murmurhash.d (MurmurHash3::put): Avoid unaligned
	access traps.

Index: libphobos/src/std/digest/murmurhash.d
===================================================================
--- libphobos/src/std/digest/murmurhash.d	(revision 268614)
+++ libphobos/src/std/digest/murmurhash.d	(working copy)
@@ -516,9 +516,11 @@ struct MurmurHash3(uint size /* 32 or 128 */ , uin
         // Do main work: process chunks of `Element.sizeof` bytes.
         const numElements = data.length / Element.sizeof;
         const remainderStart = numElements * Element.sizeof;
-        foreach (ref const Element block; cast(const(Element[]))(data[0 .. remainderStart]))
+        for (auto start = 0; start < remainderStart; start += Element.sizeof)
         {
-            putElement(block);
+            BufferUnion buffer;
+            buffer.data[0 .. $] = data[start .. start + Element.sizeof];
+            putElement(buffer.block);
         }
         // +1 for bufferLeeway Element.
         element_count += (numElements + 1) * Element.sizeof;

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2019-02-12 12:08 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-02-12 12:08 [PATCH] [LIBPHOBOS] Fix ualigned access in murmurhash.d (PR d/89177) Bernd Edlinger

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).