From owner-freebsd-current@FreeBSD.ORG Wed Feb 7 09:43:45 2007 Return-Path: X-Original-To: freebsd-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 1701416A4C4 for ; Wed, 7 Feb 2007 09:43:41 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (xorpc.icir.org [192.150.187.68]) by mx1.freebsd.org (Postfix) with ESMTP id D7B2E13C4B4 for ; Wed, 7 Feb 2007 09:43:41 +0000 (UTC) (envelope-from rizzo@icir.org) Received: from xorpc.icir.org (localhost [127.0.0.1]) by xorpc.icir.org (8.12.11/8.13.6) with ESMTP id l179hdGr063126; Wed, 7 Feb 2007 01:43:39 -0800 (PST) (envelope-from rizzo@xorpc.icir.org) Received: (from rizzo@localhost) by xorpc.icir.org (8.12.11/8.12.3/Submit) id l179hdDO063125; Wed, 7 Feb 2007 01:43:39 -0800 (PST) (envelope-from rizzo) Date: Wed, 7 Feb 2007 01:43:39 -0800 From: Luigi Rizzo To: Hans Petter Selasky Message-ID: <20070207014339.A63018@xorpc.icir.org> References: <20070207004131.A62183@xorpc.icir.org> <200702071020.34656.hselasky@c2i.net> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5.1i In-Reply-To: <200702071020.34656.hselasky@c2i.net>; from hselasky@c2i.net on Wed, Feb 07, 2007 at 10:20:34AM +0100 Cc: freebsd-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 09:43:46 -0000 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