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 { |
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
445 Node* x = assembler->Parameter(1); | 445 Node* x = assembler->Parameter(1); |
446 Node* y = assembler->Parameter(2); | 446 Node* y = assembler->Parameter(2); |
447 Node* context = assembler->Parameter(5); | 447 Node* context = assembler->Parameter(5); |
448 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); | 448 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); |
449 Node* y_value = assembler->TruncateTaggedToFloat64(context, y); | 449 Node* y_value = assembler->TruncateTaggedToFloat64(context, y); |
450 Node* value = assembler->Float64Pow(x_value, y_value); | 450 Node* value = assembler->Float64Pow(x_value, y_value); |
451 Node* result = assembler->ChangeFloat64ToTagged(value); | 451 Node* result = assembler->ChangeFloat64ToTagged(value); |
452 assembler->Return(result); | 452 assembler->Return(result); |
453 } | 453 } |
454 | 454 |
| 455 // ES6 section 20.2.2.27 Math.random ( ) |
| 456 void Builtins::Generate_MathRandom(CodeStubAssembler* assembler) { |
| 457 using compiler::Node; |
| 458 |
| 459 Node* context = assembler->Parameter(3); |
| 460 Node* native_context = assembler->LoadNativeContext(context); |
| 461 |
| 462 // Load cache index. |
| 463 CodeStubAssembler::Variable smi_index(assembler, |
| 464 MachineRepresentation::kTagged); |
| 465 smi_index.Bind(assembler->LoadContextElement( |
| 466 native_context, Context::MATH_RANDOM_INDEX_INDEX)); |
| 467 |
| 468 // Cached random numbers are exhausted if index is 0. Go to slow path. |
| 469 CodeStubAssembler::Label if_cached(assembler); |
| 470 assembler->GotoIf(assembler->SmiAbove(smi_index.value(), |
| 471 assembler->SmiConstant(Smi::kZero)), |
| 472 &if_cached); |
| 473 |
| 474 // Cache exhausted, populate the cache. Return value is the new index. |
| 475 smi_index.Bind( |
| 476 assembler->CallRuntime(Runtime::kGenerateRandomNumbers, context)); |
| 477 assembler->Goto(&if_cached); |
| 478 |
| 479 // Compute next index by decrement. |
| 480 assembler->Bind(&if_cached); |
| 481 Node* new_smi_index = assembler->SmiSub( |
| 482 smi_index.value(), assembler->SmiConstant(Smi::FromInt(1))); |
| 483 assembler->StoreContextElement( |
| 484 native_context, Context::MATH_RANDOM_INDEX_INDEX, new_smi_index); |
| 485 |
| 486 // Load and return next cached random number. |
| 487 Node* array = assembler->LoadContextElement(native_context, |
| 488 Context::MATH_RANDOM_CACHE_INDEX); |
| 489 Node* random = assembler->LoadFixedDoubleArrayElement( |
| 490 array, new_smi_index, MachineType::Float64(), 0, |
| 491 CodeStubAssembler::SMI_PARAMETERS); |
| 492 assembler->Return(assembler->ChangeFloat64ToTagged(random)); |
| 493 } |
| 494 |
455 // ES6 section 20.2.2.28 Math.round ( x ) | 495 // ES6 section 20.2.2.28 Math.round ( x ) |
456 void Builtins::Generate_MathRound(CodeStubAssembler* assembler) { | 496 void Builtins::Generate_MathRound(CodeStubAssembler* assembler) { |
457 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Round); | 497 Generate_MathRoundingOperation(assembler, &CodeStubAssembler::Float64Round); |
458 } | 498 } |
459 | 499 |
460 // ES6 section 20.2.2.29 Math.sign ( x ) | 500 // ES6 section 20.2.2.29 Math.sign ( x ) |
461 void Builtins::Generate_MathSign(CodeStubAssembler* assembler) { | 501 void Builtins::Generate_MathSign(CodeStubAssembler* assembler) { |
462 typedef CodeStubAssembler::Label Label; | 502 typedef CodeStubAssembler::Label Label; |
463 using compiler::Node; | 503 using compiler::Node; |
464 | 504 |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
552 void Builtins::Generate_MathMax(MacroAssembler* masm) { | 592 void Builtins::Generate_MathMax(MacroAssembler* masm) { |
553 Generate_MathMaxMin(masm, MathMaxMinKind::kMax); | 593 Generate_MathMaxMin(masm, MathMaxMinKind::kMax); |
554 } | 594 } |
555 | 595 |
556 void Builtins::Generate_MathMin(MacroAssembler* masm) { | 596 void Builtins::Generate_MathMin(MacroAssembler* masm) { |
557 Generate_MathMaxMin(masm, MathMaxMinKind::kMin); | 597 Generate_MathMaxMin(masm, MathMaxMinKind::kMin); |
558 } | 598 } |
559 | 599 |
560 } // namespace internal | 600 } // namespace internal |
561 } // namespace v8 | 601 } // namespace v8 |
OLD | NEW |