m68k: access to unaligned data in packed records
When accessing unaligned data in packed records, wrong code is generated for -Cp68000.
The following example:
type
THeader = packed record
Signature: char; { signature byte }
Nr_chars: smallint; { number of characters in file }
end;
var t: Theader;
begin
t.nr_chars := swap(t.nr_chars);
end.
generates:
main:
[0000012c] 4eb9 0000 1368 jsr FPC_INITIALIZEUNITS
[00000132] 41f9 0000 3811 lea.l $00003811,a0
[00000138] 3010 move.w (a0),d0
[0000013a] c0bc 0000 ffff and.l #$0000FFFF,d0
[00000140] 2200 move.l d0,d1
[00000142] e089 lsr.l #8,d1
[00000144] e188 lsl.l #8,d0
[00000146] 8280 or.l d0,d1
[00000148] c2bc 0000 ffff and.l #$0000FFFF,d1
[0000014e] 41f9 0000 3812 lea.l $00003812,a0
[00000154] 1081 move.b d1,(a0)
[00000156] e049 lsr.w #8,d1
[00000158] 1101 move.b d1,-(a0)
[0000015a] 4eb9 0000 1548 jsr FPC_DO_EXIT
When reading the nr_chars member, a word access to an odd address is done. When writing it back, it is correctly done using two single-byte accesses.
Another note: the code was compiled with -O2, but looks really inefficient.
Edited by Thorsten Otto