[fpc-devel] FPC_REQUIRES_PROPER_ALIGNMENT

Marc Weustink marc at dommelstein.net
Wed Oct 13 23:02:21 CEST 2004


At 16:38 13-10-2004, Jonas Maebe wrote:

>On 12 okt 2004, at 22:12, Marc Weustink wrote:
>
>>M:> Is a sigbus catchable so that you can read the data and continue as 
>>if nothing happened (or is that something at OS level)
>
>That is normally possible, yes. But as Florian said, it's quite a bit of 
>work and also extremely slow (you get 4 context switches per unaligned 
>access, + the work to load the value).

Yes I do realize that there is a penalty for doing unaligned access. That 
is something different than not allowing it.
With this option normal alligned access if fast. If someone wants to access 
memory unaligned... so be it.

>>M:> Let the user take care of alignment makes me a bit itchy. I don't get 
>>a good feeling with it.
>
>I think it's normal he has to.

Ow...

>We also don't emulate the 80-bit extended type on processors which only 
>have a 64-bit double precision fpu.

That is something different IMO. But I see no reason why it can't be done. 
Why it math supported on targets without fpu ? Why is int64 supported on 
targets not having a 64 register ?
Ok, it are all choises and a matter of time, but not a reason to do or skip 
other things.

>We also don't emulate endianess. Portability has a lot of pitfalls.

In a matter of fact, you do support endianness. As an enduser I don't have 
to take care ot the phisical representation of an integer for instance.
An integer and $FF is still a value between 0 and 255.
An integer shl 2 is still doubled no matter its representation in memory.

>>M:> But how are members of packed records accessed ?
>
>Just like members of regular records. The difference is that there are 
>simply no alignment bytes between the different fields of the record.

So accessing them result in a bus error ?

Florian replied to this:
>If you've to access an unaligned member, you've to use a move as you do in 
>C, where a memcpy is used.

I'm not talking C here. This is pascal.

When I've to interface with a record like:
   Rec: packed record
     B: Byte;
     I: Integer;
   end;

you are saying that to access Rec.I I have to do something like:
   MyInt := PInteger(aligntoptr(@Rec.I))^;
(what about writing to it ?)

This will throw away all advantages away form pascal (like strong typing etc).
And if you forget to make it aligned, you get all kinds of errors.

I hope I got this all wrong, otherwise I would be better of using a C 
compiler for this (then I've the ability to use macros to get around this)

Marc (hopes he understood this wrong)







More information about the fpc-devel mailing list