From 28d74d2e6c036515ae62ea70db44d552eaae5d3f Mon Sep 17 00:00:00 2001 From: Maks Litskevich Date: Tue, 21 Jan 2025 19:16:13 +0000 Subject: [PATCH] implement globals --- core/iwasm/interpreter/wasm_interp_fast.c | 27 ++++++++++++++++++++++- core/iwasm/interpreter/wasm_loader.c | 20 ++++++++++++++++- core/iwasm/interpreter/wasm_opcode.h | 7 +++++- 3 files changed, 51 insertions(+), 3 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 9a026428f..d972fee23 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -3595,7 +3595,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, GET_I64_FROM_ADDR((uint32 *)global_addr)); HANDLE_OP_END(); } - +#if WASM_ENABLE_SIMDE != 0 + HANDLE_OP(WASM_OP_GET_GLOBAL_128) + { + global_idx = read_uint32(frame_ip); + bh_assert(global_idx < module->e->global_count); + global = globals + global_idx; + global_addr = get_global_addr(global_data, global); + addr_ret = GET_OFFSET(); + PUT_V128_TO_ADDR(frame_lp + addr_ret, + GET_V128_FROM_ADDR((uint32 *)global_addr)); + HANDLE_OP_END(); + } +#endif HANDLE_OP(WASM_OP_SET_GLOBAL) { global_idx = read_uint32(frame_ip); @@ -3662,6 +3674,19 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, GET_I64_FROM_ADDR(frame_lp + addr1)); HANDLE_OP_END(); } +#if WASM_ENABLE_SIMDE != 0 + HANDLE_OP(WASM_OP_SET_GLOBAL_128) + { + global_idx = read_uint32(frame_ip); + bh_assert(global_idx < module->e->global_count); + global = globals + global_idx; + global_addr = get_global_addr(global_data, global); + addr1 = GET_OFFSET(); + PUT_V128_TO_ADDR((uint32 *)global_addr, + GET_V128_FROM_ADDR(frame_lp + addr1)); + HANDLE_OP_END(); + } +#endif /* memory load instructions */ HANDLE_OP(WASM_OP_I32_LOAD) diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index e19a648da..1a1ec8b35 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -7300,6 +7300,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_SET_GLOBAL: case WASM_OP_GET_GLOBAL_64: case WASM_OP_SET_GLOBAL_64: + case WASM_OP_GET_GLOBAL_128: + case WASM_OP_SET_GLOBAL_128: case WASM_OP_SET_GLOBAL_AUX_STACK: skip_leb_uint32(p, p_end); /* local index */ break; @@ -9111,6 +9113,11 @@ preserve_referenced_local(WASMLoaderContext *loader_ctx, uint8 opcode, loader_ctx->preserved_local_offset++; emit_label(EXT_OP_COPY_STACK_TOP); } + else if (local_type == VALUE_TYPE_V128) { + if (loader_ctx->p_code_compiled) + loader_ctx->preserved_local_offset += 4; + emit_label(EXT_OP_COPY_STACK_TOP_V128); + } else { if (loader_ctx->p_code_compiled) loader_ctx->preserved_local_offset += 2; @@ -13206,9 +13213,14 @@ re_scan: skip_label(); emit_label(WASM_OP_GET_GLOBAL_64); } + + if (global_type == VALUE_TYPE_V128) { + skip_label(); + emit_label(WASM_OP_GET_GLOBAL_128); + } +#endif /* end of WASM_ENABLE_SIMDE */ emit_uint32(loader_ctx, global_idx); PUSH_OFFSET_TYPE(global_type); -#endif /* end of WASM_ENABLE_FAST_INTERP */ break; } @@ -13300,6 +13312,12 @@ re_scan: skip_label(); emit_label(WASM_OP_SET_GLOBAL_AUX_STACK); } +#if WASM_ENABLE_SIMDE != 0 + else if (global_type == VALUE_TYPE_V128) { + skip_label(); + emit_label(WASM_OP_SET_GLOBAL_128); + } +#endif /* end of WASM_ENABLE_SIMDE */ emit_uint32(loader_ctx, global_idx); POP_OFFSET_TYPE(global_type); #endif /* end of WASM_ENABLE_FAST_INTERP */ diff --git a/core/iwasm/interpreter/wasm_opcode.h b/core/iwasm/interpreter/wasm_opcode.h index c3c5e00f8..47036e0db 100644 --- a/core/iwasm/interpreter/wasm_opcode.h +++ b/core/iwasm/interpreter/wasm_opcode.h @@ -284,6 +284,8 @@ typedef enum WASMOpcode { EXT_OP_SET_LOCAL_FAST_V128 = 0xdd, EXT_OP_TEE_LOCAL_FAST_V128 = 0xde, EXT_OP_COPY_STACK_TOP_V128 = 0xdf, + WASM_OP_GET_GLOBAL_128 = 0xe0, + WASM_OP_SET_GLOBAL_128 = 0xe1, #endif /* Post-MVP extend op prefix */ @@ -803,7 +805,10 @@ typedef enum WASMAtomicEXTOpcode { #define DEF_EXT_V128_HANDLE() \ SET_GOTO_TABLE_ELEM(EXT_OP_SET_LOCAL_FAST_V128), \ SET_GOTO_TABLE_ELEM(EXT_OP_TEE_LOCAL_FAST_V128), \ - SET_GOTO_TABLE_ELEM(EXT_OP_COPY_STACK_TOP_V128), + SET_GOTO_TABLE_ELEM(EXT_OP_COPY_STACK_TOP_V128), \ + SET_GOTO_TABLE_ELEM(WASM_OP_GET_GLOBAL_128), \ + SET_GOTO_TABLE_ELEM(WASM_OP_SET_GLOBAL_128), \ + #else #define DEF_EXT_V128_HANDLE() #endif