v8
V8 is Google’s open source high-performance JavaScript and WebAssembly engine, written in C++.
Loading...
Searching...
No Matches
vector-arithmetic.cc
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
6
9
10namespace v8 {
11namespace bigint {
12
14 X.Normalize();
15 if (X.len() == 0) return 0;
16 digit_t carry = 0;
17 int i = 0;
18 for (; i < X.len(); i++) {
19 Z[i] = digit_add3(Z[i], X[i], carry, &carry);
20 }
21 for (; i < Z.len() && carry != 0; i++) {
22 Z[i] = digit_add2(Z[i], carry, &carry);
23 }
24 return carry;
25}
26
28 X.Normalize();
29 if (X.len() == 0) return 0;
30 digit_t borrow = 0;
31 int i = 0;
32 for (; i < X.len(); i++) {
33 Z[i] = digit_sub2(Z[i], X[i], borrow, &borrow);
34 }
35 for (; i < Z.len() && borrow != 0; i++) {
36 Z[i] = digit_sub(Z[i], borrow, &borrow);
37 }
38 return borrow;
39}
40
41void Add(RWDigits Z, Digits X, Digits Y) {
42 if (X.len() < Y.len()) {
43 return Add(Z, Y, X);
44 }
45 int i = 0;
46 digit_t carry = 0;
47 for (; i < Y.len(); i++) {
48 Z[i] = digit_add3(X[i], Y[i], carry, &carry);
49 }
50 for (; i < X.len(); i++) {
51 Z[i] = digit_add2(X[i], carry, &carry);
52 }
53 for (; i < Z.len(); i++) {
54 Z[i] = carry;
55 carry = 0;
56 }
57}
58
60 X.Normalize();
61 Y.Normalize();
62 DCHECK(X.len() >= Y.len());
63 int i = 0;
64 digit_t borrow = 0;
65 for (; i < Y.len(); i++) {
66 Z[i] = digit_sub2(X[i], Y[i], borrow, &borrow);
67 }
68 for (; i < X.len(); i++) {
69 Z[i] = digit_sub(X[i], borrow, &borrow);
70 }
71 DCHECK(borrow == 0);
72 for (; i < Z.len(); i++) Z[i] = 0;
73}
74
76 DCHECK(Z.len() >= Y.len() && X.len() >= Y.len());
77 digit_t carry = 0;
78 for (int i = 0; i < Y.len(); i++) {
79 Z[i] = digit_add3(X[i], Y[i], carry, &carry);
80 }
81 return carry;
82}
83
85 DCHECK(Z.len() >= Y.len() && X.len() >= Y.len());
86 digit_t borrow = 0;
87 for (int i = 0; i < Y.len(); i++) {
88 Z[i] = digit_sub2(X[i], Y[i], borrow, &borrow);
89 }
90 return borrow;
91}
92
93bool AddSigned(RWDigits Z, Digits X, bool x_negative, Digits Y,
94 bool y_negative) {
95 if (x_negative == y_negative) {
96 Add(Z, X, Y);
97 return x_negative;
98 }
99 if (GreaterThanOrEqual(X, Y)) {
100 Subtract(Z, X, Y);
101 return x_negative;
102 }
103 Subtract(Z, Y, X);
104 return !x_negative;
105}
106
107bool SubtractSigned(RWDigits Z, Digits X, bool x_negative, Digits Y,
108 bool y_negative) {
109 if (x_negative != y_negative) {
110 Add(Z, X, Y);
111 return x_negative;
112 }
113 if (GreaterThanOrEqual(X, Y)) {
114 Subtract(Z, X, Y);
115 return x_negative;
116 }
117 Subtract(Z, Y, X);
118 return !x_negative;
119}
120
122 digit_t carry = 1;
123 int i = 0;
124 for (; carry > 0 && i < X.len(); i++) Z[i] = digit_add2(X[i], carry, &carry);
125 if (carry > 0) Z[i++] = carry;
126 for (; i < X.len(); i++) Z[i] = X[i];
127 for (; i < Z.len(); i++) Z[i] = 0;
128}
129
131 digit_t borrow = 1;
132 int i = 0;
133 for (; borrow > 0; i++) Z[i] = digit_sub(X[i], borrow, &borrow);
134 for (; i < X.len(); i++) Z[i] = X[i];
135 for (; i < Z.len(); i++) Z[i] = 0;
136}
137
138} // namespace bigint
139} // namespace v8
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 SubtractOne(RWDigits Z, Digits X)
void AddOne(RWDigits Z, Digits X)
void Add(RWDigits Z, Digits X, Digits Y)
digit_t digit_add3(digit_t a, digit_t b, digit_t c, digit_t *carry)
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)
bool GreaterThanOrEqual(Digits A, Digits B)
digit_t AddAndReturnOverflow(RWDigits Z, Digits X)
digit_t SubAndReturnBorrow(RWDigits Z, Digits X)
void Subtract(RWDigits Z, Digits X, Digits Y)
digit_t digit_sub2(digit_t a, digit_t b, digit_t borrow_in, digit_t *borrow_out)
digit_t SubtractAndReturnBorrow(RWDigits Z, Digits X, Digits Y)
digit_t AddAndReturnCarry(RWDigits Z, Digits X, Digits Y)
digit_t digit_sub(digit_t a, digit_t b, digit_t *borrow)
uintptr_t digit_t
Definition bigint.h:34
digit_t digit_add2(digit_t a, digit_t b, digit_t *carry)
#define DCHECK(condition)
Definition logging.h:482