diff --git a/src/maglev/maglev-graph-builder.cc b/src/maglev/maglev-graph-builder.cc index d63af76eef..e46d9e5897 100644 --- a/src/maglev/maglev-graph-builder.cc +++ b/src/maglev/maglev-graph-builder.cc @@ -372,6 +372,7 @@ constexpr bool BinaryOperationHasFloat64FastPath() { case Operation::kSubtract: case Operation::kMultiply: case Operation::kDivide: + case Operation::kExponentiate: case Operation::kEqual: case Operation::kStrictEqual: case Operation::kLessThan: @@ -428,7 +429,8 @@ constexpr bool BinaryOperationHasFloat64FastPath() { V(Subtract, Float64Subtract) \ V(Multiply, Float64Multiply) \ V(Divide, Float64Divide) \ - V(Negate, Float64Negate) + V(Negate, Float64Negate) \ + V(Exponentiate, Float64Exponentiate) #define MAP_COMPARE_OPERATION_TO_FLOAT64_NODE(V) \ V(Equal, Float64Equal) \ @@ -3112,6 +3114,16 @@ ValueNode* MaglevGraphBuilder::TryReduceFunctionPrototypeCall( return BuildGenericCall(receiver, context, Call::TargetType::kAny, args); } +ValueNode* MaglevGraphBuilder::TryReduceMathPow(compiler::JSFunctionRef target, + CallArguments& args) { + if (args.count() < 2) { + return GetRootConstant(RootIndex::kNanValue); + } + ValueNode* left = GetFloat64(args[0]); + ValueNode* right = GetFloat64(args[1]); + return AddNewNode({left, right}); +} + ValueNode* MaglevGraphBuilder::TryReduceBuiltin( compiler::JSFunctionRef target, CallArguments& args, const compiler::FeedbackSource& feedback_source, diff --git a/src/maglev/maglev-graph-builder.h b/src/maglev/maglev-graph-builder.h index 68e415c1cf..570d2e03a6 100644 --- a/src/maglev/maglev-graph-builder.h +++ b/src/maglev/maglev-graph-builder.h @@ -1142,6 +1142,7 @@ class MaglevGraphBuilder { V(DataViewPrototypeGetFloat64) \ V(DataViewPrototypeSetFloat64) \ V(FunctionPrototypeCall) \ + V(MathPow) \ V(StringFromCharCode) \ V(StringPrototypeCharCodeAt) diff --git a/src/maglev/maglev-graph-verifier.h b/src/maglev/maglev-graph-verifier.h index 11b5730607..1ac9f130f8 100644 --- a/src/maglev/maglev-graph-verifier.h +++ b/src/maglev/maglev-graph-verifier.h @@ -311,6 +311,7 @@ class MaglevGraphVerifier { case Opcode::kFloat64Subtract: case Opcode::kFloat64Multiply: case Opcode::kFloat64Divide: + case Opcode::kFloat64Exponentiate: case Opcode::kFloat64Equal: case Opcode::kFloat64StrictEqual: case Opcode::kFloat64LessThan: diff --git a/src/maglev/maglev-ir.cc b/src/maglev/maglev-ir.cc index c07a0df894..e71464a347 100644 --- a/src/maglev/maglev-ir.cc +++ b/src/maglev/maglev-ir.cc @@ -98,7 +98,7 @@ void UseFixed(Input& input, Register reg) { input.SetUnallocated(compiler::UnallocatedOperand::FIXED_REGISTER, reg.code(), GetVirtualRegister(input.node())); } -[[maybe_unused]] void UseFixed(Input& input, DoubleRegister reg) { +void UseFixed(Input& input, DoubleRegister reg) { input.SetUnallocated(compiler::UnallocatedOperand::FIXED_FP_REGISTER, reg.code(), GetVirtualRegister(input.node())); } @@ -3240,6 +3240,19 @@ void Float64Negate::GenerateCode(MaglevAssembler* masm, __ Negpd(value, value, kScratchRegister); } +void Float64Exponentiate::AllocateVreg(MaglevVregAllocationState* vreg_state) { + UseFixed(left_input(), xmm0); + UseFixed(right_input(), xmm1); + DefineSameAsFirst(vreg_state, this); +} + +void Float64Exponentiate::GenerateCode(MaglevAssembler* masm, + const ProcessingState& state) { + AllowExternalCallThatCantCauseGC scope(masm); + __ PrepareCallCFunction(2); + __ CallCFunction(ExternalReference::ieee754_pow_function(), 2); +} + template void Float64CompareNode::AllocateVreg( MaglevVregAllocationState* vreg_state) { diff --git a/src/maglev/maglev-ir.h b/src/maglev/maglev-ir.h index bdd3917e6f..4a42f0ca7e 100644 --- a/src/maglev/maglev-ir.h +++ b/src/maglev/maglev-ir.h @@ -72,28 +72,27 @@ class CompactInterpreterFrameState; V(GenericGreaterThan) \ V(GenericGreaterThanOrEqual) -#define INT32_OPERATIONS_NODE_LIST(V) \ - V(Int32AddWithOverflow) \ - V(Int32SubtractWithOverflow) \ - V(Int32MultiplyWithOverflow) \ - V(Int32DivideWithOverflow) \ - V(Int32ModulusWithOverflow) \ - /*V(Int32ExponentiateWithOverflow)*/ \ - V(Int32BitwiseAnd) \ - V(Int32BitwiseOr) \ - V(Int32BitwiseXor) \ - V(Int32ShiftLeft) \ - V(Int32ShiftRight) \ - V(Int32ShiftRightLogical) \ - V(Int32BitwiseNot) \ - V(Int32NegateWithOverflow) \ - V(Int32IncrementWithOverflow) \ - V(Int32DecrementWithOverflow) \ - V(Int32Equal) \ - V(Int32StrictEqual) \ - V(Int32LessThan) \ - V(Int32LessThanOrEqual) \ - V(Int32GreaterThan) \ +#define INT32_OPERATIONS_NODE_LIST(V) \ + V(Int32AddWithOverflow) \ + V(Int32SubtractWithOverflow) \ + V(Int32MultiplyWithOverflow) \ + V(Int32DivideWithOverflow) \ + V(Int32ModulusWithOverflow) \ + V(Int32BitwiseAnd) \ + V(Int32BitwiseOr) \ + V(Int32BitwiseXor) \ + V(Int32ShiftLeft) \ + V(Int32ShiftRight) \ + V(Int32ShiftRightLogical) \ + V(Int32BitwiseNot) \ + V(Int32NegateWithOverflow) \ + V(Int32IncrementWithOverflow) \ + V(Int32DecrementWithOverflow) \ + V(Int32Equal) \ + V(Int32StrictEqual) \ + V(Int32LessThan) \ + V(Int32LessThanOrEqual) \ + V(Int32GreaterThan) \ V(Int32GreaterThanOrEqual) #define FLOAT64_OPERATIONS_NODE_LIST(V) \ @@ -102,8 +101,8 @@ class CompactInterpreterFrameState; V(Float64Multiply) \ V(Float64Divide) \ /*V(Float64Modulus)*/ \ - /*V(Float64Exponentiate)*/ \ V(Float64Negate) \ + V(Float64Exponentiate) \ V(Float64Equal) \ V(Float64StrictEqual) \ V(Float64LessThan) \ @@ -1701,7 +1700,6 @@ DEF_INT32_BINARY_WITH_OVERFLOW_NODE(Subtract) DEF_INT32_BINARY_WITH_OVERFLOW_NODE(Multiply) DEF_INT32_BINARY_WITH_OVERFLOW_NODE(Divide) DEF_INT32_BINARY_WITH_OVERFLOW_NODE(Modulus) -// DEF_INT32_BINARY_WITH_OVERFLOW_NODE(Exponentiate) #undef DEF_INT32_BINARY_WITH_OVERFLOW_NODE template @@ -1841,9 +1839,27 @@ DEF_FLOAT64_BINARY_NODE(Subtract) DEF_FLOAT64_BINARY_NODE(Multiply) DEF_FLOAT64_BINARY_NODE(Divide) // DEF_FLOAT64_BINARY_NODE(Modulus) -// DEF_FLOAT64_BINARY_NODE(Exponentiate) #undef DEF_FLOAT64_BINARY_NODE +class Float64Exponentiate + : public FixedInputValueNodeT<2, Float64Exponentiate> { + using Base = FixedInputValueNodeT<2, Float64Exponentiate>; + + public: + explicit Float64Exponentiate(uint64_t bitfield) : Base(bitfield) {} + static constexpr OpProperties kProperties = + OpProperties::Float64() | OpProperties::Call(); + + static constexpr int kLeftIndex = 0; + static constexpr int kRightIndex = 1; + Input& left_input() { return Node::input(kLeftIndex); } + Input& right_input() { return Node::input(kRightIndex); } + + void AllocateVreg(MaglevVregAllocationState*); + void GenerateCode(MaglevAssembler*, const ProcessingState&); + void PrintParams(std::ostream&, MaglevGraphLabeller*) const {} +}; + template class Float64CompareNode : public FixedInputValueNodeT<2, Derived> { using Base = FixedInputValueNodeT<2, Derived>;