// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "include/v8stdint.h"
-#include "src/utils.h"
+#include "src/v8.h"
+
#include "src/bignum.h"
+#include "src/utils.h"
namespace v8 {
namespace internal {
// Guaranteed to lie in one Bigit.
void Bignum::AssignUInt16(uint16_t value) {
- ASSERT(kBigitSize >= BitSize(value));
+ DCHECK(kBigitSize >= BitSize(value));
Zero();
if (value == 0) return;
uint64_t result = 0;
for (int i = from; i < from + digits_to_read; ++i) {
int digit = buffer[i] - '0';
- ASSERT(0 <= digit && digit <= 9);
+ DCHECK(0 <= digit && digit <= 9);
result = result * 10 + digit;
}
return result;
void Bignum::AddBignum(const Bignum& other) {
- ASSERT(IsClamped());
- ASSERT(other.IsClamped());
+ DCHECK(IsClamped());
+ DCHECK(other.IsClamped());
// If this has a greater exponent than other append zero-bigits to this.
// After this call exponent_ <= other.exponent_.
EnsureCapacity(1 + Max(BigitLength(), other.BigitLength()) - exponent_);
Chunk carry = 0;
int bigit_pos = other.exponent_ - exponent_;
- ASSERT(bigit_pos >= 0);
+ DCHECK(bigit_pos >= 0);
for (int i = 0; i < other.used_digits_; ++i) {
Chunk sum = bigits_[bigit_pos] + other.bigits_[i] + carry;
bigits_[bigit_pos] = sum & kBigitMask;
bigit_pos++;
}
used_digits_ = Max(bigit_pos, used_digits_);
- ASSERT(IsClamped());
+ DCHECK(IsClamped());
}
void Bignum::SubtractBignum(const Bignum& other) {
- ASSERT(IsClamped());
- ASSERT(other.IsClamped());
+ DCHECK(IsClamped());
+ DCHECK(other.IsClamped());
// We require this to be bigger than other.
- ASSERT(LessEqual(other, *this));
+ DCHECK(LessEqual(other, *this));
Align(other);
Chunk borrow = 0;
int i;
for (i = 0; i < other.used_digits_; ++i) {
- ASSERT((borrow == 0) || (borrow == 1));
+ DCHECK((borrow == 0) || (borrow == 1));
Chunk difference = bigits_[i + offset] - other.bigits_[i] - borrow;
bigits_[i + offset] = difference & kBigitMask;
borrow = difference >> (kChunkSize - 1);
// The product of a bigit with the factor is of size kBigitSize + 32.
// Assert that this number + 1 (for the carry) fits into double chunk.
- ASSERT(kDoubleChunkSize >= kBigitSize + 32 + 1);
+ DCHECK(kDoubleChunkSize >= kBigitSize + 32 + 1);
DoubleChunk carry = 0;
for (int i = 0; i < used_digits_; ++i) {
DoubleChunk product = static_cast<DoubleChunk>(factor) * bigits_[i] + carry;
Zero();
return;
}
- ASSERT(kBigitSize < 32);
+ DCHECK(kBigitSize < 32);
uint64_t carry = 0;
uint64_t low = factor & 0xFFFFFFFF;
uint64_t high = factor >> 32;
{ kFive1, kFive2, kFive3, kFive4, kFive5, kFive6,
kFive7, kFive8, kFive9, kFive10, kFive11, kFive12 };
- ASSERT(exponent >= 0);
+ DCHECK(exponent >= 0);
if (exponent == 0) return;
if (used_digits_ == 0) return;
void Bignum::Square() {
- ASSERT(IsClamped());
+ DCHECK(IsClamped());
int product_length = 2 * used_digits_;
EnsureCapacity(product_length);
}
// Since the result was guaranteed to lie inside the number the
// accumulator must be 0 now.
- ASSERT(accumulator == 0);
+ DCHECK(accumulator == 0);
// Don't forget to update the used_digits and the exponent.
used_digits_ = product_length;
void Bignum::AssignPowerUInt16(uint16_t base, int power_exponent) {
- ASSERT(base != 0);
- ASSERT(power_exponent >= 0);
+ DCHECK(base != 0);
+ DCHECK(power_exponent >= 0);
if (power_exponent == 0) {
AssignUInt16(1);
return;
// Precondition: this/other < 16bit.
uint16_t Bignum::DivideModuloIntBignum(const Bignum& other) {
- ASSERT(IsClamped());
- ASSERT(other.IsClamped());
- ASSERT(other.used_digits_ > 0);
+ DCHECK(IsClamped());
+ DCHECK(other.IsClamped());
+ DCHECK(other.used_digits_ > 0);
// Easy case: if we have less digits than the divisor than the result is 0.
// Note: this handles the case where this == 0, too.
// This naive approach is extremely inefficient if the this divided other
// might be big. This function is implemented for doubleToString where
// the result should be small (less than 10).
- ASSERT(other.bigits_[other.used_digits_ - 1] >= ((1 << kBigitSize) / 16));
+ DCHECK(other.bigits_[other.used_digits_ - 1] >= ((1 << kBigitSize) / 16));
// Remove the multiples of the first digit.
// Example this = 23 and other equals 9. -> Remove 2 multiples.
result += bigits_[used_digits_ - 1];
SubtractTimes(other, bigits_[used_digits_ - 1]);
}
- ASSERT(BigitLength() == other.BigitLength());
+ DCHECK(BigitLength() == other.BigitLength());
// Both bignums are at the same length now.
// Since other has more than 0 digits we know that the access to
template<typename S>
static int SizeInHexChars(S number) {
- ASSERT(number > 0);
+ DCHECK(number > 0);
int result = 0;
while (number != 0) {
number >>= 4;
static char HexCharOfValue(int value) {
- ASSERT(0 <= value && value <= 16);
+ DCHECK(0 <= value && value <= 16);
if (value < 10) return value + '0';
return value - 10 + 'A';
}
bool Bignum::ToHexString(char* buffer, int buffer_size) const {
- ASSERT(IsClamped());
+ DCHECK(IsClamped());
// Each bigit must be printable as separate hex-character.
- ASSERT(kBigitSize % 4 == 0);
+ DCHECK(kBigitSize % 4 == 0);
const int kHexCharsPerBigit = kBigitSize / 4;
if (used_digits_ == 0) {
int Bignum::Compare(const Bignum& a, const Bignum& b) {
- ASSERT(a.IsClamped());
- ASSERT(b.IsClamped());
+ DCHECK(a.IsClamped());
+ DCHECK(b.IsClamped());
int bigit_length_a = a.BigitLength();
int bigit_length_b = b.BigitLength();
if (bigit_length_a < bigit_length_b) return -1;
int Bignum::PlusCompare(const Bignum& a, const Bignum& b, const Bignum& c) {
- ASSERT(a.IsClamped());
- ASSERT(b.IsClamped());
- ASSERT(c.IsClamped());
+ DCHECK(a.IsClamped());
+ DCHECK(b.IsClamped());
+ DCHECK(c.IsClamped());
if (a.BigitLength() < b.BigitLength()) {
return PlusCompare(b, a, c);
}
}
used_digits_ += zero_digits;
exponent_ -= zero_digits;
- ASSERT(used_digits_ >= 0);
- ASSERT(exponent_ >= 0);
+ DCHECK(used_digits_ >= 0);
+ DCHECK(exponent_ >= 0);
}
}
void Bignum::BigitsShiftLeft(int shift_amount) {
- ASSERT(shift_amount < kBigitSize);
- ASSERT(shift_amount >= 0);
+ DCHECK(shift_amount < kBigitSize);
+ DCHECK(shift_amount >= 0);
Chunk carry = 0;
for (int i = 0; i < used_digits_; ++i) {
Chunk new_carry = bigits_[i] >> (kBigitSize - shift_amount);
b.MultiplyByUInt32(factor);
a.SubtractBignum(b);
#endif
- ASSERT(exponent_ <= other.exponent_);
+ DCHECK(exponent_ <= other.exponent_);
if (factor < 3) {
for (int i = 0; i < factor; ++i) {
SubtractBignum(other);
borrow = difference >> (kChunkSize - 1);
}
Clamp();
- ASSERT(Bignum::Equal(a, *this));
+ DCHECK(Bignum::Equal(a, *this));
}