Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 22 additions & 4 deletions sei-db/state_db/sc/flatkv/lthash/backend_simd_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import (

//go:generate go run gen_blake3_xof16.go

// vzeroupper clears the upper halves of the vector registers.
//
//go:noescape
func vzeroupper()

// simdBackendName is the name reported by ActiveBackend for the AVX-512 path.
const simdBackendName = "simd"

Expand All @@ -22,11 +27,24 @@ func simdBackend() (backend, bool) {
if !archsimd.X86.AVX512() || !archsimd.X86.AVX512VBMI2() {
return backend{}, false
}
// The compiler emits no VZEROUPPER after AVX-512 code, and legacy-SSE code
// in the caller (memmove, SHA-NI) runs several times slower while the upper
// halves are dirty, so every kernel is wrapped here rather than trusting
// each one to clear them.
return backend{
name: simdBackendName,
expand: expandSIMD,
add: addSIMD,
sub: subSIMD,
name: simdBackendName,
expand: func(data []byte, dst *LtHash) {
expandSIMD(data, dst)
vzeroupper()
},
add: func(dst, src *LtHash) {
addSIMD(dst, src)
vzeroupper()
},
sub: func(dst, src *LtHash) {
subSIMD(dst, src)
vzeroupper()
},
}, true
}

Expand Down
8 changes: 8 additions & 0 deletions sei-db/state_db/sc/flatkv/lthash/zeroupper_amd64.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
//go:build goexperiment.simd && amd64

#include "textflag.h"

// func vzeroupper()
TEXT ·vzeroupper(SB), NOSPLIT, $0-0
VZEROUPPER
RET
Loading