From: Michal Jaegermann <michal@ellpspace.math.ualberta.ca>
To: axp-list@redhat.com
Subject: Re: problem with unaligned access on Alpha
Date: Thu, 24 Jun 1999 01:02:42 -0600 (MDT) [thread overview]
Message-ID: <199906240702.BAA06113@ellpspace.math.ualberta.ca> (raw)
In-Reply-To: <Pine.GSO.3.96.990623174255.16101B-100000@delta.ds2.pg.gda.pl> from "Maciej W. Rozycki" at Jun 23, 99 06:23:59 pm
Maciej W. Rozycki wrote:
>
> 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?
Looking at a generated assembler it seems to me that an efficiency of
reading that as a stream of unsigned bytes and composing required 16-bit
values by "shift and add" is grossly underestimated. :-) I grant that
there are tougher cases than that. OTOH Intel processors also take a
performance hit for unaligned acceses although, I understand, this
overhead is quite a bit smaller in an Intel case and they are also quiet
about it.
> 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.
Hm, I never thought about "__attribute__((packed))" trick. This would
make code, obviosly, quite gcc specific but likely this can be hidden
in some reasonably looking macros defined differently for gcc and
others. But did you look at what happens on an assembler level
(I did not - for your examples); "packed" is not coming for free.
> 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.
I bet that a lot less than an unaligned trap. :-) C Standard is also
full of dire warnings about mixing different pointer types (or using
casts to hide that practice). I guess that this is not without a reason
even if sounds like anal in places.
Somebody send me a while ago samples of a code which were supposedly
showing up an aliasing bug of egcs-1.1.2. I did not try them on Intel
but there was not a trace of bad results on Alpha. Maybe one needs much
more of a register presure before bad things will start to happen? I do
not know. Out of sheer curiosity I rewrote one example to use unions
instead of playing "efficient" pointer games. Resulting assembler was
smaller and better for union approach as opposed to the "efficient" one.
In this case everything was aligned anyway as variables were defined on
stack. But this IS a food for though.
Michal
next prev parent reply other threads:[~1999-06-24 7:58 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
1999-06-24 7:02 ` Michal Jaegermann [this message]
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