From: Brendan Hansen Date: Sat, 17 Dec 2022 05:24:00 +0000 (-0600) Subject: even faster interpretter? X-Git-Url: https://git.brendanfh.com/?a=commitdiff_plain;h=087c4afcb42dc6da1fe17ae8994ac8b01c0a627a;p=onyx.git even faster interpretter? --- diff --git a/interpreter/include/vm.h b/interpreter/include/vm.h index cb12a09a..4048ab16 100644 --- a/interpreter/include/vm.h +++ b/interpreter/include/vm.h @@ -48,6 +48,32 @@ struct ovm_static_integer_array_t { i32 len; }; +#define OVM_TYPE_NONE 0x00 +#define OVM_TYPE_I8 0x01 +#define OVM_TYPE_I16 0x02 +#define OVM_TYPE_I32 0x03 +#define OVM_TYPE_I64 0x04 +#define OVM_TYPE_F32 0x05 +#define OVM_TYPE_F64 0x06 +#define OVM_TYPE_V128 0x07 + +struct ovm_value_t { + ovm_valtype_t type; + union { + i8 i8; + i16 i16; + i32 i32; + i64 i64; + u8 u8; + u16 u16; + u32 u32; + u64 u64; + f32 f32; + f64 f64; + }; +}; + + // // Represents a program that is runnable by the // VM. It can be constructed incrementally as needed. @@ -124,6 +150,10 @@ struct ovm_state_t { // native functions linked. bh_arr(ovm_external_func_t) external_funcs; + // + // Temporary value used in computations. Should not be used otherwise. + ovm_value_t __tmp_value; + debug_thread_state_t *debug; }; @@ -196,31 +226,6 @@ ovm_value_t ovm_run_code(ovm_engine_t *engine, ovm_state_t *state, ovm_program_t // with an "infinite" value number (register) count. // -#define OVM_TYPE_NONE 0x00 -#define OVM_TYPE_I8 0x01 -#define OVM_TYPE_I16 0x02 -#define OVM_TYPE_I32 0x03 -#define OVM_TYPE_I64 0x04 -#define OVM_TYPE_F32 0x05 -#define OVM_TYPE_F64 0x06 -#define OVM_TYPE_V128 0x07 - -struct ovm_value_t { - ovm_valtype_t type; - union { - i8 i8; - i16 i16; - i32 i32; - i64 i64; - u8 u8; - u16 u16; - u32 u32; - u64 u64; - f32 f32; - f64 f64; - }; -}; - struct ovm_instr_t { u32 full_instr; diff --git a/interpreter/src/vm/vm.c b/interpreter/src/vm/vm.c index dab642a8..46a59379 100644 --- a/interpreter/src/vm/vm.c +++ b/interpreter/src/vm/vm.c @@ -546,7 +546,7 @@ void ovm_state_register_set(ovm_state_t *state, i32 idx, ovm_value_t val) { // // Function calling -static inline void ovm__func_setup_stack_frame(ovm_state_t *state, ovm_func_t *func, i32 result_number) { +static void ovm__func_setup_stack_frame(ovm_state_t *state, ovm_func_t *func, i32 result_number) { // // Push a stack frame ovm_stack_frame_t frame; @@ -572,7 +572,7 @@ static inline void ovm__func_setup_stack_frame(ovm_state_t *state, ovm_func_t *f } } -static inline ovm_stack_frame_t ovm__func_teardown_stack_frame(ovm_state_t *state) { +static ovm_stack_frame_t ovm__func_teardown_stack_frame(ovm_state_t *state) { ovm_stack_frame_t frame = bh_arr_pop(state->stack_frames); bh_arr_fastdeleten(state->numbered_values, frame.value_number_count); @@ -667,7 +667,7 @@ static inline double __ovm_copysign(a, b) double a, b; { return -a; } -static inline void __ovm_trigger_exception(ovm_state_t *state) { +static void __ovm_trigger_exception(ovm_state_t *state) { if (state->debug) { state->debug->state = debug_state_pausing; state->debug->pause_reason = debug_pause_exception; @@ -677,7 +677,7 @@ static inline void __ovm_trigger_exception(ovm_state_t *state) { } } -static inline void __ovm_debug_hook(ovm_engine_t *engine, ovm_state_t *state) { +static void __ovm_debug_hook(ovm_engine_t *engine, ovm_state_t *state) { if (!state->debug) return; if (state->debug->run_count == 0) { @@ -1033,14 +1033,13 @@ OVMI_INSTR_EXEC(ovmi_exec_return) { memcpy(&VAL(0), &state->params[extra_params], func->param_count * sizeof(ovm_value_t)); \ state->pc = func->start_instr; \ } else { \ - ovm_value_t result = {0}; \ ovm_external_func_t external_func = state->external_funcs[func->external_func_idx]; \ - external_func.native_func(external_func.userdata, &state->params[extra_params], &result); \ + external_func.native_func(external_func.userdata, &state->params[extra_params], &state->__tmp_value); \ \ ovm__func_teardown_stack_frame(state); \ \ if (instr->r >= 0) { \ - VAL(instr->r) = result; \ + VAL(instr->r) = state->__tmp_value; \ } \ } @@ -1077,10 +1076,9 @@ OVMI_INSTR_EXEC(ovmi_exec_bri_z) { if (VAL(instr->b).i32 == 0) state->pc += VAL #define OVM_CVT(n1, n2, stype, dtype, otype, ctype) \ OVMI_INSTR_EXEC(ovmi_exec_cvt_##n1##_##n2) { \ - ovm_value_t tmp_val; \ - tmp_val.dtype = (ctype) VAL(instr->a).stype; \ - tmp_val.type = otype; \ - VAL(instr->r) = tmp_val; \ + state->__tmp_value.dtype = (ctype) VAL(instr->a).stype; \ + state->__tmp_value.type = otype; \ + VAL(instr->r) = state->__tmp_value; \ NEXT_OP; \ } diff --git a/shared/lib/linux_x86_64/lib/libovmwasm.so b/shared/lib/linux_x86_64/lib/libovmwasm.so index f0890f0c..be1da68b 100755 Binary files a/shared/lib/linux_x86_64/lib/libovmwasm.so and b/shared/lib/linux_x86_64/lib/libovmwasm.so differ