From b557a84123a0bc9dec4dc3178301fd9a67a6c709 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 23 Jun 2023 15:31:54 -0600 Subject: [PATCH] [algs] Speed up fasthash for aligned uint64_t --- src/hb-algs.hh | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/src/hb-algs.hh b/src/hb-algs.hh index 86414866f..c8a3a216d 100644 --- a/src/hb-algs.hh +++ b/src/hb-algs.hh @@ -297,10 +297,28 @@ static inline uint64_t fasthash64(const void *buf, size_t len, uint64_t seed) uint64_t h = seed ^ (len * m); uint64_t v; - while (pos != end) { - v = pos++->v; - h ^= mix(v); - h *= m; +#ifndef HB_OPTIMIZE_SIZE + if (((uintptr_t) pos & 7) == 0) + { + while (pos != end) + { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wcast-align" + v = * (const uint64_t *) (pos++); +#pragma GCC diagnostic pop + h ^= mix(v); + h *= m; + } + } + else +#endif + { + while (pos != end) + { + v = pos++->v; + h ^= mix(v); + h *= m; + } } pos2 = (const unsigned char*)pos;