# HG changeset patch # User Gilles Duboscq # Date 1371201368 -7200 # Node ID 9645cfaffc62504e7464ff0213f07db7e6aca1aa # Parent 91b9c3f0100a39a9142f2107bb3f469b1ed6eba4 CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE. CodeUtil.log2 should work even for numbers that are not powers of 2 diff -r 91b9c3f0100a -r 9645cfaffc62 graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java --- a/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Fri Jun 14 09:29:10 2013 +0200 +++ b/graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java Fri Jun 14 11:16:08 2013 +0200 @@ -53,7 +53,7 @@ * @return {@code true} if the value is a power of two; {@code false} otherwise */ public static boolean isPowerOf2(int val) { - return val != 0 && (val & val - 1) == 0; + return val > 0 && (val & val - 1) == 0; } /** @@ -63,7 +63,7 @@ * @return {@code true} if the value is a power of two; {@code false} otherwise */ public static boolean isPowerOf2(long val) { - return val != 0 && (val & val - 1) == 0; + return val > 0 && (val & val - 1) == 0; } /** @@ -74,7 +74,7 @@ * @return the log base 2 of the value */ public static int log2(int val) { - assert val > 0 && isPowerOf2(val); + assert val > 0; return 31 - Integer.numberOfLeadingZeros(val); } @@ -86,7 +86,7 @@ * @return the log base 2 of the value */ public static int log2(long val) { - assert val > 0 && isPowerOf2(val); + assert val > 0; return 63 - Long.numberOfLeadingZeros(val); }