Skip to content

Commit 474acd7

Browse files
Zzzabiyakaloganek
authored andcommitted
implement local and function calls for v128 in the fast interpreter
1 parent 50faad0 commit 474acd7

File tree

3 files changed

+85
-5
lines changed

3 files changed

+85
-5
lines changed

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 55 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1699,6 +1699,11 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
16991699
GET_OPERAND(uint64, I64, off));
17001700
ret_offset += 2;
17011701
}
1702+
else if (ret_types[ret_idx] == VALUE_TYPE_V128) {
1703+
PUT_V128_TO_ADDR(prev_frame->lp + ret_offset,
1704+
GET_OPERAND_V128(off));
1705+
ret_offset += 4;
1706+
}
17021707
#if WASM_ENABLE_GC != 0
17031708
else if (wasm_is_type_reftype(ret_types[ret_idx])) {
17041709
PUT_REF_TO_ADDR(prev_frame->lp + ret_offset,
@@ -3536,6 +3541,24 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
35363541
HANDLE_OP_END();
35373542
}
35383543

3544+
#if WASM_ENABLE_SIMDE != 0
3545+
HANDLE_OP(EXT_OP_SET_LOCAL_FAST_V128)
3546+
HANDLE_OP(EXT_OP_TEE_LOCAL_FAST_V128)
3547+
{
3548+
/* clang-format off */
3549+
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
3550+
local_offset = *frame_ip++;
3551+
#else
3552+
local_offset = *frame_ip;
3553+
frame_ip += 2;
3554+
#endif
3555+
/* clang-format on */
3556+
PUT_V128_TO_ADDR((uint32 *)(frame_lp + local_offset),
3557+
GET_OPERAND_V128(0));
3558+
frame_ip += 2;
3559+
HANDLE_OP_END();
3560+
}
3561+
#endif
35393562
HANDLE_OP(WASM_OP_GET_GLOBAL)
35403563
{
35413564
global_idx = read_uint32(frame_ip);
@@ -4884,6 +4907,28 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
48844907

48854908
HANDLE_OP_END();
48864909
}
4910+
#if WASM_ENABLE_SIMDE != 0
4911+
HANDLE_OP(EXT_OP_COPY_STACK_TOP_V128)
4912+
{
4913+
addr1 = GET_OFFSET();
4914+
addr2 = GET_OFFSET();
4915+
4916+
PUT_V128_TO_ADDR(frame_lp + addr2,
4917+
GET_V128_FROM_ADDR(frame_lp + addr1));
4918+
4919+
#if WASM_ENABLE_GC != 0
4920+
/* Ignore constants because they are not reference */
4921+
if (addr1 >= 0) {
4922+
if (*FRAME_REF(addr1)) {
4923+
CLEAR_FRAME_REF(addr1);
4924+
SET_FRAME_REF(addr2);
4925+
}
4926+
}
4927+
#endif
4928+
4929+
HANDLE_OP_END();
4930+
}
4931+
#endif
48874932

48884933
HANDLE_OP(EXT_OP_COPY_STACK_VALUES)
48894934
{
@@ -6079,8 +6124,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
60796124

60806125
#define SIMD_DOUBLE_OP(simde_func) \
60816126
do { \
6082-
V128 v1 = POP_V128(); \
60836127
V128 v2 = POP_V128(); \
6128+
V128 v1 = POP_V128(); \
60846129
addr_ret = GET_OFFSET(); \
60856130
\
60866131
simde_v128_t simde_result = simde_func(SIMD_V128_TO_SIMDE_V128(v1), \
@@ -6946,6 +6991,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
69466991
}
69476992
case SIMD_i32x4_add:
69486993
{
6994+
69496995
SIMD_DOUBLE_OP(simde_wasm_i32x4_add);
69506996
break;
69516997
}
@@ -7480,8 +7526,14 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
74807526
}
74817527

74827528
for (i = 0; i < cur_func->param_count; i++) {
7483-
if (cur_func->param_types[i] == VALUE_TYPE_I64
7484-
|| cur_func->param_types[i] == VALUE_TYPE_F64) {
7529+
if (cur_func->param_types[i] == VALUE_TYPE_V128) {
7530+
PUT_V128_TO_ADDR(
7531+
outs_area->lp,
7532+
GET_OPERAND_V128(2 * (cur_func->param_count - i - 1)));
7533+
outs_area->lp += 4;
7534+
}
7535+
else if (cur_func->param_types[i] == VALUE_TYPE_I64
7536+
|| cur_func->param_types[i] == VALUE_TYPE_F64) {
74857537
PUT_I64_TO_ADDR(
74867538
outs_area->lp,
74877539
GET_OPERAND(uint64, I64,

core/iwasm/interpreter/wasm_loader.c

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12944,10 +12944,21 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1294412944
emit_label(EXT_OP_SET_LOCAL_FAST);
1294512945
emit_byte(loader_ctx, (uint8)local_offset);
1294612946
}
12947-
else {
12947+
else if (is_64bit_type(local_type)) {
1294812948
emit_label(EXT_OP_SET_LOCAL_FAST_I64);
1294912949
emit_byte(loader_ctx, (uint8)local_offset);
1295012950
}
12951+
#if WASM_ENABLE_SIMDE != 0
12952+
else if (local_type == VALUE_TYPE_V128) {
12953+
emit_label(EXT_OP_SET_LOCAL_FAST_V128);
12954+
emit_byte(loader_ctx, (uint8)local_offset);
12955+
}
12956+
#endif
12957+
else {
12958+
set_error_buf(error_buf, error_buf_size,
12959+
"unknown local type");
12960+
goto fail;
12961+
}
1295112962
POP_OFFSET_TYPE(local_type);
1295212963
}
1295312964
}

core/iwasm/interpreter/wasm_opcode.h

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,14 @@ typedef enum WASMOpcode {
278278
DEBUG_OP_BREAK = 0xdc, /* debug break point */
279279
#endif
280280

281+
#if (WASM_ENABLE_JIT != 0 \
282+
|| (WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMDE != 0)) \
283+
&& WASM_ENABLE_SIMD != 0
284+
EXT_OP_SET_LOCAL_FAST_V128 = 0xdd,
285+
EXT_OP_TEE_LOCAL_FAST_V128 = 0xde,
286+
EXT_OP_COPY_STACK_TOP_V128 = 0xdf,
287+
#endif
288+
281289
/* Post-MVP extend op prefix */
282290
WASM_OP_GC_PREFIX = 0xfb,
283291
WASM_OP_MISC_PREFIX = 0xfc,
@@ -790,6 +798,15 @@ typedef enum WASMAtomicEXTOpcode {
790798
#define SET_GOTO_TABLE_SIMD_PREFIX_ELEM()
791799
#endif
792800

801+
#if (WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMDE != 0) \
802+
&& WASM_ENABLE_SIMD != 0
803+
#define DEF_EXT_V128_HANDLE() \
804+
SET_GOTO_TABLE_ELEM(EXT_OP_SET_LOCAL_FAST_V128), \
805+
SET_GOTO_TABLE_ELEM(EXT_OP_TEE_LOCAL_FAST_V128), \
806+
SET_GOTO_TABLE_ELEM(EXT_OP_COPY_STACK_TOP_V128),
807+
#else
808+
#define DEF_EXT_V128_HANDLE()
809+
#endif
793810
/*
794811
* Macro used to generate computed goto tables for the C interpreter.
795812
*/
@@ -1021,7 +1038,7 @@ typedef enum WASMAtomicEXTOpcode {
10211038
SET_GOTO_TABLE_ELEM(WASM_OP_MISC_PREFIX), /* 0xfc */ \
10221039
SET_GOTO_TABLE_SIMD_PREFIX_ELEM() /* 0xfd */ \
10231040
SET_GOTO_TABLE_ELEM(WASM_OP_ATOMIC_PREFIX), /* 0xfe */ \
1024-
DEF_DEBUG_BREAK_HANDLE() \
1041+
DEF_DEBUG_BREAK_HANDLE() DEF_EXT_V128_HANDLE() \
10251042
};
10261043

10271044
#ifdef __cplusplus

0 commit comments

Comments
 (0)