Browse Source

m68k: minor optimizations to g_proc_exit() - use LEA for stackpointer math which is better than ADDing large constants, also only modify the SP reg once

git-svn-id: trunk@27817 -
Károly Balogh 11 years ago
parent
commit
28323135f8
1 changed files with 12 additions and 5 deletions
  1. 12 5
      compiler/m68k/cgcpu.pas

+ 12 - 5
compiler/m68k/cgcpu.pas

@@ -1716,9 +1716,8 @@ unit cgcpu;
     procedure tcg68k.g_proc_exit(list : TAsmList; parasize: longint; nostackframe: boolean);
     procedure tcg68k.g_proc_exit(list : TAsmList; parasize: longint; nostackframe: boolean);
       var
       var
         r,hregister : TRegister;
         r,hregister : TRegister;
-        spr : TRegister;
-        fpr : TRegister;
         ref : TReference;
         ref : TReference;
+        ref2: TReference;
       begin
       begin
         if not nostackframe then
         if not nostackframe then
           begin
           begin
@@ -1752,15 +1751,23 @@ unit cgcpu;
                     hregister:=NR_A0;
                     hregister:=NR_A0;
                     cg.a_reg_alloc(list,hregister);
                     cg.a_reg_alloc(list,hregister);
                     reference_reset_base(ref,NR_STACK_POINTER_REG,0,4);
                     reference_reset_base(ref,NR_STACK_POINTER_REG,0,4);
-                    ref.direction:=dir_inc;
                     list.concat(taicpu.op_ref_reg(A_MOVE,S_L,ref,hregister));
                     list.concat(taicpu.op_ref_reg(A_MOVE,S_L,ref,hregister));
 
 
+                    { instead of using a postincrement above (which also writes the     }
+                    { stackpointer reg) simply add 4 to the parasize, the instructions  }
+                    { below then take that size into account as well, so SP reg is only }
+                    { written once (KB) }
+                    parasize:=parasize+4;
+
                     r:=NR_SP;
                     r:=NR_SP;
                     { can we do a quick addition ... }
                     { can we do a quick addition ... }
-                    if (parasize > 0) and (parasize < 9) then
+                    if (parasize < 9) then
                        list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,r))
                        list.concat(taicpu.op_const_reg(A_ADDQ,S_L,parasize,r))
                     else { nope ... }
                     else { nope ... }
-                       list.concat(taicpu.op_const_reg(A_ADD,S_L,parasize,r));
+                       begin
+                         reference_reset_base(ref2,NR_STACK_POINTER_REG,parasize,4);
+                         list.concat(taicpu.op_ref_reg(A_LEA,S_NO,ref2,r));
+                       end;
 
 
                     reference_reset_base(ref,hregister,0,4);
                     reference_reset_base(ref,hregister,0,4);
                     list.concat(taicpu.op_ref(A_JMP,S_NO,ref));
                     list.concat(taicpu.op_ref(A_JMP,S_NO,ref));