SIMD (Single Instruction Multiple Data) extension for golang. Provide AVX (Advanced Vector Extensions) binding for amd64 and NEON binding for arm64.
Forked from https://github.com/monochromegane/go-avx
Set CGO_CFLAGS_ALLOW=-mfma
to build binary for amd64.
package main
import (
"fmt"
"github.com/gumigumi4f/go-vx"
)
func main() {
dim := 8
x := vx.AlignedAlloc(dim)
y := vx.AlignedAlloc(dim)
z := vx.AlignedAlloc(dim)
defer vx.Free(x)
defer vx.Free(y)
defer vx.Free(z)
for i := 0; i < dim; i++ {
x[i] = float32(i)
y[i] = float32(i + 1)
}
vx.Add(dim, x, y, z)
fmt.Printf("%v\n", z) // [1 3 5 7 9 11 13 15]
}
- Add
- Sub
- Mul
- Div
- Dot
See also vx_test.go
.
Run go test -bench Benchmark ./... -run="^Benchmark"
goos: linux
goarch: amd64
pkg: github.com/gumigumi4f/go-vx
BenchmarkDotVx-2 364 3201061 ns/op
BenchmarkDotNative-2 100 10833781 ns/op
PASS
ok github.com/gumigumi4f/go-vx 3.953s
goos: linux
goarch: arm64
pkg: github.com/gumigumi4f/go-vx
BenchmarkDotVx 274 4275091 ns/op
BenchmarkDotNative 100 10599838 ns/op
PASS
ok github.com/gumigumi4f/go-vx 4.154s