Skip to content

Commit 4135622

Browse files
authored
Fix fast jit several issues (#1163)
1 parent d40eb1d commit 4135622

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -696,9 +696,16 @@ mov_r_to_m(x86::Assembler &a, uint32 bytes_dst, uint32 kind_dst,
696696
* @return new stream
697697
*/
698698
static bool
699-
mov_imm_to_m(x86::Assembler &a, x86::Mem &m_dst, Imm imm_src)
699+
mov_imm_to_m(x86::Assembler &a, x86::Mem &m_dst, Imm imm_src, uint32 bytes_dst)
700700
{
701-
a.mov(m_dst, imm_src);
701+
if (bytes_dst == 8) {
702+
/* As there is no instruction `MOV m64, imm64`, we use
703+
two instructions to implement it */
704+
a.mov(regs_i64[REG_I64_FREE_IDX], imm_src);
705+
a.mov(m_dst, regs_i64[REG_I64_FREE_IDX]);
706+
}
707+
else
708+
a.mov(m_dst, imm_src);
702709
return true;
703710
}
704711

@@ -931,7 +938,7 @@ st_imm_to_base_imm_offset_imm(x86::Assembler &a, uint32 bytes_dst,
931938
x86::Mem m((uintptr_t)(base + offset), bytes_dst);
932939
Imm imm;
933940
imm_set_value(imm, data_src, bytes_dst);
934-
return mov_imm_to_m(a, m, imm);
941+
return mov_imm_to_m(a, m, imm, bytes_dst);
935942
}
936943

937944
/**
@@ -954,7 +961,7 @@ st_imm_to_base_imm_offset_r(x86::Assembler &a, uint32 bytes_dst, void *data_src,
954961
x86::Mem m(regs_i64[reg_no_offset], base, bytes_dst);
955962
Imm imm;
956963
imm_set_value(imm, data_src, bytes_dst);
957-
return mov_imm_to_m(a, m, imm);
964+
return mov_imm_to_m(a, m, imm, bytes_dst);
958965
}
959966

960967
/**
@@ -977,7 +984,7 @@ st_imm_to_base_r_offset_imm(x86::Assembler &a, uint32 bytes_dst, void *data_src,
977984
x86::Mem m(regs_i64[reg_no_base], offset, bytes_dst);
978985
Imm imm;
979986
imm_set_value(imm, data_src, bytes_dst);
980-
return mov_imm_to_m(a, m, imm);
987+
return mov_imm_to_m(a, m, imm, bytes_dst);
981988
}
982989

983990
/**
@@ -1001,7 +1008,7 @@ st_imm_to_base_r_offset_r(x86::Assembler &a, uint32 bytes_dst, void *data_src,
10011008
x86::Mem m(regs_i64[reg_no_base], regs_i64[reg_no_offset], 0, 0, bytes_dst);
10021009
Imm imm;
10031010
imm_set_value(imm, data_src, bytes_dst);
1004-
return mov_imm_to_m(a, m, imm);
1011+
return mov_imm_to_m(a, m, imm, bytes_dst);
10051012
}
10061013

10071014
/**

core/iwasm/fast-jit/fe/jit_emit_control.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,7 @@ handle_op_end(JitCompContext *cc, uint8 **p_frame_ip, bool is_block_polymorphic)
454454
jit_basic_block_label(block->basic_block_end);
455455
}
456456
else if (insn->opcode == JIT_OP_BNE) {
457-
*(jit_insn_opnd(insn, 1)) =
457+
*(jit_insn_opnd(insn, 2)) =
458458
jit_basic_block_label(block->basic_block_end);
459459
}
460460
else {

core/iwasm/interpreter/wasm_interp_classic.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -837,8 +837,14 @@ jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx,
837837
WASMModuleInstance *module_inst =
838838
(WASMModuleInstance *)exec_env->module_inst;
839839
WASMFunctionInstance *cur_func = module_inst->functions + func_idx;
840+
uint32 *sp_org;
840841

842+
sp_org = prev_frame->sp;
841843
wasm_interp_call_func_native(module_inst, exec_env, cur_func, prev_frame);
844+
/* Restore the stack pointer of previous frame as the caller in
845+
jitted code will just read the return value and won't decrease
846+
the stack pointer */
847+
prev_frame->sp = sp_org;
842848

843849
return wasm_get_exception(module_inst) ? false : true;
844850
}

0 commit comments

Comments
 (0)