diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2018-07-17 06:25:19 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2018-07-17 06:25:19 -0700 |
commit | a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951 (patch) | |
tree | 4c526eff2fde246ab1b6c4373e0b44c417dd860c | |
parent | afba8c78ff2ee42dc9f8951ef3c4c89ba8a13076 (diff) | |
download | txr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.tar.gz txr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.tar.bz2 txr-a9ed9c463eeb2ec81ef4733f9be8dbfcb7cf7951.zip |
hash: replace hashing function for doubles.
* hash.c (hash_double): Rewrite silly byte rotation with
union aliased against ucnum array.
-rw-r--r-- | hash.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -181,14 +181,17 @@ static u32_t hash_buf(const mem_t *ptr, ucnum size, u32_t seed) static ucnum hash_double(double n) { + union hack { + volatile double d; + volatile ucnum a[sizeof (double) / sizeof (ucnum)]; + } u; ucnum h = 0; + int i; - mem_t *p = coerce(mem_t *, &n), *q = p + sizeof(double); + u.d = n; - while (p < q) { - h = h << 8 | h >> (8 * sizeof h - 1); - h += *p++; - } + for (i = 0; i < sizeof u.a / sizeof u.a[0]; i++) + h += u.a[i]; return h; } |