Thread (34 messages) flat view 34 messages, 6 authors, 2014-01-09

Re: [PATCH net-next V2 3/3] net: Add GRO support for vxlan traffic

From: Tom Herbert <hidden>
Date: 2014-01-07 21:09:51

On Tue, Jan 7, 2014 at 12:12 PM, Or Gerlitz [off-list ref] wrote:
On Tue, Jan 7, 2014 at 10:02 PM, Eric Dumazet [off-list ref] wrote:
quoted
On Tue, 2014-01-07 at 21:43 +0200, Or Gerlitz wrote:
quoted
On Tue, Jan 7, 2014 at 8:08 PM, Tom Herbert [off-list ref] wrote:
quoted
quoted
Why ^ instead of != ?
The XOR approach is very popular in the GRO stack, e.g see the IPv4 chain
of inet_gro_receive() && tcp_gro_receive(), I guess this might relates
to more efficient assembly code for ^ vs. != and/or the fast/elegant
transitive nature of that operator
This trick is only needed/used when many compares are folded into a
single conditional :

if (a->f1 != b->f1 || a->f2 != b->f2)

->

if (((a->f1 ^ b->f1) | (a->f2 ^ b->f2)) != 0)

Please do not use XOR for a single compare.
OK, but just out of curiosity -- what's the reasoning? clarity or
efficiency or both?
Both. Compiling a simple program and comparing alternatives: gcc
produced the identical code for the single conditional (^ vs !=)
using the cmp instruction. Testing the two conditional case like Eric
provided; the second method (using ^) resulted in 4 more instructions,
but only one branch as opposed to two in the first method (!=). Method
#1 has the advantage of short circuiting when the first condition is
true, so organizing the conditionals to maximize the probability of
short circuit could be beneficial.

quoted
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help