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