|
202 | 202 | // MP_VM_RETURN_YIELD, ip, sp valid, yielded value in *sp
|
203 | 203 | // MP_VM_RETURN_EXCEPTION, exception in state[0]
|
204 | 204 | mp_vm_return_kind_t MICROPY_WRAP_MP_EXECUTE_BYTECODE(mp_execute_bytecode)(mp_code_state_t *code_state, volatile mp_obj_t inject_exc) {
|
| 205 | + |
205 | 206 | #define SELECTIVE_EXC_IP (0)
|
| 207 | +// When disabled, code_state->ip is updated unconditionally during op |
| 208 | +// dispatch, and this is subsequently used in the exception handler |
| 209 | +// (either NLR jump or direct RAISE). This is good for code size because it |
| 210 | +// happens in a single place but is more work than necessary, as many opcodes |
| 211 | +// cannot raise. Enabling SELECTIVE_EXC_IP means that code_state->ip |
| 212 | +// is "selectively" updated only during handling of opcodes that might raise. |
| 213 | +// This costs about 360 bytes on PYBV11 for a 1-3% performance gain (e.g. 3% |
| 214 | +// in bm_fft.py). On rp2040, there is zero code size diff for a 0-1% gain. |
| 215 | +// (Both with computed goto enabled). |
206 | 216 | #if SELECTIVE_EXC_IP
|
207 |
| -#define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } /* stores ip 1 byte past last opcode */ |
| 217 | +// Note: Because ip has already been advanced by one byte in the dispatch, the |
| 218 | +// value of ip here is one byte past the last opcode. |
| 219 | +#define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } |
| 220 | +// No need to update in dispatch. |
208 | 221 | #define MARK_EXC_IP_GLOBAL()
|
209 | 222 | #else
|
210 | 223 | #define MARK_EXC_IP_SELECTIVE()
|
211 |
| -#define MARK_EXC_IP_GLOBAL() { code_state->ip = ip; } /* stores ip pointing to last opcode */ |
| 224 | +// Immediately before dispatch, save the current ip, which will be the opcode |
| 225 | +// about to be dispatched. |
| 226 | +#define MARK_EXC_IP_GLOBAL() { code_state->ip = ip; } |
212 | 227 | #endif
|
| 228 | + |
213 | 229 | #if MICROPY_OPT_COMPUTED_GOTO
|
214 | 230 | #include "py/vmentrytable.h"
|
215 | 231 | #define DISPATCH() do { \
|
|
0 commit comments