5#ifndef V8_BIGINT_BIGINT_H_
6#define V8_BIGINT_BIGINT_H_
21#define BIGINT_H_DCHECK(cond) \
23 std::cerr << __FILE__ << ":" << __LINE__ << ": "; \
24 std::cerr << "Assertion failed: " #cond "\n"; \
28extern bool kAdvancedAlgorithmsEnabledInLibrary;
30#define BIGINT_H_DCHECK(cond) (void(0))
36#if UINTPTR_MAX == 0xFFFFFFFF
38using twodigit_t = uint64_t;
39#define HAVE_TWODIGIT_T 1
40static constexpr int kLog2DigitBits = 5;
41#elif UINTPTR_MAX == 0xFFFFFFFFFFFFFFFF
43static constexpr int kLog2DigitBits = 6;
44#if defined(__SIZEOF_INT128__)
45using twodigit_t = __uint128_t;
46#define HAVE_TWODIGIT_T 1
49#error Unsupported platform.
100 return digits_ == other.digits_ &&
len_ == other.len_;
147#if UINTPTR_MAX == 0xFFFFFFFF
177 :
ptr_(reinterpret_cast<uint32_t*>(ptr)) {}
227 int diff = A.len() - B.len();
228 if (diff != 0)
return diff;
230 while (
i >= 0 && A[
i] == B[
i])
i--;
232 return A[
i] > B[
i] ? 1 : -1;
236void Add(RWDigits Z, Digits
X, Digits Y);
238bool AddSigned(RWDigits Z, Digits
X,
bool x_negative, Digits Y,
241void AddOne(RWDigits Z, Digits
X);
244void Subtract(RWDigits Z, Digits
X, Digits Y);
285class FromStringAccumulator;
322 return std::max(x_length, y_length) + 1;
326 : std::max(x_length, y_length);
331 return same_sign ? std::max(x_length, y_length)
335 return X.len() + Y.
len();
339#if V8_ADVANCED_BIGINT_ALGORITHMS
347 constexpr int kBarrettExtraScratch = 0;
349 return A.len() - B.len() + 1 + kBarrettExtraScratch;
373#if !defined(DEBUG) && (defined(__GNUC__) || defined(__clang__))
375#define ALWAYS_INLINE inline __attribute__((always_inline))
376#elif !defined(DEBUG) && defined(_MSC_VER)
377#define ALWAYS_INLINE __forceinline
379#define ALWAYS_INLINE inline
411 template <
class CharIt>
427 template <
class CharIt>
447#if defined(__GNUC__) || defined(__clang__)
449#define HAVE_BUILTIN_MUL_OVERFLOW 1
451#define HAVE_BUILTIN_MUL_OVERFLOW 0
457 255, 255, 255, 255, 255, 255, 255, 255,
458 255, 255, 255, 255, 255, 255, 255, 255,
459 255, 255, 255, 255, 255, 255, 255, 255,
460 255, 255, 255, 255, 255, 255, 255, 255,
461 255, 255, 255, 255, 255, 255, 255, 255,
462 255, 255, 255, 255, 255, 255, 255, 255,
463 0, 1, 2, 3, 4, 5, 6, 7,
464 8, 9, 255, 255, 255, 255, 255, 255,
465 255, 10, 11, 12, 13, 14, 15, 16,
466 17, 18, 19, 20, 21, 22, 23, 24,
467 25, 26, 27, 28, 29, 30, 31, 32,
468 33, 34, 35, 255, 255, 255, 255, 255,
469 255, 10, 11, 12, 13, 14, 15, 16,
470 17, 18, 19, 20, 21, 22, 23, 24,
471 25, 26, 27, 28, 29, 30, 31, 32,
472 33, 34, 35, 255, 255, 255, 255, 255,
476static constexpr uint8_t
kCharBits[] = {1, 2, 3, 0, 4, 0, 0, 0, 5};
478template <
class CharIt>
481 radix_ =
static_cast<uint8_t
>(radix);
482 const int char_bits =
kCharBits[radix >> 2];
496 if (bits_left < char_bits)
break;
497 bits_left -= char_bits;
498 part = (part << char_bits) | d;
501 if (current ==
end) {
514template <
class CharIt>
517 CharIt current =
start;
518#if !HAVE_BUILTIN_MUL_OVERFLOW
543#if HAVE_BUILTIN_MUL_OVERFLOW
545 if (__builtin_mul_overflow(multiplier, radix, &new_multiplier))
break;
546 multiplier = new_multiplier;
548 if (multiplier > kMaxMultiplier)
break;
551 part = part * radix + d;
554 if (current ==
end) {
575 result = twodigit_t{low} + high + carry;
619#undef BIGINT_H_DCHECK
621#undef HAVE_BUILTIN_MUL_OVERFLOW
#define BIGINT_H_DCHECK(cond)
digit_t read_4byte_aligned(int i)
Digits(digit_t *mem, int len)
const digit_t * digits() const
bool operator==(const Digits &other) const
Digits(Digits src, int offset, int len)
digit_t operator[](int i)
Digits(const digit_t *mem, int len)
FromStringAccumulator(int max_digits)
ALWAYS_INLINE bool AddPart(digit_t multiplier, digit_t part, bool is_last)
ALWAYS_INLINE CharIt Parse(CharIt start, CharIt end, digit_t radix)
ALWAYS_INLINE CharIt ParsePowerTwo(CharIt start, CharIt end, digit_t radix)
std::vector< digit_t > heap_parts_
digit_t stack_parts_[kStackParts]
void operator()(Processor *proc)
Status Modulo(RWDigits R, Digits A, Digits B)
Status Divide(RWDigits Q, Digits A, Digits B)
static Processor * New(Platform *platform)
Status Multiply(RWDigits Z, Digits X, Digits Y)
Status ToString(char *out, uint32_t *out_length, Digits X, int radix, bool sign)
Status FromString(RWDigits Z, FromStringAccumulator *accumulator)
WritableDigitReference(digit_t *ptr)
WritableDigitReference(const WritableDigitReference &src)=default
void operator=(digit_t digit)
WritableDigitReference & operator=(const WritableDigitReference &src)
WritableDigitReference operator[](int i)
RWDigits operator+(int i)
RWDigits(RWDigits src, int offset, int len)
RWDigits(digit_t *mem, int len)
too high values may cause the compiler to set high thresholds for inlining to as much as possible avoid inlined allocation of objects that cannot escape trace load stores from virtual maglev objects use TurboFan fast string builder analyze liveness of environment slots and zap dead values trace TurboFan load elimination emit data about basic block usage in builtins to this enable builtin reordering when run mksnapshot flag for emit warnings when applying builtin profile data verify register allocation in TurboFan randomly schedule instructions to stress dependency tracking enable store store elimination in TurboFan rewrite far to near simulate GC compiler thread race related to allow float parameters to be passed in simulator mode JS Wasm Run additional turbo_optimize_inlined_js_wasm_wrappers enable experimental feedback collection in generic lowering enable Turboshaft s WasmLoadElimination enable Turboshaft s low level load elimination for JS enable Turboshaft s escape analysis for string concatenation use enable Turbolev features that we want to ship in the not too far future trace individual Turboshaft reduction steps trace intermediate Turboshaft reduction steps invocation count threshold for early optimization Enables optimizations which favor memory size over execution speed Enables sampling allocation profiler with X as a sample interval min size of a semi the new space consists of two semi spaces max size of the Collect garbage after Collect garbage after keeps maps alive for< n > old space garbage collections print one detailed trace line in allocation gc speed threshold for starting incremental marking via a task in percent of available threshold for starting incremental marking immediately in percent of available Use a single schedule for determining a marking schedule between JS and C objects schedules the minor GC task with kUserVisible priority max worker number of concurrent for NumberOfWorkerThreads start background threads that allocate memory concurrent_array_buffer_sweeping use parallel threads to clear weak refs in the atomic pause trace progress of the incremental marking trace object counts and memory usage report a tick only when allocated zone memory changes by this amount TracingFlags::gc_stats TracingFlags::gc_stats track native contexts that are expected to be garbage collected verify heap pointers before and after GC memory reducer runs GC with ReduceMemoryFootprint flag Maximum number of memory reducer GCs scheduled Old gen GC speed is computed directly from gc tracer counters Perform compaction on full GCs based on V8 s default heuristics Perform compaction on every full GC Perform code space compaction when finalizing a full GC with stack Stress GC compaction to flush out bugs with moving objects flush of baseline code when it has not been executed recently Use time base code flushing instead of age Use a progress bar to scan large objects in increments when incremental marking is active force incremental marking for small heaps and run it more often force marking at random points between and X(inclusive) percent " "of the regular marking start limit") DEFINE_INT(stress_scavenge
ZoneVector< RpoNumber > & result
uint32_t ToStringResultLength(Digits X, int radix, bool sign)
int SubtractSignedResultLength(int x_length, int y_length, bool same_sign)
void BitwiseXor_NegNeg(RWDigits Z, Digits X, Digits Y)
bool AsIntN(RWDigits Z, Digits X, bool x_negative, int n)
void BitwiseAnd_PosPos(RWDigits Z, Digits X, Digits Y)
void SubtractOne(RWDigits Z, Digits X)
void BitwiseOr_PosNeg(RWDigits Z, Digits X, Digits Y)
int RightShift_ResultLength(Digits X, bool x_sign, digit_t shift, RightShiftState *state)
void AddOne(RWDigits Z, Digits X)
void BitwiseXor_PosPos(RWDigits Z, Digits X, Digits Y)
void LeftShift(RWDigits Z, Digits X, digit_t shift)
int Compare(Digits A, Digits B)
void BitwiseOr_PosPos(RWDigits Z, Digits X, Digits Y)
static constexpr uint8_t kCharValue[]
static constexpr int kDigitBits
int ModuloResultLength(Digits B)
void BitwiseAnd_NegNeg(RWDigits Z, Digits X, Digits Y)
constexpr char kStringZapValue
int AsIntNResultLength(Digits X, bool x_negative, int n)
void Add(RWDigits Z, Digits X, Digits Y)
int AddSignedResultLength(int x_length, int y_length, bool same_sign)
bool SubtractSigned(RWDigits Z, Digits X, bool x_negative, Digits Y, bool y_negative)
bool AddSigned(RWDigits Z, Digits X, bool x_negative, Digits Y, bool y_negative)
static constexpr int kStackParts
void AsUintN_Neg(RWDigits Z, Digits X, int n)
int SubtractResultLength(int x_length, int y_length)
void Subtract(RWDigits Z, Digits X, Digits Y)
static constexpr uint8_t kCharBits[]
void BitwiseOr_NegNeg(RWDigits Z, Digits X, Digits Y)
void RightShift(RWDigits Z, Digits X, digit_t shift, const RightShiftState &state)
constexpr int kBarrettThreshold
int AsUintN_Neg_ResultLength(int n)
int DivideResultLength(Digits A, Digits B)
int MultiplyResultLength(Digits X, Digits Y)
void BitwiseXor_PosNeg(RWDigits Z, Digits X, Digits Y)
int AddResultLength(int x_length, int y_length)
int AsUintN_Pos_ResultLength(Digits X, int n)
void BitwiseAnd_PosNeg(RWDigits Z, Digits X, Digits Y)
void AsUintN_Pos(RWDigits Z, Digits X, int n)