Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 9 Jul 2011 20:04:32 +0300
From:      Kostik Belousov <kostikbel@gmail.com>
To:        Ed Schouten <ed@80386.nl>
Cc:        svn-src-head@FreeBSD.org, svn-src-all@FreeBSD.org, src-committers@FreeBSD.org
Subject:   Re: svn commit: r223884 - head/sys/sys
Message-ID:  <20110709170432.GL48734@deviant.kiev.zoral.com.ua>
In-Reply-To: <20110709153628.GJ16219@hoeg.nl>
References:  <201107091429.p69ETNNu003910@svn.freebsd.org> <20110709153628.GJ16219@hoeg.nl>

next in thread | previous in thread | raw e-mail | index | archive | help

--eULE+JHRRz2mSqwH
Content-Type: text/plain; charset=us-ascii
Content-Disposition: inline
Content-Transfer-Encoding: quoted-printable

On Sat, Jul 09, 2011 at 05:36:28PM +0200, Ed Schouten wrote:
> Hi Kostik,
>=20
> * Konstantin Belousov <kib@FreeBSD.org>, 20110709 16:29:
> > +static __inline uint16_t
> > +bitcount16(uint32_t x)
>=20
> Shouldn't we use uint16_t for the argument here?
Not sure. uint32_t type of argument avoids repromotion, allowing to
do the full-register calculation on both 32 and 64 bit architectures.

The function correctly handles non-zero upper half-word on its own.

>=20
> When I saw the code, I thought by myself, this could be done more
> efficiently:
>=20
> | static __inline uint16_t
> | bitcount16(uint16_t x)
> | {
> |
> | 	x =3D (x & 0x5555) + ((x >> 1) & 0x5555);
> | 	x =3D (x & 0x3333) + ((x >> 2) & 0x3333);
> | 	x *=3D 0x1111;
> | 	return (x >> 12);
> | }
>=20
> But some testing revealed it works for all inputs, except 65536. d'oh!
>=20
> --=20
>  Ed Schouten <ed@80386.nl>
>  WWW: http://80386.nl/



--eULE+JHRRz2mSqwH
Content-Type: application/pgp-signature
Content-Disposition: inline

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (FreeBSD)

iEYEARECAAYFAk4YiiAACgkQC3+MBN1Mb4hBxQCgtf1CQybdUzbopmNuPw8ysusr
tEgAoK3a/E/FBBoO/16ZZyV2p6ew7w6v
=uHxi
-----END PGP SIGNATURE-----

--eULE+JHRRz2mSqwH--



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20110709170432.GL48734>