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

Unified Diff: src/builtins.cc

Issue 1827813004: [turbofan] Introduce proper abstractions for ToNumber truncations. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | src/code-stubs.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins.cc
diff --git a/src/builtins.cc b/src/builtins.cc
index ffad7b26487f1ff4017f697b2c8c0685ff6f4c92..b99806eedfe7106c1519e16a9f7960a58de8a441 100644
--- a/src/builtins.cc
+++ b/src/builtins.cc
@@ -2033,74 +2033,14 @@ BUILTIN(MathImul) {
// ES6 section 20.2.2.32 Math.sqrt ( x )
void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) {
- typedef compiler::CodeStubAssembler::Label Label;
- typedef compiler::Node Node;
- typedef compiler::CodeStubAssembler::Variable Variable;
+ using compiler::Node;
+ Node* x = assembler->Parameter(1);
Node* context = assembler->Parameter(4);
-
- // Shared entry for the floating point sqrt.
- Label do_fsqrt(assembler);
- Variable var_fsqrt_x(assembler, MachineRepresentation::kFloat64);
-
- // We might need to loop once due to the ToNumber conversion.
- Variable var_x(assembler, MachineRepresentation::kTagged);
- Label loop(assembler, &var_x);
- var_x.Bind(assembler->Parameter(1));
- assembler->Goto(&loop);
- assembler->Bind(&loop);
- {
- // Load the current {x} value.
- Node* x = var_x.value();
-
- // Check if {x} is a Smi or a HeapObject.
- Label if_xissmi(assembler), if_xisnotsmi(assembler);
- assembler->Branch(assembler->WordIsSmi(x), &if_xissmi, &if_xisnotsmi);
-
- assembler->Bind(&if_xissmi);
- {
- // Perform the floating point sqrt.
- var_fsqrt_x.Bind(assembler->SmiToFloat64(x));
- assembler->Goto(&do_fsqrt);
- }
-
- assembler->Bind(&if_xisnotsmi);
- {
- // Load the map of {x}.
- Node* x_map = assembler->LoadMap(x);
-
- // Check if {x} is a HeapNumber.
- Label if_xisnumber(assembler),
- if_xisnotnumber(assembler, Label::kDeferred);
- assembler->Branch(
- assembler->WordEqual(x_map, assembler->HeapNumberMapConstant()),
- &if_xisnumber, &if_xisnotnumber);
-
- assembler->Bind(&if_xisnumber);
- {
- // Perform the floating point sqrt.
- var_fsqrt_x.Bind(assembler->LoadHeapNumberValue(x));
- assembler->Goto(&do_fsqrt);
- }
-
- assembler->Bind(&if_xisnotnumber);
- {
- // Convert {x} to a Number first.
- Callable callable =
- CodeFactory::NonNumberToNumber(assembler->isolate());
- var_x.Bind(assembler->CallStub(callable, context, x));
- assembler->Goto(&loop);
- }
- }
- }
-
- assembler->Bind(&do_fsqrt);
- {
- Node* x = var_fsqrt_x.value();
- Node* value = assembler->Float64Sqrt(x);
- Node* result = assembler->AllocateHeapNumberWithValue(value);
- assembler->Return(result);
- }
+ Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
+ Node* value = assembler->Float64Sqrt(x_value);
+ Node* result = assembler->AllocateHeapNumberWithValue(value);
+ assembler->Return(result);
}
// -----------------------------------------------------------------------------
« no previous file with comments | « no previous file | src/code-stubs.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698