Browse Source

+ perform unsigned modulus by power of 2 constant by using an AND instruction (instead of DIV) on x86

git-svn-id: trunk@36756 -
nickysn 8 years ago
parent
commit
7c306f18e3
1 changed files with 8 additions and 0 deletions
  1. 8 0
      compiler/x86/nx86mat.pas

+ 8 - 0
compiler/x86/nx86mat.pas

@@ -510,6 +510,14 @@ interface
                   end;
               end;
           end
+        { unsigned modulus by a power-of-2 constant? }
+        else if (nodetype=modn) and (right.nodetype=ordconstn) and
+                ispowerof2(tordconstnode(right).value,power) and
+                not(is_signed(left.resultdef)) then
+          begin
+            emit_const_reg(A_AND,opsize,(aint(1) shl power)-1,hreg1);
+            location.register:=hreg1;
+          end
         else
           begin
             {Bring denominator to a register.}