From a8a5d1e8c8db3b7c64e1921005ceb5a5d47280f4 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 9 Jun 2017 13:31:57 +1000 Subject: 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. --- py/objgenerator.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'py/objgenerator.c') diff --git a/py/objgenerator.c b/py/objgenerator.c index 2e57fdf4b..8cb0e60cc 100644 --- a/py/objgenerator.c +++ b/py/objgenerator.c @@ -54,12 +54,9 @@ STATIC mp_obj_t gen_wrap_call(mp_obj_t self_in, size_t n_args, size_t n_kw, cons mp_obj_fun_bc_t *self_fun = (mp_obj_fun_bc_t*)self->fun; assert(self_fun->base.type == &mp_type_fun_bc); - // get start of bytecode - const byte *ip = self_fun->bytecode; - // bytecode prelude: get state size and exception stack size - mp_uint_t n_state = mp_decode_uint(&ip); - mp_uint_t n_exc_stack = mp_decode_uint(&ip); + size_t n_state = mp_decode_uint_value(self_fun->bytecode); + size_t n_exc_stack = mp_decode_uint_value(mp_decode_uint_skip(self_fun->bytecode)); // allocate the generator object, with room for local stack and exception stack mp_obj_gen_instance_t *o = m_new_obj_var(mp_obj_gen_instance_t, byte, -- cgit v1.2.3