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/vm.c | |
parent | 4352b944d2fe0919b34774bec1a6ea440649a1df (diff) | |
download | micropython-a8a5d1e8c8db3b7c64e1921005ceb5a5d47280f4.tar.gz micropython-a8a5d1e8c8db3b7c64e1921005ceb5a5d47280f4.zip |
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/vm.c')
-rw-r--r-- | py/vm.c | 13 |
1 files changed, 8 insertions, 5 deletions
@@ -1363,22 +1363,25 @@ unwind_loop: // TODO need a better way of not adding traceback to constant objects (right now, just GeneratorExit_obj and MemoryError_obj) if (nlr.ret_val != &mp_const_GeneratorExit_obj && nlr.ret_val != &mp_const_MemoryError_obj) { const byte *ip = code_state->fun_bc->bytecode; - mp_decode_uint(&ip); // skip n_state - mp_decode_uint(&ip); // skip n_exc_stack + ip = mp_decode_uint_skip(ip); // skip n_state + ip = mp_decode_uint_skip(ip); // skip n_exc_stack ip++; // skip scope_params ip++; // skip n_pos_args ip++; // skip n_kwonly_args ip++; // skip n_def_pos_args size_t bc = code_state->ip - ip; - size_t code_info_size = mp_decode_uint(&ip); + size_t code_info_size = mp_decode_uint_value(ip); + ip = mp_decode_uint_skip(ip); // skip code_info_size bc -= code_info_size; #if MICROPY_PERSISTENT_CODE qstr block_name = ip[0] | (ip[1] << 8); qstr source_file = ip[2] | (ip[3] << 8); ip += 4; #else - qstr block_name = mp_decode_uint(&ip); - qstr source_file = mp_decode_uint(&ip); + qstr block_name = mp_decode_uint_value(ip); + ip = mp_decode_uint_skip(ip); + qstr source_file = mp_decode_uint_value(ip); + ip = mp_decode_uint_skip(ip); #endif size_t source_line = 1; size_t c; |