From owner-freebsd-current@FreeBSD.ORG Wed Feb 7 10:42:33 2007 Return-Path: X-Original-To: current@freebsd.org Delivered-To: freebsd-current@FreeBSD.ORG Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id 2DD9916A419 for ; Wed, 7 Feb 2007 10:42:33 +0000 (UTC) (envelope-from stb@lassitu.de) Received: from koef.zs64.net (koef.zs64.net [212.12.50.230]) by mx1.freebsd.org (Postfix) with ESMTP id 88ACB13C494 for ; Wed, 7 Feb 2007 10:42:32 +0000 (UTC) (envelope-from stb@lassitu.de) Received: from koef.zs64.net (koef.zs64.net [212.12.50.230]) by koef.zs64.net (8.13.8/8.13.8) with ESMTP id l17APnjk084245; Wed, 7 Feb 2007 11:25:49 +0100 (CET) (envelope-from stb@lassitu.de) X-Squirrel-UserHash: WRhS X-Squirrel-FromHash: SV0BLFJbGwk= Message-ID: <15241.SV0BLFJbGwk=.1170843949.squirrel@koef.zs64.net> In-Reply-To: <20070207004131.A62183@xorpc.icir.org> References: <20070207004131.A62183@xorpc.icir.org> Date: Wed, 7 Feb 2007 11:25:49 +0100 (CET) From: "Stefan Bethke" To: "Luigi Rizzo" User-Agent: SquirrelMail/1.4.9a MIME-Version: 1.0 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: 8bit X-Priority: 3 (Normal) Importance: Normal Cc: current@freebsd.org Subject: Re: C macro to find the next power of 2 ? X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Feb 2007 10:42:33 -0000 On Wed, February 7, 2007 09:41, Luigi Rizzo wrote: > My problem is that some hardware wants data structures aligned to > the next power of 2 with respect to their size, and the code > in question (the ehci driver in case you care) has hardwired > constants for this, and possibly wrong ones. > > It would be nice if one could write > > struct foo_desc { > ... > }; > > #define FOO_ALIGN next_power_of_2(sizeof(struct foo_desc)) > > instead of having to count fields and make guesses on the size > of pointers and so on. _Hacker's Delight_ contains many cool tricks, including multiple solutions for this, IIRC. I'll have a look tonight when I'm back home. Cheers, Stefan -- Stefan Bethke +49 170 3460140