-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
61 lines (48 loc) · 1.05 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package main
import (
"fmt"
"github.com/klauspost/cpuid/v2"
"github.com/Crash129/go-simd-example/avo"
"github.com/Crash129/go-simd-example/cgo"
"github.com/Crash129/go-simd-example/gocc"
"github.com/Crash129/go-simd-example/gosimd"
)
func main() {
a := make([]float32, 32)
b := make([]float32, 32)
out := make([]float32, 32)
for i := range a {
a[i] = float32(i + 1)
b[i] = float32(100)
}
fmt.Printf("a:\t%+v\n", a)
fmt.Printf("b:\t%+v\n", b)
fmt.Println()
clear(out)
plainGo(a, b, out)
fmt.Printf("plain:\t%+v\n", out)
if cpuid.CPU.Has(cpuid.ASIMD) {
clear(out)
cgo.Add(a, b, out)
fmt.Printf("cgo:\t%+v\n", out)
clear(out)
gosimd.Add(a, b, out)
fmt.Printf("gosimd:\t%+v\n", out)
}
if cpuid.CPU.Has(cpuid.AVX2) {
clear(out)
cgo.Add(a, b, out)
fmt.Printf("cgo:\t%+v\n", out)
clear(out)
gocc.Add(a, b, out)
fmt.Printf("gocc:\t%+v\n", out)
clear(out)
avo.Add(a, b, out)
fmt.Printf("avo:\t%+v\n", out)
}
}
func plainGo(a []float32, b []float32, out []float32) {
for i := range a {
out[i] = a[i] + b[i]
}
}