Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Jay.Estabrook at hp.com (Jay Estabrook)
Subject: Getting rid of Unaligned Accesses (UA)
Date: Thu, 22 May 2008 14:53:34 -0400	[thread overview]
Message-ID: <4835C12E.60905@hp.com> (raw)

Hi, Alpha folk,

I hope there's someone(s) out there that might have comments to offer
on how best to coerce the GCC compiler into generating the code WE want,
rather than what GCC wants.

To fix an unaligned access (UA) problem in "dbus",  a union pointer
address which was not always aligned (gcc assumes they are, by default,
it seems), I changed something like the following, which appears in the
file: dbus-marshal-basic.c:dbus_marshal_read_basic():

    vp->byt = _dbus_get_byte(str, pos);
to:
    *((char*)&vp->byt) = _dbus_get_byte(str, pos);

Under GCC-4.1.2-23, this generated code that did the appropriate things
to prevent a UA.

HOWEVER, when I built it under GCC-4.1.2-37, it reverted to the original
bad code (always assuming alignment). I had to change it yet again, to
the following:

    *((volatile char*)&vp->byt) = _dbus_get_byte(str, pos);

to get it to produce the good code again.

So, my question: is the final version (using "volatile") the only real
way to guarantee good code in this (and similar) instance?

Or is there another more (or less) obvious way to do so?

I certainly didn't expect the behavior to change like this between
releases and not major/minor versions... :-\

Thanks for any insights,

--Jay++





             reply	other threads:[~2008-05-22 18:53 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-05-22 18:53 Jay.Estabrook [this message]
2008-05-22 19:10 ` Getting rid of Unaligned Accesses (UA) macro
2008-05-22 19:13   ` Jay.Estabrook
2008-05-22 20:24     ` macro
2008-05-22 22:30       ` netbeans
2008-05-23 13:54         ` Jay.Estabrook
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox