kopia lustrzana https://github.com/micropython/micropython
py/emitglue: Provide a truncated mp_raw_code_t for non-asm code.
The `asm_n_pos_args` and `asm_type_sig` members of `mp_raw_code_t` are only used for raw codes of type MP_CODE_NATIVE_ASM, which are rare, for example in frozen code. So using a truncated `mp_raw_code_t` in these cases helps to reduce frozen code size on targets that have MICROPY_EMIT_INLINE_ASM enabled. With this, change in firmware size of RPI_PICO builds is -648. Signed-off-by: Damien George <damien@micropython.org>pull/13628/head
rodzic
39bf055d23
commit
416465d81e
|
@ -207,7 +207,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
|
||||||
|
|
||||||
#define MP_DYNRUNTIME_INIT_ENTRY \
|
#define MP_DYNRUNTIME_INIT_ENTRY \
|
||||||
mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \
|
mp_obj_t old_globals = mp_fun_table.swap_globals(self->context->module.globals); \
|
||||||
mp_raw_code_t rc; \
|
mp_raw_code_truncated_t rc; \
|
||||||
rc.kind = MP_CODE_NATIVE_VIPER; \
|
rc.kind = MP_CODE_NATIVE_VIPER; \
|
||||||
rc.scope_flags = 0; \
|
rc.scope_flags = 0; \
|
||||||
(void)rc;
|
(void)rc;
|
||||||
|
@ -217,7 +217,7 @@ static inline void *mp_obj_malloc_helper_dyn(size_t num_bytes, const mp_obj_type
|
||||||
return mp_const_none;
|
return mp_const_none;
|
||||||
|
|
||||||
#define MP_DYNRUNTIME_MAKE_FUNCTION(f) \
|
#define MP_DYNRUNTIME_MAKE_FUNCTION(f) \
|
||||||
(mp_make_function_from_raw_code((rc.fun_data = (f), &rc), self->context, NULL))
|
(mp_make_function_from_raw_code((rc.fun_data = (f), (const mp_raw_code_t *)&rc), self->context, NULL))
|
||||||
|
|
||||||
#define mp_import_name(name, fromlist, level) \
|
#define mp_import_name(name, fromlist, level) \
|
||||||
(mp_fun_table.import_name((name), (fromlist), (level)))
|
(mp_fun_table.import_name((name), (fromlist), (level)))
|
||||||
|
|
|
@ -84,6 +84,29 @@ typedef struct _mp_raw_code_t {
|
||||||
#endif
|
#endif
|
||||||
} mp_raw_code_t;
|
} mp_raw_code_t;
|
||||||
|
|
||||||
|
// Version of mp_raw_code_t but without the asm_n_pos_args/asm_type_sig entries, which are
|
||||||
|
// only needed when the kind is MP_CODE_NATIVE_ASM. So this struct can be used when the
|
||||||
|
// kind is MP_CODE_BYTECODE, MP_CODE_NATIVE_PY or MP_CODE_NATIVE_VIPER, to reduce its size.
|
||||||
|
typedef struct _mp_raw_code_truncated_t {
|
||||||
|
uint32_t kind : 3;
|
||||||
|
uint32_t scope_flags : 7;
|
||||||
|
const void *fun_data;
|
||||||
|
struct _mp_raw_code_t **children;
|
||||||
|
#if MICROPY_PERSISTENT_CODE_SAVE || MICROPY_DEBUG_PRINTERS
|
||||||
|
uint32_t fun_data_len;
|
||||||
|
#endif
|
||||||
|
#if MICROPY_PERSISTENT_CODE_SAVE
|
||||||
|
uint16_t n_children;
|
||||||
|
#if MICROPY_EMIT_MACHINE_CODE
|
||||||
|
uint16_t prelude_offset;
|
||||||
|
#endif
|
||||||
|
#if MICROPY_PY_SYS_SETTRACE
|
||||||
|
uint32_t line_of_definition;
|
||||||
|
mp_bytecode_prelude_t prelude;
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
} mp_raw_code_truncated_t;
|
||||||
|
|
||||||
mp_raw_code_t *mp_emit_glue_new_raw_code(void);
|
mp_raw_code_t *mp_emit_glue_new_raw_code(void);
|
||||||
|
|
||||||
void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
|
void mp_emit_glue_assign_bytecode(mp_raw_code_t *rc, const byte *code,
|
||||||
|
|
|
@ -683,7 +683,7 @@ class CompiledModule:
|
||||||
else:
|
else:
|
||||||
print(" .obj_table = NULL,")
|
print(" .obj_table = NULL,")
|
||||||
print(" },")
|
print(" },")
|
||||||
print(" .rc = &raw_code_%s," % self.raw_code.escaped_name)
|
print(" .rc = (const mp_raw_code_t *)&raw_code_%s," % self.raw_code.escaped_name)
|
||||||
print("};")
|
print("};")
|
||||||
|
|
||||||
def freeze_constant_obj(self, obj_name, obj):
|
def freeze_constant_obj(self, obj_name, obj):
|
||||||
|
@ -898,7 +898,7 @@ class RawCode(object):
|
||||||
print()
|
print()
|
||||||
print("static const mp_raw_code_t *const children_%s[] = {" % self.escaped_name)
|
print("static const mp_raw_code_t *const children_%s[] = {" % self.escaped_name)
|
||||||
for rc in self.children:
|
for rc in self.children:
|
||||||
print(" &raw_code_%s," % rc.escaped_name)
|
print(" (const mp_raw_code_t *)&raw_code_%s," % rc.escaped_name)
|
||||||
if prelude_ptr:
|
if prelude_ptr:
|
||||||
print(" (void *)%s," % prelude_ptr)
|
print(" (void *)%s," % prelude_ptr)
|
||||||
print("};")
|
print("};")
|
||||||
|
@ -906,7 +906,11 @@ class RawCode(object):
|
||||||
|
|
||||||
def freeze_raw_code(self, prelude_ptr=None, type_sig=0):
|
def freeze_raw_code(self, prelude_ptr=None, type_sig=0):
|
||||||
# Generate mp_raw_code_t.
|
# Generate mp_raw_code_t.
|
||||||
print("static const mp_raw_code_t raw_code_%s = {" % self.escaped_name)
|
if self.code_kind == MP_CODE_NATIVE_ASM:
|
||||||
|
raw_code_type = "mp_raw_code_t"
|
||||||
|
else:
|
||||||
|
raw_code_type = "mp_raw_code_truncated_t"
|
||||||
|
print("static const %s raw_code_%s = {" % (raw_code_type, self.escaped_name))
|
||||||
print(" .kind = %s," % RawCode.code_kind_str[self.code_kind])
|
print(" .kind = %s," % RawCode.code_kind_str[self.code_kind])
|
||||||
print(" .scope_flags = 0x%02x," % self.scope_flags)
|
print(" .scope_flags = 0x%02x," % self.scope_flags)
|
||||||
print(" .fun_data = fun_data_%s," % self.escaped_name)
|
print(" .fun_data = fun_data_%s," % self.escaped_name)
|
||||||
|
@ -949,10 +953,9 @@ class RawCode(object):
|
||||||
print(" },")
|
print(" },")
|
||||||
print(" #endif")
|
print(" #endif")
|
||||||
print(" #endif")
|
print(" #endif")
|
||||||
print(" #if MICROPY_EMIT_INLINE_ASM")
|
if self.code_kind == MP_CODE_NATIVE_ASM:
|
||||||
print(" .asm_n_pos_args = %u," % self.n_pos_args)
|
print(" .asm_n_pos_args = %u," % self.n_pos_args)
|
||||||
print(" .asm_type_sig = %u," % type_sig)
|
print(" .asm_type_sig = %u," % type_sig)
|
||||||
print(" #endif")
|
|
||||||
print("};")
|
print("};")
|
||||||
|
|
||||||
global raw_code_count, raw_code_content
|
global raw_code_count, raw_code_content
|
||||||
|
|
Ładowanie…
Reference in New Issue