Detect CPU features in Sum()

This commit is contained in:
Evgenii Stratonikov 2019-10-04 17:57:53 +03:00
parent 083d0ff054
commit 38df9b2c63

View file

@ -70,9 +70,19 @@ func New() hash.Hash {
// Sum returns Tillich-Zémor checksum of data. // Sum returns Tillich-Zémor checksum of data.
func Sum(data []byte) [hashSize]byte { func Sum(data []byte) [hashSize]byte {
d := newAVX2Inline() if hasAVX2 {
_, _ = d.Write(data) // no errors d := newAVX2Inline()
return d.checkSum() _, _ = 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. // Concat performs combining of hashes based on homomorphic property.