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 #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 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
102 void Builtins::Generate_NonPrimitiveToPrimitive_Number( | 102 void Builtins::Generate_NonPrimitiveToPrimitive_Number( |
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 compiler::Node* Builtins::GenerateImpl_StringToNumber( |
| 113 CodeStubAssembler* assembler, compiler::Node* input, |
| 114 compiler::Node* context) { |
113 typedef CodeStubAssembler::Label Label; | 115 typedef CodeStubAssembler::Label Label; |
114 typedef compiler::Node Node; | 116 typedef compiler::Node Node; |
115 typedef TypeConversionDescriptor Descriptor; | 117 typedef CodeStubAssembler::Variable Variable; |
116 | 118 |
117 Node* input = assembler->Parameter(Descriptor::kArgument); | 119 Label runtime(assembler, Label::kDeferred); |
118 Node* context = assembler->Parameter(Descriptor::kContext); | 120 Label end(assembler); |
119 | 121 |
120 Label runtime(assembler); | 122 Variable var_result(assembler, MachineRepresentation::kTagged); |
121 | 123 |
122 // Check if string has a cached array index. | 124 // Check if string has a cached array index. |
123 Node* hash = assembler->LoadNameHashField(input); | 125 Node* hash = assembler->LoadNameHashField(input); |
124 Node* bit = assembler->Word32And( | 126 Node* bit = assembler->Word32And( |
125 hash, assembler->Int32Constant(String::kContainsCachedArrayIndexMask)); | 127 hash, assembler->Int32Constant(String::kContainsCachedArrayIndexMask)); |
126 assembler->GotoIf(assembler->Word32NotEqual(bit, assembler->Int32Constant(0)), | 128 assembler->GotoIf(assembler->Word32NotEqual(bit, assembler->Int32Constant(0)), |
127 &runtime); | 129 &runtime); |
128 | 130 |
129 assembler->Return(assembler->SmiTag( | 131 var_result.Bind(assembler->SmiTag( |
130 assembler->BitFieldDecode<String::ArrayIndexValueBits>(hash))); | 132 assembler->BitFieldDecode<String::ArrayIndexValueBits>(hash))); |
| 133 assembler->Goto(&end); |
131 | 134 |
132 assembler->Bind(&runtime); | 135 assembler->Bind(&runtime); |
133 { | 136 { |
134 // Note: We cannot tail call to the runtime here, as js-to-wasm | 137 // Note: We cannot tail call to the runtime here, as js-to-wasm |
135 // trampolines also use this code currently, and they declare all | 138 // trampolines also use this code currently, and they declare all |
136 // outgoing parameters as untagged, while we would push a tagged | 139 // outgoing parameters as untagged, while we would push a tagged |
137 // object here. | 140 // object here. |
138 Node* result = | 141 var_result.Bind( |
139 assembler->CallRuntime(Runtime::kStringToNumber, context, input); | 142 assembler->CallRuntime(Runtime::kStringToNumber, context, input)); |
140 assembler->Return(result); | 143 assembler->Goto(&end); |
141 } | 144 } |
| 145 |
| 146 assembler->Bind(&end); |
| 147 return var_result.value(); |
| 148 } |
| 149 |
| 150 void Builtins::Generate_StringToNumber(CodeStubAssembler* assembler) { |
| 151 typedef TypeConversionDescriptor Descriptor; |
| 152 assembler->Return(Builtins::GenerateImpl_StringToNumber( |
| 153 assembler, assembler->Parameter(Descriptor::kArgument), |
| 154 assembler->Parameter(Descriptor::kContext))); |
142 } | 155 } |
143 | 156 |
144 // ES6 section 7.1.3 ToNumber ( argument ) | 157 // ES6 section 7.1.3 ToNumber ( argument ) |
145 void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) { | 158 void Builtins::Generate_NonNumberToNumber(CodeStubAssembler* assembler) { |
146 typedef CodeStubAssembler::Label Label; | 159 typedef CodeStubAssembler::Label Label; |
147 typedef compiler::Node Node; | 160 typedef compiler::Node Node; |
148 typedef CodeStubAssembler::Variable Variable; | 161 typedef CodeStubAssembler::Variable Variable; |
149 typedef TypeConversionDescriptor Descriptor; | 162 typedef TypeConversionDescriptor Descriptor; |
150 | 163 |
151 Node* input = assembler->Parameter(Descriptor::kArgument); | 164 Node* input = assembler->Parameter(Descriptor::kArgument); |
(...skipping 24 matching lines...) Expand all Loading... |
176 &if_inputisoddball); | 189 &if_inputisoddball); |
177 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); | 190 STATIC_ASSERT(LAST_JS_RECEIVER_TYPE == LAST_TYPE); |
178 assembler->Branch(assembler->Int32GreaterThanOrEqual( | 191 assembler->Branch(assembler->Int32GreaterThanOrEqual( |
179 input_instance_type, | 192 input_instance_type, |
180 assembler->Int32Constant(FIRST_JS_RECEIVER_TYPE)), | 193 assembler->Int32Constant(FIRST_JS_RECEIVER_TYPE)), |
181 &if_inputisreceiver, &if_inputisother); | 194 &if_inputisreceiver, &if_inputisother); |
182 | 195 |
183 assembler->Bind(&if_inputisstring); | 196 assembler->Bind(&if_inputisstring); |
184 { | 197 { |
185 // The {input} is a String, use the fast stub to convert it to a Number. | 198 // The {input} is a String, use the fast stub to convert it to a Number. |
186 // TODO(bmeurer): Consider inlining the StringToNumber logic here. | 199 assembler->Return( |
187 Callable callable = CodeFactory::StringToNumber(assembler->isolate()); | 200 Builtins::GenerateImpl_StringToNumber(assembler, input, context)); |
188 assembler->TailCallStub(callable, context, input); | |
189 } | 201 } |
190 | 202 |
191 assembler->Bind(&if_inputisoddball); | 203 assembler->Bind(&if_inputisoddball); |
192 { | 204 { |
193 // The {input} is an Oddball, we just need to the Number value of it. | 205 // The {input} is an Oddball, we just need to the Number value of it. |
194 Node* result = | 206 Node* result = |
195 assembler->LoadObjectField(input, Oddball::kToNumberOffset); | 207 assembler->LoadObjectField(input, Oddball::kToNumberOffset); |
196 assembler->Return(result); | 208 assembler->Return(result); |
197 } | 209 } |
198 | 210 |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
348 | 360 |
349 assembler->Bind(&return_true); | 361 assembler->Bind(&return_true); |
350 assembler->Return(assembler->BooleanConstant(true)); | 362 assembler->Return(assembler->BooleanConstant(true)); |
351 | 363 |
352 assembler->Bind(&return_false); | 364 assembler->Bind(&return_false); |
353 assembler->Return(assembler->BooleanConstant(false)); | 365 assembler->Return(assembler->BooleanConstant(false)); |
354 } | 366 } |
355 | 367 |
356 } // namespace internal | 368 } // namespace internal |
357 } // namespace v8 | 369 } // namespace v8 |
OLD | NEW |