diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index b6503d808..3db29e848 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -320,12 +320,18 @@ else () message (" Wakeup of blocking operations enabled") endif () if (WAMR_BUILD_SIMD EQUAL 1) - if (NOT WAMR_BUILD_TARGET MATCHES "RISCV64.*") - add_definitions (-DWASM_ENABLE_SIMD=1) - message (" SIMD enabled") - else () + set(SIMD_ENABLED 0) + if (WAMR_BUILD_TARGET MATCHES "RISCV64.*") + set(WAMR_BUILD_SIMD 0) message (" SIMD disabled due to not supported on target RISCV64") + elseif (WAMR_BUILD_FAST_INTERP EQUAL 1 AND WAMR_BUILD_SIMDE EQUAL 0) + set(WAMR_BUILD_SIMD 0) + message(" SIMD disabled as the simde is not built in fast interpreter mode") + else() + set(SIMD_ENABLED 1) + message (" SIMD enabled") endif () + add_definitions(-DWASM_ENABLE_SIMD=${SIMD_ENABLED}) endif () if (WAMR_BUILD_AOT_STACK_FRAME EQUAL 1) add_definitions (-DWASM_ENABLE_AOT_STACK_FRAME=1) diff --git a/build-scripts/runtime_lib.cmake b/build-scripts/runtime_lib.cmake index 29789d671..ec3a370d6 100644 --- a/build-scripts/runtime_lib.cmake +++ b/build-scripts/runtime_lib.cmake @@ -155,8 +155,14 @@ if (WAMR_BUILD_LIB_RATS EQUAL 1) include (${IWASM_DIR}/libraries/lib-rats/lib_rats.cmake) endif () -if (WAMR_BUILD_LIB_SIMDE EQUAL 1) - include (${IWASM_DIR}/libraries/simde/simde.cmake) +if (WAMR_BUILD_SIMD EQUAL 1 AND WAMR_BUILD_FAST_INTERP EQUAL 1) + if (NOT (WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "ARM.*")) + message(STATUS "SIMDe doesnt support platform " ${WAMR_BUILD_TARGET}) + set(WAMR_BUILD_SIMDE 0) + else() + include (${IWASM_DIR}/libraries/simde/simde.cmake) + set (WAMR_BUILD_SIMDE 1) + endif() endif () if (WAMR_BUILD_WASM_CACHE EQUAL 1) diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index ee1ba73c6..5aee64b4d 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -3541,7 +3541,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP_END(); } -#if WASM_ENABLE_SIMDE != 0 +#if WASM_ENABLE_SIMD != 0 HANDLE_OP(EXT_OP_SET_LOCAL_FAST_V128) HANDLE_OP(EXT_OP_TEE_LOCAL_FAST_V128) { @@ -3595,8 +3595,8 @@ 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) +#if WASM_ENABLE_SIMD != 0 + HANDLE_OP(WASM_OP_GET_GLOBAL_V128) { global_idx = read_uint32(frame_ip); bh_assert(global_idx < module->e->global_count); @@ -3675,7 +3675,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP_END(); } #if WASM_ENABLE_SIMDE != 0 - HANDLE_OP(WASM_OP_SET_GLOBAL_128) + HANDLE_OP(WASM_OP_SET_GLOBAL_V128) { global_idx = read_uint32(frame_ip); bh_assert(global_idx < module->e->global_count); @@ -4932,7 +4932,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, HANDLE_OP_END(); } -#if WASM_ENABLE_SIMDE != 0 +#if WASM_ENABLE_SIMD != 0 HANDLE_OP(EXT_OP_COPY_STACK_TOP_V128) { addr1 = GET_OFFSET(); @@ -5837,7 +5837,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, { uint32 offset, addr; offset = read_uint32(frame_ip); - addr = POP_I32(); + addr = GET_OPERAND(uint32, I32, 0); + frame_ip += 2; addr_ret = GET_OFFSET(); CHECK_MEMORY_OVERFLOW(16); PUT_V128_TO_ADDR(frame_lp + addr_ret, LOAD_V128(maddr)); @@ -5850,7 +5851,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, addr = GET_OPERAND(uint32, I32, 0); \ frame_ip += 2; \ addr_ret = GET_OFFSET(); \ - CHECK_MEMORY_OVERFLOW(4); \ + CHECK_MEMORY_OVERFLOW(16); \ \ simde_v128_t simde_result = simde_func(maddr); \ \ @@ -5858,7 +5859,6 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, SIMDE_V128_TO_SIMD_V128(simde_result, result); \ PUT_V128_TO_ADDR(frame_lp + addr_ret, result); \ \ - break; \ } while (0) case SIMD_v128_load8x8_s: { @@ -5936,7 +5936,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, offset += base; addr = GET_OPERAND(uint32, I32, 0); - CHECK_MEMORY_OVERFLOW(4); + CHECK_MEMORY_OVERFLOW(16); STORE_V128(maddr, data); break; } diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 4e2d6f337..eaba5555b 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -7301,8 +7301,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_GET_GLOBAL_64: case WASM_OP_SET_GLOBAL_64: #if WASM_ENABLE_SIMDE != 0 - case WASM_OP_GET_GLOBAL_128: - case WASM_OP_SET_GLOBAL_128: + case WASM_OP_GET_GLOBAL_V128: + case WASM_OP_SET_GLOBAL_V128: #endif case WASM_OP_SET_GLOBAL_AUX_STACK: skip_leb_uint32(p, p_end); /* local index */ @@ -9588,6 +9588,7 @@ wasm_loader_get_const_offset(WASMLoaderContext *ctx, uint8 type, void *value, bh_memcpy_s(&(c->value.v128), sizeof(WASMValue), value, sizeof(V128)); ctx->const_cell_num++; + break; #if WASM_ENABLE_REF_TYPES != 0 && WASM_ENABLE_GC == 0 case VALUE_TYPE_EXTERNREF: case VALUE_TYPE_FUNCREF: @@ -13226,7 +13227,7 @@ re_scan: #if WASM_ENABLE_SIMDE != 0 if (global_type == VALUE_TYPE_V128) { skip_label(); - emit_label(WASM_OP_GET_GLOBAL_128); + emit_label(WASM_OP_GET_GLOBAL_V128); } #endif /* end of WASM_ENABLE_SIMDE */ emit_uint32(loader_ctx, global_idx); @@ -13326,7 +13327,7 @@ re_scan: #if WASM_ENABLE_SIMDE != 0 else if (global_type == VALUE_TYPE_V128) { skip_label(); - emit_label(WASM_OP_SET_GLOBAL_128); + emit_label(WASM_OP_SET_GLOBAL_V128); } #endif /* end of WASM_ENABLE_SIMDE */ emit_uint32(loader_ctx, global_idx); diff --git a/core/iwasm/interpreter/wasm_opcode.h b/core/iwasm/interpreter/wasm_opcode.h index 176515c57..9660bb123 100644 --- a/core/iwasm/interpreter/wasm_opcode.h +++ b/core/iwasm/interpreter/wasm_opcode.h @@ -278,13 +278,13 @@ typedef enum WASMOpcode { DEBUG_OP_BREAK = 0xdc, /* debug break point */ #endif -#if WASM_ENABLE_JIT != 0 || WASM_ENABLE_FAST_INTERP != 0 \ - && WASM_ENABLE_SIMD != 0 +#if WASM_ENABLE_JIT != 0 \ + || WASM_ENABLE_FAST_INTERP != 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, - WASM_OP_GET_GLOBAL_128 = 0xe0, - WASM_OP_SET_GLOBAL_128 = 0xe1, + WASM_OP_GET_GLOBAL_V128 = 0xe0, + WASM_OP_SET_GLOBAL_V128 = 0xe1, #endif /* Post-MVP extend op prefix */ @@ -798,13 +798,13 @@ typedef enum WASMAtomicEXTOpcode { #define SET_GOTO_TABLE_SIMD_PREFIX_ELEM() #endif -#if WASM_ENABLE_FAST_INTERP != 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), \ - SET_GOTO_TABLE_ELEM(WASM_OP_GET_GLOBAL_V128), \ - SET_GOTO_TABLE_ELEM(WASM_OP_SET_GLOBAL_V128), +#if (WASM_ENABLE_FAST_INTERP != 0) && WASM_ENABLE_SIMD != 0 +#define DEF_EXT_V128_HANDLE() \ + SET_GOTO_TABLE_ELEM(EXT_OP_SET_LOCAL_FAST_V128), /* 0xdd */ \ + SET_GOTO_TABLE_ELEM(EXT_OP_TEE_LOCAL_FAST_V128), /* 0xde */ \ + SET_GOTO_TABLE_ELEM(EXT_OP_COPY_STACK_TOP_V128), /* 0xdf */ \ + SET_GOTO_TABLE_ELEM(WASM_OP_GET_GLOBAL_V128), /* 0xe0 */ \ + SET_GOTO_TABLE_ELEM(WASM_OP_SET_GLOBAL_V128), /* 0xe1 */ #else #define DEF_EXT_V128_HANDLE() diff --git a/core/iwasm/libraries/simde/simde.cmake b/core/iwasm/libraries/simde/simde.cmake index 1219c8e5b..eeb0e8d1f 100644 --- a/core/iwasm/libraries/simde/simde.cmake +++ b/core/iwasm/libraries/simde/simde.cmake @@ -4,12 +4,7 @@ set (LIB_SIMDE_DIR ${CMAKE_CURRENT_LIST_DIR}) -if (WAMR_BUILD_TARGET MATCHES "AARCH64.*" OR WAMR_BUILD_TARGET MATCHES "ARM.*") - add_definitions (-DWASM_ENABLE_SIMDE=1) -else() - message(WARNING "Disabling SIMD for fast interpreter as the target is not supported") - set(WAMR_BUILD_SIMD 0) -endif() +add_definitions (-DWASM_ENABLE_SIMDE=1) include_directories(${LIB_SIMDE_DIR} ${LIB_SIMDE_DIR}/simde)