Skip to content

Commit aba25a0

Browse files
committed
Avoid BM2 in the AVX(1) implementation
I could've also generated all options for with/without BMI2/AVX2, but I simply went for having the fastest option require AVX2+BMI2 and use AVX(1) as the fallback.
1 parent d4e96fc commit aba25a0

8 files changed

+493
-601
lines changed

asm_amd64.s

Lines changed: 169 additions & 238 deletions
Large diffs are not rendered by default.

detect_avx2_always.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ func hasAVX() bool {
66
return true
77
}
88

9-
func hasAVX2() bool {
10-
return true
11-
}
12-
13-
func hasBMI2() bool {
9+
func hasAVX2AndBMI2() bool {
1410
return true
1511
}

detect_avx2_never.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ func hasAVX() bool {
66
return false
77
}
88

9-
func hasAVX2() bool {
10-
return false
11-
}
12-
13-
func hasBMI2() bool {
9+
func hasAVX2AndBMI2() bool {
1410
return false
1511
}

detect_avx2_runtime.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@ package vectorcmp
44

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

7+
var axv2AndBmi2 = cpu.X86.HasAVX2 && cpu.X86.HasBMI2
8+
79
func hasAVX() bool {
810
return cpu.X86.HasAVX
911
}
1012

11-
func hasAVX2() bool {
12-
return cpu.X86.HasAVX2
13-
}
14-
15-
func hasBMI2() bool {
16-
return cpu.X86.HasBMI2
13+
func hasAVX2AndBMI2() bool {
14+
return axv2AndBmi2
1715
}

detect_avx2_testing.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,6 @@ func hasAVX() bool {
66
return true
77
}
88

9-
func hasAVX2() bool {
9+
func hasAVX2AndBMI2() bool {
1010
return false
1111
}
12-
13-
func hasBMI2() bool {
14-
return true
15-
}

0 commit comments

Comments
 (0)