Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
* Unaligned memory explained.
       [not found] <Pine.LNX.3.91.961118213406.28446A-100000@ims1.imagestream.com>
@ 1996-11-19 22:18 ` Marc Singer
  0 siblings, 0 replies; 2+ messages in thread
From: Marc Singer @ 1996-11-19 22:18 UTC (permalink / raw)


> You don't have to worry about the unaligned memory errors.  They
> have something do do with the way the alpha uses memory (could some
> one please go over this in detail).

This is a simple one.  Alpha and 68k and most RISC processors don't
like to access unaligned memory.  "What is unaligned memory?" you ask.
Bytes are always aligned because each memory address refers to one
byte and therefore there is a unique byte at every address that does
not overlap any other bytes.  Aligned 16-bit words all have the
least-significant bit set to zero.  The first 16-bit word is at
address 0, the second is at address 2.  An unaligned 16-bit word would
have an odd address such as 1 or 5 or 7.  The CPU manufacturers make
this requirement because the CPU can be more efficient when reading
aligned memory.  BTW, aligned 32-bit values have the two LSBs set to
zero.

"Why are aligned accesses more efficient?" you ask.  Let's assume that
the CPU can read 32 bits at a time.  The address decode logic is very
simple when we want to access aligned data because all memory can be
uniquely referenced by ignoring the lowest two address bits.  We can
use this assumption to streamline the cache and to reduce the number
of pins leaving the CPU chip.  If we want to access an unaligned
32-bit value we need to read twice, discard the uninteresting portions
of the data, and combine what's left.

"Why is this all-of-a-sudden a problem?" you ask.  The x86 performs
unaligned memory accesses by reading twice and fixing the result.
It's not efficient and is usually optimized out of good programs, but
since the x86 permits this behavior the programmers who were not
careful about aligning their data will find their programs faulting on
RISC machines.  It is possible that the unaligned memory is the fault
of one of those foolish Microsoft/IBM engineers who designed another
persistent (serialized or in other words written-to-disk) data
structure that is unaligned.  One annoying example is the BMP bitmap
format.  Partition tables may be another.

-- Marc Singer

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

* Re: Unaligned memory explained.
@ 1996-11-20  9:32 Martin Ostermann
  0 siblings, 0 replies; 2+ messages in thread
From: Martin Ostermann @ 1996-11-20  9:32 UTC (permalink / raw)


elf@netcom.com (Marc Singer) writes:
> > You don't have to worry about the unaligned memory errors.  They
> > have something do do with the way the alpha uses memory (could some
> > one please go over this in detail).
> 
[good explainations ommited]
> "Why is this all-of-a-sudden a problem?" you ask.  The x86 performs
> unaligned memory accesses by reading twice and fixing the result.
> It's not efficient and is usually optimized out of good programs, but
> since the x86 permits this behavior the programmers who were not
> careful about aligning their data will find their programs faulting on
> RISC machines.  

I'd like to add:

The reason we don't have to worry badly about it is that on
Linux/Axp the OS catches the traps caused by this fault, and it is
emulating the above behaviour, e.g. the program will be executed
slowly, but correctly.

Martin

-- 
Martin Ostermann                | mailto:ost@comnets.rwth-aachen.de
Communication Networks          | http://www.comnets.rwth-aachen.de/~ost
Aachen University of Technology | phoneto:++49/241/807917
Germany                         | faxto:++49/241/8890378

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

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

end of thread, other threads:[~1996-11-20  9:32 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-11-20  9:32 Unaligned memory explained Martin Ostermann
     [not found] <Pine.LNX.3.91.961118213406.28446A-100000@ims1.imagestream.com>
1996-11-19 22:18 ` Marc Singer

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