summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorAlessandro Gatti <a.gatti@frob.it>2025-03-04 00:55:25 +0100
committerDamien George <damien@micropython.org>2025-05-29 12:12:39 +1000
commitf5d10c322ecacc6be208388fa93adba5bee6eb0c (patch)
treeca4e15f5f93600e72a97dfa13e9031e5bf53f778
parent1006ed69f0ee8ea326a02ff05f45234c62d32d4e (diff)
downloadmicropython-f5d10c322ecacc6be208388fa93adba5bee6eb0c.tar.gz
micropython-f5d10c322ecacc6be208388fa93adba5bee6eb0c.zip
py/asmxtensa: Emit prologue jump only when constants table is in use.HEADmaster
This commit simplifies native functions' prologue code by not emitting a jump opcode that goes over the function's constants pool if the pool is empty. The original code assumed the constants pool is never empty as large 32-bits constants are commonly used, but for inline assembler functions that may not be the case. This meant that inline assembler functions may start with an unneeded jump (along with its alignment byte), using four bytes more than necessary. This commit is limited to the "xtensa" target, as "xtensawin" doesn't support inline assembler functions yet, so native functions' constant pools are almost always guaranteed to hold one or more values. Signed-off-by: Alessandro Gatti <a.gatti@frob.it>
-rw-r--r--py/asmxtensa.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/py/asmxtensa.c b/py/asmxtensa.c
index 0e612bfa7e..ab2e7aeaeb 100644
--- a/py/asmxtensa.c
+++ b/py/asmxtensa.c
@@ -66,10 +66,12 @@ void asm_xtensa_end_pass(asm_xtensa_t *as) {
}
void asm_xtensa_entry(asm_xtensa_t *as, int num_locals) {
- // jump over the constants
- asm_xtensa_op_j(as, as->num_const * WORD_SIZE + 4 - 4);
- mp_asm_base_get_cur_to_write_bytes(&as->base, 1); // padding/alignment byte
- as->const_table = (uint32_t *)mp_asm_base_get_cur_to_write_bytes(&as->base, as->num_const * 4);
+ if (as->num_const > 0) {
+ // jump over the constants
+ asm_xtensa_op_j(as, as->num_const * WORD_SIZE + 4 - 4);
+ mp_asm_base_get_cur_to_write_bytes(&as->base, 1); // padding/alignment byte
+ as->const_table = (uint32_t *)mp_asm_base_get_cur_to_write_bytes(&as->base, as->num_const * 4);
+ }
// adjust the stack-pointer to store a0, a12, a13, a14, a15 and locals, 16-byte aligned
as->stack_adjust = (((ASM_XTENSA_NUM_REGS_SAVED + num_locals) * WORD_SIZE) + 15) & ~15;
@@ -183,6 +185,8 @@ size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32) {
// store the constant in the table
if (as->const_table != NULL) {
as->const_table[as->cur_const] = i32;
+ } else {
+ assert((as->base.pass != MP_ASM_PASS_EMIT) && "Constants table was not built.");
}
++as->cur_const;
return loc;