Browse Source

* x86: Some refactoring to use aoc_ForceNewIteration instead of manually advancing p

J. Gareth "Curious Kit" Moreton 2 years ago
parent
commit
b8933dd267
3 changed files with 96 additions and 3 deletions
  1. 46 0
      compiler/i386/aoptcpu.pas
  2. 4 3
      compiler/x86/aoptx86.pas
  3. 46 0
      compiler/x86_64/aoptcpu.pas

+ 46 - 0
compiler/i386/aoptcpu.pas

@@ -126,6 +126,22 @@ unit aoptcpu;
           end;
           Break;
         until False;
+
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;
 
 
@@ -300,6 +316,21 @@ unit aoptcpu;
           else
             ;
         end;
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;
 
 
@@ -402,6 +433,21 @@ unit aoptcpu;
           else
             ;
         end;
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;
 
 

+ 4 - 3
compiler/x86/aoptx86.pas

@@ -14612,9 +14612,10 @@ unit aoptx86;
                 taicpu(hp1).clearop(1);
                 taicpu(hp1).ops := 0;
 
-                { A change was made, but not with p, so move forward 1 }
-                p := tai(p.Next);
-                Result := True;
+                { A change was made, but not with p, so don't set Result, but
+                  notify the compiler that a change was made }
+                Include(OptsToCheck, aoc_ForceNewIteration);
+
                 Exit; { and -> btr won't happen because an opsize of S_W won't be optimised anyway }
               end;
           end;

+ 46 - 0
compiler/x86_64/aoptcpu.pas

@@ -63,6 +63,22 @@ uses
           else
             ;
         end;
+
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;
 
 
@@ -218,6 +234,21 @@ uses
           else
             ;
         end;
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;
 
 
@@ -270,6 +301,21 @@ uses
           else
             ;
         end;
+        { If this flag is set, something was optimised ahead of p, so move
+          ahead by 1 instruction but treat as if Result was set to True }
+        if aoc_ForceNewIteration in OptsToCheck then
+          begin
+            Exclude(OptsToCheck, aoc_ForceNewIteration);
+
+            if not Result then
+              begin
+                if (p.typ in SkipInstr) then
+                  UpdateUsedRegs(p);
+
+                p := tai(p.Next);
+                Result := True;
+              end;
+          end;
       end;