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