bytealg

package
v1.2.13 Latest Latest
Warning

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

Go to latest
Published: Oct 24, 2026 License: Apache-2.0 Imports: 1 Imported by: 0

README

Byte kernels for protocol parsers

Mask, IndexByte and ValidHeaderValue provide bounded fast paths for the repository's WebSocket and XML implementations. They allocate nothing.

Build Backend
Go, GOEXPERIMENT=simd, arm64 simd/archsimd, NEON
Go, GOEXPERIMENT=simd, amd64 with AVX2 simd/archsimd, runtime CPU check
TinyGo with cgo, darwin/linux/windows arm64 Clang vectors, NEON
TinyGo with cgo, darwin/linux/windows amd64 Clang vectors, baseline SSE2
Other builds Scalar masking/validation and standard-library byte search

Standard Go always uses bytes.IndexByte, retaining its existing architecture optimizations. TinyGo uses the bounded C vector search on inputs of at least 64 bytes. Masking and header validation also select vectors at 64 bytes.

Mask consumes a multiple-of-16 prefix with a repeating little-endian 32-bit key. Callers keep their existing scalar tail and key-position handling. Both WebSocket forks use this kernel. ValidHeaderValue preserves HTAB, visible ASCII and obs-text, rejecting other controls and DEL. It has no caller since the fasthttp fork moved to v1.76.0, whose scanner validates each value in the same pass that finds the end of its line. XML uses IndexByte without changing refill offsets or token boundaries.

All loads and stores stay inside the slice's length, including unaligned inputs. C uses fixed-size memcpy operations for unaligned vector access and requires no intrinsic headers or external library. The optional bytealg_c tag selects this backend under host Go for validation with Clang.

go test ./internal/bytealg
GOEXPERIMENT=simd go test ./internal/bytealg
CC=clang go test -tags bytealg_c ./internal/bytealg
tinygo test ./internal/bytealg
clang -O2 -g -fsanitize=address,undefined \
  internal/bytealg/testdata/vector_bounds.c -o /tmp/bytealg-bounds
/tmp/bytealg-bounds

See measurements for workloads and measured gains.

Documentation

Overview

Package bytealg provides bounded byte kernels shared by protocol parsers.

Index

Constants

View Source
const Available = false

Variables

This section is empty.

Functions

func IndexByte

func IndexByte(b []byte, c byte) int

IndexByte uses Go's architecture-optimized standard implementation.

func Mask

func Mask(b []byte, key uint32) int

Mask XORs a whole-vector prefix with the four little-endian bytes of key. It returns the number of bytes processed; the caller handles the tail.

func ValidHeaderValue

func ValidHeaderValue(b []byte) bool

ValidHeaderValue accepts HTAB, visible ASCII and obs-text, excluding DEL.

Types

This section is empty.

Jump to

Keyboard shortcuts

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