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

Side by Side Diff: src/builtins.cc

Issue 1852553003: [builtins] Migrate Math.clz32 to a TurboFan builtin. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 8 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/builtins.h ('k') | src/compiler/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 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/builtins.h" 5 #include "src/builtins.h"
6 6
7 #include "src/api.h" 7 #include "src/api.h"
8 #include "src/api-arguments.h" 8 #include "src/api-arguments.h"
9 #include "src/api-natives.h" 9 #include "src/api-natives.h"
10 #include "src/base/once.h" 10 #include "src/base/once.h"
(...skipping 2164 matching lines...) Expand 10 before | Expand all | Expand 10 after
2175 } 2175 }
2176 2176
2177 } // namespace 2177 } // namespace
2178 2178
2179 // ES6 section 20.2.2.10 Math.ceil ( x ) 2179 // ES6 section 20.2.2.10 Math.ceil ( x )
2180 void Builtins::Generate_MathCeil(compiler::CodeStubAssembler* assembler) { 2180 void Builtins::Generate_MathCeil(compiler::CodeStubAssembler* assembler) {
2181 Generate_MathRoundingOperation(assembler, 2181 Generate_MathRoundingOperation(assembler,
2182 &compiler::CodeStubAssembler::Float64Ceil); 2182 &compiler::CodeStubAssembler::Float64Ceil);
2183 } 2183 }
2184 2184
2185 // ES6 section 20.2.2.11 Math.clz32 ( x )
2186 void Builtins::Generate_MathClz32(compiler::CodeStubAssembler* assembler) {
2187 typedef compiler::CodeStubAssembler::Label Label;
2188 typedef compiler::Node Node;
2189 typedef compiler::CodeStubAssembler::Variable Variable;
2190
2191 Node* context = assembler->Parameter(4);
2192
2193 // Shared entry point for the clz32 operation.
2194 Variable var_clz32_x(assembler, MachineRepresentation::kWord32);
2195 Label do_clz32(assembler);
2196
2197 // We might need to loop once for ToNumber conversion.
2198 Variable var_x(assembler, MachineRepresentation::kTagged);
2199 Label loop(assembler, &var_x);
2200 var_x.Bind(assembler->Parameter(1));
2201 assembler->Goto(&loop);
2202 assembler->Bind(&loop);
2203 {
2204 // Load the current {x} value.
2205 Node* x = var_x.value();
2206
2207 // Check if {x} is a Smi or a HeapObject.
2208 Label if_xissmi(assembler), if_xisnotsmi(assembler);
2209 assembler->Branch(assembler->WordIsSmi(x), &if_xissmi, &if_xisnotsmi);
2210
2211 assembler->Bind(&if_xissmi);
2212 {
2213 var_clz32_x.Bind(assembler->SmiToWord32(x));
2214 assembler->Goto(&do_clz32);
2215 }
2216
2217 assembler->Bind(&if_xisnotsmi);
2218 {
2219 // Check if {x} is a HeapNumber.
2220 Label if_xisheapnumber(assembler),
2221 if_xisnotheapnumber(assembler, Label::kDeferred);
2222 assembler->Branch(
2223 assembler->WordEqual(assembler->LoadMap(x),
2224 assembler->HeapNumberMapConstant()),
2225 &if_xisheapnumber, &if_xisnotheapnumber);
2226
2227 assembler->Bind(&if_xisheapnumber);
2228 {
2229 var_clz32_x.Bind(assembler->TruncateHeapNumberValueToWord32(x));
2230 assembler->Goto(&do_clz32);
2231 }
2232
2233 assembler->Bind(&if_xisnotheapnumber);
2234 {
2235 // Need to convert {x} to a Number first.
2236 Callable callable =
2237 CodeFactory::NonNumberToNumber(assembler->isolate());
2238 var_x.Bind(assembler->CallStub(callable, context, x));
2239 assembler->Goto(&loop);
2240 }
2241 }
2242 }
2243
2244 assembler->Bind(&do_clz32);
2245 {
2246 Node* x_value = var_clz32_x.value();
2247 Node* value = assembler->Word32Clz(x_value);
2248 Node* result = assembler->ChangeInt32ToTagged(value);
2249 assembler->Return(result);
2250 }
2251 }
2252
2185 // ES6 section 20.2.2.16 Math.floor ( x ) 2253 // ES6 section 20.2.2.16 Math.floor ( x )
2186 void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) { 2254 void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
2187 Generate_MathRoundingOperation(assembler, 2255 Generate_MathRoundingOperation(assembler,
2188 &compiler::CodeStubAssembler::Float64Floor); 2256 &compiler::CodeStubAssembler::Float64Floor);
2189 } 2257 }
2190 2258
2191 // ES6 section 20.2.2.17 Math.fround ( x ) 2259 // ES6 section 20.2.2.17 Math.fround ( x )
2192 BUILTIN(MathFround) { 2260 BUILTIN(MathFround) {
2193 HandleScope scope(isolate); 2261 HandleScope scope(isolate);
2194 DCHECK_EQ(2, args.length()); 2262 DCHECK_EQ(2, args.length());
(...skipping 2572 matching lines...) Expand 10 before | Expand all | Expand 10 after
4767 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 4835 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
4768 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4836 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4769 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4837 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4770 #undef DEFINE_BUILTIN_ACCESSOR_C 4838 #undef DEFINE_BUILTIN_ACCESSOR_C
4771 #undef DEFINE_BUILTIN_ACCESSOR_A 4839 #undef DEFINE_BUILTIN_ACCESSOR_A
4772 #undef DEFINE_BUILTIN_ACCESSOR_T 4840 #undef DEFINE_BUILTIN_ACCESSOR_T
4773 #undef DEFINE_BUILTIN_ACCESSOR_H 4841 #undef DEFINE_BUILTIN_ACCESSOR_H
4774 4842
4775 } // namespace internal 4843 } // namespace internal
4776 } // namespace v8 4844 } // namespace v8
OLDNEW
« no previous file with comments | « src/builtins.h ('k') | src/compiler/code-stub-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698