瀏覽代碼

* x86-64: adjust stack by push/pop if possible

git-svn-id: trunk@45476 -
florian 5 年之前
父節點
當前提交
8f0a3cfce7
共有 2 個文件被更改,包括 18 次插入6 次删除
  1. 10 3
      compiler/x86/cgx86.pas
  2. 8 3
      compiler/x86_64/cgcpu.pas

+ 10 - 3
compiler/x86/cgx86.pas

@@ -3146,9 +3146,16 @@ unit cgx86;
         var
           href : treference;
         begin
-          reference_reset_base(href,NR_STACK_POINTER_REG,-a,ctempposinvalid,0,[]);
-          { normally, lea is a better choice than a sub to adjust the stack pointer }
-          list.concat(Taicpu.op_ref_reg(A_LEA,TCGSize2OpSize[OS_ADDR],href,NR_STACK_POINTER_REG));
+{$ifdef x86_64}
+          if localsize=8 then
+            list.concat(Taicpu.op_reg(A_PUSH,TCGSize2OpSize[OS_ADDR],NR_RAX))
+          else
+{$endif x86_64}
+            begin
+              reference_reset_base(href,NR_STACK_POINTER_REG,-a,ctempposinvalid,0,[]);
+              { normally, lea is a better choice than a sub to adjust the stack pointer }
+              list.concat(Taicpu.op_ref_reg(A_LEA,TCGSize2OpSize[OS_ADDR],href,NR_STACK_POINTER_REG));
+            end;
         end;
 
 {$ifdef x86}

+ 8 - 3
compiler/x86_64/cgcpu.pas

@@ -353,9 +353,14 @@ unit cgcpu;
         var
           href : treference;
         begin
-          reference_reset_base(href,NR_STACK_POINTER_REG,a,ctempposinvalid,0,[]);
-          { normally, lea is a better choice than an add }
-          list.concat(Taicpu.op_ref_reg(A_LEA,TCGSize2OpSize[OS_ADDR],href,NR_STACK_POINTER_REG));
+          if a=8 then
+            list.concat(Taicpu.op_reg(A_POP,TCGSize2OpSize[OS_ADDR],NR_RCX))
+          else
+            begin
+              reference_reset_base(href,NR_STACK_POINTER_REG,a,ctempposinvalid,0,[]);
+              { normally, lea is a better choice than an add }
+              list.concat(Taicpu.op_ref_reg(A_LEA,TCGSize2OpSize[OS_ADDR],href,NR_STACK_POINTER_REG));
+            end;
         end;
 
       var