diff options
| author | Damien George <damien.p.george@gmail.com> | 2014-12-22 12:49:57 +0000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2014-12-22 12:49:57 +0000 |
| commit | 74eb44c392449b54a3f0dcf268ee7448909f7b07 (patch) | |
| tree | 0e00d8c961e08de3304c5c58da3845bbb6ebdf20 /py/bc.h | |
| parent | 81836c28b346c5158e6fc8a79b74a8caa7211dd7 (diff) | |
py: Reduce size of VM exception stack element by 1 machine word.
This optimisation reduces the VM exception stack element (mp_exc_stack_t)
by 1 word, by using bit 1 of a pointer to store whether the opcode was a
FINALLY or WITH opcode. This optimisation was pending, waiting for
maturity of the exception handling code, which has now proven itself.
Saves 1 machine word RAM for each exception (4->3 words per exception).
Increases stmhal code by 4 bytes, and decreases unix x64 code by 32
bytes.
Diffstat (limited to 'py/bc.h')
| -rw-r--r-- | py/bc.h | 13 |
1 files changed, 6 insertions, 7 deletions
@@ -28,12 +28,10 @@ typedef struct _mp_exc_stack { const byte *handler; // bit 0 is saved currently_in_except_block value + // bit 1 is whether the opcode was SETUP_WITH or SETUP_FINALLY mp_obj_t *val_sp; // Saved exception, valid if currently_in_except_block bit is 1 mp_obj_t prev_exc; - // We might only have 2 interesting cases here: SETUP_EXCEPT & SETUP_FINALLY, - // consider storing it in bit 1 of val_sp. TODO: SETUP_WITH? - byte opcode; } mp_exc_stack_t; typedef struct _mp_code_state { @@ -56,7 +54,8 @@ void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t void mp_bytecode_print(const void *descr, mp_uint_t n_total_args, const byte *code, mp_uint_t len); void mp_bytecode_print2(const byte *code, mp_uint_t len); -// Helper macros to access pointer with least significant bit holding a flag -#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)1))) -#define MP_TAGPTR_TAG(x) ((mp_uint_t)(x) & 1) -#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((mp_uint_t)(ptr) | tag)) +// Helper macros to access pointer with least significant bits holding flags +#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)3))) +#define MP_TAGPTR_TAG0(x) ((mp_uint_t)(x) & 1) +#define MP_TAGPTR_TAG1(x) ((mp_uint_t)(x) & 2) +#define MP_TAGPTR_MAKE(ptr, tag) ((void*)((mp_uint_t)(ptr) | (tag))) |
