Skip to content

Commit

Permalink
implement local and function calls for v128 in the fast interpreter
Browse files Browse the repository at this point in the history
  • Loading branch information
Zzzabiyaka committed Jan 3, 2025
1 parent dc06250 commit 29181b5
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 52 deletions.
7 changes: 5 additions & 2 deletions core/iwasm/interpreter/wasm_interp_fast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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);
Expand Down Expand Up @@ -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();
Expand All @@ -4926,6 +4928,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,

HANDLE_OP_END();
}
#endif

HANDLE_OP(EXT_OP_COPY_STACK_VALUES)
{
Expand Down
2 changes: 2 additions & 0 deletions core/iwasm/interpreter/wasm_loader.c
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
111 changes: 61 additions & 50 deletions core/iwasm/interpreter/wasm_opcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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.
*/
Expand Down Expand Up @@ -1001,33 +1015,30 @@ 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 */ \
HANDLE_OPCODE(WASM_OP_REF_IS_NULL), /* 0xd4 */ \
HANDLE_OPCODE(WASM_OP_REF_FUNC), /* 0xd5 */ \
HANDLE_OPCODE(WASM_OP_REF_EQ), /* 0xd6 */ \
HANDLE_OPCODE(WASM_OP_REF_AS_NON_NULL), /* 0xd7 */ \
HANDLE_OPCODE(WASM_OP_BR_ON_NULL), /* 0xd8 */ \
HANDLE_OPCODE(WASM_OP_BR_ON_NON_NULL), /* 0xd9 */ \
HANDLE_OPCODE(EXT_OP_BLOCK), /* 0xda */ \
HANDLE_OPCODE(EXT_OP_LOOP), /* 0xdb */ \
HANDLE_OPCODE(EXT_OP_IF), /* 0xdc */ \
HANDLE_OPCODE(EXT_OP_BR_TABLE_CACHE), /* 0xdd */ \
HANDLE_OPCODE(EXT_OP_TRY), /* 0xde */ \
HANDLE_OPCODE(EXT_OP_SET_LOCAL_FAST), /* 0xc9 */ \
HANDLE_OPCODE(EXT_OP_TEE_LOCAL_FAST), /* 0xca */ \
HANDLE_OPCODE(EXT_OP_TEE_LOCAL_FAST_I64), /* 0xcb */ \
HANDLE_OPCODE(EXT_OP_COPY_STACK_TOP), /* 0xcc */ \
HANDLE_OPCODE(EXT_OP_COPY_STACK_TOP_I64), /* 0xcd */ \
HANDLE_OPCODE(EXT_OP_COPY_STACK_VALUES), /* 0xce */ \
HANDLE_OPCODE(WASM_OP_IMPDEP), /* 0xcf */ \
HANDLE_OPCODE(WASM_OP_REF_NULL), /* 0xd0 */ \
HANDLE_OPCODE(WASM_OP_REF_IS_NULL), /* 0xd1 */ \
HANDLE_OPCODE(WASM_OP_REF_FUNC), /* 0xd2 */ \
HANDLE_OPCODE(WASM_OP_REF_EQ), /* 0xd3 */ \
HANDLE_OPCODE(WASM_OP_REF_AS_NON_NULL), /* 0xd4 */ \
HANDLE_OPCODE(WASM_OP_BR_ON_NULL), /* 0xd5 */ \
HANDLE_OPCODE(WASM_OP_BR_ON_NON_NULL), /* 0xd6 */ \
HANDLE_OPCODE(EXT_OP_BLOCK), /* 0xd7 */ \
HANDLE_OPCODE(EXT_OP_LOOP), /* 0xd8 */ \
HANDLE_OPCODE(EXT_OP_IF), /* 0xd9 */ \
HANDLE_OPCODE(EXT_OP_BR_TABLE_CACHE), /* 0xda */ \
HANDLE_OPCODE(EXT_OP_TRY), /* 0xdb */ \
SET_GOTO_TABLE_ELEM(WASM_OP_GC_PREFIX), /* 0xfb */ \
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
Expand Down

0 comments on commit 29181b5

Please sign in to comment.