Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 20 Sep 2012 11:58:54 +0200
From:      =?utf-8?Q?Dag-Erling_Sm=C3=B8rgrav?= <des@des.no>
To:        Pawel Jakub Dawidek <pjd@FreeBSD.org>
Cc:        freebsd-security@freebsd.org, Jonathan Anderson <jonathan.anderson@cl.cam.ac.uk>
Subject:   Re: Collecting entropy from device_attach() times.
Message-ID:  <86boh1t3q9.fsf@ds4.des.no>
In-Reply-To: <20120919192923.GA1416@garage.freebsd.pl> (Pawel Jakub Dawidek's message of "Wed, 19 Sep 2012 21:29:24 %2B0200")
References:  <20120918211422.GA1400@garage.freebsd.pl> <A8FD98DD94774D00B4E5F78D3174C1B4@gmail.com> <20120919192923.GA1416@garage.freebsd.pl>

next in thread | previous in thread | raw e-mail | index | archive | help
Pawel Jakub Dawidek <pjd@FreeBSD.org> writes:
> http://people.freebsd.org/~pjd/patches/harvest_device_attach.2.patch

You can replace highbit(x) - 9 with flsll(x) - 10.  Unfortunately, we
don't have flsll() in the kernel, but here's a simple implementation:

/*
 * Find last bit set in an unsigned long long.  Assumes that ULL is
 * always 64 bits wide while UL may be either 32 or 64 bits wide.
 */
static __inline unsigned int
flsll(unsigned long long mask)
{
#ifdef __LP64__
        return (flsl(mask));
#else
        return (mask >> 32 ? 32 + flsl(mask >> 32) : flsl(mask));
#endif
}

On i386 and amd64, flsl() is an inline function that expands to a single
assembler instruction.  On all other platforms, it is a function in
libkern, which is stupid - gcc and clang have builtin functions for it
which are almost certainly faster than a function call.

Same goes for s/last bit/first bit/; s/fls/ffs/g.

DES
--=20
Dag-Erling Sm=C3=B8rgrav - des@des.no



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