Browse Source

* simplifications by Rika (*2 loops => shl/Bsr), resolves #39717

florian 3 years ago
parent
commit
4f9c19d943
2 changed files with 66 additions and 86 deletions
  1. 7 18
      compiler/raatt.pas
  2. 59 68
      compiler/rgobj.pas

+ 7 - 18
compiler/raatt.pas

@@ -1070,7 +1070,6 @@ unit raatt;
        symval     ,sectionname: string;
        symval     ,sectionname: string;
        lasTSec    : TAsmSectiontype;
        lasTSec    : TAsmSectiontype;
        l1,
        l1,
-       l2,
        l3,
        l3,
        l4,
        l4,
        symofs     : tcgint;
        symofs     : tcgint;
@@ -1221,16 +1220,10 @@ unit raatt;
                Consume(AS_ALIGN);
                Consume(AS_ALIGN);
                l1:=BuildConstExpression(false,false);
                l1:=BuildConstExpression(false,false);
                if (target_info.system in [system_i386_GO32V2]) then
                if (target_info.system in [system_i386_GO32V2]) then
-                 begin
-                    l2:=1;
-                    if (l1>=0) and (l1<=16) then
-                      while (l1>0) do
-                        begin
-                          l2:=2*l2;
-                          dec(l1);
-                        end;
-                    l1:=l2;
-                 end;
+                 if (l1>=0) and (l1<=16) then
+                   l1:=tcgint(1) shl l1
+                 else
+                   l1:=1;
                ConcatAlign(curlist,l1);
                ConcatAlign(curlist,l1);
                Message(asmr_n_align_is_target_specific);
                Message(asmr_n_align_is_target_specific);
                if actasmtoken<>AS_SEPARATOR then
                if actasmtoken<>AS_SEPARATOR then
@@ -1249,14 +1242,10 @@ unit raatt;
              Begin
              Begin
                Consume(AS_P2ALIGN);
                Consume(AS_P2ALIGN);
                l1:=BuildConstExpression(false,false);
                l1:=BuildConstExpression(false,false);
-               l2:=1;
                if (l1>=0) and (l1<=16) then
                if (l1>=0) and (l1<=16) then
-                 while (l1>0) do
-                   begin
-                      l2:=2*l2;
-                      dec(l1);
-                   end;
-               l1:=l2;
+                 l1:=tcgint(1) shl l1
+               else
+                 l1:=1;
                if actasmtoken=AS_COMMA then
                if actasmtoken=AS_COMMA then
                  begin
                  begin
                    Consume(AS_COMMA);
                    Consume(AS_COMMA);

+ 59 - 68
compiler/rgobj.pas

@@ -339,25 +339,22 @@ unit rgobj;
         begin
         begin
           if header.count<2 then
           if header.count<2 then
             exit;
             exit;
-          p:=1;
-          while 2*cardinal(p)<header.count do
-            p:=2*p;
-          while p<>0 do
-            begin
-              for h:=p to header.count-1 do
-                begin
-                  i:=h;
-                  t:=data[i];
-                  repeat
-                    if data[i-p].id<=t.id then
-                      break;
-                    data[i]:=data[i-p];
-                    dec(i,p);
-                  until i<p;
-                  data[i]:=t;
-                end;
-              p:=p shr 1;
-            end;
+          p:=longword(1) shl BsrDWord(header.count-1);
+          repeat
+            for h:=p to header.count-1 do
+              begin
+                i:=h;
+                t:=data[i];
+                repeat
+                  if data[i-p].id<=t.id then
+                    break;
+                  data[i]:=data[i-p];
+                  dec(i,p);
+                until i<p;
+                data[i]:=t;
+              end;
+            p:=p shr 1;
+          until p=0;
           header.sorted_until:=header.count-1;
           header.sorted_until:=header.count-1;
         end;
         end;
     end;
     end;
@@ -1013,11 +1010,47 @@ unit rgobj;
         begin
         begin
           if length<2 then
           if length<2 then
             exit;
             exit;
-          p:=1;
-          while 2*p<length do
-            p:=2*p;
-          while p<>0 do
-            begin
+          p:=longword(1) shl BsrDWord(length-1);
+          repeat
+            for h:=p to length-1 do
+              begin
+                i:=h;
+                t:=buf^[i];
+                adjt:=reginfo[buf^[i]].adjlist;
+                lent:=0;
+                if adjt<>nil then
+                  lent:=adjt^.length;
+                repeat
+                  adji:=reginfo[buf^[i-p]].adjlist;
+                  leni:=0;
+                  if adji<>nil then
+                    leni:=adji^.length;
+                  if leni>=lent then
+                    break;
+                  buf^[i]:=buf^[i-p];
+                  dec(i,p)
+                until i<p;
+                buf^[i]:=t;
+              end;
+            p:=p shr 1;
+          until p=0;
+        end;
+    end;
+
+
+    { sort spilled nodes by increasing number of interferences }
+    procedure Trgobj.sort_spillednodes;
+      var
+        p,h,i,leni,lent:longword;
+        t:Tsuperregister;
+        adji,adjt:Psuperregisterworklist;
+      begin
+        with spillednodes do
+          begin
+            if length<2 then
+              exit;
+            p:=longword(1) shl BsrDWord(length-1);
+            repeat
               for h:=p to length-1 do
               for h:=p to length-1 do
                 begin
                 begin
                   i:=h;
                   i:=h;
@@ -1031,7 +1064,7 @@ unit rgobj;
                     leni:=0;
                     leni:=0;
                     if adji<>nil then
                     if adji<>nil then
                       leni:=adji^.length;
                       leni:=adji^.length;
-                    if leni>=lent then
+                    if leni<=lent then
                       break;
                       break;
                     buf^[i]:=buf^[i-p];
                     buf^[i]:=buf^[i-p];
                     dec(i,p)
                     dec(i,p)
@@ -1039,49 +1072,7 @@ unit rgobj;
                   buf^[i]:=t;
                   buf^[i]:=t;
                 end;
                 end;
               p:=p shr 1;
               p:=p shr 1;
-            end;
-        end;
-    end;
-
-
-    { sort spilled nodes by increasing number of interferences }
-    procedure Trgobj.sort_spillednodes;
-      var
-        p,h,i,leni,lent:longword;
-        t:Tsuperregister;
-        adji,adjt:Psuperregisterworklist;
-      begin
-        with spillednodes do
-          begin
-            if length<2 then
-              exit;
-            p:=1;
-            while 2*p<length do
-              p:=2*p;
-            while p<>0 do
-              begin
-                for h:=p to length-1 do
-                  begin
-                    i:=h;
-                    t:=buf^[i];
-                    adjt:=reginfo[buf^[i]].adjlist;
-                    lent:=0;
-                    if adjt<>nil then
-                      lent:=adjt^.length;
-                    repeat
-                      adji:=reginfo[buf^[i-p]].adjlist;
-                      leni:=0;
-                      if adji<>nil then
-                        leni:=adji^.length;
-                      if leni<=lent then
-                        break;
-                      buf^[i]:=buf^[i-p];
-                      dec(i,p)
-                    until i<p;
-                    buf^[i]:=t;
-                  end;
-                p:=p shr 1;
-              end;
+            until p=0;
           end;
           end;
       end;
       end;