From 50982dd14521633f37017c629f87ed07c6798d7d Mon Sep 17 00:00:00 2001 From: "liang.he" Date: Thu, 9 Jun 2022 12:10:39 +0800 Subject: [PATCH] Implement opcode memory.size (#1217) --- core/iwasm/fast-jit/fe/jit_emit_memory.c | 14 +++++++++++++- core/iwasm/fast-jit/fe/jit_emit_memory.h | 2 +- core/iwasm/fast-jit/jit_frontend.c | 3 +-- 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.c b/core/iwasm/fast-jit/fe/jit_emit_memory.c index 3621eab26..c162d94cc 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.c +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.c @@ -468,8 +468,20 @@ fail: } bool -jit_compile_op_memory_size(JitCompContext *cc) +jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx) { + JitReg mem_inst, res; + + mem_inst = get_memory_inst_reg(cc->jit_frame, mem_idx); + + res = jit_cc_new_reg_I32(cc); + GEN_INSN(LDI32, res, mem_inst, + NEW_CONST(I32, offsetof(WASMMemoryInstance, cur_page_count))); + + PUSH_I32(res); + + return true; +fail: return false; } diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.h b/core/iwasm/fast-jit/fe/jit_emit_memory.h index 4f1d04cda..8f483bd01 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.h +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.h @@ -44,7 +44,7 @@ bool jit_compile_op_f64_store(JitCompContext *cc, uint32 align, uint32 offset); bool -jit_compile_op_memory_size(JitCompContext *cc); +jit_compile_op_memory_size(JitCompContext *cc, uint32 mem_idx); bool jit_compile_op_memory_grow(JitCompContext *cc, uint32 mem_idx); diff --git a/core/iwasm/fast-jit/jit_frontend.c b/core/iwasm/fast-jit/jit_frontend.c index 1ae48c364..b068c02c9 100644 --- a/core/iwasm/fast-jit/jit_frontend.c +++ b/core/iwasm/fast-jit/jit_frontend.c @@ -1423,9 +1423,8 @@ jit_compile_func(JitCompContext *cc) case WASM_OP_MEMORY_SIZE: read_leb_uint32(frame_ip, frame_ip_end, mem_idx); - if (!jit_compile_op_memory_size(cc)) + if (!jit_compile_op_memory_size(cc, mem_idx)) return false; - (void)mem_idx; break; case WASM_OP_MEMORY_GROW: