From owner-freebsd-hackers Sun Aug 22 6:16:16 1999 Delivered-To: freebsd-hackers@freebsd.org Received: from hda.hda.com (hda-bicnet.bicnet.net [209.244.238.132]) by hub.freebsd.org (Postfix) with ESMTP id 5547A14D01 for ; Sun, 22 Aug 1999 06:15:59 -0700 (PDT) (envelope-from dufault@hda.hda.com) Received: (from dufault@localhost) by hda.hda.com (8.8.5/8.8.5) id JAA18225; Sun, 22 Aug 1999 09:14:27 -0400 (EDT) From: Peter Dufault Message-Id: <199908221314.JAA18225@hda.hda.com> Subject: Re: from number to power of two In-Reply-To: from Nick Hibma at "Aug 22, 99 10:00:35 am" To: hibma@skylink.it Date: Sun, 22 Aug 1999 09:14:26 -0400 (EDT) Cc: hackers@FreeBSD.ORG X-Mailer: ELM [version 2.4ME+ PL25 (25)] MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: owner-freebsd-hackers@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.ORG > 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