v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
div-helpers.h
Go to the documentation of this file.
1// Copyright 2021 the V8 project authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#ifndef V8_BIGINT_DIV_HELPERS_H_
6#define V8_BIGINT_DIV_HELPERS_H_
7
8#include <memory>
9
10#include "src/bigint/bigint.h"
11#include "src/bigint/util.h"
12
13namespace v8 {
14namespace bigint {
15
16void LeftShift(RWDigits Z, Digits X, int shift);
17void RightShift(RWDigits Z, Digits X, int shift);
18
19inline void PutAt(RWDigits Z, Digits A, int count) {
20 int len = std::min(A.len(), count);
21 int i = 0;
22 for (; i < len; i++) Z[i] = A[i];
23 for (; i < count; i++) Z[i] = 0;
24}
25
26// Division algorithms typically need to left-shift their inputs into
27// "bit-normalized" form (i.e. top bit is set). The inputs are considered
28// read-only, and V8 relies on that by allowing concurrent reads from them,
29// so by default, {ShiftedDigits} allocate temporary storage for their
30// contents. In-place modification is opt-in for cases where callers can
31// guarantee that it is safe.
32// When callers allow in-place shifting and wish to undo it, they have to do
33// so manually using {Reset()}.
34// If {shift} is not given, it is auto-detected from {original}'s
35// leading zeros.
36class ShiftedDigits : public Digits {
37 public:
38 explicit ShiftedDigits(Digits& original, int shift = -1,
39 bool allow_inplace = false)
40 : Digits(original.digits_, original.len_) {
41 int leading_zeros = CountLeadingZeros(original.msd());
42 if (shift < 0) {
43 shift = leading_zeros;
44 } else if (shift > leading_zeros) {
45 allow_inplace = false;
46 len_++;
47 }
48 shift_ = shift;
49 if (shift == 0) {
50 inplace_ = true;
51 return;
52 }
53 inplace_ = allow_inplace;
54 if (!inplace_) {
55 digit_t* digits = new digit_t[len_];
56 storage_.reset(digits);
58 }
59 RWDigits rw_view(digits_, len_);
60 LeftShift(rw_view, original, shift_);
61 }
62 ~ShiftedDigits() = default;
63
64 void Reset() {
65 if (inplace_) {
66 RWDigits rw_view(digits_, len_);
67 RightShift(rw_view, rw_view, shift_);
68 }
69 }
70
71 int shift() { return shift_; }
72
73 private:
74 int shift_;
76 std::unique_ptr<digit_t[]> storage_;
77};
78
79} // namespace bigint
80} // namespace v8
81
82#endif // V8_BIGINT_DIV_HELPERS_H_
digit_t * digits_
Definition bigint.h:118
const digit_t * digits() const
Definition bigint.h:114
digit_t msd()
Definition bigint.h:94
ShiftedDigits(Digits &original, int shift=-1, bool allow_inplace=false)
Definition div-helpers.h:38
std::unique_ptr< digit_t[]> storage_
Definition div-helpers.h:76
uint32_t count
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
void PutAt(RWDigits Z, Digits A, int count)
Definition div-helpers.h:19
void LeftShift(RWDigits Z, Digits X, digit_t shift)
Definition bitwise.cc:136
constexpr int CountLeadingZeros(T value)
Definition util.h:30
void RightShift(RWDigits Z, Digits X, digit_t shift, const RightShiftState &state)
Definition bitwise.cc:195
uintptr_t digit_t
Definition bigint.h:34