by Stan Drapkin
SIMD-accelerated XOR operations on byte spans for up to 32x speedup.
- Uses
System.Numerics.Tensors.TensorPrimitives.Xorfor high-performance platform-optimized vectorizedXOR. - Target:
.NET 10+. - Speedup: Performance depends on runtime and CPU SIMD support.
- Safety: Methods are static, stateless, and safe for concurrent use.
- All spans must have equal length (
ArgumentOutOfRangeExceptionis thrown otherwise).
dotnet add package FastXor
///Xor's left byte span into dest byte span.
public static void Xor(Span<byte> dest, ReadOnlySpan<byte> left)
///Xor's left and right byte spans into dest byte span.
public static void Xor(Span<byte> dest, ReadOnlySpan<byte> left, ReadOnlySpan<byte> right)// using SecurityDriven;
// In-place XOR: dest ^= left (lengths must match)
Span<byte> dest = stackalloc byte[64];
ReadOnlySpan<byte> left = new byte[64];
FastXor.Xor(dest, left);
// Two-source XOR: dest = left ^ right (all lengths must match)
ReadOnlySpan<byte> right = new byte[64];
FastXor.Xor(dest, left, right);