[fpc-devel]68k codegen patch

Balogh, Karoly (Charlie/iNQ) charlie at scenergy.dfmk.hu
Wed Jun 4 16:51:42 CEST 2003


Hi,

Here is my first fix to the 68k codegenerator. Hope it's ok.
It's needed because the original codegenerator sometimes generated
instructions like lsl.l #10,d2 which is definitely not a really
good idea, and GNU AS screamed... :)

Example code:

Program Bug2;

Var BigArray : Array[0..64,0..255] Of DWord;
    Counter,Counter2  : DWord;

Begin
 For Counter:=0 To 64 Do Begin
   For Counter2:=0 To 255 Do Begin
     BigArray[Counter,Counter2]:=1;
    End;
  End;
End.

Compiled (without my patch):

    movel    #0,_COUNTER
.L5:
    movel    #0,_COUNTER2
.L10:
    movel    _COUNTER,%d2
    lea    _BIGARRAY,%a2
    lsll    #10,%d2         <--- WHOOPS!!!
    movel    _COUNTER2,%d3
    lea    (%a2,%d2.l),%a3
    lsll    #2,%d3
    movel    #1,(%a3,%d3.l)
    cmpl    #255,_COUNTER2
    bcc    .L9
    addql    #1,_COUNTER2
    jmp    .L10
.L9:
    cmpl    #64,_COUNTER
    bcc    .L4
    addql    #1,_COUNTER
    jmp    .L5
.L4:

Same code compiled, with my patch:

    movel    #0,_COUNTER
.L5:
    movel    #0,_COUNTER2
.L10:
    movel    _COUNTER,%d2
    lea    _BIGARRAY,%a2
    moveql    #10,%d0      <- better huh? :)
    lsll    %d0,%d2        <-
    movel    _COUNTER2,%d3
    lea    (%a2,%d2.l),%a3
    lsll    #2,%d3
    movel    #1,(%a3,%d3.l)
    cmpl    #255,_COUNTER2
    bcc    .L9
    addql    #1,_COUNTER2
    jmp    .L10
.L9:
    cmpl    #64,_COUNTER
    bcc    .L4
    addql    #1,_COUNTER
    jmp    .L5
.L4:

Patch attached. Should be applied to /compiler/m68k/cgmem.pas in the
fixes branch.

Bye,
-- 
Charlie/iNQ
.:%[ Cybernetic Hydraulic Android Responsible for ]%:. 
.:%[    Logical Infiltration and Exploration      ]%:.
.:%[         Member of TeamOS/2 Hungary           ]%:.
.:%[     Member of Hungarian Amiga User Group     ]%:.
-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
Name: cgmem.pas.patch
URL: <http://lists.freepascal.org/pipermail/fpc-devel/attachments/20030604/502b494b/attachment.ksh>


More information about the fpc-devel mailing list