Skip to content

Commit

Permalink
Add 0013 patch, and release as 0.15.0+ds-9~exp1
Browse files Browse the repository at this point in the history
Fix unaligned access issue found on sparc64 arch.
Thanks to James Clarke <jrtc27@jrtc27.com>.
  • Loading branch information
rogers0 committed Oct 21, 2016
1 parent 451eb16 commit 54357ad
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 0 deletions.
8 changes: 8 additions & 0 deletions debian/changelog
@@ -1,3 +1,11 @@
libcork (0.15.0+ds-9~exp1) experimental; urgency=medium

* debian/patches:
- Add 0013 patch to fix unaligned access issue found on sparc64 arch
Thanks to James Clarke <jrtc27@jrtc27.com>.

-- Roger Shimizu <rogershimizu@gmail.com> Fri, 21 Oct 2016 20:25:41 +0900

libcork (0.15.0+ds-8) unstable; urgency=medium

* debian/patches:
Expand Down
@@ -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; \
1 change: 1 addition & 0 deletions debian/patches/series
Expand Up @@ -10,3 +10,4 @@
0010-extend-test-timeout-of-bitset-case-to-60-seconds.patch
0011-make-version-in-soname-the-same-as-library-version.patch
0012-bump-libcork-version-to-16.0.2.patch
0013-fix-unaligned-access-issue-found-on-sparc64-arch.patch

0 comments on commit 54357ad

Please sign in to comment.