Skip to content
This repository has been archived by the owner on Apr 26, 2018. It is now read-only.

Commit

Permalink
internal: use arrays instead of make for simple values. (#22)
Browse files Browse the repository at this point in the history
Fixes #16
  • Loading branch information
harshavardhana authored and fwessels committed Jul 22, 2016
1 parent 326c321 commit c50cace
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 22 deletions.
6 changes: 3 additions & 3 deletions benchmarks_test.go
Expand Up @@ -27,11 +27,11 @@ import (

func benchmarkHash(b *testing.B, hash func() hash.Hash) {
b.SetBytes(1024 * 1024)
data := make([]byte, 1024)
var data [1024]byte
for i := 0; i < b.N; i++ {
h := hash()
for j := 0; j < 1024; j++ {
h.Write(data)
h.Write(data[:])
}
h.Sum(nil)
}
Expand Down Expand Up @@ -59,7 +59,7 @@ func BenchmarkComparisonBlake2B(b *testing.B) {

// Benchmark blake2b implementation.
var bench = New512()
var buf = make([]byte, 128*1024)
var buf [128 * 1024]byte

func benchmarkSize(b *testing.B, size int) {
b.SetBytes(int64(size))
Expand Down
11 changes: 6 additions & 5 deletions compressAvx2_amd64.go
Expand Up @@ -23,11 +23,12 @@ package blake2b
func compressAVX2Loop(p []uint8, in, iv, t, f, shffle, out []uint64)

func compressAVX2(d *digest, p []uint8) {
var (
in [8]uint64
out [8]uint64
shffle [8]uint64
)

in := make([]uint64, 8, 8)
out := make([]uint64, 8, 8)

shffle := make([]uint64, 8, 8)
// vector for PSHUFB instruction
shffle[0] = 0x0201000706050403
shffle[1] = 0x0a09080f0e0d0c0b
Expand All @@ -40,7 +41,7 @@ func compressAVX2(d *digest, p []uint8) {

in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]

compressAVX2Loop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
compressAVX2Loop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])

d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
}
11 changes: 6 additions & 5 deletions compressAvx_amd64.go
Expand Up @@ -23,18 +23,19 @@ package blake2b
func blockAVXLoop(p []uint8, in, iv, t, f, shffle, out []uint64)

func compressAVX(d *digest, p []uint8) {
var (
in [8]uint64
out [8]uint64
shffle [2]uint64
)

in := make([]uint64, 8, 8)
out := make([]uint64, 8, 8)

shffle := make([]uint64, 2, 2)
// vector for PSHUFB instruction
shffle[0] = 0x0201000706050403
shffle[1] = 0x0a09080f0e0d0c0b

in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]

blockAVXLoop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
blockAVXLoop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])

d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
}
11 changes: 6 additions & 5 deletions compressSse_amd64.go
Expand Up @@ -23,18 +23,19 @@ package blake2b
func blockSSELoop(p []uint8, in, iv, t, f, shffle, out []uint64)

func compressSSE(d *digest, p []uint8) {
var (
in [8]uint64
out [8]uint64
shffle [2]uint64
)

in := make([]uint64, 8, 8)
out := make([]uint64, 8, 8)

shffle := make([]uint64, 2, 2)
// vector for PSHUFB instruction
shffle[0] = 0x0201000706050403
shffle[1] = 0x0a09080f0e0d0c0b

in[0], in[1], in[2], in[3], in[4], in[5], in[6], in[7] = d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7]

blockSSELoop(p, in, iv[:], d.t[:], d.f[:], shffle, out)
blockSSELoop(p, in[:], iv[:], d.t[:], d.f[:], shffle[:], out[:])

d.h[0], d.h[1], d.h[2], d.h[3], d.h[4], d.h[5], d.h[6], d.h[7] = out[0], out[1], out[2], out[3], out[4], out[5], out[6], out[7]
}
9 changes: 5 additions & 4 deletions compress_generic.go
Expand Up @@ -26,12 +26,13 @@ func compressGeneric(d *digest, p []uint8) {
v13 := iv[5] ^ d.t[1]
v14 := iv[6] ^ d.f[0]
v15 := iv[7] ^ d.f[1]
var m [16]uint64

j := 0
for i := 0; i < 16; i++ {
m[i] = uint64(p[j]) | uint64(p[j+1])<<8 | uint64(p[j+2])<<16 | uint64(p[j+3])<<24 |
uint64(p[j+4])<<32 | uint64(p[j+5])<<40 | uint64(p[j+6])<<48 | uint64(p[j+7])<<56
var m [16]uint64
for i := range m {
m[i] = uint64(p[j]) | uint64(p[j+1])<<8 | uint64(p[j+2])<<16 |
uint64(p[j+3])<<24 | uint64(p[j+4])<<32 | uint64(p[j+5])<<40 |
uint64(p[j+6])<<48 | uint64(p[j+7])<<56
j += 8
}

Expand Down

0 comments on commit c50cace

Please sign in to comment.