simd

package module
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 19, 2025 License: MIT Imports: 9 Imported by: 3

README

[_]       [_]            [_]         [_]
[_]       [_]            [_]         [_]
[S]ingle  [I]nstruction  [M]ultiple  [D]ata
[_]       [_]            [_]         [_]
[_]       [_]            [_]         [_]

SIMD support via Go assembly for arithmetic, bitwise, maximum, and minimum operations. Allowing for parallel element-wise computations. Resulting in a 100% to 400% speedup. Currently AMD64 (x86_64) and ARM64 processors are supported.

Function Documentation

SIMD Support

AMD64 (x86_64) ARM64
AddFloat32 SSE / AVX / AVX512VL NEON
AddFloat64 SSE2 / AVX / AVX512VL NEON
AddInt32 SSE2 / AVX2 / AVX512VL NEON
AddInt64 SSE2 / AVX2 / AVX512VL NEON
AndInt32 SSE2 / AVX2 / AVX512VL NEON
AndInt64 SSE2 / AVX2 / AVX512VL NEON
DivFloat32 SSE / AVX / AVX512VL
DivFloat64 SSE2 / AVX / AVX512VL
DivInt32
DivInt64
MaxFloat32 SSE / AVX / AVX512VL
MaxFloat64 SSE2 / AVX / AVX512VL
MaxInt32 SSE4.1 / AVX2 / AVX512VL
MaxInt64 AVX512VL
MinFloat32 SSE / AVX / AVX512VL
MinFloat64 SSE2 / AVX / AVX512VL
MinInt32 SSE4.1 / AVX2 / AVX512VL
MinInt64 AVX512VL
MulFloat32 SSE / AVX / AVX512VL NEON
MulFloat64 SSE2 / AVX / AVX512VL NEON
MulInt32 SSE4.1 / AVX2 / AVX512VL NEON
MulInt64 AVX512VL
OrInt32 SSE2 / AVX2 / AVX512VL NEON
OrInt64 SSE2 / AVX2 / AVX512VL NEON
SubFloat32 SSE / AVX / AVX512VL NEON
SubFloat64 SSE2 / AVX / AVX512VL NEON
SubInt32 SSE2 / AVX2 / AVX512VL NEON
SubInt64 SSE2 / AVX2 / AVX512VL NEON
XorInt32 SSE2 / AVX2 / AVX512VL
XorInt64 SSE2 / AVX2 / AVX512VL

Make Targets

Tests
Command Description
make test Compiles and runs tests natively on hardware.
make test_amd64 Cross compiles for amd64 and runs tests via QEMU (qemu-x86_64).
make test_arm64 Cross compiles for arm64 and runs tests via QEMU (qemu-aarch64).

AMD64 Performance (AMD Ryzen 7 7840U / DDR5 SO-DIMM)

Elements Go ns/op SIMD ns/op Performance x
Small Vectors
100 38.33 7.580 5.056
200 79.59 12.80 6.217
300 117.0 18.45 9.593
400 154.5 16.20 9.537
500 191.5 20.38 9.396
600 228.6 26.37 8.668
700 265.6 33.70 7.881
800 303.1 29.38 10.31
900 340.3 33.54 10.14
Medium Vectors
1000 377.4 39.60 9.530
2000 751.2 69.45 10.81
3000 1153 148.3 7.774
4000 1499 325.1 4.610
5000 1871 431.6 4.335
6000 2243 523.6 4.283
7000 2614 614.1 4.256
8000 2987 701.6 4.257
9000 3360 792.5 4.239
Large Vectors
10000 3725 878.5 4.240
20000 7458 1754 4.251
30000 11187 2631 4.251
40000 14908 3509 4.248
50000 18677 4373 4.270
60000 22363 5276 4.238
70000 26107 6319 4.131
80000 29854 7820 3.817
90000 33613 9222 3.644

ARM64 Performance (Apple M1 Pro / LPDDR5 SDRAM)

Elements Go ns/op SIMD ns/op Performance x
Small Vectors
100 51.81 13.68 3.787
200 102.2 24.24 4.216
300 152.8 35.93 4.252
400 209.0 47.71 4.380
500 258.7 64.88 3.987
600 309.8 73.42 4.219
700 359.6 89.01 4.039
800 410.6 101.9 4.029
900 460.3 112.5 4.091
Medium Vectors
1000 511.5 124.3 4.115
2000 1015 241.0 4.211
3000 1520 356.9 4.258
4000 2024 473.1 4.278
5000 2527 589.9 4.283
6000 3032 706.1 4.294
7000 3535 822.5 4.297
8000 4039 939.2 4.300
9000 4543 1056 4.302
Large Vectors
10000 5046 1172 4.305
20000 10107 2394 4.221
30000 15139 3599 4.206
40000 20178 4957 4.070
50000 25218 6190 4.073
60000 30253 7277 4.157
70000 35285 8707 4.052
80000 40346 9924 4.065
90000 45378 11189 4.055

Documentation

Overview

SIMD support via Go assembly for arithmetic and bitwise operations. Allowing for parallel element-wise computations.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func AddFloat32

func AddFloat32(left, right, result []float32) int

AddFloat32 performs element-wise addition on left and right, storing the sums in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := AddFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [4 16 6 14 0 0]

func AddFloat64

func AddFloat64(left, right, result []float64) int

AddFloat64 performs element-wise addition on left and right, storing the sums in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := AddFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [4 16 6 14 0 0]

func AddInt32

func AddInt32(left, right, result []int32) int

AddInt32 performs element-wise addition on left and right, storing the sums in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := AddInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [4 16 6 14 0 0]

func AddInt64

func AddInt64(left, right, result []int64) int

AddInt64 performs element-wise addition on left and right, storing the sums in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := AddInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [4 16 6 14 0 0]

func AndInt32

func AndInt32(left, right, result []int32) int

AndInt32 performs element-wise AND on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := AndInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [1 1 0 0 0 0]

func AndInt64

func AndInt64(left, right, result []int64) int

AndInt64 performs element-wise AND on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := AndInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [1 1 0 0 0 0]

func DivFloat32

func DivFloat32(left, right, result []float32) int

DivFloat32 performs element-wise division on left and right, storing the quotients in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := DivFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [0.33333334 1.2857143 0.5 1.3333334 0 0]

func DivFloat64

func DivFloat64(left, right, result []float64) int

DivFloat64 performs element-wise division on left and right, storing the quotients in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := DivFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [0.3333333333333333 1.2857142857142858 0.5 1.3333333333333333 0 0]

func DivInt32

func DivInt32(left, right, result []int32) int

DivInt32 performs element-wise division on left and right, storing the quotients in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := DivInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [0 1 0 1 0 0]

func DivInt64

func DivInt64(left, right, result []int64) int

DivInt64 performs element-wise division on left and right, storing the quotients in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := DivInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [0 1 0 1 0 0]

func MaxFloat32 added in v1.2.4

func MaxFloat32(left, right, result []float32) int

MaxFloat32 performs element-wise maximum on left and right, storing the maxes in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := MaxFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [3 9 4 8 0 0]

func MaxFloat64 added in v1.2.4

func MaxFloat64(left, right, result []float64) int

MaxFloat64 performs element-wise maximum on left and right, storing the maxes in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := MaxFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [3 9 4 8 0 0]

func MaxInt32 added in v1.2.4

func MaxInt32(left, right, result []int32) int

MaxInt32 performs element-wise maximum on left and right, storing the maxes in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := MaxInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [3 9 4 8 0 0]

func MaxInt64 added in v1.2.4

func MaxInt64(left, right, result []int64) int

MaxInt64 performs element-wise maximum on left and right, storing the maxes in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := MaxInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [3 9 4 8 0 0]

func MinFloat32 added in v1.2.4

func MinFloat32(left, right, result []float32) int

MinFloat32 performs element-wise minimum on left and right, storing the mins in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := MinFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [1 7 2 6 0 0]

func MinFloat64 added in v1.2.4

func MinFloat64(left, right, result []float64) int

MinFloat64 performs element-wise minimum on left and right, storing the mins in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := MinFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [1 7 2 6 0 0]

func MinInt32 added in v1.2.4

func MinInt32(left, right, result []int32) int

MinInt32 performs element-wise minimum on left and right, storing the mins in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := MinInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [1 7 2 6 0 0]

func MinInt64 added in v1.2.4

func MinInt64(left, right, result []int64) int

MinInt64 performs element-wise minimum on left and right, storing the mins in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := MinInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [1 7 2 6 0 0]

func MulFloat32

func MulFloat32(left, right, result []float32) int

MulFloat32 performs element-wise multiplication on left and right, storing the products in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := MulFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [3 63 8 48 0 0]

func MulFloat64

func MulFloat64(left, right, result []float64) int

MulFloat64 performs element-wise multiplication on left and right, storing the products in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := MulFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [3 63 8 48 0 0]

func MulInt32

func MulInt32(left, right, result []int32) int

MulInt32 performs element-wise multiplication on left and right, storing the products in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := MulInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [3 63 8 48 0 0]

func MulInt64

func MulInt64(left, right, result []int64) int

MulInt64 performs element-wise multiplication on left and right, storing the products in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := MulInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [3 63 8 48 0 0]

func OrInt32

func OrInt32(left, right, result []int32) int

OrInt32 performs element-wise OR on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := OrInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [3 15 6 14 0 0]

func OrInt64

func OrInt64(left, right, result []int64) int

OrInt64 performs element-wise OR on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := OrInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [3 15 6 14 0 0]

func SubFloat32

func SubFloat32(left, right, result []float32) int

SubFloat32 performs element-wise subtraction on left and right, storing the differences in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float32{1, 9, 2, 8}
right := []float32{3, 7, 4, 6, 5}
result := []float32{0, 0, 0, 0, 0, 0}
length := SubFloat32(left, right, result)
fmt.Print(length, result)
Output:
4 [-2 2 -2 2 0 0]

func SubFloat64

func SubFloat64(left, right, result []float64) int

SubFloat64 performs element-wise subtraction on left and right, storing the differences in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []float64{1, 9, 2, 8}
right := []float64{3, 7, 4, 6, 5}
result := []float64{0, 0, 0, 0, 0, 0}
length := SubFloat64(left, right, result)
fmt.Print(length, result)
Output:
4 [-2 2 -2 2 0 0]

func SubInt32

func SubInt32(left, right, result []int32) int

SubInt32 performs element-wise subtraction on left and right, storing the differences in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := SubInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [-2 2 -2 2 0 0]

func SubInt64

func SubInt64(left, right, result []int64) int

SubInt64 performs element-wise subtraction on left and right, storing the differences in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := SubInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [-2 2 -2 2 0 0]

func XorInt32

func XorInt32(left, right, result []int32) int

XorInt32 performs element-wise XOR on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int32{1, 9, 2, 8}
right := []int32{3, 7, 4, 6, 5}
result := []int32{0, 0, 0, 0, 0, 0}
length := XorInt32(left, right, result)
fmt.Print(length, result)
Output:
4 [2 14 6 14 0 0]

func XorInt64

func XorInt64(left, right, result []int64) int

XorInt64 performs element-wise XOR on left and right, storing the results in result. The operation is performed up to the shortest length of left, right, and result. Returns the number of operations performed.

Example
left := []int64{1, 9, 2, 8}
right := []int64{3, 7, 4, 6, 5}
result := []int64{0, 0, 0, 0, 0, 0}
length := XorInt64(left, right, result)
fmt.Print(length, result)
Output:
4 [2 14 6 14 0 0]

Types

This section is empty.

Directories

Path Synopsis
internal
avx
sse

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL