Revision: 24187
Author: [email protected]
Date: Wed Sep 24 14:55:13 2014 UTC
Log: Extend JSBuiltinReducer to cover Math.fround as well.
[email protected]
TEST=compiler-unittests/JSBuiltinReducerTest.MathFround
Review URL: https://codereview.chromium.org/594183004
https://code.google.com/p/v8/source/detail?r=24187
Added:
/branches/bleeding_edge/test/mjsunit/asm
/branches/bleeding_edge/test/mjsunit/asm/math-fround.js
Modified:
/branches/bleeding_edge/src/compiler/graph-unittest.cc
/branches/bleeding_edge/src/compiler/graph-unittest.h
/branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc
/branches/bleeding_edge/src/compiler/js-builtin-reducer.cc
/branches/bleeding_edge/src/compiler/js-builtin-reducer.h
/branches/bleeding_edge/src/compiler.cc
=======================================
--- /dev/null
+++ /branches/bleeding_edge/test/mjsunit/asm/math-fround.js Wed Sep 24
14:55:13 2014 UTC
@@ -0,0 +1,40 @@
+// Copyright 2014 the V8 project authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// Flags: --turbo-asm
+
+function Module(stdlib) {
+ "use asm";
+
+ var fround = stdlib.Math.fround;
+
+ // f: double -> float
+ function f(a) {
+ a = +a;
+ return fround(a);
+ }
+
+ return { f: f };
+}
+
+var f = Module({ Math: Math }).f;
+
+assertTrue(isNaN(f(NaN)));
+assertTrue(isNaN(f(undefined)));
+assertTrue(isNaN(f(function() {})));
+
+assertEquals("Infinity", String(1/f(0)));
+assertEquals("-Infinity", String(1/f(-0)));
+assertEquals("Infinity", String(f(Infinity)));
+assertEquals("-Infinity", String(f(-Infinity)));
+assertEquals("Infinity", String(f(1E200)));
+assertEquals("-Infinity", String(f(-1E200)));
+assertEquals("Infinity", String(1/f(1E-300)));
+assertEquals("-Infinity", String(1/f(-1E-300)));
+
+assertEquals(0, f(0));
+assertEquals(1, f(1));
+assertEquals(1.5, f(1.5));
+assertEquals(1.3370000123977661, f(1.337));
+assertEquals(-4.300000190734863, f(-4.3));
=======================================
--- /branches/bleeding_edge/src/compiler/graph-unittest.cc Wed Sep 24
10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/compiler/graph-unittest.cc Wed Sep 24
14:55:13 2014 UTC
@@ -769,6 +769,7 @@
IS_UNOP_MATCHER(ChangeInt32ToInt64)
IS_UNOP_MATCHER(ChangeUint32ToFloat64)
IS_UNOP_MATCHER(ChangeUint32ToUint64)
+IS_UNOP_MATCHER(TruncateFloat64ToFloat32)
IS_UNOP_MATCHER(TruncateFloat64ToInt32)
IS_UNOP_MATCHER(TruncateInt64ToInt32)
IS_UNOP_MATCHER(Float64Sqrt)
=======================================
--- /branches/bleeding_edge/src/compiler/graph-unittest.h Wed Sep 24
10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/compiler/graph-unittest.h Wed Sep 24
14:55:13 2014 UTC
@@ -129,6 +129,7 @@
Matcher<Node*> IsChangeInt32ToInt64(const Matcher<Node*>& input_matcher);
Matcher<Node*> IsChangeUint32ToFloat64(const Matcher<Node*>&
input_matcher);
Matcher<Node*> IsChangeUint32ToUint64(const Matcher<Node*>& input_matcher);
+Matcher<Node*> IsTruncateFloat64ToFloat32(const Matcher<Node*>&
input_matcher);
Matcher<Node*> IsTruncateFloat64ToInt32(const Matcher<Node*>&
input_matcher);
Matcher<Node*> IsTruncateInt64ToInt32(const Matcher<Node*>& input_matcher);
Matcher<Node*> IsFloat64Sqrt(const Matcher<Node*>& input_matcher);
=======================================
--- /branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc Wed
Sep 24 10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/compiler/js-builtin-reducer-unittest.cc Wed
Sep 24 14:55:13 2014 UTC
@@ -171,6 +171,32 @@
}
}
}
+
+
+//
-----------------------------------------------------------------------------
+// Math.fround
+
+
+TEST_F(JSBuiltinReducerTest, MathFround) {
+ Handle<Object> m =
+ JSObject::GetProperty(isolate()->global_object(),
+
isolate()->factory()->NewStringFromAsciiChecked(
+ "Math")).ToHandleChecked();
+ Handle<JSFunction> f = Handle<JSFunction>::cast(
+ JSObject::GetProperty(m,
isolate()->factory()->NewStringFromAsciiChecked(
+ "fround")).ToHandleChecked());
+
+ TRACED_FOREACH(Type*, t0, kNumberTypes) {
+ Node* p0 = Parameter(t0, 0);
+ Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
+ Node* call = graph()->NewNode(javascript()->Call(3,
NO_CALL_FUNCTION_FLAGS),
+ fun, UndefinedConstant(), p0);
+ Reduction r = Reduce(call);
+
+ ASSERT_TRUE(r.Changed());
+ EXPECT_THAT(r.replacement(), IsTruncateFloat64ToFloat32(p0));
+ }
+}
} // namespace compiler
} // namespace internal
=======================================
--- /branches/bleeding_edge/src/compiler/js-builtin-reducer.cc Wed Sep 24
10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/compiler/js-builtin-reducer.cc Wed Sep 24
14:55:13 2014 UTC
@@ -149,6 +149,19 @@
}
return NoChange();
}
+
+
+// ES6 draft 08-24-14, section 20.2.2.17.
+Reduction JSBuiltinReducer::ReduceMathFround(Node* node) {
+ JSCallReduction r(node);
+ if (r.InputsMatchOne(Type::Number())) {
+ // Math.fround(a:number) -> TruncateFloat64ToFloat32(a)
+ Node* value =
+ graph()->NewNode(machine()->TruncateFloat64ToFloat32(), r.left());
+ return Replace(value);
+ }
+ return NoChange();
+}
Reduction JSBuiltinReducer::Reduce(Node* node) {
@@ -163,6 +176,8 @@
return ReplaceWithPureReduction(node, ReduceMathMax(node));
case kMathImul:
return ReplaceWithPureReduction(node, ReduceMathImul(node));
+ case kMathFround:
+ return ReplaceWithPureReduction(node, ReduceMathFround(node));
default:
break;
}
=======================================
--- /branches/bleeding_edge/src/compiler/js-builtin-reducer.h Wed Sep 24
10:24:19 2014 UTC
+++ /branches/bleeding_edge/src/compiler/js-builtin-reducer.h Wed Sep 24
14:55:13 2014 UTC
@@ -33,6 +33,7 @@
Reduction ReduceMathSqrt(Node* node);
Reduction ReduceMathMax(Node* node);
Reduction ReduceMathImul(Node* node);
+ Reduction ReduceMathFround(Node* node);
JSGraph* jsgraph_;
SimplifiedOperatorBuilder simplified_;
=======================================
--- /branches/bleeding_edge/src/compiler.cc Wed Sep 24 07:08:27 2014 UTC
+++ /branches/bleeding_edge/src/compiler.cc Wed Sep 24 14:55:13 2014 UTC
@@ -323,7 +323,6 @@
OptimizedCompileJob::Status OptimizedCompileJob::CreateGraph() {
- DCHECK(isolate()->use_crankshaft());
DCHECK(info()->IsOptimizing());
DCHECK(!info()->IsCompilingForDebugging());
--
--
v8-dev mailing list
[email protected]
http://groups.google.com/group/v8-dev
---
You received this message because you are subscribed to the Google Groups "v8-dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/d/optout.