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

Unified Diff: src/builtins/builtins-math.cc

Issue 2728463006: Migrate Math.Min/Max to CodeStubAssembler (Closed)
Patch Set: Created 3 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/code-assembler.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/builtins/builtins-math.cc
diff --git a/src/builtins/builtins-math.cc b/src/builtins/builtins-math.cc
index f5249138c7a51f75955879e5a9b035e105910189..19dc52bd427f1dedf5369188d9c636515c191c4c 100644
--- a/src/builtins/builtins-math.cc
+++ b/src/builtins/builtins-math.cc
@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include <limits>
+
#include "src/builtins/builtins-utils.h"
#include "src/builtins/builtins.h"
#include "src/code-factory.h"
@@ -494,8 +496,37 @@ TF_BUILTIN(MathTrunc, MathBuiltinsAssembler) {
MathRoundingOperation(&CodeStubAssembler::Float64Trunc);
}
-void Builtins::Generate_MathMax(MacroAssembler* masm) {
- Generate_MathMaxMin(masm, MathMaxMinKind::kMax);
+// ES6 section 20.2.2.24 Math.max ( value1, value2 , ...values )
+TF_BUILTIN(MathMax, MathBuiltinsAssembler) {
+ Label return_result(this), return_nan(this);
+
+ Node* argc = Parameter(BuiltinDescriptor::kArgumentsCount);
+ Node* context = Parameter(BuiltinDescriptor::kContext);
+
+ CodeStubArguments arguments(this, ChangeInt32ToIntPtr(argc));
+ // From now on use word-size argc value.
+ argc = arguments.GetLength();
+
+ // If no arguments are given, the result is -infinity.
+ Variable result(this, MachineRepresentation::kFloat64);
+ result.Bind(Float64Constant(-1.0 * V8_INFINITY));
+ GotoIf(IntPtrEqual(argc, IntPtrConstant(0)), &return_result);
+
+ Node* nan = Float64Constant(std::numeric_limits<double>::quiet_NaN());
+ CodeStubAssembler::VariableList vars({&result}, zone());
+ arguments.ForEach(vars,
+ [this, context, nan, &result, &return_nan](Node* arg) {
+ Node* float_value = TruncateTaggedToFloat64(context, arg);
+ GotoIf(Float64Equal(float_value, nan), &return_nan);
vabr (Chromium) 2017/03/03 10:39:14 Interestingly, when I remove this jump, the perfor
+ result.Bind(Float64Max(result.value(), float_value));
+ });
+
+ Goto(&return_result);
+ Bind(&return_result);
+ { arguments.PopAndReturn(AllocateHeapNumberWithValue(result.value())); }
+
+ Bind(&return_nan);
+ { arguments.PopAndReturn(AllocateHeapNumberWithValue(nan)); }
}
void Builtins::Generate_MathMin(MacroAssembler* masm) {
« no previous file with comments | « src/builtins/builtins.h ('k') | src/compiler/code-assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698