public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* memcpy to an unaligned address
@ 2005-08-02 17:32 Shaun Jackman
  2005-08-02 17:43 ` Dave Korn
                   ` (2 more replies)
  0 siblings, 3 replies; 35+ messages in thread
From: Shaun Jackman @ 2005-08-02 17:32 UTC (permalink / raw)
  To: gcc

In a typical Ethernet/IP ARP header the source IP address is
unaligned. Instead of using...
	out->srcIPAddr = in->dstIPAddr;
... I used...
	memcpy(&out->srcIPAddr, &in->dstIPAddr, sizeof(uint32_t));
... to account for the unaligned destination. This worked until gcc 4,
which now generates a simple load/store.
	ldr     r3, [r6, #24]
	adds    r2, r4, #0
	adds    r2, #14
	str     r3, [r2, #0]
A nice optimisation, but in this case it's incorrect. $r4 is aligned,
and the result of adding #14 to $r4 is an unaligned pointer.

Should gcc know better, or do I need to give it a little more
information to help it out?

Please cc me in your reply. Cheers,
Shaun

^ permalink raw reply	[flat|nested] 35+ messages in thread

end of thread, other threads:[~2005-08-05 16:09 UTC | newest]

Thread overview: 35+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <345be691050804025955c0b4ab@mail.gmail.com>
2005-08-04 15:06 ` memcpy to an unaligned address Shaun Jackman
2005-08-04 15:09   ` Christian Joensson
2005-08-05  8:41   ` Carl Whitwell
2005-08-05 16:09     ` Shaun Jackman
2005-08-02 17:32 Shaun Jackman
2005-08-02 17:43 ` Dave Korn
2005-08-02 19:13   ` Shaun Jackman
2005-08-02 19:19     ` Paul Koning
2005-08-02 19:26       ` Shaun Jackman
2005-08-02 19:40         ` Dave Korn
2005-08-02 19:48           ` Paul Koning
2005-08-02 20:15           ` Shaun Jackman
2005-08-02 20:29             ` Paul Koning
2005-08-02 20:29             ` Mike Stump
2005-08-02 20:38               ` Andrew Pinski
2005-08-02 20:45                 ` Ian Lance Taylor
2005-08-02 21:30                   ` Mike Stump
2005-08-02 21:34                     ` Joe Buck
2005-08-03 18:00                   ` Richard Henderson
2005-08-03 18:15                     ` Shaun Jackman
2005-08-03 18:19                       ` Dave Korn
2005-08-03 21:26                       ` Richard Henderson
2005-08-04  4:42                     ` Ian Lance Taylor
2005-08-04 12:40                     ` Paul Koning
2005-08-02 20:46                 ` Paul Koning
2005-08-02 22:17                   ` Shaun Jackman
2005-08-03 17:16                     ` Paul Koning
2005-08-02 22:26                   ` Shaun Jackman
2005-08-02 22:29                     ` Shaun Jackman
2005-08-02 21:05                 ` Mike Stump
2005-08-02 21:11                   ` Joe Buck
2005-08-02 22:15                     ` Shaun Jackman
2005-08-02 22:12                       ` Joe Buck
2005-08-02 17:48 ` Falk Hueffner
2005-08-02 18:03 ` Mike Stump

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 read-only IMAP folder(s) and NNTP newsgroup(s).