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

Side by Side Diff: src/code-stubs.cc

Issue 2364473006: [stubs] Extract ToInteger to CodeStubAssembler (Closed)
Patch Set: Created 4 years, 3 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 unified diff | Download patch
« no previous file with comments | « src/code-stub-assembler.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 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/code-stubs.h" 5 #include "src/code-stubs.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "src/ast/ast.h" 9 #include "src/ast/ast.h"
10 #include "src/bootstrapper.h" 10 #include "src/bootstrapper.h"
(...skipping 4909 matching lines...) Expand 10 before | Expand all | Expand 10 after
4920 4920
4921 assembler->Bind(&return_two53minus1); 4921 assembler->Bind(&return_two53minus1);
4922 assembler->Return(assembler->NumberConstant(kMaxSafeInteger)); 4922 assembler->Return(assembler->NumberConstant(kMaxSafeInteger));
4923 4923
4924 assembler->Bind(&return_zero); 4924 assembler->Bind(&return_zero);
4925 assembler->Return(assembler->SmiConstant(Smi::FromInt(0))); 4925 assembler->Return(assembler->SmiConstant(Smi::FromInt(0)));
4926 } 4926 }
4927 } 4927 }
4928 4928
4929 void ToIntegerStub::GenerateAssembly(CodeStubAssembler* assembler) const { 4929 void ToIntegerStub::GenerateAssembly(CodeStubAssembler* assembler) const {
4930 typedef CodeStubAssembler::Label Label;
4931 typedef compiler::Node Node; 4930 typedef compiler::Node Node;
4932 typedef CodeStubAssembler::Variable Variable;
4933 4931
4934 Node* context = assembler->Parameter(1); 4932 Node* input = assembler->Parameter(Descriptor::kArgument);
4933 Node* context = assembler->Parameter(Descriptor::kContext);
4935 4934
4936 // We might need to loop once for ToNumber conversion. 4935 assembler->Return(assembler->ToInteger(context, input));
4937 Variable var_arg(assembler, MachineRepresentation::kTagged);
4938 Label loop(assembler, &var_arg);
4939 var_arg.Bind(assembler->Parameter(0));
4940 assembler->Goto(&loop);
4941 assembler->Bind(&loop);
4942 {
4943 // Shared entry points.
4944 Label return_arg(assembler), return_zero(assembler, Label::kDeferred);
4945
4946 // Load the current {arg} value.
4947 Node* arg = var_arg.value();
4948
4949 // Check if {arg} is a Smi.
4950 assembler->GotoIf(assembler->WordIsSmi(arg), &return_arg);
4951
4952 // Check if {arg} is a HeapNumber.
4953 Label if_argisheapnumber(assembler),
4954 if_argisnotheapnumber(assembler, Label::kDeferred);
4955 assembler->Branch(assembler->WordEqual(assembler->LoadMap(arg),
4956 assembler->HeapNumberMapConstant()),
4957 &if_argisheapnumber, &if_argisnotheapnumber);
4958
4959 assembler->Bind(&if_argisheapnumber);
4960 {
4961 // Load the floating-point value of {arg}.
4962 Node* arg_value = assembler->LoadHeapNumberValue(arg);
4963
4964 // Check if {arg} is NaN.
4965 assembler->GotoUnless(assembler->Float64Equal(arg_value, arg_value),
4966 &return_zero);
4967
4968 // Truncate {arg} towards zero.
4969 Node* value = assembler->Float64Trunc(arg_value);
4970 var_arg.Bind(assembler->ChangeFloat64ToTagged(value));
4971 assembler->Goto(&return_arg);
4972 }
4973
4974 assembler->Bind(&if_argisnotheapnumber);
4975 {
4976 // Need to convert {arg} to a Number first.
4977 Callable callable = CodeFactory::NonNumberToNumber(assembler->isolate());
4978 var_arg.Bind(assembler->CallStub(callable, context, arg));
4979 assembler->Goto(&loop);
4980 }
4981
4982 assembler->Bind(&return_arg);
4983 assembler->Return(var_arg.value());
4984
4985 assembler->Bind(&return_zero);
4986 assembler->Return(assembler->SmiConstant(Smi::FromInt(0)));
4987 }
4988 } 4936 }
4989 4937
4990 void StoreInterceptorStub::GenerateAssembly( 4938 void StoreInterceptorStub::GenerateAssembly(
4991 CodeStubAssembler* assembler) const { 4939 CodeStubAssembler* assembler) const {
4992 typedef compiler::Node Node; 4940 typedef compiler::Node Node;
4993 4941
4994 Node* receiver = assembler->Parameter(Descriptor::kReceiver); 4942 Node* receiver = assembler->Parameter(Descriptor::kReceiver);
4995 Node* name = assembler->Parameter(Descriptor::kName); 4943 Node* name = assembler->Parameter(Descriptor::kName);
4996 Node* value = assembler->Parameter(Descriptor::kValue); 4944 Node* value = assembler->Parameter(Descriptor::kValue);
4997 Node* context = assembler->Parameter(Descriptor::kContext); 4945 Node* context = assembler->Parameter(Descriptor::kContext);
(...skipping 1319 matching lines...) Expand 10 before | Expand all | Expand 10 after
6317 6265
6318 if (type == MachineType::Pointer()) { 6266 if (type == MachineType::Pointer()) {
6319 return Representation::External(); 6267 return Representation::External();
6320 } 6268 }
6321 6269
6322 return Representation::Tagged(); 6270 return Representation::Tagged();
6323 } 6271 }
6324 6272
6325 } // namespace internal 6273 } // namespace internal
6326 } // namespace v8 6274 } // namespace v8
OLDNEW
« no previous file with comments | « src/code-stub-assembler.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698