diff --git a/.github/workflows/compilation_on_android_ubuntu.yml b/.github/workflows/compilation_on_android_ubuntu.yml index 8a4a6aefe..01356dc66 100644 --- a/.github/workflows/compilation_on_android_ubuntu.yml +++ b/.github/workflows/compilation_on_android_ubuntu.yml @@ -166,6 +166,7 @@ jobs: "-DWAMR_BUILD_MULTI_MEMORY=1", "-DWAMR_BUILD_SHARED=1", "-DWAMR_BUILD_EXTENDED_CONST_EXPR=1", + "-DWAMR_BUILD_LIME1=1 -DWAMR_BUILD_BULK_MEMORY=0 -DWAMR_BUILD_REF_TYPES=0 -DWAMR_BUILD_SIMD=0", ] os: [ubuntu-22.04] platform: [android, linux] diff --git a/build-scripts/config_common.cmake b/build-scripts/config_common.cmake index 838baab9d..52c6d94af 100644 --- a/build-scripts/config_common.cmake +++ b/build-scripts/config_common.cmake @@ -221,6 +221,14 @@ if (NOT DEFINED WAMR_BUILD_BULK_MEMORY) set (WAMR_BUILD_BULK_MEMORY 1) endif () +if (NOT DEFINED WAMR_BUILD_BULK_MEMORY_OPT) + set (WAMR_BUILD_BULK_MEMORY_OPT 0) +endif () + +if (NOT DEFINED WAMR_BUILD_CALL_INDIRECT_OVERLONG) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 0) +endif () + if (NOT DEFINED WAMR_BUILD_EXCE_HANDLING) set (WAMR_BUILD_EXCE_HANDLING 0) endif () @@ -253,10 +261,27 @@ if (NOT DEFINED WAMR_BUILD_EXTENDED_CONST_EXPR) set (WAMR_BUILD_EXTENDED_CONST_EXPR 0) endif () +if (NOT DEFINED WAMR_BUILD_LIME1) + set (WAMR_BUILD_LIME1 0) +endif () + ######################################## # Compilation options to marco ######################################## +if (WAMR_BUILD_LIME1 EQUAL 1) + set (WAMR_BUILD_BULK_MEMORY_OPT 1) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 1) + set (WAMR_BUILD_EXTENDED_CONST_EXPR 1) +endif () + +if (WAMR_BUILD_BULK_MEMORY EQUAL 1) + set (WAMR_BUILD_BULK_MEMORY_OPT 1) +endif () +if (WAMR_BUILD_REF_TYPES EQUAL 1) + set (WAMR_BUILD_CALL_INDIRECT_OVERLONG 1) +endif () + message ("-- Build Configurations:") message (" Build as target ${WAMR_BUILD_TARGET}") message (" Build for platform ${WAMR_BUILD_PLATFORM}") @@ -366,6 +391,11 @@ if (WAMR_BUILD_BULK_MEMORY EQUAL 1) else () add_definitions (-DWASM_ENABLE_BULK_MEMORY=0) endif () +if (WAMR_BUILD_BULK_MEMORY_OPT EQUAL 1) + add_definitions (-DWASM_ENABLE_BULK_MEMORY_OPT=1) +else() + add_definitions (-DWASM_ENABLE_BULK_MEMORY_OPT=0) +endif () if (WAMR_BUILD_SHARED_MEMORY EQUAL 1) add_definitions (-DWASM_ENABLE_SHARED_MEMORY=1) message (" Shared memory enabled") @@ -457,6 +487,11 @@ endif () if (WAMR_BUILD_REF_TYPES EQUAL 1) add_definitions (-DWASM_ENABLE_REF_TYPES=1) endif () +if (WAMR_BUILD_CALL_INDIRECT_OVERLONG EQUAL 1) + add_definitions (-DWASM_ENABLE_CALL_INDIRECT_OVERLONG=1) +else () + add_definitions(-DWASM_ENABLE_CALL_INDIRECT_OVERLONG=0) +endif () if (WAMR_BUILD_GC EQUAL 1) if (WAMR_TEST_GC EQUAL 1) message(" GC testing enabled") @@ -727,6 +762,9 @@ else() message (" Extended constant expression disabled") add_definitions(-DWASM_ENABLE_EXTENDED_CONST_EXPR=0) endif () +if (WAMR_BUILD_LIME1 EQUAL 1) + message (" Lime1 enabled") +endif () ######################################## # Show Phase4 Wasm proposals status. ######################################## @@ -742,6 +780,8 @@ message ( " \"Branch Hinting\"\n" " Configurable. 0 is OFF. 1 is ON:\n" " \"Bulk Memory Operation\" via WAMR_BUILD_BULK_MEMORY: ${WAMR_BUILD_BULK_MEMORY}\n" +" \"Bulk-memory-opt\" via WAMR_BUILD_BULK_MEMORY_OPT: ${WAMR_BUILD_BULK_MEMORY_OPT}\n" +" \"Call-indirect-overlong\" via WAMR_BUILD_CALL_INDIRECT_OVERLONG: ${WAMR_BUILD_CALL_INDIRECT_OVERLONG}\n" " \"Extended Constant Expressions\" via WAMR_BUILD_EXTENDED_CONST_EXPR: ${WAMR_BUILD_EXTENDED_CONST_EXPR}\n" " \"Fixed-width SIMD\" via WAMR_BUILD_SIMD: ${WAMR_BUILD_SIMD}\n" " \"Garbage Collection\" via WAMR_BUILD_GC: ${WAMR_BUILD_GC}\n" diff --git a/core/config.h b/core/config.h index 060bb3259..cb5db1d0c 100644 --- a/core/config.h +++ b/core/config.h @@ -214,6 +214,10 @@ #define WASM_ENABLE_BULK_MEMORY 0 #endif +#ifndef WASM_ENABLE_BULK_MEMORY_OPT +#define WASM_ENABLE_BULK_MEMORY_OPT 0 +#endif + /* Shared memory */ #ifndef WASM_ENABLE_SHARED_MEMORY #define WASM_ENABLE_SHARED_MEMORY 0 @@ -579,6 +583,10 @@ unless used elsewhere */ #define WASM_ENABLE_REF_TYPES 0 #endif +#ifndef WASM_ENABLE_CALL_INDIRECT_OVERLONG +#define WASM_ENABLE_CALL_INDIRECT_OVERLONG 0 +#endif + #ifndef WASM_ENABLE_BRANCH_HINTS #define WASM_ENABLE_BRANCH_HINTS 0 #endif diff --git a/core/iwasm/compilation/aot_compiler.c b/core/iwasm/compilation/aot_compiler.c index 60c772570..29026e800 100644 --- a/core/iwasm/compilation/aot_compiler.c +++ b/core/iwasm/compilation/aot_compiler.c @@ -1236,8 +1236,8 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) uint32 tbl_idx; read_leb_uint32(frame_ip, frame_ip_end, type_idx); - - if (comp_ctx->enable_gc || comp_ctx->enable_ref_types) { + if (comp_ctx->enable_gc + || comp_ctx->enable_call_indirect_overlong) { read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); } else { @@ -2462,6 +2462,14 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) UINT8_MAX */ opcode = (uint8)opcode1; +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + if (WASM_OP_MEMORY_COPY <= opcode + && opcode <= WASM_OP_MEMORY_FILL + && !comp_ctx->enable_bulk_memory_opt) { + goto unsupport_bulk_memory_opt; + } +#endif + #if WASM_ENABLE_BULK_MEMORY != 0 if (WASM_OP_MEMORY_INIT <= opcode && opcode <= WASM_OP_MEMORY_FILL @@ -2530,6 +2538,8 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) return false; break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { frame_ip += 2; @@ -2544,7 +2554,7 @@ aot_compile_func(AOTCompContext *comp_ctx, uint32 func_index) return false; break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -3971,6 +3981,13 @@ unsupport_gc_and_ref_types: return false; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 +unsupport_bulk_memory_opt: + aot_set_last_error("bulk memory opt instruction was found, " + "try enabling bulk-memory-opt or bulk-memory option"); + return false; +#endif + #if WASM_ENABLE_BULK_MEMORY != 0 unsupport_bulk_memory: aot_set_last_error("bulk memory instruction was found, " diff --git a/core/iwasm/compilation/aot_emit_memory.c b/core/iwasm/compilation/aot_emit_memory.c index 0659c2b40..0dec2ed36 100644 --- a/core/iwasm/compilation/aot_emit_memory.c +++ b/core/iwasm/compilation/aot_emit_memory.c @@ -1481,7 +1481,7 @@ fail: return false; } -#if WASM_ENABLE_BULK_MEMORY != 0 || WASM_ENABLE_STRINGREF != 0 +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 || WASM_ENABLE_STRINGREF != 0 LLVMValueRef check_bulk_memory_overflow(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, LLVMValueRef offset, LLVMValueRef bytes) @@ -1769,7 +1769,9 @@ aot_compile_op_data_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, fail: return false; } +#endif /* end of WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) { @@ -1931,7 +1933,7 @@ aot_compile_op_memory_fill(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx) fail: return false; } -#endif /* end of WASM_ENABLE_BULK_MEMORY */ +#endif /* end of WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_SHARED_MEMORY != 0 bool diff --git a/core/iwasm/compilation/aot_emit_memory.h b/core/iwasm/compilation/aot_emit_memory.h index 1eb95993c..5b87377be 100644 --- a/core/iwasm/compilation/aot_emit_memory.h +++ b/core/iwasm/compilation/aot_emit_memory.h @@ -78,7 +78,9 @@ aot_compile_op_memory_init(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, bool aot_compile_op_data_drop(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx, uint32 seg_index); +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool aot_compile_op_memory_copy(AOTCompContext *comp_ctx, AOTFuncContext *func_ctx); diff --git a/core/iwasm/compilation/aot_llvm.c b/core/iwasm/compilation/aot_llvm.c index ed36749be..ab351e6d4 100644 --- a/core/iwasm/compilation/aot_llvm.c +++ b/core/iwasm/compilation/aot_llvm.c @@ -2731,6 +2731,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_bulk_memory) comp_ctx->enable_bulk_memory = true; + if (option->enable_bulk_memory_opt) + comp_ctx->enable_bulk_memory_opt = true; + if (option->enable_thread_mgr) comp_ctx->enable_thread_mgr = true; @@ -2740,6 +2743,9 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) if (option->enable_ref_types) comp_ctx->enable_ref_types = true; + if (option->enable_call_indirect_overlong) + comp_ctx->enable_call_indirect_overlong = true; + comp_ctx->aux_stack_frame_type = option->aux_stack_frame_type; comp_ctx->call_stack_features = option->call_stack_features; @@ -3324,7 +3330,7 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) /* Return error if ref-types and GC are disabled by command line but ref-types instructions are used */ - if (!option->enable_ref_types && !option->enable_gc + if (!option->enable_call_indirect_overlong && !option->enable_gc && wasm_module->is_ref_types_used) { aot_set_last_error("ref-types instruction was found, " "try removing --disable-ref-types option " @@ -3338,9 +3344,13 @@ aot_create_comp_context(const AOTCompData *comp_data, aot_comp_option_t option) } if (!wasm_module->is_ref_types_used) { option->enable_ref_types = comp_ctx->enable_ref_types = false; + option->enable_call_indirect_overlong = + comp_ctx->enable_call_indirect_overlong = false; } if (!wasm_module->is_bulk_memory_used) { option->enable_bulk_memory = comp_ctx->enable_bulk_memory = false; + option->enable_bulk_memory_opt = comp_ctx->enable_bulk_memory_opt = + false; } #endif diff --git a/core/iwasm/compilation/aot_llvm.h b/core/iwasm/compilation/aot_llvm.h index a83fddb49..5bd75a38c 100644 --- a/core/iwasm/compilation/aot_llvm.h +++ b/core/iwasm/compilation/aot_llvm.h @@ -416,6 +416,10 @@ typedef struct AOTCompContext { /* Bulk memory feature */ bool enable_bulk_memory; + /* Bulk memory opt feature. will be enabled alongside the + * enable_bulk_memory */ + bool enable_bulk_memory_opt; + /* Boundary Check */ bool enable_bound_check; @@ -452,6 +456,9 @@ typedef struct AOTCompContext { /* Reference Types */ bool enable_ref_types; + /* Call Indirect Overlong. will be enabled alongside the enable_ref_types */ + bool enable_call_indirect_overlong; + /* Disable LLVM built-in intrinsics */ bool disable_llvm_intrinsics; diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.c b/core/iwasm/fast-jit/fe/jit_emit_memory.c index bbe82cf67..07269a655 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.c +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.c @@ -713,7 +713,9 @@ jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx) return jit_emit_callnative(cc, wasm_data_drop, 0, args, sizeof(args) / sizeof(args[0])); } +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 static int wasm_copy_memory(WASMModuleInstance *inst, uint32 src_mem_idx, uint32 dst_mem_idx, uint32 len, uint32 src_offset, diff --git a/core/iwasm/fast-jit/fe/jit_emit_memory.h b/core/iwasm/fast-jit/fe/jit_emit_memory.h index 6565cdc11..2fdacccf5 100644 --- a/core/iwasm/fast-jit/fe/jit_emit_memory.h +++ b/core/iwasm/fast-jit/fe/jit_emit_memory.h @@ -55,7 +55,9 @@ jit_compile_op_memory_init(JitCompContext *cc, uint32 mem_idx, uint32 seg_idx); bool jit_compile_op_data_drop(JitCompContext *cc, uint32 seg_idx); +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 bool jit_compile_op_memory_copy(JitCompContext *cc, uint32 src_mem_idx, uint32 dst_mem_idx); diff --git a/core/iwasm/fast-jit/jit_frontend.c b/core/iwasm/fast-jit/jit_frontend.c index 566783b6f..c96b5410b 100644 --- a/core/iwasm/fast-jit/jit_frontend.c +++ b/core/iwasm/fast-jit/jit_frontend.c @@ -1627,7 +1627,7 @@ jit_compile_func(JitCompContext *cc) read_leb_uint32(frame_ip, frame_ip_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); #else frame_ip++; @@ -2336,6 +2336,8 @@ jit_compile_func(JitCompContext *cc) return false; break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { uint32 src_mem_idx, dst_mem_idx; @@ -2353,7 +2355,7 @@ jit_compile_func(JitCompContext *cc) return false; break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: { diff --git a/core/iwasm/include/aot_comp_option.h b/core/iwasm/include/aot_comp_option.h index 069ceab31..9a9023ee2 100644 --- a/core/iwasm/include/aot_comp_option.h +++ b/core/iwasm/include/aot_comp_option.h @@ -62,13 +62,16 @@ typedef struct AOTCompOption { char *cpu_features; bool is_sgx_platform; bool enable_bulk_memory; + bool enable_bulk_memory_opt; bool enable_thread_mgr; bool enable_tail_call; bool enable_simd; bool enable_ref_types; + bool enable_call_indirect_overlong; bool enable_gc; bool enable_aux_stack_check; bool enable_extended_const; + bool enable_lime1; AOTStackFrameType aux_stack_frame_type; AOTCallStackFeatures call_stack_features; bool enable_perf_profiling; diff --git a/core/iwasm/interpreter/wasm_interp_classic.c b/core/iwasm/interpreter/wasm_interp_classic.c index 8f5f1821a..9ba3a5f4f 100644 --- a/core/iwasm/interpreter/wasm_interp_classic.c +++ b/core/iwasm/interpreter/wasm_interp_classic.c @@ -1567,7 +1567,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 uint64 linear_mem_size = 0; if (memory) #if WASM_ENABLE_THREAD_MGR == 0 @@ -2370,7 +2370,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, cur_type = wasm_types[tidx]; /* clang-format off */ -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 read_leb_uint32(frame_ip, frame_ip_end, tbl_idx); #else frame_ip++; @@ -5774,6 +5774,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, segment); break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { mem_offset_t dst, src, len; @@ -5894,7 +5896,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, memset(mdst, fill_val, len); break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -6879,7 +6881,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 out_of_bounds: wasm_set_exception(module, "out of bounds memory access"); #endif diff --git a/core/iwasm/interpreter/wasm_interp_fast.c b/core/iwasm/interpreter/wasm_interp_fast.c index 5cbb3cbe9..a326018ef 100644 --- a/core/iwasm/interpreter/wasm_interp_fast.c +++ b/core/iwasm/interpreter/wasm_interp_fast.c @@ -1501,7 +1501,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, WASMMemoryInstance *memory = wasm_get_default_memory(module); #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 uint64 linear_mem_size = 0; if (memory) #if WASM_ENABLE_THREAD_MGR == 0 @@ -5200,6 +5200,8 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, segment); break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { uint32 dst, src, len; @@ -5290,7 +5292,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, memset(mdst, fill_val, len); break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { @@ -7805,7 +7807,7 @@ wasm_interp_call_func_bytecode(WASMModuleInstance *module, #if !defined(OS_ENABLE_HW_BOUND_CHECK) \ || WASM_CPU_SUPPORTS_UNALIGNED_ADDR_ACCESS == 0 \ - || WASM_ENABLE_BULK_MEMORY != 0 + || WASM_ENABLE_BULK_MEMORY_OPT != 0 out_of_bounds: wasm_set_exception(module, "out of bounds memory access"); #endif diff --git a/core/iwasm/interpreter/wasm_loader.c b/core/iwasm/interpreter/wasm_loader.c index 2346b2952..19ca24949 100644 --- a/core/iwasm/interpreter/wasm_loader.c +++ b/core/iwasm/interpreter/wasm_loader.c @@ -5869,6 +5869,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + option.enable_bulk_memory_opt = true; +#endif #if WASM_ENABLE_THREAD_MGR != 0 option.enable_thread_mgr = true; #endif @@ -5882,6 +5885,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, option.enable_ref_types = true; #elif WASM_ENABLE_GC != 0 option.enable_gc = true; +#endif +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 + option.enable_call_indirect_overlong = true; #endif option.enable_aux_stack_check = true; #if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \ @@ -7739,7 +7745,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_RETURN_CALL_INDIRECT: #endif skip_leb_uint32(p, p_end); /* typeidx */ -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 skip_leb_uint32(p, p_end); /* tableidx */ #else u8 = read_uint8(p); /* 0x00 */ @@ -8164,6 +8170,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_DATA_DROP: skip_leb_uint32(p, p_end); break; +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: skip_leb_memidx(p, p_end); skip_leb_memidx(p, p_end); @@ -8171,7 +8179,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_MEMORY_FILL: skip_leb_memidx(p, p_end); break; -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: case WASM_OP_TABLE_COPY: @@ -12987,7 +12995,7 @@ re_scan: #endif pb_read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 || WASM_ENABLE_GC != 0 #if WASM_ENABLE_WAMR_COMPILER != 0 if (p + 1 < p_end && *p != 0x00) { /* @@ -15673,8 +15681,11 @@ re_scan: emit_uint32(loader_ctx, data_seg_idx); #endif if (module->import_memory_count == 0 - && module->memory_count == 0) - goto fail_unknown_memory; + && module->memory_count == 0) { + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; + } pb_read_leb_uint32(p, p_end, memidx); check_memidx(module, memidx); @@ -15723,6 +15734,12 @@ re_scan: #endif break; } + fail_data_cnt_sec_require: + set_error_buf(error_buf, error_buf_size, + "data count section required"); + goto fail; +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { CHECK_BUF(p, p_end, sizeof(int16)); @@ -15733,8 +15750,11 @@ re_scan: check_memidx(module, memidx); if (module->import_memory_count == 0 - && module->memory_count == 0) - goto fail_unknown_memory; + && module->memory_count == 0) { + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; + } POP_MEM_OFFSET(); POP_MEM_OFFSET(); @@ -15753,7 +15773,9 @@ re_scan: check_memidx(module, memidx); if (module->import_memory_count == 0 && module->memory_count == 0) { - goto fail_unknown_memory; + set_error_buf(error_buf, error_buf_size, + "unknown memory 0"); + goto fail; } POP_MEM_OFFSET(); POP_I32(); @@ -15766,16 +15788,7 @@ re_scan: #endif break; } - - fail_unknown_memory: - set_error_buf(error_buf, error_buf_size, - "unknown memory 0"); - goto fail; - fail_data_cnt_sec_require: - set_error_buf(error_buf, error_buf_size, - "data count section required"); - goto fail; -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 || WASM_ENABLE_GC != 0 case WASM_OP_TABLE_INIT: { diff --git a/core/iwasm/interpreter/wasm_mini_loader.c b/core/iwasm/interpreter/wasm_mini_loader.c index 6fff2fa17..b9dcc9877 100644 --- a/core/iwasm/interpreter/wasm_mini_loader.c +++ b/core/iwasm/interpreter/wasm_mini_loader.c @@ -2388,6 +2388,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #if WASM_ENABLE_BULK_MEMORY != 0 option.enable_bulk_memory = true; #endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 + option.enable_bulk_memory_opt = true; +#endif #if WASM_ENABLE_THREAD_MGR != 0 option.enable_thread_mgr = true; #endif @@ -2399,6 +2402,9 @@ init_llvm_jit_functions_stage1(WASMModule *module, char *error_buf, #endif #if WASM_ENABLE_REF_TYPES != 0 option.enable_ref_types = true; +#endif +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 + option.enable_call_indirect_overlong = true; #endif option.enable_aux_stack_check = true; #if WASM_ENABLE_PERF_PROFILING != 0 || WASM_ENABLE_DUMP_CALL_STACK != 0 \ @@ -3849,7 +3855,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_RETURN_CALL_INDIRECT: #endif skip_leb_uint32(p, p_end); /* typeidx */ -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 skip_leb_uint32(p, p_end); /* tableidx */ #else u8 = read_uint8(p); /* 0x00 */ @@ -4111,6 +4117,8 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_DATA_DROP: skip_leb_uint32(p, p_end); break; +#endif +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: skip_leb_memidx(p, p_end); skip_leb_memidx(p, p_end); @@ -4118,7 +4126,7 @@ wasm_loader_find_block_addr(WASMExecEnv *exec_env, BlockAddr *block_addr_cache, case WASM_OP_MEMORY_FILL: skip_leb_memidx(p, p_end); break; -#endif +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: case WASM_OP_TABLE_COPY: @@ -7069,7 +7077,7 @@ re_scan: pb_read_leb_uint32(p, p_end, type_idx); -#if WASM_ENABLE_REF_TYPES != 0 +#if WASM_ENABLE_CALL_INDIRECT_OVERLONG != 0 pb_read_leb_uint32(p, p_end, table_idx); #else CHECK_BUF(p, p_end, 1); @@ -8274,6 +8282,8 @@ re_scan: #endif break; } +#endif /* WASM_ENABLE_BULK_MEMORY */ +#if WASM_ENABLE_BULK_MEMORY_OPT != 0 case WASM_OP_MEMORY_COPY: { CHECK_MEMORY(); @@ -8306,7 +8316,7 @@ re_scan: #endif break; } -#endif /* WASM_ENABLE_BULK_MEMORY */ +#endif /* WASM_ENABLE_BULK_MEMORY_OPT */ #if WASM_ENABLE_REF_TYPES != 0 case WASM_OP_TABLE_INIT: { diff --git a/doc/build_wamr.md b/doc/build_wamr.md index 6d4e60741..798c79264 100644 --- a/doc/build_wamr.md +++ b/doc/build_wamr.md @@ -297,6 +297,18 @@ Currently we only profile the memory consumption of module, module_instance and - **WAMR_BUILD_EXTENDED_CONST_EXPR**=1/0, default to disable if not set. > Note: See [Extended Constant Expressions](https://github.com/WebAssembly/extended-const/blob/main/proposals/extended-const/Overview.md) for more details. +### **Enable bulk-memory-opt** +- **WAMR_BUILD_BULK_MEMORY_OPT**=1/0, default to disable if not set. +> Note: See [bulk-memory-opt](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#bulk-memory-opt) for more details. + +### **Enable call-indirect-overlong** +- **WAMR_BUILD_CALL_INDIRECT_OVERLONG**=1/0, default to disable if not set. +> Note: See [call-indirect-overlong](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#call-indirect-overlong) for more details. + +### **Enable Lime1 target** +- **WAMR_BUILD_LIME1**=1/0, default to disable if not set. +> Note: See [Lime1](https://github.com/WebAssembly/tool-conventions/blob/main/Lime.md#lime1) for more details. + ### **Configurable memory access boundary check** - **WAMR_CONFIGURABLE_BOUNDS_CHECKS**=1/0, default to disable if not set > Note: If it is enabled, allow to run `iwasm --disable-bounds-checks` to disable the memory access boundary checks for interpreter mode. @@ -366,3 +378,10 @@ For Valgrind, begin with the following configurations and add additional ones as -DWAMR_DISABLE_WRITE_GS_BASE=0 #... ``` + +To enable the minimal Lime1 feature set, we need to disable some features that are on by default, such as +bulk memory and reference types: + +```Bash +cmake .. -DWAMR_BUILD_LIME1=1 -DWAMR_BUILD_BULK_MEMORY=0 -DWAMR_BUILD_REF_TYPES=0 -DDWAMR_BUILD_SIMD=0 +``` diff --git a/doc/build_wasm_app.md b/doc/build_wasm_app.md index 3c4b519b6..648d21534 100644 --- a/doc/build_wasm_app.md +++ b/doc/build_wasm_app.md @@ -355,6 +355,8 @@ Usage: wamrc [options] -o output_file wasm_file llvmir-unopt Unoptimized LLVM IR llvmir-opt Optimized LLVM IR --disable-bulk-memory Disable the MVP bulk memory feature + --enable-bulk-memory-opt Enable bulk memory opt feature + --enable-extended-const Enable extended const expr feature --enable-multi-thread Enable multi-thread feature, the dependent features bulk-memory and thread-mgr will be enabled automatically --enable-tail-call Enable the post-MVP tail call feature @@ -363,6 +365,9 @@ Usage: wamrc [options] -o output_file wasm_file and by default it is enabled in x86-64 target and disabled in other targets --disable-ref-types Disable the MVP reference types feature + --enable-call-indirect-overlong + Enable call indirect overlong feature + --enable-lime1 Enable Lime1 --disable-aux-stack-check Disable auxiliary stack overflow/underflow check --enable-dump-call-stack Enable stack trace feature --enable-perf-profiling Enable function performance profiling diff --git a/wamr-compiler/CMakeLists.txt b/wamr-compiler/CMakeLists.txt index c01c4fd0f..513fd0049 100644 --- a/wamr-compiler/CMakeLists.txt +++ b/wamr-compiler/CMakeLists.txt @@ -41,11 +41,13 @@ endif() add_definitions(-DWASM_ENABLE_INTERP=1) add_definitions(-DWASM_ENABLE_WAMR_COMPILER=1) add_definitions(-DWASM_ENABLE_BULK_MEMORY=1) +add_definitions(-DWASM_ENABLE_BULK_MEMORY_OPT=1) add_definitions(-DWASM_DISABLE_HW_BOUND_CHECK=1) add_definitions(-DWASM_ENABLE_SHARED_MEMORY=1) add_definitions(-DWASM_ENABLE_THREAD_MGR=1) add_definitions(-DWASM_ENABLE_TAIL_CALL=1) add_definitions(-DWASM_ENABLE_REF_TYPES=1) +add_definitions(-DWASM_ENABLE_CALL_INDIRECT_OVERLONG=1) add_definitions(-DWASM_ENABLE_BRANCH_HINTS=1) add_definitions(-DWASM_ENABLE_CUSTOM_NAME_SECTION=1) add_definitions(-DWASM_ENABLE_AOT_STACK_FRAME=1) diff --git a/wamr-compiler/main.c b/wamr-compiler/main.c index 2ca9a175d..f0675a351 100644 --- a/wamr-compiler/main.c +++ b/wamr-compiler/main.c @@ -159,6 +159,8 @@ print_help() printf(" llvmir-unopt Unoptimized LLVM IR\n"); printf(" llvmir-opt Optimized LLVM IR\n"); printf(" --disable-bulk-memory Disable the MVP bulk memory feature\n"); + printf(" --enable-bulk-memory-opt Enable bulk memory opt feature\n"); + printf(" --enable-extended-const Enable extended const expr feature\n"); printf(" --enable-multi-thread Enable multi-thread feature, the dependent features bulk-memory and\n"); printf(" thread-mgr will be enabled automatically\n"); printf(" --enable-tail-call Enable the post-MVP tail call feature\n"); @@ -167,6 +169,9 @@ print_help() printf(" and by default it is enabled in them and disabled in other targets\n"); printf(" --disable-ref-types Disable the MVP reference types feature, it will be disabled forcibly if\n"); printf(" GC is enabled\n"); + printf(" --enable-call-indirect-overlong\n"); + printf(" Enable call indirect overlong feature\n"); + printf(" --enable-lime1 Enable Lime1\n"); printf(" --disable-aux-stack-check Disable auxiliary stack overflow/underflow check\n"); printf(" --enable-dump-call-stack Enable stack trace feature\n"); printf(" --call-stack-features=\n"); @@ -423,9 +428,12 @@ main(int argc, char *argv[]) option.enable_simd = true; option.enable_aux_stack_check = true; option.enable_bulk_memory = true; + option.enable_bulk_memory_opt = false; option.enable_ref_types = true; + option.enable_call_indirect_overlong = false; option.enable_gc = false; option.enable_extended_const = false; + option.enable_lime1 = false; aot_call_stack_features_init_default(&option.call_stack_features); /* Process options */ @@ -519,6 +527,9 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--disable-bulk-memory")) { option.enable_bulk_memory = false; } + else if (!strcmp(argv[0], "--enable-bulk-memory-opt")) { + option.enable_bulk_memory_opt = true; + } else if (!strcmp(argv[0], "--enable-multi-thread")) { option.enable_bulk_memory = true; option.enable_thread_mgr = true; @@ -536,12 +547,18 @@ main(int argc, char *argv[]) else if (!strcmp(argv[0], "--disable-ref-types")) { option.enable_ref_types = false; } + else if (!strcmp(argv[0], "--enable-call-indirect-overlong")) { + option.enable_call_indirect_overlong = true; + } else if (!strcmp(argv[0], "--disable-aux-stack-check")) { option.enable_aux_stack_check = false; } else if (!strcmp(argv[0], "--enable-extended-const")) { option.enable_extended_const = true; } + else if (!strcmp(argv[0], "--enable-lime1")) { + option.enable_lime1 = true; + } else if (!strcmp(argv[0], "--enable-dump-call-stack")) { option.aux_stack_frame_type = AOT_STACK_FRAME_TYPE_STANDARD; } @@ -747,6 +764,20 @@ main(int argc, char *argv[]) option.bounds_checks = true; } + if (option.enable_bulk_memory) { + option.enable_bulk_memory_opt = true; + } + + if (option.enable_ref_types) { + option.enable_call_indirect_overlong = true; + } + + if (option.enable_lime1) { + option.enable_call_indirect_overlong = true; + option.enable_bulk_memory_opt = true; + option.enable_extended_const = true; + } + if (!use_dummy_wasm) { wasm_file_name = argv[0];