Browse Source

New POPCNT tests to evaluate new optimisations

J. Gareth "Curious Kit" Moreton 3 years ago
parent
commit
fd54c958c9
2 changed files with 46 additions and 0 deletions
  1. 26 0
      tests/test/opt/tpopcnt1.pp
  2. 20 0
      tests/test/opt/tpopcnt2.pp

+ 26 - 0
tests/test/opt/tpopcnt1.pp

@@ -0,0 +1,26 @@
+{ %CPU=i386,x86_64 }
+{ %OPT=-O2 -CpCOREAVX }
+
+var
+  X: LongWord;
+begin
+  for X := 0 to 9 do
+    if PopCnt(X) = 0 then
+      begin
+        if X <> 0 then
+          begin
+            WriteLn('FAIL: PopCnt(', X, ') = 0 returned True');
+            Halt(1);
+          end;
+      end
+    else
+      begin
+        if X = 0 then
+          begin
+            WriteLn('FAIL: PopCnt(0) = 0 returned False');
+            Halt(1);
+          end;
+      end;
+
+  WriteLn('ok');
+end.

+ 20 - 0
tests/test/opt/tpopcnt2.pp

@@ -0,0 +1,20 @@
+{ %CPU=i386,x86_64 }
+{ %OPT=-O2 -CpCOREAVX }
+
+var
+  X, Y: LongWord;
+begin
+  for X := 0 to 9 do
+    begin
+      Y := PopCnt(X);
+      { Condition arranged this way so the input of PopCnt is checked first.
+        If both X and Y are zero or both X and Y are not zero, then all is well. }
+      if (X = 0) xor (Y = 0) then
+        begin
+          WriteLn('FAIL: Condition implies PopCnt(', X, ') = ', Y, ' and not ', PopCnt(X));
+          Halt(1);
+        end;
+    end;
+
+  WriteLn('ok');
+end.