svn commit: r303811 - in head/sys: net net80211

Peter Jeremy peter at rulingia.com
Sun Aug 7 19:31:06 UTC 2016


On 2016-Aug-07 11:03:23 +0200, Hans Petter Selasky <hps at selasky.org> wrote:
>On 08/07/16 05:48, Adrian Chadd wrote:
>> +#define	ETHER_IS_BROADCAST(addr) \
>> +	(((addr)[0] & (addr)[1] & (addr)[2] & \
>> +	  (addr)[3] & (addr)[4] & (addr)[5]) == 0xff)
>>
>The compiler might be able to produce more optimal code if you use "+" 
>instead of "&", because there are instructions on x86, that can add 
>multiple variables at the same time. With "&" you need to process every 
>one as a single instructions usually I think.
>
> > +#define	ETHER_IS_BROADCAST(addr) \
> > +	(((addr)[0] + (addr)[1] + (addr)[2] + \
> > +	  (addr)[3] + (addr)[4] + (addr)[5]) == (6*0xff))

IMHO, Adrian's code is clearer and micro-optimisations like this belong
in the complier, not the code.  There are lots of alternative ways you
could write the macro and, unless you can demonstrate that the micro-
optimisation is worthwhile, you should pick the one that is clearer to
the software maintainer.

If you want to make a few more assumptions (64-bit unaligned little-endian
architecture with at least 2 accessible bytes beyond the address), the
following has the added advantage of only referencing (addr) once.  (I'm
not suggesting it as a replacement though).

#define	ETHER_IS_BROADCAST(addr) \
	((*(const long *)(addr) & 0x00ffffffl) == 0x00ffffffl)

-- 
Peter Jeremy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 949 bytes
Desc: not available
URL: <http://lists.freebsd.org/pipermail/svn-src-all/attachments/20160808/eecb7252/attachment.sig>


More information about the svn-src-all mailing list