github.com/metacubex/sing-tun@v0.2.7-0.20240512075008-89e7c6208eec/internal/clashtcpip/tcpip_amd64.go (about)

     1  //go:build !noasm
     2  
     3  package clashtcpip
     4  
     5  import (
     6  	"unsafe"
     7  
     8  	"golang.org/x/sys/cpu"
     9  )
    10  
    11  //go:noescape
    12  func sumAsmAvx2(data unsafe.Pointer, length uintptr) uintptr
    13  
    14  func SumAVX2(data []byte) uint32 {
    15  	if len(data) == 0 {
    16  		return 0
    17  	}
    18  
    19  	return uint32(sumAsmAvx2(unsafe.Pointer(&data[0]), uintptr(len(data))))
    20  }
    21  
    22  func init() {
    23  	if cpu.X86.HasAVX2 {
    24  		SumFnc = SumAVX2
    25  	}
    26  }