Commits

Hakan Ardo  committed 23117ab

simplified the check to see if the value is a power of 2

  • Participants
  • Parent commits c339496
  • Branches jit-int

Comments (0)

Files changed (1)

File pypy/jit/metainterp/optimizeopt/rewrite.py

 
         if v1.intbound.known_ge(IntBound(0, 0)) and v2.is_constant():
             val = v2.box.getint()
-            shift = 0
-            while (1 << shift) < val:
-                shift += 1
-            if (1 << shift) == val:
+            if val & (val - 1) == 0 and val > 0: # val == 2**shift
+                shift = 0
+                while (1 << shift) < val:
+                    shift += 1
                 op = op.copy_and_change(rop.INT_RSHIFT,
                                         args = [op.getarg(0), ConstInt(shift)])
         self.emit_operation(op)