blamka_amd64.go (1366B)
1 // Copyright 2017 The Go Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build amd64 && gc && !purego 6 // +build amd64,gc,!purego 7 8 package argon2 9 10 import "golang.org/x/sys/cpu" 11 12 func init() { 13 useSSE4 = cpu.X86.HasSSE41 14 } 15 16 //go:noescape 17 func mixBlocksSSE2(out, a, b, c *block) 18 19 //go:noescape 20 func xorBlocksSSE2(out, a, b, c *block) 21 22 //go:noescape 23 func blamkaSSE4(b *block) 24 25 func processBlockSSE(out, in1, in2 *block, xor bool) { 26 var t block 27 mixBlocksSSE2(&t, in1, in2, &t) 28 if useSSE4 { 29 blamkaSSE4(&t) 30 } else { 31 for i := 0; i < blockLength; i += 16 { 32 blamkaGeneric( 33 &t[i+0], &t[i+1], &t[i+2], &t[i+3], 34 &t[i+4], &t[i+5], &t[i+6], &t[i+7], 35 &t[i+8], &t[i+9], &t[i+10], &t[i+11], 36 &t[i+12], &t[i+13], &t[i+14], &t[i+15], 37 ) 38 } 39 for i := 0; i < blockLength/8; i += 2 { 40 blamkaGeneric( 41 &t[i], &t[i+1], &t[16+i], &t[16+i+1], 42 &t[32+i], &t[32+i+1], &t[48+i], &t[48+i+1], 43 &t[64+i], &t[64+i+1], &t[80+i], &t[80+i+1], 44 &t[96+i], &t[96+i+1], &t[112+i], &t[112+i+1], 45 ) 46 } 47 } 48 if xor { 49 xorBlocksSSE2(out, in1, in2, &t) 50 } else { 51 mixBlocksSSE2(out, in1, in2, &t) 52 } 53 } 54 55 func processBlock(out, in1, in2 *block) { 56 processBlockSSE(out, in1, in2, false) 57 } 58 59 func processBlockXOR(out, in1, in2 *block) { 60 processBlockSSE(out, in1, in2, true) 61 }