Commit 7482128a authored by Liu Yu's avatar Liu Yu Committed by V8 LUCI CQ

[loong64][mips] Implement jump_table with GenerateSwitchTable in Sparkplug

Besides, port commit 9711289d to mips
and loong64, and fix an error with the usage of BlockTrampolinePoolFor.

Change-Id: Ifee64f8471e1d2db8945768370a30ab06210420c
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3269369Reviewed-by: 's avatarZhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Commit-Queue: Zhao Jiazhong <zhaojiazhong-hf@loongson.cn>
Auto-Submit: Liu yu <liuyu@loongson.cn>
Cr-Commit-Position: refs/heads/main@{#77784}
parent d359ade3
......@@ -414,26 +414,17 @@ void BaselineAssembler::Switch(Register reg, int case_value_base,
Label** labels, int num_labels) {
ASM_CODE_COMMENT(masm_);
Label fallthrough;
if (case_value_base > 0) {
if (case_value_base != 0) {
__ Sub_d(reg, reg, Operand(case_value_base));
}
ScratchRegisterScope scope(this);
Register scratch = scope.AcquireScratch();
__ Branch(&fallthrough, AsMasmCondition(Condition::kUnsignedGreaterThanEqual),
reg, Operand(num_labels));
int entry_size_log2 = 2;
__ pcaddi(scratch, 3);
__ Alsl_d(scratch, reg, scratch, entry_size_log2);
__ Jump(scratch);
{
TurboAssembler::BlockTrampolinePoolScope(masm());
__ BlockTrampolinePoolFor(num_labels * kInstrSize);
for (int i = 0; i < num_labels; ++i) {
__ Branch(labels[i]);
}
__ GenerateSwitchTable(reg, num_labels,
[labels](size_t i) { return labels[i]; });
__ bind(&fallthrough);
}
}
#undef __
......
......@@ -426,29 +426,17 @@ void BaselineAssembler::Switch(Register reg, int case_value_base,
Label** labels, int num_labels) {
ASM_CODE_COMMENT(masm_);
Label fallthrough;
if (case_value_base > 0) {
if (case_value_base != 0) {
__ Subu(reg, reg, Operand(case_value_base));
}
ScratchRegisterScope scope(this);
Register temp = scope.AcquireScratch();
__ Branch(&fallthrough, AsMasmCondition(Condition::kUnsignedGreaterThanEqual),
reg, Operand(num_labels));
__ push(ra);
int entry_size_log2 = 3;
__ nal();
__ addiu(reg, reg, 3);
__ Lsa(temp, ra, reg, entry_size_log2);
__ pop(ra);
__ Jump(temp);
{
TurboAssembler::BlockTrampolinePoolScope(masm());
__ BlockTrampolinePoolFor(num_labels * kInstrSize * 2);
for (int i = 0; i < num_labels; ++i) {
__ Branch(labels[i]);
}
__ GenerateSwitchTable(reg, num_labels,
[labels](size_t i) { return labels[i]; });
__ bind(&fallthrough);
}
}
#undef __
......
......@@ -424,29 +424,17 @@ void BaselineAssembler::Switch(Register reg, int case_value_base,
Label** labels, int num_labels) {
ASM_CODE_COMMENT(masm_);
Label fallthrough;
if (case_value_base > 0) {
if (case_value_base != 0) {
__ Dsubu(reg, reg, Operand(case_value_base));
}
ScratchRegisterScope scope(this);
Register temp = scope.AcquireScratch();
__ Branch(&fallthrough, AsMasmCondition(Condition::kUnsignedGreaterThanEqual),
reg, Operand(num_labels));
__ push(ra);
int entry_size_log2 = 3;
__ nal();
__ daddiu(reg, reg, 3);
__ Dlsa(temp, ra, reg, entry_size_log2);
__ pop(ra);
__ Jump(temp);
{
TurboAssembler::BlockTrampolinePoolScope(masm());
__ BlockTrampolinePoolFor(num_labels * kInstrSize * 2);
for (int i = 0; i < num_labels; ++i) {
__ Branch(labels[i]);
}
__ GenerateSwitchTable(reg, num_labels,
[labels](size_t i) { return labels[i]; });
__ bind(&fallthrough);
}
}
#undef __
......
......@@ -1062,7 +1062,7 @@ void TurboAssembler::GenerateSwitchTable(Register index, size_t case_count,
Func GetLabelFunction) {
UseScratchRegisterScope scope(this);
Register scratch = scope.Acquire();
BlockTrampolinePoolFor((3 + case_count) * kInstrSize);
BlockTrampolinePoolFor(3 + case_count);
pcaddi(scratch, 3);
alsl_d(scratch, index, scratch, kInstrSizeLog2);
......
......@@ -1515,6 +1515,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
inline int UnboundLabelsCount() { return unbound_labels_count_; }
bool is_trampoline_emitted() const { return trampoline_emitted_; }
protected:
// Load Scaled Address instruction.
void lsa(Register rd, Register rt, Register rs, uint8_t sa);
......@@ -1570,8 +1572,6 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
bool has_exception() const { return internal_trampoline_exception_; }
bool is_trampoline_emitted() const { return trampoline_emitted_; }
// Temporarily block automatic assembly buffer growth.
void StartBlockGrowBuffer() {
DCHECK(!block_buffer_growth_);
......
......@@ -1562,6 +1562,8 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
inline int UnboundLabelsCount() { return unbound_labels_count_; }
bool is_trampoline_emitted() const { return trampoline_emitted_; }
protected:
// Load Scaled Address instructions.
void lsa(Register rd, Register rt, Register rs, uint8_t sa);
......@@ -1618,8 +1620,6 @@ class V8_EXPORT_PRIVATE Assembler : public AssemblerBase {
bool has_exception() const { return internal_trampoline_exception_; }
bool is_trampoline_emitted() const { return trampoline_emitted_; }
// Temporarily block automatic assembly buffer growth.
void StartBlockGrowBuffer() {
DCHECK(!block_buffer_growth_);
......
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