From 38895ee688325859ff8dab92ccf4333c5fb47a30 Mon Sep 17 00:00:00 2001 From: Maks Litskevich Date: Fri, 3 Jan 2025 12:57:53 +0000 Subject: [PATCH] implement local and function calls for v128 in the fast interpreter --- core/iwasm/interpreter/wasm_interp_fast.c | 7 ++- core/iwasm/interpreter/wasm_loader.c | 2 + core/iwasm/interpreter/wasm_opcode.h | 73 +++++++++++++---------- 3 files changed, 49 insertions(+), 33 deletions(-) diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index af4b5e206f..e374555326 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -3540,6 +3540,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, frame_ip += 2; HANDLE_OP_END(); } + +#if WASM_ENABLE_SIMDE != 0 HANDLE_OP(EXT_OP_SET_LOCAL_FAST_V128) HANDLE_OP(EXT_OP_TEE_LOCAL_FAST_V128) { @@ -3556,7 +3558,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, frame_ip += 2; HANDLE_OP_END(); } - +#endif HANDLE_OP(WASM_OP_GET_GLOBAL) { global_idx = read_uint32(frame_ip); @@ -4905,7 +4907,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP_END(); } - +#if WASM_ENABLE_SIMDE != 0 HANDLE_OP(EXT_OP_COPY_STACK_TOP_V128) { addr1 = GET_OFFSET(); @@ -4926,6 +4928,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP_END(); } +#endif HANDLE_OP(EXT_OP_COPY_STACK_VALUES) { diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 076aa13fb6..fa1d2ad5d4 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -12948,10 +12948,12 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func, emit_label(EXT_OP_SET_LOCAL_FAST_I64); emit_byte(loader_ctx, (uint8)local_offset); } +#if WASM_ENABLE_SIMDE != 0 else if (local_type == VALUE_TYPE_V128) { emit_label(EXT_OP_SET_LOCAL_FAST_V128); emit_byte(loader_ctx, (uint8)local_offset); } +#endif else { set_error_buf(error_buf, error_buf_size, "unknown local type"); diff --git a/core/iwasm/interpreter/wasm_opcode.h b/core/iwasm/interpreter/wasm_opcode.h index bde5488a6c..600ac62bfd 100644 --- a/core/iwasm/interpreter/wasm_opcode.h +++ b/core/iwasm/interpreter/wasm_opcode.h @@ -250,35 +250,40 @@ typedef enum WASMOpcode { /* extend op code */ EXT_OP_GET_LOCAL_FAST = 0xc7, EXT_OP_SET_LOCAL_FAST_I64 = 0xc8, - EXT_OP_SET_LOCAL_FAST_V128 = 0xc9, - EXT_OP_SET_LOCAL_FAST = 0xca, - EXT_OP_TEE_LOCAL_FAST = 0xcb, - EXT_OP_TEE_LOCAL_FAST_I64 = 0xcc, - EXT_OP_TEE_LOCAL_FAST_V128 = 0xcd, - EXT_OP_COPY_STACK_TOP = 0xce, - EXT_OP_COPY_STACK_TOP_I64 = 0xcf, - EXT_OP_COPY_STACK_TOP_V128 = 0xd0, - EXT_OP_COPY_STACK_VALUES = 0xd1, - - WASM_OP_IMPDEP = 0xd2, - - WASM_OP_REF_NULL = 0xd3, /* ref.null */ - WASM_OP_REF_IS_NULL = 0xd4, /* ref.is_null */ - WASM_OP_REF_FUNC = 0xd5, /* ref.func */ - WASM_OP_REF_EQ = 0xd6, /* ref.eq */ - WASM_OP_REF_AS_NON_NULL = 0xd7, /* ref.as_non_null */ - WASM_OP_BR_ON_NULL = 0xd8, /* br_on_null */ - WASM_OP_BR_ON_NON_NULL = 0xd9, /* br_on_non_null */ - - EXT_OP_BLOCK = 0xda, /* block with blocktype */ - EXT_OP_LOOP = 0xdb, /* loop with blocktype */ - EXT_OP_IF = 0xdc, /* if with blocktype */ - EXT_OP_BR_TABLE_CACHE = 0xdd, /* br_table from cache */ - - EXT_OP_TRY = 0xde, /* try block with blocktype */ + EXT_OP_SET_LOCAL_FAST = 0xc9, + EXT_OP_TEE_LOCAL_FAST = 0xca, + EXT_OP_TEE_LOCAL_FAST_I64 = 0xcb, + EXT_OP_COPY_STACK_TOP = 0xcc, + EXT_OP_COPY_STACK_TOP_I64 = 0xcd, + EXT_OP_COPY_STACK_VALUES = 0xce, + + WASM_OP_IMPDEP = 0xcf, + + WASM_OP_REF_NULL = 0xd0, /* ref.null */ + WASM_OP_REF_IS_NULL = 0xd1, /* ref.is_null */ + WASM_OP_REF_FUNC = 0xd2, /* ref.func */ + WASM_OP_REF_EQ = 0xd3, /* ref.eq */ + WASM_OP_REF_AS_NON_NULL = 0xd4, /* ref.as_non_null */ + WASM_OP_BR_ON_NULL = 0xd5, /* br_on_null */ + WASM_OP_BR_ON_NON_NULL = 0xd6, /* br_on_non_null */ + + EXT_OP_BLOCK = 0xd7, /* block with blocktype */ + EXT_OP_LOOP = 0xd8, /* loop with blocktype */ + EXT_OP_IF = 0xd9, /* if with blocktype */ + EXT_OP_BR_TABLE_CACHE = 0xda, /* br_table from cache */ + + EXT_OP_TRY = 0xdb, /* try block with blocktype */ #if WASM_ENABLE_DEBUG_INTERP != 0 - DEBUG_OP_BREAK = 0xdf, /* debug break point */ + DEBUG_OP_BREAK = 0xdc, /* debug break point */ +#endif + +#if (WASM_ENABLE_JIT != 0 \ + || (WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMDE != 0)) \ + && WASM_ENABLE_SIMD != 0 + EXT_OP_SET_LOCAL_FAST_V128 = 0xdd, + EXT_OP_TEE_LOCAL_FAST_V128 = 0xde, + EXT_OP_COPY_STACK_TOP_V128 = 0xdf, #endif /* Post-MVP extend op prefix */ @@ -793,6 +798,15 @@ typedef enum WASMAtomicEXTOpcode { #define SET_GOTO_TABLE_SIMD_PREFIX_ELEM() #endif +#if (WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMDE != 0) \ + && WASM_ENABLE_SIMD != 0 +#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), +#else +#define DEF_EXT_V128_HANDLE() +#endif /* * Macro used to generate computed goto tables for the C interpreter. */ @@ -1001,14 +1015,11 @@ typedef enum WASMAtomicEXTOpcode { HANDLE_OPCODE(WASM_OP_SELECT_64), /* 0xc6 */ \ HANDLE_OPCODE(EXT_OP_GET_LOCAL_FAST), /* 0xc7 */ \ HANDLE_OPCODE(EXT_OP_SET_LOCAL_FAST_I64), /* 0xc8 */ \ - HANDLE_OPCODE(EXT_OP_SET_LOCAL_FAST_V128), /* 0xc9 */ \ HANDLE_OPCODE(EXT_OP_SET_LOCAL_FAST), /* 0xca */ \ HANDLE_OPCODE(EXT_OP_TEE_LOCAL_FAST), /* 0xcb */ \ HANDLE_OPCODE(EXT_OP_TEE_LOCAL_FAST_I64), /* 0xcc */ \ - HANDLE_OPCODE(EXT_OP_TEE_LOCAL_FAST_V128), /* 0xcd */ \ HANDLE_OPCODE(EXT_OP_COPY_STACK_TOP), /* 0xce */ \ HANDLE_OPCODE(EXT_OP_COPY_STACK_TOP_I64), /* 0xcf */ \ - HANDLE_OPCODE(EXT_OP_COPY_STACK_TOP_V128), /* 0xd0 */ \ HANDLE_OPCODE(EXT_OP_COPY_STACK_VALUES), /* 0xd1 */ \ HANDLE_OPCODE(WASM_OP_IMPDEP), /* 0xd2 */ \ HANDLE_OPCODE(WASM_OP_REF_NULL), /* 0xd3 */ \ @@ -1027,7 +1038,7 @@ typedef enum WASMAtomicEXTOpcode { SET_GOTO_TABLE_ELEM(WASM_OP_MISC_PREFIX), /* 0xfc */ \ SET_GOTO_TABLE_SIMD_PREFIX_ELEM() /* 0xfd */ \ SET_GOTO_TABLE_ELEM(WASM_OP_ATOMIC_PREFIX), /* 0xfe */ \ - DEF_DEBUG_BREAK_HANDLE() \ + DEF_DEBUG_BREAK_HANDLE() DEF_EXT_V128_HANDLE() \ }; #ifdef __cplusplus