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

Side by Side Diff: src/builtins/builtins-conversion.cc

Issue 2293943002: [builtins] Create StringToNumber helper. (Closed)
Patch Set: Addressed nits. 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 | « no previous file | src/code-stub-assembler.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "src/code-factory.h" 7 #include "src/code-factory.h"
8 8
9 namespace v8 { 9 namespace v8 {
10 namespace internal { 10 namespace internal {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
103 CodeStubAssembler* assembler) { 103 CodeStubAssembler* assembler) {
104 Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kNumber); 104 Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kNumber);
105 } 105 }
106 106
107 void Builtins::Generate_NonPrimitiveToPrimitive_String( 107 void Builtins::Generate_NonPrimitiveToPrimitive_String(
108 CodeStubAssembler* assembler) { 108 CodeStubAssembler* assembler) {
109 Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kString); 109 Generate_NonPrimitiveToPrimitive(assembler, ToPrimitiveHint::kString);
110 } 110 }
111 111
112 void Builtins::Generate_StringToNumber(CodeStubAssembler* assembler) { 112 void Builtins::Generate_StringToNumber(CodeStubAssembler* assembler) {
113 typedef CodeStubAssembler::Label Label;
114 typedef compiler::Node Node; 113 typedef compiler::Node Node;
115 typedef TypeConversionDescriptor Descriptor; 114 typedef TypeConversionDescriptor Descriptor;
116 115
117 Node* input = assembler->Parameter(Descriptor::kArgument); 116 Node* input = assembler->Parameter(Descriptor::kArgument);
118 Node* context = assembler->Parameter(Descriptor::kContext); 117 Node* context = assembler->Parameter(Descriptor::kContext);
119 118
120 Label runtime(assembler); 119 assembler->Return(assembler->StringToNumber(context, input));
121
122 // Check if string has a cached array index.
123 Node* hash = assembler->LoadNameHashField(input);
124 Node* bit = assembler->Word32And(
125 hash, assembler->Int32Constant(String::kContainsCachedArrayIndexMask));
126 assembler->GotoIf(assembler->Word32NotEqual(bit, assembler->Int32Constant(0)),
127 &runtime);
128
129 assembler->Return(assembler->SmiTag(
130 assembler->BitFieldDecode<String::ArrayIndexValueBits>(hash)));
131
132 assembler->Bind(&runtime);
133 {
134 // Note: We cannot tail call to the runtime here, as js-to-wasm
135 // trampolines also use this code currently, and they declare all
136 // outgoing parameters as untagged, while we would push a tagged
137 // object here.
138 Node* result =
139 assembler->CallRuntime(Runtime::kStringToNumber, context, input);
140 assembler->Return(result);
141 }
142 } 120 }
143 121
144 // ES6 section 7.1.3 ToNumber ( argument ) 122 // ES6 section 7.1.3 ToNumber ( argument )
145 void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) { 123 void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) {
146 typedef CodeStubAssembler::Label Label; 124 typedef CodeStubAssembler::Label Label;
147 typedef compiler::Node Node; 125 typedef compiler::Node Node;
148 typedef CodeStubAssembler::Variable Variable; 126 typedef CodeStubAssembler::Variable Variable;
149 typedef TypeConversionDescriptor Descriptor; 127 typedef TypeConversionDescriptor Descriptor;
150 128
151 Node* input = assembler->Parameter(Descriptor::kArgument); 129 Node* input = assembler->Parameter(Descriptor::kArgument);
(...skipping 24 matching lines...) Expand all
176 &if_inputisoddball); 154 &if_inputisoddball);
177 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); 155 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE);
178 assembler->Branch(assembler->Int32GreaterThanOrEqual( 156 assembler->Branch(assembler->Int32GreaterThanOrEqual(
179 input_instance_type, 157 input_instance_type,
180 assembler->Int32Constant(FIRST_JS_RECEIVER_TYPE)), 158 assembler->Int32Constant(FIRST_JS_RECEIVER_TYPE)),
181 &if_inputisreceiver, &if_inputisother); 159 &if_inputisreceiver, &if_inputisother);
182 160
183 assembler->Bind(&if_inputisstring); 161 assembler->Bind(&if_inputisstring);
184 { 162 {
185 // The {input} is a String, use the fast stub to convert it to a Number. 163 // The {input} is a String, use the fast stub to convert it to a Number.
186 // TODO(bmeurer): Consider inlining the StringToNumber logic here. 164 assembler->Return(assembler->StringToNumber(context, input));
187 Callable callable = CodeFactory::StringToNumber(assembler->isolate());
188 assembler->TailCallStub(callable, context, input);
189 } 165 }
190 166
191 assembler->Bind(&if_inputisoddball); 167 assembler->Bind(&if_inputisoddball);
192 { 168 {
193 // The {input} is an Oddball, we just need to the Number value of it. 169 // The {input} is an Oddball, we just need to the Number value of it.
194 Node* result = 170 Node* result =
195 assembler->LoadObjectField(input, Oddball::kToNumberOffset); 171 assembler->LoadObjectField(input, Oddball::kToNumberOffset);
196 assembler->Return(result); 172 assembler->Return(result);
197 } 173 }
198 174
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
348 324
349 assembler->Bind(&return_true); 325 assembler->Bind(&return_true);
350 assembler->Return(assembler->BooleanConstant(true)); 326 assembler->Return(assembler->BooleanConstant(true));
351 327
352 assembler->Bind(&return_false); 328 assembler->Bind(&return_false);
353 assembler->Return(assembler->BooleanConstant(false)); 329 assembler->Return(assembler->BooleanConstant(false));
354 } 330 }
355 331
356 } // namespace internal 332 } // namespace internal
357 } // namespace v8 333 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698