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

Skip to content

Commit f5d10c3

Browse files
agattidpgeorge
authored andcommitted
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 1006ed6 commit f5d10c3

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
@@ -66,10 +66,12 @@ void asm_xtensa_end_pass(asm_xtensa_t *as) {
6666
}
6767

6868
void asm_xtensa_entry(asm_xtensa_t *as, int num_locals) {
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);
69+
if (as->num_const > 0) {
70+
// jump over the constants
71+
asm_xtensa_op_j(as, as->num_const * WORD_SIZE + 4 - 4);
72+
mp_asm_base_get_cur_to_write_bytes(&as->base, 1); // padding/alignment byte
73+
as->const_table = (uint32_t *)mp_asm_base_get_cur_to_write_bytes(&as->base, as->num_const * 4);
74+
}
7375

7476
// adjust the stack-pointer to store a0, a12, a13, a14, a15 and locals, 16-byte aligned
7577
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) {
183185
// store the constant in the table
184186
if (as->const_table != NULL) {
185187
as->const_table[as->cur_const] = i32;
188+
} else {
189+
assert((as->base.pass != MP_ASM_PASS_EMIT) && "Constants table was not built.");
186190
}
187191
++as->cur_const;
188192
return loc;

0 commit comments

Comments
 (0)
0