View Issue Details

IDProjectCategoryView StatusLast Update
0030872FPCRTLpublic2016-12-04 10:21
ReporterGennady Agranov Assigned ToFlorian  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionwon't fix 
Platformarm-linuxOSRaspbian 
Product Version3.0.1 
Summary0030872: misaligned data exception
DescriptionMy CPU is ARMv7 and FPC was compiled for this CPU
If I use {$PACKRECORDS 1} and double field inside the record in not aligned
call to Format('%f',[field]) throws an exception
Steps To Reproduce// {$PACKRECORDS 1}
program policing_test;

uses SysUtils;

type ABC = record
  e: double;
  i: boolean;
  f: double;
end;

 var A: ABC;

 begin
   a.e := 3.1415; //ok
    a.f := 2.7181; //ok
   writeln(Format('%8f',[a.e])); //ok
   writeln(Format('%8f',[a.f])); //exception
end.
TagsNo tags attached.
Fixed in Revision
FPCOldBugId
FPCTarget
Attached Files

Activities

Gennady Agranov

2016-11-05 15:18

reporter   ~0095592

Sorry - forgot to uncomment {$PACKRECORDS 1}

Jonas Maebe

2016-11-05 22:23

manager   ~0095601

I don't think we support unaligned floating point loads on any platform right now. That would also be even slower than unaligned integer loads, because you would first have to load those values in integer registers and from there transfer them to floating point registers (which, on ARM with VFP, can fortunately happen in one instruction rather than having to pass again via memory, but still...).

Florian

2016-11-06 19:31

administrator   ~0095613

Actually, FPC supports unaligned floating point variables if it knows about it, example derived from the code given here:

# [18] a.f:=d+1;
    vldr d0,.Lj11
    vadd.f64 d0,d1,d0
    vmov r0,r2,d0
    ldr r1,.Lj8
    strb r0,[r1]
    mov r0,r0,lsr 0000008
    strb r0,[r1, 0000001]
    mov r0,r0,lsr 0000008
    strb r0,[r1, 0000002]
    mov r0,r0,lsr 0000008
    strb r0,[r1, 0000003]
    ldr r1,.Lj13
    strb r2,[r1]
    mov r0,r2,lsr 0000008
    strb r0,[r1, 0000001]
    mov r0,r0,lsr 0000008
    strb r0,[r1, 0000002]
    mov r0,r0,lsr 0000008
    strb r0,[r1, 0000003]

The problem of the given code using format is, that doubles are passed by reference to format and format assumes all references are naturally aligned. This is a common assumption for most libraries that they can assume references are properly aligned. This keeps the generated code small and fast. Of course, we could tell format to assume that references might be badly aligned, but as the code above shows, this results in bloat, so this will not be fixed.

Marco van de Voort

2016-11-06 22:48

manager   ~0095620

Last edited: 2016-11-06 22:48

View 2 revisions

(or let code that knows it is unaligned copy it to an aligned temp before calling the routine)

Issue History

Date Modified Username Field Change
2016-11-05 15:13 Gennady Agranov New Issue
2016-11-05 15:18 Gennady Agranov Note Added: 0095592
2016-11-05 22:23 Jonas Maebe Note Added: 0095601
2016-11-06 19:31 Florian Note Added: 0095613
2016-11-06 19:31 Florian Status new => resolved
2016-11-06 19:31 Florian Resolution open => won't fix
2016-11-06 19:31 Florian Assigned To => Florian
2016-11-06 22:48 Marco van de Voort Note Added: 0095620
2016-11-06 22:48 Marco van de Voort Note Edited: 0095620 View Revisions