[maglev] Add Float64Exp + inline Math.pow

Bug: v8:7700
Change-Id: I681503d062e88609131979a6eea0fdee08b93ef1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/4055941
Reviewed-by: Leszek Swirski <leszeks@chromium.org>
Commit-Queue: Victor Gomes <victorgomes@chromium.org>
Cr-Commit-Position: refs/heads/main@{#84482}
This commit is contained in:
Victor Gomes 2022-11-25 11:22:01 +01:00 committed by V8 LUCI CQ
parent 0fec70aeb1
commit 029e8a2f19
5 changed files with 70 additions and 27 deletions

View File

@ -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<Float64Exponentiate>({left, right});
}
ValueNode* MaglevGraphBuilder::TryReduceBuiltin(
compiler::JSFunctionRef target, CallArguments& args,
const compiler::FeedbackSource& feedback_source,

View File

@ -1142,6 +1142,7 @@ class MaglevGraphBuilder {
V(DataViewPrototypeGetFloat64) \
V(DataViewPrototypeSetFloat64) \
V(FunctionPrototypeCall) \
V(MathPow) \
V(StringFromCharCode) \
V(StringPrototypeCharCodeAt)

View File

@ -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:

View File

@ -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 <class Derived, Operation kOperation>
void Float64CompareNode<Derived, kOperation>::AllocateVreg(
MaglevVregAllocationState* vreg_state) {

View File

@ -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 <class Derived, Operation kOperation>
@ -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 Derived, Operation kOperation>
class Float64CompareNode : public FixedInputValueNodeT<2, Derived> {
using Base = FixedInputValueNodeT<2, Derived>;