shithub: mc

Download patch

ref: 7ef923fc9dfde99b672009f84340f5f398b96a80
parent: ce24eebafcac443fd6572eff80e06b7303f37e36
author: Lucas Gabriel Vuotto <lvuotto92@gmail.com>
date: Sat Sep 9 06:42:01 EDT 2017

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>

--- a/lib/std/hashfuncs.myr
+++ b/lib/std/hashfuncs.myr
@@ -144,23 +144,21 @@
 	-> 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)
--- a/lib/std/test/hashfuncs.myr
+++ b/lib/std/test/hashfuncs.myr
@@ -108,10 +108,6 @@
 		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)
 	;;
 }