Import WAMR Fast JIT (#1343)
Import WAMR Fast JIT which is a lightweight JIT with quick startup, small footprint, relatively good performance (~40% to ~50% of LLVM JIT) and good portability. Platforms supported: Linux, MacOS and Linux SGX. Arch supported: x86-64.
This commit is contained in:
@ -56,7 +56,7 @@ wasm_load(uint8 *buf, uint32 size, char *error_buf, uint32 error_buf_size)
|
||||
|
||||
WASMModule *
|
||||
wasm_load_from_sections(WASMSection *section_list, char *error_buf,
|
||||
uint32_t error_buf_size)
|
||||
uint32 error_buf_size)
|
||||
{
|
||||
return wasm_loader_load_from_sections(section_list, error_buf,
|
||||
error_buf_size);
|
||||
@ -349,6 +349,24 @@ memory_instantiate(WASMModuleInstance *module_inst, uint32 num_bytes_per_page,
|
||||
}
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
if (memory_data_size > 0) {
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
memory->mem_bound_check_1byte = memory_data_size - 1;
|
||||
memory->mem_bound_check_2bytes = memory_data_size - 2;
|
||||
memory->mem_bound_check_4bytes = memory_data_size - 4;
|
||||
memory->mem_bound_check_8bytes = memory_data_size - 8;
|
||||
memory->mem_bound_check_16bytes = memory_data_size - 16;
|
||||
#else
|
||||
memory->mem_bound_check_1byte = (uint32)memory_data_size - 1;
|
||||
memory->mem_bound_check_2bytes = (uint32)memory_data_size - 2;
|
||||
memory->mem_bound_check_4bytes = (uint32)memory_data_size - 4;
|
||||
memory->mem_bound_check_8bytes = (uint32)memory_data_size - 8;
|
||||
memory->mem_bound_check_16bytes = (uint32)memory_data_size - 16;
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_SHARED_MEMORY != 0
|
||||
if (0 != os_mutex_init(&memory->mem_lock)) {
|
||||
set_error_buf(error_buf, error_buf_size, "init mutex failed");
|
||||
@ -693,6 +711,10 @@ functions_instantiate(const WASMModule *module, WASMModuleInstance *module_inst,
|
||||
function++;
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
module_inst->fast_jit_func_ptrs = module->fast_jit_func_ptrs;
|
||||
#endif
|
||||
|
||||
bh_assert((uint32)(function - functions) == function_count);
|
||||
(void)module_inst;
|
||||
return functions;
|
||||
@ -2470,6 +2492,22 @@ wasm_enlarge_memory(WASMModuleInstance *module, uint32 inc_page_count)
|
||||
memory->memory_data_end =
|
||||
memory->memory_data + memory->num_bytes_per_page * total_page_count;
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
#if UINTPTR_MAX == UINT64_MAX
|
||||
memory->mem_bound_check_1byte = total_size - 1;
|
||||
memory->mem_bound_check_2bytes = total_size - 2;
|
||||
memory->mem_bound_check_4bytes = total_size - 4;
|
||||
memory->mem_bound_check_8bytes = total_size - 8;
|
||||
memory->mem_bound_check_16bytes = total_size - 16;
|
||||
#else
|
||||
memory->mem_bound_check_1byte = (uint32)total_size - 1;
|
||||
memory->mem_bound_check_2bytes = (uint32)total_size - 2;
|
||||
memory->mem_bound_check_4bytes = (uint32)total_size - 4;
|
||||
memory->mem_bound_check_8bytes = (uint32)total_size - 8;
|
||||
memory->mem_bound_check_16bytes = (uint32)total_size - 16;
|
||||
#endif
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
@ -2564,14 +2602,14 @@ wasm_enlarge_table(WASMModuleInstance *module_inst, uint32 table_idx,
|
||||
}
|
||||
#endif /* WASM_ENABLE_REF_TYPES != 0 */
|
||||
|
||||
bool
|
||||
wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
|
||||
uint32_t element_indices, uint32_t argc, uint32_t argv[])
|
||||
static bool
|
||||
call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
|
||||
uint32 argc, uint32 argv[], bool check_type_idx, uint32 type_idx)
|
||||
{
|
||||
WASMModuleInstance *module_inst = NULL;
|
||||
WASMTableInstance *table_inst = NULL;
|
||||
uint32_t function_indices = 0;
|
||||
WASMFunctionInstance *function_inst = NULL;
|
||||
uint32 func_idx = 0;
|
||||
WASMFunctionInstance *func_inst = NULL;
|
||||
|
||||
module_inst = (WASMModuleInstance *)exec_env->module_inst;
|
||||
bh_assert(module_inst);
|
||||
@ -2582,7 +2620,7 @@ wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
if (element_indices >= table_inst->cur_size) {
|
||||
if (elem_idx >= table_inst->cur_size) {
|
||||
wasm_set_exception(module_inst, "undefined element");
|
||||
goto got_exception;
|
||||
}
|
||||
@ -2591,8 +2629,8 @@ wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
|
||||
* please be aware that table_inst->base_addr may point
|
||||
* to another module's table
|
||||
**/
|
||||
function_indices = ((uint32_t *)table_inst->base_addr)[element_indices];
|
||||
if (function_indices == NULL_REF) {
|
||||
func_idx = ((uint32 *)table_inst->base_addr)[elem_idx];
|
||||
if (func_idx == NULL_REF) {
|
||||
wasm_set_exception(module_inst, "uninitialized element");
|
||||
goto got_exception;
|
||||
}
|
||||
@ -2600,14 +2638,29 @@ wasm_call_indirect(WASMExecEnv *exec_env, uint32_t tbl_idx,
|
||||
/**
|
||||
* we insist to call functions owned by the module itself
|
||||
**/
|
||||
if (function_indices >= module_inst->function_count) {
|
||||
if (func_idx >= module_inst->function_count) {
|
||||
wasm_set_exception(module_inst, "unknown function");
|
||||
goto got_exception;
|
||||
}
|
||||
|
||||
function_inst = module_inst->functions + function_indices;
|
||||
func_inst = module_inst->functions + func_idx;
|
||||
|
||||
interp_call_wasm(module_inst, exec_env, function_inst, argc, argv);
|
||||
if (check_type_idx) {
|
||||
WASMType *cur_type = module_inst->module->types[type_idx];
|
||||
WASMType *cur_func_type;
|
||||
|
||||
if (func_inst->is_import_func)
|
||||
cur_func_type = func_inst->u.func_import->func_type;
|
||||
else
|
||||
cur_func_type = func_inst->u.func->func_type;
|
||||
|
||||
if (!wasm_type_equal(cur_type, cur_func_type)) {
|
||||
wasm_set_exception(module_inst, "indirect call type mismatch");
|
||||
goto got_exception;
|
||||
}
|
||||
}
|
||||
|
||||
interp_call_wasm(module_inst, exec_env, func_inst, argc, argv);
|
||||
|
||||
(void)clear_wasi_proc_exit_exception(module_inst);
|
||||
return !wasm_get_exception(module_inst) ? true : false;
|
||||
@ -2616,6 +2669,23 @@ got_exception:
|
||||
return false;
|
||||
}
|
||||
|
||||
bool
|
||||
wasm_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
|
||||
uint32 argc, uint32 argv[])
|
||||
{
|
||||
return call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, false, 0);
|
||||
}
|
||||
|
||||
#if WASM_ENABLE_FAST_JIT != 0
|
||||
bool
|
||||
jit_call_indirect(WASMExecEnv *exec_env, uint32 tbl_idx, uint32 elem_idx,
|
||||
uint32 type_idx, uint32 argc, uint32 argv[])
|
||||
{
|
||||
return call_indirect(exec_env, tbl_idx, elem_idx, argc, argv, true,
|
||||
type_idx);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if WASM_ENABLE_THREAD_MGR != 0
|
||||
bool
|
||||
wasm_set_aux_stack(WASMExecEnv *exec_env, uint32 start_offset, uint32 size)
|
||||
|
||||
Reference in New Issue
Block a user