Skip to content

Commit 4680779

Browse files
committed
Add avx
1 parent 3901ab7 commit 4680779

9 files changed

Lines changed: 544 additions & 215 deletions

File tree

internal/math32/floats.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
package math32
22

33
var (
4-
useAVX512 bool // nolint unused
5-
useNEON bool // nolint unused
4+
useAVX bool // nolint unused
5+
useNEON bool // nolint unused
66
)
77

88
// Dot two vectors.

internal/math32/floats_amd64.go

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,26 +3,46 @@
33
package math32
44

55
import (
6+
"unsafe"
7+
68
"golang.org/x/sys/cpu"
79
)
810

911
func init() {
10-
useAVX512 = cpu.X86.HasAVX512
12+
useAVX = cpu.X86.HasAVX
1113
}
1214

15+
//go:noescape
16+
func _dot_product_avx(a, b unsafe.Pointer, n uintptr, result unsafe.Pointer)
17+
18+
//go:noescape
19+
func _squared_l2_avx(a, b unsafe.Pointer, n uintptr, result unsafe.Pointer)
20+
1321
func dot(a, b []float32) float32 {
1422
switch {
15-
case useAVX512:
16-
return dotGeneric(a, b) // TODO
23+
case useAVX:
24+
var ret float32
25+
26+
if len(a) > 0 {
27+
_dot_product_avx(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), uintptr(len(a)), unsafe.Pointer(&ret))
28+
}
29+
30+
return ret
1731
default:
1832
return dotGeneric(a, b)
1933
}
2034
}
2135

2236
func squaredL2(a, b []float32) float32 {
2337
switch {
24-
case useAVX512:
25-
return squaredL2Generic(a, b) // TODO
38+
case useAVX:
39+
var ret float32
40+
41+
if len(a) > 0 {
42+
_squared_l2_avx(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), uintptr(len(a)), unsafe.Pointer(&ret))
43+
}
44+
45+
return ret
2646
default:
2747
return squaredL2Generic(a, b)
2848
}

internal/math32/floats_arm64.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ func init() {
1313
}
1414

1515
//go:noescape
16-
func _vdot_neon(a unsafe.Pointer, b unsafe.Pointer, n uintptr, ret unsafe.Pointer)
16+
func _dot_product_neon(a unsafe.Pointer, b unsafe.Pointer, n uintptr, ret unsafe.Pointer)
1717

1818
//go:noescape
1919
func _squared_l2_neon(a, b unsafe.Pointer, n uintptr, result unsafe.Pointer)
@@ -24,7 +24,7 @@ func dot(a, b []float32) float32 {
2424
var ret float32
2525

2626
if len(a) > 0 {
27-
_vdot_neon(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), uintptr(len(a)), unsafe.Pointer(&ret))
27+
_dot_product_neon(unsafe.Pointer(&a[0]), unsafe.Pointer(&b[0]), uintptr(len(a)), unsafe.Pointer(&ret))
2828
}
2929

3030
return ret

internal/math32/floats_arm64.s

Lines changed: 0 additions & 137 deletions
This file was deleted.

0 commit comments

Comments
 (0)