vm: cut vmentrytable size

This also adds a bit of code everywhere we DISPATCH(), but the net is
+232 bytes free on Feather M0 Adalogger.

Key assumption: All of the offsets in mp_execute_bytecode fit in 16 bits;
it is not clear whether the compiler will verify this assumption (e.g.,
by warning that a constant will be truncated)
This commit is contained in:
Jeff Epler 2021-03-05 16:47:00 -06:00
parent d2056a46ee
commit 28638df589
2 changed files with 81 additions and 79 deletions

View File

@ -132,7 +132,7 @@ mp_vm_return_kind_t PLACE_IN_ITCM(mp_execute_bytecode)(mp_code_state_t *code_sta
#define DISPATCH() do { \
TRACE(ip); \
MARK_EXC_IP_GLOBAL(); \
goto *entry_table[*ip++]; \
goto *(void*)((char*)&&entry_MP_BC_LOAD_CONST_FALSE + entry_table[*ip++]); \
} while (0)
#define DISPATCH_WITH_PEND_EXC_CHECK() goto pending_exception_check
#define ENTRY(op) entry_##op

View File

@ -31,88 +31,90 @@
#include "supervisor/linker.h"
static const void *const PLACE_IN_DTCM_DATA(entry_table[256]) = {
[0 ... 255] = &&entry_default,
[MP_BC_LOAD_CONST_FALSE] = &&entry_MP_BC_LOAD_CONST_FALSE,
[MP_BC_LOAD_CONST_NONE] = &&entry_MP_BC_LOAD_CONST_NONE,
[MP_BC_LOAD_CONST_TRUE] = &&entry_MP_BC_LOAD_CONST_TRUE,
[MP_BC_LOAD_CONST_SMALL_INT] = &&entry_MP_BC_LOAD_CONST_SMALL_INT,
[MP_BC_LOAD_CONST_STRING] = &&entry_MP_BC_LOAD_CONST_STRING,
[MP_BC_LOAD_CONST_OBJ] = &&entry_MP_BC_LOAD_CONST_OBJ,
[MP_BC_LOAD_NULL] = &&entry_MP_BC_LOAD_NULL,
[MP_BC_LOAD_FAST_N] = &&entry_MP_BC_LOAD_FAST_N,
[MP_BC_LOAD_DEREF] = &&entry_MP_BC_LOAD_DEREF,
[MP_BC_LOAD_NAME] = &&entry_MP_BC_LOAD_NAME,
[MP_BC_LOAD_GLOBAL] = &&entry_MP_BC_LOAD_GLOBAL,
[MP_BC_LOAD_ATTR] = &&entry_MP_BC_LOAD_ATTR,
[MP_BC_LOAD_METHOD] = &&entry_MP_BC_LOAD_METHOD,
[MP_BC_LOAD_SUPER_METHOD] = &&entry_MP_BC_LOAD_SUPER_METHOD,
[MP_BC_LOAD_BUILD_CLASS] = &&entry_MP_BC_LOAD_BUILD_CLASS,
[MP_BC_LOAD_SUBSCR] = &&entry_MP_BC_LOAD_SUBSCR,
[MP_BC_STORE_FAST_N] = &&entry_MP_BC_STORE_FAST_N,
[MP_BC_STORE_DEREF] = &&entry_MP_BC_STORE_DEREF,
[MP_BC_STORE_NAME] = &&entry_MP_BC_STORE_NAME,
[MP_BC_STORE_GLOBAL] = &&entry_MP_BC_STORE_GLOBAL,
[MP_BC_STORE_ATTR] = &&entry_MP_BC_STORE_ATTR,
[MP_BC_STORE_SUBSCR] = &&entry_MP_BC_STORE_SUBSCR,
[MP_BC_DELETE_FAST] = &&entry_MP_BC_DELETE_FAST,
[MP_BC_DELETE_DEREF] = &&entry_MP_BC_DELETE_DEREF,
[MP_BC_DELETE_NAME] = &&entry_MP_BC_DELETE_NAME,
[MP_BC_DELETE_GLOBAL] = &&entry_MP_BC_DELETE_GLOBAL,
[MP_BC_DUP_TOP] = &&entry_MP_BC_DUP_TOP,
[MP_BC_DUP_TOP_TWO] = &&entry_MP_BC_DUP_TOP_TWO,
[MP_BC_POP_TOP] = &&entry_MP_BC_POP_TOP,
[MP_BC_ROT_TWO] = &&entry_MP_BC_ROT_TWO,
[MP_BC_ROT_THREE] = &&entry_MP_BC_ROT_THREE,
[MP_BC_JUMP] = &&entry_MP_BC_JUMP,
[MP_BC_POP_JUMP_IF_TRUE] = &&entry_MP_BC_POP_JUMP_IF_TRUE,
[MP_BC_POP_JUMP_IF_FALSE] = &&entry_MP_BC_POP_JUMP_IF_FALSE,
[MP_BC_JUMP_IF_TRUE_OR_POP] = &&entry_MP_BC_JUMP_IF_TRUE_OR_POP,
[MP_BC_JUMP_IF_FALSE_OR_POP] = &&entry_MP_BC_JUMP_IF_FALSE_OR_POP,
[MP_BC_SETUP_WITH] = &&entry_MP_BC_SETUP_WITH,
[MP_BC_WITH_CLEANUP] = &&entry_MP_BC_WITH_CLEANUP,
[MP_BC_UNWIND_JUMP] = &&entry_MP_BC_UNWIND_JUMP,
[MP_BC_SETUP_EXCEPT] = &&entry_MP_BC_SETUP_EXCEPT,
[MP_BC_SETUP_FINALLY] = &&entry_MP_BC_SETUP_FINALLY,
[MP_BC_END_FINALLY] = &&entry_MP_BC_END_FINALLY,
[MP_BC_GET_ITER] = &&entry_MP_BC_GET_ITER,
[MP_BC_GET_ITER_STACK] = &&entry_MP_BC_GET_ITER_STACK,
[MP_BC_FOR_ITER] = &&entry_MP_BC_FOR_ITER,
[MP_BC_POP_BLOCK] = &&entry_MP_BC_POP_BLOCK,
[MP_BC_POP_EXCEPT] = &&entry_MP_BC_POP_EXCEPT,
[MP_BC_BUILD_TUPLE] = &&entry_MP_BC_BUILD_TUPLE,
[MP_BC_BUILD_LIST] = &&entry_MP_BC_BUILD_LIST,
[MP_BC_BUILD_MAP] = &&entry_MP_BC_BUILD_MAP,
[MP_BC_STORE_MAP] = &&entry_MP_BC_STORE_MAP,
#define COMPUTE_ENTRY(x) ((char*)(x) - (char*)&&entry_MP_BC_LOAD_CONST_FALSE)
static int16_t const PLACE_IN_DTCM_DATA(entry_table[256]) = {
[0 ... 255] = COMPUTE_ENTRY(&&entry_default),
[MP_BC_LOAD_CONST_FALSE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_FALSE),
[MP_BC_LOAD_CONST_NONE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_NONE),
[MP_BC_LOAD_CONST_TRUE] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_TRUE),
[MP_BC_LOAD_CONST_SMALL_INT] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_SMALL_INT),
[MP_BC_LOAD_CONST_STRING] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_STRING),
[MP_BC_LOAD_CONST_OBJ] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_OBJ),
[MP_BC_LOAD_NULL] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_NULL),
[MP_BC_LOAD_FAST_N] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_FAST_N),
[MP_BC_LOAD_DEREF] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_DEREF),
[MP_BC_LOAD_NAME] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_NAME),
[MP_BC_LOAD_GLOBAL] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_GLOBAL),
[MP_BC_LOAD_ATTR] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_ATTR),
[MP_BC_LOAD_METHOD] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_METHOD),
[MP_BC_LOAD_SUPER_METHOD] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_SUPER_METHOD),
[MP_BC_LOAD_BUILD_CLASS] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_BUILD_CLASS),
[MP_BC_LOAD_SUBSCR] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_SUBSCR),
[MP_BC_STORE_FAST_N] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_FAST_N),
[MP_BC_STORE_DEREF] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_DEREF),
[MP_BC_STORE_NAME] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_NAME),
[MP_BC_STORE_GLOBAL] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_GLOBAL),
[MP_BC_STORE_ATTR] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_ATTR),
[MP_BC_STORE_SUBSCR] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_SUBSCR),
[MP_BC_DELETE_FAST] = COMPUTE_ENTRY(&&entry_MP_BC_DELETE_FAST),
[MP_BC_DELETE_DEREF] = COMPUTE_ENTRY(&&entry_MP_BC_DELETE_DEREF),
[MP_BC_DELETE_NAME] = COMPUTE_ENTRY(&&entry_MP_BC_DELETE_NAME),
[MP_BC_DELETE_GLOBAL] = COMPUTE_ENTRY(&&entry_MP_BC_DELETE_GLOBAL),
[MP_BC_DUP_TOP] = COMPUTE_ENTRY(&&entry_MP_BC_DUP_TOP),
[MP_BC_DUP_TOP_TWO] = COMPUTE_ENTRY(&&entry_MP_BC_DUP_TOP_TWO),
[MP_BC_POP_TOP] = COMPUTE_ENTRY(&&entry_MP_BC_POP_TOP),
[MP_BC_ROT_TWO] = COMPUTE_ENTRY(&&entry_MP_BC_ROT_TWO),
[MP_BC_ROT_THREE] = COMPUTE_ENTRY(&&entry_MP_BC_ROT_THREE),
[MP_BC_JUMP] = COMPUTE_ENTRY(&&entry_MP_BC_JUMP),
[MP_BC_POP_JUMP_IF_TRUE] = COMPUTE_ENTRY(&&entry_MP_BC_POP_JUMP_IF_TRUE),
[MP_BC_POP_JUMP_IF_FALSE] = COMPUTE_ENTRY(&&entry_MP_BC_POP_JUMP_IF_FALSE),
[MP_BC_JUMP_IF_TRUE_OR_POP] = COMPUTE_ENTRY(&&entry_MP_BC_JUMP_IF_TRUE_OR_POP),
[MP_BC_JUMP_IF_FALSE_OR_POP] = COMPUTE_ENTRY(&&entry_MP_BC_JUMP_IF_FALSE_OR_POP),
[MP_BC_SETUP_WITH] = COMPUTE_ENTRY(&&entry_MP_BC_SETUP_WITH),
[MP_BC_WITH_CLEANUP] = COMPUTE_ENTRY(&&entry_MP_BC_WITH_CLEANUP),
[MP_BC_UNWIND_JUMP] = COMPUTE_ENTRY(&&entry_MP_BC_UNWIND_JUMP),
[MP_BC_SETUP_EXCEPT] = COMPUTE_ENTRY(&&entry_MP_BC_SETUP_EXCEPT),
[MP_BC_SETUP_FINALLY] = COMPUTE_ENTRY(&&entry_MP_BC_SETUP_FINALLY),
[MP_BC_END_FINALLY] = COMPUTE_ENTRY(&&entry_MP_BC_END_FINALLY),
[MP_BC_GET_ITER] = COMPUTE_ENTRY(&&entry_MP_BC_GET_ITER),
[MP_BC_GET_ITER_STACK] = COMPUTE_ENTRY(&&entry_MP_BC_GET_ITER_STACK),
[MP_BC_FOR_ITER] = COMPUTE_ENTRY(&&entry_MP_BC_FOR_ITER),
[MP_BC_POP_BLOCK] = COMPUTE_ENTRY(&&entry_MP_BC_POP_BLOCK),
[MP_BC_POP_EXCEPT] = COMPUTE_ENTRY(&&entry_MP_BC_POP_EXCEPT),
[MP_BC_BUILD_TUPLE] = COMPUTE_ENTRY(&&entry_MP_BC_BUILD_TUPLE),
[MP_BC_BUILD_LIST] = COMPUTE_ENTRY(&&entry_MP_BC_BUILD_LIST),
[MP_BC_BUILD_MAP] = COMPUTE_ENTRY(&&entry_MP_BC_BUILD_MAP),
[MP_BC_STORE_MAP] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_MAP),
#if MICROPY_PY_BUILTINS_SET
[MP_BC_BUILD_SET] = &&entry_MP_BC_BUILD_SET,
[MP_BC_BUILD_SET] = COMPUTE_ENTRY(&&entry_MP_BC_BUILD_SET),
#endif
#if MICROPY_PY_BUILTINS_SLICE
[MP_BC_BUILD_SLICE] = &&entry_MP_BC_BUILD_SLICE,
[MP_BC_BUILD_SLICE] = COMPUTE_ENTRY(&&entry_MP_BC_BUILD_SLICE),
#endif
[MP_BC_STORE_COMP] = &&entry_MP_BC_STORE_COMP,
[MP_BC_UNPACK_SEQUENCE] = &&entry_MP_BC_UNPACK_SEQUENCE,
[MP_BC_UNPACK_EX] = &&entry_MP_BC_UNPACK_EX,
[MP_BC_MAKE_FUNCTION] = &&entry_MP_BC_MAKE_FUNCTION,
[MP_BC_MAKE_FUNCTION_DEFARGS] = &&entry_MP_BC_MAKE_FUNCTION_DEFARGS,
[MP_BC_MAKE_CLOSURE] = &&entry_MP_BC_MAKE_CLOSURE,
[MP_BC_MAKE_CLOSURE_DEFARGS] = &&entry_MP_BC_MAKE_CLOSURE_DEFARGS,
[MP_BC_CALL_FUNCTION] = &&entry_MP_BC_CALL_FUNCTION,
[MP_BC_CALL_FUNCTION_VAR_KW] = &&entry_MP_BC_CALL_FUNCTION_VAR_KW,
[MP_BC_CALL_METHOD] = &&entry_MP_BC_CALL_METHOD,
[MP_BC_CALL_METHOD_VAR_KW] = &&entry_MP_BC_CALL_METHOD_VAR_KW,
[MP_BC_RETURN_VALUE] = &&entry_MP_BC_RETURN_VALUE,
[MP_BC_RAISE_VARARGS] = &&entry_MP_BC_RAISE_VARARGS,
[MP_BC_YIELD_VALUE] = &&entry_MP_BC_YIELD_VALUE,
[MP_BC_YIELD_FROM] = &&entry_MP_BC_YIELD_FROM,
[MP_BC_IMPORT_NAME] = &&entry_MP_BC_IMPORT_NAME,
[MP_BC_IMPORT_FROM] = &&entry_MP_BC_IMPORT_FROM,
[MP_BC_IMPORT_STAR] = &&entry_MP_BC_IMPORT_STAR,
[MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63] = &&entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI,
[MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15] = &&entry_MP_BC_LOAD_FAST_MULTI,
[MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15] = &&entry_MP_BC_STORE_FAST_MULTI,
[MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NUM_BYTECODE - 1] = &&entry_MP_BC_UNARY_OP_MULTI,
[MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + MP_BINARY_OP_NUM_BYTECODE - 1] = &&entry_MP_BC_BINARY_OP_MULTI,
[MP_BC_STORE_COMP] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_COMP),
[MP_BC_UNPACK_SEQUENCE] = COMPUTE_ENTRY(&&entry_MP_BC_UNPACK_SEQUENCE),
[MP_BC_UNPACK_EX] = COMPUTE_ENTRY(&&entry_MP_BC_UNPACK_EX),
[MP_BC_MAKE_FUNCTION] = COMPUTE_ENTRY(&&entry_MP_BC_MAKE_FUNCTION),
[MP_BC_MAKE_FUNCTION_DEFARGS] = COMPUTE_ENTRY(&&entry_MP_BC_MAKE_FUNCTION_DEFARGS),
[MP_BC_MAKE_CLOSURE] = COMPUTE_ENTRY(&&entry_MP_BC_MAKE_CLOSURE),
[MP_BC_MAKE_CLOSURE_DEFARGS] = COMPUTE_ENTRY(&&entry_MP_BC_MAKE_CLOSURE_DEFARGS),
[MP_BC_CALL_FUNCTION] = COMPUTE_ENTRY(&&entry_MP_BC_CALL_FUNCTION),
[MP_BC_CALL_FUNCTION_VAR_KW] = COMPUTE_ENTRY(&&entry_MP_BC_CALL_FUNCTION_VAR_KW),
[MP_BC_CALL_METHOD] = COMPUTE_ENTRY(&&entry_MP_BC_CALL_METHOD),
[MP_BC_CALL_METHOD_VAR_KW] = COMPUTE_ENTRY(&&entry_MP_BC_CALL_METHOD_VAR_KW),
[MP_BC_RETURN_VALUE] = COMPUTE_ENTRY(&&entry_MP_BC_RETURN_VALUE),
[MP_BC_RAISE_VARARGS] = COMPUTE_ENTRY(&&entry_MP_BC_RAISE_VARARGS),
[MP_BC_YIELD_VALUE] = COMPUTE_ENTRY(&&entry_MP_BC_YIELD_VALUE),
[MP_BC_YIELD_FROM] = COMPUTE_ENTRY(&&entry_MP_BC_YIELD_FROM),
[MP_BC_IMPORT_NAME] = COMPUTE_ENTRY(&&entry_MP_BC_IMPORT_NAME),
[MP_BC_IMPORT_FROM] = COMPUTE_ENTRY(&&entry_MP_BC_IMPORT_FROM),
[MP_BC_IMPORT_STAR] = COMPUTE_ENTRY(&&entry_MP_BC_IMPORT_STAR),
[MP_BC_LOAD_CONST_SMALL_INT_MULTI ... MP_BC_LOAD_CONST_SMALL_INT_MULTI + 63] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_CONST_SMALL_INT_MULTI),
[MP_BC_LOAD_FAST_MULTI ... MP_BC_LOAD_FAST_MULTI + 15] = COMPUTE_ENTRY(&&entry_MP_BC_LOAD_FAST_MULTI),
[MP_BC_STORE_FAST_MULTI ... MP_BC_STORE_FAST_MULTI + 15] = COMPUTE_ENTRY(&&entry_MP_BC_STORE_FAST_MULTI),
[MP_BC_UNARY_OP_MULTI ... MP_BC_UNARY_OP_MULTI + MP_UNARY_OP_NUM_BYTECODE - 1] = COMPUTE_ENTRY(&&entry_MP_BC_UNARY_OP_MULTI),
[MP_BC_BINARY_OP_MULTI ... MP_BC_BINARY_OP_MULTI + MP_BINARY_OP_NUM_BYTECODE - 1] = COMPUTE_ENTRY(&&entry_MP_BC_BINARY_OP_MULTI),
};
#ifdef __clang__