public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Imre Deak <imre.deak@nokia.com>
To: ext Mathieu Desnoyers <mathieu.desnoyers@efficios.com>
Cc: Russell King - ARM Linux <linux@arm.linux.org.uk>,
	Alexander Shishkin <virtuoso@slind.org>,
	"linux-arm-kernel@lists.infradead.org" 
	<linux-arm-kernel@lists.infradead.org>,
	Jamie Lokier <jamie@shareable.org>,
	"rostedt@goodmis.org" <rostedt@goodmis.org>,
	"mingo@elte.hu" <mingo@elte.hu>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: Re: [RFC PATCH] create generic alignment api (v2)
Date: Sun, 28 Mar 2010 18:40:29 +0300	[thread overview]
Message-ID: <20100328154029.GA21061@localhost> (raw)
In-Reply-To: <20100328012247.GA17763@Krystal>

On Sun, Mar 28, 2010 at 03:22:47AM +0200, ext Mathieu Desnoyers wrote:
>  [...]
> +/**
> + * offset_align - Calculate the offset needed to align an object on its natural
> + *                alignment towards higher addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be added to align towards higher
> + * addresses.
> + */
> +static inline size_t offset_align(size_t align_drift, size_t alignment)
> +{
> +	return (alignment - align_drift) & (alignment - 1);
> +}
> +
> +/**
> + * offset_align_floor - Calculate the offset needed to align an object
> + *                      on its natural alignment towards lower addresses.
> + * @align_drift:  object offset from an "alignment"-aligned address.
> + * @alignment:    natural object alignment. Must be non-zero, power of 2.
> + *
> + * Returns the offset that must be substracted to align towards lower addresses.
> + */
> +static inline size_t offset_align_floor(size_t align_drift, size_t alignment)
> +{
> +	return (align_drift - alignment) & (alignment - 1);
> +}
> +
> +#define object_align(object)						       \
> +	((typeof(object))((size_t) object + offset_align((size_t) object,      \
> +			  sizeof(object))))
> +
> +#define object_align_floor(object)					       \
> +	((typeof(object))((size_t) object - offset_align_floor((size_t) object,\
> +			  sizeof(object))))
> +

Here object must be a pointer, but then sizeof(object) will result in
aligning to the arch word size not the object's natural alignment. Is
this what you intended?

--Imre


  reply	other threads:[~2010-03-28 15:41 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-03-28  1:22 [RFC PATCH] create generic alignment api (v2) Mathieu Desnoyers
2010-03-28 15:40 ` Imre Deak [this message]
2010-03-28 18:29   ` Mathieu Desnoyers
2010-03-29  0:09   ` [RFC PATCH] create generic alignment api (v5) Mathieu Desnoyers
2010-05-01 18:35     ` Alexander Shishkin
2010-05-01 19:10       ` Mathieu Desnoyers
2010-05-01 19:29         ` Alexander Shishkin
2010-05-01 19:45           ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20100328154029.GA21061@localhost \
    --to=imre.deak@nokia.com \
    --cc=jamie@shareable.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@arm.linux.org.uk \
    --cc=mathieu.desnoyers@efficios.com \
    --cc=mingo@elte.hu \
    --cc=rostedt@goodmis.org \
    --cc=virtuoso@slind.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox