Skip to content

Commit

Permalink
Somewhat faster xor_buf
Browse files Browse the repository at this point in the history
Avoids the cast alignment problems of yesteryear
  • Loading branch information
randombit committed Oct 13, 2017
1 parent 388cb52 commit a085c32
Showing 1 changed file with 15 additions and 18 deletions.
33 changes: 15 additions & 18 deletions src/lib/utils/mem_ops.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,28 +166,25 @@ inline void xor_buf(uint8_t out[],
{
while(length >= 16)
{
out[0] ^= in[0];
out[1] ^= in[1];
out[2] ^= in[2];
out[3] ^= in[3];
out[4] ^= in[4];
out[5] ^= in[5];
out[6] ^= in[6];
out[7] ^= in[7];
out[8] ^= in[8];
out[9] ^= in[9];
out[10] ^= in[10];
out[11] ^= in[11];
out[12] ^= in[12];
out[13] ^= in[13];
out[14] ^= in[14];
out[15] ^= in[15];
uint64_t x0, x1, y0, y1;
memcpy(&x0, in, 8);
memcpy(&x1, in + 8, 8);
memcpy(&y0, out, 8);
memcpy(&y1, out + 8, 8);

y0 ^= x0;
y1 ^= x1;
memcpy(out, &y0, 8);
memcpy(out + 8, &y1, 8);
out += 16; in += 16; length -= 16;
}

for(size_t i = 0; i != length; ++i)
while(length > 0)
{
out[i] ^= in[i];
out[0] ^= in[0];
out += 1;
in += 1;
length -= 1;
}
}

Expand Down

0 comments on commit a085c32

Please sign in to comment.