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: ChangeFloat64ToTagged 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/builtins/ia32/builtins-ia32.cc » ('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..2054e4e428d1c83cb653fba8382c53502a314195 100644
--- a/src/builtins/builtins-math.cc
+++ b/src/builtins/builtins-math.cc
@@ -23,6 +23,8 @@ class MathBuiltinsAssembler : public CodeStubAssembler {
protected:
void MathRoundingOperation(Node* (CodeStubAssembler::*float64op)(Node*));
void MathUnaryOperation(Node* (CodeStubAssembler::*float64op)(Node*));
+ void MathMaxMin(Node* (CodeStubAssembler::*float64op)(Node*, Node*),
+ double default_val);
};
// ES6 section - 20.2.2.1 Math.abs ( x )
@@ -163,6 +165,26 @@ void MathBuiltinsAssembler::MathUnaryOperation(
Return(result);
}
+void MathBuiltinsAssembler::MathMaxMin(
+ Node* (CodeStubAssembler::*float64op)(Node*, Node*), double default_val) {
+ Node* argc = Parameter(BuiltinDescriptor::kArgumentsCount);
+ Node* context = Parameter(BuiltinDescriptor::kContext);
+
+ CodeStubArguments arguments(this, ChangeInt32ToIntPtr(argc));
+ argc = arguments.GetLength();
+
+ Variable result(this, MachineRepresentation::kFloat64);
+ result.Bind(Float64Constant(default_val));
+
+ CodeStubAssembler::VariableList vars({&result}, zone());
+ arguments.ForEach(vars, [this, float64op, context, &result](Node* arg) {
+ Node* float_value = TruncateTaggedToFloat64(context, arg);
+ result.Bind((this->*float64op)(result.value(), float_value));
+ });
+
+ arguments.PopAndReturn(ChangeFloat64ToTagged(result.value()));
+}
+
// ES6 section 20.2.2.2 Math.acos ( x )
TF_BUILTIN(MathAcos, MathBuiltinsAssembler) {
MathUnaryOperation(&CodeStubAssembler::Float64Acos);
@@ -494,12 +516,14 @@ 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) {
+ MathMaxMin(&CodeStubAssembler::Float64Max, -1.0 * V8_INFINITY);
}
-void Builtins::Generate_MathMin(MacroAssembler* masm) {
- Generate_MathMaxMin(masm, MathMaxMinKind::kMin);
+// ES6 section 20.2.2.25 Math.min ( value1, value2 , ...values )
+TF_BUILTIN(MathMin, MathBuiltinsAssembler) {
+ MathMaxMin(&CodeStubAssembler::Float64Min, V8_INFINITY);
}
} // namespace internal
« no previous file with comments | « src/builtins/builtins.h ('k') | src/builtins/ia32/builtins-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698