Skip to content

Commit 72db2a3

Browse files
committed
Add select 128
1 parent 9773390 commit 72db2a3

File tree

4 files changed

+78
-8
lines changed

4 files changed

+78
-8
lines changed

core/iwasm/compilation/aot_compiler.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1316,6 +1316,13 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index)
13161316
return false;
13171317
break;
13181318

1319+
#if WASM_ENABLE_SIMD != 0
1320+
case WASM_OP_SELECT_128:
1321+
if (!aot_compile_op_select(comp_ctx, func_ctx, true))
1322+
return false;
1323+
break;
1324+
#endif
1325+
13191326
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
13201327
case WASM_OP_SELECT_T:
13211328
{

core/iwasm/interpreter/wasm_interp_fast.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1888,6 +1888,31 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module,
18881888
}
18891889
HANDLE_OP_END();
18901890
}
1891+
#if WASM_ENABLE_JIT != 0 \
1892+
|| WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMD != 0
1893+
HANDLE_OP(WASM_OP_SELECT_128)
1894+
{
1895+
cond = frame_lp[GET_OFFSET()];
1896+
addr1 = GET_OFFSET();
1897+
addr2 = GET_OFFSET();
1898+
addr_ret = GET_OFFSET();
1899+
1900+
V128 v1 = GET_V128_FROM_ADDR(frame_lp + addr1);
1901+
V128 v2 = GET_V128_FROM_ADDR(frame_lp + addr2);
1902+
1903+
if (!cond) {
1904+
if (addr_ret != addr1)
1905+
PUT_V128_TO_ADDR(frame_lp + addr_ret,
1906+
GET_V128_FROM_ADDR(frame_lp + addr1));
1907+
}
1908+
else {
1909+
if (addr_ret != addr2)
1910+
PUT_V128_TO_ADDR(frame_lp + addr_ret,
1911+
GET_V128_FROM_ADDR(frame_lp + addr2));
1912+
}
1913+
HANDLE_OP_END();
1914+
}
1915+
#endif
18911916

18921917
#if WASM_ENABLE_GC != 0
18931918
HANDLE_OP(WASM_OP_SELECT_T)

core/iwasm/interpreter/wasm_loader.c

Lines changed: 42 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7295,6 +7295,9 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache,
72957295
case WASM_OP_SELECT:
72967296
case WASM_OP_DROP_64:
72977297
case WASM_OP_SELECT_64:
7298+
#if WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMD != 0
7299+
case WASM_OP_SELECT_128:
7300+
#endif
72987301
break;
72997302

73007303
#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0
@@ -12809,6 +12812,42 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1280912812
#if (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) \
1281012813
|| (WASM_ENABLE_FAST_INTERP != 0)
1281112814
case VALUE_TYPE_V128:
12815+
#if WASM_ENABLE_FAST_INTERP == 0
12816+
*(p - 1) = WASM_OP_SELECT_128;
12817+
#endif
12818+
#if WASM_ENABLE_FAST_INTERP != 0
12819+
if (loader_ctx->p_code_compiled) {
12820+
uint8 opcode_tmp = WASM_OP_SELECT_128;
12821+
#if WASM_ENABLE_LABELS_AS_VALUES != 0
12822+
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
12823+
*(void **)(p_code_compiled_tmp
12824+
- sizeof(void *)) =
12825+
handle_table[opcode_tmp];
12826+
#else
12827+
#if UINTPTR_MAX == UINT64_MAX
12828+
/* emit int32 relative offset in 64-bit target
12829+
*/
12830+
int32 offset =
12831+
(int32)((uint8 *)handle_table[opcode_tmp]
12832+
- (uint8 *)handle_table[0]);
12833+
*(int32 *)(p_code_compiled_tmp
12834+
- sizeof(int32)) = offset;
12835+
#else
12836+
/* emit uint32 label address in 32-bit target */
12837+
*(uint32 *)(p_code_compiled_tmp
12838+
- sizeof(uint32)) =
12839+
(uint32)(uintptr_t)handle_table[opcode_tmp];
12840+
#endif
12841+
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
12842+
#else /* else of WASM_ENABLE_LABELS_AS_VALUES */
12843+
#if WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS != 0
12844+
*(p_code_compiled_tmp - 1) = opcode_tmp;
12845+
#else
12846+
*(p_code_compiled_tmp - 2) = opcode_tmp;
12847+
#endif /* end of WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS */
12848+
#endif /* end of WASM_ENABLE_LABELS_AS_VALUES */
12849+
}
12850+
#endif /* end of WASM_ENABLE_FAST_INTERP */
1281212851
break;
1281312852
#endif /* (WASM_ENABLE_WAMR_COMPILER != 0) || (WASM_ENABLE_JIT != 0) || \
1281412853
(WASM_ENABLE_FAST_INTERP != 0) */
@@ -12906,12 +12945,9 @@ wasm_loader_prepare_bytecode(WASMModule *module, WASMFunction *func,
1290612945
uint8 opcode_tmp = WASM_OP_SELECT;
1290712946

1290812947
if (type == VALUE_TYPE_V128) {
12909-
#if (WASM_ENABLE_SIMD == 0) \
12910-
|| ((WASM_ENABLE_WAMR_COMPILER == 0) && (WASM_ENABLE_JIT == 0) \
12911-
&& (WASM_ENABLE_FAST_INTERP == 0))
12912-
set_error_buf(error_buf, error_buf_size,
12913-
"SIMD v128 type isn't supported");
12914-
goto fail;
12948+
#if WASM_ENABLE_JIT != 0 \
12949+
|| WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMD != 0
12950+
opcode_tmp = WASM_OP_SELECT_128;
1291512951
#endif
1291612952
}
1291712953
else {

core/iwasm/interpreter/wasm_opcode.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,12 +279,13 @@ typedef enum WASMOpcode {
279279
#endif
280280

281281
#if WASM_ENABLE_JIT != 0 \
282-
|| WASM_ENABLE_FAST_INTERP != 0 && WASM_ENABLE_SIMD != 0
282+
|| WASM_ENABLE_FAST_INTERP != 0 || WASM_ENABLE_WAMR_COMPILER != 0 && WASM_ENABLE_SIMD != 0
283283
EXT_OP_SET_LOCAL_FAST_V128 = 0xdd,
284284
EXT_OP_TEE_LOCAL_FAST_V128 = 0xde,
285285
EXT_OP_COPY_STACK_TOP_V128 = 0xdf,
286286
WASM_OP_GET_GLOBAL_V128 = 0xe0,
287287
WASM_OP_SET_GLOBAL_V128 = 0xe1,
288+
WASM_OP_SELECT_128 = 0xe2,
288289
#endif
289290

290291
/* Post-MVP extend op prefix */
@@ -804,7 +805,8 @@ typedef enum WASMAtomicEXTOpcode {
804805
SET_GOTO_TABLE_ELEM(EXT_OP_TEE_LOCAL_FAST_V128), /* 0xde */ \
805806
SET_GOTO_TABLE_ELEM(EXT_OP_COPY_STACK_TOP_V128), /* 0xdf */ \
806807
SET_GOTO_TABLE_ELEM(WASM_OP_GET_GLOBAL_V128), /* 0xe0 */ \
807-
SET_GOTO_TABLE_ELEM(WASM_OP_SET_GLOBAL_V128), /* 0xe1 */
808+
SET_GOTO_TABLE_ELEM(WASM_OP_SET_GLOBAL_V128), /* 0xe1 */ \
809+
SET_GOTO_TABLE_ELEM(WASM_OP_SELECT_128), /* 0xe2 */
808810

809811
#else
810812
#define DEF_EXT_V128_HANDLE()

0 commit comments

Comments
 (0)