Преглед на файлове

+ Tconstexprint-version of ispowerof2() to correctly deal with constants
> high(int64) (mantis #29620)

git-svn-id: trunk@33191 -

Jonas Maebe преди 9 години
родител
ревизия
315b32918e
променени са 3 файла, в които са добавени 30 реда и са изтрити 0 реда
  1. 1 0
      .gitattributes
  2. 17 0
      compiler/cutils.pas
  3. 12 0
      tests/webtbs/tw29620.pp

+ 1 - 0
.gitattributes

@@ -14970,6 +14970,7 @@ tests/webtbs/tw2956.pp svneol=native#text/plain
 tests/webtbs/tw2958.pp svneol=native#text/plain
 tests/webtbs/tw29585.pp svneol=native#text/plain
 tests/webtbs/tw29609.pp svneol=native#text/pascal
+tests/webtbs/tw29620.pp svneol=native#text/plain
 tests/webtbs/tw2966.pp svneol=native#text/plain
 tests/webtbs/tw29669.pp svneol=native#text/plain
 tests/webtbs/tw29669a.pp svneol=native#text/plain

+ 17 - 0
compiler/cutils.pas

@@ -103,6 +103,7 @@ interface
        exponent value is returned in power.
     }
     function ispowerof2(value : int64;out power : longint) : boolean;
+    function ispowerof2(value : Tconstexprint;out power : longint) : boolean;
     function nextpowerof2(value : int64; out power: longint) : int64;
 {$ifdef VER2_6}  { only 2.7.1+ has a popcnt function in the system unit }
     function PopCnt(AValue : Byte): Byte;
@@ -866,6 +867,22 @@ implementation
       end;
 
 
+    function ispowerof2(value: Tconstexprint; out power: longint): boolean;
+      begin
+        if value.signed or
+           (value.uvalue<=high(int64)) then
+          result:=ispowerof2(value.svalue,power)
+        else if not value.signed and
+            (value.svalue=low(int64)) then
+          begin
+            result:=true;
+            power:=63;
+          end
+        else
+          result:=false;
+      end;
+
+
     function nextpowerof2(value : int64; out power: longint) : int64;
     {
       returns the power of 2 >= value

+ 12 - 0
tests/webtbs/tw29620.pp

@@ -0,0 +1,12 @@
+var x:uint64;
+    y:longword;
+begin
+ y:=123;
+ x:=y*uint64(10116239910488455739);
+ if x<>8365656051540097625 then
+   halt(1);
+ x:=y*uint64($8000000000000000);
+ if x<>(uint64(123) shl 63) then
+   halt(2);
+end.
+