From: "Will Newton" <will.newton@gmail.com>
To: "Harvey Harrison" <harvey.harrison@gmail.com>
Cc: linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [RFC-PATCH 1/5] unaligned: introduce common header
Date: Tue, 11 Nov 2008 09:50:57 +0000 [thread overview]
Message-ID: <87a5b0800811110150m407ea6b3wc265b824a448ee20@mail.gmail.com> (raw)
In-Reply-To: <1226343084.22742.11.camel@brick>
On Mon, Nov 10, 2008 at 6:51 PM, Harvey Harrison
<harvey.harrison@gmail.com> wrote:
> On Mon, 2008-11-10 at 18:35 +0000, Will Newton wrote:
>> On Mon, Nov 10, 2008 at 4:51 PM, Harvey Harrison
>> <harvey.harrison@gmail.com> wrote:
>> >
>> > In this particular case, packed isn't right as you know big_data is
>> > aligned (as long as you can guarantee the struct alignment), so you'd
>> > probably want:
>> >
>> > struct foo {
>> > u64 big_data;
>> > u8 small_data;
>> > u32 medium_data __attribute__((__packed__));
>> > }
>> >
>> > But that's not what we're talking about in the kernel's case.
>>
>> Perhaps that would be a neater way of expressing what is required in
>> my simple example, but it's fairly common to use packed on the whole
>> struct which could be because a field that is "packed" by default on
>> one architecture might not be on another. You could mark every field
>> as packed but few people seem to do that and as far as I am aware
>> there is no documented difference between packing all members and the
>> whole struct. The gcc documentation for packed is pretty short:
>
> Actually it's documented that putting attribute(packed) on the struct
> is equivalent to putting attribute(packed) on _every_ member of the
> struct.
>
>> The packed attribute specifies that a variable or structure field
>> should have the smallest
>> possible alignment—one byte for a variable, and one bit for a field,
>> unless you specify a
>> larger value with the aligned attribute.
>>
>> I'd love to know if the pointer alignment behaviour is widespread and
>> then maybe write a patch for the gcc manual.
>
> Well, it's kind of the whole point of __packed isn't it? Otherwise the
> struct members get naturally (or some arch-dependent value) aligned,
> which the compiler can rely on unless you say __packed.
>
> So in my example above, the compiler _knows_ how it has aligned
> big_data and small_data and can use whatever access is most efficient,
> but it can't make any assumptions about medium_data, so access through
> a pointer _must_ be done unaligned.
>
> struct foo *bar;
> bar->medium_data; // compiler must do this unaligned
Agreed, but the packed struct unaligned access code does this:
struct __una_u16 { u16 x __attribute__((packed)); };
On an architecture with struct alignment > 1 this will not work. Which
is why I believe that the memmove code must stay for those
architectures.
prev parent reply other threads:[~2008-11-11 9:51 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-05 18:16 Harvey Harrison
[not found] ` <87a5b0800811080447m2cebebb7j77afe9592f72ab11@mail.gmail.com>
[not found] ` <1226290940.5478.3.camel@brick>
2008-11-10 11:49 ` Will Newton
2008-11-10 16:51 ` Harvey Harrison
2008-11-10 18:35 ` Will Newton
2008-11-10 18:51 ` Harvey Harrison
2008-11-11 9:50 ` Will Newton [this message]
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=87a5b0800811110150m407ea6b3wc265b824a448ee20@mail.gmail.com \
--to=will.newton@gmail.com \
--cc=harvey.harrison@gmail.com \
--cc=linux-kernel@vger.kernel.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
all inboxes | Powered by JetHome®