Browse Source

+ added compile time const evaluation optimization for PopCnt(const)

git-svn-id: trunk@35937 -
nickysn 8 years ago
parent
commit
32395bbcbb
3 changed files with 111 additions and 0 deletions
  1. 1 0
      .gitattributes
  2. 7 0
      compiler/ninl.pas
  3. 103 0
      tests/test/tpopcnt2.pp

+ 1 - 0
.gitattributes

@@ -13006,6 +13006,7 @@ tests/test/tpointermath2.pp svneol=native#text/pascal
 tests/test/tpointermath3.pp svneol=native#text/pascal
 tests/test/tpointermath3.pp svneol=native#text/pascal
 tests/test/tpoll.pp svneol=native#text/plain
 tests/test/tpoll.pp svneol=native#text/plain
 tests/test/tpopcnt1.pp svneol=native#text/pascal
 tests/test/tpopcnt1.pp svneol=native#text/pascal
+tests/test/tpopcnt2.pp svneol=native#text/pascal
 tests/test/tprec1.pp svneol=native#text/plain
 tests/test/tprec1.pp svneol=native#text/plain
 tests/test/tprec10.pp svneol=native#text/plain
 tests/test/tprec10.pp svneol=native#text/plain
 tests/test/tprec11.pp svneol=native#text/plain
 tests/test/tprec11.pp svneol=native#text/plain

+ 7 - 0
compiler/ninl.pas

@@ -2534,6 +2534,13 @@ implementation
               in_ror_x,
               in_ror_x,
               in_ror_x_y :
               in_ror_x_y :
                 result:=handle_const_rox;
                 result:=handle_const_rox;
+              in_popcnt_x :
+                begin
+                  if left.nodetype=ordconstn then
+                    begin
+                      result:=cordconstnode.create(PopCnt(tordconstnode(left).value),resultdef,false);
+                    end;
+                end;
             end;
             end;
           end;
           end;
       end;
       end;

+ 103 - 0
tests/test/tpopcnt2.pp

@@ -0,0 +1,103 @@
+begin
+  { 8 Bit }
+
+  if popcnt(byte($a4))<>3 then
+    halt(1);
+
+  if popcnt(byte($0))<>0 then
+    halt(1);
+
+  if popcnt(byte($20))<>1 then
+    halt(1);
+
+  writeln('popcnt(<byte>); passed');
+
+{
+  if popcnt(shortint($54))<>3 then
+    halt(1);
+
+  if popcnt(shortint($0))<>0 then
+    halt(1);
+
+  if popcnt(shortint($20))<>1 then
+    halt(1);
+}
+
+  { 16 Bit }
+
+  if popcnt(word($a4a4))<>6 then
+    halt(1);
+
+  if popcnt(word($0))<>0 then
+    halt(1);
+
+  if popcnt(word($2020))<>2 then
+    halt(1);
+
+  writeln('popcnt(<word>); passed');
+
+{
+  if popcnt(integer($5454))<>6 then
+    halt(1);
+
+  if popcnt(integer($0))<>0 then
+    halt(1);
+
+  if popcnt(integer($2020))<>2 then
+    halt(1);
+}
+
+  { 32 Bit }
+
+  if popcnt(dword($a4a4a4a4))<>12 then
+    halt(1);
+
+  if popcnt(dword($0))<>0 then
+    halt(1);
+
+  if popcnt(dword($20402040))<>4 then
+    halt(1);
+
+  writeln('popcnt(<dword>); passed');
+
+{
+  if popcnt(longint($54545454))<>12 then
+    halt(1);
+
+  if popcnt(longint($0))<>0 then
+    halt(1);
+
+  if popcnt(longint($20402080))<>4 then
+    halt(1);
+}
+
+  { 64 Bit }
+
+  if popcnt(qword($a4a4a4a4a4a4a4a4))<>24 then
+    halt(1);
+
+  if popcnt(qword($0))<>0 then
+    halt(1);
+
+  if popcnt(qword($2040204080804001))<>8 then
+    halt(1);
+
+  if popcnt(qword($a4a4a4a400000000))<>12 then
+    halt(1);
+
+  writeln('popcnt(<qword>); passed');
+
+{
+  if popcnt(int64($5454545454545454))<>24 then
+    halt(1);
+
+  if popcnt(int64($0))<>0 then
+    halt(1);
+
+  if popcnt(int64($2040208020402080))<>8 then
+    halt(1);
+}
+
+  writeln('ok');
+end.
+