aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEtienne Bergeron2013-12-03 06:47:51 (EST)
committerMatthew Khouzam2013-12-06 07:55:35 (EST)
commit3c74d845ebdceead69be310e802b3b468cf713da (patch)
tree5e259c4e337c166f3c2525558a79e90994bbf810
parent3eff651d4c6fea2e420556f185eda47707b2fa6d (diff)
downloadorg.eclipse.linuxtools-3c74d845ebdceead69be310e802b3b468cf713da.zip
org.eclipse.linuxtools-3c74d845ebdceead69be310e802b3b468cf713da.tar.gz
org.eclipse.linuxtools-3c74d845ebdceead69be310e802b3b468cf713da.tar.bz2
ctf: simplify getMinValue/getMaxValue computation.refs/changes/16/19416/2
The BigNumber divide is useless in this case. Change-Id: Ibec0c081430b93ff4873db3bf9de3a2eece76f29 Signed-off-by: Etienne Bergeron <etienne.bergeron@gmail.com> Signed-off-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Reviewed-on: https://git.eclipse.org/r/19416 Tested-by: Hudson CI
-rw-r--r--lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java45
1 files changed, 34 insertions, 11 deletions
diff --git a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
index 3f6ded3..5e2ba99 100644
--- a/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
+++ b/lttng/org.eclipse.linuxtools.ctf.core/src/org/eclipse/linuxtools/ctf/core/event/types/IntegerDeclaration.java
@@ -82,6 +82,7 @@ public class IntegerDeclaration implements IDeclaration {
/**
* Is the integer signed?
+ *
* @return the is the integer signed
*/
public boolean isSigned() {
@@ -90,6 +91,7 @@ public class IntegerDeclaration implements IDeclaration {
/**
* Get the integer base commonly decimal or hex
+ *
* @return the integer base
*/
public int getBase() {
@@ -97,7 +99,8 @@ public class IntegerDeclaration implements IDeclaration {
}
/**
- * Gets the byte order
+ * Get the byte order
+ *
* @return the byte order
*/
public ByteOrder getByteOrder() {
@@ -106,6 +109,7 @@ public class IntegerDeclaration implements IDeclaration {
/**
* Get encoding, chars are 8 bit ints
+ *
* @return the encoding
*/
public Encoding getEncoding() {
@@ -114,16 +118,18 @@ public class IntegerDeclaration implements IDeclaration {
/**
* Is the integer a character (8 bits and encoded?)
+ *
* @return is the integer a char
*/
- public boolean isCharacter() {
+ public boolean isCharacter() {
return (length == 8) && (encoding != Encoding.NONE);
}
- /**
- * How many bits is this int
- * @return the length of the int
- */
+ /**
+ * Get the length in bits for this integer
+ *
+ * @return the length of the integer
+ */
public int getLength() {
return length;
}
@@ -135,11 +141,13 @@ public class IntegerDeclaration implements IDeclaration {
/**
* The integer's clock, since timestamps are stored in ints
+ *
* @return the integer's clock, can be null. (most often it is)
*/
public String getClock() {
return clock;
}
+
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@@ -163,9 +171,16 @@ public class IntegerDeclaration implements IDeclaration {
* @since 2.0
*/
public BigInteger getMaxValue() {
- BigInteger capacity = BigInteger.ONE.shiftLeft(length);
- BigInteger max = signed ? capacity.divide(BigInteger.valueOf(2)) : capacity;
- return max.subtract(BigInteger.ONE);
+ /*
+ * Compute the number of bits able to represent an unsigned number,
+ * ignoring sign bit.
+ */
+ int significant_bits = length - (signed ? 1 : 0);
+ /*
+ * For a given N significant bits, compute the maximal value which is
+ * (1 << N) - 1.
+ */
+ return BigInteger.ONE.shiftLeft(significant_bits).subtract(BigInteger.ONE);
}
/**
@@ -179,8 +194,16 @@ public class IntegerDeclaration implements IDeclaration {
return BigInteger.ZERO;
}
- BigInteger capacity = BigInteger.ONE.shiftLeft(length);
- return capacity.divide(BigInteger.valueOf(2)).negate();
+ /*
+ * Compute the number of bits able to represent an unsigned number,
+ * without the sign bit.
+ */
+ int significant_bits = length - 1;
+ /*
+ * For a given N significant bits, compute the minimal value which is
+ * - (1 << N).
+ */
+ return BigInteger.ONE.shiftLeft(significant_bits).negate();
}
}