Help us shape the future of Go! Take the 2026 Go Developer Survey

simd

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Nov 15, 2024 License: MIT Imports: 8 Imported by: 3

README

SIMD (Single Instruction, Multiple Data)

Simd support via Go assembly for arithmetic and bitwise operations. Allowing for parallel element-wise computations. Resulting in 200 - 470% speedup. Currently supports 64-bit x86 and 64-bit ARM processors.

Function Documentation

Simd Support

64-bit x86 64-bit ARM
AddFloat32 SSE2 / AVX NEON
AddFloat64 SSE2 / AVX NEON
AddInt32 SSE2 / AVX2 NEON
AddInt64 SSE2 / AVX2 NEON
AndInt32 SSE2 / AVX2
AndInt64 SSE2 / AVX2
DivFloat32 SSE2 / AVX
DivFloat64 SSE2 / AVX
DivInt32
DivInt64
MulFloat32 SSE2 / AVX NEON
MulFloat64 SSE2 / AVX NEON
MulInt32 SSE4.1 / AVX2 NEON
MulInt64
OrInt32 SSE2 / AVX2
OrInt64 SSE2 / AVX2
SubFloat32 SSE2 / AVX NEON
SubFloat64 SSE2 / AVX NEON
SubInt32 SSE2 / AVX2 NEON
SubInt64 SSE2 / AVX2 NEON
XorInt32 SSE2 / AVX2
XorInt64 SSE2 / AVX2

AMD64 Simd Performance:

Large Vectors Medium Vectors Large Vectors

Documentation

Overview

Simd support for arithmetic 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 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.

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.

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.

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.

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