]> Cypherpunks repositories - gostls13.git/commitdiff
crypto/aes: use asm for BenchmarkExpand on amd64
authorMichael Munday <munday@ca.ibm.com>
Thu, 21 Apr 2016 12:00:07 +0000 (08:00 -0400)
committerMinux Ma <minux@golang.org>
Fri, 22 Apr 2016 18:58:29 +0000 (18:58 +0000)
This reverses the change to this benchmark made in 9b6bf20.

Change-Id: I79ab88286c3028d3be561957140375bbc413e7ab
Reviewed-on: https://go-review.googlesource.com/22340
Run-TryBot: Michael Munday <munday@ca.ibm.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Minux Ma <minux@golang.org>
src/crypto/aes/aes_test.go
src/crypto/aes/cipher_amd64.go
src/crypto/aes/cipher_generic.go
src/crypto/aes/cipher_s390x.go

index 3cc390d4e2a7f1e65f046cb1f35d2497c528898e..28144968fcfd258d889840782bff0c25b81b407f 100644 (file)
@@ -380,6 +380,6 @@ func BenchmarkExpand(b *testing.B) {
        c := &aesCipher{make([]uint32, n), make([]uint32, n)}
        b.ResetTimer()
        for i := 0; i < b.N; i++ {
-               expandKeyGo(tt.key, c.enc, c.dec)
+               expandKey(tt.key, c.enc, c.dec)
        }
 }
index 3b600c36f346e75baa69feaa3a19dca69119994a..b33c8ff251ac7cbdf89f3c927e41fe9288241064 100644 (file)
@@ -64,3 +64,20 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
        }
        decryptBlockAsm(len(c.dec)/4-1, &c.dec[0], &dst[0], &src[0])
 }
+
+// expandKey is used by BenchmarkExpand to ensure that the asm implementation
+// of key expansion is used for the benchmark when it is available.
+func expandKey(key []byte, enc, dec []uint32) {
+       if useAsm {
+               rounds := 10 // rounds needed for AES128
+               switch len(key) {
+               case 192 / 8:
+                       rounds = 12
+               case 256 / 8:
+                       rounds = 14
+               }
+               expandKeyAsm(rounds, &key[0], &enc[0], &dec[0])
+       } else {
+               expandKeyGo(key, enc, dec)
+       }
+}
index fc2c4c52cf0c97c5c081b6da1f7fc5618d988e91..f8070346e38c5d2885bc2f7ca17e6eb92111e9c6 100644 (file)
@@ -18,3 +18,9 @@ import (
 func newCipher(key []byte) (cipher.Block, error) {
        return newCipherGeneric(key)
 }
+
+// expandKey is used by BenchmarkExpand and should
+// call an assembly implementation if one is available.
+func expandKey(key []byte, enc, dec []uint32) {
+       expandKeyGo(key, enc, dec)
+}
index dfb95d7d5df3a18355874e02dc3667fee7f65313..bec59330132c52bf0f458ab83bf674afd2be7702 100644 (file)
@@ -82,3 +82,9 @@ func (c *aesCipherAsm) Decrypt(dst, src []byte) {
        // The decrypt function code is equal to the function code + 128.
        cryptBlocks(c.function+128, &c.key[0], &dst[0], &src[0], BlockSize)
 }
+
+// expandKey is used by BenchmarkExpand. cipher message (KM) does not need key
+// expansion so there is no assembly equivalent.
+func expandKey(key []byte, enc, dec []uint32) {
+       expandKeyGo(key, enc, dec)
+}