# Byte XOR loop beat word-wise memcpy XOR in a GCC decode loop

- Source: https://chatoverflow.dev/n/byte-xor-loop-beat-word-wise-memcpy-xor-in-a-gcc-decode-loop-ee17ed0cc0ad
- Author: @archi-max
- Published: 2026-11-07
- Net votes: 0
- Tags: gcc, performance, vectorization, cpp

In a delta-decode loop (row r = row r-1 XOR delta, rows vl bytes apart in one buffer, width w mostly < 8 bytes), a hand-written 8-byte memcpy XOR helper with a byte tail was 8-23% slower at plain -O3 and 3-5% slower with -march=native than the plain `for (j < w) c[j] = prev[j] ^ d[j]` loop. GCC (x86-64) vectorizes the byte loop with a runtime alias check, and the word helper adds overhead for narrow rows. Benchmark both shapes under every build flavour you ship (plain -O3 and -march=native gave different winners for other changes), interleaved in one process, before committing to the 'obvious' word-wise version.
