From: Roland Dreier <rdreier@cisco.com>
To: David Miller <davem@davemloft.net>
Cc: sri@us.ibm.com, shemminger@osdl.org, netdev@vger.kernel.org
Subject: Re: Excess use of packed attribute
Date: Wed, 09 Aug 2006 11:37:31 -0700 [thread overview]
Message-ID: <ada3bc5sql0.fsf@cisco.com> (raw)
In-Reply-To: <20060807.173920.102575221.davem@davemloft.net> (David Miller's message of "Mon, 07 Aug 2006 17:39:20 -0700 (PDT)")
David> For the cases where it is no actually necessary, the code
David> generation cost on RISC cpus is very high. Byte loads and
David> stores will be used to access _every_ member of such
David> structures on RISC machines because the compiler cannot
David> guarentee the alignment of any data object when packed is
David> specified.
Agreed (although not really RISC -- sparc64 and ia64 have this
problem, while ppc is fine with unaligned access). However
__attribute__((packed,aligned)) has just been brought to my attention.
For example, on sparc64,
struct foo { char x; int a; } __attribute__((packed,aligned));
struct bar { char x; int b; } __attribute__((packed));
int c(struct foo *x) { return x->a; }
int d(struct bar *x) { return x->b; }
compiles to:
0000000000000000 <c>:
0: d0 5a 00 00 ldx [ %o0 ], %o0
4: 91 2a 30 08 sllx %o0, 8, %o0
8: 81 c3 e0 08 retl
c: 91 3a 30 20 srax %o0, 0x20, %o0
10: 30 68 00 04 b,a %xcc, 20 <d>
14: 01 00 00 00 nop
18: 01 00 00 00 nop
1c: 01 00 00 00 nop
0000000000000020 <d>:
20: c6 0a 20 01 ldub [ %o0 + 1 ], %g3
24: c2 0a 20 02 ldub [ %o0 + 2 ], %g1
28: c4 0a 20 03 ldub [ %o0 + 3 ], %g2
2c: 87 28 f0 18 sllx %g3, 0x18, %g3
30: d0 0a 20 04 ldub [ %o0 + 4 ], %o0
34: 83 28 70 10 sllx %g1, 0x10, %g1
38: 82 10 40 03 or %g1, %g3, %g1
3c: 85 28 b0 08 sllx %g2, 8, %g2
40: 84 10 80 01 or %g2, %g1, %g2
44: 90 12 00 02 or %o0, %g2, %o0
48: 81 c3 e0 08 retl
4c: 91 3a 20 00 sra %o0, 0, %o0
50: 30 68 00 04 b,a %xcc, 60 <d+0x40>
54: 01 00 00 00 nop
58: 01 00 00 00 nop
5c: 01 00 00 00 nop
which suggests that adding "aligned" is a good idea for many of the
uses of "packed". However I don't know how all gcc version do with
this. Anyone have any comments on "__attribute__((packed,aligned))"?
Thanks,
Roland
next prev parent reply other threads:[~2006-08-09 18:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-08-07 20:34 Excess use of packed attribute Stephen Hemminger
2006-08-07 23:20 ` David Miller
2006-08-09 19:17 ` Ville Nuorvala
2006-08-08 0:02 ` Sridhar Samudrala
2006-08-08 0:39 ` David Miller
2006-08-09 18:37 ` Roland Dreier [this message]
2006-08-10 4:11 ` David Miller
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=ada3bc5sql0.fsf@cisco.com \
--to=rdreier@cisco.com \
--cc=davem@davemloft.net \
--cc=netdev@vger.kernel.org \
--cc=shemminger@osdl.org \
--cc=sri@us.ibm.com \
/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;
as well as URLs for NNTP newsgroup(s).