Commit 5ff309de authored by Lu Yahan's avatar Lu Yahan Committed by V8 LUCI CQ

[riscv64] Argument Count Consistency

Port 255aaed9
Port 6bd44dfe

Change-Id: I9d57cf7782c267bda4532d0408e69b671e6001f1
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3220271Reviewed-by: 's avatarji qiu <qiuji@iscas.ac.cn>
Reviewed-by: 's avatarJakob Gruber <jgruber@chromium.org>
Commit-Queue: ji qiu <qiuji@iscas.ac.cn>
Commit-Queue: Yahan Lu <yahan@iscas.ac.cn>
Auto-Submit: Yahan Lu <yahan@iscas.ac.cn>
Cr-Commit-Position: refs/heads/main@{#77407}
parent 40d6e7de
...@@ -357,7 +357,7 @@ declare_args() { ...@@ -357,7 +357,7 @@ declare_args() {
v8_current_cpu == "x86" || v8_current_cpu == "x64" || v8_current_cpu == "x86" || v8_current_cpu == "x64" ||
v8_current_cpu == "arm" || v8_current_cpu == "arm64" || v8_current_cpu == "arm" || v8_current_cpu == "arm64" ||
v8_current_cpu == "mips64el" || v8_current_cpu == "mipsel" || v8_current_cpu == "mips64el" || v8_current_cpu == "mipsel" ||
v8_current_cpu == "loong64" v8_current_cpu == "loong64" || v8_current_cpu == "riscv64"
} }
# Derived defaults. # Derived defaults.
......
...@@ -503,9 +503,10 @@ void BaselineAssembler::EmitReturn(MacroAssembler* masm) { ...@@ -503,9 +503,10 @@ void BaselineAssembler::EmitReturn(MacroAssembler* masm) {
__ masm()->LeaveFrame(StackFrame::BASELINE); __ masm()->LeaveFrame(StackFrame::BASELINE);
// Drop receiver + arguments. // Drop receiver + arguments.
__ masm()->Add64(params_size, params_size, 1); // Include the receiver. __ masm()->DropArguments(params_size, MacroAssembler::kCountIsInteger,
__ masm()->slli(params_size, params_size, kSystemPointerSizeLog2); kJSArgcIncludesReceiver
__ masm()->Add64(sp, sp, params_size); ? MacroAssembler::kCountIncludesReceiver
: MacroAssembler::kCountExcludesReceiver);
__ masm()->Ret(); __ masm()->Ret();
} }
......
This diff is collapsed.
...@@ -3751,7 +3751,11 @@ void MacroAssembler::InvokePrologue(Register expected_parameter_count, ...@@ -3751,7 +3751,11 @@ void MacroAssembler::InvokePrologue(Register expected_parameter_count,
Sub64(t0, t0, Operand(1)); Sub64(t0, t0, Operand(1));
Add64(src, src, Operand(kSystemPointerSize)); Add64(src, src, Operand(kSystemPointerSize));
Add64(dest, dest, Operand(kSystemPointerSize)); Add64(dest, dest, Operand(kSystemPointerSize));
Branch(&copy, ge, t0, Operand(zero_reg)); if (kJSArgcIncludesReceiver) {
Branch(&copy, gt, t0, Operand(zero_reg));
} else {
Branch(&copy, ge, t0, Operand(zero_reg));
}
} }
// Fill remaining expected arguments with undefined values. // Fill remaining expected arguments with undefined values.
...@@ -5031,6 +5035,46 @@ void TurboAssembler::DecompressAnyTagged(const Register& destination, ...@@ -5031,6 +5035,46 @@ void TurboAssembler::DecompressAnyTagged(const Register& destination,
RecordComment("]"); RecordComment("]");
} }
void MacroAssembler::DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode, Register scratch) {
switch (type) {
case kCountIsInteger: {
CalcScaledAddress(sp, sp, count, kPointerSizeLog2);
break;
}
case kCountIsSmi: {
STATIC_ASSERT(kSmiTagSize == 1 && kSmiTag == 0);
DCHECK_NE(scratch, no_reg);
SmiScale(scratch, count, kPointerSizeLog2);
Add64(sp, sp, scratch);
break;
}
case kCountIsBytes: {
Add64(sp, sp, count);
break;
}
}
if (mode == kCountExcludesReceiver) {
Add64(sp, sp, kSystemPointerSize);
}
}
void MacroAssembler::DropArgumentsAndPushNewReceiver(Register argc,
Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode,
Register scratch) {
DCHECK(!AreAliased(argc, receiver));
if (mode == kCountExcludesReceiver) {
// Drop arguments without receiver and override old receiver.
DropArguments(argc, type, kCountIncludesReceiver, scratch);
Sd(receiver, MemOperand(sp));
} else {
DropArguments(argc, type, mode, scratch);
push(receiver);
}
}
} // namespace internal } // namespace internal
} // namespace v8 } // namespace v8
......
...@@ -1252,6 +1252,15 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler { ...@@ -1252,6 +1252,15 @@ class V8_EXPORT_PRIVATE MacroAssembler : public TurboAssembler {
And(scratch, value, Operand(kSmiTagMask)); And(scratch, value, Operand(kSmiTagMask));
} }
enum ArgumentsCountMode { kCountIncludesReceiver, kCountExcludesReceiver };
enum ArgumentsCountType { kCountIsInteger, kCountIsSmi, kCountIsBytes };
void DropArguments(Register count, ArgumentsCountType type,
ArgumentsCountMode mode, Register scratch = no_reg);
void DropArgumentsAndPushNewReceiver(Register argc, Register receiver,
ArgumentsCountType type,
ArgumentsCountMode mode,
Register scratch = no_reg);
// Jump if the register contains a non-smi. // Jump if the register contains a non-smi.
void JumpIfNotSmi(Register value, Label* not_smi_label); void JumpIfNotSmi(Register value, Label* not_smi_label);
......
...@@ -3212,7 +3212,9 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) { ...@@ -3212,7 +3212,9 @@ void CodeGenerator::AssembleReturn(InstructionOperand* additional_pop_count) {
if (drop_jsargs) { if (drop_jsargs) {
// We must pop all arguments from the stack (including the receiver). This // We must pop all arguments from the stack (including the receiver). This
// number of arguments is given by max(1 + argc_reg, parameter_slots). // number of arguments is given by max(1 + argc_reg, parameter_slots).
__ Add64(t0, t0, Operand(1)); // Also pop the receiver. if (!kJSArgcIncludesReceiver) {
__ Add64(t0, t0, Operand(1)); // Also pop the receiver.
}
if (parameter_slots > 1) { if (parameter_slots > 1) {
Label done; Label done;
__ li(kScratchReg, parameter_slots); __ li(kScratchReg, parameter_slots);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment