svn commit: r223884 - head/sys/sys

Kostik Belousov kostikbel at gmail.com
Sat Jul 9 17:04:42 UTC 2011


On Sat, Jul 09, 2011 at 05:36:28PM +0200, Ed Schouten wrote:
> Hi Kostik,
> 
> * Konstantin Belousov <kib at FreeBSD.org>, 20110709 16:29:
> > +static __inline uint16_t
> > +bitcount16(uint32_t x)
> 
> 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.

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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 196 bytes
Desc: not available
Url : http://lists.freebsd.org/pipermail/svn-src-all/attachments/20110709/844f314d/attachment.pgp


More information about the svn-src-all mailing list