1
0
mirror of https://github.com/fumiama/blake2b-simd.git synced 2026-06-08 20:10:33 +08:00

Detect SSE automatically and enable corresponding optimized code path.

With this change, following happens.

```
if sse {
   compressSSE()
   return
}
compressGeneric()
```

compressGeneric is used as a fallback when SSE is not detected.
This commit is contained in:
Harshavardhana
2016-06-25 00:25:28 -07:00
committed by Harshavardhana
parent 83ff4cf5f4
commit 3a46db1cb4
10 changed files with 1553 additions and 1456 deletions

View File

@@ -21,6 +21,8 @@ import (
"testing"
)
// TestSum - tests and validates golden set of values again
// pre-defined set of inputs and matches blake2b output.
func TestSum(t *testing.T) {
buf := make([]byte, len(golden))
for i := range buf {
@@ -76,44 +78,6 @@ func TestKeyedSum(t *testing.T) {
}
}
var bench = New512()
var buf = make([]byte, 8<<10)
func BenchmarkWrite1K(b *testing.B) {
b.SetBytes(1024)
for i := 0; i < b.N; i++ {
bench.Write(buf[:1024])
}
}
func BenchmarkWrite8K(b *testing.B) {
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
bench.Write(buf)
}
}
func BenchmarkHash64(b *testing.B) {
b.SetBytes(64)
for i := 0; i < b.N; i++ {
Sum512(buf[:64])
}
}
func BenchmarkHash128(b *testing.B) {
b.SetBytes(128)
for i := 0; i < b.N; i++ {
Sum512(buf[:128])
}
}
func BenchmarkHash1K(b *testing.B) {
b.SetBytes(1024)
for i := 0; i < b.N; i++ {
Sum512(buf[:1024])
}
}
// Test vectors taken from reference implementation in C#.
var golden = []string{
"786a02f742015903c6c6fd852552d272912f4740e15847618a86e217f71f5419d25e1031afee585313896444934eb04b903a685b1448b755d56f701afe9be2ce",
@@ -632,3 +596,55 @@ var goldenKeyed = []string{
"d444bfa2362a96df213d070e33fa841f51334e4e76866b8139e8af3bb3398be2dfaddcbc56b9146de9f68118dc5829e74b0c28d7711907b121f9161cb92b69a9",
"142709d62e28fcccd0af97fad0f8465b971e82201dc51070faa0372aa43e92484be1c1e73ba10906d5d1853db6a4106e0a7bf9800d373d6dee2d46d62ef2a461",
}
// Benchmark blake2b implementation.
var bench = New512()
var buf = make([]byte, 128*1024)
// Benchmark writes of 64 bytes.
func BenchmarkHash64(b *testing.B) {
b.SetBytes(64)
for i := 0; i < b.N; i++ {
Sum512(buf[:64])
}
}
// Benchmark writes of 128 bytes.
func BenchmarkHash128(b *testing.B) {
b.SetBytes(128)
for i := 0; i < b.N; i++ {
Sum512(buf[:128])
}
}
// Benchmark writes of 1KiB bytes.
func BenchmarkWrite1K(b *testing.B) {
b.SetBytes(1024)
for i := 0; i < b.N; i++ {
bench.Write(buf[:1024])
}
}
// Benchmark writes of 8KiB bytes.
func BenchmarkWrite8K(b *testing.B) {
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
bench.Write(buf[:8192])
}
}
// Benchmark writes of 32KiB bytes.
func BenchmarkWrite32K(b *testing.B) {
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
bench.Write(buf[:32*1024])
}
}
// Benchmark writes of 128KiB bytes.
func BenchmarkWrite128K(b *testing.B) {
b.SetBytes(int64(len(buf)))
for i := 0; i < b.N; i++ {
bench.Write(buf)
}
}