diff options
author | Damien George <damien.p.george@gmail.com> | 2017-03-17 16:38:46 +1100 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2017-03-17 16:50:19 +1100 |
commit | 5640e6dacd39d97adffce8490991c457f457b1cd (patch) | |
tree | c1978abcf974c64cc7aede37404f113ac74faafc /py/bc.c | |
parent | 71a3d6ec3bd02c5bd13334537e1bd146bb643bad (diff) |
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.
Diffstat (limited to 'py/bc.c')
-rw-r--r-- | py/bc.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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; |