Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

replace custom CPU feature detection #7

Merged
merged 1 commit into from
May 1, 2018
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
33 changes: 16 additions & 17 deletions highwayhashAVX2_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,14 @@

package highwayhash

import "golang.org/x/sys/cpu"

var (
useSSE4 = supportsSSE4()
useAVX2 = supportsAVX2()
useSSE4 = cpu.X86.HasSSE41
useAVX2 = cpu.X86.HasAVX2
useNEON = false
)

//go:noescape
func supportsSSE4() bool

//go:noescape
func supportsAVX2() bool

//go:noescape
func initializeSSE4(state *[16]uint64, key []byte)

Expand All @@ -38,31 +34,34 @@ func finalizeSSE4(out []byte, state *[16]uint64)
func finalizeAVX2(out []byte, state *[16]uint64)

func initialize(state *[16]uint64, key []byte) {
if useAVX2 {
switch {
case useAVX2:
initializeAVX2(state, key)
} else if useSSE4 {
case useSSE4:
initializeSSE4(state, key)
} else {
default:
initializeGeneric(state, key)
}
}

func update(state *[16]uint64, msg []byte) {
if useAVX2 {
switch {
case useAVX2:
updateAVX2(state, msg)
} else if useSSE4 {
case useSSE4:
updateSSE4(state, msg)
} else {
default:
updateGeneric(state, msg)
}
}

func finalize(out []byte, state *[16]uint64) {
if useAVX2 {
switch {
case useAVX2:
finalizeAVX2(out, state)
} else if useSSE4 {
case useSSE4:
finalizeSSE4(out, state)
} else {
default:
finalizeGeneric(out, state)
}
}
5 changes: 0 additions & 5 deletions highwayhashAVX2_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,3 @@ hash64:
MOVQ DX, 0(BX)
RET

// func supportsAVX2() bool
TEXT ·supportsAVX2(SB), 4, $0-1
MOVQ runtime·support_avx2(SB), AX
MOVB AX, ret+0(FP)
RET
7 changes: 3 additions & 4 deletions highwayhash_amd64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@

package highwayhash

import "golang.org/x/sys/cpu"

var (
useSSE4 = supportsSSE4()
useSSE4 = cpu.X86.HasSSE41
useAVX2 = false
useNEON = false
)

//go:noescape
func supportsSSE4() bool

//go:noescape
func initializeSSE4(state *[16]uint64, key []byte)

Expand Down
9 changes: 0 additions & 9 deletions highwayhash_amd64.s
Original file line number Diff line number Diff line change
Expand Up @@ -292,12 +292,3 @@ hash64:
MOVQ m10, DX
MOVQ DX, 0(BX)
RET

// func supportsSSE4() bool
TEXT ·supportsSSE4(SB), 4, $0-1
MOVL $1, AX
CPUID
SHRL $19, CX // Bit 19 indicates SSE4 support
ANDL $1, CX // CX != 0 if support SSE4
MOVB CX, ret+0(FP)
RET