From: "Maciej W. Rozycki" <macro@ds2.pg.gda.pl>
To: axp-list@redhat.com
Subject: Re: problem with unaligned access on Alpha
Date: Wed, 23 Jun 1999 18:23:59 +0200 (MET DST) [thread overview]
Message-ID: <Pine.GSO.3.96.990623174255.16101B-100000@delta.ds2.pg.gda.pl> (raw)
In-Reply-To: <199906231456.IAA03278@ellpspace.math.ualberta.ca>
On Wed, 23 Jun 1999, Michal Jaegermann wrote:
> Legality aside peple who write such "nice" code should be run out of
> town. Unfortunately such way is quite popular; mostly because in most
> situations one can get away with it.
Let me give you a real example. I have a stream of compressed data
created on a 16-bit machine. It is a mixture of 8-bit and 16-bit
unsigned quantities. How would you handle it most efficiently?
I would define a "uint8_t *x" pointer (a "void *x" would be an option
here, but the former one allows pointer arithmetics in a portable way) and
depending on the current necessity I would use it as is for 8-bit
quantities or use "((uint16_s *)&(x))->v" cast (where "uint16_s" is
defined as "typedef struct { uint16_t v __attribute__((packed)); }
uint16_s;") to access 16-bit ones. As of egcs 1.1 this should inform the
compiler, data is potentially unaligned and result in a possibly most
efficient code, i.e. a single opcode for machines that do not have any
alignment constraints (like i386) or two opcodes for unaligned fetch for
machines that do not support unaligned bus accesses (like Alpha or MIPS).
One can use "uint8_t" fetches with appropriate shifting and ORing (it's
still necessary on different-endian machines even though some archs have
explicit support for most common endianness convertions) but this wastes a
lot of unnecessary cycles.
If you have any other ideas, please do not hesitate to share them.
--
+ Maciej W. Rozycki, Technical University of Gdansk, Poland +
+--------------------------------------------------------------+
+ e-mail: macro@ds2.pg.gda.pl, PGP key available +
next prev parent reply other threads:[~1999-06-23 17:22 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-06-23 10:23 problem with unaligned access on Alpha Christian Groessler
1999-06-23 14:55 ` Maciej W. Rozycki
1999-06-23 14:56 ` Michal Jaegermann
1999-06-23 16:23 ` Maciej W. Rozycki [this message]
1999-06-24 7:02 ` Michal Jaegermann
1999-06-25 20:21 ` Maciej W. Rozycki
-- strict thread matches above, loose matches on Subject: below --
1999-06-29 9:12 Wessels, Hans
1999-06-29 15:07 ` Michal Jaegermann
1999-07-05 17:23 ` Maciej W. Rozycki
1999-06-24 8:54 Christian Groessler
1999-06-24 8:29 Christian Groessler
1999-06-24 15:26 ` Michal Jaegermann
1999-06-22 10:59 Christian Groessler
1999-06-22 12:32 ` Stefan Katzenbeisser
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