forked from dcreager/libcork
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add 0013 patch, and release as 0.15.0+ds-9~exp1
Fix unaligned access issue found on sparc64 arch. Thanks to James Clarke <jrtc27@jrtc27.com>.
- Loading branch information
Showing
3 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
90 changes: 90 additions & 0 deletions
90
debian/patches/0013-fix-unaligned-access-issue-found-on-sparc64-arch.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
From: James Clarke <jrtc27@jrtc27.com> | ||
Date: Mon, 29 Aug 2016 14:23:10 +0100 | ||
Subject: fix unaligned access issue found on sparc64 arch | ||
|
||
--- | ||
include/libcork/core/hash.h | 36 ++++++++++++++++++++++++++++-------- | ||
1 file changed, 28 insertions(+), 8 deletions(-) | ||
|
||
diff --git a/include/libcork/core/hash.h b/include/libcork/core/hash.h | ||
index 824eb82..09a46ca 100644 | ||
--- a/include/libcork/core/hash.h | ||
+++ b/include/libcork/core/hash.h | ||
@@ -17,6 +17,8 @@ | ||
#include <libcork/core/types.h> | ||
#include <libcork/core/u128.h> | ||
|
||
+/* Needed for memcpy */ | ||
+#include <string.h> | ||
|
||
#ifndef CORK_HASH_ATTRIBUTES | ||
#define CORK_HASH_ATTRIBUTES CORK_ATTR_UNUSED static inline | ||
@@ -44,6 +46,24 @@ typedef struct { | ||
|
||
CORK_ATTR_UNUSED | ||
static inline | ||
+uint32_t cork_getblock32(const uint32_t *p, int i) | ||
+{ | ||
+ uint32_t u; | ||
+ memcpy(&u, p + i, sizeof(u)); | ||
+ return u; | ||
+} | ||
+ | ||
+CORK_ATTR_UNUSED | ||
+static inline | ||
+uint64_t cork_getblock64(const uint64_t *p, int i) | ||
+{ | ||
+ uint64_t u; | ||
+ memcpy(&u, p + i, sizeof(u)); | ||
+ return u; | ||
+} | ||
+ | ||
+CORK_ATTR_UNUSED | ||
+static inline | ||
uint32_t cork_fmix32(uint32_t h) | ||
{ | ||
h ^= h >> 16; | ||
@@ -87,7 +107,7 @@ cork_stable_hash_buffer(cork_hash seed, const void *src, size_t len) | ||
|
||
/* body */ | ||
for (curr = blocks; curr != end; curr++) { | ||
- uint32_t k1 = CORK_UINT32_HOST_TO_LITTLE(*curr); | ||
+ uint32_t k1 = CORK_UINT32_HOST_TO_LITTLE(cork_getblock32((const uint32_t *) curr, 0)); | ||
|
||
k1 *= c1; | ||
k1 = CORK_ROTL32(k1,15); | ||
@@ -129,7 +149,7 @@ do { \ | ||
\ | ||
/* body */ \ | ||
for (curr = blocks; curr != end; curr++) { \ | ||
- uint32_t k1 = *curr; \ | ||
+ uint32_t k1 = cork_getblock32((const uint32_t *) curr, 0); \ | ||
\ | ||
k1 *= c1; \ | ||
k1 = CORK_ROTL32(k1,15); \ | ||
@@ -181,10 +201,10 @@ do { \ | ||
\ | ||
/* body */ \ | ||
for (curr = blocks; curr != end; curr += 4) { \ | ||
- uint32_t k1 = curr[0]; \ | ||
- uint32_t k2 = curr[1]; \ | ||
- uint32_t k3 = curr[2]; \ | ||
- uint32_t k4 = curr[3]; \ | ||
+ uint32_t k1 = cork_getblock32((const uint32_t *) curr, 0); \ | ||
+ uint32_t k2 = cork_getblock32((const uint32_t *) curr, 1); \ | ||
+ uint32_t k3 = cork_getblock32((const uint32_t *) curr, 2); \ | ||
+ uint32_t k4 = cork_getblock32((const uint32_t *) curr, 3); \ | ||
\ | ||
k1 *= c1; k1 = CORK_ROTL32(k1,15); k1 *= c2; h1 ^= k1; \ | ||
h1 = CORK_ROTL32(h1,19); h1 += h2; h1 = h1*5+0x561ccd1b; \ | ||
@@ -264,8 +284,8 @@ do { \ | ||
\ | ||
/* body */ \ | ||
for (curr = blocks; curr != end; curr += 2) { \ | ||
- uint64_t k1 = curr[0]; \ | ||
- uint64_t k2 = curr[1]; \ | ||
+ uint64_t k1 = cork_getblock64((const uint64_t *) curr, 0); \ | ||
+ uint64_t k2 = cork_getblock64((const uint64_t *) curr, 1); \ | ||
\ | ||
k1 *= c1; k1 = CORK_ROTL64(k1,31); k1 *= c2; h1 ^= k1; \ | ||
h1 = CORK_ROTL64(h1,27); h1 += h2; h1 = h1*5+0x52dce729; \ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters