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

Side by Side Diff: src/builtins.cc

Issue 1841993002: [builtins] Make Math.ceil, Math.trunc and Math.round optimizable. (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 1989 matching lines...) Expand 10 before | Expand all | Expand 10 after
2000 2000
2001 // ES6 section 20.2.2.6 Math.atan ( x ) 2001 // ES6 section 20.2.2.6 Math.atan ( x )
2002 BUILTIN(MathAtan) { 2002 BUILTIN(MathAtan) {
2003 HandleScope scope(isolate); 2003 HandleScope scope(isolate);
2004 DCHECK_EQ(2, args.length()); 2004 DCHECK_EQ(2, args.length());
2005 Handle<Object> x = args.at<Object>(1); 2005 Handle<Object> x = args.at<Object>(1);
2006 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); 2006 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x));
2007 return *isolate->factory()->NewHeapNumber(std::atan(x->Number())); 2007 return *isolate->factory()->NewHeapNumber(std::atan(x->Number()));
2008 } 2008 }
2009 2009
2010 // ES6 section 20.2.2.16 Math.floor ( x ) 2010 namespace {
2011 void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) { 2011
2012 void Generate_MathRoundingOperation(
2013 compiler::CodeStubAssembler* assembler,
2014 compiler::Node* (compiler::CodeStubAssembler::*float64op)(
2015 compiler::Node*)) {
2012 typedef compiler::CodeStubAssembler::Label Label; 2016 typedef compiler::CodeStubAssembler::Label Label;
2013 typedef compiler::Node Node; 2017 typedef compiler::Node Node;
2014 typedef compiler::CodeStubAssembler::Variable Variable; 2018 typedef compiler::CodeStubAssembler::Variable Variable;
2015 2019
2016 Node* context = assembler->Parameter(4); 2020 Node* context = assembler->Parameter(4);
2017 2021
2018 // We might need to loop once for ToNumber conversion. 2022 // We might need to loop once for ToNumber conversion.
2019 Variable var_x(assembler, MachineRepresentation::kTagged); 2023 Variable var_x(assembler, MachineRepresentation::kTagged);
2020 Label loop(assembler, &var_x); 2024 Label loop(assembler, &var_x);
2021 var_x.Bind(assembler->Parameter(1)); 2025 var_x.Bind(assembler->Parameter(1));
(...skipping 19 matching lines...) Expand all
2041 Label if_xisheapnumber(assembler), 2045 Label if_xisheapnumber(assembler),
2042 if_xisnotheapnumber(assembler, Label::kDeferred); 2046 if_xisnotheapnumber(assembler, Label::kDeferred);
2043 assembler->Branch( 2047 assembler->Branch(
2044 assembler->WordEqual(assembler->LoadMap(x), 2048 assembler->WordEqual(assembler->LoadMap(x),
2045 assembler->HeapNumberMapConstant()), 2049 assembler->HeapNumberMapConstant()),
2046 &if_xisheapnumber, &if_xisnotheapnumber); 2050 &if_xisheapnumber, &if_xisnotheapnumber);
2047 2051
2048 assembler->Bind(&if_xisheapnumber); 2052 assembler->Bind(&if_xisheapnumber);
2049 { 2053 {
2050 Node* x_value = assembler->LoadHeapNumberValue(x); 2054 Node* x_value = assembler->LoadHeapNumberValue(x);
2051 Node* value = assembler->Float64Floor(x_value); 2055 Node* value = (assembler->*float64op)(x_value);
2052 Node* result = assembler->ChangeFloat64ToTagged(value); 2056 Node* result = assembler->ChangeFloat64ToTagged(value);
2053 assembler->Return(result); 2057 assembler->Return(result);
2054 } 2058 }
2055 2059
2056 assembler->Bind(&if_xisnotheapnumber); 2060 assembler->Bind(&if_xisnotheapnumber);
2057 { 2061 {
2058 // Need to convert {x} to a Number first. 2062 // Need to convert {x} to a Number first.
2059 Callable callable = 2063 Callable callable =
2060 CodeFactory::NonNumberToNumber(assembler->isolate()); 2064 CodeFactory::NonNumberToNumber(assembler->isolate());
2061 var_x.Bind(assembler->CallStub(callable, context, x)); 2065 var_x.Bind(assembler->CallStub(callable, context, x));
2062 assembler->Goto(&loop); 2066 assembler->Goto(&loop);
2063 } 2067 }
2064 } 2068 }
2065 } 2069 }
2066 } 2070 }
2067 2071
2072 } // namespace
2073
2074 // ES6 section 20.2.2.10 Math.ceil ( x )
2075 void Builtins::Generate_MathCeil(compiler::CodeStubAssembler* assembler) {
2076 Generate_MathRoundingOperation(assembler,
2077 &compiler::CodeStubAssembler::Float64Ceil);
2078 }
2079
2080 // ES6 section 20.2.2.16 Math.floor ( x )
2081 void Builtins::Generate_MathFloor(compiler::CodeStubAssembler* assembler) {
2082 Generate_MathRoundingOperation(assembler,
2083 &compiler::CodeStubAssembler::Float64Floor);
2084 }
2085
2068 // ES6 section 20.2.2.17 Math.fround ( x ) 2086 // ES6 section 20.2.2.17 Math.fround ( x )
2069 BUILTIN(MathFround) { 2087 BUILTIN(MathFround) {
2070 HandleScope scope(isolate); 2088 HandleScope scope(isolate);
2071 DCHECK_EQ(2, args.length()); 2089 DCHECK_EQ(2, args.length());
2072 Handle<Object> x = args.at<Object>(1); 2090 Handle<Object> x = args.at<Object>(1);
2073 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); 2091 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x));
2074 float x32 = DoubleToFloat32(x->Number()); 2092 float x32 = DoubleToFloat32(x->Number());
2075 return *isolate->factory()->NewNumber(x32); 2093 return *isolate->factory()->NewNumber(x32);
2076 } 2094 }
2077 2095
2078 // ES6 section 20.2.2.19 Math.imul ( x, y ) 2096 // ES6 section 20.2.2.19 Math.imul ( x, y )
2079 BUILTIN(MathImul) { 2097 BUILTIN(MathImul) {
2080 HandleScope scope(isolate); 2098 HandleScope scope(isolate);
2081 DCHECK_EQ(3, args.length()); 2099 DCHECK_EQ(3, args.length());
2082 Handle<Object> x = args.at<Object>(1); 2100 Handle<Object> x = args.at<Object>(1);
2083 Handle<Object> y = args.at<Object>(2); 2101 Handle<Object> y = args.at<Object>(2);
2084 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x)); 2102 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, x, Object::ToNumber(x));
2085 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y)); 2103 ASSIGN_RETURN_FAILURE_ON_EXCEPTION(isolate, y, Object::ToNumber(y));
2086 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y)); 2104 int product = static_cast<int>(NumberToUint32(*x) * NumberToUint32(*y));
2087 return *isolate->factory()->NewNumberFromInt(product); 2105 return *isolate->factory()->NewNumberFromInt(product);
2088 } 2106 }
2089 2107
2108 // ES6 section 20.2.2.28 Math.round ( x )
2109 void Builtins::Generate_MathRound(compiler::CodeStubAssembler* assembler) {
2110 Generate_MathRoundingOperation(assembler,
2111 &compiler::CodeStubAssembler::Float64Round);
2112 }
2113
2090 // ES6 section 20.2.2.32 Math.sqrt ( x ) 2114 // ES6 section 20.2.2.32 Math.sqrt ( x )
2091 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) { 2115 void Builtins::Generate_MathSqrt(compiler::CodeStubAssembler* assembler) {
2092 using compiler::Node; 2116 using compiler::Node;
2093 2117
2094 Node* x = assembler->Parameter(1); 2118 Node* x = assembler->Parameter(1);
2095 Node* context = assembler->Parameter(4); 2119 Node* context = assembler->Parameter(4);
2096 Node* x_value = assembler->TruncateTaggedToFloat64(context, x); 2120 Node* x_value = assembler->TruncateTaggedToFloat64(context, x);
2097 Node* value = assembler->Float64Sqrt(x_value); 2121 Node* value = assembler->Float64Sqrt(x_value);
2098 Node* result = assembler->ChangeFloat64ToTagged(value); 2122 Node* result = assembler->ChangeFloat64ToTagged(value);
2099 assembler->Return(result); 2123 assembler->Return(result);
2100 } 2124 }
2101 2125
2126 // ES6 section 20.2.2.35 Math.trunc ( x )
2127 void Builtins::Generate_MathTrunc(compiler::CodeStubAssembler* assembler) {
2128 Generate_MathRoundingOperation(assembler,
2129 &compiler::CodeStubAssembler::Float64Trunc);
2130 }
2131
2102 // ----------------------------------------------------------------------------- 2132 // -----------------------------------------------------------------------------
2103 // ES6 section 26.1 The Reflect Object 2133 // ES6 section 26.1 The Reflect Object
2104 2134
2105 2135
2106 // ES6 section 26.1.3 Reflect.defineProperty 2136 // ES6 section 26.1.3 Reflect.defineProperty
2107 BUILTIN(ReflectDefineProperty) { 2137 BUILTIN(ReflectDefineProperty) {
2108 HandleScope scope(isolate); 2138 HandleScope scope(isolate);
2109 DCHECK_EQ(4, args.length()); 2139 DCHECK_EQ(4, args.length());
2110 Handle<Object> target = args.at<Object>(1); 2140 Handle<Object> target = args.at<Object>(1);
2111 Handle<Object> key = args.at<Object>(2); 2141 Handle<Object> key = args.at<Object>(2);
(...skipping 2520 matching lines...) Expand 10 before | Expand all | Expand 10 after
4632 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T) 4662 BUILTIN_LIST_T(DEFINE_BUILTIN_ACCESSOR_T)
4633 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H) 4663 BUILTIN_LIST_H(DEFINE_BUILTIN_ACCESSOR_H)
4634 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A) 4664 BUILTIN_LIST_DEBUG_A(DEFINE_BUILTIN_ACCESSOR_A)
4635 #undef DEFINE_BUILTIN_ACCESSOR_C 4665 #undef DEFINE_BUILTIN_ACCESSOR_C
4636 #undef DEFINE_BUILTIN_ACCESSOR_A 4666 #undef DEFINE_BUILTIN_ACCESSOR_A
4637 #undef DEFINE_BUILTIN_ACCESSOR_T 4667 #undef DEFINE_BUILTIN_ACCESSOR_T
4638 #undef DEFINE_BUILTIN_ACCESSOR_H 4668 #undef DEFINE_BUILTIN_ACCESSOR_H
4639 4669
4640 } // namespace internal 4670 } // namespace internal
4641 } // namespace v8 4671 } // 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