Re: Misc Qns...

From: Mark F. Haigh (mfhaigh_at_sbcglobal.ten)
Date: 12/17/03


Date: Wed, 17 Dec 2003 07:46:28 GMT

Jack Klein wrote:
> On Tue, 16 Dec 2003 16:00:20 GMT, Thomas Matthews
> <Thomas_MatthewsSpitsOnSpamBots@sbcglobal.net> wrote in comp.lang.c:
>
>
>>Jin wrote:
>>
>>
>>>1. Will simply taking the address of a non-aligned variable (but not
>>> deferencing it) produce undefined behavior?
>>
>>Not according to the _Standard_. Alignment restrictions are an
>>implementation detail, not one of the standard. My understanding is
>>that accessing data that is not aligned will just take more fetches
>>by the processor.
>
>
> You are very, very wrong here. Some platforms, such as Intel x86,
> will perform additional memory cycles, to be sure.
>
> But there are at least two other types of responses in current
> architectures, particularly RISC and/or DSP:
>
> 1. The low bits of the pointer are merely ignored. On this type of
> architecture if you tried to access a 32 bit value at any of the
> addresses 0x1000, 0x1001, 0x1002, or 0x1003 would pick up the four
> bytes at 0x1000 through 0x1003 inclusive. Even if you expected trying
> to read a 32 bit value with a pointer containing 0x1003 to pick up
> that byte plus 0x1004, 0x1005, and 0x1006.
>
> 2. The processor platform performs automatic alignment checks and
> generates a trap or exception if a multi-byte object is accessed at an
> address with incorrect alignment. If there is an operating system
> involved, it generally terminates the program that did this with
> something called "sigbus" or some such.
>

#2 may also direct the trap or exception to a kernel handler that fixes
up the access with the expected results, using byte loads. Of course,
it's horrendously slow. It's sometimes used to help poorly written
(most often x86-centric) software limp along on things like ARM Linux
and such.

Mark F. Haigh
mfhaigh@sbcglobal.net



Relevant Pages

  • Re: Proper Error Handling of SQL Connection opening
    ... I've read (and I'm a .NET book junkie) has to be Jeffrey Richter's Applied ... Exception handling is and how to employ it. ... Don't trap exceptions just to trap them. ...
    (microsoft.public.dotnet.framework.compactframework)
  • Re: Misc Qns...
    ... architectures, particularly RISC and/or DSP: ... The low bits of the pointer are merely ignored. ... The processor platform performs automatic alignment checks and ...
    (comp.lang.c)
  • Re: semantics of loating point exception handling
    ... The C standard doesn't really have much to say about FP exceptions being ... The terminology here is that the "exception" is the overflow, or whatever, ... When the exception is raised, if its trap is disabled, ... the trap handler is liable to not be called until ...
    (comp.lang.c)
  • Re: Trap Overflow - Intel Compilers
    ... Greg: Thanks. ... gdb facilitated an excellent traceback too. ... Also is it possible to trap an underflow also? ... -|compiling that will trap this exception, ...
    (comp.lang.fortran)
  • [PATCH 18/30] microblaze_mmu_v1: entry.S, entry.h
    ... Definitions used by low-level trap handlers ... system calls save and restore all registers (except result ... * Trap entered via exception, so EE bit is set, and interrupts ...
    (Linux-Kernel)