Skip to content

Commit

Permalink
replace custom CPU feature detection
Browse files Browse the repository at this point in the history
This change replaces the custom CPU feature detection code using
the new `x/sys/cpu` package.

Fixes #6
  • Loading branch information
Andreas Auernhammer committed Apr 30, 2018
1 parent 9c7e959 commit 342af21
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 35 deletions.
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

0 comments on commit 342af21

Please sign in to comment.