Debian Codegraph @

/

debian golang-github-templexxx-xorsimd 0.4.4-1debian golang-github-templexxx-xorsimd-dev gomod github.com/templexxx/xorsimd debiangogoinimakefilemarkdownshellyaml 17 files · 234 symbols
View dependency graph

Depends on

README (full)

xorsimd

GoDoc MIT licensed Build Status Go Report Card Sourcegraph

xorsimd provides high-throughput XOR operations for byte slices. On amd64 it selects AVX-512/AVX2/SSE2 implementations, and falls back to portable Go code on other architectures.

Install

go get github.com/templexxx/xorsimd

Quick Start

package main

import "github.com/templexxx/xorsimd"

func main() {
	a := []byte{1, 2, 3, 4}
	b := []byte{9, 8, 7, 6}
	dst := make([]byte, 4)

	// dst = a ^ b
	n := xorsimd.Bytes(dst, a, b)
	_ = n

	// dst = src[0] ^ src[1] ^ src[2] ...
	src := [][]byte{a, b, []byte{1, 1, 1, 1}}
	n = xorsimd.Encode(dst, src)
	_ = n
}

API Notes

  • Encode(dst, src) XORs all rows in src into dst and returns the number of bytes processed.
  • Encode requires len(src) >= 1.
  • Bytes(dst, a, b) is a convenience wrapper around Encode.
  • Bytes8, Bytes16, Bytes8Align, and Bytes16Align are fixed-size helpers.
  • BytesA processes len(a) bytes; BytesB processes len(b) bytes.

All APIs may reuse overlapping slices. For correctness, callers must ensure the input slices are long enough for the selected function variant.

Performance

Performance mainly depends on:

  • CPU SIMD instruction support.
  • Number of input source rows.
  • Slice size.

Benchmark formula:

I/O = (src_num + 1) * vector_size / cost

Test environment:

  • AWS c5d.xlarge
  • Intel Xeon Platinum 8124M @ 3.00GHz
  • Single physical core
Src NumVector SizeAVX512 I/O (MB/s)AVX2 I/O (MB/s)SSE2 I/O (MB/s)
54KB270403.73142825.2574443.91
51MB26948.3426887.3726950.65
58MB17881.3217212.5616402.97
104KB190445.30102953.5953244.04
101MB26424.4426618.6526094.39
108MB15471.3114866.7213565.80

Run Tests and Benchmarks

go test ./...
go test -bench=. -benchmem
dir .github/
dir debian/
file .gitattributes
file .gitignore
file LICENSE
file README.md
file go.mod
file go.sum
file xor.go
file xor_amd64.go
file xor_generic.go
file xor_test.go
file xoravx2_amd64.s
file xoravx512_amd64.s
file xorbytes_amd64.s
file xorsse2_amd64.s