[pypy-svn] pypy jit-int: simplified the check to see if the value is a power of 2
hakanardo
commits-noreply at bitbucket.org
Sat Jan 8 13:13:05 CET 2011
Author: Hakan Ardo <hakan at debian.org>
Branch: jit-int
Changeset: r40489:23117ab3a187
Date: 2011-01-08 11:32 +0100
http://bitbucket.org/pypy/pypy/changeset/23117ab3a187/
Log: simplified the check to see if the value is a power of 2
diff --git a/pypy/jit/metainterp/optimizeopt/rewrite.py b/pypy/jit/metainterp/optimizeopt/rewrite.py
--- a/pypy/jit/metainterp/optimizeopt/rewrite.py
+++ b/pypy/jit/metainterp/optimizeopt/rewrite.py
@@ -386,10 +386,10 @@
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)
More information about the Pypy-commit
mailing list