summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLucas Gabriel Vuotto <lvuotto92@gmail.com>2017-09-09 10:42:01 -0300
committerOri Bernstein <ori@eigenstate.org>2017-09-09 12:17:12 -0700
commit7ef923fc9dfde99b672009f84340f5f398b96a80 (patch)
tree0479e6df115c66a2a368af3d4673b2ac4f37469c
parentce24eebafcac443fd6572eff80e06b7303f37e36 (diff)
downloadmc-7ef923fc9dfde99b672009f84340f5f398b96a80.tar.gz
Improve siphash performance and tests
* Inline rotl * Be specific about which entry failed from the test vector Signed-off-by: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
-rw-r--r--lib/std/hashfuncs.myr14
-rw-r--r--lib/std/test/hashfuncs.myr6
2 files changed, 7 insertions, 13 deletions
diff --git a/lib/std/hashfuncs.myr b/lib/std/hashfuncs.myr
index 023f63a..eca00c9 100644
--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -144,23 +144,21 @@ const murmurhash2 = {data, seed
-> h
}
-const rotl = {x, n -> uint64; -> (x << n) | (x >> (64 - n))}
-
const sipround = {v0, v1, v2, v3 -> (uint64, uint64, uint64, uint64)
v0 += v1
- v1 = rotl(v1, 13)
+ v1 = (v1 << 13) | (v1 >> 51)
v1 ^= v0
- v0 = rotl(v0, 32)
+ v0 = (v0 << 32) | (v0 >> 32)
v2 += v3
- v3 = rotl(v3, 16)
+ v3 = (v3 << 16) | (v3 >> 48)
v3 ^= v2
v2 += v1
- v1 = rotl(v1, 17)
+ v1 = (v1 << 17) | (v1 >> 47)
v1 ^= v2
- v2 = rotl(v2, 32)
+ v2 = (v2 << 32) | (v2 >> 32)
v0 += v3
- v3 = rotl(v3, 21)
+ v3 = (v3 << 21) | (v3 >> 43)
v3 ^= v0
-> (v0, v1, v2, v3)
diff --git a/lib/std/test/hashfuncs.myr b/lib/std/test/hashfuncs.myr
index 94313b0..f1684f9 100644
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -108,10 +108,6 @@ const siphashreferencetestvector = {ctx
msg[i] = i
h = std.siphash24(msg[:i], key)
e = std.getle64(siphashtestvector[i][:])
- if e != h
- testr.fail(ctx, "wrong siphash value\n")
- else
- testr.ok(ctx)
- ;;
+ testr.check(ctx, e == h, "wrong siphash value for entry {}: got {x}\n", i, h)
;;
}