Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(198)

Side by Side Diff: src/builtins/builtins-math.cc

Issue 2504913002: Revert of [refactoring] Split CodeAssemblerState out of CodeAssembler (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/builtins/builtins-iterator.cc ('k') | src/builtins/builtins-number.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 the V8 project authors. All rights reserved. 1 // Copyright 2016 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/builtins/builtins.h" 5 #include "src/builtins/builtins.h"
6 #include "src/builtins/builtins-utils.h" 6 #include "src/builtins/builtins-utils.h"
7 7
8 #include "src/code-factory.h" 8 #include "src/code-factory.h"
9 9
10 namespace v8 { 10 namespace v8 {
11 namespace internal { 11 namespace internal {
12 12
13 // ----------------------------------------------------------------------------- 13 // -----------------------------------------------------------------------------
14 // ES6 section 20.2.2 Function Properties of the Math Object 14 // ES6 section 20.2.2 Function Properties of the Math Object
15 15
16 // ES6 section - 20.2.2.1 Math.abs ( x ) 16 // ES6 section - 20.2.2.1 Math.abs ( x )
17 void Builtins::Generate_MathAbs(compiler::CodeAssemblerState* state) { 17 void Builtins::Generate_MathAbs(CodeStubAssembler* assembler) {
18 typedef CodeStubAssembler::Label Label; 18 typedef CodeStubAssembler::Label Label;
19 typedef compiler::Node Node; 19 typedef compiler::Node Node;
20 typedef CodeStubAssembler::Variable Variable; 20 typedef CodeStubAssembler::Variable Variable;
21 CodeStubAssembler assembler(state);
22
23 Node* context = assembler.Parameter(4);
24
25 // We might need to loop once for ToNumber conversion.
26 Variable var_x(&assembler, MachineRepresentation::kTagged);
27 Label loop(&assembler, &var_x);
28 var_x.Bind(assembler.Parameter(1));
29 assembler.Goto(&loop);
30 assembler.Bind(&loop);
31 {
32 // Load the current {x} value.
33 Node* x = var_x.value();
34
35 // Check if {x} is a Smi or a HeapObject.
36 Label if_xissmi(&assembler), if_xisnotsmi(&assembler);
37 assembler.Branch(assembler.TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi);
38
39 assembler.Bind(&if_xissmi);
40 {
41 // Check if {x} is already positive.
42 Label if_xispositive(&assembler), if_xisnotpositive(&assembler);
43 assembler.BranchIfSmiLessThanOrEqual(
44 assembler.SmiConstant(Smi::FromInt(0)), x, &if_xispositive,
45 &if_xisnotpositive);
46
47 assembler.Bind(&if_xispositive);
48 {
49 // Just return the input {x}.
50 assembler.Return(x);
51 }
52
53 assembler.Bind(&if_xisnotpositive);
54 {
55 // Try to negate the {x} value.
56 Node* pair = assembler.IntPtrSubWithOverflow(
57 assembler.IntPtrConstant(0), assembler.BitcastTaggedToWord(x));
58 Node* overflow = assembler.Projection(1, pair);
59 Label if_overflow(&assembler, Label::kDeferred),
60 if_notoverflow(&assembler);
61 assembler.Branch(overflow, &if_overflow, &if_notoverflow);
62
63 assembler.Bind(&if_notoverflow);
64 {
65 // There is a Smi representation for negated {x}.
66 Node* result = assembler.Projection(0, pair);
67 result = assembler.BitcastWordToTagged(result);
68 assembler.Return(result);
69 }
70
71 assembler.Bind(&if_overflow);
72 {
73 Node* result = assembler.NumberConstant(0.0 - Smi::kMinValue);
74 assembler.Return(result);
75 }
76 }
77 }
78
79 assembler.Bind(&if_xisnotsmi);
80 {
81 // Check if {x} is a HeapNumber.
82 Label if_xisheapnumber(&assembler),
83 if_xisnotheapnumber(&assembler, Label::kDeferred);
84 assembler.Branch(assembler.WordEqual(assembler.LoadMap(x),
85 assembler.HeapNumberMapConstant()),
86 &if_xisheapnumber, &if_xisnotheapnumber);
87
88 assembler.Bind(&if_xisheapnumber);
89 {
90 Node* x_value = assembler.LoadHeapNumberValue(x);
91 Node* value = assembler.Float64Abs(x_value);
92 Node* result = assembler.AllocateHeapNumberWithValue(value);
93 assembler.Return(result);
94 }
95
96 assembler.Bind(&if_xisnotheapnumber);
97 {
98 // Need to convert {x} to a Number first.
99 Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate());
100 var_x.Bind(assembler.CallStub(callable, context, x));
101 assembler.Goto(&loop);
102 }
103 }
104 }
105 }
106
107 namespace {
108
109 void Generate_MathRoundingOperation(
110 CodeStubAssembler* assembler,
111 compiler::Node* (CodeStubAssembler::*float64op)(compiler::Node*)) {
112 typedef CodeStubAssembler::Label Label;
113 typedef compiler::Node Node;
114 typedef CodeStubAssembler::Variable Variable;
115 21
116 Node* context = assembler->Parameter(4); 22 Node* context = assembler->Parameter(4);
117 23
118 // We might need to loop once for ToNumber conversion. 24 // We might need to loop once for ToNumber conversion.
119 Variable var_x(assembler, MachineRepresentation::kTagged); 25 Variable var_x(assembler, MachineRepresentation::kTagged);
120 Label loop(assembler, &var_x); 26 Label loop(assembler, &var_x);
121 var_x.Bind(assembler->Parameter(1)); 27 var_x.Bind(assembler->Parameter(1));
122 assembler->Goto(&loop); 28 assembler->Goto(&loop);
123 assembler->Bind(&loop); 29 assembler->Bind(&loop);
124 { 30 {
125 // Load the current {x} value. 31 // Load the current {x} value.
126 Node* x = var_x.value(); 32 Node* x = var_x.value();
127 33
128 // Check if {x} is a Smi or a HeapObject. 34 // Check if {x} is a Smi or a HeapObject.
129 Label if_xissmi(assembler), if_xisnotsmi(assembler); 35 Label if_xissmi(assembler), if_xisnotsmi(assembler);
130 assembler->Branch(assembler->TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi); 36 assembler->Branch(assembler->TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi);
131 37
132 assembler->Bind(&if_xissmi); 38 assembler->Bind(&if_xissmi);
133 { 39 {
134 // Nothing to do when {x} is a Smi. 40 // Check if {x} is already positive.
135 assembler->Return(x); 41 Label if_xispositive(assembler), if_xisnotpositive(assembler);
42 assembler->BranchIfSmiLessThanOrEqual(
43 assembler->SmiConstant(Smi::FromInt(0)), x, &if_xispositive,
44 &if_xisnotpositive);
45
46 assembler->Bind(&if_xispositive);
47 {
48 // Just return the input {x}.
49 assembler->Return(x);
50 }
51
52 assembler->Bind(&if_xisnotpositive);
53 {
54 // Try to negate the {x} value.
55 Node* pair = assembler->IntPtrSubWithOverflow(
56 assembler->IntPtrConstant(0), assembler->BitcastTaggedToWord(x));
57 Node* overflow = assembler->Projection(1, pair);
58 Label if_overflow(assembler, Label::kDeferred),
59 if_notoverflow(assembler);
60 assembler->Branch(overflow, &if_overflow, &if_notoverflow);
61
62 assembler->Bind(&if_notoverflow);
63 {
64 // There is a Smi representation for negated {x}.
65 Node* result = assembler->Projection(0, pair);
66 result = assembler->BitcastWordToTagged(result);
67 assembler->Return(result);
68 }
69
70 assembler->Bind(&if_overflow);
71 {
72 Node* result = assembler->NumberConstant(0.0 - Smi::kMinValue);
73 assembler->Return(result);
74 }
75 }
136 } 76 }
137 77
138 assembler->Bind(&if_xisnotsmi); 78 assembler->Bind(&if_xisnotsmi);
139 { 79 {
140 // Check if {x} is a HeapNumber. 80 // Check if {x} is a HeapNumber.
141 Label if_xisheapnumber(assembler), 81 Label if_xisheapnumber(assembler),
142 if_xisnotheapnumber(assembler, Label::kDeferred); 82 if_xisnotheapnumber(assembler, Label::kDeferred);
143 assembler->Branch( 83 assembler->Branch(
144 assembler->WordEqual(assembler->LoadMap(x), 84 assembler->WordEqual(assembler->LoadMap(x),
145 assembler->HeapNumberMapConstant()), 85 assembler->HeapNumberMapConstant()),
146 &if_xisheapnumber, &if_xisnotheapnumber); 86 &if_xisheapnumber, &if_xisnotheapnumber);
147 87
148 assembler->Bind(&if_xisheapnumber); 88 assembler->Bind(&if_xisheapnumber);
149 { 89 {
150 Node* x_value = assembler->LoadHeapNumberValue(x); 90 Node* x_value = assembler->LoadHeapNumberValue(x);
91 Node* value = assembler->Float64Abs(x_value);
92 Node* result = assembler->AllocateHeapNumberWithValue(value);
93 assembler->Return(result);
94 }
95
96 assembler->Bind(&if_xisnotheapnumber);
97 {
98 // Need to convert {x} to a Number first.
99 Callable callable =
100 CodeFactory::NonNumberToNumber(assembler->isolate());
101 var_x.Bind(assembler->CallStub(callable, context, x));
102 assembler->Goto(&loop);
103 }
104 }
105 }
106 }
107
108 namespace {
109
110 void Generate_MathRoundingOperation(
111 CodeStubAssembler* assembler,
112 compiler::Node* (CodeStubAssembler::*float64op)(compiler::Node*)) {
113 typedef CodeStubAssembler::Label Label;
114 typedef compiler::Node Node;
115 typedef CodeStubAssembler::Variable Variable;
116
117 Node* context = assembler->Parameter(4);
118
119 // We might need to loop once for ToNumber conversion.
120 Variable var_x(assembler, MachineRepresentation::kTagged);
121 Label loop(assembler, &var_x);
122 var_x.Bind(assembler->Parameter(1));
123 assembler->Goto(&loop);
124 assembler->Bind(&loop);
125 {
126 // Load the current {x} value.
127 Node* x = var_x.value();
128
129 // Check if {x} is a Smi or a HeapObject.
130 Label if_xissmi(assembler), if_xisnotsmi(assembler);
131 assembler->Branch(assembler->TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi);
132
133 assembler->Bind(&if_xissmi);
134 {
135 // Nothing to do when {x} is a Smi.
136 assembler->Return(x);
137 }
138
139 assembler->Bind(&if_xisnotsmi);
140 {
141 // Check if {x} is a HeapNumber.
142 Label if_xisheapnumber(assembler),
143 if_xisnotheapnumber(assembler, Label::kDeferred);
144 assembler->Branch(
145 assembler->WordEqual(assembler->LoadMap(x),
146 assembler->HeapNumberMapConstant()),
147 &if_xisheapnumber, &if_xisnotheapnumber);
148
149 assembler->Bind(&if_xisheapnumber);
150 {
151 Node* x_value = assembler->LoadHeapNumberValue(x);
151 Node* value = (assembler->*float64op)(x_value); 152 Node* value = (assembler->*float64op)(x_value);
152 Node* result = assembler->ChangeFloat64ToTagged(value); 153 Node* result = assembler->ChangeFloat64ToTagged(value);
153 assembler->Return(result); 154 assembler->Return(result);
154 } 155 }
155 156
156 assembler->Bind(&if_xisnotheapnumber); 157 assembler->Bind(&if_xisnotheapnumber);
157 { 158 {
158 // Need to convert {x} to a Number first. 159 // Need to convert {x} to a Number first.
159 Callable callable = 160 Callable callable =
160 CodeFactory::NonNumberToNumber(assembler->isolate()); 161 CodeFactory::NonNumberToNumber(assembler->isolate());
(...skipping 13 matching lines...) Expand all
174 Node* context = assembler->Parameter(4); 175 Node* context = assembler->Parameter(4);
175 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); 176 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
176 Node* value = (assembler->*float64op)(x_value); 177 Node* value = (assembler->*float64op)(x_value);
177 Node* result = assembler->AllocateHeapNumberWithValue(value); 178 Node* result = assembler->AllocateHeapNumberWithValue(value);
178 assembler->Return(result); 179 assembler->Return(result);
179 } 180 }
180 181
181 } // namespace 182 } // namespace
182 183
183 // ES6 section 20.2.2.2 Math.acos ( x ) 184 // ES6 section 20.2.2.2 Math.acos ( x )
184 void Builtins::Generate_MathAcos(compiler::CodeAssemblerState* state) { 185 void Builtins::Generate_MathAcos(CodeStubAssembler* assembler) {
185 CodeStubAssembler assembler(state); 186 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Acos);
186 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Acos);
187 } 187 }
188 188
189 // ES6 section 20.2.2.3 Math.acosh ( x ) 189 // ES6 section 20.2.2.3 Math.acosh ( x )
190 void Builtins::Generate_MathAcosh(compiler::CodeAssemblerState* state) { 190 void Builtins::Generate_MathAcosh(CodeStubAssembler* assembler) {
191 CodeStubAssembler assembler(state); 191 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Acosh);
192 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Acosh);
193 } 192 }
194 193
195 // ES6 section 20.2.2.4 Math.asin ( x ) 194 // ES6 section 20.2.2.4 Math.asin ( x )
196 void Builtins::Generate_MathAsin(compiler::CodeAssemblerState* state) { 195 void Builtins::Generate_MathAsin(CodeStubAssembler* assembler) {
197 CodeStubAssembler assembler(state); 196 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Asin);
198 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Asin);
199 } 197 }
200 198
201 // ES6 section 20.2.2.5 Math.asinh ( x ) 199 // ES6 section 20.2.2.5 Math.asinh ( x )
202 void Builtins::Generate_MathAsinh(compiler::CodeAssemblerState* state) { 200 void Builtins::Generate_MathAsinh(CodeStubAssembler* assembler) {
203 CodeStubAssembler assembler(state); 201 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Asinh);
204 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Asinh);
205 } 202 }
206 203
207 // ES6 section 20.2.2.6 Math.atan ( x ) 204 // ES6 section 20.2.2.6 Math.atan ( x )
208 void Builtins::Generate_MathAtan(compiler::CodeAssemblerState* state) { 205 void Builtins::Generate_MathAtan(CodeStubAssembler* assembler) {
209 CodeStubAssembler assembler(state); 206 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Atan);
210 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Atan);
211 } 207 }
212 208
213 // ES6 section 20.2.2.7 Math.atanh ( x ) 209 // ES6 section 20.2.2.7 Math.atanh ( x )
214 void Builtins::Generate_MathAtanh(compiler::CodeAssemblerState* state) { 210 void Builtins::Generate_MathAtanh(CodeStubAssembler* assembler) {
215 CodeStubAssembler assembler(state); 211 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Atanh);
216 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Atanh);
217 } 212 }
218 213
219 // ES6 section 20.2.2.8 Math.atan2 ( y, x ) 214 // ES6 section 20.2.2.8 Math.atan2 ( y, x )
220 void Builtins::Generate_MathAtan2(compiler::CodeAssemblerState* state) { 215 void Builtins::Generate_MathAtan2(CodeStubAssembler* assembler) {
221 using compiler::Node; 216 using compiler::Node;
222 CodeStubAssembler assembler(state);
223 217
224 Node* y = assembler.Parameter(1); 218 Node* y = assembler->Parameter(1);
225 Node* x = assembler.Parameter(2); 219 Node* x = assembler->Parameter(2);
226 Node* context = assembler.Parameter(5); 220 Node* context = assembler->Parameter(5);
227 Node* y_value = assembler.TruncateTaggedToFloat64(context, y); 221 Node* y_value = assembler->TruncateTaggedToFloat64(context, y);
228 Node* x_value = assembler.TruncateTaggedToFloat64(context, x); 222 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
229 Node* value = assembler.Float64Atan2(y_value, x_value); 223 Node* value = assembler->Float64Atan2(y_value, x_value);
230 Node* result = assembler.AllocateHeapNumberWithValue(value); 224 Node* result = assembler->AllocateHeapNumberWithValue(value);
231 assembler.Return(result); 225 assembler->Return(result);
232 } 226 }
233 227
234 // ES6 section 20.2.2.10 Math.ceil ( x ) 228 // ES6 section 20.2.2.10 Math.ceil ( x )
235 void Builtins::Generate_MathCeil(compiler::CodeAssemblerState* state) { 229 void Builtins::Generate_MathCeil(CodeStubAssembler* assembler) {
236 CodeStubAssembler assembler(state); 230 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Ceil);
237 Generate_MathRoundingOperation(&assembler, &CodeStubAssembler::Float64Ceil);
238 } 231 }
239 232
240 // ES6 section 20.2.2.9 Math.cbrt ( x ) 233 // ES6 section 20.2.2.9 Math.cbrt ( x )
241 void Builtins::Generate_MathCbrt(compiler::CodeAssemblerState* state) { 234 void Builtins::Generate_MathCbrt(CodeStubAssembler* assembler) {
242 CodeStubAssembler assembler(state); 235 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Cbrt);
243 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Cbrt);
244 } 236 }
245 237
246 // ES6 section 20.2.2.11 Math.clz32 ( x ) 238 // ES6 section 20.2.2.11 Math.clz32 ( x )
247 void Builtins::Generate_MathClz32(compiler::CodeAssemblerState* state) { 239 void Builtins::Generate_MathClz32(CodeStubAssembler* assembler) {
248 typedef CodeStubAssembler::Label Label; 240 typedef CodeStubAssembler::Label Label;
249 typedef compiler::Node Node; 241 typedef compiler::Node Node;
250 typedef CodeStubAssembler::Variable Variable; 242 typedef CodeStubAssembler::Variable Variable;
251 CodeStubAssembler assembler(state);
252 243
253 Node* context = assembler.Parameter(4); 244 Node* context = assembler->Parameter(4);
254 245
255 // Shared entry point for the clz32 operation. 246 // Shared entry point for the clz32 operation.
256 Variable var_clz32_x(&assembler, MachineRepresentation::kWord32); 247 Variable var_clz32_x(assembler, MachineRepresentation::kWord32);
257 Label do_clz32(&assembler); 248 Label do_clz32(assembler);
258 249
259 // We might need to loop once for ToNumber conversion. 250 // We might need to loop once for ToNumber conversion.
260 Variable var_x(&assembler, MachineRepresentation::kTagged); 251 Variable var_x(assembler, MachineRepresentation::kTagged);
261 Label loop(&assembler, &var_x); 252 Label loop(assembler, &var_x);
262 var_x.Bind(assembler.Parameter(1)); 253 var_x.Bind(assembler->Parameter(1));
263 assembler.Goto(&loop); 254 assembler->Goto(&loop);
264 assembler.Bind(&loop); 255 assembler->Bind(&loop);
265 { 256 {
266 // Load the current {x} value. 257 // Load the current {x} value.
267 Node* x = var_x.value(); 258 Node* x = var_x.value();
268 259
269 // Check if {x} is a Smi or a HeapObject. 260 // Check if {x} is a Smi or a HeapObject.
270 Label if_xissmi(&assembler), if_xisnotsmi(&assembler); 261 Label if_xissmi(assembler), if_xisnotsmi(assembler);
271 assembler.Branch(assembler.TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi); 262 assembler->Branch(assembler->TaggedIsSmi(x), &if_xissmi, &if_xisnotsmi);
272 263
273 assembler.Bind(&if_xissmi); 264 assembler->Bind(&if_xissmi);
274 { 265 {
275 var_clz32_x.Bind(assembler.SmiToWord32(x)); 266 var_clz32_x.Bind(assembler->SmiToWord32(x));
276 assembler.Goto(&do_clz32); 267 assembler->Goto(&do_clz32);
277 } 268 }
278 269
279 assembler.Bind(&if_xisnotsmi); 270 assembler->Bind(&if_xisnotsmi);
280 { 271 {
281 // Check if {x} is a HeapNumber. 272 // Check if {x} is a HeapNumber.
282 Label if_xisheapnumber(&assembler), 273 Label if_xisheapnumber(assembler),
283 if_xisnotheapnumber(&assembler, Label::kDeferred); 274 if_xisnotheapnumber(assembler, Label::kDeferred);
284 assembler.Branch(assembler.WordEqual(assembler.LoadMap(x), 275 assembler->Branch(
285 assembler.HeapNumberMapConstant()), 276 assembler->WordEqual(assembler->LoadMap(x),
286 &if_xisheapnumber, &if_xisnotheapnumber); 277 assembler->HeapNumberMapConstant()),
278 &if_xisheapnumber, &if_xisnotheapnumber);
287 279
288 assembler.Bind(&if_xisheapnumber); 280 assembler->Bind(&if_xisheapnumber);
289 { 281 {
290 var_clz32_x.Bind(assembler.TruncateHeapNumberValueToWord32(x)); 282 var_clz32_x.Bind(assembler->TruncateHeapNumberValueToWord32(x));
291 assembler.Goto(&do_clz32); 283 assembler->Goto(&do_clz32);
292 } 284 }
293 285
294 assembler.Bind(&if_xisnotheapnumber); 286 assembler->Bind(&if_xisnotheapnumber);
295 { 287 {
296 // Need to convert {x} to a Number first. 288 // Need to convert {x} to a Number first.
297 Callable callable = CodeFactory::NonNumberToNumber(assembler.isolate()); 289 Callable callable =
298 var_x.Bind(assembler.CallStub(callable, context, x)); 290 CodeFactory::NonNumberToNumber(assembler->isolate());
299 assembler.Goto(&loop); 291 var_x.Bind(assembler->CallStub(callable, context, x));
292 assembler->Goto(&loop);
300 } 293 }
301 } 294 }
302 } 295 }
303 296
304 assembler.Bind(&do_clz32); 297 assembler->Bind(&do_clz32);
305 { 298 {
306 Node* x_value = var_clz32_x.value(); 299 Node* x_value = var_clz32_x.value();
307 Node* value = assembler.Word32Clz(x_value); 300 Node* value = assembler->Word32Clz(x_value);
308 Node* result = assembler.ChangeInt32ToTagged(value); 301 Node* result = assembler->ChangeInt32ToTagged(value);
309 assembler.Return(result); 302 assembler->Return(result);
310 } 303 }
311 } 304 }
312 305
313 // ES6 section 20.2.2.12 Math.cos ( x ) 306 // ES6 section 20.2.2.12 Math.cos ( x )
314 void Builtins::Generate_MathCos(compiler::CodeAssemblerState* state) { 307 void Builtins::Generate_MathCos(CodeStubAssembler* assembler) {
315 CodeStubAssembler assembler(state); 308 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Cos);
316 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Cos);
317 } 309 }
318 310
319 // ES6 section 20.2.2.13 Math.cosh ( x ) 311 // ES6 section 20.2.2.13 Math.cosh ( x )
320 void Builtins::Generate_MathCosh(compiler::CodeAssemblerState* state) { 312 void Builtins::Generate_MathCosh(CodeStubAssembler* assembler) {
321 CodeStubAssembler assembler(state); 313 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Cosh);
322 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Cosh);
323 } 314 }
324 315
325 // ES6 section 20.2.2.14 Math.exp ( x ) 316 // ES6 section 20.2.2.14 Math.exp ( x )
326 void Builtins::Generate_MathExp(compiler::CodeAssemblerState* state) { 317 void Builtins::Generate_MathExp(CodeStubAssembler* assembler) {
327 CodeStubAssembler assembler(state); 318 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Exp);
328 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Exp);
329 } 319 }
330 320
331 // ES6 section 20.2.2.15 Math.expm1 ( x ) 321 // ES6 section 20.2.2.15 Math.expm1 ( x )
332 void Builtins::Generate_MathExpm1(compiler::CodeAssemblerState* state) { 322 void Builtins::Generate_MathExpm1(CodeStubAssembler* assembler) {
333 CodeStubAssembler assembler(state); 323 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Expm1);
334 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Expm1);
335 } 324 }
336 325
337 // ES6 section 20.2.2.16 Math.floor ( x ) 326 // ES6 section 20.2.2.16 Math.floor ( x )
338 void Builtins::Generate_MathFloor(compiler::CodeAssemblerState* state) { 327 void Builtins::Generate_MathFloor(CodeStubAssembler* assembler) {
339 CodeStubAssembler assembler(state); 328 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Floor);
340 Generate_MathRoundingOperation(&assembler, &CodeStubAssembler::Float64Floor);
341 } 329 }
342 330
343 // ES6 section 20.2.2.17 Math.fround ( x ) 331 // ES6 section 20.2.2.17 Math.fround ( x )
344 void Builtins::Generate_MathFround(compiler::CodeAssemblerState* state) { 332 void Builtins::Generate_MathFround(CodeStubAssembler* assembler) {
345 using compiler::Node; 333 using compiler::Node;
346 CodeStubAssembler assembler(state);
347 334
348 Node* x = assembler.Parameter(1); 335 Node* x = assembler->Parameter(1);
349 Node* context = assembler.Parameter(4); 336 Node* context = assembler->Parameter(4);
350 Node* x_value = assembler.TruncateTaggedToFloat64(context, x); 337 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
351 Node* value32 = assembler.TruncateFloat64ToFloat32(x_value); 338 Node* value32 = assembler->TruncateFloat64ToFloat32(x_value);
352 Node* value = assembler.ChangeFloat32ToFloat64(value32); 339 Node* value = assembler->ChangeFloat32ToFloat64(value32);
353 Node* result = assembler.AllocateHeapNumberWithValue(value); 340 Node* result = assembler->AllocateHeapNumberWithValue(value);
354 assembler.Return(result); 341 assembler->Return(result);
355 } 342 }
356 343
357 // ES6 section 20.2.2.18 Math.hypot ( value1, value2, ...values ) 344 // ES6 section 20.2.2.18 Math.hypot ( value1, value2, ...values )
358 BUILTIN(MathHypot) { 345 BUILTIN(MathHypot) {
359 HandleScope scope(isolate); 346 HandleScope scope(isolate);
360 int const length = args.length() - 1; 347 int const length = args.length() - 1;
361 if (length == 0) return Smi::kZero; 348 if (length == 0) return Smi::kZero;
362 DCHECK_LT(0, length); 349 DCHECK_LT(0, length);
363 double max = 0; 350 double max = 0;
364 bool one_arg_is_nan = false; 351 bool one_arg_is_nan = false;
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 double summand = n * n - compensation; 387 double summand = n * n - compensation;
401 double preliminary = sum + summand; 388 double preliminary = sum + summand;
402 compensation = (preliminary - sum) - summand; 389 compensation = (preliminary - sum) - summand;
403 sum = preliminary; 390 sum = preliminary;
404 } 391 }
405 392
406 return *isolate->factory()->NewNumber(std::sqrt(sum) * max); 393 return *isolate->factory()->NewNumber(std::sqrt(sum) * max);
407 } 394 }
408 395
409 // ES6 section 20.2.2.19 Math.imul ( x, y ) 396 // ES6 section 20.2.2.19 Math.imul ( x, y )
410 void Builtins::Generate_MathImul(compiler::CodeAssemblerState* state) { 397 void Builtins::Generate_MathImul(CodeStubAssembler* assembler) {
411 using compiler::Node; 398 using compiler::Node;
412 CodeStubAssembler assembler(state);
413 399
414 Node* x = assembler.Parameter(1); 400 Node* x = assembler->Parameter(1);
415 Node* y = assembler.Parameter(2); 401 Node* y = assembler->Parameter(2);
416 Node* context = assembler.Parameter(5); 402 Node* context = assembler->Parameter(5);
417 Node* x_value = assembler.TruncateTaggedToWord32(context, x); 403 Node* x_value = assembler->TruncateTaggedToWord32(context, x);
418 Node* y_value = assembler.TruncateTaggedToWord32(context, y); 404 Node* y_value = assembler->TruncateTaggedToWord32(context, y);
419 Node* value = assembler.Int32Mul(x_value, y_value); 405 Node* value = assembler->Int32Mul(x_value, y_value);
420 Node* result = assembler.ChangeInt32ToTagged(value); 406 Node* result = assembler->ChangeInt32ToTagged(value);
421 assembler.Return(result); 407 assembler->Return(result);
422 } 408 }
423 409
424 // ES6 section 20.2.2.20 Math.log ( x ) 410 // ES6 section 20.2.2.20 Math.log ( x )
425 void Builtins::Generate_MathLog(compiler::CodeAssemblerState* state) { 411 void Builtins::Generate_MathLog(CodeStubAssembler* assembler) {
426 CodeStubAssembler assembler(state); 412 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Log);
427 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Log);
428 } 413 }
429 414
430 // ES6 section 20.2.2.21 Math.log1p ( x ) 415 // ES6 section 20.2.2.21 Math.log1p ( x )
431 void Builtins::Generate_MathLog1p(compiler::CodeAssemblerState* state) { 416 void Builtins::Generate_MathLog1p(CodeStubAssembler* assembler) {
432 CodeStubAssembler assembler(state); 417 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Log1p);
433 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Log1p);
434 } 418 }
435 419
436 // ES6 section 20.2.2.22 Math.log10 ( x ) 420 // ES6 section 20.2.2.22 Math.log10 ( x )
437 void Builtins::Generate_MathLog10(compiler::CodeAssemblerState* state) { 421 void Builtins::Generate_MathLog10(CodeStubAssembler* assembler) {
438 CodeStubAssembler assembler(state); 422 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Log10);
439 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Log10);
440 } 423 }
441 424
442 // ES6 section 20.2.2.23 Math.log2 ( x ) 425 // ES6 section 20.2.2.23 Math.log2 ( x )
443 void Builtins::Generate_MathLog2(compiler::CodeAssemblerState* state) { 426 void Builtins::Generate_MathLog2(CodeStubAssembler* assembler) {
444 CodeStubAssembler assembler(state); 427 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Log2);
445 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Log2);
446 } 428 }
447 429
448 // ES6 section 20.2.2.26 Math.pow ( x, y ) 430 // ES6 section 20.2.2.26 Math.pow ( x, y )
449 void Builtins::Generate_MathPow(compiler::CodeAssemblerState* state) { 431 void Builtins::Generate_MathPow(CodeStubAssembler* assembler) {
450 using compiler::Node; 432 using compiler::Node;
451 CodeStubAssembler assembler(state);
452 433
453 Node* x = assembler.Parameter(1); 434 Node* x = assembler->Parameter(1);
454 Node* y = assembler.Parameter(2); 435 Node* y = assembler->Parameter(2);
455 Node* context = assembler.Parameter(5); 436 Node* context = assembler->Parameter(5);
456 Node* x_value = assembler.TruncateTaggedToFloat64(context, x); 437 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
457 Node* y_value = assembler.TruncateTaggedToFloat64(context, y); 438 Node* y_value = assembler->TruncateTaggedToFloat64(context, y);
458 Node* value = assembler.Float64Pow(x_value, y_value); 439 Node* value = assembler->Float64Pow(x_value, y_value);
459 Node* result = assembler.ChangeFloat64ToTagged(value); 440 Node* result = assembler->ChangeFloat64ToTagged(value);
460 assembler.Return(result); 441 assembler->Return(result);
461 } 442 }
462 443
463 // ES6 section 20.2.2.27 Math.random ( ) 444 // ES6 section 20.2.2.27 Math.random ( )
464 void Builtins::Generate_MathRandom(compiler::CodeAssemblerState* state) { 445 void Builtins::Generate_MathRandom(CodeStubAssembler* assembler) {
465 using compiler::Node; 446 using compiler::Node;
466 CodeStubAssembler assembler(state);
467 447
468 Node* context = assembler.Parameter(3); 448 Node* context = assembler->Parameter(3);
469 Node* native_context = assembler.LoadNativeContext(context); 449 Node* native_context = assembler->LoadNativeContext(context);
470 450
471 // Load cache index. 451 // Load cache index.
472 CodeStubAssembler::Variable smi_index(&assembler, 452 CodeStubAssembler::Variable smi_index(assembler,
473 MachineRepresentation::kTagged); 453 MachineRepresentation::kTagged);
474 smi_index.Bind(assembler.LoadContextElement( 454 smi_index.Bind(assembler->LoadContextElement(
475 native_context, Context::MATH_RANDOM_INDEX_INDEX)); 455 native_context, Context::MATH_RANDOM_INDEX_INDEX));
476 456
477 // Cached random numbers are exhausted if index is 0. Go to slow path. 457 // Cached random numbers are exhausted if index is 0. Go to slow path.
478 CodeStubAssembler::Label if_cached(&assembler); 458 CodeStubAssembler::Label if_cached(assembler);
479 assembler.GotoIf( 459 assembler->GotoIf(assembler->SmiAbove(smi_index.value(),
480 assembler.SmiAbove(smi_index.value(), assembler.SmiConstant(Smi::kZero)), 460 assembler->SmiConstant(Smi::kZero)),
481 &if_cached); 461 &if_cached);
482 462
483 // Cache exhausted, populate the cache. Return value is the new index. 463 // Cache exhausted, populate the cache. Return value is the new index.
484 smi_index.Bind( 464 smi_index.Bind(
485 assembler.CallRuntime(Runtime::kGenerateRandomNumbers, context)); 465 assembler->CallRuntime(Runtime::kGenerateRandomNumbers, context));
486 assembler.Goto(&if_cached); 466 assembler->Goto(&if_cached);
487 467
488 // Compute next index by decrement. 468 // Compute next index by decrement.
489 assembler.Bind(&if_cached); 469 assembler->Bind(&if_cached);
490 Node* new_smi_index = assembler.SmiSub( 470 Node* new_smi_index = assembler->SmiSub(
491 smi_index.value(), assembler.SmiConstant(Smi::FromInt(1))); 471 smi_index.value(), assembler->SmiConstant(Smi::FromInt(1)));
492 assembler.StoreContextElement( 472 assembler->StoreContextElement(
493 native_context, Context::MATH_RANDOM_INDEX_INDEX, new_smi_index); 473 native_context, Context::MATH_RANDOM_INDEX_INDEX, new_smi_index);
494 474
495 // Load and return next cached random number. 475 // Load and return next cached random number.
496 Node* array = assembler.LoadContextElement(native_context, 476 Node* array = assembler->LoadContextElement(native_context,
497 Context::MATH_RANDOM_CACHE_INDEX); 477 Context::MATH_RANDOM_CACHE_INDEX);
498 Node* random = assembler.LoadFixedDoubleArrayElement( 478 Node* random = assembler->LoadFixedDoubleArrayElement(
499 array, new_smi_index, MachineType::Float64(), 0, 479 array, new_smi_index, MachineType::Float64(), 0,
500 CodeStubAssembler::SMI_PARAMETERS); 480 CodeStubAssembler::SMI_PARAMETERS);
501 assembler.Return(assembler.AllocateHeapNumberWithValue(random)); 481 assembler->Return(assembler->AllocateHeapNumberWithValue(random));
502 } 482 }
503 483
504 // ES6 section 20.2.2.28 Math.round ( x ) 484 // ES6 section 20.2.2.28 Math.round ( x )
505 void Builtins::Generate_MathRound(compiler::CodeAssemblerState* state) { 485 void Builtins::Generate_MathRound(CodeStubAssembler* assembler) {
506 CodeStubAssembler assembler(state); 486 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Round);
507 Generate_MathRoundingOperation(&assembler, &CodeStubAssembler::Float64Round);
508 } 487 }
509 488
510 // ES6 section 20.2.2.29 Math.sign ( x ) 489 // ES6 section 20.2.2.29 Math.sign ( x )
511 void Builtins::Generate_MathSign(compiler::CodeAssemblerState* state) { 490 void Builtins::Generate_MathSign(CodeStubAssembler* assembler) {
512 typedef CodeStubAssembler::Label Label; 491 typedef CodeStubAssembler::Label Label;
513 using compiler::Node; 492 using compiler::Node;
514 CodeStubAssembler assembler(state);
515 493
516 // Convert the {x} value to a Number. 494 // Convert the {x} value to a Number.
517 Node* x = assembler.Parameter(1); 495 Node* x = assembler->Parameter(1);
518 Node* context = assembler.Parameter(4); 496 Node* context = assembler->Parameter(4);
519 Node* x_value = assembler.TruncateTaggedToFloat64(context, x); 497 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
520 498
521 // Return -1 if {x} is negative, 1 if {x} is positive, or {x} itself. 499 // Return -1 if {x} is negative, 1 if {x} is positive, or {x} itself.
522 Label if_xisnegative(&assembler), if_xispositive(&assembler); 500 Label if_xisnegative(assembler), if_xispositive(assembler);
523 assembler.GotoIf( 501 assembler->GotoIf(
524 assembler.Float64LessThan(x_value, assembler.Float64Constant(0.0)), 502 assembler->Float64LessThan(x_value, assembler->Float64Constant(0.0)),
525 &if_xisnegative); 503 &if_xisnegative);
526 assembler.GotoIf( 504 assembler->GotoIf(
527 assembler.Float64LessThan(assembler.Float64Constant(0.0), x_value), 505 assembler->Float64LessThan(assembler->Float64Constant(0.0), x_value),
528 &if_xispositive); 506 &if_xispositive);
529 assembler.Return(assembler.ChangeFloat64ToTagged(x_value)); 507 assembler->Return(assembler->ChangeFloat64ToTagged(x_value));
530 508
531 assembler.Bind(&if_xisnegative); 509 assembler->Bind(&if_xisnegative);
532 assembler.Return(assembler.SmiConstant(Smi::FromInt(-1))); 510 assembler->Return(assembler->SmiConstant(Smi::FromInt(-1)));
533 511
534 assembler.Bind(&if_xispositive); 512 assembler->Bind(&if_xispositive);
535 assembler.Return(assembler.SmiConstant(Smi::FromInt(1))); 513 assembler->Return(assembler->SmiConstant(Smi::FromInt(1)));
536 } 514 }
537 515
538 // ES6 section 20.2.2.30 Math.sin ( x ) 516 // ES6 section 20.2.2.30 Math.sin ( x )
539 void Builtins::Generate_MathSin(compiler::CodeAssemblerState* state) { 517 void Builtins::Generate_MathSin(CodeStubAssembler* assembler) {
540 CodeStubAssembler assembler(state); 518 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Sin);
541 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Sin);
542 } 519 }
543 520
544 // ES6 section 20.2.2.31 Math.sinh ( x ) 521 // ES6 section 20.2.2.31 Math.sinh ( x )
545 void Builtins::Generate_MathSinh(compiler::CodeAssemblerState* state) { 522 void Builtins::Generate_MathSinh(CodeStubAssembler* assembler) {
546 CodeStubAssembler assembler(state); 523 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Sinh);
547 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Sinh);
548 } 524 }
549 525
550 // ES6 section 20.2.2.32 Math.sqrt ( x ) 526 // ES6 section 20.2.2.32 Math.sqrt ( x )
551 void Builtins::Generate_MathSqrt(compiler::CodeAssemblerState* state) { 527 void Builtins::Generate_MathSqrt(CodeStubAssembler* assembler) {
552 CodeStubAssembler assembler(state); 528 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Sqrt);
553 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Sqrt);
554 } 529 }
555 530
556 // ES6 section 20.2.2.33 Math.tan ( x ) 531 // ES6 section 20.2.2.33 Math.tan ( x )
557 void Builtins::Generate_MathTan(compiler::CodeAssemblerState* state) { 532 void Builtins::Generate_MathTan(CodeStubAssembler* assembler) {
558 CodeStubAssembler assembler(state); 533 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Tan);
559 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Tan);
560 } 534 }
561 535
562 // ES6 section 20.2.2.34 Math.tanh ( x ) 536 // ES6 section 20.2.2.34 Math.tanh ( x )
563 void Builtins::Generate_MathTanh(compiler::CodeAssemblerState* state) { 537 void Builtins::Generate_MathTanh(CodeStubAssembler* assembler) {
564 CodeStubAssembler assembler(state); 538 Generate_MathUnaryOperation(assembler, &CodeStubAssembler::Float64Tanh);
565 Generate_MathUnaryOperation(&assembler, &CodeStubAssembler::Float64Tanh);
566 } 539 }
567 540
568 // ES6 section 20.2.2.35 Math.trunc ( x ) 541 // ES6 section 20.2.2.35 Math.trunc ( x )
569 void Builtins::Generate_MathTrunc(compiler::CodeAssemblerState* state) { 542 void Builtins::Generate_MathTrunc(CodeStubAssembler* assembler) {
570 CodeStubAssembler assembler(state); 543 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Trunc);
571 Generate_MathRoundingOperation(&assembler, &CodeStubAssembler::Float64Trunc);
572 } 544 }
573 545
574 void Builtins::Generate_MathMax(MacroAssembler* masm) { 546 void Builtins::Generate_MathMax(MacroAssembler* masm) {
575 Generate_MathMaxMin(masm, MathMaxMinKind::kMax); 547 Generate_MathMaxMin(masm, MathMaxMinKind::kMax);
576 } 548 }
577 549
578 void Builtins::Generate_MathMin(MacroAssembler* masm) { 550 void Builtins::Generate_MathMin(MacroAssembler* masm) {
579 Generate_MathMaxMin(masm, MathMaxMinKind::kMin); 551 Generate_MathMaxMin(masm, MathMaxMinKind::kMin);
580 } 552 }
581 553
582 } // namespace internal 554 } // namespace internal
583 } // namespace v8 555 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins/builtins-iterator.cc ('k') | src/builtins/builtins-number.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698