From 38df9b2c63bf4a41d78f601187d0d8556202e972 Mon Sep 17 00:00:00 2001 From: Evgenii Stratonikov Date: Fri, 4 Oct 2019 17:57:53 +0300 Subject: [PATCH] Detect CPU features in Sum() --- tz/hash.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/tz/hash.go b/tz/hash.go index 1ec8612..b617d40 100644 --- a/tz/hash.go +++ b/tz/hash.go @@ -70,9 +70,19 @@ func New() hash.Hash { // Sum returns Tillich-ZĂ©mor checksum of data. func Sum(data []byte) [hashSize]byte { - d := newAVX2Inline() - _, _ = d.Write(data) // no errors - return d.checkSum() + if hasAVX2 { + d := newAVX2Inline() + _, _ = d.Write(data) // no errors + return d.checkSum() + } else if hasAVX { + d := newAVX() + _, _ = d.Write(data) // no errors + return d.checkSum() + } else { + d := newPure() + _, _ = d.Write(data) // no errors + return d.checkSum() + } } // Concat performs combining of hashes based on homomorphic property.