fast scrambler for 1Gbit Ethernet
An answer to this question on Stack Overflow.
Question
I have to add scrambler for skb->data(socket buffer). When I try to scramble each byte in skb->data, the speed decreases 10 times.
for (i = 0; i < skb->len; i++){
skb->data[i] = skb->data[i]^lfsr[i];
}
How can I scramble skb->data faster? Update: How can i scramble more than one byte in one iteration?
Answer
You can remove the pointer dereferencing, use in-place memory manipulation, and use OpenMP to parallelize the loop, like so:
//Compile with -fopenmp flag
const int len = skb->len;
auto &data = skb->data;
#pragma omp parallel for simd
for(int i=0;i<len;i++)
data[i] ^= lfsr[i];