py: Add wrapper macros so hot VM functions can go in fast code location.
For example, on esp32 they can go in iRAM to improve performance. Signed-off-by: Damien George <damien@micropython.org>
This commit is contained in:
parent
eea6cd85b3
commit
8412568e7b
2
py/map.c
2
py/map.c
@ -153,7 +153,7 @@ STATIC void mp_map_rehash(mp_map_t *map) {
|
||||
// - returns slot, with key non-null and value=MP_OBJ_NULL if it was added
|
||||
// MP_MAP_LOOKUP_REMOVE_IF_FOUND behaviour:
|
||||
// - returns NULL if not found, else the slot if was found in with key null and value non-null
|
||||
mp_map_elem_t *mp_map_lookup(mp_map_t *map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind) {
|
||||
mp_map_elem_t *MICROPY_WRAP_MP_MAP_LOOKUP(mp_map_lookup)(mp_map_t * map, mp_obj_t index, mp_map_lookup_kind_t lookup_kind) {
|
||||
// If the map is a fixed array then we must only be called for a lookup
|
||||
assert(!map->is_fixed || lookup_kind == MP_MAP_LOOKUP);
|
||||
|
||||
|
@ -1594,6 +1594,30 @@ typedef double mp_float_t;
|
||||
/*****************************************************************************/
|
||||
/* Hooks for a port to wrap functions with attributes */
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_BINARY_OP
|
||||
#define MICROPY_WRAP_MP_BINARY_OP(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_EXECUTE_BYTECODE
|
||||
#define MICROPY_WRAP_MP_EXECUTE_BYTECODE(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_LOAD_GLOBAL
|
||||
#define MICROPY_WRAP_MP_LOAD_GLOBAL(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_LOAD_NAME
|
||||
#define MICROPY_WRAP_MP_LOAD_NAME(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_MAP_LOOKUP
|
||||
#define MICROPY_WRAP_MP_MAP_LOOKUP(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_OBJ_GET_TYPE
|
||||
#define MICROPY_WRAP_MP_OBJ_GET_TYPE(f) f
|
||||
#endif
|
||||
|
||||
#ifndef MICROPY_WRAP_MP_SCHED_EXCEPTION
|
||||
#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) f
|
||||
#endif
|
||||
|
2
py/obj.c
2
py/obj.c
@ -37,7 +37,7 @@
|
||||
#include "py/stackctrl.h"
|
||||
#include "py/stream.h" // for mp_obj_print
|
||||
|
||||
const mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in) {
|
||||
const mp_obj_type_t *MICROPY_WRAP_MP_OBJ_GET_TYPE(mp_obj_get_type)(mp_const_obj_t o_in) {
|
||||
#if MICROPY_OBJ_IMMEDIATE_OBJS && MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_A
|
||||
|
||||
if (mp_obj_is_obj(o_in)) {
|
||||
|
@ -157,7 +157,7 @@ void mp_deinit(void) {
|
||||
#endif
|
||||
}
|
||||
|
||||
mp_obj_t mp_load_name(qstr qst) {
|
||||
mp_obj_t MICROPY_WRAP_MP_LOAD_NAME(mp_load_name)(qstr qst) {
|
||||
// logic: search locals, globals, builtins
|
||||
DEBUG_OP_printf("load name %s\n", qstr_str(qst));
|
||||
// If we're at the outer scope (locals == globals), dispatch to load_global right away
|
||||
@ -170,7 +170,7 @@ mp_obj_t mp_load_name(qstr qst) {
|
||||
return mp_load_global(qst);
|
||||
}
|
||||
|
||||
mp_obj_t mp_load_global(qstr qst) {
|
||||
mp_obj_t MICROPY_WRAP_MP_LOAD_GLOBAL(mp_load_global)(qstr qst) {
|
||||
// logic: search globals, builtins
|
||||
DEBUG_OP_printf("load global %s\n", qstr_str(qst));
|
||||
mp_map_elem_t *elem = mp_map_lookup(&mp_globals_get()->map, MP_OBJ_NEW_QSTR(qst), MP_MAP_LOOKUP);
|
||||
@ -311,7 +311,7 @@ mp_obj_t mp_unary_op(mp_unary_op_t op, mp_obj_t arg) {
|
||||
}
|
||||
}
|
||||
|
||||
mp_obj_t mp_binary_op(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
mp_obj_t MICROPY_WRAP_MP_BINARY_OP(mp_binary_op)(mp_binary_op_t op, mp_obj_t lhs, mp_obj_t rhs) {
|
||||
DEBUG_OP_printf("binary " UINT_FMT " %q %p %p\n", op, mp_binary_op_method_name[op], lhs, rhs);
|
||||
|
||||
// TODO correctly distinguish inplace operators for mutable objects
|
||||
|
2
py/vm.c
2
py/vm.c
@ -186,7 +186,7 @@
|
||||
// MP_VM_RETURN_NORMAL, sp valid, return value in *sp
|
||||
// MP_VM_RETURN_YIELD, ip, sp valid, yielded value in *sp
|
||||
// MP_VM_RETURN_EXCEPTION, exception in state[0]
|
||||
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state_t *code_state, volatile mp_obj_t inject_exc) {
|
||||
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) {
|
||||
#define SELECTIVE_EXC_IP (0)
|
||||
#if SELECTIVE_EXC_IP
|
||||
#define MARK_EXC_IP_SELECTIVE() { code_state->ip = ip; } /* stores ip 1 byte past last opcode */
|
||||
|
Loading…
Reference in New Issue
Block a user