diff options
| author | Damien George <damien.p.george@gmail.com> | 2017-06-09 13:31:57 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2017-06-09 13:36:33 +1000 |
| commit | a8a5d1e8c8db3b7c64e1921005ceb5a5d47280f4 (patch) | |
| tree | 8b6ba37193f4c3eaaa9a1115d2be6d90055ce565 /py/bc.c | |
| parent | 4352b944d2fe0919b34774bec1a6ea440649a1df (diff) | |
py: Provide mp_decode_uint_skip() to help reduce stack usage.
Taking the address of a local variable leads to increased stack usage, so
the mp_decode_uint_skip() function is added to reduce the need for taking
addresses. The changes in this patch reduce stack usage of a Python call
by 8 bytes on ARM Thumb, by 16 bytes on non-windowing Xtensa archs, and by
16 bytes on x86-64. Code size is also slightly reduced on most archs by
around 32 bytes.
Diffstat (limited to 'py/bc.c')
| -rw-r--r-- | py/bc.c | 10 |
1 files changed, 9 insertions, 1 deletions
@@ -64,6 +64,14 @@ mp_uint_t mp_decode_uint_value(const byte *ptr) { return mp_decode_uint(&ptr); } +// This function is used to help reduce stack usage at the caller, for the case when +// the caller doesn't need the actual value and just wants to skip over it. +const byte *mp_decode_uint_skip(const byte *ptr) { + while ((*ptr++) & 0x80) { + } + return 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 @@ -115,7 +123,7 @@ void mp_setup_code_state(mp_code_state_t *code_state, size_t n_args, size_t n_kw // get params size_t n_state = mp_decode_uint(&code_state->ip); - mp_decode_uint(&code_state->ip); // skip n_exc_stack + code_state->ip = mp_decode_uint_skip(code_state->ip); // skip n_exc_stack size_t scope_flags = *code_state->ip++; size_t n_pos_args = *code_state->ip++; size_t n_kwonly_args = *code_state->ip++; |
