8000 py/asmxtensa: Emit prologue jump only when constants table is in use. · micropython/micropython@13a659d · GitHub
[go: up one dir, main page]

Skip to content

Commit 13a659d

Browse files
committed
py/asmxtensa: Emit prologue jump only when constants table is in use.
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>
1 parent df20769 commit 13a659d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

py/asmxtensa.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -65,10 +65,12 @@ void asm_xtensa_end_pass(asm_xtensa_t *as) {
6565
}
6666

6767
void asm_xtensa_entry(asm_xtensa_t *as, int num_locals) {
68-
// jump over the constants
69-
asm_xtensa_op_j(as, as->num_const * WORD_SIZE + 4 - 4);
70-
mp_asm_base_get_cur_to_write_bytes(&as->base, 1); // padding/alignment byte
71-
as->const_table = (uint32_t *)mp_asm_base_get_cur_to_write_bytes(&as->base, as->num_const * 4);
68+
if (as->num_const > 0) {
69+
// jump over the constants
70+
asm_xtensa_op_j(as, as->num_const * WORD_SIZE + 4 - 4);
71+
mp_asm_base_get_cur_to_write_bytes(&as->base, 1); // padding/alignment byte
72+
as->const_table = (uint32_t *)mp_asm_base_get_cur_to_write_bytes(&as->base, as->num_const * 4);
73+
}
7274

7375
// adjust the stack-pointer to store a0, a12, a13, a14, a15 and locals, 16-byte aligned
7476
as->stack_adjust = (((ASM_XTENSA_NUM_REGS_SAVED + num_locals) * WORD_SIZE) + 15) & ~15;
@@ -182,6 +184,8 @@ size_t asm_xtensa_mov_reg_i32(asm_xtensa_t *as, uint reg_dest, uint32_t i32) {
182184
// store the constant in the table
183185
if (as->const_table != NULL) {
184186
as->const_table[as->cur_const] = i32;
187+
} else {
188+
assert((as->base.pass != MP_ASM_PASS_EMIT) && "Constants table was not built.");
185189
}
186190
++as->cur_const;
187191
return loc;

0 commit comments

Comments
 (0)
0