return BitVector(high - low + 1, d_value.extractBitRange(high - low + 1, low));
}
- /*
- Bitwise operations on BitVectors
+ /**
+ * Bitwise operations on BitVectors
*/
// xor
return BitVector(d_size, d_value.bitwiseNot());
}
- /*
- Arithmetic operations on BitVectors
+ /**
+ * Arithmetic operations on BitVectors
*/
}
/**
- * Total division function that returns 0 when the denominator is 0.
+ * Total division function that returns 2^d_size-1 (signed: -1) when the
+ * denominator is 0 (d_value / 0 = 2^d_size - 1)..
*/
BitVector unsignedDivTotal (const BitVector& y) const {
}
/**
- * Total division function that returns 0 when the denominator is 0.
+ * Total remainder function that returns d_value when the denominator is 0
+ * (d_value % 0 = d_value).
*/
BitVector unsignedRemTotal(const BitVector& y) const {
CheckArgument(d_size == y.d_size, y);
}
- /*
- Extend operations
+ /**
+ * Extend operations
*/
BitVector zeroExtend(unsigned amount) const {
return BitVector(d_size + amount, d_value);
}
}
- /*
- Shifts on BitVectors
+ /**
+ * Shifts on BitVectors
*/
BitVector leftShift(const BitVector& y) const {
if (y.d_value > Integer(d_size)) {
if (y.d_value == 0) {
return *this;
}
-
// making sure we don't lose information casting
CheckArgument(y.d_value < Integer(1).multiplyByPow2(32), y);
uint32_t amount = y.d_value.toUnsignedInt();
if(y.d_value > Integer(d_size)) {
return BitVector(d_size, Integer(0));
}
-
// making sure we don't lose information casting
CheckArgument(y.d_value < Integer(1).multiplyByPow2(32), y);
uint32_t amount = y.d_value.toUnsignedInt();
}
- /*
- Convenience functions
+ /**
+ * Convenience functions
*/
size_t hash() const {
return d_value;
}
+ /**
+ * Return Integer corresponding to two's complement interpretation of bv.
+ */
Integer toSignedInt() const {
- // returns Integer corresponding to two's complement interpretation of bv
unsigned size = d_size;
Integer sign_bit = d_value.extractBitRange(1,size-1);
Integer val = d_value.extractBitRange(size-1, 0);
}
/**
- Returns k is the integer is equal to 2^{k-1} and zero
- otherwise
- @return k if the integer is equal to 2^{k-1} and zero otherwise
+ * Return k if the integer is equal to 2^{k-1} and zero otherwise.
*/
unsigned isPow2() {
return d_value.isPow2();
}
private:
- /*
- Class invariants:
- * no overflows: 2^d_size < d_value
- * no negative numbers: d_value >= 0
+ /**
+ * Class invariants:
+ * - no overflows: 2^d_size < d_value
+ * - no negative numbers: d_value >= 0
*/
unsigned d_size;
Integer d_value;