diff --git a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp index 89b12da00..4714c5d9b 100644 --- a/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp +++ b/core/iwasm/fast-jit/cg/x86-64/jit_codegen_x86_64.cpp @@ -696,9 +696,16 @@ mov_r_to_m(x86::Assembler &a, uint32 bytes_dst, uint32 kind_dst, * @return new stream */ static bool -mov_imm_to_m(x86::Assembler &a, x86::Mem &m_dst, Imm imm_src) +mov_imm_to_m(x86::Assembler &a, x86::Mem &m_dst, Imm imm_src, uint32 bytes_dst) { - a.mov(m_dst, imm_src); + if (bytes_dst == 8) { + /* As there is no instruction `MOV m64, imm64`, we use + two instructions to implement it */ + a.mov(regs_i64[REG_I64_FREE_IDX], imm_src); + a.mov(m_dst, regs_i64[REG_I64_FREE_IDX]); + } + else + a.mov(m_dst, imm_src); return true; } @@ -931,7 +938,7 @@ st_imm_to_base_imm_offset_imm(x86::Assembler &a, uint32 bytes_dst, x86::Mem m((uintptr_t)(base + offset), bytes_dst); Imm imm; imm_set_value(imm, data_src, bytes_dst); - return mov_imm_to_m(a, m, imm); + return mov_imm_to_m(a, m, imm, bytes_dst); } /** @@ -954,7 +961,7 @@ st_imm_to_base_imm_offset_r(x86::Assembler &a, uint32 bytes_dst, void *data_src, x86::Mem m(regs_i64[reg_no_offset], base, bytes_dst); Imm imm; imm_set_value(imm, data_src, bytes_dst); - return mov_imm_to_m(a, m, imm); + return mov_imm_to_m(a, m, imm, bytes_dst); } /** @@ -977,7 +984,7 @@ st_imm_to_base_r_offset_imm(x86::Assembler &a, uint32 bytes_dst, void *data_src, x86::Mem m(regs_i64[reg_no_base], offset, bytes_dst); Imm imm; imm_set_value(imm, data_src, bytes_dst); - return mov_imm_to_m(a, m, imm); + return mov_imm_to_m(a, m, imm, bytes_dst); } /** @@ -1001,7 +1008,7 @@ st_imm_to_base_r_offset_r(x86::Assembler &a, uint32 bytes_dst, void *data_src, x86::Mem m(regs_i64[reg_no_base], regs_i64[reg_no_offset], 0, 0, bytes_dst); Imm imm; imm_set_value(imm, data_src, bytes_dst); - return mov_imm_to_m(a, m, imm); + return mov_imm_to_m(a, m, imm, bytes_dst); } /** diff --git a/core/iwasm/fast-jit/fe/jit_emit_control.c b/core/iwasm/fast-jit/fe/jit_emit_control.c index 407a78544..f638c0901 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_control.c +++ b/core/iwasm/fast-jit/fe/jit_emit_control.c @@ -454,7 +454,7 @@ handle_op_end(JitCompContext *cc, uint8 **p_frame_ip, bool is_block_polymorphic) jit_basic_block_label(block->basic_block_end); } else if (insn->opcode == JIT_OP_BNE) { - *(jit_insn_opnd(insn, 1)) = + *(jit_insn_opnd(insn, 2)) = jit_basic_block_label(block->basic_block_end); } else { diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 11e8fd7a4..a38500513 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -837,8 +837,14 @@ jit_invoke_native(WASMExecEnv *exec_env, uint32 func_idx, WASMModuleInstance *module_inst = (WASMModuleInstance *)exec_env->module_inst; WASMFunctionInstance *cur_func = module_inst->functions + func_idx; + uint32 *sp_org; + sp_org = prev_frame->sp; wasm_interp_call_func_native(module_inst, exec_env, cur_func, prev_frame); + /* Restore the stack pointer of previous frame as the caller in + jitted code will just read the return value and won't decrease + the stack pointer */ + prev_frame->sp = sp_org; return wasm_get_exception(module_inst) ? false : true; }