Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 Feb 2007 01:43:39 -0800
From:      Luigi Rizzo <rizzo@icir.org>
To:        Hans Petter Selasky <hselasky@c2i.net>
Cc:        freebsd-current@freebsd.org
Subject:   Re: C macro to find the next power of 2 ?
Message-ID:  <20070207014339.A63018@xorpc.icir.org>
In-Reply-To: <200702071020.34656.hselasky@c2i.net>; from hselasky@c2i.net on Wed, Feb 07, 2007 at 10:20:34AM %2B0100
References:  <20070207004131.A62183@xorpc.icir.org> <200702071020.34656.hselasky@c2i.net>

next in thread | previous in thread | raw e-mail | index | archive | help
On Wed, Feb 07, 2007 at 10:20:34AM +0100, Hans Petter Selasky wrote:
> Hi Luigi,
> 
> Why don't you hardcode the structures with the correct alignment, and maybe 
> you find the __align() macro useful.

because i want the compiler to do the dirty work -- compute the
alignment for me.

The __align() macro, which in the end expands to

	__attribute__ ((aligned (n)))

doesn't help here because requires you to supply a value for
the alignment. The other form (without 'n') computes it but only

	"to the maximum useful alignment for the target machine you
	are compiling for".

(see http://gcc.gnu.org/onlinedocs/gcc-4.1.1/gcc/Type-Attributes.html#Type-Attributes )

The example in the manpage is ambiguous but basically at
least on gcc 3.4.6 and RELENG_6 / i386 the automatic
alignment defaults to 16 bytes (hence the size is just
the next multiple of 16, not the next power of 2).

> What you are discovering is an old issue. Hardware structures must be 
> indexable without addition.

well the issue for me is just how to make the compiler do the calculation.

	cheers
	luigi



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