[fpc-devel] data alignment and int64 (or qword, maybe any singlepiece of size 8 if any)
Пётр Косаревский
ppkk at mail.ru
Tue May 16 10:35:34 CEST 2006
Main warning at the end of the message.
> This is not always true. Sparc requires 64bit alignment for doubles. And
> i386 requires 128bit alignment for XMM.
1. I think, that when you optimize for size, default options should be "avoid alignment when possible".
2. SSE2 is a special case and, by the way, will FPC support integer SSE2 operations? (Current mmx unit is not widely used, so Florian K. said it is low priority.)
Compile this with "-OG" and notice, that while record has size 9, individual variables of that type are aligned by 16-byte. (FPC 2.0.3, i386, win32)
And it does not depend on processor model: -Cp386 and -CpPENTIUM4 yield the same results.
{$A-}
type
a= record
a: int64;
b: byte;
end;
var
x: a;
y: byte; // these are
yy: longword; // 9
zz: longword; // bytes
z: a;
begin
writeln(sizeof(a));
writeln(longint(@x));
writeln(longint(@y));
writeln(longint(@z));
end.
This program makes me feel strange: it aligns records by 16 bytes for no reason (last two addresses are odd). (Don't forget {$A-})
{$A-}
type
a= record
b: byte;
a: int64;
end;
var
x: a;
y: byte;
yy: longword;
zz: longword;
z: a;
begin
writeln(sizeof(a));
writeln;
writeln(longint(@x));
writeln(longint(@y));
writeln(longint(@z));
writeln;
writeln(longint(@(x.a)));
writeln(longint(@(z.a)));
end.
Get rid of {$A-}, use "-O3rp4", "-CpPENTIUM4", and one of int64 addresses is not 4 bytes aligned! And records are persistently 16 bytes aligned!
More information about the fpc-devel
mailing list