From: Denys Vlasenko <vda.linux@googlemail.com>
To: Daniel Drake <dsd@gentoo.org>
Cc: linux-kernel@vger.kernel.org, davem@davemloft.net,
kune@deine-taler.de, johannes@sipsolutions.net
Subject: Re: [RFC] Documentation about unaligned memory access
Date: Sun, 25 Nov 2007 00:27:25 -0800 [thread overview]
Message-ID: <200711250027.25221.vda.linux@googlemail.com> (raw)
In-Reply-To: <20071123001554.12F8B9D4A1F@zog.reactivated.net>
On Thursday 22 November 2007 16:15, Daniel Drake wrote:
> In summary: if your code causes unaligned memory accesses to happen, your
> code will not work on some platforms, and will perform *very* badly on
> others.
Although understanding alignment is important, there is another
extreme - what I call "sadistic alignment". It's when data is being
aligned even if it will definitely run on an arch which doesn't require
this (arch/x86/*), or data being aligned to ridiculously large boundary.
Like gcc aligning any char array bigger that 31 byte to 32 bytes.
Bytes, not bits. Try to compile this with -O2:
static char s1[] = "12345678901234567890123456789012";
static char s2[] = "12345678901234567890123456789012";
void f(char*);
void g() {
f(s1);
f(s2);
}
$ hexdump -Cv t.o
00000000 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00 00 00 |.ELF............|
00000010 01 00 03 00 01 00 00 00 00 00 00 00 00 00 00 00 |................|
00000020 38 01 00 00 00 00 00 00 34 00 00 00 00 00 28 00 |8.......4.....(.|
00000030 0a 00 07 00 55 89 e5 83 ec 08 c7 04 24 40 00 00 |....U.......$@..|
00000040 00 e8 fc ff ff ff c7 04 24 00 00 00 00 e8 fc ff |........$.......|
00000050 ff ff c9 c3 00 00 00 00 00 00 00 00 00 00 00 00 |................| <=== HERE
00000060 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 |1234567890123456|
00000070 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 |7890123456789012|
00000080 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| <=== HERE
00000090 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 |................| <=== HERE
000000a0 31 32 33 34 35 36 37 38 39 30 31 32 33 34 35 36 |1234567890123456|
000000b0 37 38 39 30 31 32 33 34 35 36 37 38 39 30 31 32 |7890123456789012|
000000c0 00 00 00 00 00 47 43 43 3a 20 28 47 4e 55 29 20 |.....GCC: (GNU) |
000000d0 34 2e 30 2e 33 20 28 55 62 75 6e 74 75 20 34 2e |4.0.3 (Ubuntu 4.|
000000e0 30 2e 33 2d 31 75 62 75 6e 74 75 35 29 00 00 2e |0.3-1ubuntu5)...|
000000f0 73 79 6d 74 61 62 00 2e 73 74 72 74 61 62 00 2e |symtab..strtab..|
43 bytes wasted!
Thankfully, it is fixed in later gcc versions.
Please do not succumb to "alignment scare" in your doc.
--
vda
next prev parent reply other threads:[~2007-11-25 8:27 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-23 0:15 [RFC] Documentation about unaligned memory access Daniel Drake
2007-11-23 0:27 ` Avuton Olrich
2007-11-23 1:29 ` Alan Cox
2007-11-23 3:04 ` Kyle Moffett
2007-11-23 6:18 ` dean gaudet
2007-11-23 9:46 ` Arne Georg Gleditsch
2007-11-26 14:50 ` dean gaudet
2007-11-23 1:29 ` David Miller
2007-11-23 10:06 ` Jan Engelhardt
2007-11-23 11:43 ` Heikki Orsila
2007-11-25 11:16 ` Geert Uytterhoeven
2007-11-25 11:24 ` Heikki Orsila
2007-11-26 0:48 ` Alan Cox
2007-11-26 17:12 ` Ben Dooks
2007-11-27 7:51 ` Kumar Gala
2007-11-23 22:02 ` Vadim Lobanov
2007-11-23 22:52 ` Dmitri Vorobiev
2007-11-24 13:34 ` Pierre Ossman
2007-11-24 15:50 ` Luciano Rocha
2007-11-24 16:19 ` Pierre Ossman
2007-11-24 17:22 ` Luciano Rocha
2007-11-24 17:35 ` Pierre Ossman
2007-11-24 18:28 ` Luciano Rocha
2007-11-24 17:53 ` Haavard Skinnemoen
2007-11-25 8:27 ` Denys Vlasenko [this message]
2007-11-25 14:13 ` Olaf Titz
2007-11-26 9:14 ` DM
2007-11-26 14:47 ` Johannes Berg
2007-11-27 0:40 ` Arnaldo Carvalho de Melo
2007-11-26 14:51 ` Johannes Berg
2007-11-30 8:18 ` Jörn Engel
[not found] <fa.U+CIv4JClOmn6KppLkEOSk7RW0Y@ifi.uio.no>
2007-11-23 1:24 ` Robert Hancock
2007-11-23 2:07 ` Andi Kleen
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=200711250027.25221.vda.linux@googlemail.com \
--to=vda.linux@googlemail.com \
--cc=davem@davemloft.net \
--cc=dsd@gentoo.org \
--cc=johannes@sipsolutions.net \
--cc=kune@deine-taler.de \
--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