From: chas w. - C. <ch...@cm...> - 2011-10-19 13:54:15
|
On Tue, 18 Oct 2011 23:20:58 -0700 Philip Prindeville <phi...@re...> wrote: > On 8/15/11 8:39 AM, Pascal Hambourg wrote: > > chas williams - CONTRACTOR a écrit : > >> On Fri, 12 Aug 2011 22:01:10 +0200 > > > memcmp(skb->data + 8, pad, BR2684_PAD_LEN) == 0 > > or > > skb->data[8] == 0 && skb->data[9] == 0 > > or > > (skb->data[8] | skb->data[9]) == 0 > > > > Which one is fastest ? I'm afraid this is platform-dependent. > > Or is there a built-in function in the kernel which can do this > > efficiently ? > > Sorry about getting to the party late, but... just to double-check what I thought I knew... > > Wouldn't the proper check be: > > __be16_to_cpup(&skb->data[8]) == 0 > > You might need a cast there to (__be16 *)... and yes, arguably, zero is the same in both LE and BE architectures, but it's worth being consistent if it stops you from overlooking it elsewhere (and losing portability). if you really want to go this route, you should cast the 0 to the correct endian -- this can be optimized at compile time. however, i think it is just safer to use memcmp() -- however, i dont know any platform that can't poorly aligned 16-bit words. |