Date: Mon, 8 Aug 2016 05:23:33 +1000 From: Peter Jeremy <peter@rulingia.com> To: Hans Petter Selasky <hps@selasky.org> Cc: Adrian Chadd <adrian@FreeBSD.org>, src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: Re: svn commit: r303811 - in head/sys: net net80211 Message-ID: <20160807192333.GA79784@server.rulingia.com> In-Reply-To: <46183559-343f-401b-6471-3822e3383a50@selasky.org> References: <201608070348.u773mXXt030939@repo.freebsd.org> <46183559-343f-401b-6471-3822e3383a50@selasky.org>
next in thread | previous in thread | raw e-mail | index | archive | help
--a8Wt8u1KmwUX3Y2C Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On 2016-Aug-07 11:03:23 +0200, Hans Petter Selasky <hps@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]) =3D=3D 0xff) >> >The compiler might be able to produce more optimal code if you use "+"=20 >instead of "&", because there are instructions on x86, that can add=20 >multiple variables at the same time. With "&" you need to process every=20 >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]) =3D=3D (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) =3D=3D 0x00ffffffl) --=20 Peter Jeremy --a8Wt8u1KmwUX3Y2C Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQJ8BAEBCgBmBQJXp4q1XxSAAAAAAC4AKGlzc3Vlci1mcHJAbm90YXRpb25zLm9w ZW5wZ3AuZmlmdGhob3JzZW1hbi5uZXRFRUIyOTg2QzMwNjcxRTc0RTY1QzIyN0Ux NkE1OTdBMEU0QTIwQjM0AAoJEBall6Dkogs0a4YP/jMIA7H+af/LRfWjZDnxNyRq Kk0nMu+H4yfXmmYrw42UW4MqM2YkNpjw9cJ/x1fb9Vm1hKK9y7Z3Yx23QlX/Ffd5 g7YQrlTDBgtbmtzMknyJ4yWO6Z5fESMj3Kndxcwg1fUBppow/Zzri2j0mkWSKlHb b8jXecifM1QqxBfVz3ePhHJ5I7GtNmYn3mDO29TqLsjRTto5jp9jGnKDOQkyBcV0 kc6wICXZ8PcIuteHmxQcoNXEktYzhoTxJWd/pS01pMZK6ZcvIzZQKEayCmVVML0Y jLzrLcTzLYK/+z54e4XW77uPNPNj1CuEUOvTO4hUeMM/HJ3GwbZxG8hZnO4hMBdx hhQzTqIeNv3irlI5lJKrU6Ezf7N3Q5Zpf+X33D6uiEJ631380SID/e23ExzO5C8G uTirWxZrEAAyN+puyAJDz4Bzoo87U4VwsdbHBPlD4k6rSwz/PSdjVDBQZjoK0uKI cN+Fnw3YZImrgj/UDMtDlXpmgBvjpxzp9ycejZ+ejhg9cnv1bC57jNcgAua2aH5a 6gmYcWfkiUJ1Fx8KHxMy4yMqgX+UPmVLtR0i9h3F/Qk3wEsrhOqc7bolsw/gAIAT w3N4IJw+go8Kdao+Yxt6GO+hBBcOixxuS2Q1hlC5IwfISxUUwv0sPFWBUJJu6w84 iv/5Y3ILXpBievwymsIB =7NB+ -----END PGP SIGNATURE----- --a8Wt8u1KmwUX3Y2C--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20160807192333.GA79784>