5 #ifndef V8_OBJECTS_BIGINT_H_ 6 #define V8_OBJECTS_BIGINT_H_ 8 #include "src/globals.h" 9 #include "src/objects.h" 10 #include "src/utils.h" 13 #include "src/objects/object-macros.h" 19 class ValueDeserializer;
20 class ValueSerializer;
26 inline int length()
const {
27 intptr_t bitfield = RELAXED_READ_INTPTR_FIELD(
this, kBitfieldOffset);
28 return LengthBits::decode(static_cast<uint32_t>(bitfield));
32 inline int synchronized_length()
const {
33 intptr_t bitfield = ACQUIRE_READ_INTPTR_FIELD(
this, kBitfieldOffset);
34 return LengthBits::decode(static_cast<uint32_t>(bitfield));
38 static const int kMaxLengthBits = kMaxInt - kPointerSize * kBitsPerByte - 1;
39 static const int kMaxLength = kMaxLengthBits / (kPointerSize * kBitsPerByte);
43 static const int kLengthFieldBits = 30;
44 STATIC_ASSERT(kMaxLength <= ((1 << kLengthFieldBits) - 1));
47 STATIC_ASSERT(LengthBits::kNext <= 32);
49 static const int kBitfieldOffset = HeapObject::kHeaderSize;
50 static const int kDigitsOffset = kBitfieldOffset + kPointerSize;
51 static const int kHeaderSize = kDigitsOffset;
54 friend class ::v8::internal::BigInt;
58 static const int kDigitSize =
sizeof(
digit_t);
60 STATIC_ASSERT(kDigitSize == kPointerSize);
62 static const int kDigitBits = kDigitSize * kBitsPerByte;
63 static const int kHalfDigitBits = kDigitBits / 2;
64 static const digit_t kHalfDigitMask = (1ull << kHalfDigitBits) - 1;
67 inline bool sign()
const {
68 intptr_t bitfield = RELAXED_READ_INTPTR_FIELD(
this, kBitfieldOffset);
69 return SignBits::decode(static_cast<uint32_t>(bitfield));
72 inline digit_t digit(
int n)
const {
73 SLOW_DCHECK(0 <= n && n < length());
74 Address address = FIELD_ADDR(
this, kDigitsOffset + n * kDigitSize);
75 return *
reinterpret_cast<digit_t*
>(address);
78 bool is_zero()
const {
return length() == 0; }
80 DISALLOW_IMPLICIT_CONSTRUCTORS(BigIntBase);
145 bool ToBoolean() {
return !is_zero(); }
148 return is_zero() ? 0 : ComputeLongHash(static_cast<uint64_t>(digit(0)));
158 static ComparisonResult CompareToDouble(
Handle<BigInt> x,
double y);
168 const uint64_t* words);
169 int64_t AsInt64(
bool* lossless =
nullptr);
170 uint64_t AsUint64(
bool* lossless =
nullptr);
172 void ToWordsArray64(
int* sign_bit,
int* words64_count, uint64_t* words);
177 void BigIntShortPrint(std::ostream& os);
179 inline static int SizeFor(
int length) {
180 return kHeaderSize + length * kDigitSize;
185 ShouldThrow should_throw = kThrowOnError);
208 Isolate* isolate,
int radix,
int charcount, ShouldThrow should_throw,
209 PretenureFlag pretenure);
215 uint32_t GetBitfieldForSerialization()
const;
216 static int DigitsByteLengthForBitfield(
uint32_t bitfield);
219 void SerializeDigits(uint8_t* storage);
222 PretenureFlag pretenure);
224 DISALLOW_IMPLICIT_CONSTRUCTORS(
BigInt);
230 #include "src/objects/object-macros-undef.h" 232 #endif // V8_OBJECTS_BIGINT_H_