Explorar el Código

Reworked ispowerof2 in cutils.pas

IsPowerOf2 now uses the BsfQWord intrinsic introduced in Freepascal 2.6,
instead of the old shl loop, to find the power.

git-svn-id: trunk@21771 -
masta hace 13 años
padre
commit
8001979f7e
Se han modificado 1 ficheros con 4 adiciones y 20 borrados
  1. 4 20
      compiler/cutils.pas

+ 4 - 20
compiler/cutils.pas

@@ -813,27 +813,11 @@ implementation
     {
       return if value is a power of 2. And if correct return the power
     }
-      var
-         hl : int64;
-         i : longint;
       begin
-         if value and (value - 1) <> 0 then
-           begin
-             ispowerof2 := false;
-             exit
-           end;
-         hl:=1;
-         ispowerof2:=true;
-         for i:=0 to 63 do
-           begin
-              if hl=value then
-                begin
-                   power:=i;
-                   exit;
-                end;
-              hl:=hl shl 1;
-           end;
-         ispowerof2:=false;
+        if (value = 0) or (value and (value - 1) <> 0) then
+          exit(false);
+        power:=BsfQWord(value);
+        result:=true;
       end;