浏览代码

Introduce CPU_BC_HAS_SIZE_LIMIT to limit acceptable range when looking for unconditional jump label, to remain eligible for exchange with conditional jump

Pierre Muller 1 月之前
父节点
当前提交
f061541bad
共有 3 个文件被更改,包括 27 次插入1 次删除
  1. 16 1
      compiler/aoptobj.pas
  2. 2 0
      compiler/fpcdefs.inc
  3. 9 0
      compiler/globals.pas

+ 16 - 1
compiler/aoptobj.pas

@@ -1261,13 +1261,28 @@ Unit AoptObj;
 
       class function TAOptObj.FindLabel(L: TasmLabel; Var hp: Tai): Boolean;
       Var TempP: Tai;
+{$ifdef CPU_BC_HAS_SIZE_LIMIT}
+         count: ASizeUInt;
+{$endif CPU_BC_HAS_SIZE_LIMIT}
       Begin
         TempP := hp;
+{$ifdef CPU_BC_HAS_SIZE_LIMIT}
+        count:=0;
+{$endif CPU_BC_HAS_SIZE_LIMIT}
         While Assigned(TempP) and
+{$ifdef CPU_BC_HAS_SIZE_LIMIT}
+	     (count < BC_max_distance) and
+{$endif CPU_BC_HAS_SIZE_LIMIT}
              (TempP.typ In SkipInstr + [ait_label,ait_align]) Do
           If (TempP.typ <> ait_Label) Or
              (Tai_label(TempP).labsym <> L)
-            Then GetNextInstruction(TempP, TempP)
+            Then
+               begin
+                 GetNextInstruction(TempP, TempP);
+{$ifdef CPU_BC_HAS_SIZE_LIMIT}
+		 inc(count);
+{$endif CPU_BC_HAS_SIZE_LIMIT}
+               end
             Else
               Begin
                 hp := TempP;

+ 2 - 0
compiler/fpcdefs.inc

@@ -183,6 +183,7 @@
   {$define cpurefshaveindexreg}
   {$define SUPPORT_SAFECALL}
   {$define SUPPORT_GET_FRAME}
+  {$define CPU_BC_HAS_SIZE_LIMIT}
 {$endif powerpc}
 
 {$ifdef powerpc64}
@@ -196,6 +197,7 @@
   {$define cpurefshaveindexreg}
   {$define cpuno32bitops}
   {$define SUPPORT_SAFECALL}
+  {$define CPU_BC_HAS_SIZE_LIMIT}
 {$endif powerpc64}
 
 {$ifdef arm}

+ 9 - 0
compiler/globals.pas

@@ -232,6 +232,15 @@ Const
 
     const
       LinkMapWeightDefault = 1000;
+{$ifdef CPU_BC_HAS_SIZE_LIMIT}
+    {$if defined(POWERPC) or defined(POWERPC64)}
+      { instructions are 4-byte long and relative jump distance
+        a signed 16-bit signed integer, code as
+        reduced by a small amount to avoid troubles
+        as distance can be modified by optimizations. }
+      BC_max_distance = ($8000 div 4) - $100;
+    {$endif}
+{$endif CPU_BC_HAS_SIZE_LIMIT}
 
     type
       TLinkRec = record