py: Provide mp_decode_uint_value to help optimise stack usage.

This has a noticeable improvement on x86-64 and Thumb2 archs, where stack
usage is reduced by 2 machine words in the VM.
pull/2965/head
Damien George 2017-03-17 16:38:46 +11:00
rodzic 71a3d6ec3b
commit 5640e6dacd
4 zmienionych plików z 14 dodań i 9 usunięć

16
py/bc.c
Wyświetl plik

@ -54,6 +54,16 @@ mp_uint_t mp_decode_uint(const byte **ptr) {
return unum;
}
// This function is used to help reduce stack usage at the caller, for the case when
// the caller doesn't need to increase the ptr argument. If ptr is a local variable
// and the caller uses mp_decode_uint(&ptr) instead of this function, then the compiler
// must allocate a slot on the stack for ptr, and this slot cannot be reused for
// anything else in the function because the pointer may have been stored in a global
// and reused later in the function.
mp_uint_t mp_decode_uint_value(const byte *ptr) {
return mp_decode_uint(&ptr);
}
STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, size_t expected, size_t given) {
#if MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE
// generic message, used also for other argument issues
@ -246,11 +256,7 @@ continue2:;
const byte *ip = code_state->ip;
// jump over code info (source file and line-number mapping)
{
const byte *ip2 = ip;
size_t code_info_size = mp_decode_uint(&ip2);
ip += code_info_size;
}
ip += mp_decode_uint_value(ip);
// bytecode prelude: initialise closed over variables
size_t local_num;

Wyświetl plik

@ -91,6 +91,7 @@ typedef struct _mp_code_state_t {
} mp_code_state_t;
mp_uint_t mp_decode_uint(const byte **ptr);
mp_uint_t mp_decode_uint_value(const byte *ptr);
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc);
mp_code_state_t *mp_obj_fun_bc_prepare_codestate(mp_obj_t func, size_t n_args, size_t n_kw, const mp_obj_t *args);

Wyświetl plik

@ -135,8 +135,7 @@ mp_vm_return_kind_t mp_obj_gen_resume(mp_obj_t self_in, mp_obj_t send_value, mp_
break;
case MP_VM_RETURN_EXCEPTION: {
const byte *bc = self->code_state.fun_bc->bytecode;
size_t n_state = mp_decode_uint(&bc);
size_t n_state = mp_decode_uint_value(self->code_state.fun_bc->bytecode);
self->code_state.ip = 0;
*ret_val = self->code_state.state[n_state - 1];
break;

Wyświetl plik

@ -162,8 +162,7 @@ mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp
run_code_state: ;
#endif
// Pointers which are constant for particular invocation of mp_execute_bytecode()
const byte *temp_bc = code_state->fun_bc->bytecode;
size_t n_state = mp_decode_uint(&temp_bc);
size_t n_state = mp_decode_uint_value(code_state->fun_bc->bytecode);
mp_obj_t * /*const*/ fastn = &code_state->state[n_state - 1];
mp_exc_stack_t * /*const*/ exc_stack = (mp_exc_stack_t*)(code_state->state + n_state);