Mercurial > hg > truffle
changeset 10038:9645cfaffc62
CodeUtil.isPowerOf2 should not return true for Integer/Long.MIN_VALUE.
CodeUtil.log2 should work even for numbers that are not powers of 2
author | Gilles Duboscq <duboscq@ssw.jku.at> |
---|---|
date | Fri, 14 Jun 2013 11:16:08 +0200 |
parents | 91b9c3f0100a |
children | 92cbc5e88484 |
files | graal/com.oracle.graal.api.code/src/com/oracle/graal/api/code/CodeUtil.java |
diffstat | 1 files changed, 4 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- 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); }