From df9ac2c165946c17e2d49dfa3dcf987bc2217def Mon Sep 17 00:00:00 2001 From: "sigurds@chromium.org" Date: Fri, 24 Oct 2014 13:06:48 +0000 Subject: [PATCH] Add Float64Floor, Float64Ceil, Float64RoundTruncate, Float64RoundTiesAway operators. These operators are not supported by any backends yet, and a backend is free to not support them. R=bmeurer@chromium.org TEST=unittest/machine-operator Review URL: https://codereview.chromium.org/668173002 Cr-Commit-Position: refs/heads/master@{#24874} git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@24874 ce2b1a6d-e550-0410-aec6-3dcde31c8c00 --- src/base/flags.h | 5 +-- src/compiler/arm/instruction-selector-arm.cc | 6 ++++ .../arm64/instruction-selector-arm64.cc | 6 ++++ .../ia32/instruction-selector-ia32.cc | 6 ++++ src/compiler/instruction-selector.h | 3 ++ src/compiler/machine-operator.cc | 9 ++++-- src/compiler/machine-operator.h | 32 ++++++++++++++++++- .../mips/instruction-selector-mips.cc | 6 ++++ src/compiler/opcodes.h | 4 +++ src/compiler/pipeline.cc | 3 +- src/compiler/simplified-lowering.cc | 4 +++ src/compiler/typer.cc | 24 ++++++++++++++ src/compiler/verifier.cc | 4 +++ src/compiler/x64/instruction-selector-x64.cc | 6 ++++ .../compiler/machine-operator-unittest.cc | 4 ++- 15 files changed, 114 insertions(+), 8 deletions(-) diff --git a/src/base/flags.h b/src/base/flags.h index 3f4dfe77d6..060dba818a 100644 --- a/src/base/flags.h +++ b/src/base/flags.h @@ -26,8 +26,9 @@ class Flags FINAL { typedef S mask_type; Flags() : mask_(0) {} - Flags(flag_type flag) : mask_(flag) {} // NOLINT(runtime/explicit) - explicit Flags(mask_type mask) : mask_(mask) {} + Flags(flag_type flag) // NOLINT(runtime/explicit) + : mask_(static_cast(flag)) {} + explicit Flags(mask_type mask) : mask_(static_cast(mask)) {} Flags& operator&=(const Flags& flags) { mask_ &= flags.mask_; diff --git a/src/compiler/arm/instruction-selector-arm.cc b/src/compiler/arm/instruction-selector-arm.cc index ec0c5b8acb..95e1bde289 100644 --- a/src/compiler/arm/instruction-selector-arm.cc +++ b/src/compiler/arm/instruction-selector-arm.cc @@ -1135,6 +1135,12 @@ void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { VisitFloat64Compare(this, node, &cont); } + +// static +MachineOperatorBuilder::Flags +InstructionSelector::SupportedMachineOperatorFlags() { + return MachineOperatorBuilder::Flag::kNoFlags; +} } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/arm64/instruction-selector-arm64.cc b/src/compiler/arm64/instruction-selector-arm64.cc index 3d27d8d7c2..d23b54d1da 100644 --- a/src/compiler/arm64/instruction-selector-arm64.cc +++ b/src/compiler/arm64/instruction-selector-arm64.cc @@ -1285,6 +1285,12 @@ void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { VisitFloat64Compare(this, node, &cont); } + +// static +MachineOperatorBuilder::Flags +InstructionSelector::SupportedMachineOperatorFlags() { + return MachineOperatorBuilder::Flag::kNoFlags; +} } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/ia32/instruction-selector-ia32.cc b/src/compiler/ia32/instruction-selector-ia32.cc index 894794b47c..ca4bf1ba16 100644 --- a/src/compiler/ia32/instruction-selector-ia32.cc +++ b/src/compiler/ia32/instruction-selector-ia32.cc @@ -877,6 +877,12 @@ void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { VisitFloat64Compare(this, node, &cont); } + +// static +MachineOperatorBuilder::Flags +InstructionSelector::SupportedMachineOperatorFlags() { + return MachineOperatorBuilder::Flag::kNoFlags; +} } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/instruction-selector.h b/src/compiler/instruction-selector.h index cc06f10c5d..e4bd409764 100644 --- a/src/compiler/instruction-selector.h +++ b/src/compiler/instruction-selector.h @@ -85,6 +85,9 @@ class InstructionSelector FINAL { return Features(CpuFeatures::SupportedFeatures()); } + // TODO(sigurds) This should take a CpuFeatures argument. + static MachineOperatorBuilder::Flags SupportedMachineOperatorFlags(); + // =========================================================================== // ============ Architecture-independent graph covering methods. ============= // =========================================================================== diff --git a/src/compiler/machine-operator.cc b/src/compiler/machine-operator.cc index b5da8297e1..6e1180f9f5 100644 --- a/src/compiler/machine-operator.cc +++ b/src/compiler/machine-operator.cc @@ -110,6 +110,10 @@ StoreRepresentation const& StoreRepresentationOf(Operator const* op) { V(Float64Div, Operator::kNoProperties, 2, 1) \ V(Float64Mod, Operator::kNoProperties, 2, 1) \ V(Float64Sqrt, Operator::kNoProperties, 1, 1) \ + V(Float64Ceil, Operator::kNoProperties, 1, 1) \ + V(Float64Floor, Operator::kNoProperties, 1, 1) \ + V(Float64RoundTruncate, Operator::kNoProperties, 1, 1) \ + V(Float64RoundTiesAway, Operator::kNoProperties, 1, 1) \ V(Float64Equal, Operator::kCommutative, 2, 1) \ V(Float64LessThan, Operator::kNoProperties, 2, 1) \ V(Float64LessThanOrEqual, Operator::kNoProperties, 2, 1) \ @@ -188,8 +192,8 @@ static base::LazyInstance::type kImpl = LAZY_INSTANCE_INITIALIZER; -MachineOperatorBuilder::MachineOperatorBuilder(MachineType word) - : impl_(kImpl.Get()), word_(word) { +MachineOperatorBuilder::MachineOperatorBuilder(MachineType word, Flags flags) + : impl_(kImpl.Get()), word_(word), flags_(flags) { DCHECK(word == kRepWord32 || word == kRepWord64); } @@ -236,7 +240,6 @@ const Operator* MachineOperatorBuilder::Store(StoreRepresentation rep) { UNREACHABLE(); return NULL; } - } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/machine-operator.h b/src/compiler/machine-operator.h index 568d3eb2b8..1951446079 100644 --- a/src/compiler/machine-operator.h +++ b/src/compiler/machine-operator.h @@ -5,6 +5,7 @@ #ifndef V8_COMPILER_MACHINE_OPERATOR_H_ #define V8_COMPILER_MACHINE_OPERATOR_H_ +#include "src/base/flags.h" #include "src/compiler/machine-type.h" namespace v8 { @@ -57,7 +58,19 @@ StoreRepresentation const& StoreRepresentationOf(Operator const*); // for generating code to run on architectures such as ia32, x64, arm, etc. class MachineOperatorBuilder FINAL { public: - explicit MachineOperatorBuilder(MachineType word = kMachPtr); + // Flags that specify which operations are available. This is useful + // for operations that are unsupported by some back-ends. + enum class Flag : unsigned { + kNoFlags = 0, + kFloat64Floor = 1 << 0, + kFloat64Ceil = 1 << 1, + kFloat64RoundTruncate = 1 << 2, + kFloat64RoundTiesAway = 1 << 3 + }; + typedef base::Flags Flags; + + explicit MachineOperatorBuilder(MachineType word = kMachPtr, + Flags supportedOperators = Flag::kNoFlags); const Operator* Word32And(); const Operator* Word32Or(); @@ -135,6 +148,20 @@ class MachineOperatorBuilder FINAL { const Operator* Float64LessThan(); const Operator* Float64LessThanOrEqual(); + // Floating point rounding. + const Operator* Float64Floor(); + const Operator* Float64Ceil(); + const Operator* Float64RoundTruncate(); + const Operator* Float64RoundTiesAway(); + bool HasFloat64Floor() { return flags_ & Flag::kFloat64Floor; } + bool HasFloat64Ceil() { return flags_ & Flag::kFloat64Ceil; } + bool HasFloat64RoundTruncate() { + return flags_ & Flag::kFloat64RoundTruncate; + } + bool HasFloat64RoundTiesAway() { + return flags_ & Flag::kFloat64RoundTiesAway; + } + // load [base + index] const Operator* Load(LoadRepresentation rep); @@ -181,8 +208,11 @@ class MachineOperatorBuilder FINAL { private: const MachineOperatorBuilderImpl& impl_; const MachineType word_; + const Flags flags_; }; + +DEFINE_OPERATORS_FOR_FLAGS(MachineOperatorBuilder::Flags) } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/mips/instruction-selector-mips.cc b/src/compiler/mips/instruction-selector-mips.cc index 5ad99307ee..dc1749ad18 100644 --- a/src/compiler/mips/instruction-selector-mips.cc +++ b/src/compiler/mips/instruction-selector-mips.cc @@ -647,6 +647,12 @@ void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { VisitFloat64Compare(this, node, &cont); } + +// static +MachineOperatorBuilder::Flags +InstructionSelector::SupportedMachineOperatorFlags() { + return MachineOperatorBuilder::Flag::kNoFlags; +} } // namespace compiler } // namespace internal } // namespace v8 diff --git a/src/compiler/opcodes.h b/src/compiler/opcodes.h index cbc0d0760c..4853110bb1 100644 --- a/src/compiler/opcodes.h +++ b/src/compiler/opcodes.h @@ -226,6 +226,10 @@ V(Float64Equal) \ V(Float64LessThan) \ V(Float64LessThanOrEqual) \ + V(Float64Floor) \ + V(Float64Ceil) \ + V(Float64RoundTruncate) \ + V(Float64RoundTiesAway) \ V(LoadStackPointer) #define VALUE_OP_LIST(V) \ diff --git a/src/compiler/pipeline.cc b/src/compiler/pipeline.cc index 3b337444b6..a46686b65e 100644 --- a/src/compiler/pipeline.cc +++ b/src/compiler/pipeline.cc @@ -178,7 +178,8 @@ Handle Pipeline::GenerateCode() { // construction. This is currently only needed for the node cache, which the // typer could sweep over later. Typer typer(&graph, info()->context()); - MachineOperatorBuilder machine; + MachineOperatorBuilder machine( + kMachPtr, InstructionSelector::SupportedMachineOperatorFlags()); CommonOperatorBuilder common(zone()); JSOperatorBuilder javascript(zone()); JSGraph jsgraph(&graph, &common, &javascript, &machine); diff --git a/src/compiler/simplified-lowering.cc b/src/compiler/simplified-lowering.cc index 9204e88d9f..1a4ca96b07 100644 --- a/src/compiler/simplified-lowering.cc +++ b/src/compiler/simplified-lowering.cc @@ -915,6 +915,10 @@ class RepresentationSelector { case IrOpcode::kFloat64Mod: return VisitFloat64Binop(node); case IrOpcode::kFloat64Sqrt: + case IrOpcode::kFloat64Floor: + case IrOpcode::kFloat64Ceil: + case IrOpcode::kFloat64RoundTruncate: + case IrOpcode::kFloat64RoundTiesAway: return VisitUnop(node, kMachFloat64, kMachFloat64); case IrOpcode::kFloat64Equal: case IrOpcode::kFloat64LessThan: diff --git a/src/compiler/typer.cc b/src/compiler/typer.cc index 2030b7cc17..b4a62a1ece 100644 --- a/src/compiler/typer.cc +++ b/src/compiler/typer.cc @@ -1770,6 +1770,30 @@ Bounds Typer::Visitor::TypeFloat64LessThanOrEqual(Node* node) { } +Bounds Typer::Visitor::TypeFloat64Floor(Node* node) { + // TODO(sigurds): We could have a tighter bound here. + return Bounds(Type::Number()); +} + + +Bounds Typer::Visitor::TypeFloat64Ceil(Node* node) { + // TODO(sigurds): We could have a tighter bound here. + return Bounds(Type::Number()); +} + + +Bounds Typer::Visitor::TypeFloat64RoundTruncate(Node* node) { + // TODO(sigurds): We could have a tighter bound here. + return Bounds(Type::Number()); +} + + +Bounds Typer::Visitor::TypeFloat64RoundTiesAway(Node* node) { + // TODO(sigurds): We could have a tighter bound here. + return Bounds(Type::Number()); +} + + Bounds Typer::Visitor::TypeLoadStackPointer(Node* node) { return Bounds(Type::Internal()); } diff --git a/src/compiler/verifier.cc b/src/compiler/verifier.cc index d0b40e74fc..0bae1efd35 100644 --- a/src/compiler/verifier.cc +++ b/src/compiler/verifier.cc @@ -702,6 +702,10 @@ GenericGraphVisit::Control Verifier::Visitor::Pre(Node* node) { case IrOpcode::kFloat64Div: case IrOpcode::kFloat64Mod: case IrOpcode::kFloat64Sqrt: + case IrOpcode::kFloat64Floor: + case IrOpcode::kFloat64Ceil: + case IrOpcode::kFloat64RoundTruncate: + case IrOpcode::kFloat64RoundTiesAway: case IrOpcode::kFloat64Equal: case IrOpcode::kFloat64LessThan: case IrOpcode::kFloat64LessThanOrEqual: diff --git a/src/compiler/x64/instruction-selector-x64.cc b/src/compiler/x64/instruction-selector-x64.cc index 03240c2b28..78713a0f96 100644 --- a/src/compiler/x64/instruction-selector-x64.cc +++ b/src/compiler/x64/instruction-selector-x64.cc @@ -1108,6 +1108,12 @@ void InstructionSelector::VisitFloat64LessThanOrEqual(Node* node) { VisitFloat64Compare(this, node, &cont); } + +// static +MachineOperatorBuilder::Flags +InstructionSelector::SupportedMachineOperatorFlags() { + return MachineOperatorBuilder::Flag::kNoFlags; +} } // namespace compiler } // namespace internal } // namespace v8 diff --git a/test/unittests/compiler/machine-operator-unittest.cc b/test/unittests/compiler/machine-operator-unittest.cc index 9d66f9e47b..41ac5c1ca5 100644 --- a/test/unittests/compiler/machine-operator-unittest.cc +++ b/test/unittests/compiler/machine-operator-unittest.cc @@ -202,7 +202,9 @@ const PureOperator kPureOperators[] = { PURE(Float64Div, 2, 1), PURE(Float64Mod, 2, 1), PURE(Float64Sqrt, 1, 1), PURE(Float64Equal, 2, 1), PURE(Float64LessThan, 2, 1), PURE(Float64LessThanOrEqual, 2, 1), - PURE(LoadStackPointer, 0, 1) + PURE(LoadStackPointer, 0, 1), PURE(Float64Floor, 1, 1), + PURE(Float64Ceil, 1, 1), PURE(Float64RoundTruncate, 1, 1), + PURE(Float64RoundTiesAway, 1, 1), #undef PURE };