}
-// ES6 draft 10-14-14, section 20.2.2.16.
-Reduction JSBuiltinReducer::ReduceMathFloor(Node* node) {
- if (!machine()->HasFloat64RoundDown()) return NoChange();
- JSCallReduction r(node);
- if (r.InputsMatchOne(Type::Number())) {
- // Math.floor(a:number) -> Float64RoundDown(a)
- Node* value = graph()->NewNode(machine()->Float64RoundDown(), r.left());
- return Replace(value);
- }
- return NoChange();
-}
-
-
Reduction JSBuiltinReducer::Reduce(Node* node) {
JSCallReduction r(node);
return ReplaceWithPureReduction(node, ReduceMathImul(node));
case kMathFround:
return ReplaceWithPureReduction(node, ReduceMathFround(node));
- case kMathFloor:
- return ReplaceWithPureReduction(node, ReduceMathFloor(node));
default:
break;
}
}
}
-
-// -----------------------------------------------------------------------------
-// Math.floor
-
-
-TEST_F(JSBuiltinReducerTest, MathFloorAvailable) {
- Handle<JSFunction> f = MathFunction("floor");
-
- TRACED_FOREACH(Type*, t0, kNumberTypes) {
- Node* p0 = Parameter(t0, 0);
- Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
- Node* call =
- graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
- fun, UndefinedConstant(), p0);
- Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kFloat64RoundDown);
-
- ASSERT_TRUE(r.Changed());
- EXPECT_THAT(r.replacement(), IsFloat64RoundDown(p0));
- }
-}
-
-
-TEST_F(JSBuiltinReducerTest, MathFloorUnavailable) {
- Handle<JSFunction> f = MathFunction("floor");
-
- TRACED_FOREACH(Type*, t0, kNumberTypes) {
- Node* p0 = Parameter(t0, 0);
- Node* fun = HeapConstant(Unique<HeapObject>::CreateUninitialized(f));
- Node* call =
- graph()->NewNode(javascript()->CallFunction(3, NO_CALL_FUNCTION_FLAGS),
- fun, UndefinedConstant(), p0);
- Reduction r = Reduce(call, MachineOperatorBuilder::Flag::kNoFlags);
-
- ASSERT_FALSE(r.Changed());
- }
-}
-
} // namespace compiler
} // namespace internal
} // namespace v8