[Pkg-privacy-commits] [golang-siphash-dev] 16/23: Inline calls to binary.LittleEndian.
Ximin Luo
infinity0 at moszumanska.debian.org
Sat Aug 22 12:55:53 UTC 2015
This is an automated email from the git hooks/post-receive script.
infinity0 pushed a commit to branch master
in repository golang-siphash-dev.
commit cbf42844566479571470a9a52236c333a0e8038b
Author: Dmitry Chestnykh <dmitry at codingrobots.com>
Date: Thu Jun 21 16:49:06 2012 +0200
Inline calls to binary.LittleEndian.
On Core 2 Duo MacBook:
benchmark old ns/op new ns/op delta
BenchmarkFull8 256 240 -6.25%
BenchmarkFull16 279 258 -7.53%
BenchmarkFull40 278 263 -5.40%
BenchmarkFull64 440 421 -4.32%
BenchmarkFull128 439 426 -2.96%
BenchmarkFull1K 3485 3071 -11.88%
BenchmarkFull8K 25866 22968 -11.20%
benchmark old MB/s new MB/s speedup
BenchmarkFull8 31.14 33.26 1.07x
BenchmarkFull16 57.19 61.90 1.08x
BenchmarkFull40 86.32 91.12 1.06x
BenchmarkFull64 145.39 151.88 1.04x
BenchmarkFull128 291.35 300.01 1.03x
BenchmarkFull1K 293.77 333.41 1.13x
BenchmarkFull8K 316.70 356.65 1.13x
---
siphash.go | 24 ++++++++++++++----------
1 file changed, 14 insertions(+), 10 deletions(-)
diff --git a/siphash.go b/siphash.go
index 60a2ec4..a0c3390 100644
--- a/siphash.go
+++ b/siphash.go
@@ -9,10 +9,7 @@
// created by Jean-Philippe Aumasson and Daniel J. Bernstein.
package siphash
-import (
- "encoding/binary"
- "hash"
-)
+import "hash"
const (
// The block size of hash algorithm in bytes.
@@ -38,8 +35,13 @@ type digest struct {
// New returns a new hash.Hash64 computing SipHash-2-4 with 16-byte key.
func New(key []byte) hash.Hash64 {
d := new(digest)
- d.k0 = binary.LittleEndian.Uint64(key[0:8])
- d.k1 = binary.LittleEndian.Uint64(key[8:16])
+
+ d.k0 = uint64(key[0]) | uint64(key[1])<<8 | uint64(key[2])<<16 | uint64(key[3])<<24 |
+ uint64(key[4])<<32 | uint64(key[5])<<40 | uint64(key[6])<<48 | uint64(key[7])<<56
+
+ d.k1 = uint64(key[8]) | uint64(key[9])<<8 | uint64(key[10])<<16 | uint64(key[11])<<24 |
+ uint64(key[12])<<32 | uint64(key[13])<<40 | uint64(key[14])<<48 | uint64(key[15])<<56
+
d.Reset()
return d
}
@@ -61,7 +63,8 @@ func block(d *digest, p []uint8) {
v0, v1, v2, v3 := d.v0, d.v1, d.v2, d.v3
for len(p) >= BlockSize {
- m := binary.LittleEndian.Uint64(p)
+ m := uint64(p[0]) | uint64(p[1])<<8 | uint64(p[2])<<16 | uint64(p[3])<<24 |
+ uint64(p[4])<<32 | uint64(p[5])<<40 | uint64(p[6])<<48 | uint64(p[7])<<56
v3 ^= m
for i := 0; i < cRounds; i++ {
@@ -151,7 +154,8 @@ func (d0 *digest) Sum64() uint64 {
}
func (d *digest) Sum(in []byte) []byte {
- var tmp [8]byte
- binary.LittleEndian.PutUint64(tmp[:], d.Sum64())
- return append(in, tmp[:]...)
+ v := d.Sum64()
+ in = append(in, byte(v), byte(v>>8), byte(v>>16), byte(v>>24),
+ byte(v>>32), byte(v>>40), byte(v>>48), byte(v>>56))
+ return in
}
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-privacy/packages/golang-siphash-dev.git
More information about the Pkg-privacy-commits
mailing list