Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 22 Aug 1999 09:14:26 -0400 (EDT)
From:      Peter Dufault <dufault@hda.com>
To:        hibma@skylink.it
Cc:        hackers@FreeBSD.ORG
Subject:   Re: from number to power of two
Message-ID:  <199908221314.JAA18225@hda.hda.com>
In-Reply-To: <Pine.BSF.4.10.9908220956450.7595-100000@heidi.plazza.it> from Nick Hibma at "Aug 22, 99 10:00:35 am"

next in thread | previous in thread | raw e-mail | index | archive | help
> It seems that all the solutions are too generic and slow. As I only have
> to check the numbers 0-32 (actually 1-32), a block of if statements is
> almost as fast as a table look up in 33 elements.

I doubt it - use the table for a small fixed size set then
use Warner's "(n) ? (1 << (ffs(n) - 1)) : 0".
The possible inline ffs is in machine/cpufunc.h

ffs() is fundamental to scheduling queues and cryptography and
should have attention paid to it.  As Warner said, it could be
a single instruction on some architectures.

Peter

-- 
Peter Dufault (dufault@hda.com)   Realtime development, Machine control,
HD Associates, Inc.               Safety critical systems, Agency approval


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




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