+ Tconstexprint-version of ispowerof2() to correctly deal with constants

> high(int64) (mantis #29620)

git-svn-id: trunk@33191 -
This commit is contained in:
Jonas Maebe 2016-03-06 14:16:47 +00:00
parent 3e59c05ecc
commit 315b32918e
3 changed files with 30 additions and 0 deletions

1
.gitattributes vendored
View File

@ -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

View File

@ -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
tests/webtbs/tw29620.pp Normal file
View File

@ -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.