Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Feb 2007 11:25:49 +0100 (CET)
From:      "Stefan Bethke" <stb@lassitu.de>
To:        "Luigi Rizzo" <rizzo@icir.org>
Cc:        current@freebsd.org
Subject:   Re: C macro to find the next power of 2 ?
Message-ID:  <15241.SV0BLFJbGwk=.1170843949.squirrel@koef.zs64.net>
In-Reply-To: <20070207004131.A62183@xorpc.icir.org>
References:  <20070207004131.A62183@xorpc.icir.org>

next in thread | previous in thread | raw e-mail | index | archive | help
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 <stb@lassitu.de> +49 170 3460140




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?15241.SV0BLFJbGwk=.1170843949.squirrel>