Source file src/internal/runtime/maps/memhash_aes_simd.go

     1  // Copyright 2026 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 && goexperiment.simd
     6  
     7  package maps
     8  
     9  import (
    10  	"simd/archsimd"
    11  	"unsafe"
    12  )
    13  
    14  const memHashUsesVAES = true
    15  
    16  func memHash32AES(p unsafe.Pointer, seed uintptr) uintptr {
    17  	var state archsimd.Uint64x2
    18  	state = state.SetElem(0, uint64(seed)).SetElem(1, uint64(*(*uint32)(p)))
    19  
    20  	hash := state.
    21  		AsUint8x16().
    22  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[0])))).
    23  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[16])))).
    24  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[32])))).
    25  		AsUint64x2().
    26  		GetElem(0)
    27  	return uintptr(hash)
    28  }
    29  
    30  func memHash64AES(p unsafe.Pointer, seed uintptr) uintptr {
    31  	var state archsimd.Uint64x2
    32  	state = state.SetElem(0, uint64(seed)).SetElem(1, *(*uint64)(p))
    33  
    34  	hash := state.
    35  		AsUint8x16().
    36  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[0])))).
    37  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[16])))).
    38  		AESEncryptOneRound(archsimd.LoadUint32x4((*[4]uint32)(unsafe.Pointer(&aeskeysched[32])))).
    39  		AsUint64x2().
    40  		GetElem(0)
    41  	return uintptr(hash)
    42  }
    43  
    44  // TODO: Both strHashAES and memHashAES use aeshashbody that is quite large.
    45  // So there is no point in rewriting them using simd intrinsics, since they won't be inlinable.
    46  // Maybe in future we can do it for better maitanability.
    47  //
    48  //go:noescape
    49  func memHashAES(p unsafe.Pointer, h, s uintptr) uintptr
    50  
    51  //go:noescape
    52  func strHashAES(p unsafe.Pointer, h uintptr) uintptr
    53  

View as plain text