Skip to content

Commit

Permalink
[riscv64][sparkplug] Fix sparkplug verify framesize failed
Browse files Browse the repository at this point in the history
Change-Id: I7481749ba3d5c41d7405b0d88a51defbc8bec9d6
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3093009
Auto-Submit: Yahan Lu <yahan@iscas.ac.cn>
Reviewed-by: Ji Qiu <qiuji@iscas.ac.cn>
Commit-Queue: Yahan Lu <yahan@iscas.ac.cn>
Cr-Commit-Position: refs/heads/master@{#76277}
  • Loading branch information
luyahan authored and V8 LUCI CQ committed Aug 13, 2021
1 parent 52720f6 commit d8dc66f
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 275 deletions.
260 changes: 71 additions & 189 deletions src/baseline/riscv64/baseline-assembler-riscv64-inl.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,38 +109,27 @@ void BaselineAssembler::JumpIfNotSmi(Register value, Label* target,
}

void BaselineAssembler::CallBuiltin(Builtin builtin) {
if (masm()->options().short_builtin_calls) {
__ CallBuiltin(builtin);
} else {
ASM_CODE_COMMENT_STRING(masm_,
__ CommentForOffHeapTrampoline("call", builtin));
Register temp = t6;
__ LoadEntryFromBuiltin(builtin, temp);
__ Call(temp);
}
ASM_CODE_COMMENT_STRING(masm_,
__ CommentForOffHeapTrampoline("call", builtin));
Register temp = t6;
__ LoadEntryFromBuiltin(builtin, temp);
__ Call(temp);
}

void BaselineAssembler::TailCallBuiltin(Builtin builtin) {
if (masm()->options().short_builtin_calls) {
// Generate pc-relative jump.
__ TailCallBuiltin(builtin);
} else {
ASM_CODE_COMMENT_STRING(
masm_, __ CommentForOffHeapTrampoline("tail call", builtin));
// t6 be used for function call in RISCV64
// For example 'jalr t6' or 'jal t6'
Register temp = t6;
__ LoadEntryFromBuiltin(builtin, temp);
__ Jump(temp);
}
ASM_CODE_COMMENT_STRING(masm_,
__ CommentForOffHeapTrampoline("tail call", builtin));
Register temp = t6;
__ LoadEntryFromBuiltin(builtin, temp);
__ Jump(temp);
}

void BaselineAssembler::TestAndBranch(Register value, int mask, Condition cc,
Label* target, Label::Distance) {
ScratchRegisterScope temps(this);
Register tmp = temps.AcquireScratch();
__ And(tmp, value, Operand(mask));
__ Branch(target, AsMasmCondition(cc), tmp, Operand(mask));
__ Branch(target, AsMasmCondition(cc), tmp, Operand(zero_reg));
}

void BaselineAssembler::JumpIf(Condition cc, Register lhs, const Operand& rhs,
Expand All @@ -161,6 +150,11 @@ void BaselineAssembler::JumpIfInstanceType(Condition cc, Register map,
Label* target, Label::Distance) {
ScratchRegisterScope temps(this);
Register type = temps.AcquireScratch();
if (FLAG_debug_code) {
__ AssertNotSmi(map);
__ GetObjectType(map, type, type);
__ Assert(eq, AbortReason::kUnexpectedValue, type, Operand(MAP_TYPE));
}
__ Ld(type, FieldMemOperand(map, Map::kInstanceTypeOffset));
__ Branch(target, AsMasmCondition(cc), type, Operand(instance_type));
}
Expand All @@ -182,44 +176,28 @@ void BaselineAssembler::JumpIfSmi(Condition cc, Register value, Smi smi,
}
void BaselineAssembler::JumpIfSmi(Condition cc, Register lhs, Register rhs,
Label* target, Label::Distance) {
ScratchRegisterScope temps(this);
Register temp = temps.AcquireScratch();
// todo: compress pointer
__ AssertSmi(lhs);
__ AssertSmi(rhs);
if (COMPRESS_POINTERS_BOOL) {
__ Sub32(temp, lhs, rhs);
} else {
__ Sub64(temp, lhs, rhs);
}
__ Branch(target, AsMasmCondition(cc), temp, Operand(zero_reg));
__ Branch(target, AsMasmCondition(cc), lhs, Operand(rhs));
}
void BaselineAssembler::JumpIfTagged(Condition cc, Register value,
MemOperand operand, Label* target,
Label::Distance) {
// todo: compress pointer
ScratchRegisterScope temps(this);
Register tmp1 = temps.AcquireScratch();
Register tmp2 = temps.AcquireScratch();
__ Ld(tmp1, operand);
if (COMPRESS_POINTERS_BOOL) {
__ Sub32(tmp2, value, tmp1);
} else {
__ Sub64(tmp2, value, tmp1);
}
__ Branch(target, AsMasmCondition(cc), tmp2, Operand(zero_reg));
Register scratch = temps.AcquireScratch();
__ Ld(scratch, operand);
__ Branch(target, AsMasmCondition(cc), value, Operand(scratch));
}
void BaselineAssembler::JumpIfTagged(Condition cc, MemOperand operand,
Register value, Label* target,
Label::Distance) {
// todo: compress pointer
ScratchRegisterScope temps(this);
Register tmp1 = temps.AcquireScratch();
Register tmp2 = temps.AcquireScratch();
__ Ld(tmp1, operand);
if (COMPRESS_POINTERS_BOOL) {
__ Sub32(tmp2, tmp1, value);
} else {
__ Sub64(tmp2, tmp1, value);
}
__ Branch(target, AsMasmCondition(cc), tmp2, Operand(zero_reg));
Register scratch = temps.AcquireScratch();
__ Ld(scratch, operand);
__ Branch(target, AsMasmCondition(cc), scratch, Operand(value));
}
void BaselineAssembler::JumpIfByte(Condition cc, Register value, int32_t byte,
Label* target, Label::Distance) {
Expand Down Expand Up @@ -267,137 +245,51 @@ inline Register ToRegister(BaselineAssembler* basm,
return reg;
}

template <typename... Args>
struct CountPushHelper;
template <>
struct CountPushHelper<> {
static int Count() { return 0; }
};
template <typename Arg, typename... Args>
struct CountPushHelper<Arg, Args...> {
static int Count(Arg arg, Args... args) {
return 1 + CountPushHelper<Args...>::Count(args...);
}
};
template <typename... Args>
struct CountPushHelper<interpreter::RegisterList, Args...> {
static int Count(interpreter::RegisterList list, Args... args) {
return list.register_count() + CountPushHelper<Args...>::Count(args...);
}
};

template <typename... Args>
struct PushAllHelper;
template <typename... Args>
void PushAll(BaselineAssembler* basm, Args... args) {
PushAllHelper<Args...>::Push(basm, args...);
}
template <typename... Args>
void PushAllReverse(BaselineAssembler* basm, Args... args) {
PushAllHelper<Args...>::PushReverse(basm, args...);
}

template <>
struct PushAllHelper<> {
static void Push(BaselineAssembler* basm) {}
static void PushReverse(BaselineAssembler* basm) {}
static int Push(BaselineAssembler* basm) { return 0; }
static int PushReverse(BaselineAssembler* basm) { return 0; }
};

inline void PushSingle(MacroAssembler* masm, RootIndex source) {
masm->PushRoot(source);
}
inline void PushSingle(MacroAssembler* masm, Register reg) { masm->Push(reg); }

inline void PushSingle(MacroAssembler* masm, Smi value) { masm->Push(value); }
inline void PushSingle(MacroAssembler* masm, Handle<HeapObject> object) {
masm->Push(object);
}
inline void PushSingle(MacroAssembler* masm, int32_t immediate) {
masm->li(kScratchReg, (int64_t)(immediate));
PushSingle(masm, kScratchReg);
}

inline void PushSingle(MacroAssembler* masm, TaggedIndex value) {
masm->li(kScratchReg, static_cast<int64_t>(value.ptr()));
PushSingle(masm, kScratchReg);
}
inline void PushSingle(MacroAssembler* masm, MemOperand operand) {
masm->Ld(kScratchReg, operand);
PushSingle(masm, kScratchReg);
}
inline void PushSingle(MacroAssembler* masm, interpreter::Register source) {
return PushSingle(masm, BaselineAssembler::RegisterFrameOperand(source));
}

template <typename Arg>
struct PushAllHelper<Arg> {
static void Push(BaselineAssembler* basm, Arg arg) {
PushSingle(basm->masm(), arg);
static int Push(BaselineAssembler* basm, Arg arg) {
BaselineAssembler::ScratchRegisterScope scope(basm);
basm->masm()->Push(ToRegister(basm, &scope, arg));
return 1;
}
static void PushReverse(BaselineAssembler* basm, Arg arg) {
// Push the padding register to round up the amount of values pushed.
static int PushReverse(BaselineAssembler* basm, Arg arg) {
return Push(basm, arg);
}
};
template <typename Arg1, typename Arg2, typename... Args>
struct PushAllHelper<Arg1, Arg2, Args...> {
static void Push(BaselineAssembler* basm, Arg1 arg1, Arg2 arg2,
Args... args) {
{
BaselineAssembler::ScratchRegisterScope scope(basm);
basm->masm()->Push(ToRegister(basm, &scope, arg1),
ToRegister(basm, &scope, arg2));
}
PushAll(basm, args...);
}
static void PushReverse(BaselineAssembler* basm, Arg1 arg1, Arg2 arg2,
Args... args) {
PushAllReverse(basm, args...);
{
BaselineAssembler::ScratchRegisterScope scope(basm);
basm->masm()->Push(ToRegister(basm, &scope, arg2),
ToRegister(basm, &scope, arg1));
}
}
};
// Currently RegisterLists are always be the last argument, so we don't
// specialize for the case where they're not. We do still specialise for the
// aligned and unaligned cases.
template <typename Arg>
struct PushAllHelper<Arg, interpreter::RegisterList> {
static void Push(BaselineAssembler* basm, Arg arg,
interpreter::RegisterList list) {
DCHECK_EQ(list.register_count() % 2, 1);
PushAll(basm, arg, list[0], list.PopLeft());
template <typename Arg, typename... Args>
struct PushAllHelper<Arg, Args...> {
static int Push(BaselineAssembler* basm, Arg arg, Args... args) {
PushAllHelper<Arg>::Push(basm, arg);
return 1 + PushAllHelper<Args...>::Push(basm, args...);
}
static void PushReverse(BaselineAssembler* basm, Arg arg,
interpreter::RegisterList list) {
if (list.register_count() == 0) {
PushAllReverse(basm, arg);
} else {
PushAllReverse(basm, arg, list[0], list.PopLeft());
}
static int PushReverse(BaselineAssembler* basm, Arg arg, Args... args) {
int nargs = PushAllHelper<Args...>::PushReverse(basm, args...);
PushAllHelper<Arg>::Push(basm, arg);
return nargs + 1;
}
};
template <>
struct PushAllHelper<interpreter::RegisterList> {
static void Push(BaselineAssembler* basm, interpreter::RegisterList list) {
DCHECK_EQ(list.register_count() % 2, 0);
for (int reg_index = 0; reg_index < list.register_count(); reg_index += 2) {
PushAll(basm, list[reg_index], list[reg_index + 1]);
static int Push(BaselineAssembler* basm, interpreter::RegisterList list) {
for (int reg_index = 0; reg_index < list.register_count(); ++reg_index) {
PushAllHelper<interpreter::Register>::Push(basm, list[reg_index]);
}
return list.register_count();
}
static void PushReverse(BaselineAssembler* basm,
interpreter::RegisterList list) {
int reg_index = list.register_count() - 1;
if (reg_index % 2 == 0) {
// Push the padding register to round up the amount of values pushed.
PushAllReverse(basm, list[reg_index]);
reg_index--;
}
for (; reg_index >= 1; reg_index -= 2) {
PushAllReverse(basm, list[reg_index - 1], list[reg_index]);
static int PushReverse(BaselineAssembler* basm,
interpreter::RegisterList list) {
for (int reg_index = list.register_count() - 1; reg_index >= 0;
--reg_index) {
PushAllHelper<interpreter::Register>::Push(basm, list[reg_index]);
}
return list.register_count();
}
};

Expand All @@ -414,10 +306,9 @@ struct PopAllHelper<Register> {
}
};
template <typename... T>
struct PopAllHelper<Register, Register, T...> {
static void Pop(BaselineAssembler* basm, Register reg1, Register reg2,
T... tail) {
basm->masm()->Pop(reg1, reg2);
struct PopAllHelper<Register, T...> {
static void Pop(BaselineAssembler* basm, Register reg, T... tail) {
PopAllHelper<Register>::Pop(basm, reg);
PopAllHelper<T...>::Pop(basm, tail...);
}
};
Expand All @@ -426,20 +317,12 @@ struct PopAllHelper<Register, Register, T...> {

template <typename... T>
int BaselineAssembler::Push(T... vals) {
// We have to count the pushes first, to decide whether to add padding before
// the first push.
int push_count = detail::CountPushHelper<T...>::Count(vals...);
if (push_count % 2 == 0) {
detail::PushAll(this, vals...);
} else {
detail::PushAll(this, vals...);
}
return push_count;
return detail::PushAllHelper<T...>::Push(this, vals...);
}

template <typename... T>
void BaselineAssembler::PushReverse(T... vals) {
detail::PushAllReverse(this, vals...);
detail::PushAllHelper<T...>::PushReverse(this, vals...);
}

template <typename... T>
Expand All @@ -461,7 +344,7 @@ void BaselineAssembler::LoadTaggedAnyField(Register output, Register source,
}
void BaselineAssembler::LoadByteField(Register output, Register source,
int offset) {
__ Ld(output, FieldMemOperand(source, offset));
__ Lb(output, FieldMemOperand(source, offset));
}
void BaselineAssembler::StoreTaggedSignedField(Register target, int offset,
Smi value) {
Expand Down Expand Up @@ -495,11 +378,11 @@ void BaselineAssembler::AddToInterruptBudgetAndJumpIfNotExceeded(
JSFunction::kFeedbackCellOffset);

Register interrupt_budget = scratch_scope.AcquireScratch();
__ Ld(interrupt_budget,
__ Lw(interrupt_budget,
FieldMemOperand(feedback_cell, FeedbackCell::kInterruptBudgetOffset));
// Remember to set flags as part of the add!
__ Add64(interrupt_budget, interrupt_budget, weight);
__ Sd(interrupt_budget,
__ Add32(interrupt_budget, interrupt_budget, weight);
__ Sw(interrupt_budget,
FieldMemOperand(feedback_cell, FeedbackCell::kInterruptBudgetOffset));
if (skip_interrupt_label) {
DCHECK_LT(weight, 0);
Expand All @@ -517,11 +400,11 @@ void BaselineAssembler::AddToInterruptBudgetAndJumpIfNotExceeded(
JSFunction::kFeedbackCellOffset);

Register interrupt_budget = scratch_scope.AcquireScratch();
__ Ld(interrupt_budget,
__ Lw(interrupt_budget,
FieldMemOperand(feedback_cell, FeedbackCell::kInterruptBudgetOffset));
// Remember to set flags as part of the add!
__ Add64(interrupt_budget, interrupt_budget, weight);
__ Sd(interrupt_budget,
__ Add32(interrupt_budget, interrupt_budget, weight);
__ Sw(interrupt_budget,
FieldMemOperand(feedback_cell, FeedbackCell::kInterruptBudgetOffset));
if (skip_interrupt_label)
__ Branch(skip_interrupt_label, ge, interrupt_budget, Operand(weight));
Expand Down Expand Up @@ -556,20 +439,19 @@ void BaselineAssembler::Switch(Register reg, int case_value_base,
int32_t Hi20 = (((int32_t)imm64 + 0x800) >> 12);
int32_t Lo12 = (int32_t)imm64 << 20 >> 20;
__ auipc(temp, Hi20); // Read PC + Hi20 into t6
__ lui(temp, Lo12); // jump PC + Hi20 + Lo12
__ addi(temp, temp, Lo12); // jump PC + Hi20 + Lo12

int entry_size_log2 = 2;
Register temp2 = scope.AcquireScratch();
__ CalcScaledAddress(temp2, temp, reg, entry_size_log2);
int entry_size_log2 = 3;
__ CalcScaledAddress(temp, temp, reg, entry_size_log2);
__ Jump(temp);
{
TurboAssembler::BlockTrampolinePoolScope(masm());
__ BlockTrampolinePoolFor(num_labels * kInstrSize);
__ BlockTrampolinePoolFor(num_labels * kInstrSize * 2);
__ bind(&table);
for (int i = 0; i < num_labels; ++i) {
__ Branch(labels[i]);
__ BranchLong(labels[i]);
}
DCHECK_EQ(num_labels * kInstrSize, __ InstructionsGeneratedSince(&table));
DCHECK_EQ(num_labels * 2, __ InstructionsGeneratedSince(&table));
__ bind(&fallthrough);
}
}
Expand Down Expand Up @@ -598,7 +480,7 @@ void BaselineAssembler::EmitReturn(MacroAssembler* masm) {
__ masm()->Push(kJSFunctionRegister);
__ CallRuntime(Runtime::kBytecodeBudgetInterruptFromBytecode, 1);

__ masm()->Pop(kInterpreterAccumulatorRegister, params_size);
__ masm()->Pop(params_size, kInterpreterAccumulatorRegister);
__ masm()->SmiUntag(params_size);

__ Bind(&skip_interrupt_label);
Expand Down
Loading

0 comments on commit d8dc66f

Please sign in to comment.