...

Source file src/pkg/crypto/sha1/sha1block_amd64.go

     1	// Copyright 2016 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	package sha1
     6	
     7	import "internal/cpu"
     8	
     9	//go:noescape
    10	func blockAVX2(dig *digest, p []byte)
    11	
    12	//go:noescape
    13	func blockAMD64(dig *digest, p []byte)
    14	
    15	var useAVX2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI1 && cpu.X86.HasBMI2
    16	
    17	func block(dig *digest, p []byte) {
    18		if useAVX2 && len(p) >= 256 {
    19			// blockAVX2 calculates sha1 for 2 block per iteration
    20			// it also interleaves precalculation for next block.
    21			// So it may read up-to 192 bytes past end of p
    22			// We may add checks inside blockAVX2, but this will
    23			// just turn it into a copy of blockAMD64,
    24			// so call it directly, instead.
    25			safeLen := len(p) - 128
    26			if safeLen%128 != 0 {
    27				safeLen -= 64
    28			}
    29			blockAVX2(dig, p[:safeLen])
    30			blockAMD64(dig, p[safeLen:])
    31		} else {
    32			blockAMD64(dig, p)
    33		}
    34	}
    35	

View as plain text